-
Notifications
You must be signed in to change notification settings - Fork 13
/
dockerbot.py
197 lines (179 loc) · 10.5 KB
/
dockerbot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
from loguru import logger
import time, re, random, datetime, telepot, os, sys
from subprocess import call
import subprocess, yaml, shutil
from os import path
from telepot.loop import MessageLoop
from dotenv import load_dotenv
configfile="/opt/dockerbot/config/config.yml"
original_configfile = r'/etc/config.yml'
def copyConfig():
if not os.path.exists(configfile):
shutil.copyfile(original_configfile, configfile)
copyConfig()
# Load Configuration
with open("/opt/dockerbot/config/config.yml", 'r') as stream:
try:
list = yaml.safe_load(stream)
except yaml.YAMLError as exc:
print(exc)
# Vars For https://web.mashov.info
v_MASHOV_NUMBER_OF_KIDS = len(list['mashov'])
if v_MASHOV_NUMBER_OF_KIDS >= 1 and list['mashov']['kid1']['MASHOV_USER_ID_KID'] != None:
v_MASHOV_NUMBER_OF_KIDS = v_MASHOV_NUMBER_OF_KIDS + 1
def handle(msg):
config_edu = 1
config_mashov = 1
message_id = str(msg['message_id'])
chat_id = msg['chat']['id']
_command = command = str(msg['text'])
logger.info("{message_id} Got msg: {command}")
# Reject unauthorized requests
if str(chat_id) not in os.getenv('ALLOWED_IDS'):
bot.sendPhoto(
chat_id, "https://github.com/t0mer/dockerbot/raw/master/No-Trespassing.gif")
logger.error(f"[{message_id}] Chat id not allowed: {chat_id}")
return
#need to fix: so only active parts will show and not all options
if command == '/?' or command == '/start':
bot.sendMessage(chat_id, "List of available commands: ")
if list['edu']['USER_ID'] and list['edu']['USER_KEY'] != None:
bot.sendMessage(
chat_id, "/sign_edu or /sign- This command start the sign process at https://parents.education.gov.il ")
if v_MASHOV_NUMBER_OF_KIDS >= 1 and list['mashov']['kid1']['MASHOV_USER_ID_KID'] != None:
bot.sendMessage(
chat_id, "/sign_mashov - This command start the sign process at https://web.mashov.info/students/login ")
if list['infogan']['BASE_URL'] and list['infogan']['KID_ID'] and list['infogan']['PARENT_NAME'] and list['infogan']['KID_NAME'] and list['infogan']['PARENT_ID'] != None:
bot.sendMessage(
chat_id, "/sign_infogan - This command start the sign process at https://www.infogan.co.il/ ")
if list['webtop']['USER_ID'] and list['webtop']['USER_KEY'] != None:
bot.sendMessage(
chat_id, "/sign_webtop - This command start the sign process at https://www.webtop.co.il/v2/? ")
if list['amdocs']['EMAIL'] and list['amdocs']['USER_ID'] and list['amdocs']['PASSWORD'] != None:
bot.sendMessage(
chat_id, "/sign_amdocs - This command start the sign process at Amdocs ")
if command == '/sign_edu' or command == '/sign':
if list['edu']['USER_ID'] and list['edu']['USER_KEY'] != None:
Image = '/opt/dockerbot/images/edu_approval.png'
try:
bot.sendMessage(
chat_id, "Starting Sign process at https://parents.education.gov.il")
import Health_Statements
if Health_Statements.sign(str(list['edu']['USER_ID']), list['edu']['USER_KEY'], Image) == 1:
time.sleep(1)
bot.sendPhoto(chat_id=chat_id,
photo=open(str(Image), 'rb'))
bot.sendMessage(chat_id, "Signed")
logger.info(
f"[{message_id}] Return result to command {command}. Result image path: {Image}")
else:
bot.sendMessage(
chat_id, "Well, Somthing went wrong, please check the logs for more info")
except Exception as ex:
logger.exception(
f"[{message_id}] Failed to handle command. Msg: {command}")
bot.sendMessage(chat_id, f"ERROR: {str(ex)}")
else:
bot.sendMessage(chat_id, "edu NOT configured")
if command == '/sign_infogan':
if list['infogan']['BASE_URL'] and list['infogan']['KID_ID'] and list['infogan']['PARENT_NAME'] and list['infogan']['KID_NAME'] and list['infogan']['PARENT_ID'] != None:
Image = '/opt/dockerbot/images/infogan_approval.png'
try:
bot.sendMessage(
chat_id, "Starting Sign process at https://https://campaign.infogan.co.il/")
import Infogan_Health_Statements
if Infogan_Health_Statements.sign(list['infogan']['PARENT_NAME'], str(list['infogan']['PARENT_ID']), list['infogan']['KID_NAME'], str(list['infogan']['KID_ID']), list['infogan']['BASE_URL'], Image) == 1:
bot.sendPhoto(chat_id=chat_id, photo=open(str(Image), 'rb'))
time.sleep(1)
os.remove(str(Image))
logger.info(f"[{message_id}] Return result to command {command}. Result image path: {Image}")
bot.sendMessage(chat_id, "Signed")
else:
bot.sendMessage(chat_id, "Well, Somthing went wrong, please check the logs for more info")
except Exception as ex:
logger.exception(
f"[{message_id}] Failed to handle command. Msg: {command}")
bot.sendMessage(chat_id, f"ERROR: {str(ex)}")
else:
bot.sendMessage(chat_id, "infogan NOT configured")
if command == '/sign_webtop':
if list['webtop']['USER_ID'] and list['webtop']['USER_KEY'] != None:
try:
Image = '/opt/dockerbot/images/webtop_approval.png'
bot.sendMessage(
chat_id, "Starting Sign process at https://www.webtop.co.il/mobilev2/?")
import Webtop_Health_Statements
if Webtop_Health_Statements.sign(list['webtop']['USER_ID'], list['webtop']['USER_KEY'], Image) == 1:
time.sleep(2)
bot.sendPhoto(chat_id=chat_id, photo=open(str(Image), 'rb'))
logger.info(f"[{message_id}] Return result to command {command}. Result image path: {Image}")
bot.sendMessage(chat_id, "Signed")
else:
bot.sendMessage(chat_id, "Well, Somthing went wrong, please check the logs for more info")
except Exception as ex:
logger.exception(f"[{message_id}] Failed to handle command. Msg: {command}")
bot.sendMessage(chat_id, f"ERROR: {str(ex)}")
else:
bot.sendMessage(chat_id, "webtop NOT configured")
if command == '/sign_mashov':
Image = '/opt/dockerbot/images/mashov_approval_'
if v_MASHOV_NUMBER_OF_KIDS >= 1 and list['mashov']['kid1']['MASHOV_USER_ID_KID'] != None:
try:
import Mashov_Health_Statements
if v_MASHOV_NUMBER_OF_KIDS >= 1 and list['mashov']['kid1']['MASHOV_USER_ID_KID'] != None:
for Mashov_Kid_Number in range(1, v_MASHOV_NUMBER_OF_KIDS, 1):
if list['mashov']['kid'+str(Mashov_Kid_Number)]['MASHOV_USER_ID_KID'] and list['mashov']['kid'+str(Mashov_Kid_Number)]['MASHOV_USER_PWD_KID'] and list['mashov']['kid'+str(Mashov_Kid_Number)]['MASHOV_SCHOOL_ID_KID'] != None:
bot.sendMessage(chat_id,"Starting Sign process at https://web.mashov.info/students/login for Kid Number: " + str(Mashov_Kid_Number))
Prep_Switch_MASHOV_USER_DICT_ID_KID = list['mashov']['kid'+str(Mashov_Kid_Number)]['MASHOV_USER_ID_KID']
Prep_Switch_MASHOV_USER_DICT_ID_PWD = list['mashov']['kid'+str(Mashov_Kid_Number)]['MASHOV_USER_PWD_KID']
Prep_Switch_MASHOV_USER_DICT_ID_SCHOOL_ID = list['mashov']['kid'+str(Mashov_Kid_Number)]['MASHOV_SCHOOL_ID_KID']
Mashov_Health_Statements.sign(Prep_Switch_MASHOV_USER_DICT_ID_KID, Prep_Switch_MASHOV_USER_DICT_ID_PWD, Prep_Switch_MASHOV_USER_DICT_ID_SCHOOL_ID, str(Mashov_Kid_Number), Image + str(Mashov_Kid_Number) + ".png")
else:
bot.sendMessage(chat_id, "mashov NOT configured")
config_mashov = 0
for file in os.listdir("/opt/dockerbot/images"):
if file.endswith(".png") and file.startswith("mashov"):
Image = os.path.join("/opt/dockerbot/images", file)
bot.sendPhoto(chat_id=chat_id, photo=open(str(Image), 'rb'))
os.remove(str(Image))
logger.info(f"[{message_id}] Return result to command {command}. Result image path: {Image}")
if config_mashov != 0:
bot.sendMessage(chat_id, "Signed")
except Exception as ex:
logger.exception(f"[{message_id}] Failed to handle command. Msg: {command}")
bot.sendMessage(chat_id, f"ERROR: {str(ex)}")
else:
bot.sendMessage(chat_id, "mashov NOT configured")
if command == '/sign_amdocs':
if list['amdocs']['EMAIL'] and list['amdocs']['USER_ID'] and list['amdocs']['PASSWORD'] != None:
Image = '/opt/dockerbot/images/amdocs_approval.png'
try:
bot.sendMessage(
chat_id, "Starting Sign process at Amdocs")
import Amdocs_Health_Statements
if Amdocs_Health_Statements.sign(str(list['amdocs']['EMAIL']), str(list['amdocs']['USER_ID']), str(list['amdocs']['PASSWORD']), Image) == 1:
bot.sendPhoto(chat_id=chat_id, photo=open(str(Image), 'rb'))
time.sleep(1)
os.remove(str(Image))
logger.info(f"[{message_id}] Return result to command {command}. Result image path: {Image}")
bot.sendMessage(chat_id, "Signed")
else:
bot.sendMessage(chat_id, "Well, Somthing went wrong, please check the logs for more info")
except Exception as ex:
logger.exception(
f"[{message_id}] Failed to handle command. Msg: {command}")
bot.sendMessage(chat_id, f"ERROR: {str(ex)}")
else:
bot.sendMessage(chat_id, "Amdocs NOT configured")
msg = f"Done message handling: {command}"
logger.info(f"[{message_id}] {msg}")
bot = telepot.Bot(os.getenv('API_KEY'))
MessageLoop(bot, handle).run_as_thread()
logger.info('I am listening...')
while 1:
time.sleep(10)
if os.path.isfile(configfile):
continue
else:
copyConfig()
logger.error("Recoverd Config to /opt/dockerbot/config/")