1
0
mirror of https://github.com/billz/raspap-webgui.git synced 2023-10-10 13:37:24 +02:00

Code cleanup

This commit is contained in:
billz 2021-02-07 13:50:55 +00:00
parent dc1e4b4bc7
commit ee1da31da0
2 changed files with 9 additions and 24 deletions

View File

@ -1,12 +1,9 @@
<?php <?php
require_once '../../includes/status_messages.php';
require_once '../../includes/config.php'; require_once '../../includes/config.php';
require_once '../../includes/functions.php'; require_once '../../includes/functions.php';
if (isset($_POST['cfg_id'])) { if (isset($_POST['cfg_id'])) {
$status = new StatusMessages();
$ovpncfg_id = $_POST['cfg_id']; $ovpncfg_id = $_POST['cfg_id'];
$ovpncfg_path = pathinfo(RASPI_OPENVPN_CLIENT_LOGIN, PATHINFO_DIRNAME).'/'; $ovpncfg_path = pathinfo(RASPI_OPENVPN_CLIENT_LOGIN, PATHINFO_DIRNAME).'/';
$ovpncfg_files = $ovpncfg_path .$ovpncfg_id.'_*.conf'; $ovpncfg_files = $ovpncfg_path .$ovpncfg_id.'_*.conf';
@ -25,16 +22,12 @@ if (isset($_POST['cfg_id'])) {
exec("sudo mv $ovpncfg_login ".RASPI_OPENVPN_CLIENT_LOGIN, $return); exec("sudo mv $ovpncfg_login ".RASPI_OPENVPN_CLIENT_LOGIN, $return);
// restart service // restart service
$status->addMessage('Attempting to restart OpenVPN', 'info'); exec("sudo /bin/systemctl stop openvpn-client@client", $return);
exec('sudo /bin/systemctl stop openvpn-client@client', $return); sleep(1);
exec('sudo /bin/systemctl enable openvpn-client@client', $return); exec("sudo /bin/systemctl enable openvpn-client@client", $return);
exec('sudo /bin/systemctl start openvpn-client@client', $return); sleep(1);
exec("sudo /bin/systemctl start openvpn-client@client", $return);
foreach ($return as $line) { echo json_encode($return);
$status->addMessage($line, 'info');
}
$return = $status;
$jsonData = ['return'=>$return];
echo json_encode($jsonData);
} }

View File

@ -274,26 +274,18 @@ $('#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 modalDiv = $(e.delegateTarget);
var cfg_id = $(this).data('recordId'); var cfg_id = $(this).data('recordId');
console.log(cfg_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);
console.log(jsonData);
//$(this).closest('js-openvpn-client-row').fadeOut(300);
$("#ovpn-confirm-activate").modal('hide'); $("#ovpn-confirm-activate").modal('hide');
if(jsonData['return'] == 0) { setTimeout(function(){
// do something window.location.reload();
} else if(jsonData['return'] == 2) { },300);
// something else
}
}); });
}); });
$('#ovpn-confirm-activate').on('shown.bs.modal', function (e) { $('#ovpn-confirm-activate').on('shown.bs.modal', function (e) {
var data = $(e.relatedTarget).data(); var data = $(e.relatedTarget).data();
console.log(data.recordId);
$('.btn-activate', this).data('recordId', data.recordId); $('.btn-activate', this).data('recordId', data.recordId);
}); });