Пример #1
0
 public function install()
 {
     $sql = "CREATE TABLE IF NOT EXISTS miscapps (miscapps_id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, ext VARCHAR( 50 ) , description VARCHAR( 50 ) , dest VARCHAR( 255 ))";
     $q = $this->db->prepare($sql);
     $q = $q->execute();
     unset($sql);
     unset($q);
     //Migration... Is this still needed
     global $db;
     $results = array();
     $sql = "SELECT miscapps_id, dest FROM miscapps";
     $results = $db->getAll($sql, DB_FETCHMODE_ASSOC);
     if (!\DB::IsError($results)) {
         // error - table must not be there
         foreach ($results as $result) {
             $old_dest = $result['dest'];
             $this->id = $result['miscapps_id'];
             $new_dest = merge_ext_followme(trim($old_dest));
             if ($new_dest != $old_dest) {
                 $sql = "UPDATE miscapps SET dest = '{$new_dest}' WHERE miscapps_id = {$miscapps_id}  AND dest = '{$old_dest}'";
                 $results = $db->query($sql);
                 if (DB::IsError($results)) {
                     die_freepbx($results->getMessage());
                 }
             }
         }
     }
 }
Пример #2
0
function DbConnect()
{
    $options = array();
    if (DB_TYPE == "postgres") {
        $datasource = 'pgsql://' . USER . ':' . PASS . '@' . HOST . '/' . DBNAME;
    } else {
        if (DB_TYPE == "sqlite3") {
            /* on centos this extension is not loaded by default */
            if (!extension_loaded('sqlite3') && !extension_loaded('SQLITE3')) {
                dl('sqlite3.so');
            }
            if (!@(require_once 'DB/sqlite3.php')) {
                die_freepbx("Your PHP installation has no PEAR/SQLite3 support. Please install php-sqlite3 and php-pear.");
            }
            $datasource = "sqlite3:///asteriskcdr.db?mode=0666";
            $options = array('debug' => 4, 'portability' => DB_PORTABILITY_NUMROWS);
        } else {
            $datasource = DB_TYPE . '://' . USER . ':' . PASS . '@' . HOST . '/' . DBNAME;
        }
    }
    if (!empty($options)) {
        $db = DB::connect($datasource, $options);
    } else {
        $db = DB::connect($datasource);
    }
    // attempt connection
    if (DB::isError($db)) {
        die($db->getDebugInfo());
    }
    return $db;
}
Пример #3
0
function setcid_edit($cid_id, $description, $cid_name, $cid_num, $dest)
{
    global $db;
    $sql = "UPDATE setcid SET " . "description = '" . $db->escapeSimple($description) . "', " . "cid_name = '" . $db->escapeSimple($cid_name) . "', " . "cid_num = '" . $db->escapeSimple($cid_num) . "', " . "dest = '" . $db->escapeSimple($dest) . "' " . "WHERE cid_id = " . $db->escapeSimple($cid_id);
    $result = $db->query($sql);
    if (DB::IsError($result)) {
        die_freepbx($result->getMessage() . $sql);
    }
}
Пример #4
0
function contactdir_get_all_server_types()
{
    global $db;
    $sql = "select * from contactdir_server_types";
    $results = $db->getAll($sql, DB_FETCHMODE_ASSOC);
    if (DB::IsError($results)) {
        die_freepbx($result->getDebugInfo());
    }
    return $results;
}
Пример #5
0
function legacy_extensions_del($context, $exten)
{
    global $db;
    $sql = "DELETE FROM extensions WHERE context = '" . $db->escapeSimple($context) . "' AND `extension` = '" . $db->escapeSimple($exten) . "'";
    $result = $db->query($sql);
    if (DB::IsError($result)) {
        die_freepbx($sql . "<br>\n" . $result->getMessage());
    }
    return $result;
}
Пример #6
0
function ttsengines_get_all_engines()
{
    global $db;
    $sql = "select * from ttsengines";
    $results = $db->getAll($sql, DB_FETCHMODE_ASSOC);
    if (DB::IsError($results)) {
        die_freepbx($result->getDebugInfo());
    }
    return $results;
}
Пример #7
0
 /**
  * Connecting to the Database object
  * If you pass nothing to this it will assume the default database
  *
  * Otherwise you can send it parameters that match PDO parameter settings:
  * PDO::__construct ( string $dsn [, string $username [, string $password [, array $options ]]] )
  *
  * You will then be returned a PDO Database object that you can work with
  * to manipulate databases outside of FreePBX, a good example of this is with
  * CDRs where the module has to connect to the external CDR Database
  */
 public function __construct()
 {
     $args = func_get_args();
     if (is_object($args[0]) && get_class($args[0]) == "FreePBX") {
         $this->FreePBX = $args[0];
         array_shift($args);
     }
     if (class_exists("FreePBX")) {
         $amp_conf = \FreePBX::$conf;
     } else {
         if (is_array($args[0]) && !empty($args[0])) {
             $amp_conf = $args[0];
             array_shift($args);
         } else {
             throw new \Exception("FreePBX class does not exist, and no amp_conf found.");
         }
     }
     //Isset, not empty and is a string that's the only valid DSN we will accept here
     if (isset($args[0]) && !empty($args[0]) && is_string($args[0])) {
         $dsn = $args[0];
     } else {
         if (empty($amp_conf['AMPDBSOCK'])) {
             $host = !empty($amp_conf['AMPDBHOST']) ? $amp_conf['AMPDBHOST'] : 'localhost';
             $dsn = $amp_conf['AMPDBENGINE'] . ":host=" . $host . ";dbname=" . $amp_conf['AMPDBNAME'] . ";charset=utf8";
         } else {
             $dsn = $amp_conf['AMPDBENGINE'] . ":unix_socket=" . $amp_conf['AMPDBSOCK'] . ";dbname=" . $amp_conf['AMPDBNAME'] . ";charset=utf8";
         }
     }
     if (isset($args[1]) && !empty($args[0]) && is_string($args[0])) {
         $username = $args[1];
     } else {
         $username = $amp_conf['AMPDBUSER'];
     }
     if (isset($args[2]) && !empty($args[0]) && is_string($args[0])) {
         $password = $args[2];
     } else {
         $password = $amp_conf['AMPDBPASS'];
     }
     $options = isset($args[3]) ? $args[3] : array();
     if (version_compare(PHP_VERSION, '5.3.6', '<')) {
         $options[\PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET NAMES utf8';
     }
     try {
         if (!empty($options)) {
             parent::__construct($dsn, $username, $password, $options);
         } else {
             parent::__construct($dsn, $username, $password);
         }
     } catch (\Exception $e) {
         die_freepbx($e->getMessage(), $e);
     }
     $this->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
 }
Пример #8
0
 function parse($strInputXML)
 {
     $this->resParser = xml_parser_create();
     xml_set_object($this->resParser, $this);
     xml_set_element_handler($this->resParser, "tagOpen", "tagClosed");
     xml_set_character_data_handler($this->resParser, "tagData");
     $this->strXmlData = xml_parse($this->resParser, $strInputXML);
     if (!$this->strXmlData) {
         die_freepbx(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($this->resParser)), xml_get_current_line_number($this->resParser)));
     }
     xml_parser_free($this->resParser);
     return $this->arrOutput;
 }
Пример #9
0
function presencestate_item_del($id)
{
    global $db;
    $sql = 'DELETE FROM presencestate_prefs WHERE `item_id` = ?';
    $ret = $db->query($sql, array($id));
    if (DB::isError($ret)) {
        die_freepbx("Could not delete presence state.\n");
    }
    $sql = 'DELETE FROM presencestate_list WHERE `id` = ?';
    $ret = $db->query($sql, array($id));
    if (DB::isError($ret)) {
        die_freepbx("Could not delete presence state.\n");
    }
}
Пример #10
0
 /**
  * Connecting to the Database object
  * If you pass nothing to this it will assume the default database
  *
  * Otherwise you can send it parameters that match PDO parameter settings:
  * PDO::__construct ( string $dsn [, string $username [, string $password [, array $options ]]] )
  *
  * You will then be returned a PDO Database object that you can work with
  * to manipulate databases outside of FreePBX, a good example of this is with
  * CDRs where the module has to connect to the external CDR Database
  */
 public function __construct()
 {
     $args = func_get_args();
     if (is_object($args[0]) && get_class($args[0]) == "FreePBX") {
         $this->FreePBX = $args[0];
         array_shift($args);
     }
     $amp_conf = FreePBX::$conf;
     //Isset, not empty and is a string that's the only valid DSN we will accept here
     if (isset($args[0]) && !empty($args[0]) && is_string($args[0])) {
         $dsn = $args[0];
     } else {
         $host = !empty($amp_conf['AMPDBHOST']) ? $amp_conf['AMPDBHOST'] : 'localhost';
         //Note: charset=utf8 requires php 5.3.6 (http://php.net/manual/en/mysqlinfo.concepts.charset.php)
         $dsn = "mysql:host=" . $host . ";dbname=" . $amp_conf['AMPDBNAME'] . ";charset=utf8";
     }
     if (isset($args[1]) && !empty($args[0]) && is_string($args[0])) {
         $username = $args[1];
     } else {
         $username = $amp_conf['AMPDBUSER'];
     }
     if (isset($args[2]) && !empty($args[0]) && is_string($args[0])) {
         $password = $args[2];
     } else {
         $password = $amp_conf['AMPDBPASS'];
     }
     $options = isset($args[3]) ? $args[3] : array();
     if (version_compare(PHP_VERSION, '5.3.6', '<')) {
         $options[\PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET NAMES utf8';
     }
     try {
         if (!empty($options)) {
             parent::__construct($dsn, $username, $password, $options);
         } else {
             parent::__construct($dsn, $username, $password);
         }
     } catch (\Exception $e) {
         die_freepbx($e->getMessage(), $e);
     }
     $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
 }
Пример #11
0
 function getAmpUser($username)
 {
     global $db;
     $sql = "SELECT username, password_sha1, extension_low, extension_high, deptname, sections FROM ampusers WHERE username = '******'";
     $results = $db->getAll($sql);
     if ($db->IsError($results)) {
         die_freepbx($sql . "<br>\n" . $results->getMessage());
     }
     if (count($results) > 0) {
         $user = array();
         $user["username"] = $results[0][0];
         $user["password_sha1"] = $results[0][1];
         $user["extension_low"] = $results[0][2];
         $user["extension_high"] = $results[0][3];
         $user["deptname"] = $results[0][4];
         $user["sections"] = explode(";", $results[0][5]);
         return $user;
     } else {
         return false;
     }
 }
Пример #12
0
function sql($sql, $type = "query", $fetchmode = null)
{
    global $db;
    $results = $db->{$type}($sql, $fetchmode);
    /* FUTURE
    	switch($type) {
    		case "query":
    			$results = $db->$type($sql);
    			break;
    		case "getAssoc":
    			$results = $db->$type($sql,false,array(),$fetchmode);
    			break;
    		default:
    			$results = $db->$type($sql,array(),$fetchmode);
    			break;
    	}
    	*/
    if (DB::IsError($results)) {
        die_freepbx($results->getDebugInfo() . "SQL - <br /> {$sql}");
    }
    return $results;
}
Пример #13
0
function languages_edit($language_id, $description, $lang_code, $dest)
{
    global $db;
    $sql = "UPDATE languages SET " . "description = '" . $db->escapeSimple($description) . "', " . "lang_code = '" . $db->escapeSimple($lang_code) . "', " . "dest = '" . $db->escapeSimple($dest) . "' " . "WHERE language_id = " . $db->escapeSimple($language_id);
    $result = $db->query($sql);
    if (DB::IsError($result)) {
        die_freepbx($result->getMessage() . $sql);
    }
}
Пример #14
0
function callrecording_edit($callrecording_id, $description, $callrecording_mode, $dest)
{
    global $db;
    $sql = "UPDATE callrecording SET " . "description = '" . $db->escapeSimple($description) . "', " . "callrecording_mode = '" . $db->escapeSimple($callrecording_mode) . "', " . "dest = '" . $db->escapeSimple($dest) . "' " . "WHERE callrecording_id = " . $db->escapeSimple($callrecording_id);
    $result = $db->query($sql);
    if (DB::IsError($result)) {
        die_freepbx($result->getMessage() . $sql);
    }
}
	if((!$rule_match['status']) || (!$rule_match['number'])){
		if($debug)
		{
			print "Searching Superfecta Cache ... ";
		}
		
		//clear old cache
		$sql = "DELETE FROM superfectacache WHERE dateentered < DATE_SUB(NOW(),INTERVAL ".(isset($run_param['Cache_Timeout'])?$run_param['Cache_Timeout']:$source_param['Cache_Timeout']['default'])." DAY)";
		$db->query($sql);
		
		//query cache
		$sql = "SELECT callerid FROM superfectacache WHERE number = '$thenumber'";
		$sres = $db->getOne($sql);
		if (DB::IsError($sres))
		{
			die_freepbx( "Error: " . $sres->getMessage() .  "<br>");
		}
		
		//check to see if there is a valid return and that it's not numeric
		if(($sres != '') && !is_numeric($sres))
		{
			$caller_id = $sres;
			$cache_found = true;
		}
		else if($debug)
		{
			print "not found<br>\n";
		}
	}elseif($debug){
		print "Matched cache exclusion rule: '".$rule_match['pattern']."' with: '".$rule_match['number']."'<br>\nSkipping cache 
lookup.<br>\n";
Пример #16
0
        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"));
}
$count = sql('SELECT COUNT(*) FROM `ivr` WHERE `enable_directory` = "CHECKED"', 'getOne');
if ($count) {
    global $db;
    $notifications =& notifications::create($db);
    $extext = sprintf(_("There are %s IVRs that have the legacy Directory dialing enabled. This has been deprecated and will be removed from future releases. You should convert your IVRs to use the Directory module for this functionality and assign an IVR destination to a desired Directory. You can install the Directory module from the Online Module Repository"), $count);
    $notifications->add_notice('ivr', 'DIRECTORY_DEPRECATED', sprintf(_('Deprecated Directory used by %s IVRs'), $count), $extext, '', true, true);
    out(_("posting notice about deprecated functionality"));
}
// This used to be called from page.ivr.php every time, it should not be needed, it should
Пример #17
0
 /** Internal use only */
 function _setenabled($modulename, $enabled)
 {
     global $db;
     $sql = 'UPDATE modules SET enabled = ' . ($enabled ? '1' : '0') . ' WHERE modulename = "' . $db->escapeSimple($modulename) . '"';
     $results = $db->query($sql);
     if (DB::IsError($results)) {
         die_freepbx($sql . "<br>\n" . $results->getMessage());
     }
     $modulelist =& modulelist::create($db);
     $modulelist->invalidate();
 }
Пример #18
0
        $check = $db->query($sql);
        if (DB::IsError($check)) {
            echo "Can not remove column " . $row[0] . ": " . $check->getMessage() . "<br>";
            //not fatal error
        } else {
            print 'Removed unused column ' . $row[0] . ' from ' . $tablename . ' table.<br>';
        }
    }
}
//add any missing columns that are not already in the table
foreach ($cols as $key => $val) {
    if (!in_array($key, $curret_cols)) {
        $sql = "ALTER TABLE {$tablename} ADD " . $key . " " . $val;
        $check = $db->query($sql);
        if (DB::IsError($check)) {
            die_freepbx("Can not add column " . $key . ": " . $check->getMessage() . "<br>");
        } else {
            print 'Added column ' . $key . ' to ' . $tablename . ' table.<br>';
        }
    }
}
// Populate table with default values if this is a new install
$sql = "SELECT COUNT(*) FROM {$tablename}";
$check = $db->getAll($sql, DB_FETCHMODE_ASSOC);
if ($check['0']['COUNT(*)'] == 0) {
    $sql = "INSERT INTO {$tablename} (id, destination, silence, itterations) VALUES('1','*****@*****.**', '1500', '1')";
    $check = $db->query($sql);
    if (DB::IsError($check)) {
        echo "Can not populate settings with default values<br>";
    } else {
        echo "Populating settings with default values<br>";
Пример #19
0
function fax_get_destinations()
{
    global $db;
    $sql = "SELECT fax_users.user,fax_users.faxemail,fax_users.faxattachformat FROM fax_users where fax_users.faxenabled = 'true' ORDER BY fax_users.user";
    $results = $db->getAll($sql, DB_FETCHMODE_ASSOC);
    if (DB::IsError($results)) {
        die_freepbx($results->getMessage() . "<br><br>Error selecting from fax");
    }
    $final = array();
    $warning = array();
    foreach ($results as $res) {
        $o = \FreePBX::Userman()->getUserByID($res['user']);
        if (!empty($o)) {
            if (empty($o['email'])) {
                $warning[] = $o['username'];
                continue;
            }
            $res['uname'] = $o['username'];
            $res['name'] = !empty($o['displayname']) ? $o['displayname'] : $o['fname'] . " " . $o['lname'];
            $res['name'] = trim($res['name']);
            $res['name'] = !empty($res['name']) ? $res['name'] : $o['username'];
            $final[] = $res;
        }
    }
    $nt = \notifications::create();
    if (!empty($warning)) {
        $nt->add_warning("fax", "invalid_email", _("Invalid Email for Inbound Fax"), sprintf(_("User Manager users '%s' have the ability to receive faxes but have no email address defined so they will not be able to receive faxes."), implode(",", $warning)), "", true, true);
    } else {
        $nt->delete("fax", "invalid_email");
    }
    return $final;
}
Пример #20
0
function miscapps_edit($miscapps_id, $description, $ext, $dest, $enabled = true)
{
    global $db;
    $sql = "UPDATE miscapps SET " . "description = '" . $db->escapeSimple($description) . "', " . "ext = '" . $db->escapeSimple($ext) . "', " . "dest = '" . $db->escapeSimple($dest) . "' " . "WHERE miscapps_id = " . $db->escapeSimple($miscapps_id);
    $result = $db->query($sql);
    if (DB::IsError($result)) {
        die_freepbx($result->getMessage() . $sql);
    }
    $fc = new featurecode('miscapps', 'miscapp_' . $miscapps_id);
    $fc->setDescription($description);
    $fc->setDefault($ext, true);
    $fc->setEnabled($enabled);
    $fc->update();
}
Пример #21
0
function customappsreg_customextens_edit($old_custom_exten, $custom_exten, $description, $notes)
{
    global $db;
    $sql = "UPDATE custom_extensions SET " . "custom_exten = " . sql_formattext($custom_exten) . ", " . "description = " . sql_formattext($description) . ", " . "notes = " . sql_formattext($notes) . " " . "WHERE custom_exten = " . sql_formattext($old_custom_exten);
    $result = $db->query($sql);
    if (DB::IsError($result)) {
        die_freepbx($result->getMessage() . $sql);
    }
}
Пример #22
0
$sql[] = 'CREATE TABLE IF NOT EXISTS `presencestate_list` (
 `id` int(11) NOT NULL auto_increment,
 `type` varchar(25),
 `message` varchar(80) default NULL,
 PRIMARY KEY (`id`)
);';
$sql[] = 'CREATE TABLE IF NOT EXISTS `presencestate_prefs` (
 `extension` varchar(20) NOT NULL,
 `item_id` int(11) NOT NULL,
 `pref` varchar(25),
 PRIMARY KEY (`extension`, `item_id`)
);';
/* Check for first install */
$q = $db->query('SELECT * FROM presencestate_list;');
if (DB::isError($q)) {
    /* Add default presence states */
    $sql[] = 'INSERT INTO presencestate_list (`type`) VALUES
	 ("available"),
	 ("chat"),
	 ("away"),
	 ("dnd"),
	 ("xa"),
	 ("unavailable")
	;';
}
foreach ($sql as $statement) {
    $check = $db->query($statement);
    if (DB::IsError($check)) {
        die_freepbx("Can not execute {$statement} : " . $check->getMessage() . "\n");
    }
}
Пример #23
0
$autoincrement = $amp_conf["AMPDBENGINE"] == "sqlite3" ? "AUTOINCREMENT" : "AUTO_INCREMENT";
$sql = "CREATE TABLE IF NOT EXISTS callback (\n\tcallback_id INTEGER NOT NULL PRIMARY KEY {$autoincrement},\n\tdescription VARCHAR( 50 ) ,\n\tcallbacknum VARCHAR( 100 ) ,\n\tdestination VARCHAR( 50 ) ,\n\tsleep INTEGER,\n\tdeptname VARCHAR( 50 )\n);";
$check = $db->query($sql);
if (DB::IsError($check)) {
    die_freepbx("Can not create `callback` table: " . $check->getMessage() . "\n");
}
// Version 1.1 upgrade - add sleep time.
$sql = "SELECT sleep FROM callback";
$check = $db->getRow($sql, DB_FETCHMODE_ASSOC);
if (DB::IsError($check)) {
    // add new field
    sql('ALTER TABLE callback ADD COLUMN sleep INT DEFAULT 0');
}
$results = array();
$sql = "SELECT callback_id, destination FROM callback";
$results = $db->getAll($sql, DB_FETCHMODE_ASSOC);
if (!DB::IsError($results)) {
    // error - table must not be there
    foreach ($results as $result) {
        $old_dest = $result['destination'];
        $callback_id = $result['callback_id'];
        $new_dest = merge_ext_followme(trim($old_dest));
        if ($new_dest != $old_dest) {
            $sql = "UPDATE callback SET destination = '{$new_dest}' WHERE callback_id = {$callback_id}  AND destination = '{$old_dest}'";
            $results = $db->query($sql);
            if (DB::IsError($results)) {
                die_freepbx($results->getMessage());
            }
        }
    }
}
Пример #24
0
$db_table_name = !empty($amp_conf['CDRDBTABLENAME']) ? $amp_conf['CDRDBTABLENAME'] : "cdr";
$system_monitor_dir = isset($amp_conf['ASTSPOOLDIR']) ? $amp_conf['ASTSPOOLDIR'] . "/monitor" : "/var/spool/asterisk/monitor";
// if CDRDBHOST and CDRDBTYPE are not empty then we assume an external connection and don't use the default connection
//
if (!empty($amp_conf["CDRDBHOST"]) && !empty($amp_conf["CDRDBTYPE"])) {
    $db_hash = array('mysql' => 'mysql', 'postgres' => 'pgsql');
    $db_type = $db_hash[$amp_conf["CDRDBTYPE"]];
    $db_host = $amp_conf["CDRDBHOST"];
    $db_port = empty($amp_conf["CDRDBPORT"]) ? '' : ':' . $amp_conf["CDRDBPORT"];
    $db_user = empty($amp_conf["CDRDBUSER"]) ? $amp_conf["AMPDBUSER"] : $amp_conf["CDRDBUSER"];
    $db_pass = empty($amp_conf["CDRDBPASS"]) ? $amp_conf["AMPDBPASS"] : $amp_conf["CDRDBPASS"];
    $datasource = $db_type . '://' . $db_user . ':' . $db_pass . '@' . $db_host . $db_port . '/' . $db_name;
    $dbcdr = DB::connect($datasource);
    // attempt connection
    if (DB::isError($dbcdr)) {
        die_freepbx($dbcdr->getDebugInfo());
    }
} else {
    $dbcdr = $db;
}
// Make sure they're both escaped with backticks.
if ($db_name[0] !== '`') {
    $db_name = "`{$db_name}`";
}
if ($db_table_name[0] !== '`') {
    $db_table_name = "`{$db_table_name}`";
}
// For use in encrypt-decrypt of path and filename for the recordings
include_once "crypt.php";
switch ($action) {
    case 'cdr_play':
    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("*"));
        }
    }
Пример #26
0
 function splice($section, $extension, $priority, $command, $new_tag = "", $offset = 0, $fixmultiplelabels = false)
 {
     $extension = ' ' . $extension . ' ';
     // if the priority is a tag, then we look for the real priority to insert it before that
     // tag. If the tag does not exists, then we put it at the very end which may not be
     // desired but it puts it somewhere
     //
     if (!$this->is_priority(trim($priority))) {
         $new_priority = false;
         $count = 0;
         $label = $priority;
         if (isset($this->_exts[$section][$extension])) {
             foreach ($this->_exts[$section][$extension] as $pri => $curr_command) {
                 if ($curr_command['tag'] == $priority) {
                     $new_priority = $count;
                     break;
                 }
                 $count++;
             }
         }
         if ($new_priority === false) {
             $priority = $count;
         } else {
             $priority = $new_priority + $offset;
             if ($priority < 0) {
                 $priority = 0;
             }
         }
     }
     if ($priority == 0) {
         $basetag = '1';
         if (!isset($this->_exts[$section][$extension][0])) {
             die_freepbx("died in splice {$section} {$extension}");
         }
         // we'll be defining a new pri "1", so change existing "1" to "n"
         $this->_exts[$section][$extension][0]['basetag'] = 'n';
     } else {
         $basetag = 'n';
     }
     $newcommand = array('basetag' => $basetag, 'tag' => $new_tag, 'addpri' => '', 'cmd' => $command);
     /* This will remove the tag value if entry is being added after an existing tag as
      *  if we do not do this then asterisk will jump to the last label
      */
     if ($fixmultiplelabels && $offset > 0 && $new_tag == $label && $new_priority && isset($this->_exts[$section][$extension])) {
         $newcommand['new_tag'] = '';
     }
     /* This will fix an issue with having multiple entrypoint labels by the same name,
      *  asterisk by default seems to pick the last one. This will remove all labels by
      *  the same name so that the new entry will go in at the top correctly
      */
     if ($fixmultiplelabels && $offset <= 0 && $new_tag == $label && isset($this->_exts[$section][$extension])) {
         foreach ($this->_exts[$section][$extension] as $_ext_k => &$_ext_v) {
             if ($_ext_v['tag'] != $label) {
                 continue;
             }
             $_ext_v['tag'] = '';
         }
     }
     /* This little routine from http://ca.php.net/array_splice overcomes 
      *  problems that array_splice has with multidmentional arrays
      */
     $array = isset($this->_exts[$section][$extension]) ? $this->_exts[$section][$extension] : array();
     $ky = $priority;
     $val = $newcommand;
     $n = $ky;
     foreach ($array as $key => $value) {
         $backup_array[$key] = $array[$key];
     }
     $upper_limit = count($array);
     while ($n <= $upper_limit) {
         if ($n == $ky) {
             $array[$n] = $val;
             // echo $n;
         } else {
             $i = $n - "1";
             $array[$n] = $backup_array[$i];
         }
         $n++;
     }
     // apply our newly modified array
     //echo "Splicing [$section] $extension\n";
     $this->_exts[$section][$extension] = $array;
     //print_r($this->_exts[$section][$extension]);
 }
Пример #27
0
<?php

if (!defined('FREEPBX_IS_AUTH')) {
    die('No direct script access allowed');
}
global $db;
global $amp_conf;
$autoincrement = $amp_conf["AMPDBENGINE"] == "sqlite" || $amp_conf["AMPDBENGINE"] == "sqlite3" ? "AUTOINCREMENT" : "AUTO_INCREMENT";
$sql[] = "CREATE TABLE IF NOT EXISTS pinsets ( \n\tpinsets_id INTEGER NOT NULL PRIMARY KEY {$autoincrement}, \n\tpasswords LONGTEXT, \n\tdescription VARCHAR( 50 ) , \n\taddtocdr TINYINT( 1 ) , \n\tdeptname VARCHAR( 50 )\n)";
$sql[] = "CREATE TABLE IF NOT EXISTS pinset_usage ( \n\tpinsets_id INTEGER NOT NULL,\n\tdispname VARCHAR( 30 ),\n\tforeign_id VARCHAR( 30 ),\n  PRIMARY KEY (`dispname`, `foreign_id`)\n)";
foreach ($sql as $q) {
    $check = $db->query($q);
    if (DB::IsError($check)) {
        die_freepbx("Can not create pinset tables\n" . $check->getDebugInfo());
    }
}
outn(_("checking if migration required.."));
$sql = "SELECT `used_by` FROM pinsets WHERE used_by != ''";
$check = $db->getRow($sql, DB_FETCHMODE_ASSOC);
if (!DB::IsError($check)) {
    outn(_("migrating.."));
    /* We need to now migrate from from the old format of dispname_id where the only supported dispname
         so far has been "routing" and the "id" used was the imperfect nnn-name. As it truns out, it was
         possible to have the same route name perfiously so we will try to detect that. This was really ugly
         so if we can't find stuff we will simply report errors and let the user go back and fix things.
       */
    $sql = "SELECT * FROM pinsets";
    $pinsets = $db->getAll($sql, DB_FETCHMODE_ASSOC);
    if (DB::IsError($result)) {
        out(_("unknown error fetching table data"));
        out(_("migration aborted"));
Пример #28
0
    function out($text)
    {
        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 {
    echo "<br>Success, wrote ({$includecontent})<br> to file ({$filename})<br><br>";
    fclose($handle);
} else {
    echo "The file {$filename} is not writable";
}
?>
Verifying / Installing cronjob into the FreePBX cron manager.<br>
<?php 
$sql = "SELECT * FROM `cronmanager` WHERE `module` = 't' LIMIT 1;";
$res = $db->query($sql);
if ($res->numRows() != 2) {
    $sql = "INSERT INTO\tcronmanager (module,id,time,freq,command) VALUES ('trunkalarm','every_day',23,24,'/usr/bin/find /var/lib/asterisk/sounds/tts -name \"*.wav\" -mtime +1 -exec rm {} \\\\;')";
    $sql = "INSERT INTO\tcronmanager (module,id,time,freq,command) VALUES ('trunkalarm',*,15,*,'/asterisk/agi-bin/monitor_trunk.php \\\\;')";
    $check = $db->query($sql);
    if (DB::IsError($check)) {
        die_freepbx("Can not create values in cronmanager table: " . $check->getMessage() . "\n");
    }
}
?>
Verifying / Creating TTS Folder.<br>
<?php 
$parm_tts_dir = '/var/lib/asterisk/sounds/tts';
if (!is_dir($parm_tts_dir)) {
    mkdir($parm_tts_dir, 0775);
}
?>
Creating Feature Code.<br>
<?php 
// Register FeatureCode - Trunk Monitor;
$fcc = new featurecode('trunkalarm', 'trunkalarm');
$fcc->setDescription('Trunk Alarm');
Пример #30
0
function __core_routing_getroutetrunks($route)
{
    global $db;
    $sql = "SELECT DISTINCT args FROM extensions WHERE context = 'outrt-" . $route . "' AND (args LIKE 'dialout-trunk,%' OR args LIKE 'dialout-enum,%' OR args LIKE 'dialout-dundi,%') ORDER BY CAST(priority as UNSIGNED) ";
    $results = $db->getAll($sql);
    if (DB::IsError($results)) {
        die_freepbx($results->getMessage());
    }
    $trunks = array();
    foreach ($results as $row) {
        if (preg_match('/^dialout-trunk,(\\d+)/', $row[0], $matches)) {
            // check in_array -- even though we did distinct
            // we still might get ${EXTEN} and ${EXTEN:1} if they used | to split a pattern
            if (!in_array("OUT_" . $matches[1], $trunks)) {
                $trunks[] = "OUT_" . $matches[1];
            }
        } else {
            if (preg_match('/^dialout-enum,(\\d+)/', $row[0], $matches)) {
                if (!in_array("OUT_" . $matches[1], $trunks)) {
                    $trunks[] = "OUT_" . $matches[1];
                }
            } else {
                if (preg_match('/^dialout-dundi,(\\d+)/', $row[0], $matches)) {
                    if (!in_array("OUT_" . $matches[1], $trunks)) {
                        $trunks[] = "OUT_" . $matches[1];
                    }
                }
            }
        }
    }
    return $trunks;
}