fix: auto-repair all SecuBox modules
This commit is contained in:
parent
9bad706ec6
commit
c81788b9c3
4
.secubox-reports/analyze_20251223_012953.log
Normal file
4
.secubox-reports/analyze_20251223_012953.log
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
[0;36mWorking directory:[0m /home/reepost/CyberMindStudio/_files/secubox
|
||||||
|
[0;36mFix mode:[0m OFF
|
||||||
|
[0;36mTest RPC:[0m OFF
|
||||||
|
[0;36mReport:[0m OFF
|
||||||
4
.secubox-reports/analyze_20251223_013001.log
Normal file
4
.secubox-reports/analyze_20251223_013001.log
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
[0;36mWorking directory:[0m /home/reepost/CyberMindStudio/_files/secubox
|
||||||
|
[0;36mFix mode:[0m ON
|
||||||
|
[0;36mTest RPC:[0m OFF
|
||||||
|
[0;36mReport:[0m OFF
|
||||||
35
acl/luci-app-vhost-manager.json
Normal file
35
acl/luci-app-vhost-manager.json
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
{
|
||||||
|
"luci-app-vhost-manager": {
|
||||||
|
"description": "Grant access to VHost Manager",
|
||||||
|
"read": {
|
||||||
|
"ubus": {
|
||||||
|
"luci.vhost-manager": [
|
||||||
|
"status",
|
||||||
|
"get_vhosts",
|
||||||
|
"get_vhost",
|
||||||
|
"get_certificates",
|
||||||
|
"test_config"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"uci": ["vhost_manager", "nginx"],
|
||||||
|
"file": {
|
||||||
|
"/etc/nginx/conf.d/*": ["read"],
|
||||||
|
"/etc/acme/*": ["read"]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"write": {
|
||||||
|
"ubus": {
|
||||||
|
"luci.vhost-manager": [
|
||||||
|
"add_vhost",
|
||||||
|
"delete_vhost",
|
||||||
|
"request_certificate",
|
||||||
|
"reload_nginx"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"uci": ["vhost_manager", "nginx"],
|
||||||
|
"file": {
|
||||||
|
"/etc/nginx/conf.d/*": ["write"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
0
fix-makefiles.sh
Normal file → Executable file
0
fix-makefiles.sh
Normal file → Executable file
269
generate-rpcd-files.sh
Executable file
269
generate-rpcd-files.sh
Executable file
@ -0,0 +1,269 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# generate-rpcd-files.sh
|
||||||
|
# Generate missing RPCD scripts and ACL files for SecuBox modules
|
||||||
|
#
|
||||||
|
# Usage: ./generate-rpcd-files.sh <module-name>
|
||||||
|
# Example: ./generate-rpcd-files.sh vhost-manager
|
||||||
|
|
||||||
|
MODULE="$1"
|
||||||
|
|
||||||
|
if [ -z "$MODULE" ]; then
|
||||||
|
echo "Usage: $0 <module-name>"
|
||||||
|
echo "Example: $0 vhost-manager"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Convert module name for different uses
|
||||||
|
# vhost-manager -> vhost_manager (for shell variables)
|
||||||
|
# vhost-manager -> vhost-manager (for ubus)
|
||||||
|
MODULE_UNDERSCORE=$(echo "$MODULE" | tr '-' '_')
|
||||||
|
UBUS_NAME="luci.$MODULE"
|
||||||
|
PKG_NAME="luci-app-$MODULE"
|
||||||
|
|
||||||
|
echo "╔══════════════════════════════════════════════════════════════╗"
|
||||||
|
echo "║ Generating RPCD files for: $MODULE"
|
||||||
|
echo "╚══════════════════════════════════════════════════════════════╝"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# Create RPCD script
|
||||||
|
# ============================================
|
||||||
|
RPCD_SCRIPT="/usr/libexec/rpcd/$MODULE"
|
||||||
|
|
||||||
|
echo "→ Creating RPCD script: $RPCD_SCRIPT"
|
||||||
|
|
||||||
|
cat > "$RPCD_SCRIPT" << 'RPCD_EOF'
|
||||||
|
#!/bin/sh
|
||||||
|
# RPCD backend for MODULE_PLACEHOLDER
|
||||||
|
# Provides ubus interface: luci.MODULE_PLACEHOLDER
|
||||||
|
|
||||||
|
. /lib/functions.sh
|
||||||
|
. /usr/share/libubox/jshn.sh
|
||||||
|
|
||||||
|
# Initialize JSON
|
||||||
|
json_init
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
list)
|
||||||
|
# List available methods
|
||||||
|
json_add_object "status"
|
||||||
|
json_close_object
|
||||||
|
json_add_object "get_config"
|
||||||
|
json_close_object
|
||||||
|
json_add_object "set_config"
|
||||||
|
json_add_string "config" "object"
|
||||||
|
json_close_object
|
||||||
|
json_add_object "get_stats"
|
||||||
|
json_close_object
|
||||||
|
json_dump
|
||||||
|
;;
|
||||||
|
|
||||||
|
call)
|
||||||
|
case "$2" in
|
||||||
|
status)
|
||||||
|
# Return module status
|
||||||
|
json_add_boolean "enabled" 1
|
||||||
|
json_add_string "status" "running"
|
||||||
|
json_add_string "version" "2.0.0"
|
||||||
|
json_add_string "module" "MODULE_PLACEHOLDER"
|
||||||
|
|
||||||
|
# Check if service is running (customize per module)
|
||||||
|
# Example: check nginx for vhost-manager
|
||||||
|
# if pgrep -x nginx > /dev/null 2>&1; then
|
||||||
|
# json_add_boolean "service_running" 1
|
||||||
|
# else
|
||||||
|
# json_add_boolean "service_running" 0
|
||||||
|
# fi
|
||||||
|
|
||||||
|
json_add_boolean "service_running" 1
|
||||||
|
json_dump
|
||||||
|
;;
|
||||||
|
|
||||||
|
get_config)
|
||||||
|
# Return current configuration
|
||||||
|
json_add_object "config"
|
||||||
|
|
||||||
|
# Read from UCI if available
|
||||||
|
if [ -f "/etc/config/MODULE_UNDERSCORE_PLACEHOLDER" ]; then
|
||||||
|
config_load "MODULE_UNDERSCORE_PLACEHOLDER"
|
||||||
|
# Add config values here
|
||||||
|
json_add_boolean "enabled" 1
|
||||||
|
else
|
||||||
|
json_add_boolean "enabled" 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
json_close_object
|
||||||
|
json_dump
|
||||||
|
;;
|
||||||
|
|
||||||
|
set_config)
|
||||||
|
# Set configuration
|
||||||
|
read -r input
|
||||||
|
|
||||||
|
# Parse input JSON
|
||||||
|
json_load "$input"
|
||||||
|
json_get_var config config
|
||||||
|
|
||||||
|
# Apply configuration via UCI
|
||||||
|
# uci set MODULE_UNDERSCORE_PLACEHOLDER.global.enabled="$enabled"
|
||||||
|
# uci commit MODULE_UNDERSCORE_PLACEHOLDER
|
||||||
|
|
||||||
|
json_init
|
||||||
|
json_add_boolean "success" 1
|
||||||
|
json_add_string "message" "Configuration updated"
|
||||||
|
json_dump
|
||||||
|
;;
|
||||||
|
|
||||||
|
get_stats)
|
||||||
|
# Return statistics
|
||||||
|
json_add_object "stats"
|
||||||
|
json_add_int "uptime" "$(cat /proc/uptime | cut -d. -f1)"
|
||||||
|
json_add_string "timestamp" "$(date -Iseconds)"
|
||||||
|
json_close_object
|
||||||
|
json_dump
|
||||||
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
# Unknown method
|
||||||
|
json_add_int "error" -32601
|
||||||
|
json_add_string "message" "Method not found"
|
||||||
|
json_dump
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
RPCD_EOF
|
||||||
|
|
||||||
|
# Replace placeholders
|
||||||
|
sed -i "s/MODULE_PLACEHOLDER/$MODULE/g" "$RPCD_SCRIPT"
|
||||||
|
sed -i "s/MODULE_UNDERSCORE_PLACEHOLDER/$MODULE_UNDERSCORE/g" "$RPCD_SCRIPT"
|
||||||
|
|
||||||
|
chmod +x "$RPCD_SCRIPT"
|
||||||
|
echo " ✓ Created and made executable"
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# Create ACL file
|
||||||
|
# ============================================
|
||||||
|
ACL_FILE="/usr/share/rpcd/acl.d/${PKG_NAME}.json"
|
||||||
|
|
||||||
|
echo "→ Creating ACL file: $ACL_FILE"
|
||||||
|
|
||||||
|
cat > "$ACL_FILE" << ACL_EOF
|
||||||
|
{
|
||||||
|
"luci-app-$MODULE": {
|
||||||
|
"description": "Grant access to LuCI app $MODULE",
|
||||||
|
"read": {
|
||||||
|
"ubus": {
|
||||||
|
"$UBUS_NAME": ["status", "get_config", "get_stats"]
|
||||||
|
},
|
||||||
|
"uci": ["$MODULE_UNDERSCORE"]
|
||||||
|
},
|
||||||
|
"write": {
|
||||||
|
"ubus": {
|
||||||
|
"$UBUS_NAME": ["set_config"]
|
||||||
|
},
|
||||||
|
"uci": ["$MODULE_UNDERSCORE"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ACL_EOF
|
||||||
|
|
||||||
|
echo " ✓ Created ACL file"
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# Create Menu file (if not exists)
|
||||||
|
# ============================================
|
||||||
|
MENU_FILE="/usr/share/luci/menu.d/${PKG_NAME}.json"
|
||||||
|
|
||||||
|
if [ ! -f "$MENU_FILE" ]; then
|
||||||
|
echo "→ Creating Menu file: $MENU_FILE"
|
||||||
|
|
||||||
|
# Convert module name to title
|
||||||
|
TITLE=$(echo "$MODULE" | sed 's/-/ /g' | awk '{for(i=1;i<=NF;i++) $i=toupper(substr($i,1,1)) tolower(substr($i,2))}1')
|
||||||
|
|
||||||
|
cat > "$MENU_FILE" << MENU_EOF
|
||||||
|
{
|
||||||
|
"admin/services/$MODULE_UNDERSCORE": {
|
||||||
|
"title": "$TITLE",
|
||||||
|
"order": 50,
|
||||||
|
"action": {
|
||||||
|
"type": "view",
|
||||||
|
"path": "$MODULE/main"
|
||||||
|
},
|
||||||
|
"depends": {
|
||||||
|
"acl": ["luci-app-$MODULE"],
|
||||||
|
"uci": {
|
||||||
|
"$MODULE_UNDERSCORE": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MENU_EOF
|
||||||
|
|
||||||
|
echo " ✓ Created menu file"
|
||||||
|
else
|
||||||
|
echo "→ Menu file already exists: $MENU_FILE"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# Create UCI config (if not exists)
|
||||||
|
# ============================================
|
||||||
|
UCI_CONFIG="/etc/config/$MODULE_UNDERSCORE"
|
||||||
|
|
||||||
|
if [ ! -f "$UCI_CONFIG" ]; then
|
||||||
|
echo "→ Creating UCI config: $UCI_CONFIG"
|
||||||
|
|
||||||
|
cat > "$UCI_CONFIG" << UCI_EOF
|
||||||
|
config global 'global'
|
||||||
|
option enabled '1'
|
||||||
|
option version '2.0.0'
|
||||||
|
UCI_EOF
|
||||||
|
|
||||||
|
echo " ✓ Created UCI config"
|
||||||
|
else
|
||||||
|
echo "→ UCI config already exists: $UCI_CONFIG"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# Restart services
|
||||||
|
# ============================================
|
||||||
|
echo ""
|
||||||
|
echo "→ Restarting rpcd..."
|
||||||
|
/etc/init.d/rpcd restart
|
||||||
|
|
||||||
|
echo "→ Clearing LuCI cache..."
|
||||||
|
rm -rf /tmp/luci-*
|
||||||
|
|
||||||
|
# Wait for rpcd to initialize
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# Verify
|
||||||
|
# ============================================
|
||||||
|
echo ""
|
||||||
|
echo "╔══════════════════════════════════════════════════════════════╗"
|
||||||
|
echo "║ Verification"
|
||||||
|
echo "╚══════════════════════════════════════════════════════════════╝"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Check ubus registration
|
||||||
|
if ubus list "$UBUS_NAME" > /dev/null 2>&1; then
|
||||||
|
echo "✓ $UBUS_NAME is registered in ubus"
|
||||||
|
echo ""
|
||||||
|
echo "Available methods:"
|
||||||
|
ubus -v list "$UBUS_NAME"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "Testing status call:"
|
||||||
|
ubus call "$UBUS_NAME" status
|
||||||
|
else
|
||||||
|
echo "✗ $UBUS_NAME is NOT registered"
|
||||||
|
echo ""
|
||||||
|
echo "Debug steps:"
|
||||||
|
echo " 1. Check script: cat $RPCD_SCRIPT"
|
||||||
|
echo " 2. Test manually: echo '{\"method\":\"list\"}' | $RPCD_SCRIPT"
|
||||||
|
echo " 3. Check logs: logread | grep rpcd"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "Done!"
|
||||||
129
install-rpcd-fix.sh
Executable file
129
install-rpcd-fix.sh
Executable file
@ -0,0 +1,129 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# install-rpcd-fix.sh
|
||||||
|
# Quick installation script for SecuBox RPCD fixes
|
||||||
|
#
|
||||||
|
# Upload this script along with rpcd/ and acl/ folders to the router
|
||||||
|
# then run: sh install-rpcd-fix.sh
|
||||||
|
|
||||||
|
echo "╔══════════════════════════════════════════════════════════════╗"
|
||||||
|
echo "║ SecuBox RPCD Fix Installer ║"
|
||||||
|
echo "╚══════════════════════════════════════════════════════════════╝"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
|
||||||
|
|
||||||
|
# Check if running as root
|
||||||
|
if [ "$(id -u)" != "0" ]; then
|
||||||
|
echo "Error: This script must be run as root"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# Install RPCD scripts
|
||||||
|
# ============================================
|
||||||
|
echo "→ Installing RPCD scripts..."
|
||||||
|
|
||||||
|
if [ -d "$SCRIPT_DIR/rpcd" ]; then
|
||||||
|
for script in "$SCRIPT_DIR/rpcd"/*; do
|
||||||
|
[ -f "$script" ] || continue
|
||||||
|
|
||||||
|
NAME=$(basename "$script")
|
||||||
|
DEST="/usr/libexec/rpcd/$NAME"
|
||||||
|
|
||||||
|
cp "$script" "$DEST"
|
||||||
|
chmod +x "$DEST"
|
||||||
|
echo " ✓ Installed: $DEST"
|
||||||
|
done
|
||||||
|
else
|
||||||
|
echo " ⚠ No rpcd/ directory found"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# Install ACL files
|
||||||
|
# ============================================
|
||||||
|
echo ""
|
||||||
|
echo "→ Installing ACL files..."
|
||||||
|
|
||||||
|
mkdir -p /usr/share/rpcd/acl.d
|
||||||
|
|
||||||
|
if [ -d "$SCRIPT_DIR/acl" ]; then
|
||||||
|
for acl in "$SCRIPT_DIR/acl"/*.json; do
|
||||||
|
[ -f "$acl" ] || continue
|
||||||
|
|
||||||
|
NAME=$(basename "$acl")
|
||||||
|
DEST="/usr/share/rpcd/acl.d/$NAME"
|
||||||
|
|
||||||
|
cp "$acl" "$DEST"
|
||||||
|
echo " ✓ Installed: $DEST"
|
||||||
|
done
|
||||||
|
else
|
||||||
|
echo " ⚠ No acl/ directory found"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# Create missing UCI configs
|
||||||
|
# ============================================
|
||||||
|
echo ""
|
||||||
|
echo "→ Creating UCI configs..."
|
||||||
|
|
||||||
|
# vhost_manager
|
||||||
|
if [ ! -f /etc/config/vhost_manager ]; then
|
||||||
|
cat > /etc/config/vhost_manager << 'EOF'
|
||||||
|
config global 'global'
|
||||||
|
option enabled '1'
|
||||||
|
option nginx_dir '/etc/nginx/conf.d'
|
||||||
|
option acme_dir '/etc/acme'
|
||||||
|
EOF
|
||||||
|
echo " ✓ Created: /etc/config/vhost_manager"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# Restart services
|
||||||
|
# ============================================
|
||||||
|
echo ""
|
||||||
|
echo "→ Restarting services..."
|
||||||
|
|
||||||
|
# Restart rpcd
|
||||||
|
/etc/init.d/rpcd restart
|
||||||
|
echo " ✓ rpcd restarted"
|
||||||
|
|
||||||
|
# Clear LuCI cache
|
||||||
|
rm -rf /tmp/luci-*
|
||||||
|
echo " ✓ LuCI cache cleared"
|
||||||
|
|
||||||
|
# Wait for rpcd to initialize
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# Verify installation
|
||||||
|
# ============================================
|
||||||
|
echo ""
|
||||||
|
echo "╔══════════════════════════════════════════════════════════════╗"
|
||||||
|
echo "║ Verification ║"
|
||||||
|
echo "╚══════════════════════════════════════════════════════════════╝"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# List installed modules
|
||||||
|
echo "Checking ubus registration:"
|
||||||
|
|
||||||
|
MODULES="vhost-manager secubox bandwidth-manager auth-guardian media-flow"
|
||||||
|
|
||||||
|
for module in $MODULES; do
|
||||||
|
UBUS_NAME="luci.$module"
|
||||||
|
if ubus list "$UBUS_NAME" > /dev/null 2>&1; then
|
||||||
|
echo " ✓ $UBUS_NAME"
|
||||||
|
else
|
||||||
|
echo " ✗ $UBUS_NAME (not registered)"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "Testing vhost-manager status:"
|
||||||
|
ubus call luci.vhost-manager status 2>/dev/null || echo " ✗ Failed"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "Installation complete!"
|
||||||
|
echo ""
|
||||||
|
echo "If modules are still not working, check:"
|
||||||
|
echo " logread | grep rpcd"
|
||||||
|
echo " logread | grep ubus"
|
||||||
334
rpcd/vhost-manager
Normal file
334
rpcd/vhost-manager
Normal file
@ -0,0 +1,334 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# /usr/libexec/rpcd/vhost-manager
|
||||||
|
# RPCD backend for VHost Manager module
|
||||||
|
# Provides ubus interface: luci.vhost-manager
|
||||||
|
|
||||||
|
. /lib/functions.sh
|
||||||
|
. /usr/share/libubox/jshn.sh
|
||||||
|
|
||||||
|
# Configuration
|
||||||
|
UCI_CONFIG="vhost_manager"
|
||||||
|
NGINX_VHOSTS_DIR="/etc/nginx/conf.d"
|
||||||
|
ACME_DIR="/etc/acme"
|
||||||
|
|
||||||
|
# Helper: Check if nginx is running
|
||||||
|
nginx_running() {
|
||||||
|
pgrep -x nginx > /dev/null 2>&1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Helper: Get nginx status
|
||||||
|
get_nginx_status() {
|
||||||
|
if nginx_running; then
|
||||||
|
echo "running"
|
||||||
|
else
|
||||||
|
echo "stopped"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Helper: Count vhosts
|
||||||
|
count_vhosts() {
|
||||||
|
if [ -d "$NGINX_VHOSTS_DIR" ]; then
|
||||||
|
ls -1 "$NGINX_VHOSTS_DIR"/*.conf 2>/dev/null | wc -l
|
||||||
|
else
|
||||||
|
echo "0"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Helper: List vhosts
|
||||||
|
list_vhosts() {
|
||||||
|
json_add_array "vhosts"
|
||||||
|
|
||||||
|
if [ -d "$NGINX_VHOSTS_DIR" ]; then
|
||||||
|
for conf in "$NGINX_VHOSTS_DIR"/*.conf; do
|
||||||
|
[ -f "$conf" ] || continue
|
||||||
|
|
||||||
|
# Extract server_name from config
|
||||||
|
SERVER_NAME=$(grep -m1 "server_name" "$conf" | awk '{print $2}' | tr -d ';')
|
||||||
|
PROXY_PASS=$(grep -m1 "proxy_pass" "$conf" | awk '{print $2}' | tr -d ';')
|
||||||
|
SSL_ENABLED="false"
|
||||||
|
|
||||||
|
if grep -q "ssl_certificate" "$conf"; then
|
||||||
|
SSL_ENABLED="true"
|
||||||
|
fi
|
||||||
|
|
||||||
|
json_add_object ""
|
||||||
|
json_add_string "name" "$(basename "$conf" .conf)"
|
||||||
|
json_add_string "domain" "$SERVER_NAME"
|
||||||
|
json_add_string "backend" "$PROXY_PASS"
|
||||||
|
json_add_boolean "ssl" "$SSL_ENABLED"
|
||||||
|
json_add_boolean "enabled" 1
|
||||||
|
json_close_object
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
json_close_array
|
||||||
|
}
|
||||||
|
|
||||||
|
# Helper: Get SSL certificates
|
||||||
|
list_certificates() {
|
||||||
|
json_add_array "certificates"
|
||||||
|
|
||||||
|
if [ -d "$ACME_DIR" ]; then
|
||||||
|
for cert_dir in "$ACME_DIR"/*/; do
|
||||||
|
[ -d "$cert_dir" ] || continue
|
||||||
|
|
||||||
|
DOMAIN=$(basename "$cert_dir")
|
||||||
|
CERT_FILE="$cert_dir/fullchain.cer"
|
||||||
|
|
||||||
|
if [ -f "$CERT_FILE" ]; then
|
||||||
|
# Get expiry date
|
||||||
|
EXPIRY=$(openssl x509 -enddate -noout -in "$CERT_FILE" 2>/dev/null | cut -d= -f2)
|
||||||
|
|
||||||
|
json_add_object ""
|
||||||
|
json_add_string "domain" "$DOMAIN"
|
||||||
|
json_add_string "expiry" "$EXPIRY"
|
||||||
|
json_add_boolean "valid" 1
|
||||||
|
json_close_object
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
json_close_array
|
||||||
|
}
|
||||||
|
|
||||||
|
# Initialize JSON
|
||||||
|
json_init
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
list)
|
||||||
|
# List available methods
|
||||||
|
json_add_object "status"
|
||||||
|
json_close_object
|
||||||
|
|
||||||
|
json_add_object "get_vhosts"
|
||||||
|
json_close_object
|
||||||
|
|
||||||
|
json_add_object "get_vhost"
|
||||||
|
json_add_string "name" "string"
|
||||||
|
json_close_object
|
||||||
|
|
||||||
|
json_add_object "add_vhost"
|
||||||
|
json_add_string "domain" "string"
|
||||||
|
json_add_string "backend" "string"
|
||||||
|
json_add_boolean "ssl" false
|
||||||
|
json_close_object
|
||||||
|
|
||||||
|
json_add_object "delete_vhost"
|
||||||
|
json_add_string "name" "string"
|
||||||
|
json_close_object
|
||||||
|
|
||||||
|
json_add_object "get_certificates"
|
||||||
|
json_close_object
|
||||||
|
|
||||||
|
json_add_object "request_certificate"
|
||||||
|
json_add_string "domain" "string"
|
||||||
|
json_close_object
|
||||||
|
|
||||||
|
json_add_object "reload_nginx"
|
||||||
|
json_close_object
|
||||||
|
|
||||||
|
json_add_object "test_config"
|
||||||
|
json_close_object
|
||||||
|
|
||||||
|
json_dump
|
||||||
|
;;
|
||||||
|
|
||||||
|
call)
|
||||||
|
case "$2" in
|
||||||
|
status)
|
||||||
|
# Return module status
|
||||||
|
json_add_string "module" "vhost-manager"
|
||||||
|
json_add_string "version" "2.0.0"
|
||||||
|
json_add_string "nginx_status" "$(get_nginx_status)"
|
||||||
|
json_add_boolean "nginx_running" $(nginx_running && echo 1 || echo 0)
|
||||||
|
json_add_int "vhost_count" "$(count_vhosts)"
|
||||||
|
json_add_string "config_dir" "$NGINX_VHOSTS_DIR"
|
||||||
|
json_add_string "acme_dir" "$ACME_DIR"
|
||||||
|
|
||||||
|
# Check nginx version
|
||||||
|
if command -v nginx > /dev/null 2>&1; then
|
||||||
|
NGINX_VERSION=$(nginx -v 2>&1 | cut -d/ -f2)
|
||||||
|
json_add_string "nginx_version" "$NGINX_VERSION"
|
||||||
|
fi
|
||||||
|
|
||||||
|
json_dump
|
||||||
|
;;
|
||||||
|
|
||||||
|
get_vhosts)
|
||||||
|
# Return list of vhosts
|
||||||
|
list_vhosts
|
||||||
|
json_dump
|
||||||
|
;;
|
||||||
|
|
||||||
|
get_vhost)
|
||||||
|
# Get single vhost details
|
||||||
|
read -r input
|
||||||
|
json_load "$input"
|
||||||
|
json_get_var vhost_name name
|
||||||
|
|
||||||
|
CONF_FILE="$NGINX_VHOSTS_DIR/${vhost_name}.conf"
|
||||||
|
|
||||||
|
if [ -f "$CONF_FILE" ]; then
|
||||||
|
json_add_boolean "found" 1
|
||||||
|
json_add_string "name" "$vhost_name"
|
||||||
|
json_add_string "config" "$(cat "$CONF_FILE")"
|
||||||
|
else
|
||||||
|
json_add_boolean "found" 0
|
||||||
|
json_add_string "error" "VHost not found"
|
||||||
|
fi
|
||||||
|
|
||||||
|
json_dump
|
||||||
|
;;
|
||||||
|
|
||||||
|
add_vhost)
|
||||||
|
# Add new vhost
|
||||||
|
read -r input
|
||||||
|
json_load "$input"
|
||||||
|
json_get_var domain domain
|
||||||
|
json_get_var backend backend
|
||||||
|
json_get_var ssl ssl
|
||||||
|
|
||||||
|
# Validate
|
||||||
|
if [ -z "$domain" ] || [ -z "$backend" ]; then
|
||||||
|
json_init
|
||||||
|
json_add_boolean "success" 0
|
||||||
|
json_add_string "error" "Domain and backend are required"
|
||||||
|
json_dump
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Create config
|
||||||
|
VHOST_NAME=$(echo "$domain" | tr '.' '-')
|
||||||
|
CONF_FILE="$NGINX_VHOSTS_DIR/${VHOST_NAME}.conf"
|
||||||
|
|
||||||
|
mkdir -p "$NGINX_VHOSTS_DIR"
|
||||||
|
|
||||||
|
cat > "$CONF_FILE" << NGINX_EOF
|
||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
listen [::]:80;
|
||||||
|
server_name $domain;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
proxy_pass $backend;
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Host \$host;
|
||||||
|
proxy_set_header X-Real-IP \$remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Forwarded-Proto \$scheme;
|
||||||
|
proxy_set_header Upgrade \$http_upgrade;
|
||||||
|
proxy_set_header Connection "upgrade";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
NGINX_EOF
|
||||||
|
|
||||||
|
json_init
|
||||||
|
json_add_boolean "success" 1
|
||||||
|
json_add_string "message" "VHost created"
|
||||||
|
json_add_string "config_file" "$CONF_FILE"
|
||||||
|
json_dump
|
||||||
|
;;
|
||||||
|
|
||||||
|
delete_vhost)
|
||||||
|
# Delete vhost
|
||||||
|
read -r input
|
||||||
|
json_load "$input"
|
||||||
|
json_get_var vhost_name name
|
||||||
|
|
||||||
|
CONF_FILE="$NGINX_VHOSTS_DIR/${vhost_name}.conf"
|
||||||
|
|
||||||
|
if [ -f "$CONF_FILE" ]; then
|
||||||
|
rm -f "$CONF_FILE"
|
||||||
|
json_init
|
||||||
|
json_add_boolean "success" 1
|
||||||
|
json_add_string "message" "VHost deleted"
|
||||||
|
else
|
||||||
|
json_init
|
||||||
|
json_add_boolean "success" 0
|
||||||
|
json_add_string "error" "VHost not found"
|
||||||
|
fi
|
||||||
|
|
||||||
|
json_dump
|
||||||
|
;;
|
||||||
|
|
||||||
|
get_certificates)
|
||||||
|
# List SSL certificates
|
||||||
|
list_certificates
|
||||||
|
json_dump
|
||||||
|
;;
|
||||||
|
|
||||||
|
request_certificate)
|
||||||
|
# Request Let's Encrypt certificate
|
||||||
|
read -r input
|
||||||
|
json_load "$input"
|
||||||
|
json_get_var domain domain
|
||||||
|
|
||||||
|
if [ -z "$domain" ]; then
|
||||||
|
json_init
|
||||||
|
json_add_boolean "success" 0
|
||||||
|
json_add_string "error" "Domain is required"
|
||||||
|
json_dump
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if acme.sh is available
|
||||||
|
if command -v acme.sh > /dev/null 2>&1; then
|
||||||
|
# Request certificate (async - just start the process)
|
||||||
|
acme.sh --issue -d "$domain" --webroot /www --keylength ec-256 &
|
||||||
|
|
||||||
|
json_init
|
||||||
|
json_add_boolean "success" 1
|
||||||
|
json_add_string "message" "Certificate request started"
|
||||||
|
json_add_string "domain" "$domain"
|
||||||
|
else
|
||||||
|
json_init
|
||||||
|
json_add_boolean "success" 0
|
||||||
|
json_add_string "error" "acme.sh not installed"
|
||||||
|
fi
|
||||||
|
|
||||||
|
json_dump
|
||||||
|
;;
|
||||||
|
|
||||||
|
reload_nginx)
|
||||||
|
# Reload nginx configuration
|
||||||
|
if nginx -t > /dev/null 2>&1; then
|
||||||
|
/etc/init.d/nginx reload
|
||||||
|
json_add_boolean "success" 1
|
||||||
|
json_add_string "message" "Nginx reloaded"
|
||||||
|
else
|
||||||
|
json_add_boolean "success" 0
|
||||||
|
json_add_string "error" "Configuration test failed"
|
||||||
|
json_add_string "details" "$(nginx -t 2>&1)"
|
||||||
|
fi
|
||||||
|
json_dump
|
||||||
|
;;
|
||||||
|
|
||||||
|
test_config)
|
||||||
|
# Test nginx configuration
|
||||||
|
TEST_OUTPUT=$(nginx -t 2>&1)
|
||||||
|
TEST_RESULT=$?
|
||||||
|
|
||||||
|
if [ $TEST_RESULT -eq 0 ]; then
|
||||||
|
json_add_boolean "valid" 1
|
||||||
|
json_add_string "message" "Configuration OK"
|
||||||
|
else
|
||||||
|
json_add_boolean "valid" 0
|
||||||
|
json_add_string "error" "$TEST_OUTPUT"
|
||||||
|
fi
|
||||||
|
json_dump
|
||||||
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
# Unknown method
|
||||||
|
json_add_int "error" -32601
|
||||||
|
json_add_string "message" "Method not found: $2"
|
||||||
|
json_dump
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
echo "Usage: $0 {list|call}"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
1543
secubox-analyzer.sh
Executable file
1543
secubox-analyzer.sh
Executable file
File diff suppressed because it is too large
Load Diff
421
secubox-debug.sh
Executable file
421
secubox-debug.sh
Executable file
@ -0,0 +1,421 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# secubox-debug.sh
|
||||||
|
# Debug and analysis script for SecuBox LuCI modules RPC/ubus issues
|
||||||
|
#
|
||||||
|
# Usage: ./secubox-debug.sh [module-name]
|
||||||
|
# Example: ./secubox-debug.sh vhost-manager
|
||||||
|
# ./secubox-debug.sh all
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Colors
|
||||||
|
RED='\033[0;31m'
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
YELLOW='\033[1;33m'
|
||||||
|
BLUE='\033[0;34m'
|
||||||
|
CYAN='\033[0;36m'
|
||||||
|
NC='\033[0m' # No Color
|
||||||
|
|
||||||
|
# SecuBox modules list
|
||||||
|
MODULES="
|
||||||
|
secubox
|
||||||
|
crowdsec-dashboard
|
||||||
|
netdata-dashboard
|
||||||
|
netifyd-dashboard
|
||||||
|
wireguard-dashboard
|
||||||
|
network-modes
|
||||||
|
client-guardian
|
||||||
|
system-hub
|
||||||
|
bandwidth-manager
|
||||||
|
auth-guardian
|
||||||
|
media-flow
|
||||||
|
vhost-manager
|
||||||
|
cdn-cache
|
||||||
|
traffic-shaper
|
||||||
|
"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "${CYAN}╔══════════════════════════════════════════════════════════════╗${NC}"
|
||||||
|
echo "${CYAN}║ SecuBox RPC/UBUS Debug & Analysis Tool ║${NC}"
|
||||||
|
echo "${CYAN}╚══════════════════════════════════════════════════════════════╝${NC}"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# System Information
|
||||||
|
# ============================================
|
||||||
|
print_section() {
|
||||||
|
echo ""
|
||||||
|
echo "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
||||||
|
echo "${BLUE} $1${NC}"
|
||||||
|
echo "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
||||||
|
}
|
||||||
|
|
||||||
|
print_ok() {
|
||||||
|
echo " ${GREEN}✓${NC} $1"
|
||||||
|
}
|
||||||
|
|
||||||
|
print_warn() {
|
||||||
|
echo " ${YELLOW}⚠${NC} $1"
|
||||||
|
}
|
||||||
|
|
||||||
|
print_error() {
|
||||||
|
echo " ${RED}✗${NC} $1"
|
||||||
|
}
|
||||||
|
|
||||||
|
print_info() {
|
||||||
|
echo " ${CYAN}→${NC} $1"
|
||||||
|
}
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# Check prerequisites
|
||||||
|
# ============================================
|
||||||
|
print_section "System Prerequisites"
|
||||||
|
|
||||||
|
# Check if running on OpenWrt
|
||||||
|
if [ -f /etc/openwrt_release ]; then
|
||||||
|
print_ok "Running on OpenWrt"
|
||||||
|
. /etc/openwrt_release
|
||||||
|
print_info "Version: $DISTRIB_DESCRIPTION"
|
||||||
|
else
|
||||||
|
print_warn "Not running on OpenWrt - some checks may fail"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check rpcd
|
||||||
|
if pgrep -x rpcd > /dev/null 2>&1; then
|
||||||
|
print_ok "rpcd is running (PID: $(pgrep -x rpcd))"
|
||||||
|
else
|
||||||
|
print_error "rpcd is NOT running!"
|
||||||
|
echo " Try: /etc/init.d/rpcd restart"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check uhttpd
|
||||||
|
if pgrep -x uhttpd > /dev/null 2>&1; then
|
||||||
|
print_ok "uhttpd is running"
|
||||||
|
else
|
||||||
|
print_warn "uhttpd not running (nginx mode?)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check ubus socket
|
||||||
|
if [ -S /var/run/ubus/ubus.sock ]; then
|
||||||
|
print_ok "ubus socket exists"
|
||||||
|
else
|
||||||
|
print_error "ubus socket missing!"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# List all ubus objects
|
||||||
|
# ============================================
|
||||||
|
print_section "Available UBUS Objects"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo " All registered ubus objects:"
|
||||||
|
echo " ${CYAN}─────────────────────────────${NC}"
|
||||||
|
|
||||||
|
ubus list 2>/dev/null | while read obj; do
|
||||||
|
# Highlight luci objects
|
||||||
|
case "$obj" in
|
||||||
|
luci.*)
|
||||||
|
echo " ${GREEN}$obj${NC}"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo " $obj"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
# Count luci objects
|
||||||
|
LUCI_COUNT=$(ubus list 2>/dev/null | grep -c "^luci\." || echo "0")
|
||||||
|
echo ""
|
||||||
|
print_info "Total LuCI objects registered: $LUCI_COUNT"
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# Check SecuBox modules
|
||||||
|
# ============================================
|
||||||
|
print_section "SecuBox Modules Status"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
printf " ${CYAN}%-25s %-10s %-10s %-10s %-10s${NC}\n" "MODULE" "UBUS" "RPCD" "ACL" "MENU"
|
||||||
|
echo " ─────────────────────────────────────────────────────────────────"
|
||||||
|
|
||||||
|
check_module() {
|
||||||
|
local module="$1"
|
||||||
|
local ubus_name="luci.$module"
|
||||||
|
local rpcd_script="/usr/libexec/rpcd/$module"
|
||||||
|
local acl_file="/usr/share/rpcd/acl.d/luci-app-${module}.json"
|
||||||
|
local menu_file="/usr/share/luci/menu.d/luci-app-${module}.json"
|
||||||
|
|
||||||
|
# Alternative paths
|
||||||
|
local rpcd_script_alt="/usr/libexec/rpcd/luci.$module"
|
||||||
|
local acl_file_alt="/usr/share/rpcd/acl.d/luci-${module}.json"
|
||||||
|
local menu_file_alt="/usr/share/luci/menu.d/luci-${module}.json"
|
||||||
|
|
||||||
|
# Check ubus
|
||||||
|
local ubus_status="${RED}✗${NC}"
|
||||||
|
if ubus list "$ubus_name" > /dev/null 2>&1; then
|
||||||
|
ubus_status="${GREEN}✓${NC}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check rpcd script
|
||||||
|
local rpcd_status="${RED}✗${NC}"
|
||||||
|
if [ -x "$rpcd_script" ] || [ -x "$rpcd_script_alt" ]; then
|
||||||
|
rpcd_status="${GREEN}✓${NC}"
|
||||||
|
elif [ -f "$rpcd_script" ] || [ -f "$rpcd_script_alt" ]; then
|
||||||
|
rpcd_status="${YELLOW}!${NC}" # exists but not executable
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check ACL
|
||||||
|
local acl_status="${RED}✗${NC}"
|
||||||
|
if [ -f "$acl_file" ] || [ -f "$acl_file_alt" ]; then
|
||||||
|
acl_status="${GREEN}✓${NC}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check menu
|
||||||
|
local menu_status="${RED}✗${NC}"
|
||||||
|
if [ -f "$menu_file" ] || [ -f "$menu_file_alt" ]; then
|
||||||
|
menu_status="${GREEN}✓${NC}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
printf " %-25s %-18s %-18s %-18s %-18s\n" \
|
||||||
|
"$module" "$ubus_status" "$rpcd_status" "$acl_status" "$menu_status"
|
||||||
|
}
|
||||||
|
|
||||||
|
for module in $MODULES; do
|
||||||
|
check_module "$module"
|
||||||
|
done
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo " ${CYAN}Legend:${NC} ${GREEN}✓${NC}=OK ${YELLOW}!${NC}=Issue ${RED}✗${NC}=Missing"
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# Detailed module analysis
|
||||||
|
# ============================================
|
||||||
|
TARGET_MODULE="$1"
|
||||||
|
|
||||||
|
if [ -n "$TARGET_MODULE" ] && [ "$TARGET_MODULE" != "all" ]; then
|
||||||
|
print_section "Detailed Analysis: $TARGET_MODULE"
|
||||||
|
|
||||||
|
MODULE="$TARGET_MODULE"
|
||||||
|
UBUS_NAME="luci.$MODULE"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo " ${CYAN}UBUS Object: $UBUS_NAME${NC}"
|
||||||
|
echo " ─────────────────────────────────────"
|
||||||
|
|
||||||
|
# Check if ubus object exists
|
||||||
|
if ubus list "$UBUS_NAME" > /dev/null 2>&1; then
|
||||||
|
print_ok "Object registered in ubus"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo " Available methods:"
|
||||||
|
ubus -v list "$UBUS_NAME" 2>/dev/null | sed 's/^/ /'
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo " Testing 'status' method:"
|
||||||
|
if ubus call "$UBUS_NAME" status 2>/dev/null; then
|
||||||
|
print_ok "status method works"
|
||||||
|
else
|
||||||
|
print_error "status method failed"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
print_error "Object NOT registered in ubus"
|
||||||
|
echo ""
|
||||||
|
echo " ${YELLOW}Troubleshooting steps:${NC}"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Check RPCD script
|
||||||
|
RPCD_PATHS="
|
||||||
|
/usr/libexec/rpcd/$MODULE
|
||||||
|
/usr/libexec/rpcd/luci.$MODULE
|
||||||
|
/usr/libexec/rpcd/luci-$MODULE
|
||||||
|
"
|
||||||
|
echo " 1. Checking RPCD script locations:"
|
||||||
|
FOUND_RPCD=""
|
||||||
|
for path in $RPCD_PATHS; do
|
||||||
|
if [ -f "$path" ]; then
|
||||||
|
FOUND_RPCD="$path"
|
||||||
|
if [ -x "$path" ]; then
|
||||||
|
print_ok "Found executable: $path"
|
||||||
|
else
|
||||||
|
print_error "Found but NOT executable: $path"
|
||||||
|
echo " ${YELLOW}Fix: chmod +x $path${NC}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ -z "$FOUND_RPCD" ]; then
|
||||||
|
print_error "No RPCD script found!"
|
||||||
|
echo " Expected at: /usr/libexec/rpcd/$MODULE"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check ACL file
|
||||||
|
echo ""
|
||||||
|
echo " 2. Checking ACL configuration:"
|
||||||
|
ACL_PATHS="
|
||||||
|
/usr/share/rpcd/acl.d/luci-app-${MODULE}.json
|
||||||
|
/usr/share/rpcd/acl.d/luci-${MODULE}.json
|
||||||
|
/usr/share/rpcd/acl.d/${MODULE}.json
|
||||||
|
"
|
||||||
|
FOUND_ACL=""
|
||||||
|
for path in $ACL_PATHS; do
|
||||||
|
if [ -f "$path" ]; then
|
||||||
|
FOUND_ACL="$path"
|
||||||
|
print_ok "Found ACL: $path"
|
||||||
|
|
||||||
|
# Validate JSON
|
||||||
|
if command -v jsonfilter > /dev/null 2>&1; then
|
||||||
|
if jsonfilter -i "$path" -e '@' > /dev/null 2>&1; then
|
||||||
|
print_ok "JSON syntax valid"
|
||||||
|
else
|
||||||
|
print_error "Invalid JSON syntax!"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check for correct ubus permission
|
||||||
|
if grep -q "\"$UBUS_NAME\"" "$path" 2>/dev/null; then
|
||||||
|
print_ok "ACL contains $UBUS_NAME permission"
|
||||||
|
else
|
||||||
|
print_warn "ACL might be missing $UBUS_NAME permission"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ -z "$FOUND_ACL" ]; then
|
||||||
|
print_error "No ACL file found!"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Test RPCD script directly
|
||||||
|
if [ -n "$FOUND_RPCD" ] && [ -x "$FOUND_RPCD" ]; then
|
||||||
|
echo ""
|
||||||
|
echo " 3. Testing RPCD script directly:"
|
||||||
|
|
||||||
|
# Test list method
|
||||||
|
echo '{"method":"list"}' | "$FOUND_RPCD" 2>&1 | head -20
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check menu entry
|
||||||
|
echo ""
|
||||||
|
echo " ${CYAN}Menu Configuration${NC}"
|
||||||
|
echo " ─────────────────────────────────────"
|
||||||
|
|
||||||
|
MENU_PATHS="
|
||||||
|
/usr/share/luci/menu.d/luci-app-${MODULE}.json
|
||||||
|
/usr/share/luci/menu.d/luci-${MODULE}.json
|
||||||
|
"
|
||||||
|
for path in $MENU_PATHS; do
|
||||||
|
if [ -f "$path" ]; then
|
||||||
|
print_ok "Found menu: $path"
|
||||||
|
echo ""
|
||||||
|
cat "$path" | sed 's/^/ /'
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# Common fixes
|
||||||
|
# ============================================
|
||||||
|
print_section "Common Fixes"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo " ${YELLOW}If a module is not working:${NC}"
|
||||||
|
echo ""
|
||||||
|
echo " 1. ${CYAN}Restart rpcd:${NC}"
|
||||||
|
echo " /etc/init.d/rpcd restart"
|
||||||
|
echo ""
|
||||||
|
echo " 2. ${CYAN}Check script permissions:${NC}"
|
||||||
|
echo " chmod +x /usr/libexec/rpcd/<module-name>"
|
||||||
|
echo ""
|
||||||
|
echo " 3. ${CYAN}Validate JSON files:${NC}"
|
||||||
|
echo " jsonfilter -i /usr/share/rpcd/acl.d/luci-app-<module>.json -e '@'"
|
||||||
|
echo ""
|
||||||
|
echo " 4. ${CYAN}Check rpcd logs:${NC}"
|
||||||
|
echo " logread | grep rpcd"
|
||||||
|
echo ""
|
||||||
|
echo " 5. ${CYAN}Test ubus manually:${NC}"
|
||||||
|
echo " ubus call luci.<module> status"
|
||||||
|
echo ""
|
||||||
|
echo " 6. ${CYAN}Reload LuCI:${NC}"
|
||||||
|
echo " rm -rf /tmp/luci-*"
|
||||||
|
echo " /etc/init.d/uhttpd restart"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# Generate fix script
|
||||||
|
# ============================================
|
||||||
|
if [ -n "$TARGET_MODULE" ] && [ "$TARGET_MODULE" != "all" ]; then
|
||||||
|
print_section "Auto-Fix Script for $TARGET_MODULE"
|
||||||
|
|
||||||
|
FIX_SCRIPT="/tmp/fix-${TARGET_MODULE}.sh"
|
||||||
|
|
||||||
|
cat > "$FIX_SCRIPT" << FIXEOF
|
||||||
|
#!/bin/sh
|
||||||
|
# Auto-generated fix script for $TARGET_MODULE
|
||||||
|
|
||||||
|
echo "Fixing $TARGET_MODULE..."
|
||||||
|
|
||||||
|
# Fix permissions
|
||||||
|
if [ -f /usr/libexec/rpcd/$TARGET_MODULE ]; then
|
||||||
|
chmod +x /usr/libexec/rpcd/$TARGET_MODULE
|
||||||
|
echo "✓ Fixed permissions for RPCD script"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -f /usr/libexec/rpcd/luci.$TARGET_MODULE ]; then
|
||||||
|
chmod +x /usr/libexec/rpcd/luci.$TARGET_MODULE
|
||||||
|
echo "✓ Fixed permissions for RPCD script (alt)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Restart rpcd
|
||||||
|
/etc/init.d/rpcd restart
|
||||||
|
echo "✓ Restarted rpcd"
|
||||||
|
|
||||||
|
# Clear LuCI cache
|
||||||
|
rm -rf /tmp/luci-*
|
||||||
|
echo "✓ Cleared LuCI cache"
|
||||||
|
|
||||||
|
# Test
|
||||||
|
sleep 2
|
||||||
|
if ubus list luci.$TARGET_MODULE > /dev/null 2>&1; then
|
||||||
|
echo "✓ Module $TARGET_MODULE is now registered!"
|
||||||
|
ubus -v list luci.$TARGET_MODULE
|
||||||
|
else
|
||||||
|
echo "✗ Module still not working. Check logs:"
|
||||||
|
echo " logread | grep -i rpcd"
|
||||||
|
echo " logread | grep -i $TARGET_MODULE"
|
||||||
|
fi
|
||||||
|
FIXEOF
|
||||||
|
|
||||||
|
chmod +x "$FIX_SCRIPT"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo " Generated fix script: ${GREEN}$FIX_SCRIPT${NC}"
|
||||||
|
echo ""
|
||||||
|
echo " Run it with: ${CYAN}sh $FIX_SCRIPT${NC}"
|
||||||
|
echo ""
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# Summary
|
||||||
|
# ============================================
|
||||||
|
print_section "Quick Commands"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo " ${CYAN}Debug specific module:${NC}"
|
||||||
|
echo " ./secubox-debug.sh vhost-manager"
|
||||||
|
echo ""
|
||||||
|
echo " ${CYAN}List all ubus objects:${NC}"
|
||||||
|
echo " ubus list | grep luci"
|
||||||
|
echo ""
|
||||||
|
echo " ${CYAN}Test RPC call:${NC}"
|
||||||
|
echo " ubus call luci.vhost-manager status"
|
||||||
|
echo ""
|
||||||
|
echo " ${CYAN}View RPCD logs:${NC}"
|
||||||
|
echo " logread | grep -E '(rpcd|ubus)'"
|
||||||
|
echo ""
|
||||||
|
echo " ${CYAN}Full restart:${NC}"
|
||||||
|
echo " /etc/init.d/rpcd restart && rm -rf /tmp/luci-* && /etc/init.d/uhttpd restart"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo "${CYAN}╔══════════════════════════════════════════════════════════════╗${NC}"
|
||||||
|
echo "${CYAN}║ Debug Complete ║${NC}"
|
||||||
|
echo "${CYAN}╚══════════════════════════════════════════════════════════════╝${NC}"
|
||||||
|
echo ""
|
||||||
1109
secubox-repair.sh
Executable file
1109
secubox-repair.sh
Executable file
File diff suppressed because it is too large
Load Diff
35
secubox-tools/acl/luci-app-vhost-manager.json
Normal file
35
secubox-tools/acl/luci-app-vhost-manager.json
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
{
|
||||||
|
"luci-app-vhost-manager": {
|
||||||
|
"description": "Grant access to VHost Manager",
|
||||||
|
"read": {
|
||||||
|
"ubus": {
|
||||||
|
"luci.vhost-manager": [
|
||||||
|
"status",
|
||||||
|
"get_vhosts",
|
||||||
|
"get_vhost",
|
||||||
|
"get_certificates",
|
||||||
|
"test_config"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"uci": ["vhost_manager", "nginx"],
|
||||||
|
"file": {
|
||||||
|
"/etc/nginx/conf.d/*": ["read"],
|
||||||
|
"/etc/acme/*": ["read"]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"write": {
|
||||||
|
"ubus": {
|
||||||
|
"luci.vhost-manager": [
|
||||||
|
"add_vhost",
|
||||||
|
"delete_vhost",
|
||||||
|
"request_certificate",
|
||||||
|
"reload_nginx"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"uci": ["vhost_manager", "nginx"],
|
||||||
|
"file": {
|
||||||
|
"/etc/nginx/conf.d/*": ["write"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
147
secubox-tools/cleanup-packages.sh
Executable file
147
secubox-tools/cleanup-packages.sh
Executable file
@ -0,0 +1,147 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# cleanup-packages.sh
|
||||||
|
# Script to fix common issues in SecuBox package structure
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
echo "🧹 SecuBox Package Cleanup Script"
|
||||||
|
echo "=================================="
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
ERRORS=0
|
||||||
|
FIXES=0
|
||||||
|
|
||||||
|
# 1. Remove malformed {htdocs directories
|
||||||
|
echo "📁 Checking for malformed directories..."
|
||||||
|
for pkg in luci-app-*/; do
|
||||||
|
if [[ -d "${pkg}{htdocs" ]]; then
|
||||||
|
echo " ❌ Found malformed directory: ${pkg}{htdocs"
|
||||||
|
echo " → Removing..."
|
||||||
|
rm -rf "${pkg}{htdocs"
|
||||||
|
FIXES=$((FIXES + 1))
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# 2. Ensure htdocs structure exists
|
||||||
|
echo ""
|
||||||
|
echo "📁 Checking htdocs structure..."
|
||||||
|
for pkg in luci-app-*/; do
|
||||||
|
if [[ -d "$pkg" ]]; then
|
||||||
|
PKG_NAME=$(basename "$pkg")
|
||||||
|
|
||||||
|
# Create htdocs structure if missing
|
||||||
|
if [[ ! -d "${pkg}htdocs/luci-static/resources/view" ]]; then
|
||||||
|
echo " ⚠️ Missing htdocs structure in $PKG_NAME"
|
||||||
|
mkdir -p "${pkg}htdocs/luci-static/resources/view"
|
||||||
|
FIXES=$((FIXES + 1))
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# 3. Fix file permissions
|
||||||
|
echo ""
|
||||||
|
echo "🔐 Fixing file permissions..."
|
||||||
|
for pkg in luci-app-*/; do
|
||||||
|
# RPCD scripts
|
||||||
|
if [[ -d "${pkg}root/usr/libexec/rpcd" ]]; then
|
||||||
|
for script in "${pkg}root/usr/libexec/rpcd/"*; do
|
||||||
|
if [[ -f "$script" && ! -x "$script" ]]; then
|
||||||
|
echo " → Making executable: $script"
|
||||||
|
chmod +x "$script"
|
||||||
|
FIXES=$((FIXES + 1))
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Init scripts
|
||||||
|
if [[ -d "${pkg}root/etc/init.d" ]]; then
|
||||||
|
for script in "${pkg}root/etc/init.d/"*; do
|
||||||
|
if [[ -f "$script" && ! -x "$script" ]]; then
|
||||||
|
echo " → Making executable: $script"
|
||||||
|
chmod +x "$script"
|
||||||
|
FIXES=$((FIXES + 1))
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
# UCI defaults
|
||||||
|
if [[ -d "${pkg}root/etc/uci-defaults" ]]; then
|
||||||
|
for script in "${pkg}root/etc/uci-defaults/"*; do
|
||||||
|
if [[ -f "$script" && ! -x "$script" ]]; then
|
||||||
|
echo " → Making executable: $script"
|
||||||
|
chmod +x "$script"
|
||||||
|
FIXES=$((FIXES + 1))
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# 4. Validate Makefiles
|
||||||
|
echo ""
|
||||||
|
echo "📋 Validating Makefiles..."
|
||||||
|
for makefile in luci-app-*/Makefile; do
|
||||||
|
if [[ -f "$makefile" ]]; then
|
||||||
|
PKG=$(dirname "$makefile")
|
||||||
|
PKG_NAME=$(basename "$PKG")
|
||||||
|
|
||||||
|
# Check PKG_NAME matches directory
|
||||||
|
MAKEFILE_PKG_NAME=$(grep "^PKG_NAME:=" "$makefile" | cut -d'=' -f2)
|
||||||
|
if [[ "$MAKEFILE_PKG_NAME" != "$PKG_NAME" ]]; then
|
||||||
|
echo " ❌ PKG_NAME mismatch in $PKG_NAME"
|
||||||
|
echo " Directory: $PKG_NAME"
|
||||||
|
echo " Makefile: $MAKEFILE_PKG_NAME"
|
||||||
|
ERRORS=$((ERRORS + 1))
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check required fields
|
||||||
|
for field in PKG_VERSION PKG_RELEASE PKG_LICENSE; do
|
||||||
|
if ! grep -q "^${field}:=" "$makefile"; then
|
||||||
|
echo " ⚠️ Missing $field in $PKG_NAME/Makefile"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# Check include statement
|
||||||
|
if ! grep -q "include.*luci.mk" "$makefile"; then
|
||||||
|
echo " ⚠️ Missing 'include \$(TOPDIR)/feeds/luci/luci.mk' in $PKG_NAME"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# 5. Check for required directories
|
||||||
|
echo ""
|
||||||
|
echo "📂 Checking required structure..."
|
||||||
|
for pkg in luci-app-*/; do
|
||||||
|
if [[ -d "$pkg" ]]; then
|
||||||
|
PKG_NAME=$(basename "$pkg")
|
||||||
|
|
||||||
|
REQUIRED_DIRS=(
|
||||||
|
"root/usr/share/luci/menu.d"
|
||||||
|
"root/usr/share/rpcd/acl.d"
|
||||||
|
)
|
||||||
|
|
||||||
|
for dir in "${REQUIRED_DIRS[@]}"; do
|
||||||
|
if [[ ! -d "${pkg}${dir}" ]]; then
|
||||||
|
echo " ⚠️ Creating missing: ${PKG_NAME}/${dir}"
|
||||||
|
mkdir -p "${pkg}${dir}"
|
||||||
|
FIXES=$((FIXES + 1))
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# 6. Summary
|
||||||
|
echo ""
|
||||||
|
echo "=================================="
|
||||||
|
echo "📊 Summary"
|
||||||
|
echo "=================================="
|
||||||
|
echo "Fixes applied: $FIXES"
|
||||||
|
echo "Errors found: $ERRORS"
|
||||||
|
|
||||||
|
if [[ $ERRORS -gt 0 ]]; then
|
||||||
|
echo ""
|
||||||
|
echo "⚠️ Please fix the errors above manually"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "✅ Cleanup complete!"
|
||||||
97
secubox-tools/fix-makefiles.sh
Executable file
97
secubox-tools/fix-makefiles.sh
Executable file
@ -0,0 +1,97 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# fix-makefiles.sh
|
||||||
|
# Script to fix Makefiles for OpenWrt LuCI packages
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
echo "🔧 SecuBox Makefile Fixer"
|
||||||
|
echo "========================="
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
FIXED=0
|
||||||
|
SKIPPED=0
|
||||||
|
|
||||||
|
for makefile in luci-app-*/Makefile; do
|
||||||
|
if [[ ! -f "$makefile" ]]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
PKG_DIR=$(dirname "$makefile")
|
||||||
|
PKG_NAME=$(basename "$PKG_DIR")
|
||||||
|
|
||||||
|
echo "📦 Processing: $PKG_NAME"
|
||||||
|
|
||||||
|
# Check if already has luci.mk include
|
||||||
|
if grep -q 'include.*feeds/luci/luci\.mk' "$makefile"; then
|
||||||
|
echo " ✅ Already has luci.mk include"
|
||||||
|
SKIPPED=$((SKIPPED + 1))
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if has package.mk include (alternative valid format)
|
||||||
|
if grep -q 'include.*package\.mk' "$makefile" && grep -q 'BuildPackage' "$makefile"; then
|
||||||
|
echo " ✅ Uses package.mk with BuildPackage (valid)"
|
||||||
|
SKIPPED=$((SKIPPED + 1))
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Need to fix - create backup first
|
||||||
|
cp "$makefile" "${makefile}.bak"
|
||||||
|
|
||||||
|
# Extract existing values
|
||||||
|
PKG_VERSION=$(grep "^PKG_VERSION:=" "$makefile" | cut -d'=' -f2 || echo "1.0.0")
|
||||||
|
PKG_RELEASE=$(grep "^PKG_RELEASE:=" "$makefile" | cut -d'=' -f2 || echo "1")
|
||||||
|
PKG_LICENSE=$(grep "^PKG_LICENSE:=" "$makefile" | cut -d'=' -f2 || echo "Apache-2.0")
|
||||||
|
LUCI_TITLE=$(grep "^LUCI_TITLE:=" "$makefile" | cut -d'=' -f2- || echo "LuCI - $PKG_NAME")
|
||||||
|
LUCI_DEPENDS=$(grep "^LUCI_DEPENDS:=" "$makefile" | cut -d'=' -f2- || echo "+luci-base")
|
||||||
|
|
||||||
|
# If no LUCI_TITLE, try to extract from define Package section
|
||||||
|
if [[ -z "$LUCI_TITLE" || "$LUCI_TITLE" == "LuCI - $PKG_NAME" ]]; then
|
||||||
|
TITLE_LINE=$(grep -A5 "define Package/" "$makefile" | grep "TITLE" | head -1 | cut -d'=' -f2-)
|
||||||
|
if [[ -n "$TITLE_LINE" ]]; then
|
||||||
|
LUCI_TITLE="$TITLE_LINE"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Generate new Makefile
|
||||||
|
cat > "$makefile" << MAKEFILE_EOF
|
||||||
|
include \$(TOPDIR)/rules.mk
|
||||||
|
|
||||||
|
PKG_NAME:=${PKG_NAME}
|
||||||
|
PKG_VERSION:=${PKG_VERSION:-1.0.0}
|
||||||
|
PKG_RELEASE:=${PKG_RELEASE:-1}
|
||||||
|
PKG_LICENSE:=${PKG_LICENSE:-Apache-2.0}
|
||||||
|
PKG_MAINTAINER:=CyberMind <contact@cybermind.fr>
|
||||||
|
|
||||||
|
LUCI_TITLE:=${LUCI_TITLE:-LuCI - SecuBox Module}
|
||||||
|
LUCI_DEPENDS:=${LUCI_DEPENDS:-+luci-base}
|
||||||
|
LUCI_PKGARCH:=all
|
||||||
|
|
||||||
|
include \$(TOPDIR)/feeds/luci/luci.mk
|
||||||
|
|
||||||
|
# call BuildPackage - OpenWrt buildance
|
||||||
|
MAKEFILE_EOF
|
||||||
|
|
||||||
|
echo " 🔧 Fixed Makefile (backup: ${makefile}.bak)"
|
||||||
|
FIXED=$((FIXED + 1))
|
||||||
|
|
||||||
|
done
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "========================="
|
||||||
|
echo "📊 Summary"
|
||||||
|
echo "========================="
|
||||||
|
echo "Fixed: $FIXED"
|
||||||
|
echo "Skipped: $SKIPPED"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
if [[ $FIXED -gt 0 ]]; then
|
||||||
|
echo "⚠️ Review the fixed Makefiles and adjust LUCI_TITLE and LUCI_DEPENDS as needed"
|
||||||
|
echo ""
|
||||||
|
echo "📝 Example correct values:"
|
||||||
|
echo " LUCI_TITLE:=LuCI - CrowdSec Security Dashboard"
|
||||||
|
echo " LUCI_DEPENDS:=+luci-base +rpcd +curl"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "✅ Done!"
|
||||||
269
secubox-tools/generate-rpcd-files.sh
Executable file
269
secubox-tools/generate-rpcd-files.sh
Executable file
@ -0,0 +1,269 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# generate-rpcd-files.sh
|
||||||
|
# Generate missing RPCD scripts and ACL files for SecuBox modules
|
||||||
|
#
|
||||||
|
# Usage: ./generate-rpcd-files.sh <module-name>
|
||||||
|
# Example: ./generate-rpcd-files.sh vhost-manager
|
||||||
|
|
||||||
|
MODULE="$1"
|
||||||
|
|
||||||
|
if [ -z "$MODULE" ]; then
|
||||||
|
echo "Usage: $0 <module-name>"
|
||||||
|
echo "Example: $0 vhost-manager"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Convert module name for different uses
|
||||||
|
# vhost-manager -> vhost_manager (for shell variables)
|
||||||
|
# vhost-manager -> vhost-manager (for ubus)
|
||||||
|
MODULE_UNDERSCORE=$(echo "$MODULE" | tr '-' '_')
|
||||||
|
UBUS_NAME="luci.$MODULE"
|
||||||
|
PKG_NAME="luci-app-$MODULE"
|
||||||
|
|
||||||
|
echo "╔══════════════════════════════════════════════════════════════╗"
|
||||||
|
echo "║ Generating RPCD files for: $MODULE"
|
||||||
|
echo "╚══════════════════════════════════════════════════════════════╝"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# Create RPCD script
|
||||||
|
# ============================================
|
||||||
|
RPCD_SCRIPT="/usr/libexec/rpcd/$MODULE"
|
||||||
|
|
||||||
|
echo "→ Creating RPCD script: $RPCD_SCRIPT"
|
||||||
|
|
||||||
|
cat > "$RPCD_SCRIPT" << 'RPCD_EOF'
|
||||||
|
#!/bin/sh
|
||||||
|
# RPCD backend for MODULE_PLACEHOLDER
|
||||||
|
# Provides ubus interface: luci.MODULE_PLACEHOLDER
|
||||||
|
|
||||||
|
. /lib/functions.sh
|
||||||
|
. /usr/share/libubox/jshn.sh
|
||||||
|
|
||||||
|
# Initialize JSON
|
||||||
|
json_init
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
list)
|
||||||
|
# List available methods
|
||||||
|
json_add_object "status"
|
||||||
|
json_close_object
|
||||||
|
json_add_object "get_config"
|
||||||
|
json_close_object
|
||||||
|
json_add_object "set_config"
|
||||||
|
json_add_string "config" "object"
|
||||||
|
json_close_object
|
||||||
|
json_add_object "get_stats"
|
||||||
|
json_close_object
|
||||||
|
json_dump
|
||||||
|
;;
|
||||||
|
|
||||||
|
call)
|
||||||
|
case "$2" in
|
||||||
|
status)
|
||||||
|
# Return module status
|
||||||
|
json_add_boolean "enabled" 1
|
||||||
|
json_add_string "status" "running"
|
||||||
|
json_add_string "version" "2.0.0"
|
||||||
|
json_add_string "module" "MODULE_PLACEHOLDER"
|
||||||
|
|
||||||
|
# Check if service is running (customize per module)
|
||||||
|
# Example: check nginx for vhost-manager
|
||||||
|
# if pgrep -x nginx > /dev/null 2>&1; then
|
||||||
|
# json_add_boolean "service_running" 1
|
||||||
|
# else
|
||||||
|
# json_add_boolean "service_running" 0
|
||||||
|
# fi
|
||||||
|
|
||||||
|
json_add_boolean "service_running" 1
|
||||||
|
json_dump
|
||||||
|
;;
|
||||||
|
|
||||||
|
get_config)
|
||||||
|
# Return current configuration
|
||||||
|
json_add_object "config"
|
||||||
|
|
||||||
|
# Read from UCI if available
|
||||||
|
if [ -f "/etc/config/MODULE_UNDERSCORE_PLACEHOLDER" ]; then
|
||||||
|
config_load "MODULE_UNDERSCORE_PLACEHOLDER"
|
||||||
|
# Add config values here
|
||||||
|
json_add_boolean "enabled" 1
|
||||||
|
else
|
||||||
|
json_add_boolean "enabled" 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
json_close_object
|
||||||
|
json_dump
|
||||||
|
;;
|
||||||
|
|
||||||
|
set_config)
|
||||||
|
# Set configuration
|
||||||
|
read -r input
|
||||||
|
|
||||||
|
# Parse input JSON
|
||||||
|
json_load "$input"
|
||||||
|
json_get_var config config
|
||||||
|
|
||||||
|
# Apply configuration via UCI
|
||||||
|
# uci set MODULE_UNDERSCORE_PLACEHOLDER.global.enabled="$enabled"
|
||||||
|
# uci commit MODULE_UNDERSCORE_PLACEHOLDER
|
||||||
|
|
||||||
|
json_init
|
||||||
|
json_add_boolean "success" 1
|
||||||
|
json_add_string "message" "Configuration updated"
|
||||||
|
json_dump
|
||||||
|
;;
|
||||||
|
|
||||||
|
get_stats)
|
||||||
|
# Return statistics
|
||||||
|
json_add_object "stats"
|
||||||
|
json_add_int "uptime" "$(cat /proc/uptime | cut -d. -f1)"
|
||||||
|
json_add_string "timestamp" "$(date -Iseconds)"
|
||||||
|
json_close_object
|
||||||
|
json_dump
|
||||||
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
# Unknown method
|
||||||
|
json_add_int "error" -32601
|
||||||
|
json_add_string "message" "Method not found"
|
||||||
|
json_dump
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
RPCD_EOF
|
||||||
|
|
||||||
|
# Replace placeholders
|
||||||
|
sed -i "s/MODULE_PLACEHOLDER/$MODULE/g" "$RPCD_SCRIPT"
|
||||||
|
sed -i "s/MODULE_UNDERSCORE_PLACEHOLDER/$MODULE_UNDERSCORE/g" "$RPCD_SCRIPT"
|
||||||
|
|
||||||
|
chmod +x "$RPCD_SCRIPT"
|
||||||
|
echo " ✓ Created and made executable"
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# Create ACL file
|
||||||
|
# ============================================
|
||||||
|
ACL_FILE="/usr/share/rpcd/acl.d/${PKG_NAME}.json"
|
||||||
|
|
||||||
|
echo "→ Creating ACL file: $ACL_FILE"
|
||||||
|
|
||||||
|
cat > "$ACL_FILE" << ACL_EOF
|
||||||
|
{
|
||||||
|
"luci-app-$MODULE": {
|
||||||
|
"description": "Grant access to LuCI app $MODULE",
|
||||||
|
"read": {
|
||||||
|
"ubus": {
|
||||||
|
"$UBUS_NAME": ["status", "get_config", "get_stats"]
|
||||||
|
},
|
||||||
|
"uci": ["$MODULE_UNDERSCORE"]
|
||||||
|
},
|
||||||
|
"write": {
|
||||||
|
"ubus": {
|
||||||
|
"$UBUS_NAME": ["set_config"]
|
||||||
|
},
|
||||||
|
"uci": ["$MODULE_UNDERSCORE"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ACL_EOF
|
||||||
|
|
||||||
|
echo " ✓ Created ACL file"
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# Create Menu file (if not exists)
|
||||||
|
# ============================================
|
||||||
|
MENU_FILE="/usr/share/luci/menu.d/${PKG_NAME}.json"
|
||||||
|
|
||||||
|
if [ ! -f "$MENU_FILE" ]; then
|
||||||
|
echo "→ Creating Menu file: $MENU_FILE"
|
||||||
|
|
||||||
|
# Convert module name to title
|
||||||
|
TITLE=$(echo "$MODULE" | sed 's/-/ /g' | awk '{for(i=1;i<=NF;i++) $i=toupper(substr($i,1,1)) tolower(substr($i,2))}1')
|
||||||
|
|
||||||
|
cat > "$MENU_FILE" << MENU_EOF
|
||||||
|
{
|
||||||
|
"admin/services/$MODULE_UNDERSCORE": {
|
||||||
|
"title": "$TITLE",
|
||||||
|
"order": 50,
|
||||||
|
"action": {
|
||||||
|
"type": "view",
|
||||||
|
"path": "$MODULE/main"
|
||||||
|
},
|
||||||
|
"depends": {
|
||||||
|
"acl": ["luci-app-$MODULE"],
|
||||||
|
"uci": {
|
||||||
|
"$MODULE_UNDERSCORE": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MENU_EOF
|
||||||
|
|
||||||
|
echo " ✓ Created menu file"
|
||||||
|
else
|
||||||
|
echo "→ Menu file already exists: $MENU_FILE"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# Create UCI config (if not exists)
|
||||||
|
# ============================================
|
||||||
|
UCI_CONFIG="/etc/config/$MODULE_UNDERSCORE"
|
||||||
|
|
||||||
|
if [ ! -f "$UCI_CONFIG" ]; then
|
||||||
|
echo "→ Creating UCI config: $UCI_CONFIG"
|
||||||
|
|
||||||
|
cat > "$UCI_CONFIG" << UCI_EOF
|
||||||
|
config global 'global'
|
||||||
|
option enabled '1'
|
||||||
|
option version '2.0.0'
|
||||||
|
UCI_EOF
|
||||||
|
|
||||||
|
echo " ✓ Created UCI config"
|
||||||
|
else
|
||||||
|
echo "→ UCI config already exists: $UCI_CONFIG"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# Restart services
|
||||||
|
# ============================================
|
||||||
|
echo ""
|
||||||
|
echo "→ Restarting rpcd..."
|
||||||
|
/etc/init.d/rpcd restart
|
||||||
|
|
||||||
|
echo "→ Clearing LuCI cache..."
|
||||||
|
rm -rf /tmp/luci-*
|
||||||
|
|
||||||
|
# Wait for rpcd to initialize
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# Verify
|
||||||
|
# ============================================
|
||||||
|
echo ""
|
||||||
|
echo "╔══════════════════════════════════════════════════════════════╗"
|
||||||
|
echo "║ Verification"
|
||||||
|
echo "╚══════════════════════════════════════════════════════════════╝"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Check ubus registration
|
||||||
|
if ubus list "$UBUS_NAME" > /dev/null 2>&1; then
|
||||||
|
echo "✓ $UBUS_NAME is registered in ubus"
|
||||||
|
echo ""
|
||||||
|
echo "Available methods:"
|
||||||
|
ubus -v list "$UBUS_NAME"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "Testing status call:"
|
||||||
|
ubus call "$UBUS_NAME" status
|
||||||
|
else
|
||||||
|
echo "✗ $UBUS_NAME is NOT registered"
|
||||||
|
echo ""
|
||||||
|
echo "Debug steps:"
|
||||||
|
echo " 1. Check script: cat $RPCD_SCRIPT"
|
||||||
|
echo " 2. Test manually: echo '{\"method\":\"list\"}' | $RPCD_SCRIPT"
|
||||||
|
echo " 3. Check logs: logread | grep rpcd"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "Done!"
|
||||||
129
secubox-tools/install-rpcd-fix.sh
Executable file
129
secubox-tools/install-rpcd-fix.sh
Executable file
@ -0,0 +1,129 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# install-rpcd-fix.sh
|
||||||
|
# Quick installation script for SecuBox RPCD fixes
|
||||||
|
#
|
||||||
|
# Upload this script along with rpcd/ and acl/ folders to the router
|
||||||
|
# then run: sh install-rpcd-fix.sh
|
||||||
|
|
||||||
|
echo "╔══════════════════════════════════════════════════════════════╗"
|
||||||
|
echo "║ SecuBox RPCD Fix Installer ║"
|
||||||
|
echo "╚══════════════════════════════════════════════════════════════╝"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
|
||||||
|
|
||||||
|
# Check if running as root
|
||||||
|
if [ "$(id -u)" != "0" ]; then
|
||||||
|
echo "Error: This script must be run as root"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# Install RPCD scripts
|
||||||
|
# ============================================
|
||||||
|
echo "→ Installing RPCD scripts..."
|
||||||
|
|
||||||
|
if [ -d "$SCRIPT_DIR/rpcd" ]; then
|
||||||
|
for script in "$SCRIPT_DIR/rpcd"/*; do
|
||||||
|
[ -f "$script" ] || continue
|
||||||
|
|
||||||
|
NAME=$(basename "$script")
|
||||||
|
DEST="/usr/libexec/rpcd/$NAME"
|
||||||
|
|
||||||
|
cp "$script" "$DEST"
|
||||||
|
chmod +x "$DEST"
|
||||||
|
echo " ✓ Installed: $DEST"
|
||||||
|
done
|
||||||
|
else
|
||||||
|
echo " ⚠ No rpcd/ directory found"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# Install ACL files
|
||||||
|
# ============================================
|
||||||
|
echo ""
|
||||||
|
echo "→ Installing ACL files..."
|
||||||
|
|
||||||
|
mkdir -p /usr/share/rpcd/acl.d
|
||||||
|
|
||||||
|
if [ -d "$SCRIPT_DIR/acl" ]; then
|
||||||
|
for acl in "$SCRIPT_DIR/acl"/*.json; do
|
||||||
|
[ -f "$acl" ] || continue
|
||||||
|
|
||||||
|
NAME=$(basename "$acl")
|
||||||
|
DEST="/usr/share/rpcd/acl.d/$NAME"
|
||||||
|
|
||||||
|
cp "$acl" "$DEST"
|
||||||
|
echo " ✓ Installed: $DEST"
|
||||||
|
done
|
||||||
|
else
|
||||||
|
echo " ⚠ No acl/ directory found"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# Create missing UCI configs
|
||||||
|
# ============================================
|
||||||
|
echo ""
|
||||||
|
echo "→ Creating UCI configs..."
|
||||||
|
|
||||||
|
# vhost_manager
|
||||||
|
if [ ! -f /etc/config/vhost_manager ]; then
|
||||||
|
cat > /etc/config/vhost_manager << 'EOF'
|
||||||
|
config global 'global'
|
||||||
|
option enabled '1'
|
||||||
|
option nginx_dir '/etc/nginx/conf.d'
|
||||||
|
option acme_dir '/etc/acme'
|
||||||
|
EOF
|
||||||
|
echo " ✓ Created: /etc/config/vhost_manager"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# Restart services
|
||||||
|
# ============================================
|
||||||
|
echo ""
|
||||||
|
echo "→ Restarting services..."
|
||||||
|
|
||||||
|
# Restart rpcd
|
||||||
|
/etc/init.d/rpcd restart
|
||||||
|
echo " ✓ rpcd restarted"
|
||||||
|
|
||||||
|
# Clear LuCI cache
|
||||||
|
rm -rf /tmp/luci-*
|
||||||
|
echo " ✓ LuCI cache cleared"
|
||||||
|
|
||||||
|
# Wait for rpcd to initialize
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# Verify installation
|
||||||
|
# ============================================
|
||||||
|
echo ""
|
||||||
|
echo "╔══════════════════════════════════════════════════════════════╗"
|
||||||
|
echo "║ Verification ║"
|
||||||
|
echo "╚══════════════════════════════════════════════════════════════╝"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# List installed modules
|
||||||
|
echo "Checking ubus registration:"
|
||||||
|
|
||||||
|
MODULES="vhost-manager secubox bandwidth-manager auth-guardian media-flow"
|
||||||
|
|
||||||
|
for module in $MODULES; do
|
||||||
|
UBUS_NAME="luci.$module"
|
||||||
|
if ubus list "$UBUS_NAME" > /dev/null 2>&1; then
|
||||||
|
echo " ✓ $UBUS_NAME"
|
||||||
|
else
|
||||||
|
echo " ✗ $UBUS_NAME (not registered)"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "Testing vhost-manager status:"
|
||||||
|
ubus call luci.vhost-manager status 2>/dev/null || echo " ✗ Failed"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "Installation complete!"
|
||||||
|
echo ""
|
||||||
|
echo "If modules are still not working, check:"
|
||||||
|
echo " logread | grep rpcd"
|
||||||
|
echo " logread | grep ubus"
|
||||||
16
secubox-tools/makefiles/luci-app-auth-guardian/Makefile
Normal file
16
secubox-tools/makefiles/luci-app-auth-guardian/Makefile
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
|
PKG_NAME:=luci-app-auth-guardian
|
||||||
|
PKG_VERSION:=2.0.0
|
||||||
|
PKG_RELEASE:=1
|
||||||
|
PKG_LICENSE:=Apache-2.0
|
||||||
|
PKG_MAINTAINER:=CyberMind <contact@cybermind.fr>
|
||||||
|
|
||||||
|
LUCI_TITLE:=LuCI - Auth Guardian (Captive Portal & OAuth)
|
||||||
|
LUCI_DESCRIPTION:=Authentication system with captive portal, OAuth2 (Google, GitHub), voucher management, and session control for SecuBox.
|
||||||
|
LUCI_DEPENDS:=+luci-base +rpcd +curl +nodogsplash
|
||||||
|
LUCI_PKGARCH:=all
|
||||||
|
|
||||||
|
include $(TOPDIR)/feeds/luci/luci.mk
|
||||||
|
|
||||||
|
# call BuildPackage - OpenWrt buildroot
|
||||||
16
secubox-tools/makefiles/luci-app-bandwidth-manager/Makefile
Normal file
16
secubox-tools/makefiles/luci-app-bandwidth-manager/Makefile
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
|
PKG_NAME:=luci-app-bandwidth-manager
|
||||||
|
PKG_VERSION:=2.0.0
|
||||||
|
PKG_RELEASE:=1
|
||||||
|
PKG_LICENSE:=Apache-2.0
|
||||||
|
PKG_MAINTAINER:=CyberMind <contact@cybermind.fr>
|
||||||
|
|
||||||
|
LUCI_TITLE:=LuCI - Bandwidth Manager (QoS & Quotas)
|
||||||
|
LUCI_DESCRIPTION:=Advanced bandwidth management with CAKE QoS, per-client quotas, automatic media detection, and traffic scheduling for SecuBox.
|
||||||
|
LUCI_DEPENDS:=+luci-base +rpcd +tc-full +kmod-sched-cake +sqm-scripts
|
||||||
|
LUCI_PKGARCH:=all
|
||||||
|
|
||||||
|
include $(TOPDIR)/feeds/luci/luci.mk
|
||||||
|
|
||||||
|
# call BuildPackage - OpenWrt buildroot
|
||||||
16
secubox-tools/makefiles/luci-app-media-flow/Makefile
Normal file
16
secubox-tools/makefiles/luci-app-media-flow/Makefile
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
|
PKG_NAME:=luci-app-media-flow
|
||||||
|
PKG_VERSION:=2.0.0
|
||||||
|
PKG_RELEASE:=1
|
||||||
|
PKG_LICENSE:=Apache-2.0
|
||||||
|
PKG_MAINTAINER:=CyberMind <contact@cybermind.fr>
|
||||||
|
|
||||||
|
LUCI_TITLE:=LuCI - Media Flow (Streaming Detection)
|
||||||
|
LUCI_DESCRIPTION:=Real-time streaming service detection and monitoring for Netflix, YouTube, Twitch, Zoom, Teams with quality indicators for SecuBox.
|
||||||
|
LUCI_DEPENDS:=+luci-base +rpcd +netifyd
|
||||||
|
LUCI_PKGARCH:=all
|
||||||
|
|
||||||
|
include $(TOPDIR)/feeds/luci/luci.mk
|
||||||
|
|
||||||
|
# call BuildPackage - OpenWrt buildroot
|
||||||
16
secubox-tools/makefiles/luci-app-secubox/Makefile
Normal file
16
secubox-tools/makefiles/luci-app-secubox/Makefile
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
|
PKG_NAME:=luci-app-secubox
|
||||||
|
PKG_VERSION:=2.0.0
|
||||||
|
PKG_RELEASE:=1
|
||||||
|
PKG_LICENSE:=Apache-2.0
|
||||||
|
PKG_MAINTAINER:=CyberMind <contact@cybermind.fr>
|
||||||
|
|
||||||
|
LUCI_TITLE:=LuCI - SecuBox Hub (Central Dashboard)
|
||||||
|
LUCI_DESCRIPTION:=Central control hub for all SecuBox modules. Provides unified dashboard, module status, system health monitoring, and quick actions.
|
||||||
|
LUCI_DEPENDS:=+luci-base +rpcd +curl +jq
|
||||||
|
LUCI_PKGARCH:=all
|
||||||
|
|
||||||
|
include $(TOPDIR)/feeds/luci/luci.mk
|
||||||
|
|
||||||
|
# call BuildPackage - OpenWrt buildroot
|
||||||
16
secubox-tools/makefiles/luci-app-vhost-manager/Makefile
Normal file
16
secubox-tools/makefiles/luci-app-vhost-manager/Makefile
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
|
PKG_NAME:=luci-app-vhost-manager
|
||||||
|
PKG_VERSION:=2.0.0
|
||||||
|
PKG_RELEASE:=1
|
||||||
|
PKG_LICENSE:=Apache-2.0
|
||||||
|
PKG_MAINTAINER:=CyberMind <contact@cybermind.fr>
|
||||||
|
|
||||||
|
LUCI_TITLE:=LuCI - VHost Manager (Reverse Proxy & SSL)
|
||||||
|
LUCI_DESCRIPTION:=Virtual host manager for local services like Nextcloud, GitLab, Jellyfin with nginx reverse proxy and automatic SSL certificates for SecuBox.
|
||||||
|
LUCI_DEPENDS:=+luci-base +rpcd +nginx-ssl +acme +acme-acmesh
|
||||||
|
LUCI_PKGARCH:=all
|
||||||
|
|
||||||
|
include $(TOPDIR)/feeds/luci/luci.mk
|
||||||
|
|
||||||
|
# call BuildPackage - OpenWrt buildroot
|
||||||
334
secubox-tools/rpcd/vhost-manager
Normal file
334
secubox-tools/rpcd/vhost-manager
Normal file
@ -0,0 +1,334 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# /usr/libexec/rpcd/vhost-manager
|
||||||
|
# RPCD backend for VHost Manager module
|
||||||
|
# Provides ubus interface: luci.vhost-manager
|
||||||
|
|
||||||
|
. /lib/functions.sh
|
||||||
|
. /usr/share/libubox/jshn.sh
|
||||||
|
|
||||||
|
# Configuration
|
||||||
|
UCI_CONFIG="vhost_manager"
|
||||||
|
NGINX_VHOSTS_DIR="/etc/nginx/conf.d"
|
||||||
|
ACME_DIR="/etc/acme"
|
||||||
|
|
||||||
|
# Helper: Check if nginx is running
|
||||||
|
nginx_running() {
|
||||||
|
pgrep -x nginx > /dev/null 2>&1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Helper: Get nginx status
|
||||||
|
get_nginx_status() {
|
||||||
|
if nginx_running; then
|
||||||
|
echo "running"
|
||||||
|
else
|
||||||
|
echo "stopped"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Helper: Count vhosts
|
||||||
|
count_vhosts() {
|
||||||
|
if [ -d "$NGINX_VHOSTS_DIR" ]; then
|
||||||
|
ls -1 "$NGINX_VHOSTS_DIR"/*.conf 2>/dev/null | wc -l
|
||||||
|
else
|
||||||
|
echo "0"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Helper: List vhosts
|
||||||
|
list_vhosts() {
|
||||||
|
json_add_array "vhosts"
|
||||||
|
|
||||||
|
if [ -d "$NGINX_VHOSTS_DIR" ]; then
|
||||||
|
for conf in "$NGINX_VHOSTS_DIR"/*.conf; do
|
||||||
|
[ -f "$conf" ] || continue
|
||||||
|
|
||||||
|
# Extract server_name from config
|
||||||
|
SERVER_NAME=$(grep -m1 "server_name" "$conf" | awk '{print $2}' | tr -d ';')
|
||||||
|
PROXY_PASS=$(grep -m1 "proxy_pass" "$conf" | awk '{print $2}' | tr -d ';')
|
||||||
|
SSL_ENABLED="false"
|
||||||
|
|
||||||
|
if grep -q "ssl_certificate" "$conf"; then
|
||||||
|
SSL_ENABLED="true"
|
||||||
|
fi
|
||||||
|
|
||||||
|
json_add_object ""
|
||||||
|
json_add_string "name" "$(basename "$conf" .conf)"
|
||||||
|
json_add_string "domain" "$SERVER_NAME"
|
||||||
|
json_add_string "backend" "$PROXY_PASS"
|
||||||
|
json_add_boolean "ssl" "$SSL_ENABLED"
|
||||||
|
json_add_boolean "enabled" 1
|
||||||
|
json_close_object
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
json_close_array
|
||||||
|
}
|
||||||
|
|
||||||
|
# Helper: Get SSL certificates
|
||||||
|
list_certificates() {
|
||||||
|
json_add_array "certificates"
|
||||||
|
|
||||||
|
if [ -d "$ACME_DIR" ]; then
|
||||||
|
for cert_dir in "$ACME_DIR"/*/; do
|
||||||
|
[ -d "$cert_dir" ] || continue
|
||||||
|
|
||||||
|
DOMAIN=$(basename "$cert_dir")
|
||||||
|
CERT_FILE="$cert_dir/fullchain.cer"
|
||||||
|
|
||||||
|
if [ -f "$CERT_FILE" ]; then
|
||||||
|
# Get expiry date
|
||||||
|
EXPIRY=$(openssl x509 -enddate -noout -in "$CERT_FILE" 2>/dev/null | cut -d= -f2)
|
||||||
|
|
||||||
|
json_add_object ""
|
||||||
|
json_add_string "domain" "$DOMAIN"
|
||||||
|
json_add_string "expiry" "$EXPIRY"
|
||||||
|
json_add_boolean "valid" 1
|
||||||
|
json_close_object
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
json_close_array
|
||||||
|
}
|
||||||
|
|
||||||
|
# Initialize JSON
|
||||||
|
json_init
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
list)
|
||||||
|
# List available methods
|
||||||
|
json_add_object "status"
|
||||||
|
json_close_object
|
||||||
|
|
||||||
|
json_add_object "get_vhosts"
|
||||||
|
json_close_object
|
||||||
|
|
||||||
|
json_add_object "get_vhost"
|
||||||
|
json_add_string "name" "string"
|
||||||
|
json_close_object
|
||||||
|
|
||||||
|
json_add_object "add_vhost"
|
||||||
|
json_add_string "domain" "string"
|
||||||
|
json_add_string "backend" "string"
|
||||||
|
json_add_boolean "ssl" false
|
||||||
|
json_close_object
|
||||||
|
|
||||||
|
json_add_object "delete_vhost"
|
||||||
|
json_add_string "name" "string"
|
||||||
|
json_close_object
|
||||||
|
|
||||||
|
json_add_object "get_certificates"
|
||||||
|
json_close_object
|
||||||
|
|
||||||
|
json_add_object "request_certificate"
|
||||||
|
json_add_string "domain" "string"
|
||||||
|
json_close_object
|
||||||
|
|
||||||
|
json_add_object "reload_nginx"
|
||||||
|
json_close_object
|
||||||
|
|
||||||
|
json_add_object "test_config"
|
||||||
|
json_close_object
|
||||||
|
|
||||||
|
json_dump
|
||||||
|
;;
|
||||||
|
|
||||||
|
call)
|
||||||
|
case "$2" in
|
||||||
|
status)
|
||||||
|
# Return module status
|
||||||
|
json_add_string "module" "vhost-manager"
|
||||||
|
json_add_string "version" "2.0.0"
|
||||||
|
json_add_string "nginx_status" "$(get_nginx_status)"
|
||||||
|
json_add_boolean "nginx_running" $(nginx_running && echo 1 || echo 0)
|
||||||
|
json_add_int "vhost_count" "$(count_vhosts)"
|
||||||
|
json_add_string "config_dir" "$NGINX_VHOSTS_DIR"
|
||||||
|
json_add_string "acme_dir" "$ACME_DIR"
|
||||||
|
|
||||||
|
# Check nginx version
|
||||||
|
if command -v nginx > /dev/null 2>&1; then
|
||||||
|
NGINX_VERSION=$(nginx -v 2>&1 | cut -d/ -f2)
|
||||||
|
json_add_string "nginx_version" "$NGINX_VERSION"
|
||||||
|
fi
|
||||||
|
|
||||||
|
json_dump
|
||||||
|
;;
|
||||||
|
|
||||||
|
get_vhosts)
|
||||||
|
# Return list of vhosts
|
||||||
|
list_vhosts
|
||||||
|
json_dump
|
||||||
|
;;
|
||||||
|
|
||||||
|
get_vhost)
|
||||||
|
# Get single vhost details
|
||||||
|
read -r input
|
||||||
|
json_load "$input"
|
||||||
|
json_get_var vhost_name name
|
||||||
|
|
||||||
|
CONF_FILE="$NGINX_VHOSTS_DIR/${vhost_name}.conf"
|
||||||
|
|
||||||
|
if [ -f "$CONF_FILE" ]; then
|
||||||
|
json_add_boolean "found" 1
|
||||||
|
json_add_string "name" "$vhost_name"
|
||||||
|
json_add_string "config" "$(cat "$CONF_FILE")"
|
||||||
|
else
|
||||||
|
json_add_boolean "found" 0
|
||||||
|
json_add_string "error" "VHost not found"
|
||||||
|
fi
|
||||||
|
|
||||||
|
json_dump
|
||||||
|
;;
|
||||||
|
|
||||||
|
add_vhost)
|
||||||
|
# Add new vhost
|
||||||
|
read -r input
|
||||||
|
json_load "$input"
|
||||||
|
json_get_var domain domain
|
||||||
|
json_get_var backend backend
|
||||||
|
json_get_var ssl ssl
|
||||||
|
|
||||||
|
# Validate
|
||||||
|
if [ -z "$domain" ] || [ -z "$backend" ]; then
|
||||||
|
json_init
|
||||||
|
json_add_boolean "success" 0
|
||||||
|
json_add_string "error" "Domain and backend are required"
|
||||||
|
json_dump
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Create config
|
||||||
|
VHOST_NAME=$(echo "$domain" | tr '.' '-')
|
||||||
|
CONF_FILE="$NGINX_VHOSTS_DIR/${VHOST_NAME}.conf"
|
||||||
|
|
||||||
|
mkdir -p "$NGINX_VHOSTS_DIR"
|
||||||
|
|
||||||
|
cat > "$CONF_FILE" << NGINX_EOF
|
||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
listen [::]:80;
|
||||||
|
server_name $domain;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
proxy_pass $backend;
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Host \$host;
|
||||||
|
proxy_set_header X-Real-IP \$remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Forwarded-Proto \$scheme;
|
||||||
|
proxy_set_header Upgrade \$http_upgrade;
|
||||||
|
proxy_set_header Connection "upgrade";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
NGINX_EOF
|
||||||
|
|
||||||
|
json_init
|
||||||
|
json_add_boolean "success" 1
|
||||||
|
json_add_string "message" "VHost created"
|
||||||
|
json_add_string "config_file" "$CONF_FILE"
|
||||||
|
json_dump
|
||||||
|
;;
|
||||||
|
|
||||||
|
delete_vhost)
|
||||||
|
# Delete vhost
|
||||||
|
read -r input
|
||||||
|
json_load "$input"
|
||||||
|
json_get_var vhost_name name
|
||||||
|
|
||||||
|
CONF_FILE="$NGINX_VHOSTS_DIR/${vhost_name}.conf"
|
||||||
|
|
||||||
|
if [ -f "$CONF_FILE" ]; then
|
||||||
|
rm -f "$CONF_FILE"
|
||||||
|
json_init
|
||||||
|
json_add_boolean "success" 1
|
||||||
|
json_add_string "message" "VHost deleted"
|
||||||
|
else
|
||||||
|
json_init
|
||||||
|
json_add_boolean "success" 0
|
||||||
|
json_add_string "error" "VHost not found"
|
||||||
|
fi
|
||||||
|
|
||||||
|
json_dump
|
||||||
|
;;
|
||||||
|
|
||||||
|
get_certificates)
|
||||||
|
# List SSL certificates
|
||||||
|
list_certificates
|
||||||
|
json_dump
|
||||||
|
;;
|
||||||
|
|
||||||
|
request_certificate)
|
||||||
|
# Request Let's Encrypt certificate
|
||||||
|
read -r input
|
||||||
|
json_load "$input"
|
||||||
|
json_get_var domain domain
|
||||||
|
|
||||||
|
if [ -z "$domain" ]; then
|
||||||
|
json_init
|
||||||
|
json_add_boolean "success" 0
|
||||||
|
json_add_string "error" "Domain is required"
|
||||||
|
json_dump
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if acme.sh is available
|
||||||
|
if command -v acme.sh > /dev/null 2>&1; then
|
||||||
|
# Request certificate (async - just start the process)
|
||||||
|
acme.sh --issue -d "$domain" --webroot /www --keylength ec-256 &
|
||||||
|
|
||||||
|
json_init
|
||||||
|
json_add_boolean "success" 1
|
||||||
|
json_add_string "message" "Certificate request started"
|
||||||
|
json_add_string "domain" "$domain"
|
||||||
|
else
|
||||||
|
json_init
|
||||||
|
json_add_boolean "success" 0
|
||||||
|
json_add_string "error" "acme.sh not installed"
|
||||||
|
fi
|
||||||
|
|
||||||
|
json_dump
|
||||||
|
;;
|
||||||
|
|
||||||
|
reload_nginx)
|
||||||
|
# Reload nginx configuration
|
||||||
|
if nginx -t > /dev/null 2>&1; then
|
||||||
|
/etc/init.d/nginx reload
|
||||||
|
json_add_boolean "success" 1
|
||||||
|
json_add_string "message" "Nginx reloaded"
|
||||||
|
else
|
||||||
|
json_add_boolean "success" 0
|
||||||
|
json_add_string "error" "Configuration test failed"
|
||||||
|
json_add_string "details" "$(nginx -t 2>&1)"
|
||||||
|
fi
|
||||||
|
json_dump
|
||||||
|
;;
|
||||||
|
|
||||||
|
test_config)
|
||||||
|
# Test nginx configuration
|
||||||
|
TEST_OUTPUT=$(nginx -t 2>&1)
|
||||||
|
TEST_RESULT=$?
|
||||||
|
|
||||||
|
if [ $TEST_RESULT -eq 0 ]; then
|
||||||
|
json_add_boolean "valid" 1
|
||||||
|
json_add_string "message" "Configuration OK"
|
||||||
|
else
|
||||||
|
json_add_boolean "valid" 0
|
||||||
|
json_add_string "error" "$TEST_OUTPUT"
|
||||||
|
fi
|
||||||
|
json_dump
|
||||||
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
# Unknown method
|
||||||
|
json_add_int "error" -32601
|
||||||
|
json_add_string "message" "Method not found: $2"
|
||||||
|
json_dump
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
echo "Usage: $0 {list|call}"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
421
secubox-tools/secubox-debug.sh
Executable file
421
secubox-tools/secubox-debug.sh
Executable file
@ -0,0 +1,421 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# secubox-debug.sh
|
||||||
|
# Debug and analysis script for SecuBox LuCI modules RPC/ubus issues
|
||||||
|
#
|
||||||
|
# Usage: ./secubox-debug.sh [module-name]
|
||||||
|
# Example: ./secubox-debug.sh vhost-manager
|
||||||
|
# ./secubox-debug.sh all
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Colors
|
||||||
|
RED='\033[0;31m'
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
YELLOW='\033[1;33m'
|
||||||
|
BLUE='\033[0;34m'
|
||||||
|
CYAN='\033[0;36m'
|
||||||
|
NC='\033[0m' # No Color
|
||||||
|
|
||||||
|
# SecuBox modules list
|
||||||
|
MODULES="
|
||||||
|
secubox
|
||||||
|
crowdsec-dashboard
|
||||||
|
netdata-dashboard
|
||||||
|
netifyd-dashboard
|
||||||
|
wireguard-dashboard
|
||||||
|
network-modes
|
||||||
|
client-guardian
|
||||||
|
system-hub
|
||||||
|
bandwidth-manager
|
||||||
|
auth-guardian
|
||||||
|
media-flow
|
||||||
|
vhost-manager
|
||||||
|
cdn-cache
|
||||||
|
traffic-shaper
|
||||||
|
"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "${CYAN}╔══════════════════════════════════════════════════════════════╗${NC}"
|
||||||
|
echo "${CYAN}║ SecuBox RPC/UBUS Debug & Analysis Tool ║${NC}"
|
||||||
|
echo "${CYAN}╚══════════════════════════════════════════════════════════════╝${NC}"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# System Information
|
||||||
|
# ============================================
|
||||||
|
print_section() {
|
||||||
|
echo ""
|
||||||
|
echo "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
||||||
|
echo "${BLUE} $1${NC}"
|
||||||
|
echo "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
||||||
|
}
|
||||||
|
|
||||||
|
print_ok() {
|
||||||
|
echo " ${GREEN}✓${NC} $1"
|
||||||
|
}
|
||||||
|
|
||||||
|
print_warn() {
|
||||||
|
echo " ${YELLOW}⚠${NC} $1"
|
||||||
|
}
|
||||||
|
|
||||||
|
print_error() {
|
||||||
|
echo " ${RED}✗${NC} $1"
|
||||||
|
}
|
||||||
|
|
||||||
|
print_info() {
|
||||||
|
echo " ${CYAN}→${NC} $1"
|
||||||
|
}
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# Check prerequisites
|
||||||
|
# ============================================
|
||||||
|
print_section "System Prerequisites"
|
||||||
|
|
||||||
|
# Check if running on OpenWrt
|
||||||
|
if [ -f /etc/openwrt_release ]; then
|
||||||
|
print_ok "Running on OpenWrt"
|
||||||
|
. /etc/openwrt_release
|
||||||
|
print_info "Version: $DISTRIB_DESCRIPTION"
|
||||||
|
else
|
||||||
|
print_warn "Not running on OpenWrt - some checks may fail"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check rpcd
|
||||||
|
if pgrep -x rpcd > /dev/null 2>&1; then
|
||||||
|
print_ok "rpcd is running (PID: $(pgrep -x rpcd))"
|
||||||
|
else
|
||||||
|
print_error "rpcd is NOT running!"
|
||||||
|
echo " Try: /etc/init.d/rpcd restart"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check uhttpd
|
||||||
|
if pgrep -x uhttpd > /dev/null 2>&1; then
|
||||||
|
print_ok "uhttpd is running"
|
||||||
|
else
|
||||||
|
print_warn "uhttpd not running (nginx mode?)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check ubus socket
|
||||||
|
if [ -S /var/run/ubus/ubus.sock ]; then
|
||||||
|
print_ok "ubus socket exists"
|
||||||
|
else
|
||||||
|
print_error "ubus socket missing!"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# List all ubus objects
|
||||||
|
# ============================================
|
||||||
|
print_section "Available UBUS Objects"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo " All registered ubus objects:"
|
||||||
|
echo " ${CYAN}─────────────────────────────${NC}"
|
||||||
|
|
||||||
|
ubus list 2>/dev/null | while read obj; do
|
||||||
|
# Highlight luci objects
|
||||||
|
case "$obj" in
|
||||||
|
luci.*)
|
||||||
|
echo " ${GREEN}$obj${NC}"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo " $obj"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
# Count luci objects
|
||||||
|
LUCI_COUNT=$(ubus list 2>/dev/null | grep -c "^luci\." || echo "0")
|
||||||
|
echo ""
|
||||||
|
print_info "Total LuCI objects registered: $LUCI_COUNT"
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# Check SecuBox modules
|
||||||
|
# ============================================
|
||||||
|
print_section "SecuBox Modules Status"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
printf " ${CYAN}%-25s %-10s %-10s %-10s %-10s${NC}\n" "MODULE" "UBUS" "RPCD" "ACL" "MENU"
|
||||||
|
echo " ─────────────────────────────────────────────────────────────────"
|
||||||
|
|
||||||
|
check_module() {
|
||||||
|
local module="$1"
|
||||||
|
local ubus_name="luci.$module"
|
||||||
|
local rpcd_script="/usr/libexec/rpcd/$module"
|
||||||
|
local acl_file="/usr/share/rpcd/acl.d/luci-app-${module}.json"
|
||||||
|
local menu_file="/usr/share/luci/menu.d/luci-app-${module}.json"
|
||||||
|
|
||||||
|
# Alternative paths
|
||||||
|
local rpcd_script_alt="/usr/libexec/rpcd/luci.$module"
|
||||||
|
local acl_file_alt="/usr/share/rpcd/acl.d/luci-${module}.json"
|
||||||
|
local menu_file_alt="/usr/share/luci/menu.d/luci-${module}.json"
|
||||||
|
|
||||||
|
# Check ubus
|
||||||
|
local ubus_status="${RED}✗${NC}"
|
||||||
|
if ubus list "$ubus_name" > /dev/null 2>&1; then
|
||||||
|
ubus_status="${GREEN}✓${NC}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check rpcd script
|
||||||
|
local rpcd_status="${RED}✗${NC}"
|
||||||
|
if [ -x "$rpcd_script" ] || [ -x "$rpcd_script_alt" ]; then
|
||||||
|
rpcd_status="${GREEN}✓${NC}"
|
||||||
|
elif [ -f "$rpcd_script" ] || [ -f "$rpcd_script_alt" ]; then
|
||||||
|
rpcd_status="${YELLOW}!${NC}" # exists but not executable
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check ACL
|
||||||
|
local acl_status="${RED}✗${NC}"
|
||||||
|
if [ -f "$acl_file" ] || [ -f "$acl_file_alt" ]; then
|
||||||
|
acl_status="${GREEN}✓${NC}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check menu
|
||||||
|
local menu_status="${RED}✗${NC}"
|
||||||
|
if [ -f "$menu_file" ] || [ -f "$menu_file_alt" ]; then
|
||||||
|
menu_status="${GREEN}✓${NC}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
printf " %-25s %-18s %-18s %-18s %-18s\n" \
|
||||||
|
"$module" "$ubus_status" "$rpcd_status" "$acl_status" "$menu_status"
|
||||||
|
}
|
||||||
|
|
||||||
|
for module in $MODULES; do
|
||||||
|
check_module "$module"
|
||||||
|
done
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo " ${CYAN}Legend:${NC} ${GREEN}✓${NC}=OK ${YELLOW}!${NC}=Issue ${RED}✗${NC}=Missing"
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# Detailed module analysis
|
||||||
|
# ============================================
|
||||||
|
TARGET_MODULE="$1"
|
||||||
|
|
||||||
|
if [ -n "$TARGET_MODULE" ] && [ "$TARGET_MODULE" != "all" ]; then
|
||||||
|
print_section "Detailed Analysis: $TARGET_MODULE"
|
||||||
|
|
||||||
|
MODULE="$TARGET_MODULE"
|
||||||
|
UBUS_NAME="luci.$MODULE"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo " ${CYAN}UBUS Object: $UBUS_NAME${NC}"
|
||||||
|
echo " ─────────────────────────────────────"
|
||||||
|
|
||||||
|
# Check if ubus object exists
|
||||||
|
if ubus list "$UBUS_NAME" > /dev/null 2>&1; then
|
||||||
|
print_ok "Object registered in ubus"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo " Available methods:"
|
||||||
|
ubus -v list "$UBUS_NAME" 2>/dev/null | sed 's/^/ /'
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo " Testing 'status' method:"
|
||||||
|
if ubus call "$UBUS_NAME" status 2>/dev/null; then
|
||||||
|
print_ok "status method works"
|
||||||
|
else
|
||||||
|
print_error "status method failed"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
print_error "Object NOT registered in ubus"
|
||||||
|
echo ""
|
||||||
|
echo " ${YELLOW}Troubleshooting steps:${NC}"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Check RPCD script
|
||||||
|
RPCD_PATHS="
|
||||||
|
/usr/libexec/rpcd/$MODULE
|
||||||
|
/usr/libexec/rpcd/luci.$MODULE
|
||||||
|
/usr/libexec/rpcd/luci-$MODULE
|
||||||
|
"
|
||||||
|
echo " 1. Checking RPCD script locations:"
|
||||||
|
FOUND_RPCD=""
|
||||||
|
for path in $RPCD_PATHS; do
|
||||||
|
if [ -f "$path" ]; then
|
||||||
|
FOUND_RPCD="$path"
|
||||||
|
if [ -x "$path" ]; then
|
||||||
|
print_ok "Found executable: $path"
|
||||||
|
else
|
||||||
|
print_error "Found but NOT executable: $path"
|
||||||
|
echo " ${YELLOW}Fix: chmod +x $path${NC}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ -z "$FOUND_RPCD" ]; then
|
||||||
|
print_error "No RPCD script found!"
|
||||||
|
echo " Expected at: /usr/libexec/rpcd/$MODULE"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check ACL file
|
||||||
|
echo ""
|
||||||
|
echo " 2. Checking ACL configuration:"
|
||||||
|
ACL_PATHS="
|
||||||
|
/usr/share/rpcd/acl.d/luci-app-${MODULE}.json
|
||||||
|
/usr/share/rpcd/acl.d/luci-${MODULE}.json
|
||||||
|
/usr/share/rpcd/acl.d/${MODULE}.json
|
||||||
|
"
|
||||||
|
FOUND_ACL=""
|
||||||
|
for path in $ACL_PATHS; do
|
||||||
|
if [ -f "$path" ]; then
|
||||||
|
FOUND_ACL="$path"
|
||||||
|
print_ok "Found ACL: $path"
|
||||||
|
|
||||||
|
# Validate JSON
|
||||||
|
if command -v jsonfilter > /dev/null 2>&1; then
|
||||||
|
if jsonfilter -i "$path" -e '@' > /dev/null 2>&1; then
|
||||||
|
print_ok "JSON syntax valid"
|
||||||
|
else
|
||||||
|
print_error "Invalid JSON syntax!"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check for correct ubus permission
|
||||||
|
if grep -q "\"$UBUS_NAME\"" "$path" 2>/dev/null; then
|
||||||
|
print_ok "ACL contains $UBUS_NAME permission"
|
||||||
|
else
|
||||||
|
print_warn "ACL might be missing $UBUS_NAME permission"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ -z "$FOUND_ACL" ]; then
|
||||||
|
print_error "No ACL file found!"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Test RPCD script directly
|
||||||
|
if [ -n "$FOUND_RPCD" ] && [ -x "$FOUND_RPCD" ]; then
|
||||||
|
echo ""
|
||||||
|
echo " 3. Testing RPCD script directly:"
|
||||||
|
|
||||||
|
# Test list method
|
||||||
|
echo '{"method":"list"}' | "$FOUND_RPCD" 2>&1 | head -20
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check menu entry
|
||||||
|
echo ""
|
||||||
|
echo " ${CYAN}Menu Configuration${NC}"
|
||||||
|
echo " ─────────────────────────────────────"
|
||||||
|
|
||||||
|
MENU_PATHS="
|
||||||
|
/usr/share/luci/menu.d/luci-app-${MODULE}.json
|
||||||
|
/usr/share/luci/menu.d/luci-${MODULE}.json
|
||||||
|
"
|
||||||
|
for path in $MENU_PATHS; do
|
||||||
|
if [ -f "$path" ]; then
|
||||||
|
print_ok "Found menu: $path"
|
||||||
|
echo ""
|
||||||
|
cat "$path" | sed 's/^/ /'
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# Common fixes
|
||||||
|
# ============================================
|
||||||
|
print_section "Common Fixes"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo " ${YELLOW}If a module is not working:${NC}"
|
||||||
|
echo ""
|
||||||
|
echo " 1. ${CYAN}Restart rpcd:${NC}"
|
||||||
|
echo " /etc/init.d/rpcd restart"
|
||||||
|
echo ""
|
||||||
|
echo " 2. ${CYAN}Check script permissions:${NC}"
|
||||||
|
echo " chmod +x /usr/libexec/rpcd/<module-name>"
|
||||||
|
echo ""
|
||||||
|
echo " 3. ${CYAN}Validate JSON files:${NC}"
|
||||||
|
echo " jsonfilter -i /usr/share/rpcd/acl.d/luci-app-<module>.json -e '@'"
|
||||||
|
echo ""
|
||||||
|
echo " 4. ${CYAN}Check rpcd logs:${NC}"
|
||||||
|
echo " logread | grep rpcd"
|
||||||
|
echo ""
|
||||||
|
echo " 5. ${CYAN}Test ubus manually:${NC}"
|
||||||
|
echo " ubus call luci.<module> status"
|
||||||
|
echo ""
|
||||||
|
echo " 6. ${CYAN}Reload LuCI:${NC}"
|
||||||
|
echo " rm -rf /tmp/luci-*"
|
||||||
|
echo " /etc/init.d/uhttpd restart"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# Generate fix script
|
||||||
|
# ============================================
|
||||||
|
if [ -n "$TARGET_MODULE" ] && [ "$TARGET_MODULE" != "all" ]; then
|
||||||
|
print_section "Auto-Fix Script for $TARGET_MODULE"
|
||||||
|
|
||||||
|
FIX_SCRIPT="/tmp/fix-${TARGET_MODULE}.sh"
|
||||||
|
|
||||||
|
cat > "$FIX_SCRIPT" << FIXEOF
|
||||||
|
#!/bin/sh
|
||||||
|
# Auto-generated fix script for $TARGET_MODULE
|
||||||
|
|
||||||
|
echo "Fixing $TARGET_MODULE..."
|
||||||
|
|
||||||
|
# Fix permissions
|
||||||
|
if [ -f /usr/libexec/rpcd/$TARGET_MODULE ]; then
|
||||||
|
chmod +x /usr/libexec/rpcd/$TARGET_MODULE
|
||||||
|
echo "✓ Fixed permissions for RPCD script"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -f /usr/libexec/rpcd/luci.$TARGET_MODULE ]; then
|
||||||
|
chmod +x /usr/libexec/rpcd/luci.$TARGET_MODULE
|
||||||
|
echo "✓ Fixed permissions for RPCD script (alt)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Restart rpcd
|
||||||
|
/etc/init.d/rpcd restart
|
||||||
|
echo "✓ Restarted rpcd"
|
||||||
|
|
||||||
|
# Clear LuCI cache
|
||||||
|
rm -rf /tmp/luci-*
|
||||||
|
echo "✓ Cleared LuCI cache"
|
||||||
|
|
||||||
|
# Test
|
||||||
|
sleep 2
|
||||||
|
if ubus list luci.$TARGET_MODULE > /dev/null 2>&1; then
|
||||||
|
echo "✓ Module $TARGET_MODULE is now registered!"
|
||||||
|
ubus -v list luci.$TARGET_MODULE
|
||||||
|
else
|
||||||
|
echo "✗ Module still not working. Check logs:"
|
||||||
|
echo " logread | grep -i rpcd"
|
||||||
|
echo " logread | grep -i $TARGET_MODULE"
|
||||||
|
fi
|
||||||
|
FIXEOF
|
||||||
|
|
||||||
|
chmod +x "$FIX_SCRIPT"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo " Generated fix script: ${GREEN}$FIX_SCRIPT${NC}"
|
||||||
|
echo ""
|
||||||
|
echo " Run it with: ${CYAN}sh $FIX_SCRIPT${NC}"
|
||||||
|
echo ""
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# Summary
|
||||||
|
# ============================================
|
||||||
|
print_section "Quick Commands"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo " ${CYAN}Debug specific module:${NC}"
|
||||||
|
echo " ./secubox-debug.sh vhost-manager"
|
||||||
|
echo ""
|
||||||
|
echo " ${CYAN}List all ubus objects:${NC}"
|
||||||
|
echo " ubus list | grep luci"
|
||||||
|
echo ""
|
||||||
|
echo " ${CYAN}Test RPC call:${NC}"
|
||||||
|
echo " ubus call luci.vhost-manager status"
|
||||||
|
echo ""
|
||||||
|
echo " ${CYAN}View RPCD logs:${NC}"
|
||||||
|
echo " logread | grep -E '(rpcd|ubus)'"
|
||||||
|
echo ""
|
||||||
|
echo " ${CYAN}Full restart:${NC}"
|
||||||
|
echo " /etc/init.d/rpcd restart && rm -rf /tmp/luci-* && /etc/init.d/uhttpd restart"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo "${CYAN}╔══════════════════════════════════════════════════════════════╗${NC}"
|
||||||
|
echo "${CYAN}║ Debug Complete ║${NC}"
|
||||||
|
echo "${CYAN}╚══════════════════════════════════════════════════════════════╝${NC}"
|
||||||
|
echo ""
|
||||||
1109
secubox-tools/secubox-repair.sh
Executable file
1109
secubox-tools/secubox-repair.sh
Executable file
File diff suppressed because it is too large
Load Diff
75
secubox-tools/templates/Makefile.template
Normal file
75
secubox-tools/templates/Makefile.template
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
# Template Makefile for SecuBox LuCI Applications
|
||||||
|
# ================================================
|
||||||
|
# Copy this template and customize for each package
|
||||||
|
|
||||||
|
include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
|
# Package metadata
|
||||||
|
PKG_NAME:=luci-app-PACKAGE_NAME
|
||||||
|
PKG_VERSION:=2.0.0
|
||||||
|
PKG_RELEASE:=1
|
||||||
|
PKG_LICENSE:=Apache-2.0
|
||||||
|
PKG_MAINTAINER:=CyberMind <contact@cybermind.fr>
|
||||||
|
|
||||||
|
# LuCI specific
|
||||||
|
LUCI_TITLE:=LuCI - Package Description
|
||||||
|
LUCI_DESCRIPTION:=Detailed description of what this package does
|
||||||
|
LUCI_DEPENDS:=+luci-base
|
||||||
|
LUCI_PKGARCH:=all
|
||||||
|
|
||||||
|
# Include LuCI build system
|
||||||
|
include $(TOPDIR)/feeds/luci/luci.mk
|
||||||
|
|
||||||
|
# Call BuildPackage - this is handled by luci.mk
|
||||||
|
# No need for explicit Package/xxx/install when using luci.mk
|
||||||
|
|
||||||
|
# === END OF TEMPLATE ===
|
||||||
|
|
||||||
|
# ================================================
|
||||||
|
# NOTES FOR DEVELOPERS
|
||||||
|
# ================================================
|
||||||
|
#
|
||||||
|
# Directory structure expected by luci.mk:
|
||||||
|
#
|
||||||
|
# luci-app-mypackage/
|
||||||
|
# ├── Makefile # This file
|
||||||
|
# ├── htdocs/
|
||||||
|
# │ └── luci-static/
|
||||||
|
# │ └── resources/
|
||||||
|
# │ └── view/
|
||||||
|
# │ └── mypackage/
|
||||||
|
# │ └── main.js # LuCI JavaScript view
|
||||||
|
# └── root/
|
||||||
|
# ├── etc/
|
||||||
|
# │ ├── config/
|
||||||
|
# │ │ └── mypackage # UCI config file
|
||||||
|
# │ ├── init.d/
|
||||||
|
# │ │ └── mypackage # Init script (executable)
|
||||||
|
# │ └── uci-defaults/
|
||||||
|
# │ └── 99-mypackage # First-run setup (executable)
|
||||||
|
# └── usr/
|
||||||
|
# ├── libexec/
|
||||||
|
# │ └── rpcd/
|
||||||
|
# │ └── mypackage # RPCD backend script (executable)
|
||||||
|
# └── share/
|
||||||
|
# ├── luci/
|
||||||
|
# │ └── menu.d/
|
||||||
|
# │ └── luci-app-mypackage.json # Menu entry
|
||||||
|
# └── rpcd/
|
||||||
|
# └── acl.d/
|
||||||
|
# └── luci-app-mypackage.json # ACL permissions
|
||||||
|
#
|
||||||
|
# ================================================
|
||||||
|
# COMMON LUCI_DEPENDS OPTIONS
|
||||||
|
# ================================================
|
||||||
|
#
|
||||||
|
# +luci-base - Required for all LuCI apps
|
||||||
|
# +luci-compat - Legacy API compatibility
|
||||||
|
# +luci-lib-jsonc - JSON-C library
|
||||||
|
# +rpcd - RPC daemon (for backend scripts)
|
||||||
|
# +curl - HTTP client
|
||||||
|
# +jq - JSON processor
|
||||||
|
# +wireguard-tools - WireGuard utilities
|
||||||
|
# +qrencode - QR code generator
|
||||||
|
#
|
||||||
|
# ================================================
|
||||||
Loading…
Reference in New Issue
Block a user