From e7f12aa19e7103b6a8925bd885cfe7bb582074fa Mon Sep 17 00:00:00 2001 From: Alex <40072887+alexdcrane@users.noreply.github.com> Date: Thu, 13 Oct 2022 09:37:20 -0600 Subject: [PATCH] Update sms.php (#168) * Update sms.php * Delete root.php * Update sms_broadcast.php * Update sms_broadcast_edit.php * Update sms_broadcast_process.php * Update sms_delete.php * Update sms_edit.php * Update sms_hook_common.php * Update sms_broadcast_process.php * Update sms_mdr.php * Update sms_hook_bandwidth.php * Update sms_hook_didww.php * Update sms_hook_flowroute.php * Update sms_hook_twilio.php * Update sms_hook_thinq.php * Update sms_hook_telnyx.php * Update sms_hook_peerless.php * Update sms_hook_plivo.php * Update sms_hook_teli.php * Update sms_hook_bandwidth.php * Update sms_hook_didww.php * Update sms_hook_flowroute.php * Update sms_hook_telnyx.php * Update sms_hook_thinq.php * Update sms_hook_twilio.php --- sms/hook/sms_hook_bandwidth.php | 8 +- sms/hook/sms_hook_didww.php | 8 +- sms/hook/sms_hook_flowroute.php | 5 +- sms/hook/sms_hook_peerless.php | 6 +- sms/hook/sms_hook_plivo.php | 8 +- sms/hook/sms_hook_teli.php | 8 +- sms/hook/sms_hook_telnyx.php | 8 +- sms/hook/sms_hook_thinq.php | 6 +- sms/hook/sms_hook_twilio.php | 6 +- sms/root.php | 205 -------------------------------- sms/sms.php | 12 +- sms/sms_broadcast.php | 9 +- sms/sms_broadcast_edit.php | 9 +- sms/sms_broadcast_process.php | 8 +- sms/sms_delete.php | 14 ++- sms/sms_edit.php | 13 +- sms/sms_hook_common.php | 10 +- sms/sms_mdr.php | 7 +- 18 files changed, 107 insertions(+), 243 deletions(-) delete mode 100755 sms/root.php diff --git a/sms/hook/sms_hook_bandwidth.php b/sms/hook/sms_hook_bandwidth.php index 38fc9367..f7a20842 100755 --- a/sms/hook/sms_hook_bandwidth.php +++ b/sms/hook/sms_hook_bandwidth.php @@ -1,7 +1,10 @@ \ No newline at end of file + +?> diff --git a/sms/hook/sms_hook_didww.php b/sms/hook/sms_hook_didww.php index 294852a3..9e885e56 100644 --- a/sms/hook/sms_hook_didww.php +++ b/sms/hook/sms_hook_didww.php @@ -1,7 +1,10 @@ \ No newline at end of file + +?> diff --git a/sms/hook/sms_hook_flowroute.php b/sms/hook/sms_hook_flowroute.php index 906ad135..409119c3 100755 --- a/sms/hook/sms_hook_flowroute.php +++ b/sms/hook/sms_hook_flowroute.php @@ -1,7 +1,10 @@ diff --git a/sms/hook/sms_hook_plivo.php b/sms/hook/sms_hook_plivo.php index 688151f9..bd23fbab 100755 --- a/sms/hook/sms_hook_plivo.php +++ b/sms/hook/sms_hook_plivo.php @@ -1,7 +1,10 @@ \ No newline at end of file + +?> diff --git a/sms/hook/sms_hook_teli.php b/sms/hook/sms_hook_teli.php index 5fb65dee..5e4ac07c 100755 --- a/sms/hook/sms_hook_teli.php +++ b/sms/hook/sms_hook_teli.php @@ -1,7 +1,10 @@ \ No newline at end of file + +?> diff --git a/sms/hook/sms_hook_telnyx.php b/sms/hook/sms_hook_telnyx.php index c0047e55..59791402 100755 --- a/sms/hook/sms_hook_telnyx.php +++ b/sms/hook/sms_hook_telnyx.php @@ -1,7 +1,10 @@ \ No newline at end of file + +?> diff --git a/sms/hook/sms_hook_thinq.php b/sms/hook/sms_hook_thinq.php index 046cbffa..05356c52 100755 --- a/sms/hook/sms_hook_thinq.php +++ b/sms/hook/sms_hook_thinq.php @@ -1,7 +1,10 @@ diff --git a/sms/hook/sms_hook_twilio.php b/sms/hook/sms_hook_twilio.php index 09daf9a6..58b70507 100755 --- a/sms/hook/sms_hook_twilio.php +++ b/sms/hook/sms_hook_twilio.php @@ -1,7 +1,10 @@ diff --git a/sms/root.php b/sms/root.php deleted file mode 100755 index 393725d7..00000000 --- a/sms/root.php +++ /dev/null @@ -1,205 +0,0 @@ - - Portions created by the Initial Developer are Copyright (C) 2008-2012 - the Initial Developer. All Rights Reserved. - - Contributor(s): - Mark J Crane -*/ - -// make sure the PATH_SEPARATOR is defined - umask(2); - if (!defined("PATH_SEPARATOR")) { - if (strpos($_ENV["OS"], "Win") !== false) { - define("PATH_SEPARATOR", ";"); - } else { - define("PATH_SEPARATOR", ":"); - } - } - - if (!isset($output_format)) $output_format = (PHP_SAPI == 'cli') ? 'text' : 'html'; - - // make sure the document_root is set - $_SERVER["SCRIPT_FILENAME"] = str_replace("\\", '/', $_SERVER["SCRIPT_FILENAME"]); - if(PHP_SAPI == 'cli'){ - chdir(pathinfo(realpath($_SERVER["PHP_SELF"]), PATHINFO_DIRNAME)); - $script_full_path = str_replace("\\", '/', getcwd() . '/' . $_SERVER["SCRIPT_FILENAME"]); - $dirs = explode('/', pathinfo($script_full_path, PATHINFO_DIRNAME)); - if (file_exists('/project_root.php')) { - $path = '/'; - } else { - $i = 1; - $path = ''; - while ($i < count($dirs)) { - $path .= '/' . $dirs[$i]; - if (file_exists($path. '/project_root.php')) { - break; - } - $i++; - } - } - $_SERVER["DOCUMENT_ROOT"] = $path; - }else{ - $_SERVER["DOCUMENT_ROOT"] = str_replace($_SERVER["PHP_SELF"], "", $_SERVER["SCRIPT_FILENAME"]); - } - $_SERVER["DOCUMENT_ROOT"] = realpath($_SERVER["DOCUMENT_ROOT"]); -// try to detect if a project path is being used - if (!defined('PROJECT_PATH')) { - if (is_dir($_SERVER["DOCUMENT_ROOT"]. '/fusionpbx')) { - define('PROJECT_PATH', '/fusionpbx'); - } elseif (file_exists($_SERVER["DOCUMENT_ROOT"]. '/project_root.php')) { - define('PROJECT_PATH', ''); - } else { - $dirs = explode('/', str_replace('\\', '/', pathinfo($_SERVER["PHP_SELF"], PATHINFO_DIRNAME))); - $i = 1; - $path = $_SERVER["DOCUMENT_ROOT"]; - while ($i < count($dirs)) { - $path .= '/' . $dirs[$i]; - if (file_exists($path. '/project_root.php')) { - break; - } - $i++; - } - if(!file_exists($path. '/project_root.php')){ - die("Failed to locate the Project Root by searching for project_root.php please contact support for assistance"); - } - $project_path = str_replace($_SERVER["DOCUMENT_ROOT"], "", $path); - define('PROJECT_PATH', $project_path); - } - $_SERVER["PROJECT_ROOT"] = realpath($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH); - set_include_path(get_include_path() . PATH_SEPARATOR . $_SERVER["PROJECT_ROOT"]); - } - -if (!class_exists('IP4Filter')) { - class IP4Filter { - - private static $_IP_TYPE_SINGLE = 'single'; - private static $_IP_TYPE_WILDCARD = 'wildcard'; - private static $_IP_TYPE_MASK = 'mask'; - private static $_IP_TYPE_CIDR = 'CIDR'; - private static $_IP_TYPE_SECTION = 'section'; - private $_allowed_ips = array(); - - public function __construct($allowed_ips) { - $this->_allowed_ips = $allowed_ips; - } - - public function check($ip, $allowed_ips = null) { - $allowed_ips = $allowed_ips ? $allowed_ips : $this->_allowed_ips; - - foreach ($allowed_ips as $allowed_ip) { - $type = $this->_judge_ip_type($allowed_ip); - $sub_rst = call_user_func(array($this, '_sub_checker_' . $type), $allowed_ip, $ip); - - if ($sub_rst) { - return true; - } - } - - return false; - } - - private function _judge_ip_type($ip) { - if (strpos($ip, '*')) { - return self :: $_IP_TYPE_WILDCARD; - } - - if (strpos($ip, '/')) { - $tmp = explode('/', $ip); - if (strpos($tmp[1], '.')) { - return self :: $_IP_TYPE_MASK; - } else { - return self :: $_IP_TYPE_CIDR; - } - } - - if (strpos($ip, '-')) { - return self :: $_IP_TYPE_SECTION; - } - - if (ip2long($ip)) { - return self :: $_IP_TYPE_SINGLE; - } - - return false; - } - - private function _sub_checker_single($allowed_ip, $ip) { - return (ip2long($allowed_ip) == ip2long($ip)); - } - - private function _sub_checker_wildcard($allowed_ip, $ip) { - $allowed_ip_arr = explode('.', $allowed_ip); - $ip_arr = explode('.', $ip); - for ($i = 0; $i < count($allowed_ip_arr); $i++) { - if ($allowed_ip_arr[$i] == '*') { - return true; - } else { - if (false == ($allowed_ip_arr[$i] == $ip_arr[$i])) { - return false; - } - } - } - } - - private function _sub_checker_mask($allowed_ip, $ip) { - list($allowed_ip_ip, $allowed_ip_mask) = explode('/', $allowed_ip); - $begin = (ip2long($allowed_ip_ip) & ip2long($allowed_ip_mask)) + 1; - $end = (ip2long($allowed_ip_ip) | (~ ip2long($allowed_ip_mask))) + 1; - $ip = ip2long($ip); - return ($ip >= $begin && $ip <= $end); - } - - private function _sub_checker_section($allowed_ip, $ip) { - list($begin, $end) = explode('-', $allowed_ip); - $begin = ip2long($begin); - $end = ip2long($end); - $ip = ip2long($ip); - return ($ip >= $begin && $ip <= $end); - } - - private function _sub_checker_CIDR($CIDR, $IP) { - list ($net, $mask) = explode('/', $CIDR); - return ( ip2long($IP) & ~((1 << (32 - $mask)) - 1) ) == ip2long($net); - } - - } - - function check_acl(){ - global $db, $debug, $domain_uuid, $domain_name; - - //select node_cidr from v_access_control_nodes where node_cidr != ''; - $sql = "select node_cidr from v_access_control_nodes where node_cidr != '' and node_type = 'allow'"; - $prep_statement = $db->prepare(check_sql($sql)); - $prep_statement->execute(); - $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); - if (count($result) == 0) { - die("No ACL's"); - } - foreach ($result as &$row) { - $allowed_ips[] = $row['node_cidr']; - } - - $acl = new IP4Filter($allowed_ips); - - return $acl->check($_SERVER['REMOTE_ADDR'],$allowed_ips); - } -} -?> \ No newline at end of file diff --git a/sms/sms.php b/sms/sms.php index b628d2bf..cf8ed139 100755 --- a/sms/sms.php +++ b/sms/sms.php @@ -23,9 +23,15 @@ Contributor(s): Mark J Crane */ -include "root.php"; -require_once "resources/require.php"; -require_once "resources/check_auth.php"; + +//set the include path + $conf = glob("{/usr/local/etc,/etc}/fusionpbx/config.conf", GLOB_BRACE); + set_include_path(parse_ini_file($conf[0])['document.root']); + +//includes files + require_once "resources/require.php"; + require_once "resources/check_auth.php"; + if (permission_exists('sms_view')) { //access granted } diff --git a/sms/sms_broadcast.php b/sms/sms_broadcast.php index b5771b1f..da061fb4 100644 --- a/sms/sms_broadcast.php +++ b/sms/sms_broadcast.php @@ -24,8 +24,11 @@ Mark J Crane */ -//includes - require_once "root.php"; +//set the include path + $conf = glob("{/usr/local/etc,/etc}/fusionpbx/config.conf", GLOB_BRACE); + set_include_path(parse_ini_file($conf[0])['document.root']); + +//includes files require_once "resources/require.php"; require_once "resources/check_auth.php"; require_once "resources/paging.php"; @@ -191,4 +194,4 @@ //include the footer require_once "resources/footer.php"; -?> \ No newline at end of file +?> diff --git a/sms/sms_broadcast_edit.php b/sms/sms_broadcast_edit.php index a6cd7493..49361566 100644 --- a/sms/sms_broadcast_edit.php +++ b/sms/sms_broadcast_edit.php @@ -25,8 +25,11 @@ Luis Daniel Lucio Quiroz */ -//includes - include "root.php"; +//set the include path + $conf = glob("{/usr/local/etc,/etc}/fusionpbx/config.conf", GLOB_BRACE); + set_include_path(parse_ini_file($conf[0])['document.root']); + +//includes files require_once "resources/require.php"; require_once "resources/check_auth.php"; @@ -336,4 +339,4 @@ function upload_file($sql, $sms_broadcast_phone_numbers) { //include the footer require_once "resources/footer.php"; -?> \ No newline at end of file +?> diff --git a/sms/sms_broadcast_process.php b/sms/sms_broadcast_process.php index d7beff54..6ecd97f2 100644 --- a/sms/sms_broadcast_process.php +++ b/sms/sms_broadcast_process.php @@ -1,6 +1,10 @@ \ No newline at end of file +?> diff --git a/sms/sms_delete.php b/sms/sms_delete.php index 056ba212..33b78290 100755 --- a/sms/sms_delete.php +++ b/sms/sms_delete.php @@ -25,9 +25,15 @@ Call Block is written by Gerrit Visser */ -include "root.php"; -require_once "resources/require.php"; -require_once "resources/check_auth.php"; + +//set the include path + $conf = glob("{/usr/local/etc,/etc}/fusionpbx/config.conf", GLOB_BRACE); + set_include_path(parse_ini_file($conf[0])['document.root']); + +//includes files + require_once "resources/require.php"; + require_once "resources/check_auth.php"; + if (permission_exists('sms_delete')) { //access granted } @@ -62,4 +68,4 @@ header("Location: sms.php"); return; -?> \ No newline at end of file +?> diff --git a/sms/sms_edit.php b/sms/sms_edit.php index 717dac71..dc688938 100755 --- a/sms/sms_edit.php +++ b/sms/sms_edit.php @@ -31,9 +31,14 @@ */ -include "root.php"; -require_once "resources/require.php"; -require_once "resources/check_auth.php"; +//set the include path + $conf = glob("{/usr/local/etc,/etc}/fusionpbx/config.conf", GLOB_BRACE); + set_include_path(parse_ini_file($conf[0])['document.root']); + +//includes files + require_once "resources/require.php"; + require_once "resources/check_auth.php"; + if (permission_exists('sms_add') || permission_exists('sms_edit')) { //access granted } @@ -285,4 +290,4 @@ //show the footer require_once "resources/footer.php"; -?> \ No newline at end of file +?> diff --git a/sms/sms_hook_common.php b/sms/sms_hook_common.php index 0b9491d5..5ece6874 100755 --- a/sms/sms_hook_common.php +++ b/sms/sms_hook_common.php @@ -30,15 +30,18 @@ James Rose */ -include "root.php"; +//set the include path +$conf = glob("{/usr/local/etc,/etc}/fusionpbx/config.conf", GLOB_BRACE); +set_include_path(parse_ini_file($conf[0])['document.root']); + +//includes files +require_once "resources/require.php"; include "app/sms/sms_email.php"; //luarun /var/www/html/app/sms/sms.lua TO FROM 'BODY' $debug = true; -require_once "resources/require.php"; - function route_and_send_sms($from, $to, $body, $media = "") { global $db, $debug, $domain_uuid, $domain_name, $mailsent; @@ -197,4 +200,5 @@ function route_and_send_sms($from, $to, $body, $media = "") { unset ($prep_statement); } } + ?> diff --git a/sms/sms_mdr.php b/sms/sms_mdr.php index f70b42fb..816337a0 100755 --- a/sms/sms_mdr.php +++ b/sms/sms_mdr.php @@ -31,8 +31,11 @@ */ -//includes - include "root.php"; +//set the include path + $conf = glob("{/usr/local/etc,/etc}/fusionpbx/config.conf", GLOB_BRACE); + set_include_path(parse_ini_file($conf[0])['document.root']); + +//includes files require_once "resources/require.php"; require_once "resources/check_auth.php";