-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
178 lines (155 loc) · 5.02 KB
/
main.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
#!/bin/bash
# | |
# --+----------------------------------------------------------+--
# | Code by : yasserbdj96 |
# | Email : [email protected] |
# | Github : https://github.com/yasserbdj96 |
# | BTC : bc1q2dks8w8uurca5xmfwv4jwl7upehyjjakr3xga9 |
# --+----------------------------------------------------------+--
# | all posts #yasserbdj96 ,all views my own. |
# --+----------------------------------------------------------+--
# | |
#START{
import argparse
import eel
from ashar import *
import json
import os
# INPUT ARG
ap = argparse.ArgumentParser()
ap.add_argument('-p', '--password', required=True)
ap.add_argument('-c', '--change', required=False)
ap.add_argument('-f', '--file', required=False)
ap.add_argument('-po', '--port', required=False)
ap.add_argument('-a', '--add', required=False)
args = ap.parse_args()
pathx=os.path.dirname(os.path.abspath(__file__))
#
global password_key
# json path:
if args.port==None:
port = 8080
else:
port = int(args.port)
# json path:
global filename
if args.file==None:
filename = pathx+'/src/data.json'
else:
filename = args.file
# login:
with open(filename, 'r+') as f:
data = json.load(f)
if data["password"]!="":
if ashar(args.password,"true",smbls="").encode()==data["password"]:
password_key=args.password
else:
print("The password is wrong")
exit()
else:
# for first time:
print("No password exist!")
np=input("Enter your password:")
data["password"]=ashar(np,"true",smbls="").encode()
f.seek(0)
json.dump(data, f, indent=4)
f.truncate()
print("The password has been registered successfully")
password_key=np
#exit()
# change password:
if args.change!=None:
new_password=args.change
old_password=args.password
with open(filename, 'r+') as f:
data = json.load(f)
data["password"]=ashar(new_password,"true",smbls="").encode()
for i in range(len(data["data"])):
my_passwd=ashar(old_password,data["data"][int(i)]["password"],smbls='').decode()
data["data"][int(i)]["password"]=ashar(new_password,my_passwd,smbls='').encode()
f.seek(0)
json.dump(data, f, indent=4)
f.truncate()
print("The password has been changed successfully")
password_key=new_password
else:
pass
# add csv:
if args.add!=None:
import csv
with open(args.add, 'r') as file:
csvreader = csv.reader(file)
i=0
for row in csvreader:
passwd=ashar(password_key,row[3],smbls='').encode()
entry={"url": f"{row[0]}","username": f"{row[2]}","password": f"{passwd}","backup":""}
with open(filename, 'r+') as f:
if i!=0:
data = json.load(f)
data["data"].append(entry)
f.seek(0) # <--- should reset file position to the beginning.
json.dump(data, f, indent=4)
f.truncate()
i+=1
print("Done!")
else:
pass
#
eel.init(pathx+'/src')
# data_file:
@eel.expose
def data_file():
with open(filename, 'r') as f:
data = json.load(f)
return data
# decode
@eel.expose
def decode(text):
return ashar(password_key,text,smbls="").decode()
# encode
@eel.expose
def encode(text):
return ashar(password_key,text,smbls="").encode()
# addnew
@eel.expose
def addnew(url,user,passwd,other):
passwd=ashar(password_key,passwd,smbls='').encode()
entry={"url": f"{url}","username": f"{user}","password": f"{passwd}","backup": f"{other}"}
with open(filename, 'r+') as f:
data = json.load(f)
data["data"].append(entry)
f.seek(0) # <--- should reset file position to the beginning.
json.dump(data, f, indent=4)
f.truncate()
return "Done!"
# addnew
@eel.expose
def edit(url,user,passwd,other,i):
passwd=ashar(password_key,passwd,smbls='').encode()
with open(filename, 'r+') as f:
data = json.load(f)
data["data"][int(i)]["url"]=url
data["data"][int(i)]["username"]=user
data["data"][int(i)]["password"]=passwd
data["data"][int(i)]["backup"]=other
f.seek(0) # <--- should reset file position to the beginning.
json.dump(data, f, indent=4)
f.truncate()
return "Done!"
# delete
@eel.expose
def delt(ix):
with open(filename, 'r+') as f:
data = json.load(f)
del data["data"][ix]
f.seek(0) # <--- should reset file position to the beginning.
json.dump(data, f, indent=4)
f.truncate()
return "Done!"
#iswork:
@eel.expose
def iswork():
return "True"
#eel.start("main.html",host="127.0.0.1",port=80,size=(1050,500))
eel.start("index.html",host="127.0.0.1",port=port,mode='default')
#}END.