newrun
This commit is contained in:
@@ -1,69 +0,0 @@
|
||||
import requests
|
||||
import sys
|
||||
|
||||
# Configuration from admin_gui.py
|
||||
API_URL = "https://backend.aidg168.uk/api/v1"
|
||||
TOKEN = "admin-secret-token"
|
||||
HEADERS = {"x-admin-token": TOKEN}
|
||||
|
||||
def fix_group():
|
||||
print(f"Connecting to {API_URL}...")
|
||||
|
||||
# 1. List groups
|
||||
try:
|
||||
resp = requests.get(f"{API_URL}/admin/groups", headers=HEADERS)
|
||||
resp.raise_for_status()
|
||||
groups = resp.json()
|
||||
except Exception as e:
|
||||
print(f"Error listing groups: {e}")
|
||||
print("Please check your network connection or server status.")
|
||||
return
|
||||
|
||||
print(f"Found {len(groups)} groups.")
|
||||
|
||||
target_group = None
|
||||
default_exists = False
|
||||
|
||||
for g in groups:
|
||||
print(f" - ID: {g['id']}, Name: {g['name']}, Comment: {g.get('comment')}")
|
||||
if g['name'] == '默认':
|
||||
target_group = g
|
||||
if g['name'] == 'default':
|
||||
default_exists = True
|
||||
|
||||
if default_exists:
|
||||
print("\n[OK] Group 'default' already exists.")
|
||||
if target_group:
|
||||
print("Warning: Group '默认' also exists. Please verify which one you want to keep.")
|
||||
else:
|
||||
print("Everything looks good.")
|
||||
return
|
||||
|
||||
if target_group:
|
||||
print(f"\nFound group '默认' (ID: {target_group['id']}). Renaming to 'default'...")
|
||||
try:
|
||||
url = f"{API_URL}/admin/groups/{target_group['id']}"
|
||||
# The API expects JSON body with fields to update
|
||||
resp = requests.put(url, json={"name": "default"}, headers=HEADERS)
|
||||
resp.raise_for_status()
|
||||
print("Success! Group renamed to 'default'.")
|
||||
except Exception as e:
|
||||
print(f"Error renaming group: {e}")
|
||||
if hasattr(e, 'response') and e.response:
|
||||
print(f"Server response: {e.response.text}")
|
||||
else:
|
||||
print("\nGroup '默认' not found and 'default' does not exist.")
|
||||
print("Creating 'default' group...")
|
||||
try:
|
||||
url = f"{API_URL}/admin/groups"
|
||||
payload = {"name": "default", "comment": "Default User Group"}
|
||||
resp = requests.post(url, json=payload, headers=HEADERS)
|
||||
resp.raise_for_status()
|
||||
print("Success! Group 'default' created.")
|
||||
except Exception as e:
|
||||
print(f"Error creating group: {e}")
|
||||
if hasattr(e, 'response') and e.response:
|
||||
print(f"Server response: {e.response.text}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
fix_group()
|
||||
@@ -1,127 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
测试数据库连接和 app_deployments 表(通过 SSH 隧道)
|
||||
"""
|
||||
import json
|
||||
import pymysql
|
||||
from datetime import datetime
|
||||
import sys
|
||||
import io
|
||||
from sshtunnel import SSHTunnelForwarder
|
||||
|
||||
# 设置 stdout 为 UTF-8
|
||||
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
|
||||
|
||||
def load_config():
|
||||
with open('deploy_config.json', 'r', encoding='utf-8') as f:
|
||||
return json.load(f)
|
||||
|
||||
def test_connection():
|
||||
print("="*60)
|
||||
print("测试 MySQL 数据库连接(通过 SSH 隧道)")
|
||||
print("="*60)
|
||||
|
||||
config = load_config()
|
||||
mysql_config = config['mysql']
|
||||
|
||||
print(f"\n📋 SSH 服务器:")
|
||||
print(f" 地址: {config['host']}")
|
||||
print(f" 端口: {config['port']}")
|
||||
print(f" 用户: {config['username']}")
|
||||
|
||||
print(f"\n📋 MySQL 配置:")
|
||||
print(f" 主机: {mysql_config['host']}")
|
||||
print(f" 端口: {mysql_config['port']}")
|
||||
print(f" 用户: {mysql_config['username']}")
|
||||
print(f" 数据库: {mysql_config['database']}")
|
||||
|
||||
tunnel = None
|
||||
|
||||
try:
|
||||
print("\n🔌 创建 SSH 隧道...")
|
||||
tunnel = SSHTunnelForwarder(
|
||||
(config['host'], int(config.get('port', 22))),
|
||||
ssh_username=config['username'],
|
||||
ssh_password=config['password'],
|
||||
remote_bind_address=('127.0.0.1', int(mysql_config.get('port', 3306)))
|
||||
)
|
||||
tunnel.start()
|
||||
print(f"✅ SSH 隧道已建立,本地端口: {tunnel.local_bind_port}")
|
||||
|
||||
print("\n🔌 连接 MySQL...")
|
||||
conn = pymysql.connect(
|
||||
host='127.0.0.1',
|
||||
port=tunnel.local_bind_port,
|
||||
user=mysql_config['username'],
|
||||
password=mysql_config['password'],
|
||||
database=mysql_config['database'],
|
||||
charset='utf8mb4',
|
||||
cursorclass=pymysql.cursors.DictCursor
|
||||
)
|
||||
|
||||
print("✅ MySQL 连接成功!")
|
||||
|
||||
# 测试创建表
|
||||
print("\n📝 创建/检查 app_deployments 表...")
|
||||
with conn.cursor() as cursor:
|
||||
sql = """
|
||||
CREATE TABLE IF NOT EXISTS app_deployments (
|
||||
id INT PRIMARY KEY AUTO_INCREMENT,
|
||||
version VARCHAR(50) UNIQUE NOT NULL,
|
||||
deployed_at DATETIME NOT NULL,
|
||||
is_current BOOLEAN DEFAULT FALSE,
|
||||
file_size_mb DECIMAL(10, 2),
|
||||
comment VARCHAR(500),
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
)
|
||||
"""
|
||||
cursor.execute(sql)
|
||||
conn.commit()
|
||||
print("✅ 表已就绪")
|
||||
|
||||
# 查看表结构
|
||||
print("\n📊 表结构:")
|
||||
with conn.cursor() as cursor:
|
||||
cursor.execute("DESCRIBE app_deployments")
|
||||
for row in cursor.fetchall():
|
||||
print(f" {row['Field']}: {row['Type']} {'(主键)' if row['Key'] == 'PRI' else ''}")
|
||||
|
||||
# 查看现有数据
|
||||
print("\n📚 现有部署记录:")
|
||||
with conn.cursor() as cursor:
|
||||
cursor.execute("SELECT * FROM app_deployments ORDER BY deployed_at DESC")
|
||||
records = cursor.fetchall()
|
||||
|
||||
if records:
|
||||
for i, rec in enumerate(records, 1):
|
||||
status = "✅ 当前" if rec['is_current'] else ""
|
||||
print(f"\n [{i}] {rec['version']} {status}")
|
||||
print(f" 部署时间: {rec['deployed_at']}")
|
||||
print(f" 大小: {rec['file_size_mb']} MB")
|
||||
print(f" 备注: {rec['comment'] or '无'}")
|
||||
else:
|
||||
print(" (暂无记录)")
|
||||
|
||||
conn.close()
|
||||
|
||||
print("\n" + "="*60)
|
||||
print("✅ 测试完成!数据库一切正常")
|
||||
print("="*60)
|
||||
|
||||
except Exception as e:
|
||||
print(f"\n❌ 测试失败: {e}")
|
||||
print("\n请检查:")
|
||||
print(" 1. SSH 服务器是否可访问")
|
||||
print(" 2. deploy_config.json 配置是否正确")
|
||||
print(" 3. 服务器上 MySQL 服务是否运行")
|
||||
print(" 4. 数据库用户权限是否足够")
|
||||
return False
|
||||
finally:
|
||||
if tunnel:
|
||||
tunnel.stop()
|
||||
print("\n🔌 SSH 隧道已关闭")
|
||||
|
||||
return True
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_connection()
|
||||
@@ -1,24 +0,0 @@
|
||||
import sys
|
||||
from PyQt5.QtWidgets import QApplication
|
||||
try:
|
||||
from admin_gui import AdminWindow
|
||||
print("Successfully imported AdminWindow")
|
||||
except Exception as e:
|
||||
print(f"Failed to import AdminWindow: {e}")
|
||||
sys.exit(1)
|
||||
|
||||
def main():
|
||||
app = QApplication(sys.argv)
|
||||
try:
|
||||
window = AdminWindow()
|
||||
print("Successfully instantiated AdminWindow")
|
||||
# Don't show or exec, just check if it crashes on init
|
||||
# window.show()
|
||||
except Exception as e:
|
||||
print(f"Failed to instantiate AdminWindow: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
sys.exit(1)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,113 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
测试版本管理系统(使用 SSH + JSON 文件)
|
||||
"""
|
||||
import json
|
||||
import sys
|
||||
import io
|
||||
import paramiko
|
||||
|
||||
# 设置 stdout 为 UTF-8
|
||||
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
|
||||
|
||||
def load_config():
|
||||
with open('deploy_config.json', 'r', encoding='utf-8') as f:
|
||||
return json.load(f)
|
||||
|
||||
def test_connection():
|
||||
print("="*60)
|
||||
print("测试版本管理系统(SSH + JSON 文件)")
|
||||
print("="*60)
|
||||
|
||||
config = load_config()
|
||||
|
||||
print(f"\n📋 SSH 服务器:")
|
||||
print(f" 地址: {config['host']}")
|
||||
print(f" 端口: {config['port']}")
|
||||
print(f" 用户: {config['username']}")
|
||||
|
||||
ssh = None
|
||||
sftp = None
|
||||
remote_file = '/var/www/app_versions/.deployments.json'
|
||||
|
||||
try:
|
||||
print("\n🔌 连接 SSH...")
|
||||
ssh = paramiko.SSHClient()
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
ssh.connect(
|
||||
hostname=config['host'],
|
||||
port=int(config.get('port', 22)),
|
||||
username=config['username'],
|
||||
password=config['password'],
|
||||
timeout=10
|
||||
)
|
||||
print("✅ SSH 连接成功!")
|
||||
|
||||
# 测试创建目录
|
||||
print("\n📁 检查/创建版本目录...")
|
||||
stdin, stdout, stderr = ssh.exec_command('mkdir -p /var/www/app_versions')
|
||||
stdout.channel.recv_exit_status()
|
||||
print("✅ 目录已就绪: /var/www/app_versions/")
|
||||
|
||||
# 测试读写 JSON 文件
|
||||
print(f"\n📝 测试版本记录文件: {remote_file}")
|
||||
sftp = ssh.open_sftp()
|
||||
|
||||
try:
|
||||
# 尝试读取现有文件
|
||||
with sftp.open(remote_file, 'r') as f:
|
||||
content = f.read().decode('utf-8')
|
||||
data = json.loads(content)
|
||||
print(f"✅ 文件已存在,读取成功")
|
||||
except IOError:
|
||||
# 文件不存在,创建新文件
|
||||
print(" 文件不存在,创建新文件...")
|
||||
data = {'deployments': []}
|
||||
with sftp.open(remote_file, 'w') as f:
|
||||
f.write(json.dumps(data, indent=2, ensure_ascii=False).encode('utf-8'))
|
||||
print("✅ 文件创建成功")
|
||||
|
||||
# 显示现有记录
|
||||
print("\n📚 现有部署记录:")
|
||||
if data['deployments']:
|
||||
for i, rec in enumerate(sorted(data['deployments'], key=lambda x: x['deployed_at'], reverse=True), 1):
|
||||
status = "✅ 当前" if rec.get('is_current') else ""
|
||||
print(f"\n [{i}] {rec['version']} {status}")
|
||||
print(f" 部署时间: {rec['deployed_at']}")
|
||||
print(f" 大小: {rec.get('file_size_mb', '-')} MB")
|
||||
print(f" 备注: {rec.get('comment') or '无'}")
|
||||
else:
|
||||
print(" (暂无记录)")
|
||||
|
||||
# 测试写入
|
||||
print("\n✏️ 测试写入...")
|
||||
with sftp.open(remote_file, 'w') as f:
|
||||
f.write(json.dumps(data, indent=2, ensure_ascii=False).encode('utf-8'))
|
||||
print("✅ 写入成功")
|
||||
|
||||
print("\n" + "="*60)
|
||||
print("✅ 测试完成!版本管理系统一切正常")
|
||||
print("="*60)
|
||||
print("\n💡 系统说明:")
|
||||
print(" - 不需要 MySQL 数据库")
|
||||
print(" - 版本信息存储在服务器的 JSON 文件中")
|
||||
print(" - 文件位置: /var/www/app_versions/.deployments.json")
|
||||
|
||||
except Exception as e:
|
||||
print(f"\n❌ 测试失败: {e}")
|
||||
print("\n请检查:")
|
||||
print(" 1. SSH 服务器是否可访问")
|
||||
print(" 2. deploy_config.json 配置是否正确")
|
||||
print(" 3. 服务器上是否有写入权限")
|
||||
return False
|
||||
finally:
|
||||
if sftp:
|
||||
sftp.close()
|
||||
if ssh:
|
||||
ssh.close()
|
||||
|
||||
return True
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_connection()
|
||||
|
||||
Reference in New Issue
Block a user