Viewing file: server_diag.php (8.51 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
// Comprehensive server diagnostic script
error_reporting(E_ALL);
ini_set('display_errors', 1);
header('Content-Type: text/html; charset=utf-8');
echo '<!DOCTYPE html><html><head><title>Server Diagnostics</title><style>
body { font-family: monospace; margin: 20px; background: #f5f5f5; }
.pass { color: #28a745; font-weight: bold; }
.fail { color: #dc3545; font-weight: bold; }
.warn { color: #ffc107; font-weight: bold; }
.section { background: white; padding: 15px; margin: 10px 0; border-radius: 5px; border-left: 4px solid #007bff; }
pre { background: #f8f9fa; padding: 10px; border-radius: 3px; overflow-x: auto; }
</style></head><body>';
echo '<h1>🔍 Server Environment Diagnostics</h1>';
// Basic PHP Info
echo '<div class="section"><h2>📋 Basic Environment</h2>';
echo '<strong>PHP Version:</strong> ' . PHP_VERSION . '<br>';
echo '<strong>Server Software:</strong> ' . ($_SERVER['SERVER_SOFTWARE'] ?? 'Unknown') . '<br>';
echo '<strong>Document Root:</strong> ' . ($_SERVER['DOCUMENT_ROOT'] ?? 'Unknown') . '<br>';
echo '<strong>Script Path:</strong> ' . __FILE__ . '<br>';
echo '<strong>Current Directory:</strong> ' . __DIR__ . '<br>';
echo '<strong>HTTPS Status:</strong> ';
$isHttps = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ||
(!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') ||
(!empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443);
echo $isHttps ? '<span class="pass">✓ HTTPS Active</span>' : '<span class="warn">⚠ HTTP Only</span>';
echo '</div>';
// PHP Extensions Check
echo '<div class="section"><h2>🔧 Required PHP Extensions</h2>';
$extensions = [
'curl' => 'cURL (required for HTTP requests)',
'dom' => 'DOM/XML (required for HTML parsing)',
'json' => 'JSON (required for data handling)',
'openssl' => 'OpenSSL (required for encryption)',
'mbstring' => 'Multibyte String (recommended)'
];
foreach ($extensions as $ext => $desc) {
$loaded = extension_loaded($ext);
$status = $loaded ? '<span class="pass">✓ Loaded</span>' : '<span class="fail">✗ Missing</span>';
echo "<strong>$ext:</strong> $status - $desc<br>";
}
echo '</div>';
// Function Availability
echo '<div class="section"><h2>🎯 Critical Functions</h2>';
$functions = [
'curl_init' => 'cURL initialization',
'file_get_contents' => 'File reading',
'file_put_contents' => 'File writing',
'json_encode' => 'JSON encoding',
'json_decode' => 'JSON decoding',
'openssl_encrypt' => 'Data encryption',
'mkdir' => 'Directory creation'
];
foreach ($functions as $func => $desc) {
$exists = function_exists($func);
$status = $exists ? '<span class="pass">✓ Available</span>' : '<span class="fail">✗ Missing</span>';
echo "<strong>$func:</strong> $status - $desc<br>";
}
echo '</div>';
// Directory and File Permissions
echo '<div class="section"><h2>📁 File System Permissions</h2>';
$testDir = __DIR__ . '/storage';
echo "<strong>Storage Directory:</strong> $testDir<br>";
if (!is_dir($testDir)) {
$created = @mkdir($testDir, 0775, true);
echo '<strong>Create storage/:</strong> ' . ($created ? '<span class="pass">✓ Created</span>' : '<span class="fail">✗ Failed</span>') . '<br>';
} else {
echo '<strong>Storage exists:</strong> <span class="pass">✓ Yes</span><br>';
}
$testFile = $testDir . '/writetest.txt';
$writeTest = @file_put_contents($testFile, 'test-' . time());
echo '<strong>Write Test:</strong> ' . ($writeTest !== false ? '<span class="pass">✓ Writable</span>' : '<span class="fail">✗ Not Writable</span>') . '<br>';
if ($writeTest !== false) {
$readTest = @file_get_contents($testFile);
echo '<strong>Read Test:</strong> ' . ($readTest !== false ? '<span class="pass">✓ Readable</span>' : '<span class="fail">✗ Not Readable</span>') . '<br>';
@unlink($testFile);
}
// Check for required files
echo '<strong>Required Files:</strong><br>';
$requiredFiles = ['auth_token.php', 'cookie_utils.php', 'login_flow.php', 'index.html', 'setup_env.php'];
foreach ($requiredFiles as $file) {
$path = __DIR__ . '/' . $file;
$exists = is_file($path);
$status = $exists ? '<span class="pass">✓ Found</span>' : '<span class="fail">✗ Missing</span>';
echo " $file: $status<br>";
}
$configPath = __DIR__ . '/config.php';
$configExists = is_file($configPath);
echo " config.php: " . ($configExists ? '<span class="pass">✓ Found</span>' : '<span class="warn">⚠ Missing (run setup_env.php)</span>') . '<br>';
echo '</div>';
// Test cURL functionality
echo '<div class="section"><h2>🌐 Network Connectivity</h2>';
if (function_exists('curl_init')) {
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => 'https://httpbin.org/get',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 10,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_USERAGENT => 'Server-Diag/1.0'
]);
$result = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error($ch);
curl_close($ch);
if ($result && $httpCode == 200) {
echo '<strong>cURL Test:</strong> <span class="pass">✓ Working</span> (HTTP 200)<br>';
} else {
echo '<strong>cURL Test:</strong> <span class="fail">✗ Failed</span><br>';
echo "<strong>Error:</strong> $error<br>";
echo "<strong>HTTP Code:</strong> $httpCode<br>";
}
} else {
echo '<strong>cURL Test:</strong> <span class="fail">✗ cURL not available</span><br>';
}
echo '</div>';
// Memory and Limits
echo '<div class="section"><h2>⚙️ PHP Configuration</h2>';
echo '<strong>Memory Limit:</strong> ' . ini_get('memory_limit') . '<br>';
echo '<strong>Max Execution Time:</strong> ' . ini_get('max_execution_time') . 's<br>';
echo '<strong>Upload Max Size:</strong> ' . ini_get('upload_max_filesize') . '<br>';
echo '<strong>Post Max Size:</strong> ' . ini_get('post_max_size') . '<br>';
echo '<strong>Display Errors:</strong> ' . (ini_get('display_errors') ? 'On' : 'Off') . '<br>';
echo '<strong>Error Reporting:</strong> ' . error_reporting() . '<br>';
echo '</div>';
// Test login_flow.php syntax
echo '<div class="section"><h2>🔍 Login Flow Syntax Check</h2>';
$loginFile = __DIR__ . '/login_flow.php';
if (is_file($loginFile)) {
ob_start();
$syntaxCheck = exec("php -l \"$loginFile\" 2>&1", $output, $returnCode);
ob_end_clean();
if ($returnCode === 0) {
echo '<strong>Syntax Check:</strong> <span class="pass">✓ Valid PHP</span><br>';
} else {
echo '<strong>Syntax Check:</strong> <span class="fail">✗ Syntax Error</span><br>';
echo '<pre>' . htmlspecialchars(implode("\n", $output)) . '</pre>';
}
} else {
echo '<strong>Syntax Check:</strong> <span class="fail">✗ login_flow.php not found</span><br>';
}
echo '</div>';
// Environment Variables
echo '<div class="section"><h2>🔐 Environment & Config</h2>';
if ($configExists) {
$config = include $configPath;
echo '<strong>Config loaded:</strong> <span class="pass">✓ Yes</span><br>';
echo '<strong>ONE_TIME_SECRET:</strong> ' . (isset($config['ONE_TIME_SECRET']) ? '<span class="pass">✓ Set</span>' : '<span class="fail">✗ Missing</span>') . '<br>';
echo '<strong>COOKIE_ENCRYPTION_KEY:</strong> ' . (isset($config['COOKIE_ENCRYPTION_KEY']) ? '<span class="pass">✓ Set</span>' : '<span class="fail">✗ Missing</span>') . '<br>';
} else {
echo '<strong>Config Status:</strong> <span class="warn">⚠ config.php missing</span><br>';
echo '<strong>Action Required:</strong> Run setup_env.php with bot and chat parameters<br>';
}
echo '</div>';
echo '<div class="section"><h2>🚀 Next Steps</h2>';
echo '<ol>';
if (!$isHttps) {
echo '<li><strong>HTTPS:</strong> Ensure you\'re accessing via HTTPS URLs</li>';
}
foreach ($extensions as $ext => $desc) {
if (!extension_loaded($ext)) {
echo "<li><strong>Enable $ext:</strong> Contact your hosting provider to enable php-$ext</li>";
}
}
if (!$configExists) {
echo '<li><strong>Create config.php:</strong> Run setup_env.php?bot=YOUR_BOT_TOKEN&chat=YOUR_CHAT_ID</li>';
}
if ($writeTest === false) {
echo '<li><strong>Fix permissions:</strong> Make storage/ directory writable (chmod 775)</li>';
}
echo '<li><strong>Test login_flow.php:</strong> Visit the HTTPS URL and check for specific error messages</li>';
echo '</ol>';
echo '</div>';
echo '</body></html>';
?>
|