Skip to content

Commit 5bd0a25

Browse files
Create migrate_da_settings.py
1 parent 1b67ce9 commit 5bd0a25

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

app/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)