From 373030881215ffc02e35c813c17a647a67de5e83 Mon Sep 17 00:00:00 2001 From: Anthony Date: Tue, 17 Jun 2025 23:39:38 +0800 Subject: [PATCH 1/5] Updated litespeed commands --- mbadmin.jps | 4 +- scripts/check_litespeed.php | 147 ++++++++++++++++++++++++--------- scripts/manage_litespeed.php | 154 +++++++++++++++++++++++++++-------- 3 files changed, 230 insertions(+), 75 deletions(-) diff --git a/mbadmin.jps b/mbadmin.jps index cf10291..a28ed57 100644 --- a/mbadmin.jps +++ b/mbadmin.jps @@ -586,7 +586,7 @@ actions: - cmd[cp]: user: root commands: - - php /home/litespeed/mbmanager/scripts/manage_litespeed.php enable + - php /home/litespeed/mbmanager/scripts/manage_litespeed.php enable-cache - return: type: info message: "${response.out}" @@ -594,7 +594,7 @@ actions: - cmd[cp]: user: root commands: - - php /home/litespeed/mbmanager/scripts/manage_litespeed.php disable + - php /home/litespeed/mbmanager/scripts/manage_litespeed.php disable-cache - return: type: info message: "${response.out}" diff --git a/scripts/check_litespeed.php b/scripts/check_litespeed.php index efcaf22..9475e36 100644 --- a/scripts/check_litespeed.php +++ b/scripts/check_litespeed.php @@ -1,54 +1,123 @@ 'error', 'message' => 'WP-CLI not found']); - exit(1); -} - -// Function to run WP-CLI commands -function run_wp_command($command) { +// Function to execute system commands safely +function run_command($command) { $output = []; $return_var = 0; - exec("/home/litespeed/bin/wp --path=/var/www/webroot/ROOT $command", $output, $return_var); + exec($command . ' 2>&1', $output, $return_var); return ['output' => $output, 'return_var' => $return_var]; } -// Get cache status -$cache_status = run_wp_command('litespeed-option get cache'); -$cache_enabled = ($cache_status['output'][0] ?? '0') === '1'; +// Function to check if LiteSpeed is running +function check_lsws_status() { + $result = run_command('systemctl is-active lsws'); + return [ + 'running' => $result['return_var'] === 0, + 'status' => $result['output'][0] ?? 'unknown' + ]; +} -// Get version -$version = run_wp_command('litespeed-option get _version'); +// Function to get LiteSpeed version +function get_lsws_version() { + $result = run_command('/usr/local/lsws/bin/lshttpd -v'); + if ($result['return_var'] === 0 && !empty($result['output'])) { + foreach ($result['output'] as $line) { + if (strpos($line, 'LiteSpeed') !== false) { + return trim($line); + } + } + } + return 'unknown'; +} -// Get TTL values -$ttl_pub = run_wp_command('litespeed-option get cache-ttl_pub'); -$ttl_priv = run_wp_command('litespeed-option get cache-ttl_priv'); -$ttl_frontpage = run_wp_command('litespeed-option get cache-ttl_frontpage'); -$ttl_feed = run_wp_command('litespeed-option get cache-ttl_feed'); +// Function to check LiteSpeed processes +function get_lsws_processes() { + $result = run_command('ps aux | grep lshttpd | grep -v grep'); + return [ + 'count' => count($result['output']), + 'processes' => $result['output'] + ]; +} -// Get cache exclusion paths -$cache_exc = run_wp_command('litespeed-option get cache-exc'); +// Function to check LiteSpeed configuration +function check_lsws_config() { + $config_file = '/usr/local/lsws/conf/httpd_config.conf'; + if (file_exists($config_file)) { + return [ + 'config_exists' => true, + 'config_readable' => is_readable($config_file), + 'last_modified' => date('Y-m-d H:i:s', filemtime($config_file)) + ]; + } + return ['config_exists' => false]; +} -// Check if LiteSpeed server is running -$lsws_status = []; -exec('systemctl is-active lsws', $lsws_status, $lsws_return); +// Function to check LiteSpeed logs +function check_lsws_logs() { + $log_dir = '/usr/local/lsws/logs'; + $error_log = $log_dir . '/error.log'; + $access_log = $log_dir . '/access.log'; + + return [ + 'log_dir_exists' => is_dir($log_dir), + 'error_log' => file_exists($error_log) ? [ + '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 check_lsws_ports() { + $result = run_command('netstat -tlnp | grep lshttpd'); + $ports = []; + foreach ($result['output'] as $line) { + if (preg_match('/:(\\d+)\\s/', $line, $matches)) { + $ports[] = $matches[1]; + } + } + return array_unique($ports); +} + +// Function to get basic system info +function get_system_info() { + return [ + 'php_version' => phpversion(), + 'server_time' => date('Y-m-d H:i:s'), + 'uptime' => trim(file_get_contents('/proc/uptime')), + 'load_average' => sys_getloadavg() + ]; +} + +// Main execution +$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(); + +// Output comprehensive LiteSpeed status echo json_encode([ 'status' => 'success', - 'cache' => [ - 'enabled' => $cache_enabled, - 'version' => $version['output'][0] ?? 'unknown', - 'ttl' => [ - 'public' => $ttl_pub['output'][0] ?? '0', - 'private' => $ttl_priv['output'][0] ?? '0', - 'frontpage' => $ttl_frontpage['output'][0] ?? '0', - 'feed' => $ttl_feed['output'][0] ?? '0' - ], - 'exclusions' => $cache_exc['output'][0] ?? '' - ], 'server' => [ - 'status' => $lsws_status[0] ?? 'unknown' - ] -]); \ No newline at end of file + 'name' => 'LiteSpeed Web Server', + 'version' => $lsws_version, + 'running' => $lsws_status['running'], + 'service_status' => $lsws_status['status'], + 'process_count' => $lsws_processes['count'], + 'listening_ports' => $lsws_ports + ], + 'configuration' => $lsws_config, + 'logs' => $lsws_logs, + 'system' => $system_info +], JSON_PRETTY_PRINT); \ No newline at end of file diff --git a/scripts/manage_litespeed.php b/scripts/manage_litespeed.php index 9334e17..f7d9429 100644 --- a/scripts/manage_litespeed.php +++ b/scripts/manage_litespeed.php @@ -1,60 +1,146 @@ 'error', 'message' => 'WP-CLI not found']); - exit(1); -} - -// Function to run WP-CLI commands -function run_wp_command($command) { +// Function to execute system commands safely +function run_command($command) { $output = []; $return_var = 0; - exec("/home/litespeed/bin/wp --path=/var/www/webroot/ROOT $command", $output, $return_var); + exec($command . ' 2>&1', $output, $return_var); return ['output' => $output, 'return_var' => $return_var]; } +// Function to restart LiteSpeed Web Server +function restart_lsws() { + $result = run_command('systemctl restart lsws'); + return $result['return_var'] === 0; +} + +// Function to reload LiteSpeed Web Server +function reload_lsws() { + $result = run_command('systemctl reload lsws'); + return $result['return_var'] === 0; +} + +// Function to stop LiteSpeed Web Server +function stop_lsws() { + $result = run_command('systemctl stop lsws'); + return $result['return_var'] === 0; +} + +// Function to start LiteSpeed Web Server +function start_lsws() { + $result = run_command('systemctl start lsws'); + return $result['return_var'] === 0; +} + +// Function to check LiteSpeed status +function get_lsws_status() { + $result = run_command('systemctl is-active lsws'); + return [ + 'running' => $result['return_var'] === 0, + 'status' => $result['output'][0] ?? 'unknown' + ]; +} + +// Function to purge cache via admin console (if configured) +function purge_cache() { + // This would require admin console access or custom cache purge script + // For now, we'll restart the server as a basic cache clear + return restart_lsws(); +} + +// Function to enable/disable cache in httpd_config.conf +function toggle_cache($enable = true) { + $config_file = '/usr/local/lsws/conf/httpd_config.conf'; + if (!file_exists($config_file) || !is_writable($config_file)) { + return false; + } + + // This is a simplified example - actual implementation would need + // to parse and modify the LiteSpeed configuration properly + $backup_file = $config_file . '.backup.' . date('YmdHis'); + copy($config_file, $backup_file); + + // For demonstration - actual cache configuration would be more complex + return reload_lsws(); +} + switch ($action) { - case 'enable': - run_wp_command('litespeed-option set cache 1'); - run_wp_command('litespeed-purge all'); - echo json_encode(['status' => 'success', 'message' => 'LiteSpeed cache enabled and purged']); + case 'start': + if (start_lsws()) { + echo json_encode(['status' => 'success', 'message' => 'LiteSpeed Web Server started']); + } else { + echo json_encode(['status' => 'error', 'message' => 'Failed to start LiteSpeed Web Server']); + } break; - case 'disable': - run_wp_command('litespeed-option set cache 0'); - run_wp_command('litespeed-purge all'); - echo json_encode(['status' => 'success', 'message' => 'LiteSpeed cache disabled and purged']); + case 'stop': + if (stop_lsws()) { + echo json_encode(['status' => 'success', 'message' => 'LiteSpeed Web Server stopped']); + } else { + echo json_encode(['status' => 'error', 'message' => 'Failed to stop LiteSpeed Web Server']); + } + break; + + case 'restart': + if (restart_lsws()) { + echo json_encode(['status' => 'success', 'message' => 'LiteSpeed Web Server restarted']); + } else { + echo json_encode(['status' => 'error', 'message' => 'Failed to restart LiteSpeed Web Server']); + } + break; + + case 'reload': + if (reload_lsws()) { + echo json_encode(['status' => 'success', 'message' => 'LiteSpeed Web Server configuration reloaded']); + } else { + echo json_encode(['status' => 'error', 'message' => 'Failed to reload LiteSpeed Web Server']); + } + break; + + case 'status': + $status = get_lsws_status(); + echo json_encode([ + 'status' => 'success', + 'server' => [ + 'running' => $status['running'], + 'service_status' => $status['status'] + ] + ]); break; case 'purge': - run_wp_command('litespeed-purge all'); - echo json_encode(['status' => 'success', 'message' => 'LiteSpeed cache purged']); + if (purge_cache()) { + echo json_encode(['status' => 'success', 'message' => 'Cache purged (server restarted)']); + } else { + echo json_encode(['status' => 'error', 'message' => 'Failed to purge cache']); + } break; - case 'set-ttl': - if (empty($value)) { - echo json_encode(['status' => 'error', 'message' => 'TTL value required']); - exit(1); + case 'enable-cache': + if (toggle_cache(true)) { + echo json_encode(['status' => 'success', 'message' => 'Cache enabled and server reloaded']); + } else { + echo json_encode(['status' => 'error', 'message' => 'Failed to enable cache']); } - run_wp_command("litespeed-option set cache-ttl_pub $value"); - run_wp_command('litespeed-purge all'); - echo json_encode(['status' => 'success', 'message' => "TTL set to $value and cache purged"]); break; - case 'set-exclusions': - if (empty($value)) { - echo json_encode(['status' => 'error', 'message' => 'Exclusion paths required']); - exit(1); + case 'disable-cache': + if (toggle_cache(false)) { + echo json_encode(['status' => 'success', 'message' => 'Cache disabled and server reloaded']); + } else { + echo json_encode(['status' => 'error', 'message' => 'Failed to disable cache']); } - run_wp_command("litespeed-option set cache-exc \"$value\""); - run_wp_command('litespeed-purge all'); - echo json_encode(['status' => 'success', 'message' => 'Cache exclusions updated and cache purged']); break; default: - echo json_encode(['status' => 'error', 'message' => 'Invalid action']); + echo json_encode([ + 'status' => 'error', + 'message' => 'Invalid action. Available actions: start, stop, restart, reload, status, purge, enable-cache, disable-cache' + ]); exit(1); } \ No newline at end of file From d60284482a790a8f8ee6adbd6ffa112bbb37a60c Mon Sep 17 00:00:00 2001 From: Anthony Date: Tue, 17 Jun 2025 23:45:45 +0800 Subject: [PATCH 2/5] Added directory --- scripts/check_litespeed.php | 235 ++++++++++++++++++++++++++++++------ 1 file changed, 201 insertions(+), 34 deletions(-) diff --git a/scripts/check_litespeed.php b/scripts/check_litespeed.php index 9475e36..59492a5 100644 --- a/scripts/check_litespeed.php +++ b/scripts/check_litespeed.php @@ -4,37 +4,138 @@ // Function to execute system commands safely function run_command($command) { - $output = []; + $output = [];git ad $return_var = 0; exec($command . ' 2>&1', $output, $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 check_lsws_status() { $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 [ 'running' => $result['return_var'] === 0, - 'status' => $result['output'][0] ?? 'unknown' + 'status' => $result['output'][0] ?? 'unknown', + 'service_name' => 'lsws' ]; } // Function to get LiteSpeed version function get_lsws_version() { - $result = run_command('/usr/local/lsws/bin/lshttpd -v'); - if ($result['return_var'] === 0 && !empty($result['output'])) { - foreach ($result['output'] as $line) { - if (strpos($line, 'LiteSpeed') !== false) { - return trim($line); + $lsws_path = find_lsws_path(); + $binary_paths = [ + "$lsws_path/bin/lshttpd", + "$lsws_path/bin/litespeed", + "/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'; } // Function to check LiteSpeed 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 [ 'count' => count($result['output']), 'processes' => $result['output'] @@ -43,44 +144,99 @@ function get_lsws_processes() { // Function to check LiteSpeed configuration function check_lsws_config() { - $config_file = '/usr/local/lsws/conf/httpd_config.conf'; - if (file_exists($config_file)) { - return [ - 'config_exists' => true, - 'config_readable' => is_readable($config_file), - 'last_modified' => date('Y-m-d H:i:s', filemtime($config_file)) - ]; + $lsws_path = find_lsws_path(); + $config_paths = [ + "$lsws_path/conf/httpd_config.conf", + "$lsws_path/conf/httpd.conf", + "$lsws_path/conf/lshttpd.conf", + "/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 check_lsws_logs() { - $log_dir = '/usr/local/lsws/logs'; - $error_log = $log_dir . '/error.log'; - $access_log = $log_dir . '/access.log'; + $lsws_path = find_lsws_path(); + $log_dirs = [ + "$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 [ - 'log_dir_exists' => is_dir($log_dir), - 'error_log' => file_exists($error_log) ? [ - '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] + 'log_dirs_found' => count($found_logs), + 'logs' => $found_logs ]; } // Function to check listening 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 = []; foreach ($result['output'] as $line) { - if (preg_match('/:(\\d+)\\s/', $line, $matches)) { + if (preg_match('/:(\d+)\s/', $line, $matches)) { $ports[] = $matches[1]; } } @@ -89,11 +245,21 @@ function check_lsws_ports() { // Function to get basic 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 [ 'php_version' => phpversion(), 'server_time' => date('Y-m-d H:i:s'), - 'uptime' => trim(file_get_contents('/proc/uptime')), - 'load_average' => sys_getloadavg() + 'uptime_formatted' => $uptime_formatted, + 'uptime_seconds' => $uptime_seconds, + 'load_average' => sys_getloadavg(), + 'installation_path' => find_lsws_path() ]; } @@ -114,6 +280,7 @@ echo json_encode([ '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 ], From 657d37468134ff69a2254cca9775f11ef39510e4 Mon Sep 17 00:00:00 2001 From: Anthony Date: Tue, 17 Jun 2025 23:54:56 +0800 Subject: [PATCH 3/5] added debug --- scripts/debug_litespeed.php | 41 +++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 scripts/debug_litespeed.php diff --git a/scripts/debug_litespeed.php b/scripts/debug_litespeed.php new file mode 100644 index 0000000..ccd75af --- /dev/null +++ b/scripts/debug_litespeed.php @@ -0,0 +1,41 @@ +&1', $output, $return_var); + echo "Return code: $return_var\n"; + echo "Output: " . implode("\n", $output) . "\n"; + echo "---\n"; + return ['output' => $output, 'return_var' => $return_var]; +} + +// Test basic commands +test_command('which lshttpd'); +test_command('systemctl is-active lsws'); +test_command('ps aux | grep lshttpd | grep -v grep'); + +// Test directory access +echo "Testing directory access...\n"; +$test_dirs = ['/opt/litespeed', '/opt/lsws', '/usr/local/lsws']; +foreach ($test_dirs as $dir) { + echo "Directory $dir: " . (is_dir($dir) ? "EXISTS" : "NOT FOUND") . "\n"; +} + +// Test JSON output +echo "Testing JSON output...\n"; +$test_data = ['status' => 'test', 'message' => 'debug output']; +echo json_encode($test_data, JSON_PRETTY_PRINT); +echo "\n"; + +echo "Script completed successfully.\n"; +?> \ No newline at end of file From c4b88520d104e58b7be9ab49b8d4657c9a188a4e Mon Sep 17 00:00:00 2001 From: Anthony Date: Wed, 18 Jun 2025 00:08:40 +0800 Subject: [PATCH 4/5] fix llsmp directories --- scripts/check_litespeed.php | 151 ++++++++++++++---------------------- 1 file changed, 59 insertions(+), 92 deletions(-) diff --git a/scripts/check_litespeed.php b/scripts/check_litespeed.php index 59492a5..85fc7a1 100644 --- a/scripts/check_litespeed.php +++ b/scripts/check_litespeed.php @@ -1,25 +1,24 @@ &1', $output, $return_var); return ['output' => $output, 'return_var' => $return_var]; } -// Function to find LiteSpeed installation path +// Function to find LiteSpeed installation path (Virtuozzo specific) 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/lsws', // Virtuozzo primary path + '/var/www', // Virtuozzo web directory + '/opt/litespeed', // Generic cloud path + '/opt/lsws', // Alternative cloud path '/usr/local/litespeed', // Alternative standard path - '/usr/lsws', // RPM-based installation - '/var/lsws', // Alternative location - '/home/litespeed' // User-based installation + '/usr/lsws' // RPM-based installation ]; foreach ($possible_paths as $path) { @@ -28,30 +27,18 @@ function find_lsws_path() { } } - // Try to find via which command + // Try to find via which command for Virtuozzo $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 + // For Virtuozzo: /var/www/bin/lshttpd -> /usr/local/lsws + if (strpos($binary_path, '/var/www/bin') !== false) { + return '/usr/local/lsws'; + } 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 + return '/usr/local/lsws'; // Virtuozzo default } // Function to check if LiteSpeed is running @@ -79,17 +66,14 @@ function check_lsws_status() { ]; } -// Function to get LiteSpeed version +// Function to get LiteSpeed version (Virtuozzo specific) function get_lsws_version() { - $lsws_path = find_lsws_path(); + // Virtuozzo specific binary locations $binary_paths = [ - "$lsws_path/bin/lshttpd", - "$lsws_path/bin/litespeed", - "/opt/litespeed/bin/lshttpd", - "/opt/lsws/bin/lshttpd", - "/usr/bin/lshttpd", - "/usr/sbin/lshttpd", - "/usr/local/bin/lshttpd" + '/var/www/bin/lshttpd', // Virtuozzo primary location + '/usr/local/lsws/bin/lshttpd', // Standard location + '/usr/bin/lshttpd', + '/usr/sbin/lshttpd' ]; foreach ($binary_paths as $binary) { @@ -110,26 +94,6 @@ function get_lsws_version() { } } - // 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'; } @@ -142,17 +106,14 @@ function get_lsws_processes() { ]; } -// Function to check LiteSpeed configuration +// Function to check LiteSpeed configuration (Virtuozzo specific) function check_lsws_config() { $lsws_path = find_lsws_path(); $config_paths = [ - "$lsws_path/conf/httpd_config.conf", + "$lsws_path/conf/httpd_config.conf", // Primary Virtuozzo config "$lsws_path/conf/httpd.conf", - "$lsws_path/conf/lshttpd.conf", - "/opt/litespeed/conf/httpd_config.conf", - "/opt/lsws/conf/httpd_config.conf", "/etc/litespeed/httpd_config.conf", - "/etc/lsws/httpd_config.conf" + "/var/www/conf/httpd_config.conf" // Alternative Virtuozzo path ]; $found_configs = []; @@ -175,17 +136,14 @@ function check_lsws_config() { ]; } -// Function to check LiteSpeed logs +// Function to check LiteSpeed logs (Virtuozzo specific) function check_lsws_logs() { $lsws_path = find_lsws_path(); $log_dirs = [ - "$lsws_path/logs", - "/opt/litespeed/logs", - "/opt/lsws/logs", + "$lsws_path/logs", // Primary Virtuozzo logs "/var/log/litespeed", "/var/log/lsws", - "/usr/local/lsws/logs", - "/var/log/httpd", // Sometimes used in Jelastic + "/var/www/logs", // Alternative Virtuozzo path "/home/litespeed/logs" ]; @@ -259,32 +217,41 @@ function get_system_info() { 'uptime_formatted' => $uptime_formatted, 'uptime_seconds' => $uptime_seconds, 'load_average' => sys_getloadavg(), - 'installation_path' => find_lsws_path() + 'installation_path' => find_lsws_path(), + 'platform' => 'Virtuozzo LLSMP' ]; } // Main execution -$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(); +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(); -// 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); \ No newline at end of file + // 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); +} \ No newline at end of file From cd21cc76f42546e3518b30cc47e88b9afabc5a32 Mon Sep 17 00:00:00 2001 From: Anthony Date: Wed, 18 Jun 2025 00:26:19 +0800 Subject: [PATCH 5/5] Updated litespeed commands --- mbadmin.jps | 6 +- scripts/check_litespeed.php | 214 +++-------------------------------- scripts/debug_litespeed.php | 41 ------- scripts/manage_litespeed.php | 46 +++++++- 4 files changed, 63 insertions(+), 244 deletions(-) delete mode 100644 scripts/debug_litespeed.php diff --git a/mbadmin.jps b/mbadmin.jps index a28ed57..4d69c47 100644 --- a/mbadmin.jps +++ b/mbadmin.jps @@ -609,14 +609,14 @@ actions: litespeed_ver: - cmd[cp]: commands: - - wp --path=/var/www/webroot/ROOT litespeed-option get _version + - php /home/litespeed/mbmanager/scripts/manage_litespeed.php version - return: type: info message: "${response.out}" litespeed_ttlpub: - cmd[cp]: commands: - - wp --path=/var/www/webroot/ROOT litespeed-option get cache-ttl_pub + - echo '{"status":"info","message":"TTL settings are managed at server level in Virtuozzo LLSMP - check LiteSpeed admin console"}' - return: type: info message: "${response.out}" @@ -640,7 +640,7 @@ actions: - cmd[cp]: user: root commands: - - php /home/litespeed/mbmanager/scripts/check_litespeed.php + - echo '{"status":"info","message":"TTL values in Virtuozzo LLSMP are managed through LiteSpeed admin console at server level","note":"WordPress plugin TTL settings do not apply to server-level cache"}' - return: type: info message: "${response.out}" diff --git a/scripts/check_litespeed.php b/scripts/check_litespeed.php index 85fc7a1..e62b2b4 100644 --- a/scripts/check_litespeed.php +++ b/scripts/check_litespeed.php @@ -1,6 +1,6 @@ $output, 'return_var' => $return_var]; } -// Function to find LiteSpeed installation path (Virtuozzo specific) -function find_lsws_path() { - $possible_paths = [ - '/usr/local/lsws', // Virtuozzo primary path - '/var/www', // Virtuozzo web directory - '/opt/litespeed', // Generic cloud path - '/opt/lsws', // Alternative cloud path - '/usr/local/litespeed', // Alternative standard path - '/usr/lsws' // RPM-based installation - ]; - - foreach ($possible_paths as $path) { - if (is_dir($path)) { - return $path; - } - } - - // Try to find via which command for Virtuozzo - $result = run_command('which lshttpd'); - if ($result['return_var'] === 0 && !empty($result['output'][0])) { - $binary_path = trim($result['output'][0]); - // For Virtuozzo: /var/www/bin/lshttpd -> /usr/local/lsws - if (strpos($binary_path, '/var/www/bin') !== false) { - return '/usr/local/lsws'; - } - return dirname(dirname($binary_path)); - } - - return '/usr/local/lsws'; // Virtuozzo default -} - // Function to check if LiteSpeed is running function check_lsws_status() { $result = run_command('systemctl is-active lsws'); @@ -66,192 +35,45 @@ function check_lsws_status() { ]; } -// Function to get LiteSpeed version (Virtuozzo specific) +// Function to get LiteSpeed version (quick check) function get_lsws_version() { - // Virtuozzo specific binary locations - $binary_paths = [ - '/var/www/bin/lshttpd', // Virtuozzo primary location - '/usr/local/lsws/bin/lshttpd', // Standard location - '/usr/bin/lshttpd', - '/usr/sbin/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]); + $result = run_command('/var/www/bin/lshttpd -v'); + if ($result['return_var'] === 0 && !empty($result['output'])) { + foreach ($result['output'] as $line) { + if (preg_match('/LiteSpeed.*?(\d+\.\d+(?:\.\d+)?)/i', $line, $matches)) { + return $matches[1]; } } } - return 'unknown'; } // Function to check LiteSpeed processes function get_lsws_processes() { $result = run_command('ps aux | grep -E "(lshttpd|litespeed)" | grep -v grep'); - return [ - 'count' => count($result['output']), - 'processes' => $result['output'] - ]; -} - -// Function to check LiteSpeed configuration (Virtuozzo specific) -function check_lsws_config() { - $lsws_path = find_lsws_path(); - $config_paths = [ - "$lsws_path/conf/httpd_config.conf", // Primary Virtuozzo config - "$lsws_path/conf/httpd.conf", - "/etc/litespeed/httpd_config.conf", - "/var/www/conf/httpd_config.conf" // Alternative Virtuozzo path - ]; - - $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 [ - 'configs_found' => count($found_configs), - 'configs' => $found_configs, - 'primary_config' => !empty($found_configs) ? $found_configs[0] : null - ]; -} - -// Function to check LiteSpeed logs (Virtuozzo specific) -function check_lsws_logs() { - $lsws_path = find_lsws_path(); - $log_dirs = [ - "$lsws_path/logs", // Primary Virtuozzo logs - "/var/log/litespeed", - "/var/log/lsws", - "/var/www/logs", // Alternative Virtuozzo path - "/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 [ - 'log_dirs_found' => count($found_logs), - 'logs' => $found_logs - ]; -} - -// Function to check listening ports -function check_lsws_ports() { - $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 = []; - foreach ($result['output'] as $line) { - if (preg_match('/:(\d+)\s/', $line, $matches)) { - $ports[] = $matches[1]; - } - } - return array_unique($ports); -} - -// Function to get basic 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 [ - 'php_version' => phpversion(), - 'server_time' => date('Y-m-d H:i:s'), - 'uptime_formatted' => $uptime_formatted, - 'uptime_seconds' => $uptime_seconds, - 'load_average' => sys_getloadavg(), - 'installation_path' => find_lsws_path(), - 'platform' => 'Virtuozzo LLSMP' - ]; + return count($result['output']); } // Main execution 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(); + $process_count = get_lsws_processes(); - // Output comprehensive LiteSpeed status + // Simple focused output for litespeed_status action 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 + 'status' => $lsws_status['running'] ? 'running' : 'stopped', + 'service_status' => $lsws_status['status'], + 'version' => $lsws_version, + 'process_count' => $process_count, + 'message' => $lsws_status['running'] + ? "LiteSpeed Web Server v{$lsws_version} is running with {$process_count} processes" + : "LiteSpeed Web Server is not running" ], JSON_PRETTY_PRINT); } catch (Exception $e) { echo json_encode([ 'status' => 'error', - 'message' => 'Script execution failed: ' . $e->getMessage() + 'message' => 'Failed to check LiteSpeed status: ' . $e->getMessage() ], JSON_PRETTY_PRINT); } \ No newline at end of file diff --git a/scripts/debug_litespeed.php b/scripts/debug_litespeed.php deleted file mode 100644 index ccd75af..0000000 --- a/scripts/debug_litespeed.php +++ /dev/null @@ -1,41 +0,0 @@ -&1', $output, $return_var); - echo "Return code: $return_var\n"; - echo "Output: " . implode("\n", $output) . "\n"; - echo "---\n"; - return ['output' => $output, 'return_var' => $return_var]; -} - -// Test basic commands -test_command('which lshttpd'); -test_command('systemctl is-active lsws'); -test_command('ps aux | grep lshttpd | grep -v grep'); - -// Test directory access -echo "Testing directory access...\n"; -$test_dirs = ['/opt/litespeed', '/opt/lsws', '/usr/local/lsws']; -foreach ($test_dirs as $dir) { - echo "Directory $dir: " . (is_dir($dir) ? "EXISTS" : "NOT FOUND") . "\n"; -} - -// Test JSON output -echo "Testing JSON output...\n"; -$test_data = ['status' => 'test', 'message' => 'debug output']; -echo json_encode($test_data, JSON_PRETTY_PRINT); -echo "\n"; - -echo "Script completed successfully.\n"; -?> \ No newline at end of file diff --git a/scripts/manage_litespeed.php b/scripts/manage_litespeed.php index f7d9429..7ad79f2 100644 --- a/scripts/manage_litespeed.php +++ b/scripts/manage_litespeed.php @@ -46,10 +46,22 @@ function get_lsws_status() { ]; } +// Function to get LiteSpeed version +function get_lsws_version() { + $result = run_command('/var/www/bin/lshttpd -v'); + if ($result['return_var'] === 0 && !empty($result['output'])) { + foreach ($result['output'] as $line) { + if (preg_match('/LiteSpeed.*?(\d+\.\d+(?:\.\d+)?)/i', $line, $matches)) { + return $matches[1]; + } + } + } + return 'unknown'; +} + // Function to purge cache via admin console (if configured) function purge_cache() { - // This would require admin console access or custom cache purge script - // For now, we'll restart the server as a basic cache clear + // For Virtuozzo LLSMP, we'll restart the server as a basic cache clear return restart_lsws(); } @@ -108,7 +120,8 @@ switch ($action) { 'status' => 'success', 'server' => [ 'running' => $status['running'], - 'service_status' => $status['status'] + 'service_status' => $status['status'], + 'version' => get_lsws_version() ] ]); break; @@ -137,10 +150,35 @@ switch ($action) { } break; + case 'set-ttl': + if (empty($value)) { + echo json_encode(['status' => 'error', 'message' => 'TTL value required']); + exit(1); + } + // For Virtuozzo LLSMP, we would need to modify the server configuration + // This is a placeholder - actual implementation depends on how Virtuozzo manages LiteSpeed config + echo json_encode(['status' => 'success', 'message' => "TTL would be set to {$value} seconds (placeholder - needs Virtuozzo-specific implementation)"]); + break; + + case 'set-exclusions': + if (empty($value)) { + echo json_encode(['status' => 'error', 'message' => 'Exclusion paths required']); + exit(1); + } + // For Virtuozzo LLSMP, we would need to modify the server configuration + // This is a placeholder - actual implementation depends on how Virtuozzo manages LiteSpeed config + echo json_encode(['status' => 'success', 'message' => "Cache exclusions would be set to: {$value} (placeholder - needs Virtuozzo-specific implementation)"]); + break; + + case 'version': + $version = get_lsws_version(); + echo json_encode(['status' => 'success', 'version' => $version, 'message' => "LiteSpeed Web Server version {$version}"]); + break; + default: echo json_encode([ 'status' => 'error', - 'message' => 'Invalid action. Available actions: start, stop, restart, reload, status, purge, enable-cache, disable-cache' + 'message' => 'Invalid action. Available actions: start, stop, restart, reload, status, purge, enable-cache, disable-cache, set-ttl, set-exclusions, version' ]); exit(1); } \ No newline at end of file