whoami7 - Manager
:
/
home
/
simspala
/
yoursimzone.com
/
Upload File:
files >> /home/simspala/yoursimzone.com/checking.php
<?php declare(strict_types=1); date_default_timezone_set("Africa/Lagos"); set_time_limit(0); // ======================= // DATABASE CONFIG // ======================= $dsn = 'mysql:host=localhost;dbname=simspala_yoursim;charset=utf8mb4'; $dbUser = 'simspala_yoursim'; $dbPass = 'simspala_yoursim'; // ======================= // LOG FILE // ======================= $logFile = __DIR__ . '/weekly_reactivate.log'; function writeLog(string $message): void { global $logFile; file_put_contents( $logFile, "[" . date("Y-m-d H:i:s") . "] {$message}\n", FILE_APPEND ); } // ======================= // NORMALIZE PHONE // 0803... -> +234803... // 234803... -> +234803... // +234803... -> +234803... // ======================= function normalizePhone(string $phone): string { $phone = trim($phone); $phone = str_replace([' ', '-', '(', ')'], '', $phone); if (strpos($phone, '+234') === 0) { return $phone; } if (strpos($phone, '234') === 0) { return '+' . $phone; } if (strpos($phone, '0') === 0) { return '+234' . substr($phone, 1); } return $phone; } try { // ======================= // CONNECT DATABASE // ======================= $pdo = new PDO($dsn, $dbUser, $dbPass, [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, ]); // ======================= // TARGET USER // ======================= $email = "mbiee4241@gmail.com"; $stmt = $pdo->prepare(" SELECT id FROM users WHERE email = ? LIMIT 1 "); $stmt->execute([$email]); $user = $stmt->fetch(); if (!$user) { writeLog("ERROR: User not found: {$email}"); exit; } $userId = (int) $user['id']; // ======================= // CRITICAL TRANSACTION // MESSAGE PATTERNS // ======================= $criticalPatterns = [ 'daily limit', 'maximum limit', 'maximum limit of 10 data shares', 'you have reached the maximum limit of 10 data shares', 'data balance is not sufficient', 'activation of data transfer', ]; // ======================= // FIND DISABLED WEEKLY SIMS // ======================= $stmt = $pdo->prepare(" SELECT id, phone_number, data_bal FROM servers WHERE user_id = ? AND `group` = 'WEEKLY' AND vend_data = 0 AND data_bal IS NOT NULL AND data_bal != '' ORDER BY id ASC "); $stmt->execute([$userId]); $servers = $stmt->fetchAll(); if (!$servers) { exit; } // ======================= // GET LAST TRANSACTION // FOR EACH SENDER // ======================= $lastTransactionStmt = $pdo->prepare(" SELECT id, message, api_response, created_at FROM transactions WHERE sender_id = ? ORDER BY id DESC LIMIT 1 "); // ======================= // REACTIVATE QUERY // ======================= $update = $pdo->prepare(" UPDATE servers SET vend_data = 1, server_on = 1, attempts = 0, failure_count = 0 WHERE id = ? AND user_id = ? AND `group` = 'WEEKLY' AND vend_data = 0 "); $activated = 0; $skippedCritical = 0; $skippedBalance = 0; // ======================= // CHECK EACH SERVER // ======================= foreach ($servers as $server) { $serverId = (int) $server['id']; $serverPhone = normalizePhone( (string) $server['phone_number'] ); $rawBalance = trim( (string) $server['data_bal'] ); // ======================= // CLEAN BALANCE // ======================= // Example: // 7 GB -> 7 GB // 7.5 GB -> 7.5 GB // 10 GB -> 10 GB // 7,168 MB -> 7168 MB // 1,023.96 MB -> 1023.96 MB // ======================= $cleanBalance = str_replace( ',', '', $rawBalance ); // ======================= // EXTRACT NUMBER // ======================= if (!preg_match( '/([0-9]+(?:\.[0-9]+)?)/', $cleanBalance, $matches )) { writeLog( "SKIPPED INVALID BALANCE | " . "ID: {$serverId} | " . "PHONE: {$serverPhone} | " . "BALANCE: {$rawBalance}" ); continue; } $number = (float) $matches[1]; // ======================= // CONVERT TO GB // ======================= if (stripos($cleanBalance, 'GB') !== false) { $balanceGB = $number; } elseif (stripos($cleanBalance, 'MB') !== false) { $balanceGB = $number / 1024; } else { writeLog( "SKIPPED UNKNOWN BALANCE UNIT | " . "ID: {$serverId} | " . "PHONE: {$serverPhone} | " . "BALANCE: {$rawBalance}" ); continue; } // ======================= // MUST HAVE 7 GB OR ABOVE // ======================= if ($balanceGB < 7) { $skippedBalance++; continue; } // ======================= // GET LAST TRANSACTION // ======================= $lastTransactionStmt->execute([ $serverPhone ]); $lastTransaction = $lastTransactionStmt->fetch(); // ======================= // CHECK LAST MESSAGE // ======================= if ($lastTransaction) { $transactionMessage = trim( (string) ($lastTransaction['message'] ?? '') ); $apiResponse = trim( (string) ($lastTransaction['api_response'] ?? '') ); // Check both fields $lastMessage = $transactionMessage . ' ' . $apiResponse; $criticalFound = false; $matchedPattern = ''; foreach ($criticalPatterns as $pattern) { if ( $lastMessage !== '' && stripos($lastMessage, $pattern) !== false ) { $criticalFound = true; $matchedPattern = $pattern; break; } } // ======================= // CRITICAL MESSAGE FOUND // DO NOT REACTIVATE // ======================= if ($criticalFound) { $skippedCritical++; writeLog( "SKIPPED CRITICAL | " . "SERVER_ID: {$serverId} | " . "PHONE: {$serverPhone} | " . "BALANCE: {$rawBalance} | " . "TRANSACTION_ID: {$lastTransaction['id']} | " . "MATCHED: {$matchedPattern} | " . "MESSAGE: {$transactionMessage} | " . "API_RESPONSE: {$apiResponse}" ); continue; } } // ======================= // ALL CHECKS PASSED // REACTIVATE SERVER // ======================= $update->execute([ $serverId, $userId ]); if ($update->rowCount() > 0) { $activated++; writeLog( "REACTIVATED | " . "SERVER_ID: {$serverId} | " . "PHONE: {$serverPhone} | " . "BALANCE: {$rawBalance} | " . "BALANCE_GB: " . round($balanceGB, 2) ); } } // ======================= // SUMMARY // ======================= if ( $activated > 0 || $skippedCritical > 0 ) { writeLog( "DONE | " . "ACTIVATED: {$activated} | " . "SKIPPED_CRITICAL: {$skippedCritical} | " . "SKIPPED_LOW_BALANCE: {$skippedBalance}" ); } } catch (Throwable $e) { writeLog( "ERROR: {$e->getMessage()} | " . "FILE: {$e->getFile()} | " . "LINE: {$e->getLine()}" ); }
Copyright ©2021 || Defacer Indonesia