From 6911231620bd20d80362dfd73e977dab0373dfc8 Mon Sep 17 00:00:00 2001 From: rapperskull Date: Wed, 26 Jun 2019 12:33:30 +0200 Subject: [PATCH 01/11] Added option for assigning static IP Addresses to the phones (for now it probably works only with Cisco/LinkSys SPA9XX phones) --- Endpointman_Advanced.class.php | 62 ++++++++++++- functions.inc.php | 10 ++- includes/abstraction/freepbx.inc | 2 +- includes/devices_manager.inc | 52 ++++++----- includes/functions.inc | 70 ++++++++++++--- install.php | 35 +++++--- lib/epm_data_abstraction.class.php | 2 +- module.xml | 3 +- templates/freepbx/devices_manager.html | 91 ++++++++++++------- views/epm_advanced_settings.page.php | 117 +++++++++++++++++++++++++ 10 files changed, 357 insertions(+), 87 deletions(-) diff --git a/Endpointman_Advanced.class.php b/Endpointman_Advanced.class.php index f8dae74e..3aef228d 100644 --- a/Endpointman_Advanced.class.php +++ b/Endpointman_Advanced.class.php @@ -12,7 +12,7 @@ class Endpointman_Advanced { - public $MODULES_PATH; + public $MODULES_PATH; public $LOCAL_PATH; public $PHONE_MODULES_PATH; @@ -45,6 +45,18 @@ public function __construct($freepbx = null, $cfgmod = null, $epm_config) } } } + + /** + * @param String $mask - decimal, dot separated representation of a IPv4 subnet mask - e.g. "255.255.255.0" + * @return bool + */ + function validate_dotted_netmask($mask) { + if (!$m = ip2long($mask)) { + return false; + } + $s = str_pad(decbin($m), 32, '0', STR_PAD_LEFT); + return preg_match('/^1{' . substr_count($s,"1") . '}/', $s) == true; + } public function myShowPage(&$pagedata) { if(empty($pagedata)) @@ -354,11 +366,19 @@ private function epm_advanced_settings_saveconfig () case "srvip": $dget['value'] = trim($dget['value']); - $sql = "UPDATE endpointman_global_vars SET value='" . $dget['value'] . "' WHERE var_name='srvip'"; + if(filter_var($dget['value'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)){ + $sql = "UPDATE endpointman_global_vars SET value='" . $dget['value'] . "' WHERE var_name='srvip'"; + } else { + $retarr = array("status" => false, "message" => _("Invalid Server IP Address!")); + } break; case "intsrvip": $dget['value'] = trim($dget['value']); - $sql = "UPDATE endpointman_global_vars SET value='" . $dget['value'] . "' WHERE var_name='intsrvip'"; + if(filter_var($dget['value'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)){ + $sql = "UPDATE endpointman_global_vars SET value='" . $dget['value'] . "' WHERE var_name='intsrvip'"; + } else { + $retarr = array("status" => false, "message" => _("Invalid Server Internal IP Address!")); + } break; case "tz": $sql = "UPDATE endpointman_global_vars SET value='" . $dget['value'] . "' WHERE var_name='tz'"; @@ -414,6 +434,42 @@ private function epm_advanced_settings_saveconfig () } $sql = "UPDATE endpointman_global_vars SET value='" . $dget['value'] . "' WHERE var_name='server_type'"; break; + + case "netmask": + $dget['value'] = trim($dget['value']); + if($this->validate_dotted_netmask($dget['value'])){ + $sql = "UPDATE endpointman_global_vars SET value='" . $dget['value'] . "' WHERE var_name='netmask'"; + } else { + $retarr = array("status" => false, "message" => _("Invalid netmask!")); + } + break; + + case "gateway": + $dget['value'] = trim($dget['value']); + if(filter_var($dget['value'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)){ + $sql = "UPDATE endpointman_global_vars SET value='" . $dget['value'] . "' WHERE var_name='gateway'"; + } else { + $retarr = array("status" => false, "message" => _("Invalid Gateway IP Address!")); + } + break; + + case "dns1": + $dget['value'] = trim($dget['value']); + if(filter_var($dget['value'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)){ + $sql = "UPDATE endpointman_global_vars SET value='" . $dget['value'] . "' WHERE var_name='dns1'"; + } else { + $retarr = array("status" => false, "message" => _("Invalid Primary DNS IP Address!")); + } + break; + + case "dns2": + $dget['value'] = trim($dget['value']); + if(filter_var($dget['value'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)){ + $sql = "UPDATE endpointman_global_vars SET value='" . $dget['value'] . "' WHERE var_name='dns2'"; + } else { + $retarr = array("status" => false, "message" => _("Invalid Secondary DNS IP Address!")); + } + break; default: $retarr = array("status" => false, "message" => _("Name invalid: ") . $dget['name'] ); diff --git a/functions.inc.php b/functions.inc.php index d617757b..1b6cf656 100644 --- a/functions.inc.php +++ b/functions.inc.php @@ -106,13 +106,15 @@ function endpointman_configpageinit($pagename) { } } - $mac = isset($_REQUEST['epm_mac']) ? $_REQUEST['epm_mac'] : null; + $mac = isset($_REQUEST['epm_mac']) ? trim($_REQUEST['epm_mac']) : null; if (!empty($mac)) { //Mac is set $brand = isset($_REQUEST['epm_brand']) ? $_REQUEST['epm_brand'] : null; $model = isset($_REQUEST['epm_model']) ? $_REQUEST['epm_model'] : null; $line = isset($_REQUEST['epm_line']) ? $_REQUEST['epm_line'] : null; + $conn_type = isset($_REQUEST['epm_conn_type']) ? trim($_REQUEST['epm_conn_type']) : null; + $static_ip = isset($_REQUEST['epm_static_ip']) ? trim($_REQUEST['epm_static_ip']) : null; $temp = isset($_REQUEST['epm_temps']) ? $_REQUEST['epm_temps'] : null; if (isset($_REQUEST['name'])) { $name = isset($_REQUEST['name']) ? $_REQUEST['name'] : null; @@ -143,7 +145,7 @@ function endpointman_configpageinit($pagename) { if (($lines_list) AND (isset($model)) AND (isset($line)) AND (!isset($delete)) AND (isset($temp))) { //Modifying line already in the database - $endpoint->update_device($macid, $model, $temp, $lines_list['luid'], $name, $lines_list['line']); + $endpoint->update_device($macid, $model, $conn_type, $static_ip, $temp, $lines_list['luid'], $name, $lines_list['line']); $row = $endpoint->get_phone_info($macid); if (isset($reboot)) { @@ -160,7 +162,7 @@ function endpointman_configpageinit($pagename) { $endpoint->add_line($macid, $line, $extdisplay, $name); } - $endpoint->update_device($macid, $model, $temp, NULL, NULL, NULL, FALSE); + $endpoint->update_device($macid, $model, $conn_type, $static_ip, $temp, NULL, NULL, NULL, FALSE); $row = $endpoint->get_phone_info($macid); if (isset($reboot)) { @@ -171,7 +173,7 @@ function endpointman_configpageinit($pagename) { } } elseif (!isset($delete)) { //Add Extension/Phone to database - $mac_id = $endpoint->add_device($mac, $model, $extdisplay, $temp, NULL, $name); + $mac_id = $endpoint->add_device($mac, $model, $conn_type, $static_ip, $extdisplay, $temp, NULL, $name); if ($mac_id) { debug('Write files?'); diff --git a/includes/abstraction/freepbx.inc b/includes/abstraction/freepbx.inc index e8527630..17bdff94 100644 --- a/includes/abstraction/freepbx.inc +++ b/includes/abstraction/freepbx.inc @@ -56,7 +56,7 @@ class epm_data_abstraction { } function all_devices() { - $sql = 'SELECT endpointman_mac_list.id , endpointman_mac_list.mac , endpointman_model_list.model, endpointman_model_list.enabled , endpointman_brand_list.name, endpointman_mac_list.global_custom_cfg_data, endpointman_mac_list.template_id FROM endpointman_mac_list , endpointman_model_list , endpointman_brand_list WHERE ( endpointman_model_list.id = endpointman_mac_list.model ) AND ( endpointman_model_list.brand = endpointman_brand_list.id )'; + $sql = 'SELECT endpointman_mac_list.id , endpointman_mac_list.mac , endpointman_model_list.model, endpointman_model_list.enabled , endpointman_brand_list.name, endpointman_mac_list.global_custom_cfg_data, endpointman_mac_list.template_id, endpointman_mac_list.conn_type, endpointman_mac_list.static_ip FROM endpointman_mac_list , endpointman_model_list , endpointman_brand_list WHERE ( endpointman_model_list.id = endpointman_mac_list.model ) AND ( endpointman_model_list.brand = endpointman_brand_list.id )'; $temp = $this->sql($sql,'getAll',DB_FETCHMODE_ASSOC); return($temp); } diff --git a/includes/devices_manager.inc b/includes/devices_manager.inc index 80e68d8d..ff333648 100644 --- a/includes/devices_manager.inc +++ b/includes/devices_manager.inc @@ -72,28 +72,36 @@ switch ($sub_type) { } break; case "button_save": + $_REQUEST['static_ip'] = trim($_REQUEST['static_ip']); + if(!empty($_REQUEST['static_ip']) && !filter_var($_REQUEST['static_ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { + $endpoint->error['update_device'] = _("Invalid IP Address") . "!"; + } else { + $sql = "SELECT id FROM endpointman_mac_list WHERE static_ip = '" . $_REQUEST['static_ip'] . "' AND id <> " . $_REQUEST['edit_id']; + $used = $endpoint->eda->sql($sql, 'getOne'); + if ($used) { + $endpoint->error['update_device'] = "You can't assign the same IP Address to multiple devices!"; + } else { + $sql = 'SELECT * FROM endpointman_line_list WHERE mac_id = '. $_REQUEST['edit_id']; + $lines_list = $endpoint->eda->sql($sql,'getAll',DB_FETCHMODE_ASSOC); + foreach($lines_list as $row) { + $sql = "SELECT description FROM devices WHERE id = ".$_REQUEST['ext_list_'.$row['luid']]; + $name = $endpoint->eda->sql($sql,'getOne'); + + $sql = "UPDATE endpointman_line_list SET ipei = '".$_REQUEST['ipei_'.$row['luid']]."', line = '".$_REQUEST['line_list_'.$row['luid']]."', ext = '".$_REQUEST['ext_list_'.$row['luid']]."', description = '".$endpoint->eda->escapeSimple($name)."' WHERE luid = ". $row['luid']; + $endpoint->eda->sql($sql); + } + $sql = "UPDATE endpointman_mac_list SET template_id = '".$_REQUEST['template_list']."', model = '".$_REQUEST['model_list']."', conn_type = '".$_REQUEST['conn_type']."', static_ip = '".$_REQUEST['static_ip']."' WHERE id = ". $_REQUEST['edit_id']; + $endpoint->eda->sql($sql); + $row = $endpoint->get_phone_info($_REQUEST['edit_id']); + $endpoint->prepare_configs($row); + $endpoint->message['edit_save'] = _("Saved")."!"; + $mode = NULL; + } + - $sql = 'SELECT * FROM endpointman_line_list WHERE mac_id = '. $_REQUEST['edit_id']; - - $lines_list = $endpoint->eda->sql($sql,'getAll',DB_FETCHMODE_ASSOC); - - foreach($lines_list as $row) { - $sql = "SELECT description FROM devices WHERE id = ".$_REQUEST['ext_list_'.$row['luid']]; - $name = $endpoint->eda->sql($sql,'getOne'); - - $sql = "UPDATE endpointman_line_list SET ipei = '".$_REQUEST['ipei_'.$row['luid']]."', line = '".$_REQUEST['line_list_'.$row['luid']]."', ext = '".$_REQUEST['ext_list_'.$row['luid']]."', description = '".$endpoint->eda->escapeSimple($name)."' WHERE luid = ". $row['luid']; - $endpoint->eda->sql($sql); } - $sql = "UPDATE endpointman_mac_list SET template_id = '".$_REQUEST['template_list']."', model = '".$_REQUEST['model_list']."' WHERE id = ". $_REQUEST['edit_id']; - $endpoint->eda->sql($sql); - - $row = $endpoint->get_phone_info($_REQUEST['edit_id']); - $endpoint->prepare_configs($row); - - $endpoint->message['edit_save'] = _("Saved")."!"; - $mode = NULL; break; case "delete": $sql = 'SELECT mac_id FROM endpointman_line_list WHERE luid = '.$_REQUEST['edit_id'] ; @@ -108,7 +116,7 @@ switch ($sub_type) { $edit_row['id'] = $_REQUEST['edit_id']; break; case "add" : - $mac_id = $endpoint->add_device($_REQUEST['mac'],$_REQUEST['model_list'],$_REQUEST['ext_list'],$_REQUEST['template_list'],$_REQUEST['line_list']); + $mac_id = $endpoint->add_device($_REQUEST['mac'],$_REQUEST['model_list'],$_REQUEST['conn_type'],$_REQUEST['static_ip'],$_REQUEST['ext_list'],$_REQUEST['template_list'],$_REQUEST['line_list']); if($mac_id) { $phone_info = $endpoint->get_phone_info($mac_id); $endpoint->prepare_configs($phone_info); @@ -280,7 +288,7 @@ switch ($sub_type) { case "add_selected_phones" : if(isset($_REQUEST['add'])) { foreach($_REQUEST['add'] as $num) { - $mac_id = $endpoint->add_device($_REQUEST['mac_'.$num],$_REQUEST['model_list_'.$num],$_REQUEST['ext_list_'.$num]); + $mac_id = $endpoint->add_device($_REQUEST['mac_'.$num],$_REQUEST['model_list_'.$num],$_REQUEST['conn_type_'.$num],$_REQUEST['static_ip_'.$num],$_REQUEST['ext_list_'.$num]); if($mac_id) { $phone_info = $endpoint->get_phone_info($mac_id); if(isset($_REQUEST['reboot_sel'])) { @@ -527,6 +535,7 @@ if (isset($template_editor)) { $endpoint->tpl->assign("amp_conf_serial", base64_encode(serialize($amp_send))); $endpoint->tpl->assign("no_add", $no_add); $endpoint->tpl->assign("mode", $mode); + $endpoint->tpl->assign("conn_types", $endpoint->connectionTypes()); $edit_row['id'] = isset($edit_row['id']) ? $edit_row['id'] : '0'; @@ -565,6 +574,9 @@ if (isset($template_editor)) { $endpoint->tpl->assign("brand_id", $edit_row['brand_id']); $endpoint->tpl->assign("models_ava", $ma); + $endpoint->tpl->assign("conn_types", $endpoint->connectionTypes($edit_row['conn_type'])); + $endpoint->tpl->assign("static_ip", $edit_row['static_ip']); + $endpoint->tpl->assign("display_templates", $endpoint->display_templates($edit_row['product_id'],$edit_row['template_id'])); } else { diff --git a/includes/functions.inc b/includes/functions.inc index c0dfb2ec..ddc49216 100644 --- a/includes/functions.inc +++ b/includes/functions.inc @@ -323,10 +323,16 @@ class endpointmanager { return($phone_info); } - function add_device($mac, $model, $ext, $template=NULL, $line=NULL, $displayname=NULL) { - $ipei = $_REQUEST['ipei']; + function add_device($mac, $model, $conn_type, $static_ip, $ext, $template=NULL, $line=NULL, $displayname=NULL) { + $ipei = $_REQUEST['ipei']; $mac = $this->mac_check_clean($mac); - if ($mac) { + if (!$mac) { + $this->error['add_device'] = _("Invalid MAC Address") . "!"; + return(FALSE); + } elseif(!empty($static_ip) && !filter_var($static_ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { + $this->error['add_device'] = _("Invalid IP Address") . "!"; + return(FALSE); + } else { if (empty($model)) { $this->error['add_device'] = _("You Must Select A Model From the Drop Down") . "!"; return(FALSE); @@ -343,7 +349,7 @@ class endpointmanager { $template = $dup['template_id']; } - $sql = "UPDATE endpointman_mac_list SET model = " . $model . ", template_id = " . $template . " WHERE id = " . $dup['id']; + $sql = "UPDATE endpointman_mac_list SET model = " . $model . ", conn_type = " . $conn_type . ", static_ip = " . $static_ip . ", template_id = " . $template . " WHERE id = " . $dup['id']; $this->eda->sql($sql); $return = $this->add_line($dup['id'], $line, $ext); if ($return) { @@ -363,6 +369,14 @@ class endpointmanager { $this->error['add_device'] = "You can't assign the same user to multiple devices!"; return(FALSE); } + + $sql = "SELECT id FROM endpointman_mac_list WHERE static_ip = '" . $static_ip . "'"; + $used = $this->eda->sql($sql, 'getOne'); + + if ($used) { + $this->error['add_device'] = "You can't assign the same IP Address to multiple devices!"; + return(FALSE); + } if (!isset($displayname)) { $sql = 'SELECT description FROM devices WHERE id = ' . $ext; @@ -375,7 +389,7 @@ class endpointmanager { $row = & $this->eda->sql($sql, 'getRow', DB_FETCHMODE_ASSOC); - $sql = "INSERT INTO `endpointman_mac_list` (`mac`, `model`, `template_id`) VALUES ('" . $mac . "', '" . $model . "', '" . $template . "')"; + $sql = "INSERT INTO `endpointman_mac_list` (`mac`, `model`, `conn_type`, `static_ip`, `template_id`) VALUES ('" . $mac . "', '" . $model . "', '" . $conn_type . "', '" . $static_ip . "', '" . $template . "')"; $this->eda->sql($sql); $sql = 'SELECT last_insert_id()'; @@ -396,9 +410,6 @@ class endpointmanager { return(FALSE); } } - } else { - $this->error['add_device'] = _("Invalid MAC Address") . "!"; - return(FALSE); } } @@ -476,8 +487,21 @@ class endpointmanager { } } - function update_device($macid, $model, $template, $luid=NULL, $name=NULL, $line=NULL, $update_lines=TRUE) { - $sql = "UPDATE endpointman_mac_list SET model = " . $model . ", template_id = " . $template . " WHERE id = " . $macid; + function update_device($macid, $model, $conn_type, $static_ip, $template, $luid=NULL, $name=NULL, $line=NULL, $update_lines=TRUE) { + if(!empty($static_ip) && !filter_var($static_ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { + $this->error['update_device'] = _("Invalid IP Address") . "!"; + return(FALSE); + } + + $sql = "SELECT id FROM endpointman_mac_list WHERE static_ip = '" . $static_ip . "' AND id <> " . $macid; + $used = $this->eda->sql($sql, 'getOne'); + + if ($used) { + $this->error['update_device'] = "You can't assign the same IP Address to multiple devices!"; + return(FALSE); + } + + $sql = "UPDATE endpointman_mac_list SET model = " . $model . ", template_id = " . $template . ", conn_type = " . $conn_type . ", static_ip = " . $static_ip . " WHERE id = " . $macid; $this->eda->sql($sql); if ($update_lines) { @@ -897,8 +921,8 @@ class endpointmanager { $res = $this->eda->sql($sql); if (count($res)) { - //Returns Brand Name, Brand Directory, Model Name, Mac Address, Extension (FreePBX), Custom Configuration Template, Custom Configuration Data, Product Name, Product ID, Product Configuration Directory, Product Configuration Version, Product XML name, - $sql = "SELECT endpointman_mac_list.specific_settings, endpointman_mac_list.config_files_override, endpointman_mac_list.global_user_cfg_data, endpointman_model_list.id as model_id, endpointman_brand_list.id as brand_id, endpointman_brand_list.name, endpointman_brand_list.directory, endpointman_model_list.model, endpointman_mac_list.mac, endpointman_mac_list.template_id, endpointman_mac_list.global_custom_cfg_data, endpointman_product_list.long_name, endpointman_product_list.id as product_id, endpointman_product_list.cfg_dir, endpointman_product_list.cfg_ver, endpointman_model_list.template_data, endpointman_model_list.enabled, endpointman_mac_list.global_settings_override FROM endpointman_line_list, endpointman_mac_list, endpointman_model_list, endpointman_brand_list, endpointman_product_list WHERE endpointman_mac_list.model = endpointman_model_list.id AND endpointman_brand_list.id = endpointman_model_list.brand AND endpointman_product_list.id = endpointman_model_list.product_id AND endpointman_mac_list.id = endpointman_line_list.mac_id AND endpointman_mac_list.id = " . $mac_id; + //Returns Brand Name, Brand Directory, Model Name, Mac Address, Extension (FreePBX), Connection Type, IP Address, Custom Configuration Template, Custom Configuration Data, Product Name, Product ID, Product Configuration Directory, Product Configuration Version, Product XML name, + $sql = "SELECT endpointman_mac_list.specific_settings, endpointman_mac_list.config_files_override, endpointman_mac_list.global_user_cfg_data, endpointman_model_list.id as model_id, endpointman_brand_list.id as brand_id, endpointman_brand_list.name, endpointman_brand_list.directory, endpointman_model_list.model, endpointman_mac_list.mac, endpointman_mac_list.conn_type, endpointman_mac_list.static_ip, endpointman_mac_list.template_id, endpointman_mac_list.global_custom_cfg_data, endpointman_product_list.long_name, endpointman_product_list.id as product_id, endpointman_product_list.cfg_dir, endpointman_product_list.cfg_ver, endpointman_model_list.template_data, endpointman_model_list.enabled, endpointman_mac_list.global_settings_override FROM endpointman_line_list, endpointman_mac_list, endpointman_model_list, endpointman_brand_list, endpointman_product_list WHERE endpointman_mac_list.model = endpointman_model_list.id AND endpointman_brand_list.id = endpointman_model_list.brand AND endpointman_product_list.id = endpointman_model_list.product_id AND endpointman_mac_list.id = endpointman_line_list.mac_id AND endpointman_mac_list.id = " . $mac_id; $phone_info = $this->eda->sql($sql, 'getRow', DB_FETCHMODE_ASSOC); @@ -2044,7 +2068,6 @@ class endpointmanager { - //Loop through Lines! $li = 0; foreach ($phone_info['line'] as $line) { @@ -2112,6 +2135,10 @@ class endpointmanager { $provisioner_lib->settings['provispass'] = $getSysadminSettings[provispass][value]; $provisioner_lib->settings['sslhpro'] = $getSysadminSettings[sslhpro][value]; $provisioner_lib->settings['hpro'] = $getSysadminSettings[hpro][value]; + $provisioner_lib->settings['netmask'] = $this->global_cfg['netmask']; + $provisioner_lib->settings['gateway'] = $this->global_cfg['gateway']; + $provisioner_lib->settings['dns1'] = $this->global_cfg['dns1']; + $provisioner_lib->settings['dns2'] = $this->global_cfg['dns2']; $provisioner_lib->settings['timestamp'] = time(); @@ -2238,6 +2265,8 @@ class endpointmanager { } $provisioner_lib->settings['mac'] = $phone_info['mac']; + $provisioner_lib->settings['conn_type'] = $phone_info['conn_type']; + $provisioner_lib->settings['static_ip'] = $phone_info['static_ip']; $provisioner_lib->mac = $phone_info['mac']; //Setting a line variable here...these aren't defined in the template_data.xml file yet. however they will still be parsed @@ -3815,6 +3844,21 @@ class endpointmanager { return($temp); } + + function connectionTypes($selected = NULL) { + $modes = array("DHCP", "Static IP"); + $temp = array(); + $i = 0; + foreach ($modes as $mode) { + $temp[$i]['value'] = $mode; + $temp[$i]['text'] = $mode; + if ($mode == $selected) { + $temp[$i]['selected'] = "selected"; + } + $i++; + } + return($temp); + } function listTZ($selected) { require('timezone.inc'); diff --git a/install.php b/install.php index 453de9e6..30a92e02 100644 --- a/install.php +++ b/install.php @@ -97,7 +97,11 @@ function epm_find_exec($exec) { (26, 'adminpass', '123456'), (27, 'userpass', '111111'), (28, 'intsrvip', ''), - (29, 'disable_endpoint_warning', '0')"; + (29, 'disable_endpoint_warning', '0'), + (30, 'netmask', '255.255.255.0'), + (31, 'gateway', ''), + (32, 'dns1', ''), + (33, 'dns2', '')"; $db->query($sql); out("Done"); @@ -117,16 +121,25 @@ function epm_find_exec($exec) { if ($epmdbversion < "14.0.0.1"){ -$sql = "UPDATE endpointman_global_vars SET value = 'http://mirror.freepbx.org/provisioner/v3/' WHERE var_name = 'update_server'"; -$db->query($sql); + $sql = "UPDATE endpointman_global_vars SET value = 'http://mirror.freepbx.org/provisioner/v3/' WHERE var_name = 'update_server'"; + $db->query($sql); } if ($epmdbversion < "14.0.1.4"){ - $sql = "INSERT INTO `endpointman_global_vars` (`idnum`, `var_name`, `value`) VALUES - (26, 'adminpass', '123456'), - (27, 'userpass', '111111'), - (28, 'intsrvip', ''), - (29, 'disable_endpoint_warning', '0')"; - $db->query($sql); - out("Done"); - } \ No newline at end of file + $sql = "INSERT INTO `endpointman_global_vars` (`idnum`, `var_name`, `value`) VALUES + (26, 'adminpass', '123456'), + (27, 'userpass', '111111'), + (28, 'intsrvip', ''), + (29, 'disable_endpoint_warning', '0')"; + $db->query($sql); +} + +if($epmdbversion < "14.0.4"){ + $sql = "INSERT INTO `endpointman_global_vars` (`idnum`, `var_name`, `value`) VALUES + (30, 'netmask', '255.255.255.0'), + (31, 'gateway', ''), + (32, 'dns1', ''), + (33, 'dns2', '')"; + $db->query($sql); + out("Done"); +} diff --git a/lib/epm_data_abstraction.class.php b/lib/epm_data_abstraction.class.php index 6e30b736..5d9a1d17 100644 --- a/lib/epm_data_abstraction.class.php +++ b/lib/epm_data_abstraction.class.php @@ -20,7 +20,7 @@ function all_products() { } function all_devices() { - $sql = 'SELECT endpointman_mac_list.id , endpointman_mac_list.mac , endpointman_model_list.model, endpointman_model_list.enabled , endpointman_brand_list.name, endpointman_mac_list.global_custom_cfg_data, endpointman_mac_list.template_id FROM endpointman_mac_list , endpointman_model_list , endpointman_brand_list WHERE ( endpointman_model_list.id = endpointman_mac_list.model ) AND ( endpointman_model_list.brand = endpointman_brand_list.id )'; + $sql = 'SELECT endpointman_mac_list.id , endpointman_mac_list.mac , endpointman_model_list.model, endpointman_model_list.enabled , endpointman_brand_list.name, endpointman_mac_list.global_custom_cfg_data, endpointman_mac_list.template_id, endpointman_mac_list.conn_type, endpointman_mac_list.static_ip FROM endpointman_mac_list , endpointman_model_list , endpointman_brand_list WHERE ( endpointman_model_list.id = endpointman_mac_list.model ) AND ( endpointman_model_list.brand = endpointman_brand_list.id )'; $temp = sql($sql,'getAll',DB_FETCHMODE_ASSOC); return($temp); } diff --git a/module.xml b/module.xml index ef806766..7442f95c 100644 --- a/module.xml +++ b/module.xml @@ -2,7 +2,7 @@ endpointman unsupported OSS PBX End Point Manager - 14.0.3 + 14.0.4 setup Settings GPLv3+ @@ -23,6 +23,7 @@ Pull Requests can be made to either of these and are encouraged. + *14.0.4* Added option for assigning static IP Addresses to the phones *14.0.3* Support for PHP 7 *14.0.2.1* Line State icon was only red. The state green/red is now fixed and works. *14.0.2* Fixed a Problem if Sysadmin is not installed. Sysadmin is a commercial module and should not be forced to be installed to use OSS EPM. diff --git a/templates/freepbx/devices_manager.html b/templates/freepbx/devices_manager.html index fbe154a3..6d7856e4 100644 --- a/templates/freepbx/devices_manager.html +++ b/templates/freepbx/devices_manager.html @@ -207,19 +207,26 @@

{if condition="$mode != 'EDIT'"}{else} - - - - - - - - - - - - - + + + + + + +{if condition="$mode == 'EDIT'"} + +{/if} + + + + + + @@ -283,6 +290,23 @@

{if condition="$mode != 'EDIT'"}{else} {/if} + +{if condition="$mode == 'EDIT'"} + +{/if} + + + + + + + + +
- - - - - {$value.line} - {$value.ext} - {$value.description} - - - - {/loop} + + alt=":"> + + + + + {$value.line} + {$value.ext} - {$value.description} + + + + + + + {/loop} {/loop} - + diff --git a/views/epm_advanced_settings.page.php b/views/epm_advanced_settings.page.php index 17e2e3d5..f1bf8e9e 100644 --- a/views/epm_advanced_settings.page.php +++ b/views/epm_advanced_settings.page.php @@ -292,6 +292,123 @@
+
+

+
+
+ +
+
+
+
+
+
+ + +
+
+ "> +
+
+
+
+
+
+
+ +
+
+
+ + +
+
+
+
+
+
+ + +
+
+
+ "> + + + +
+
+
+
+
+
+
+
+ +
+
+
+ + +
+
+
+
+
+
+ + +
+
+
+ "> + + + +
+
+
+
+
+
+
+
+ +
+
+
+ + +
+
+
+
+
+
+ + +
+
+
+ "> + + + +
+
+
+
+
+
+
+
+ +
+
+
+ +
+

From 8614675f764aaf2138c5b2286a591f9551c75229 Mon Sep 17 00:00:00 2001 From: rapperskull Date: Wed, 26 Jun 2019 15:47:16 +0200 Subject: [PATCH 02/11] Use the standard method to assign static IPs. --- includes/devices_manager.inc | 15 +++++++------ includes/functions.inc | 43 ++++++++++++++++++++++++++---------- module.xml | 2 ++ 3 files changed, 41 insertions(+), 19 deletions(-) diff --git a/includes/devices_manager.inc b/includes/devices_manager.inc index ff333648..462fb3b8 100644 --- a/includes/devices_manager.inc +++ b/includes/devices_manager.inc @@ -453,13 +453,14 @@ foreach($devices_list as $devices_row) { } $list[$i]['master_id'] = $i; foreach($line_list as $line_row) { - $list[$i]['line'][$z]['ext'] = $line_row['ext']; - $list[$i]['line'][$z]['line'] = $line_row['line']; - $list[$i]['line'][$z]['description'] = $line_row['description']; - $list[$i]['line'][$z]['luid'] = $line_row['luid']; - $list[$i]['line'][$z]['ipei'] = $line_row['ipei']; - $list[$i]['line'][$z]['master_id'] = $i; - $z++; + $list[$i]['line'][$z]['ext'] = $line_row['ext']; + $list[$i]['line'][$z]['line'] = $line_row['line']; + $list[$i]['line'][$z]['description'] = $line_row['description']; + $list[$i]['line'][$z]['conn_type'] = $devices_row['conn_type']=="STATIC" ? "Static IP" : $devices_row['conn_type']; + $list[$i]['line'][$z]['luid'] = $line_row['luid']; + $list[$i]['line'][$z]['ipei'] = $line_row['ipei']; + $list[$i]['line'][$z]['master_id'] = $i; + $z++; } $ext = $list[$i]['line'][0]['ext']; diff --git a/includes/functions.inc b/includes/functions.inc index ddc49216..b98f03a6 100644 --- a/includes/functions.inc +++ b/includes/functions.inc @@ -2135,10 +2135,6 @@ class endpointmanager { $provisioner_lib->settings['provispass'] = $getSysadminSettings[provispass][value]; $provisioner_lib->settings['sslhpro'] = $getSysadminSettings[sslhpro][value]; $provisioner_lib->settings['hpro'] = $getSysadminSettings[hpro][value]; - $provisioner_lib->settings['netmask'] = $this->global_cfg['netmask']; - $provisioner_lib->settings['gateway'] = $this->global_cfg['gateway']; - $provisioner_lib->settings['dns1'] = $this->global_cfg['dns1']; - $provisioner_lib->settings['dns2'] = $this->global_cfg['dns2']; $provisioner_lib->settings['timestamp'] = time(); @@ -2265,8 +2261,24 @@ class endpointmanager { } $provisioner_lib->settings['mac'] = $phone_info['mac']; - $provisioner_lib->settings['conn_type'] = $phone_info['conn_type']; - $provisioner_lib->settings['static_ip'] = $phone_info['static_ip']; + if (empty($provisioner_lib->settings['network']['connection_type'])) { + $provisioner_lib->settings['network']['connection_type'] = $phone_info['conn_type']; + } + if (empty($provisioner_lib->settings['network']['ipv4'])) { + $provisioner_lib->settings['network']['ipv4'] = $phone_info['static_ip']; + } + if (empty($provisioner_lib->settings['network']['subnet'])) { + $provisioner_lib->settings['network']['subnet'] = $this->global_cfg['netmask']; + } + if (empty($provisioner_lib->settings['network']['gateway'])) { + $provisioner_lib->settings['network']['gateway'] = $this->global_cfg['gateway']; + } + if (empty($provisioner_lib->settings['network']['primary_dns'])) { + $provisioner_lib->settings['network']['primary_dns'] = $this->global_cfg['dns1']; + } + if (empty($provisioner_lib->settings['network']['secondary_dns'])) { + $provisioner_lib->settings['network']['secondary_dns'] = $this->global_cfg['dns2']; + } $provisioner_lib->mac = $phone_info['mac']; //Setting a line variable here...these aren't defined in the template_data.xml file yet. however they will still be parsed @@ -2293,6 +2305,7 @@ class endpointmanager { if ($time > 360) { $this->error['generate_time'] = "It took an awfully long time to generate configs...(" . round($time, 2) . " seconds)"; } + //var_dump($provisioner_lib); if ($write) { $this->write_configs($provisioner_lib, $reboot, $settings['config_location'], $phone_info, $returned_data); } else { @@ -3846,13 +3859,19 @@ class endpointmanager { } function connectionTypes($selected = NULL) { - $modes = array("DHCP", "Static IP"); - $temp = array(); + $temp = array( + array( + "value" => "DHCP", + "text" => "DHCP" + ), + array( + "value" => "STATIC", + "text" => "Static IP" + ) + ); $i = 0; - foreach ($modes as $mode) { - $temp[$i]['value'] = $mode; - $temp[$i]['text'] = $mode; - if ($mode == $selected) { + foreach ($temp as $mode) { + if ($mode['value'] == $selected) { $temp[$i]['selected'] = "selected"; } $i++; diff --git a/module.xml b/module.xml index 7442f95c..e16adec7 100644 --- a/module.xml +++ b/module.xml @@ -115,6 +115,8 @@ + + From e6bf7139db8d6dc677e1156fcff58e944db7b055 Mon Sep 17 00:00:00 2001 From: rapperskull Date: Thu, 27 Jun 2019 07:20:12 +0200 Subject: [PATCH 03/11] Fix typo --- assets/js/epm_advanced.js | 2 +- assets/js/epm_global.js | 2 +- templates/freepbx/devices_manager.html | 7 +------ 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/assets/js/epm_advanced.js b/assets/js/epm_advanced.js index f34ffdde..a00cce2e 100644 --- a/assets/js/epm_advanced.js +++ b/assets/js/epm_advanced.js @@ -726,7 +726,7 @@ function epm_advanced_tab_oui_manager_refresh_table(showmsg = true) { $("#mygrid").bootstrapTable('refresh'); if (showmsg === true) { - fpbxToast("Table Refrash Ok!", '', 'success'); + fpbxToast("Table Refresh Ok!", '', 'success'); } } diff --git a/assets/js/epm_global.js b/assets/js/epm_global.js index 13da73a1..27c12400 100644 --- a/assets/js/epm_global.js +++ b/assets/js/epm_global.js @@ -223,7 +223,7 @@ function epm_global_refresh_table(snametable = "", showmsg = false) if (snametable === "") { return; } $(snametable).bootstrapTable('refresh'); if (showmsg === true) { - fpbxToast("Table Refrash Ok!", '', 'success'); + fpbxToast("Table Refresh Ok!", '', 'success'); } } diff --git a/templates/freepbx/devices_manager.html b/templates/freepbx/devices_manager.html index 6d7856e4..1ec799ca 100644 --- a/templates/freepbx/devices_manager.html +++ b/templates/freepbx/devices_manager.html @@ -218,12 +218,7 @@

{if condition="$mode != 'EDIT'"}{else} - + From 57c7a50ccc6a6c4ce3ecc7ee56414cc9f7174add Mon Sep 17 00:00:00 2001 From: rapperskull Date: Thu, 27 Jun 2019 08:56:17 +0200 Subject: [PATCH 04/11] Allow for empty gateway, primary and secondary DNS --- Endpointman_Advanced.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Endpointman_Advanced.class.php b/Endpointman_Advanced.class.php index 3aef228d..0284d062 100644 --- a/Endpointman_Advanced.class.php +++ b/Endpointman_Advanced.class.php @@ -446,7 +446,7 @@ private function epm_advanced_settings_saveconfig () case "gateway": $dget['value'] = trim($dget['value']); - if(filter_var($dget['value'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)){ + if(empty($dget['value']) || filter_var($dget['value'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)){ $sql = "UPDATE endpointman_global_vars SET value='" . $dget['value'] . "' WHERE var_name='gateway'"; } else { $retarr = array("status" => false, "message" => _("Invalid Gateway IP Address!")); @@ -455,7 +455,7 @@ private function epm_advanced_settings_saveconfig () case "dns1": $dget['value'] = trim($dget['value']); - if(filter_var($dget['value'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)){ + if(empty($dget['value']) || filter_var($dget['value'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)){ $sql = "UPDATE endpointman_global_vars SET value='" . $dget['value'] . "' WHERE var_name='dns1'"; } else { $retarr = array("status" => false, "message" => _("Invalid Primary DNS IP Address!")); @@ -464,7 +464,7 @@ private function epm_advanced_settings_saveconfig () case "dns2": $dget['value'] = trim($dget['value']); - if(filter_var($dget['value'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)){ + if(empty($dget['value']) || filter_var($dget['value'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)){ $sql = "UPDATE endpointman_global_vars SET value='" . $dget['value'] . "' WHERE var_name='dns2'"; } else { $retarr = array("status" => false, "message" => _("Invalid Secondary DNS IP Address!")); From 85ddea837fe64d33cb7a08bf9095a39af7aa61c4 Mon Sep 17 00:00:00 2001 From: rapperskull Date: Thu, 27 Jun 2019 13:14:09 +0200 Subject: [PATCH 05/11] Fixed bug when updating extension --- functions.inc.php | 9 +++++---- includes/functions.inc | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/functions.inc.php b/functions.inc.php index 1b6cf656..35dc5071 100644 --- a/functions.inc.php +++ b/functions.inc.php @@ -135,8 +135,9 @@ function endpointman_configpageinit($pagename) { $reboot = isset($_REQUEST['epm_reboot']) ? $_REQUEST['epm_reboot'] : null; if ($endpoint->mac_check_clean($mac)) { - $sql = "SELECT id FROM endpointman_mac_list WHERE mac = '" . $endpoint->mac_check_clean($mac) . "'"; - $macid = $endpoint->eda->sql($sql, 'getOne'); + $sql = "SELECT * FROM endpointman_mac_list WHERE mac = '" . $endpoint->mac_check_clean($mac) . "'"; + $device = $endpoint->eda->sql($sql, 'getRow', DB_FETCHMODE_ASSOC); + $macid = $device['id']; if ($macid) { //In Database already @@ -145,7 +146,7 @@ function endpointman_configpageinit($pagename) { if (($lines_list) AND (isset($model)) AND (isset($line)) AND (!isset($delete)) AND (isset($temp))) { //Modifying line already in the database - $endpoint->update_device($macid, $model, $conn_type, $static_ip, $temp, $lines_list['luid'], $name, $lines_list['line']); + $endpoint->update_device($macid, $model, $device['conn_type'], $device['static_ip'], $temp, $lines_list['luid'], $name, $lines_list['line']); $row = $endpoint->get_phone_info($macid); if (isset($reboot)) { @@ -162,7 +163,7 @@ function endpointman_configpageinit($pagename) { $endpoint->add_line($macid, $line, $extdisplay, $name); } - $endpoint->update_device($macid, $model, $conn_type, $static_ip, $temp, NULL, NULL, NULL, FALSE); + $endpoint->update_device($macid, $model, $device['conn_type'], $device['static_ip'], $temp, NULL, NULL, NULL, FALSE); $row = $endpoint->get_phone_info($macid); if (isset($reboot)) { diff --git a/includes/functions.inc b/includes/functions.inc index b98f03a6..6d3ffaae 100644 --- a/includes/functions.inc +++ b/includes/functions.inc @@ -501,7 +501,7 @@ class endpointmanager { return(FALSE); } - $sql = "UPDATE endpointman_mac_list SET model = " . $model . ", template_id = " . $template . ", conn_type = " . $conn_type . ", static_ip = " . $static_ip . " WHERE id = " . $macid; + $sql = "UPDATE endpointman_mac_list SET model = " . $model . ", template_id = " . $template . ", conn_type = '" . $conn_type . "', static_ip = '" . $static_ip . "' WHERE id = " . $macid; $this->eda->sql($sql); if ($update_lines) { From 4e212e28b1043706696e6effad89f19c0c9f27d7 Mon Sep 17 00:00:00 2001 From: rapperskull Date: Fri, 28 Jun 2019 02:51:56 +0200 Subject: [PATCH 06/11] Fix unescaped variables in DB UPDATE --- includes/functions.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/functions.inc b/includes/functions.inc index 6d3ffaae..c14d160c 100644 --- a/includes/functions.inc +++ b/includes/functions.inc @@ -349,7 +349,7 @@ class endpointmanager { $template = $dup['template_id']; } - $sql = "UPDATE endpointman_mac_list SET model = " . $model . ", conn_type = " . $conn_type . ", static_ip = " . $static_ip . ", template_id = " . $template . " WHERE id = " . $dup['id']; + $sql = "UPDATE endpointman_mac_list SET model = " . $model . ", conn_type = '" . $conn_type . "', static_ip = '" . $static_ip . "', template_id = " . $template . " WHERE id = " . $dup['id']; $this->eda->sql($sql); $return = $this->add_line($dup['id'], $line, $ext); if ($return) { From 345d91bc4f8a3b6f682eaa4895ef05ae0a901410 Mon Sep 17 00:00:00 2001 From: rapperskull Date: Fri, 28 Jun 2019 04:10:58 +0200 Subject: [PATCH 07/11] Add ability to override global settings for netmask, gateway and DNSs --- Endpointman_Templates.class.php | 9 ++ assets/js/epm_templates.js | 10 +- includes/functions.inc | 5 + .../editor.views.dialog.cfg.global.php | 119 ++++++++++++++++++ 4 files changed, 142 insertions(+), 1 deletion(-) diff --git a/Endpointman_Templates.class.php b/Endpointman_Templates.class.php index 4fc55a28..e2b75682 100644 --- a/Endpointman_Templates.class.php +++ b/Endpointman_Templates.class.php @@ -222,6 +222,11 @@ public function epm_template_custom_config_update_global () $_REQUEST['srvip'] = trim($_REQUEST['srvip']); #trim whitespace from IP address $_REQUEST['config_loc'] = trim($_REQUEST['config_loc']); #trim whitespace from Config Location + + $_REQUEST['netmask'] = trim($_REQUEST['netmask']); + $_REQUEST['gateway'] = trim($_REQUEST['gateway']); + $_REQUEST['dns1'] = trim($_REQUEST['dns1']); + $_REQUEST['dns2'] = trim($_REQUEST['dns2']); $settings_warning = ""; if (strlen($_REQUEST['config_loc']) > 0) { @@ -253,6 +258,10 @@ public function epm_template_custom_config_update_global () $settings['srvip'] = (isset($_REQUEST['srvip']) ? $_REQUEST['srvip'] : ""); $settings['ntp'] = (isset($_REQUEST['ntp_server']) ? $_REQUEST['ntp_server'] : ""); $settings['tz'] = (isset($_REQUEST['tz']) ? $_REQUEST['tz'] : ""); + $settings['netmask'] = (isset($_REQUEST['netmask']) ? $_REQUEST['netmask'] : ""); + $settings['gateway'] = (isset($_REQUEST['gateway']) ? $_REQUEST['gateway'] : ""); + $settings['dns1'] = (isset($_REQUEST['dns1']) ? $_REQUEST['dns1'] : ""); + $settings['dns2'] = (isset($_REQUEST['dns2']) ? $_REQUEST['dns2'] : ""); $settings_ser = serialize($settings); unset($settings); diff --git a/assets/js/epm_templates.js b/assets/js/epm_templates.js index 76768129..a686f867 100644 --- a/assets/js/epm_templates.js +++ b/assets/js/epm_templates.js @@ -358,6 +358,10 @@ function epm_template_custom_config_get_global(elmnt) epm_global_input_value_change_bt("#config_loc", data.settings.config_location, false); epm_global_input_value_change_bt("#tz", data.settings.tz, false); epm_global_input_value_change_bt("#ntp_server", data.settings.ntp, false); + epm_global_input_value_change_bt("#netmask", data.settings.netmask, false); + epm_global_input_value_change_bt("#gateway", data.settings.gateway, false); + epm_global_input_value_change_bt("#dns1", data.settings.dns1, false); + epm_global_input_value_change_bt("#dns2", data.settings.dns2, false); if (elmnt.name == "button_undo_globals") { fpbxToast(data.message, '', 'success'); @@ -384,7 +388,11 @@ function epm_template_custom_config_update_global(elmnt) ntp_server: epm_global_get_value_by_form("FormCfgGlobalTemplate","ntp_server"), srvip: epm_global_get_value_by_form("FormCfgGlobalTemplate","srvip"), config_loc: epm_global_get_value_by_form("FormCfgGlobalTemplate","config_loc"), - server_type: epm_global_get_value_by_form("FormCfgGlobalTemplate","server_type") + server_type: epm_global_get_value_by_form("FormCfgGlobalTemplate","server_type"), + netmask: epm_global_get_value_by_form("FormCfgGlobalTemplate","netmask"), + gateway: epm_global_get_value_by_form("FormCfgGlobalTemplate","gateway"), + dns1: epm_global_get_value_by_form("FormCfgGlobalTemplate","dns1"), + dns2: epm_global_get_value_by_form("FormCfgGlobalTemplate","dns2") }, dataType: 'json', timeout: 60000, diff --git a/includes/functions.inc b/includes/functions.inc index c14d160c..62e992aa 100644 --- a/includes/functions.inc +++ b/includes/functions.inc @@ -2011,6 +2011,11 @@ class endpointmanager { } $new_template_data['ntp'] = $settings['ntp']; + + $new_template_data['network']['subnet'] = $settings['netmask']; + $new_template_data['network']['gateway'] = $settings['gateway']; + $new_template_data['network']['primary_dns'] = $settings['dns1']; + $new_template_data['network']['secondary_dns'] = $settings['dns2']; //Overwrite all specific settings variables now if (!empty($phone_info['specific_settings'])) { diff --git a/views/epm_templates/editor.views.dialog.cfg.global.php b/views/epm_templates/editor.views.dialog.cfg.global.php index a06778f4..f2786b1c 100644 --- a/views/epm_templates/editor.views.dialog.cfg.global.php +++ b/views/epm_templates/editor.views.dialog.cfg.global.php @@ -189,6 +189,125 @@ +
+

+
+
+ +
+
+
+
+
+
+ + +
+
+ " id="netmask" name="netmask" value=""> +
+
+
+
+
+
+
+ +
+
+
+ + +
+
+
+
+
+
+ + +
+
+
+ " id="gateway" name="gateway" value=""> + + + +
+
+
+
+
+
+
+
+ +
+
+
+ + +
+
+
+
+
+
+ + +
+
+
+ " id="dns1" name="dns1" value=""> + + + +
+
+
+
+
+
+
+
+ +
+
+
+ + +
+
+
+
+
+
+ + +
+
+
+ " id="dns2" name="dns2" value=""> + + + +
+
+
+
+
+
+
+
+ +
+
+
+ +
+ + +