#!/usr/bin/env python3 """Force MiroTalk default zh-CN + nomadro loading/init UI (no MiroTalk chrome).""" from __future__ import annotations import re import sys from pathlib import Path import paramiko HOST = "82.157.112.245" USER = "ubuntu" PASS = "Xiao4669805" BASE = "/opt/nomadro-services/mirotalk" LOCAL_CSS = Path(__file__).with_name("nomadro-embed.css") LOADING_HTML = """

正在进入活动厅

请允许摄像头 / 麦克风权限
游民社区 · nomadro
""" QR_HTML = """ """ def ssh() -> paramiko.SSHClient: c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect( HOST, username=USER, password=PASS, timeout=30, allow_agent=False, look_for_keys=False ) return c def run(c: paramiko.SSHClient, cmd: str, timeout: int = 120) -> tuple[str, int]: _i, o, e = c.exec_command(cmd, timeout=timeout) out = o.read().decode("utf-8", "ignore") err = e.read().decode("utf-8", "ignore") return out + (("\n" + err) if err.strip() else ""), o.channel.recv_exit_status() def write(c: paramiko.SSHClient, remote: str, data: str) -> None: tmp = f"/tmp/{Path(remote).name}" sftp = c.open_sftp() with sftp.file(tmp, "w") as f: f.write(data.encode("utf-8")) sftp.close() out, code = run(c, f"sudo mv {tmp} {remote} && sudo chmod 644 {remote}") if code != 0: raise RuntimeError(out) def patch_config(text: str) -> str: text = re.sub(r"language:\s*'en'", "language: 'zh-CN'", text, count=1) text = re.sub(r"name:\s*'MiroTalk'", "name: 'nomadro'", text, count=1) text = text.replace( "customizeRoomButtonLabel: 'CUSTOMIZE ROOM'", "customizeRoomButtonLabel: '自定义房间'", ) text = text.replace( "joinLastLabel: 'Your recent room:'", "joinLastLabel: '最近房间:'", ) # Chinese site titles (landing / client) replacements = { "landingTitle: 'MiroTalk a Free Secure Video Calls, Chat & Screen Sharing.'": "landingTitle: 'nomadro 游民社区 · 线上视频厅'", "newCallTitle: 'MiroTalk a Free Secure Video Calls, Chat & Screen Sharing.'": "newCallTitle: 'nomadro 游民社区 · 线上视频厅'", "newCallRoomTitle: 'Pick name.
Share URL.
Start conference.'": "newCallRoomTitle: '进入房间
开始活动'", "clientTitle: 'MiroTalk WebRTC Video call, Chat Room & Screen Sharing.'": "clientTitle: 'nomadro 视频厅'", "joinRoomTitle: 'Pick name.
Share URL.
Start conference.'": "joinRoomTitle: '进入活动房间'", "joinRoomButtonLabel: 'JOIN ROOM'": "joinRoomButtonLabel: '进入房间'", "loginTitle: 'MiroTalk - Host Protected login required.'": "loginTitle: 'nomadro · 需要登录'", "privacyPolicyTitle: 'MiroTalk - privacy and policy.'": "privacyPolicyTitle: 'nomadro 隐私政策'", "notFoundTitle: 'MiroTalk - 404 Page not found.'": "notFoundTitle: '页面不存在'", "waitingRoomTitle: 'MiroTalk - Waiting for host to start the meeting'": "waitingRoomTitle: '等待主持人开始'", "waitingRoomHeading: 'Waiting for host...'": "waitingRoomHeading: '等待主持人…'", "waitingRoomStatus: 'Checking room status...'": "waitingRoomStatus: '检查房间状态…'", "waitingRoomReady: 'Room is ready! Joining...'": "waitingRoomReady: '房间已就绪,正在进入…'", "waitingRoomWaiting: 'Waiting for host to start the meeting...'": "waitingRoomWaiting: '等待主持人开始活动…'", "waitingRoomHostLink: 'Are you the host?'": "waitingRoomHostLink: '你是主持人?'", "waitingRoomLoginLink: 'Login here'": "waitingRoomLoginLink: '点此登录'", "image: 'https://p2p.mirotalk.com/images/preview.png'": "image: 'https://nomadro.cn/favicon.ico'", "url: 'https://p2p.mirotalk.com'": "url: 'https://nomadro.cn/social'", } for a, b in replacements.items(): text = text.replace(a, b) return text def patch_brand_js(text: str) -> str: text = text.replace("language: 'en'", "language: 'zh-CN'", 1) text = text.replace("name: 'MiroTalk'", "name: 'nomadro'", 1) text = text.replace( "title: 'MiroTalk
Free browser based Real-time video calls.
Simple, Secure, Fast.'", "title: 'nomadro
游民社区 · 线上活动厅'", 1, ) text = text.replace( "clientTitle: 'MiroTalk WebRTC Video call, Chat Room & Screen Sharing.'", "clientTitle: 'nomadro 视频厅'", 1, ) # hide marketing sections in client-side fallback for key in ( "topSponsors", "features", "browsers", "teams", "tryEasier", "poweredBy", "sponsors", "pastSponsors", "advertisers", "supportUs", "footer", ): text = re.sub(rf"{key}:\s*true", f"{key}: false", text) text = re.sub( r"about:\s*\{[\s\S]*?\n \},", "about: {\n" " imageUrl: '../images/logo.svg',\n" " title: 'nomadro 视频厅',\n" " html: '游民社区 · 线上活动',\n" " },", text, count=1, ) return text def patch_client_html(text: str) -> str: text = text.replace('', '', 1) text = re.sub( r'
[\s\S]*?
\s*\n\s*\n\s*', LOADING_HTML + "\n\n ", text, count=1, ) text = re.sub( r'
\s*\n\s*\n\s*', QR_HTML + "\n\n ", text, count=1, ) # kill SEO WebRTC h1 promo text = re.sub( r'
[\s\S]*?
', '', text, count=1, ) if "nomadro-embed.css" not in text: text = text.replace( '', '\n' ' ', 1, ) if "document.documentElement.classList.add('nomadro-embed')" not in text: boot = ( "" ) text = text.replace("", f" {boot}\n ", 1) text = re.sub( r"[^<]*", 'nomadro 视频厅', text, count=1, ) # init loader: use N mark instead of svg logo text = text.replace( '', '', ) return text def patch_translate_js(text: str) -> str: # Default Google Translate page language stays en (source), but brand language drives target. # Prefer zh-CN when brand missing. text = text.replace( "const language = brand?.app?.language || 'en';", "const language = brand?.app?.language || 'zh-CN';", ) text = text.replace( "if (language === 'en') return; // No need to switch if default is 'en'", "if (language === 'en' || language === 'en-US') return;", ) return text def patch_client_js_icons(text: str) -> str: # default about/avatar images away from mirotalk gif text = text.replace( "about: '../images/mirotalk-logo.gif'", "about: '../images/logo.svg'", ) text = text.replace( "avatar: '../images/mirotalk-logo.png'", "avatar: '../images/logo.svg'", ) return text def main() -> int: c = ssh() print("connected") if LOCAL_CSS.exists(): write(c, f"{BASE}/public/css/nomadro-embed.css", LOCAL_CSS.read_text(encoding="utf-8")) print("css ok") for remote, fn in [ (f"{BASE}/app/src/config.js", patch_config), (f"{BASE}/public/js/brand.js", patch_brand_js), (f"{BASE}/public/views/client.html", patch_client_html), (f"{BASE}/public/js/translate.js", patch_translate_js), (f"{BASE}/public/js/client.js", patch_client_js_icons), ]: out, code = run(c, f"sudo cat {remote}") if code != 0: print("fail read", remote) return 1 new = fn(out) if new != out: write(c, remote, new) print("patched", remote) else: print("unchanged", remote) # clear brand session cache note: clients use sessionStorage brandDataP2P — new loads get server brand out, code = run( c, "sudo systemctl restart mirotalk-p2p && sleep 2 && systemctl is-active mirotalk-p2p", ) print(out.strip()) if "active" not in out: return 1 smoke, _ = run( c, "curl -s 'http://127.0.0.1:9300/join?room=t&name=t¬ify=0' | " "grep -oE '正在进入活动厅|zh-CN|nomadro-mark|Please allow the camera' | sort -u", ) print("smoke:", smoke) if "Please allow the camera" in smoke or "正在进入活动厅" not in smoke: print("WARN: loading text not fully replaced", file=sys.stderr) c.close() return 0 if __name__ == "__main__": raise SystemExit(main())