修复生产审查凭据泄露风险并增加持久投递队列
This commit is contained in:
1 parent
071460ed9a
commit
6b009197bc
70 files changed
+1581
-262
No files matched your search
@@ -1,10 +1,11 @@
|
||||
from email.mime.text import MIMEText
|
||||
import smtplib
|
||||
import os
|
||||
msg = MIMEText('hello, send by Python...', 'plain', 'utf-8')
|
||||
|
||||
|
||||
from_addr = "admin@domain.com"
|
||||
password = "admin"
|
||||
password = os.environ["SMAIL_TEST_SMTP_PASSWORD"]
|
||||
to_addr = "admin@domain.com"
|
||||
smtp_server = "127.0.0.1"
|
||||
|
||||
@@ -12,4 +13,4 @@ server = smtplib.SMTP(smtp_server, 25)
|
||||
server.starttls()
|
||||
server.login(from_addr, password)
|
||||
server.sendmail(from_addr, [to_addr], msg.as_string())
|
||||
server.quit()
|
||||
server.quit()
|
||||
+3
-2
@@ -1,7 +1,8 @@
|
||||
import paramiko
|
||||
ssh = paramiko.SSHClient()
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
ssh.connect('47.108.78.12', port=22, username='root', password='10102442Lb!', timeout=10)
|
||||
ssh.set_missing_host_key_policy(paramiko.RejectPolicy())
|
||||
from tools.remote_ssh import connect_remote
|
||||
connect_remote(ssh)
|
||||
sftp = ssh.open_sftp()
|
||||
print('Uploading out/smail to /opt/smail/smail.new ...')
|
||||
sftp.put('out/smail', '/opt/smail/smail.new')
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import urllib.request, urllib.parse, hmac, hashlib, base64, time, json, paramiko, subprocess
|
||||
|
||||
client = paramiko.SSHClient()
|
||||
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
client.connect('47.108.78.12', port=22, username='root', password='10102442Lb!', timeout=10)
|
||||
client.set_missing_host_key_policy(paramiko.RejectPolicy())
|
||||
from remote_ssh import connect_remote
|
||||
connect_remote(client)
|
||||
stdin, stdout, stderr = client.exec_command('cat /opt/smail/ssl/dkim/dkim.priv')
|
||||
priv_key = stdout.read().decode('utf-8')
|
||||
client.close()
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import paramiko
|
||||
ssh = paramiko.SSHClient()
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
ssh.connect('47.108.78.12', port=22, username='root', password='10102442Lb!', timeout=10)
|
||||
ssh.set_missing_host_key_policy(paramiko.RejectPolicy())
|
||||
from remote_ssh import connect_remote
|
||||
connect_remote(ssh)
|
||||
_, out, _ = ssh.exec_command('cat /opt/smail/config/smtp.json; echo ===; cat /opt/smail/config/email.json')
|
||||
print(out.read().decode('utf-8', errors='ignore'))
|
||||
ssh.close()
|
||||
@@ -1,7 +1,8 @@
|
||||
import paramiko
|
||||
ssh = paramiko.SSHClient()
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
ssh.connect('47.108.78.12', port=22, username='root', password='10102442Lb!', timeout=10)
|
||||
ssh.set_missing_host_key_policy(paramiko.RejectPolicy())
|
||||
from remote_ssh import connect_remote
|
||||
connect_remote(ssh)
|
||||
stdin, stdout, stderr = ssh.exec_command("sqlite3 /opt/smail/data/smail.db \"SELECT * FROM client_credential;\"")
|
||||
print('client_credential:\n', stdout.read().decode())
|
||||
stdin, stdout, stderr = ssh.exec_command("sqlite3 /opt/smail/data/smail.db \"SELECT * FROM protocol_credential;\"")
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import paramiko
|
||||
ssh = paramiko.SSHClient()
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
ssh.connect("47.108.78.12", port=22, username="root", password="10102442Lb!", timeout=10)
|
||||
ssh.set_missing_host_key_policy(paramiko.RejectPolicy())
|
||||
from remote_ssh import connect_remote
|
||||
connect_remote(ssh)
|
||||
stdin, stdout, stderr = ssh.exec_command('sqlite3 /opt/smail/data/smail.db "SELECT id, type, subject, from_address, send_user_id, status, error, create_time FROM email WHERE id >= 20;"')
|
||||
print("Security questions:\n", stdout.read().decode())
|
||||
stdin, stdout, stderr = ssh.exec_command('sqlite3 /opt/smail/data/smail.db "SELECT id, user_id, email_id, is_read, group_id, status, create FROM user_email WHERE email_id >= 20;"')
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import paramiko
|
||||
ssh = paramiko.SSHClient()
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
ssh.connect("47.108.78.12", port=22, username="root", password="10102442Lb!", timeout=10)
|
||||
ssh.set_missing_host_key_policy(paramiko.RejectPolicy())
|
||||
from remote_ssh import connect_remote
|
||||
connect_remote(ssh)
|
||||
stdin, stdout, stderr = ssh.exec_command('sqlite3 /opt/smail/data/smail.db "SELECT id, type, subject, from_address, [to], send_user_id, status FROM email WHERE id >= 10;"')
|
||||
print("Emails >= 10:\n", stdout.read().decode())
|
||||
stdin, stdout, stderr = ssh.exec_command('sqlite3 /opt/smail/data/smail.db "SELECT id, user_id, email_id, is_read, group_id, status FROM user_email WHERE email_id >= 10;"')
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import paramiko
|
||||
ssh = paramiko.SSHClient()
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
ssh.connect("47.108.78.12", port=22, username="root", password="10102442Lb!", timeout=10)
|
||||
ssh.set_missing_host_key_policy(paramiko.RejectPolicy())
|
||||
from remote_ssh import connect_remote
|
||||
connect_remote(ssh)
|
||||
stdin, stdout, stderr = ssh.exec_command('sqlite3 /opt/smail/data/smail.db "SELECT id, error FROM email WHERE id = 24;"')
|
||||
print("Email 24 error:\n", stdout.read().decode())
|
||||
stdin, stdout, stderr = ssh.exec_command('sqlite3 /opt/smail/data/smail.db "SELECT * FROM email WHERE id = 24;"')
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import paramiko
|
||||
ssh = paramiko.SSHClient()
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
ssh.connect('47.108.78.12', port=22, username='root', password='10102442Lb!', timeout=10)
|
||||
ssh.set_missing_host_key_policy(paramiko.RejectPolicy())
|
||||
from remote_ssh import connect_remote
|
||||
connect_remote(ssh)
|
||||
stdin, stdout, stderr = ssh.exec_command("sqlite3 /opt/smail/data/smail.db \"SELECT sql FROM sqlite_master WHERE name='external_email';\"")
|
||||
print('SCHEMA:\n', stdout.read().decode())
|
||||
stdin, stdout, stderr = ssh.exec_command("sqlite3 /opt/smail/data/smail.db \"SELECT * FROM external_email;\"")
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import paramiko
|
||||
ssh = paramiko.SSHClient()
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
ssh.connect("47.108.78.12", port=22, username="root", password="10102442Lb!", timeout=10)
|
||||
ssh.set_missing_host_key_policy(paramiko.RejectPolicy())
|
||||
from remote_ssh import connect_remote
|
||||
connect_remote(ssh)
|
||||
stdin, stdout, stderr = ssh.exec_command('sqlite3 /opt/smail/data/smail.db "SELECT e.id, e.subject, e.type, ue.status, ue.group_id, ue.is_read FROM email e LEFT JOIN user_email ue ON e.id = ue.email_id WHERE ue.user_id = 1 AND ue.status = 0 AND e.type = 0 AND (ue.group_id = 0 OR ue.group_id = 1) ORDER BY e.id DESC;"')
|
||||
print("Inbox query result:\n", stdout.read().decode())
|
||||
stdin, stdout, stderr = ssh.exec_command('sqlite3 /opt/smail/data/smail.db "SELECT e.id, e.subject, e.type, e.status, e.error FROM email e WHERE e.send_user_id = 1 ORDER BY e.id DESC LIMIT 5;"')
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import paramiko
|
||||
ssh = paramiko.SSHClient()
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
ssh.connect("47.108.78.12", port=22, username="root", password="10102442Lb!", timeout=10)
|
||||
ssh.set_missing_host_key_policy(paramiko.RejectPolicy())
|
||||
from remote_ssh import connect_remote
|
||||
connect_remote(ssh)
|
||||
stdin, stdout, stderr = ssh.exec_command("tail -n 25 /opt/smail/log/stdout.log")
|
||||
print(stdout.read().decode("utf-8", errors="ignore"))
|
||||
stdin, stdout, stderr = ssh.exec_command("ps aux | grep smail")
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import paramiko
|
||||
ssh = paramiko.SSHClient()
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
ssh.connect("47.108.78.12", port=22, username="root", password="10102442Lb!", timeout=10)
|
||||
ssh.set_missing_host_key_policy(paramiko.RejectPolicy())
|
||||
from remote_ssh import connect_remote
|
||||
connect_remote(ssh)
|
||||
stdin, stdout, stderr = ssh.exec_command('tail -n 40 /opt/smail/log/runtime-2026-09-14.log')
|
||||
print("Grep 6567567:\n", stdout.read().decode())
|
||||
stdin, stdout, stderr = ssh.exec_command('tail -n 40 /opt/smail/log/stdout.log')
|
||||
|
||||
@@ -1,7 +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)
|
||||
client.set_missing_host_key_policy(paramiko.RejectPolicy())
|
||||
from remote_ssh import connect_remote
|
||||
connect_remote(client)
|
||||
cmd = 'systemctl list-unit-files | grep -E "(mysql|mariadb|postgresql)"'
|
||||
stdin, stdout, stderr = client.exec_command(cmd)
|
||||
print("DB units:\n", stdout.read().decode('utf-8'))
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import paramiko
|
||||
ssh = paramiko.SSHClient()
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
ssh.connect('47.108.78.12', port=22, username='root', password='10102442Lb!', timeout=10)
|
||||
ssh.set_missing_host_key_policy(paramiko.RejectPolicy())
|
||||
from remote_ssh import connect_remote
|
||||
connect_remote(ssh)
|
||||
_, out, _ = ssh.exec_command('ss -tulpn; ps aux | grep smail')
|
||||
print(out.read().decode('utf-8', errors='ignore'))
|
||||
ssh.close()
|
||||
@@ -1,8 +1,9 @@
|
||||
import paramiko
|
||||
|
||||
ssh = paramiko.SSHClient()
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
ssh.connect("47.108.78.12", port=22, username="root", password="10102442Lb!")
|
||||
ssh.set_missing_host_key_policy(paramiko.RejectPolicy())
|
||||
from remote_ssh import connect_remote
|
||||
connect_remote(ssh)
|
||||
|
||||
sftp = ssh.open_sftp()
|
||||
with sftp.open("/tmp/test_api.py", "w") as f:
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import paramiko
|
||||
ssh = paramiko.SSHClient()
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
ssh.connect("47.108.78.12", port=22, username="root", password="10102442Lb!", timeout=10)
|
||||
ssh.set_missing_host_key_policy(paramiko.RejectPolicy())
|
||||
from remote_ssh import connect_remote
|
||||
connect_remote(ssh)
|
||||
stdin, stdout, stderr = ssh.exec_command('sqlite3 /opt/smail/data/smail.db "date"')
|
||||
print("Security questions:\n", stdout.read().decode())
|
||||
stdin, stdout, stderr = ssh.exec_command('sqlite3 /opt/smail/data/smail.db "date -u"')
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import paramiko
|
||||
ssh = paramiko.SSHClient()
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
ssh.connect("47.108.78.12", port=22, username="root", password="10102442Lb!", timeout=10)
|
||||
ssh.set_missing_host_key_policy(paramiko.RejectPolicy())
|
||||
from remote_ssh import connect_remote
|
||||
connect_remote(ssh)
|
||||
stdin, stdout, stderr = ssh.exec_command('date')
|
||||
print("Server Date:\n", stdout.read().decode())
|
||||
stdin, stdout, stderr = ssh.exec_command('uptime')
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import paramiko
|
||||
ssh = paramiko.SSHClient()
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
ssh.connect("47.108.78.12", port=22, username="root", password="10102442Lb!", timeout=10)
|
||||
ssh.set_missing_host_key_policy(paramiko.RejectPolicy())
|
||||
from remote_ssh import connect_remote
|
||||
connect_remote(ssh)
|
||||
stdin, stdout, stderr = ssh.exec_command('sqlite3 /opt/smail/data/smail.db "SELECT user_id, email_id FROM user_email WHERE email_id = 22;"')
|
||||
print("Security questions:\n", stdout.read().decode())
|
||||
stdin, stdout, stderr = ssh.exec_command('sqlite3 /opt/smail/data/smail.db "SELECT user_id, email_id FROM user_email WHERE email_id = 23;"')
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import paramiko
|
||||
|
||||
ssh = paramiko.SSHClient()
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
ssh.connect("47.108.78.12", port=22, username="root", password="10102442Lb!", timeout=10)
|
||||
ssh.set_missing_host_key_policy(paramiko.RejectPolicy())
|
||||
from remote_ssh import connect_remote
|
||||
connect_remote(ssh)
|
||||
|
||||
def run(cmd):
|
||||
stdin, stdout, stderr = ssh.exec_command(cmd)
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import paramiko
|
||||
ssh = paramiko.SSHClient()
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
ssh.connect('47.108.78.12', port=22, username='root', password='10102442Lb!', timeout=10)
|
||||
ssh.set_missing_host_key_policy(paramiko.RejectPolicy())
|
||||
from remote_ssh import connect_remote
|
||||
connect_remote(ssh)
|
||||
|
||||
s = '''import sqlite3, base64, glob
|
||||
from cryptography.hazmat.primitives.ciphers.aead import AESGCM
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
"""仅在 47 服务器备份并升级 Smail,保留双库和失败证据。"""
|
||||
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import sqlite3
|
||||
import subprocess
|
||||
import time
|
||||
|
||||
|
||||
ROOT = Path('/opt/smail')
|
||||
STAGING = Path('/var/tmp/smail-review-20260917')
|
||||
DATABASES = ('smail.db', 'smail-state.db')
|
||||
|
||||
|
||||
def run(*args):
|
||||
return subprocess.check_output(args, text=True).strip()
|
||||
|
||||
|
||||
def digest(path):
|
||||
with path.open('rb') as stream:
|
||||
return hashlib.file_digest(stream, 'sha256').hexdigest()
|
||||
|
||||
|
||||
def snapshot(source, target):
|
||||
with sqlite3.connect(f'file:{source}?mode=ro', uri=True) as original:
|
||||
with sqlite3.connect(target) as copied:
|
||||
original.backup(copied)
|
||||
assert copied.execute('PRAGMA integrity_check').fetchone()[0] == 'ok'
|
||||
target.chmod(0o600)
|
||||
|
||||
|
||||
def wait_ready():
|
||||
for _ in range(60):
|
||||
result = subprocess.run([
|
||||
'curl', '--silent', '--fail', '--max-time', '2', '--noproxy', '*',
|
||||
'--cacert', str(ROOT / 'ssl/custom.crt'), '--resolve',
|
||||
'mail.solit.cn:443:127.0.0.1', 'https://mail.solit.cn/api/ping',
|
||||
], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
if result.returncode == 0 and run('systemctl', 'is-active', 'smail.service') == 'active':
|
||||
return
|
||||
time.sleep(1)
|
||||
raise RuntimeError('升级后服务未就绪')
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--main-sha', required=True)
|
||||
parser.add_argument('--admin-sha', required=True)
|
||||
args = parser.parse_args()
|
||||
os.umask(0o077)
|
||||
assert os.geteuid() == 0 and ROOT.resolve() == ROOT and not ROOT.is_symlink()
|
||||
assert run('hostname') == 'ikun2'
|
||||
assert '172.31.134.42/20' in run('ip', '-4', 'address', 'show')
|
||||
assert run('systemctl', 'show', 'smail.service', '--property=User', '--value') == 'smail'
|
||||
assert run('systemctl', 'is-active', 'smail.service') == 'active'
|
||||
expected = {'smail': args.main_sha, 'smail-admin': args.admin_sha}
|
||||
for name, checksum in expected.items():
|
||||
path = STAGING / name
|
||||
with path.open('rb') as binary:
|
||||
header = binary.read(20)
|
||||
assert header[:5] == b'\x7fELF\x02' and header[18:20] == b'\x3e\x00'
|
||||
assert digest(path) == checksum
|
||||
assert not (ROOT / name).is_symlink()
|
||||
|
||||
backup = Path('/var/backups') / time.strftime('smail-before-outbox-%Y%m%d-%H%M%S')
|
||||
backup.mkdir(mode=0o700)
|
||||
installed = False
|
||||
subprocess.run(['systemctl', 'stop', 'smail.service'], check=True)
|
||||
try:
|
||||
# 停服归档包含配置、密钥和日志,仅保存在远程受保护目录。
|
||||
archive = backup / 'smail.tar.gz'
|
||||
subprocess.run(['tar', '-czf', str(archive), '-C', '/opt', 'smail'], check=True)
|
||||
subprocess.run(['tar', '-dzf', str(archive), '-C', '/opt'], check=True)
|
||||
archive.chmod(0o600)
|
||||
for name in DATABASES:
|
||||
source = ROOT / 'data' / name
|
||||
assert source.resolve() == source and not source.is_symlink()
|
||||
snapshot(source, backup / name)
|
||||
for name in expected:
|
||||
shutil.copy2(ROOT / name, backup / name)
|
||||
installed = True
|
||||
for name, checksum in expected.items():
|
||||
subprocess.run(['install', '-m', '0755', '-o', 'root', '-g', 'root',
|
||||
str(STAGING / name), str(ROOT / name)], check=True)
|
||||
assert digest(ROOT / name) == checksum
|
||||
subprocess.run(['systemctl', 'start', 'smail.service'], check=True)
|
||||
wait_ready()
|
||||
for name in DATABASES:
|
||||
with sqlite3.connect(f'file:{ROOT / "data" / name}?mode=ro', uri=True) as database:
|
||||
assert database.execute('PRAGMA integrity_check').fetchone()[0] == 'ok'
|
||||
with sqlite3.connect(f'file:{ROOT / "data/smail.db"}?mode=ro', uri=True) as database:
|
||||
version = database.execute('SELECT MAX(version) FROM schema_migration').fetchone()[0]
|
||||
assert version == 23
|
||||
states = dict(database.execute('SELECT state,COUNT(*) FROM outbound_delivery GROUP BY state'))
|
||||
result = {'backup': str(backup), 'archive_sha256': digest(archive),
|
||||
'artifacts': expected, 'migration': version, 'queue_states': states,
|
||||
'service': run('systemctl', 'is-active', 'smail.service'),
|
||||
'admin_version': run(str(ROOT / 'smail-admin'), 'version'),
|
||||
'database_integrity': 'ok', 'database_reset': False}
|
||||
(backup / 'result.json').write_text(json.dumps(result, ensure_ascii=False, indent=2), encoding='utf-8')
|
||||
print(json.dumps(result, ensure_ascii=False, indent=2))
|
||||
except BaseException:
|
||||
if installed:
|
||||
subprocess.run(['systemctl', 'stop', 'smail.service'], check=True)
|
||||
for name in DATABASES:
|
||||
snapshot(ROOT / 'data' / name, backup / ('failed-' + name))
|
||||
snapshot(backup / name, ROOT / 'data' / name)
|
||||
shutil.chown(ROOT / 'data' / name, user='smail', group='smail')
|
||||
for name in expected:
|
||||
shutil.copy2(backup / name, ROOT / name)
|
||||
subprocess.run(['systemctl', 'start', 'smail.service'], check=True)
|
||||
print('升级失败,备份及故障证据保留于:' + str(backup))
|
||||
raise
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -1,7 +1,8 @@
|
||||
import paramiko, time
|
||||
ssh = paramiko.SSHClient()
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
ssh.connect("47.108.78.12", port=22, username="root", password="10102442Lb!", timeout=10)
|
||||
ssh.set_missing_host_key_policy(paramiko.RejectPolicy())
|
||||
from remote_ssh import connect_remote
|
||||
connect_remote(ssh)
|
||||
s_in, s_out, s_err = ssh.exec_command("chmod +x /opt/smail/smail_new && pkill -9 -f smail || true")
|
||||
s_out.channel.recv_exit_status()
|
||||
time.sleep(1)
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import paramiko
|
||||
ssh = paramiko.SSHClient()
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
ssh.connect("47.108.78.12", port=22, username="root", password="10102442Lb!", timeout=10)
|
||||
ssh.set_missing_host_key_policy(paramiko.RejectPolicy())
|
||||
from remote_ssh import connect_remote
|
||||
connect_remote(ssh)
|
||||
stdin, stdout, stderr = ssh.exec_command('sqlite3 /opt/smail/data/smail.db "SELECT id, subject, send_user_id, send_time FROM email ;"')
|
||||
print("Emails:\n", stdout.read().decode())
|
||||
stdin, stdout, stderr = ssh.exec_command('sqlite3 /opt/smail/data/smail.db "SELECT id, user_id, email_id, is_read, is_trash FROM user_email ;"')
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
import paramiko, time
|
||||
|
||||
ssh = paramiko.SSHClient()
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
ssh.connect("47.108.78.12", port=22, username="root", password="10102442Lb!", timeout=10)
|
||||
ssh.set_missing_host_key_policy(paramiko.RejectPolicy())
|
||||
from remote_ssh import connect_remote
|
||||
connect_remote(ssh)
|
||||
|
||||
cmd = """python3 -c '
|
||||
import hashlib, json
|
||||
|
||||
@@ -1,7 +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=10)
|
||||
client.set_missing_host_key_policy(paramiko.RejectPolicy())
|
||||
from remote_ssh import connect_remote
|
||||
connect_remote(client)
|
||||
cmd = 'openssl rsa -in /opt/smail/ssl/dkim/dkim.priv -pubout -outform PEM'
|
||||
stdin, stdout, stderr = client.exec_command(cmd)
|
||||
lines = [l.strip() for l in stdout.read().decode('utf-8').splitlines() if '---' not in l and l.strip()]
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import paramiko
|
||||
ssh = paramiko.SSHClient()
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
ssh.connect('47.108.78.12', port=22, username='root', password='10102442Lb!', timeout=10)
|
||||
ssh.set_missing_host_key_policy(paramiko.RejectPolicy())
|
||||
from remote_ssh import connect_remote
|
||||
connect_remote(ssh)
|
||||
_, stdout, _ = ssh.exec_command('sqlite3 /opt/smail/data/smail.db ".schema client_credential"')
|
||||
print(stdout.read().decode())
|
||||
_, stdout, _ = ssh.exec_command('sqlite3 /opt/smail/data/smail.db ".schema protocol_credential"')
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import paramiko
|
||||
ssh = paramiko.SSHClient()
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
ssh.connect("47.108.78.12", port=22, username="root", password="10102442Lb!", timeout=10)
|
||||
ssh.set_missing_host_key_policy(paramiko.RejectPolicy())
|
||||
from remote_ssh import connect_remote
|
||||
connect_remote(ssh)
|
||||
stdin, stdout, stderr = ssh.exec_command('sqlite3 /opt/smail/data/smail.db "SELECT id, type, subject, from_address, send_user_id, status FROM email ORDER BY id ASC;"')
|
||||
print("Security questions:\n", stdout.read().decode())
|
||||
stdin, stdout, stderr = ssh.exec_command('sqlite3 /opt/smail/data/smail.db "SELECT user_id, count(*), sum(consumed) FROM recovery_code GROUP BY user_id;"')
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import paramiko
|
||||
ssh = paramiko.SSHClient()
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
ssh.connect("47.108.78.12", port=22, username="root", password="10102442Lb!", timeout=10)
|
||||
ssh.set_missing_host_key_policy(paramiko.RejectPolicy())
|
||||
from remote_ssh import connect_remote
|
||||
connect_remote(ssh)
|
||||
stdin, stdout, stderr = ssh.exec_command('sqlite3 /opt/smail/data/smail.db "SELECT id, user_id, email_id, is_read, group_id, status FROM user_email ORDER BY id DESC LIMIT 10;"')
|
||||
print("Security questions:\n", stdout.read().decode("utf-8", errors="ignore").encode("utf-8"))
|
||||
stdin, stdout, stderr = ssh.exec_command('sqlite3 /opt/smail/data/smail.db "SELECT id, type, subject, send_user_id, status FROM email ORDER BY id DESC LIMIT 10;"')
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import paramiko
|
||||
ssh = paramiko.SSHClient()
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
ssh.connect("47.108.78.12", port=22, username="root", password="10102442Lb!", timeout=10)
|
||||
ssh.set_missing_host_key_policy(paramiko.RejectPolicy())
|
||||
from remote_ssh import connect_remote
|
||||
connect_remote(ssh)
|
||||
stdin, stdout, stderr = ssh.exec_command('sqlite3 /opt/smail/data/smail.db "SELECT user_id, question FROM security_question;"')
|
||||
print("Security questions:\n", stdout.read().decode())
|
||||
stdin, stdout, stderr = ssh.exec_command('sqlite3 /opt/smail/data/smail.db "SELECT user_id, count(*), sum(consumed) FROM recovery_code GROUP BY user_id;"')
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import paramiko
|
||||
ssh = paramiko.SSHClient()
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
ssh.connect("47.108.78.12", port=22, username="root", password="10102442Lb!", timeout=10)
|
||||
ssh.set_missing_host_key_policy(paramiko.RejectPolicy())
|
||||
from remote_ssh import connect_remote
|
||||
connect_remote(ssh)
|
||||
stdin, stdout, stderr = ssh.exec_command('sqlite3 /opt/smail/data/smail.db ".schema security_question"')
|
||||
print("Schema security_question:\n", stdout.read().decode())
|
||||
stdin, stdout, stderr = ssh.exec_command('sqlite3 /opt/smail/data/smail.db ".schema recovery_code"')
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import paramiko
|
||||
ssh = paramiko.SSHClient()
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
ssh.connect("47.108.78.12", port=22, username="root", password="10102442Lb!", timeout=10)
|
||||
ssh.set_missing_host_key_policy(paramiko.RejectPolicy())
|
||||
from remote_ssh import connect_remote
|
||||
connect_remote(ssh)
|
||||
stdin, stdout, stderr = ssh.exec_command('sqlite3 /opt/smail/data/smail.db "SELECT * FROM security_question WHERE user_id = 2;"')
|
||||
print("Testuser2 security question:\n", stdout.read().decode())
|
||||
stdin, stdout, stderr = ssh.exec_command('sqlite3 /opt/smail/data/smail.db "SELECT * FROM recovery_code WHERE user_id = 2;"')
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import paramiko
|
||||
ssh = paramiko.SSHClient()
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
ssh.connect("47.108.78.12", port=22, username="root", password="10102442Lb!", timeout=10)
|
||||
ssh.set_missing_host_key_policy(paramiko.RejectPolicy())
|
||||
from remote_ssh import connect_remote
|
||||
connect_remote(ssh)
|
||||
stdin, stdout, stderr = ssh.exec_command('sqlite3 /opt/smail/data/smail.db "SELECT id, account, name, role, is_admin, disabled FROM user;"')
|
||||
print("Users in DB:\n", stdout.read().decode())
|
||||
stdin, stdout, stderr = ssh.exec_command('sqlite3 /opt/smail/data/smail.db ".tables"')
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import argparse
|
||||
import pathlib
|
||||
import shlex
|
||||
import sys
|
||||
|
||||
import paramiko
|
||||
|
||||
from remote_ssh import connect_remote
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--command")
|
||||
parser.add_argument("--upload", nargs=2, action="append", default=[])
|
||||
args = parser.parse_args()
|
||||
client = connect_remote(paramiko.SSHClient())
|
||||
try:
|
||||
with client.open_sftp() as sftp:
|
||||
for source, destination in args.upload:
|
||||
target = pathlib.PurePosixPath(destination)
|
||||
if (not target.is_absolute() or ".." in target.parts
|
||||
or len(target.parts) < 5 or target.parts[1:3] != ("var", "tmp")
|
||||
or not target.parts[3].startswith("smail-review-")):
|
||||
raise ValueError("上传路径必须位于项目审查临时目录")
|
||||
command = "install -d -m 0755 " + shlex.quote(str(target.parent))
|
||||
_, output, error = client.exec_command(command)
|
||||
if output.channel.recv_exit_status() != 0:
|
||||
raise RuntimeError(error.read().decode("utf-8", "replace"))
|
||||
sftp.put(source, destination)
|
||||
sftp.chmod(destination, 0o755 if destination.endswith(".test") else 0o644)
|
||||
if args.command:
|
||||
_, output, error = client.exec_command(args.command, timeout=900)
|
||||
for line in output:
|
||||
print(line, end="", flush=True)
|
||||
errors = error.read().decode("utf-8", "replace")
|
||||
if errors:
|
||||
print(errors, file=sys.stderr)
|
||||
return output.channel.recv_exit_status()
|
||||
return 0
|
||||
finally:
|
||||
client.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
@@ -0,0 +1,28 @@
|
||||
import os
|
||||
|
||||
import paramiko
|
||||
|
||||
|
||||
def connect_remote(client):
|
||||
host = os.environ.get("SMAIL_SSH_HOST", "47.108.78.12")
|
||||
user = os.environ.get("SMAIL_SSH_USER", "root")
|
||||
password = os.environ.get("SMAIL_SSH_PASSWORD") or None
|
||||
key = os.environ.get("SMAIL_SSH_KEY") or None
|
||||
client.load_system_host_keys()
|
||||
known_hosts = os.environ.get("SMAIL_SSH_KNOWN_HOSTS")
|
||||
if known_hosts:
|
||||
client.load_host_keys(known_hosts)
|
||||
client.set_missing_host_key_policy(paramiko.RejectPolicy())
|
||||
client.connect(
|
||||
host,
|
||||
port=int(os.environ.get("SMAIL_SSH_PORT", "22")),
|
||||
username=user,
|
||||
password=password,
|
||||
key_filename=key,
|
||||
look_for_keys=password is None,
|
||||
allow_agent=password is None,
|
||||
timeout=10,
|
||||
auth_timeout=10,
|
||||
banner_timeout=10,
|
||||
)
|
||||
return client
|
||||
@@ -0,0 +1,12 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
cd /var/tmp/smail-review-20260917
|
||||
for name in outbox utils-send utils-smtp controllers-email db-migration res_init services-dbmigration; do
|
||||
if runuser -u smail -- "./$name.test" -test.v -test.timeout=180s > "$name.result.log" 2>&1; then
|
||||
printf '%s PASS\n' "$name"
|
||||
tail -n 3 "$name.result.log"
|
||||
else
|
||||
cat "$name.result.log"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
@@ -2,8 +2,9 @@
|
||||
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
|
||||
import paramiko
|
||||
ssh = paramiko.SSHClient()
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
ssh.connect('47.108.78.12', port=22, username='root', password='10102442Lb!', timeout=10)
|
||||
ssh.set_missing_host_key_policy(paramiko.RejectPolicy())
|
||||
from remote_ssh import connect_remote
|
||||
connect_remote(ssh)
|
||||
|
||||
s = '''
|
||||
import sqlite3
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import paramiko
|
||||
ssh = paramiko.SSHClient()
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
ssh.connect('47.108.78.12', port=22, username='root', password='10102442Lb!', timeout=10)
|
||||
ssh.set_missing_host_key_policy(paramiko.RejectPolicy())
|
||||
from remote_ssh import connect_remote
|
||||
connect_remote(ssh)
|
||||
|
||||
s = '''
|
||||
import sqlite3
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import paramiko
|
||||
ssh = paramiko.SSHClient()
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
ssh.connect('47.108.78.12', port=22, username='root', password='10102442Lb!', timeout=10)
|
||||
ssh.set_missing_host_key_policy(paramiko.RejectPolicy())
|
||||
from remote_ssh import connect_remote
|
||||
connect_remote(ssh)
|
||||
|
||||
s = '''
|
||||
import sqlite3
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
|
||||
import paramiko
|
||||
ssh = paramiko.SSHClient()
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
ssh.connect('47.108.78.12', port=22, username='root', password='10102442Lb!', timeout=10)
|
||||
ssh.set_missing_host_key_policy(paramiko.RejectPolicy())
|
||||
from remote_ssh import connect_remote
|
||||
connect_remote(ssh)
|
||||
|
||||
_, out, err = ssh.exec_command('python3 /tmp/check_hex2.py')
|
||||
print('OUT:\n', out.read().decode('utf-8', errors='ignore'))
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
|
||||
import paramiko
|
||||
ssh = paramiko.SSHClient()
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
ssh.connect('47.108.78.12', port=22, username='root', password='10102442Lb!', timeout=10)
|
||||
ssh.set_missing_host_key_policy(paramiko.RejectPolicy())
|
||||
from remote_ssh import connect_remote
|
||||
connect_remote(ssh)
|
||||
|
||||
s = '''
|
||||
import sqlite3
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import paramiko
|
||||
ssh = paramiko.SSHClient()
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
ssh.connect('47.108.78.12', port=22, username='root', password='10102442Lb!', timeout=10)
|
||||
ssh.set_missing_host_key_policy(paramiko.RejectPolicy())
|
||||
from remote_ssh import connect_remote
|
||||
connect_remote(ssh)
|
||||
|
||||
s = '''
|
||||
import sqlite3
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
|
||||
import paramiko
|
||||
ssh = paramiko.SSHClient()
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
ssh.connect('47.108.78.12', port=22, username='root', password='10102442Lb!', timeout=10)
|
||||
ssh.set_missing_host_key_policy(paramiko.RejectPolicy())
|
||||
from remote_ssh import connect_remote
|
||||
connect_remote(ssh)
|
||||
|
||||
s = '''
|
||||
import sqlite3
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import paramiko
|
||||
ssh = paramiko.SSHClient()
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
ssh.connect('47.108.78.12', port=22, username='root', password='10102442Lb!', timeout=10)
|
||||
ssh.set_missing_host_key_policy(paramiko.RejectPolicy())
|
||||
from remote_ssh import connect_remote
|
||||
connect_remote(ssh)
|
||||
|
||||
s = '''
|
||||
import sqlite3, base64, glob
|
||||
|
||||
@@ -32,11 +32,11 @@ with sync_playwright() as p:
|
||||
page.screenshot(path=os.path.join(test_log_dir, 'step2_admin_password.png'))
|
||||
|
||||
# Step 2: 输入管理员密码
|
||||
print('输入管理员密码 10102442Lb!...')
|
||||
print('输入管理员密码 [redacted]...')
|
||||
pwd_inputs = page.locator('.form input')
|
||||
print('密码页输入框数量:', pwd_inputs.count())
|
||||
for i in range(pwd_inputs.count()):
|
||||
pwd_inputs.nth(i).fill('10102442Lb!')
|
||||
pwd_inputs.nth(i).fill(os.environ["SMAIL_TEST_ADMIN_PASSWORD"])
|
||||
|
||||
time.sleep(1)
|
||||
page.screenshot(path=os.path.join(test_log_dir, 'step2_password_filled.png'))
|
||||
|
||||
@@ -38,7 +38,7 @@ with sync_playwright() as p:
|
||||
inputs = page.locator('.database-form input, .ctn input')
|
||||
print('找到输入框数量:', inputs.count())
|
||||
for i in range(inputs.count()):
|
||||
inputs.nth(i).fill('10102442Lb!')
|
||||
inputs.nth(i).fill(os.environ["SMAIL_TEST_ADMIN_PASSWORD"])
|
||||
|
||||
time.sleep(1)
|
||||
page.screenshot(path=os.path.join(test_log_dir, 'step2_password_filled.png'))
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import paramiko
|
||||
ssh = paramiko.SSHClient()
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
ssh.connect('47.108.78.12', port=22, username='root', password='10102442Lb!', timeout=10)
|
||||
ssh.set_missing_host_key_policy(paramiko.RejectPolicy())
|
||||
from remote_ssh import connect_remote
|
||||
connect_remote(ssh)
|
||||
|
||||
s = '''import smtplib, ssl
|
||||
from email.mime.text import MIMEText
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import paramiko
|
||||
ssh = paramiko.SSHClient()
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
ssh.connect("47.108.78.12", port=22, username="root", password="10102442Lb!", timeout=10)
|
||||
ssh.set_missing_host_key_policy(paramiko.RejectPolicy())
|
||||
from remote_ssh import connect_remote
|
||||
connect_remote(ssh)
|
||||
stdin, stdout, stderr = ssh.exec_command("echo HELLO")
|
||||
print(stdout:, stdout.read().decode())
|
||||
print(stderr:, stderr.read().decode())
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import paramiko
|
||||
ssh = paramiko.SSHClient()
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
ssh.connect("47.108.78.12", port=22, username="root", password="10102442Lb!", timeout=10)
|
||||
ssh.set_missing_host_key_policy(paramiko.RejectPolicy())
|
||||
from remote_ssh import connect_remote
|
||||
connect_remote(ssh)
|
||||
stdin, stdout, stderr = ssh.exec_command('python3 -c "import sqlite3; conn=sqlite3.connect(\x27/opt/smail/data/smail.db\x27); c=conn.cursor(); print(c.execute(\x27SELECT id, user_id, email_id, is_read, is_trash FROM user_email ORDER BY id DESC LIMIT 5\x27).fetchall())"')
|
||||
print("User emails top 5:\n", stdout.read().decode())
|
||||
stdin, stdout, stderr = ssh.exec_command('python3 -c "import sqlite3; conn=sqlite3.connect(\x27/opt/smail/data/smail.db\x27); c=conn.cursor(); print(c.execute(\x27SELECT id, subject, send_time FROM email ORDER BY id DESC LIMIT 5\x27).fetchall())"')
|
||||
|
||||
@@ -1,7 +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)
|
||||
client.set_missing_host_key_policy(paramiko.RejectPolicy())
|
||||
from remote_ssh import connect_remote
|
||||
connect_remote(client)
|
||||
client.exec_command('systemctl stop smail-init; pkill -9 smail')
|
||||
|
||||
setup_script = '''#!/bin/bash
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import paramiko
|
||||
ssh = paramiko.SSHClient()
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
ssh.connect("47.108.78.12", port=22, username="root", password="10102442Lb!", timeout=10)
|
||||
ssh.set_missing_host_key_policy(paramiko.RejectPolicy())
|
||||
from remote_ssh import connect_remote
|
||||
connect_remote(ssh)
|
||||
|
||||
cmd = """python3 -c '
|
||||
import json
|
||||
|
||||
Reference in new issue
Block a user