-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaonit.py
209 lines (173 loc) · 7.97 KB
/
aonit.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
198
199
200
201
202
203
204
205
206
207
208
209
import string,random
import requests
import arrow
import sqlite3
from datetime import datetime,date
import json
import os.path
import win32com.client
import constants
KalkanCOMTest = win32com.client.Dispatch("KalkanCryptCOMLib.KalkanCryptCOM.2")
KalkanCOMTest.Init()
class IntegrationAonit():
def __init__(self):
if os.path.exists('conf.json') == False:
with open('conf.json', 'w+') as f:
data = {"ip_addresses": [
"10.245.12.102",
"10.245.12.67"
],
"mac_addresses": ["000B3D000058","000B3A007F26"],
"gost_pass": "null",
"gost_path": "null",
"selected_ip_address": "10.245.12.67",
"login": "null",
"password": "null",
"aonit_server_ip": "127.0.0.1"}
json.dump(data,f, ensure_ascii=False, indent=4)
with open('conf.json') as f:
self.data = json.load(f)
else:
with open('conf.json') as f:
self.data = json.load(f)
self.login = self.data['login']
self.path = self.data['gost_path']
self.password = self.data['password']
self.con = sqlite3.connect("mydb.db",check_same_thread=False)
self.cursor = self.con.cursor()
self.url=self.data['selected_ip_address']
self.headers = {'content-type': 'application/soap+xml; charset=utf-8'}
self.dateToBody = arrow.get(datetime.now())
def sendRequestToAonit(self,todayday):
try:
response = requests.get(self.url,headers=self.headers)
print(self.login,self.password,self.url)
self.cursor.execute("SELECT * FROM events WHERE created_at = ?;",(todayday,))
events = self.cursor.fetchall()
def iinIterable():
string = ''
for event in events:
string += f"<value>{event[1]}</value>"
return string
def eventCodeIterable():
string = ''
for event in events:
string += f"<value>{event[3]}</value>"
return string
def datetimeIterable():
string = ''
for event in events:
string += f"<value>{event[4]}</value>"
return string
def testItrable():
string = ''
for event in events:
string += f"<value>Не задано</value>"
return string
body = f"""
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="id-0002">
<m:SendMessage xmlns:m="http://bip.bee.kz/SyncChannel/v10/Types">
<request>
<requestInfo>
<messageId>String</messageId>
<serviceId>EKyzmetUniversalService</serviceId>
<messageDate>{self.dateToBody}</messageDate>
<sender>
<senderId>{self.login}</senderId>
<password>{self.password}</password>
</sender>
<properties>
<key></key>
<value></value>
</properties>
</requestInfo>
<requestData>
<data>
<Request serviceName="sendEventFromACSList" xsi:noNamespaceSchemaLocation="EKyzmetUniversalService.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<param>
<key>ИИН</key>
<type>String</type>
<values>
{iinIterable()}
</values>
</param>
<param>
<key>Событие</key>
<type>String</type>
<values>
{eventCodeIterable()}
</values>
</param>
<param>
<key>Время</key>
<type>String</type>
<values>
{datetimeIterable()}
</values>
</param>
<param>
<key>БИН</key>
<type>String</type>
<values>
{testItrable()}
</values>
</param>
<param>
<key>Номер этажа</key>
<type>String</type>
<values>
{testItrable()}
</values>
</param>
<param>
<key>Наименование здания</key>
<type>String</type>
<values>
{testItrable()}
</values>
</param>
</Request>
</data>
</requestData>
</request>
</m:SendMessage>
</soap:Body></soap:Envelope>
"""
inData = body
KalkanCOMTest.LoadKeyStore(constants.KCST_PKCS12,self.data["gost_pass"],self.path, 'test')
err = KalkanCOMTest.GetLastError()
if err > 0:
print(" Error: " + str(hex(int(err))) + "\n" )
signNodeId = "id-0002"
outData = ""
outSign = KalkanCOMTest.SignWSSE("test", 0, inData,signNodeId,outData)
KalkanCOMTest.XMLFinalize()
with open('xml-format.xml', 'w') as xml:
xml.write(outSign)
strErr, err = KalkanCOMTest.GetLastErrorString()
if err > 0:
print(" Error: " + str(hex(int(err))) + "\n" + strErr.replace("\n","\r\n"))
outSign = outSign.encode('utf-8')
response = requests.post(self.url,data=outSign, headers=self.headers)
responseTurple = (0, "0", "12.08.2002")
if response.status_code == 200:
responseTurple = (response.status_code, response.text,todayday)
self.cursor.execute("INSERT INTO responses VALUES (NULL,?,?,?)", responseTurple)
self.con.commit()
print(f'Сообщение успешно отправлено КОД:{response.status_code}')
print(response.text)
else:
responseTurple = (response.status_code, response.text, todayday)
self.cursor.execute("INSERT INTO responses VALUES (NULL,?,?,?)", responseTurple)
self.con.commit()
print(response.text)
print(f'Есть ошибка КОД:{response.status_code}')
return {
"code": 200,
"url": self.url
}
except requests.exceptions.ConnectionError:
return {
"code": 500,
"url": self.url
}