diff --git a/Endpointman_Advanced.class.php b/Endpointman_Advanced.class.php index f8dae74e..0284d062 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(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!")); + } + break; + + case "dns1": + $dget['value'] = trim($dget['value']); + 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!")); + } + break; + + case "dns2": + $dget['value'] = trim($dget['value']); + 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!")); + } + break; default: $retarr = array("status" => false, "message" => _("Name invalid: ") . $dget['name'] ); diff --git a/Endpointman_Templates.class.php b/Endpointman_Templates.class.php index 4fc55a28..e1b031dc 100644 --- a/Endpointman_Templates.class.php +++ b/Endpointman_Templates.class.php @@ -194,6 +194,10 @@ public function epm_template_custom_config_get_global() $settings['config_location'] = ""; //$this->configmod->get("config_location"); $settings['tz'] = $this->configmod->get("tz"); $settings['server_type'] = $this->configmod->get("server_type"); + $settings['netmask'] = ""; + $settings['gateway'] = ""; + $settings['dns1'] = ""; + $settings['dns2'] = ""; } $retarr = array("status" => true, "settings" => $settings, "message" => _("Global Config Read OK!")); @@ -222,6 +226,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 +262,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_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/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/functions.inc.php b/functions.inc.php index d617757b..35dc5071 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; @@ -133,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 @@ -143,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, $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)) { @@ -160,7 +163,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, $device['conn_type'], $device['static_ip'], $temp, NULL, NULL, NULL, FALSE); $row = $endpoint->get_phone_info($macid); if (isset($reboot)) { @@ -171,7 +174,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..9652fd7c 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); @@ -146,22 +154,10 @@ switch ($sub_type) { case "rebuild_selected_phones": if(isset($_REQUEST['selected'])) { $sql = "SELECT mac_id, ext FROM endpointman_line_list"; - $endpoint->eda->sql($sql); - $lines = $endpoint->eda->sql($sql,'getAll',DB_FETCHMODE_ASSOC); - - foreach($_REQUEST['selected'] as $key => $data) { - - foreach($lines as $line){ - if ($data == $line[ext]){ - $sql = "SELECT mac_id FROM endpointman_line_list WHERE ext = " . $data; - $endpoint->eda->sql($sql); - $macid = $endpoint->eda->sql($sql,'getrow',DB_FETCHMODE_ASSOC); - $_REQUEST['selected'][$key] = $macid[mac_id]; - - } - } - - + $endpoint->eda->sql($sql); + $lines = $endpoint->eda->sql($sql,'getAll',DB_FETCHMODE_ASSOC); + + foreach($_REQUEST['selected'] as $key => $data) { $phone_info = $endpoint->get_phone_info($_REQUEST['selected'][$key]); if(isset($_REQUEST['reboot'])) { $endpoint->prepare_configs($phone_info); @@ -280,7 +276,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'])) { @@ -295,25 +291,13 @@ switch ($sub_type) { case "change_brand" : if(isset($_REQUEST['selected'])) { if(($_REQUEST['brand_list_selected'] > 0) AND ($_REQUEST['model_list_selected'] > 0)) { - $sql = "SELECT mac_id, ext FROM endpointman_line_list"; - $endpoint->eda->sql($sql); - $lines = $endpoint->eda->sql($sql,'getAll',DB_FETCHMODE_ASSOC); - - foreach($_REQUEST['selected'] as $key => $data) { - - foreach($lines as $line){ - if ($data == $line[ext]){ - $sql = "SELECT mac_id FROM endpointman_line_list WHERE ext = " . $data; - $endpoint->eda->sql($sql); - $macid = $endpoint->eda->sql($sql,'getrow',DB_FETCHMODE_ASSOC); - $_REQUEST['selected'][$key] = $macid[mac_id]; - - } - } - + $sql = "SELECT mac_id, ext FROM endpointman_line_list"; + $endpoint->eda->sql($sql); + $lines = $endpoint->eda->sql($sql,'getAll',DB_FETCHMODE_ASSOC); + + foreach($_REQUEST['selected'] as $key => $data) { $sql = "UPDATE endpointman_mac_list SET global_custom_cfg_data = '', template_id = 0, global_user_cfg_data = '', config_files_override = '', model = '".$_REQUEST['model_list_selected']."' WHERE id = ". $_REQUEST['selected'][$key]; $endpoint->eda->sql($sql); - $phone_info = $endpoint->get_phone_info($_REQUEST['selected'][$key]); $endpoint->prepare_configs($phone_info); $rebooted = ""; @@ -445,13 +429,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']; @@ -527,6 +512,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 +551,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..2ddd332c 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,15 @@ class endpointmanager { $this->error['add_device'] = "You can't assign the same user to multiple devices!"; return(FALSE); } + + if(!empty($static_ip)){ + $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 +390,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 +411,6 @@ class endpointmanager { return(FALSE); } } - } else { - $this->error['add_device'] = _("Invalid MAC Address") . "!"; - return(FALSE); } } @@ -476,10 +488,24 @@ 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); + } + + if(!empty($static_ip)){ + $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) { if (isset($luid)) { $this->update_line($luid, NULL, $name, $line); @@ -555,12 +581,10 @@ class endpointmanager { } function delete_device($mac_id) { - - - $sql = "DELETE FROM endpointman_line_list WHERE ext=" . $mac_id; + $sql = "DELETE FROM endpointman_line_list WHERE mac_id=" . $mac_id; $this->eda->sql($sql); - - $sql = "DELETE FROM endpointman_mac_list WHERE NOT EXISTS (SELECT * FROM endpointman_line_list WHERE mac_id = id)"; + + $sql = "DELETE FROM endpointman_mac_list WHERE NOT EXISTS (SELECT * FROM endpointman_line_list WHERE mac_id = id)"; $this->eda->sql($sql); $this->message['delete_device'] = "Deleted!"; return(TRUE); @@ -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); @@ -1849,24 +1873,23 @@ class endpointmanager { $provisioner_lib = new $class(); //Determine if global settings have been overridden - if ($phone_info['template_id'] > 0) { - if (isset($phone_info['template_data_info']['global_settings_override'])) { - $settings = unserialize($phone_info['template_data_info']['global_settings_override']); - } else { - $settings['srvip'] = $this->global_cfg['srvip']; - $settings['ntp'] = $this->global_cfg['ntp']; - $settings['config_location'] = $this->global_cfg['config_location']; - $settings['tz'] = $this->global_cfg['tz']; - } - } else { - if (isset($phone_info['global_settings_override'])) { - $settings = unserialize($phone_info['global_settings_override']); - } else { - $settings['srvip'] = $this->global_cfg['srvip']; - $settings['ntp'] = $this->global_cfg['ntp']; - $settings['config_location'] = $this->global_cfg['config_location']; - $settings['tz'] = $this->global_cfg['tz']; - } + if ($phone_info['template_id'] > 0 && isset($phone_info['template_data_info']['global_settings_override'])) { + $settings = unserialize($phone_info['template_data_info']['global_settings_override']); + } elseif (isset($phone_info['global_settings_override'])) { + $settings = unserialize($phone_info['global_settings_override']); + } + + if(empty($settings['srvip'])){ + $settings['srvip'] = $this->global_cfg['srvip']; + } + if(empty($settings['ntp'])){ + $settings['ntp'] = $this->global_cfg['ntp']; + } + if(empty($settings['config_location'])){ + $settings['config_location'] = $this->global_cfg['config_location']; + } + if(empty($settings['tz'])){ + $settings['tz'] = $this->global_cfg['tz']; } @@ -1987,6 +2010,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'])) { @@ -2044,7 +2072,6 @@ class endpointmanager { - //Loop through Lines! $li = 0; foreach ($phone_info['line'] as $line) { @@ -2238,6 +2265,24 @@ class endpointmanager { } $provisioner_lib->settings['mac'] = $phone_info['mac']; + 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 @@ -2264,6 +2309,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 { @@ -3815,6 +3861,27 @@ class endpointmanager { return($temp); } + + function connectionTypes($selected = NULL) { + $temp = array( + array( + "value" => "DHCP", + "text" => "DHCP" + ), + array( + "value" => "STATIC", + "text" => "Static IP" + ) + ); + $i = 0; + foreach ($temp as $mode) { + if ($mode['value'] == $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..e16adec7 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. @@ -114,6 +115,8 @@ + + diff --git a/templates/freepbx/devices_manager.html b/templates/freepbx/devices_manager.html index fbe154a3..80899ab1 100644 --- a/templates/freepbx/devices_manager.html +++ b/templates/freepbx/devices_manager.html @@ -207,19 +207,21 @@

{if condition="$mode != 'EDIT'"}{else} - - - - - - - - - - - - - + + + + + + +{if condition="$mode == 'EDIT'"} + +{/if} + + + + + + @@ -283,6 +285,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 @@
+
+

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

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=""> + + + +
+
+
+
+
+
+
+
+ +
+
+
+ +
+ + +