From f943e5c96169357ec591b5a36bfb9bcb1d305944 Mon Sep 17 00:00:00 2001 From: usmannasir Date: Sun, 21 Sep 2025 00:37:02 +0500 Subject: [PATCH 1/2] some bug fixes to install.py --- install/install.py | 47 +++++++++++++++------------------------------- 1 file changed, 15 insertions(+), 32 deletions(-) diff --git a/install/install.py b/install/install.py index c8a1f4efa..673f2c4a7 100644 --- a/install/install.py +++ b/install/install.py @@ -690,7 +690,21 @@ password="%s" # self.setupVirtualEnv(self.distro) - ### Database migrations will be handled after database creation + # Now run Django migrations since we're in /usr/local/CyberCP and database exists + os.chdir("/usr/local/CyberCP") + logging.InstallLog.writeToFile("Running Django migrations...") + preFlightsChecks.stdOut("Running Django migrations...") + + # Create fresh migrations for all apps + command = "/usr/local/CyberPanel-venv/bin/python manage.py makemigrations" + preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR) + + # Apply all migrations + command = "/usr/local/CyberPanel-venv/bin/python manage.py migrate" + preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR) + + logging.InstallLog.writeToFile("Django migrations completed successfully!") + preFlightsChecks.stdOut("Django migrations completed successfully!") if not os.path.exists("/usr/local/CyberCP/public"): os.mkdir("/usr/local/CyberCP/public") @@ -2917,37 +2931,6 @@ def main(): installCyberPanel.Main(cwd, mysql, distro, ent, serial, port, args.ftp, args.powerdns, args.publicip, remotemysql, mysqlhost, mysqldb, mysqluser, mysqlpassword, mysqlport) - # Now that database is created, run Django migrations - preFlightsChecks.stdOut("Running Django migrations...") - # The application should be at /usr/local/CyberCP after download_install_CyberPanel - if os.path.exists("/usr/local/CyberCP"): - os.chdir("/usr/local/CyberCP") - preFlightsChecks.stdOut("Changed to /usr/local/CyberCP directory for migrations") - else: - # Check if it's still in cyberpanel (move may have failed) - if os.path.exists("/usr/local/cyberpanel"): - preFlightsChecks.stdOut("WARNING: Application is in /usr/local/cyberpanel instead of /usr/local/CyberCP") - preFlightsChecks.stdOut("Attempting to fix directory structure...") - - # Try to move it now - os.chdir("/usr/local") - if os.path.exists("CyberCP"): - shutil.rmtree("CyberCP") - shutil.move("cyberpanel", "CyberCP") - os.chdir("/usr/local/CyberCP") - preFlightsChecks.stdOut("Fixed: Moved cyberpanel to CyberCP") - else: - preFlightsChecks.stdOut("ERROR: Neither /usr/local/CyberCP nor /usr/local/cyberpanel exists!") - sys.exit(1) - - # Create fresh migrations for all apps - command = "/usr/local/CyberPanel-venv/bin/python manage.py makemigrations" - preFlightsChecks.call(command, distro, command, command, 1, 1, os.EX_OSERR) - - # Apply all migrations - command = "/usr/local/CyberPanel-venv/bin/python manage.py migrate" - preFlightsChecks.call(command, distro, command, command, 1, 1, os.EX_OSERR) - checks.setupPHPAndComposer() checks.fix_selinux_issue() checks.install_psmisc() From 570a4953d0a4d59240fb0094372b5adcb02bb5d2 Mon Sep 17 00:00:00 2001 From: usmannasir Date: Sun, 21 Sep 2025 01:07:38 +0500 Subject: [PATCH 2/2] some bug fixes to install.py --- baseTemplate/models.py | 10 +++++----- baseTemplate/signals.py | 10 +++++----- install/install.py | 8 ++++++-- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/baseTemplate/models.py b/baseTemplate/models.py index b02b2ca38..e4ec671b0 100644 --- a/baseTemplate/models.py +++ b/baseTemplate/models.py @@ -2,7 +2,7 @@ from django.db import models -from django.contrib.auth.models import User +from loginSystem.models import Administrator # Create your models here. @@ -16,15 +16,15 @@ class CyberPanelCosmetic(models.Model): class UserNotificationPreferences(models.Model): """Model to store user notification dismissal preferences""" - user = models.OneToOneField(User, on_delete=models.CASCADE, related_name='notification_preferences') + user = models.OneToOneField(Administrator, on_delete=models.CASCADE, related_name='notification_preferences') backup_notification_dismissed = models.BooleanField(default=False, help_text="Whether user has dismissed the backup notification") ai_scanner_notification_dismissed = models.BooleanField(default=False, help_text="Whether user has dismissed the AI scanner notification") created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) - + class Meta: verbose_name = "User Notification Preferences" verbose_name_plural = "User Notification Preferences" - + def __str__(self): - return f"Notification Preferences for {self.user.username}" \ No newline at end of file + return f"Notification Preferences for {self.user.userName}" \ No newline at end of file diff --git a/baseTemplate/signals.py b/baseTemplate/signals.py index 6c7b22340..1d840e201 100644 --- a/baseTemplate/signals.py +++ b/baseTemplate/signals.py @@ -1,13 +1,13 @@ # -*- coding: utf-8 -*- from django.db.models.signals import post_save from django.dispatch import receiver -from django.contrib.auth.models import User +from loginSystem.models import Administrator from .models import UserNotificationPreferences -@receiver(post_save, sender=User) +@receiver(post_save, sender=Administrator) def create_user_notification_preferences(sender, instance, created, **kwargs): - """Create default notification preferences when a new user is created""" + """Create default notification preferences when a new Administrator is created""" if created: UserNotificationPreferences.objects.create( user=instance, @@ -16,8 +16,8 @@ def create_user_notification_preferences(sender, instance, created, **kwargs): ) -@receiver(post_save, sender=User) +@receiver(post_save, sender=Administrator) def save_user_notification_preferences(sender, instance, **kwargs): - """Save notification preferences when user is saved""" + """Save notification preferences when Administrator is saved""" if hasattr(instance, 'notification_preferences'): instance.notification_preferences.save() diff --git a/install/install.py b/install/install.py index 673f2c4a7..dabdfbec4 100644 --- a/install/install.py +++ b/install/install.py @@ -695,12 +695,16 @@ password="%s" logging.InstallLog.writeToFile("Running Django migrations...") preFlightsChecks.stdOut("Running Django migrations...") + # Reset migration history in database (in case of re-installation) + command = "/usr/local/CyberPanel-venv/bin/python manage.py migrate --fake-initial" + preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) + # Create fresh migrations for all apps command = "/usr/local/CyberPanel-venv/bin/python manage.py makemigrations" preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR) - # Apply all migrations - command = "/usr/local/CyberPanel-venv/bin/python manage.py migrate" + # Apply all migrations with --fake-initial to handle existing tables + command = "/usr/local/CyberPanel-venv/bin/python manage.py migrate --fake-initial" preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR) logging.InstallLog.writeToFile("Django migrations completed successfully!")