-
Notifications
You must be signed in to change notification settings - Fork 11
/
config.py
451 lines (402 loc) · 16.8 KB
/
config.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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
__author__ = 'Prototype-X'
import configparser
import os
class ConfigException(RuntimeError):
pass
class Config(object):
def __init__(self):
self.config = configparser.ConfigParser()
self.config.optionxform = str
path_cfg = str(os.path.dirname(os.path.abspath(__file__)))
if os.path.exists(path_cfg + '/bl-rkn.cfg'):
try:
self.config.read(path_cfg + '/bl-rkn.cfg')
except configparser.ParsingError:
print('Config bl-rkn.cfg syntax error')
exit()
elif not os.path.exists(path_cfg + '/bl-rkn.cfg'):
self.config.add_section('DataBase')
self.config.set('DataBase', 'Type', '0')
self.config.set('DataBase', 'Name', 'blacklist')
self.config.set('DataBase', 'Host', 'localhost')
self.config.set('DataBase', 'Port', '5432')
self.config.set('DataBase', 'User', 'User')
self.config.set('DataBase', 'Password', 'Password')
self.config.add_section('Log')
self.config.set('Log', 'LogCount', '7')
self.config.set('Log', 'LogRotate', 'midnight')
self.config.set('Log', 'LogInterval', '1')
self.config.set('Log', 'LogPathFName', 'bl-rkn.log')
self.config.add_section('Notify')
self.config.set('Notify', 'Notify', '0')
self.config.set('Notify', 'Auth', '0')
self.config.set('Notify', 'StartTLS', '0')
self.config.set('Notify', 'Server', 'localhost')
self.config.set('Notify', 'Port', '25')
self.config.set('Notify', 'Subject', 'vigruzki.rkn.gov.ru ver. 2.2 update')
self.config.set('Notify', 'From', '[email protected]')
self.config.set('Notify', 'To', '[email protected]')
self.config.add_section('Request')
self.config.set('Request', 'GenerateRequest', '0')
self.config.set('Request', 'OperatorName', 'ООО "телеком"')
self.config.set('Request', 'inn', '1234567890')
self.config.set('Request', 'ogrn', '1234567891234')
self.config.set('Request', 'email', '1@ru')
self.config.set('Request', 'XMLPathFName', 'request.xml')
self.config.set('Request', 'P7SPathFName', 'request.xml.p7s')
self.config.set('Request', 'PEMPathFName', 'cert.pem')
self.config.set('Request', 'ID', '123456789abcdef00000000000000001')
self.config.add_section('History')
self.config.set('History', 'HistoryCount', '0')
self.config.set('History', 'DiffCount', '1')
self.config.add_section('Dump')
self.config.set('Dump', 'lastDumpDate', '1')
self.config.set('Dump', 'lastDumpDateUrgently', '1')
self.config.set('Dump', 'DumpFileSave', '1')
self.config.set('Dump', 'DumpPath', '')
self.config.set('Dump', 'GetResultMaxCount', '10')
self.config.add_section('Resolver')
self.config.set('Resolver', 'Resolver', '0')
self.config.set('Resolver', 'QueryTimeout', '0.5')
self.config.set('Resolver', 'IPv6', '0')
self.config.set('Resolver', 'DNS', '8.8.4.4 77.88.8.1')
self.config.add_section('OpenSSL')
self.config.set('OpenSSL', 'Path', '')
with open(path_cfg + '/bl-rkn.cfg', 'w') as configfile:
self.config.write(configfile)
def Type(self):
try:
dbtype = self.config.getint('DataBase', 'Type')
except (configparser.NoOptionError, configparser.NoSectionError):
print('Error section DataBase or option Type in config file')
dbtype = 0
exit()
return dbtype
def Name(self):
try:
name = self.config.get('DataBase', 'Name')
except (configparser.NoOptionError, configparser.NoSectionError):
print('Error section DataBase or option Name in config file')
name = 'blacklist'
exit()
return name
def Host(self):
try:
host = self.config.get('DataBase', 'Host')
except (configparser.NoOptionError, configparser.NoSectionError):
print('Error section DataBase or option Host in config file')
host = 'localhost'
exit()
return host
def Port(self):
try:
port = self.config.getint('DataBase', 'Port')
except (configparser.NoOptionError, configparser.NoSectionError):
print('Error section DataBase or option MySQLPort in config file')
port = '5432'
exit()
return port
def User(self):
try:
user = self.config.get('DataBase', 'User')
except (configparser.NoOptionError, configparser.NoSectionError):
print('Error section DataBase or option MySQLUser in config file')
user = 'User'
exit()
return user
def Password(self):
try:
pwd = self.config.get('DataBase', 'Password')
except (configparser.NoOptionError, configparser.NoSectionError):
print('Error section DataBase or option Password in config file')
pwd = 'Password'
exit()
return pwd
def LogCount(self):
try:
log_count = self.config.getint('Log', 'LogCount')
except (configparser.NoOptionError, configparser.NoSectionError):
print('Error section Log or option Log in config file')
log_count = 7
exit()
return log_count
def LogRotate(self):
try:
log_rotate = self.config.get('Log', 'LogRotate')
except (configparser.NoOptionError, configparser.NoSectionError):
print('Error section Log or option Log in config file')
log_rotate = 'midnight'
exit()
return log_rotate
def LogInterval(self):
try:
log_interval = self.config.getint('Log', 'LogInterval')
except (configparser.NoOptionError, configparser.NoSectionError):
print('Error section Log or option Log in config file')
log_interval = 1
exit()
return log_interval
def LogPathFName(self):
try:
log_path = self.config.get('Log', 'LogPathFName')
except (configparser.NoOptionError, configparser.NoSectionError):
print('Error section Log or option LogPathFName in config file')
log_path = 'bl-rkn.log'
exit()
return log_path
def Notify(self):
try:
notify = self.config.getboolean('Notify', 'Notify')
except (configparser.NoOptionError, configparser.NoSectionError):
print('Error section Notify or option Notify in config file')
notify = False
exit()
return notify
def MailServer(self):
try:
mail_server = self.config.get('Notify', 'Server')
except (configparser.NoOptionError, configparser.NoSectionError):
print('Error section Notify or option Server in config file')
mail_server = 'localhost'
exit()
return mail_server
def MailPort(self):
try:
mail_port = self.config.get('Notify', 'Port')
except (configparser.NoOptionError, configparser.NoSectionError):
print('Error section Notify or option Port in config file')
mail_port = '25'
exit()
return mail_port
def MailAuth(self):
try:
mail_auth = self.config.getboolean('Notify', 'Auth')
except (configparser.NoOptionError, configparser.NoSectionError):
print('Error section Notify or option Auth in config file')
mail_auth = False
exit()
return mail_auth
def StartTLS(self):
try:
starttls = self.config.getboolean('Notify', 'StartTLS')
except (configparser.NoOptionError, configparser.NoSectionError):
print('Error section Notify or option StartTLS in config file')
starttls = False
exit()
return starttls
def MailLogin(self):
try:
mail_login = self.config.get('Notify', 'Login')
except (configparser.NoOptionError, configparser.NoSectionError):
print('Error section Notify or option Login in config file')
mail_login = ''
exit()
return mail_login
def MailPassword(self):
try:
mail_password = self.config.get('Notify', 'Password')
except (configparser.NoOptionError, configparser.NoSectionError):
print('Error section Notify or option Password in config file')
mail_password = ''
exit()
return mail_password
def MailSubject(self):
try:
mail_subject = self.config.get('Notify', 'Subject')
except (configparser.NoOptionError, configparser.NoSectionError):
print('Error section Notify or option Subject in config file')
mail_subject = 'vigruzki.rkn.gov.ru ver. 2.2 update'
exit()
return mail_subject
def MailFrom(self):
try:
from_mail = self.config.get('Notify', 'From')
except (configparser.NoOptionError, configparser.NoSectionError):
print('Error section Notify or option From in config file')
from_mail = '[email protected]'
exit()
return from_mail
def MailTo(self):
try:
to_mail = self.config.get('Notify', 'To')
except (configparser.NoOptionError, configparser.NoSectionError):
print('Error section Notify or option To in config file')
to_mail = '[email protected]'
exit()
return to_mail
def GenRequest(self):
try:
gen_request = self.config.getboolean('Request', 'GenerateRequest')
except (configparser.NoOptionError, configparser.NoSectionError):
print('Error section Request or option GenerateRequest in config file')
gen_request = False
exit()
return gen_request
def OperatorName(self):
try:
operator = self.config.get('Request', 'OperatorName')
except (configparser.NoOptionError, configparser.NoSectionError):
print('Error section Request or option OperatorName in config file')
operator = 'ООО "Телеком"'
exit()
return operator
def inn(self):
try:
inn = self.config.getint('Request', 'inn')
except (configparser.NoOptionError, configparser.NoSectionError):
print('Error section Request or option inn in config file')
inn = '1234567890'
exit()
return inn
def ogrn(self):
try:
ogrn = self.config.getint('Request', 'ogrn')
except (configparser.NoOptionError, configparser.NoSectionError):
print('Error section Request or option Request in config file')
ogrn = '1234567891234'
exit()
return ogrn
def email(self):
try:
email = self.config.get('Request', 'email')
except (configparser.NoOptionError, configparser.NoSectionError):
print('Error section Request or option email in config file')
email = '1@ru'
exit()
return email
def XMLPathFName(self):
try:
xml_path = self.config.get('Request', 'XMLPathFName')
except (configparser.NoOptionError, configparser.NoSectionError):
print('Error section Request or option XMLPathFName in config file')
xml_path = 'request.xml'
exit()
return xml_path
def P7SPathFName(self):
try:
p7s_path = self.config.get('Request', 'P7SPathFName')
except (configparser.NoOptionError, configparser.NoSectionError):
print('Error section Request or option P7SPathFName in config file')
p7s_path = 'request.xml.p7s'
exit()
return p7s_path
def PEMPathFName(self):
try:
pem_path = self.config.get('Request', 'PEMPathFName')
except (configparser.NoOptionError, configparser.NoSectionError):
print('Error section Request or option PEMPathFName in config file')
pem_path = 'cert.pem'
exit()
return pem_path
def ID(self):
try:
id_path = self.config.get('Request', 'ID')
except (configparser.NoOptionError, configparser.NoSectionError):
print('Error section Request or option ID in config file')
id_path = '123456789abcdef00000000000000001'
exit()
return id_path
def HistoryCount(self):
try:
history_count = self.config.get('History', 'HistoryCount')
except (configparser.NoOptionError, configparser.NoSectionError):
print('Error section History or option HistoryCount in config file')
history_count = '0'
exit()
return int(history_count)
def DiffCount(self):
try:
diff_count = self.config.get('History', 'DiffCount')
except (configparser.NoOptionError, configparser.NoSectionError):
print('Error section History or option DiffCount in config file')
diff_count = '1'
exit()
return int(diff_count)
def lastDumpDateUrgently(self):
try:
file_save = self.config.getboolean('Dump', 'lastDumpDateUrgently')
except (configparser.NoOptionError, configparser.NoSectionError):
print('Error section Dump or option lastDumpDateUrgently in config file')
file_save = True
exit()
return file_save
def lastDumpDate(self):
try:
file_save = self.config.getboolean('Dump', 'lastDumpDate')
except (configparser.NoOptionError, configparser.NoSectionError):
print('Error section Dump or option lastDumpDate in config file')
file_save = False
exit()
return file_save
def DumpFileSave(self):
try:
file_save = self.config.getboolean('Dump', 'DumpFileSave')
except (configparser.NoOptionError, configparser.NoSectionError):
print('Error section Dump or option DumpFileSave in config file')
file_save = True
exit()
return file_save
def DumpPath(self):
try:
dump_path = self.config.get('Dump', 'DumpPath')
except (configparser.NoOptionError, configparser.NoSectionError):
print('Error section Dump or option DumpPath in config file')
dump_path = ''
exit()
return dump_path
def GetResultMaxCount(self):
try:
result_count = self.config.getint('Dump', 'GetResultMaxCount')
except (configparser.NoOptionError, configparser.NoSectionError):
print('Error section Dump or option GetResultMaxCount in config file')
result_count = 3
exit()
return result_count
def Path(self):
try:
path = self.config.get('OpenSSL', 'Path')
except (configparser.NoOptionError, configparser.NoSectionError):
print('Error section OpenSSL or option Path in config file')
path = ''
exit()
return path
def Resolver(self):
try:
res = self.config.getboolean('Resolver', 'Resolver')
except (configparser.NoOptionError, configparser.NoSectionError):
print('Error section Resolver or option Resolver in config file')
res = False
exit()
return res
def QueryTimeout(self):
try:
timeout = self.config.getfloat('Resolver', 'QueryTimeout')
except (configparser.NoOptionError, configparser.NoSectionError):
print('Error section Resolver or option QueryTimeout in config file')
timeout = 0.5
exit()
return timeout
def IPv6(self):
try:
ipv6 = self.config.getboolean('Resolver', 'IPv6')
except (configparser.NoOptionError, configparser.NoSectionError):
print('Error section Resolver or option IPv6 in config file')
ipv6 = False
exit()
return ipv6
def DNS(self):
try:
dns = self.config.get('Resolver', 'DNS')
except (configparser.NoOptionError, configparser.NoSectionError):
print('Error section Resolver or option DNS in config file')
dns = '8.8.8.8 77.88.8.1'
exit()
return dns
def Reverse(self):
try:
self.config.set('Resolver', 'Resolver', '0')
except (configparser.NoOptionError, configparser.NoSectionError, TypeError) as err:
print(err)
exit()