2025-06-13 17:17:12 +00:00
|
|
|
<?php
|
2025-06-17 15:39:38 +00:00
|
|
|
// LiteSpeed Web Server Management for LLSMP
|
|
|
|
// No WordPress or WP-CLI required
|
|
|
|
|
2025-06-13 17:17:12 +00:00
|
|
|
$action = $argv[1] ?? 'status';
|
|
|
|
$value = $argv[2] ?? '';
|
|
|
|
|
2025-06-17 15:39:38 +00:00
|
|
|
// Function to execute system commands safely
|
|
|
|
function run_command($command) {
|
2025-06-13 17:17:12 +00:00
|
|
|
$output = [];
|
|
|
|
$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 15:39:38 +00:00
|
|
|
// 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();
|
|
|
|
}
|
|
|
|
|
2025-06-13 17:17:12 +00:00
|
|
|
switch ($action) {
|
2025-06-17 15:39:38 +00:00
|
|
|
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 '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']);
|
|
|
|
}
|
2025-06-13 17:17:12 +00:00
|
|
|
break;
|
|
|
|
|
2025-06-17 15:39:38 +00:00
|
|
|
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']
|
|
|
|
]
|
|
|
|
]);
|
2025-06-13 17:17:12 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'purge':
|
2025-06-17 15:39:38 +00:00
|
|
|
if (purge_cache()) {
|
|
|
|
echo json_encode(['status' => 'success', 'message' => 'Cache purged (server restarted)']);
|
|
|
|
} else {
|
|
|
|
echo json_encode(['status' => 'error', 'message' => 'Failed to purge cache']);
|
|
|
|
}
|
2025-06-13 17:17:12 +00:00
|
|
|
break;
|
|
|
|
|
2025-06-17 15:39:38 +00:00
|
|
|
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']);
|
2025-06-13 17:17:12 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2025-06-17 15:39:38 +00:00
|
|
|
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']);
|
2025-06-13 17:17:12 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2025-06-17 15:39:38 +00:00
|
|
|
echo json_encode([
|
|
|
|
'status' => 'error',
|
|
|
|
'message' => 'Invalid action. Available actions: start, stop, restart, reload, status, purge, enable-cache, disable-cache'
|
|
|
|
]);
|
2025-06-13 17:17:12 +00:00
|
|
|
exit(1);
|
|
|
|
}
|