33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
#!/usr/bin/env python3
|
|
"""Fix AppServiceProvider — ensure AddonServiceProvider is registered."""
|
|
import sys
|
|
|
|
f = '/var/www/pterodactyl/app/Providers/AppServiceProvider.php'
|
|
content = open(f).read()
|
|
|
|
if 'AddonServiceProvider' in content and '$this->app->register' in content.split('AddonServiceProvider')[0].split('\n')[-2:][0]:
|
|
print('Already correctly patched')
|
|
sys.exit(0)
|
|
|
|
# Remove the broken line (the one without $this->)
|
|
lines = content.splitlines(keepends=True)
|
|
fixed = []
|
|
for line in lines:
|
|
# Replace the broken orphan line
|
|
if '->app->register(\\Pterodactyl\\Addons\\AdvancedAdmin\\AddonServiceProvider::class)' in line and not '$this' in line:
|
|
fixed.append(' $this->app->register(\\Pterodactyl\\Addons\\AdvancedAdmin\\AddonServiceProvider::class);\n')
|
|
else:
|
|
fixed.append(line)
|
|
|
|
content = ''.join(fixed)
|
|
open(f, 'w').write(content)
|
|
print('Fixed: $this-> added to AddonServiceProvider line')
|
|
|
|
# Verify
|
|
result = open(f).read()
|
|
if '$this->app->register(\\Pterodactyl\\Addons\\AdvancedAdmin\\AddonServiceProvider::class)' in result:
|
|
print('Verification OK')
|
|
else:
|
|
print('ERROR: Verification failed')
|
|
sys.exit(1)
|