Added directory

main
Anthony 2025-06-17 23:45:45 +08:00
parent 3730308812
commit d60284482a
1 changed files with 201 additions and 34 deletions

View File

@ -4,37 +4,138 @@
// Function to execute system commands safely // Function to execute system commands safely
function run_command($command) { function run_command($command) {
$output = []; $output = [];git ad
$return_var = 0; $return_var = 0;
exec($command . ' 2>&1', $output, $return_var); exec($command . ' 2>&1', $output, $return_var);
return ['output' => $output, 'return_var' => $return_var]; return ['output' => $output, 'return_var' => $return_var];
} }
// Function to find LiteSpeed installation path
function find_lsws_path() {
$possible_paths = [
'/opt/litespeed', // Common Jelastic/Virtuozzo path
'/opt/lsws', // Alternative Jelastic path
'/usr/local/lsws', // Standard LiteSpeed path
'/usr/local/litespeed', // Alternative standard path
'/usr/lsws', // RPM-based installation
'/var/lsws', // Alternative location
'/home/litespeed' // User-based installation
];
foreach ($possible_paths as $path) {
if (is_dir($path)) {
return $path;
}
}
// Try to find via which command
$result = run_command('which lshttpd');
if ($result['return_var'] === 0 && !empty($result['output'][0])) {
$binary_path = trim($result['output'][0]);
// Remove /bin/lshttpd to get base path
return dirname(dirname($binary_path));
}
// Try to find binary in common locations
$binary_locations = [
'/opt/litespeed/bin/lshttpd',
'/opt/lsws/bin/lshttpd',
'/usr/bin/lshttpd',
'/usr/sbin/lshttpd',
'/usr/local/bin/lshttpd'
];
foreach ($binary_locations as $binary) {
if (file_exists($binary)) {
return dirname(dirname($binary));
}
}
return '/opt/litespeed'; // Jelastic/Virtuozzo default fallback
}
// Function to check if LiteSpeed is running // Function to check if LiteSpeed is running
function check_lsws_status() { function check_lsws_status() {
$result = run_command('systemctl is-active lsws'); $result = run_command('systemctl is-active lsws');
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
];
}
}
}
return [ return [
'running' => $result['return_var'] === 0, 'running' => $result['return_var'] === 0,
'status' => $result['output'][0] ?? 'unknown' 'status' => $result['output'][0] ?? 'unknown',
'service_name' => 'lsws'
]; ];
} }
// Function to get LiteSpeed version // Function to get LiteSpeed version
function get_lsws_version() { function get_lsws_version() {
$result = run_command('/usr/local/lsws/bin/lshttpd -v'); $lsws_path = find_lsws_path();
if ($result['return_var'] === 0 && !empty($result['output'])) { $binary_paths = [
foreach ($result['output'] as $line) { "$lsws_path/bin/lshttpd",
if (strpos($line, 'LiteSpeed') !== false) { "$lsws_path/bin/litespeed",
return trim($line); "/opt/litespeed/bin/lshttpd",
"/opt/lsws/bin/lshttpd",
"/usr/bin/lshttpd",
"/usr/sbin/lshttpd",
"/usr/local/bin/lshttpd"
];
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]);
} }
} }
} }
// Try alternative version detection commands
$version_commands = [
'lshttpd -v',
'litespeed -v',
'/opt/litespeed/bin/lshttpd -v',
'/opt/lsws/bin/lshttpd -v'
];
foreach ($version_commands as $cmd) {
$result = run_command($cmd);
if ($result['return_var'] === 0 && !empty($result['output'])) {
foreach ($result['output'] as $line) {
if (preg_match('/LiteSpeed.*?(\d+\.\d+(?:\.\d+)?)/i', $line, $matches)) {
return "LiteSpeed Web Server " . $matches[1];
}
}
return trim($result['output'][0]);
}
}
return 'unknown'; return 'unknown';
} }
// Function to check LiteSpeed processes // Function to check LiteSpeed processes
function get_lsws_processes() { function get_lsws_processes() {
$result = run_command('ps aux | grep lshttpd | grep -v grep'); $result = run_command('ps aux | grep -E "(lshttpd|litespeed)" | grep -v grep');
return [ return [
'count' => count($result['output']), 'count' => count($result['output']),
'processes' => $result['output'] 'processes' => $result['output']
@ -43,44 +144,99 @@ function get_lsws_processes() {
// Function to check LiteSpeed configuration // Function to check LiteSpeed configuration
function check_lsws_config() { function check_lsws_config() {
$config_file = '/usr/local/lsws/conf/httpd_config.conf'; $lsws_path = find_lsws_path();
if (file_exists($config_file)) { $config_paths = [
return [ "$lsws_path/conf/httpd_config.conf",
'config_exists' => true, "$lsws_path/conf/httpd.conf",
'config_readable' => is_readable($config_file), "$lsws_path/conf/lshttpd.conf",
'last_modified' => date('Y-m-d H:i:s', filemtime($config_file)) "/opt/litespeed/conf/httpd_config.conf",
]; "/opt/lsws/conf/httpd_config.conf",
"/etc/litespeed/httpd_config.conf",
"/etc/lsws/httpd_config.conf"
];
$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)
];
}
} }
return ['config_exists' => false];
return [
'configs_found' => count($found_configs),
'configs' => $found_configs,
'primary_config' => !empty($found_configs) ? $found_configs[0] : null
];
} }
// Function to check LiteSpeed logs // Function to check LiteSpeed logs
function check_lsws_logs() { function check_lsws_logs() {
$log_dir = '/usr/local/lsws/logs'; $lsws_path = find_lsws_path();
$error_log = $log_dir . '/error.log'; $log_dirs = [
$access_log = $log_dir . '/access.log'; "$lsws_path/logs",
"/opt/litespeed/logs",
"/opt/lsws/logs",
"/var/log/litespeed",
"/var/log/lsws",
"/usr/local/lsws/logs",
"/var/log/httpd", // Sometimes used in Jelastic
"/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]
];
}
}
return [ return [
'log_dir_exists' => is_dir($log_dir), 'log_dirs_found' => count($found_logs),
'error_log' => file_exists($error_log) ? [ 'logs' => $found_logs
'exists' => true,
'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,
'size' => filesize($access_log),
'last_modified' => date('Y-m-d H:i:s', filemtime($access_log))
] : ['exists' => false]
]; ];
} }
// Function to check listening ports // Function to check listening ports
function check_lsws_ports() { function check_lsws_ports() {
$result = run_command('netstat -tlnp | grep lshttpd'); $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)"');
}
$ports = []; $ports = [];
foreach ($result['output'] as $line) { foreach ($result['output'] as $line) {
if (preg_match('/:(\\d+)\\s/', $line, $matches)) { if (preg_match('/:(\d+)\s/', $line, $matches)) {
$ports[] = $matches[1]; $ports[] = $matches[1];
} }
} }
@ -89,11 +245,21 @@ function check_lsws_ports() {
// Function to get basic system info // Function to get basic system info
function get_system_info() { function get_system_info() {
$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)
);
return [ return [
'php_version' => phpversion(), 'php_version' => phpversion(),
'server_time' => date('Y-m-d H:i:s'), 'server_time' => date('Y-m-d H:i:s'),
'uptime' => trim(file_get_contents('/proc/uptime')), 'uptime_formatted' => $uptime_formatted,
'load_average' => sys_getloadavg() 'uptime_seconds' => $uptime_seconds,
'load_average' => sys_getloadavg(),
'installation_path' => find_lsws_path()
]; ];
} }
@ -114,6 +280,7 @@ echo json_encode([
'version' => $lsws_version, 'version' => $lsws_version,
'running' => $lsws_status['running'], 'running' => $lsws_status['running'],
'service_status' => $lsws_status['status'], 'service_status' => $lsws_status['status'],
'service_name' => $lsws_status['service_name'],
'process_count' => $lsws_processes['count'], 'process_count' => $lsws_processes['count'],
'listening_ports' => $lsws_ports 'listening_ports' => $lsws_ports
], ],