-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathonstart.py
More file actions
162 lines (134 loc) · 6.01 KB
/
onstart.py
File metadata and controls
162 lines (134 loc) · 6.01 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
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
from rich.console import Console
from rich.table import Table
import maskpass
import yaml
import sys
from config import password
# all commands options
from commands import (
BASIC_FUNCTIONAL_COMMMANDS,
CONNECTION_RELATED_COMMANDS,
RESEARCH_COMMANDS
)
console = Console()
class OnStart:
"""Tasks to perfrom after login
"""
def display_tool_info(self):
"""Display welcome and about description content about tool
"""
# read ascii_title.txt to display ASCII styled title first
with open("./ascii_title.txt", "r", encoding="utf-8") as file:
title = str(file.read())
# display ASCII styled title
console.print(f"\n\n[purple]{title}[/purple]")
# display basic about description
console.print("[bold]OnionSpy 🕵🏻♂️ is a research tool for a Dark Web on over the Tor Network that designed for crawling and monitoring .onion 🧅 sites on the Tor network. It enables health checks on dark web sites, performs searches for given queries across the dark web, and handles various Tor-related tasks to facilitate secure and anonymous exploration.[/bold]\n\n")
def check_pass(self):
"""Check password in config.yaml
"""
try:
if password is None:
return False
# if password found
return True
except KeyboardInterrupt:
console.print("\n[green]Exit![/green]")
sys.exit(1)
except Exception as e:
console.print(f"[red]Oops! {e}[/red]\n")
def create_pass(self):
"""Ask user to create to a new password
"""
# read config file
with open("./config.yaml", "r") as file:
config = yaml.safe_load(file)
try:
while True:
# ask user for input new password
user_pass = maskpass.askpass(
prompt="Please create a new password for login: ", mask="*")
if not user_pass:
continue
# if password length smaller than four letters
if len(user_pass) <= 4:
console.print("[yellow]Password length must be greater than four letters![/yellow]\n")
continue
# write password back to config file
config["app"]["password"] = user_pass
with open("./config.yaml", "w") as file:
yaml.safe_dump(config, file, sort_keys=False)
console.print("[green]All set![/green]\n")
return
except KeyboardInterrupt:
console.print("\n[green]Exit![/green]")
sys.exit(1)
except Exception as e:
console.print(f"[red]Oops! {e}[/red]\n")
def ask_for_pass(self):
"""Ask user for password to login into tool
"""
try:
times = 5
ask = 1
while ask <= times:
user_pass = maskpass.askpass(
prompt="Enter your password to login: ", mask="*")
if not user_pass:
continue
# if user password does not match with exact saved password
if user_pass != password:
console.print(
"[red]Wrong password! Please try again.[/red]\n")
ask += 1
continue
# if user password match with exact saved password
return True
# if user enters wrong password continuously then exit from tool
console.print(
"[red]After trying few times your password does not match with exact password. Logging out![/red]")
return False
except KeyboardInterrupt:
console.print("\n[green]Exit![/green]")
sys.exit(1)
except Exception as e:
console.print(f"[red]Oops! {e}[/red]\n")
def display_available_commands(self):
"""Display all available commands
"""
try:
# create table to display commands in readable manner
# 1. basic functional commands
basic_commands_table = Table(
title="Basic Functional Options", show_lines=True)
basic_commands_table.add_column("Command")
basic_commands_table.add_column("Purpose")
for basic_command in BASIC_FUNCTIONAL_COMMMANDS:
basic_commands_table.add_row(
f"[cyan]{basic_command["name"]}[/cyan]", f"[bold]{basic_command["purpose"]}[/bold]")
# display basic functional commands
console.print(basic_commands_table)
# 2. connection related commands
conn_commands_table = Table(
title="Connection Related Options", show_lines=True)
conn_commands_table.add_column("Command")
conn_commands_table.add_column("Purpose")
conn_commands_table.add_column("Example")
for conn_command in CONNECTION_RELATED_COMMANDS:
conn_commands_table.add_row(
f"[cyan]{conn_command["name"]}[/cyan]", f"[bold]{conn_command["purpose"]}[/bold]", f"[bold]{conn_command["example"]}[/bold]")
# display connection commands
console.print(conn_commands_table)
# 3. research commands
research_commands_table = Table(
title="Research & Analysis Options", show_lines=True)
research_commands_table.add_column("Command")
research_commands_table.add_column("Purpose")
research_commands_table.add_column("Example")
for research_command in RESEARCH_COMMANDS:
research_commands_table.add_row(
f"[cyan]{research_command["name"]}[/cyan]", f"[bold]{research_command["purpose"]}[/bold]", f"[bold]{research_command["example"]}[/bold]")
# display research commands
console.print(research_commands_table)
except Exception:
pass