This commit is contained in:
parent
a34ca0e959
commit
6df9130bce
18
test/tools/check_page.py
Normal file
18
test/tools/check_page.py
Normal file
@ -0,0 +1,18 @@
|
||||
from playwright.sync_api import sync_playwright
|
||||
|
||||
with sync_playwright() as p:
|
||||
browser = p.chromium.launch(headless=True)
|
||||
page = browser.new_page()
|
||||
page.on(console, lambda msg: print(f[CONSOLE {msg.type}] {msg.text}))
|
||||
page.on(pageerror, lambda exc: print(f[PAGE ERROR] {exc}))
|
||||
response = page.goto(http://47.108.78.12/)
|
||||
print(Status:, response.status)
|
||||
content = page.content()
|
||||
print(HTML length:, len(content))
|
||||
next_btn = page.locator(#next)
|
||||
print(next locator count:, next_btn.count())
|
||||
buttons = page.locator(button)
|
||||
print(Total buttons:, buttons.count())
|
||||
for i in range(buttons.count()):
|
||||
print(fButton {i}: text={buttons.nth(i).inner_text()} id={buttons.nth(i).get_attribute('id')})
|
||||
browser.close()
|
||||
8
test/tools/check_remote_db.py
Normal file
8
test/tools/check_remote_db.py
Normal file
@ -0,0 +1,8 @@
|
||||
import paramiko
|
||||
client = paramiko.SSHClient()
|
||||
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
client.connect('47.108.78.12', port=22, username='root', password='10102442Lb!', timeout=8)
|
||||
cmd = 'systemctl list-unit-files | grep -E (mysql|mariadb|postgresql)'
|
||||
stdin, stdout, stderr = client.exec_command(cmd)
|
||||
print(DB units:, stdout.read().decode('utf-8'))
|
||||
client.close()
|
||||
70
test/tools/run_visual_setup.py
Normal file
70
test/tools/run_visual_setup.py
Normal file
@ -0,0 +1,70 @@
|
||||
import time, os
|
||||
from playwright.sync_api import sync_playwright
|
||||
|
||||
test_log_dir = os.path.join(os.getcwd(), 'test-log', 'cloud-deploy-' + str(int(time.time())))
|
||||
os.makedirs(test_log_dir, exist_ok=True)
|
||||
|
||||
with sync_playwright() as p:
|
||||
print('启动可视化浏览器...')
|
||||
browser = p.chromium.launch(
|
||||
headless=False,
|
||||
slow_mo=800,
|
||||
args=['--start-maximized', '--no-sandbox']
|
||||
)
|
||||
context = browser.new_context(viewport=None)
|
||||
page = context.new_page()
|
||||
|
||||
print('打开: http://47.108.78.12/')
|
||||
page.goto('http://47.108.78.12/', wait_until='networkidle')
|
||||
time.sleep(1)
|
||||
page.screenshot(path=os.path.join(test_log_dir, 'step0_welcome.png'))
|
||||
|
||||
# Step 0 -> 1: 点击欢迎界面的下一步 (id=next)
|
||||
print('点击欢迎页 #next...')
|
||||
page.locator('#next').click()
|
||||
time.sleep(2)
|
||||
page.screenshot(path=os.path.join(test_log_dir, 'step1_database.png'))
|
||||
|
||||
# Step 1: 数据库选择 (默认 SQLite3)
|
||||
print('数据库页 #next (SQLite3)...')
|
||||
page.locator('#next').click()
|
||||
time.sleep(2)
|
||||
page.screenshot(path=os.path.join(test_log_dir, 'step2_admin_password.png'))
|
||||
|
||||
# Step 2: 输入管理员密码
|
||||
print('输入管理员密码 10102442Lb!...')
|
||||
pwd_inputs = page.locator('.form input')
|
||||
print('密码页输入框数量:', pwd_inputs.count())
|
||||
for i in range(pwd_inputs.count()):
|
||||
pwd_inputs.nth(i).fill('10102442Lb!')
|
||||
|
||||
time.sleep(1)
|
||||
page.screenshot(path=os.path.join(test_log_dir, 'step2_password_filled.png'))
|
||||
page.locator('#next').click()
|
||||
time.sleep(2)
|
||||
page.screenshot(path=os.path.join(test_log_dir, 'step3_domain.png'))
|
||||
|
||||
# Step 3: 设置域名
|
||||
print('设置域名: web=mail.solit.cn, smtp=solit.cn...')
|
||||
domain_inputs = page.locator('.form input')
|
||||
print('域名页输入框数量:', domain_inputs.count())
|
||||
if domain_inputs.count() >= 2:
|
||||
domain_inputs.nth(0).fill('mail.solit.cn')
|
||||
domain_inputs.nth(1).fill('solit.cn')
|
||||
|
||||
time.sleep(1)
|
||||
page.screenshot(path=os.path.join(test_log_dir, 'step3_domain_filled.png'))
|
||||
page.locator('#next').click()
|
||||
time.sleep(3)
|
||||
page.screenshot(path=os.path.join(test_log_dir, 'step4_dns_records.png'))
|
||||
|
||||
# Step 4: DNS 设置预览
|
||||
print('DNS 记录预览页,等待 3 秒观察...')
|
||||
time.sleep(3)
|
||||
page.locator('#next').click()
|
||||
time.sleep(3)
|
||||
page.screenshot(path=os.path.join(test_log_dir, 'step5_ssl.png'))
|
||||
|
||||
print('已成功推进至 SSL 设置页,保持窗口开启供查看 15 秒...')
|
||||
time.sleep(15)
|
||||
browser.close()
|
||||
75
test/tools/run_visual_wizard.py
Normal file
75
test/tools/run_visual_wizard.py
Normal file
@ -0,0 +1,75 @@
|
||||
import time, os
|
||||
from playwright.sync_api import sync_playwright
|
||||
|
||||
test_log_dir = os.path.join(os.getcwd(), 'test-log', 'cloud-setup-' + str(int(time.time())))
|
||||
os.makedirs(test_log_dir, exist_ok=True)
|
||||
|
||||
with sync_playwright() as p:
|
||||
print('启动可视化浏览器,开始初始化向导流程...')
|
||||
browser = p.chromium.launch(
|
||||
headless=False,
|
||||
slow_mo=600,
|
||||
args=['--start-maximized', '--no-sandbox']
|
||||
)
|
||||
context = browser.new_context(viewport=None)
|
||||
page = context.new_page()
|
||||
|
||||
print('直接访问引导页: http://47.108.78.12/#/setup')
|
||||
page.goto('http://47.108.78.12/#/setup', wait_until='networkidle')
|
||||
time.sleep(2)
|
||||
page.screenshot(path=os.path.join(test_log_dir, 'step0_welcome.png'))
|
||||
print('【步骤 0:欢迎页】截图已保存')
|
||||
|
||||
# 点击下一步进入数据库设置
|
||||
print('点击“下一步”进入数据库设置...')
|
||||
page.locator('#next').click()
|
||||
time.sleep(2)
|
||||
page.screenshot(path=os.path.join(test_log_dir, 'step1_database.png'))
|
||||
print('【步骤 1:数据库设置】截图已保存,默认选用 SQLite3')
|
||||
|
||||
# 点击下一步进入管理员密码设置
|
||||
print('确认 SQLite3 数据库,点击“下一步”...')
|
||||
page.locator('#next').click()
|
||||
time.sleep(2)
|
||||
page.screenshot(path=os.path.join(test_log_dir, 'step2_admin_password.png'))
|
||||
print('【步骤 2:设置管理员密码】截图已保存')
|
||||
|
||||
# 输入密码
|
||||
inputs = page.locator('.database-form input, .ctn input')
|
||||
print('找到输入框数量:', inputs.count())
|
||||
for i in range(inputs.count()):
|
||||
inputs.nth(i).fill('10102442Lb!')
|
||||
|
||||
time.sleep(1)
|
||||
page.screenshot(path=os.path.join(test_log_dir, 'step2_password_filled.png'))
|
||||
page.locator('#next').click()
|
||||
time.sleep(2)
|
||||
page.screenshot(path=os.path.join(test_log_dir, 'step3_domain.png'))
|
||||
print('【步骤 3:设置域名】截图已保存')
|
||||
|
||||
# 填写域名: Web域名与主域名
|
||||
domain_inputs = page.locator('.ctn input')
|
||||
print('域名输入框数量:', domain_inputs.count())
|
||||
if domain_inputs.count() >= 2:
|
||||
domain_inputs.nth(0).fill('mail.solit.cn')
|
||||
domain_inputs.nth(1).fill('solit.cn')
|
||||
elif domain_inputs.count() == 1:
|
||||
domain_inputs.first.fill('solit.cn')
|
||||
|
||||
time.sleep(1)
|
||||
page.screenshot(path=os.path.join(test_log_dir, 'step3_domain_filled.png'))
|
||||
print('点击“下一步”提交域名配置...')
|
||||
page.locator('#next').click()
|
||||
time.sleep(3)
|
||||
page.screenshot(path=os.path.join(test_log_dir, 'step4_dns.png'))
|
||||
print('【步骤 4:DNS 设置检查】截图已保存,展示权威解析记录状态')
|
||||
|
||||
# 点击下一步进入 SSL 配置
|
||||
time.sleep(3)
|
||||
print('点击“下一步”进入 SSL 证书配置...')
|
||||
page.locator('#next').click()
|
||||
time.sleep(3)
|
||||
page.screenshot(path=os.path.join(test_log_dir, 'step5_ssl.png'))
|
||||
print('【步骤 5:SSL 证书模式】截图已保存,窗口将保持 20 秒供查看...')
|
||||
time.sleep(20)
|
||||
browser.close()
|
||||
22
test/tools/test_remote_setup.py
Normal file
22
test/tools/test_remote_setup.py
Normal file
@ -0,0 +1,22 @@
|
||||
import paramiko
|
||||
client = paramiko.SSHClient()
|
||||
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
client.connect('47.108.78.12', port=22, username='root', password='10102442Lb!', timeout=8)
|
||||
client.exec_command('systemctl stop smail-init; pkill -9 smail')
|
||||
|
||||
setup_script = '''#!/bin/bash
|
||||
export SMAIL_SETUP_HOST=0.0.0.0
|
||||
export SMAIL_SETUP_ALLOWED_CIDRS=0.0.0.0/0
|
||||
export SMAIL_SETUP_TOKEN=setup-secret-token-1234567890123456
|
||||
cd /opt/smail
|
||||
exec ./smail -p 80
|
||||
'''
|
||||
sftp = client.open_sftp()
|
||||
with sftp.file('/opt/smail/start-setup.sh', 'w') as f:
|
||||
f.write(setup_script)
|
||||
sftp.close()
|
||||
|
||||
cmd2 = 'chmod +x /opt/smail/start-setup.sh; nohup /opt/smail/start-setup.sh > /opt/smail/log/init.log 2>&1 & sleep 2; ss -tulnp | grep 80'
|
||||
stdin, stdout, stderr = client.exec_command(cmd2)
|
||||
print(stdout.read().decode('utf-8'))
|
||||
client.close()
|
||||
Loading…
Reference in New Issue
Block a user