Example #1
0
function voicemail_configprocess()
{
    //create vars from the request
    extract($_REQUEST);
    $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
    $extdisplay = isset($_REQUEST['extdisplay']) ? $_REQUEST['extdisplay'] : null;
    //if submitting form, update database
    switch ($action) {
        case "add":
            if (!isset($GLOBALS['abort']) || $GLOBALS['abort'] !== true) {
                $usage_arr = framework_check_extension_usage($_REQUEST['extension']);
                if (!empty($usage_arr)) {
                    $GLOBALS['abort'] = true;
                } else {
                    voicemail_mailbox_add($extdisplay, $_REQUEST);
                    needreload();
                }
            }
            break;
        case "del":
            // call remove before del, it needs to know context info
            //
            voicemail_mailbox_remove($extdisplay);
            voicemail_mailbox_del($extdisplay);
            needreload();
            break;
        case "edit":
            if (!isset($GLOBALS['abort']) || $GLOBALS['abort'] !== true) {
                voicemail_mailbox_del($extdisplay);
                if ($vm != 'disabled') {
                    voicemail_mailbox_add($extdisplay, $_REQUEST);
                }
                needreload();
            }
            break;
    }
}
Example #2
0
    $any_devices = core_devices_get($ext);
    if (count($any_devices) > 0 || !core_devices_add($ext, $tech, '', 'fixed', $ext, $displayname, $emergencycid)) {
        var_dump($any_devices);
        fatal("Attempt to add device failed, aborting");
        exit(1);
    }
}
if (in_array('remext', $actions)) {
    $actions_taken = true;
    if (core_users_get($ext) != null) {
        debug("removing user {$ext}");
        core_users_del($ext);
        core_devices_del($ext);
    } else {
        debug("not removing user {$ext}");
    }
    if (voicemail_mailbox_get($ext) != null) {
        debug("removing vm {$ext}");
        voicemail_mailbox_del($ext);
    } else {
        debug("not removing vm {$ext}");
    }
}
if ($actions_taken) {
    debug("Request completed successfully");
    exit(0);
} else {
    warning("No actions were performed");
    exit(10);
}
exit;
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;
}
 /**
  * Delete user function, it's run twice because of scemantics with
  * old freepbx but it's harmless
  * @param  string $extension The extension number
  * @param  bool $editmode  If we are in edit mode or not
  */
 public function delUser($extension, $editmode = false)
 {
     if (!$editmode) {
         if (!function_exists('voicemail_mailbox_remove')) {
             $this->FreePBX->Modules->loadFunctionsInc('voicemail');
         }
         voicemail_mailbox_remove($extension);
         voicemail_mailbox_del($extension);
     }
 }