diff --git a/app/scripts/resources/classes/scripts.php b/app/scripts/resources/classes/scripts.php index 5b49902dcd..710cc0d85f 100644 --- a/app/scripts/resources/classes/scripts.php +++ b/app/scripts/resources/classes/scripts.php @@ -32,248 +32,248 @@ * @method string copy_files * @method string write_config */ -class scripts { +if (!class_exists('scripts')) { + class scripts { - public $db; + 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; - } - } - - /** - * Called when there are no references to a particular object - * unset the variables used in the class - */ - public function __destruct() { - foreach ($this as $key => $value) { - unset($this->$key); - } - } - - /** - * Corrects the path for specifically for windows - */ - private function correct_path($path) { - global $IS_WINDOWS; - if ($IS_WINDOWS == null) { - if (stristr(PHP_OS, 'WIN')) { $IS_WINDOWS = true; } else { $IS_WINDOWS = false; } - } - if ($IS_WINDOWS) { - return str_replace('\\', '/', $path); - } - return $path; - } - - /** - * Copy the switch scripts from the web directory to the switch directory - */ - public function copy_files() { - if (strlen($_SESSION['switch']['scripts']['dir']) > 0) { - $dst_dir = $_SESSION['switch']['scripts']['dir']; - if(strlen($dst_dir) == 0) { - throw new Exception("Cannot copy scripts the 'script_dir' is empty"); - } - if (file_exists($dst_dir)) { - //get the source directory - if (file_exists('/usr/share/examples/fusionpbx/resources/install/scripts')){ - $src_dir = '/usr/share/examples/fusionpbx/resources/install/scripts'; - } - else { - $src_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/install/scripts'; - } - if (is_readable($dst_dir)) { - recursive_copy($src_dir, $dst_dir); - unset($src_dir, $dst_dir); - }else{ - throw new Exception("Cannot read from '$src_dir' to get the scripts"); - } - chmod($dst_dir, 0774); - } else { - throw new Exception("Scripts directory doesn't exist"); + /** + * 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; } } - } - /** - * Writes the config.lua - */ - public function write_config() { - if (is_dir($_SESSION['switch']['scripts']['dir'])) { + /** + * Called when there are no references to a particular object + * unset the variables used in the class + */ + public function __destruct() { + foreach ($this as $key => $value) { + unset($this->$key); + } + } - //define the global variables - global $db_type; - global $db_name; - global $db_host; - global $db_port; - global $db_path; - global $db_username; - global $db_password; + /** + * Corrects the path for specifically for windows + */ + private function correct_path($path) { + global $IS_WINDOWS; + if ($IS_WINDOWS == null) { + if (stristr(PHP_OS, 'WIN')) { $IS_WINDOWS = true; } else { $IS_WINDOWS = false; } + } + if ($IS_WINDOWS) { + return str_replace('\\', '/', $path); + } + return $path; + } - //replace the backslash with a forward slash - $db_path = str_replace("\\", "/", $db_path); - - //get the odbc information - $sql = "select count(*) as num_rows 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); - foreach ($result as &$row) { - $dsn_name = $row["database_name"]; - $dsn_username = $row["database_username"]; - $dsn_password = $row["database_password"]; - break; //limit to 1 row - } - unset ($prep_statement); + /** + * Copy the switch scripts from the web directory to the switch directory + */ + public function copy_files() { + if (strlen($_SESSION['switch']['scripts']['dir']) > 0) { + $dst_dir = $_SESSION['switch']['scripts']['dir']; + if(strlen($dst_dir) == 0) { + throw new Exception("Cannot copy scripts the 'script_dir' is empty"); + } + if (file_exists($dst_dir)) { + //get the source directory + if (file_exists('/usr/share/examples/fusionpbx/resources/install/scripts')){ + $src_dir = '/usr/share/examples/fusionpbx/resources/install/scripts'; } else { - $odbc_num_rows = '0'; + $src_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/install/scripts'; } - } - - //get the recordings directory - $recordings_dir = $_SESSION['switch']['recordings']['dir']; - - //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")){ - $config = "/usr/local/etc/fusionpbx/config.lua"; - } - else { - //connect to event socket - $esl = new event_socket; - $esl->connect($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']); - $script_dir = trim($esl->request('api global_getvar script_dir')); - $config = $script_dir."/resources/config.lua"; - } - $fout = fopen($config,"w"); - if(!$fout){ - return; - } - - //make the config.lua - $tmp = "\n"; - $tmp .= "--set the variables\n"; - if (strlen($_SESSION['switch']['sounds']['dir']) > 0) { - $tmp .= $this->correct_path(" sounds_dir = [[".$_SESSION['switch']['sounds']['dir']."]];\n"); - } - if (strlen($_SESSION['switch']['phrases']['dir']) > 0) { - $tmp .= $this->correct_path(" phrases_dir = [[".$_SESSION['switch']['phrases']['dir']."]];\n"); - } - if (strlen($_SESSION['switch']['db']['dir']) > 0) { - $tmp .= $this->correct_path(" database_dir = [[".$_SESSION['switch']['db']['dir']."]];\n"); - } - if (strlen($_SESSION['switch']['recordings']['dir']) > 0) { - $tmp .= $this->correct_path(" recordings_dir = [[".$recordings_dir."]];\n"); - } - if (strlen($_SESSION['switch']['storage']['dir']) > 0) { - $tmp .= $this->correct_path(" storage_dir = [[".$_SESSION['switch']['storage']['dir']."]];\n"); - } - if (strlen($_SESSION['switch']['voicemail']['dir']) > 0) { - $tmp .= $this->correct_path(" voicemail_dir = [[".$_SESSION['switch']['voicemail']['dir']."]];\n"); - } - if (strlen($_SESSION['switch']['scripts']['dir']) > 0) { - $tmp .= $this->correct_path(" scripts_dir = [[".$_SESSION['switch']['scripts']['dir']."]];\n"); - } - $tmp .= $this->correct_path(" php_dir = [[".PHP_BINDIR."]];\n"); - if (substr(strtoupper(PHP_OS), 0, 3) == "WIN") { - $tmp .= " php_bin = \"php.exe\";\n"; - } - else { - $tmp .= " php_bin = \"php\";\n"; - } - $tmp .= $this->correct_path(" document_root = [[".$_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."]];\n"); - $tmp .= "\n"; - - if ((strlen($db_type) > 0) || (strlen($dsn_name) > 0)) { - $tmp .= "--database information\n"; - $tmp .= " database = {}\n"; - $tmp .= " database.type = \"".$db_type."\";\n"; - $tmp .= " database.name = \"".$db_name."\";\n"; - $tmp .= $this->correct_path(" database.path = [[".$db_path."]];\n"); - - if (strlen($dsn_name) > 0) { - $tmp .= " database.system = \"odbc://".$dsn_name.":".$dsn_username.":".$dsn_password."\";\n"; - $tmp .= " database.switch = \"odbc://freeswitch:".$dsn_username.":".$dsn_password."\";\n"; + if (is_readable($dst_dir)) { + recursive_copy($src_dir, $dst_dir); + unset($src_dir, $dst_dir); + }else{ + throw new Exception("Cannot read from '$src_dir' to get the scripts"); } - elseif ($db_type == "pgsql") { - if ($db_host == "localhost") { $db_host = "127.0.0.1"; } - $tmp .= " database.system = \"pgsql://hostaddr=".$db_host." port=".$db_port." dbname=".$db_name." user=".$db_username." password=".$db_password." options='' application_name='".$db_name."'\";\n"; - $tmp .= " database.switch = \"pgsql://hostaddr=".$db_host." port=".$db_port." dbname=freeswitch user=".$db_username." password=".$db_password." options='' application_name='freeswitch'\";\n"; + chmod($dst_dir, 0774); + } else { + throw new Exception("Scripts directory doesn't exist"); + } + } + } + + /** + * Writes the config.lua + */ + public function write_config() { + if (is_dir($_SESSION['switch']['scripts']['dir'])) { + + //define the global variables + global $db_type; + global $db_name; + global $db_host; + global $db_port; + global $db_path; + global $db_username; + global $db_password; + + //replace the backslash with a forward slash + $db_path = str_replace("\\", "/", $db_path); + + //get the odbc information + $sql = "select count(*) as num_rows 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); + foreach ($result as &$row) { + $dsn_name = $row["database_name"]; + $dsn_username = $row["database_username"]; + $dsn_password = $row["database_password"]; + break; //limit to 1 row + } + unset ($prep_statement); + } + else { + $odbc_num_rows = '0'; + } } - elseif ($db_type == "sqlite") { - $tmp .= " database.system = \"sqlite://".$db_path."/".$db_name."\";\n"; - $tmp .= " database.switch = \"sqlite://".$_SESSION['switch']['db']['dir']."\";\n"; + + //get the recordings directory + $recordings_dir = $_SESSION['switch']['recordings']['dir']; + + //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")){ + $config = "/usr/local/etc/fusionpbx/config.lua"; } - elseif ($db_type == "mysql") { - $tmp .= " database.system = \"\";\n"; - $tmp .= " database.switch = \"\";\n"; + else { + //connect to event socket + $esl = new event_socket; + $esl->connect($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']); + $script_dir = trim($esl->request('api global_getvar script_dir')); + $config = $script_dir."/resources/config.lua"; + } + $fout = fopen($config,"w"); + if(!$fout){ + return; + } + + //make the config.lua + $tmp = "\n"; + $tmp .= "--set the variables\n"; + if (strlen($_SESSION['switch']['sounds']['dir']) > 0) { + $tmp .= $this->correct_path(" sounds_dir = [[".$_SESSION['switch']['sounds']['dir']."]];\n"); + } + if (strlen($_SESSION['switch']['phrases']['dir']) > 0) { + $tmp .= $this->correct_path(" phrases_dir = [[".$_SESSION['switch']['phrases']['dir']."]];\n"); + } + if (strlen($_SESSION['switch']['db']['dir']) > 0) { + $tmp .= $this->correct_path(" database_dir = [[".$_SESSION['switch']['db']['dir']."]];\n"); + } + if (strlen($_SESSION['switch']['recordings']['dir']) > 0) { + $tmp .= $this->correct_path(" recordings_dir = [[".$recordings_dir."]];\n"); + } + if (strlen($_SESSION['switch']['storage']['dir']) > 0) { + $tmp .= $this->correct_path(" storage_dir = [[".$_SESSION['switch']['storage']['dir']."]];\n"); + } + if (strlen($_SESSION['switch']['voicemail']['dir']) > 0) { + $tmp .= $this->correct_path(" voicemail_dir = [[".$_SESSION['switch']['voicemail']['dir']."]];\n"); + } + if (strlen($_SESSION['switch']['scripts']['dir']) > 0) { + $tmp .= $this->correct_path(" scripts_dir = [[".$_SESSION['switch']['scripts']['dir']."]];\n"); + } + $tmp .= $this->correct_path(" php_dir = [[".PHP_BINDIR."]];\n"); + if (substr(strtoupper(PHP_OS), 0, 3) == "WIN") { + $tmp .= " php_bin = \"php.exe\";\n"; + } + else { + $tmp .= " php_bin = \"php\";\n"; + } + $tmp .= $this->correct_path(" document_root = [[".$_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."]];\n"); + $tmp .= "\n"; + + if ((strlen($db_type) > 0) || (strlen($dsn_name) > 0)) { + $tmp .= "--database information\n"; + $tmp .= " database = {}\n"; + $tmp .= " database.type = \"".$db_type."\";\n"; + $tmp .= " database.name = \"".$db_name."\";\n"; + $tmp .= $this->correct_path(" database.path = [[".$db_path."]];\n"); + + if (strlen($dsn_name) > 0) { + $tmp .= " database.system = \"odbc://".$dsn_name.":".$dsn_username.":".$dsn_password."\";\n"; + $tmp .= " database.switch = \"odbc://freeswitch:".$dsn_username.":".$dsn_password."\";\n"; + } + elseif ($db_type == "pgsql") { + if ($db_host == "localhost") { $db_host = "127.0.0.1"; } + $tmp .= " database.system = \"pgsql://hostaddr=".$db_host." port=".$db_port." dbname=".$db_name." user=".$db_username." password=".$db_password." options='' application_name='".$db_name."'\";\n"; + $tmp .= " database.switch = \"pgsql://hostaddr=".$db_host." port=".$db_port." dbname=freeswitch user=".$db_username." password=".$db_password." options='' application_name='freeswitch'\";\n"; + } + elseif ($db_type == "sqlite") { + $tmp .= " database.system = \"sqlite://".$db_path."/".$db_name."\";\n"; + $tmp .= " database.switch = \"sqlite://".$_SESSION['switch']['db']['dir']."\";\n"; + } + elseif ($db_type == "mysql") { + $tmp .= " database.system = \"\";\n"; + $tmp .= " database.switch = \"\";\n"; + } + $tmp .= "\n"; + } + $tmp .= "--set defaults\n"; + $tmp .= " expire = {}\n"; + $tmp .= " expire.directory = \"3600\";\n"; + $tmp .= " expire.dialplan = \"3600\";\n"; + $tmp .= " expire.languages = \"3600\";\n"; + $tmp .= " expire.sofia = \"3600\";\n"; + $tmp .= " expire.acl = \"3600\";\n"; + $tmp .= "\n"; + $tmp .= "--set xml_handler\n"; + $tmp .= " xml_handler = {}\n"; + $tmp .= " xml_handler.fs_path = false;\n"; + $tmp .= "\n"; + $tmp .= "--set the debug options\n"; + $tmp .= " debug.params = false;\n"; + $tmp .= " debug.sql = false;\n"; + $tmp .= " debug.xml_request = false;\n"; + $tmp .= " debug.xml_string = false;\n"; + $tmp .= " debug.cache = false;\n"; + $tmp .= "\n"; + $tmp .= "--additional info\n"; + $tmp .= " domain_count = ".count($_SESSION["domains"]).";\n"; + $tmp .= $this->correct_path(" temp_dir = [[".$_SESSION['server']['temp']['dir']."]];\n"); + if (isset($_SESSION['domain']['dial_string']['text'])) { + $tmp .= " dial_string = \"".$_SESSION['domain']['dial_string']['text']."\";\n"; } $tmp .= "\n"; - } - $tmp .= "--set defaults\n"; - $tmp .= " expire = {}\n"; - $tmp .= " expire.directory = \"3600\";\n"; - $tmp .= " expire.dialplan = \"3600\";\n"; - $tmp .= " expire.languages = \"3600\";\n"; - $tmp .= " expire.sofia = \"3600\";\n"; - $tmp .= " expire.acl = \"3600\";\n"; - $tmp .= "\n"; - $tmp .= "--set xml_handler\n"; - $tmp .= " xml_handler = {}\n"; - $tmp .= " xml_handler.fs_path = false;\n"; - $tmp .= "\n"; - $tmp .= "--set the debug options\n"; - $tmp .= " debug.params = false;\n"; - $tmp .= " debug.sql = false;\n"; - $tmp .= " debug.xml_request = false;\n"; - $tmp .= " debug.xml_string = false;\n"; - $tmp .= " debug.cache = false;\n"; - $tmp .= "\n"; - $tmp .= "--additional info\n"; - $tmp .= " domain_count = ".count($_SESSION["domains"]).";\n"; - $tmp .= $this->correct_path(" temp_dir = [[".$_SESSION['server']['temp']['dir']."]];\n"); - if (isset($_SESSION['domain']['dial_string']['text'])) { - $tmp .= " dial_string = \"".$_SESSION['domain']['dial_string']['text']."\";\n"; - } - $tmp .= "\n"; - $tmp .= "--include local.lua\n"; - $tmp .= " require(\"resources.functions.file_exists\");\n"; - $tmp .= " if (file_exists(\"/etc/fusionpbx/local.lua\")) then\n"; - $tmp .= " dofile(\"/etc/fusionpbx/local.lua\");\n"; - $tmp .= " elseif (file_exists(\"/usr/local/etc/fusionpbx/local.lua\")) then\n"; - $tmp .= " dofile(\"/usr/local/etc/fusionpbx/local.lua\");\n"; - $tmp .= " elseif (file_exists(scripts_dir..\"/resources/local.lua\")) then\n"; - $tmp .= " require(\"resources.local\");\n"; - $tmp .= " end\n"; - fwrite($fout, $tmp); - unset($tmp); - fclose($fout); - } - } //end config_lua - -} //end scripts class - + $tmp .= "--include local.lua\n"; + $tmp .= " require(\"resources.functions.file_exists\");\n"; + $tmp .= " if (file_exists(\"/etc/fusionpbx/local.lua\")) then\n"; + $tmp .= " dofile(\"/etc/fusionpbx/local.lua\");\n"; + $tmp .= " elseif (file_exists(\"/usr/local/etc/fusionpbx/local.lua\")) then\n"; + $tmp .= " dofile(\"/usr/local/etc/fusionpbx/local.lua\");\n"; + $tmp .= " elseif (file_exists(scripts_dir..\"/resources/local.lua\")) then\n"; + $tmp .= " require(\"resources.local\");\n"; + $tmp .= " end\n"; + fwrite($fout, $tmp); + unset($tmp); + fclose($fout); + } + } //end config_lua + } //end scripts class +} /* //example use diff --git a/resources/classes/domains.php b/resources/classes/domains.php index ac556abcf7..c3382e47bb 100644 --- a/resources/classes/domains.php +++ b/resources/classes/domains.php @@ -25,6 +25,7 @@ sreis */ +if (!class_exists('domains')) { class domains { //define variables @@ -352,5 +353,6 @@ } } +} ?> \ No newline at end of file diff --git a/resources/classes/groups.php b/resources/classes/groups.php index fb48d90e94..aeb719e64e 100644 --- a/resources/classes/groups.php +++ b/resources/classes/groups.php @@ -32,158 +32,157 @@ * @method boolean delete * @method boolean defaults */ -class groups { +if (!class_exists('groups')) { + class groups { - public $db; + 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; - } - } - - /** - * Called when there are no references to a particular object - * unset the variables used in the class - */ - public function __destruct() { - foreach ($this as $key => $value) { - unset($this->$key); - } - } - - /** - * add a group - */ - public function add() { - $id = uuid(); - //return $id; - return false; - } - - /** - * delete a group - */ - public function delete($id) { - return false; - } - - /** - * add defaults groups - */ - public function defaults() { - - //if the are no groups add the default groups - $sql = "SELECT * FROM v_groups "; - $sql .= "WHERE domain_uuid is null "; - $result = $this->db->query($sql)->fetch(); - $prep_statement = $this->db->prepare(check_sql($sql)); - if ($prep_statement) { - $prep_statement->execute(); - $result = $prep_statement->fetchAll(PDO::FETCH_ASSOC); - if (count($result) == 0) { - $x = 0; - $tmp[$x]['group_name'] = 'superadmin'; - $tmp[$x]['group_description'] = 'Super Administrator Group'; - $tmp[$x]['group_protected'] = 'false'; - $x++; - $tmp[$x]['group_name'] = 'admin'; - $tmp[$x]['group_description'] = 'Administrator Group'; - $tmp[$x]['group_protected'] = 'false'; - $x++; - $tmp[$x]['group_name'] = 'user'; - $tmp[$x]['group_description'] = 'User Group'; - $tmp[$x]['group_protected'] = 'false'; - $x++; - $tmp[$x]['group_name'] = 'public'; - $tmp[$x]['group_description'] = 'Public Group'; - $tmp[$x]['group_protected'] = 'false'; - $x++; - $tmp[$x]['group_name'] = 'agent'; - $tmp[$x]['group_description'] = 'Call Center Agent Group'; - $tmp[$x]['group_protected'] = 'false'; - $this->db->beginTransaction(); - foreach($tmp as $row) { - if (strlen($row['group_name']) > 0) { - $sql = "insert into v_groups "; - $sql .= "("; - $sql .= "domain_uuid, "; - $sql .= "group_uuid, "; - $sql .= "group_name, "; - $sql .= "group_description, "; - $sql .= "group_protected "; - $sql .= ")"; - $sql .= "values "; - $sql .= "("; - $sql .= "null, "; - $sql .= "'".uuid()."', "; - $sql .= "'".$row['group_name']."', "; - $sql .= "'".$row['group_description']."', "; - $sql .= "'".$row['group_protected']."' "; - $sql .= ")"; - $this->db->exec($sql); - unset($sql); - } - } - $this->db->commit(); - } - unset($prep_statement, $result); + /** + * 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; } + } - //if there are no permissions listed in v_group_permissions then set the default permissions - $sql = "select count(*) as count from v_group_permissions "; - $sql .= "where domain_uuid is null "; - $prep_statement = $this->db->prepare($sql); - $prep_statement->execute(); - $result = $prep_statement->fetch(PDO::FETCH_ASSOC); - unset ($prep_statement); - if ($result['count'] == 0) { - //build the apps array - $config_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_config.php"); - $x = 0; - foreach ($config_list as &$config_path) { - include($config_path); + /** + * Called when there are no references to a particular object + * unset the variables used in the class + */ + public function __destruct() { + foreach ($this as $key => $value) { + unset($this->$key); + } + } + + /** + * add a group + */ + public function add() { + $id = uuid(); + //return $id; + return false; + } + + /** + * delete a group + */ + public function delete($id) { + return false; + } + + /** + * add defaults groups + */ + public function defaults() { + + //if the are no groups add the default groups + $sql = "SELECT * FROM v_groups "; + $sql .= "WHERE domain_uuid is null "; + $result = $this->db->query($sql)->fetch(); + $prep_statement = $this->db->prepare(check_sql($sql)); + if ($prep_statement) { + $prep_statement->execute(); + $result = $prep_statement->fetchAll(PDO::FETCH_ASSOC); + if (count($result) == 0) { + $x = 0; + $tmp[$x]['group_name'] = 'superadmin'; + $tmp[$x]['group_description'] = 'Super Administrator Group'; + $tmp[$x]['group_protected'] = 'false'; $x++; - } - //no permissions found add the defaults - $this->db->beginTransaction(); - foreach($apps as $app) { - foreach ($app['permissions'] as $row) { - foreach ($row['groups'] as $group) { - //add the record - $sql = "insert into v_group_permissions "; + $tmp[$x]['group_name'] = 'admin'; + $tmp[$x]['group_description'] = 'Administrator Group'; + $tmp[$x]['group_protected'] = 'false'; + $x++; + $tmp[$x]['group_name'] = 'user'; + $tmp[$x]['group_description'] = 'User Group'; + $tmp[$x]['group_protected'] = 'false'; + $x++; + $tmp[$x]['group_name'] = 'public'; + $tmp[$x]['group_description'] = 'Public Group'; + $tmp[$x]['group_protected'] = 'false'; + $x++; + $tmp[$x]['group_name'] = 'agent'; + $tmp[$x]['group_description'] = 'Call Center Agent Group'; + $tmp[$x]['group_protected'] = 'false'; + $this->db->beginTransaction(); + foreach($tmp as $row) { + if (strlen($row['group_name']) > 0) { + $sql = "insert into v_groups "; $sql .= "("; - $sql .= "group_permission_uuid, "; $sql .= "domain_uuid, "; - $sql .= "permission_name, "; - $sql .= "group_name "; + $sql .= "group_uuid, "; + $sql .= "group_name, "; + $sql .= "group_description, "; + $sql .= "group_protected "; $sql .= ")"; $sql .= "values "; $sql .= "("; - $sql .= "'".uuid()."', "; $sql .= "null, "; - $sql .= "'".$row['name']."', "; - $sql .= "'".$group."' "; + $sql .= "'".uuid()."', "; + $sql .= "'".$row['group_name']."', "; + $sql .= "'".$row['group_description']."', "; + $sql .= "'".$row['group_protected']."' "; $sql .= ")"; $this->db->exec($sql); unset($sql); } } + $this->db->commit(); } - $this->db->commit(); - } - } - - -} //end scripts class + unset($prep_statement, $result); + } + //if there are no permissions listed in v_group_permissions then set the default permissions + $sql = "select count(*) as count from v_group_permissions "; + $sql .= "where domain_uuid is null "; + $prep_statement = $this->db->prepare($sql); + $prep_statement->execute(); + $result = $prep_statement->fetch(PDO::FETCH_ASSOC); + unset ($prep_statement); + if ($result['count'] == 0) { + //build the apps array + $config_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_config.php"); + $x = 0; + foreach ($config_list as &$config_path) { + include($config_path); + $x++; + } + //no permissions found add the defaults + $this->db->beginTransaction(); + foreach($apps as $app) { + foreach ($app['permissions'] as $row) { + foreach ($row['groups'] as $group) { + //add the record + $sql = "insert into v_group_permissions "; + $sql .= "("; + $sql .= "group_permission_uuid, "; + $sql .= "domain_uuid, "; + $sql .= "permission_name, "; + $sql .= "group_name "; + $sql .= ")"; + $sql .= "values "; + $sql .= "("; + $sql .= "'".uuid()."', "; + $sql .= "null, "; + $sql .= "'".$row['name']."', "; + $sql .= "'".$group."' "; + $sql .= ")"; + $this->db->exec($sql); + unset($sql); + } + } + } + $this->db->commit(); + } + } + } //end scripts class +} /* //example use $group = new groups; diff --git a/resources/classes/menu.php b/resources/classes/menu.php index b75ae5db64..6852450c5c 100644 --- a/resources/classes/menu.php +++ b/resources/classes/menu.php @@ -25,6 +25,7 @@ */ //define the menu class +if (!class_exists('menu')) { class menu { //define the variables public $menu_uuid; @@ -580,5 +581,6 @@ } } //end function } +} ?> \ No newline at end of file diff --git a/resources/classes/schema.php b/resources/classes/schema.php index b143ce5c1a..2dd1026f28 100644 --- a/resources/classes/schema.php +++ b/resources/classes/schema.php @@ -26,6 +26,7 @@ include "root.php"; //define the schema class +if (!class_exists('schema')) { class schema { //define variables @@ -873,8 +874,8 @@ include "root.php"; //else if ($output == "return") { return $response; //} - } //end function + } } //example use diff --git a/resources/classes/switch_settings.php b/resources/classes/switch_settings.php index d60c4c6c21..6a21cf3cc4 100644 --- a/resources/classes/switch_settings.php +++ b/resources/classes/switch_settings.php @@ -5,246 +5,248 @@ * * @method settings will add missing switch directories to default settings */ -class switch_settings { +if (!class_exists('switch_settings')) { + class switch_settings { - public $db; - public $event_socket_ip_address; - public $event_socket_port; - public $event_socket_password; + public $db; + public $event_socket_ip_address; + public $event_socket_port; + public $event_socket_password; - /** - * 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; + /** + * 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; + } } - } - /** - * Called when there are no references to a particular object - * unset the variables used in the class - */ - public function __destruct() { - foreach ($this as $key => $value) { - unset($this->$key); + /** + * Called when there are no references to a particular object + * unset the variables used in the class + */ + public function __destruct() { + foreach ($this as $key => $value) { + unset($this->$key); + } } - } - /** - * settings Set switch directories in default settings - */ - public function settings() { + /** + * settings Set switch directories in default settings + */ + public function settings() { - //define the variables - if (!isset($this->event_socket_ip_address)) { - $this->event_socket_ip_address = $_SESSION['event_socket_ip_address']; - } - if (!isset($this->event_socket_port)) { - $this->event_socket_port = $_SESSION['event_socket_port']; - } - if (!isset($this->event_socket_password)) { - $this->event_socket_password = $_SESSION['event_socket_password']; - } - - //connect to event socket - $esl = new event_socket; - $esl->connect($this->event_socket_ip_address, $this->event_socket_port, $this->event_socket_password); - - //run the api command - $result = $esl->request('api global_getvar'); - - //close event socket - fclose($fp); - - //set the result as a named array - $vars = array(); - foreach (explode("\n", $result) as $row) { - $a = explode("=", $row); - if (substr($a[0], -4) == "_dir") { - $vars[$a[0]] = $a[1]; + //define the variables + if (!isset($this->event_socket_ip_address)) { + $this->event_socket_ip_address = $_SESSION['event_socket_ip_address']; + } + if (!isset($this->event_socket_port)) { + $this->event_socket_port = $_SESSION['event_socket_port']; + } + if (!isset($this->event_socket_password)) { + $this->event_socket_password = $_SESSION['event_socket_password']; } - } - //set the bin directory - if ($vars['base_dir'] == "/usr/local/freeswitch") { - $bin = "/usr/local/freeswitch/bin"; - } else { - $bin = ""; - } + //connect to event socket + $esl = new event_socket; + $esl->connect($this->event_socket_ip_address, $this->event_socket_port, $this->event_socket_password); - //create the default settings array - $x=0; - $array[$x]['default_setting_category'] = 'switch'; - $array[$x]['default_setting_subcategory'] = 'bin'; - $array[$x]['default_setting_name'] = 'dir'; - $array[$x]['default_setting_value'] = $bin; - $array[$x]['default_setting_enabled'] = 'true'; - $array[$x]['default_setting_description'] = ''; - $x++; - $array[$x]['default_setting_category'] = 'switch'; - $array[$x]['default_setting_subcategory'] = 'base'; - $array[$x]['default_setting_name'] = 'dir'; - $array[$x]['default_setting_value'] = $vars['base_dir']; - $array[$x]['default_setting_enabled'] = 'true'; - $array[$x]['default_setting_description'] = ''; - $x++; - $array[$x]['default_setting_category'] = 'switch'; - $array[$x]['default_setting_subcategory'] = 'call_center'; - $array[$x]['default_setting_name'] = 'dir'; - $array[$x]['default_setting_value'] = $vars['conf_dir'].'/autoload_configs'; - $array[$x]['default_setting_enabled'] = 'false'; - $array[$x]['default_setting_description'] = ''; - $x++; - $array[$x]['default_setting_category'] = 'switch'; - $array[$x]['default_setting_subcategory'] = 'conf'; - $array[$x]['default_setting_name'] = 'dir'; - $array[$x]['default_setting_value'] = $vars['conf_dir']; - $array[$x]['default_setting_enabled'] = 'true'; - $array[$x]['default_setting_description'] = ''; - $x++; - $array[$x]['default_setting_category'] = 'switch'; - $array[$x]['default_setting_subcategory'] = 'db'; - $array[$x]['default_setting_name'] = 'dir'; - $array[$x]['default_setting_value'] = $vars['db_dir']; - $array[$x]['default_setting_enabled'] = 'true'; - $array[$x]['default_setting_description'] = ''; - $x++; - $array[$x]['default_setting_category'] = 'switch'; - $array[$x]['default_setting_subcategory'] = 'dialplan'; - $array[$x]['default_setting_name'] = 'dir'; - $array[$x]['default_setting_value'] = $vars['conf_dir'].'/dialplan'; - $array[$x]['default_setting_enabled'] = 'false'; - $array[$x]['default_setting_description'] = ''; - $x++; - $array[$x]['default_setting_category'] = 'switch'; - $array[$x]['default_setting_subcategory'] = 'extensions'; - $array[$x]['default_setting_name'] = 'dir'; - $array[$x]['default_setting_value'] = $vars['conf_dir'].'/directory'; - $array[$x]['default_setting_enabled'] = 'false'; - $array[$x]['default_setting_description'] = ''; - $x++; - $array[$x]['default_setting_category'] = 'switch'; - $array[$x]['default_setting_subcategory'] = 'grammar'; - $array[$x]['default_setting_name'] = 'dir'; - $array[$x]['default_setting_value'] = $vars['grammar_dir']; - $array[$x]['default_setting_enabled'] = 'true'; - $array[$x]['default_setting_description'] = ''; - $x++; - $array[$x]['default_setting_category'] = 'switch'; - $array[$x]['default_setting_subcategory'] = 'log'; - $array[$x]['default_setting_name'] = 'dir'; - $array[$x]['default_setting_value'] = $vars['log_dir']; - $array[$x]['default_setting_enabled'] = 'true'; - $array[$x]['default_setting_description'] = ''; - $x++; - $array[$x]['default_setting_category'] = 'switch'; - $array[$x]['default_setting_subcategory'] = 'mod'; - $array[$x]['default_setting_name'] = 'dir'; - $array[$x]['default_setting_value'] = $vars['mod_dir']; - $array[$x]['default_setting_enabled'] = 'true'; - $array[$x]['default_setting_description'] = ''; - $x++; - $array[$x]['default_setting_category'] = 'switch'; - $array[$x]['default_setting_subcategory'] = 'phrases'; - $array[$x]['default_setting_name'] = 'dir'; - $array[$x]['default_setting_value'] = $vars['conf_dir'].'/lang'; - $array[$x]['default_setting_enabled'] = 'false'; - $array[$x]['default_setting_description'] = ''; - $x++; - $array[$x]['default_setting_category'] = 'switch'; - $array[$x]['default_setting_subcategory'] = 'recordings'; - $array[$x]['default_setting_name'] = 'dir'; - $array[$x]['default_setting_value'] = $vars['recordings_dir']; - $array[$x]['default_setting_enabled'] = 'true'; - $array[$x]['default_setting_description'] = ''; - $x++; - $array[$x]['default_setting_category'] = 'switch'; - $array[$x]['default_setting_subcategory'] = 'scripts'; - $array[$x]['default_setting_name'] = 'dir'; - $array[$x]['default_setting_value'] = $vars['script_dir']; - $array[$x]['default_setting_enabled'] = 'true'; - $array[$x]['default_setting_description'] = ''; - $x++; - $array[$x]['default_setting_category'] = 'switch'; - $array[$x]['default_setting_subcategory'] = 'sip_profiles'; - $array[$x]['default_setting_name'] = 'dir'; - $array[$x]['default_setting_value'] = $vars['conf_dir'].'/sip_profiles'; - $array[$x]['default_setting_enabled'] = 'false'; - $array[$x]['default_setting_description'] = ''; - $x++; - $array[$x]['default_setting_category'] = 'switch'; - $array[$x]['default_setting_subcategory'] = 'sounds'; - $array[$x]['default_setting_name'] = 'dir'; - $array[$x]['default_setting_value'] = $vars['sounds_dir']; - $array[$x]['default_setting_enabled'] = 'true'; - $array[$x]['default_setting_description'] = ''; - $x++; - $array[$x]['default_setting_category'] = 'switch'; - $array[$x]['default_setting_subcategory'] = 'storage'; - $array[$x]['default_setting_name'] = 'dir'; - $array[$x]['default_setting_value'] = $vars['storage_dir']; - $array[$x]['default_setting_enabled'] = 'true'; - $array[$x]['default_setting_description'] = ''; - $x++; - $array[$x]['default_setting_category'] = 'switch'; - $array[$x]['default_setting_subcategory'] = 'voicemail'; - $array[$x]['default_setting_name'] = 'dir'; - $array[$x]['default_setting_value'] = $vars['storage_dir'].'/voicemail'; - $array[$x]['default_setting_enabled'] = 'true'; - $array[$x]['default_setting_description'] = ''; - $x++; + //run the api command + $result = $esl->request('api global_getvar'); - //get an array of the default settings - $sql = "select * from v_default_settings "; - $sql .= "where default_setting_category = 'switch' "; - $prep_statement = $this->db->prepare($sql); - $prep_statement->execute(); - $default_settings = $prep_statement->fetchAll(PDO::FETCH_NAMED); - unset ($prep_statement, $sql); + //close event socket + fclose($fp); - //find the missing default settings - $x = 0; - foreach ($array as $setting) { - $found = false; - $missing[$x] = $setting; - foreach ($default_settings as $row) { - if (trim($row['default_setting_subcategory']) == trim($setting['default_setting_subcategory'])) { - $found = true; - //remove items from the array that were found - unset($missing[$x]); + //set the result as a named array + $vars = array(); + foreach (explode("\n", $result) as $row) { + $a = explode("=", $row); + if (substr($a[0], -4) == "_dir") { + $vars[$a[0]] = $a[1]; } } + + //set the bin directory + if ($vars['base_dir'] == "/usr/local/freeswitch") { + $bin = "/usr/local/freeswitch/bin"; + } else { + $bin = ""; + } + + //create the default settings array + $x=0; + $array[$x]['default_setting_category'] = 'switch'; + $array[$x]['default_setting_subcategory'] = 'bin'; + $array[$x]['default_setting_name'] = 'dir'; + $array[$x]['default_setting_value'] = $bin; + $array[$x]['default_setting_enabled'] = 'true'; + $array[$x]['default_setting_description'] = ''; + $x++; + $array[$x]['default_setting_category'] = 'switch'; + $array[$x]['default_setting_subcategory'] = 'base'; + $array[$x]['default_setting_name'] = 'dir'; + $array[$x]['default_setting_value'] = $vars['base_dir']; + $array[$x]['default_setting_enabled'] = 'true'; + $array[$x]['default_setting_description'] = ''; + $x++; + $array[$x]['default_setting_category'] = 'switch'; + $array[$x]['default_setting_subcategory'] = 'call_center'; + $array[$x]['default_setting_name'] = 'dir'; + $array[$x]['default_setting_value'] = $vars['conf_dir'].'/autoload_configs'; + $array[$x]['default_setting_enabled'] = 'false'; + $array[$x]['default_setting_description'] = ''; + $x++; + $array[$x]['default_setting_category'] = 'switch'; + $array[$x]['default_setting_subcategory'] = 'conf'; + $array[$x]['default_setting_name'] = 'dir'; + $array[$x]['default_setting_value'] = $vars['conf_dir']; + $array[$x]['default_setting_enabled'] = 'true'; + $array[$x]['default_setting_description'] = ''; + $x++; + $array[$x]['default_setting_category'] = 'switch'; + $array[$x]['default_setting_subcategory'] = 'db'; + $array[$x]['default_setting_name'] = 'dir'; + $array[$x]['default_setting_value'] = $vars['db_dir']; + $array[$x]['default_setting_enabled'] = 'true'; + $array[$x]['default_setting_description'] = ''; + $x++; + $array[$x]['default_setting_category'] = 'switch'; + $array[$x]['default_setting_subcategory'] = 'dialplan'; + $array[$x]['default_setting_name'] = 'dir'; + $array[$x]['default_setting_value'] = $vars['conf_dir'].'/dialplan'; + $array[$x]['default_setting_enabled'] = 'false'; + $array[$x]['default_setting_description'] = ''; + $x++; + $array[$x]['default_setting_category'] = 'switch'; + $array[$x]['default_setting_subcategory'] = 'extensions'; + $array[$x]['default_setting_name'] = 'dir'; + $array[$x]['default_setting_value'] = $vars['conf_dir'].'/directory'; + $array[$x]['default_setting_enabled'] = 'false'; + $array[$x]['default_setting_description'] = ''; + $x++; + $array[$x]['default_setting_category'] = 'switch'; + $array[$x]['default_setting_subcategory'] = 'grammar'; + $array[$x]['default_setting_name'] = 'dir'; + $array[$x]['default_setting_value'] = $vars['grammar_dir']; + $array[$x]['default_setting_enabled'] = 'true'; + $array[$x]['default_setting_description'] = ''; + $x++; + $array[$x]['default_setting_category'] = 'switch'; + $array[$x]['default_setting_subcategory'] = 'log'; + $array[$x]['default_setting_name'] = 'dir'; + $array[$x]['default_setting_value'] = $vars['log_dir']; + $array[$x]['default_setting_enabled'] = 'true'; + $array[$x]['default_setting_description'] = ''; + $x++; + $array[$x]['default_setting_category'] = 'switch'; + $array[$x]['default_setting_subcategory'] = 'mod'; + $array[$x]['default_setting_name'] = 'dir'; + $array[$x]['default_setting_value'] = $vars['mod_dir']; + $array[$x]['default_setting_enabled'] = 'true'; + $array[$x]['default_setting_description'] = ''; + $x++; + $array[$x]['default_setting_category'] = 'switch'; + $array[$x]['default_setting_subcategory'] = 'phrases'; + $array[$x]['default_setting_name'] = 'dir'; + $array[$x]['default_setting_value'] = $vars['conf_dir'].'/lang'; + $array[$x]['default_setting_enabled'] = 'false'; + $array[$x]['default_setting_description'] = ''; + $x++; + $array[$x]['default_setting_category'] = 'switch'; + $array[$x]['default_setting_subcategory'] = 'recordings'; + $array[$x]['default_setting_name'] = 'dir'; + $array[$x]['default_setting_value'] = $vars['recordings_dir']; + $array[$x]['default_setting_enabled'] = 'true'; + $array[$x]['default_setting_description'] = ''; + $x++; + $array[$x]['default_setting_category'] = 'switch'; + $array[$x]['default_setting_subcategory'] = 'scripts'; + $array[$x]['default_setting_name'] = 'dir'; + $array[$x]['default_setting_value'] = $vars['script_dir']; + $array[$x]['default_setting_enabled'] = 'true'; + $array[$x]['default_setting_description'] = ''; + $x++; + $array[$x]['default_setting_category'] = 'switch'; + $array[$x]['default_setting_subcategory'] = 'sip_profiles'; + $array[$x]['default_setting_name'] = 'dir'; + $array[$x]['default_setting_value'] = $vars['conf_dir'].'/sip_profiles'; + $array[$x]['default_setting_enabled'] = 'false'; + $array[$x]['default_setting_description'] = ''; + $x++; + $array[$x]['default_setting_category'] = 'switch'; + $array[$x]['default_setting_subcategory'] = 'sounds'; + $array[$x]['default_setting_name'] = 'dir'; + $array[$x]['default_setting_value'] = $vars['sounds_dir']; + $array[$x]['default_setting_enabled'] = 'true'; + $array[$x]['default_setting_description'] = ''; + $x++; + $array[$x]['default_setting_category'] = 'switch'; + $array[$x]['default_setting_subcategory'] = 'storage'; + $array[$x]['default_setting_name'] = 'dir'; + $array[$x]['default_setting_value'] = $vars['storage_dir']; + $array[$x]['default_setting_enabled'] = 'true'; + $array[$x]['default_setting_description'] = ''; + $x++; + $array[$x]['default_setting_category'] = 'switch'; + $array[$x]['default_setting_subcategory'] = 'voicemail'; + $array[$x]['default_setting_name'] = 'dir'; + $array[$x]['default_setting_value'] = $vars['storage_dir'].'/voicemail'; + $array[$x]['default_setting_enabled'] = 'true'; + $array[$x]['default_setting_description'] = ''; $x++; - } - //add the missing default settings - foreach ($missing as $row) { - //add the default settings - $orm = new orm; - $orm->name('default_settings'); - $orm->save($row); - $message = $orm->message; - unset($orm); - //print_r($message); - } - unset($missing); + //get an array of the default settings + $sql = "select * from v_default_settings "; + $sql .= "where default_setting_category = 'switch' "; + $prep_statement = $this->db->prepare($sql); + $prep_statement->execute(); + $default_settings = $prep_statement->fetchAll(PDO::FETCH_NAMED); + unset ($prep_statement, $sql); - //set the default settings - foreach ($array as $row) { - if (!isset($_SESSION['switch'][$row['default_setting_subcategory']])) { - if ($row['default_setting_enabled'] != "false") { - $_SESSION['switch'][$row['default_setting_subcategory']] = $row['default_setting_value']; + //find the missing default settings + $x = 0; + foreach ($array as $setting) { + $found = false; + $missing[$x] = $setting; + foreach ($default_settings as $row) { + if (trim($row['default_setting_subcategory']) == trim($setting['default_setting_subcategory'])) { + $found = true; + //remove items from the array that were found + unset($missing[$x]); + } + } + $x++; + } + + //add the missing default settings + foreach ($missing as $row) { + //add the default settings + $orm = new orm; + $orm->name('default_settings'); + $orm->save($row); + $message = $orm->message; + unset($orm); + //print_r($message); + } + unset($missing); + + //set the default settings + foreach ($array as $row) { + if (!isset($_SESSION['switch'][$row['default_setting_subcategory']])) { + if ($row['default_setting_enabled'] != "false") { + $_SESSION['switch'][$row['default_setting_subcategory']] = $row['default_setting_value']; + } } } - } - //unset the array variable - unset($array); + //unset the array variable + unset($array); + } } } diff --git a/resources/classes/users.php b/resources/classes/users.php index 807de878be..da4ec3d1bc 100644 --- a/resources/classes/users.php +++ b/resources/classes/users.php @@ -31,43 +31,44 @@ * @method string add * @method boolean delete */ -class users { +if (!class_exists('users')) { + class users { - /** - * Called when the object is created - */ - public function __construct() { - //place holder - } - - /** - * Called when there are no references to a particular object - * unset the variables used in the class - */ - public function __destruct() { - foreach ($this as $key => $value) { - unset($this->$key); + /** + * Called when the object is created + */ + public function __construct() { + //place holder } - } - /** - * add a user - */ - public function add($username, $password) { - $id = uuid(); - //return $id; - return false; - } + /** + * Called when there are no references to a particular object + * unset the variables used in the class + */ + public function __destruct() { + foreach ($this as $key => $value) { + unset($this->$key); + } + } - /** - * delete a user - */ - public function delete($id) { - return false; - } + /** + * add a user + */ + public function add($username, $password) { + $id = uuid(); + //return $id; + return false; + } -} //end scripts class + /** + * delete a user + */ + public function delete($id) { + return false; + } + } //end scripts class +} /* //example use $user = new users;