Files
webgui/emhttp/plugins/dynamix/NetworkRules.page
bergware b14a636043 Network enhancements
- visual updates
2025-01-14 10:21:49 +01:00

82 lines
2.6 KiB
Plaintext

Menu="NetworkSettings"
Title="Interface Rules"
Tag="icon-network"
Cond="file_exists('/boot/config/network-rules.cfg')"
---
<?PHP
/* Copyright 2005-2025, Lime Technology
* Copyright 2012-2025, Bergware International.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*/
?>
<?
$cfg = '/boot/config/network-rules.cfg';
function strip($item) {
[$key,$val] = explode('"',$item);
return $val;
}
exec("awk '/NAME=\"eth/{print $4 $8}' $cfg",$rules);
exec("grep -Po '^# \K.*' $cfg",$info);
$link = []; $i = 0;
foreach ($rules as $rule) {
[$mac,$eth] = array_map('strip',my_explode(',',$rule));
$link[$eth]['mac'] = $mac;
$link[$eth]['info'] = $info[$i++];
}
ksort($link,SORT_NATURAL);
?>
<script>
var info = {};
<?foreach ($link as $eth => $val):?>
info['<?='_'.str_replace(':','',$val['mac'])?>'] = "<?=$val['info']?>";
<?endforeach;?>
function check_rules(form) {
var mac = [];
$(form).find('select[name^="eth"]').each(function(){mac.push($(this).val());});
if (mac.same()) {
swal({title:"_(MAC address mismatch)_",text:"_(Rules contain duplicate MAC address assignments)_",type:'error',html:true,confirmButtonText:"_(Ok)_"});
return false;
} else {
return true;
}
}
function update_info(id,mac) {
$('#info-'+id).html(info['_'+mac.replace(/:/g,'')]);
}
</script>
<div class="title nocontrol shift">&nbsp;</div>
<form markdown="1" name="network_rules" method="POST" action="/update.php" target="progressFrame" onsubmit="return check_rules(this)">
<input type="hidden" name="#file" value="not-used">
<input type="hidden" name="#include" value="/webGui/include/update.rules.php">
<input type="hidden" name="#cfg" value="<?=$cfg?>">
<?foreach ($link as $eth => $file):?>
_(Interface)_ <?=$eth?>:
: <select name="<?=$eth?>" onchange="update_info(this.name,this.value)">
<?foreach ($link as $my => $val):?>
<?=mk_option($file['mac'],$val['mac'],strtoupper($val['mac']));?>
<?endforeach;?>
</select><span id="info-<?=$eth?>"><?=$file['info']?></span>
<?endforeach;?>
&nbsp;
: <input type="submit" value="_(Apply)_" disabled><input type="button" value="_(Done)_" onclick="done()">
</form>
:eth_network_rules_help:
<?if (file_exists('/tmp/network-rules.tmp')):?>
<br><span class="error" style="text-align:center;padding:12px 0">_(Please **Reboot** system to make new rules active)_</span>
<?endif;?>