mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-07 13:56:01 +01:00
Remove SECURITY_INSTALLATION.md and implement SSL reconciliation features in manageSSL module. Add new views and URLs for SSL reconciliation, enhance mobile responsiveness in templates, and update SSL utilities for improved functionality. Update upgrade script for scheduled SSL reconciliation tasks.
This commit is contained in:
98
plogical/management/commands/ssl_reconcile.py
Normal file
98
plogical/management/commands/ssl_reconcile.py
Normal file
@@ -0,0 +1,98 @@
|
||||
#!/usr/local/CyberCP/bin/python
|
||||
"""
|
||||
Django management command for SSL reconciliation
|
||||
Usage: python manage.py ssl_reconcile [--all|--domain <domain>]
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import django
|
||||
|
||||
# Add CyberPanel to Python path
|
||||
sys.path.append('/usr/local/CyberCP')
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings")
|
||||
django.setup()
|
||||
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from plogical.sslReconcile import SSLReconcile
|
||||
from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Reconcile SSL certificates and ACME challenge configurations'
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument(
|
||||
'--all',
|
||||
action='store_true',
|
||||
help='Reconcile SSL for all domains',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--domain',
|
||||
type=str,
|
||||
help='Reconcile SSL for a specific domain',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--fix-acme',
|
||||
action='store_true',
|
||||
help='Fix ACME challenge contexts for all domains',
|
||||
)
|
||||
|
||||
def handle(self, *args, **options):
|
||||
if options['all']:
|
||||
self.stdout.write('Starting SSL reconciliation for all domains...')
|
||||
try:
|
||||
success = SSLReconcile.reconcile_all()
|
||||
if success:
|
||||
self.stdout.write(
|
||||
self.style.SUCCESS('SSL reconciliation completed successfully!')
|
||||
)
|
||||
else:
|
||||
self.stdout.write(
|
||||
self.style.ERROR('SSL reconciliation failed. Check logs for details.')
|
||||
)
|
||||
except Exception as e:
|
||||
raise CommandError(f'SSL reconciliation failed: {str(e)}')
|
||||
|
||||
elif options['domain']:
|
||||
domain = options['domain']
|
||||
self.stdout.write(f'Starting SSL reconciliation for domain: {domain}')
|
||||
try:
|
||||
success = SSLReconcile.reconcile_domain(domain)
|
||||
if success:
|
||||
self.stdout.write(
|
||||
self.style.SUCCESS(f'SSL reconciliation completed for {domain}!')
|
||||
)
|
||||
else:
|
||||
self.stdout.write(
|
||||
self.style.ERROR(f'SSL reconciliation failed for {domain}. Check logs for details.')
|
||||
)
|
||||
except Exception as e:
|
||||
raise CommandError(f'SSL reconciliation failed for {domain}: {str(e)}')
|
||||
|
||||
elif options['fix_acme']:
|
||||
self.stdout.write('Fixing ACME challenge contexts for all domains...')
|
||||
try:
|
||||
from plogical.sslUtilities import sslUtilities
|
||||
from websiteFunctions.models import Websites
|
||||
|
||||
fixed_count = 0
|
||||
for website in Websites.objects.all():
|
||||
if sslUtilities.fix_acme_challenge_context(website.domain):
|
||||
fixed_count += 1
|
||||
self.stdout.write(f'Fixed ACME context for: {website.domain}')
|
||||
|
||||
self.stdout.write(
|
||||
self.style.SUCCESS(f'Fixed ACME challenge contexts for {fixed_count} domains!')
|
||||
)
|
||||
except Exception as e:
|
||||
raise CommandError(f'Failed to fix ACME contexts: {str(e)}')
|
||||
|
||||
else:
|
||||
self.stdout.write(
|
||||
self.style.WARNING('Please specify --all, --domain <domain>, or --fix-acme')
|
||||
)
|
||||
self.stdout.write('Usage examples:')
|
||||
self.stdout.write(' python manage.py ssl_reconcile --all')
|
||||
self.stdout.write(' python manage.py ssl_reconcile --domain example.com')
|
||||
self.stdout.write(' python manage.py ssl_reconcile --fix-acme')
|
||||
Reference in New Issue
Block a user