Skip to content

Commit c6743bd

Browse files
Add files via upload
1 parent da62643 commit c6743bd

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

debug_users.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env python3
2+
from app.main import create_app
3+
from app.models import db, User
4+
5+
app = create_app()
6+
7+
with app.app_context():
8+
print("\n=== User Debug Info ===")
9+
users = User.query.all()
10+
11+
for user in users:
12+
print(f"\nUser: {user.username}")
13+
print(f" ID: {user.id}")
14+
print(f" Admin: {user.is_admin}")
15+
print(f" Has encryption key: {bool(user.encryption_key)}")
16+
print(f" DA Server: {user.da_server}")
17+
print(f" DA Username: {user.da_username}")
18+
print(f" Has DA Password: {bool(user.da_password_encrypted)}")
19+
print(f" DA Domain: {user.da_domain}")
20+
21+
# Fix missing encryption keys
22+
if not user.encryption_key:
23+
print(" [!] Generating missing encryption key...")
24+
user.generate_encryption_key()
25+
db.session.commit()
26+
print(" [✓] Encryption key generated")
27+
28+
print("\n=== Debug complete ===")

migrate_add_admin.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from app.main import create_app
2+
from app.models import db, User
3+
4+
app = create_app()
5+
6+
with app.app_context():
7+
# Add is_admin column to existing users
8+
users = User.query.all()
9+
for user in users:
10+
if not hasattr(user, 'is_admin'):
11+
user.is_admin = user.username == 'admin' # Make 'admin' user an admin
12+
13+
db.session.commit()
14+
print("Migration completed. Admin flags added to users.")

migrate_da_settings.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from app.main import create_app
2+
from app.models import db, User
3+
from app.config import Config
4+
5+
app = create_app()
6+
7+
with app.app_context():
8+
# Add new columns to existing users
9+
users = User.query.all()
10+
11+
# If global settings exist, migrate them to admin user
12+
admin = User.query.filter_by(username='admin').first()
13+
if admin and hasattr(Config, 'DA_SERVER'):
14+
print("Migrating global DirectAdmin settings to admin user...")
15+
admin.da_server = Config.DA_SERVER
16+
admin.da_username = Config.DA_USERNAME
17+
admin.da_domain = Config.DA_DOMAIN
18+
19+
# Generate encryption key if not exists
20+
if not admin.encryption_key:
21+
from cryptography.fernet import Fernet
22+
admin.encryption_key = Fernet.generate_key().decode()
23+
24+
# Encrypt and store password
25+
if hasattr(Config, 'DA_PASSWORD'):
26+
admin.set_da_password(Config.DA_PASSWORD)
27+
28+
db.session.commit()
29+
print("Migration completed!")

0 commit comments

Comments
 (0)