function voicemail_get_settings($vmconf, $action, $extension = "")
{
    $settings = array();
    switch ($action) {
        case "dialplan":
            // DEFAULTS:
            $settings['VM_OPTS'] = '';
            $settings['VM_DDTYPE'] = 'b';
            $settings['VM_GAIN'] = '12';
            $settings['OPERATOR_XTN'] = '';
            $settings['VMX_OPTS_LOOP'] = '';
            $settings['VMX_OPTS_DOVM'] = '';
            $settings['VMX_TIMEOUT'] = '2';
            $settings['VMX_REPEAT'] = '1';
            $settings['VMX_LOOPS'] = '1';
            $vmsettings = voicemail_admin_get();
            // replace defaults with any values present in the DB
            foreach ($vmsettings as $k => $v) {
                $settings[$k] = $vmsettings[$k];
            }
            break;
        case "tz":
            if (is_array($vmconf) && !empty($vmconf["zonemessages"]) && is_array($vmconf["zonemessages"])) {
                foreach ($vmconf["zonemessages"] as $key => $val) {
                    $settings[$key] = $val;
                }
            }
            break;
        case "bsettings":
        case "settings":
            /* Settings can apply to system-wide settings OR to account-specific settings. 		       */
            /* Specifying a context and extension indicates account-specific settings are being requested. */
            if (!empty($extension)) {
                $vmbox = voicemail_mailbox_get($extension);
                if ($vmbox !== null) {
                    $settings["enabled"] = true;
                } else {
                    $settings["enabled"] = false;
                }
                $settings["vmcontext"] = $c = isset($vmbox["vmcontext"]) ? $vmbox["vmcontext"] : "default";
                $settings["pwd"] = isset($vmbox["pwd"]) ? $vmbox["pwd"] : "";
                $settings["name"] = isset($vmbox["name"]) && $vmbox["name"] != "" ? $vmbox["name"] : "";
                if ($settings["name"] == "") {
                    $this_exten = core_users_get($extension);
                    $settings["name"] = $this_exten["name"];
                }
                $settings["email"] = isset($vmbox["email"]) ? $vmbox["email"] : "";
                $settings["pager"] = isset($vmbox["pager"]) ? $vmbox["pager"] : "";
                $options = isset($vmbox["options"]) ? $vmbox["options"] : array();
                foreach ($options as $key => $val) {
                    $settings[$key] = $val;
                }
                /* Get Call Me number */
                global $astman;
                if (!$astman->connected()) {
                    die_freepbx(_("Asterisk doesn't appear to be running, Cannot connect to Asterisk Manager"));
                }
                $cmd = "database get AMPUSER {$extension}/callmenum";
                $callmenum = "";
                $results = $astman->send_request("Command", array("Command" => $cmd));
                if (is_array($results)) {
                    foreach ($results as $results_elem) {
                        if (preg_match('/Value: [^\\s]*/', $results_elem, $matches) > 0) {
                            $parts = preg_split('/ /', trim($matches[0]));
                            $callmenum = $parts[1];
                            break;
                        }
                    }
                }
                $settings["callmenum"] = $callmenum;
                /* End - Call Me number obtained */
            } else {
                if (is_array($vmconf) && is_array($vmconf["general"])) {
                    $settings = $vmconf["general"];
                }
            }
            break;
        default:
            break;
    }
    return $settings;
}
Example #2
0
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();
        }
    }
}
Example #3
0
function core_getdestinfo($dest)
{
    global $amp_conf;
    global $active_modules;
    // Check for Extension Number Destinations
    //
    $users = \FreePBX::Core()->getAllUsers();
    if (substr(trim($dest), 0, 16) == 'from-did-direct,') {
        $exten = explode(',', $dest);
        $exten = $exten[1];
        if (!isset($users[$exten])) {
            return array();
        } else {
            $name = isset($users[$exten]['name']) ? $users[$exten]['name'] : '';
            $display = $amp_conf['AMPEXTENSIONS'] == "deviceanduser" ? 'users' : 'extensions';
            return array('description' => sprintf(_("User Extension %s: %s"), $exten, $name), 'edit_url' => "config.php?type=setup&display={$display}&extdisplay=" . urlencode($exten) . "&skip=0");
        }
    } else {
        if (substr(trim($dest), 0, 10) == 'ext-trunk,') {
            $exten = explode(',', $dest);
            $exten = $exten[1];
            $thisexten = core_trunks_getDetails($exten);
            if (empty($thisexten)) {
                return array();
            } else {
                $display = 'trunks';
                $name = isset($thisexten['name']) && $thisexten['name'] ? $thisexten['name'] : '';
                return array('description' => sprintf(_('Trunk: %s (%s)'), $name, $thisexten['tech']), 'edit_url' => "config.php?type=setup&display={$display}&extdisplay=OUT_" . urlencode($exten));
            }
            // Check for voicemail box destinations
            //
        } else {
            if (substr(trim($dest), 0, 12) == 'ext-local,vm') {
                $exten = explode(',', $dest);
                $exten = substr($exten[1], 3);
                if (!function_exists('voicemail_mailbox_get')) {
                    return array();
                }
                if (!isset($users[$exten])) {
                    return array();
                }
                $box = voicemail_mailbox_get($exten);
                if ($box == null) {
                    return array();
                }
                $description = sprintf(_("User Extension %s: %s"), $exten, $box['name']);
                $display = $amp_conf['AMPEXTENSIONS'] == "deviceanduser" ? 'users' : 'extensions';
                return array('description' => $description, 'edit_url' => "config.php?type=setup&display={$display}&extdisplay=" . urlencode($exten) . "&skip=0");
                // Check for blackhole Termination Destinations
                //
            } else {
                if (substr(trim($dest), 0, 14) == 'app-blackhole,') {
                    $exten = explode(',', $dest);
                    $exten = $exten[1];
                    switch ($exten) {
                        case 'hangup':
                            $description = 'Hangup';
                            break;
                        case 'congestion':
                            $description = 'Congestion';
                            break;
                        case 'busy':
                            $description = 'Busy';
                            break;
                        case 'zapateller':
                            $description = 'Play SIT Tone (Zapateller)';
                            break;
                        case 'musiconhold':
                            $description = 'Put caller on hold forever';
                            break;
                        case 'ring':
                            $description = 'Play ringtones to caller';
                            break;
                        case 'no-service':
                            $description = 'Play no service message';
                            break;
                        default:
                            $description = false;
                    }
                    if ($description) {
                        return array('description' => 'Core: ' . $description, 'edit_url' => false);
                    } else {
                        return array();
                    }
                    // None of the above, so not one of ours
                } else {
                    return false;
                }
            }
        }
    }
}
Example #4
0
 /**
  * Get a voicemail box by extension
  * @param int $ext The extension
  */
 public function getVoicemailBoxByExtension($ext)
 {
     if (empty($this->vmBoxData[$ext])) {
         //TODO: Lazy...
         if (!function_exists('voicemail_mailbox_get')) {
             include_once __DIR__ . '/functions.inc.php';
         }
         $this->vmBoxData[$ext] = voicemail_mailbox_get($ext);
     }
     return !empty($this->vmBoxData[$ext]) ? $this->vmBoxData[$ext] : false;
 }
Example #5
0
function core_users_add($vars, $editmode = false)
{
    extract($vars);
    global $db;
    global $amp_conf;
    global $astman;
    $thisexten = isset($thisexten) ? $thisexten : '';
    if (trim($extension) == '') {
        echo "<script>javascript:alert('" . _("You must put in an extension (or user) number") . "');</script>";
        return false;
    }
    //ensure this id is not already in use
    $extens = core_users_list();
    if (is_array($extens)) {
        foreach ($extens as $exten) {
            if ($exten[0] === $extension) {
                echo "<script>javascript:alert('" . sprintf(_("This user/extension %s is already in use"), $extension) . "');</script>";
                return false;
            }
        }
    }
    $newdid_name = isset($newdid_name) ? $db->escapeSimple($newdid_name) : '';
    $newdid = isset($newdid) ? $newdid : '';
    $newdid = preg_replace("/[^0-9._XxNnZz\\[\\]\\-\\+]/", "", trim($newdid));
    $newdidcid = isset($newdidcid) ? trim($newdidcid) : '';
    if (!preg_match('/^priv|^block|^unknown|^restrict|^unavail|^anonym/', strtolower($newdidcid))) {
        $newdidcid = preg_replace("/[^0-9._XxNnZz\\[\\]\\-\\+]/", "", $newdidcid);
    }
    // Well more ugliness since the javascripts are already in here
    if ($newdid != '' || $newdidcid != '') {
        $existing = core_did_get($newdid, $newdidcid);
        if (!empty($existing)) {
            echo "<script>javascript:alert('" . sprintf(_("A route with this DID/CID: %s/%s already exists"), $existing['extension'], $existing['cidnum']) . "')</script>";
            return false;
        }
    }
    $sipname = preg_replace("/\\s/", "", trim($sipname));
    if (!core_sipname_check($sipname, $extension)) {
        echo "<script>javascript:alert('" . _("This sipname: {$sipname} is already in use") . "');</script>";
        return false;
    }
    //build the recording variable
    $recording = "out=" . $record_out . "|in=" . $record_in;
    //escape quotes and any other bad chars:
    if (!get_magic_quotes_gpc()) {
        $outboundcid = $db->escapeSimple($outboundcid);
        $name = $db->escapeSimple($name);
    }
    //if voicemail is enabled, set the box@context to use
    //havn't checked but why is voicemail needed on users anyway?  Doesn't exactly make it modular !
    if (function_exists('voicemail_mailbox_get')) {
        $vmbox = voicemail_mailbox_get($extension);
        if ($vmbox == null) {
            $voicemail = "novm";
        } else {
            $voicemail = $vmbox['vmcontext'];
        }
    }
    // Clean replace any <> with () in display name - should have javascript stopping this but ...
    //
    $name = preg_replace(array('/</', '/>/'), array('(', ')'), trim($name));
    //insert into users table
    $sql = "INSERT INTO users (extension,password,name,voicemail,ringtimer,noanswer,recording,outboundcid,sipname) values (\"";
    $sql .= "{$extension}\", \"";
    $sql .= isset($password) ? $password : '';
    $sql .= "\", \"";
    $sql .= isset($name) ? $name : '';
    $sql .= "\", \"";
    $sql .= isset($voicemail) ? $voicemail : 'default';
    $sql .= "\", \"";
    $sql .= isset($ringtimer) ? $ringtimer : '';
    $sql .= "\", \"";
    $sql .= isset($noanswer) ? $noanswer : '';
    $sql .= "\", \"";
    $sql .= isset($recording) ? $recording : '';
    $sql .= "\", \"";
    $sql .= isset($outboundcid) ? $outboundcid : '';
    $sql .= "\", \"";
    $sql .= isset($sipname) ? $sipname : '';
    $sql .= "\")";
    sql($sql);
    //write to astdb
    if ($astman) {
        $cid_masquerade = isset($cid_masquerade) && trim($cid_masquerade) != "" ? trim($cid_masquerade) : $extension;
        $astman->database_put("AMPUSER", $extension . "/password", isset($password) ? $password : '');
        $astman->database_put("AMPUSER", $extension . "/ringtimer", isset($ringtimer) ? $ringtimer : '');
        $astman->database_put("AMPUSER", $extension . "/noanswer", isset($noanswer) ? $noanswer : '');
        $astman->database_put("AMPUSER", $extension . "/recording", isset($recording) ? $recording : '');
        $astman->database_put("AMPUSER", $extension . "/outboundcid", isset($outboundcid) ? "\"" . $outboundcid . "\"" : '');
        $astman->database_put("AMPUSER", $extension . "/cidname", isset($name) ? "\"" . $name . "\"" : '');
        $astman->database_put("AMPUSER", $extension . "/cidnum", $cid_masquerade);
        $astman->database_put("AMPUSER", $extension . "/voicemail", "\"" . isset($voicemail) ? $voicemail : '' . "\"");
        switch ($call_screen) {
            case '0':
                $astman->database_del("AMPUSER", $extension . "/screen");
                break;
            case 'nomemory':
                $astman->database_put("AMPUSER", $extension . "/screen", "\"nomemory\"");
                break;
            case 'memory':
                $astman->database_put("AMPUSER", $extension . "/screen", "\"memory\"");
                break;
            default:
        }
        if (!$editmode) {
            $astman->database_put("AMPUSER", $extension . "/device", "\"" . (isset($device) ? $device : '') . "\"");
        }
        if (trim($callwaiting) == 'enabled') {
            $astman->database_put("CW", $extension, "\"ENABLED\"");
        } else {
            if (trim($callwaiting) == 'disabled') {
                $astman->database_del("CW", $extension);
            } else {
                echo "ERROR: this state should not exist<br>";
            }
        }
        if (trim($pinless) == 'enabled') {
            $astman->database_put("AMPUSER", $extension . "/pinless", "\"NOPASSWD\"");
        } else {
            if (trim($pinless) == 'disabled') {
                $astman->database_del("AMPUSER", $extension . "/pinless");
            } else {
                echo "ERROR: this state should not exist<br>";
            }
        }
        // Moved VmX setup to voicemail module since it is part of voicemail
        //
    } else {
        die_freepbx("Cannot connect to Asterisk Manager with " . $amp_conf["AMPMGRUSER"] . "/" . $amp_conf["AMPMGRPASS"]);
    }
    // OK - got this far, if they entered a new inbound DID/CID let's deal with it now
    // remember - in the nice and ugly world of this old code, $vars has been extracted
    // newdid and newdidcid
    // Now if $newdid is set we need to add the DID to the routes
    //
    if ($newdid != '' || $newdidcid != '') {
        $did_dest = 'from-did-direct,' . $extension . ',1';
        $did_vars['extension'] = $newdid;
        $did_vars['cidnum'] = $newdidcid;
        $did_vars['privacyman'] = '';
        $did_vars['alertinfo'] = '';
        $did_vars['ringing'] = '';
        $did_vars['mohclass'] = 'default';
        $did_vars['description'] = $newdid_name;
        $did_vars['grppre'] = '';
        $did_vars['delay_answer'] = '0';
        $did_vars['pricid'] = '';
        core_did_add($did_vars, $did_dest);
    }
    return true;
}
Example #6
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;
Example #7
0
 /**
  * @verb GET
  * @returns - a mailbox resource
  * @uri /voicemail/mailboxes/:id
  */
 function get_mailbox_id($params)
 {
     return voicemail_mailbox_get($params['id']);
 }