| Server IP : 173.209.174.21 / Your IP : 216.73.216.89 Web Server : Apache/2.4.58 (Ubuntu) System : Linux wcfs-server 6.8.0-124-generic #124-Ubuntu SMP PREEMPT_DYNAMIC Tue May 26 13:00:45 UTC 2026 x86_64 User : nodor ( 1000) PHP Version : 8.3.6 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/wifi-wcfs/ |
Upload File : |
<?php
declare(strict_types=1);
function config(): array
{
$path = __DIR__ . '/config/env.php';
if (!file_exists($path)) {
$path = __DIR__ . '/config/env.example.php';
}
return require $path;
}
function db(): PDO
{
static $pdo = null;
if ($pdo instanceof PDO) {
return $pdo;
}
$cfg = config();
$dir = dirname($cfg['sqlite_path']);
if (!is_dir($dir)) {
mkdir($dir, 0750, true);
}
$pdo = new PDO('sqlite:' . $cfg['sqlite_path']);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->exec(
'CREATE TABLE IF NOT EXISTS checkout_sessions (
id INTEGER PRIMARY KEY AUTOINCREMENT,
session_token TEXT NOT NULL UNIQUE,
plan_id TEXT NOT NULL,
client_mac TEXT,
client_ip TEXT,
ruckus_sip TEXT,
start_url TEXT,
status TEXT NOT NULL DEFAULT "created",
amount REAL NOT NULL,
created_at TEXT NOT NULL,
approved_at TEXT,
expires_at TEXT,
raw_status_json TEXT
)'
);
foreach ([
'ruckus_sip TEXT',
'start_url TEXT',
] as $column) {
try {
$pdo->exec('ALTER TABLE checkout_sessions ADD COLUMN ' . $column);
} catch (PDOException $e) {
if (strpos($e->getMessage(), 'duplicate column') === false) {
throw $e;
}
}
}
return $pdo;
}
function plans(): array
{
$json = file_get_contents(__DIR__ . '/config/plans.json');
$plans = json_decode($json, true);
if (!is_array($plans)) {
throw new RuntimeException('Could not read config/plans.json');
}
return $plans;
}
function find_plan(string $planId): ?array
{
foreach (plans() as $plan) {
if (($plan['id'] ?? '') === $planId) {
return $plan;
}
}
return null;
}
function client_mac_from_request(): ?string
{
foreach (['mac', 'client_mac', 'clientMac', 'sta_mac', 'client-mac'] as $key) {
if (!empty($_REQUEST[$key])) {
return preg_replace('/[^0-9A-Fa-f:.-]/', '', (string) $_REQUEST[$key]);
}
}
return null;
}
function north_request(string $method, string $path, array $headers = [], ?array $body = null): array
{
$cfg = config();
$ch = curl_init(rtrim($cfg['north_base_url'], '/') . $path);
$httpHeaders = array_merge([
'Authorization: Bearer ' . $cfg['north_private_api_key'],
'Content-Type: application/json',
'User-Agent: Wilson Creek WiFi Embedded Checkout',
], $headers);
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => $method,
CURLOPT_HTTPHEADER => $httpHeaders,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 20,
]);
if ($body !== null) {
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body));
}
$raw = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
$error = curl_error($ch);
curl_close($ch);
if ($raw === false) {
throw new RuntimeException('North request failed: ' . $error);
}
$decoded = json_decode($raw, true);
if ($status < 200 || $status >= 300) {
throw new RuntimeException('North returned HTTP ' . $status . ': ' . $raw);
}
return is_array($decoded) ? $decoded : ['raw' => $raw];
}
function authorize_paid_device(?string $mac, array $plan, string $expiresAt): void
{
// Hook FreeRADIUS or another access-control system here.
// For example, insert/update a radcheck/radreply row for this MAC address.
}
function send_payment_notification(array $session, array $plan, array $status, string $expiresAt): void
{
$cfg = config();
$to = trim((string) ($cfg['notification_email'] ?? ''));
if ($to === '') {
return;
}
$from = trim((string) ($cfg['notification_from_email'] ?? 'wifi@wilsoncreekfarmsupply.com'));
$amount = number_format((float) ($plan['price'] ?? $session['amount'] ?? 0), 2);
$subject = 'Wi-Fi pass sold - $' . $amount;
$body = implode("\n", [
'A Wi-Fi pass was approved.',
'',
'Plan: ' . ($plan['name'] ?? $session['plan_id'] ?? 'Unknown'),
'Amount: $' . $amount,
'Device MAC: ' . ($session['client_mac'] ?: 'Unknown'),
'Device IP: ' . ($session['client_ip'] ?: 'Unknown'),
'Approved UTC: ' . gmdate('c'),
'Expires UTC: ' . $expiresAt,
'North status: ' . ($status['status'] ?? 'Unknown'),
'',
'Session ID: ' . ($session['id'] ?? ''),
]);
$headers = [
'From: Wilson Creek Wi-Fi <' . $from . '>',
'Reply-To: ' . $from,
'Content-Type: text/plain; charset=UTF-8',
];
@mail($to, $subject, $body, implode("\r\n", $headers));
}
function json_response(array $payload, int $status = 200): void
{
http_response_code($status);
header('Content-Type: application/json');
echo json_encode($payload);
exit;
}