manage.py 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216
  1. #!/usr/bin/env python3
  2. import shutil
  3. import sys
  4. import datetime
  5. import platform
  6. import os
  7. from urllib.request import urlopen, HTTPError
  8. import re
  9. import subprocess
  10. import string
  11. import time
  12. import random
  13. import socket
  14. texts = {
  15. 'hello1': {
  16. 'en': 'SafeLine is a self-hosted WAF(Web Application Firewall) to protect your web apps from attacks and exploits.',
  17. 'zh': 'SafeLine,中文名 "雷池",是一款简单好用, 效果突出的 Web 应用防火墙(WAF),可以保护 Web 服务不受黑客攻击。'
  18. },
  19. 'hello2': {
  20. 'en': 'A web application firewall helps protect web apps by filtering and monitoring HTTP traffic between a web application and the Internet. It typically protects web apps from attacks such as SQL injection, XSS, code injection, os command injection, CRLF injection, ldap injection, xpath injection, RCE, XXE, SSRF, path traversal, backdoor, bruteforce, http-flood, bot abused, among others.',
  21. 'zh': '雷池通过过滤和监控 Web 应用与互 联网之间的 HTTP 流量来保护 Web 服务。可以保护 Web 服务免受 SQL 注入、XSS 、 代码注入、命令注入、CRLF 注入、ldap 注入、xpath 注入、RCE、XXE、SSRF、路径遍历、后门、暴力破解、CC、爬虫 等攻击。'
  22. },
  23. 'talking-group': {
  24. 'en': '\n'
  25. 'https://discord.gg/SVnZGzHFvn\n'
  26. '\n'
  27. 'Join discord group for more informations of SafeLine by above address',
  28. 'zh': '\n'
  29. '▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄\n'
  30. '█ ▄▄▄▄▄ █▀ █▀▀██▀▄▀▀▄▀▄▀▄██ ▄▄▄▄▄ █\n'
  31. '█ █ █ █▀ ▄ █▀▄▄▀▀ ▄█▄ ▀█ █ █ █\n'
  32. '█ █▄▄▄█ █▀█ █▄█▄▀▀▄▀▄ ▀▀▄▄█ █▄▄▄█ █\n'
  33. '█▄▄▄▄▄▄▄█▄█▄█ █▄▀ █ ▀▄▀ █▄█▄▄▄▄▄▄▄█\n'
  34. '█▄ ▄▄ █▄▄ ▄█▄▄▄▄▀▄▀▀▄██ ▄▄▀▄█▄▀ ▀█\n'
  35. '█▄ ▄▀▄ ▄▀▄ ▀ ▄█▀ ▀▄ █▀▀ ▀█▀▄██▄▀▄██\n'
  36. '██ ▀▄█ ▄ ▄▄▀▄▀▀█▄▀▄▄▀▄▀▄ ▄ ▀▄▄▄█▀▀█\n'
  37. '█ █▀▄▀ ▄▀▄▄▀█▀ ▄▄ █▄█▀▀▄▀▀█▄█▄█▀▄██\n'
  38. '█ █ ▀ ▄▀▀ ██▄█▄▄▄▄▄▀▄▀▀▀▄▄▀█▄▀█ ▀█\n'
  39. '█ █ ▀▄ ▄██▀▀ ▄█▀ ▀███▄ ▀▄▀▄▄ ▄▀▄██\n'
  40. '█▀▄▄█ ▄▀▄▀ ▄▀▀▀▄▀▄▀ ▄▀▄ ▄▀ ▄▀█ ▀█\n'
  41. '█ █ █ █▄▀ █▄█▀ ▄▄███▀▀▀▄█▀▄ ▀ ▀▄██\n'
  42. '█▄███▄█▄▄▀▄ █▄█▄▄▄▄▀▀▄█▀▀ ▄▄▄ ▀█ █\n'
  43. '█ ▄▄▄▄▄ █▄▀█ ▄█▀▄ █▀█▄ ▀ █▄█ ▀▄▀█\n'
  44. '█ █ █ █ █▄▀▀▀▄▄▄▀▀▀▀▀▀ ▄▄ ▀█ █\n'
  45. '█ █▄▄▄█ █ ▀█▀ ▄▄▄▄ ▀█ ▀▀▄▀ ▀▀ ▀███\n'
  46. '█▄▄▄▄▄▄▄█▄▄██▄█▄▄█▄██▄██▄▄█▄▄█▄█▄██\n'
  47. '\n'
  48. '微信扫描上方二维码加入雷池项目讨论组'
  49. },
  50. 'input-target-path': {
  51. 'en': 'Input the path to install SafeLine WAF',
  52. 'zh': '请输入雷池 WAF 的安装目录'
  53. },
  54. 'input-mgt-port': {
  55. 'en': 'Input the mgt port',
  56. 'zh': '请输入雷池 WAF 的管理端口'
  57. },
  58. 'python-version-too-low': {
  59. 'en': 'The Python version is too low, Python 3.5 above is required',
  60. 'zh': 'Python 版本过低, 脚本无法运行, 需要 Python 3.5 以上'
  61. },
  62. 'not-a-tty': {
  63. 'en': 'Stdin is not a standard TTY',
  64. 'zh': '运行脚本的方式不对, STDIN 不是标准的 TTY'
  65. },
  66. 'not-root': {
  67. 'en': 'Requires root privileges to run',
  68. 'zh': '需要 root 权限才能运行'
  69. },
  70. 'not-linux': {
  71. 'en': 'SafeLine WAF does not support %s OS yet',
  72. 'zh': '雷池 WAF 暂时不支持 %s 操作系统'
  73. },
  74. 'unsupported-arch': {
  75. 'en': 'SafeLine WAF does not support %s processor yet',
  76. 'zh': '雷池 WAF 暂时不支持 %s 处理器'
  77. },
  78. 'prepare-to-install': {
  79. 'en': 'Will be going to installing SafeLine WAF for you.',
  80. 'zh': '即将为您安装雷池 WAF'
  81. },
  82. 'choice-action': {
  83. 'en': 'Choice what do you want to do',
  84. 'zh': '选择你要执行的动作'
  85. },
  86. 'default-value': {
  87. 'en': 'Keep blank default to',
  88. 'zh': '留空则为默认值'
  89. },
  90. 'ssse3-not-support': {
  91. 'en': 'SSSE3 instruction set not enabled in your CPU',
  92. 'zh': '当前 CPU 未启用 SSSE3 指令集'
  93. },
  94. 'precheck-failed': {
  95. 'en': 'The environment does not meet the installation conditions of SafeLine WAF',
  96. 'zh': '当前环境不符合雷池 WAF 的安装条件'
  97. },
  98. 'precheck-passed': {
  99. 'en': 'Installation environment check passed',
  100. 'zh': '检查安装环境已完成'
  101. },
  102. 'insufficient-memory': {
  103. 'en': 'Remaining memory is less than 1 GB',
  104. 'zh': '剩余内存不足 1 GB'
  105. },
  106. 'docker-not-installed': {
  107. 'en': 'Running SafeLine WAF requires Docker, but Docker is not installed',
  108. 'zh': '运行雷池 WAF 依赖 Docker, 但是 Docker 没安装'
  109. },
  110. 'docker-compose-not-installed': {
  111. 'en': 'Running SafeLine WAF requires Docker Compose, but Docker Compose is not installed',
  112. 'zh': '运行雷池 WAF 依赖 Docker Compose, 但是 Docker Compose 没安装'
  113. },
  114. 'docker-version-too-low': {
  115. 'en': 'Docker version is too low, it does not match SafeLine WAF',
  116. 'zh': 'Docker 版本太低, 不满足雷池 WAF 的安装需求'
  117. },
  118. 'if-install-docker': {
  119. 'en': 'Do you want the latest version of Docker to be automatically installed for you?',
  120. 'zh': '是否需要为你自动安装 Docker 的最新版本'
  121. },
  122. 'if-update-docker': {
  123. 'en': 'Do you want to update your Docker version?',
  124. 'zh': '是否需要为你自动更新 Docker 版本'
  125. },
  126. 'install-docker-failed': {
  127. 'en': 'Failed to install Docker. Please try to install Docker manually before installing SafeLine WAF',
  128. 'zh': '安装 Docker 失败, 请尝试手动安装 Docker 后再来安装雷池 WAF'
  129. },
  130. 'install-docker': {
  131. 'en': 'Docker is being installed for you. It will take a few minutes. Please wait patiently.',
  132. 'zh': '正在为你安装 Docker, 需要几分钟时间, 请耐心等待'
  133. },
  134. 'get-space-failed': {
  135. 'en': 'Unable to query disk capacity of "%s"',
  136. 'zh': '无法查询 "%s" 的磁盘容量'
  137. },
  138. 'remain-disk-capacity': {
  139. 'en': 'Disk capacity of "%s" has %s avaiable',
  140. 'zh': '"%s" 路径有 %s 的空间可用'
  141. },
  142. 'insufficient-disk-capacity': {
  143. 'en': 'Insufficient disk capacity of "%s", at least 5 GB is required to install SafeLine WAF',
  144. 'zh': '"%s" 的磁盘容量不足,安装雷池 WAF 至少需要 5 GB'
  145. },
  146. 'pg-pass-contains-invalid-char': {
  147. 'en': 'The POSTGRES_PASSWORD variable contains special characters and cannot be started normally',
  148. 'zh': 'POSTGRES_PASSWORD 变量包含特殊字符, 无法正常启动'
  149. },
  150. 'invalid-path': {
  151. 'en': '"%s" is not a valid absolute path',
  152. 'zh': '"%s" 不是合法的绝对路径'
  153. },
  154. 'path-exists': {
  155. 'en': '"%s" already exists, please select a new directory',
  156. 'zh': '路径 "%s" 已存在,请选择一个全新的目录'
  157. },
  158. 'fail-to-parse-route': {
  159. 'en': 'Unable to parse /proc/net/route file',
  160. 'zh': '无法解析 /proc/net/route 文件'
  161. },
  162. 'fail-to-download-compose': {
  163. 'en': 'Failed to download docker compose script',
  164. 'zh': '下载 docker compose 脚本失败'
  165. },
  166. 'fail-to-create-dir': {
  167. 'en': 'Unable to create the "%s" directory',
  168. 'zh': '无法创建 "%s" 目录'
  169. },
  170. 'docker-pull': {
  171. 'en': 'Pulling Docker image',
  172. 'zh': '正在拉取 Docker 镜像'
  173. },
  174. 'try-another-image-source': {
  175. 'en': 'Try another image source',
  176. 'zh': '尝试使用其他镜像源'
  177. },
  178. 'image-clean': {
  179. 'en': 'Cleaning Docker image',
  180. "zh": '正在清理 Docker 镜像'
  181. },
  182. 'update-config': {
  183. 'en': 'Updating .env configuration files',
  184. 'zh': '正在更新 .env 配置文件'
  185. },
  186. 'download-compose': {
  187. 'en': 'Downloading the compose.yaml file',
  188. 'zh': '正在下载 compose.yaml 文件'
  189. },
  190. 'download-reset-tengine': {
  191. 'en': 'Downloading the reset_tengine script',
  192. 'zh': '正在下载 reset_tengine.sh 文件'
  193. },
  194. 'fail-to-pull-image': {
  195. 'en': 'Failed to pull Docker image',
  196. 'zh': '拉取 Docker 镜像失败'
  197. },
  198. 'docker-up': {
  199. 'en': 'Starting Docker containers',
  200. 'zh': '正在启动 Docker 容器'
  201. },
  202. 'fail-to-up': {
  203. 'en': 'Failed to start Docker containers',
  204. 'zh': '启动 Docker 容器失败'
  205. },
  206. 'fail-to-down': {
  207. 'en': 'Failed to stop Docker containers',
  208. 'zh': '停止 Docker 容器失败'
  209. },
  210. 'install-finish': {
  211. 'en': 'SafeLine WAF installation completed',
  212. 'zh': '雷池 WAF 安装完成'
  213. },
  214. 'upgrade-finish': {
  215. 'en': 'SafeLine WAF upgrade completed',
  216. 'zh': '雷池 WAF 升级完成'
  217. },
  218. 'go-to-panel': {
  219. 'en': 'SafeLine WAF management panel: https://%s:%s/',
  220. 'zh': '雷池 WAF 管理面板: https://%s:%s/'
  221. }
  222. ,'install': {
  223. 'en': 'INSTALL',
  224. 'zh': '安装'
  225. },
  226. 'repair': {
  227. 'en': 'REPAIR',
  228. 'zh': '修复'
  229. },
  230. 'uninstall': {
  231. 'en': 'UNINSTALL',
  232. 'zh': '卸载'
  233. },
  234. 'upgrade': {
  235. 'en': 'UPGRADE',
  236. 'zh': '升级'
  237. },
  238. 'backup': {
  239. 'en': 'BACKUP',
  240. 'zh': '备份'
  241. },
  242. 'yes': {
  243. 'en': 'Yes',
  244. 'zh': '是'
  245. },
  246. 'no': {
  247. 'en': 'No',
  248. 'zh': '否'
  249. },
  250. 'fail-to-get-installed-dir': {
  251. 'en': 'Failed to get installed dir',
  252. 'zh': '未能找到安装目录',
  253. },
  254. 'fail-to-connect-image-source': {
  255. 'en': 'Failed to connect image source',
  256. 'zh': '无法连接到任何镜像源'
  257. },
  258. 'fail-to-connect-docker-source': {
  259. 'en': 'Failed to connect docker source',
  260. 'zh': '无法连接到任何 docker 源'
  261. },
  262. 'fail-to-download-docker-installation': {
  263. 'en': 'Failed to download docker installation',
  264. "zh": '下载 docker 安装脚本失败'
  265. },
  266. 'docker-source': {
  267. 'en': 'Docker source',
  268. "zh": 'docker 源'
  269. },
  270. 'reset-admin': {
  271. 'en': 'Setup admin',
  272. "zh": '设置 admin'
  273. },
  274. 'docker-version': {
  275. 'en': 'Checking docker version',
  276. 'zh': '检查 docker 版本'
  277. },
  278. 'docker-compose-version': {
  279. 'en': 'Checking docker compose version',
  280. 'zh': '检查 docker compose 版本'
  281. },
  282. 'keyboard-interrupt': {
  283. 'en': 'Installation cancelled',
  284. "zh": '取消安装'
  285. },
  286. 'docker-up-iptables-failed': {
  287. 'en': 'Iptables policy error, try to restart docker',
  288. 'zh': 'iptables 规则错误,尝试重启 docker'
  289. },
  290. 'install-channel': {
  291. 'en': 'Installing',
  292. 'zh': '安装通道'
  293. },
  294. 'preview-release': {
  295. 'en': 'Preview',
  296. 'zh': '预览版'
  297. },
  298. 'lts-release': {
  299. 'en': 'LTS',
  300. 'zh': 'LTS 版'
  301. },
  302. 'fail-to-docker-down': {
  303. 'en': 'Failed to stop container',
  304. 'zh': '停止 docker 容器失败'
  305. },
  306. 'fail-to-remove-dir': {
  307. 'en': 'Failed to remove safeline installation directory',
  308. 'zh': '删除雷池安装目录失败'
  309. },
  310. 'uninstall-finish': {
  311. 'en': 'SafeLine WAF uninstall completed',
  312. 'zh': '雷池 WAF 卸载完成'
  313. },
  314. 'docker-down': {
  315. 'en': 'Stopping SafeLine WAF container',
  316. 'zh': '正在停止雷池 WAF 容器'
  317. },
  318. 'reset-tengine': {
  319. 'en': 'RESET TENGINE CONFIG',
  320. 'zh': '重置 tengine 配置',
  321. },
  322. 'reset-postgres': {
  323. 'en': 'RESET DATABASE PASSWORD',
  324. 'zh': '重置数据库密码'
  325. },
  326. 'fail-to-find-nginx': {
  327. 'en': 'Failed to find tengine config path',
  328. 'zh': '未找到 tengine 配置目录'
  329. },
  330. 'nginx-backup-dir': {
  331. 'en': 'Tengine config backup directory',
  332. 'zh': 'tengine 配置备份目录'
  333. },
  334. 'fail-to-backup-nginx': {
  335. 'en': 'Failed to backup tengine config',
  336. 'zh': '备份 tengine 目录失败'
  337. },
  338. 'docker-restart': {
  339. 'en': 'Restart docker container',
  340. 'zh': '重启 docker 容器'
  341. },
  342. 'docker-exec': {
  343. 'en': 'Executing docker command',
  344. 'zh': '执行 docker 命令'
  345. },
  346. 'fail-to-recover-static': {
  347. 'en': 'Failed to recover tengine static config',
  348. 'zh': '恢复 tengine 静态站点资源失败'
  349. },
  350. 'fail-to-find-env': {
  351. 'en': 'Failed to find .env file',
  352. 'zh': '未找到 .env 文件'
  353. },
  354. 'fail-to-find-postgres-password': {
  355. 'en': 'Failed to find postgres password',
  356. 'zh': '未找到数据库密码'
  357. },
  358. 'fail-to-reset-postgres-password': {
  359. 'en': 'Failed to reset postgres password',
  360. 'zh': '重置数据库密码失败'
  361. },
  362. 'reset-postgres-password-finish': {
  363. 'en': 'Reset postgres password completed',
  364. 'zh': '重置数据库密码完成'
  365. },
  366. 'reset-tengine-finish': {
  367. 'en': 'Reset tengine finish completed',
  368. 'zh': '重置 tengine 配置完成'
  369. },
  370. 'if-remove-waf': {
  371. 'en': 'Do you want to uninstall SafeLine WAF, this operation will delete all data in the directory',
  372. 'zh': '是否确认卸载雷池,该操作会删除目录下所有数据'
  373. }
  374. }
  375. lang = ''
  376. def text(label, var=()):
  377. t = texts.get(label, {
  378. 'en': 'Unknown "%s" (%s)' % (label, var),
  379. 'zh': '未知变量 "%s" (%s)' % (label, var)
  380. })
  381. return t[lang if lang in t else 'en'] % var
  382. BOLD = 1
  383. DIM = 1
  384. BLINK = 5
  385. REVERSE = 7
  386. RED = 31
  387. GREEN = 32
  388. YELLOW = 33
  389. BLUE = 34
  390. CYAN = 36
  391. DEBUG = False
  392. LTS = False
  393. IMAGE_CLEAN = False
  394. EN = False
  395. INSTALL = False
  396. DOMAIN = 'waf-ce.chaitin.cn'
  397. def color(t, attrs=[], end=True):
  398. t = '\x1B[%sm%s' % (';'.join([str(i) for i in attrs]), t)
  399. if end:
  400. t = t + '\x1B[m'
  401. return t
  402. def banner():
  403. t = r'''
  404. ______ ___ _____ _ ____ ____ _ ________
  405. .' ____ \ .' ..] |_ _| (_) |_ _| |_ _| / \ |_ __ |
  406. | (___ \_| ,--. _| |_ .---. | | __ _ .--. .---. \ \ /\ / / / _ \ | |_ \_|
  407. _.____`. `'_\ : '-| |-' / /__\\ | | _ [ | [ `.-. | / /__\\ \ \/ \/ / / ___ \ | _|
  408. | \____) | // | |, | | | \__., _| |__/ | | | | | | | | \__., \ /\ / _/ / \ \_ _| |_
  409. \______.' \'-;__/ [___] '.__.' |________| [___] [___||__] '.__.' \/ \/ |____| |____| |_____|
  410. '''.strip('\n')
  411. print(color(t + '\n', [GREEN, BLINK]))
  412. class log():
  413. @staticmethod
  414. def _log(c, l, s):
  415. t = datetime.datetime.now().strftime('%H:%M:%S')
  416. print('\r\033[0;%dm[%-5s %s]: %s\033[0m' % (c, l, t, s))
  417. @staticmethod
  418. def debug(s):
  419. if DEBUG:
  420. log._log(DIM, 'DEBUG', s)
  421. @staticmethod
  422. def info(s):
  423. log._log(CYAN, 'INFO', s)
  424. @staticmethod
  425. def warning(s):
  426. log._log(YELLOW, 'WARN', s)
  427. @staticmethod
  428. def error(s):
  429. log._log(RED, 'ERROR', s)
  430. def get_url(url):
  431. try:
  432. response = urlopen(url)
  433. content = response.read()
  434. return content.decode('utf-8')
  435. except Exception as e:
  436. log.error(e)
  437. def ui_read(question, default):
  438. while True:
  439. if default is None:
  440. sys.stdout.write('%s: ' % (
  441. color(question, [GREEN]),
  442. ))
  443. else:
  444. sys.stdout.write('%s %s: ' % (
  445. color(question, [GREEN]),
  446. color('(%s %s)' % (text('default-value'), default), [YELLOW]),
  447. ))
  448. r = input().strip()
  449. if len(r) == 0:
  450. if default is None or len(default) == 0:
  451. continue
  452. r = default
  453. return r
  454. def ui_choice(question, options):
  455. while True:
  456. s_options = '[ %s ]' % ' '.join(['%s.%s' % option for option in options])
  457. s_choices = '(%s)' % '/'.join([option[0] for option in options])
  458. sys.stdout.write('%s %s %s: ' % (color(question, [GREEN]), color(s_options, [YELLOW]), color(s_choices, [YELLOW])))
  459. r = input().strip()
  460. if r in [i[0] for i in options]:
  461. return r
  462. def humen_size(x):
  463. if x >= 1024 * 1024 * 1024 * 1024:
  464. return '%.02f TB' % (x / 1024 / 1024 / 1024 / 1024)
  465. elif x >= 1024 * 1024 * 1024:
  466. return '%.02f GB' % (x / 1024 / 1024 / 1024)
  467. elif x >= 1024 * 1024:
  468. return '%.02f MB' % (x / 1024 / 1024)
  469. elif x >= 1024:
  470. return '%.02f KB' % (x / 1024)
  471. else:
  472. return '%d Bytes'
  473. def rand_subnet():
  474. routes = []
  475. try:
  476. with open('/proc/net/route', 'r') as f:
  477. next(f)
  478. for line in f:
  479. parts = line.split()
  480. if len(parts) < 8:
  481. continue
  482. destination = int(parts[1], 0x10)
  483. if destination == 0:
  484. continue
  485. mask = int(parts[7], 0x10)
  486. routes.append((destination, mask))
  487. except Exception as e:
  488. log.error(text('fail-to-parse-route') + ' ' + str(e))
  489. for i in range(256):
  490. t = 192
  491. t += 168 << 8
  492. t += i << 16
  493. for route in routes:
  494. if t & route[1] == route[0]:
  495. break
  496. else:
  497. return '%d.%d.%d' % (t & 0xFF, (t >> 8) & 0xFF, (t >> 16) & 0xFF)
  498. return '172.22.222'
  499. def free_space(path):
  500. while not os.path.exists(path) and path != '/':
  501. path = os.path.dirname(path)
  502. try:
  503. st = os.statvfs(path)
  504. free_bytes = st.f_bavail * st.f_frsize
  505. return free_bytes
  506. except Exception as e:
  507. log.error(text('get-space-failed', path) + ' ' + str(e))
  508. return None
  509. def free_memory():
  510. t = filter(lambda x: 'MemAvailable' in x, open('/proc/meminfo', 'r').readlines())
  511. return int(next(t).split()[1]) * 1024
  512. def exec_command(*args,shell=False):
  513. try:
  514. proc = subprocess.run(args, check=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True,shell=shell)
  515. subprocess_output(proc.stdout.strip())
  516. return proc.returncode, proc.stdout, proc.stderr
  517. except Exception as e:
  518. return -1, '', str(e)
  519. def exec_command_with_loading(*args, cwd=None, env=None):
  520. try:
  521. with subprocess.Popen(args, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, env=env, cwd=cwd) as proc:
  522. if not DEBUG:
  523. loading = ["⣾", "⣽", "⣻", "⢿", "⡿", "⣟", "⣯", "⣷"]
  524. iloading = 0
  525. while proc.poll() is None:
  526. sys.stderr.write('\r' + loading[iloading])
  527. sys.stderr.flush()
  528. iloading = (iloading + 1) % len(loading)
  529. time.sleep(0.1)
  530. sys.stderr.write('\r')
  531. sys.stderr.flush()
  532. else:
  533. for line in iter(proc.stdout.readline, b''):
  534. if line.strip() != '':
  535. log.debug(" -->> "+line.strip())
  536. if proc.poll() is not None and line == '':
  537. break
  538. return proc.returncode, proc.stdout.read(), proc.stderr.read()
  539. except Exception as e:
  540. return -1, '', str(e)
  541. def subprocess_output(stdout):
  542. if stdout != '':
  543. log.debug(" -->> "+stdout)
  544. else:
  545. log.debug(" -->> subprocess empty output")
  546. def start_docker():
  547. return exec_command('systemctl enable docker && systemctl daemon-reload && systemctl restart docker',shell=True)
  548. def check_port(port):
  549. if not INSTALL:
  550. return True
  551. try:
  552. with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
  553. s.bind(('0.0.0.0', int(port)))
  554. return True
  555. except Exception as e:
  556. log.debug("try listen mgt port failed: "+str(e))
  557. return False
  558. def install_docker():
  559. log.info(text('install-docker'))
  560. log.debug("downloading get-docker.sh")
  561. if not save_file_from_url('https://'+DOMAIN+'/release/latest/get-docker.sh','get-docker.sh'):
  562. raise Exception(text('fail-to-download-docker-installation'))
  563. source = docker_source()
  564. if source == '':
  565. raise Exception(text('fail-to-connect-docker-source'))
  566. log.debug(text('docker-source')+': '+source)
  567. env = {
  568. "DOWNLOAD_URL": source,
  569. "https_proxy": os.environ.get('https_proxy',''),
  570. }
  571. log.debug("installing docker")
  572. r = exec_command_with_loading('bash get-docker.sh',env=env)
  573. if r[0] == 0:
  574. p = start_docker()
  575. subprocess_output(p[1].strip())
  576. if p[0] != 0:
  577. log.error("start docker failed: "+p[2].strip())
  578. return p[0] == 0
  579. else:
  580. log.error("install docker error: "+r[2].strip())
  581. return False
  582. compose_command = ''
  583. def precheck_docker_compose():
  584. log.info(text("docker-compose-version"))
  585. global compose_command
  586. while True:
  587. version_output = ''
  588. proc = exec_command('docker', 'compose', 'version')
  589. if proc[0] == 0:
  590. help_proc = exec_command('docker', 'compose', 'up', '--help')
  591. if help_proc[0] == 0 and '--detach' in help_proc[1]:
  592. compose_command = 'docker compose'
  593. version_output = proc[1].strip()
  594. else:
  595. log.debug('docker compose can not find detach argument')
  596. else:
  597. compose_proc = exec_command('docker-compose', 'version')
  598. if compose_proc[0] == 0:
  599. help_proc = exec_command('docker-compose', 'up', '--help')
  600. if help_proc[0] == 0 and '--detach' in help_proc[1]:
  601. compose_command = 'docker-compose'
  602. version_output = compose_proc[1].strip()
  603. else:
  604. log.debug('docker-compose can not find detach argument')
  605. else:
  606. log.warning(text('docker-compose-not-installed'))
  607. if version_output != '':
  608. t = re.findall(r'^Docker Compose version v?(\d+)\.', version_output)
  609. if len(t) == 0:
  610. log.warning(text('docker-compose-not-installed'))
  611. elif int(t[0]) < 2:
  612. log.warning(text('docker-version-too-low'))
  613. else:
  614. return True
  615. action = ui_choice(text('if-update-docker'), [
  616. ('y', text('yes')),
  617. ('n', text('no')),
  618. ])
  619. if action.lower() == 'n':
  620. return False
  621. elif action.lower() == 'y':
  622. if not install_docker():
  623. log.warning(text('install-docker-failed'))
  624. return False
  625. def precheck():
  626. if platform.machine() in ('x86_64', 'AMD64') and 'ssse3' not in open('/proc/cpuinfo', 'r').read().lower():
  627. log.warning(text('ssse3-not-support'))
  628. return False
  629. if free_memory() < 1024 * 1024 * 1024:
  630. log.warning(text('insufficient-memory'))
  631. return False
  632. log.info(text("docker-version"))
  633. while True:
  634. proc = exec_command('docker', '--version')
  635. if proc[0] == 0:
  636. t = re.findall(r'^Docker version (\d+)\.', proc[1])
  637. if len(t) == 0:
  638. log.warning(text('docker-not-installed'))
  639. elif int(t[0]) < 20:
  640. log.warning(text('docker-version-too-low'))
  641. else:
  642. break
  643. else:
  644. log.warning(text('docker-not-installed'))
  645. action = ui_choice(text('if-install-docker'), [
  646. ('y', text('yes')),
  647. ('n', text('no')),
  648. ])
  649. if action.lower() == 'n':
  650. return False
  651. elif action.lower() == 'y':
  652. if not install_docker():
  653. log.warning(text('install-docker-failed'))
  654. return False
  655. if not precheck_docker_compose():
  656. return False
  657. return True
  658. def docker_pull(cwd):
  659. log.info(text('docker-pull'))
  660. try:
  661. subprocess.check_call(compose_command+' pull', cwd=cwd, shell=True)
  662. return True
  663. except Exception as e:
  664. log.warning("docker pull error: "+str(e))
  665. return False
  666. def docker_restart(container):
  667. log.info(text('docker-restart')+": "+container)
  668. try:
  669. subprocess.check_call('docker restart '+container, shell=True)
  670. return True
  671. except Exception as e:
  672. log.error("docker restart error: "+str(e))
  673. return False
  674. def docker_exec(container, command):
  675. log.info(text('docker-exec')+": ("+container+") "+command)
  676. try:
  677. subprocess.check_call('docker exec '+container+' '+command, shell=True)
  678. return True
  679. except Exception as e:
  680. log.error("docker exec error: "+str(e))
  681. return False
  682. def image_clean():
  683. log.info(text('image-clean'))
  684. proc = exec_command('docker image prune -f --filter="label=maintainer=SafeLine-CE"', shell=True)
  685. if proc[0] != 0:
  686. log.warning("remove docker image failed: "+proc[2])
  687. def docker_up(cwd):
  688. log.info(text('docker-up'))
  689. while True:
  690. p = exec_command_with_loading(compose_command+' up -d --remove-orphans', cwd=cwd)
  691. if p[0] == 0:
  692. return True
  693. if 'iptables failed' in p[2]:
  694. log.warning("docker up error: "+p[2])
  695. while True:
  696. action = ui_choice(text('docker-up-iptables-failed'),[
  697. ('y', text('yes')),
  698. ('n', text('no')),
  699. ])
  700. if action.lower() == 'y':
  701. start_docker()
  702. break
  703. elif action.lower() == 'n':
  704. return False
  705. else:
  706. log.error("docker up error: "+p[2])
  707. def docker_down(cwd):
  708. log.info(text('docker-down'))
  709. try:
  710. subprocess.check_call(compose_command+' down', cwd=cwd, shell=True)
  711. return True
  712. except Exception:
  713. return False
  714. def get_url_time(url):
  715. now = datetime.datetime.now()
  716. try:
  717. urlopen(url)
  718. except HTTPError as e:
  719. log.debug("get url "+url+" status: "+str(e.status))
  720. if e.status > 499:
  721. return 999999
  722. except Exception as e:
  723. log.debug("get url "+url+" failed: "+str(e))
  724. return 999999
  725. return (datetime.datetime.now() - now).microseconds / 1000
  726. def get_avg_delay(url):
  727. log.debug("test url avg delay: "+url)
  728. total_delay = 0
  729. for i in range(3):
  730. total_delay += get_url_time(url)
  731. avg_delay = total_delay / 3
  732. log.debug("url "+url+" avg delay: "+str(avg_delay))
  733. return avg_delay
  734. pull_failed_prefix = []
  735. def image_source():
  736. source = {
  737. 'https://registry-1.docker.io': 'chaitin',
  738. "https://swr.cn-east-3.myhuaweicloud.com": 'swr.cn-east-3.myhuaweicloud.com/chaitin-safeline'
  739. }
  740. min_delay = -1
  741. image_prefix = ''
  742. for url, prefix in source.items():
  743. if prefix in pull_failed_prefix:
  744. continue
  745. delay = get_avg_delay(url)
  746. if delay > 0 and (min_delay < 0 or delay < min_delay):
  747. min_delay = delay
  748. image_prefix = prefix
  749. log.debug("use image_prefix: "+image_prefix)
  750. return image_prefix
  751. def docker_source():
  752. sources = [
  753. "https://mirrors.aliyun.com/docker-ce/",
  754. "https://mirrors.tencent.com/docker-ce/",
  755. "https://download.docker.com"
  756. ]
  757. min_delay = -1
  758. source = ''
  759. for v in sources:
  760. delay = get_avg_delay(v)
  761. if delay > 0 and (min_delay < 0 or delay < min_delay):
  762. min_delay = delay
  763. source = v
  764. return source
  765. def read_config(path,config):
  766. with open(path, 'r') as f:
  767. for line in f.readlines():
  768. if line.strip() == '':
  769. continue
  770. try:
  771. s = line.index('=')
  772. if s > 0:
  773. k = line[:s].strip()
  774. v = line[s + 1:].strip()
  775. config[k] = v
  776. except ValueError:
  777. continue
  778. def generate_config(path):
  779. log.info(text('update-config'))
  780. config = {
  781. 'SAFELINE_DIR': path,
  782. 'POSTGRES_PASSWORD': '',
  783. 'MGT_PORT': '',
  784. 'RELEASE': '',
  785. 'CHANNEL': '',
  786. 'REGION': '',
  787. 'IMAGE_PREFIX': '',
  788. 'IMAGE_TAG': '',
  789. 'SUBNET_PREFIX': '',
  790. 'ARCH_SUFFIX': ''
  791. }
  792. env_path = os.path.join(path,'.env')
  793. if os.path.exists(env_path):
  794. read_config(env_path,config)
  795. if config['ARCH_SUFFIX'] == '':
  796. if platform.machine() == 'aarch64':
  797. config['ARCH_SUFFIX'] = '-arm'
  798. if config['POSTGRES_PASSWORD'] == '':
  799. config['POSTGRES_PASSWORD'] = ''.join([random.choice(string.ascii_letters + string.digits) for i in range(20)])
  800. if config['SUBNET_PREFIX'] == '':
  801. config['SUBNET_PREFIX'] = rand_subnet()
  802. if config['RELEASE'] == '' and LTS:
  803. config['RELEASE'] = '-lts'
  804. config['CHANNEL'] = '-lts'
  805. default_try = False
  806. if config['MGT_PORT'] == '9443':
  807. default_try = True
  808. while not config['MGT_PORT'].isnumeric() or int(config['MGT_PORT']) >= 65536 or int(config['MGT_PORT']) <= 0 or not check_port(config['MGT_PORT']):
  809. if not default_try:
  810. config['MGT_PORT'] = '9443'
  811. default_try = True
  812. else:
  813. config['MGT_PORT'] = ui_read(text('input-mgt-port'),None)
  814. if config['REGION'] == '' and EN:
  815. config['REGION'] = '-g'
  816. if not config['POSTGRES_PASSWORD'].isalnum():
  817. log.info(text('pg-pass-contains-invalid-char'))
  818. raise Exception(text('pg-pass-contains-invalid-char'))
  819. if config['IMAGE_PREFIX'] == '' or config['IMAGE_PREFIX'] in pull_failed_prefix:
  820. config['IMAGE_PREFIX'] = image_source()
  821. if config['IMAGE_PREFIX'] == '':
  822. raise Exception(text('fail-to-connect-image-source'))
  823. config['IMAGE_TAG'] = 'latest'
  824. with open(env_path, 'w') as f:
  825. for k in config:
  826. f.write('%s=%s\n' % (k, config[k]))
  827. return config
  828. def show_address(mgt_port):
  829. s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  830. s.connect(("8.8.8.8", 80))
  831. local_ip = s.getsockname()[0]
  832. log.info(text('go-to-panel', (local_ip, mgt_port)))
  833. log.info(text('go-to-panel', ('0.0.0.0', mgt_port)))
  834. def reset_admin():
  835. log.info(text('reset-admin'))
  836. while True:
  837. p = exec_command('docker', 'inspect','--format=\'{{.State.Health.Status}}\'', 'safeline-mgt')
  838. if p[0] == 0 and p[1].strip().replace("'",'') == 'healthy':
  839. break
  840. elif p[0] != 0:
  841. log.debug("get safeline-mgt status error: "+str(p[2]))
  842. log.info("wait safeline-mgt healthy, sleep 5s")
  843. time.sleep(5)
  844. proc = exec_command('docker exec safeline-mgt /app/mgt-cli reset-admin --once',shell=True)
  845. if proc[0] != 0:
  846. log.warning(proc[2])
  847. elif proc[1].strip() != '':
  848. log.info('\n'+proc[1].strip())
  849. def install():
  850. global INSTALL
  851. INSTALL = True
  852. log.info(text('prepare-to-install'))
  853. if not precheck():
  854. log.error(text('precheck-failed'))
  855. return
  856. log.info(text('precheck-passed'))
  857. while True:
  858. safeline_path = ui_read(text('input-target-path'), '/data/safeline')
  859. if not safeline_path.startswith('/'):
  860. log.warning(text('invalid-path', safeline_path))
  861. continue
  862. if os.path.exists(safeline_path):
  863. log.warning(text('path-exists', safeline_path))
  864. continue
  865. if free_space(safeline_path) < 5 * 1024 * 1024 * 1024:
  866. log.warning(text('insufficient-disk-capacity'))
  867. continue
  868. break
  869. try:
  870. os.makedirs(safeline_path)
  871. except Exception as e:
  872. log.error(text('fail-to-create-dir', safeline_path) + ' ' + str(e))
  873. return
  874. log.info(text('remain-disk-capacity', (safeline_path, humen_size(free_space(safeline_path)))))
  875. log.info(text('download-compose'))
  876. if not save_file_from_url('https://'+DOMAIN+'/release/latest/compose.yaml',os.path.join(safeline_path, 'docker-compose.yaml')):
  877. log.error(text('fail-to-download-compose'))
  878. return
  879. if os.path.exists(os.path.join(safeline_path, 'compose.yaml')):
  880. os.rename(os.path.join(safeline_path, 'compose.yaml'),os.path.join(safeline_path, 'compose.yaml.bak'))
  881. while True:
  882. config = generate_config(safeline_path)
  883. if docker_pull(safeline_path):
  884. break
  885. pull_failed_prefix.append(config['IMAGE_PREFIX'])
  886. log.info(text('try-another-image-source'))
  887. if not docker_up(safeline_path):
  888. log.error(text('fail-to-up'))
  889. return
  890. log.info(text('install-finish'))
  891. reset_admin()
  892. show_address(config['MGT_PORT'])
  893. def get_installed_dir():
  894. safeline_path = ''
  895. safeline_path_proc = exec_command('docker','inspect','--format','\'{{index .Config.Labels "com.docker.compose.project.working_dir"}}\'', 'safeline-mgt')
  896. if safeline_path_proc[0] == 0:
  897. safeline_path = safeline_path_proc[1].strip().replace("'",'')
  898. else:
  899. log.debug("get installed dir error: "+ safeline_path_proc[2])
  900. log.debug("find safeline installed path: " + safeline_path)
  901. if safeline_path == '' or not os.path.exists(safeline_path):
  902. log.warning(text('fail-to-get-installed-dir'))
  903. return ui_read(text('input-target-path'),None)
  904. return safeline_path
  905. def save_file_from_url(url, path):
  906. log.debug('saving '+url+' to '+path)
  907. data = get_url(url)
  908. if data is None:
  909. return False
  910. with open(path, 'w') as f:
  911. f.write(data)
  912. return True
  913. def upgrade():
  914. safeline_path = get_installed_dir()
  915. if not precheck_docker_compose():
  916. log.error(text('precheck-failed'))
  917. return
  918. log.info(text('download-compose'))
  919. if not save_file_from_url('https://'+DOMAIN+'/release/latest/compose.yaml', os.path.join(safeline_path, 'docker-compose.yaml')):
  920. log.error(text('fail-to-download-compose'))
  921. return
  922. if os.path.exists(os.path.join(safeline_path, 'compose.yaml')):
  923. os.rename(os.path.join(safeline_path, 'compose.yaml'),os.path.join(safeline_path, 'compose.yaml.bak'))
  924. while True:
  925. config = generate_config(safeline_path)
  926. if docker_pull(safeline_path):
  927. break
  928. pull_failed_prefix.append(config['IMAGE_PREFIX'])
  929. log.info(text('try-another-image-source'))
  930. if not docker_up(safeline_path):
  931. log.error(text('fail-to-up'))
  932. return
  933. if IMAGE_CLEAN:
  934. image_clean()
  935. log.info(text('upgrade-finish'))
  936. reset_admin()
  937. show_address(config['MGT_PORT'])
  938. pass
  939. def reset_tengine():
  940. safeline_path = get_installed_dir()
  941. resources_path = os.path.join(safeline_path, 'resources')
  942. nginx_path = os.path.join(resources_path,'nginx')
  943. if not os.path.exists(nginx_path):
  944. log.error(text('fail-to-find-nginx'))
  945. return
  946. backup_path = os.path.join(resources_path, 'nginx.'+str(datetime.datetime.now().timestamp()))
  947. log.info(text('nginx-backup-dir') +': '+ backup_path)
  948. try:
  949. shutil.move(nginx_path, backup_path)
  950. except Exception as e:
  951. log.error(text('fail-to-backup-nginx')+': '+str(e))
  952. return
  953. if docker_restart('safeline-tengine'):
  954. docker_exec('safeline-mgt', 'gentenginewebsite')
  955. if os.path.exists(os.path.join(backup_path, 'static')):
  956. try:
  957. shutil.copy(os.path.join(backup_path, 'static'), os.path.join(nginx_path, 'static'))
  958. except Exception as e:
  959. log.error(text('fail-to-recover-static')+': '+str(e))
  960. return
  961. log.info(text('reset-tengine-finish'))
  962. def reset_postgres():
  963. safeline_path = get_installed_dir()
  964. if not precheck_docker_compose():
  965. log.error(text('precheck-failed'))
  966. return
  967. env_file = os.path.join(safeline_path, '.env')
  968. if not os.path.exists(env_file):
  969. log.error(text('fail-to-find-env'))
  970. return
  971. config = {}
  972. read_config(env_file, config)
  973. if config['POSTGRES_PASSWORD'] == '':
  974. log.error(text('fail-to-find-postgres-password'))
  975. return
  976. if not docker_exec('safeline-pg','psql -U safeline-ce -c "ALTER USER \\"safeline-ce\\" WITH PASSWORD \''+config['POSTGRES_PASSWORD']+'\';"'):
  977. log.error(text('fail-to-reset-postgres-password'))
  978. return
  979. if not docker_down(safeline_path):
  980. log.error(text('fail-to-down'))
  981. return
  982. if not docker_up(safeline_path):
  983. log.error(text('fail-to-up'))
  984. return
  985. log.info(text('reset-postgres-password-finish'))
  986. def repair():
  987. action = ui_choice(text('choice-action'),[
  988. ('1', text('reset-tengine')),
  989. ('2', text('reset-postgres')),
  990. ])
  991. if action =='1':
  992. reset_tengine()
  993. elif action =='2':
  994. reset_postgres()
  995. def backup():
  996. pass
  997. def uninstall():
  998. safeline_path = get_installed_dir()
  999. action = ui_choice(text('if-remove-waf')+": "+safeline_path,[
  1000. ('y', text('yes')),
  1001. ('n', text('no')),
  1002. ])
  1003. if action == 'n':
  1004. return
  1005. if not precheck_docker_compose():
  1006. log.error(text('precheck-failed'))
  1007. return
  1008. if not docker_down(safeline_path):
  1009. log.error(text('fail-to-docker-down'))
  1010. return
  1011. try:
  1012. shutil.rmtree(safeline_path)
  1013. except Exception as e:
  1014. log.debug("remove dir failed: "+str(e))
  1015. log.error(text('fail-to-remove-dir'))
  1016. log.info(text('uninstall-finish'))
  1017. def init_global_config():
  1018. global lang, DEBUG, LTS, IMAGE_CLEAN, EN, DOMAIN
  1019. lang = 'zh'
  1020. if '--debug' in sys.argv:
  1021. DEBUG = True
  1022. if '--lts' in sys.argv:
  1023. LTS = True
  1024. if '--image-clean' in sys.argv:
  1025. IMAGE_CLEAN = True
  1026. if '--en' in sys.argv:
  1027. EN = True
  1028. lang = 'en'
  1029. DOMAIN = 'waf.chaitin.com'
  1030. def main():
  1031. init_global_config()
  1032. banner()
  1033. log.info(text('hello1'))
  1034. log.info(text('hello2'))
  1035. print()
  1036. if LTS:
  1037. log.info(text('install-channel')+": "+text('lts-release'))
  1038. if sys.version_info.major == 2 or (sys.version_info.major == 3 and sys.version_info.minor <= 5):
  1039. log.error(text('python-version-too-low'))
  1040. return
  1041. if not sys.stdin.isatty():
  1042. log.error(text('not-a-tty'))
  1043. return
  1044. if os.geteuid() != 0:
  1045. log.error(text('not-root'))
  1046. return
  1047. if platform.system() != 'Linux':
  1048. log.error(text('not-linux', platform.system()))
  1049. return
  1050. if platform.machine() not in ('aarch64', 'x86_64', 'AMD64'):
  1051. log.error(text('unsupported-arch', platform.machine()))
  1052. return
  1053. action = ui_choice(text('choice-action'), [
  1054. ('1', text('install')),
  1055. ('2', text('upgrade')),
  1056. ('3', text('uninstall')),
  1057. ('4', text('repair')),
  1058. # ('4', text('backup'))
  1059. ])
  1060. if action == '1':
  1061. install()
  1062. elif action == '2':
  1063. upgrade()
  1064. elif action == '3':
  1065. uninstall()
  1066. elif action == '4':
  1067. repair()
  1068. # elif action == '4':
  1069. # backup()
  1070. if __name__ == '__main__':
  1071. try:
  1072. main()
  1073. except KeyboardInterrupt:
  1074. log.warning(text('keyboard-interrupt'))
  1075. pass
  1076. except Exception as e:
  1077. log.error(e)
  1078. finally:
  1079. print(color(text('talking-group') + '\n', [GREEN]))