📄 settings.module
字号:
<?php/** * @file * Functions for the interface to the call monitor recordings *//** * Class for settings */class Settings { var $protocol_table; var $protocol_config_files; /* * rank (for prioritizing modules) */ function rank() { $rank = 100000; return $rank; } /* * init */ function init() { // determine what protocol user is using global $ASTERISK_PROTOCOLS; foreach ($ASTERISK_PROTOCOLS as $protocol => $value) { $data = $this->getProtocolRecordSettings($value['table'],$_SESSION['ari_user']['extension']); if (count($data)) { $this->protocol_table = $value['table']; $this->protocol_config_files = $value['config_files']; break; } } } /* * Adds menu item to nav menu * * @param $args * Common arguments */ function navMenu($args) { global $ARI_NO_LOGIN; // check logout if ($_SESSION['ari_user'] && !$ARI_NO_LOGIN) { $logout = 1; } if ($logout!='') { $ret .= " <br> <p><small><small><a href='" . $_SESSION['ARI_ROOT'] . "?m=Settings&f=display'>" . _("Settings") . "</a></small></small></p>"; } return $ret; } /* * Acts on the user settings * * @param $args * Common arguments * @param $a * action */ function action($args) { global $STANDALONE; global $ARI_ADMIN_USERNAME; global $ASTERISK_VOICEMAIL_CONF; global $SETTINGS_ALLOW_VOICEMAIL_PASSWORD_SET; global $SETTINGS_VOICEMAIL_PASSWORD_LENGTH; global $SETTINGS_VOICEMAIL_PASSWORD_EXACT; global $SETTINGS_ALLOW_CALL_RECORDING_SET; // args $m = getArgument($args,'m'); $a = getArgument($args,'a'); $lang_code = getArgument($args,'lang_code'); $call_forward_enable = getArgument($args,'call_forward_enable'); $call_forward_number = getArgument($args,'call_forward_number'); $voicemail_password = getArgument($args,'voicemail_password'); $voicemail_password_confirm = getArgument($args,'voicemail_password_confirm'); $voicemail_email_address = getArgument($args,'voicemail_email_address'); $voicemail_pager_address = getArgument($args,'voicemail_pager_address'); $voicemail_email_enable = getArgument($args,'voicemail_email_enable'); if (isset($_SESSION['ari_user']['voicemail_email'])) { foreach (array_keys($_SESSION['ari_user']['voicemail_email']) as $key) { $var = "voicemail_email_$key"; $$var = getArgument($args,$var); } } $voicemail_audio_format = getArgument($args,'voicemail_audio_format'); $record_in = getArgument($args,'record_in'); $record_out = getArgument($args,'record_out'); $language = new Language(); if ($a=='update') { $exten = $_SESSION['ari_user']['extension']; if ($exten!=$ARI_ADMIN_USERNAME) { // update call forward number if (!$STANDALONE['use']) { $stripped_call_forward_number = preg_replace('/-|\(|\)|\s/','',$call_forward_number); if ($call_forward_enable && !is_numeric($stripped_call_forward_number)) { $_SESSION['ari_error'] = _("Call forward number not changed") . "<br>" . sprintf(_("Number %s must contain dial numbers (characters like '(', '-', and ')' are ok)"),$call_forward_number); } else { // set database $this->setCallForward($exten,$call_forward_enable,$stripped_call_forward_number); // store cookie $stripped = preg_replace('/-|\(|\)|\s/','',$_COOKIE['ari_call_forward_number']); if ($call_forward_number && $stripped!=$stripped_call_forward_number) { setcookie("ari_call_forward_number", $call_forward_number, time()+365*24*60*60); } } } // voicemail settings if ($_SESSION['ari_user']['voicemail_enabled']==1) { // update voicemail password if ($SETTINGS_ALLOW_VOICEMAIL_PASSWORD_SET) { // update voicemail password if ($voicemail_password=='' || $voicemail_password_confirm=='') { $_SESSION['ari_error'] = _("Voicemail password not changed") . "<br>" . _("Password and password confirm must not be blank"); } else if ((strlen($voicemail_password)<$SETTINGS_VOICEMAIL_PASSWORD_LENGTH) || !is_numeric($voicemail_password)) { $_SESSION['ari_error'] = _("Voicemail password not changed") . "<br>" . sprintf(_("Passwords must be all numbers and greater than %d digits"),$SETTINGS_VOICEMAIL_PASSWORD_LENGTH); } else if (strlen($voicemail_password)!=$SETTINGS_VOICEMAIL_PASSWORD_LENGTH && $SETTINGS_VOICEMAIL_PASSWORD_EXACT || !is_numeric($voicemail_password)) { $_SESSION['ari_error'] = _("Voicemail password not changed") . "<br>" . sprintf(_("Passwords must be all numbers and only %d digits"),$SETTINGS_VOICEMAIL_PASSWORD_LENGTH); } else if ($voicemail_password!=$voicemail_password_confirm) { $_SESSION['ari_error'] = _("Voicemail password not changed") . "<br>" . _("Password and password confirm do not match"); } else { // check for writable the files $temp_file = $ASTERISK_VOICEMAIL_CONF . ".tmp"; $fp = fopen($temp_file, "w"); if (!$fp) { $_SESSION['ari_error'] = _("Voicemail password not changed") . "<br>" . sprintf(_("%s does not exist or is not writable"),$temp_file); } else if (!is_writable($ASTERISK_VOICEMAIL_CONF)) { $_SESSION['ari_error'] = _("Voicemail password not changed") . "<br>" . sprintf(_("%s does not exist or is not writable"),$ASTERISK_VOICEMAIL_CONF); } else { // update session $_SESSION['ari_user']['voicemail_password'] = $voicemail_password; // save password $lines = file($ASTERISK_VOICEMAIL_CONF); foreach ($lines as $key => $line) { unset($value); list($var,$value) = split('=>',$line); $var = trim($var); if ($var==$exten && $value) { // write out line with password change $buf = split(',',$value); $buf[0] = $voicemail_password; $line = $var . " => " . join(',', $buf); fwrite($fp, $line); } else { // write out original line with no changes fwrite($fp, $line); } } fclose($fp); unlink($ASTERISK_VOICEMAIL_CONF); rename($temp_file,$ASTERISK_VOICEMAIL_CONF); $voicemail_reload = 1; } } // voicemail email address if ($voicemail_email_enable && ($voicemail_email_address && !preg_match('/@/',$voicemail_email_address) || ($voicemail_pager_address && !preg_match('/@/',$voicemail_pager_address)))) { $_SESSION['ari_error'] = _("Voicemail email and pager address not changed") . "<br>" . ("'$voicemail_email_address' and '$voicemail_pager_address' must be a valid email addresses"); } else { // check for writable the files $temp_file = $ASTERISK_VOICEMAIL_CONF . ".tmp"; $fp = fopen($temp_file, "w"); if (!$fp) { $_SESSION['ari_error'] = _("Voicemail email settings not changed") . "<br>" . sprintf(_("%s does not exist or is not writable"),$temp_file); } else if (!is_writable($ASTERISK_VOICEMAIL_CONF)) { $_SESSION['ari_error'] = _("Voicemail email settings not changed") . "<br>" . sprintf(_("%s does not exist or is not writable"),$ASTERISK_VOICEMAIL_CONF); } else { // store cookie if ($voicemail_email_enable) { setcookie("ari_voicemail_email_address", $voicemail_email_address, time()+365*24*60*60); setcookie("ari_voicemail_pager_address", $voicemail_pager_address, time()+365*24*60*60); foreach (array_keys($_SESSION['ari_user']['voicemail_email']) as $key) { $var = "voicemail_email_$key"; $var_cookie = "ari_" . $var; setcookie("$var_cookie", $$var, time()+365*24*60*60); } } // update session $_SESSION['ari_user']['voicemail_email_enable'] = $voicemail_email_enable; if ($voicemail_email_enable) { $_SESSION['ari_user']['voicemail_email_address'] = $voicemail_email_address; $_SESSION['ari_user']['voicemail_pager_address'] = $voicemail_pager_address; foreach (array_keys($_SESSION['ari_user']['voicemail_email']) as $key) { $option = "voicemail_email_$key"; $_SESSION['ari_user']['voicemail_email'][$key] = $$option; } } // save settings if (!$voicemail_email_enable) { $voicemail_email_address = ''; $voicemail_pager_address = ''; } $lines = file($ASTERISK_VOICEMAIL_CONF); foreach ($lines as $key => $line) { unset($value); list($var,$value) = split('=>',$line); $var = trim($var); if ($var==$exten && $value) { // write out line with voicemail email change $buf = split(',',$value); $buf[2] = $voicemail_email_address; $buf[3] = $voicemail_pager_address; foreach ($_SESSION['ari_user']['voicemail_email'] as $key => $value) { $option = "voicemail_email_$key"; if ($$option && $key) { $options .= $key . "=" . $value; } else { $options .= $key . "=no"; } $options .= "|"; } $buf[4] = substr($options, 0, -1); $line = $var . " =>" . join(',', $buf); if (substr($line, 0, -1)!="\n") { $line .= "\n"; } fwrite($fp, $line); } else { // write out original line with no changes fwrite($fp, $line); } } fclose($fp); unlink($ASTERISK_VOICEMAIL_CONF); rename($temp_file,$ASTERISK_VOICEMAIL_CONF);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -