<?php
$Tag = isset($_GET["tag"]) ? $_GET["tag"] : '';
$UserID = isset($_GET["userid"]) ? $_GET["userid"] : '';

if ($Tag === "vpnconfigV2") {
    $db = new SQLite3("./vpn.db");
    $vpn = $db->query("SELECT * FROM vpnconfig");

    $vpnConfigs = [];
    while ($vpna = $vpn->fetchArray(SQLITE3_ASSOC)) {
        $vpnConfigs[] = [
            "id" => $vpna["id"],
            "userid" => $vpna["userid"],
            "vpn_appid" => $vpna["vpn_appid"],
            "vpn_country" => $vpna["vpn_country"],
            "vpn_state" => $vpna["vpn_state"],
            "vpn_config" => $vpna["vpn_config"],
            "vpn_status" => $vpna["vpn_status"],
            "auth_type" => $vpna["auth_type"],
            "auth_embedded" => $vpna["auth_embedded"],
            "username" => $vpna["username"],
            "password" => $vpna["password"],
            "date" => $vpna["date"]
        ];
    }

    $response = [
        "tag" => "vpnconfigV2",
        "success" => "1",
        "api_ver" => "1.0v",
        "vpnconfigs" => $vpnConfigs
    ];

    $jsonResponse = json_encode($response);

    // Encrypt the response if needed
    echo bin2hex(openssl_encrypt($jsonResponse, "AES-128-CBC", "mysecretkeywsdef", OPENSSL_RAW_DATA, "myuniqueivparamu"));
} else {
    // In case the tag is not "vpnconfigV2", you can include your default behavior or handle it accordingly.
    // For simplicity, I'm echoing a message here.
    echo "Invalid or missing 'tag' parameter for VPN configuration.";
}
?>
