示例#1
0
function core_devices_configprocess()
{
    if (!class_exists('agi_asteriskmanager')) {
        include 'common/php-asmanager.php';
    }
    //make sure we can connect to Asterisk Manager
    if (!checkAstMan()) {
        return false;
    }
    //create vars from the request
    $tech = $action = null;
    extract($_REQUEST);
    if ($tech == "virtual" || $action == "edit" && $tech == '') {
        return true;
    }
    $extension = isset($extension) ? $extension : null;
    $deviceid = isset($deviceid) ? $deviceid : null;
    $name = isset($name) ? $name : null;
    $action = isset($action) ? $action : null;
    // fixed users only in extensions mode
    if ($display == 'extensions') {
        $devicetype = 'fixed';
        $deviceid = $deviceuser = $extension;
        $description = $name;
    }
    //if submitting form, update database
    switch ($action) {
        case "add":
            // really bad hack - but if core_users_add fails, want to stop core_devices_add
            if (!isset($GLOBALS['abort']) || $GLOBALS['abort'] !== true || !$_SESSION["AMP_user"]->checkSection('999')) {
                if (core_devices_add($deviceid, $tech, $devinfo_dial, $devicetype, $deviceuser, $description, $emergency_cid)) {
                    needreload();
                    if ($deviceuser != 'new') {
                        redirect_standard_continue();
                    }
                }
            } else {
                // This is a bit messy, because by this time, other modules may have added the device but this tries to block
                // the user who does not have add permission from adding a new extension.
                //
                $GLOBALS['abort'] = true;
            }
            break;
        case "del":
            core_devices_del($extdisplay);
            needreload();
            redirect_standard_continue();
            break;
        case "edit":
            //just delete and re-add
            // really bad hack - but if core_users_edit fails, want to stop core_devices_edit
            if (!isset($GLOBALS['abort']) || $GLOBALS['abort'] !== true) {
                core_devices_del($extdisplay, true);
                core_devices_add($deviceid, $tech, $devinfo_dial, $devicetype, $deviceuser, $description, $emergency_cid, true);
                needreload();
                redirect_standard_continue('extdisplay');
            }
            break;
        case "resetall":
            //form a url with this option to nuke the AMPUSER & DEVICE trees and start over.
            core_users2astdb();
            core_devices2astdb();
            break;
    }
    return true;
}
示例#2
0
function core_devices_configprocess()
{
    if (!class_exists('agi_asteriskmanager')) {
        include 'common/php-asmanager.php';
    }
    //make sure we can connect to Asterisk Manager
    if (!checkAstMan()) {
        return false;
    }
    //create vars from the request
    $tech = $action = null;
    extract($_REQUEST);
    if ($tech == "virtual" || $action == "edit" && $tech == '') {
        return true;
    }
    $extension = isset($extension) ? $extension : null;
    $deviceid = isset($deviceid) ? $deviceid : null;
    $name = isset($name) ? $name : null;
    $action = isset($action) ? $action : null;
    // fixed users only in extensions mode
    if ($display == 'extensions') {
        $devicetype = 'fixed';
        $deviceid = $deviceuser = $extension;
        $description = $name;
    }
    //if submitting form, update database
    switch ($action) {
        case "add":
            // really bad hack - but if core_users_add fails, want to stop core_devices_add
            if (!isset($GLOBALS['abort']) || $GLOBALS['abort'] !== true || !$_SESSION["AMP_user"]->checkSection('999')) {
                if (core_devices_add($deviceid, $tech, $devinfo_dial, $devicetype, $deviceuser, $description, $emergency_cid)) {
                    needreload();
                    if ($deviceuser == 'new') {
                        //redirect_standard_continue();
                    }
                }
            } else {
                // This is a bit messy, because by this time, other modules may have added the device but this tries to block
                // the user who does not have add permission from adding a new extension.
                //
                $GLOBALS['abort'] = true;
            }
            break;
        case "del":
            core_devices_del($extdisplay);
            //$_REQUEST['exdisplay'] = isset($_REQUEST['exdisplay'])?NULL:'';
            //$_REQUEST['action'] = isset($_REQUEST['action'])?NULL:'';
            needreload();
            redirect_standard_continue();
            break;
        case "edit":
            //just delete and re-add
            // really bad hack - but if core_users_edit fails, want to stop core_devices_edit
            if (!isset($GLOBALS['abort']) || $GLOBALS['abort'] !== true) {
                //delete then re add, insanity.
                core_devices_del($extdisplay, true);
                //PJSIP <--> CHAN_SIP Switcher, not the best but better than it was before and lets us continue forward into PHP 5.5
                if (isset($_REQUEST['changesipdriver']) && !empty($_REQUEST['devinfo_sipdriver']) && ($tech == 'pjsip' || $tech == 'sip')) {
                    $tech = $_REQUEST['devinfo_sipdriver'] == 'chan_sip' ? 'sip' : 'pjsip';
                    $rtech = $_REQUEST['devinfo_sipdriver'] == 'chan_sip' ? 'pjsip' : 'sip';
                    $devinfo_dial = preg_replace('/^' . $rtech . '\\/' . $deviceid . '$/i', strtoupper($tech) . '/' . $deviceid, $devinfo_dial);
                    $flag = 2;
                    $fields = FreePBX::Core()->convertRequest2Array($deviceid, $tech, $flag);
                    $settings = array("dial" => array("value" => $devinfo_dial, "flag" => isset($fields['dial']['flag']) ? $fields['dial']['flag'] : $flag++), "devicetype" => array("value" => $devicetype, "flag" => isset($fields['devicetype']['flag']) ? $fields['devicetype']['flag'] : $flag++), "user" => array("value" => $deviceuser, "flag" => isset($fields['deviceuser']['flag']) ? $fields['deviceuser']['flag'] : $flag++), "description" => array("value" => $description, "flag" => isset($fields['description']['flag']) ? $fields['description']['flag'] : $flag++), "emergency_cid" => array("value" => $emergency_cid, "flag" => isset($fields['emergency_cid']['flag']) ? $fields['emergency_cid']['flag'] : $flag++));
                    $settings = array_merge($fields, $settings);
                    return FreePBX::Core()->addDevice($deviceid, $tech, $settings, true);
                } else {
                    core_devices_add($deviceid, $tech, $devinfo_dial, $devicetype, $deviceuser, $description, $emergency_cid, true);
                }
                needreload();
                //redirect_standard_continue('extdisplay');
            }
            break;
        case "resetall":
            //form a url with this option to nuke the AMPUSER & DEVICE trees and start over.
            core_users2astdb();
            core_devices2astdb();
            break;
    }
    return true;
}
示例#3
0
if (in_array('addext', $actions)) {
    $actions_taken = true;
    debug("core_devices_add({$ext}, {$tech}, '', 'fixed', {$ext}, {$displayname}, {$emergencycid})");
    $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");