Publish reviewed history-free open-source snapshot (2026-10-12)
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
import os
|
||||
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
from control.models import Plan, RoutingPolicy
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "创建默认套餐、全局路由策略和首个管理员"
|
||||
|
||||
def handle(self, *args, **options):
|
||||
Plan.objects.get_or_create(
|
||||
slug="employee-benefit",
|
||||
defaults={
|
||||
"name": "员工福利",
|
||||
"audience": Plan.Audience.EMPLOYEE,
|
||||
"employee_benefit": True,
|
||||
"price_cny": 0,
|
||||
"traffic_limit_gb": 0,
|
||||
"duration_days": 0,
|
||||
"device_limit": 3,
|
||||
"description": "公司内部员工免费使用,离职后由管理员立即停权。",
|
||||
"sort_order": 1,
|
||||
},
|
||||
)
|
||||
Plan.objects.get_or_create(
|
||||
slug="external-monthly",
|
||||
defaults={
|
||||
"name": "外部联系人月度套餐",
|
||||
"audience": Plan.Audience.EXTERNAL,
|
||||
"price_cny": 39,
|
||||
"traffic_limit_gb": 100,
|
||||
"duration_days": 30,
|
||||
"device_limit": 3,
|
||||
"description": "外部联系人付费套餐,付款确认后开通。",
|
||||
"sort_order": 10,
|
||||
},
|
||||
)
|
||||
RoutingPolicy.objects.get_or_create(
|
||||
name="公司全局策略",
|
||||
defaults={
|
||||
"is_global": True,
|
||||
"rules": [
|
||||
"DOMAIN-SUFFIX,cn,DIRECT",
|
||||
"GEOIP,CN,DIRECT",
|
||||
"MATCH,节点选择",
|
||||
],
|
||||
"description": "国内直连,其余流量使用节点;可在后台调整。",
|
||||
},
|
||||
)
|
||||
|
||||
username = os.getenv("VPN_ADMIN_USERNAME", "").strip()
|
||||
password = os.getenv("VPN_ADMIN_PASSWORD", "")
|
||||
email = os.getenv("VPN_ADMIN_EMAIL", "").strip().lower()
|
||||
if not username or not password or not email:
|
||||
self.stdout.write("未提供完整管理员环境变量,跳过管理员创建。")
|
||||
return
|
||||
User = get_user_model()
|
||||
if User.objects.filter(username=username).exists():
|
||||
self.stdout.write(f"管理员 {username} 已存在。")
|
||||
return
|
||||
User.objects.create_superuser(
|
||||
username=username,
|
||||
email=email,
|
||||
password=password,
|
||||
display_name="VPN 管理员",
|
||||
identity_type=User.IdentityType.EMPLOYEE,
|
||||
account_status=User.AccountStatus.ACTIVE,
|
||||
)
|
||||
self.stdout.write(self.style.SUCCESS(f"已创建管理员 {username}。"))
|
||||
|
||||
Reference in New Issue
Block a user