diff --git a/app/dialplans/resources/classes/dialplan.php b/app/dialplans/resources/classes/dialplan.php
index 59e08d8869..aac9cf37b6 100644
--- a/app/dialplans/resources/classes/dialplan.php
+++ b/app/dialplans/resources/classes/dialplan.php
@@ -29,10 +29,10 @@ include "root.php";
if (!class_exists('dialplan')) {
class dialplan {
//variables
- public $db;
public $result;
public $domain_uuid;
public $dialplan_uuid;
+ public $dialplan_detail_uuid;
public $xml;
public $json;
public $display_type;
@@ -70,151 +70,114 @@ include "root.php";
//class constructor
public function __construct() {
- //connect to the database if not connected
- if (!$this->db) {
- require_once "resources/classes/database.php";
- $database = new database;
- $database->connect();
- $this->db = $database->db;
- }
-
//set the default value
$this->dialplan_global = false;
}
public function dialplan_add() {
-
- $sql = "insert into v_dialplans ";
- $sql .= "(";
- $sql .= "domain_uuid, ";
- $sql .= "app_uuid, ";
- $sql .= "dialplan_uuid, ";
- $sql .= "dialplan_name, ";
- $sql .= "dialplan_number, ";
- $sql .= "dialplan_destination, ";
- $sql .= "dialplan_continue, ";
- $sql .= "dialplan_order, ";
- $sql .= "dialplan_context, ";
- $sql .= "dialplan_enabled, ";
- $sql .= "dialplan_description ";
- $sql .= ")";
- $sql .= "values ";
- $sql .= "(";
- if ($this->dialplan_global) {
- $sql .= "null, ";
- }
- else {
- $sql .= "'".check_str($this->domain_uuid)."', ";
- }
- $sql .= "'".check_str($this->app_uuid)."', ";
- $sql .= "'".check_str($this->dialplan_uuid)."', ";
- $sql .= "'".check_str($this->dialplan_name)."', ";
- $sql .= "'".check_str($this->dialplan_number)."', ";
- $sql .= "'".check_str($this->dialplan_destination)."', ";
- $sql .= "'".check_str($this->dialplan_continue)."', ";
- $sql .= "'".check_str($this->dialplan_order)."', ";
- $sql .= "'".check_str($this->dialplan_context)."', ";
- $sql .= "'".check_str($this->dialplan_enabled)."', ";
- $sql .= "'".check_str($this->dialplan_description)."' ";
- $sql .= ")";
- $this->db->exec(check_sql($sql));
- unset($sql);
- } //end function
+ //build insert array
+ $array['dialplans'][0]['dialplan_uuid'] = $this->dialplan_uuid;
+ $array['dialplans'][0]['domain_uuid'] = !$this->dialplan_global ? $this->domain_uuid : null;
+ $array['dialplans'][0]['app_uuid'] = $this->app_uuid;
+ $array['dialplans'][0]['dialplan_name'] = $this->dialplan_name;
+ $array['dialplans'][0]['dialplan_number'] = $this->dialplan_number;
+ $array['dialplans'][0]['dialplan_destination'] = $this->dialplan_destination;
+ $array['dialplans'][0]['dialplan_continue'] = $this->dialplan_continue;
+ $array['dialplans'][0]['dialplan_order'] = $this->dialplan_order;
+ $array['dialplans'][0]['dialplan_context'] = $this->dialplan_order;
+ $array['dialplans'][0]['dialplan_enabled'] = $this->dialplan_enabled;
+ $array['dialplans'][0]['dialplan_description'] = $this->dialplan_description;
+ //grant temporary permissions
+ $p = new permissions;
+ $p->add('dialplan_add', 'temp');
+ //execute insert
+ $database = new database;
+ $database->app_name = 'dialplans';
+ $database->app_uuid = '742714e5-8cdf-32fd-462c-cbe7e3d655db';
+ $database->save($array);
+ unset($array);
+ //revoke temporary permissions
+ $p->delete('dialplan_add', 'temp');
+ }
public function dialplan_update() {
-
- $sql = "update v_dialplans set ";
- $sql .= "dialplan_name = '".check_str($this->dialplan_name)."', ";
- if (strlen($this->dialplan_continue) > 0) {
- $sql .= "dialplan_continue = '".check_str($this->dialplan_continue)."', ";
- }
- $sql .= "dialplan_order = '".check_str($this->dialplan_order)."', ";
- $sql .= "dialplan_context = '".check_str($this->dialplan_context)."', ";
- $sql .= "dialplan_enabled = '".check_str($this->dialplan_enabled)."', ";
- $sql .= "dialplan_description = '".check_str($this->dialplan_description)."' ";
- $sql .= "where (domain_uuid = '".check_str($this->domain_uuid)."' or domain_uuid is null) ";
- $sql .= "and dialplan_uuid = '".check_str($this->dialplan_uuid)."' ";
- //echo "sql: ".$sql."
";
- $this->db->query($sql);
- unset($sql);
+ //build update array
+ $array['dialplans'][0]['dialplan_uuid'] = $this->dialplan_uuid;
+ $array['dialplans'][0]['dialplan_name'] = $this->dialplan_name;
+ if (strlen($this->dialplan_continue) > 0) {
+ $array['dialplans'][0]['dialplan_continue'] = $this->dialplan_continue;
+ }
+ $array['dialplans'][0]['dialplan_order'] = $this->dialplan_order;
+ $array['dialplans'][0]['dialplan_context'] = $this->dialplan_context;
+ $array['dialplans'][0]['dialplan_enabled'] = $this->dialplan_enabled;
+ $array['dialplans'][0]['dialplan_description'] = $this->dialplan_description;
+ //grant temporary permissions
+ $p = new permissions;
+ $p->add('dialplan_edit', 'temp');
+ //execute update
+ $database = new database;
+ $database->app_name = 'dialplans';
+ $database->app_uuid = '742714e5-8cdf-32fd-462c-cbe7e3d655db';
+ $database->save($array);
+ unset($array);
+ //revoke temporary permissions
+ $p->delete('dialplan_edit', 'temp');
}
public function dialplan_detail_add() {
-
- $dialplan_detail_uuid = uuid();
- $sql = "insert into v_dialplan_details ";
- $sql .= "(";
- $sql .= "dialplan_detail_uuid, ";
- $sql .= "domain_uuid, ";
- $sql .= "dialplan_uuid, ";
- $sql .= "dialplan_detail_tag, ";
- $sql .= "dialplan_detail_order, ";
- $sql .= "dialplan_detail_type, ";
- $sql .= "dialplan_detail_data, ";
- $sql .= "dialplan_detail_break, ";
- $sql .= "dialplan_detail_inline, ";
- $sql .= "dialplan_detail_group ";
- $sql .= ") ";
- $sql .= "values ";
- $sql .= "( ";
- $sql .= "'".$dialplan_detail_uuid."', ";
- if ($this->dialplan_global) {
- $sql .= "null, ";
- }
- else {
- $sql .= "'".check_str($this->domain_uuid)."', ";
- }
- $sql .= "'".check_str($this->dialplan_uuid)."', ";
- $sql .= "'".check_str($this->dialplan_detail_tag)."', ";
- $sql .= "'".check_str($this->dialplan_detail_order)."', ";
- $sql .= "'".check_str($this->dialplan_detail_type)."', ";
- $sql .= "'".check_str($this->dialplan_detail_data)."', ";
- if (strlen($this->dialplan_detail_break) == 0) {
- $sql .= "null, ";
- }
- else {
- $sql .= "'".check_str($this->dialplan_detail_break)."', ";
- }
- if (strlen($this->dialplan_detail_inline) == 0) {
- $sql .= "null, ";
- }
- else {
- $sql .= "'".check_str($this->dialplan_detail_inline)."', ";
- }
- if (strlen($this->dialplan_detail_group) == 0) {
- $sql .= "null ";
- }
- else {
- $sql .= "'".check_str($this->dialplan_detail_group)."' ";
- }
- $sql .= ")";
- //echo $sql."\n\n";
- $this->db->exec(check_sql($sql));
- unset($sql);
- } //end function
+ //build insert array
+ $dialplan_detail_uuid = uuid();
+ $array['dialplan_details'][0]['dialplan_detail_uuid'] = $dialplan_detail_uuid;
+ $array['dialplan_details'][0]['domain_uuid'] = !$this->dialplan_global ? $this->domain_uuid : null;
+ $array['dialplan_details'][0]['dialplan_uuid'] = $this->dialplan_uuid;
+ $array['dialplan_details'][0]['dialplan_detail_tag'] = $this->dialplan_detail_tag;
+ $array['dialplan_details'][0]['dialplan_detail_order'] = $this->dialplan_detail_order;
+ $array['dialplan_details'][0]['dialplan_detail_type'] = $this->dialplan_detail_type;
+ $array['dialplan_details'][0]['dialplan_detail_data'] = $this->dialplan_detail_data;
+ $array['dialplan_details'][0]['dialplan_detail_break'] = strlen($this->dialplan_detail_break) != 0 ? $this->dialplan_detail_break : null;
+ $array['dialplan_details'][0]['dialplan_detail_inline'] = strlen($this->dialplan_detail_inline) != 0 ? $this->dialplan_detail_inline : null;
+ $array['dialplan_details'][0]['dialplan_detail_group'] = strlen($this->dialplan_detail_group) != 0 ? $this->dialplan_detail_group : null;
+ //grant temporary permissions
+ $p = new permissions;
+ $p->add('dialplan_detail_add', 'temp');
+ //execute insert
+ $database = new database;
+ $database->app_name = 'dialplans';
+ $database->app_uuid = '742714e5-8cdf-32fd-462c-cbe7e3d655db';
+ $database->save($array);
+ unset($array);
+ //revoke temporary permissions
+ $p->delete('dialplan_detail_add', 'temp');
+ }
public function dialplan_detail_update() {
-
- $sql = "update v_dialplans set ";
- $sql .= "dialplan_detail_order = '".check_str($this->dialplan_detail_order)."', ";
- $sql .= "dialplan_detail_type = '".check_str($this->dialplan_detail_type)."', ";
- $sql .= "dialplan_detail_data = '".check_str($this->dialplan_detail_data)."', ";
- if (strlen($this->dialplan_detail_break) > 0) {
- $sql .= "dialplan_detail_break = '".check_str($this->dialplan_detail_break)."', ";
- }
- if (strlen($this->dialplan_detail_inline) > 0) {
- $sql .= "dialplan_detail_inline = '".check_str($this->dialplan_detail_inline)."', ";
- }
- if (strlen($this->dialplan_detail_group) > 0) {
- $sql .= "dialplan_detail_group = '".check_str($this->dialplan_detail_group)."', ";
- }
- $sql .= "dialplan_detail_tag = '".check_str($this->dialplan_detail_tag)."' ";
- $sql .= "where (domain_uuid = '".check_str($this->domain_uuid)."' or domain_uuid is null) ";
- $sql .= "and dialplan_uuid = '".check_str($this->dialplan_uuid)."' ";
- //echo "sql: ".$sql."
";
- $this->db->query($sql);
- unset($sql);
- } //end function
+ //build update array
+ $array['dialplan_details'][0]['dialplan_detail_uuid'] = $this->dialplan_detail_uuid;
+ $array['dialplan_details'][0]['dialplan_detail_tag'] = $this->dialplan_detail_tag;
+ $array['dialplan_details'][0]['dialplan_detail_order'] = $this->dialplan_detail_order;
+ $array['dialplan_details'][0]['dialplan_detail_type'] = $this->dialplan_detail_type;
+ $array['dialplan_details'][0]['dialplan_detail_data'] = $this->dialplan_detail_data;
+ if (strlen($this->dialplan_detail_break) != 0) {
+ $array['dialplan_details'][0]['dialplan_detail_break'] = $this->dialplan_detail_break;
+ }
+ if (strlen($this->dialplan_detail_inline) != 0) {
+ $array['dialplan_details'][0]['dialplan_detail_inline'] = $this->dialplan_detail_inline;
+ }
+ if (strlen($this->dialplan_detail_group) != 0) {
+ $array['dialplan_details'][0]['dialplan_detail_group'] = $this->dialplan_detail_group;
+ }
+ //grant temporary permissions
+ $p = new permissions;
+ $p->add('dialplan_detail_edit', 'temp');
+ //execute update
+ $database = new database;
+ $database->app_name = 'dialplans';
+ $database->app_uuid = '742714e5-8cdf-32fd-462c-cbe7e3d655db';
+ $database->save($array);
+ unset($array);
+ //revoke temporary permissions
+ $p->delete('dialplan_detail_edit', 'temp');
+ }
public function restore_advanced_xml() {
$switch_dialplan_dir = $this->switch_dialplan_dir;
@@ -244,39 +207,25 @@ include "root.php";
}
private function app_uuid_exists() {
- $sql = "select domain_uuid from v_dialplans ";
- $sql .= "where (domain_uuid = '".$this->domain_uuid."' or domain_uuid is null) ";
- $sql .= "and app_uuid = '".$this->app_uuid."' ";
- $prep_statement = $this->db->prepare(check_sql($sql));
- if ($prep_statement) {
- $prep_statement->execute();
- $result = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
- if (count($result)) {
- return true;
- }
- else {
- return false;
- }
- }
- unset($sql, $prep_statement, $result);
+ $sql = "select count(*) from v_dialplans ";
+ $sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
+ $sql .= "and app_uuid = :app_uuid ";
+ $parameters['domain_uuid'] = $this->domain_uuid;
+ $parameters['app_uuid'] = $this->app_uuid;
+ $database = new database;
+ return $database->select($sql, $parameters, 'column') != 0 ? true : false;
+ unset($sql, $parameters);
}
public function dialplan_exists() {
- $sql = "select domain_uuid from v_dialplans ";
- $sql .= "where (domain_uuid = '".$this->domain_uuid."' or domain_uuid is null)";
- $sql .= "and dialplan_uuid = '".$this->dialplan_uuid."' ";
- $prep_statement = $this->db->prepare(check_sql($sql));
- if ($prep_statement) {
- $prep_statement->execute();
- $result = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
- if (count($result)) {
- return true;
- }
- else {
- return false;
- }
- }
- unset($sql, $prep_statement, $result);
+ $sql = "select count(*) from v_dialplans ";
+ $sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null)";
+ $sql .= "and dialplan_uuid = :dialplan_uuid ";
+ $parameters['domain_uuid'] = $this->domain_uuid;
+ $parameters['dialplan_uuid'] = $this->dialplan_uuid;
+ $database = new database;
+ return $database->select($sql, $parameters, 'column') != 0 ? true : false;
+ unset($sql, $parameters);
}
public function import() {
@@ -312,11 +261,10 @@ include "root.php";
//get the list of domains
if (!isset($_SESSION['domains'])) {
- $sql = "select * from v_domains; ";
- $prep_statement = $this->db->prepare($sql);
- $prep_statement->execute();
- $_SESSION['domains'] = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
- unset($sql, $prep_statement);
+ $sql = "select * from v_domains ";
+ $database = new database;
+ $_SESSION['domains'] = $database->select($sql, null, 'all');
+ unset($sql);
}
//check if the dialplan app uuid exists
@@ -330,8 +278,6 @@ include "root.php";
}
//check if the dialplan exists
if (!$this->app_uuid_exists()) {
- //start the transaction
- $this->db->beginTransaction();
//get the attributes
$this->dialplan_uuid = uuid();
$this->dialplan_name = $dialplan['extension']['@attributes']['name'];
@@ -439,8 +385,6 @@ include "root.php";
$x++;
}
}
- //end the transaction
- $this->db->commit();
//update the session array
$_SESSION['upgrade']['app_defaults']['dialplans'][$domain['domain_name']][]['dialplan_name'] = $this->dialplan_name;
}
@@ -455,10 +399,12 @@ include "root.php";
//check the session array if it doesn't exist then build the array
if (!is_array($_SESSION[$_SESSION['domain_uuid']]['outbound_routes'])) {
//get the outbound routes from the database
- $sql = "select * from v_dialplans as d, v_dialplan_details as s ";
+ $sql = "select * ";
+ $sql .= "from v_dialplans as d, ";
+ $sql .= "v_dialplan_details as s ";
$sql .= "where ";
$sql .= "( ";
- $sql .= "d.domain_uuid = '".$this->domain_uuid."' ";
+ $sql .= "d.domain_uuid = :domain_uuid ";
$sql .= "or d.domain_uuid is null ";
$sql .= ") ";
$sql .= "and d.app_uuid = '8c914ec3-9fc0-8ab5-4cda-6c9288bdc9a3' ";
@@ -469,92 +415,98 @@ include "root.php";
$sql .= "d.dialplan_name asc, ";
$sql .= "d.dialplan_uuid asc, ";
$sql .= "s.dialplan_detail_group asc, ";
- $sql .= "CASE s.dialplan_detail_tag ";
- $sql .= "WHEN 'condition' THEN 1 ";
- $sql .= "WHEN 'action' THEN 2 ";
- $sql .= "WHEN 'anti-action' THEN 3 ";
- $sql .= "ELSE 100 END, ";
+ $sql .= "case s.dialplan_detail_tag ";
+ $sql .= "when 'condition' then 1 ";
+ $sql .= "when 'action' then 2 ";
+ $sql .= "when 'anti-action' then 3 ";
+ $sql .= "else 100 end, ";
$sql .= "s.dialplan_detail_order asc ";
- $prep_statement = $this->db->prepare(check_sql($sql));
- $prep_statement->execute();
- $dialplans = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
- unset($prep_statement, $sql);
+ $parameters['domain_uuid'] = $this->domain_uuid;
+ $database = new database;
+ $dialplans = $database->select($sql, $parameters, 'all');
+ unset($sql, $parameters);
$x = 0; $y = 0;
- if (isset($dialplans)) foreach ($dialplans as &$row) {
- //if the previous dialplan uuid has not been set then set it
- if (!isset($previous_dialplan_uuid)) { $previous_dialplan_uuid = $row['dialplan_uuid']; }
+ if (isset($dialplans) && @sizeof($dialplans) != 0) {
+ foreach ($dialplans as &$row) {
+ //if the previous dialplan uuid has not been set then set it
+ if (!isset($previous_dialplan_uuid)) { $previous_dialplan_uuid = $row['dialplan_uuid']; }
- //increment dialplan ordinal number
- if ($previous_dialplan_uuid != $row['dialplan_uuid']) {
- $x++; $y = 0;
- }
+ //increment dialplan ordinal number
+ if ($previous_dialplan_uuid != $row['dialplan_uuid']) {
+ $x++; $y = 0;
+ }
- //build the array
- $array[$x]['dialplan_uuid'] = $row['dialplan_uuid'];
- $array[$x]['dialplan_context'] = $row['dialplan_context'];
- $array[$x]['dialplan_name'] = $row['dialplan_name'];
- $array[$x]['dialplan_continue'] = $row['dialplan_continue'];
- $array[$x]['dialplan_order'] = $row['dialplan_order'];
- $array[$x]['dialplan_enabled'] = $row['dialplan_enabled'];
- $array[$x]['dialplan_description'] = $row['dialplan_description'];
- if (strlen($row['dialplan_detail_uuid']) > 0) {
- $array[$x]['dialplan_details'][$y]['dialplan_uuid'] = $row['dialplan_uuid'];
- $array[$x]['dialplan_details'][$y]['dialplan_detail_uuid'] = $row['dialplan_detail_uuid'];
- $array[$x]['dialplan_details'][$y]['dialplan_detail_tag'] = $row['dialplan_detail_tag'];
- $array[$x]['dialplan_details'][$y]['dialplan_detail_type'] = $row['dialplan_detail_type'];
- $array[$x]['dialplan_details'][$y]['dialplan_detail_data'] = $row['dialplan_detail_data'];
- $y++;
- }
+ //build the array
+ $array[$x]['dialplan_uuid'] = $row['dialplan_uuid'];
+ $array[$x]['dialplan_context'] = $row['dialplan_context'];
+ $array[$x]['dialplan_name'] = $row['dialplan_name'];
+ $array[$x]['dialplan_continue'] = $row['dialplan_continue'];
+ $array[$x]['dialplan_order'] = $row['dialplan_order'];
+ $array[$x]['dialplan_enabled'] = $row['dialplan_enabled'];
+ $array[$x]['dialplan_description'] = $row['dialplan_description'];
+ if (strlen($row['dialplan_detail_uuid']) > 0) {
+ $array[$x]['dialplan_details'][$y]['dialplan_uuid'] = $row['dialplan_uuid'];
+ $array[$x]['dialplan_details'][$y]['dialplan_detail_uuid'] = $row['dialplan_detail_uuid'];
+ $array[$x]['dialplan_details'][$y]['dialplan_detail_tag'] = $row['dialplan_detail_tag'];
+ $array[$x]['dialplan_details'][$y]['dialplan_detail_type'] = $row['dialplan_detail_type'];
+ $array[$x]['dialplan_details'][$y]['dialplan_detail_data'] = $row['dialplan_detail_data'];
+ $y++;
+ }
- //set the previous dialplan_uuid
- $previous_dialplan_uuid = $row['dialplan_uuid'];
- }
- unset ($prep_statement);
- //set the session array
- $_SESSION[$_SESSION['domain_uuid']]['outbound_routes'] = $array;
- } //end if !is_array
- //find the matching outbound routes
- if (isset($_SESSION[$_SESSION['domain_uuid']]['outbound_routes'])) foreach ($_SESSION[$_SESSION['domain_uuid']]['outbound_routes'] as $row) {
- if (isset($row['dialplan_details'])) foreach ($row['dialplan_details'] as $field) {
- if ($field['dialplan_detail_tag'] == "condition") {
- if ($field['dialplan_detail_type'] == "destination_number") {
- $dialplan_detail_data = $field['dialplan_detail_data'];
- $pattern = '/'.$dialplan_detail_data.'/';
- preg_match($pattern, $destination_number, $matches, PREG_OFFSET_CAPTURE);
- if (count($matches) == 0) {
- $regex_match = false;
- }
- else {
- $regex_match = true;
- $regex_match_1 = $matches[1][0];
- $regex_match_2 = $matches[2][0];
- $regex_match_3 = $matches[3][0];
- }
+ //set the previous dialplan_uuid
+ $previous_dialplan_uuid = $row['dialplan_uuid'];
}
}
- if ($regex_match) {
- //get the variables
- if ($field[dialplan_detail_type] == "set" && $field[dialplan_detail_tag] == "action") {
- //only set variables with values not variables
- if (strpos($field[dialplan_detail_data], '$') === false) {
- $this->variables .= $field[dialplan_detail_data].",";
+ //set the session array
+ $_SESSION[$_SESSION['domain_uuid']]['outbound_routes'] = $array;
+ }
+
+ //find the matching outbound routes
+ if (isset($_SESSION[$_SESSION['domain_uuid']]['outbound_routes'])) {
+ foreach ($_SESSION[$_SESSION['domain_uuid']]['outbound_routes'] as $row) {
+ if (isset($row['dialplan_details'])) {
+ foreach ($row['dialplan_details'] as $field) {
+ if ($field['dialplan_detail_tag'] == "condition") {
+ if ($field['dialplan_detail_type'] == "destination_number") {
+ $dialplan_detail_data = $field['dialplan_detail_data'];
+ $pattern = '/'.$dialplan_detail_data.'/';
+ preg_match($pattern, $destination_number, $matches, PREG_OFFSET_CAPTURE);
+ if (count($matches) == 0) {
+ $regex_match = false;
+ }
+ else {
+ $regex_match = true;
+ $regex_match_1 = $matches[1][0];
+ $regex_match_2 = $matches[2][0];
+ $regex_match_3 = $matches[3][0];
+ }
}
}
- //process the $x detail data variables
- if ($field['dialplan_detail_tag'] == "action" && $field['dialplan_detail_type'] == "bridge" && $dialplan_detail_data != "\${enum_auto_route}") {
- $dialplan_detail_data = $field['dialplan_detail_data'];
- $dialplan_detail_data = str_replace("\$1", $regex_match_1, $dialplan_detail_data);
- $dialplan_detail_data = str_replace("\$2", $regex_match_2, $dialplan_detail_data);
- $dialplan_detail_data = str_replace("\$3", $regex_match_3, $dialplan_detail_data);
- $this->bridges = $dialplan_detail_data;
- }
- }
- }
- } // end if isset
- } // outbound_routes
+ if ($regex_match) {
+ //get the variables
+ if ($field[dialplan_detail_type] == "set" && $field[dialplan_detail_tag] == "action") {
+ //only set variables with values not variables
+ if (strpos($field[dialplan_detail_data], '$') === false) {
+ $this->variables .= $field[dialplan_detail_data].",";
+ }
+ }
+ //process the $x detail data variables
+ if ($field['dialplan_detail_tag'] == "action" && $field['dialplan_detail_type'] == "bridge" && $dialplan_detail_data != "\${enum_auto_route}") {
+ $dialplan_detail_data = $field['dialplan_detail_data'];
+ $dialplan_detail_data = str_replace("\$1", $regex_match_1, $dialplan_detail_data);
+ $dialplan_detail_data = str_replace("\$2", $regex_match_2, $dialplan_detail_data);
+ $dialplan_detail_data = str_replace("\$3", $regex_match_3, $dialplan_detail_data);
+ $this->bridges = $dialplan_detail_data;
+ }
+ } //if
+ } //foreach
+ } //if
+ } //foreach
+ } //if
+ } //function
//reads dialplan details from the database to build the xml
- public function xml () {
+ public function xml() {
//set the xml array and then concatenate the array to a string
/* $xml = "\n"; */
@@ -572,35 +524,37 @@ include "root.php";
if ($this->source == "dialplans") {
//get the data using a join between the dialplans and dialplan details tables
$sql = "select dialplan_uuid, dialplan_xml ";
- $sql .= "from v_dialplans \n";
- if (isset($this->uuid)) {
- $sql .= "where dialplan_uuid = '".$this->uuid."' \n";
+ $sql .= "from v_dialplans ";
+ if (is_uuid($this->uuid)) {
+ $sql .= "where dialplan_uuid = :dialplan_uuid ";
+ $parameters['dialplan_uuid'] = $this->uuid;
}
else {
if (isset($this->context)) {
if ($this->context == "public" || substr($this->context, 0, 7) == "public@" || substr($this->context, -7) == ".public") {
- $sql .= "where dialplan_context = '" . $this->context . "' \n";
+ $sql .= "where dialplan_context = :dialplan_context ";
}
else {
- $sql .= "where (dialplan_context = '" . $this->context . "' or dialplan_context = '\${domain_name}') \n";
+ $sql .= "where (dialplan_context = :dialplan_context or dialplan_context = '\${domain_name}') ";
}
- $sql .= "and dialplan_enabled = 'true' \n";
+ $sql .= "and dialplan_enabled = 'true' ";
+ $parameters['dialplan_context'] = $this->context;
}
}
if ($this->is_empty == "dialplan_xml") {
- $sql .= "and p.dialplan_xml is null \n";
+ $sql .= "and p.dialplan_xml is null ";
}
- $sql .= "order by \n";
- $sql .= "dialplan_context asc, \n";
- $sql .= "dialplan_order asc \n";
- //echo $sql;
- $prep_statement = $this->db->prepare(check_sql($sql));
- $prep_statement->execute();
- $results = $prep_statement->fetchAll(PDO::FETCH_NAMED);
- //echo $sql;
- foreach ($results as $row) {
- $dialplans[$row["dialplan_uuid"]] = $row["dialplan_xml"];
+ $sql .= "order by ";
+ $sql .= "dialplan_context asc, ";
+ $sql .= "dialplan_order asc ";
+ $database = new database;
+ $results = $database->select($sql, $parameters, 'all');
+ if (is_array($result) && @sizeof($result) != 0) {
+ foreach ($results as $row) {
+ $dialplans[$row["dialplan_uuid"]] = $row["dialplan_xml"];
+ }
}
+ unset($sql, $parameters, $results, $row);
}
//get the dialplans from the dialplan details
@@ -608,277 +562,278 @@ include "root.php";
//get the data using a join between the dialplans and dialplan details tables
$sql = "select ";
- $sql .= "p.domain_uuid, p.dialplan_uuid, p.app_uuid, p.dialplan_context, p.dialplan_name, p.dialplan_number, \n";
- $sql .= "p.dialplan_continue, p.dialplan_order, p.dialplan_enabled, p.dialplan_description, \n";
- $sql .= "s.dialplan_detail_uuid, s.dialplan_detail_tag, s.dialplan_detail_type, s.dialplan_detail_data, \n";
- $sql .= "s.dialplan_detail_break, s.dialplan_detail_inline, s.dialplan_detail_group, s.dialplan_detail_order \n";
- $sql .= "from v_dialplans as p, v_dialplan_details as s \n";
- $sql .= "where p.dialplan_uuid = s.dialplan_uuid \n";
+ $sql .= "p.domain_uuid, p.dialplan_uuid, p.app_uuid, p.dialplan_context, p.dialplan_name, p.dialplan_number, ";
+ $sql .= "p.dialplan_continue, p.dialplan_order, p.dialplan_enabled, p.dialplan_description, ";
+ $sql .= "s.dialplan_detail_uuid, s.dialplan_detail_tag, s.dialplan_detail_type, s.dialplan_detail_data, ";
+ $sql .= "s.dialplan_detail_break, s.dialplan_detail_inline, s.dialplan_detail_group, s.dialplan_detail_order ";
+ $sql .= "from v_dialplans as p, v_dialplan_details as s ";
+ $sql .= "where p.dialplan_uuid = s.dialplan_uuid ";
if ($this->is_empty == "dialplan_xml") {
- $sql .= "and p.dialplan_xml is null \n";
+ $sql .= "and p.dialplan_xml is null ";
}
if (isset($this->context)) {
if ($this->context == "public" || substr($this->context, 0, 7) == "public@" || substr($this->context, -7) == ".public") {
- $sql .= "and p.dialplan_context = '" . $this->context . "' \n";
+ $sql .= "and p.dialplan_context = :dialplan_context ";
}
else {
- $sql .= "and (p.dialplan_context = '" . $this->context . "' or p.dialplan_context = '\${domain_name}') \n";
+ $sql .= "and (p.dialplan_context = :dialplan_context or p.dialplan_context = '\${domain_name}') ";
}
- $sql .= "and p.dialplan_enabled = 'true' \n";
+ $sql .= "and p.dialplan_enabled = 'true' ";
+ $parameters['dialplan_context'] = $this->context;
}
- if (isset($this->uuid)) {
- $sql .= "and p.dialplan_uuid = '".$this->uuid."' \n";
- $sql .= "and s.dialplan_uuid = '".$this->uuid."' \n";
+ if (is_uuid($this->uuid)) {
+ $sql .= "and p.dialplan_uuid = :dialplan_uuid ";
+ $sql .= "and s.dialplan_uuid = :dialplan_uuid ";
+ $parameters['dialplan_uuid'] = $this->uuid;
}
- $sql .= "order by \n";
- $sql .= "p.dialplan_order asc, \n";
- $sql .= "p.dialplan_name asc, \n";
- $sql .= "p.dialplan_uuid asc, \n";
- $sql .= "s.dialplan_detail_group asc, \n";
- $sql .= "CASE s.dialplan_detail_tag \n";
- $sql .= "WHEN 'condition' THEN 1 \n";
- $sql .= "WHEN 'action' THEN 2 \n";
- $sql .= "WHEN 'anti-action' THEN 3 \n";
- $sql .= "ELSE 100 END, \n";
- $sql .= "s.dialplan_detail_order asc \n";
- $prep_statement = $this->db->prepare(check_sql($sql));
- $prep_statement->execute();
- $results = $prep_statement->fetchAll(PDO::FETCH_NAMED);
-
- //debug info
- //echo "sql: $sql\n";
- //echo "
\n"; - //print_r($results); - //echo "\n"; - //exit; + $sql .= "order by "; + $sql .= "p.dialplan_order asc, "; + $sql .= "p.dialplan_name asc, "; + $sql .= "p.dialplan_uuid asc, "; + $sql .= "s.dialplan_detail_group asc, "; + $sql .= "case s.dialplan_detail_tag "; + $sql .= "when 'condition' then 1 "; + $sql .= "when 'action' then 2 "; + $sql .= "when 'anti-action' then 3 "; + $sql .= "else 100 end, "; + $sql .= "s.dialplan_detail_order asc "; + $database = new database; + $results = $database->select($sql, $parameters, 'all'); + unset($sql, $parameters); //loop through the results to get the xml from the dialplan_xml field or from dialplan details table $x = 0; - foreach ($results as $row) { - //clear flag pass - $pass = false; + if (is_array($result) && @sizeof($result) != 0) { + foreach ($results as $row) { + //clear flag pass + $pass = false; - //get the dialplan - $domain_uuid = $row["domain_uuid"]; - $dialplan_uuid = $row["dialplan_uuid"]; - //$app_uuid = $row["app_uuid"]; - $this->context = $row["dialplan_context"]; - $dialplan_name = $row["dialplan_name"]; - //$dialplan_number = $row["dialplan_number"]; - $dialplan_continue = $row["dialplan_continue"]; - //$dialplan_order = $row["dialplan_order"]; - //$dialplan_enabled = $row["dialplan_enabled"]; - //$dialplan_description = $row["dialplan_description"]; + //get the dialplan + $domain_uuid = $row["domain_uuid"]; + $dialplan_uuid = $row["dialplan_uuid"]; + //$app_uuid = $row["app_uuid"]; + $this->context = $row["dialplan_context"]; + $dialplan_name = $row["dialplan_name"]; + //$dialplan_number = $row["dialplan_number"]; + $dialplan_continue = $row["dialplan_continue"]; + //$dialplan_order = $row["dialplan_order"]; + //$dialplan_enabled = $row["dialplan_enabled"]; + //$dialplan_description = $row["dialplan_description"]; - //$get the dialplan details - //$dialplan_detail_uuid = $row["dialplan_detail_uuid"]; - $dialplan_detail_tag = $row["dialplan_detail_tag"]; - $dialplan_detail_type = $row["dialplan_detail_type"]; - $dialplan_detail_data = $row["dialplan_detail_data"]; - $dialplan_detail_break = $row["dialplan_detail_break"]; - $dialplan_detail_inline = $row["dialplan_detail_inline"]; - $dialplan_detail_group = $row["dialplan_detail_group"]; - //$dialplan_detail_order = $row["dialplan_detail_order; + //$get the dialplan details + //$dialplan_detail_uuid = $row["dialplan_detail_uuid"]; + $dialplan_detail_tag = $row["dialplan_detail_tag"]; + $dialplan_detail_type = $row["dialplan_detail_type"]; + $dialplan_detail_data = $row["dialplan_detail_data"]; + $dialplan_detail_break = $row["dialplan_detail_break"]; + $dialplan_detail_inline = $row["dialplan_detail_inline"]; + $dialplan_detail_group = $row["dialplan_detail_group"]; + //$dialplan_detail_order = $row["dialplan_detail_order; - //remove $$ and replace with $ - $dialplan_detail_data = str_replace("$$", "$", $dialplan_detail_data); + //remove $$ and replace with $ + $dialplan_detail_data = str_replace("$$", "$", $dialplan_detail_data); - //get the dialplan detail inline - $detail_inline = ""; - if ($dialplan_detail_inline) { - if (strlen($dialplan_detail_inline) > 0) { - $detail_inline = " inline=\"" . $dialplan_detail_inline . "\""; - } - } - - //close the tags - if ($dialplan_tag_status != "closed") { - if (($previous_dialplan_uuid != $dialplan_uuid) || ($previous_dialplan_detail_group != $dialplan_detail_group)) { - if ($condition_tag_status != "closed") { - if ($condition_attribute && (strlen($condition_attribute) > 0)) { - $xml .= "
\n"; - //print_r($access_control_nodes); - //echo "\n"; - } + $parameters['access_control_uuid'] = $access_control_uuid; + $database = new database; + $access_control_nodes = $database->select($sql, $parameters, 'all'); + unset($sql, $parameters); - //get the existing nodes - $sql = "select * from v_sip_profiles "; + //get the sip profile name + $sql = "select sip_profile_name from v_sip_profiles "; $sql .= "where sip_profile_enabled = 'true' "; $sql .= "order by sip_profile_name asc "; $sql .= "limit 1; "; if ($this->debug) { echo $sql."
\n";
- //print_r($array);
- //echo "\n";
- //exit;
+ unset($array);
//update the dialplan xml
$dialplans = new dialplan;
@@ -612,63 +588,97 @@ if (!class_exists('providers')) {
//delete each node
$nodes = $this->nodes($provider);
- foreach ($nodes as $row) {
- $sql = "delete from v_access_control_nodes ";
- $sql .= "where access_control_node_uuid = '".$row['uuid']."'; ";
- $this->db->query($sql);
- unset($sql);
+ if (is_array($nodes) && @sizeof($nodes) != 0) {
+ $x = 0;
+ foreach ($nodes as $row) {
+ //build delete array
+ $array['access_control_nodes'][$x]['access_control_node_uuid'] = $row['uuid'];
+ $x++;
+ }
+ if (is_array($array) && @sizeof($array) != 0) {
+ //grant temporary permissions
+ $p = new permissions;
+ $p->add('access_control_node_delete', 'temp');
+ //execute delete
+ $database = new database;
+ $database->app_name = 'providers';
+ $database->app_uuid = 'b12946a2-f5f7-4eb9-8b79-7d90b89f8aef';
+ $database->delete($array);
+ unset($array);
+ //revoke temporary permissions
+ $p->delete('access_control_node_delete', 'temp');
+ }
}
- //get the existing nodes
- $sql = "select * from v_sip_profiles ";
+ //get the sip profile name
+ $sql = "select sip_profile_name from v_sip_profiles ";
$sql .= "where sip_profile_enabled = 'true' ";
$sql .= "order by sip_profile_name asc ";
$sql .= "limit 1; ";
if ($this->debug) {
echo $sql."
\n";
}
- $prep_statement = $this->db->prepare(check_sql($sql));
- if ($prep_statement) {
- $prep_statement->execute();
- $result = $prep_statement->fetch(PDO::FETCH_ASSOC);
- $sip_profile_name = $result['sip_profile_name'];
- }
+ $database = new database;
+ $sip_profile_name = $database->select($sql, null, 'column');
+ unset($sql);
//create the event socket connection
$fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
//get the hostname
- if ($fp) { $sip_profile_hostname = event_socket_request($fp, 'api switchname'); }
+ if ($fp) { $sip_profile_hostname = event_socket_request($fp, 'api switchname'); }
//delete outbound routes
$outbound_routes = $this->outbound_routes($provider);
+ $x = 0;
foreach ($outbound_routes as $row) {
- //delete child data
- $sql = "delete from v_dialplan_details ";
- $sql .= "where dialplan_uuid = '".$row['dialplan_uuid']."'; ";
- $this->db->query($sql);
- unset($sql);
-
- //delete parent data
- $sql = "delete from v_dialplans ";
- $sql .= "where dialplan_uuid = '".$row['dialplan_uuid']."'; ";
- $this->db->query($sql);
- unset($sql);
+ //build child data delete array
+ $array['dialplan_details'][$x]['dialplan_uuid'] = $row['dialplan_uuid'];
+ //build parent delete array
+ $array['dialplans'][$x]['dialplan_uuid'] = $row['dialplan_uuid'];
+ $x++;
+ }
+ if (is_array($array) && @sizeof($array) != 0) {
+ //grant temporary permissions
+ $p = new permissions;
+ $p->add('dialplan_detail_delete', 'temp');
+ $p->add('dialplan_delete', 'temp');
+ //execute delete
+ $database = new database;
+ $database->app_name = 'providers';
+ $database->app_uuid = 'b12946a2-f5f7-4eb9-8b79-7d90b89f8aef';
+ $database->delete($array);
+ unset($array);
+ //revoke temporary permissions
+ $p->delete('dialplan_detail_delete', 'temp');
+ $p->delete('dialplan_delete', 'temp');
}
//delete each gateway
$gateways = $this->gateways($provider);
+ $x = 0;
foreach ($gateways as $row) {
//stop the gateway
- $cmd = "sofia profile ".$sip_profile_name." killgw ".$row['uuid'];
- if ($fp) { event_socket_request($fp, "api ".$cmd); }
+ $cmd = "sofia profile ".$sip_profile_name." killgw ".$row['uuid'];
+ if ($fp) { event_socket_request($fp, "api ".$cmd); }
- //delete the gateway
- $sql = "delete from v_gateways ";
- $sql .= "where gateway_uuid = '".$row['uuid']."'; ";
- $this->db->query($sql);
- unset($sql);
+ //build gateway delete array
+ $array['gateways'][$x]['gateway_uuid'] = $row['uuid'];
+ $x++;
+ }
+ if (is_array($array) && @sizeof($array) != 0) {
+ //grant temporary permissions
+ $p = new permissions;
+ $p->add('gateway_delete', 'temp');
+ //execute delete
+ $database = new database;
+ $database->app_name = 'providers';
+ $database->app_uuid = 'b12946a2-f5f7-4eb9-8b79-7d90b89f8aef';
+ $database->delete($array);
+ unset($array);
+ //revoke temporary permissions
+ $p->delete('gateway_delete', 'temp');
}
//clear the cache
@@ -681,7 +691,7 @@ if (!class_exists('providers')) {
if ($fp) { event_socket_request($fp, "api sofia profile ".$sip_profile_name." rescan"); }
}
- } //end scripts class
+ }
}
/*
@@ -691,4 +701,4 @@ if (!class_exists('providers')) {
$provider->setup();
*/
-?>
+?>
\ No newline at end of file
diff --git a/app/registrations/resources/classes/registrations.php b/app/registrations/resources/classes/registrations.php
index 7a123530ef..84bac197cc 100644
--- a/app/registrations/resources/classes/registrations.php
+++ b/app/registrations/resources/classes/registrations.php
@@ -8,19 +8,11 @@
if (!class_exists('registrations')) {
class registrations {
- public $db;
-
/**
* Called when the object is created
*/
public function __construct() {
- //connect to the database if not connected
- if (!$this->db) {
- require_once "resources/classes/database.php";
- $database = new database;
- $database->connect();
- $this->db = $database->db;
- }
+
}
/**
@@ -47,105 +39,105 @@ if (!class_exists('registrations')) {
//get the default settings
$sql = "select sip_profile_name from v_sip_profiles ";
$sql .= "where sip_profile_enabled = 'true' ";
- if ($profile == 'all' || $profile == '') {
- $prep_statement = $this->db->prepare($sql);
+ if ($profile != 'all' && $profile != '') {
+ $sql .= "and sip_profile_name = :sip_profile_name ";
+ $parameters['sip_profile_name'] = $profile;
}
- else {
- $sql .= "and sip_profile_name=:sip_profile_name ";
- $prep_statement = $this->db->prepare($sql);
- $prep_statement->bindParam(':sip_profile_name', $profile);
- }
- $prep_statement->execute();
- $sip_profiles = $prep_statement->fetchAll(PDO::FETCH_NAMED);
- foreach ($sip_profiles as $field) {
+ $database = new database;
+ $sip_profiles = $database->select($sql, $parameters, 'all');
+ if (is_array($sip_profiles) && @sizeof($sip_profiles) != 0) {
+ foreach ($sip_profiles as $field) {
- //get sofia status profile information including registrations
- $cmd = "api sofia xmlstatus profile ".$field['sip_profile_name']." reg";
- $xml_response = trim(event_socket_request($fp, $cmd));
- if ($xml_response == "Invalid Profile!") { $xml_response = "".$text['label-message']." "; }
- $xml_response = str_replace("", "", $xml_response);
- $xml_response = str_replace(" ", "", $xml_response);
- if (strlen($xml_response) > 101) {
- try {
- $xml = new SimpleXMLElement($xml_response);
+ //get sofia status profile information including registrations
+ $cmd = "api sofia xmlstatus profile ".$field['sip_profile_name']." reg";
+ $xml_response = trim(event_socket_request($fp, $cmd));
+ if ($xml_response == "Invalid Profile!") { $xml_response = "".$text['label-message']." "; }
+ $xml_response = str_replace("", "", $xml_response);
+ $xml_response = str_replace(" ", "", $xml_response);
+ if (strlen($xml_response) > 101) {
+ try {
+ $xml = new SimpleXMLElement($xml_response);
+ }
+ catch(Exception $e) {
+ echo $e->getMessage();
+ exit;
+ }
+ $array = json_decode(json_encode($xml), true);
}
- catch(Exception $e) {
- echo $e->getMessage();
- exit;
+
+ //normalize the array
+ if (is_array($array) && !is_array($array['registrations']['registration'][0])) {
+ $row = $array['registrations']['registration'];
+ unset($array['registrations']['registration']);
+ $array['registrations']['registration'][0] = $row;
}
- $array = json_decode(json_encode($xml) , true);
- }
- //normalize the array
- if (is_array($array) && !is_array($array['registrations']['registration'][0])) {
- $row = $array['registrations']['registration'];
- unset($array['registrations']['registration']);
- $array['registrations']['registration'][0] = $row;
- }
+ //set the registrations array
+ if (is_array($array)) {
+ foreach ($array['registrations']['registration'] as $row) {
- //set the registrations array
- if (is_array($array)) {
- foreach ($array['registrations']['registration'] as $row) {
+ //build the registrations array
+ //$registrations[0] = $row;
+ $user_array = explode('@', $row['user']);
+ $registrations[$id]['user'] = $row['user'] ?: '';
+ $registrations[$id]['call-id'] = $row['call-id'] ?: '';
+ $registrations[$id]['contact'] = $row['contact'] ?: '';
+ $registrations[$id]['sip-auth-user'] = $row['sip-auth-user'] ?: '';
+ $registrations[$id]['agent'] = $row['agent'] ?: '';
+ $registrations[$id]['host'] = $row['host'] ?: '';
+ $registrations[$id]['network-port'] = $row['network-port'] ?: '';
+ $registrations[$id]['sip-auth-realm'] = $row['sip-auth-realm'] ?: '';
+ $registrations[$id]['mwi-account'] = $row['mwi-account'] ?: '';
+ $registrations[$id]['status'] = $row['status'] ?: '';
+ $registrations[$id]['ping-time'] = $row['ping-time'] ?: '';
+ $registrations[$id]['sip_profile_name'] = $field['sip_profile_name'];
- //build the registrations array
- //$registrations[0] = $row;
- $user_array = explode('@', $row['user']);
- $registrations[$id]['user'] = $row['user'] ?: '';
- $registrations[$id]['call-id'] = $row['call-id'] ?: '';
- $registrations[$id]['contact'] = $row['contact'] ?: '';
- $registrations[$id]['sip-auth-user'] = $row['sip-auth-user'] ?: '';
- $registrations[$id]['agent'] = $row['agent'] ?: '';
- $registrations[$id]['host'] = $row['host'] ?: '';
- $registrations[$id]['network-port'] = $row['network-port'] ?: '';
- $registrations[$id]['sip-auth-realm'] = $row['sip-auth-realm'] ?: '';
- $registrations[$id]['mwi-account'] = $row['mwi-account'] ?: '';
- $registrations[$id]['status'] = $row['status'] ?: '';
- $registrations[$id]['ping-time'] = $row['ping-time'] ?: '';
- $registrations[$id]['sip_profile_name'] = $field['sip_profile_name'];
-
- //get network-ip to url or blank
- if(isset($row['network-ip'])) {
- $registrations[$id]['network-ip'] = $row['network-ip'];
- } else {
- $registrations[$id]['network-ip'] = '';
- }
-
- //get the LAN IP address if it exists replace the external ip
- $call_id_array = explode('@', $row['call-id']);
- if (isset($call_id_array[1])) {
- $agent = $row['agent'];
- $lan_ip = $call_id_array[1];
- if (false !== stripos($agent, 'grandstream')) {
- $lan_ip = str_ireplace(
- array('A','B','C','D','E','F','G','H','I','J'),
- array('0','1','2','3','4','5','6','7','8','9'),
- $lan_ip);
+ //get network-ip to url or blank
+ if (isset($row['network-ip'])) {
+ $registrations[$id]['network-ip'] = $row['network-ip'];
+ }
+ else {
+ $registrations[$id]['network-ip'] = '';
}
- elseif(1 === preg_match('/\ACL750A/', $agent)) {
- //required for GIGASET Sculpture CL750A puts _ in it's lan ip account
- $lan_ip = preg_replace('/_/', '.', $lan_ip);
- }
- $registrations[$id]['lan-ip'] = $lan_ip;
- } else {
- $registrations[$id]['lan-ip'] = '';
- }
- //remove unrelated domains
- if (count($_SESSION["domains"]) > 1) {
- if (!(permission_exists('registration_all') && $profile == "all")) {
- if ($registrations[$id]['sip-auth-realm'] == $_SESSION['domain_name']) {}
- elseif ($user_array[1] == $_SESSION['domain_name']){}
- else {
- unset($registrations[$id]);
+ //get the LAN IP address if it exists replace the external ip
+ $call_id_array = explode('@', $row['call-id']);
+ if (isset($call_id_array[1])) {
+ $agent = $row['agent'];
+ $lan_ip = $call_id_array[1];
+ if (false !== stripos($agent, 'grandstream')) {
+ $lan_ip = str_ireplace(
+ array('A','B','C','D','E','F','G','H','I','J'),
+ array('0','1','2','3','4','5','6','7','8','9'),
+ $lan_ip);
+ }
+ elseif(1 === preg_match('/\ACL750A/', $agent)) {
+ //required for GIGASET Sculpture CL750A puts _ in it's lan ip account
+ $lan_ip = preg_replace('/_/', '.', $lan_ip);
+ }
+ $registrations[$id]['lan-ip'] = $lan_ip;
+ }
+ else {
+ $registrations[$id]['lan-ip'] = '';
+ }
+
+ //remove unrelated domains
+ if (count($_SESSION["domains"]) > 1) {
+ if (!(permission_exists('registration_all') && $profile == "all")) {
+ if ($registrations[$id]['sip-auth-realm'] == $_SESSION['domain_name']) {}
+ else if ($user_array[1] == $_SESSION['domain_name']) {}
+ else {
+ unset($registrations[$id]);
+ }
}
}
- }
- //increment the array id
- $id++;
+ //increment the array id
+ $id++;
+ }
+ unset($array);
}
- unset($array);
- }
+ }
}
//return the registrations array
@@ -166,17 +158,14 @@ if (!class_exists('registrations')) {
//get the default settings
$sql = "select sip_profile_name from v_sip_profiles ";
$sql .= "where sip_profile_enabled = 'true' ";
- if ($profile == 'all' || $profile == '') {
- $prep_statement = $this->db->prepare($sql);
+ if ($profile != 'all' && $profile != '') {
+ $sql .= "and sip_profile_name = :sip_profile_name ";
+ $parameters['sip_profile_name'] = $profile;
}
- else {
- $sql .= "and sip_profile_name=:sip_profile_name ";
- $prep_statement = $this->db->prepare($sql);
- $prep_statement->bindParam(':sip_profile_name', $profile);
- }
- $prep_statement->execute();
- $sip_profiles = $prep_statement->fetchAll(PDO::FETCH_NAMED);
- foreach ($sip_profiles as $field) {
+ $database = new database;
+ $sip_profiles = $database->select($sql, $parameters, 'all');
+ if (is_array($sip_profiles) && @sizeof($sip_profiles) != 0) {
+ foreach ($sip_profiles as $field) {
//get sofia status profile information including registrations
$cmd = "api sofia xmlstatus profile ".$field['sip_profile_name']." reg";
@@ -193,10 +182,11 @@ if (!class_exists('registrations')) {
echo $e->getMessage();
exit;
}
- $array = json_decode(json_encode($xml) , true);
+ $array = json_decode(json_encode($xml), true);
$count = $count + count($array['registrations']['registration']);
}
+ }
}
//return the registrations count
@@ -205,10 +195,11 @@ if (!class_exists('registrations')) {
}
}
+
/*
$obj = new registrations;
$registrations = $obj->get('all');
print($registrations);
*/
-?>
+?>
\ No newline at end of file
diff --git a/app/scripts/resources/classes/scripts.php b/app/scripts/resources/classes/scripts.php
index 7d84ed560b..62ae17a7dd 100644
--- a/app/scripts/resources/classes/scripts.php
+++ b/app/scripts/resources/classes/scripts.php
@@ -53,8 +53,7 @@ if (!class_exists('scripts')) {
* Called when the object is created
*/
public function __construct() {
- //connect to the database if not connected
- require_once "resources/classes/database.php";
+ //get database properties
$database = new database;
$database->connect();
$this->db = $database->db;
@@ -137,35 +136,16 @@ if (!class_exists('scripts')) {
$this->db_path = str_replace("\\", "/", $this->db_path);
//get the odbc information
- $sql = "select count(*) as num_rows from v_databases ";
+ $sql = "select * from v_databases ";
$sql .= "where database_driver = 'odbc' ";
- $prep_statement = $this->db->prepare($sql);
- if ($prep_statement) {
- $prep_statement->execute();
- $row = $prep_statement->fetch(PDO::FETCH_ASSOC);
- unset($prep_statement);
- if ($row['num_rows'] > 0) {
- $odbc_num_rows = $row['num_rows'];
-
- $sql = "select * from v_databases ";
- $sql .= "where database_driver = 'odbc' ";
- $prep_statement = $this->db->prepare(check_sql($sql));
- $prep_statement->execute();
- $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
- if (is_array($result)) {
- foreach ($result as &$row) {
- $this->dsn_name = $row["database_name"];
- $this->dsn_username = $row["database_username"];
- $this->dsn_password = $row["database_password"];
- break; //limit to 1 row
- }
- unset ($prep_statement);
- }
- }
- else {
- $odbc_num_rows = '0';
- }
+ $database = new database;
+ $row = $database->select($sql, null, 'row');
+ if (is_array($row) && @sizeof($row) != 0) {
+ $this->dsn_name = $row["database_name"];
+ $this->dsn_username = $row["database_username"];
+ $this->dsn_password = $row["database_password"];
}
+ unset($sql, $row);
//get the recordings directory
if (is_array($_SESSION['switch']['recordings'])) {
@@ -183,7 +163,8 @@ if (!class_exists('scripts')) {
//find the location to write the config.lua
if (is_dir("/etc/fusionpbx")){
$config = "/etc/fusionpbx/config.lua";
- } elseif (is_dir("/usr/local/etc/fusionpbx")){
+ }
+ else if (is_dir("/usr/local/etc/fusionpbx")){
$config = "/usr/local/etc/fusionpbx/config.lua";
}
else {
@@ -346,9 +327,11 @@ if (!class_exists('scripts')) {
unset($tmp);
fclose($fout);
}
- } //end config_lua
- } //end scripts class
+ }
+
+ }
}
+
/*
//example use
@@ -356,4 +339,5 @@ if (!class_exists('scripts')) {
$obj = new scripts;
$obj->write_config();
*/
-?>
+
+?>
\ No newline at end of file
diff --git a/app/voicemails/resources/classes/voicemail.php b/app/voicemails/resources/classes/voicemail.php
index d2f0f43c3e..ce0adb456f 100644
--- a/app/voicemails/resources/classes/voicemail.php
+++ b/app/voicemails/resources/classes/voicemail.php
@@ -26,7 +26,6 @@
//define the voicemail class
class voicemail {
- public $db;
public $domain_uuid;
public $domain_name;
public $voicemail_uuid;
@@ -37,14 +36,6 @@
public $app_uuid;
public function __construct() {
- //connect to the database if not connected
- if (!$this->db) {
- require_once "resources/classes/database.php";
- $database = new database;
- $database->connect();
- $this->db = $database->db;
- }
-
//set the application specific uuid
$this->app_uuid = 'b523c2d2-64cd-46f1-9520-ca4b4098e044';
@@ -63,60 +54,55 @@
public function get_voicemail_id() {
//check if for valid input
- if (is_uuid($this->voicemail_uuid) && is_uuid($this->domain_uuid) ) {
- //input is valid
- }
- else {
+ if (!is_uuid($this->voicemail_uuid) || !is_uuid($this->domain_uuid)) {
return false;
}
//get the voicemail id if it isn't set already
if (!isset($this->voicemail_id)) {
$sql = "select voicemail_id from v_voicemails ";
- $sql .= "where domain_uuid = '".$this->domain_uuid."' ";
- $sql .= "and voicemail_uuid = '".$this->voicemail_uuid."' ";
- $prep_statement = $this->db->prepare(check_sql($sql));
- $prep_statement->execute();
- $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
- if (is_array($result)) foreach ($result as &$row) {
- $this->voicemail_id = $row["voicemail_id"];
+ $sql .= "where domain_uuid = :domain_uuid ";
+ $sql .= "and voicemail_uuid = :voicemail_uuid ";
+ $parameters['domain_uuid'] = $this->domain_uuid;
+ $parameters['voicemail_uuid'] = $this->voicemail_uuid;
+ $database = new database;
+ $voicemail_id = $database->select($sql, $parameters, 'column');
+ if (is_numeric($voicemail_id)) {
+ $this->voicemail_id = $voicemail_id;
}
- unset ($prep_statement);
+ unset($sql, $parameters, $voicemail_id);
}
}
public function voicemails() {
//check if for valid input
- if (is_uuid($this->domain_uuid)) {
- //input is valid
- }
- else {
+ if (!is_uuid($this->domain_uuid)) {
return false;
}
//set the voicemail id and voicemail uuid arrays
- if (isset($_SESSION['user']['extension'])) foreach ($_SESSION['user']['extension'] as $index => $row) {
- if (strlen($row['number_alias']) > 0) {
- $voicemail_ids[$index]['voicemail_id'] = $row['number_alias'];
- }
- else {
- $voicemail_ids[$index]['voicemail_id'] = $row['user'];
+ if (isset($_SESSION['user']['extension'])) {
+ foreach ($_SESSION['user']['extension'] as $index => $row) {
+ $voicemail_ids[$index]['voicemail_id'] = strlen($row['number_alias']) > 0 ? $row['number_alias'] : $row['user'];
}
}
- if (isset($_SESSION['user']['voicemail'])) foreach ($_SESSION['user']['voicemail'] as $row) {
- if (strlen($row['voicemail_uuid']) > 0) {
- $voicemail_uuids[]['voicemail_uuid'] = $row['voicemail_uuid'];
+ if (isset($_SESSION['user']['voicemail'])) {
+ foreach ($_SESSION['user']['voicemail'] as $row) {
+ if (strlen($row['voicemail_uuid']) > 0) {
+ $voicemail_uuids[]['voicemail_uuid'] = $row['voicemail_uuid'];
+ }
}
}
//get the uuid and voicemail_id
$sql = "select * from v_voicemails ";
- $sql .= "where domain_uuid = '".$this->domain_uuid."' ";
- if (strlen($this->voicemail_uuid) > 0) {
+ $sql .= "where domain_uuid = :domain_uuid ";
+ if (is_uuid($this->voicemail_uuid)) {
if (permission_exists('voicemail_delete')) {
//view specific voicemail box usually reserved for an admin or superadmin
- $sql .= "and voicemail_uuid = '".$this->voicemail_uuid."' ";
+ $sql .= "and voicemail_uuid = :voicemail_uuid ";
+ $parameters['voicemail_uuid'] = $this->voicemail_uuid;
}
else {
//ensure that the requested voicemail box is assigned to this user
@@ -124,10 +110,10 @@
if (is_array($voicemail_uuids)) {
foreach($voicemail_uuids as $row) {
if ($voicemail_uuid == $row['voicemail_uuid']) {
- $sql .= "and voicemail_uuid = '".$row['voicemail_uuid']."' ";
+ $sql .= "and voicemail_uuid = :voicemail_uuid ";
+ $parameters['voicemail_uuid'] = $row['voicemail_uuid'];
$found = true;
}
- $x++;
}
}
//id requested is not owned by the user return no results
@@ -137,20 +123,18 @@
}
}
else {
- $x = 0;
- if (count($voicemail_ids) > 0) {
+ if (is_array($voicemail_ids) && @sizeof($voicemail_ids) != 0) {
//show only the assigned voicemail ids
- $sql .= "and (";
- if (is_array($voicemail_ids)) foreach($voicemail_ids as $row) {
- if ($x == 0) {
- $sql .= "voicemail_id = '".$row['voicemail_id']."' ";
- }
- else {
- $sql .= " or voicemail_id = '".$row['voicemail_id']."'";
- }
+ $x = 0;
+ $sql .= "and ( ";
+ foreach($voicemail_ids as $row) {
+ $sql_where_or[] = "voicemail_id = :voicemail_id_".$x;
+ $parameters['voicemail_id_'.$x] = $row['voicemail_id'];
$x++;
}
- $sql .= ")";
+ $sql .= implode(' or ', $sql_where_or);
+ $sql .= ") ";
+ unset($sql_where_or);
}
else {
//no assigned voicemail ids so return no results
@@ -158,10 +142,10 @@
}
}
$sql .= "order by voicemail_id asc ";
- $prep_statement = $this->db->prepare(check_sql($sql));
- $prep_statement->execute();
- $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
- unset ($prep_statement);
+ $parameters['domain_uuid'] = $this->domain_uuid;
+ $database = new database;
+ $result = $database->select($sql, $parameters, 'all');
+ unset($sql, $parameters);
return $result;
}
@@ -170,13 +154,15 @@
$voicemails = $this->voicemails();
//add the voicemail messages to the array
- if (is_array($voicemails)) foreach ($voicemails as &$row) {
- //get the voicemail messages
- $this->voicemail_uuid = $row['voicemail_uuid'];
- $this->voicemail_id = $row['voicemail_id'];
- $result = $this->voicemail_messages();
- $voicemail_count = count($result);
- $row['messages'] = $result;
+ if (is_array($voicemails)) {
+ foreach ($voicemails as &$row) {
+ //get the voicemail messages
+ $this->voicemail_uuid = $row['voicemail_uuid'];
+ $this->voicemail_id = $row['voicemail_id'];
+ $result = $this->voicemail_messages();
+ $voicemail_count = count($result);
+ $row['messages'] = $result;
+ }
}
//return the array
@@ -186,43 +172,40 @@
public function voicemail_messages() {
//check if for valid input
- if (is_numeric($this->voicemail_id) && is_uuid($this->domain_uuid)) {
- //input is valid
- }
- else {
+ if (!is_numeric($this->voicemail_id) || !is_uuid($this->domain_uuid)) {
return false;
}
//get the message from the database
$sql = "select * from v_voicemail_messages as m, v_voicemails as v ";
- $sql .= "where m.domain_uuid = '$this->domain_uuid' ";
+ $sql .= "where m.domain_uuid = :domain_uuid ";
$sql .= "and m.voicemail_uuid = v.voicemail_uuid ";
- if (is_array($this->voicemail_id)) {
- $sql .= "and (";
+ if (is_array($this->voicemail_id) && @sizeof($this->voicemail_id) != 0) {
$x = 0;
- if (is_array($this->voicemail_id)) foreach($this->voicemail_id as $row) {
- if ($x > 0) {
- $sql .= "or ";
- }
- $sql .= "v.voicemail_id = '".$row['voicemail_id']."' ";
+ $sql .= "and ( ";
+ foreach ($this->voicemail_id as $row) {
+ $sql_where_or[] = "v.voicemail_id = :voicemail_id_".$x;
+ $parameters['voicemail_id_'.$x] = $row['voicemail_id'];
$x++;
}
+ $sql .= implode(' or ', $sql_where_or);
$sql .= ") ";
+ unset($sql_where_or);
}
else {
- $sql .= "and v.voicemail_id = '$this->voicemail_id' ";
+ $sql .= "and v.voicemail_id = :voicemail_id ";
+ $parameters['voicemail_id'] = $this->voicemail_id;
}
if (strlen($this->order_by) == 0) {
$sql .= "order by v.voicemail_id, m.created_epoch desc ";
}
else {
- $sql .= "order by v.voicemail_id, m.$this->order_by $this->order ";
+ $sql .= "order by v.voicemail_id, m.".$this->order_by." ".$this->order." ";
}
- //$sql .= "limit $this->rows_per_page offset $this->offset ";
- $prep_statement = $this->db->prepare(check_sql($sql));
- $prep_statement->execute();
- $result = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
- unset ($prep_statement, $sql);
+ $parameters['domain_uuid'] = $this->domain_uuid;
+ $database = new database;
+ $result = $database->select($sql, $parameters, 'all');
+ unset($sql, $parameters);
//update the array with additional information
if (is_array($result)) {
@@ -259,11 +242,7 @@
$this->get_voicemail_id();
//check if for valid input
- if (is_uuid($this->voicemail_uuid)
- && is_uuid($this->domain_uuid)) {
- //input is valid
- }
- else {
+ if (!is_uuid($this->voicemail_uuid) || !is_uuid($this->domain_uuid)) {
return false;
}
@@ -279,69 +258,67 @@
@rmdir($file_path);
}
- //delete voicemail destinations
- $sql = "delete from v_voicemail_destinations ";
- $sql .= "where domain_uuid = '".$this->domain_uuid."' ";
- $sql .= "and voicemail_uuid = '".$this->voicemail_uuid."' ";
- $prep_statement = $this->db->prepare(check_sql($sql));
- $prep_statement->execute();
- unset($sql, $prep_statement);
+ //build voicemail destinations delete array
+ $array['voicemail_destinations'][0]['domain_uuid'] = $this->domain_uuid;
+ $array['voicemail_destinations'][0]['voicemail_uuid'] = $this->voicemail_uuid;
- //delete voicemail greetings
+ //build voicemail greetings delete array
if (is_numeric($this->voicemail_id)) {
- $sql = "delete from v_voicemail_greetings ";
- $sql .= "where domain_uuid = '".$this->domain_uuid."' ";
- $sql .= "and voicemail_id = '".$this->voicemail_id."' ";
- $prep_statement = $this->db->prepare(check_sql($sql));
- $prep_statement->execute();
- unset($sql, $prep_statement);
+ $array['voicemail_greetings'][0]['domain_uuid'] = $this->domain_uuid;
+ $array['voicemail_greetings'][0]['voicemail_id'] = $this->voicemail_id;
}
- //delete voicemail options
- $sql = "delete from v_voicemail_options ";
- $sql .= "where domain_uuid = '".$this->domain_uuid."' ";
- $sql .= "and voicemail_uuid = '".$this->voicemail_uuid."' ";
- $prep_statement = $this->db->prepare(check_sql($sql));
- $prep_statement->execute();
- unset($sql, $prep_statement);
+ //build voicemail options delete array
+ $array['voicemail_options'][0]['domain_uuid'] = $this->domain_uuid;
+ $array['voicemail_options'][0]['voicemail_uuid'] = $this->voicemail_uuid;
+
+ //build voicemail delete array
+ $array['voicemails'][0]['domain_uuid'] = $this->domain_uuid;
+ $array['voicemails'][0]['voicemail_uuid'] = $this->voicemail_uuid;
+
+ //grant temporary permissions
+ $p = new permissions;
+ $p->add('voicemail_destination_delete', 'temp');
+ if (is_numeric($this->voicemail_id)) {
+ $p->add('voicemail_greeting_delete', 'temp');
+ }
+ $p->add('voicemail_option_delete', 'temp');
+ $p->add('voicemail_delete', 'temp');
+
+ //execute delete
+ $database = new database;
+ $database->app_name = 'voicemails';
+ $database->app_uuid = 'b523c2d2-64cd-46f1-9520-ca4b4098e044';
+ $database->delete($array);
+ unset($array);
+
+ //revoke temporary permissions
+ $p->delete('voicemail_destination_delete', 'temp');
+ if (is_numeric($this->voicemail_id)) {
+ $p->delete('voicemail_greeting_delete', 'temp');
+ }
+ $p->delete('voicemail_option_delete', 'temp');
+ $p->delete('voicemail_delete', 'temp');
- //delete voicemail
- $sql = "delete from v_voicemails ";
- $sql .= "where domain_uuid = '".$this->domain_uuid."' ";
- $sql .= "and voicemail_uuid = '".$this->voicemail_uuid."' ";
- $prep_statement = $this->db->prepare(check_sql($sql));
- $prep_statement->execute();
- unset($sql, $prep_statement);
}
public function message_count() {
//check if for valid input
- if (is_uuid($this->voicemail_uuid) && is_uuid($this->domain_uuid)) {
- //input is valid
- }
- else {
+ if (!is_uuid($this->voicemail_uuid) || !is_uuid($this->domain_uuid)) {
return false;
}
- //get the message count
- $sql = "select count(*) as num_rows from v_voicemail_messages ";
- $sql .= "where domain_uuid = '".$this->domain_uuid."' ";
- $sql .= "and voicemail_uuid = '".$this->voicemail_uuid."' ";
- $prep_statement = $this->db->prepare($sql);
- if ($prep_statement) {
- $prep_statement->execute();
- $row = $prep_statement->fetch(PDO::FETCH_ASSOC);
- if ($row['num_rows'] > 0) {
- $num_rows = $row['num_rows'];
- }
- else {
- $num_rows = '0';
- }
- }
-
//return the message count
- return $num_rows;
+ $sql = "select count(*) from v_voicemail_messages ";
+ $sql .= "where domain_uuid = :domain_uuid ";
+ $sql .= "and voicemail_uuid = :voicemail_uuid ";
+ $parameters['domain_uuid'] = $this->domain_uuid;
+ $parameters['voicemail_uuid'] = $this->voicemail_uuid;
+ $database = new database;
+ return $database->select($sql, $parameters, 'column');
+ unset($sql, $parameters);
+
}
public function message_waiting() {
@@ -362,19 +339,17 @@
$this->get_voicemail_id();
//check if for valid input
- if (is_numeric($this->voicemail_id)
- && is_uuid($this->voicemail_uuid)
- && is_uuid($this->domain_uuid)
- && is_uuid($this->voicemail_message_uuid)) {
- //input is valid
- }
- else {
+ if (!is_numeric($this->voicemail_id)
+ || !is_uuid($this->voicemail_uuid)
+ || !is_uuid($this->domain_uuid)
+ || !is_uuid($this->voicemail_message_uuid)
+ ) {
return false;
}
//delete the recording
$file_path = $_SESSION['switch']['voicemail']['dir']."/default/".$_SESSION['domain_name']."/".$this->voicemail_id;
- if ($this->voicemail_message_uuid != '') {
+ if (is_uuid($this->voicemail_message_uuid)) {
foreach (glob($file_path."/intro_".$this->voicemail_message_uuid.".*") as $file_name) {
unlink($file_name);
}
@@ -388,16 +363,26 @@
}
}
- //delete voicemail message(s)
- $sql = "delete from v_voicemail_messages ";
- $sql .= "where domain_uuid = '".$this->domain_uuid."' ";
- $sql .= "and voicemail_uuid = '".$this->voicemail_uuid."' ";
- if ($this->voicemail_message_uuid != '') {
- $sql .= "and voicemail_message_uuid = '".$this->voicemail_message_uuid."' ";
+ //build delete array
+ $array['voicemail_messages'][0]['domain_uuid'] = $this->domain_uuid;
+ $array['voicemail_messages'][0]['voicemail_uuid'] = $this->voicemail_uuid;
+ if (is_uuid($this->voicemail_message_uuid)) {
+ $array['voicemail_messages'][0]['voicemail_message_uuid'] = $this->voicemail_message_uuid;
}
- $prep_statement = $this->db->prepare(check_sql($sql));
- $prep_statement->execute();
- unset($sql);
+
+ //grant temporary permissions
+ $p = new permissions;
+ $p->add('voicemail_message_delete', 'temp');
+
+ //execute delete
+ $database = new database;
+ $database->app_name = 'voicemails';
+ $database->app_uuid = 'b523c2d2-64cd-46f1-9520-ca4b4098e044';
+ $database->delete($array);
+ unset($array);
+
+ //revoke temporary permissions
+ $p->delete('voicemail_message_delete', 'temp');
//check the message waiting status
$this->message_waiting();
@@ -406,35 +391,38 @@
public function message_toggle() {
//check if for valid input
- if (is_uuid($this->voicemail_uuid)
- && is_uuid($this->domain_uuid)
- && is_uuid($this->voicemail_message_uuid)) {
- //input is valid
- }
- else {
+ if (!is_uuid($this->voicemail_uuid)
+ || !is_uuid($this->domain_uuid)
+ || !is_uuid($this->voicemail_message_uuid)
+ ) {
return false;
}
//get message status
$sql = "select message_status from v_voicemail_messages ";
- $sql .= "where domain_uuid = '".$this->domain_uuid."' ";
- $sql .= "and voicemail_uuid = '".$this->voicemail_uuid."' ";
- $sql .= "and voicemail_message_uuid = '".$this->voicemail_message_uuid."' ";
- $prep_statement = $this->db->prepare(check_sql($sql));
- $prep_statement->execute();
- $row = $prep_statement->fetch(PDO::FETCH_NAMED);
- $new_status = ($row['message_status'] == 'saved') ? 'null' : "'saved'";
- unset($sql, $prep_statement, $row);
+ $sql .= "where voicemail_message_uuid = :voicemail_message_uuid ";
+ $parameters['voicemail_message_uuid'] = $this->voicemail_message_uuid;
+ $database = new database;
+ $new_status = $database->select($sql, $parameters, 'column') != 'saved' ? 'saved' : null;
+ unset($sql, $parameters);
- //set message status
- $sql = "update v_voicemail_messages set ";
- $sql .= "message_status = ".$new_status." ";
- $sql .= "where domain_uuid = '".$this->domain_uuid."' ";
- $sql .= "and voicemail_uuid = '".$this->voicemail_uuid."' ";
- $sql .= "and voicemail_message_uuid = '".$this->voicemail_message_uuid."' ";
- $prep_statement = $this->db->prepare(check_sql($sql));
- $prep_statement->execute();
- unset($sql, $prep_statement);
+ //build message status update array
+ $array['voicemail_messages'][0]['voicemail_message_uuid'] = $this->voicemail_message_uuid;
+ $array['voicemail_messages'][0]['message_status'] = $new_status;
+
+ //grant temporary permissions
+ $p = new permissions;
+ $p->add('voicemail_message_edit', 'temp');
+
+ //execute update
+ $database = new database;
+ $database->app_name = 'voicemails';
+ $database->app_uuid = 'b523c2d2-64cd-46f1-9520-ca4b4098e044';
+ $database->save($array);
+ unset($array);
+
+ //revoke temporary permissions
+ $p->delete('voicemail_message_edit', 'temp');
//check the message waiting status
$this->message_waiting();
@@ -443,24 +431,30 @@
public function message_saved() {
//check if for valid input
- if (is_uuid($this->voicemail_uuid)
- && is_uuid($this->domain_uuid)
- && is_uuid($this->voicemail_message_uuid)) {
- //input is valid
- }
- else {
+ if (!is_uuid($this->voicemail_uuid)
+ || !is_uuid($this->domain_uuid)
+ || !is_uuid($this->voicemail_message_uuid)
+ ) {
return false;
}
- //set the voicemail status to saved
- $sql = "update v_voicemail_messages set ";
- $sql .= "message_status = 'saved' ";
- $sql .= "where domain_uuid = '".$this->domain_uuid."' ";
- $sql .= "and voicemail_uuid = '".$this->voicemail_uuid."' ";
- $sql .= "and voicemail_message_uuid = '".$this->voicemail_message_uuid."' ";
- $prep_statement = $this->db->prepare(check_sql($sql));
- $prep_statement->execute();
- unset($sql, $prep_statement);
+ //build message status update array
+ $array['voicemail_messages'][0]['voicemail_message_uuid'] = $this->voicemail_message_uuid;
+ $array['voicemail_messages'][0]['message_status'] = 'saved';
+
+ //grant temporary permissions
+ $p = new permissions;
+ $p->add('voicemail_message_edit', 'temp');
+
+ //execute update
+ $database = new database;
+ $database->app_name = 'voicemails';
+ $database->app_uuid = 'b523c2d2-64cd-46f1-9520-ca4b4098e044';
+ $database->save($array);
+ unset($array);
+
+ //revoke temporary permissions
+ $p->delete('voicemail_message_edit', 'temp');
//check the message waiting status
$this->message_waiting();
@@ -469,13 +463,11 @@
public function message_download() {
//check if for valid input
- if (is_numeric($this->voicemail_id)
- && is_uuid($this->voicemail_uuid)
- && is_uuid($this->domain_uuid)
- && is_uuid($this->voicemail_message_uuid)) {
- //input is valid
- }
- else {
+ if (!is_numeric($this->voicemail_id)
+ || !is_uuid($this->voicemail_uuid)
+ || !is_uuid($this->domain_uuid)
+ || !is_uuid($this->voicemail_message_uuid)
+ ) {
return false;
}
@@ -490,42 +482,41 @@
//prepare base64 content from db, if enabled
if ($_SESSION['voicemail']['storage_type']['text'] == 'base64') {
- $sql = "select message_base64 from ";
+ $sql = "select message_base64 ";
+ $sql .= "from ";
$sql .= "v_voicemail_messages as m, ";
$sql .= "v_voicemails as v ";
$sql .= "where ";
$sql .= "m.voicemail_uuid = v.voicemail_uuid ";
- $sql .= "and v.voicemail_id = '".$this->voicemail_id."' ";
- $sql .= "and m.voicemail_uuid = '".$this->voicemail_uuid."' ";
- $sql .= "and m.domain_uuid = '".$this->domain_uuid."' ";
- $sql .= "and m.voicemail_message_uuid = '".$this->voicemail_message_uuid."' ";
- $prep_statement = $this->db->prepare(check_sql($sql));
- $prep_statement->execute();
- $result = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
- if (is_array($result)) {
- foreach($result as &$row) {
- if ($row['message_base64'] != '') {
- $message_decoded = base64_decode($row['message_base64']);
- file_put_contents($path.'/msg_'.$this->voicemail_message_uuid.'.ext', $message_decoded);
- $finfo = finfo_open(FILEINFO_MIME_TYPE); //determine mime type (requires PHP >= 5.3.0, must be manually enabled on Windows)
- $file_mime = finfo_file($finfo, $path.'/msg_'.$this->voicemail_message_uuid.'.ext');
- finfo_close($finfo);
- switch ($file_mime) {
- case 'audio/x-wav':
- case 'audio/wav':
- $file_ext = 'wav';
- break;
- case 'audio/mpeg':
- case 'audio/mp3':
- $file_ext = 'mp3';
- break;
- }
- rename($path.'/msg_'.$this->voicemail_message_uuid.'.ext', $path.'/msg_'.$this->voicemail_message_uuid.'.'.$file_ext);
- }
- break;
+ $sql .= "and v.voicemail_id = :voicemail_id ";
+ $sql .= "and m.voicemail_uuid = :voicemail_uuid ";
+ $sql .= "and m.domain_uuid = :domain_uuid ";
+ $sql .= "and m.voicemail_message_uuid = :voicemail_message_uuid ";
+ $parameters['voicemail_id'] = $this->voicemail_id;
+ $parameters['voicemail_uuid'] = $this->voicemail_uuid;
+ $parameters['domain_uuid'] = $this->domain_uuid;
+ $parameters['voicemail_message_uuid'] = $this->voicemail_message_uuid;
+ $database = new database;
+ $message_base64 = $database->select($sql, $parameters, 'column');
+ if ($message_base64 != '') {
+ $message_decoded = base64_decode($message_base64);
+ file_put_contents($path.'/msg_'.$this->voicemail_message_uuid.'.ext', $message_decoded);
+ $finfo = finfo_open(FILEINFO_MIME_TYPE); //determine mime type (requires PHP >= 5.3.0, must be manually enabled on Windows)
+ $file_mime = finfo_file($finfo, $path.'/msg_'.$this->voicemail_message_uuid.'.ext');
+ finfo_close($finfo);
+ switch ($file_mime) {
+ case 'audio/x-wav':
+ case 'audio/wav':
+ $file_ext = 'wav';
+ break;
+ case 'audio/mpeg':
+ case 'audio/mp3':
+ $file_ext = 'mp3';
+ break;
}
+ rename($path.'/msg_'.$this->voicemail_message_uuid.'.ext', $path.'/msg_'.$this->voicemail_message_uuid.'.'.$file_ext);
}
- unset ($sql, $prep_statement, $result, $message_decoded);
+ unset($sql, $parameters, $message_base64, $message_decoded);
}
//prepare and stream the file
@@ -571,7 +562,8 @@
@unlink($path.'/msg_'.$this->voicemail_message_uuid.'.'.$file_ext);
}
- } // download
+ }
+
}
//example voicemail messages
@@ -607,4 +599,4 @@ foreach ($_SESSION['user']['extension'] as $value) {
}
*/
-?>
+?>
\ No newline at end of file
diff --git a/app/voicemails/voicemail_messages.php b/app/voicemails/voicemail_messages.php
index 00700b9dfc..c0925434b2 100644
--- a/app/voicemails/voicemail_messages.php
+++ b/app/voicemails/voicemail_messages.php
@@ -59,7 +59,6 @@
$voicemail_uuid = $_REQUEST["voicemail_uuid"];
if (is_uuid($voicemail_message_uuid) && $voicemail_id != '' && is_uuid($voicemail_uuid)) {
$voicemail = new voicemail;
- $voicemail->db = $db;
$voicemail->domain_uuid = $_SESSION['domain_uuid'];
$voicemail->voicemail_id = $voicemail_id;
$voicemail->voicemail_uuid = $voicemail_uuid;
@@ -76,7 +75,6 @@
//get the voicemail
$vm = new voicemail;
- $vm->db = $db;
$vm->domain_uuid = $_SESSION['domain_uuid'];
$vm->voicemail_uuid = $voicemail_uuid;
$vm->order_by = $order_by;
diff --git a/core/authentication/resources/classes/plugins/database.php b/core/authentication/resources/classes/plugins/database.php
index fc28dd096f..7a8a110450 100644
--- a/core/authentication/resources/classes/plugins/database.php
+++ b/core/authentication/resources/classes/plugins/database.php
@@ -26,85 +26,62 @@ class plugin_database {
*/
function database() {
- //save the database connection to a local variable
- include "root.php";
- require_once "resources/classes/database.php";
- $database = new database;
- $database->connect();
- $db = $database->db;
+ //set the default status
+ $user_authorized = false;
//check the username and password if they don't match then redirect to the login
- $sql = "select * from v_users ";
+ $sql = "select * from v_users where ";
if (strlen($this->key) > 30) {
- $sql .= "where api_key = :key ";
- //$sql .= "where api_key = '".$this->key."' ";
+ $sql .= "api_key = :key ";
+ $parameters['api_key'] = $this->key;
}
else {
- $sql .= "where lower(username) = lower(:username) ";
- //$sql .= "where username = '".$this->username."' ";
+ $sql .= "lower(username) = lower(:username) ";
+ $parameters['username'] = $this->username;
}
- if ($_SESSION["users"]["unique"]["text"] == "global") {
- //unique username - global (example: email address)
- }
- else {
- //unique username - per domain
+ if ($_SESSION["users"]["unique"]["text"] != "global") {
+ //unique username per domain (not globally unique across system - example: email address)
$sql .= "and domain_uuid = :domain_uuid ";
- //$sql .= "and domain_uuid = '".$this->domain_uuid."' ";
+ $parameters['domain_uuid'] = $this->domain_uuid;
}
$sql .= "and (user_enabled = 'true' or user_enabled is null) ";
- $prep_statement = $db->prepare($sql);
- if ($_SESSION["users"]["unique"]["text"] != "global") {
- $prep_statement->bindParam(':domain_uuid', $this->domain_uuid);
- }
- if (strlen($this->key) > 30) {
- $prep_statement->bindParam(':key', $this->key);
- }
- if (strlen($this->username) > 0) {
- $prep_statement->bindParam(':username', $this->username);
- }
- $prep_statement->execute();
- $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
- $user_authorized = false;
- if (is_array($result)) {
- foreach ($result as &$row) {
+ $database = new database;
+ $row = $database->select($sql, $parameters, 'row');
+ if (is_array($row) && @sizeof($row) != 0) {
- //get the domain uuid when users are unique globally
- if ($_SESSION["users"]["unique"]["text"] == "global" && $row["domain_uuid"] != $this->domain_uuid) {
- //set the domain_uuid
- $this->domain_uuid = $row["domain_uuid"];
- $this->domain_name = $_SESSION['domains'][$this->domain_uuid]['domain_name'];
+ //get the domain uuid when users are unique globally
+ if ($_SESSION["users"]["unique"]["text"] == "global" && $row["domain_uuid"] != $this->domain_uuid) {
+ //set the domain_uuid
+ $this->domain_uuid = $row["domain_uuid"];
+ $this->domain_name = $_SESSION['domains'][$this->domain_uuid]['domain_name'];
- //set the domain session variables
- $_SESSION["domain_uuid"] = $this->domain_uuid;
- $_SESSION["domain_name"] = $this->domain_name;
+ //set the domain session variables
+ $_SESSION["domain_uuid"] = $this->domain_uuid;
+ $_SESSION["domain_name"] = $this->domain_name;
- //set the setting arrays
- $domain = new domains();
- $domain->db = $db;
- $domain->set();
- }
+ //set the setting arrays
+ $domain = new domains();
+ $domain->db = $db;
+ $domain->set();
+ }
- //set the user_uuid
- $this->user_uuid = $row['user_uuid'];
- $this->contact_uuid = $row['contact_uuid'];
+ //set the user_uuid
+ $this->user_uuid = $row['user_uuid'];
+ $this->contact_uuid = $row['contact_uuid'];
- //if salt is not defined then use the default salt for backwards compatibility
- if (strlen($row["salt"]) == 0) {
- $row["salt"] = 'e3.7d.12';
- }
+ //if salt is not defined then use the default salt for backwards compatibility
+ if (strlen($row["salt"]) == 0) {
+ $row["salt"] = 'e3.7d.12';
+ }
- //compare the password provided by the user with the one in the database
- if (md5($row["salt"].$this->password) == $row["password"]) {
- $user_authorized = true;
- } elseif (strlen($this->key) > 30 && $this->key == $row["api_key"]) {
- $user_authorized = true;
- } else {
- $user_authorized = false;
- }
+ //compare the password provided by the user with the one in the database
+ if (md5($row["salt"].$this->password) == $row["password"]) {
+ $user_authorized = true;
+ }
+ else if (strlen($this->key) > 30 && $this->key == $row["api_key"]) {
+ $user_authorized = true;
+ }
- //end the loop
- break;
- }
}
unset($result);
@@ -119,14 +96,10 @@ class plugin_database {
$result["domain_uuid"] = $this->domain_uuid;
$result["contact_uuid"] = $this->contact_uuid;
$result["sql"] = $sql;
- if ($user_authorized) {
- $result["authorized"] = "true";
- }
- else {
- $result["authorized"] = "false";
- }
+ $result["authorized"] = $user_authorized ? 'true' : 'false';
+
return $result;
}
}
-?>
+?>
\ No newline at end of file
diff --git a/core/authentication/resources/classes/plugins/ldap.php b/core/authentication/resources/classes/plugins/ldap.php
index 54e4ffdcb0..569233e127 100644
--- a/core/authentication/resources/classes/plugins/ldap.php
+++ b/core/authentication/resources/classes/plugins/ldap.php
@@ -23,13 +23,6 @@ class plugin_ldap {
*/
function ldap() {
- //save the database connection to a local variable
- include "root.php";
- require_once "resources/classes/database.php";
- $database = new database;
- $database->connect();
- $db = $database->db;
-
//use ldap to validate the user credentials
if (isset($_SESSION["ldap"]["certpath"])) {
$s = "LDAPTLS_CERT=" . $_SESSION["ldap"]["certpath"]["text"];
@@ -41,13 +34,13 @@ class plugin_ldap {
}
$host = $_SESSION["ldap"]["server_host"]["text"];
$port = $_SESSION["ldap"]["server_port"]["numeric"];
- $connect = ldap_connect($host,$port)
+ $connect = ldap_connect($host, $port)
or die("Could not connect to the LDAP server.");
//ldap_set_option($connect, LDAP_OPT_NETWORK_TIMEOUT, 10);
ldap_set_option($connect, LDAP_OPT_PROTOCOL_VERSION, 3);
//ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, 7);
- //set the default for $user_authorized to false
+ //set the default status
$user_authorized = false;
//provide backwards compatability
@@ -69,54 +62,37 @@ class plugin_ldap {
$user_authorized = true;
break;
}
- else {
- //connection failed
- $user_authorized = false;
- }
- }
- else {
- //password not provided
- $user_authorized = false;
}
}
//check to see if the user exists
if ($user_authorized) {
$sql = "select * from v_users ";
- $sql .= "where username=:username ";
- if ($_SESSION["users"]["unique"]["text"] == "global") {
- //unique username - global (example: email address)
- }
- else {
- //unique username - per domain
- $sql .= "and domain_uuid=:domain_uuid ";
- }
- $prep_statement = $db->prepare($sql);
+ $sql .= "where username = :username ";
if ($_SESSION["users"]["unique"]["text"] != "global") {
- $prep_statement->bindParam(':domain_uuid', $this->domain_uuid);
+ //unique username per domain (not globally unique across system - example: email address)
+ $sql .= "and domain_uuid = :domain_uuid ";
+ $parameters['domain_uuid'] = $this->domain_uuid;
}
- $prep_statement->bindParam(':username', $this->username);
- $prep_statement->execute();
- $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
- if (count($result) > 0) {
- foreach ($result as &$row) {
- if ($_SESSION["users"]["unique"]["text"] == "global" && $row["domain_uuid"] != $this->domain_uuid) {
- //get the domain uuid
- $this->domain_uuid = $row["domain_uuid"];
- $this->domain_name = $_SESSION['domains'][$this->domain_uuid]['domain_name'];
+ $parameters['username'] = $this->username;
+ $database = new database;
+ $row = $database->select($sql, $parameters, 'row');
+ if (is_array($row) && @sizeof($row) != 0) {
+ if ($_SESSION["users"]["unique"]["text"] == "global" && $row["domain_uuid"] != $this->domain_uuid) {
+ //get the domain uuid
+ $this->domain_uuid = $row["domain_uuid"];
+ $this->domain_name = $_SESSION['domains'][$this->domain_uuid]['domain_name'];
- //set the domain session variables
- $_SESSION["domain_uuid"] = $this->domain_uuid;
- $_SESSION["domain_name"] = $this->domain_name;
+ //set the domain session variables
+ $_SESSION["domain_uuid"] = $this->domain_uuid;
+ $_SESSION["domain_name"] = $this->domain_name;
- //set the setting arrays
- $domain = new domains();
- $domain->db = $db;
- $domain->set();
- }
- $this->user_uuid = $row["user_uuid"];
- $this->contact_uuid = $row["contact_uuid"];
+ //set the setting arrays
+ $domain = new domains();
+ $domain->set();
}
+ $this->user_uuid = $row["user_uuid"];
+ $this->contact_uuid = $row["contact_uuid"];
}
else {
//salt used with the password to create a one way hash
@@ -127,53 +103,40 @@ class plugin_ldap {
$this->user_uuid = uuid();
$this->contact_uuid = uuid();
- //add the user
- $sql = "insert into v_users ";
- $sql .= "(";
- $sql .= "domain_uuid, ";
- $sql .= "user_uuid, ";
- $sql .= "contact_uuid, ";
- $sql .= "username, ";
- $sql .= "password, ";
- $sql .= "salt, ";
- $sql .= "add_date, ";
- $sql .= "add_user, ";
- $sql .= "user_enabled ";
- $sql .= ") ";
- $sql .= "values ";
- $sql .= "(";
- $sql .= "'".$this->domain_uuid."', ";
- $sql .= "'".$this->user_uuid."', ";
- $sql .= "'".$this->contact_uuid."', ";
- $sql .= "'".strtolower($this->username)."', ";
- $sql .= "'".md5($salt.$password)."', ";
- $sql .= "'".$salt."', ";
- $sql .= "now(), ";
- $sql .= "'".strtolower($this->username)."', ";
- $sql .= "'true' ";
- $sql .= ")";
- $db->exec(check_sql($sql));
- unset($sql);
+ //build user insert array
+ $array['users'][0]['user_uuid'] = $this->user_uuid;
+ $array['users'][0]['domain_uuid'] = $this->domain_uuid;
+ $array['users'][0]['contact_uuid'] = $this->contact_uuid;
+ $array['users'][0]['username'] = strtolower($this->username);
+ $array['users'][0]['password'] = md5($salt.$password);
+ $array['users'][0]['salt'] = $salt;
+ $array['users'][0]['add_date'] = now();
+ $array['users'][0]['add_user'] = strtolower($this->username);
+ $array['users'][0]['user_enabled'] = 'true';
- //add the user to group user
- $group_name = 'user';
- $sql = "insert into v_user_groups ";
- $sql .= "(";
- $sql .= "user_group_uuid, ";
- $sql .= "domain_uuid, ";
- $sql .= "group_name, ";
- $sql .= "user_uuid ";
- $sql .= ")";
- $sql .= "values ";
- $sql .= "(";
- $sql .= "'".uuid()."', ";
- $sql .= "'".$this->domain_uuid."', ";
- $sql .= "'".$group_name."', ";
- $sql .= "'".$this->user_uuid."' ";
- $sql .= ")";
- $db->exec(check_sql($sql));
- unset($sql);
+ //build user group insert array
+ $array['user_groups'][0]['user_group_uuid'] = uuid();
+ $array['user_groups'][0]['domain_uuid'] = $this->domain_uuid;
+ $array['user_groups'][0]['group_name'] = 'user';
+ $array['user_groups'][0]['user_uuid'] = $this->user_uuid;
+
+ //grant temporary permissions
+ $p = new permissions;
+ $p->add('user_add', 'temp');
+ $p->add('user_group_add', 'temp');
+
+ //execute insert
+ $database = new database;
+ $database->app_name = 'authentication';
+ $database->app_uuid = 'a8a12918-69a4-4ece-a1ae-3932be0e41f1';
+ $database->save($array);
+ unset($array);
+
+ //revoke temporary permissions
+ $p->delete('user_add', 'temp');
+ $p->delete('user_group_add', 'temp');
}
+ unset($sql, $parameters, $row);
}
//result array
@@ -185,14 +148,9 @@ class plugin_ldap {
}
$result["user_uuid"] = $this->user_uuid;
$result["domain_uuid"] = $this->domain_uuid;
- if ($user_authorized) {
- $result["authorized"] = "true";
- }
- else {
- $result["authorized"] = "false";
- }
+ $result["authorized"] = $user_authorized ? 'true' : 'false';
return $result;
}
}
-?>
+?>
\ No newline at end of file
diff --git a/core/groups/resources/classes/permission.php b/core/groups/resources/classes/permission.php
index eee18da465..57451fc623 100644
--- a/core/groups/resources/classes/permission.php
+++ b/core/groups/resources/classes/permission.php
@@ -29,105 +29,113 @@
//delete the permissions
function delete() {
- //set the variables
- $db = $this->db;
//get unprotected groups and their domain uuids (if any)
- $sql = "select group_name, domain_uuid from v_groups where group_protected <> 'true' ";
- $prep_statement = $db->prepare(check_sql($sql));
- $prep_statement->execute();
- $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
- $result_count = count($result);
- if ($result_count > 0) {
+ $sql = "select group_name, domain_uuid ";
+ $sql .= "from v_groups ";
+ $sql .= "where group_protected <> 'true' ";
+ $database = new database;
+ $result = $database->select($sql, null, 'all');
+ if (is_array($result) && @sizeof($result) != 0) {
foreach($result as $row) {
$unprotected_groups[$row['group_name']] = $row['domain_uuid'];
}
}
- unset ($prep_statement, $sql, $result, $result_count);
+ unset($sql, $result, $row);
//delete unprotected group permissions
if (is_array($unprotected_groups) && sizeof($unprotected_groups) > 0) {
+ $x = 0;
foreach ($unprotected_groups as $unprotected_group_name => $unprotected_domain_uuid) {
- $sql = "delete from v_group_permissions where ";
- $sql .= "group_name = '".$unprotected_group_name."' ";
- $sql .= "and domain_uuid ".(($unprotected_domain_uuid != '') ? " = '".$unprotected_domain_uuid."' " : " is null ");
- if (false === $db->exec($sql)) {
- //echo $db->errorCode() . "
";
- $info = $db->errorInfo();
- print_r($info);
- // $info[0] == $db->errorCode() unified error code
- // $info[1] is the driver specific error code
- // $info[2] is the driver specific error string
- }
+ //build delete array
+ $array['group_permissions'][$x]['group_name'] = $unprotected_group_name;
+ $array['group_permissions'][$x]['domain_uuid'] = $unprotected_domain_uuid != '' ? $unprotected_domain_uuid : null;
+ $x++;
+ }
+ if (is_array($array) && @sizeof($array) != 0) {
+ //grant temporary permissions
+ $p = new permissions;
+ $p->add('group_permission_delete', 'temp');
+ //execute delete
+ $database = new database;
+ $database->app_name = 'groups';
+ $database->app_uuid = '2caf27b0-540a-43d5-bb9b-c9871a1e4f84';
+ $database->delete($array);
+ unset($array);
+ //revoke temporary permissions
+ $p->delete('group_permission_delete', 'temp');
}
}
}
//restore the permissions
function restore() {
- //set the variables
- $db = $this->db;
-
//delete the group permisisons
$this->delete();
//get the $apps array from the installed apps from the core and mod directories
$config_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_config.php");
- $x=0;
+ $x = 0;
foreach ($config_list as &$config_path) {
include($config_path);
$x++;
}
//restore default permissions
- foreach($apps as $row) {
+ $x = 0;
+ foreach ($apps as $row) {
foreach ($row['permissions'] as $permission) {
//set the variables
if ($permission['groups']) {
foreach ($permission['groups'] as $group) {
//check group protection
- $sql = "select * from v_groups ";
- $sql .= "where group_name = '".$group."' ";
+ $sql = "select count(*) from v_groups ";
+ $sql .= "where group_name = :group_name ";
$sql .= "and group_protected = 'true'";
- $prep_statement = $db->prepare(check_sql($sql));
- if ($prep_statement) {
- $prep_statement->execute();
- $result = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
- unset ($prep_statement);
- if (count($result) == 0) {
- //if the item uuid is not currently in the db then add it
- $sql = "select * from v_group_permissions ";
- $sql .= "where permission_name = '".$permission['name']."' ";
- $sql .= "and group_name = '$group' ";
- $prep_statement = $db->prepare(check_sql($sql));
- if ($prep_statement) {
- $prep_statement->execute();
- $result = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
- unset ($prep_statement);
- if (count($result) == 0) {
- //insert the default permissions into the database
- $sql = "insert into v_group_permissions ";
- $sql .= "(";
- $sql .= "group_permission_uuid, ";
- $sql .= "permission_name, ";
- $sql .= "group_name ";
- $sql .= ") ";
- $sql .= "values ";
- $sql .= "(";
- $sql .= "'".uuid()."', ";
- $sql .= "'".$permission['name']."', ";
- $sql .= "'".$group."' ";
- $sql .= ");";
- $db->exec(check_sql($sql));
- unset($sql);
- } // if count
- } // if prepared statement
- } // if count
- } // if prepared statement
- } // foreach group permission
- } // if permission
- } // foreach permission
- } // foreach app
+ $parameters['group_name'] = $group;
+ $database = new database;
+ $num_rows = $database->select($sql, $parameters, 'column');
+ unset($sql, $parameters);
- } // function
- } // class
+ if ($num_rows == 0) {
+ //if the item uuid is not currently in the db then add it
+ $sql = "select count(*) from v_group_permissions ";
+ $sql .= "where permission_name = :permission_name ";
+ $sql .= "and group_name = :group_name ";
+ $parameters['permission_name'] = $permission['name'];
+ $parameters['group_name'] = $group;
+ $database = new database;
+ $num_rows = $database->select($sql, $parameters, 'column');
+ unset($sql, $parameters);
+
+ if ($num_rows == 0) {
+ //build default permissions insert array
+ $array['group_permissions'][$x]['group_permission_uuid'] = uuid();
+ $array['group_permissions'][$x]['permission_name'] = $permission['name'];
+ $array['group_permissions'][$x]['group_name'] = $group;
+ $x++;
+ }
+ }
+ }
+ }
+ }
+ }
+ if (is_array($array) && @sizeof($array)) {
+ //grant temporary permissions
+ $p = new permissions;
+ $p->add('group_permission_add', 'temp');
+
+ //execute insert
+ $database = new database;
+ $database->app_name = 'groups';
+ $database->app_uuid = '2caf27b0-540a-43d5-bb9b-c9871a1e4f84';
+ $database->save($array);
+ unset($array);
+
+ //revoke temporary permissions
+ $p->delete('group_permission_add', 'temp');
+ }
+
+ }
+
+ }
?>
\ No newline at end of file
diff --git a/resources/classes/captcha.php b/resources/classes/captcha.php
index 28462857c0..55b5f33ad6 100644
--- a/resources/classes/captcha.php
+++ b/resources/classes/captcha.php
@@ -34,8 +34,6 @@ class captcha {
/**
* Called when the object is created
*/
- //public $db;
- //public $domain_uuid;
public $code;
/**