whoami7 - Manager
:
/
home
/
simspala
/
yoursimzone.com
/
Upload File:
files >> /home/simspala/yoursimzone.com/refresh_all.php
<?php /*********************************************************** * ONE-PAGE UCUT REFRESH (Batch 50 · usleep) * Pure PHP • Background Execution • cURL • MySQL PDO * Modern UI + Instant "success" Echo ***********************************************************/ ignore_user_abort(true); set_time_limit(0); $dsn = 'mysql:host=localhost;dbname=simspala_yoursim;charset=utf8mb4'; $dbUser = 'simspala_yoursim'; $dbPass = 'simspala_yoursim'; /*********************************************************************** * FRONT-END UI PAGE ***********************************************************************/ if ($_SERVER['REQUEST_METHOD'] !== 'POST') { ?> <!DOCTYPE html> <html> <head> <title>UCUT Refresh (Batch Auto)</title> <style> body { margin:0; padding:0; height:100vh; display:flex; justify-content:center; align-items:center; background: linear-gradient(135deg, #131722, #1b2336); font-family: "Segoe UI", Arial, sans-serif; } .card { width: 360px; background: rgba(255,255,255,0.08); padding: 35px; border-radius: 16px; backdrop-filter: blur(12px); box-shadow: 0 0 25px rgba(0,0,0,0.25); text-align:center; color:white; } input { width:100%; padding:12px; font-size:16px; margin-top:10px; border-radius: 8px; border: none; outline: none; background: rgba(255,255,255,0.15); color:white; } button { margin-top:20px; width:100%; padding:12px; background: linear-gradient(135deg, #4a92ff, #005dff); border: none; border-radius: 10px; font-size:16px; color:white; cursor:pointer; transition:0.25s; } button:hover { transform: scale(1.05); } footer { margin-top:25px; font-size:12px; opacity:0.6; } </style> </head> <body> <div class="card"> <h2>UCUT Batch Refresh</h2> <p>Enter user email. System will refresh all SIM stats <b>in batches of 50</b>.</p> <form method="POST"> <input type="email" name="email" placeholder="user@example.com" required> <button type="submit">Start Refresh</button> </form> <footer>Process continues even if you close this window.</footer> </div> </body> </html> <?php exit; } /*********************************************************************** * IMMEDIATE RESPONSE (NO WAITING) ***********************************************************************/ $email = trim($_POST['email'] ?? ''); header('Content-Type: text/plain'); echo "success"; // <--- requested if (function_exists('fastcgi_finish_request')) { fastcgi_finish_request(); // flush and let backend continue } /*********************************************************************** * BACKGROUND PROCESS STARTS HERE ***********************************************************************/ $logFile = __DIR__ . "/refresh_stats.log"; try { $pdo = new PDO($dsn, $dbUser, $dbPass, [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ]); } catch (Exception $e) { file_put_contents($logFile, "[DB ERROR] ".$e->getMessage()."\n", FILE_APPEND); exit; } file_put_contents($logFile, "\n===== START ($email @ ".date('Y-m-d H:i:s').") =====\n", FILE_APPEND ); /*********************************************************************** * FETCH SERVERS ***********************************************************************/ $stmt = $pdo->prepare("SELECT * FROM servers WHERE user_email=? ORDER BY id ASC"); $stmt->execute([$email]); $servers = $stmt->fetchAll(PDO::FETCH_ASSOC); $batches = array_chunk($servers, 50); // batch size 50 /*********************************************************************** * UCUT REFRESH FUNCTION ***********************************************************************/ function safeRefreshStats($pdo, $server, $logFile) { $url = "https://mtn-dxl-ucut-services.mymtnnxgeaprod.mtnnigeria.net/v1/ucut/customerBalance"; $payload = json_encode(["msisdn" => $server["phone_number"]]); $headers = [ "Authorization: Bearer " . $server["server_token"], "Channel: MTNAPPNXG", "Content-Type: application/json" ]; $ch = curl_init($url); curl_setopt_array($ch, [ CURLOPT_POST => true, CURLOPT_POSTFIELDS => $payload, CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 25, CURLOPT_CONNECTTIMEOUT => 15, CURLOPT_HTTPHEADER => $headers, CURLOPT_SSL_VERIFYPEER => true, CURLOPT_SSL_VERIFYHOST => 2, CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4, ]); $response = curl_exec($ch); $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); $err = curl_error($ch); curl_close($ch); if ($response === false) { file_put_contents($logFile, "[CURL ERROR] {$server['phone_number']} => $err\n", FILE_APPEND ); return false; } file_put_contents($logFile, "[RAW] {$server['phone_number']} ($status) => ".substr($response,0,1500)."\n", FILE_APPEND ); if ($status < 200 || $status >= 300) { file_put_contents($logFile, "[HTTP FAIL] {$server['phone_number']} => HTTP $status\n", FILE_APPEND ); return false; } $json = json_decode($response, true); if (!$json || !isset($json["data"]["balance"])) { file_put_contents($logFile, "[PARSE FAIL] {$server['phone_number']}\n", FILE_APPEND ); return false; } // Extract values $dataBal = null; $airBal = null; $expire = null; foreach ($json["data"]["balance"] as $b) { if ($b["balanceType"] === "Data Bundle") { $val = $b["balanceDetail"]["activeValue"] ?? 0; $unit = $b["balanceDetail"]["activeUnit"] ?? ""; $dataBal = trim("$val $unit"); $rawExp = $b["wallets"][0]["expiryDate"] ?? null; if ($rawExp) { $ts = strtotime($rawExp); $expire = ($ts && $ts < strtotime("2037-12-31")) ? date("Y-m-d H:i:s", $ts) : "2037-12-31 23:59:59"; } } if (strtolower($b["balanceType"]) === "main balance") { $airBal = $b["balanceDetail"]["activeValue"] ?? 0; } } // Log parsed file_put_contents($logFile, "[PARSED] {$server['phone_number']} => airtime=$airBal data=$dataBal exp=$expire\n", FILE_APPEND ); // Update DB $stmt = $pdo->prepare(" UPDATE servers SET data_bal=?, airtime_bal=?, data_expire_at=? WHERE id=? "); $stmt->execute([$dataBal, $airBal, $expire, $server["id"]]); return true; } /*********************************************************************** * PROCESS BATCHES UNTIL FINISHED (usleep) ***********************************************************************/ foreach ($batches as $i => $batch) { file_put_contents($logFile, "--- Batch ".($i+1)." of ".count($batches)." ---\n", FILE_APPEND ); foreach ($batch as $srv) { safeRefreshStats($pdo, $srv, $logFile); // Delay for MTN throttling control (0.9s) usleep(900000); } } file_put_contents($logFile, "===== DONE ($email @ ".date('Y-m-d H:i:s').") =====\n", FILE_APPEND ); ?>
Copyright ©2021 || Defacer Indonesia