Files
keenetic_ssh-web/executor.py
Андрей Бобырев 7047270784 keenetic_ssh-web: веб-панель CLI на Entware (порт 2001), расписание, вывод команд
- Flask + Waitress, пароль и ALLOWED_IPS
- install.sh / uninstall.sh, init Entware
- README, FUNDING, полоска автора

Made-with: Cursor
2026-04-25 23:51:22 +03:00

53 lines
1.6 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""Запуск команд из store.json (API и фоновый планировщик)."""
from __future__ import annotations
from typing import Any
from runner import run_shell, touch_item
from store import load_store, save_store
def run_items(
item_ids: list[str] | None,
only_scheduled: bool,
*,
timeout: int,
) -> list[dict[str, Any]]:
"""
item_ids=None — все с enabled (ручной «выполнить всё»).
only_scheduled=True — только enabled+schedule (фон).
"""
data = load_store()
items = list(data.get("items") or [])
id_set = set(item_ids) if item_ids is not None else None
out: list[dict[str, Any]] = []
changed = False
for it in items:
iid = it.get("id")
if not iid:
continue
if id_set is not None and iid not in id_set:
continue
if not it.get("enabled", True):
if id_set is not None:
out.append(
{
"id": iid,
"name": it.get("name"),
"ok": False,
"output": "",
"msg": "Выключено (ВКЛ)",
}
)
continue
if only_scheduled and not it.get("schedule"):
continue
res = run_shell(it.get("command") or "", timeout=timeout)
touch_item(items, iid, res)
changed = True
out.append({"id": iid, "name": it.get("name"), **res})
if changed:
data["items"] = items
save_store(data)
return out