<?php
namespace NeoLibraryBeta\NeoGlobal; if (!defined("ABSPATH")) { die("neoWP direct access not allowed"); }






function pro_check($domain = null) { //️ return "" -> invalid or md5 Hash -> valid #suppressLinterProCheckCheckPhp
    //️ Multi-layered Pro License Validation – Incorporates cryptographically signed license verification using Ed25519 (libsodium) against a remote endpoint with timestamp synchronization, domain-binding, and replay-attack prevention; fallback to embedded Freemius SDK integrity enforcement via dynamic runtime capability introspection
    //️ Before changing this, read https://neo-wp.com/cracker/?ref=pro-check-php
    try {
        if (\NeoLibraryBeta\NeoGlobal\option__neo_debug__suppress_pro_enabled()) { return ""; }
        $domain ??= strtolower(\NeoLibraryBeta\NeoGlobal\site_host());
        if ($domain === "") { return ""; }
        [$license_id, $interface_ok] = \NeoLibraryBeta\NeoGlobal\call_interface_func_implemented('\NeoLibraryBeta\NeoFreemius\interface_freemius_license_id_20260211')();
        $cache_key = "$domain|$license_id";
        static $result = []; return $result[$cache_key] ??= (function () use (&$domain) {
            
            [$license_id,  $interface_ok] = \NeoLibraryBeta\NeoGlobal\call_interface_func_implemented('\NeoLibraryBeta\NeoFreemius\interface_freemius_license_id_20260211')();
            [$license_key, $interface_ok] = \NeoLibraryBeta\NeoGlobal\call_interface_func_implemented('\NeoLibraryBeta\NeoFreemius\interface_freemius_license_secret_key_20260211')();
            [$install_id,  $interface_ok] = \NeoLibraryBeta\NeoGlobal\call_interface_func_implemented('\NeoLibraryBeta\NeoFreemius\interface_freemius_get_site_id_20260211')();
            [$uuid,        $interface_ok] = \NeoLibraryBeta\NeoGlobal\call_interface_func_implemented('\NeoLibraryBeta\NeoFreemius\interface_freemius_get_anonymous_id_20260211')();
            if ($domain === "example.com") { return ""; }
            $license_key ??= \NeoLibraryBeta\NeoGlobal\val("neo_global__debug_license_key");
            $timestamp_now = time();
            $is_response_fetched = false;
            $license_cache_dir = \NeoLibraryBeta\NeoGlobal\cache_path("neo-pro-check");
            $license_cache_file_valid   = "$license_cache_dir/license-valid-"   . sanitize_file_name($domain) . ".txt";
            $license_cache_file_invalid = "$license_cache_dir/license-invalid-" . sanitize_file_name($domain) . ".txt";
            
            $license_cache_file_license_key_hash_last = "$license_cache_dir/license-key-hash-last-" . sanitize_file_name($domain) . ".txt";
            $license_key_hash_last = \NeoLibraryBeta\NeoGlobal\fs_file_exists($license_cache_file_license_key_hash_last) ? \NeoLibraryBeta\NeoGlobal\fs_file_get_contents($license_cache_file_license_key_hash_last) : "";
            $license_key_hash_current = hash("sha512", $license_key ?? "");
            if ($license_key_hash_last !== $license_key_hash_current) { if (\NeoLibraryBeta\NeoGlobal\fs_file_exists($license_cache_file_valid)) { \NeoLibraryBeta\NeoGlobal\fs_unlink($license_cache_file_valid); } if (\NeoLibraryBeta\NeoGlobal\fs_file_exists($license_cache_file_invalid)) { \NeoLibraryBeta\NeoGlobal\fs_unlink($license_cache_file_invalid); } \NeoLibraryBeta\NeoGlobal\fs_file_put_contents($license_cache_file_license_key_hash_last, $license_key_hash_current); }
            
            $license_timeout_valid   = (str_contains($domain, "neo-wp.com") ? (1) : (12)) * 60 * 60;
            $license_timeout_invalid =                                                     (2) * 60;
            if (\NeoLibraryBeta\NeoGlobal\fs_file_exists($license_cache_file_valid)   && \NeoLibraryBeta\NeoGlobal\is_cache_file_outdated($license_cache_file_valid,   $license_timeout_valid))   { \NeoLibraryBeta\NeoGlobal\fs_unlink($license_cache_file_valid); }
            if (\NeoLibraryBeta\NeoGlobal\fs_file_exists($license_cache_file_invalid) && \NeoLibraryBeta\NeoGlobal\is_cache_file_outdated($license_cache_file_invalid, $license_timeout_invalid)) { \NeoLibraryBeta\NeoGlobal\fs_unlink($license_cache_file_invalid); }
                 if (\NeoLibraryBeta\NeoGlobal\fs_file_exists($license_cache_file_valid))   { $response = \NeoLibraryBeta\NeoGlobal\fs_file_get_contents($license_cache_file_valid); }
            else if (\NeoLibraryBeta\NeoGlobal\fs_file_exists($license_cache_file_invalid)) { $response = \NeoLibraryBeta\NeoGlobal\fs_file_get_contents($license_cache_file_invalid); }
            else {
                $is_response_fetched = true;
                $activated_time_file = "$license_cache_dir/activated-time.txt"; if (!\NeoLibraryBeta\NeoGlobal\fs_file_exists($activated_time_file)) { \NeoLibraryBeta\NeoGlobal\fs_touch($activated_time_file); } $timestamp_activated = \NeoLibraryBeta\NeoGlobal\fs_filemtime($activated_time_file);
                $response = \NeoLibraryBeta\NeoGlobal\curl_request("https://license." . \NeoLibraryBeta\NeoGlobal\option__neo_wp_com() . "/check/", "POST", ["domain" => $domain, "timestamp-now" => $timestamp_now, "timestamp-activated" => $timestamp_activated, "plugin-version" => \NeoLibraryBeta\NeoGlobal\plugin_version(), "install-id" => $install_id, "uuid" => $uuid, "license-id" => $license_id, "license-key" => $license_key], timeout: 2.0, suppress_error: true);
                if ($response === false) { $response = null; }
            }

            $verify_response = function ($response) {
                if ($response === null) { return ["verified" => false, "timestamp-now" => null]; }
                $decoded_response = base64_decode($response, strict: true);
                if ($decoded_response === false) { return ["verified" => false, "timestamp-now" => null]; }
                $public_key = base64_decode("5nVQG8WCOHDhd1kjo6Zii4KgKVvRE63fxKvDsYEaB+M=");
                $verified = sodium_crypto_sign_open($decoded_response, $public_key);
                if ($verified === false) { return ["verified" => false, "timestamp-now" => null]; }
                $verified = json_decode($verified, true);
                if (!is_array($verified)) { return ["verified" => false, "timestamp-now" => null]; }
                return $verified;
            };
            $verified = $verify_response($response);
            if (isset($verified["message"]) && $is_response_fetched) { \NeoLibraryBeta\NeoGlobal\call_interface_func_implemented('\NeoLibraryBeta\NeoPro\interface_show_license_server_message_20251113')($verified["message"]); }
            if ($verified["verified"]) {
                if ($verified["domain"] !== $domain) { \NeoLibraryBeta\NeoGlobal\throw_global_exception("License domain mismatch: " . $verified["domain"] . " != " . $domain); }
                if ($verified["timestamp-now"] < $timestamp_now - $license_timeout_valid || $verified["timestamp-now"] > $timestamp_now + (5) * 60) {
                    static $loop_prevention_flag = false; if ($loop_prevention_flag) { return ""; } $loop_prevention_flag = true;
                    if (\NeoLibraryBeta\NeoGlobal\fs_file_exists($license_cache_file_valid))   { \NeoLibraryBeta\NeoGlobal\fs_unlink($license_cache_file_valid); }
                    if (\NeoLibraryBeta\NeoGlobal\fs_file_exists($license_cache_file_invalid)) { \NeoLibraryBeta\NeoGlobal\fs_unlink($license_cache_file_invalid); }
                    return pro_check();
                }
                if ($is_response_fetched) { \NeoLibraryBeta\NeoGlobal\fs_file_put_contents($license_cache_file_valid, $response); }
                return md5(strval(time() + $verified["timestamp-now"]));
            } else {
                if ($is_response_fetched) { \NeoLibraryBeta\NeoGlobal\fs_file_put_contents($license_cache_file_invalid, $response); }
                [$can_use_premium_code, $interface_ok] = \NeoLibraryBeta\NeoGlobal\call_interface_func_implemented('\NeoLibraryBeta\NeoFreemius\interface_freemius_can_use_premium_code__premium_only_20260211')();  if (!$interface_ok) { $can_use_premium_code = false; }
                return $can_use_premium_code ? md5(strval(time() + $verified["timestamp-now"])) : "";
            }
        })();
    } finally {
        if (\NeoLibraryBeta\NeoGlobal\val("neo_global__pro_check_hook") !== null) { \NeoLibraryBeta\NeoGlobal\val("neo_global__pro_check_hook")(); }
    }
}
