IISHKO: Telegram bot, Mini App and gateway
checks / pytest (push) Has been cancelled
checks / moderation (push) Has been cancelled
checks / node (push) Has been cancelled

Initial public release.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-30 21:51:30 +03:00
co-authored by Claude Opus 5.5
commit 0ee6fb843b
179 changed files with 59173 additions and 0 deletions
+58
View File
@@ -0,0 +1,58 @@
# Деплой (примеры)
Это **примеры**, а не готовый боевой деплой. Пути (`/opt/...`), домены (`your-domain.com`)
и порты замените на свои. Все приватные порты по умолчанию — loopback (`127.0.0.1`);
наружу выставляйте только через reverse proxy с TLS.
## Состав
| Файл | Назначение |
|---|---|
| `systemd/grok-bot.service` | Telegram-бот (long polling), `bot/grok_bot.py` |
| `systemd/iishko-webapp.service` | Mini App backend, `bot/webapp/server.py`, `127.0.0.1:8850` |
| `systemd/grok-web-skin.service` | скин шлюза, `gateway/grok-web-skin.py`, `127.0.0.1:48001` |
| `systemd/grok-healthcheck.*`, `grok-alert-watch.*` | периодические проверки живости/алертов |
| `systemd/grok-media-tts.service`, `iishko-fw.service` | вспомогательные сервисы, optional |
| `caddy/Caddyfile.example` | маршрутизация `/webapp/*`, `/v1/*`, статика сайта |
Единицы сняты с боевого сервера и оставлены как пример структуры: перед использованием
поправьте `WorkingDirectory`, `ExecStart`, `Environment=` и пути к БД.
## Порядок
1. Внешний шлюз (New API / one-api) поднимается **отдельно** — в репозиторий не входит.
Заведите каналы, получите мастер-ключ.
2. Заполните `.env` (см. `.env.example`) и `bot/config.json` (из `bot/config.example.json`).
3. `python scripts/selfcheck.py` — офлайн-проверка перед стартом.
4. Запустите бота, Mini App и скин; наружу — через Caddy.
## Переменные окружения
PowerShell:
```powershell
$env:PYTHONPATH = "bot;gateway"
$env:GROK_BOT_CFG = "C:\iishko\bot\config.json"
$env:IISHKO_ADMIN_IDS = "123456789"
python bot\grok_bot.py
```
POSIX:
```bash
export PYTHONPATH=bot:gateway
export GROK_BOT_CFG=$PWD/bot/config.json
export IISHKO_ADMIN_IDS=123456789
python bot/grok_bot.py
```
## Выключено по умолчанию
Автобан Mini App (`IISHKO_ENTRY_AUTOBAN=0`), уведомления (`IISHKO_NOTIFICATIONS_ENABLED=0`),
песочница (`IISHKO_SANDBOX_ENABLED=0`), гео-база (файла нет), платежи (токены пустые).
Включайте осознанно: автобан трогает балансы и ключи реальных аккаунтов.
## Чего здесь нет
Баз данных, ключей, логов и юнитов посторонних сервисов.
Датасет DB-IP (~121 MB) скачивается отдельно: `bot/geo/provenance.json`.
+92
View File
@@ -0,0 +1,92 @@
{
acme_ca https://acme-v02.api.letsencrypt.org/directory
# Bound the buffers: on 2026-09-30 caddy reached 5.9 GB anon-rss and the kernel
# OOM-killed it three times, which took the whole site and API down with it.
servers {
trusted_proxies static 127.0.0.1/32 # TODO: your edge/CDN proxy CIDR
trusted_proxies_strict
timeouts {
read_body 60s
read_header 30s
write 1h
idle 5m
}
}
}
(api_common) {
# There were NO access logs at all, so the 429 storm of 2026-10-03 could not be
# attributed to a client until the relay log was grepped by hand.
log {
output file /var/log/caddy/access.log {
roll_size 30MiB
roll_keep 10
roll_keep_for 720h
}
format json
}
header {
Strict-Transport-Security "max-age=15552000; includeSubDomains"
X-Content-Type-Options "nosniff"
Referrer-Policy "strict-origin-when-cross-origin"
-Server
}
request_body {
max_size 40MB
}
}
api.your-domain.com {
import api_common
handle /v1/media/* {
reverse_proxy 127.0.0.1:8000 {
# media responses are large; stream instead of buffering whole bodies
flush_interval -1
transport http {
read_timeout 300s
dial_timeout 10s
}
}
}
# [WEBAPP-WIRE 19.10] Mini App: /webapp -> 127.0.0.1:8850
handle /webapp {
redir /webapp/ 301
}
handle_path /webapp/* {
reverse_proxy 127.0.0.1:8850 {
header_up X-Real-IP {client_ip}
flush_interval -1
transport http {
read_timeout 60s
dial_timeout 5s
}
}
}
handle {
reverse_proxy 127.0.0.1:48001 {
header_up X-Forwarded-For {client_ip}
# generations and SSE streams outlive the defaults; "context canceled" /
# "http2: stream closed" in the error log were proxies giving up early
flush_interval -1
transport http {
read_timeout 900s
dial_timeout 10s
keepalive 30s
}
}
}
}
your-domain.com {
import api_common
reverse_proxy 127.0.0.1:48001 {
header_up X-Forwarded-For {client_ip}
flush_interval -1
transport http {
read_timeout 900s
dial_timeout 10s
}
}
}
import zai_shim.caddy
+7
View File
@@ -0,0 +1,7 @@
[Unit]
Description=Push stack ALERTs to the owner (Telegram)
After=network-online.target
[Service]
Type=oneshot
Nice=10
ExecStart=/opt/venv/bin/python /opt/grok-gateway/grok-alert-watch.py
+8
View File
@@ -0,0 +1,8 @@
[Unit]
Description=Grok stack alert watch, every 3 min
[Timer]
OnBootSec=3min
OnUnitActiveSec=180
Persistent=true
[Install]
WantedBy=timers.target
+13
View File
@@ -0,0 +1,13 @@
[Unit]
Description=Grok Telegram Bot
After=network-online.target new-api.service
Wants=network-online.target
[Service]
WorkingDirectory=/opt/grok-bot
ExecStart=/opt/venv/bin/python /opt/grok-bot/iishko_bot.py
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
+6
View File
@@ -0,0 +1,6 @@
[Unit]
Description=Grok stack healthcheck (new-api, g2a) — oneshot, запускается таймером
[Service]
Type=oneshot
ExecStart=/usr/bin/python3 /opt/grok-gateway/grok-healthcheck.py
+10
View File
@@ -0,0 +1,10 @@
[Unit]
Description=Grok stack healthcheck — каждые 60с
[Timer]
OnBootSec=60
OnUnitActiveSec=60
Persistent=true
[Install]
WantedBy=timers.target
+10
View File
@@ -0,0 +1,10 @@
[Unit]
Description=TTS adapter for grok gateway
After=network.target
[Service]
WorkingDirectory=/opt/grok-bot
ExecStart=/opt/venv/bin/python /opt/grok-bot/media_tts.py
Restart=always
RestartSec=3
[Install]
WantedBy=multi-user.target
+12
View File
@@ -0,0 +1,12 @@
[Unit]
Description=your-handle web skin (dark multiai theme)
After=network-online.target new-api.service
[Service]
TimeoutStopSec=30
ExecStart=/opt/venv/bin/python /opt/grok-web-skin.py
Restart=always
RestartSec=3
[Install]
WantedBy=multi-user.target
+13
View File
@@ -0,0 +1,13 @@
[Unit]
Description=iishko internal-ports firewall
After=network-pre.target
Before=network.target
Wants=network-pre.target
[Service]
Type=oneshot
ExecStart=/usr/local/sbin/iishko-fw.sh
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
+25
View File
@@ -0,0 +1,25 @@
[Unit]
Description=IISHKO moderation policy (loopback only, no Telegram poller)
After=network.target
[Service]
Type=simple
User=root
WorkingDirectory=/opt/grok-bot
EnvironmentFile=/etc/iishko/moderation.env
ExecStart=/opt/grok-bot/bin/iishko-moderation -addr 127.0.0.1:48003
Restart=on-failure
RestartSec=3
TimeoutStopSec=15
NoNewPrivileges=true
PrivateTmp=true
ProtectSystem=strict
ProtectHome=true
RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX
CapabilityBoundingSet=
MemoryMax=128M
TasksMax=32
UMask=0077
[Install]
WantedBy=multi-user.target
+12
View File
@@ -0,0 +1,12 @@
[Unit]
Description=iishko webapp (Mini App backend)
After=network.target
[Service]
ExecStart=/opt/venv/bin/python /opt/grok-bot/webapp/server.py
WorkingDirectory=/opt/grok-bot/webapp
Restart=always
RestartSec=3
[Install]
WantedBy=multi-user.target