Exemplo n.º 1
0
 public function getOOBEModules()
 {
     $mods = module_functions::create();
     $i = $mods->getinfo(false, array(MODULE_STATUS_ENABLED), true);
     // Make sure framework always runs.
     $tmparr = array("framework" => 10);
     foreach ($i as $modname => $arr) {
         if (!isset($arr['oobe'])) {
             continue;
         }
         // We've found a module with OOBE hooks!
         $xml = \FreePBX::Modules()->getXML($modname);
         if (!$xml->oobe->attributes()->priority) {
             $priority = 100;
         } else {
             $priority = (int) $xml->oobe->attributes()->priority;
         }
         $tmparr[$modname] = $priority;
     }
     // Sort the list of found hooks by priority.
     asort($tmparr);
     // And add them to $retarr
     $retarr = array();
     foreach ($tmparr as $modname => $null) {
         $xml = \FreePBX::Modules()->getXML($modname);
         $retarr[$modname] = (string) $xml->name;
     }
     return $retarr;
 }
Exemplo n.º 2
0
function module_set_active_repos($repos)
{
    _module_backtrace();
    $modulef = module_functions::create();
    foreach ($repos as $repo => $status) {
        $modulef->set_active_repo($repo, $status);
    }
}
Exemplo n.º 3
0
 public function __construct($freepbx = null)
 {
     if ($freepbx == null) {
         throw new Exception("Need to be instantiated with a FreePBX Object");
     }
     $this->FreePBX = $freepbx;
     if (!class_exists('module_functions')) {
         throw new Exception("module_functions class missing? Bootstrap not run?");
     }
     $this->modclass = module_functions::create();
     $this->getActiveModules();
 }
Exemplo n.º 4
0
    require $dirname . '/libraries/gui_auth.php';
    frameworkPasswordCheck();
}
if (!isset($no_auth) && !defined('FREEPBX_IS_AUTH')) {
    die('No direct script access allowed');
}
//we should never need this, just another line of defence
bootstrap_include_hooks('pre_module_load', 'all_mods');
$bootstrap_settings['function_modules_included'] = false;
$restrict_mods_local = $restrict_mods;
//I'm pretty sure if this is == true then there is no need to even pull all
//the module info as we are going down a path such as an ajax path that this
//is just overhead. (We'll know soon enough if this is too restrcitive).
if ($restrict_mods_local !== true) {
    $isauth = !isset($no_auth);
    $modulef =& module_functions::create();
    $active_modules = $modulef->getinfo(false, MODULE_STATUS_ENABLED);
    $modpath = $amp_conf['AMPWEBROOT'] . '/admin/modules/';
    if (is_array($active_modules)) {
        $force_autoload = false;
        foreach ($active_modules as $key => $module) {
            //check if this module was was excluded
            $is_selected = is_array($restrict_mods_local) && isset($restrict_mods_local[$key]);
            //get file path
            $file = $modpath . $key . '/functions.inc.php';
            $file_exists = is_file($file);
            //check authentication, skip this module if we dont have auth
            $needs_auth = isset($module['requires_auth']) && $module['requires_auth'] == 'false' ? false : true;
            if (!$isauth && $needs_auth) {
                continue;
            }
Exemplo n.º 5
0
 /**
  * Generate UCP assets if needed
  * @param {bool} $regenassets = false If set to true regenerate assets even if not needed
  */
 public function generateUCP($regenassets = false)
 {
     $modulef =& module_functions::create();
     $modules = $modulef->getinfo(false);
     $path = $this->FreePBX->Config->get_conf_setting('AMPWEBROOT');
     $location = $path . '/ucp';
     if (!file_exists($location)) {
         symlink(dirname(__FILE__) . '/htdocs', $location);
     }
     foreach ($modules as $module) {
         if (isset($module['rawname'])) {
             $rawname = trim($module['rawname']);
             if (file_exists($path . '/admin/modules/' . $rawname . '/ucp') && file_exists($path . '/admin/modules/' . $rawname . '/ucp/' . ucfirst($rawname) . ".class.php")) {
                 if ($module['status'] == MODULE_STATUS_ENABLED) {
                     if (!file_exists($location . "/modules/" . ucfirst($rawname))) {
                         symlink($path . '/admin/modules/' . $rawname . '/ucp', $location . '/modules/' . ucfirst($rawname));
                     }
                 } elseif ($module['status'] != MODULE_STATUS_DISABLED && $module['status'] != MODULE_STATUS_ENABLED) {
                     if (file_exists($location . "/modules/" . ucfirst($rawname)) && is_link($location . "/modules/" . ucfirst($rawname))) {
                         unlink($location . "/modules/" . ucfirst($rawname));
                     }
                 }
             }
         }
     }
     if ($regenassets) {
         $this->refreshAssets();
     }
 }
Exemplo n.º 6
0
function displayRepoSelect($buttons, $online = false, $repo_list = array())
{
    global $display, $online, $tabindex;
    $modulef = module_functions::create();
    $displayvars = array("display" => $display, "online" => $online, "tabindex" => $tabindex, "repo_list" => $repo_list, "active_repos" => $modulef->get_active_repos());
    $button_display = '';
    $href = "config.php?display={$display}";
    $button_template = '<input type="button" value="%s" onclick="location.href=\'%s\';" />' . "\n";
    $displayvars['button_display'] = '';
    foreach ($buttons as $button) {
        switch ($button) {
            case 'local':
                $displayvars['button_display'] .= sprintf($button_template, _("Manage local modules"), $href);
                break;
            case 'upload':
                $displayvars['button_display'] .= sprintf($button_template, _("Upload modules"), $href . '&action=upload');
                break;
        }
    }
    $brand = \FreePBX::Config()->get("DASHBOARD_FREEPBX_BRAND");
    $displayvars['tooltip'] = _("Choose the repositories that you want to check for new modules. Any updates available for modules you have on your system will be detected even if the repository is not checked. If you are installing a new system, you may want to start with the Basic repository and update all modules, then go back and review the others.") . ' ';
    $displayvars['tooltip'] .= sprintf(_(" The modules in the Extended repository are less common and may receive lower levels of support. The Unsupported repository has modules that are not supported by the %s team but may receive some level of support by the authors."), $brand) . ' ';
    $displayvars['tooltip'] .= _("The Commercial repository is reserved for modules that are available for purchase and commercially supported.") . ' ';
    $displayvars['tooltip'] .= '<br /><br /><small><i>(' . sprintf(_("Checking for updates will transmit your %s, Distro, Asterisk and PHP version numbers along with a unique but random identifier. This is used to provide proper update information and track version usage to focus development and maintenance efforts. No private information is transmitted."), $brand) . ')</i></small>';
    return load_view('views/module_admin/reposelect.php', $displayvars);
}
Exemplo n.º 7
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->mf = \module_functions::create();
     $this->out = $output;
     $this->input = $input;
     $args = $input->getArgument('args');
     if ($input->getOption('debug')) {
         $this->DEBUG = True;
     } else {
         $this->DEBUG = False;
     }
     switch ($input->getOption('format')) {
         case "jsonpretty":
             $this->pretty = true;
             $this->format = 'json';
             break;
         case "json":
             $this->format = 'json';
             break;
         default:
             $this->format = 'plain';
             break;
     }
     if ($input->getOption('force')) {
         $this->force = True;
         if ($this->DEBUG) {
             $this->writeln(_('Force Enabled'));
         }
     } else {
         $this->force = False;
         if ($this->DEBUG) {
             $this->writeln(_('Force Disabled'));
         }
     }
     $repos = $input->getOption('repo');
     if ($repos) {
         $this->write(_("Getting Remote Repo list..."));
         $remotes = $this->mf->get_remote_repos(true);
         $this->writeln(_("Done"));
         $local = $this->mf->get_active_repos();
         foreach ($repos as $repo) {
             if (in_array($repo, $remotes)) {
                 $this->setRepos = true;
                 if (!in_array($repo, array_keys($local))) {
                     $this->writeln("Enabling repo: [{$repo}]");
                     $this->mf->set_active_repo($repo);
                 }
             } else {
                 $this->writeln("No such repo: [{$repo}], skipping");
             }
         }
     }
     if (!empty($args)) {
         if ($this->DEBUG) {
             print_r($args);
         }
         $this->handleArgs($args);
     } else {
         $this->writeln($this->showHelp());
     }
 }
Exemplo n.º 8
0
/**
 * Helper function to laod hooks for bootstrap_include_hooks()
 */
function _bootstrap_parse_hooks()
{
    $hooks = array();
    $modulef = module_functions::create();
    $modules = $modulef->getinfo(false, MODULE_STATUS_ENABLED);
    foreach ($modules as $mymod => $mod) {
        if (isset($mod['bootstrap_hooks'])) {
            foreach ($mod['bootstrap_hooks'] as $type => $type_mods) {
                switch ($type) {
                    case 'pre_module_load':
                    case 'post_module_load':
                        //first get all_mods
                        if (isset($type_mods['all_mods'])) {
                            $hooks[$type]['all_mods'] = isset($hooks[$type]['all_mods']) ? array_merge($hooks[$type]['all_mods'], (array) $type_mods['all_mods']) : (array) $type_mods['all_mods'];
                            unset($type_mods['all_mods']);
                        }
                        if (!isset($type_mods)) {
                            break;
                            //break if there are no more hooks to include
                        }
                        //now load all remaining modules
                        foreach ($type_mods as $type_mod) {
                            $hooks[$type][$mymod] = isset($hooks[$type][$mymod]) ? array_merge($hooks[$type][$mymod], (array) $type_mod) : (array) $type_mod;
                        }
                        break;
                    default:
                        break;
                }
            }
        }
    }
    return $hooks;
}
Exemplo n.º 9
0
 } else {
     if (file_exists($module_file) && class_exists('\\Schmooze\\Zend') && \Schmooze\Zend::fileIsLicensed($module_file) && $complete_zend) {
         $amp_conf['VIEW_ZEND_CONFIG'] = empty($amp_conf['VIEW_ZEND_CONFIG']) ? 'views/zend_config.php' : $amp_conf['VIEW_ZEND_CONFIG'];
         if (file_exists($amp_conf['VIEW_ZEND_CONFIG'])) {
             echo load_view($amp_conf['VIEW_ZEND_CONFIG']);
         } else {
             die_freepbx(_("Your Zend Configuration is not fully setup. Please recitfy the problem and reload this page"));
         }
     } else {
         if (file_exists($module_file)) {
             //check module first and foremost, but not during quietmode
             if (!isset($_REQUEST['quietmode']) && $amp_conf['SIGNATURECHECK'] && !isset($_REQUEST['fw_popover'])) {
                 //Since we are viewing this module update it's signature
                 $gpgstatus = module_functions::create()->updateSignature($module_name, false);
                 //check all cached signatures
                 $modules = module_functions::create()->getAllSignatures();
                 if (!$modules['validation']) {
                     //$type = (!empty($modules['statuses']['untrusted']) || !empty($modules['statuses']['tampered'])) ? 'danger' : 'warning';
                     $danger = array();
                     $warning = array();
                     //priority sorting
                     $stauses = array("revoked", "untrusted", "tampered", "unsigned", "unknown");
                     foreach ($stauses as $st) {
                         if (!empty($modules['statuses'][$st]) && $st != 'unsigned') {
                             $danger = array_merge($danger, $modules['statuses'][$st]);
                         } else {
                             if (!empty($modules['statuses'][$st]) && $st == 'unsigned') {
                                 $warning = array_merge($warning, $modules['statuses'][$st]);
                             }
                         }
                     }
Exemplo n.º 10
0
 /**
  * Retrieve a remote file
  * Stores file into memory
  * @param  string $path The full path to said file
  * @return string       binary representation of file
  */
 private function getRemoteFile($path)
 {
     $modulef =& \module_functions::create();
     $contents = null;
     $mirrors = $modulef->generate_remote_urls($path, true);
     $params = $mirrors['options'];
     $params['sv'] = 2;
     foreach ($mirrors['mirrors'] as $url) {
         set_time_limit($this->maxTimeLimit);
         try {
             $pest = \FreePBX::Curl()->pest($url);
             $contents = $pest->post($url . $path, $params);
             if (isset($pest->last_headers['x-regenerate-id'])) {
                 $modulef->_regenerate_unique_id();
             }
             if (!empty($contents)) {
                 return $contents;
             }
         } catch (\Exception $e) {
             freepbx_log(FPBX_LOG_ERROR, sprintf(_('Failed to get remote file, error was:'), (string) $e->getMessage()));
         }
     }
 }
Exemplo n.º 11
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $args = $input->getArgument('args');
     $command = isset($args[0]) ? $args[0] : '';
     switch ($command) {
         case 'cleanplaybackcache':
             $output->writeln(_("Starting Cache cleanup"));
             $days = \FreePBX::Config()->get("CACHE_CLEANUP_DAYS");
             $time = $days * 24 * 60 * 60;
             $path = \FreePBX::Config()->get("AMPPLAYBACK");
             $path = trim($path);
             $user = \FreePBX::Config()->get("AMPASTERISKWEBUSER");
             $formats = \FreePBX::Media()->getSupportedHTML5Formats();
             if (empty($path) || $path == "/") {
                 $output->writeln("<error>" . sprintf(_("Invalid path %s"), $path) . "</error>");
                 exit(1);
             }
             if (file_exists($path)) {
                 foreach (new \DirectoryIterator($path) as $fileInfo) {
                     if ($fileInfo->isDot()) {
                         continue;
                     }
                     $info = posix_getpwuid($fileInfo->getOwner());
                     if ($info['name'] != $user) {
                         continue;
                     }
                     $extension = pathinfo($fileInfo->getFilename(), PATHINFO_EXTENSION);
                     if ($fileInfo->isFile() && in_array($extension, $formats) && time() - $fileInfo->getCTime() >= $time) {
                         $output->writeln(sprintf(_("Removing file %s"), basename($fileInfo->getRealPath())));
                         unlink($fileInfo->getRealPath());
                     }
                 }
             }
             $output->writeln(_("Finished cleaning up cache"));
             break;
         case 'signaturecheck':
             \module_functions::create()->getAllSignatures(false, true);
             break;
         case 'tablefix':
             if (posix_geteuid() != 0) {
                 $output->writeln("<error>You need to be root to run this command</error>");
                 exit(1);
             }
             $process = new Process('mysqlcheck --repair --all-databases');
             try {
                 $output->writeln(_("Attempting to repair MySQL Tables this may take a while"));
                 $process->mustRun();
                 $output->writeln(_("MySQL Tables Repaired"));
             } catch (ProcessFailedException $e) {
                 $output->writeln(sprintf(_("MySQL table repair Failed: %s"), $e->getMessage()));
             }
             break;
         case "zendid":
             $output->writeln("===========================");
             foreach (zend_get_id() as $id) {
                 $output->writeln($id);
             }
             $output->writeln("===========================");
             break;
         default:
             $output->writeln('Invalid argument');
             break;
     }
 }
Exemplo n.º 12
0
    // RHEL / CentOS
    $data = @parse_ini_file('/etc/sysconfig/clock');
    if (!empty($data['ZONE'])) {
        $timezone = trim($data['ZONE']);
    }
}
$set['category'] = 'System Setup';
$set['value'] = !empty($timezone) ? $timezone : "UTC";
$set['defaultval'] = 'UTC';
$set['name'] = 'PHP Timezone';
$set['description'] = "Timezone that should be used by PHP. Empty value will use PHP defaults. List of value Timezones: <a href='http://php.net/manual/en/timezones.php'>http://php.net/manual/en/timezones.php</a>";
$set['hidden'] = 0;
$set['emptyok'] = 1;
$set['readonly'] = 0;
$set['level'] = 0;
$set['options'] = \DateTimeZone::listIdentifiers();
$set['module'] = '';
$set['type'] = CONF_TYPE_CSELECT;
$freepbx_conf->define_conf_setting('PHPTIMEZONE', $set);
$freepbx_conf->commit_conf_settings();
$mf = \module_functions::create();
$info = $mf->getinfo("core");
if (!empty($info['core']['dbversion']) && version_compare_freepbx($info['core']['dbversion'], "13.0.45", "<=")) {
    outn(_("Migrating force_rport to the right default value..."));
    $res = $db->query("UPDATE sip SET data = 'yes' WHERE keyword = 'force_rport'");
    if (!DB::IsError($res)) {
        out(_("done"));
    } else {
        out(_("error occured"));
    }
}
Exemplo n.º 13
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->mf = \module_functions::create();
     $this->out = $output;
     $this->input = $input;
     $this->colot = false;
     $args = $input->getArgument('args');
     if ($input->getOption('skipchown')) {
         $this->skipchown = true;
     }
     if ($input->getOption('color')) {
         $this->color = true;
     }
     if ($input->getOption('edge')) {
         $this->writeln('<info>' . _('Edge repository temporarily enabled') . '</info>');
         $this->previousEdge = \FreePBX::Config()->get('MODULEADMINEDGE');
         \FreePBX::Config()->update('MODULEADMINEDGE', 1);
     }
     if ($input->getOption('debug')) {
         $this->DEBUG = True;
     } else {
         $this->DEBUG = False;
     }
     switch ($input->getOption('format')) {
         case "jsonpretty":
             $this->pretty = true;
             $this->format = 'json';
             break;
         case "json":
             $this->format = 'json';
             break;
         default:
             $this->format = 'plain';
             break;
     }
     if ($input->getOption('force')) {
         $this->force = True;
         if ($this->DEBUG) {
             $this->writeln(_('Force Enabled'));
         }
     } else {
         $this->force = False;
         if ($this->DEBUG) {
             $this->writeln(_('Force Disabled'));
         }
     }
     $repos = $input->getOption('repo');
     if ($repos) {
         $this->write(_("Getting Remote Repo list..."));
         $remotes = $this->mf->get_remote_repos(true);
         $this->writeln(_("Done"));
         $local = $this->mf->get_active_repos();
         foreach ($repos as $repo) {
             if (in_array($repo, $remotes)) {
                 $this->setRepos = true;
                 if (!in_array($repo, array_keys($local))) {
                     $this->writeln("Enabling repo: [{$repo}]");
                     $this->mf->set_active_repo($repo);
                 }
             } else {
                 $this->writeln("No such repo: [{$repo}], skipping");
             }
         }
     }
     if (!empty($args)) {
         if ($this->DEBUG) {
             print_r($args);
         }
         $this->handleArgs($args);
     } else {
         $this->writeln($this->showHelp());
     }
     if ($input->getOption('edge')) {
         \FreePBX::Config()->update('MODULEADMINEDGE', $this->previousEdge);
     }
 }