2023-03-12 03:56:01 +00:00
|
|
|
|
from amis import (
|
|
|
|
|
Page,
|
|
|
|
|
PageSchema,
|
|
|
|
|
Html,
|
|
|
|
|
Property,
|
|
|
|
|
Service,
|
|
|
|
|
Flex,
|
|
|
|
|
ActionType,
|
|
|
|
|
LevelEnum,
|
|
|
|
|
Divider,
|
|
|
|
|
Log,
|
|
|
|
|
Alert,
|
|
|
|
|
Form,
|
|
|
|
|
Dialog,
|
|
|
|
|
Select,
|
|
|
|
|
Group,
|
|
|
|
|
InputText,
|
|
|
|
|
DisplayModeEnum,
|
|
|
|
|
Horizontal,
|
|
|
|
|
)
|
2023-01-31 16:24:56 +00:00
|
|
|
|
|
|
|
|
|
from pagermaid.config import Config
|
|
|
|
|
from pagermaid.web.html import get_logo
|
|
|
|
|
|
|
|
|
|
logo = Html(html=get_logo())
|
|
|
|
|
select_log_num = Select(
|
2023-03-12 03:56:01 +00:00
|
|
|
|
label="日志数量",
|
|
|
|
|
name="log_num",
|
2023-01-31 16:24:56 +00:00
|
|
|
|
value=100,
|
|
|
|
|
options=[
|
2023-03-12 03:56:01 +00:00
|
|
|
|
{"label": 100, "value": 100},
|
|
|
|
|
{"label": 200, "value": 200},
|
|
|
|
|
{"label": 300, "value": 300},
|
|
|
|
|
{"label": 400, "value": 400},
|
|
|
|
|
{"label": 500, "value": 500},
|
|
|
|
|
],
|
2023-01-31 16:24:56 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
log_page = Log(
|
|
|
|
|
autoScroll=True,
|
2023-03-12 03:56:01 +00:00
|
|
|
|
placeholder="暂无日志数据...",
|
|
|
|
|
operation=["stop", "showLineNumber", "filter"],
|
2023-01-31 16:24:56 +00:00
|
|
|
|
source={
|
2023-03-12 03:56:01 +00:00
|
|
|
|
"method": "get",
|
|
|
|
|
"url": "/pagermaid/api/log?num=${log_num | raw}",
|
|
|
|
|
"headers": {"token": Config.WEB_SECRET_KEY},
|
|
|
|
|
},
|
2023-01-31 16:24:56 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
cmd_input = Form(
|
|
|
|
|
mode=DisplayModeEnum.horizontal,
|
|
|
|
|
horizontal=Horizontal(left=0),
|
|
|
|
|
wrapWithPanel=False,
|
|
|
|
|
body=[
|
2023-03-12 03:56:01 +00:00
|
|
|
|
InputText(
|
|
|
|
|
name="command",
|
|
|
|
|
required=True,
|
|
|
|
|
clearable=True,
|
|
|
|
|
addOn=ActionType.Dialog(
|
|
|
|
|
label="执行",
|
|
|
|
|
level=LevelEnum.primary,
|
|
|
|
|
dialog=Dialog(
|
|
|
|
|
title="命令执行结果",
|
|
|
|
|
size="xl",
|
|
|
|
|
body=Log(
|
|
|
|
|
autoScroll=True,
|
|
|
|
|
placeholder="执行命令中,请稍候...",
|
|
|
|
|
operation=["stop", "showLineNumber", "filter"],
|
|
|
|
|
source={
|
|
|
|
|
"method": "get",
|
|
|
|
|
"url": "/pagermaid/api/run_sh?cmd=${command | raw}",
|
|
|
|
|
"headers": {"token": Config.WEB_SECRET_KEY},
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
],
|
2023-01-31 16:24:56 +00:00
|
|
|
|
)
|
|
|
|
|
eval_input = Form(
|
|
|
|
|
mode=DisplayModeEnum.horizontal,
|
|
|
|
|
horizontal=Horizontal(left=0),
|
|
|
|
|
wrapWithPanel=False,
|
|
|
|
|
body=[
|
2023-03-12 03:56:01 +00:00
|
|
|
|
InputText(
|
|
|
|
|
name="command",
|
|
|
|
|
required=True,
|
|
|
|
|
clearable=True,
|
|
|
|
|
addOn=ActionType.Dialog(
|
|
|
|
|
label="执行",
|
|
|
|
|
level=LevelEnum.primary,
|
|
|
|
|
dialog=Dialog(
|
|
|
|
|
title="命令执行结果",
|
|
|
|
|
size="xl",
|
|
|
|
|
body=Log(
|
|
|
|
|
autoScroll=True,
|
|
|
|
|
placeholder="执行命令中,请稍候...",
|
|
|
|
|
operation=["stop", "showLineNumber", "filter"],
|
|
|
|
|
source={
|
|
|
|
|
"method": "get",
|
|
|
|
|
"url": "/pagermaid/api/run_eval?cmd=${command | raw}",
|
|
|
|
|
"headers": {"token": Config.WEB_SECRET_KEY},
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
operation_button = Flex(
|
|
|
|
|
justify="center",
|
|
|
|
|
items=[
|
|
|
|
|
ActionType.Ajax(
|
|
|
|
|
label="更新",
|
|
|
|
|
api="/pagermaid/api/bot_update",
|
|
|
|
|
confirmText="该操作会更新 PagerMaid-Pyro ,请在更新完成后手动重启,请确认执行该操作",
|
|
|
|
|
level=LevelEnum.info,
|
|
|
|
|
),
|
|
|
|
|
ActionType.Ajax(
|
|
|
|
|
label="重启",
|
|
|
|
|
className="m-l",
|
|
|
|
|
api="/pagermaid/api/bot_restart",
|
|
|
|
|
confirmText="该操作会重启 PagerMaid-Pyro ,请耐心等待重启",
|
|
|
|
|
level=LevelEnum.danger,
|
|
|
|
|
),
|
|
|
|
|
ActionType.Dialog(
|
|
|
|
|
label="日志",
|
|
|
|
|
className="m-l",
|
2023-01-31 16:24:56 +00:00
|
|
|
|
level=LevelEnum.primary,
|
|
|
|
|
dialog=Dialog(
|
2023-03-12 03:56:01 +00:00
|
|
|
|
title="查看日志",
|
|
|
|
|
size="xl",
|
|
|
|
|
actions=[],
|
|
|
|
|
body=[
|
|
|
|
|
Alert(
|
|
|
|
|
level=LevelEnum.info,
|
|
|
|
|
body='查看最近最多500条日志,不会自动刷新,需要手动点击两次"暂停键"来进行刷新。',
|
|
|
|
|
),
|
|
|
|
|
Form(body=[Group(body=[select_log_num]), log_page]),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
ActionType.Dialog(
|
|
|
|
|
label="shell",
|
|
|
|
|
className="m-l",
|
|
|
|
|
level=LevelEnum.warning,
|
|
|
|
|
dialog=Dialog(title="shell", size="lg", actions=[], body=[cmd_input]),
|
|
|
|
|
),
|
|
|
|
|
ActionType.Dialog(
|
|
|
|
|
label="eval",
|
|
|
|
|
className="m-l",
|
|
|
|
|
level=LevelEnum.warning,
|
|
|
|
|
dialog=Dialog(title="eval", size="lg", actions=[], body=[eval_input]),
|
|
|
|
|
),
|
|
|
|
|
],
|
2023-01-31 16:24:56 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
status = Service(
|
2023-03-12 03:56:01 +00:00
|
|
|
|
api="/pagermaid/api/status",
|
2023-01-31 16:24:56 +00:00
|
|
|
|
body=Property(
|
2023-03-12 03:56:01 +00:00
|
|
|
|
title="运行信息",
|
2023-01-31 16:24:56 +00:00
|
|
|
|
column=2,
|
|
|
|
|
items=[
|
2023-03-12 03:56:01 +00:00
|
|
|
|
Property.Item(label="Bot 版本", content="${version}"),
|
|
|
|
|
Property.Item(label="Bot 运行时间", content="${run_time}"),
|
|
|
|
|
Property.Item(label="CPU占用率", content="${cpu_percent}"),
|
|
|
|
|
Property.Item(label="RAM占用率", content="${ram_percent}"),
|
|
|
|
|
Property.Item(label="SWAP占用率", content="${swap_percent}", span=2),
|
|
|
|
|
],
|
|
|
|
|
),
|
2023-01-31 16:24:56 +00:00
|
|
|
|
)
|
|
|
|
|
|
2023-03-12 03:56:01 +00:00
|
|
|
|
page_detail = Page(title="", body=[logo, operation_button, Divider(), status])
|
|
|
|
|
page = PageSchema(
|
|
|
|
|
url="/home", label="首页", icon="fa fa-home", isDefaultPage=True, schema=page_detail
|
|
|
|
|
)
|