shadecrypt 0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
shadecrypt/__init__.py ADDED
@@ -0,0 +1,16 @@
1
+ import os
2
+ from shadecrypt.core import shadeDB
3
+
4
+ try:
5
+ os.mkdir('~/.shadecrypt/',0o744)
6
+ except Exception as error:
7
+ pass
8
+ CONFIG_PATH = '~/.shadecrypt/config.scdb'
9
+ if not os.path.exists(CONFIG_PATH):
10
+ with open(CONFIG_PATH,"w"):
11
+ pass
12
+ os.chmod(CONFIG_PATH,0o644)
13
+ instance = shadeDB(CONFIG_PATH,write=True)
14
+ instance = shadeDB(CONFIG_PATH,write=True)
15
+
16
+
shadecrypt/cli.py ADDED
@@ -0,0 +1,259 @@
1
+ import sys,ast,socket,pickle
2
+ from shadecrypt.core import shadeDB
3
+ from shadecrypt.config import load_config,set_current_db
4
+ from shadecrypt.service import is_true,server,red,blue,green,plain,yellow
5
+ red = '\x1b[1;31m'
6
+ green = '\x1b[1;32m'
7
+ plain = '\x1b[1;0m'
8
+ blue = '\x1b[1;34m'
9
+
10
+ def is_native(path):
11
+ if path.endswith('.scdb'):
12
+ return True
13
+ return False
14
+
15
+ def handle_rq(token='',command='',key='',value='',admin_token='',multiple=False,port=8382):
16
+ port = int(port)
17
+ if is_true(token,load_config().get('token','null')):
18
+ if command in ["get","id","pull"]:
19
+ try:
20
+ with socket.socket(socket.AF_INET,socket.SOCK_STREAM) as s:
21
+ s.connect(('127.0.0.1',port))
22
+ if command == "get":
23
+ request = {"token":token,"command":command,"key":key,"multiple":multiple}
24
+ elif command == "id":
25
+ request = {"token":token,"command":command,"key":key}
26
+ else:
27
+ request = {"token":token,"command":command,"admin_token":admin_token,"key":key}
28
+ request = pickle.dumps(request)
29
+ s.sendall(request)
30
+ receive = s.recv(5120)
31
+ if receive:
32
+ response = pickle.loads(receive)
33
+ if response['status'] == "OK":
34
+ print(response.get('data','null'))
35
+ else:
36
+ print(response.get('message','An error occured'))
37
+ except ConnectionRefusedError:
38
+ print(f"{red}O{plain}ops! connection was refused,are you sure the server is running?")
39
+ finally:
40
+ s.close()
41
+
42
+ elif command in ["stop","clear","remove"]:
43
+ try:
44
+ with socket.socket(socket.AF_INET,socket.SOCK_STREAM) as s:
45
+ s.connect(('127.0.0.1',port))
46
+ if command == "stop":
47
+ request = {"command":command,"token":token,"admin_token":admin_token}
48
+ encode = pickle.dumps(request)
49
+ s.sendall(encode)
50
+ receive = s.recv(5120)
51
+ if receive:
52
+ response = pickle.loads(receive)
53
+ if response['status'] == "OK":
54
+ print(f"{green}S{plain}uccessfully closed the server")
55
+ else:
56
+ print(response.get('message','An error occured'))
57
+ elif command in ["clear","remove"]:
58
+ request = {"token":token,"admin_token":admin_token,"command":command,"key":key}
59
+
60
+ request = pickle.dumps(request)
61
+ s.sendall(request)
62
+ receive = s.recv(5120)
63
+ if receive:
64
+ response = pickle.loads(receive)
65
+ if response['status'] == "OK":
66
+ print(response.get('message'))
67
+ else:
68
+ print(response.get('message'))
69
+ except ConnectionRefusedError:
70
+ print(f"{red}O{plain}ops! connection was refused,are you sure the server is running?")
71
+ finally:
72
+ s.close()
73
+
74
+ elif command == "update":
75
+ with socket.socket(socket.AF_INET,socket.SOCK_STREAM) as s:
76
+ try:
77
+ s.connect(('127.0.0.1',port))
78
+ request = {"token":token,"command":command,"admin_token":admin_token,"key":key,"value":value}
79
+ request = pickle.dumps(request)
80
+ s.sendall(request)
81
+ receive = s.recv(5120)
82
+ if receive:
83
+ response = pickle.loads(receive)
84
+ if response['status'] == "OK":
85
+ print(response.get('message'))
86
+ else:
87
+ print(response.get('message'))
88
+ except ConnectionRefusedError:
89
+ print(f"{red}O{plain}ops! connection was refused,are you sure the server is running?")
90
+ finally:
91
+ s.close()
92
+ elif command == "pull":
93
+ with socket.socket(socket.AF_INET,socket.SOCK_STREAM) as s:
94
+ try:
95
+ s.connect(('127.0.0.1',port))
96
+ request = {"token":token,"command":command,"admin_token":admin_token,"key":key}
97
+ request = pickle.dumps(request)
98
+ s.sendall(request)
99
+ receive = s.recv(5120)
100
+ if receive:
101
+ response = pickle.loads(receive)
102
+ if response['status'] == "OK":
103
+ print(response.get('message'))
104
+ else:
105
+ print(response.get('message'))
106
+ except ConnectionRefusedError:
107
+ print(f"{red}O{plain}ops! connection was refused,are you sure the server is running?")
108
+ finally:
109
+ s.close()
110
+ else:
111
+ pass
112
+
113
+ def correct(value):
114
+ if value.upper() == "TRUE":
115
+ return True
116
+ elif value.upper() == "FALSE":
117
+ return False
118
+ else:
119
+ try:
120
+ return int(value)
121
+ except ValueError:
122
+ try:
123
+ return float(value)
124
+ except ValueError:
125
+ try:
126
+ return complex(value)
127
+ except ValueError:
128
+ return value
129
+
130
+ def main():
131
+ loaded = load_config()
132
+ if len(sys.argv) < 2:
133
+ print('Usage: shadecrypt [args...]')
134
+ sys.exit(1)
135
+
136
+ command = sys.argv[1]
137
+ if command == "status":
138
+ for key,val in loaded.items():
139
+ print(f'{key} : {val}')
140
+
141
+ args = sys.argv[2:]
142
+
143
+ if command == "init":
144
+ if not args:
145
+ print(f'Usage: shadecrypt init db_path/db_name.scdb Enter : backup ; if you intend to allow backups otherwise leave empty \n\n{blue}E{plain}xample: shadecrypt init mydb.scdb backup')
146
+ sys.exit(1)
147
+ db_path = args[0]
148
+ bkup = True if len(args)>1 and args[1] == "backup" else False
149
+ if is_native(db_path):
150
+ shadedb = shadeDB(db_path,backup=bkup)
151
+ set_current_db(db_path,backup=bkup)
152
+ if shadedb.status() == "Active and running...":
153
+ print(f'Shadecrypt : initialised {db_path} and already set as default database disk.')
154
+ pass
155
+
156
+ return
157
+
158
+ if command == "use":
159
+ if len(args) >= 1:
160
+ db_path = args[0]
161
+ bkup = True if len(args) > 1 and args[1] == "backup" else False
162
+ if is_native(db_path):
163
+ set_current_db(db_path,backup=bkup)
164
+ print(f'shadecrypt: default db has been set to {green}{db_path}{plain}\nAllow backup : {bkup}')
165
+ else:
166
+ print(f'Usage: to change your current database disk\n{blue}E{plain}xample: shadecrypt use newdb.scdb backup ')
167
+ pass
168
+ if command == "ls":
169
+ print('Current db :%s'%load_config().get("current_db",None))
170
+
171
+ if command == "start":
172
+ port = args[0] if len(args) == 1 else 8382
173
+ server(loaded.get('current_db'), backup = loaded.get('allow_backup',False),port = port)
174
+ return
175
+
176
+ if command in ["get","id"]:
177
+ if len(args) >= 1:
178
+ fetch = args[0]
179
+ multiple = True if len(args) >= 2 and args[1] == "multiple" else False
180
+ token = loaded.get('token')
181
+ port = loaded.get('port',8382)
182
+ handle_rq(token=token,command=command,key=fetch,multiple=multiple,port=port)
183
+ else:
184
+ print(f"""
185
+ Usage:
186
+ shadecrypt get key multiple
187
+ shadecrypt id key - to fetch the given key's id
188
+
189
+ {blue}E{plain}xample : shadecrypt get shade multiple
190
+ {blue}E{plain}xample2 : shadecrypt get shade.age
191
+
192
+ {yellow}O{plain}nly provide shade.age fetch the specified data from the key row - shade
193
+ """)
194
+ if command in ["stop","remove","clear"]:
195
+ if len(args) >= 1:
196
+ if command == "remove":
197
+ target = args[0]
198
+ handle_rq(token = loaded.get('token','null'),command = command,key = target,admin_token=loaded.get('admin_token','null'),port=loaded.get('port',8382))
199
+ elif command in ["stop","clear"]:
200
+ handle_rq(token = loaded.get('token','null'),command = command, admin_token = loaded.get('admin_token','null'),port=loaded.get('port',8382))
201
+ else:
202
+ print(f"""
203
+ Usage:
204
+
205
+ {red}s{plain}hadecrypt remove key
206
+ {red}s{plain}hadecrypt stop - to close server remotely
207
+ {red}s{plain}hadecrypt clear - to clear the database record
208
+
209
+ {blue}E{plain}xample : shadecrypt remove shade or shadecrypt remove shade.age - remove the specified row data
210
+
211
+ {red}E{plain}xample2 : shadecrypt stop - remotely close the database
212
+ {red}E{plain}xample3 : shadecrypt clear - clear database
213
+
214
+ {yellow}R{plain}ead the full documentation at \'shadecrypt pypi\' for a better understanding
215
+ """)
216
+
217
+ if command == "update":
218
+ if len(args) > 1:
219
+ key = args[0]
220
+ value = args[1]
221
+ if "." in key:
222
+ construct = dict()
223
+ key, pkey = key.split('.',1)
224
+ construct[pkey] = correct(value)
225
+ handle_rq(token=loaded.get('token','null'),admin_token=loaded.get('admin_token'),command=command,key=key,value=construct,port=loaded.get('port',8382))
226
+ else:
227
+ handle_rq(token=loaded.get('token','null'),admin_token=loaded.get('admin_token'),command=command,key=key,value=value,port=loaded.get('port',8382))
228
+
229
+
230
+ else:
231
+ print(f"""
232
+ Usage:
233
+
234
+ {red}s{plain}hadecrypt update key value
235
+
236
+ {blue}E{plain}xample : shadecrypt update shade ola - single string
237
+ {blue}E{plain}xample2 : shadecrypt update shade ['software engineer','shell','pentester','inventor'] - multiple values
238
+ {blue}E{plain}xample3 : shadecrypt update shade {{"age":15,"status":"active","passion":"solving problems","skills":["python","js","engineering"]}} - mutiple key, value to populate the key row
239
+
240
+ {yellow}R{plain}ead the full documentation at \'shadecrypt pypi\' for a better understanding
241
+ """)
242
+
243
+ if command == "pull":
244
+ if len(args) == 1:
245
+ key = args[0]
246
+ if "." in key:
247
+ handle_rq(token=loaded.get('token','null'),admin_token=loaded.get('admin_token'),command=command,key=key,port=loaded.get('port',8382))
248
+ else:
249
+ print(f"Do you mean to provide {red}{key}.data{plain}")
250
+ else:
251
+ print(f"""
252
+ Usage:
253
+
254
+ {blue}s{plain}hadecrypt pull shade.age
255
+ This should fetch the specified data from the provided row.
256
+ """)
257
+
258
+ if __name__ == "__main__":
259
+ pass
shadecrypt/config.py ADDED
@@ -0,0 +1,22 @@
1
+ import os
2
+ from shadecrypt.__init__ import instance,CONFIG_PATH
3
+
4
+ def load_config():
5
+ if os.path.exists(CONFIG_PATH):
6
+ return instance.export_dict()
7
+ return {"current_db": None, "recent": None}
8
+
9
+
10
+ def set_current_db(path,backup=False):
11
+ try:
12
+ cur_history = instance.get('current_db')
13
+ except Exception:
14
+ cur_history = None
15
+ finally:
16
+ if cur_history != path:
17
+ instance.update(('recent_db',cur_history))
18
+ instance.update(('current_db',path))
19
+ instance.update(('allow_backup',backup))
20
+
21
+ if __name__ == "__main__":
22
+ pass