-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
executable file
·130 lines (122 loc) · 3.28 KB
/
cli.py
File metadata and controls
executable file
·130 lines (122 loc) · 3.28 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
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
#!/usr/bin/env python3
from dataclasses import dataclass # For internal storage sorting
@dataclass
class User:
username: str
flags: list
password: str = None
import os, sys
shell = 'PySH'
bin = '/'.join(sys.argv[0].split('/')[:-1]) + '/py/'
if sys.argv[0].count('/') < 1:
bin = './py/'
if not os.path.isdir(bin):
# Currently only supports darwin, will add case system when install.sh is updated
bin = '/usr/local/share/pysh/'
if not os.path.isdir(bin):
print("Failed to get resources")
quit()
accounts = []
account = None
flags = []
hashseed = os.getenv('PYTHONHASHSEED')
if not hashseed:
os.environ['PYTHONHASHSEED'] = '0'
os.execv(sys.executable, [sys.executable] + sys.argv)
class Login():
def create_log_file(self,path:str = bin+'users'):
if not os.path.isfile(path):
with open(path,'a') as i:
i.write('')
else:
return True
def get_login(self,path:str = bin+'users'): # from file
with open(path,'r',encoding='utf-8-sig') as i:
for n in i.readlines():
args = n.split('|')
if len(args) < 3:
break
test = User(args[0],args[1].split(','),int(args[2]))
accounts.append(test)
def add_login(self,account:User,path:str = bin+'users'):
with open(path,'a') as i:
i.write(f'{account.username}|{",".join(account.flags)}|{account.password}\n')
def main():
global account
global accounts
global flags
if Login().create_log_file():
Login().get_login()
else:
flags.append('administrator')
log = False
account = User(input('Username: '),flags)
for i in accounts:
if account.username == i.username:
account.password = hash(input(f'Welcome back, {account.username}\nPlease enter your password: '))
for i in accounts:
if account.username == i.username and account.password == i.password:
log = True
break
if flags:
while not account.password:
account.password = hash(input('This account isn\'t recognized.\nPlease enter a new password: '))
if account.password:
Login().add_login(account)
log = True
accounts.append(account)
if not log:
print('Failed login. Please try again')
main()
return
commands = {}
i = []
for (path, dirs, files) in os.walk(bin):
i.extend(files)
break
for i in i:
if not i.endswith('.py'):
continue
with open(bin + i,'r') as file:
exec(file.read(), commands, None)
commands['shell'] = shell
commands['accounts'] = accounts
commands['account'] = account
if not len(sys.argv) > 1:
commands['clear']()
while log:
if not commands['account']:
log = False
commands['clear']()
main()
return
location = commands['os'].getcwd()
work = False
if len(sys.argv) > 1:
cmd = sys.argv[2:]
cmd.insert(0,os.path.splitext(sys.argv[1])[0][2:])
else:
cmd = input(f'{os.path.abspath(location)}:~ {account.username}$ ').lstrip().rstrip().split(' ')
for i in commands:
if i in ('__builtins__','system','os','inspect','platform') or not callable(commands[i]):
continue
if cmd[0] == i:
try:
cmd.pop(0)
output = commands[i](*cmd)
if output:
print(output)
except IndexError as e:
print(f'{shell}: {i}: {e}')
except Exception as e:
print(f'{shell}: {i}: {e}')
work = True
break
if not work:
print(f'{shell}: command not found: {cmd[0]}')
if len(sys.argv) > 1:
return
main()
return
if __name__ == "__main__":
main()