TP-Link M7350 Quick Status
Auto-run on page load
⚠️ Fetching quick status from router...
⚠️ Reading password from password.txt...';
if (!file_exists('password.txt')) {
throw new Exception("Could not find password.txt in directory.");
}
$password = trim(file_get_contents('password.txt'));
// Step 1: Get nonce
$status = '
⚠️ Getting nonce from router...';
$nonceData = json_encode(['module' => 'authenticator', 'action' => 0]);
$ch = curl_init("http://{$host}/cgi-bin/auth_cgi");
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $nonceData,
CURLOPT_HTTPHEADER => [
'Content-Type: application/x-www-form-urlencoded; charset=UTF-8',
'X-Requested-With: XMLHttpRequest',
'Referer: http://' . $host . '/login.html'
],
CURLOPT_TIMEOUT => 10,
]);
$response = curl_exec($ch);
if (curl_errno($ch)) {
throw new Exception("Connection failed: " . curl_error($ch));
}
curl_close($ch);
$nonceResult = json_decode($response, true);
if (!$nonceResult || !isset($nonceResult['nonce'])) {
throw new Exception("Failed to get nonce from router");
}
$nonce = $nonceResult['nonce'];
$n_out = htmlspecialchars($nonce);
// Step 2: Calculate digest and get token
$status = '
⚠️ Logging in...';
$digest = md5($password . ':' . $nonce);
$loginData = json_encode([
'module' => 'authenticator',
'action' => 1,
'digest' => $digest
]);
$ch = curl_init("http://{$host}/cgi-bin/auth_cgi");
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $loginData,
CURLOPT_HTTPHEADER => [
'Content-Type: application/x-www-form-urlencoded; charset=UTF-8',
'X-Requested-With: XMLHttpRequest',
'Referer: http://' . $host . '/login.html'
],
CURLOPT_TIMEOUT => 10,
]);
$response = curl_exec($ch);
if (curl_errno($ch)) {
throw new Exception("Login failed: " . curl_error($ch));
}
curl_close($ch);
$loginResult = json_decode($response, true);
if (!$loginResult || !isset($loginResult['token'])) {
throw new Exception("Login Failed - check password.txt content.");
}
$token = $loginResult['token'];
$t_out = htmlspecialchars($token);
// Step 3: Fetch status information
$status = '
⚠️ Fetching status information...';
$statusData = json_encode([
'token' => $token,
'module' => 'status',
'action' => 0
]);
$ch = curl_init("http://{$host}/cgi-bin/web_cgi");
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $statusData,
CURLOPT_HTTPHEADER => [
'Content-Type: application/x-www-form-urlencoded; charset=UTF-8',
'X-Requested-With: XMLHttpRequest',
'Referer: http://' . $host . '/settings.html'
],
CURLOPT_TIMEOUT => 10,
]);
$response = curl_exec($ch);
if (curl_errno($ch)) {
throw new Exception("Failed to fetch status: " . curl_error($ch));
}
curl_close($ch);
// Extract values from the JSON response
function extractValue($data, $key) {
$pattern = '/"' . preg_quote($key, '/') . '"\s*:\s*"([^"]*)"/';
preg_match($pattern, $data, $matches);
return $matches[1] ?? null;
}
// Extract values
$ipv4 = extractValue($response, 'ipv4');
$ssid = extractValue($response, 'ssid');
$model = extractValue($response, 'model');
$firmware = extractValue($response, 'firmwareVer');
$mac = extractValue($response, 'mac');
// Extract number of clients
preg_match('/"number"\s*:\s*(\d+)/', $response, $clientsMatch);
$clients = $clientsMatch[1] ?? '0';
// Extract total statistics
preg_match('/"totalStatistics"\s*:\s*"([^"]*)"/', $response, $bytesMatch);
$bytesStr = $bytesMatch[1] ?? '0';
$bytes = isset($bytesStr) ? intval(explode('.', $bytesStr)[0]) : 0;
// Convert bytes to GB
$gb = number_format($bytes / 1073741824, 2);
// Build the output
$output = '
Connection Status:
Connected
✓
Network Type:
LTE
4G
IPv4 Address:
' . htmlspecialchars($ipv4 ?? 'N/A') . '
SSID:
' . htmlspecialchars($ssid ?? 'N/A') . '
Current Clients:
' . htmlspecialchars($clients) . '
Monthly Used:
' . $gb . ' GB
(Raw bytes: ' . number_format($bytes) . ')
Model:
' . htmlspecialchars($model ?? 'Unknown') . '
Firmware:
' . htmlspecialchars($firmware ?? 'Unknown') . '
MAC Address:
' . htmlspecialchars($mac ?? 'Unknown') . '
✓ Status fetched successfully!
Done.
';
$status = '
✓ Status fetched successfully!';
$success = true;
} catch (Exception $e) {
$status = '
✗ Error: ' . htmlspecialchars($e->getMessage()) . '';
$output = '
Error Details:
' . htmlspecialchars($e->getMessage()) . '
Check console for more details.
';
}
?>
Reading credentials from password.txt...