Simplify template, update save actions

This commit is contained in:
billz 2021-07-08 11:22:17 +01:00
parent 8374d032b3
commit 2ccce60189
2 changed files with 24 additions and 19 deletions

View File

@ -10,10 +10,12 @@ function DisplayWireGuardConfig()
{
$status = new StatusMessages();
if (!RASPI_MONITOR_ENABLED) {
$optRules = $_POST['wgRules'];
if (isset($_POST['savewgsettings']) && !is_uploaded_file($_FILES["wgFile"]["tmp_name"])) {
$optRules = $_POST['wgRules'];
$optConf = $_POST['wgCnfOpt'];
$optSrvEnable = $_POST['wgSrvEnable'];
if (isset($_POST['savewgsettings']) && $optConf == 'manual' && $optSrvEnable == 1 ) {
SaveWireGuardConfig($status);
} elseif (isset($_POST['savewgsettings']) && is_uploaded_file($_FILES["wgFile"]["tmp_name"])) {
} elseif (isset($_POST['savewgsettings']) && $optConf == 'upload' && is_uploaded_file($_FILES["wgFile"]["tmp_name"])) {
SaveWireGuardUpload($status, $_FILES['wgFile'], $optRules);
} elseif (isset($_POST['startwg'])) {
$status->addMessage('Attempting to start WireGuard', 'info');
@ -30,7 +32,7 @@ function DisplayWireGuardConfig()
}
}
// fetch wg config
// fetch server config
exec('sudo cat '. RASPI_WIREGUARD_CONFIG, $return);
$conf = ParseConfig($return);
$wg_srvpubkey = exec('sudo cat '. RASPI_WIREGUARD_PATH .'wg-server-public.key', $return);
@ -42,7 +44,7 @@ function DisplayWireGuardConfig()
$wg_senabled = true;
}
// todo: iterate multiple peer configs
// fetch client config
exec('sudo cat '. RASPI_WIREGUARD_PATH.'client.conf', $preturn);
$conf = ParseConfig($preturn);
$wg_pipaddress = ($conf['Address'] == '') ? getDefaultNetValue('wireguard','peer','Address') : $conf['Address'];

View File

@ -9,22 +9,13 @@
<div class="info-value col-xs-3"><?php echo htmlspecialchars($public_ip, ENT_QUOTES); ?><a class="text-gray-500" href="https://ipapi.co/<?php echo($public_ip); ?>" target="_blank" rel="noopener noreferrer"><i class="fas fa-external-link-alt ml-2"></i></a></div>
</div>
</div>
<div class="input-group">
<div class="custom-control custom-switch">
<input class="custom-control-input" id="server_enabled" type="checkbox" name="wg_senabled" value="1" <?php echo $wg_senabled ? ' checked="checked"' : "" ?> aria-describedby="server-description">
<label class="custom-control-label" for="server_enabled"><?php echo _("Enable server") ?></label>
</div>
<p id="wg-description">
<small><?php echo _("Enable this option to secure network traffic by creating an encrypted tunnel between RaspAP and configured endpoints.") ?></small>
</p>
</div>
<h5><?php echo _("Configuration Method"); ?></h5>
<div class="col-sm-12 mt-2 mb-2 form-check">
<input class="form-check-input" id="wg-upload" name="sel1" value="upload" data-toggle="" data-parent="#serversettings" data-target="#wgUpload" type="radio" checked>
<input class="form-check-input" id="wg-upload" name="wgCnfOpt" value="upload" data-toggle="" data-parent="#serversettings" data-target="#wgUpload" type="radio" checked>
<label class="form-check-label"><?php echo _("Upload file"); ?></label>
</div>
<div class="col-sm-12 mt-2 mb-2 form-check">
<input class="form-check-input" id="wg-manual" name="sel1" value="manual" data-toggle="" data-parent="#serversettings" data-target="#wgManual" type="radio">
<input class="form-check-input" id="wg-manual" name="wgCnfOpt" value="manual" data-toggle="" data-parent="#serversettings" data-target="#wgManual" type="radio">
<label class="form-check-label"><?php echo _("Create manually"); ?></label>
</div>
@ -67,10 +58,20 @@
<div class="panel panel-default panel-collapse" id="PanelManual">
<div class="panel-heading">
<h5 class="panel-title"><?php echo _("Create a local WireGuard config"); ?></h5>
<p id="wg-description">
<small><?php echo _("This option generates a new <code>wg0.conf</code> WireGuard configuration on this device.") ?></small>
</p>
<div class="input-group">
<div class="custom-control custom-switch">
<input class="custom-control-input" id="server_enabled" type="checkbox" name="wgSrvEnable" value="1" <?php echo $wg_senabled ? ' checked="checked"' : "" ?> aria-describedby="server-description">
<label class="custom-control-label" for="server_enabled"><?php echo _("Enable server") ?></label>
</div>
<p id="wg-description">
<small>
<?php echo _("Enable this option to secure network traffic by creating an encrypted tunnel between RaspAP and configured peers.") ?>
<?php echo _("This setting generates a new WireGuard <code>.conf</code> file on this device.") ?>
</small>
</p>
</div>
</div>
<div class="panel-body">
<label for="code"><?php echo _("Local public key"); ?></label>
<div class="input-group col-md-12 mb-3">
@ -94,6 +95,8 @@
<label for="code"><?php echo _("DNS"); ?></label>
<input type="text" class="form-control" name="wg_srvdns" value="<?php echo htmlspecialchars($wg_srvdns, ENT_QUOTES); ?>" />
</div>
<div class="row mb-3"></div>
</div><!-- /.panel-body -->
</div><!-- /.panel -->