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

Refactor config handling w/ symbolic links

This commit is contained in:
billz 2021-06-06 20:50:20 +01:00
parent 234f22117f
commit 1647aa3c73

View File

@ -53,7 +53,7 @@ function DisplayOpenVPNConfig()
$authUser = current($auth); $authUser = current($auth);
$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)));
$logEnable = 0; $logEnable = 0;
if (!empty($_POST) && !isset($_POST['log-openvpn'])) { if (!empty($_POST) && !isset($_POST['log-openvpn'])) {
@ -158,36 +158,34 @@ function SaveOpenVPNConfig($status, $file, $authUser, $authPassword)
throw new RuntimeException('Unable to move uploaded file'); throw new RuntimeException('Unable to move uploaded file');
} }
// Good file upload, update auth credentials if present // Good file upload, update auth credentials if present
$prepend = '# filename '.pathinfo($file['name'], PATHINFO_FILENAME) .PHP_EOL;
if (!empty($authUser) && !empty($authPassword)) { if (!empty($authUser) && !empty($authPassword)) {
$auth_flag = 1; $auth_flag = 1;
// Move tmp authdata to /etc/openvpn/login.conf // Move tmp authdata to /etc/openvpn/login.conf
$auth.= $authUser .PHP_EOL . $authPassword .PHP_EOL; $auth.= $authUser .PHP_EOL . $authPassword .PHP_EOL;
file_put_contents($tmp_authdata, $auth); file_put_contents($tmp_authdata, $auth);
file_prepend_data($tmp_authdata, $prepend);
file_move_config(RASPI_OPENVPN_CLIENT_LOGIN);
chmod($tmp_authdata, 0644); chmod($tmp_authdata, 0644);
system("sudo cp $tmp_authdata " . RASPI_OPENVPN_CLIENT_LOGIN, $return); $client_auth = RASPI_OPENVPN_CLIENT_PATH.pathinfo($file['name'], PATHINFO_FILENAME).'_login.conf';
system("sudo cp $tmp_authdata $client_auth", $return);
system("sudo rm ".RASPI_OPENVPN_CLIENT_LOGIN, $return);
system("sudo ln -s $client_auth ".RASPI_OPENVPN_CLIENT_LOGIN, $return);
if ($return !=0) { if ($return !=0) {
$status->addMessage('Unable to save client auth credentials', 'danger'); $status->addMessage('Unable to save client auth credentials', 'danger');
} }
} }
// Prepend filname tag to .ovpn client config
file_prepend_data($tmp_ovpnclient, $prepend);
// Set iptables rules and, optionally, auth-user-pass // Set iptables rules and, optionally, auth-user-pass
exec("sudo /etc/raspap/openvpn/configauth.sh $tmp_ovpnclient $auth_flag " .$_SESSION['ap_interface'], $return); exec("sudo /etc/raspap/openvpn/configauth.sh $tmp_ovpnclient $auth_flag " .$_SESSION['ap_interface'], $return);
foreach ($return as $line) { foreach ($return as $line) {
$status->addMessage($line, 'info'); $status->addMessage($line, 'info');
} }
// Copy tmp client config to /etc/openvpn/client $client_ovpn = RASPI_OPENVPN_CLIENT_PATH.pathinfo($file['name'], PATHINFO_FILENAME).'_client.conf';
file_move_config(RASPI_OPENVPN_CLIENT_CONFIG);
chmod($tmp_ovpnclient, 0644); chmod($tmp_ovpnclient, 0644);
system("sudo cp $tmp_ovpnclient " . RASPI_OPENVPN_CLIENT_CONFIG, $return); system("sudo cp $tmp_ovpnclient $client_ovpn", $return);
system("sudo rm ".RASPI_OPENVPN_CLIENT_CONFIG, $return);
system("sudo ln -s $client_ovpn ".RASPI_OPENVPN_CLIENT_CONFIG, $return);
if ($return ==0) { if ($return ==0) {
$status->addMessage('OpenVPN client.conf uploaded successfully', 'info'); $status->addMessage('OpenVPN client.conf uploaded successfully', 'info');
} else { } else {