WireGuard: minor code changes

This commit is contained in:
bergware
2022-04-15 14:01:38 +02:00
parent 15c5a59b2f
commit 89b082f5b4
3 changed files with 11 additions and 15 deletions

View File

@@ -191,7 +191,7 @@ while (isset($$eth)) {
// remove obsolete tunnels
foreach (glob("$docroot/webGui/WG[1-9]*.page",GLOB_NOSORT) as $wgX) {
if (!in_array(strtolower(basename($wgX,'.page')),$vtuns)) {
unlink($wgX);
delete_file($wgX);
$build = true;
}
}
@@ -279,7 +279,6 @@ if (!HTMLInputElement.prototype.reportValidity || (navigator.userAgent.indexOf("
}
};
}
function ipv4(ip) {
return ip.indexOf('.') > 0;
}
@@ -1229,7 +1228,7 @@ $(function(){
else if (lan) $('span#my-static2-wg0').show();
<?if (file_exists($tmp)):?>
setTimeout(function(){swal({title:"_(Peer update required)_",text:"<b><u>_(List of peers)_</u></b><br><span style='display:inline-block;text-align:left'><?=file_get_contents($tmp)?></span>",type:'warning',html:true});},200);
<?unlink($tmp);?>
<?delete_file($tmp);?>
<?endif;?>
});
</script>

View File

@@ -27,13 +27,12 @@ $netport['wgX'] = $netport['wg0']+XXX;
[$conf_wgX,$cfg_wgX,$this_wgX,$vpn_wgX] = readConf($peer_wgX,$wgX,'wgX');
?>
<script>
netbase['wgX'] = <?=$netbase['wgX']?>;
netpool['wgX'] = '<?=$netpool['wgX']?>';
netport['wgX'] = '<?=$netport['wgX']?>';
netbase['wgX'] = <?=$netbase['wgX']?>;
netpool['wgX'] = '<?=$netpool['wgX']?>';
netport['wgX'] = '<?=$netport['wgX']?>';
netbase6['wgX'] = '<?=$netbase6['wgX']?>';
netpool6['wgX'] = '<?=$netpool6['wgX']?>';
tstate['wgX'] = "<?=$check_wgX ? 'active' : ''?>";
tstate['wgX'] = "<?=$check_wgX ? 'active' : ''?>";
$(function(){
var ctrl = "<span class='status vhshift hshift'><i id='block-wgX' class='fa fa-fw fa-chevron-up' style='cursor:pointer' onclick='blockToggle(&quot;wgX&quot;)'></i></span>";

View File

@@ -131,15 +131,13 @@ function addPeer(&$x) {
function autostart($vtun,$cmd) {
global $etc;
$autostart = "$etc/autostart";
$list = @file_get_contents($autostart) ?: '';
$list = file_exists($autostart) ? array_filter(explode(' ',file_get_contents($autostart))) : [];
$key = array_search($vtun,$list);
switch ($cmd) {
case 'off':
if ($list && strpos($list,"$vtun ")!==false) file_put_contents($autostart,str_replace("$vtun ","",$list));
break;
case 'on':
if (!$list || strpos($list,"$vtun ")===false) file_put_contents($autostart,$list."$vtun ");
break;
case 'off': if ($key!==false) unset($list[$key]); break;
case 'on' : if ($key===false) $list[] = $vtun; break;
}
if (count($list)) file_put_contents($autostart,implode(' ',$list)); else delete_file($autostart);
}
function createPeerFiles($vtun) {
global $etc,$peers,$name,$gone,$vpn;