$confs = $db_cdr->getRow($sql, DB_FETCHMODE_ASSOC);
outn(_("checking if recordingfile file field needed in cdr.."));
if (DB::IsError($confs)) {
// no error... Already done
$sql = "ALTER TABLE cdr ADD recordingfile VARCHAR ( 255 ) NOT NULL default ''";
$results = $db_cdr->query($sql);
if (DB::IsError($results)) {
out(_("failed"));
freepbx_log(FPBX_LOG_ERROR, "failed to add recordingfile field to cdr table during migration");
}
out(_("added"));
} else {
out(_("already there"));
}
$sql = "SELECT did FROM cdr";
$confs = $db_cdr->getRow($sql, DB_FETCHMODE_ASSOC);
outn(_("checking if did file field needed in cdr.."));
if (DB::IsError($confs)) {
// no error... Already done
$sql = "ALTER TABLE cdr ADD did VARCHAR ( 50 ) NOT NULL default ''";
$results = $db_cdr->query($sql);
if (DB::IsError($results)) {
out(_("failed"));
freepbx_log(FPBX_LOG_ERROR, "failed to add did field to cdr table during migration");
}
out(_("added"));
} else {
out(_("already there"));
}
}
}
//connect to cdrdb if requestes
if ($bootstrap_settings['cdrdb']) {
$dsn = array('phptype' => $amp_conf['CDRDBTYPE'] ? $amp_conf['CDRDBTYPE'] : $amp_conf['AMPDBENGINE'], 'hostspec' => $amp_conf['CDRDBHOST'] ? $amp_conf['CDRDBHOST'] : $amp_conf['AMPDBHOST'], 'username' => $amp_conf['CDRDBUSER'] ? $amp_conf['CDRDBUSER'] : $amp_conf['AMPDBUSER'], 'password' => $amp_conf['CDRDBPASS'] ? $amp_conf['CDRDBPASS'] : $amp_conf['AMPDBPASS'], 'port' => $amp_conf['CDRDBPORT'] ? $amp_conf['CDRDBPORT'] : '3306', 'database' => $amp_conf['CDRDBNAME'] ? $amp_conf['CDRDBNAME'] : 'asteriskcdrdb');
$cdrdb = DB::connect($dsn);
}
$bootstrap_settings['astman_connected'] = false;
if (!$bootstrap_settings['skip_astman']) {
require_once $dirname . '/libraries/php-asmanager.php';
$astman = new AGI_AsteriskManager($bootstrap_settings['astman_config'], $bootstrap_settings['astman_options']);
// attempt to connect to asterisk manager proxy
if (!$amp_conf["ASTMANAGERPROXYPORT"] || !($res = $astman->connect($amp_conf["ASTMANAGERHOST"] . ":" . $amp_conf["ASTMANAGERPROXYPORT"], $amp_conf["AMPMGRUSER"], $amp_conf["AMPMGRPASS"], $bootstrap_settings['astman_events']))) {
// attempt to connect directly to asterisk, if no proxy or if proxy failed
if (!($res = $astman->connect($amp_conf["ASTMANAGERHOST"] . ":" . $amp_conf["ASTMANAGERPORT"], $amp_conf["AMPMGRUSER"], $amp_conf["AMPMGRPASS"], $bootstrap_settings['astman_events']))) {
// couldn't connect at all
unset($astman);
freepbx_log(FPBX_LOG_CRITICAL, "Connection attmempt to AMI failed");
} else {
$bootstrap_settings['astman_connected'] = true;
}
}
} else {
$bootstrap_settings['astman_connected'] = true;
}
//Because BMO was moved upward we have to inject this lower
if (isset($astman)) {
FreePBX::create()->astman = $astman;
}
//include gui functions + auth if nesesarry
// If set to freepbx_auth but we are in a cli mode, then don't bother authenticating either way.
// TODO: is it ever possible through an apache or httplite configuration to run a web launched php script
// as 'cli' ? Also, from a security perspective, should we just require this always be set to false
$result = $db->query($sql);
if (DB::IsError($result)) {
out(_("Unable to add index to tech field in devices"));
freepbx_log(FPBX_LOG_ERROR, "Failed to add index to tech field in the devices table");
} else {
out(_("Adding index to tech field in the devices"));
}
}
$sql = "SHOW KEYS FROM users WHERE Key_name='extension'";
$check = $db->getOne($sql);
if (empty($check)) {
$sql = "ALTER TABLE users ADD KEY `extension` (`extension`)";
$result = $db->query($sql);
if (DB::IsError($result)) {
out(_("Unable to add index to extensions field in users"));
freepbx_log(FPBX_LOG_ERROR, "Failed to add index to extensions field in the users table");
} else {
out(_("Adding index to extensions field in the users"));
}
}
// The following are from General Settings that may need to be migrated.
// We will first create them all, the define_conf_settings() method will
// not change the value if already set. We will update the settings
// to the currently configured values from the globals table afer defining
// them here and then remove them from the globals table.
$globals_convert['VMX_CONTEXT'] = 'from-internal';
$globals_convert['VMX_PRI'] = '1';
$globals_convert['VMX_TIMEDEST_CONTEXT'] = '';
$globals_convert['VMX_TIMEDEST_EXT'] = 'dovm';
$globals_convert['VMX_TIMEDEST_PRI'] = '1';
$globals_convert['VMX_LOOPDEST_CONTEXT'] = '';
开发者ID:lidl,项目名称:core,代码行数:31,代码来源:install.php
示例10: _freepbx_log
/**
* FreePBX Logging
*
* @param const $level Notification Level to show (can be blank for all)
* @param string $module Raw name of the module requesting
* @param string $id ID of the notification
* @param string $display_text The text that will be displayed as the subject/header of the message
* @ignore
*/
function _freepbx_log($level, $module, $id, $display_text, $extended_text = null)
{
global $amp_conf;
if ($amp_conf['LOG_NOTIFICATIONS']) {
if ($extended_text) {
$display_text .= " ({$extended_text})";
}
freepbx_log($level, "[NOTIFICATION]-[{$module}]-[{$id}] - {$display_text}");
}
}
/** Include additional files requested in module.xml for install and uninstall
* @param array The modulexml array
* @param string The action to perform, either 'install' or 'uninstall'
* @return boolean If the action was successful, currently TRUE so we don't prevent the install
*/
function _module_runscripts_include($modulexml, $type)
{
global $amp_conf;
foreach ($modulexml as $modulename => $items) {
$moduledir = $amp_conf["AMPWEBROOT"] . "/admin/modules/" . $modulename;
if (isset($items['fileinclude'][$type]) && !empty($items['fileinclude'][$type])) {
if (!is_array($items['fileinclude'][$type])) {
$ret = _modules_doinclude($moduledir . '/' . $items['fileinclude'][$type], $modulename);
if (!$ret) {
freepbx_log(FPBX_LOG_WARNING, sprintf(_("failed to include %s during %s of the %s module."), $items['fileinclude'][$type], $type, $modulename));
}
} else {
foreach ($items['fileinclude'][$type] as $key => $filename) {
$ret = _modules_doinclude($moduledir . '/' . $filename, $modulename);
if (!$ret) {
freepbx_log(FPBX_LOG_WARNING, sprintf(_("failed to include %s during %s of the %s module."), $filename, $type, $modulename));
}
}
}
}
}
return true;
}
}
if (!function_exists("out")) {
function out($text)
{
echo $text . "<br />";
}
}
// Remove this section in FreePBX 14
$sql = "SHOW KEYS FROM `{$db_name}`.`{$db_table_name}` WHERE Key_name='did'";
$check = $dbcdr->getOne($sql);
if (empty($check)) {
$sql = "ALTER TABLE `{$db_name}`.`{$db_table_name}` ADD INDEX `did` (`did` ASC)";
$result = $dbcdr->query($sql);
if (DB::IsError($result)) {
out(_("Unable to add index to did field in the cdr table"));
freepbx_log(FPBX_LOG_ERROR, "Failed to add index to did field in the cdr table");
} else {
out(_("Adding index to did field in the cdr table"));
}
}
// Remove this section in FreePBX 14
$db_name = FreePBX::Config()->get('CDRDBNAME');
$db_host = FreePBX::Config()->get('CDRDBHOST');
$db_port = FreePBX::Config()->get('CDRDBPORT');
$db_user = FreePBX::Config()->get('CDRDBUSER');
$db_pass = FreePBX::Config()->get('CDRDBPASS');
$db_table = FreePBX::Config()->get('CDRDBTABLENAME');
$dbt = FreePBX::Config()->get('CDRDBTYPE');
$db_hash = array('mysql' => 'mysql', 'postgres' => 'pgsql');
$dbt = !empty($dbt) ? $dbt : 'mysql';
$db_type = $db_hash[$dbt];
/**
* Actually run GPG
* @param string Params to pass to gpg
* @param fd File Descriptor to feed to stdin of gpg
* @return array returns assoc array consisting of (array)status, (string)stdout, (string)stderr and (int)exitcode
*/
public function runGPG($params, $stdin = null)
{
$fds = array(array("file", "/dev/null", "r"), array("pipe", "w"), array("pipe", "w"), array("pipe", "w"));
// If we need to send stuff to stdin, then do it!
if ($stdin) {
$fds[0] = $stdin;
}
$webuser = FreePBX::Freepbx_conf()->get('AMPASTERISKWEBUSER');
$home = $this->getGpgLocation();
// We need to ensure that our environment variables are sane.
// Luckily, we know just the right things to say...
if (!isset($this->gpgenv)) {
$this->gpgenv['PATH'] = "/bin:/usr/bin";
$this->gpgenv['USER'] = $webuser;
$this->gpgenv['HOME'] = "/tmp";
$this->gpgenv['SHELL'] = "/bin/bash";
}
$homedir = "--homedir {$home}";
$cmd = $this->gpg . " {$homedir} " . $this->gpgopts . " --status-fd 3 {$params}";
$proc = proc_open($cmd, $fds, $pipes, "/tmp", $this->gpgenv);
if (!is_resource($proc)) {
// Unable to start!
freepbx_log(FPBX_LOG_FATAL, "Tried to run command and failed: " . $cmd);
throw new \Exception(sprintf(_("Unable to start GPG, the command was: [%s]"), $cmd));
}
// Wait $timeout seconds for it to finish.
$tmp = null;
$r = array($pipes[3]);
if (!stream_select($r, $tmp, $tmp, $this->timeout)) {
freepbx_log(FPBX_LOG_FATAL, "Tried to run command and failed: " . $cmd);
throw new \RuntimeException(sprintf(_("GPG took too long to run the command: [%s]"), $cmd));
}
// We grab stdout and stderr first, as the status fd won't
// have completed and closed until those FDs are emptied.
$retarr['stdout'] = stream_get_contents($pipes[1]);
$retarr['stderr'] = stream_get_contents($pipes[2]);
$status = explode("\n", stream_get_contents($pipes[3]));
array_pop($status);
// Remove trailing blank line
$retarr['status'] = $status;
$exitcode = proc_close($proc);
$retarr['exitcode'] = $exitcode;
return $retarr;
}
请发表评论