Files
webgui/emhttp/plugins/dynamix/NetworkRules.page
bergware 202cb8c222 Move inline styling in page files to dedicated css files
Instead of styling defined inside a page file, these settings are now kept in a dedicated css file. This has several advantages:

- It comes much easier to maintain styling, all css files are easy to find and update
- Browser can cache css files, which may improve page loading time
- Separate theme css files exist, no more need to make selection by coding

- This PR is a 1-to-1 move of existing inline styling to css files
- In future more optimization can be made by consolidating css files
2023-10-14 19:02:35 +02:00

105 lines
3.4 KiB
Plaintext

Menu="NetworkSettings"
Title="Interface Rules"
Tag="icon-network"
Cond="file_exists('/boot/config/network-rules.cfg')"
---
<?PHP
/* Copyright 2023, Lime Technology
* Copyright 2023, 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,'')]);
}
<?if (!$tabbed):?>
function toggleRules() {
var tag = '#tag_rules';
var view = '#rules_table';
if ($(view).is(':visible')) {
$(tag).removeClass('fa-chevron-up').addClass('fa-chevron-down');
$.cookie(view,'hide',{expires:3650});
} else {
$(tag).removeClass('fa-chevron-down').addClass('fa-chevron-up');
$.removeCookie(view);
}
$(view).toggle('slow');
}
$(function(){
$('div.title').eq(-2).find('span.left').append("<span class='status vhshift'><i id='tag_rules' class='fa fa-fw fa-chevron-up' style='cursor:pointer' onclick='toggleRules()'></i></span>");
if (!$.cookie('#rules_table')) $('#rules_table').show(); else {$('#rules_table').hide(); $('#tag_rules').removeClass('fa-chevron-up').addClass('fa-chevron-down');}
});
<?else:?>
$(function(){
$('#rules_table').show();
});
<?endif;?>
</script>
<div markdown="1" id="rules_table" style="display:none">
<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;?>
</div>