47eee0291f
revert Clean main branch
98 lines
3.7 KiB
Plaintext
98 lines
3.7 KiB
Plaintext
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 = "🔄 <b>Внимание:</b> Токен камеры протух. Запросил новое СМС с кодом..."
|
|
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()
|