/**
  * function generate_module_repo_url
  * short create array of full URLs to get a file from repo
  * use this function to generate an array of URLs for all configured REPOs
  * @author Philippe Lindheimer
  *
  * @pram string
  * @returns string
  */
 function generate_remote_urls($path, $add_options = false)
 {
     global $db;
     global $amp_conf;
     $urls = array();
     $options = array();
     if ($add_options) {
         $firstinstall = false;
         $type = null;
         $sql = "SELECT * FROM module_xml WHERE id = 'installid'";
         $result = sql($sql, 'getRow', DB_FETCHMODE_ASSOC);
         // if not set so this is a first time install
         // get a new hash to account for first time install
         //
         $install_hash = $this->_generate_unique_id();
         $installid = $install_hash['uniqueid'];
         $type = $install_hash['type'];
         if (!isset($result['data']) || trim($result['data']) == "" || $installid != $result['data']) {
             //Yes they do the same thing but thats ok
             if (!isset($result['data']) || trim($result['data']) == "") {
                 $firstinstall = true;
                 $data4sql = $db->escapeSimple($installid);
                 sql("REPLACE INTO module_xml (id,time,data) VALUES ('installid'," . time() . ",'" . $data4sql . "')");
                 $data4sql = $db->escapeSimple($type);
                 sql("REPLACE INTO module_xml (id,time,data) VALUES ('type'," . time() . ",'" . $data4sql . "')");
             } else {
                 $install_hash = $this->_regenerate_unique_id();
                 $installid = $install_hash['uniqueid'];
                 $type = $install_hash['type'];
             }
         } else {
             $installid = $result['data'];
             $sql = "SELECT * FROM module_xml WHERE id = 'type'";
             $result = sql($sql, 'getRow', DB_FETCHMODE_ASSOC);
             if (isset($result['data']) && trim($result['data']) != "") {
                 $type = $result['data'];
             }
         }
         // Now we have the id and know if this is a firstime install so we can get the announcement
         //
         $options['installid'] = $installid;
         if (trim($type) != "") {
             $options['type'] = trim($type);
         }
         if ($firstinstall) {
             $options['firstinstall'] = 'yes';
         }
         //Now that we do everything in post format send back module versions
         $modules_local = $this->getinfo(false, false, true);
         foreach ($modules_local as $m => $mod) {
             if ($mod['status'] != MODULE_STATUS_BROKEN) {
                 $options['modules'][$m]['version'] = $mod['version'];
                 $options['modules'][$m]['status'] = $mod['status'];
                 $options['modules'][$m]['rawname'] = $mod['rawname'];
                 $options['modules'][$m]['license'] = !empty($mod['license']) ? $mod['license'] : "unknown";
             }
         }
         // We check specifically for false because evenif blank it means the file
         // was there so we want module.xml to do appropriate actions
         $brandid = $this->_brandid();
         if ($brandid !== false) {
             $options['brandid'] = $brandid;
         }
         $deploymentid = $this->_deploymentid();
         if ($deploymentid !== false) {
             $options['deploymentid'] = $deploymentid;
         }
         $engver = engine_getinfo();
         if ($engver['engine'] == 'asterisk' && trim($engver['engine']) != "") {
             $options['astver'] = $engver['version'];
         } else {
             $options['astver'] = $engver['raw'];
         }
         $options['phpver'] = phpversion();
         $distro_info = $this->_distro_id();
         $options['distro'] = $distro_info['pbx_type'];
         $options['distrover'] = $distro_info['pbx_version'];
         $options['pbxver'] = getversion();
         if (function_exists('core_users_list')) {
             $options['ucount'] = count(core_users_list());
         }
         // Other modules may need to add 'get' paramters to the call to the repo. Check and add them
         // here if we are adding paramters. The module should return an array of key/value pairs each of which
         // is to be appended to the GET parameters. The variable name will be prepended with the module name
         // when sent.
         //
         $repo_params = array();
         foreach (mod_func_iterator('module_repo_parameters_callback', $path) as $mod => $res) {
             if (is_array($res)) {
                 foreach ($res as $p => $v) {
                     $options[$mod . '_' . $p] = $v;
                 }
             }
         }
     }
     $repos = explode(',', $amp_conf['MODULE_REPO']);
     return array('mirrors' => $repos, 'path' => $path, 'options' => $options, 'query' => http_build_query($options));
 }
Example #2
0
         $cmd[] = $vars['restore'];
         $cmd[] = './' . $manifest['astdb'];
         exec(implode(' ', $cmd), $file);
         astdb_put(unserialize($file[0]), array('RINGGROUP', 'BLKVM', 'FM', 'dundi'));
         unset($cmd);
     }
     backup_log(_('Restoring Settings complete'));
 }
 //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)
Example #3
0
 function run_hooks($hook)
 {
     switch ($hook) {
         case 'pre-backup':
             if (isset($this->b['prebu_hook']) && $this->b['prebu_hook']) {
                 exec($this->b['prebu_hook']);
             }
             mod_func_iterator('backup_pre_backup_hook', $this);
             break;
         case 'post-backup':
             if (isset($this->b['postbu_hook']) && $this->b['postbu_hook']) {
                 exec($this->b['postbu_hook']);
             }
             mod_func_iterator('backup_post_backup_hook', $this);
             break;
     }
 }
/**
 * function generate_module_repo_url
 * short create array of full URLs to get a file from repo
 * use this function to generate an array of URLs for all configured REPOs
 * @author Philippe Lindheimer
 *
 * @pram string
 * @returns string
 */
function generate_module_repo_url($path, $add_options = false)
{
    global $db;
    global $amp_conf;
    $urls = array();
    if ($add_options) {
        $firstinstall = false;
        $type = null;
        $sql = "SELECT * FROM module_xml WHERE id = 'installid'";
        $result = sql($sql, 'getRow', DB_FETCHMODE_ASSOC);
        // if not set so this is a first time install
        // get a new hash to account for first time install
        //
        if (!isset($result['data']) || trim($result['data']) == "") {
            $firstinstall = true;
            $install_hash = _module_generate_unique_id();
            $installid = $install_hash['uniqueid'];
            $type = $install_hash['type'];
            // save the hash so we remeber this is a first time install
            //
            $data4sql = $db->escapeSimple($installid);
            sql("INSERT INTO module_xml (id,time,data) VALUES ('installid'," . time() . ",'" . $data4sql . "')");
            $data4sql = $db->escapeSimple($type);
            sql("INSERT INTO module_xml (id,time,data) VALUES ('type'," . time() . ",'" . $data4sql . "')");
            // Not a first time so save the queried hash and check if there is a type set
            //
        } else {
            $installid = $result['data'];
            $sql = "SELECT * FROM module_xml WHERE id = 'type'";
            $result = sql($sql, 'getRow', DB_FETCHMODE_ASSOC);
            if (isset($result['data']) && trim($result['data']) != "") {
                $type = $result['data'];
            }
        }
        // Now we have the id and know if this is a firstime install so we can get the announcement
        //
        $options = "?installid=" . urlencode($installid);
        if (trim($type) != "") {
            $options .= "&type=" . urlencode($type);
        }
        if ($firstinstall) {
            $options .= "&firstinstall=yes";
        }
        // We check specifically for false because evenif blank it means the file
        // was there so we want module.xml to do appropriate actions
        $brandid = _module_brandid();
        if ($brandid !== false) {
            $options .= "&brandid=" . urlencode($brandid);
        }
        $deploymentid = _module_deploymentid();
        if ($deploymentid !== false) {
            $options .= "&depolymentid=" . urlencode($deploymentid);
        }
        $engver = engine_getinfo();
        if ($engver['engine'] == 'asterisk' && trim($engver['engine']) != "") {
            $options .= "&astver=" . urlencode($engver['version']);
        } else {
            $options .= "&astver=" . urlencode($engver['raw']);
        }
        $options .= "&phpver=" . urlencode(phpversion());
        $distro_info = _module_distro_id();
        $options .= "&distro=" . urlencode($distro_info['pbx_type']);
        $options .= "&distrover=" . urlencode($distro_info['pbx_version']);
        $options .= "&fpbxver=" . urlencode(getversion());
        if (function_exists('core_users_list')) {
            $options .= "&ucount=" . urlencode(count(core_users_list()));
        }
        $path .= $options;
        // Other modules may need to add 'get' paramters to the call to the repo. Check and add them
        // here if we are adding paramters. The module should return an array of key/value pairs each of which
        // is to be appended to the GET parameters. The variable name will be prepended with the module name
        // when sent.
        //
        $repo_params = array();
        foreach (mod_func_iterator('module_repo_parameters_callback', $path) as $mod => $res) {
            if (is_array($res)) {
                foreach ($res as $p => $v) {
                    $path .= '&' . urlencode($mod) . '_' . urlencode($p) . '=' . urlencode($v);
                }
            }
        }
    }
    $repos = explode(',', $amp_conf['MODULE_REPO']);
    foreach ($repos as $repo) {
        $urls[] = $repo . $path;
    }
    return $urls;
}
function ivr_draw_entries($id, $restrict_mods = false)
{
    $headers = mod_func_iterator('draw_entries_table_header_ivr');
    $ivr_entries = ivr_get_entries($id);
    if ($ivr_entries) {
        foreach ($ivr_entries as $k => $e) {
            $entries[$k] = $e;
            $array = array('id' => $id, 'ext' => $e['selection']);
            $entries[$k]['hooks'] = mod_func_iterator('draw_entries_ivr', $array);
        }
    }
    $entries['blank'] = array('selection' => '', 'dest' => '', 'ivr_ret' => '');
    //assign to a vatriable first so that it can be passed by reference
    $array = array('id' => '', 'ext' => '');
    $entries['blank']['hooks'] = mod_func_iterator('draw_entries_ivr', $array);
    return load_view(dirname(__FILE__) . '/views/entries.php', array('headers' => $headers, 'entries' => $entries, 'restrict_mods' => $restrict_mods));
}
Example #6
0
/** Uninstall a module, but files remain
 * @param string   The name of the module to install
 * @param bool     If true, skips status and dependency checks
 * @return mixed   True if succesful, array of error messages if not succesful
 */
function module_uninstall($modulename, $force = false)
{
    global $db;
    global $amp_conf;
    $modules = module_getinfo($modulename);
    if (!isset($modules[$modulename])) {
        return array(_("Specified module not found"));
    }
    if (!$force) {
        if ($modules[$modulename]['status'] == MODULE_STATUS_NOTINSTALLED) {
            return array(_("Module not installed: cannot uninstall"));
        }
        if (($depmods = module_reversedepends($modulename)) !== false) {
            return array(_("Cannot disable: The following modules depend on this one: ") . implode(',', $depmods));
        }
    }
    // Check if another module wants this uninstall to be rejected
    // The module must have a callback: [modulename]_module_uninstall_check_callbak() that takes
    // a single modules array from module_getinfo() about the module to be uninstalled
    // and it must pass back boolean true if the uninstall can proceed, or a message
    // indicating why the uninstall must fail
    //
    $rejects = array();
    foreach (mod_func_iterator('module_uninstall_check_callback', $modules) as $mod => $res) {
        if ($res !== true) {
            $rejects[] = $res;
        }
    }
    if (!empty($rejects)) {
        return $rejects;
    }
    $sql = "DELETE FROM modules WHERE modulename = '" . $db->escapeSimple($modulename) . "'";
    $results = $db->query($sql);
    if (DB::IsError($results)) {
        return array(_("Error updating database: ") . $results->getMessage());
    }
    if (!_module_runscripts($modulename, 'uninstall', $modules)) {
        return array(_("Failed to run un-installation scripts"));
    }
    // Now make sure all feature codes are uninstalled in case the module has not already done it
    //
    require_once dirname(__FILE__) . '/featurecodes.class.php';
    //TODO: do we need this, now that we have bootstrap? -MB
    featurecodes_delModuleFeatures($modulename);
    $freepbx_conf =& freepbx_conf::create();
    $freepbx_conf->remove_module_settings($modulename);
    $mod_asset_dir = $amp_conf['AMPWEBROOT'] . "/admin/assets/" . $modulename;
    if (is_link($mod_asset_dir)) {
        @unlink($mod_asset_dir);
    }
    needreload();
    return true;
}
function directory_draw_entries_tr($id, $realid, $name = '', $foreign_name, $audio = '', $num = '', $e_id = '', $reuse_audio = false, $dataname = null)
{
    global $amp_conf, $directory_draw_recordings_list, $audio_select;
    if (!$directory_draw_recordings_list) {
        $directory_draw_recordings_list = recordings_list();
    }
    $e_id = $e_id ? $e_id : directory_get_next_id($realid);
    if (!$audio_select || !$reuse_audio) {
        unset($audio_select);
        $audio_select = '<select name="entries[' . $e_id . '][audio]" class="form-control">';
        $audio_select .= '<option value="vm" ' . ($audio == 'vm' ? 'SELECTED' : '') . '>' . _('Voicemail Greeting') . '</option>';
        $audio_select .= '<option value="tts" ' . ($audio == 'tts' ? 'SELECTED' : '') . '>' . _('Text to Speech') . '</option>';
        $audio_select .= '<option value="spell" ' . ($audio == 'spell' ? 'SELECTED' : '') . '>' . _('Spell Name') . '</option>';
        $audio_select .= '<optgroup label="' . _('System Recordings:') . '">';
        foreach ($directory_draw_recordings_list as $r) {
            $audio_select .= '<option value="' . $r['id'] . '" ' . ($audio == $r['id'] ? 'SELECTED' : '') . '>' . $r['displayname'] . '</option>';
        }
        $audio_select .= '</select>';
    }
    if ($realid != 'custom') {
        $user_type = (isset($amp_conf['AMPEXTENSION']) && $amp_conf['AMPEXTENSION']) == 'deviceanduser' ? 'user' : 'extension';
        $tlabel = sprintf(_("Edit %s: %s"), $user_type, $realid);
        $user = '******' . $user_type . 's&skip=0&extdisplay=' . $realid . '"><i class="fa fa-user"></i></a> ';
    } else {
        $user = '';
    }
    $delete = '<i alt="' . _('remove') . '" title="' . _('Click here to remove this entry') . '" class="trash-tr fa fa-trash" style="color:#2779aa;" data-name="' . $dataname . '"></i>';
    $t1_class = $name == '' ? ' class = "dpt-title form-control" ' : 'class="form-control"';
    $t2_class = $realid == 'custom' ? ' placeholder="Custom Dialstring" ' : ' placeholder="' . $realid . '" ';
    if (trim($num) == '') {
        $t2_class .= '" class = "dpt-title form-control" ';
    } else {
        $t2_class .= '" class = "form-control"';
    }
    $td[] = '<input type="hidden" readonly="readonly" name="entries[' . $e_id . '][foreign_id]" value="' . $realid . '" /><input type="text" name="entries[' . $e_id . '][name]" placeholder="' . $foreign_name . '"' . $t1_class . ' value="' . $name . '" />';
    $td[] = $audio_select;
    $td[] = '<input type="text" name="entries[' . $e_id . '][num]" ' . $t2_class . ' value="' . $num . '" />';
    $opts = array('id' => $id, 'e_id' => $e_id, 'realid' => $realid, 'name' => $name, 'audio' => $audio, 'num' => $num);
    $more_td = mod_func_iterator('draw_entries_tr_directory', $opts);
    foreach ($more_td as $mod) {
        foreach ($mod as $m) {
            $td[] = $m;
        }
    }
    $td[] = $delete . $user;
    //build html
    $html = '<tr class="entrie' . $e_id . '">';
    foreach ($td as $t) {
        if (is_array($t)) {
            $html .= '<td ' . $t['attr'] . '/>';
            $html .= $t['val'];
            $html .= '</td>';
        } else {
            $html .= '<td>' . $t . '</td>';
        }
    }
    $html .= '</tr>';
    return $html;
}
Example #8
0
function backup_get_template($id = '')
{
    global $db;
    //return a blank if no id was set, all templates if 'all' was passed
    //otherwise, a specifc template
    switch ($id) {
        case '':
            return array('id' => '', 'name' => '', 'data' => array(), 'desc' => '', 'items' => array(), 'immortal' => '');
            break;
        case 'all':
        case 'all_detailed':
            $templates = array();
            $ret = sql('SELECT * FROM backup_templates ORDER BY name', 'getAll', DB_FETCHMODE_ASSOC);
            //get hooks from other modules
            $hook_temps = mod_func_iterator('hook_backup_get_template');
            //sanatizes hooks and push them in to the stack
            foreach ($hook_temps as $mod => $template) {
                foreach ($template as $my => $temp) {
                    $ret[] = backup_template_sanitize($temp, $mod);
                }
            }
            //sanatize/argument templates
            foreach ($ret as $temp) {
                if ($id == 'all_detailed') {
                    //backup_get_template() dose its own sanatization
                    $templates[$temp['id']] = backup_get_template($temp['id']);
                } else {
                    $templates[$temp['id']] = backup_template_sanitize($temp);
                }
            }
            //this ugliness is here pending requiring php-53
            //to migrate, just copy the functions in place of the string of same name
            function _anon_func1($val)
            {
                return $val;
            }
            function _anon_func2($a, $b)
            {
                if ($a['name'] == $b['name']) {
                    return 0;
                } else {
                    return $a['name'] > $b['name'] ? 1 : -1;
                }
            }
            //remove any false values (templates that didnt pass sanitization)
            $templates = array_filter($templates, '_anon_func1');
            //sort templaes based on template name
            uasort($templates, '_anon_func2');
            return $templates;
            break;
        default:
            //if the id is preceded by a module name, ask that module for the details
            if (strpos($id, '-') !== false) {
                //get data by breaking up backup id
                list($mod, $id) = explode('-', $id);
                //return template data if $mod's function exsists
                if (function_exists($mod . '_hook_backup_get_template')) {
                    return backup_template_sanitize(call_user_func($mod . '_hook_backup_get_template', $id), $mod);
                }
            }
            $sql = 'SELECT * FROM backup_templates WHERE id = ?';
            $ret = $db->getAll($sql, array($id), DB_FETCHMODE_ASSOC);
            if ($db->IsError($ret)) {
                die_freepbx($ret->getDebugInfo());
            }
            //return a blank set if an invalid id was entered
            if (!$ret) {
                return backup_get_template('');
            }
            $ret = $ret[0];
            $sql = 'SELECT type, path, exclude FROM backup_template_details WHERE template_id = ?';
            $ret1 = $db->getAll($sql, array($id), DB_FETCHMODE_ASSOC);
            if ($db->IsError($ret1)) {
                die_freepbx($ret1->getDebugInfo());
            }
            if ($ret1) {
                foreach ($ret1 as $res) {
                    foreach ($res as $key => $value) {
                        $my[$key] = $value;
                    }
                    if ($my['exclude']) {
                        $my['exclude'] = unserialize($my['exclude']);
                    }
                    $ret['items'][] = $my;
                    unset($my);
                }
            } else {
                $ret['items'] = array();
            }
            $ret = backup_template_sanitize($ret);
            return $ret;
            break;
    }
}