fix: use 'state' for vpn 'status' check on 22.05+

This commit is contained in:
Ely Deckers 2022-06-29 14:50:39 +02:00
parent 66f4615423
commit e603ca1a7b
1 changed files with 12 additions and 1 deletions

View File

@ -56,6 +56,7 @@ const VALUE_MAPPINGS = [
"waiting" => 4,
"server_user_listening" => 5],
"openvpn.client.status" => [
"connected" => 1,
"up" => 1,
"down" => 0,
"none" => 0,
@ -797,7 +798,7 @@ class Command
}
$value = ($value_key == "status") ?
self::get_value_mapping("openvpn.client.status", $maybe_client[$value_key]) :
self::sanitize_openvpn_clientvalue_status($maybe_client) :
$maybe_client[$value_key];
return Util::result($value == "" ? $fallback_value : $value);
@ -1042,6 +1043,16 @@ class Command
print_r(PfEnv::get_pkg_info("all", false, true));
}
private static function sanitize_openvpn_clientvalue_status($client_data)
{
$is_pre_version_22_05 = in_array($client_data["status"], array_keys(VALUE_MAPPINGS["openvpn.client.status"]));
$raw_value = $is_pre_version_22_05 ?
$client_data["status"] : $client_data["state"];
return self::get_value_mapping("openvpn.client.status", $raw_value);
}
private static function get_carp_status(): int
{
$is_carp_enabled = PfEnv::get_carp_status() != 0;