feat: add RolesPage.tsx, patch_all_modules.py for all 4 addon modules

This commit is contained in:
2026-06-11 21:29:54 -05:00
parent ded0d6f1b1
commit 3236acab16
4 changed files with 483 additions and 0 deletions

97
scripts/repatch.py Normal file
View File

@@ -0,0 +1,97 @@
#!/usr/bin/env python3
"""Re-apply all addon patches after a panel update."""
import sys, os
PANEL = '/var/www/pterodactyl'
# ── 1. AppServiceProvider ─────────────────────────────────────────────────────
print("=== Patching AppServiceProvider.php ===")
asp = f'{PANEL}/app/Providers/AppServiceProvider.php'
content = open(asp).read()
INJECT = " $this->app->register(\\Pterodactyl\\Addons\\AdvancedAdmin\\AddonServiceProvider::class);"
if 'AddonServiceProvider' not in content:
old = ' public function register(): void\n {'
new = f' public function register(): void\n {{\n{INJECT}'
if old in content:
content = content.replace(old, new, 1)
open(asp, 'w').write(content)
print(f" Applied: AddonServiceProvider registered")
else:
print(f" WARN: anchor not found in AppServiceProvider")
else:
print(" Already patched")
# ── 2. routes.ts ─────────────────────────────────────────────────────────────
print("\n=== Patching routes.ts ===")
rts = f'{PANEL}/resources/scripts/routers/routes.ts'
content = open(rts).read()
IMPORT = "import NetworkTab from '@/addons/advanced-admin/network/NetworkTab';"
ROUTE_BLOCK = """,
{
path: '/addon-network',
permission: null,
name: 'Live Network',
component: NetworkTab,
}"""
# Add import
if IMPORT not in content:
lines = content.splitlines(keepends=True)
last_import = 0
for i, line in enumerate(lines):
if line.strip().startswith('import '):
last_import = i
lines.insert(last_import + 1, IMPORT + '\n')
content = ''.join(lines)
print(" Added import")
else:
print(" Import already present")
# Add route
if '/addon-network' not in content:
# Insert before the final closing of server array
target = " ],\n} as Routes;"
if target in content:
content = content.replace(target, f"{ROUTE_BLOCK},\n ],\n}} as Routes;")
print(" Added /addon-network route")
else:
print(" WARN: routes.ts closing not found - trying alternate")
# Try without the extra comma
target2 = " ]\n} as Routes;"
if target2 in content:
content = content.replace(target2, f"{ROUTE_BLOCK},\n ]\n}} as Routes;")
print(" Added /addon-network route (alt)")
else:
print(" Route already present")
open(rts, 'w').write(content)
# ── 3. Clean ServerRouter.tsx of any stray addon imports ─────────────────────
print("\n=== Cleaning ServerRouter.tsx ===")
sr = f'{PANEL}/resources/scripts/routers/ServerRouter.tsx'
content = open(sr).read()
stray = "import NetworkTab from '@/addons/advanced-admin/network/NetworkTab';\n"
if stray in content:
content = content.replace(stray, '')
open(sr, 'w').write(content)
print(" Removed stray import")
else:
print(" Clean already")
# ── 4. Remove non-existent middleware from routes ─────────────────────────────
print("\n=== Fixing addon route middleware ===")
for route_file in ['addon-client.php', 'addon-application.php']:
path = f'{PANEL}/routes/{route_file}'
content = open(path).read()
# Replace named throttle limiters that aren't registered with standard ones
import re
# Remove ->middleware('throttle:addon-*') chains that use unregistered limiters
content = re.sub(r"->middleware\('throttle:addon-[^']+'\)", "", content)
# Remove ->middleware('addon.ratelimit')
content = re.sub(r",?\s*'addon\.ratelimit'", "", content)
open(path, 'w').write(content)
print(f" Cleaned {route_file}")
print("\nAll patches applied. Rebuild the frontend next.")