Skip to content

Commit 09acfd0

Browse files
committed
Fix Issue #32
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.
1 parent bd84870 commit 09acfd0

File tree

8 files changed

+277
-200
lines changed

8 files changed

+277
-200
lines changed

Sccp_manager.class.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ private function findInstLangs() {
609609
$result = array();
610610

611611
if (!file_exists("{$this->sccppath['tftp_path']}/masterFilesStructure.xml")) {
612-
if (!$this->getFileListFromProvisioner($this->sccppath['tftp_path'])) {
612+
if (!$this->getFileListFromProvisioner($this->sccpvalues['tftp_path']['data'])) {
613613
// File does not exist and cannot get from internet.
614614
return $result;
615615
};
@@ -680,7 +680,6 @@ private function initializeTFtpLanguagePath() {
680680
*/
681681

682682
function initializeSccpPath() {
683-
684683
$this->sccppath = array(
685684
'asterisk' => $this->sccpvalues['asterisk_etc_path']['data'],
686685
'tftp_path' => $this->sccpvalues['tftp_path']['data'],
@@ -907,7 +906,7 @@ function createSccpDeviceXML(string $dev_id) {
907906
$hw_addon = explode(',', $dev_config['addon']);
908907
foreach ($hw_addon as $key) {
909908
$hw_data = $this->getSccpModelInformation('byid', false, "all", array('model' => $key));
910-
$dev_config['addon_info'][$key] = $hw_data[0]['loadimage'];
909+
$dev_config['addon_info'][$key] = $hw_data[$key]['loadimage'];
911910
}
912911
}
913912

assets/js/sccp_manager.js

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,6 @@ $(document).ready(function () {
116116
});
117117
});
118118

119-
$(".input-js-add").click(function () {
120-
add_dynamic_input($(this), $(this).data('for'), "", "");
121-
});
122-
123119
$(".table").on('click', '.table-js-add', function (e) {
124120
add_dynamic_table($(this), $(this).data('for'), "", "");
125121
});
@@ -920,32 +916,51 @@ function load_oncliсk(e, data)
920916
}
921917
}
922918

919+
// call from here not document.ready as have dynamic content
920+
$(document).on('click', ".input-js-remove" , function () {
921+
// delete the current row
922+
var pname = $(this).data('id');
923+
$('#' + pname).remove();
924+
});
923925

924-
function add_dynamic_input(pe, pclass, vdefault)
925-
{
926-
// We'd like a new one, please.
927-
pcls = pe.data('for');
928-
pname = pe.data('id');
929-
pmax = pe.data('max');
930-
jdata = JSON.parse(hex2bin(pe.data('json')));
926+
$(document).on('click', ".input-js-add" , function () {
927+
// Add new row to networks or ip array
928+
var pcls = $(this).data('for'),
929+
pname = $(this).data('id'),
930+
pmax = $(this).data('max'),
931+
prow = $(this).data('row'),
932+
pcount = $("." + pcls).length;
933+
if (pcount == pmax){
934+
//already reached max elements
935+
return;
936+
}
931937

932-
var last = $("." + pcls + ":last"),
933-
ourid = last.data('nextid'),
934-
nextid = ourid + 1;
935-
var html = "<div class = '" + pcls + " form-group form-inline' data-nextid=" + nextid + ">";
938+
jdata = JSON.parse(hex2bin($(this).data('json')));
939+
940+
var last = $("." + pcls).last(),
941+
ourid = last.data('nextid'),
942+
nextid = ourid + 1,
943+
html = "<div class = '" + pcls + "' id ='" + pname + nextid + "' form-group form-inline' data-nextid=" + nextid + ">";
936944
for (var key in jdata) {
937945
html_opt = '';
938-
html_calss = jdata[key]['class'];
939946
for (var skey in jdata[key]['options']) {
940947
html_opt += ' ' + skey + '="' + jdata[key]['options'][skey] + '"';
941948
}
942-
html += "<input type='text' name='" + pname + "[" + ourid + "][" + key + "]' class='" + html_calss + "' " + html_opt + " value='" + vdefault + "'> " + jdata[key]['nameseparator'] + " ";
949+
html += "<input type='text' name='" + pname + "[" + nextid + "][" + key + "]' class " + html_opt + "> " + jdata[key]['nameseparator'] + " ";
943950
}
951+
// add remove button
952+
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 + "'>";
953+
html += "<i class='fa fa-minus pull-right'></i></button>";
954+
// add plus button
955+
html += "<button type='button' class='btn btn-primary btn-lg input-js-add' id='" + pname + nextid + "-btn-add' data-id='" + pname + "'";
956+
html += " data-row='" + nextid + "' data-for='" + pname + "' data-max='" + pmax + "' data-json='" + $(this).data('json') + "' >";
957+
html += "<i class='fa fa-plus pull-right'></i></button>";
944958
html += "</div>\n";
945-
if (pmax >= nextid) {
946-
last.after(html);
947-
}
948-
}
959+
960+
last.after(html);
961+
962+
$('#' + pname + prow + '-btn-add').remove();
963+
});
949964

950965
function del_dynamic_table(pe, pclass, vdefault)
951966
{

conf/sccpgeneral.xml.v433

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,23 @@ and open the template in the editor. Base Version before all crash :-)
166166

167167
<page_group name="sccp_net">
168168
<label>SCCP Networks</label>
169+
<item type="IED" id="2" seq="0">
170+
<label>Deny Networks / Mask</label>
171+
<name>deny</name>
172+
<default>0.0.0.0/0.0.0.0</default>
173+
<input value="NONE" field="net" nameseparator="/">
174+
<options placeholder="0.0.0.0" pattern="^([0-9]{1,3}\.){3}[0-9]{1,3}$"/>
175+
<class></class>
176+
</input>
177+
<input value="NONE" field="mask">
178+
<options placeholder="255.255.255.0" pattern="^([0-9]{1,3}\.){3}[0-9]{1,3}$"/>
179+
<class></class>
180+
</input>
181+
<add_pluss>+</add_pluss>
182+
<max_row>5</max_row>
183+
<addbutton-disabled>Add Deny network</addbutton-disabled>
184+
<help>All RFC 1918 addresses are local networks. Should always be at least '0.0.0.0/0.0.0.0'.</help>
185+
</item>
169186
<item type="IED" id="1" seq="0">
170187
<label>Allow Networks / Mask</label>
171188
<name>permit</name>
@@ -178,6 +195,7 @@ and open the template in the editor. Base Version before all crash :-)
178195
<options placeholder="255.255.255.0" pattern="^([0-9]{1,3}\.){3}[0-9]{1,3}$"/>
179196
</input>
180197
<add_pluss>+</add_pluss>
198+
<max_row>5</max_row>
181199
<addbutton-disabled>Add Allow Range</addbutton-disabled>
182200
<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>
183201
</item>
@@ -195,30 +213,13 @@ and open the template in the editor. Base Version before all crash :-)
195213
<class></class>
196214
</input>
197215
<add_pluss>+</add_pluss>
216+
<max_row>5</max_row>
198217
<addbutton-disabled>Add Internal Range</addbutton-disabled>
199218
<help>Local network settings. Blank fields will be ignored used Network 0.0.0.0.</help>
200219
</item>
201-
<item type="IED" id="2" seq="0">
202-
<label>Deny Networks / Mask</label>
203-
<name>deny</name>
204-
<default>0.0.0.0/0.0.0.0</default>
205-
<input value="NONE" field="net" nameseparator="/">
206-
<options placeholder="0.0.0.0" pattern="^([0-9]{1,3}\.){3}[0-9]{1,3}$"/>
207-
<class></class>
208-
</input>
209-
<input value="NONE" field="mask">
210-
<options placeholder="255.255.255.0" pattern="^([0-9]{1,3}\.){3}[0-9]{1,3}$"/>
211-
<class></class>
212-
</input>
213-
<add_pluss>+</add_pluss>
214-
<addbutton-disabled>Add Deny network</addbutton-disabled>
215-
<help>All RFC 1918 addresses are local networks. Should always be at least '0.0.0.0/0.0.0.0'.</help>
216-
</item>
217220
<item type="IED" id="1" seq="98">
218221
<label>Device Connect Address / Name </label>
219222
<name>ccm_address</name>
220-
<cbutton field="internal" value="internal">Internal</cbutton>
221-
<default>0.0.0.0:2000</default>
222223
<input value="NONE" field="ip" nameseparator=":">
223224
<options placeholder="0.0.0.0 / pbx.org"/>
224225
<class></class>
@@ -228,6 +229,7 @@ and open the template in the editor. Base Version before all crash :-)
228229
<class></class>
229230
</input>
230231
<add_pluss>+</add_pluss>
232+
<max_row>5</max_row>
231233
<addbutton-disabled>Add Address</addbutton-disabled>
232234
<help>This function is useful when the server has many interfaces, but devices must connect only to some interfaces.</help>
233235
</item>
@@ -712,7 +714,7 @@ and open the template in the editor. Base Version before all crash :-)
712714
<name>srst_ip</name>
713715
<max_row>3</max_row>
714716
<default>/</default>
715-
<input value="NONE" field="Addr" nameseparator=":">
717+
<input value="NONE" field="ip" nameseparator=":">
716718
<options placeholder="0.0.0.0" pattern="^([0-9]{1,3}\.){3}[0-9]{1,3}$" />
717719
<class></class>
718720
</input>
@@ -1683,18 +1685,15 @@ and open the template in the editor. Base Version before all crash :-)
16831685
<options placeholder="255.255.255.0" pattern="^([0-9]{1,3}\.){3}[0-9]{1,3}$"/>
16841686
</input>
16851687
<add_pluss>+</add_pluss>
1688+
<max_row>5</max_row>
16861689
<addbutton-disabled>Add Deny network</addbutton-disabled>
16871690
<help>All RFC 1918 addresses are local networks. Should always be at least '0.0.0.0/0.0.0.0'.</help>
16881691
</item>
16891692
<item type="IED" id="1" seq="0">
16901693
<label>Allow Networks / Mask</label>
16911694
<name>permit</name>
16921695
<default>NONE</default>
1693-
<cbutton field="inherit" value="NONE">Inherit
1694-
<option_disabled class=".sccp_hw_net_inherit">false</option_disabled>
1695-
</cbutton>
16961696
<cbutton field="internal" value="internal"><class>sccp_hw-ar_permit-gr</class>internal</cbutton>
1697-
16981697
<class>sccp_hw_net_inherit</class>
16991698
<input value="NONE" field="net" nameseparator="/">
17001699
<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 :-)
17031702
<options placeholder="255.255.255.0" pattern="^([0-9]{1,3}\.){3}[0-9]{1,3}$"/>
17041703
</input>
17051704
<add_pluss>+</add_pluss>
1705+
<max_row>5</max_row>
17061706
<addbutton-disables>Add Allow network</addbutton-disables>
17071707
<help>Allow network settings. Blank fields will be ignored used Network 0.0.0.0.</help>
17081708
</item>
@@ -2022,6 +2022,7 @@ and open the template in the editor. Base Version before all crash :-)
20222022
<class>col-md-9</class>
20232023
</input>
20242024
<add_pluss>+</add_pluss>
2025+
<max_row>3</max_row>
20252026
<help></help>
20262027
</item>
20272028
</page_group>

sccpManClasses/dbinterface.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ function write($table_name = "", $save_value = array(), $mode = 'update', $key_f
264264
$this->db->prepare('TRUNCATE sccpsettings')->execute();
265265
$stmt = $this->db->prepare('INSERT INTO sccpsettings (keyword, data, seq, type, systemdefault) VALUES (:keyword,:data,:seq,:type,:systemdefault)');
266266
} else {
267-
$stmt = $this->db->prepare('REPLACE INTO sccpsettings (keyword, data, seq, type, systemdefault) VALUES (:keyword,:data,:seq,:type,:systemdefault)');
267+
$stmt = $this->db->prepare('REPLACE INTO sccpsettings (keyword, seq, type, data, systemdefault) VALUES (:keyword,:seq,:type,:data,:systemdefault)');
268268
}
269269
foreach ($save_value as $key => $dataArr) {
270270
if (empty($dataArr)) {

0 commit comments

Comments
 (0)