openvpn: remove is_interface_assigned() so it can be removed

This commit is contained in:
Franco Fichtner 2025-04-24 08:15:41 +02:00
parent f31d7a8aa6
commit 4ce4450537
2 changed files with 8 additions and 24 deletions

View File

@ -124,30 +124,20 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
}
if ($act == "del") {
// remove client
$response = ["status" => "failed", "message" => gettext("not found")];
if (isset($id)) {
$vpn_id = !empty($a_client[$id]) ? $a_client[$id]['vpnid'] : null;
if ($vpn_id !== null && is_interface_assigned("ovpnc{$vpn_id}")) {
$response = [
"status" => "failed",
"message" => gettext("This tunnel cannot be deleted because it is still being used as an interface.")
];
} elseif ($vpn_id !== null) {
if (isset($id) && !empty($a_client[$id])) {
openvpn_delete('client', $a_client[$id]);
unset($a_client[$id]);
write_config();
$response = ["status" => "ok"];
}
}
echo json_encode($response);
exit;
} elseif ($act == "del_x") {
if (!empty($pconfig['rule']) && is_array($pconfig['rule'])) {
foreach ($pconfig['rule'] as $rulei) {
$vpn_id = !empty($a_client[$rulei]) ? $a_client[$rulei]['vpnid'] : null;
// XXX: silently ignore entries that can't be removed, no clean option to pass messages in form result
if ($vpn_id !== null && !is_interface_assigned("ovpnc{$vpn_id}")) {
if (!empty($a_client[$rulei])) {
openvpn_delete('client', $a_client[$rulei]);
unset($a_client[$rulei]);
}

View File

@ -133,14 +133,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
}
if ($act == "del") {
// action delete
$vpn_id = !empty($a_server[$id]) ? $a_server[$id]['vpnid'] : null;
if ($vpn_id !== null && is_interface_assigned("ovpns{$vpn_id}")) {
$response = [
"status" => "failed",
"message" => gettext("This tunnel cannot be deleted because it is still being used as an interface.")
];
} elseif ($vpn_id !== null) {
$response = ["status" => "failed", "message" => gettext("not found")];
if (isset($id) && !empty($a_client[$id])) {
openvpn_delete('server', $a_server[$id]);
unset($a_server[$id]);
write_config();