-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #122 from devRawnie/menu_driven
Started making menu driven program
- Loading branch information
Showing
5 changed files
with
403 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
test.py | ||
__pycache__/ | ||
env/** | ||
.vscode/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Running the menu driven program | ||
|
||
python3 main.py | ||
|
||
## Adding new scripts to the Menu Driven Program | ||
|
||
1. Open the _scripts.py_ file. | ||
|
||
2. Create a new object inside the __SCRIPTS__ object with the following attributes | ||
|
||
"Name of the Script": { | ||
"path_to_directory": "./relative_path_to_the_scripts_folder", | ||
"program_name": "name_of_the_script_file.py", | ||
"cli_args_required": True|False, | ||
# If 'cli_args_required' is set to True, create the "arguments" key. | ||
|
||
"arguments": { | ||
"argument_name": { | ||
"description" : "Descrition of the argument", | ||
"optional": True|False, | ||
"store_only": True|False | ||
# if no value is to be passed with the argument name | ||
"positional": True|False | ||
# Set to True if name of the argument is not to be included in the program's name. | ||
}, | ||
} | ||
} | ||
|
||
### Scripts which were not included in the menu driven program | ||
|
||
1. SniffAir: The __setup.sh__ file is not included in the code directory. | ||
|
||
2. SQL Injection: The script has no interface built-in in order to interact with it using command line. | ||
|
||
3. Target-Lib: The script has no interface built-in in order to interact with it using command line. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import sys | ||
from os import chdir, listdir, getcwd | ||
from os.path import abspath | ||
|
||
from scripts import SCRIPTS | ||
|
||
|
||
def print_menu(): | ||
# Convert all the available choices to a list | ||
keys = [*SCRIPTS] | ||
|
||
# Add option to exit from the menu | ||
keys.append("Exit") | ||
|
||
# Print all the available choices | ||
count = 1 | ||
for key in keys: | ||
print("{}. {}".format(count, key)) | ||
count += 1 | ||
|
||
choice = int(input("\nEnter your choice: ")) | ||
|
||
# Check for invalid input | ||
while choice < 0 or choice > len(keys): | ||
print("\nError: Invalid Choice") | ||
return print_menu() | ||
|
||
return keys[choice-1] | ||
|
||
|
||
def main(): | ||
choice = print_menu() | ||
print() | ||
if choice == "Exit": | ||
exit(0) | ||
|
||
script_object = SCRIPTS[choice] | ||
if "cli_args_required" in script_object: | ||
if script_object["cli_args_required"]: | ||
if "arguments" not in script_object: | ||
print("Error: Name of command line arguments not passed in setup file") | ||
exit(0) | ||
else: | ||
print("Enter the value for argument(s).") | ||
args = script_object["arguments"] | ||
for arg_key in args.keys(): | ||
arg_obj = args[arg_key] | ||
if arg_obj["optional"]: | ||
val = input(f'* {arg_obj["description"]} (Press Enter to skip)- ') | ||
if "store_only" in arg_obj: | ||
if len(val) > 0: | ||
sys.argv.append(arg_key) | ||
else: | ||
if len(val) > 0: | ||
if "positional" not in arg_obj: | ||
sys.argv.append(arg_key) | ||
sys.argv.append(val) | ||
else: | ||
val = input(f'* {arg_obj["description"]} - ') | ||
if "store_only" in arg_obj: | ||
sys.argv.append(arg_key) | ||
elif "positional" not in arg_obj: | ||
sys.argv.append(arg_key) | ||
sys.argv.append(val) | ||
|
||
sys.path.append(abspath(script_object["path_to_directory"])) | ||
chdir(script_object["path_to_directory"]) | ||
|
||
with open(script_object["program_name"], 'r') as file: | ||
exec(file.read(), globals(), globals()) | ||
|
||
if __name__ == '__main__': | ||
# try: | ||
# main() | ||
# except Exception as e: | ||
# print("An exception occurred: ") | ||
# print(str(e)) | ||
main() |
Oops, something went wrong.