# -*- coding: utf-8 -*- """type-com-toolkit dashboard — stdlib only (Python 3.9+). Run: python dashboard.py -> http://127.0.0.1:8610 Form: 2captcha key + 2nd-no fallback creds + temp-mail domain -> saved to creds.json (LOCAL ONLY). Tasks: register N accounts / start gateway / radar revive -> subprocess + live log. Results: download type_accounts.jsonl / pool.json / logs. [🩸 иишко](https://t.me/AlStack) """ import glob import html import json import os import subprocess import sys import threading import time import urllib.parse from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer HERE = os.path.dirname(os.path.abspath(__file__)) ROOT = os.path.dirname(HERE) if os.path.basename(HERE) == 'tools' else HERE TOOLS = os.path.join(ROOT, 'tools') if os.path.isdir(os.path.join(ROOT, 'tools')) else HERE CREDS = 'creds.json' CREDS_PATH = os.path.join(ROOT, CREDS) TASKS_DIR = os.path.join(ROOT, 'tasks') os.makedirs(TASKS_DIR, exist_ok=True) PORT = int(os.environ.get('DASH_PORT', '8610')) PY = os.environ.get('PY311', sys.executable) CHANNEL = 'https://t.me/AlStack' PAGE = """ type-com-toolkit

⚡ type-com-toolkit

Авторег + шлюз + radar-revive для type.com — 25 моделей (Claude / GPT / Gemini). Ключи и креды хранятся ТОЛЬКО локально в creds.json.

1. Kredy

2. Задачи

требуется pool.json с живыми токенами

3. Статус

загрузка...

4. Лог задачи

Задачи:
—

5. Результаты

загрузка...
""" TASK_SCRIPTS = { 'reg': ('type_reg.py', lambda a, c: [a[0] if a else '1', c.get('void_domain') or 'voidash']), 'gw': ('typegw.py', lambda a, c: ['8600']), 'radar': ('radar_revive.py', lambda a, c: [a[0]] if a else []), 'login': ('login_token.py', lambda a, c: [a[0]] if a else []), } def load_creds(): try: return json.load(open(CREDS_PATH, encoding='utf-8')) except Exception: return {} def env_with_creds(c): env = dict(os.environ) env['PYTHONPATH'] = '' env['PYTHONIOENCODING'] = 'utf-8' if c.get('captcha_key'): keys_file = os.path.join(ROOT, 'captcha_keys.json') if not os.path.exists(keys_file): json.dump({'keys': [{'label': 'dash', 'key': c['captcha_key']}]}, open(keys_file, 'w')) env['CAPTCHA_KEYS_FILE'] = keys_file if c.get('no2_email'): env['NO2_EMAIL'] = c['no2_email'] env['NO2_PASS'] = c.get('no2_pass', '') if c.get('void_domain'): env['VOID_DOMAIN'] = c['void_domain'] if c.get('gws_email'): gws = os.path.join(ROOT, 'gws_user.json') json.dump({'email': c['gws_email'], 'password': c.get('gws_pass', '')}, open(gws, 'w')) env['GWS_USER_FILE'] = gws env['TYPE_TOOLKIT_ROOT'] = ROOT return env class Handler(BaseHTTPRequestHandler): def log_message(self, format, *args): pass def _send(self, code, body, ctype='text/html; charset=utf-8'): b = body.encode('utf-8') if isinstance(body, str) else body self.send_response(code) self.send_header('Content-Type', ctype) self.send_header('Content-Length', str(len(b))) self.end_headers() self.wfile.write(b) def _json(self, obj, code=200): self._send(code, json.dumps(obj, ensure_ascii=False), 'application/json; charset=utf-8') def _body(self): n = int(self.headers.get('Content-Length') or 0) return self.rfile.read(n).decode('utf-8', 'replace') if n else '' def do_GET(self): u = urllib.parse.urlparse(self.path) q = urllib.parse.parse_qs(u.query) if u.path == '/': self._send(200, PAGE.replace('__CH__', CHANNEL)) elif u.path == '/api/health': self._json({'ok': True, 'root': ROOT, 'python': sys.version.split()[0]}) elif u.path == '/api/stack': self._json({'html': self._stack_html()}) elif u.path == '/api/tasks': ts = sorted(os.listdir(TASKS_DIR), reverse=True) out = [] for f in ts: if f.endswith('.log'): tid = f[:-4] kind = tid.split('_', 1)[1] if '_' in tid else '?' out.append({'id': tid, 'kind': kind}) self._json({'tasks': out[:50]}) elif u.path == '/api/log': tid = (q.get('id') or [''])[0] p = os.path.join(TASKS_DIR, os.path.basename(tid) + '.log') try: self._json({'log': open(p, encoding='utf-8', errors='replace').read()[-40000:]}) except Exception: self._json({'log': ''}) elif u.path == '/api/files': pats = ['type_accounts.jsonl', 'pool.json', 'used_numbers.json', '_reuse_candidates.json'] files = [p for p in pats if os.path.exists(os.path.join(ROOT, p))] files += [os.path.basename(f) for f in glob.glob(os.path.join(TASKS_DIR, '*.log'))][-10:] self._json({'files': files}) elif u.path.startswith('/dl/'): name = os.path.basename(u.path[4:]) if name == CREDS or name in ('captcha_keys.json', 'gws_user.json', 'no2_fallback.json'): self._json({'error': 'forbidden'}, 404) return for d in (ROOT, TASKS_DIR): p = os.path.join(d, name) if os.path.isfile(p): self._send(200, open(p, 'rb').read(), 'application/octet-stream') return self._json({'error': 'not found'}, 404) else: self._json({'error': 'not found'}, 404) def do_POST(self): u = urllib.parse.urlparse(self.path) if u.path == '/api/creds': try: d = json.loads(self._body() or '{}') old = load_creds() for k, v in d.items(): if v: old[k] = v json.dump(old, open(CREDS_PATH, 'w', encoding='utf-8'), indent=1) self._json({'ok': True}) except Exception as e: self._json({'ok': False, 'error': str(e)[:200]}) elif u.path == '/api/run': try: d = json.loads(self._body() or '{}') kind = d.get('kind', '') if kind not in TASK_SCRIPTS: self._json({'ok': False, 'error': 'unknown kind'}) return script, argf = TASK_SCRIPTS[kind] c = load_creds() args = argf(d.get('args') or [], c) sp = os.path.join(TOOLS, script) if not os.path.exists(sp): self._json({'ok': False, 'error': 'script missing: ' + script}) return tid = time.strftime('%H%M%S') + '_' + kind lf = open(os.path.join(TASKS_DIR, tid + '.log'), 'w', encoding='utf-8') subprocess.Popen([PY, sp] + [str(x) for x in args], stdout=lf, stderr=subprocess.STDOUT, cwd=ROOT, env=env_with_creds(c)) self._json({'ok': True, 'id': tid}) except Exception as e: self._json({'ok': False, 'error': str(e)[:300]}) else: self._json({'error': 'not found'}, 404) def _stack_html(self): c = load_creds() rows = [] rows.append(('creds.json', 'есть' if c else 'не заполнены')) rows.append(('2captcha key', '✓' if c.get('captcha_key') else '—')) rows.append(('2nd-no fallback', '✓' if c.get('no2_email') else '—')) acc = os.path.join(ROOT, 'type_accounts.jsonl') n = 0 if os.path.exists(acc): n = sum(1 for _ in open(acc, encoding='utf-8', errors='replace')) rows.append(('аккаунтов в банке', '%d' % n)) pool = os.path.join(ROOT, 'pool.json') npool = 0 if os.path.exists(pool): try: npool = len(json.load(open(pool, encoding='utf-8'))) except Exception: pass rows.append(('токенов в пуле шлюза', '%d' % npool)) un = os.path.join(ROOT, 'used_numbers.json') nu = 0 if os.path.exists(un): try: d = json.load(open(un, encoding='utf-8')) nu = len(d) except Exception: pass rows.append(('использованных номеров', str(nu))) return '' + ''.join('' % (html.escape(k), v) for k, v in rows) + '
%s%s
' def main(): port = PORT srv = None for port in range(PORT, PORT + 20): try: srv = ThreadingHTTPServer(('127.0.0.1', port), Handler) break except OSError: continue if srv is None: print('no free port in range', PORT, PORT + 20, flush=True) sys.exit(1) print('dashboard on http://127.0.0.1:%d' % port, flush=True) srv.serve_forever() if __name__ == '__main__': main()