From a5d995284807c86596b4e8eab318295c7027b6af Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Mon, 13 Jul 2026 10:04:07 +0700 Subject: [PATCH] Add files from /homeassistant/scripts/ --- scripts/camera_log.txt | 1 + scripts/get_camera.py* | 97 +++++++++++++++++++++++++++++++ scripts/goodline_token.txt | 1 + scripts/update_goodline_token.py* | 44 ++++++++++++++ 4 files changed, 143 insertions(+) create mode 100644 scripts/camera_log.txt create mode 100644 scripts/get_camera.py* create mode 100644 scripts/goodline_token.txt create mode 100644 scripts/update_goodline_token.py* diff --git a/scripts/camera_log.txt b/scripts/camera_log.txt new file mode 100644 index 0000000..26fcce1 --- /dev/null +++ b/scripts/camera_log.txt @@ -0,0 +1 @@ +УСПЕХ! Ссылка: rtsp://vcore-jkh08.video.goodline.info:5... diff --git a/scripts/get_camera.py* b/scripts/get_camera.py* new file mode 100644 index 0000000..e17d166 --- /dev/null +++ b/scripts/get_camera.py* @@ -0,0 +1,97 @@ +import urllib.request +import urllib.error +import json +import traceback +import os + +def get_token_from_file(): + # Теперь читаем токен из обычного текстовика, а не из secrets + token_path = '/config/scripts/goodline_token.txt' + if os.path.exists(token_path): + with open(token_path, 'r') as f: + return f.read().strip() + return None + +def request_new_sms(log_file): + # Данные твоего бота (замени BOT_TOKEN на свой) + bot_token = "8329968936:AAFWZz2RTNKWvnhhKXpEXOC55qoj5Cg4_Kk" + chat_id = "-1002006010424" # Твой ID группы из прошлой автоматизации + + url_sms = 'https://api-video.goodline.info/ords/mobile/vc2/auth/phone' + payload = { + "id_device": "5116c3f1822f08", + "id_platform": 3, + "phone": "79134374202" + } + + data = json.dumps(payload).encode('utf-8') + headers = {'Content-Type': 'application/json'} + + try: + # 1. Запрос СМС у провайдера + req = urllib.request.Request(url_sms, data=data, headers=headers, method='POST') + urllib.request.urlopen(req, timeout=10) + + # 2. Уведомление в Телеграм о попытке + tg_msg = "🔄 Внимание: Токен камеры протух. Запросил новое СМС с кодом..." + tg_url = f"https://api.telegram.org/bot{bot_token}/sendMessage" + tg_payload = json.dumps({ + "chat_id": chat_id, + "text": tg_msg, + "parse_mode": "HTML" + }).encode('utf-8') + + tg_req = urllib.request.Request(tg_url, data=tg_payload, headers=headers, method='POST') + urllib.request.urlopen(tg_req, timeout=5) + + with open(log_file, 'a') as f: + f.write("СЕРВЕР: Запрошена новая СМС с кодом и отправлено уведомление в TG!\n") + + except Exception as e: + with open(log_file, 'a') as f: + f.write(f"ОШИБКА в request_new_sms: {e}\n") + +def get_url(): + log_file = '/config/scripts/camera_log.txt' + master_token = get_token_from_file() + + if not master_token: + with open(log_file, 'w') as f: + f.write("ОШИБКА: Файл goodline_token.txt пуст или не существует!\n") + request_new_sms(log_file) # Просим СМС, если токена вообще нет + return + + url = 'https://api-video.goodline.info/ords/mobile/vc2/v2/cameras/23079' + headers = { + 'token': master_token, + 'origin': 'https://video.online-dozor.ru', + 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)' + } + + try: + req = urllib.request.Request(url, headers=headers) + with urllib.request.urlopen(req, timeout=15) as response: + data = json.loads(response.read().decode()) + + rtsp = data.get('STREAM_LIVE_RTSP_HD') + sig = data.get('SIGNATURE', '').replace('wmsAuthSign=', '') + + if rtsp and sig: + final_link = f"{rtsp}?wmsAuthSign={sig}" + print(final_link, end='') + with open(log_file, 'w') as f: + f.write(f"УСПЕХ! Ссылка: {final_link[:40]}...\n") + + except urllib.error.HTTPError as e: + error_body = e.read().decode() + with open(log_file, 'w') as f: + f.write(f"ОШИБКА 401: Токен устарел!\n") + # ТОКЕН ПРОТУХ - ЗАПРАШИВАЕМ СМС! + request_new_sms(log_file) + + except Exception as e: + with open(log_file, 'w') as f: + f.write(f"КРИТИЧЕСКАЯ ОШИБКА:\n{traceback.format_exc()}\n") + +if __name__ == "__main__": + get_url() diff --git a/scripts/goodline_token.txt b/scripts/goodline_token.txt new file mode 100644 index 0000000..792cdab --- /dev/null +++ b/scripts/goodline_token.txt @@ -0,0 +1 @@ +566AFC0A-AE12-4F15-E063-2965660ADC25 \ No newline at end of file diff --git a/scripts/update_goodline_token.py* b/scripts/update_goodline_token.py* new file mode 100644 index 0000000..3db7c0d --- /dev/null +++ b/scripts/update_goodline_token.py* @@ -0,0 +1,44 @@ +import urllib.request +import json +import sys + +def verify_code(sms_code): + url = 'https://api-video.goodline.info/ords/mobile/vc2/auth/token/sms' + + # Данные из твоего скриншота + payload = { + "phone": "79134374202", + "code": str(sms_code) + } + + data = json.dumps(payload).encode('utf-8') + headers = { + 'Content-Type': 'application/json', + 'origin': 'https://video.online-dozor.ru', + 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)' + } + + req = urllib.request.Request(url, data=data, headers=headers, method='POST') + + try: + with urllib.request.urlopen(req, timeout=10) as response: + resp_json = json.loads(response.read().decode('utf-8')) + new_token = resp_json.get('TOKEN') + + if new_token: + # Записываем свежий токен в текстовый файл + with open('/config/scripts/goodline_token.txt', 'w') as f: + f.write(new_token) + print(f"Успех! Новый токен сохранен: {new_token[:10]}...") + else: + print("Ошибка: Токен не найден в ответе сервера!") + + except Exception as e: + print(f"Ошибка при отправке кода: {e}") + +if __name__ == "__main__": + # Скрипт принимает код из аргумента командной строки + if len(sys.argv) > 1: + verify_code(sys.argv[1]) + else: + print("Ошибка: Не передан СМС код!")