TP-Link M7350 System Log Fetcher (Multi-Page)
✓ Auto-running on page load - Fetching system logs...
'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',
'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
$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',
'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 logs for multiple pages
$logContainer = '
';
$totalLogs = 0;
$successfulPages = 0;
for ($i = 1; $i <= $totalPages; $i++) {
$status = "
Fetching page {$i}/{$totalPages}...";
try {
$logData = json_encode([
'token' => $token,
'module' => 'log',
'action' => 0,
'amountPerPage' => 20,
'pageNumber' => $i,
'type' => 0,
'level' => 0
]);
$ch = curl_init("http://{$host}/cgi-bin/web_cgi");
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $logData,
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("Page fetch failed: " . curl_error($ch));
}
curl_close($ch);
if ($response) {
$logContainer .= '';
$jsonData = json_decode($response, true);
if ($jsonData && isset($jsonData['logList'])) {
$logList = $jsonData['logList'];
if (!empty($logList)) {
$totalLogs += count($logList);
$successfulPages++;
foreach ($logList as $log) {
$time = htmlspecialchars($log['time'] ?? 'Unknown time');
$type = htmlspecialchars($log['type'] ?? 'Unknown');
$content = htmlspecialchars($log['content'] ?? 'No content');
$logContainer .= '
[' . $time . ']
(' . $type . ')
' . $content . '
';
}
} else {
$logContainer .= '
No logs found on this page
';
}
} else {
$logContainer .= '
Failed to parse page ' . $i . ': Invalid JSON format
';
}
}
// Small delay between requests
usleep(500000); // 500ms delay
} catch (Exception $pageError) {
$logContainer .= '
Error fetching page ' . $i . ': ' . htmlspecialchars($pageError->getMessage()) . '
';
}
}
$logContainer .= '
';
$stats = '
✓ Completed. Fetched ' . $totalLogs . ' log entries from ' . $successfulPages . ' out of ' . $totalPages . ' pages.
';
$output = $logContainer . $stats;
$status = '
✓ Log fetch completed successfully';
} catch (Exception $e) {
$status = '
Error: ' . htmlspecialchars($e->getMessage()) . '';
$output = '
Fatal error: ' . htmlspecialchars($e->getMessage()) . '
';
}
?>
Reading credentials from password.txt...
Nonce: |
Token: