/** * @verb PUT * @uri /voicemail/password/:id */ function put_password_id($params) { if (!isset($params['password'])) { return false; } $uservm = voicemail_getVoicemail(); $vmcontexts = array_keys($uservm); foreach ($vmcontexts as $vmcontext) { if (isset($uservm[$vmcontext][$params['id']])) { global $astman; $uservm[$vmcontext][$params['id']]['pwd'] = $params['password']; voicemail_saveVoicemail($uservm); $astman->send_request("Command", array("Command" => "voicemail reload")); return true; } } return false; }
function voicemail_mailbox_add($mbox, $mboxoptsarray) { global $astman; //check if VM box already exists if (voicemail_mailbox_get($mbox) != null) { trigger_error("Voicemail mailbox '{$mbox}' already exists, call to voicemail_maibox_add failed"); die_freepbx(); } $uservm = voicemail_getVoicemail(); extract($mboxoptsarray); if ($vm != 'disabled') { // need to check if there are any options entered in the text field if ($options != '') { $options = explode("|", $options); foreach ($options as $option) { $vmoption = explode("=", $option); $vmoptions[$vmoption[0]] = $vmoption[1]; } } if ($imapuser != '' && $imapuser != '') { $vmoptions['imapuser'] = $imapuser; $vmoptions['imappassword'] = $imappassword; } $vmoption = explode("=", $attach); $vmoptions[$vmoption[0]] = $vmoption[1]; $vmoption = explode("=", $saycid); $vmoptions[$vmoption[0]] = $vmoption[1]; $vmoption = explode("=", $envelope); $vmoptions[$vmoption[0]] = $vmoption[1]; $vmoption = explode("=", $delete); $vmoptions[$vmoption[0]] = $vmoption[1]; $uservm[$vmcontext][$extension] = array('mailbox' => $extension, 'pwd' => $vmpwd, 'name' => $name, 'email' => $email, 'pager' => $pager, 'options' => $vmoptions); // Update $_REQUEST with 'devinfo_mailbox, so MWI works. if (empty($_REQUEST['devinfo_mailbox'])) { $_REQUEST['devinfo_mailbox'] = "{$extension}@{$vmcontext}"; } } voicemail_saveVoicemail($uservm); $vmxobj = new vmxObject($extension); // Operator extension can be set even without VmX enabled so that it can be // used as an alternate way to provide an operator extension for a user // without VmX enabled. // if (isset($vmx_option_0_system_default) && $vmx_option_0_system_default != '') { $vmxobj->setMenuOpt("", 0, 'unavail'); $vmxobj->setMenuOpt("", 0, 'busy'); } else { if (!isset($vmx_option_0_number)) { $vmx_option_0_number = ''; } $vmx_option_0_number = preg_replace("/[^0-9]/", "", $vmx_option_0_number); $vmxobj->setMenuOpt($vmx_option_0_number, 0, 'unavail'); $vmxobj->setMenuOpt($vmx_option_0_number, 0, 'busy'); } if (isset($vmx_state) && $vmx_state) { if (isset($vmx_unavail_enabled) && $vmx_unavail_enabled != '') { $vmxobj->setState('enabled', 'unavail'); } else { $vmxobj->setState('disabled', 'unavail'); } if (isset($vmx_busy_enabled) && $vmx_busy_enabled != '') { $vmxobj->setState('enabled', 'busy'); } else { $vmxobj->setState('disabled', 'busy'); } if (isset($vmx_play_instructions) && $vmx_play_instructions == 'checked') { $vmxobj->setVmPlay(true, 'unavail'); $vmxobj->setVmPlay(true, 'busy'); } else { $vmxobj->setVmPlay(false, 'unavail'); $vmxobj->setVmPlay(false, 'busy'); } if (isset($vmx_option_1_system_default) && $vmx_option_1_system_default != '') { $vmxobj->setFollowMe(1, 'unavail'); $vmxobj->setFollowMe(1, 'busy'); } else { $vmx_option_1_number = preg_replace("/[^0-9]/", "", $vmx_option_1_number); $vmxobj->setMenuOpt($vmx_option_1_number, 1, 'unavail'); $vmxobj->setMenuOpt($vmx_option_1_number, 1, 'busy'); } if (isset($vmx_option_2_number)) { $vmx_option_2_number = preg_replace("/[^0-9]/", "", $vmx_option_2_number); $vmxobj->setMenuOpt($vmx_option_2_number, 2, 'unavail'); $vmxobj->setMenuOpt($vmx_option_2_number, 2, 'busy'); } } else { if ($vmxobj->isInitialized()) { $vmxobj->disable(); } } }
function voicemail_update_settings($action, $context = "", $extension = "", $args = null) { global $astman; global $tz_settings; global $gen_settings; /* Ensure we get the most up-to-date voicemail.conf data. */ if ($action != 'dialplan') { $vmconf = voicemail_getVoicemail(); } else { $vmconf = null; } if ($vmconf !== null) { switch ($action) { case "tz": /* First update all zonemessages opts that are already in vmconf */ $vmconf["zonemessages"] = is_array($vmconf["zonemessages"]) ? $vmconf["zonemessages"] : array(); foreach ($vmconf["zonemessages"] as $key => $val) { $id = "tz__{$key}"; $vmconf["zonemessages"][$key] = isset($args[$id]) ? $args[$id] : $vmconf["zonemessages"][$key]; /* Bad to have empty fields in vmconf. */ /* And remove deleted fields, too. */ if (empty($vmconf["zonemessages"][$key]) || $args["tzdel__{$key}"] == "true") { unset($vmconf["zonemessages"][$key]); } } /* Add new field, if one was specified */ if (!empty($args["tznew_name"]) && !empty($args["tznew_def"])) { $vmconf["zonemessages"][$args["tznew_name"]] = $args["tznew_def"]; } unset($args[$id]); /* Next record any new zonemessages opts that were on the page but not already in vmconf. */ if (is_array($tz_settings)) { foreach ($tz_settings as $key) { $id = "tz__{$key}"; if (isset($args[$id]) && !empty($args[$id])) { $vmconf["zonemessages"][$key] = $args[$id]; } } } break; case "settings": if (empty($extension) && $action == "settings") { /* First update all general opts that are already in vmconf */ $vmconf["general"] = is_array($vmconf["general"]) ? $vmconf["general"] : array(); foreach ($vmconf["general"] as $key => $val) { $id = "gen__{$key}"; $vmconf["general"][$key] = isset($args[$id]) ? $args[$id] : $vmconf["general"][$key]; //The only reason to use \r is if you're writing to a character terminal //(or more likely a "console window" emulating it) and want the next //line you write to overwrite the last one you just wrote //(sometimes used for goofy "ascii animation" effects of e.g. progress bars) //-- this is getting pretty obsolete in a world of GUIs, though;-). //http://stackoverflow.com/questions/1761051/difference-between-n-and-r $vmconf["general"][$key] = str_replace(array("\r", "\n", "\t"), array('', '\\n', '\\t'), $vmconf["general"][$key]); /* Bad to have empty fields in vmconf. */ /* also make sure no boolean undefined fields left in there */ if (trim($vmconf["general"][$key]) == "" || $vmconf["general"][$key] == 'undefined' && $gen_settings[$key]['type'] == 'flag') { unset($vmconf["general"][$key]); } unset($args[$id]); } /* Next record any new general opts that were on the page but not already in vmconf. */ if (is_array($gen_settings)) { foreach ($gen_settings as $key => $descrip) { $id = "gen__{$key}"; if (isset($args[$id]) && !empty($args[$id])) { $vmconf["general"][$key] = $args[$id]; } } } } else { if (!empty($extension)) { global $acct_settings; /* We need this to know the type for each option (text value or flag) */ /* Delete user's old settings. */ voicemail_mailbox_del($extension); /* Prepare values for user's new settings. */ /* Each Voicemail account has a line in voicemail.conf like this: */ /* extension => password,name,email,pager,options */ /* Take care of password, name, email and pager. */ $pwd = isset($args["acct__pwd"]) ? $args["acct__pwd"] : ""; unset($args["acct__pwd"]); if (isset($args["acct__name"]) && $args["acct__name"] != "") { $name = $args["acct__name"]; } else { $this_exten = core_users_get($extension); $name = $this_exten["name"]; } unset($args["acct__name"]); $email = isset($args["acct__email"]) ? $args["acct__email"] : ""; unset($args["acct__email"]); $pager = isset($args["acct__pager"]) ? $args["acct__pager"] : ""; unset($args["acct__pager"]); /* Now handle the options. */ $options = array(); $acct_settings = is_array($acct_settings) ? $acct_settings : array(); foreach ($acct_settings as $key => $descrip) { $id = "acct__{$key}"; if (isset($args[$id]) && !empty($args[$id]) && $args[$id] != "undefined") { $options[$key] = $args[$id]; } } /* Remove call me num from options - that is set in ast db */ unset($options["callmenum"]); /* New account values to vmconf */ $vmconf[$context][$extension] = array("mailbox" => $extension, "pwd" => $pwd, "name" => $name, "email" => $email, "pager" => $pager, "options" => $options); $callmenum = isset($args["acct__callmenum"]) && !empty($args["acct__callmenum"]) ? $args["acct__callmenum"] : $extension; // Save call me num. $cmd = "database put AMPUSER {$extension}/callmenum {$callmenum}"; if ($astman->connected()) { $astman->send_request("Command", array("Command" => $cmd)); } } } break; case "bsettings": if (!empty($extension)) { /* Get user's old settings, since we are only replacing the basic settings. */ $vmbox = voicemail_mailbox_get($extension); /* Delete user's old settings. */ voicemail_mailbox_del($extension); /* Prepare values for user's new BASIC settings. */ /* Each Voicemail account has a line in voicemail.conf like this: */ /* extension => password,name,email,pager,options */ /* Take care of password, name, email and pager. */ $pwd = isset($args["acct__pwd"]) ? $args["acct__pwd"] : ""; unset($args["acct__pwd"]); if (isset($args["acct__name"]) && $args["acct__name"] != "") { $name = $args["acct__name"]; } else { $this_exten = core_users_get($extension); $name = $this_exten["name"]; } unset($args["acct__name"]); $email = isset($args["acct__email"]) ? $args["acct__email"] : ""; unset($args["acct__email"]); $pager = isset($args["acct__pager"]) ? $args["acct__pager"] : ""; unset($args["acct__pager"]); /* THESE ARE COMING FROM THE USER'S OLD SETTINGS. */ $options = $vmbox["options"]; /* An array */ /* Update the four options listed on the "bsettings" page as needed. */ $basic_opts_list = array("attach", "saycid", "envelope", "delete"); foreach ($basic_opts_list as $basic_opt) { $id = "acct__" . $basic_opt; if (isset($args[$id]) && !empty($args[$id]) && $args[$id] != "undefined") { $options[$basic_opt] = $args[$id]; } else { if ($args[$id] == "undefined") { unset($options[$basic_opt]); } } } /* Remove call me num from options - that is set in ast db. Should not be here anyway, since options are coming from the old settings... */ unset($options["callmenum"]); /* New account values to vmconf */ $vmconf[$context][$extension] = array("mailbox" => $extension, "pwd" => $pwd, "name" => $name, "email" => $email, "pager" => $pager, "options" => $options); $callmenum = isset($args["acct__callmenum"]) && !empty($args["acct__callmenum"]) ? $args["acct__callmenum"] : $extension; // Save call me num. $cmd = "database put AMPUSER {$extension}/callmenum {$callmenum}"; if ($astman->connected()) { $astman->send_request("Command", array("Command" => $cmd)); } } break; default: return false; } if (!empty($vmconf)) { $vmconf['general']['charset'] = "UTF-8"; } voicemail_saveVoicemail($vmconf); if ($astman->connected()) { $astman->send_request("Command", array("Command" => "reload app_voicemail.so")); } return true; // Special Case dialplan since no voicemail.conf related configs } else { if ($action == 'dialplan') { // defaults need to be set for checkboxes unless we change them to radio buttons // $cb = array('VM_OPTS', 'VMX_OPTS_LOOP', 'VMX_OPTS_DOVM'); foreach ($cb as $cbs) { if (!isset($args[$cbs])) { $args[$cbs] = ''; } } return voicemail_admin_update($args); } } return false; }
/** * Save Voicemail Settings for an extension * @param int $ext The voicemail extension * @param string $pwd The voicemail password/pin * @param string $email The voicemail email address * @param string $page The voicemail pager number * @param string $playcid Whether to play the CID to the caller * @param string $envelope Whether to play the envelope to the caller */ public function saveVMSettingsByExtension($ext, $pwd, $email, $page, $playcid, $envelope) { $o = $this->getVoicemailBoxByExtension($ext); $context = $o['vmcontext']; $vmconf = voicemail_getVoicemail(); if (!empty($vmconf[$context][$ext])) { $vmconf[$context][$ext]['pwd'] = $pwd; $vmconf[$context][$ext]['email'] = $email; $vmconf[$context][$ext]['pager'] = $page; $vmconf[$context][$ext]['options']['saycid'] = $playcid ? 'yes' : 'no'; $vmconf[$context][$ext]['options']['envelope'] = $envelope ? 'yes' : 'no'; voicemail_saveVoicemail($vmconf); $this->astman->Reload("voicemail"); return true; } return false; }