Standardise handling of IED fields (net and ip addresses)
Correct writing to db (seq was assigned a new value which caused duplication in sccpsettings and apparent unsaved data)
Remove inherit button in device and standardise to inherit server settings. Show users what will be set.
This commit is contained in:
stevenA 2022-01-27 12:00:28 +01:00
parent fb7a7da60a
commit 34ec5dc91a
8 changed files with 280 additions and 202 deletions

View file

@ -624,7 +624,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
$result = array();
if (!file_exists("{$this->sccppath['tftp_path']}/masterFilesStructure.xml")) {
if (!$this->getFileListFromProvisioner($this->sccppath['tftp_path'])) {
if (!$this->getFileListFromProvisioner($this->sccpvalues['tftp_path']['data'])) {
// File does not exist and cannot get from internet.
return $result;
};
@ -695,7 +695,6 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
*/
function initializeSccpPath() {
$this->sccppath = array(
'asterisk' => $this->sccpvalues['asterisk_etc_path']['data'],
'tftp_path' => $this->sccpvalues['tftp_path']['data'],
@ -923,7 +922,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
$hw_addon = explode(',', $dev_config['addon']);
foreach ($hw_addon as $key) {
$hw_data = $this->getSccpModelInformation('byid', false, "all", array('model' => $key));
$dev_config['addon_info'][$key] = $hw_data[0]['loadimage'];
$dev_config['addon_info'][$key] = $hw_data[$key]['loadimage'];
}
}
if (!$sccp_native) {

View file

@ -114,10 +114,6 @@ $(document).ready(function () {
});
});
$(".input-js-add").click(function () {
add_dynamic_input($(this), $(this).data('for'), "", "");
});
$(".table").on('click', '.table-js-add', function (e) {
add_dynamic_table($(this), $(this).data('for'), "", "");
});
@ -934,32 +930,51 @@ function load_oncliсk(e, data)
}
}
// call from here not document.ready as have dynamic content
$(document).on('click', ".input-js-remove" , function () {
// delete the current row
var pname = $(this).data('id');
$('#' + pname).remove();
});
function add_dynamic_input(pe, pclass, vdefault)
{
// We'd like a new one, please.
pcls = pe.data('for');
pname = pe.data('id');
pmax = pe.data('max');
jdata = JSON.parse(hex2bin(pe.data('json')));
$(document).on('click', ".input-js-add" , function () {
// Add new row to networks or ip array
var pcls = $(this).data('for'),
pname = $(this).data('id'),
pmax = $(this).data('max'),
prow = $(this).data('row'),
pcount = $("." + pcls).length;
if (pcount == pmax){
//already reached max elements
return;
}
var last = $("." + pcls + ":last"),
ourid = last.data('nextid'),
nextid = ourid + 1;
var html = "<div class = '" + pcls + " form-group form-inline' data-nextid=" + nextid + ">";
jdata = JSON.parse(hex2bin($(this).data('json')));
var last = $("." + pcls).last(),
ourid = last.data('nextid'),
nextid = ourid + 1,
html = "<div class = '" + pcls + "' id ='" + pname + nextid + "' form-group form-inline' data-nextid=" + nextid + ">";
for (var key in jdata) {
html_opt = '';
html_calss = jdata[key]['class'];
for (var skey in jdata[key]['options']) {
html_opt += ' ' + skey + '="' + jdata[key]['options'][skey] + '"';
}
html += "<input type='text' name='" + pname + "[" + ourid + "][" + key + "]' class='" + html_calss + "' " + html_opt + " value='" + vdefault + "'> " + jdata[key]['nameseparator'] + " ";
html += "<input type='text' name='" + pname + "[" + nextid + "][" + key + "]' class " + html_opt + "> " + jdata[key]['nameseparator'] + " ";
}
// add remove button
html += "<button type='button' class='btn btn-danger btn-lg input-js-remove' id='" + pname + nextid + "-btn-remove' data-id='" + pname + nextid + "' data-for='" + pname + "'>";
html += "<i class='fa fa-minus pull-right'></i></button>";
// add plus button
html += "<button type='button' class='btn btn-primary btn-lg input-js-add' id='" + pname + nextid + "-btn-add' data-id='" + pname + "'";
html += " data-row='" + nextid + "' data-for='" + pname + "' data-max='" + pmax + "' data-json='" + $(this).data('json') + "' >";
html += "<i class='fa fa-plus pull-right'></i></button>";
html += "</div>\n";
if (pmax >= nextid) {
last.after(html);
}
}
last.after(html);
$('#' + pname + prow + '-btn-add').remove();
});
function del_dynamic_table(pe, pclass, vdefault)
{

View file

@ -166,6 +166,23 @@ and open the template in the editor. Base Version before all crash :-)
<page_group name="sccp_net">
<label>SCCP Networks</label>
<item type="IED" id="2" seq="0">
<label>Deny Networks / Mask</label>
<name>deny</name>
<default>0.0.0.0/0.0.0.0</default>
<input value="NONE" field="net" nameseparator="/">
<options placeholder="0.0.0.0" pattern="^([0-9]{1,3}\.){3}[0-9]{1,3}$"/>
<class></class>
</input>
<input value="NONE" field="mask">
<options placeholder="255.255.255.0" pattern="^([0-9]{1,3}\.){3}[0-9]{1,3}$"/>
<class></class>
</input>
<add_pluss>+</add_pluss>
<max_row>5</max_row>
<addbutton-disabled>Add Deny network</addbutton-disabled>
<help>All RFC 1918 addresses are local networks. Should always be at least '0.0.0.0/0.0.0.0'.</help>
</item>
<item type="IED" id="1" seq="0">
<label>Allow Networks / Mask</label>
<name>permit</name>
@ -178,6 +195,7 @@ and open the template in the editor. Base Version before all crash :-)
<options placeholder="255.255.255.0" pattern="^([0-9]{1,3}\.){3}[0-9]{1,3}$"/>
</input>
<add_pluss>+</add_pluss>
<max_row>5</max_row>
<addbutton-disabled>Add Allow Range</addbutton-disabled>
<help>Allow network settings. Blank fields will be ignored used Network 0.0.0.0/0.0.0.0 to resolve any existing connections. You can use the 'internal' connections only from the networks connected to the server. </help>
</item>
@ -195,30 +213,13 @@ and open the template in the editor. Base Version before all crash :-)
<class></class>
</input>
<add_pluss>+</add_pluss>
<max_row>5</max_row>
<addbutton-disabled>Add Internal Range</addbutton-disabled>
<help>Local network settings. Blank fields will be ignored used Network 0.0.0.0.</help>
</item>
<item type="IED" id="2" seq="0">
<label>Deny Networks / Mask</label>
<name>deny</name>
<default>0.0.0.0/0.0.0.0</default>
<input value="NONE" field="net" nameseparator="/">
<options placeholder="0.0.0.0" pattern="^([0-9]{1,3}\.){3}[0-9]{1,3}$"/>
<class></class>
</input>
<input value="NONE" field="mask">
<options placeholder="255.255.255.0" pattern="^([0-9]{1,3}\.){3}[0-9]{1,3}$"/>
<class></class>
</input>
<add_pluss>+</add_pluss>
<addbutton-disabled>Add Deny network</addbutton-disabled>
<help>All RFC 1918 addresses are local networks. Should always be at least '0.0.0.0/0.0.0.0'.</help>
</item>
<item type="IED" id="1" seq="98">
<label>Device Connect Address / Name </label>
<name>ccm_address</name>
<cbutton field="internal" value="internal">Internal</cbutton>
<default>0.0.0.0:2000</default>
<input value="NONE" field="ip" nameseparator=":">
<options placeholder="0.0.0.0 / pbx.org"/>
<class></class>
@ -228,6 +229,7 @@ and open the template in the editor. Base Version before all crash :-)
<class></class>
</input>
<add_pluss>+</add_pluss>
<max_row>5</max_row>
<addbutton-disabled>Add Address</addbutton-disabled>
<help>This function is useful when the server has many interfaces, but devices must connect only to some interfaces.</help>
</item>
@ -712,7 +714,7 @@ and open the template in the editor. Base Version before all crash :-)
<name>srst_ip</name>
<max_row>3</max_row>
<default>/</default>
<input value="NONE" field="Addr" nameseparator=":">
<input value="NONE" field="ip" nameseparator=":">
<options placeholder="0.0.0.0" pattern="^([0-9]{1,3}\.){3}[0-9]{1,3}$" />
<class></class>
</input>
@ -1683,6 +1685,7 @@ and open the template in the editor. Base Version before all crash :-)
<options placeholder="255.255.255.0" pattern="^([0-9]{1,3}\.){3}[0-9]{1,3}$"/>
</input>
<add_pluss>+</add_pluss>
<max_row>5</max_row>
<addbutton-disabled>Add Deny network</addbutton-disabled>
<help>All RFC 1918 addresses are local networks. Should always be at least '0.0.0.0/0.0.0.0'.</help>
</item>
@ -1690,11 +1693,7 @@ and open the template in the editor. Base Version before all crash :-)
<label>Allow Networks / Mask</label>
<name>permit</name>
<default>NONE</default>
<cbutton field="inherit" value="NONE">Inherit
<option_disabled class=".sccp_hw_net_inherit">false</option_disabled>
</cbutton>
<cbutton field="internal" value="internal"><class>sccp_hw-ar_permit-gr</class>internal</cbutton>
<class>sccp_hw_net_inherit</class>
<input value="NONE" field="net" nameseparator="/">
<options placeholder="0.0.0.0" pattern="^([0-9]{1,3}\.){3}[0-9]{1,3}$"/>
@ -1703,6 +1702,7 @@ and open the template in the editor. Base Version before all crash :-)
<options placeholder="255.255.255.0" pattern="^([0-9]{1,3}\.){3}[0-9]{1,3}$"/>
</input>
<add_pluss>+</add_pluss>
<max_row>5</max_row>
<addbutton-disables>Add Allow network</addbutton-disables>
<help>Allow network settings. Blank fields will be ignored used Network 0.0.0.0.</help>
</item>
@ -2022,6 +2022,7 @@ and open the template in the editor. Base Version before all crash :-)
<class>col-md-9</class>
</input>
<add_pluss>+</add_pluss>
<max_row>3</max_row>
<help></help>
</item>
</page_group>

View file

@ -266,7 +266,7 @@ class dbinterface
$this->db->prepare('TRUNCATE sccpsettings')->execute();
$stmt = $this->db->prepare('INSERT INTO sccpsettings (keyword, data, seq, type, systemdefault) VALUES (:keyword,:data,:seq,:type,:systemdefault)');
} else {
$stmt = $this->db->prepare('REPLACE INTO sccpsettings (keyword, data, seq, type, systemdefault) VALUES (:keyword,:data,:seq,:type,:systemdefault)');
$stmt = $this->db->prepare('REPLACE INTO sccpsettings (keyword, seq, type, data, systemdefault) VALUES (:keyword,:seq,:type,:data,:systemdefault)');
}
foreach ($save_value as $key => $dataArr) {
if (empty($dataArr)) {

View file

@ -4,6 +4,8 @@ namespace FreePBX\modules\Sccp_manager;
class formcreate
{
use \FreePBX\modules\Sccp_Manager\sccpManTraits\helperFunctions;
public function __construct($parent_class = null) {
$this->buttonDefLabel = 'chan-sccp';
$this->buttonHelpLabel = 'site';
@ -174,6 +176,8 @@ class formcreate
}
function addElementIED($child, $fvalues, $sccp_defaults,$npref, $napref) {
//$Sccp_manager = \FreePBX::create()->Sccp_manager;
// IED fields are arrays of networks and masks, or ip and ports.
$res_input = '';
$res_value = '';
$opt_at = array();
@ -187,20 +191,27 @@ class formcreate
// $res_value
$lnhtm = '';
$res_id = $napref.$child->name;
$i = 0;
//$i = 0;
$max_row = 255;
if (!empty($child->max_row)) {
$max_row = $child->max_row;
}
// fvalues are current settings - the encoding depends on where the data is
// coming from: IED fields in sccpsettings are json, elsewhere they are ; delimited.
if (!empty($fvalues[$res_n])) {
if (!empty($fvalues[$res_n]['data'])) {
$res_value = explode(';', $fvalues[$res_n]['data']);
$res_value = $this->convertCsvToArray($fvalues[$res_n]['data']);
}
}
if ($res_n == 'srst_ip') {
$res_value = $this->convertCsvToArray($sccp_defaults[$res_n]['data']);
}
if (empty($res_value)) {
$res_value = array((string) $child->default);
}
?>
<div class="element-container">
<div class="row">
@ -218,15 +229,21 @@ class formcreate
echo '<div class="form-group form-inline">';
foreach ($child->xpath('cbutton') as $value) {
$res_n = $res_id.'[0]['.$value['field'].']';
$res_vf = '';
// res_vf sets the state of the checkbox internal. This is always
// the first array element in $res_value if set
$res_vf = false;
if ($value['value']=='NONE' && empty($res_value)) {
$res_vf = 'active';
$res_vf = true;
}
$ch_key = array_search($value['value'], $res_value);
if ($ch_key !== false) {
unset($res_value[$ch_key]);
$res_vf = 'active';
$res_value = explode(';', implode(';', $res_value));
if ((isset($res_value[0]['internal'])) || ($res_value[0] == 'internal')) {
$res_vf = true;
// Remove the value from $res_value so that do not add empty row for internal
array_shift($res_value);
// If now have an empty array, add a new empty element
if (count($res_value) == 0) {
// although handle also ip, internal is never set for those arrays
$res_value[0] = array('net'=>"", 'mask' =>"");
}
}
$opt_hide ='';
$opt_class="button-checkbox";
@ -250,9 +267,9 @@ class formcreate
$opt_class .= " ".(string)$value->class;
}
echo '<span class="'.$opt_class.'"'.$opt_hide.'><button type="button" class="btn '.$res_vf.'" data-color="primary">';
echo '<i class="state-icon '. (($res_vf == 'active')?'glyphicon glyphicon-check"':'glyphicon glyphicon-uncheck'). '"></i> ';
echo $value.'</button><input type="checkbox" name="'. $res_n.'" class="hidden" '. (($res_vf == 'active')?'checked="checked"':'') .'/></span>';
echo '<span class="'.$opt_class.'"'.$opt_hide.'><button type="button" class="btn '.(($res_vf) ? 'active':"").'" data-color="primary">';
echo '<i class="state-icon '. (($res_vf)?'glyphicon glyphicon-check"':'glyphicon glyphicon-uncheck'). '"></i> ';
echo $value.'</button><input type="checkbox" name="'. $res_n.'" class="hidden" '. (($res_vf)?'checked="checked"':'') .'/></span>';
}
echo '</div>';
}
@ -261,36 +278,40 @@ class formcreate
$opt_class .= " ".(string)$child->class;
}
echo '<div class = "'.$opt_class.'">';
foreach ($res_value as $dat_v) {
$i=1;
foreach ($res_value as $addrArr) {
?>
<div class = "<?php echo $res_id;?> form-group form-inline" data-nextid=<?php echo $i+1;?> >
<div class = "<?php echo $res_id;?> form-group form-inline" data-nextid=<?php echo $i;?> id= <?php echo $res_id . $i;?>>
<?php
//$res_vf = explode('/', $dat_v);
$i2 = 0;
foreach ($child->xpath('input') as $value) {
$res_n = $res_id.'['.$i.']['.$value['field'].']';
$fields_id = (string)$value['field'];
//$opt_at[$fields_id]['nameseparator']=(string)$value['nameseparator'];
$field_id = (string)$value['field'];
$res_n = $res_id.'['.$i.']['.$field_id.']';
if (!empty($value->class)) {
$opt_at[$fields_id]['class']='form-control ' .(string)$value->class;
$opt_at[$field_id]['class']='form-control ' .(string)$value->class;
}
//$opt_at[$fields_id]['nameseparator']=(string)$value['nameseparator'];
if (!empty((string)$value['nameseparator'])) {
$res_vf = explode((string)$value['nameseparator'], $dat_v);
}
echo '<input type="text" name="'. $res_n.'" class="'.$opt_at[$fields_id]['class'].'" value="'.$res_vf[$i2].'"';
$defValue = (isset($addrArr[$field_id])) ? $addrArr[$field_id]: "";
echo '<input type="text" name="'. $res_n.'" class="'.$opt_at[$field_id]['class'].'" value="'. $defValue .'"';
if (isset($value->options)) {
foreach ($value->options ->attributes() as $optkey => $optval) {
$opt_at[$fields_id]['options'][$optkey]=(string)$optval;
$opt_at[$field_id]['options'][$optkey]=(string)$optval;
$opt_at[$field_id]['nameseparator'] = (null !== (string)$value['nameseparator']) ? (string)$value['nameseparator'] : '';
echo ' '.$optkey.'="'.$optval.'"';
}
}
echo '> '.(string)$value['nameseparator'].' ';
$i2 ++;
}
if (!empty($child->add_pluss)) {
echo '<button type="button" class="btn btn-primary btn-lg input-js-add" id="'.$res_id.'-btn" data-id="'.$res_id.'" data-for="'.$res_id.'" data-max="'.$max_row.'"data-json="'.bin2hex(json_encode($opt_at)).'"><i class="fa fa-plus pull-right"></i></button>';
if ($i <= count($res_value)) {
echo '<button type="button" class="btn btn-danger btn-lg input-js-remove" id="'.$res_id.$i.'-btn-del" data-id="'.$res_id.$i.'"><i class="fa fa-minus pull-right"></i></button>';
}
// only add plus button to the last row
if ($i == count($res_value)) {
echo '<button type="button" class="btn btn-primary btn-lg input-js-add" id="'.$res_id.$i.'-btn-add" data-id="'.$res_id.'" data-row="'.$i.'" data-for="'.$res_id.'" data-max="'.$max_row.'"data-json="'.bin2hex(json_encode($opt_at)).'"><i class="fa fa-plus pull-right"></i></button>';
}
}
echo '</div>';
$i++;

View file

@ -15,7 +15,7 @@ namespace FreePBX\modules\Sccp_manager;
class xmlinterface
{
use \FreePBX\modules\Sccp_Manager\sccpManTraits\helperFunctions;
private $val_null = 'NONE'; /// REPLACE to null Field
public function __construct($parent_class = null)
@ -152,7 +152,7 @@ class xmlinterface
$node->addAttribute('model', $var['vendor'] . ' ' . $var['model']);
}
}
\FreePBX::Sccp_manager()->saveXml($xml_work, $xml_name); // Save XMLDefault1.cnf.xml
$this->saveXml($xml_work, $xml_name); // Save XMLDefault1.cnf.xml
}
}
@ -251,29 +251,15 @@ class xmlinterface
$xnode->userModifiable = $data_values['srst_userModifiable'];
$xnode->isSecure = $data_values['srst_isSecure'];
$srst_fld = array('srst_ip' => array('ipAddr', 'port'));
foreach ($srst_fld as $srst_pro => $srs_put) {
if (empty($data_values[$srst_pro]) || ($data_values['srst_Option'] == 'disable') ) {
$srst_data =array();
} else {
$srst_data = explode(';', $data_values[$srst_pro]);
}
$si = 1;
foreach ($srst_data as $value) {
$srs_val = explode('/', $value);
$nod = $srs_put[0] . $si;
$xnode->$nod = $srs_val[0];
$nod = $srs_put[1] . $si;
$xnode->$nod = ((empty($srs_val[1])) ? "2000": $srs_val[1]);
$si++;
}
while ($si < 4) {
$nod = $srs_put[0] . $si;
$xnode->$nod = '';
$nod = $srs_put[1] . $si;
$xnode->$nod = '';
$si++;
}
// srst addresses are now stored as json;
$srst_addrs = $this->convertCsvToArray($data_values['srst_ip']);
//Now have an array of srst addresses - maybe empty
foreach ($srst_addrs as $netKey => $netValue) {
$nodeName = "ipAddr${netKey}";
$xnode->$nodeName = $netValue['ip'];
$nodeName = "port${netKey}";
$xnode->$nodeName = $netValue['port'];
}
break;
case 'connectionmonitorduration':
@ -403,7 +389,7 @@ class xmlinterface
}
}
\FreePBX::Sccp_manager()->saveXml($xml_work, $xml_name); // Save
$this->saveXml($xml_work, $xml_name); // Save
return time();
}
@ -418,20 +404,11 @@ class xmlinterface
}
$ip_fill = true;
if (!empty($data_values['ccm_address'])) {
$ccm_address = $data_values['ccm_address'];
if (strpos($ccm_address, 'internal') === false && strpos($ccm_address, '0.0.0.0') === false) {
$tmp_data = explode(';', $ccm_address);
$ip_fill = false;
foreach ($tmp_data as $tmp_row) {
if (strpos($tmp_row, '/') !== false) {
$ttmp_r = explode('/', $tmp_row); // IPv6 - ????
$rkey = $ttmp_r[0];
$res[$rkey] = array('ip' => $rkey, 'port' => $ttmp_r[1]);
} else {
$rkey = $tmp_row;
$res[$rkey] = array('ip' => $rkey, 'port' => $data_values['port']);
}
}
// ccm_address is json from sccpsettings
$ccm_address = $this->convertCsvToArray($data_values['ccm_address'], true);
// This is a sanitised list of ipaddresses and ports
foreach ($ccm_address as $netValue) {
$res[$netValue['ip']] = $netValue;
}
}
if ($ip_fill) {
@ -728,7 +705,7 @@ class xmlinterface
}
}
\FreePBX::Sccp_manager()->saveXml($xml_work, $xml_name); // Save
$this->saveXml($xml_work, $xml_name); // Save
} else {
die('Error Hardware template :' . $xml_template . ' not found');
}

View file

@ -48,7 +48,7 @@ trait ajaxHelper {
switch ($cmd_id) {
case 'savesettings':
// Consolidate this into a separate method to improve legibility
return $this->saveSccpSettings($request);
return $this->saveServerSettings($request);
break;
case 'save_sip_device':
case 'save_device':
@ -278,7 +278,8 @@ trait ajaxHelper {
}
}
function saveSccpSettings($request, $validateonly = false) {
function saveServerSettings($request, $validateonly = false) {
dbug($request);
$hdr_prefix = 'sccp_';
$hdr_arprefix = 'sccp-ar_';
$save_settings = array();
@ -323,38 +324,32 @@ trait ajaxHelper {
$sccpdevice_def = (array)$this->getTableDefaults('sccpdevice', false);
$sccpline_def = (array)$this->getTableDefaults('sccpline', false);
// before handling arrays, need to see if deny and permit are set in the request
// if they have been cleared by the users, will not be present
foreach (['deny','permit'] as $keyVal) {
if (!isset($request[$hdr_arprefix.$keyVal])) {
$tmpArr = $this->convertCsvToArray($this->sccpvalues[$keyVal]['systemdefault']);
if (isset($tmpArr[0]['internal'])) {
$request[$hdr_arprefix.$keyVal][0] = $tmpArr[0];
} else {
$request[$hdr_arprefix.$keyVal][1]['net'] = $tmpArr[0]['net'];
$request[$hdr_arprefix.$keyVal][1]['mask'] = $tmpArr[0]['mask'];
}
}
}
foreach ($request as $key => $value) {
// First handle any arrays as their prefix is part common with normal data
//$netvalue = array();
$key = (str_replace($hdr_arprefix, '', $key, $count_mods));
if ($count_mods) {
$arr_data = '';
if (!empty($this->sccpvalues[$key])) {
foreach ($value as $valArr) {
foreach ($valArr as $vkey => $vval) {
switch ($vkey) {
case 'inherit':
case 'internal':
if ($vval == 'on') {
$arr_data .= 'internal;';
}
break;
case 'port':
$arr_data .= ":{$vval}";
break;
case 'mask':
$arr_data .= "/{$vval}";
break;
default:
$arr_data .= $vval;
break;
}
}
}
if (!($this->sccpvalues[$key]['data'] == $arr_data)) {
$save_settings[$key] = $this->sccpvalues[$key];
$save_settings[$key]['data'] = $arr_data;
}
}
// Only arrays : network lists or ip lists.
$save_settings[$key]['keyword'] = $key;
$save_settings[$key]['type'] = $this->sccpvalues[$key]['type'];
$save_settings[$key]['seq'] = $this->sccpvalues[$key]['seq'];
$save_settings[$key]['data'] = $this->convertArrayToCsv($value);
$save_settings[$key]['systemdefault'] = $this->sccpvalues[$key]['systemdefault'];
continue;
}
// Now handle any normal data - arrays will not match as already handled.
@ -383,14 +378,29 @@ trait ajaxHelper {
continue 2;
}
}
}
$extSettings = $this->extconfigs->updateTftpStructure(array_merge($this->sccpvalues, $save_settings));
$save_settings = array_merge($save_settings, $extSettings);
//dbug($save_settings);
if (!empty($save_settings)) {
$this->saveSccpSettings($save_settings);
$this->sccpvalues = $this->dbinterface->get_db_SccpSetting();
}
// now add the site defaults from sccpsettings to sccpdevice for permit and deny, so that these will override
foreach (['deny', 'permit'] as $fieldId) {
$output = array();
foreach ($this->convertCsvToArray($this->sccpvalues[$fieldId]['data']) as $netValue) {
if (isset($netValue['internal'])) {
$output[] = 'internal';
continue;
}
$output[] = implode('/', $netValue);
}
$dbSaveArray[$fieldId] = array('table' => 'sccpdevice', 'field' => $fieldId, 'Default' => implode(';',$output));
}
foreach ($dbSaveArray as $key => $rowToSave) {
$this->dbinterface->updateTableDefaults($rowToSave['table'], $rowToSave['field'], $rowToSave['Default']);
}
@ -564,56 +574,51 @@ trait ajaxHelper {
break;
default:
// handle vendor prefix
if (!empty($get_settings[$hdr_vendPrefix . $key])) {
$value = $get_settings[$hdr_vendPrefix . $key];
if (!empty($get_settings["${hdr_vendPrefix}${key}"])) {
$value = $get_settings["${hdr_vendPrefix}${key}"];
}
// handle array prefix
if (!empty($get_settings[$hdr_arprefix . $key])) {
if (!empty($get_settings["${hdr_arprefix}${key}"])) {
// Only 3 types of array returned permit,deny, setvar
$arr_data = '';
$arr_clear = false;
foreach ($get_settings[$hdr_arprefix . $key] as $vkey => $vval) {
$tmp_data = '';
foreach ($vval as $vkey => $vval) {
switch ($vkey) {
case 'inherit':
if ($vval == 'on') {
$arr_clear = true;
// Злобный ХАК ?!TODO!?
if ($key == 'permit') {
$save_settings['deny'] = 'NONE';
}
}
break;
case 'internal':
if ($vval == 'on') {
$tmp_data .= 'internal;';
}
break;
default:
$tmp_data .= $vval . '/';
break;
}
$output = array();
foreach ($get_settings["${hdr_arprefix}${key}"] as $netValue) {
switch ($key) {
case 'permit':
case 'deny';
// Now have an array of settings each with keys net and Mask
// TODO: This needs to be optimised
//foreach ($valueArr as $netValue) {
if (isset($netValue['inherit'])) {
$save_settings['deny'] = 'NONE';
continue 2;
}
if (isset($netValue['internal'])) {
$output[] = 'internal';
continue;
}
if (empty($netValue['net'])) {
// empty net so ignored
continue;
}
$netValue['mask'] = (empty($netValue['mask'])) ? "255.255.255.0" : $netValue['mask'];
$output[]= implode('/', $netValue);
//}
break;
case 'setvar':
$output[] = implode(';', $netValue);
break;
// No default case
}
if (strlen($tmp_data) > 2) {
while (substr($tmp_data, -1) == '/') {
$tmp_data = substr($tmp_data, 0, -1);
}
$arr_data .= $tmp_data . ';';
}
}
while (substr($arr_data, -1) == ';') {
$arr_data = substr($arr_data, 0, -1);
}
if ($arr_clear) {
$value = 'NONE';
} else {
$value = $arr_data;
}
}
// Now only have normal prefix
if (!empty($get_settings["{$hdr_prefix}{$key}"])) {
$value = $get_settings["{$hdr_prefix}{$key}"];
}
$save_settings[$key] = implode(';', $output);
unset($output);
}
// Now only have normal prefix
if (!empty($get_settings["{$hdr_prefix}{$key}"])) {
$value = $get_settings["{$hdr_prefix}{$key}"];
}
}
if (!empty($value)) {
$save_settings[$key] = $value;
@ -647,7 +652,5 @@ trait ajaxHelper {
$search = '?display=sccp_phone';
return array('status' => true, 'message' => $msg, 'reload' => true, 'toastFlag' => $toastFlag, 'search' => $search, 'hash' => $hash);
}
}
?>

View file

@ -3,8 +3,76 @@
namespace FreePBX\modules\Sccp_manager\sccpManTraits;
trait helperfunctions {
private function convertCsvToArray($stringToConvert = "") {
// Take a csv string form of net/mask or ip/port and convert to an array
// sub arrays are separated by ";"
$outputArr = array();
if (empty($stringToConvert)) {
return $outputArr;
}
foreach (explode(";", $stringToConvert) as $value) {
//internal is always the first setting if present
if ($value == 'internal') {
$outputArr[] = array('internal' => 'on');
continue;
}
// Now handle rest of value types
$subArr = explode("/", $value);
if (count($subArr) === 2) {
// Have net/mask
$outputArr[] = array('net' => $subArr[0], 'mask' => $subArr[1]);
} else {
// have ip:port
$subArr = explode(":", $value);
$outputArr[] = array('ip' => $subArr[0], 'port' => $subArr[1]);
}
}
return $outputArr;
}
function getIpInformation($type = '') {
private function convertArrayToCsv(array $arrayToConvert) {
// About to save to db so need to convert to string
// Take an array form of net mask or ip port and convert to a csv
// sub arrays are separated by ";"
if (empty($arrayToConvert)) {
return '';
}
$output = array();
// Internal is always element 0, nets and ips start at element 1.
if ((isset($arrayToConvert[1]['net'])) || (isset($arrayToConvert[0]['internal']))) {
// Have net masks
foreach ($arrayToConvert as $netValue) {
if (isset($netValue['internal'])) {
$output[] = 'internal';
continue;
}
if (empty($netValue['net'])) {
// If network not set, user error, has added empty row so delete
continue;
}
// If the mask has not been set, set to this subnet
$netValue['mask'] = (empty($netValue['mask'])) ? "255.255.255.0" : $netValue['mask'];
$output[] = implode('/', $netValue);
}
} else {
// Have ip addresses
foreach ($arrayToConvert as $ipArr) {
if (isset($ipArr['internal'])) {
// should not be set for an ip address
continue;
}
if (empty($ipArr['ip'])) {
// If ip not set, user error, has added empty row so delete
continue;
}
$ipArr['port'] = (empty($ipArr['port'])) ? "2000" : $ipArr['port'];
$output[] = implode(':', $ipArr);
}
}
return implode(';', $output);
}
private function getIpInformation($type = '') {
$interfaces = array();
switch ($type) {
case 'ip4':
@ -301,15 +369,9 @@ trait helperfunctions {
case "allow":
case "disallow":
case "deny":
$this->sccp_conf_init['general'][$key] = explode(';', $value['data']);
break;
case "localnet":
case "permit":
$content = $value['data'];
if (strpos($content, 'internal') !== false) {
$content = str_replace(';0.0.0.0/0.0.0.0', '', $value['data']);
}
$this->sccp_conf_init['general'][$key] = explode(';', $content);
$this->sccp_conf_init['general'][$key] = explode(';', $value['data']);
break;
case "devlang":
/*