File manager - Edit - /home/webtrixia/.trash/licenses.3/client/guard.php
Back
<?php /** * CLIENT GUARD — include at the top of a client hub's protected pages. * * require __DIR__.'/client/guard.php'; * wt_guard(); // locks the whole page if license expired past grace * if (wt_module('waybills')) { ... } // per paid-module check * * It calls the master's license/verify.php on every request and keeps the * latest response only as a fallback if the master is temporarily unreachable. */ require_once dirname(__DIR__) . '/lib/db.php'; function wt_guard_settings(): array { static $s = null; if ($s !== null) return $s; try { $s = wt_db()->query("SELECT master_url, license_key, product_name FROM settings WHERE id=1")->fetch() ?: []; } catch (Throwable $e) { $s = []; } return $s; } function wt_guard_master_url(): string { $cfg = wt_guard_settings(); $master = trim($cfg['master_url'] ?? ''); if ($master === '') return ''; if (!preg_match('~^https?://~i', $master)) $master = 'https://' . $master; $master = preg_replace('~/admin(?:/.*)?$~', '', $master); $master = preg_replace('~/license/verify\.php$~', '', $master); $master = preg_replace('~/licenses/(?:admin|license)(?:/.*)?$~', '/licenses', $master); $master = rtrim($master, '/'); if (!preg_match('~/licenses$~', $master)) $master .= '/licenses'; return $master; } function wt_guard_cache_file(): string { return dirname(__DIR__) . '/cache_license.json'; } function wt_guard_verify_url(): string { $cfg = wt_guard_settings(); $master = wt_guard_master_url(); $key = $cfg['license_key'] ?? ''; if (!$master || !$key) return ''; $scheme = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http'; return $master . '/license/verify.php?key=' . urlencode($key) . '&domain=' . urlencode($_SERVER['HTTP_HOST'] ?? '') . '&scheme=' . urlencode($scheme) . '&ts=' . time(); } function wt_guard_signable(array $data): string { unset($data['signature']); ksort($data); return json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); } function wt_guard_valid_signature(array $data): bool { $cfg = wt_guard_settings(); $key = $cfg['license_key'] ?? ''; if (!$key || empty($data['signature'])) return false; $sig = (string)$data['signature']; $calc = hash_hmac('sha256', wt_guard_signable($data), $key); return hash_equals($calc, $sig); } function wt_guard_store_status(array $data): bool { if (!isset($data['state'])) return false; if (isset($data['signature']) && !wt_guard_valid_signature($data)) return false; return @file_put_contents(wt_guard_cache_file(), json_encode($data, JSON_UNESCAPED_UNICODE)) !== false; } function wt_guard_status(): array { static $status = null; if ($status !== null) return $status; $cfg = wt_guard_settings(); $master = wt_guard_master_url(); $key = $cfg['license_key'] ?? ''; if (!$master || !$key) { return $status = ['state' => 'active', 'modules' => [], 'message' => 'Локален режим (без лиценз).', 'offline' => true]; } $cacheFile = wt_guard_cache_file(); $cached = null; if (is_file($cacheFile)) { $cached = json_decode(@file_get_contents($cacheFile), true); if (!is_array($cached) || !isset($cached['state'])) $cached = null; } $url = wt_guard_verify_url(); $resp = false; if (function_exists('curl_init')) { $ch = curl_init($url); curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 8, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false]); $resp = curl_exec($ch); curl_close($ch); } elseif (ini_get('allow_url_fopen')) { $resp = @file_get_contents($url, false, stream_context_create(['http' => ['timeout' => 8], 'ssl' => ['verify_peer' => false, 'verify_peer_name' => false]])); } $data = $resp ? json_decode($resp, true) : null; if (!is_array($data) || !isset($data['state'])) { // master unreachable → serve last known status, else fail open with warning if ($cached) return $status = $cached; return $status = ['state' => 'active', 'modules' => [], 'offline' => true, 'message' => 'Лицензният сървър е временно недостъпен.']; } wt_guard_store_status($data); return $status = $data; } function wt_state(): string { return wt_guard_status()['state'] ?? 'active'; } function wt_module(string $m): bool { $mods = wt_guard_status()['modules'] ?? []; return !empty($mods[$m]); } /** Renders a full-page lock and stops execution when license is locked. */ function wt_guard(): void { $s = wt_guard_status(); if (($s['state'] ?? 'active') === 'locked' || ($s['state'] ?? '') === 'invalid') { wt_render_lock($s); exit; } } function wt_render_lock(array $s): void { $product = htmlspecialchars(wt_guard_settings()['product_name'] ?? 'Webtrixia Hub'); $msg = htmlspecialchars($s['message'] ?? 'Лицензът не е активен.'); http_response_code(402); echo '<!DOCTYPE html><html lang="bg"><head><meta charset="UTF-8"> <meta name="viewport" content="width=device-width,initial-scale=1"> <title>Лицензът е неактивен</title> <link href="https://fonts.googleapis.com/css2?family=Sora:wght@400;600;700&display=swap" rel="stylesheet"> <style> body{margin:0;font-family:Sora,sans-serif;min-height:100vh;display:flex;align-items:center;justify-content:center; background:radial-gradient(circle at 30% 0%,#1a1030,#0a0a12 60%);color:#e8e8f0;padding:24px} .card{max-width:440px;text-align:center;background:rgba(255,255,255,.04);border:1px solid rgba(255,255,255,.1); border-radius:24px;padding:44px 34px;backdrop-filter:blur(20px)} .ic{font-size:52px;margin-bottom:14px} h1{font-size:22px;margin:0 0 10px} p{color:#a0a0c0;font-size:14px;line-height:1.6;margin:0 0 8px} .prod{margin-top:22px;font-size:12px;color:#6a6a8a;letter-spacing:.1em;text-transform:uppercase} </style></head><body><div class="card"> <div class="ic">🔒</div><h1>Хъбът е заключен</h1> <p>' . $msg . '</p> <p>Свържете се с вашия доставчик за подновяване.</p> <div class="prod">' . $product . '</div> </div></body></html>'; }
| ver. 1.4 |
Github
|
.
| PHP 8.2.31 | Generation time: 0.01 |
proxy
|
phpinfo
|
Settings