-
Notifications
You must be signed in to change notification settings - Fork 0
/
Storage.py
executable file
·307 lines (154 loc) · 6.62 KB
/
Storage.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
from SQL import DBConnect
from Fileop import File , more
import os.path , sys , time , sqlite3 , os
from subprocess import call as shell
from input_ex import input_ex
from hashs import Hash_it
from datetime import datetime
hash_it = Hash_it()
current_time = datetime.today()
message = '{:%A-%B-%d-%Y}'
current_time = message.format(current_time)
class Storage :
def __init__(self):
self.db = DBConnect(FN = 'static/Account0.db', TN = 'FILES',TC = '(File_Name text,Content varchr,Dir text,DN text ,time text)')
self.db2 = DBConnect(FN = 'static/Account0.db', TN = 'Passwords',TC = '(Memo text,Password varchar)')
# shell('attrib +h static/Account0.db')
# shell('static/Account0.db')
def Passwords(self,Memo ,Password) :
self.db2.Add(TN = 'Passwords', VL = '(?,?)',Data = ( Memo,Password ))
os.system("cls||clear")
time.sleep(0.5)
print( "\n\xb0 NEW PASSWORD HAS SAVED [\xfb] \n ")
def Passwords_Safe(self):
self.db2 = sqlite3.connect("static/Account0.db")
self.db2.row_factory = sqlite3.Row
data = self.db2.execute('SELECT * FROM Passwords')
count = 1
os.system("cls||clear")
time.sleep(0.5)
for row in data:
show = "\n\xb0 [{}] MEMO : {} | PASSWORD : {} \n"
print (show.format( str(count).zfill(2) , row["Memo"] , row["Password"] ))
count += 1
if count == 1 :
print ('\n [-] THE DATABASE IS EMPTY.')
def Store(self):
os.system("cls||clear")
time.sleep(0.5)
try:
choice = input_ex("\n\xb0 [?] FOLDER \xb1 FILE : ")
if choice.lower() == "file" :
Path = input_ex('\n [?] Path : ')
Data = hash_it.en_f(Path = Path)
S_F_Path = os.path.split(Path)
self.db.Add(TN = 'FILES', VL = '(?,?,?,?,?)',Data = (S_F_Path[1],Data, False , False , current_time))
print ("\n\xb0 %s | HAS BEEN SAVED [\xfb] \n" % (S_F_Path[1]))
if choice.lower() == "folder" :
Dir = input_ex('\n [?] Path : ')
for n , file in enumerate(os.listdir(Dir)) :
if os.path.isdir(file) == False :
Data = File(Path = Dir +'/'+ file ,Mode = "rb")
Data_input = hash_it.encrypt(Data)
S_F_Path = os.path.split(file)
dir_name = os.path.dirname(Dir +"\\"+ file).split('\\')
self.db.Add(TN = 'FILES',VL = '(?,?,?,?,?)', Data = (S_F_Path[1],Data_input,True,dir_name[-1] , current_time ))
show = ("\n \xb2 [{}] \xb1 File Name : {} | Folder : {} | has been Saved [\xfb] \n")
print (show.format( str(n).zfill(2) , S_F_Path[1] ,dir_name[-1] ))
except WindowsError :
os.system("cls||clear")
time.sleep(0.5)
print ("\n\xb0 [!] WindowsError, TRY TO MOVE THE FILES TO A DIFFERENT LOCATION.")
except IOError :
os.system("cls||clear")
time.sleep(0.5)
print( "\n\xb0 [!] THE FILE IS NOT READABLE.")
def Extract(self):
choice = input_ex("\n\xb0 [?] ALL \xb1 ONE \xb1 FOLDER : ")
count = 1
if choice.lower() == "one" :
FN =input_ex( '\n\xb0 [?] FILE NAME : ')
data = self.db.Listrequest2('FILES' ,'File_Name' , FN )
for row in data:
Data_output = hash_it.decrypt(bytes(row['Content']))
File(Path = FN ,Mode = "wb" , Content = Data_output)
os.system("cls||clear")
time.sleep(0.5)
show = "\n\xb0 [{}] {} | Folder : {} | has been Extracted [\xfb] "
print (show.format(str(count).zfill(2), row['File_Name'] , row['DN'] ))
count += 1
if count == 1 :
print( '\n\xb0 [-] NameError. or The DataBase is Empty.')
elif choice == "*" or choice.lower() == 'all' :
os.system("cls||clear")
time.sleep(0.5)
data = self.db.Listrequest(TN ='FILES')
for row in data:
if int(row["Dir"]) == True :
if os.path.exists(row['DN']) == False :
os.mkdir(row["DN"])
Data_output = hash_it.decrypt(bytes(row['Content']))
File(Path = row['DN'] +'\\' + row['File_Name'] ,Mode = "wb" , Content = Data_output)
show = ('\n [{}] {} | FOLDER : {} | HAS BEEN EXTRACTED [\xfb] ')
print( show.format(str(count).zfill(2) ,row['File_Name'],row['DN']))
count +=1
if int(row['Dir']) == False :
Data_output = hash_it.decrypt(bytes(row['Content']))
File(Path = row['File_Name'] ,Mode = "wb" , Content = Data_output)
show = ('\n [{}] {} | FOLDER : {} | HAS BEEN EXTRACTED [\xfb] ')
print( show.format(str(count).zfill(2),row['File_Name'],row['DN']))
count += 1
if count == 1 :
print ('\n\xb0 [-] THE DATABASE IS EMPTY.')
def Safe(self):
os.system("cls||clear")
time.sleep(0.5)
data = self.db.Listrequest(TN ='FILES')
count = 1
Files = []
for row in data:
show = ("\n \xb2 [{}] \xb1 FILE NAME : {} | FOLDER : {} | STORING DATE : {} ")
finel = show.format(str(count).zfill(2),row["File_Name"] , row['DN'] , row['time'])
Files.append(finel)
count += 1
for line in Files :
with open('handler.sys' , "a") as file :
file.write(line)
more(Path = 'handler.sys' )
if count == 1 :
os.system('cls||clear')
print( '\n\xb0 [-] THE DATABASE IS EMPTY.')
def Delete(self ,choice):
os.system("cls||clear")
time.sleep(0.5)
count = 1
if choice.lower() == 'one' :
FN = input_ex( '\n\xb0 [?] File Name : ')
self.db.DeleteRecord('FILES' ,'File_Name' , FN )
print ('\n\xb0 %s | HAS BEEN DELETED [\xfb]' % (FN))
count +=1
if choice.lower() == 'all' or choice == "*" :
data = self.db.Listrequest(TN ='FILES')
for row in data :
self.db.DeleteRecord('FILES' ,'File_Name' ,row['File_Name'] )
show = '\n\xb0 [{}] {} | HAS BEEN DELETED [\xfb]'
print (show.format( str(count).zfill(2) , row['File_Name']) )
count +=1
if count == 1 :
os.system("cls||clear")
time.sleep(0.5)
print ('\n\xb0 [-] THE DATABASE IS EMPTY.')
# elif choice.lower() == 'folder' :
# os.system("cls||clear")
# time.sleep(0.5)
# data = self.db.Listrequest(TN ='FILES')
# for row in data:
# FN =input_ex( '\n\xb0 [?] FILE NAME : ')
# if row['Dir'] == FN :
# if os.path.exists(row['DN']) == False :
# os.mkdir(row["DN"])
# Data_output = hash_it.decrypt(bytes(row['Content']))
# File(Path = row['DN'] +'\\' + row['File_Name'] ,Mode = "wb" , Content = Data_output)
# show = ('\n [{}] {} | FOLDER : {} | HAS BEEN EXTRACTED [\xfb] ')
# print show.format(str(count).zfill(2) ,row['File_Name'],row['DN'])
# count +=1