function upgrade_all($version) { // **** Read upgrades/ directory outn("Checking for upgrades.."); // read versions list from ugprades/ $versions = array(); $dir = opendir(UPGRADE_DIR); while ($file = readdir($dir)) { if ($file[0] != "." && is_dir(UPGRADE_DIR . "/" . $file)) { $versions[] = $file; } } closedir($dir); // callback to use php's version_compare() to sort usort($versions, "version_compare_freepbx"); // find versions that are higher than the current version $starting_version = false; foreach ($versions as $check_version) { if (version_compare_freepbx($check_version, $version) > 0) { // if check_version < version $starting_version = $check_version; break; } } // run all upgrades from the list of higher versions if ($starting_version) { $pos = array_search($starting_version, $versions); $upgrades = array_slice($versions, $pos); // grab the list of versions, starting at $starting_version out(count($upgrades) . " found"); run_upgrade($upgrades); /* Set the base version of key modules, currently core and framework, to the * Version packaged with this tarball, if any. The expectation is that the * packaging scripts will make these module version numbers the same as the * release plus a '.0' which can be incremented for bug fixes delivered through * the online system between main releases. * * added if function_exists because if this is being run from framework there is no * need to reset the base version. */ if (function_exists('set_base_version')) { set_base_version(); } } else { out("No upgrades found"); } }
public function install() { $dbh = $this->db; $sql = "CREATE TABLE IF NOT EXISTS manager (\n\t\t\t`manager_id` INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,\n\t\t\t`name` VARCHAR( 15 ) NOT NULL ,\n\t\t\t`secret` VARCHAR( 50 ) ,\n\t\t\t`deny` VARCHAR( 255 ) ,\n\t\t\t`permit` VARCHAR( 255 ) ,\n\t\t\t`read` VARCHAR( 255 ) ,\n\t\t\t`write` VARCHAR( 255 )\n\t\t)"; $stmt = $dbh->prepare($sql); $stmt->execute(); \outn(_("Increasing read field size if needed..")); $sql = "ALTER TABLE `manager` CHANGE `read` `read` VARCHAR( 255 )"; $stmt = $dbh->prepare($sql); try { $stmt->execute(); \out(_("ok")); } catch (\PDOException $e) { \out(_("error encountered, not altered")); } outn(_("Increasing write field size if needed..")); $sql = "ALTER TABLE `manager` CHANGE `write` `write` VARCHAR( 255 )"; $stmt = $dbh->prepare($sql); try { $stmt->execute(); \out(_("ok")); } catch (\PDOException $e) { \out(_("error encountered, not altered")); } outn(_("Adding write timeout..")); $sql = "ALTER TABLE manager ADD writetimeout INT"; $stmt = $dbh->prepare($sql); try { $stmt->execute(); \out(_("ok")); } catch (\PDOException $e) { //We are ok with 42S21 because we are trying to add a column and it says that column is present. if ($e->getCode() == '42S21') { \out(_("Column present")); } else { //All other exceptions are bad mmmk \out($e->getMessage()); throw $e; } } }
function encrypt_passwords() { global $db; out("Updating passwords.."); $sql = "SELECT * FROM ampusers"; $users = $db->getAll($sql, NULL, DB_FETCHMODE_ASSOC); if (DB::IsError($users)) { // Error while getting the users list to update... bad die($users->getMessage()); } else { outn("(" . count($users) . " accounts) "); foreach ($users as $index => $ufields) { $sql = "UPDATE ampusers SET password_sha1='" . sha1($ufields['password']) . "' WHERE username='******'username'] . "'"; $result = $db->query($sql); if (DB::IsError($result)) { outn("Error while updating account: " . $ufields['username'] . " (" . $result->getMessage . ")"); } } } out("Done."); }
function did_migrate($incoming) { global $db; foreach ($incoming as $key => $val) { ${$key} = $db->escapeSimple($val); } // Check to make sure the did is not being used elsewhere // $sql = "SELECT * FROM incoming WHERE cidnum = '' AND extension = '{$extension}'"; $existing = $db->getAll($sql, DB_FETCHMODE_ASSOC); if (DB::IsError($existing)) { outn(sprintf(_("ERROR: trying to check if %s already in use"), $extension)); return false; } if (empty($existing)) { $sql = "INSERT INTO incoming (cidnum,extension,destination,faxexten,faxemail,answer,wait,privacyman,alertinfo, ringing, mohclass, description, grppre) values ('{$cidnum}','{$extension}','{$destination}','{$faxexten}','{$faxemail}','{$answer}','{$wait}','{$privacyman}','{$alertinfo}', '{$ringing}', '{$mohclass}', '{$description}', '{$grppre}')"; sql($sql); return true; } else { return false; } }
function get_dial_string($extnum) { global $db; $ds = ''; $sql = "SELECT value FROM globals WHERE variable = 'E{$extnum}'"; $result = $db->getAll($sql); if (DB::IsError($result)) { die($result->getMessage()); } if (count($result) > 0) { $exttech = $result[0][0]; switch ($exttech) { case "SIP": $ds = "SIP/" . $extnum; break; case "IAX2": $ds = "IAX2/" . $extnum; break; case "ZAP": $sql = "SELECT value FROM globals WHERE variable = 'ZAPCHAN_{$extnum}'"; $zapres = $db->getAll($sql); if (DB::IsError($zapres)) { die($zapres->getMessage()); } if (count($zapres) > 0) { $zapchannel = $result[0][0]; } $ds = "Zap/" . $zapchannel; break; default: outn($exttech . "..."); break; } } return $ds; }
$sql = "SELECT * FROM module_xml"; $confs = $db->getRow($sql, DB_FETCHMODE_ASSOC); if (!DB::IsError($confs)) { // no error... Already done out("Not Required"); } else { $sql = "CREATE TABLE module_xml (\n\t id varchar(20) NOT NULL default 'xml',\n\t time int(11) NOT NULL default '0',\n\t data blob NOT NULL,\n\t PRIMARY KEY (id)\n\t )"; $results = $db->query($sql); if (DB::IsError($results)) { die($results->getMessage()); } out("Done"); } // Add id filed to table so more key/values can be kept in it // outn("Adding id to module_xml table.."); $sql = "SELECT id FROM module_xml"; $confs = $db->getRow($sql, DB_FETCHMODE_ASSOC); if (!DB::IsError($confs)) { // no error... Already done out("Not Required"); } else { $sql = "ALTER TABLE module_xml ADD id VARCHAR( 20 ) NOT NULL DEFAULT 'xml' FIRST"; $results = $db->query($sql); if (DB::IsError($results)) { die($results->getMessage()); } $sql = "ALTER TABLE module_xml ADD PRIMARY KEY ( id )"; $results = $db->query($sql); if (DB::IsError($results)) { die($results->getMessage());
// Version 2.5 upgrade outn(_("checking for fcode field..")); $sql = "SELECT `fcode` FROM recordings"; $check = $db->getRow($sql, DB_FETCHMODE_ASSOC); if (DB::IsError($check)) { // add new field $sql = "ALTER TABLE recordings ADD `fcode` TINYINT( 1 ) DEFAULT 0 ;"; $result = $db->query($sql); if (DB::IsError($result)) { die_freepbx($result->getDebugInfo()); } out(_("OK")); } else { out(_("already exists")); } outn(_("checking for fcode_pass field..")); $sql = "SELECT `fcode_pass` FROM recordings"; $check = $db->getRow($sql, DB_FETCHMODE_ASSOC); if (DB::IsError($check)) { // add new field $sql = "ALTER TABLE recordings ADD `fcode_pass` VARCHAR( 20 ) NULL ;"; $result = $db->query($sql); if (DB::IsError($result)) { die_freepbx($result->getDebugInfo()); } out(_("OK")); } else { out(_("already exists")); } sql('DELETE FROM recordings WHERE displayname = "__invalid"'); $freepbx_conf =& freepbx_conf::create();
} if ($foreign_id === false) { out(); out(_("FAILED migrating route {$lookup} NOT FOUND")); outn(_("continuing..")); } else { $pinset_usage[] = array($pinset['pinsets_id'], $dispname, $foreign_id); } } } // We new have all the indices, so lets save them // $compiled = $db->prepare('INSERT INTO `pinset_usage` (`pinsets_id`, `dispname`, `foreign_id`) values (?,?,?)'); $result = $db->executeMultiple($compiled, $pinset_usage); if (DB::IsError($result)) { out("FATAL: " . $result->getDebugInfo() . "\n" . 'error inserting into pinsets_uage table'); } else { out(_("done")); outn(_("dropping used_by field..")); $sql = "ALTER TABLE `pinsets` DROP `used_by`"; $result = $db->query($sql); if (DB::IsError($result)) { out(_("no used_by field???")); } else { out(_("ok")); } } } } else { out(_("already done")); }
CREATE TABLE IF NOT EXISTS `iaxsettings` ( `keyword` VARCHAR (50) NOT NULL default '', `data` VARCHAR (255) NOT NULL default '', `seq` TINYINT (1), `type` TINYINT (1) NOT NULL default '0', PRIMARY KEY (`keyword`,`seq`,`type`) ) END; outn(_("checking for iaxsettings table..")); $tsql = "SELECT * FROM `iaxsettings` limit 1"; $check = $db->getRow($tsql, DB_FETCHMODE_ASSOC); if (DB::IsError($check)) { out(_("none, creating table")); // table does not exist, create it sql($sql); outn(_("populating default codecs..")); $sip_settings = array(array('ulaw', '1', '0'), array('alaw', '2', '1'), array('slin', '', '2'), array('g726', '', '3'), array('gsm', '3', '4'), array('g729', '', '5'), array('ilbc', '', '6'), array('g723', '', '7'), array('g726aal2', '', '8'), array('adpcm', '', '9'), array('lpc10', '', '10'), array('speex', '', '11'), array('g722', '', '12')); // Now insert minimal codec rows $compiled = $db->prepare("INSERT INTO iaxsettings (keyword, data, seq, type) values (?,?,?,'1')"); $result = $db->executeMultiple($compiled, $sip_settings); if (DB::IsError($result)) { out(_("fatal error occurred populating defaults, check module")); } else { out(_("ulaw, alaw, gsm added")); } } else { out(_("already exists")); } /* Convert language to custom field */ $sql = "SELECT MAX(seq) FROM iaxsettings WHERE type = 9"; $seq = sql($sql, 'getOne');
$include = explode('-', $myinclude['include'], 3); $include[1] = (int) $include[1]; foreach ($routes as $rt => $route) { //if we have a trunk with the same name match it and take it out of the list if ($include[2] == $route['name']) { $newincludes[] = array('new' => 'outrt-' . $route['route_id'], 'sort' => $route['seq'], 'old' => $myinclude['include']); //unset the routes so we dont search them again unset($includes[$inc]); unset($routes[$rt]); } } } //alert user of unmigrated routes foreach ($includes as $include) { out(_('FAILED to migrating Custom Context route ' . $include['description'] . '. NO MATCH FOUND')); outn(_("Continuing...")); } // We new have all the indices, so lets save them $sql = $db->prepare('UPDATE customcontexts_includes_list SET include = ?, sort = ? WHERE include = ?'); $result = $db->executeMultiple($sql, $newincludes); if (DB::IsError($result)) { out("FATAL: " . $result->getDebugInfo() . "\n" . 'error updating customcontexts_includes_list table. Aborting!'); } else { //now update the customcontexts_includes table foreach ($newincludes as $inc => $newinclude) { unset($newincludes[$inc]['sort']); } $sql = $db->prepare('UPDATE customcontexts_includes SET include = ? WHERE include = ?'); $result = $db->executeMultiple($sql, $newincludes); if (DB::IsError($result)) { out("FATAL: " . $result->getDebugInfo() . "\n" . 'error updating customcontexts_includes table. Aborting!');
public function install() { global $db; $sql[] = 'CREATE TABLE IF NOT EXISTS `contactmanager_groups` ( `id` int(11) NOT NULL AUTO_INCREMENT, `owner` int(11) NOT NULL, `name` varchar(80) NOT NULL, `type` varchar(25) NOT NULL, PRIMARY KEY (`id`) );'; $sql[] = 'CREATE TABLE IF NOT EXISTS `contactmanager_group_entries` ( `id` int(11) NOT NULL AUTO_INCREMENT, `groupid` int(11) NOT NULL, `user` int(11) NOT NULL, `displayname` varchar(100) default NULL, `fname` varchar(100) default NULL, `lname` varchar(100) default NULL, `title` varchar(100) default NULL, `company` varchar(100) default NULL, `address` varchar(200) default NULL, PRIMARY KEY (`id`) );'; $sql[] = 'CREATE TABLE IF NOT EXISTS `contactmanager_entry_numbers` ( `id` int(11) NOT NULL AUTO_INCREMENT, `entryid` int(11) NOT NULL, `number` varchar(100) default NULL, `extension` varchar(100) default NULL, `type` varchar(100), `flags` varchar(100), PRIMARY KEY (`id`) );'; $sql[] = 'CREATE TABLE IF NOT EXISTS `contactmanager_entry_images` ( `entryid` int(11) NOT NULL, `image` LONGBLOB, `format` VARCHAR(45) NOT NULL, `gravatar` tinyint(4) NOT NULL DEFAULT "0", PRIMARY KEY (`entryid`) );'; $sql[] = 'CREATE TABLE IF NOT EXISTS `contactmanager_entry_xmpps` ( `id` int(11) NOT NULL AUTO_INCREMENT, `entryid` int(11) NOT NULL, `xmpp` varchar(100) default NULL, PRIMARY KEY (`id`) );'; $sql[] = 'CREATE TABLE IF NOT EXISTS `contactmanager_entry_emails` ( `id` int(11) NOT NULL AUTO_INCREMENT, `entryid` int(11) NOT NULL, `email` varchar(100) default NULL, PRIMARY KEY (`id`) );'; $sql[] = 'CREATE TABLE IF NOT EXISTS `contactmanager_entry_websites` ( `id` int(11) NOT NULL AUTO_INCREMENT, `entryid` int(11) NOT NULL, `website` varchar(100) default NULL, PRIMARY KEY (`id`) );'; foreach ($sql as $statement) { $check = $db->query($statement); if (\DB::IsError($check)) { die_freepbx("Can not execute {$statement} : " . $check->getMessage() . "\n"); } } outn(_("checking for title field..")); $sql = "SELECT `title` FROM contactmanager_group_entries"; $check = $db->getRow($sql, DB_FETCHMODE_ASSOC); if (\DB::IsError($check)) { // add new field $sql = "ALTER TABLE contactmanager_group_entries ADD `title` varchar(100), ADD `company` varchar(100)"; $result = $db->query($sql); if (\DB::IsError($result)) { out(_("ERROR failed to update title field")); } else { out(_("OK")); } } else { out(_("already exists")); } outn(_("checking for displayname field..")); $sql = "SELECT `displayname` FROM contactmanager_group_entries"; $check = $db->getRow($sql, DB_FETCHMODE_ASSOC); if (\DB::IsError($check)) { // add new field $sql = "ALTER TABLE contactmanager_group_entries ADD `displayname` varchar(100)"; $result = $db->query($sql); if (\DB::IsError($result)) { out(_("ERROR failed to update displayname field")); } else { out(_("OK")); } } else { out(_("already exists")); } outn(_("checking for address field..")); $sql = "SELECT `address` FROM contactmanager_group_entries"; $check = $db->getRow($sql, DB_FETCHMODE_ASSOC); if (\DB::IsError($check)) { // add new field $sql = "ALTER TABLE contactmanager_group_entries ADD `address` varchar(200)"; $result = $db->query($sql); if (\DB::IsError($result)) { out(_("ERROR failed to update address field")); } else { out(_("OK")); } } else { out(_("already exists")); } outn(_("checking for extension field..")); $sql = "SELECT `extension` FROM contactmanager_entry_numbers"; $check = $db->getRow($sql, DB_FETCHMODE_ASSOC); if (\DB::IsError($check)) { // add new field $sql = "ALTER TABLE contactmanager_entry_numbers ADD `extension` varchar(100)"; $result = $db->query($sql); if (\DB::IsError($result)) { out(_("ERROR failed to update extension field")); } else { out(_("OK")); } } else { out(_("already exists")); } $sql = "SELECT * FROM contactmanager_groups WHERE type = 'userman'"; $sth = $this->db->prepare($sql); $sth->execute(); $grps = $sth->fetchAll(\PDO::FETCH_ASSOC); if (empty($grps)) { $ret = $this->addGroup(_("User Manager Group"), "userman"); $id = $this->freepbx->Userman->getAutoGroup(); $id = !empty($id) ? $id : 1; $this->freepbx->Userman->setModuleSettingByGID($id, 'contactmanager', 'groups', array("*")); } }
echo $text . "<br />"; } } if (!function_exists("outn")) { function outn($text) { echo $text; } } $autoincrement = $amp_conf["AMPDBENGINE"] == "sqlite" || $amp_conf["AMPDBENGINE"] == "sqlite3" ? "AUTOINCREMENT" : "AUTO_INCREMENT"; $sql = "CREATE TABLE IF NOT EXISTS manager (\n\t`manager_id` INTEGER NOT NULL PRIMARY KEY {$autoincrement},\n\t`name` VARCHAR( 15 ) NOT NULL ,\n\t`secret` VARCHAR( 50 ) ,\n\t`deny` VARCHAR( 255 ) ,\n\t`permit` VARCHAR( 255 ) ,\n\t`read` VARCHAR( 255 ) ,\n\t`write` VARCHAR( 255 )\n)"; $check = $db->query($sql); if (DB::IsError($check)) { die_freepbx("Can not create `manager` table" . $check->getMessage() . "\n"); } outn(_("Increasing read field size if needed..")); $sql = "ALTER TABLE `manager` CHANGE `read` `read` VARCHAR( 255 )"; $result = $db->query($sql); if (DB::IsError($check)) { out(_("error encountered, not altered")); } else { out(_("ok")); } outn(_("Increasing write field size if needed..")); $sql = "ALTER TABLE `manager` CHANGE `write` `write` VARCHAR( 255 )"; $result = $db->query($sql); if (DB::IsError($check)) { out(_("error encountered, not altered")); } else { out(_("ok")); }
<?php /* $Id$ */ /* check for old prefix based routing */ outn("Upgrading Call Groups.."); // First update "|" to "-" usage for *-HEAD. $sql = "update extensions set args = REPLACE(args,'|','-') where args LIKE 'GROUP=%' and args LIKE '%|%'"; $results = $db->query($sql); if (DB::IsError($results)) { die($results->getMessage()); } // get all call groups $sql = "select extension, args from extensions where args LIKE 'GROUP=%';"; $results = $db->getAll($sql); if (DB::IsError($results)) { die($results->getMessage()); } out(count($results) . " to check..."); if (count($results) > 0) { // yes, there are ring groups defined foreach ($results as $key => $value) { // replace * that are not at the beginning of an extension $new_extensions = preg_replace("/([0-9*#]+)\\*([0-9#]+)/", "\$1\$2#", $value[1]); // only replace if changed if ($new_extensions != $value[1]) { out("Changing " . $value[1] . " to " . $new_extensions); $sql = sprintf("update extensions set args = '%s' WHERE extension = '%s' ", $new_extensions, $value['0']) . "AND args LIKE 'GROUP=%'"; // debug("sql = ". $sql); $update_results = $db->query($sql); if (DB::IsError($update_results)) { die($update_results->getMessage());
<?php //add AMPEXTENSIONS option to amportal.conf if (!array_key_exists("AMPEXTENSIONS", $amp_conf)) { $filename = AMP_CONF; outn("\n\nUse simple Extensions [extensions] admin or separate Devices and Users [deviceanduser]?\n [extensions] "); $key = trim(fgets(STDIN, 1024)); if (preg_match('/^$/', $key)) { $amp_conf["AMPEXTENSIONS"] = "extensions"; } else { $amp_conf["AMPEXTENSIONS"] = $key; } // write amportal.conf write_amportal_conf($filename, $amp_conf); }
$set['hidden'] = 0; $set['level'] = 0; $set['module'] = 'ringgroups'; $set['category'] = 'Ring Group Module'; $set['emptyok'] = 0; $set['sortorder'] = 50; $set['name'] = 'Display Extension Ring Group Members'; $set['description'] = 'When set to true extensions that belong to one or more Ring Groups will have a Ring Group section and link back to each group they are a member of.'; $set['type'] = CONF_TYPE_BOOL; $freepbx_conf->define_conf_setting('EXTENSION_LIST_RINGGROUPS', $set, true); // Fix recording status. If it's 'yes' or 'no, it should be 'force' or 'never'. $sql = 'UPDATE `ringgroups` SET `recording`="never" WHERE `recording`="no"'; $db->query($sql); $sql = 'UPDATE `ringgroups` SET `recording`="force" WHERE `recording`="yes"'; $db->query($sql); \outn(_("Adding Column progress")); $sql = "ALTER TABLE ringgroups ADD progress VARCHAR( 10 );"; $stmt = $dbh->prepare($sql); try { $stmt->execute(); \out(_("ok")); } catch (\PDOException $e) { //We are ok with 42S21 because we are trying to add a column and it says that column is present. if ($e->getCode() == '42S21') { \out(_("Column present")); } else { //All other exceptions are bad. \out($e->getMessage()); throw $e; } }
if (DB::IsError($result)) { die($result->getDebugInfo()); } out("OK"); } out(" Processed " . $ctr . " Ring Group(s)"); } else { // might have the Ring Groups module already installed from a previous beta -- needs new table $sql = "SELECT COUNT(*) AS RES FROM modules WHERE modulename = 'ringgroups'"; $result = $db->query($sql); if (DB::IsError($result)) { die($result->getDebugInfo()); } else { $row = $result->fetchRow(); if ($row[0] > 0) { outn(" Ring Groups module in use, creating 'ringgroups' table if needed... "); // Create the new table first $sql = "CREATE TABLE IF NOT EXISTS `ringgroups` ( "; $sql .= "`grpnum` INT NOT NULL , "; $sql .= "`strategy` VARCHAR( 50 ) NOT NULL , "; $sql .= "`grptime` SMALLINT NOT NULL , "; $sql .= "`grppre` VARCHAR( 100 ) NULL , "; $sql .= "`grplist` VARCHAR( 255 ) NOT NULL , "; $sql .= "`annmsg` VARCHAR( 255 ) NULL , "; $sql .= "`postdest` VARCHAR( 255 ) NULL , "; $sql .= "PRIMARY KEY (`grpnum`) "; $sql .= ") TYPE = MYISAM "; $result = $db->query($sql); if (DB::IsError($result)) { die($result->getDebugInfo()); }
<?php if ($amp_conf["AMPDBENGINE"] != "sqlite3") { outn("Alter table globals to increase field lengths.. "); $db->query("ALTER TABLE `globals` CHANGE `value` `value` varchar(255) NOT NULL"); $db->query("ALTER TABLE `globals` CHANGE `variable` `variable` varchar(255) NOT NULL"); out("Altered"); }
<?php /* $Id$ */ /* check for old did routes entirs */ outn("Upgrading DID Routes.."); // get all did routes $sql = "SELECT extension FROM extensions WHERE context = 'ext-did' and (application = 'Macro' or application = 'Goto') and priority = '1' ORDER BY extension"; $results = $db->getAll($sql); if (DB::IsError($results)) { die($results->getMessage()); } out(count($results) . " to upgrade..."); if (count($results) > 0) { // yes, there are dids defined foreach ($results as $key => $value) { $sql = "UPDATE extensions SET priority = '2' WHERE context = 'ext-did' AND extension = '" . $value[0] . "' AND priority = '1' LIMIT 1"; $results = $db->query($sql); if (DB::IsError($results)) { die($results->getMessage()); } $sql = "INSERT INTO extensions (context, extension, priority, application, args, descr, flags) VALUES ('ext-did', '" . $value[0] . "', '1', 'SetVar', 'FROM_DID=" . $value[0] . "', '' , '0')"; $results = $db->query($sql); if (DB::IsError($results)) { die($results->getMessage()); } } } out("OK"); ?>
if (DB::IsError($result)) { out("FATAL: " . $result->getDebugInfo() . "\n" . 'error inserting into outbound_route_trunks table'); } else { outn('trunks..'); } unset($insert_trunks); out("migrated"); } outn('Updating route sequence..'); $compiled = $db->prepare('INSERT INTO `outbound_route_sequence` (`route_id`, `seq`) values (?,?)'); $result = $db->executeMultiple($compiled, $outbound_route_sequence); if (DB::IsError($result)) { out("FATAL: " . $result->getDebugInfo() . "\n" . 'error inserting into outbound_route_sequence table'); } else { out("ok"); outn('Removing old extensions table..'); //TODO: add removal code once thoroughly tested out("not implemented until thouroghly tested"); } } } } } //---------- DEPRECATED functions added here so installs work from tarball -------------- function __core_routing_getroutenames() { global $amp_conf; global $db; if ($amp_conf["AMPDBENGINE"] == "sqlite3") { $sql = "SELECT DISTINCT context FROM extensions WHERE context LIKE 'outrt-%' ORDER BY context "; $results = $db->getAll($sql);
// outn(_("Dropping grplist..")); $sql = 'SELECT grpnum, grplist FROM vmblast'; $confs = $db->getAll($sql, DB_FETCHMODE_ASSOC); if (!DB::IsError($confs)) { $list = array(); foreach ($confs as $group) { $grplist = explode('&', $group['grplist']); foreach ($grplist as $exten) { $list[] = array($group['grpnum'], addslashes(trim($exten))); } } $compiled = $db->prepare("INSERT INTO vmblast_groups (grpnum, ext) values (?,?)"); $result = $db->executeMultiple($compiled, $list); if (DB::IsError($result)) { out(_("error populating vmblast_groups table")); return false; } else { out(_("populated new table")); outn(_("Dropping old grplist field..")); $sql = "ALTER TABLE `vmblast` DROP `grplist`"; $results = $db->query($sql); if (DB::IsError($results)) { out(_("failed to drop field")); } else { out(_("OK")); } } } else { out(_("Not Needed")); }
public function refreshAssets() { include dirname(__FILE__) . '/htdocs/includes/bootstrap.php'; $ucp = \UCP\UCP::create(); outn(_("Generating Module Scripts...")); $ucp->Modules->getGlobalScripts(true); out(_("Done")); outn(_("Generating Module CSS...")); $ucp->Modules->getGlobalLess(true); out(_("Done")); outn(_("Generating Main Scripts...")); $ucp->getLess(true); out(_("Done")); outn(_("Generating Main CSS...")); $ucp->getScripts(true); out(_("Done")); exec("amportal chown"); }
$sql = "ALTER TABLE cidlookup ADD opencnam_auth_token VARCHAR(34) DEFAULT NULL"; $results = $db->query($sql); if (DB::IsError($results)) { out(_("Could not add opencnam_auth_token column to cidlookup table.")); } out(_("Done!")); outn(_("Installing OpenCNAM CallerID Lookup Sources...")); $sql = "INSERT INTO cidlookup (description, sourcetype) VALUES ('OpenCNAM', 'opencnam')"; $results = @$db->query($sql); if (DB::IsError($results)) { out(_("Failed to add OpenCNAM CallerID Lookup Source: ") . $results->getMessage()); } else { out(_("Done!")); } } else { outn(_("Cleaning up duplicate OpenCNAM CallerID Lookup Sources...")); $sql = "SELECT * FROM cidlookup WHERE description = 'OpenCNAM' AND sourcetype = 'opencnam'"; $sources = sql($sql, 'getAll', DB_FETCHMODE_ASSOC); $total = count($sources); for ($i = 0; $i < $total; $i++) { //If we are in a pro-tier then skip the fix if (!empty($sources[$i]['opencnam_account_sid'])) { continue; } //don't delete the last remaining line! if ($i != $total - 1) { $sql = "DELETE FROM cidlookup WHERE cidlookup_id=" . $sources[$i]['cidlookup_id']; sql($sql); } } out(_("Done!"));
} else { out(_("already exists")); } outn(_("checking for use_queue_context field..")); $sql = "SELECT `use_queue_context` FROM queues_config"; $check = $db->getRow($sql, DB_FETCHMODE_ASSOC); if (DB::IsError($check)) { // add new field $sql = "ALTER TABLE queues_config ADD `use_queue_context` TINYINT( 1 ) DEFAULT 0"; $result = $db->query($sql); if (DB::IsError($result)) { die_freepbx($result->getDebugInfo()); } out(_("OK")); } else { out(_("already exists")); } outn(_("checking for togglehint field..")); $sql = "SELECT `togglehint` FROM queues_config"; $check = $db->getRow($sql, DB_FETCHMODE_ASSOC); if (DB::IsError($check)) { // add new field $sql = "ALTER TABLE queues_config ADD `togglehint` TINYINT( 1 ) DEFAULT 0"; $result = $db->query($sql); if (DB::IsError($result)) { die_freepbx($result->getDebugInfo()); } out(_("OK")); } else { out(_("already exists")); }
<?php outn("Converting module_xml data field to MEDIUMBLOB.."); $sql = "ALTER TABLE `module_xml` CHANGE `data` `data` MEDIUMBLOB NOT NULL"; $results = $db->query($sql); if (DB::IsError($results)) { out("ERROR: failed to convert table " . $results->getMessage()); } else { out("OK"); }
/** * Installs or upgrades a module from it's directory * Checks dependencies, and enables * @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 install($modulename, $force = false) { $this->modDepends = array(); $this->notFound = false; global $db, $amp_conf; set_time_limit($this->maxTimeLimit); $modules = $this->getinfo($modulename); // make sure we have a directory, to begin with $dir = $amp_conf['AMPWEBROOT'] . '/admin/modules/' . $modulename; if (!is_dir($dir)) { $this->notFound = true; return array(_("Cannot find module")); } // read the module.xml file $modules = $this->getinfo($modulename); if (!isset($modules[$modulename])) { return array(_("Could not read module.xml")); } // don't force this bit - we can't install a broken module (missing files) if ($modules[$modulename]['status'] == MODULE_STATUS_BROKEN) { return array(_("Module " . $modules[$modulename]['rawname'] . " is broken and cannot be installed. You should try to download it again.")); } $mod = FreePBX::GPG()->verifyModule($modulename); $revoked = $mod['status'] & GPG::STATE_REVOKED; if ($revoked) { return array(_("Module " . $modulename . " has a revoked signature and cannot be installed")); } if (!$force) { if (!in_array($modules[$modulename]['status'], array(MODULE_STATUS_ENABLED, MODULE_STATUS_NOTINSTALLED, MODULE_STATUS_NEEDUPGRADE))) { //return array(_("This module is already installed.")); // This isn't really an error, we just exit return true; } // check dependencies if (is_array($errors = $this->checkdepends($modules[$modulename]))) { return $errors; } } // Check if another module wants this install to be rejected // The module must have a callback: [modulename]_module_install_check_callback() that takes // a single modules array from module_getinfo() about the module to be installed // and it must pass back boolean true if the installation can proceed, or a message // indicating why the installation must fail // $rejects = array(); //We need to include developer files before the callback happens during an install if (!$this->_runscripts_include($modules, 'install')) { return array(_("Failed to run installation scripts")); } foreach (mod_func_iterator('module_install_check_callback', $modules) as $mod => $res) { if ($res !== true) { $rejects[] = $res; } } if (!empty($rejects)) { return $rejects; } //Developer mode, remind them they need to run install_amp manually //run this before the install scripts below because they end up removing install.php...yup if ($modulename == 'framework' && !file_exists($dir . '/install.php')) { out(_("Framework has been detected as being in Developer mode, Please make sure to run './install_amp --update-links' manually so that any database or system settings can be updated")); } // run the scripts if (!$this->_runscripts($modulename, 'install', $modules)) { return array(_("Failed to run installation scripts")); } if ($modules[$modulename]['status'] == MODULE_STATUS_NOTINSTALLED) { // customize INSERT query $sql = "INSERT INTO modules (modulename, version, enabled) values ('" . $db->escapeSimple($modules[$modulename]['rawname']) . "','" . $db->escapeSimple($modules[$modulename]['version']) . "', 1);"; } else { // just need to update the version $sql = "UPDATE modules SET version='" . $db->escapeSimple($modules[$modulename]['version']) . "' WHERE modulename = '" . $db->escapeSimple($modules[$modulename]['rawname']) . "'"; } // run query $results = $db->query($sql); if (DB::IsError($results)) { return array(sprintf(_("Error updating database. Command was: %s; error was: %s "), $sql, $results->getMessage())); } // If module is framework then update the framework version // normally this is done inside of the funky upgrade script runner but we are changing this now as // framework and freepbx versions are the same if ($modulename == 'framework' && !empty($modules[$modulename]['version']) && getVersion() != $modules[$modulename]['version']) { out(sprintf(_("Framework Detected, Setting FreePBX Version to %s"), $modules[$modulename]['version'])); $sql = "UPDATE admin SET value = '" . $db->escapeSimple($modules[$modulename]['version']) . "' WHERE variable = 'version'"; $result = $db->query($sql); if (DB::IsError($result)) { die($result->getMessage()); } if (getVersion() != $modules[$modulename]['version']) { die(_('Internal Error. Function getVersion did not match the Framework version, even after it was suppose to be applied')); } } // module is now installed & enabled, invalidate the modulelist class since it is now stale $modulelist =& modulelist::create($db); $modulelist->invalidate(); // edit the notification table to list any remaining upgrades available or clear // it if none are left. It requres a copy of the most recent module_xml to compare // against the installed modules. // $sql = 'SELECT data FROM module_xml WHERE id = "xml"'; $data = sql($sql, "getOne"); $parser = new xml2ModuleArray($data); $xmlarray = $parser->parseAdvanced($data); $new_modules = array(); if (count($xmlarray)) { foreach ($xmlarray['xml']['module'] as $mod) { $new_modules[$mod['rawname']] = $mod; } } $this->upgrade_notifications($new_modules, 'PASSIVE'); needreload(); FreePBX::Config()->update("SIGNATURECHECK", true); $db->query("DELETE FROM admin WHERE variable = 'unsigned' LIMIT 1"); //Generate LESS on install //http://issues.freepbx.org/browse/FREEPBX-8287 outn(_("Generating CSS...")); try { if ($modulename == 'framework') { FreePBX::Less()->generateMainStyles(); } else { FreePBX::Less()->generateModuleStyles($modulename); } } catch (\Exception $e) { } out(_("Done")); return true; }
$migrate_arr = array(); $count = 0; foreach ($results as $row) { if (trim($row['recording']) != '') { $rec_id = recordings_get_or_create_id($row['recording'], 'announcement'); $migrate_arr[] = array($rec_id, $row['announcement_id']); $count++; } } if ($count) { $compiled = $db->prepare('UPDATE `announcement` SET `recording_id` = ? WHERE `announcement_id` = ?'); $result = $db->executeMultiple($compiled, $migrate_arr); if (DB::IsError($result)) { out(_("fatal error")); die_freepbx($result->getDebugInfo()); } } out(sprintf(_("migrated %s entries"), $count)); // Now remove the old recording field replaced by new id field // outn(_("dropping recording field..")); $sql = "ALTER TABLE `announcement` DROP `recording`"; $result = $db->query($sql); if (DB::IsError($result)) { out(_("no recording field???")); } else { out(_("ok")); } } else { out(_("already migrated")); }
outn(sprintf(_("Parsing %s .."), $amportalconf)); require_once $amp_conf['AMPWEBROOT'] . "/admin/functions.inc.php"; $amp_conf = parse_amportal_conf($amportalconf); if (count($amp_conf) == 0) { fatal(_("amportal.conf parsing failure"), sprintf(_("no entries found in %s"), $amportalconf)); } out(_("OK")); $asterisk_conf_file = $amp_conf["ASTETCDIR"] . "/asterisk.conf"; outn(sprintf(_("Parsing %s .."), $asterisk_conf_file)); $asterisk_conf = parse_asterisk_conf($asterisk_conf_file); if (count($asterisk_conf) == 0) { fatal(_("asterisk.conf parsing failure"), sprintf(_("no entries found in %s"), $asterisk_conf_file)); } out(_("OK")); // **** Connect to database outn(_("Connecting to database..")); # the engine to be used for the SQL queries, # if none supplied, backfall to mysql $db_engine = "mysql"; if (isset($amp_conf["AMPDBENGINE"])) { $db_engine = $amp_conf["AMPDBENGINE"]; } // Define the notification class for logging to the dashboard // $nt = notifications::create($db); switch ($db_engine) { case "pgsql": case "mysql": /* datasource in in this style: dbengine://username:password@host/database */ $db_user = $amp_conf["AMPDBUSER"];
// $freepbx_conf->remove_conf_settings('VIEW_FREEPBX'); $freepbx_conf->remove_conf_settings('VIEW_FREEPBX_ADMIN'); $freepbx_conf->remove_conf_settings('VIEW_FREEPBX_RELOAD'); $freepbx_conf->remove_conf_settings('VIEW_FREEPBX_RELOADBAR'); $freepbx_conf->remove_conf_settings('VIEW_UNAUTHORIZED'); $freepbx_conf->remove_conf_settings('VIEW_LOGGEDOUT'); $freepbx_conf->remove_conf_settings('VIEW_LOGGEDOUT'); $freepbx_conf->remove_conf_settings('BRAND_FREEPBX_ALT_RIGHT'); $freepbx_conf->remove_conf_settings('BRAND_IMAGE_FREEPBX_LINK_RIGHT'); $freepbx_conf->remove_conf_settings('BRAND_IMAGE_HIDE_NAV_BACKGROUND'); $freepbx_conf->remove_conf_settings('BRAND_HIDE_LOGO_RIGHT'); $freepbx_conf->remove_conf_settings('BRAND_HIDE_HEADER_MENUS'); $freepbx_conf->remove_conf_settings('BRAND_HIDE_HEADER_VERSION'); $freepbx_conf->remove_conf_settings('VIEW_REPORTS'); $freepbx_conf->remove_conf_settings('VIEW_PANEL'); $freepbx_conf->remove_conf_settings('BRAND_IMAGE_FREEPBX_LEFT'); //commit all settings $freepbx_conf->commit_conf_settings(); //settings global $amp_conf; $outdated = array($amp_conf['AMPWEBROOT'] . '_asterisk', $amp_conf['AMPWEBROOT'] . '/admin/views/freepbx.php', $amp_conf['AMPWEBROOT'] . '/admin/views/freepbx_admin.php', $amp_conf['AMPWEBROOT'] . '/admin/views/freepbx_reload.php', $amp_conf['AMPWEBROOT'] . '/admin/views/freepbx_reloadbar.php', $amp_conf['AMPWEBROOT'] . '/admin/views/freepbx_footer.php', $amp_conf['AMPWEBROOT'] . '/admin/views/unauthorized.php', $amp_conf['AMPWEBROOT'] . '/admin/views/loggedout.php'); out("Cleaning up deprecated or moved files:"); foreach ($outdated as $file) { outn("Checking {$file}.."); if (file_exists($file) && !is_link($file)) { unlink($file) ? out("removed") : out("failed to remove"); } else { out("Not Required"); } }
$check = $db->getRow($sql, DB_FETCHMODE_ASSOC); if (DB::IsError($check)) { // Add invalid_id field // $sql = "ALTER TABLE ivr ADD invalid_id INTEGER DEFAULT null"; $result = $db->query($sql); if (DB::IsError($result)) { out(_("fatal error")); die_freepbx($result->getDebugInfo()); } else { out(_("added")); } } else { out(_("not needed")); } outn(_("Checking for retvm..")); $sql = "SELECT retvm FROM ivr"; $check = $db->getRow($sql, DB_FETCHMODE_ASSOC); if (DB::IsError($check)) { // Add retvm field // $sql = "ALTER TABLE ivr ADD retvm VARCHAR(8);"; $result = $db->query($sql); if (DB::IsError($result)) { out(_("fatal error")); die_freepbx($result->getDebugInfo()); } else { out(_("added")); } } else { out(_("not needed"));
$sql = "ALTER TABLE users ADD privacyman TINYINT ( 1 ) NULL "; $results = $db->query($sql); if (DB::IsError($results)) { die($results->getMessage()); } out("Done"); } outn("Checking for Global var OPERATOR_XTN.."); $nrows = $db->getOne("SELECT count(*) from globals where variable='OPERATOR_XTN'"); if (!$nrows) { $db->query("insert into globals values ('OPERATOR_XTN', '')"); out("Created"); } else { out("Already exists!"); } outn("Checking for Global var VM_OPTS.."); $nrows = $db->getOne("SELECT count(*) from globals where variable='VM_OPTS'"); if (!$nrows) { $db->query("insert into globals values ('VM_OPTS', '')"); out("Created"); } else { out("Already exists!"); } outn("Checking for Global var TIMEFORMAT.."); $nrows = $db->getOne("SELECT count(*) from globals where variable='TIMEFORMAT'"); if (!$nrows) { $db->query("insert into globals values ('TIMEFORMAT', 'kM')"); out("Created"); } else { out("Already exists!"); }