-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.py
More file actions
73 lines (64 loc) · 2.49 KB
/
settings.py
File metadata and controls
73 lines (64 loc) · 2.49 KB
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
import configparser, os.path, base64
from os import path
from PyQt5.QtWidgets import QWidget
class settings(QWidget):
def encode(clear):
key = '5W0chKHKjrkTOHBwkPJpASHZALtCbeazCPYPQrSyDsvmQArmCBDbLcbzex1g63OG'
enc = []
for i in range(len(clear)):
key_c = key[i % len(key)]
enc_c = chr((ord(clear[i]) + ord(key_c)) % 256)
enc.append(enc_c)
return base64.urlsafe_b64encode("".join(enc).encode()).decode()
def decode(enc):
key = '5W0chKHKjrkTOHBwkPJpASHZALtCbeazCPYPQrSyDsvmQArmCBDbLcbzex1g63OG'
dec = []
enc = base64.urlsafe_b64decode(enc).decode()
for i in range(len(enc)):
key_c = key[i % len(key)]
dec_c = chr((256 + ord(enc[i]) - ord(key_c)) % 256)
dec.append(dec_c)
return "".join(dec)
def put_working_config(hst, prt, usr, pwd):
ln = hst + ':' + prt + ':' + usr + ':' + pwd.rjust(32)
cfg = settings.encode(ln)
f = open('.working','w')
f.write(cfg)
f.close
def get_working_config():
if path.exists(".working"):
f = open('.working', 'r')
ln = f.read()
f.close
ln = str(ln)
cfg = settings.decode(ln)
return cfg
def get_hosts():
if path.exists("settings.ini"):
config = configparser.ConfigParser()
config.read('settings.ini')
hosts = config['DEFAULT']['hosts']
#for host in config.items( "hosts" ):
#do something
return hosts
def add_host(h, prt, usr, pwd):
if not path.exists("settings.ini"):
config = configparser.ConfigParser()
config['DEFAULT']['hosts'] = h
with open('settings.ini', 'w') as configfile:
config.write(configfile)
else:
dont_add = False
config = configparser.ConfigParser()
config.read('settings.ini')
a = config['DEFAULT']['hosts']
s = a.strip().split(',')
for x in s:
x = x.strip()
if h == x :
dont_add = True
if dont_add == False:
config['DEFAULT']['hosts'] = a + ',' + h
with open('settings.ini', 'w') as configfile:
config.write(configfile)
create_working = settings.put_working_config(h, prt, usr, pwd)