-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
115 lines (93 loc) · 4.04 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
#!/usr/bin/python3
import os
import sys
import signal
from src.parser import parse_arguments
from src.struct.dump import dump
from src.struct.type.u_table import u_table
from src.struct.type.dataset import dataset
from src.style.ascii import get_ascii
from src.sql.sql_manager import sql_manager
from src.style.toolbar import make_bar, print_time
def main(arguments):
host, user, database = arguments
print("☾ Starting Selene dumper...")
print(get_ascii())
print("✦ Best database dumper written by Dawnl3ss.")
print("✦ This tool is only design for educationnal and ethical purpose. I am not responsible for your usage.")
print("✦ Github : https://github.com/dawnl3ss")
print(" ")
signal.signal(signal.SIGINT, handler)
password = input(f" MySQL {user}'s password : ")
manager = sql_manager(host, user, password, database)
if (manager.check_database()):
cursor_table = manager.connect_db().cursor()
cursor_table.execute(f"USE {database}")
cursor_rows = manager.connect_db().cursor()
cursor_rows.execute(f"USE {database}")
cursor_table.execute("SHOW TABLES")
structure = dump()
print(" ")
make_bar(3)
# store data in my oop structure
for data in cursor_table:
for table in data:
cursor_rows.execute(f"SELECT * FROM {table}")
u_tab = u_table(table, [])
for rows in cursor_rows:
u_tab.add_row(dataset(rows))
structure.add_table(u_tab)
print_time("✦ Database has been dumped !")
print(" ")
while True:
choice = input(" Which method you want to get your result ? [f=file | s=shell] : ")
print(" ")
if choice in ["shell", "s"]:
print("\n")
# display data from my oop structure
for table in structure.get_tables():
print(f"✦ Table '{table}' :")
for row in structure.get_table(table).get_rows():
for val in row.get_value():
print(" | " + str(val), end=" | ")
print(" ")
print(" ")
break
elif choice in ["file", "f"]:
if not os.path.isdir("dumps/"):
os.system("mkdir dumps/")
file = open(f"dumps/{host}--{user}--{database}.txt", 'w')
file.write(f"<---------- Database Dump : {database} ---------->\n\n")
for table in structure.get_tables():
file.write(f"✦ Table '{table}' :")
file.write("\n")
for row in structure.get_table(table).get_rows():
for val in row.get_value():
file.write(" | " + str(val) + " | ")
file.write("\n")
file.write("\n")
file.write("<-------------------------------------------------->")
file.close()
print(f"✦ Dump has been successfully writen in dumps/{host}--{user}--{database}.txt !")
print(" ")
break
else:
print("✦ Wrong method given. Restarting...")
print(" ")
else:
print(" ")
print(f"✦ Unknown database '{database}'. Closing Selene...")
print(" ")
def handler(signum, frame):
print("\n\n✦ You stopped Selene. Goodby !\n")
exit(1)
if __name__ == "__main__":
parse_arguments()
if len(sys.argv) == 7:
flags = (sys.argv[1], sys.argv[3], sys.argv[5])
if flags[0] in ["-hh", "-u", "-d"] and flags[1] in ["-hh", "-u", "-d"] and flags[2] in ["-hh", "-u", "-d"]:
main(arguments=(sys.argv[2], sys.argv[4], sys.argv[6]))
else:
os.system("python3 main.py --help")
else:
os.system("python3 main.py --help")