#!/bin/sh
# GK2 Hub Landing Page Generator
# Reads from HAProxy, Streamlit, and MetaBlogizer configs
# Copyright (C) 2025 CyberMind.fr
OUTPUT="/www/gk2-hub/index.html"
# Icons mapping
get_icon() {
case "$1" in
evolution|secubox_evolution) echo "๐" ;;
control|secubox_control) echo "๐๏ธ" ;;
fabricator|fabric) echo "๐ญ" ;;
yijing*|yling|hermes) echo "โฏ๏ธ" ;;
play) echo "๐ฎ" ;;
console|secubox_console) echo "๐ฅ๏ธ" ;;
glances) echo "๐" ;;
lldh) echo "๐" ;;
wanted|want) echo "๐ฏ" ;;
gandalf) echo "๐ง" ;;
cyberzine) echo "๐พ" ;;
devel|dev) echo "๐จโ๐ป" ;;
c3box) echo "๐ฆ" ;;
gk2) echo "โจ" ;;
secubox) echo "๐ก๏ธ" ;;
press|presse) echo "๐ฐ" ;;
oracle) echo "๐ฎ" ;;
bazi*|pix|bweep|bweek|BASIC) echo "๐" ;;
slides|sliders) echo "๐๏ธ" ;;
comic) echo "๐" ;;
eval) echo "๐งช" ;;
sappix) echo "๐ง" ;;
ftvm) echo "๐บ" ;;
cineposter*|cpf) echo "๐ฌ" ;;
wuyun) echo "๐ฌ๏ธ" ;;
hello) echo "๐" ;;
tube|peertube) echo "๐บ" ;;
social|gotosocial) echo "๐" ;;
wazuh) echo "๐" ;;
webmail|mail) echo "๐ง" ;;
media|jellyfin) echo "๐ฌ" ;;
pdf|papyrus) echo "๐" ;;
geo|gondwana) echo "๐" ;;
clock) echo "๐" ;;
money) echo "๐ฐ" ;;
osint) echo "๐" ;;
flash) echo "โก" ;;
client) echo "๐ค" ;;
mvox) echo "๐ค" ;;
*) echo "๐" ;;
esac
}
# Generate HTML
cat > "$OUTPUT" << 'HTML_HEAD'
GKยฒ Hub - SecuBox Services
HTML_HEAD
# Streamlit Apps Section
echo '
' >> "$OUTPUT"
echo '
๐ Streamlit Apps
' >> "$OUTPUT"
echo '
' >> "$OUTPUT"
# Get all streamlit instances from UCI config
grep -E "^config instance" /etc/config/streamlit 2>/dev/null | while read line; do
section=$(echo "$line" | sed "s/config instance '\([^']*\)'/\1/")
[ -z "$section" ] && continue
# Read instance config
app=$(uci -q get streamlit.$section.app)
port=$(uci -q get streamlit.$section.port)
enabled=$(uci -q get streamlit.$section.enabled)
domain=$(uci -q get streamlit.$section.domain)
[ "$enabled" != "1" ] && continue
[ -z "$app" ] && continue
[ -z "$port" ] && continue
# Check if there's a HAProxy vhost for this app
if [ -n "$domain" ]; then
url="https://$domain"
else
# Check HAProxy for matching vhost
vhost_domain=$(uci show haproxy 2>/dev/null | grep -E "\.domain=.*${section}.*gk2\.secubox\.in" | head -1 | sed "s/.*domain='\([^']*\)'/\1/")
if [ -n "$vhost_domain" ]; then
url="https://$vhost_domain"
else
url="http://192.168.255.1:$port"
fi
fi
icon=$(get_icon "$section")
display_name="$section"
cat >> "$OUTPUT" << EOF
$icon
$display_name
$app :$port
EOF
done
echo '
' >> "$OUTPUT"
echo '
' >> "$OUTPUT"
# MetaBlogizer Section
echo '
' >> "$OUTPUT"
echo '
๐ฐ MetaBlogizer Webs
' >> "$OUTPUT"
echo '
' >> "$OUTPUT"
for site in $(ls -1 /srv/metablogizer/sites/ 2>/dev/null | sort); do
[ -f "/srv/metablogizer/sites/$site/index.html" ] || continue
icon=$(get_icon "$site")
# Try to get domain from UCI
section="site_$(echo "$site" | tr '-' '_')"
domain=$(uci -q get metablogizer.$section.domain)
# Default URL mapping - try gk2.secubox.in subdomain, fallback to maegia.tv
if [ -z "$domain" ]; then
# Check if HAProxy vhost exists for gk2.secubox.in
vhost_domain=$(uci show haproxy 2>/dev/null | grep -E "\.domain='${site}\.gk2\.secubox\.in'" | head -1 | sed "s/.*domain='\([^']*\)'/\1/")
if [ -n "$vhost_domain" ]; then
url="https://$vhost_domain"
else
# Fallback to maegia.tv for some known sites
case "$site" in
gandalf) url="https://gandalf.maegia.tv" ;;
cyberzine) url="https://cyberzine.maegia.tv" ;;
devel) url="https://devel.maegia.tv" ;;
c3box) url="https://c3box.maegia.tv" ;;
gk2) url="https://gk2.maegia.tv" ;;
*) url="https://${site}.gk2.secubox.in" ;;
esac
fi
else
url="https://$domain"
fi
cat >> "$OUTPUT" << EOF
$icon
$site
EOF
done
echo '
' >> "$OUTPUT"
echo '
' >> "$OUTPUT"
# Infrastructure Section
echo '
' >> "$OUTPUT"
echo '
๐ง Infrastructure
' >> "$OUTPUT"
echo '
' >> "$OUTPUT"
echo '
' >> "$OUTPUT"
# Footer
cat >> "$OUTPUT" << EOF
EOF
echo "Generated $OUTPUT"