Merge pull request #37 from RaspAP/zbchristian-openvpn-fix

Fix openvpn activation and config display
This commit is contained in:
Bill Zimmerman 2021-06-14 07:48:07 +02:00 committed by GitHub
commit daffef71c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 7 deletions

View File

@ -291,7 +291,7 @@ $('#ovpn-confirm-delete').on('show.bs.modal', function (e) {
}); });
$('#ovpn-confirm-activate').on('click', '.btn-activate', function (e) { $('#ovpn-confirm-activate').on('click', '.btn-activate', function (e) {
var cfg_id = $(this).data('recordId'); var cfg_id = $(this).data('record-id');
$.post('ajax/openvpn/activate_ovpncfg.php',{'cfg_id':cfg_id},function(data){ $.post('ajax/openvpn/activate_ovpncfg.php',{'cfg_id':cfg_id},function(data){
jsonData = JSON.parse(data); jsonData = JSON.parse(data);
$("#ovpn-confirm-activate").modal('hide'); $("#ovpn-confirm-activate").modal('hide');

View File

@ -54,6 +54,8 @@ function DisplayOpenVPNConfig()
$authPassword = next($auth); $authPassword = next($auth);
} }
$clients = preg_grep('/_client.(conf)$/', scandir(pathinfo(RASPI_OPENVPN_CLIENT_CONFIG, PATHINFO_DIRNAME))); $clients = preg_grep('/_client.(conf)$/', scandir(pathinfo(RASPI_OPENVPN_CLIENT_CONFIG, PATHINFO_DIRNAME)));
exec("readlink ".RASPI_OPENVPN_CLIENT_CONFIG." | xargs basename", $ret);
$conf_default = empty($ret) ? "none" : $ret[0];
$logEnable = 0; $logEnable = 0;
if (!empty($_POST) && !isset($_POST['log-openvpn'])) { if (!empty($_POST) && !isset($_POST['log-openvpn'])) {
@ -79,7 +81,8 @@ function DisplayOpenVPNConfig()
"public_ip", "public_ip",
"authUser", "authUser",
"authPassword", "authPassword",
"clients" "clients",
"conf_default"
) )
); );
} }

View File

@ -8,14 +8,14 @@
</p> </p>
<div class="openvpn-configs js-openvpn-configs-container"> <div class="openvpn-configs js-openvpn-configs-container">
<?php foreach ($clients as $client) : <?php foreach ($clients as $client) :
if ($client == "client.conf") { if ($client == $conf_default) {
$label = file_get_meta(RASPI_OPENVPN_CLIENT_CONFIG,'#\sfilename\s(.*)');
$btn_class = "active"; $btn_class = "active";
} else { } else {
$label = preg_replace('/_client$/','',pathinfo($client, PATHINFO_FILENAME));
$client = $label;
$btn_class = "disabled"; $btn_class = "disabled";
}?> }
$label = preg_replace('/_client$/','',pathinfo($client, PATHINFO_FILENAME));
$client = $label;
?>
<div class="row mt-2" id="openvpn-client-row-<?php echo htmlspecialchars($client, ENT_QUOTES); ?>" > <div class="row mt-2" id="openvpn-client-row-<?php echo htmlspecialchars($client, ENT_QUOTES); ?>" >
<div class="col-md-6 col-xs-4"> <div class="col-md-6 col-xs-4">
<label><?php echo htmlspecialchars($label, ENT_QUOTES); ?></label> <label><?php echo htmlspecialchars($label, ENT_QUOTES); ?></label>