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:
parent
234f22117f
commit
1647aa3c73
@ -53,7 +53,7 @@ function DisplayOpenVPNConfig()
|
||||
$authUser = current($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;
|
||||
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');
|
||||
}
|
||||
|
||||
|
||||
// Good file upload, update auth credentials if present
|
||||
$prepend = '# filename '.pathinfo($file['name'], PATHINFO_FILENAME) .PHP_EOL;
|
||||
if (!empty($authUser) && !empty($authPassword)) {
|
||||
$auth_flag = 1;
|
||||
// Move tmp authdata to /etc/openvpn/login.conf
|
||||
$auth.= $authUser .PHP_EOL . $authPassword .PHP_EOL;
|
||||
file_put_contents($tmp_authdata, $auth);
|
||||
file_prepend_data($tmp_authdata, $prepend);
|
||||
file_move_config(RASPI_OPENVPN_CLIENT_LOGIN);
|
||||
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) {
|
||||
$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
|
||||
exec("sudo /etc/raspap/openvpn/configauth.sh $tmp_ovpnclient $auth_flag " .$_SESSION['ap_interface'], $return);
|
||||
foreach ($return as $line) {
|
||||
$status->addMessage($line, 'info');
|
||||
}
|
||||
|
||||
// Copy tmp client config to /etc/openvpn/client
|
||||
file_move_config(RASPI_OPENVPN_CLIENT_CONFIG);
|
||||
$client_ovpn = RASPI_OPENVPN_CLIENT_PATH.pathinfo($file['name'], PATHINFO_FILENAME).'_client.conf';
|
||||
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) {
|
||||
$status->addMessage('OpenVPN client.conf uploaded successfully', 'info');
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user