Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 59 additions & 3 deletions Endpointman_Advanced.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

class Endpointman_Advanced
{
public $MODULES_PATH;
public $MODULES_PATH;
public $LOCAL_PATH;
public $PHONE_MODULES_PATH;

Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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'";
Expand Down Expand Up @@ -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'] );
Expand Down
13 changes: 13 additions & 0 deletions Endpointman_Templates.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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!"));
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion assets/js/epm_advanced.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}

Expand Down
2 changes: 1 addition & 1 deletion assets/js/epm_global.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}

Expand Down
10 changes: 9 additions & 1 deletion assets/js/epm_templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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,
Expand Down
15 changes: 9 additions & 6 deletions functions.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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

Expand All @@ -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)) {
Expand All @@ -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)) {
Expand All @@ -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?');
Expand Down
2 changes: 1 addition & 1 deletion includes/abstraction/freepbx.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Loading