mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2026-01-28 02:09:03 +01:00
fix(plugins): Fix removeFromSettings to properly track INSTALLED_APPS section
- Track INSTALLED_APPS section state while iterating - Only remove plugin if found within INSTALLED_APPS section - Prevents removing plugin references from comments or other sections
This commit is contained in:
@@ -387,11 +387,18 @@ class pluginInstaller:
|
||||
def removeFromSettings(pluginName):
|
||||
data = open("/usr/local/CyberCP/CyberCP/settings.py", 'r', encoding='utf-8').readlines()
|
||||
writeToFile = open("/usr/local/CyberCP/CyberCP/settings.py", 'w', encoding='utf-8')
|
||||
|
||||
for items in data:
|
||||
|
||||
in_installed_apps = False
|
||||
for i, items in enumerate(data):
|
||||
# Track if we're in INSTALLED_APPS section
|
||||
if 'INSTALLED_APPS' in items and '=' in items:
|
||||
in_installed_apps = True
|
||||
elif in_installed_apps and items.strip().startswith(']'):
|
||||
in_installed_apps = False
|
||||
|
||||
# More precise matching: look for plugin name in quotes (e.g., 'pluginName' or "pluginName")
|
||||
# This prevents partial matches (e.g., 'pluginName2' matching 'pluginName')
|
||||
if (f"'{pluginName}'" in items or f'"{pluginName}"' in items) and 'INSTALLED_APPS' in ''.join(data[max(0, data.index(items)-5):data.index(items)+5]):
|
||||
# Only match if we're in INSTALLED_APPS section to prevent false positives
|
||||
if in_installed_apps and (f"'{pluginName}'" in items or f'"{pluginName}"' in items):
|
||||
continue
|
||||
else:
|
||||
writeToFile.writelines(items)
|
||||
|
||||
Reference in New Issue
Block a user