forked from Abacus-Group-RTO/legion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlegion.py
133 lines (107 loc) · 4.31 KB
/
legion.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/env python
"""
LEGION (https://govanguard.com)
Copyright (c) 2020 GoVanguard
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details.
You should have received a copy of the GNU General Public License along with this program.
If not, see <http://www.gnu.org/licenses/>.
"""
from app.ProjectManager import ProjectManager
from app.logging.legionLog import getStartupLogger, getDbLogger
from app.shell.DefaultShell import DefaultShell
from app.tools.nmap.DefaultNmapExporter import DefaultNmapExporter
from db.RepositoryFactory import RepositoryFactory
from ui.eventfilter import MyEventFilter
from ui.ViewState import ViewState
from ui.gui import *
from ui.gui import Ui_MainWindow
startupLog = getStartupLogger()
# check for dependencies first (make sure all non-standard dependencies are checked for here)
try:
from sqlalchemy.orm.scoping import ScopedSession as scoped_session
except ImportError as e:
startupLog.error(
"Import failed. SQL Alchemy library not found. If on Ubuntu or similar try: apt-get install python3-sqlalchemy*"
)
startupLog.error(e)
exit(1)
try:
from PyQt5 import QtWidgets, QtGui, QtCore
except ImportError as e:
startupLog.error("Import failed. PyQt5 library not found. If on Ubuntu or similar try: "
"apt-get install python3-pyqt5")
startupLog.error(e)
exit(1)
try:
import quamash
import asyncio
except ImportError as e:
startupLog.error("Import failed. Quamash or asyncio not found.")
startupLog.error(e)
exit(1)
try:
import sys
from colorama import init
init(strip=not sys.stdout.isatty())
from termcolor import cprint
from pyfiglet import figlet_format
except ImportError as e:
startupLog.error("Import failed. One or more of the terminal drawing libraries not found.")
startupLog.error(e)
exit(1)
from ui.view import *
from controller.controller import *
# Main application declaration and loop
if __name__ == "__main__":
cprint(figlet_format('LEGION'), 'yellow', 'on_red', attrs=['bold'])
app = QApplication(sys.argv)
loop = quamash.QEventLoop(app)
asyncio.set_event_loop(loop)
MainWindow = QtWidgets.QMainWindow()
app.setWindowIcon(QIcon('./images/icons/Legion-N_128x128.svg'))
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
try:
qss_file = open('./ui/legion.qss').read()
except IOError:
startupLog.error(
"The legion.qss file is missing. Your installation seems to be corrupted. " +
"Try downloading the latest version.")
exit(0)
MainWindow.setStyleSheet(qss_file)
shell = DefaultShell()
dbLog = getDbLogger()
appLogger = getAppLogger()
repositoryFactory = RepositoryFactory(dbLog)
projectManager = ProjectManager(shell, repositoryFactory, appLogger)
nmapExporter = DefaultNmapExporter(shell, appLogger)
toolCoordinator = ToolCoordinator(shell, nmapExporter)
# Model prep (logic, db and models)
logic = Logic(shell, projectManager, toolCoordinator)
startupLog.info("Creating temporary project at application start...")
logic.createNewTemporaryProject()
viewState = ViewState()
view = View(viewState, ui, MainWindow, shell) # View prep (gui)
controller = Controller(view, logic) # Controller prep (communication between model and view)
view.qss = qss_file
myFilter = MyEventFilter(view, MainWindow) # to capture events
app.installEventFilter(myFilter)
# Center the application in screen
x = app.desktop().screenGeometry().center().x()
y = app.desktop().screenGeometry().center().y()
MainWindow.move(x - MainWindow.geometry().width() / 2, y - MainWindow.geometry().height() / 2)
# Show main window
MainWindow.show()
startupLog.info("Legion started successfully.")
try:
loop.run_forever()
except KeyboardInterrupt:
pass
app.deleteLater()
loop.close()
sys.exit()