From e97dc89a494b247e8b4bd7ba7b1b697241d213fc Mon Sep 17 00:00:00 2001 From: steve-lad <72376554+steve-lad@users.noreply.github.com> Date: Sun, 6 Jun 2021 11:00:00 +0200 Subject: [PATCH] Update install.php Check realtime configuration Impose correct version --- install.php | 94 ++++++++++++++++++++++++++--------------------------- 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/install.php b/install.php index 92e22c3..3e4a033 100644 --- a/install.php +++ b/install.php @@ -69,14 +69,9 @@ if ($chanSCCPWarning) { outn("
"); outn("Error: installed version of chan-sccp is not compatible. Please upgrade chan-sccp"); } -if (!$sccp_db_ver) { - Setup_RealTime(); - outn("
"); - outn("Install Complete !"); -} else { - outn("
"); - outn("Update Complete !"); -} +Setup_RealTime(); +outn("
"); +outn("Install Complete !"); outn("
"); // Functions follow @@ -771,78 +766,83 @@ function RenameConfig() function Setup_RealTime() { + outn("
  • " . _("Checking realtime configuration ...") . "
  • "); global $amp_conf; - outn("
  • " . _("Pre config RealTime") . "
  • "); $cnf_int = \FreePBX::Config(); $cnf_wr = \FreePBX::WriteConfig(); $cnf_read = \FreePBX::LoadConfig(); - $backup_ext = array('_custom.conf', '_additional.conf','.conf'); - - $def_config = array('sccpdevice' => 'mysql,asterisk,sccpdeviceconfig', 'sccpline' => ' mysql,asterisk,sccpline'); - $def_bd_config = array('dbhost' => $amp_conf['AMPDBHOST'], 'dbname' => $amp_conf['AMPDBNAME'], - 'dbuser' => $amp_conf['AMPDBUSER'], 'dbpass' => $amp_conf['AMPDBPASS'], - 'dbport' => '3306', 'dbsock' => '/var/lib/mysql/mysql.sock','dbcharset'=>'utf8'); - $def_bd_sec = 'asterisk'; + // Define required default settings based on FreePBX and system settings $dir = $cnf_int->get('ASTETCDIR'); - $res_conf_sql = ini_get('pdo_mysql.default_socket'); - $res_conf = ''; + $sys_mysql_socket = ini_get('pdo_mysql.default_socket'); + $def_bd_config = array('dbhost' => $amp_conf['AMPDBHOST'], + 'dbname' => $amp_conf['AMPDBNAME'], + 'dbuser' => $amp_conf['AMPDBUSER'], + 'dbpass' => $amp_conf['AMPDBPASS'], + 'dbport' => '3306', + 'dbsock' => '/var/lib/mysql/mysql.sock', + 'dbcharset'=>'utf8' + ); + if (!empty($sys_mysql_socket)) { + if (file_exists($sys_mysql_socket)) { + $def_bd_config['dbsock'] = $sys_mysql_socket; + } + } + $def_bd_section = $amp_conf['AMPDBNAME']; + $def_ext_config = array('sccpdevice' => "mysql,{$def_bd_section},sccpdeviceconfig",'sccpline' => "mysql,{$def_bd_section},sccpline"); + + // Check extconfig file for correct connector values $ext_conf = ''; $ext_conf_file = 'extconfig.conf'; + $backup_ext = array('_custom.conf', '_additional.conf','.conf'); foreach ($backup_ext as $value) { if (file_exists($dir . '/extconfig' . $value)) { + // Last possibility is normal file extconfig.conf $ext_conf_file = 'extconfig' . $value; $ext_conf = $cnf_read->getConfig($ext_conf_file); break; } } - if (!empty($res_conf_sql)) { - if (file_exists($res_conf_sql)) { - $def_bd_config['dbsock'] = $res_conf_sql; - } - } if (!empty($ext_conf)) { - $tmp = array(); - if (!empty($ext_conf['settings']['sccpdevice'])) { - $tmp = explode(',', $ext_conf['settings']['sccpdevice']); - $def_config['sccpdevice'] = $ext_conf['settings']['sccpdevice']; + $currentExtSettings = array(); + $writeExtSettings = $ext_conf; + if (empty($ext_conf['settings']['sccpdevice']) || ($ext_conf['settings']['sccpdevice'] !== $def_ext_config['sccpdevice'])) { + // Have error in sccpdevice so need to correct + $writeExtSettings['settings']['sccpdevice'] = $def_ext_config['sccpdevice']; } - if (!empty($ext_conf['settings']['sccpline'])) { - if (empty($tmp)) { - $tmp = explode(',', $ext_conf['settings']['sccpline']); - $tmp[2] = 'sccpdevice'; - $def_config['sccpdevice'] = implode(',', $tmp); - } - $def_config['sccpline'] = $ext_conf['settings']['sccpline']; + if (empty($ext_conf['settings']['sccpline']) || ($ext_conf['settings']['sccpline'] !== $def_ext_config['sccpline'])) { + // Have error in sccpline so need to correct + $writeExtSettings['settings']['sccpline'] = $def_ext_config['sccpline']; } - if (!empty($tmp)) { - $def_bd_sec = $tmp[1]; + if (!empty($writeExtSettings)) { + outn("
  • " . _("Updating extconfig file ...") . "
  • "); + $cnf_wr->writeConfig($ext_conf_file, $writeExtSettings); } } - $ext_conf['settings']['sccpdevice'] = $def_config['sccpdevice']; - $ext_conf['settings']['sccpline'] = $def_config['sccpline']; + // Check database settings + $res_conf = ''; if (file_exists($dir . '/res_mysql.conf')) { $res_conf = $cnf_read->getConfig('res_mysql.conf'); - if (empty($res_conf[$def_bd_sec])) { - $res_conf[$def_bd_sec] = $def_bd_config; + if (empty($res_conf[$def_bd_section])) { + $res_conf[$def_bd_section] = $def_bd_config; + $cnf_wr->writeConfig('res_mysql.conf', $res_conf); + outn("
  • " . _("Updating res_mysql.conf file ...") . "
  • "); } - $cnf_wr->writeConfig('res_mysql.conf', $res_conf, false); } if (file_exists($dir . '/res_config_mysql.conf')) { $res_conf = $cnf_read->getConfig('res_config_mysql.conf'); - if (empty($res_conf[$def_bd_sec])) { - $res_conf[$def_bd_sec] = $def_bd_config; + if (empty($res_conf[$def_bd_section])) { + $res_conf[$def_bd_section] = $def_bd_config; + $cnf_wr->writeConfig('res_config_mysql.conf', $res_conf); + outn("
  • " . _("Updating res_config_mysql.conf file ...") . "
  • "); } - $cnf_wr->writeConfig('res_config_mysql.conf', $res_conf, false); } if (empty($res_conf)) { - $res_conf[$def_bd_sec] = $def_bd_config; -// $res_conf['general']['dbsock'] = $def_bd_config['dbsock']; + $res_conf[$def_bd_section] = $def_bd_config; $cnf_wr->writeConfig('res_config_mysql.conf', $res_conf, false); } - $cnf_wr->writeConfig($ext_conf_file, $ext_conf, false); } ?>