diff --git a/config.gen.yml b/config.gen.yml index 4759325..e0f3384 100644 --- a/config.gen.yml +++ b/config.gen.yml @@ -11,6 +11,7 @@ api_id: "ID_HERE" api_hash: "HASH_HERE" qrcode_login: "False" +web_login: "False" # Either debug logging is enabled or not debug: "False" diff --git a/pagermaid/__init__.py b/pagermaid/__init__.py index b513f85..e1c6348 100644 --- a/pagermaid/__init__.py +++ b/pagermaid/__init__.py @@ -21,8 +21,8 @@ from pagermaid.scheduler import scheduler import pyromod.listen from pyrogram import Client -pgm_version = "1.3.4" -pgm_version_code = 1304 +pgm_version = "1.4.0" +pgm_version_code = 1400 CMD_LIST = {} module_dir = __path__[0] working_dir = getcwd() diff --git a/pagermaid/__main__.py b/pagermaid/__main__.py index d983674..e5a7ef3 100644 --- a/pagermaid/__main__.py +++ b/pagermaid/__main__.py @@ -1,15 +1,16 @@ import asyncio from os import sep from signal import signal as signal_fn, SIGINT, SIGTERM, SIGABRT -from sys import path, platform +from sys import path, platform, exit from pyrogram.errors import AuthKeyUnregistered -from pagermaid import bot, logs, working_dir +from pagermaid import bot, logs, working_dir, Config from pagermaid.common.reload import load_all from pagermaid.single_utils import safe_remove from pagermaid.utils import lang, process_exit from pagermaid.web import web +from pagermaid.web.api.web_login import web_login from pyromod.methods.sign_in_qrcode import start_client path.insert(1, f"{working_dir}{sep}plugins") @@ -50,11 +51,29 @@ async def console_bot(): await process_exit(start=True, _client=bot) +async def web_bot(): + try: + await web_login.init() + except AuthKeyUnregistered: + safe_remove("pagermaid.session") + exit() + if bot.me is not None: + me = await bot.get_me() + if me.is_bot: + safe_remove("pagermaid.session") + exit() + else: + logs.info("Please use web to login, path: web_login .") + + async def main(): logs.info(lang("platform") + platform + lang("platform_load")) await web.start() - await console_bot() - logs.info(lang("start")) + if not (Config.WEB_ENABLE and Config.WEB_LOGIN): + await console_bot() + logs.info(lang("start")) + else: + await web_bot() try: await idle() diff --git a/pagermaid/config.py b/pagermaid/config.py index f7a5a2e..6ddca7a 100644 --- a/pagermaid/config.py +++ b/pagermaid/config.py @@ -48,6 +48,9 @@ class Config: QRCODE_LOGIN = strtobool( os.environ.get("QRCODE_LOGIN", config.get("qrcode_login", "false")) ) + WEB_LOGIN = strtobool( + os.environ.get("WEB_LOGIN", config.get("web_login", "false")) + ) STRING_SESSION = os.environ.get("STRING_SESSION") DEBUG = strtobool(os.environ.get("PGM_DEBUG", config["debug"])) ERROR_REPORT = strtobool( diff --git a/pagermaid/enums/__init__.py b/pagermaid/enums/__init__.py index 82dd64c..2e45042 100644 --- a/pagermaid/enums/__init__.py +++ b/pagermaid/enums/__init__.py @@ -5,3 +5,13 @@ from apscheduler.schedulers.asyncio import AsyncIOScheduler from sqlitedict import SqliteDict from httpx import AsyncClient from logging import Logger + +__all__ = [ + "Client", + "Message", + "Sub", + "AsyncIOScheduler", + "SqliteDict", + "AsyncClient", + "Logger" +] diff --git a/pagermaid/listener.py b/pagermaid/listener.py index 765bb59..ea1c4ff 100644 --- a/pagermaid/listener.py +++ b/pagermaid/listener.py @@ -34,6 +34,7 @@ from pagermaid.utils import ( process_exit, ) from pagermaid.hook import Hook +from pagermaid.web import web _lock = asyncio.Lock() @@ -197,7 +198,7 @@ def listener(**args): except SystemExit: await process_exit(start=False, _client=client, message=message) await Hook.shutdown() - sys.exit(0) + web.stop() except BaseException: exc_info = sys.exc_info()[1] exc_format = format_exc() diff --git a/pagermaid/modules/help.py b/pagermaid/modules/help.py index c8f7406..a92766e 100644 --- a/pagermaid/modules/help.py +++ b/pagermaid/modules/help.py @@ -1,7 +1,5 @@ """ The help module. """ - -from json import dump as json_dump -from os import listdir, sep +from os import listdir from pyrogram.enums import ParseMode diff --git a/pagermaid/modules/plugin.py b/pagermaid/modules/plugin.py index d9ce523..662ae92 100644 --- a/pagermaid/modules/plugin.py +++ b/pagermaid/modules/plugin.py @@ -140,7 +140,7 @@ async def plugin(message: Message): for target_plugin in active_plugins: inactive_plugins.remove(target_plugin) chdir(f"plugins{sep}") - for target_plugin in glob(f"*.py.disabled"): + for target_plugin in glob("*.py.disabled"): disabled_plugins += [f"{target_plugin[:-12]}"] chdir(f"..{sep}") active_plugins_string = "" diff --git a/pagermaid/modules/sentry.py b/pagermaid/modules/sentry.py index 429e91b..85f01ae 100644 --- a/pagermaid/modules/sentry.py +++ b/pagermaid/modules/sentry.py @@ -1,6 +1,7 @@ import sentry_sdk from subprocess import run, PIPE +import sys from time import time from pyrogram.errors import Unauthorized, UsernameInvalid @@ -18,7 +19,7 @@ def sentry_before_send(event, hint): if exc_info and isinstance(exc_info[1], (Unauthorized, UsernameInvalid)): # The user has been deleted/deactivated or session revoked safe_remove("pagermaid.session") - exit(1) + sys.exit(1) if time() <= sentry_sdk_report_time + 30: sentry_sdk_report_time = time() return None @@ -29,7 +30,7 @@ def sentry_before_send(event, hint): sentry_sdk_report_time = time() sentry_sdk_git_hash = ( - run("git rev-parse HEAD", stdout=PIPE, shell=True).stdout.decode().strip() + run("git rev-parse HEAD", stdout=PIPE, shell=True, check=True).stdout.decode(check=True).strip(check=True) ) sentry_sdk.init( Config.SENTRY_API, diff --git a/pagermaid/modules/status.py b/pagermaid/modules/status.py index edb7758..897940f 100644 --- a/pagermaid/modules/status.py +++ b/pagermaid/modules/status.py @@ -2,7 +2,7 @@ import re -from datetime import datetime, timezone +from datetime import datetime from platform import uname, python_version from sys import platform @@ -18,7 +18,7 @@ from psutil import boot_time, virtual_memory, disk_partitions from shutil import disk_usage from subprocess import Popen, PIPE -from pagermaid import start_time, Config, pgm_version +from pagermaid import Config, pgm_version from pagermaid.common.status import get_bot_uptime from pagermaid.enums import Client, Message from pagermaid.listener import listener diff --git a/pagermaid/modules/system.py b/pagermaid/modules/system.py index 78da180..0053095 100644 --- a/pagermaid/modules/system.py +++ b/pagermaid/modules/system.py @@ -1,3 +1,4 @@ +import sys from getpass import getuser from os.path import exists, sep from platform import node @@ -8,7 +9,6 @@ from pagermaid.common.system import run_eval from pagermaid.enums import Message from pagermaid.listener import listener from pagermaid.utils import attach_log, execute, lang, upload_attachment -from pagermaid.web import web @listener( @@ -51,7 +51,7 @@ async def restart(message: Message): """To re-execute PagerMaid.""" if not message.text[0].isalpha(): await message.edit(lang("restart_log")) - web.stop() + sys.exit(0) @listener( @@ -65,7 +65,8 @@ async def sh_eval(message: Message): """Run python commands from Telegram.""" dev_mode = exists(f"data{sep}dev") try: - assert dev_mode + if not dev_mode: + raise AssertionError cmd = message.text.split(" ", maxsplit=1)[1] except (IndexError, AssertionError): return await message.edit(lang("eval_need_dev")) diff --git a/pagermaid/services/__init__.py b/pagermaid/services/__init__.py index 35810b1..64d3b16 100644 --- a/pagermaid/services/__init__.py +++ b/pagermaid/services/__init__.py @@ -4,6 +4,14 @@ from pagermaid.single_utils import sqlite from pagermaid.scheduler import scheduler from pagermaid.utils import client +__all__ = [ + "bot", + "logs", + "sqlite", + "scheduler", + "client", +] + def get(name: str): data = { @@ -13,4 +21,4 @@ def get(name: str): "AsyncIOScheduler": scheduler, "AsyncClient": client, } - return data.get(name, None) + return data.get(name) diff --git a/pagermaid/single_utils.py b/pagermaid/single_utils.py index 2d4d50d..87c2b88 100644 --- a/pagermaid/single_utils.py +++ b/pagermaid/single_utils.py @@ -3,7 +3,6 @@ from os import sep, remove, mkdir from os.path import exists from typing import List, Optional, Union from apscheduler.schedulers.asyncio import AsyncIOScheduler -from httpx import AsyncClient from pyrogram import Client as OldClient from pyrogram.types import Chat as OldChat, Message as OldMessage, Dialog @@ -14,9 +13,13 @@ from pyromod.utils.errors import ( TimeoutConversationError, ListenerCanceled, ) - from sqlitedict import SqliteDict +__all__ = [ + "AlreadyInConversationError", + "TimeoutConversationError", + "ListenerCanceled", +] # init folders if not exists("data"): mkdir("data") diff --git a/pagermaid/utils.py b/pagermaid/utils.py index e725ba7..d8c9364 100644 --- a/pagermaid/utils.py +++ b/pagermaid/utils.py @@ -10,7 +10,7 @@ from sys import executable from asyncio import create_subprocess_shell, sleep from asyncio.subprocess import PIPE -from pyrogram import filters, enums +from pyrogram import filters from pagermaid.config import Config from pagermaid import bot from pagermaid.group_manager import enforce_permission diff --git a/pagermaid/web/__init__.py b/pagermaid/web/__init__.py index e641af5..079f14f 100644 --- a/pagermaid/web/__init__.py +++ b/pagermaid/web/__init__.py @@ -7,7 +7,7 @@ from starlette.responses import RedirectResponse from pagermaid import logs from pagermaid.config import Config -from pagermaid.web.api import base_api_router +from pagermaid.web.api import base_api_router, base_html_router from pagermaid.web.pages import admin_app, login_page requestAdaptor = """ @@ -39,6 +39,7 @@ class Web: def init_web(self): self.app.include_router(base_api_router) + self.app.include_router(base_html_router) self.app.add_middleware( CORSMiddleware, diff --git a/pagermaid/web/api/__init__.py b/pagermaid/web/api/__init__.py index 46b3e99..cb57d01 100644 --- a/pagermaid/web/api/__init__.py +++ b/pagermaid/web/api/__init__.py @@ -7,8 +7,12 @@ from pagermaid.web.api.ignore_groups import route as ignore_groups_route from pagermaid.web.api.login import route as login_route from pagermaid.web.api.plugin import route as plugin_route from pagermaid.web.api.status import route as status_route +from pagermaid.web.api.web_login import route as web_login_route, html_route as web_login_html_route + +__all__ = ["authentication", "base_api_router", "base_html_router"] base_api_router = APIRouter(prefix="/pagermaid/api") +base_html_router = APIRouter() base_api_router.include_router(plugin_route) base_api_router.include_router(bot_info_route) @@ -16,3 +20,5 @@ base_api_router.include_router(status_route) base_api_router.include_router(login_route) base_api_router.include_router(command_alias_route) base_api_router.include_router(ignore_groups_route) +base_api_router.include_router(web_login_route) +base_html_router.include_router(web_login_html_route) diff --git a/pagermaid/web/api/web_login.py b/pagermaid/web/api/web_login.py new file mode 100644 index 0000000..2b4121e --- /dev/null +++ b/pagermaid/web/api/web_login.py @@ -0,0 +1,125 @@ +from fastapi import APIRouter +from fastapi.responses import JSONResponse +from pydantic import BaseModel +from pyrogram.errors import BadRequest, AuthTokenExpired +from pyrogram.raw.functions.account import InitTakeoutSession +from pyrogram.raw.functions.updates import GetState +from starlette.responses import HTMLResponse + +from pagermaid import bot, logs +from pagermaid.common.reload import load_all +from pagermaid.utils import lang, process_exit +from pagermaid.web.api import authentication +from pagermaid.web.html import get_web_login_html +from pyromod.methods.sign_in_qrcode import authorize_by_qrcode_web +from pyromod.utils.errors import QRCodeWebCodeError, QRCodeWebNeedPWDError +import sys + + +class UserModel(BaseModel): + password: str + + +class WebLogin(): + def __init__(self): + self.is_authorized = False + self.need_password = False + self.password_hint = "" + + async def connect(self): + if not bot.is_connected: + self.is_authorized = await bot.connect() + + @staticmethod + async def initialize(): + if bot.is_connected and not bot.is_initialized: + await bot.initialize() + + @staticmethod + def has_login(): + return bot.me is not None + + @staticmethod + async def init_bot(): + logs.info(f"{lang('save_id')} {bot.me.first_name}({bot.me.id})") + await load_all() + await process_exit(start=True, _client=bot) + logs.info(lang("start")) + + async def init(self): + await self.connect() + if not self.is_authorized: + return + if not await bot.storage.is_bot() and bot.takeout: + bot.takeout_id = ( + await bot.invoke(InitTakeoutSession()) + ).id + + await bot.invoke(GetState()) + bot.me = await bot.get_me() + if bot.me.is_bot: + sys.exit(0) + await self.initialize() + await self.init_bot() + + +route = APIRouter() +html_route = APIRouter() +web_login = WebLogin() +web_login_html = get_web_login_html() + + +@route.get("/web_login", response_class=JSONResponse, dependencies=[authentication()]) +async def web_login_qrcode(): + if web_login.has_login(): + return {"status": 0, "msg": "已登录"} + try: + await web_login.connect() + if not web_login.is_authorized: + await authorize_by_qrcode_web(bot) + web_login.is_authorized = True + await web_login.init() + return {"status": 0, "msg": "登录成功"} + except QRCodeWebCodeError as e: + web_login.need_password = False + return {"status": 1, "msg": "未扫码", "content": e.code} + except QRCodeWebNeedPWDError as e: + web_login.need_password = True + web_login.password_hint = e.hint or "" + return {"status": 2, "msg": "需要密码", "content": web_login.password_hint} + except AuthTokenExpired: + return {"status": 3, "msg": "登录状态过期,请重新扫码登录"} + except BadRequest as e: + return {"status": 3, "msg": e.MESSAGE} + except Exception as e: + return {"status": 3, "msg": f"{type(e)}"} + + +@route.post("/web_login", response_class=JSONResponse, dependencies=[authentication()]) +async def web_login_password(user: UserModel): + if web_login.has_login(): + return {"status": 0, "msg": "已登录"} + if not web_login.need_password: + return {"status": 0, "msg": "无需密码"} + try: + await authorize_by_qrcode_web(bot, user.password) + web_login.is_authorized = True + await web_login.init() + return {"status": 0, "msg": "登录成功"} + except QRCodeWebCodeError as e: + return {"status": 1, "msg": "需要重新扫码", "content": e.code} + except QRCodeWebNeedPWDError as e: + web_login.need_password = True + return {"status": 2, "msg": "密码错误", "content": e.hint or ""} + except AuthTokenExpired: + web_login.need_password = False + return {"status": 3, "msg": "登录状态过期,请重新扫码登录"} + except BadRequest as e: + return {"status": 3, "msg": e.MESSAGE} + except Exception as e: + return {"status": 3, "msg": f"{type(e)}"} + + +@html_route.get("/web_login", response_class=HTMLResponse) +async def get_web_login(): + return web_login_html diff --git a/pagermaid/web/html/__init__.py b/pagermaid/web/html/__init__.py index e770269..77ba242 100644 --- a/pagermaid/web/html/__init__.py +++ b/pagermaid/web/html/__init__.py @@ -22,3 +22,8 @@ def get_github_logo() -> str: def get_footer() -> str: """获取 footer。""" return get_html(html_base_path / "footer.html") + + +def get_web_login_html() -> str: + """获取 web login。""" + return get_html(html_base_path / "web_login.html") diff --git a/pagermaid/web/html/web_login.html b/pagermaid/web/html/web_login.html new file mode 100644 index 0000000..6767295 --- /dev/null +++ b/pagermaid/web/html/web_login.html @@ -0,0 +1,202 @@ + + + + + + + + + + + + + QR Code Login - PagerMaid-Pyro + + + +
+
+
+
+
+

QR Code Login

+
+
+
+

Scan the QR code above to log in.

+
+
+
+
+ + +
+
+ + +
+
+ + +
+ +
+
+
+
+
+
+ + + + + + diff --git a/pagermaid/web/pages/__init__.py b/pagermaid/web/pages/__init__.py index cc8c9fe..40624c3 100644 --- a/pagermaid/web/pages/__init__.py +++ b/pagermaid/web/pages/__init__.py @@ -1,2 +1,4 @@ from .login import login_page from .main import admin_app, blank_page + +__all__ = ["admin_app", "blank_page", "login_page"] diff --git a/pagermaid/web/pages/ignore_groups.py b/pagermaid/web/pages/ignore_groups.py index 6b39021..b127c27 100644 --- a/pagermaid/web/pages/ignore_groups.py +++ b/pagermaid/web/pages/ignore_groups.py @@ -2,13 +2,10 @@ from amis import ( InputText, Switch, Card, - Tpl, CardsCRUD, PageSchema, Page, - Button, - Select, -) + ) card = Card( header=Card.Header( diff --git a/pagermaid/web/pages/plugin_remote_manage.py b/pagermaid/web/pages/plugin_remote_manage.py index 91618dc..899438c 100644 --- a/pagermaid/web/pages/plugin_remote_manage.py +++ b/pagermaid/web/pages/plugin_remote_manage.py @@ -1,4 +1,4 @@ -from amis import InputText, Switch, Card, Tpl, CardsCRUD, PageSchema, Page, Button +from amis import InputText, Switch, Card, CardsCRUD, PageSchema, Page card = Card( header=Card.Header( diff --git a/pyromod/filters/__init__.py b/pyromod/filters/__init__.py deleted file mode 100644 index 4b8f182..0000000 --- a/pyromod/filters/__init__.py +++ /dev/null @@ -1,21 +0,0 @@ -""" -pyromod - A monkeypatcher add-on for Pyrogram -Copyright (C) 2020 Cezar H. - -This file is part of pyromod. - -pyromod is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -pyromod is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with pyromod. If not, see . -""" - -from .filters import dice diff --git a/pyromod/filters/filters.py b/pyromod/filters/filters.py deleted file mode 100644 index c52d680..0000000 --- a/pyromod/filters/filters.py +++ /dev/null @@ -1,28 +0,0 @@ -""" -pyromod - A monkeypatcher add-on for Pyrogram -Copyright (C) 2020 Cezar H. - -This file is part of pyromod. - -pyromod is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -pyromod is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with pyromod. If not, see . -""" - -import pyrogram - - -def dice(ctx, message): - return hasattr(message, "dice") and message.dice - - -pyrogram.filters.dice = dice diff --git a/pyromod/listen/__init__.py b/pyromod/listen/__init__.py index b916072..0e2917e 100644 --- a/pyromod/listen/__init__.py +++ b/pyromod/listen/__init__.py @@ -17,5 +17,6 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with pyromod. If not, see . """ - from .listen import Client, MessageHandler, Chat, User + +__all__ = ["Client", "MessageHandler", "Chat", "User"] diff --git a/pyromod/listen/listen.py b/pyromod/listen/listen.py index ad5da94..9d96304 100644 --- a/pyromod/listen/listen.py +++ b/pyromod/listen/listen.py @@ -27,7 +27,7 @@ from typing import Optional, List, Union import pyrogram from pyrogram.enums import ChatType -from pagermaid.single_utils import get_sudo_list, Message +from pagermaid.single_utils import get_sudo_list from pagermaid.scheduler import add_delete_message_job from ..methods.get_dialogs_list import get_dialogs_list as get_dialogs_list_func from ..methods.read_chat_history import read_chat_history as read_chat_history_func diff --git a/pyromod/methods/sign_in_qrcode.py b/pyromod/methods/sign_in_qrcode.py index e83016f..45d0ea0 100644 --- a/pyromod/methods/sign_in_qrcode.py +++ b/pyromod/methods/sign_in_qrcode.py @@ -10,6 +10,7 @@ from pyrogram.session import Auth, Session from pyrogram.utils import ainput from pagermaid import Config +from pyromod.utils.errors import QRCodeWebNeedPWDError, QRCodeWebCodeError async def sign_in_qrcode( @@ -117,6 +118,32 @@ async def authorize_by_qrcode( return qrcode +async def authorize_by_qrcode_web( + client: Client, + password: Optional[str] = None, +): + qrcode = None + try: + if password: + client.password = password + raise SessionPasswordNeeded() + qrcode = await sign_in_qrcode(client) + except BadRequest as e: + raise e + except SessionPasswordNeeded as e: + try: + if client.password: + return await client.check_password(client.password) + except BadRequest as e: + client.password = None + raise e + raise QRCodeWebNeedPWDError(await client.get_password_hint()) from e + if isinstance(qrcode, str): + raise QRCodeWebCodeError(qrcode) + elif isinstance(qrcode, pyrogram.types.User): + return qrcode + + async def start_client(client: Client): is_authorized = await client.connect() diff --git a/pyromod/utils/__init__.py b/pyromod/utils/__init__.py index 3c9f81a..8f3b70d 100644 --- a/pyromod/utils/__init__.py +++ b/pyromod/utils/__init__.py @@ -17,5 +17,6 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with pyromod. If not, see . """ - from .utils import patch, patchable + +__all__ = ["patch", "patchable"] diff --git a/pyromod/utils/errors.py b/pyromod/utils/errors.py index 0ec0450..4870793 100644 --- a/pyromod/utils/errors.py +++ b/pyromod/utils/errors.py @@ -26,3 +26,33 @@ class ListenerCanceled(Exception): def __init__(self): super().__init__("Listener was canceled") + + +class QRCodeWebError(Exception): + """ + Occurs when the QR code is not scanned. + """ + + def __init__(self, msg: str): + self.msg = msg + super().__init__("QR code not scanned") + + +class QRCodeWebCodeError(QRCodeWebError): + """ + Occurs when the QR code is not scanned. + """ + + def __init__(self, code: str): + self.code = code + super().__init__("QR code not scanned") + + +class QRCodeWebNeedPWDError(QRCodeWebError): + """ + Occurs when the account needs to be verified. + """ + + def __init__(self, hint: str): + self.hint = hint + super().__init__("Account needs to be verified") diff --git a/utils/docker-config.sh b/utils/docker-config.sh index 6dd9788..185e957 100644 --- a/utils/docker-config.sh +++ b/utils/docker-config.sh @@ -20,7 +20,8 @@ configure () { printf "请输入应用程序 api_hash(不懂请直接回车):" read -r api_hash <&1 sed -i "s/HASH_HERE/$api_hash/" $config_file - read -p "二维码扫码登录?(避免无法收到验证码) [Y/n]" choi + printf "控制台二维码扫码登录?(避免无法收到验证码) [Y/n]" + read -r choi <&1 if [ "$choi" == "y" ] || [ "$choi" == "Y" ]; then sed -i "s/qrcode_login: \"False\"/qrcode_login: \"True\"/" $config_file fi @@ -40,29 +41,22 @@ configure () { else sed -i "s/China/$application_region/" $config_file fi - printf "请输入 Google TTS 语言(默认:zh-CN):" - read -r application_tts <&1 - if [ -z "$application_tts" ] - then - echo "tts发音语言设置为 简体中文" - else - sed -i "s/zh-CN/$application_tts/" $config_file - fi } login () { echo echo "下面进行程序运行。" echo "请在账户授权完毕后,按 Ctrl + C 使 Docker 在后台模式下运行。" + echo "如果已开启网页登录,请直接使用 Ctrl + C 使 Docker 在后台模式下运行。" echo - sleep 2 echo "Hello world!" > /pagermaid/workdir/install.lock + sleep 2 python -m pagermaid exit 0 } main () { - cd /pagermaid/workdir + cd /pagermaid/workdir || exit if [ ! -s "/pagermaid/workdir/install.lock" ]; then welcome configure diff --git a/utils/docker.sh b/utils/docker.sh index 9df478b..6aa15cc 100644 --- a/utils/docker.sh +++ b/utils/docker.sh @@ -74,11 +74,32 @@ need_web () { esac } +need_web_login () { + PGM_WEB_LOGIN=false + case $PGM_WEB in + true) + printf "请问是否需要启用 Web 登录界面 [Y/n] :" + read -r web_login <&1 + case $web_login in + [yY][eE][sS] | [yY]) + echo "您已确认需要启用 Web 登录界面 . . ." + PGM_WEB_LOGIN=true + ;; + [nN][oO] | [nN]) + ;; + *) + echo "输入错误,已跳过。" + ;; + esac + ;; + esac +} + start_docker () { echo "正在启动 Docker 容器 . . ." case $PGM_WEB in true) - docker run -dit --restart=always --name="$container_name" --hostname="$container_name" -e WEB_ENABLE="$PGM_WEB" -e WEB_SECRET_KEY="$admin_password" -e WEB_HOST=0.0.0.0 -e WEB_PORT=3333 -p 3333:3333 teampgm/pagermaid_pyro <&1 + docker run -dit --restart=always --name="$container_name" --hostname="$container_name" -e WEB_ENABLE="$PGM_WEB" -e WEB_SECRET_KEY="$admin_password" -e WEB_HOST=0.0.0.0 -e WEB_PORT=3333 -e WEB_LOGIN="$PGM_WEB_LOGIN" -p 3333:3333 teampgm/pagermaid_pyro <&1 ;; *) docker run -dit --restart=always --name="$container_name" --hostname="$container_name" teampgm/pagermaid_pyro <&1 @@ -148,6 +169,7 @@ start_installation () { access_check build_docker need_web + need_web_login start_docker data_persistence } @@ -216,6 +238,7 @@ reinstall_pager () { cleanup build_docker need_web + need_web_login start_docker data_persistence } @@ -237,10 +260,10 @@ shon_online () { echo " 6) Docker 重装 PagerMaid" echo " 7) 退出脚本" echo - echo " Version:2.1.0" + echo " Version:2.2.0" echo echo -n "请输入编号: " - read N + read -r N <&1 case $N in 1) start_installation