-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpath_traversal.command
More file actions
executable file
·132 lines (113 loc) · 3.2 KB
/
path_traversal.command
File metadata and controls
executable file
·132 lines (113 loc) · 3.2 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
131
132
#!/usr/bin/env python3
# root = ["", "root"]
# dirs = []
# path = []
# current_path = [] or ["", "root"]
dict_path = {
"root": ["" , "root"],
"current_path": [] or ["", "root"],
"dirs": [],
"path": []
}
"""
* mkdir method is used to make/create directories
* [dirs delared global list for directories]
"""
def mkdir():
global dict_path
if dir in dict_path["path"] and dir in dict_path["dirs"]:
print("ERR: DIRECTORY ALREADY EXISTS")
else:
dict_path["dirs"].append(dir)
dict_path["path"].append(dir)
print("SUCC: CREATED")
"""
* ls method is used to list all the directries
* path declared globally
"""
def ls():
if dict_path["path"] == dict_path["root"]:
dict_path["path"] = dict_path["dirs"]
print("DIRS: ", *dict_path["path"], sep="\t")
"""
* cd method is used to change the directory
* current_path, dir, path declared globally
"""
def cd():
global dict_path
if dir == "":
dict_path["current_path"] = dict_path["root"]
dict_path["path"] = dict_path["root"]
print("ENTERED IN ROOT DIRECTORY")
elif dir in dict_path["dirs"] and dir in dict_path["path"]:
dict_path["current_path"].append(dir)
dict_path["path"].clear()
print("ENTERED IN DIRECTORY: ", dict_path["current_path"])
else:
print("ERR: INVALID PATH")
"""
* pwd method is used to list the current path
* current_path declared globally
"""
def pwd():
global dict_path
print("PATH: ")
print(*dict_path["current_path"], sep="/")
"""
* rm method is used to remove the directories created.
* dirs declared globabally
"""
def rm():
global dict_path
if dir in dict_path["dirs"]:
dict_path["dirs"].remove(dir)
print("SUCC: DELETED")
else:
print("ERR: DIRECTORY DOES NOT EXIST")
"""
* session_clear method is used to clear the session. Return to root as default.
* dirs, current_path, path declared globally.
"""
def session_clear():
global dict_path
dict_path["dirs"].clear()
dict_path["current_path"].clear()
dict_path["current_path"] = dict_path["root"]
dict_path["path"].clear()
print("SUCC: CLEARED: RESET TO ROOT")
"""
* commands method has all the applied commands.
"""
def commands(argument):
commands_used = {
"mkdir": mkdir,
"ls": ls,
"cd": cd,
"pwd": pwd,
"rm": rm,
"session_clear": session_clear,
"exit": exit,
}
if char in commands_used:
# Get the function from commands_used dictionary
func = commands_used.get(argument)
# Execute the function
func()
else:
print("ERR: COMMAND ENTERED DOES NOT EXIST!")
print("INFO - COMMANDS TO USE : mkdir, ls, cd, pwd, rm, session_clear, exit")
print("<Starting your application...>")
while True:
char = input("$: ")
command_list = []
command_list.append(char.split(" "))
char = command_list[0][0]
if char in ["mkdir", "rm"] and len(command_list[0]) == 1:
print("{}:Operand Missing".format(char))
elif len(command_list[0]) == 1:
dir = ""
elif len(command_list[0]) == 2:
dir = command_list[0][1]
else:
print("ERR: INVALID SYNTAX")
commands(char)