Example #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);
            //$_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;
}
Example #2
0
 }
 //dbug($file);
 //run hooks
 if (isset($manifest['hooks']['post_restore']) && $manifest['hooks']['post_restore']) {
     backup_log(_('Running post restore script...'));
     exec($manifest['hooks']['post_restore']);
 }
 backup_log(_('Running post-restore hooks, if any...'));
 mod_func_iterator('backup_post_restore_hook', $manifest);
 //ensure that manager username and password are whatever we think they should be
 //the DB is authoritative, fetch whatever we have set there
 backup_log(_('Cleaning up...'));
 $freepbx_conf =& freepbx_conf::create();
 fpbx_ami_update($freepbx_conf->get_conf_setting('AMPMGRUSER', true), $freepbx_conf->get_conf_setting('AMPMGRPASS', true));
 // Update AstDB
 core_users2astdb();
 core_devices2astdb();
 needreload();
 //delete backup file if it was a temp file
 if (dirname($vars['restore']) == $amp_conf['ASTSPOOLDIR'] . '/tmp/') {
     unlink($vars['restore']);
 }
 /*
  * cleanup stale backup files (older than one day)
  * usually, backups will be deleted after a restore
  * However, files that were downloaded from a remote server and
  * the user aborted the restore should be cleaned up here
  */
 $files = scandir($amp_conf['ASTSPOOLDIR'] . '/tmp/');
 foreach ($files as $file) {
     $f = explode('-', $file);
Example #3
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;
}