2025-06-13 17:17:12 +00:00
|
|
|
<?php
|
2025-06-17 16:08:40 +00:00
|
|
|
// LiteSpeed Web Server Status Check for Virtuozzo LLSMP
|
2025-06-17 15:39:38 +00:00
|
|
|
// No WordPress or WP-CLI required
|
2025-06-13 17:17:12 +00:00
|
|
|
|
2025-06-17 15:39:38 +00:00
|
|
|
// Function to execute system commands safely
|
|
|
|
function run_command($command) {
|
2025-06-17 16:08:40 +00:00
|
|
|
$output = [];
|
2025-06-13 17:17:12 +00:00
|
|
|
$return_var = 0;
|
2025-06-17 15:39:38 +00:00
|
|
|
exec($command . ' 2>&1', $output, $return_var);
|
2025-06-13 17:17:12 +00:00
|
|
|
return ['output' => $output, 'return_var' => $return_var];
|
|
|
|
}
|
|
|
|
|
2025-06-17 16:08:40 +00:00
|
|
|
// Function to find LiteSpeed installation path (Virtuozzo specific)
|
2025-06-17 15:45:45 +00:00
|
|
|
function find_lsws_path() {
|
|
|
|
$possible_paths = [
|
2025-06-17 16:08:40 +00:00
|
|
|
'/usr/local/lsws', // Virtuozzo primary path
|
|
|
|
'/var/www', // Virtuozzo web directory
|
|
|
|
'/opt/litespeed', // Generic cloud path
|
|
|
|
'/opt/lsws', // Alternative cloud path
|
2025-06-17 15:45:45 +00:00
|
|
|
'/usr/local/litespeed', // Alternative standard path
|
2025-06-17 16:08:40 +00:00
|
|
|
'/usr/lsws' // RPM-based installation
|
2025-06-17 15:45:45 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
foreach ($possible_paths as $path) {
|
|
|
|
if (is_dir($path)) {
|
|
|
|
return $path;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-06-17 16:08:40 +00:00
|
|
|
// Try to find via which command for Virtuozzo
|
2025-06-17 15:45:45 +00:00
|
|
|
$result = run_command('which lshttpd');
|
|
|
|
if ($result['return_var'] === 0 && !empty($result['output'][0])) {
|
|
|
|
$binary_path = trim($result['output'][0]);
|
2025-06-17 16:08:40 +00:00
|
|
|
// For Virtuozzo: /var/www/bin/lshttpd -> /usr/local/lsws
|
|
|
|
if (strpos($binary_path, '/var/www/bin') !== false) {
|
|
|
|
return '/usr/local/lsws';
|
2025-06-17 15:45:45 +00:00
|
|
|
}
|
2025-06-17 16:08:40 +00:00
|
|
|
return dirname(dirname($binary_path));
|
2025-06-17 15:45:45 +00:00
|
|
|
}
|
|
|
|
|
2025-06-17 16:08:40 +00:00
|
|
|
return '/usr/local/lsws'; // Virtuozzo default
|
2025-06-17 15:45:45 +00:00
|
|
|
}
|
|
|
|
|
2025-06-17 15:39:38 +00:00
|
|
|
// Function to check if LiteSpeed is running
|
|
|
|
function check_lsws_status() {
|
|
|
|
$result = run_command('systemctl is-active lsws');
|
2025-06-17 15:45:45 +00:00
|
|
|
if ($result['return_var'] !== 0) {
|
|
|
|
// Try alternative service names
|
|
|
|
$alt_services = ['lshttpd', 'litespeed'];
|
|
|
|
foreach ($alt_services as $service) {
|
|
|
|
$alt_result = run_command("systemctl is-active $service");
|
|
|
|
if ($alt_result['return_var'] === 0) {
|
|
|
|
return [
|
|
|
|
'running' => true,
|
|
|
|
'status' => $alt_result['output'][0] ?? 'active',
|
|
|
|
'service_name' => $service
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-06-17 15:39:38 +00:00
|
|
|
return [
|
|
|
|
'running' => $result['return_var'] === 0,
|
2025-06-17 15:45:45 +00:00
|
|
|
'status' => $result['output'][0] ?? 'unknown',
|
|
|
|
'service_name' => 'lsws'
|
2025-06-17 15:39:38 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2025-06-17 16:08:40 +00:00
|
|
|
// Function to get LiteSpeed version (Virtuozzo specific)
|
2025-06-17 15:39:38 +00:00
|
|
|
function get_lsws_version() {
|
2025-06-17 16:08:40 +00:00
|
|
|
// Virtuozzo specific binary locations
|
2025-06-17 15:45:45 +00:00
|
|
|
$binary_paths = [
|
2025-06-17 16:08:40 +00:00
|
|
|
'/var/www/bin/lshttpd', // Virtuozzo primary location
|
|
|
|
'/usr/local/lsws/bin/lshttpd', // Standard location
|
|
|
|
'/usr/bin/lshttpd',
|
|
|
|
'/usr/sbin/lshttpd'
|
2025-06-17 15:45:45 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
foreach ($binary_paths as $binary) {
|
|
|
|
if (file_exists($binary)) {
|
|
|
|
$result = run_command("$binary -v");
|
|
|
|
if ($result['return_var'] === 0 && !empty($result['output'])) {
|
|
|
|
foreach ($result['output'] as $line) {
|
|
|
|
// Look for version patterns
|
|
|
|
if (preg_match('/LiteSpeed.*?(\d+\.\d+(?:\.\d+)?)/i', $line, $matches)) {
|
|
|
|
return "LiteSpeed Web Server " . $matches[1];
|
|
|
|
}
|
|
|
|
if (stripos($line, 'litespeed') !== false || stripos($line, 'version') !== false) {
|
|
|
|
return trim($line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return trim($result['output'][0]);
|
2025-06-17 15:39:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2025-06-17 15:45:45 +00:00
|
|
|
|
2025-06-17 15:39:38 +00:00
|
|
|
return 'unknown';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Function to check LiteSpeed processes
|
|
|
|
function get_lsws_processes() {
|
2025-06-17 15:45:45 +00:00
|
|
|
$result = run_command('ps aux | grep -E "(lshttpd|litespeed)" | grep -v grep');
|
2025-06-17 15:39:38 +00:00
|
|
|
return [
|
|
|
|
'count' => count($result['output']),
|
|
|
|
'processes' => $result['output']
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2025-06-17 16:08:40 +00:00
|
|
|
// Function to check LiteSpeed configuration (Virtuozzo specific)
|
2025-06-17 15:39:38 +00:00
|
|
|
function check_lsws_config() {
|
2025-06-17 15:45:45 +00:00
|
|
|
$lsws_path = find_lsws_path();
|
|
|
|
$config_paths = [
|
2025-06-17 16:08:40 +00:00
|
|
|
"$lsws_path/conf/httpd_config.conf", // Primary Virtuozzo config
|
2025-06-17 15:45:45 +00:00
|
|
|
"$lsws_path/conf/httpd.conf",
|
|
|
|
"/etc/litespeed/httpd_config.conf",
|
2025-06-17 16:08:40 +00:00
|
|
|
"/var/www/conf/httpd_config.conf" // Alternative Virtuozzo path
|
2025-06-17 15:45:45 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
$found_configs = [];
|
|
|
|
foreach ($config_paths as $config_file) {
|
|
|
|
if (file_exists($config_file)) {
|
|
|
|
$found_configs[] = [
|
|
|
|
'path' => $config_file,
|
|
|
|
'readable' => is_readable($config_file),
|
|
|
|
'writable' => is_writable($config_file),
|
|
|
|
'last_modified' => date('Y-m-d H:i:s', filemtime($config_file)),
|
|
|
|
'size' => filesize($config_file)
|
|
|
|
];
|
|
|
|
}
|
2025-06-17 15:39:38 +00:00
|
|
|
}
|
2025-06-17 15:45:45 +00:00
|
|
|
|
|
|
|
return [
|
|
|
|
'configs_found' => count($found_configs),
|
|
|
|
'configs' => $found_configs,
|
|
|
|
'primary_config' => !empty($found_configs) ? $found_configs[0] : null
|
|
|
|
];
|
2025-06-17 15:39:38 +00:00
|
|
|
}
|
2025-06-13 17:17:12 +00:00
|
|
|
|
2025-06-17 16:08:40 +00:00
|
|
|
// Function to check LiteSpeed logs (Virtuozzo specific)
|
2025-06-17 15:39:38 +00:00
|
|
|
function check_lsws_logs() {
|
2025-06-17 15:45:45 +00:00
|
|
|
$lsws_path = find_lsws_path();
|
|
|
|
$log_dirs = [
|
2025-06-17 16:08:40 +00:00
|
|
|
"$lsws_path/logs", // Primary Virtuozzo logs
|
2025-06-17 15:45:45 +00:00
|
|
|
"/var/log/litespeed",
|
|
|
|
"/var/log/lsws",
|
2025-06-17 16:08:40 +00:00
|
|
|
"/var/www/logs", // Alternative Virtuozzo path
|
2025-06-17 15:45:45 +00:00
|
|
|
"/home/litespeed/logs"
|
|
|
|
];
|
|
|
|
|
|
|
|
$found_logs = [];
|
|
|
|
foreach ($log_dirs as $log_dir) {
|
|
|
|
if (is_dir($log_dir)) {
|
|
|
|
$error_log = $log_dir . '/error.log';
|
|
|
|
$access_log = $log_dir . '/access.log';
|
|
|
|
$stderr_log = $log_dir . '/stderr.log';
|
|
|
|
|
|
|
|
$found_logs[] = [
|
|
|
|
'directory' => $log_dir,
|
|
|
|
'error_log' => file_exists($error_log) ? [
|
|
|
|
'exists' => true,
|
|
|
|
'path' => $error_log,
|
|
|
|
'size' => filesize($error_log),
|
|
|
|
'last_modified' => date('Y-m-d H:i:s', filemtime($error_log))
|
|
|
|
] : ['exists' => false],
|
|
|
|
'access_log' => file_exists($access_log) ? [
|
|
|
|
'exists' => true,
|
|
|
|
'path' => $access_log,
|
|
|
|
'size' => filesize($access_log),
|
|
|
|
'last_modified' => date('Y-m-d H:i:s', filemtime($access_log))
|
|
|
|
] : ['exists' => false],
|
|
|
|
'stderr_log' => file_exists($stderr_log) ? [
|
|
|
|
'exists' => true,
|
|
|
|
'path' => $stderr_log,
|
|
|
|
'size' => filesize($stderr_log),
|
|
|
|
'last_modified' => date('Y-m-d H:i:s', filemtime($stderr_log))
|
|
|
|
] : ['exists' => false]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
2025-06-17 15:39:38 +00:00
|
|
|
|
|
|
|
return [
|
2025-06-17 15:45:45 +00:00
|
|
|
'log_dirs_found' => count($found_logs),
|
|
|
|
'logs' => $found_logs
|
2025-06-17 15:39:38 +00:00
|
|
|
];
|
|
|
|
}
|
2025-06-13 17:17:12 +00:00
|
|
|
|
2025-06-17 15:39:38 +00:00
|
|
|
// Function to check listening ports
|
|
|
|
function check_lsws_ports() {
|
2025-06-17 15:45:45 +00:00
|
|
|
$result = run_command('netstat -tlnp 2>/dev/null | grep -E "(lshttpd|litespeed)"');
|
|
|
|
if (empty($result['output'])) {
|
|
|
|
// Try alternative command
|
|
|
|
$result = run_command('ss -tlnp | grep -E "(lshttpd|litespeed)"');
|
|
|
|
}
|
|
|
|
|
2025-06-17 15:39:38 +00:00
|
|
|
$ports = [];
|
|
|
|
foreach ($result['output'] as $line) {
|
2025-06-17 15:45:45 +00:00
|
|
|
if (preg_match('/:(\d+)\s/', $line, $matches)) {
|
2025-06-17 15:39:38 +00:00
|
|
|
$ports[] = $matches[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return array_unique($ports);
|
|
|
|
}
|
2025-06-13 17:17:12 +00:00
|
|
|
|
2025-06-17 15:39:38 +00:00
|
|
|
// Function to get basic system info
|
|
|
|
function get_system_info() {
|
2025-06-17 15:45:45 +00:00
|
|
|
$uptime_raw = trim(file_get_contents('/proc/uptime'));
|
|
|
|
$uptime_seconds = (float)explode(' ', $uptime_raw)[0];
|
|
|
|
$uptime_formatted = sprintf('%d days, %d hours, %d minutes',
|
|
|
|
floor($uptime_seconds / 86400),
|
|
|
|
floor(($uptime_seconds % 86400) / 3600),
|
|
|
|
floor(($uptime_seconds % 3600) / 60)
|
|
|
|
);
|
|
|
|
|
2025-06-17 15:39:38 +00:00
|
|
|
return [
|
|
|
|
'php_version' => phpversion(),
|
|
|
|
'server_time' => date('Y-m-d H:i:s'),
|
2025-06-17 15:45:45 +00:00
|
|
|
'uptime_formatted' => $uptime_formatted,
|
|
|
|
'uptime_seconds' => $uptime_seconds,
|
|
|
|
'load_average' => sys_getloadavg(),
|
2025-06-17 16:08:40 +00:00
|
|
|
'installation_path' => find_lsws_path(),
|
|
|
|
'platform' => 'Virtuozzo LLSMP'
|
2025-06-17 15:39:38 +00:00
|
|
|
];
|
|
|
|
}
|
2025-06-13 17:17:12 +00:00
|
|
|
|
2025-06-17 15:39:38 +00:00
|
|
|
// Main execution
|
2025-06-17 16:08:40 +00:00
|
|
|
try {
|
|
|
|
$lsws_status = check_lsws_status();
|
|
|
|
$lsws_version = get_lsws_version();
|
|
|
|
$lsws_processes = get_lsws_processes();
|
|
|
|
$lsws_config = check_lsws_config();
|
|
|
|
$lsws_logs = check_lsws_logs();
|
|
|
|
$lsws_ports = check_lsws_ports();
|
|
|
|
$system_info = get_system_info();
|
2025-06-13 17:17:12 +00:00
|
|
|
|
2025-06-17 16:08:40 +00:00
|
|
|
// Output comprehensive LiteSpeed status
|
|
|
|
echo json_encode([
|
|
|
|
'status' => 'success',
|
|
|
|
'server' => [
|
|
|
|
'name' => 'LiteSpeed Web Server',
|
|
|
|
'version' => $lsws_version,
|
|
|
|
'running' => $lsws_status['running'],
|
|
|
|
'service_status' => $lsws_status['status'],
|
|
|
|
'service_name' => $lsws_status['service_name'],
|
|
|
|
'process_count' => $lsws_processes['count'],
|
|
|
|
'listening_ports' => $lsws_ports
|
|
|
|
],
|
|
|
|
'configuration' => $lsws_config,
|
|
|
|
'logs' => $lsws_logs,
|
|
|
|
'system' => $system_info
|
|
|
|
], JSON_PRETTY_PRINT);
|
|
|
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
echo json_encode([
|
|
|
|
'status' => 'error',
|
|
|
|
'message' => 'Script execution failed: ' . $e->getMessage()
|
|
|
|
], JSON_PRETTY_PRINT);
|
|
|
|
}
|