diff --git a/mbadmin.jps b/mbadmin.jps index e3dcf82..31a43bc 100644 --- a/mbadmin.jps +++ b/mbadmin.jps @@ -15,6 +15,18 @@ onInstall: - mkdir -p /home/litespeed/mbmanager - mkdir -p /home/litespeed/mbmanager/relay - mkdir -p /home/litespeed/mbmanager/ssl-manager + - mkdir -p /home/litespeed/mbmanager/scripts + # Download OPCache scripts with verification + - cd /home/litespeed/mbmanager/scripts + - curl -OL https://deploy-proxy.mightybox.io/tony/mb-admin/raw/branch/main/scripts/check_opcache.php + - if [ ! -f check_opcache.php ]; then echo "Failed to download check_opcache.php"; exit 1; fi + - curl -OL https://deploy-proxy.mightybox.io/tony/mb-admin/raw/branch/main/scripts/toggle_opcache.php + - if [ ! -f toggle_opcache.php ]; then echo "Failed to download toggle_opcache.php"; exit 1; fi + - curl -OL https://deploy-proxy.mightybox.io/tony/mb-admin/raw/branch/main/scripts/clear_opcache.php + - if [ ! -f clear_opcache.php ]; then echo "Failed to download clear_opcache.php"; exit 1; fi + - curl -OL https://deploy-proxy.mightybox.io/tony/mb-admin/raw/branch/main/scripts/update_opcache_settings.sh + - if [ ! -f update_opcache_settings.sh ]; then echo "Failed to download update_opcache_settings.sh"; exit 1; fi + - chmod +x *.php *.sh # Download WordPress Installer with path verification - cd /home/litespeed/mbmanager - curl -OL https://deploy-proxy.mightybox.io/tony/mb-admin/raw/branch/main/scripts/install-wordpress.sh @@ -24,8 +36,6 @@ onInstall: - if [ ! -f litespeed_fetch_settings.sh ]; then echo "Failed to download litespeed_fetch_settings.sh"; exit 1; fi - curl -OL https://deploy-proxy.mightybox.io/tony/mb-admin/raw/branch/main/scripts/litespeed_update_settings.sh - if [ ! -f litespeed_update_settings.sh ]; then echo "Failed to download litespeed_update_settings.sh"; exit 1; fi - - curl -OL https://deploy-proxy.mightybox.io/tony/mb-admin/raw/branch/main/scripts/update_opcache_settings.sh - - if [ ! -f update_opcache_settings.sh ]; then echo "Failed to download update_opcache_settings.sh"; exit 1; fi - chmod +x *.sh # Download relay scripts with verification - cd /home/litespeed/mbmanager/relay @@ -407,36 +417,34 @@ actions: - cmd[cp]: user: root commands: - - OP_INI='/usr/local/lsws/lsphp/etc/php.d/10-opcache.ini' - - sed -i 's/opcache.enable=0/opcache.enable=1/' $OP_INI - - restartNodes: - - nodeGroup: "cp" - reboot: true - - return: enableSuccess + - php /home/litespeed/mbmanager/scripts/toggle_opcache.php enable + - return: + type: info + message: "${response.out}" disable_opcache: - cmd[cp]: user: root commands: - - OP_INI='/usr/local/lsws/lsphp/etc/php.d/10-opcache.ini' - - sed -i 's/opcache.enable=1/opcache.enable=0/' $OP_INI - - restartNodes: - - nodeGroup: "cp" - reboot: true - - return: disableSuccess + - php /home/litespeed/mbmanager/scripts/toggle_opcache.php disable + - return: + type: info + message: "${response.out}" clear_opcache: - cmd[cp]: user: root commands: - - echo "" | php - - return: clearSuccess + - php /home/litespeed/mbmanager/scripts/clear_opcache.php + - return: + type: info + message: "${response.out}" opcache_status: - cmd[cp]: user: root commands: - - echo " opcache_get_status(false)['opcache_enabled']]); ?>" | php + - php /home/litespeed/mbmanager/scripts/check_opcache.php - return: type: info message: "${response.out}" @@ -445,7 +453,7 @@ actions: - cmd[cp]: user: root commands: - - echo " \$status['memory_usage'], 'opcache_statistics' => \$status['opcache_statistics']]); ?>" | php + - php /home/litespeed/mbmanager/scripts/check_opcache.php - return: type: info message: "${response.out}" @@ -454,58 +462,63 @@ actions: - cmd[cp]: user: root commands: - - echo " \$status['scripts'], 'opcache_statistics' => \$status['opcache_statistics'], 'jit' => \$status['jit']]); ?>" | php + - php /home/litespeed/mbmanager/scripts/check_opcache.php - return: type: info message: "${response.out}" + opcache_fetch_settings: - cmd[cp]: user: root - commands: - - echo " \$ini['opcache.memory_consumption'], 'interned_strings_buffer' => \$ini['opcache.interned_strings_buffer'], 'max_accelerated_files' => \$ini['opcache.max_accelerated_files'], 'revalidate_freq' => \$ini['opcache.revalidate_freq']]); ?>" | php + commands: + - php /home/litespeed/mbmanager/scripts/check_opcache.php - return: type: info message: "${response.out}" + opcache_update_settings: - - cmd[cp]: - user: root - commands: - - bash /home/litespeed/mbmanager/update_opcache_settings.sh "${settings.memory_consumption}" "${settings.interned_strings_buffer}" "${settings.max_accelerated_files}" "${settings.revalidate_freq}" - - systemctl restart lsws - - restartNodes: - - nodeGroup: "cp" - reboot: true - - return: - type: info - message: "OPCache settings updated successfully." + - cmd[cp]: + user: root + commands: + - bash /home/litespeed/mbmanager/scripts/update_opcache_settings.sh "${settings.memory_consumption}" "${settings.interned_strings_buffer}" "${settings.max_accelerated_files}" "${settings.revalidate_freq}" + - restartNodes: + - nodeGroup: "cp" + reboot: true + - return: + type: info + message: "OPCache settings updated successfully." litespeed_status: - cmd[cp]: - commands: - - wp --path=/var/www/webroot/ROOT litespeed-option get cache + user: root + commands: + - php /home/litespeed/mbmanager/scripts/check_litespeed.php - return: type: info - message: "${response.out}" + message: "${response.out}" litespeed_enable: - cmd[cp]: - commands: - - wp --path=/var/www/webroot/ROOT litespeed-option set cache 1 + user: root + commands: + - php /home/litespeed/mbmanager/scripts/manage_litespeed.php enable - return: type: info - message: "LiteSpeed Enabled." + message: "${response.out}" litespeed_disable: - cmd[cp]: - commands: - - wp --path=/var/www/webroot/ROOT litespeed-option set cache 0 + user: root + commands: + - php /home/litespeed/mbmanager/scripts/manage_litespeed.php disable - return: type: info - message: "LiteSpeed Disabled." + message: "${response.out}" litespeed_purgeall: - cmd[cp]: - commands: - - wp --path=/var/www/webroot/ROOT litespeed-purge all + user: root + commands: + - php /home/litespeed/mbmanager/scripts/manage_litespeed.php purge - return: type: info - message: "LiteSpeed Purged Cache." + message: "${response.out}" litespeed_ver: - cmd[cp]: commands: @@ -522,29 +535,33 @@ actions: message: "${response.out}" litespeed_set_ttlpub: - cmd[cp]: - commands: - - wp --path=/var/www/webroot/ROOT litespeed-option set cache-ttl_pub "${settings.sizettl}" + user: root + commands: + - php /home/litespeed/mbmanager/scripts/manage_litespeed.php set-ttl "${settings.sizettl}" - return: type: info message: "${response.out}" update_cache_exc: - cmd[cp]: - commands: - - wp --path=/var/www/webroot/ROOT litespeed-option set cache-exc "${settings.cache_exc_paths}" - - return: + user: root + commands: + - php /home/litespeed/mbmanager/scripts/manage_litespeed.php set-exclusions "${settings.cache_exc_paths}" + - return: type: info message: "${response.out}" get_litespeed_ttl_values: - cmd[cp]: - commands: - - bash /home/litespeed/mbmanager/litespeed_fetch_settings.sh + user: root + commands: + - php /home/litespeed/mbmanager/scripts/check_litespeed.php - return: type: info message: "${response.out}" litespeed_update_settings: - cmd[cp]: + user: root commands: - - bash /home/litespeed/mbmanager/litespeed_update_settings.sh "${settings.TTL_PUB}" "${settings.TTL_PRIV}" "${settings.TTL_FRONTPAGE}" "${settings.TTL_FEED}" + - bash /home/litespeed/mbmanager/scripts/litespeed_update_settings.sh "${settings.TTL_PUB}" "${settings.TTL_PRIV}" "${settings.TTL_FRONTPAGE}" "${settings.TTL_FEED}" - restartNodes: - nodeGroup: "cp" reboot: true diff --git a/scripts/check_litespeed.php b/scripts/check_litespeed.php new file mode 100644 index 0000000..efcaf22 --- /dev/null +++ b/scripts/check_litespeed.php @@ -0,0 +1,54 @@ + 'error', 'message' => 'WP-CLI not found']); + exit(1); +} + +// Function to run WP-CLI commands +function run_wp_command($command) { + $output = []; + $return_var = 0; + exec("/home/litespeed/bin/wp --path=/var/www/webroot/ROOT $command", $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'; + +// Get version +$version = run_wp_command('litespeed-option get _version'); + +// 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'); + +// Get cache exclusion paths +$cache_exc = run_wp_command('litespeed-option get cache-exc'); + +// Check if LiteSpeed server is running +$lsws_status = []; +exec('systemctl is-active lsws', $lsws_status, $lsws_return); + +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 diff --git a/scripts/check_opcache.php b/scripts/check_opcache.php new file mode 100644 index 0000000..09c745f --- /dev/null +++ b/scripts/check_opcache.php @@ -0,0 +1,31 @@ + 'not_installed']); + exit(1); +} + +if (!ini_get('opcache.enable')) { + echo json_encode(['status' => 'disabled']); + exit(1); +} + +$status = opcache_get_status(false); +if ($status === false) { + echo json_encode(['status' => 'error', 'message' => 'Cannot retrieve OPCache status']); + exit(1); +} + +echo json_encode([ + 'status' => 'enabled', + 'enabled' => $status['opcache_enabled'], + 'memory_usage' => [ + 'used' => round($status['memory_usage']['used_memory'] / 1024 / 1024, 2), + 'free' => round($status['memory_usage']['free_memory'] / 1024 / 1024, 2), + 'wasted' => round($status['memory_usage']['wasted_memory'] / 1024 / 1024, 2) + ], + 'statistics' => [ + 'hits' => $status['opcache_statistics']['hits'], + 'misses' => $status['opcache_statistics']['misses'], + 'hit_rate' => round($status['opcache_statistics']['opcache_hit_rate'], 2) + ] +]); \ No newline at end of file diff --git a/scripts/clear_opcache.php b/scripts/clear_opcache.php new file mode 100644 index 0000000..ac71c00 --- /dev/null +++ b/scripts/clear_opcache.php @@ -0,0 +1,18 @@ + 'error', 'message' => 'OPCache is not installed']); + exit(1); +} + +if (!ini_get('opcache.enable')) { + echo json_encode(['status' => 'error', 'message' => 'OPCache is disabled']); + exit(1); +} + +$result = opcache_reset(); +if ($result === false) { + echo json_encode(['status' => 'error', 'message' => 'Failed to reset OPCache']); + exit(1); +} + +echo json_encode(['status' => 'success', 'message' => 'OPCache cleared successfully']); \ No newline at end of file diff --git a/scripts/install-wordpress.sh b/scripts/install-wordpress.sh index c83cd67..9fdae3d 100644 --- a/scripts/install-wordpress.sh +++ b/scripts/install-wordpress.sh @@ -709,141 +709,87 @@ fi # --- Let's Encrypt SSL Certificate Setup --- info "Setting up Let's Encrypt SSL certificate..." -# First, validate that the domain is publicly accessible -info "Validating domain accessibility for SSL certificate..." - -# Check if domain resolves to this server -DOMAIN_VALIDATION_FAILED=false - -# Get server's public IP -SERVER_IP=$(curl -s ifconfig.me 2>/dev/null || curl -s ipinfo.io/ip 2>/dev/null || curl -s icanhazip.com 2>/dev/null) -if [[ -z "$SERVER_IP" ]]; then - warning "Could not determine server's public IP address." - DOMAIN_VALIDATION_FAILED=true +# Install certbot if not present +if ! command_exists certbot; then + info "Installing certbot for Let's Encrypt certificate management..." + if command_exists apt-get; then + # Debian/Ubuntu + sudo apt-get update -qq + sudo apt-get install -y certbot python3-certbot-apache || error_exit "Failed to install certbot via apt-get" + elif command_exists yum; then + # CentOS/RHEL 7 + sudo yum install -y epel-release + sudo yum install -y certbot python3-certbot-apache || error_exit "Failed to install certbot via yum" + elif command_exists dnf; then + # CentOS/RHEL 8+/Fedora + sudo dnf install -y certbot python3-certbot-apache || error_exit "Failed to install certbot via dnf" + else + warning "Package manager not detected. Please install certbot manually." + info "You can install certbot using: wget https://dl.eff.org/certbot-auto && chmod a+x certbot-auto" + fi else - info "Server public IP: $SERVER_IP" + success "Certbot is already installed." fi -# Check if domain resolves -if [[ "$DOMAIN_VALIDATION_FAILED" == "false" ]]; then - DOMAIN_IP=$(dig +short "$DOMAIN" 2>/dev/null | tail -n1) - if [[ -z "$DOMAIN_IP" ]]; then - warning "Domain '$DOMAIN' does not resolve to any IP address." - warning "Domain needs to be publicly accessible and point to this server for SSL to work." - DOMAIN_VALIDATION_FAILED=true - elif [[ "$DOMAIN_IP" != "$SERVER_IP" ]]; then - warning "Domain '$DOMAIN' resolves to $DOMAIN_IP, but server IP is $SERVER_IP." - warning "Domain must point to this server for Let's Encrypt validation to work." - DOMAIN_VALIDATION_FAILED=true +# Generate SSL certificate +if command_exists certbot; then + info "Generating Let's Encrypt SSL certificate for domain: $DOMAIN" + + # Create a simple verification file for webroot authentication + WEBROOT_PATH="$WP_ROOT" + ACME_CHALLENGE_DIR="$WEBROOT_PATH/.well-known/acme-challenge" + sudo mkdir -p "$ACME_CHALLENGE_DIR" + sudo chown -R "${WEB_USER}:${WEB_GROUP}" "$WEBROOT_PATH/.well-known" + sudo chmod -R 755 "$WEBROOT_PATH/.well-known" + + # Try webroot method first (non-interactive) + info "Attempting SSL certificate generation using webroot method..." + if sudo certbot certonly \ + --webroot \ + --webroot-path="$WEBROOT_PATH" \ + --email="$WP_ADMIN_EMAIL" \ + --agree-tos \ + --non-interactive \ + --domains="$DOMAIN" \ + --expand; then + + success "SSL certificate generated successfully for $DOMAIN" + + # Set up automatic renewal + info "Setting up automatic SSL certificate renewal..." + + # Create renewal cron job if it doesn't exist + CRON_JOB="0 12 * * * /usr/bin/certbot renew --quiet --post-hook \"systemctl reload lshttpd || systemctl reload apache2 || systemctl reload nginx\"" + if ! sudo crontab -l 2>/dev/null | grep -q "certbot renew"; then + (sudo crontab -l 2>/dev/null; echo "$CRON_JOB") | sudo crontab - + success "Automatic SSL renewal configured (daily check at 12:00 PM)" + else + info "SSL renewal cron job already exists." + fi + + # For LiteSpeed, we need to restart the service to pick up new certificates + info "Restarting LiteSpeed web server to apply SSL certificate..." + if sudo systemctl is-active lshttpd &>/dev/null; then + sudo systemctl restart lshttpd || warning "Failed to restart lshttpd service" + success "LiteSpeed restarted successfully" + elif sudo systemctl is-active litespeed &>/dev/null; then + sudo systemctl restart litespeed || warning "Failed to restart litespeed service" + success "LiteSpeed restarted successfully" + else + warning "LiteSpeed service not detected or not running. You may need to manually configure SSL in LiteSpeed admin panel." + info "SSL certificate location: /etc/letsencrypt/live/$DOMAIN/" + info "Certificate file: /etc/letsencrypt/live/$DOMAIN/fullchain.pem" + info "Private key file: /etc/letsencrypt/live/$DOMAIN/privkey.pem" + fi + else - success "Domain validation passed: $DOMAIN resolves to $SERVER_IP" + warning "SSL certificate generation failed. You can manually run:" + warning "sudo certbot --webroot -w '$WP_ROOT' -d '$DOMAIN' --email '$WP_ADMIN_EMAIL' --agree-tos" + info "Or configure SSL manually in your web server control panel." fi -fi - -# Check if domain is accessible via HTTP -if [[ "$DOMAIN_VALIDATION_FAILED" == "false" ]]; then - info "Testing HTTP accessibility for domain validation..." - HTTP_TEST=$(curl -s -o /dev/null -w "%{http_code}" "http://$DOMAIN" --connect-timeout 10 --max-time 30 2>/dev/null) - if [[ "$HTTP_TEST" != "200" && "$HTTP_TEST" != "301" && "$HTTP_TEST" != "302" ]]; then - warning "Domain '$DOMAIN' is not accessible via HTTP (got status: ${HTTP_TEST:-'timeout/error'})." - warning "Let's Encrypt needs HTTP access for domain validation." - DOMAIN_VALIDATION_FAILED=true - else - success "Domain is accessible via HTTP (status: $HTTP_TEST)" - fi -fi - -# Proceed with SSL only if domain validation passed -if [[ "$DOMAIN_VALIDATION_FAILED" == "true" ]]; then - warning "Domain validation failed. Skipping SSL certificate generation." - info "To get SSL later:" - info "1. Ensure your domain '$DOMAIN' points to this server ($SERVER_IP)" - info "2. Make sure port 80 is open and accessible from the internet" - info "3. Run: sudo certbot --webroot -w '$WP_ROOT' -d '$DOMAIN' --email '$WP_ADMIN_EMAIL' --agree-tos" - info "WordPress will work without SSL, but HTTPS is recommended for production sites." else - # Install certbot if not present - if ! command_exists certbot; then - info "Installing certbot for Let's Encrypt certificate management..." - if command_exists apt-get; then - # Debian/Ubuntu - sudo apt-get update -qq - sudo apt-get install -y certbot python3-certbot-apache || error_exit "Failed to install certbot via apt-get" - elif command_exists yum; then - # CentOS/RHEL 7 - sudo yum install -y epel-release - sudo yum install -y certbot python3-certbot-apache || error_exit "Failed to install certbot via yum" - elif command_exists dnf; then - # CentOS/RHEL 8+/Fedora - sudo dnf install -y certbot python3-certbot-apache || error_exit "Failed to install certbot via dnf" - else - warning "Package manager not detected. Please install certbot manually." - info "You can install certbot using: wget https://dl.eff.org/certbot-auto && chmod a+x certbot-auto" - fi - else - success "Certbot is already installed." - fi - - # Generate SSL certificate - if command_exists certbot; then - info "Generating Let's Encrypt SSL certificate for domain: $DOMAIN" - - # Create a simple verification file for webroot authentication - WEBROOT_PATH="$WP_ROOT" - ACME_CHALLENGE_DIR="$WEBROOT_PATH/.well-known/acme-challenge" - sudo mkdir -p "$ACME_CHALLENGE_DIR" - sudo chown -R "${WEB_USER}:${WEB_GROUP}" "$WEBROOT_PATH/.well-known" - sudo chmod -R 755 "$WEBROOT_PATH/.well-known" - - # Try webroot method first (non-interactive) - info "Attempting SSL certificate generation using webroot method..." - if sudo certbot certonly \ - --webroot \ - --webroot-path="$WEBROOT_PATH" \ - --email="$WP_ADMIN_EMAIL" \ - --agree-tos \ - --non-interactive \ - --domains="$DOMAIN" \ - --expand; then - - success "SSL certificate generated successfully for $DOMAIN" - - # Set up automatic renewal - info "Setting up automatic SSL certificate renewal..." - - # Create renewal cron job if it doesn't exist - CRON_JOB="0 12 * * * /usr/bin/certbot renew --quiet --post-hook \"systemctl reload lshttpd || systemctl reload apache2 || systemctl reload nginx\"" - if ! sudo crontab -l 2>/dev/null | grep -q "certbot renew"; then - (sudo crontab -l 2>/dev/null; echo "$CRON_JOB") | sudo crontab - - success "Automatic SSL renewal configured (daily check at 12:00 PM)" - else - info "SSL renewal cron job already exists." - fi - - # For LiteSpeed, we need to restart the service to pick up new certificates - info "Restarting LiteSpeed web server to apply SSL certificate..." - if sudo systemctl is-active lshttpd &>/dev/null; then - sudo systemctl restart lshttpd || warning "Failed to restart lshttpd service" - success "LiteSpeed restarted successfully" - elif sudo systemctl is-active litespeed &>/dev/null; then - sudo systemctl restart litespeed || warning "Failed to restart litespeed service" - success "LiteSpeed restarted successfully" - else - warning "LiteSpeed service not detected or not running. You may need to manually configure SSL in LiteSpeed admin panel." - info "SSL certificate location: /etc/letsencrypt/live/$DOMAIN/" - info "Certificate file: /etc/letsencrypt/live/$DOMAIN/fullchain.pem" - info "Private key file: /etc/letsencrypt/live/$DOMAIN/privkey.pem" - fi - - else - warning "SSL certificate generation failed. You can manually run:" - warning "sudo certbot --webroot -w '$WP_ROOT' -d '$DOMAIN' --email '$WP_ADMIN_EMAIL' --agree-tos" - info "Or configure SSL manually in your web server control panel." - fi - else - warning "Certbot not available. SSL certificate not generated." - info "Please install certbot manually and run: sudo certbot --webroot -w '$WP_ROOT' -d '$DOMAIN'" - fi + warning "Certbot not available. SSL certificate not generated." + info "Please install certbot manually and run: sudo certbot --webroot -w '$WP_ROOT' -d '$DOMAIN'" fi # --- Final Summary --- diff --git a/scripts/litespeed_update_settings.sh b/scripts/litespeed_update_settings.sh index 94a9646..61e4492 100644 --- a/scripts/litespeed_update_settings.sh +++ b/scripts/litespeed_update_settings.sh @@ -1,5 +1,16 @@ #!/bin/bash +# Check if WP-CLI is available +if [ ! -f "/home/litespeed/bin/wp" ]; then + echo "WP-CLI not found" + exit 1 +fi + +# Function to run WP-CLI commands +run_wp_command() { + /home/litespeed/bin/wp --path=/var/www/webroot/ROOT "$@" +} + # Check for correct number of arguments if [ "$#" -ne 4 ]; then echo "Usage: $0 TTL_PUB TTL_PRIV TTL_FRONTPAGE TTL_FEED" @@ -12,14 +23,14 @@ TTL_PRIV=$2 TTL_FRONTPAGE=$3 TTL_FEED=$4 -# CD into WordPress directory -cd /var/www/webroot/ROOT +# Update TTL values +run_wp_command litespeed-option set cache-ttl_pub "$TTL_PUB" +run_wp_command litespeed-option set cache-ttl_priv "$TTL_PRIV" +run_wp_command litespeed-option set cache-ttl_frontpage "$TTL_FRONTPAGE" +run_wp_command litespeed-option set cache-ttl_feed "$TTL_FEED" -# Run wp-cli -wp litespeed-option set cache-ttl_pub "$TTL_PUB" -wp litespeed-option set cache-ttl_priv "$TTL_PRIV" -wp litespeed-option set cache-ttl_frontpage "$TTL_FRONTPAGE" -wp litespeed-option set cache-ttl_feed "$TTL_FEED" +# Purge cache +run_wp_command litespeed-purge all -echo "Cache settings updated successfully." +echo "LiteSpeed cache settings updated successfully" diff --git a/scripts/manage_litespeed.php b/scripts/manage_litespeed.php new file mode 100644 index 0000000..9334e17 --- /dev/null +++ b/scripts/manage_litespeed.php @@ -0,0 +1,60 @@ + 'error', 'message' => 'WP-CLI not found']); + exit(1); +} + +// Function to run WP-CLI commands +function run_wp_command($command) { + $output = []; + $return_var = 0; + exec("/home/litespeed/bin/wp --path=/var/www/webroot/ROOT $command", $output, $return_var); + return ['output' => $output, 'return_var' => $return_var]; +} + +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']); + 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']); + break; + + case 'purge': + run_wp_command('litespeed-purge all'); + echo json_encode(['status' => 'success', 'message' => 'LiteSpeed cache purged']); + break; + + case 'set-ttl': + if (empty($value)) { + echo json_encode(['status' => 'error', 'message' => 'TTL value required']); + exit(1); + } + 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); + } + 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']); + exit(1); +} \ No newline at end of file diff --git a/scripts/ssl-manager/ssl_manager.sh b/scripts/ssl-manager/ssl_manager.sh index b701db5..81f106e 100644 --- a/scripts/ssl-manager/ssl_manager.sh +++ b/scripts/ssl-manager/ssl_manager.sh @@ -164,7 +164,7 @@ update_httpd_config() { local domain="$1" local ip="$2" local listener_name="HTTPS-$domain" - local vhost_name="Jelastic" + local vhost_name="Default" log "Checking if listener exists for '$listener_name'..." local existing diff --git a/scripts/toggle_opcache.php b/scripts/toggle_opcache.php new file mode 100644 index 0000000..a3f8754 --- /dev/null +++ b/scripts/toggle_opcache.php @@ -0,0 +1,40 @@ + 'error', 'message' => 'OPCache configuration file not found']); + exit(1); +} + +$ini_content = file_get_contents($ini_file); +if ($ini_content === false) { + echo json_encode(['status' => 'error', 'message' => 'Cannot read OPCache configuration file']); + exit(1); +} + +switch ($action) { + case 'enable': + $new_content = preg_replace('/opcache\.enable\s*=\s*0/', 'opcache.enable = 1', $ini_content); + break; + case 'disable': + $new_content = preg_replace('/opcache\.enable\s*=\s*1/', 'opcache.enable = 0', $ini_content); + break; + default: + echo json_encode(['status' => 'error', 'message' => 'Invalid action']); + exit(1); +} + +if (file_put_contents($ini_file, $new_content) === false) { + echo json_encode(['status' => 'error', 'message' => 'Cannot write to OPCache configuration file']); + exit(1); +} + +// Restart LiteSpeed to apply changes +exec('service lsws restart', $output, $return_var); +if ($return_var !== 0) { + echo json_encode(['status' => 'warning', 'message' => 'OPCache ' . $action . 'd but LiteSpeed restart failed']); + exit(1); +} + +echo json_encode(['status' => 'success', 'message' => 'OPCache ' . $action . 'd successfully']); \ No newline at end of file