403Webshell
Server IP : 35.80.110.71  /  Your IP : 216.73.216.221
Web Server : Apache/2.4.58 (Ubuntu)
System : Linux ip-172-31-21-44 6.17.0-1019-aws #19~24.04.1-Ubuntu SMP Tue Jun 23 18:53:06 UTC 2026 x86_64
User : ubuntu ( 1000)
PHP Version : 8.3.31
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /var/www/wp/shared/scripts/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/wp/shared/scripts/run-lighthouse-all.sh
#!/usr/bin/env bash
#
# Run Lighthouse against every demo + the hub itself.
# Writes JSON to /var/www/wp/shared/logs/lighthouse/<slug>/<timestamp>.json.
# Pushes the four category scores into the hub's Project post meta so the
# archive cards + single-project facts panel render fresh numbers.
#
# Cron entry suggested: 0 4 * * 0 (weekly Sunday 4am).
#

set -uo pipefail

LH_DIR=/var/www/wp/shared/logs/lighthouse
HUB_PATH=/var/www/wp/hub/public
mkdir -p "$LH_DIR"

TS=$(date +%Y%m%d-%H%M%S)
TS_ISO=$(date -u +%FT%TZ)

log() { echo "[$(date +%H:%M:%S)] $*"; }
ok()  { echo "  ✓ $*"; }
warn(){ echo "  ⚠ $*"; }

run_lighthouse() {
    local slug="$1"
    local url="$2"

    mkdir -p "$LH_DIR/$slug"
    local out="$LH_DIR/$slug/$TS.json"

    log "Lighthouse: $slug @ $url"

    if ! lighthouse "$url" \
        --quiet \
        --chrome-flags="--headless --no-sandbox" \
        --output=json \
        --output-path="$out" \
        --only-categories=performance,accessibility,best-practices,seo 2>/dev/null; then
        warn "lighthouse failed for $slug — skipping meta update"
        return 1
    fi

    # Parse the four category scores from the JSON.
    local perf a11y bp seo
    perf=$(python3 -c "import json; d=json.load(open('$out')); print(round(d['categories']['performance']['score']*100))" 2>/dev/null || echo 0)
    a11y=$(python3 -c "import json; d=json.load(open('$out')); print(round(d['categories']['accessibility']['score']*100))" 2>/dev/null || echo 0)
    bp=$(python3 -c "import json; d=json.load(open('$out')); print(round(d['categories']['best-practices']['score']*100))" 2>/dev/null || echo 0)
    seo=$(python3 -c "import json; d=json.load(open('$out')); print(round(d['categories']['seo']['score']*100))" 2>/dev/null || echo 0)

    ok "$slug  perf=$perf a11y=$a11y bp=$bp seo=$seo"

    # Find the matching Project post on the hub by post_name == slug.
    local post_id
    post_id=$(sudo -u www-data wp post list --post_type=project --name="$slug" --field=ID --path="$HUB_PATH" 2>/dev/null | head -1)

    if [ -z "$post_id" ]; then
        warn "no Project post for slug=$slug on hub — JSON saved but meta not updated"
        return 0
    fi

    sudo -u www-data wp post meta update "$post_id" lighthouse_perf "$perf"          --path="$HUB_PATH" >/dev/null
    sudo -u www-data wp post meta update "$post_id" lighthouse_a11y "$a11y"          --path="$HUB_PATH" >/dev/null
    sudo -u www-data wp post meta update "$post_id" lighthouse_bp   "$bp"            --path="$HUB_PATH" >/dev/null
    sudo -u www-data wp post meta update "$post_id" lighthouse_seo  "$seo"           --path="$HUB_PATH" >/dev/null
    sudo -u www-data wp post meta update "$post_id" lighthouse_last_run "$TS_ISO"    --path="$HUB_PATH" >/dev/null

    # Retention: keep the 12 most recent JSON files per demo
    ls -t "$LH_DIR/$slug"/*.json 2>/dev/null | tail -n +13 | xargs -r rm
}

# Iterate every demo under projects/, plus the hub itself
for demo_root in /var/www/wp/projects/*/; do
    slug=$(basename "$demo_root")
    secrets="/var/www/wp/shared/secrets/${slug}.env"
    [ ! -f "$secrets" ] && continue
    # shellcheck disable=SC1090
    domain=$(grep -m1 '^DOMAIN=' "$secrets" | cut -d= -f2)
    [ -z "$domain" ] && continue
    run_lighthouse "$slug" "https://${domain}/"
done

# Hub itself
run_lighthouse "hub" "https://wp.philiprehberger.com/"

# Flush hub cache so updated meta is reflected immediately
sudo -u www-data wp cache flush --path="$HUB_PATH" >/dev/null 2>&1 || true

log "Lighthouse run complete. JSON in $LH_DIR/"
echo "$TS_ISO lighthouse run complete" >> /var/www/wp/shared/logs/lighthouse-runs.log

Youez - 2016 - github.com/yon3zu
LinuXploit