Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Address logic complexity in logic.py
- Extract remaining database related functions into respective repositories with unit test backing - Extract Python and NMap importers out of logic.py and into `importers` directory under `app` module - Optimize test fixtures for less repetition in test setup - Enhancing functions to follow camel case naming convention
- Loading branch information
Showing
27 changed files
with
1,252 additions
and
965 deletions.
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 |
---|---|---|
|
@@ -124,3 +124,5 @@ scripts/CloudFail | |
docker/runLocal.sh | ||
docker/cleanupUntagged.sh | ||
docker/cleanupExited.sh | ||
|
||
log/*.log |
Large diffs are not rendered by default.
Oops, something went wrong.
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,72 @@ | ||
""" | ||
LEGION (https://govanguard.io) | ||
Copyright (c) 2018 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/>. | ||
Author(s): Dmitriy Dubson (d.dubson@gmail.com) | ||
""" | ||
from PyQt5 import QtCore | ||
|
||
from db.database import hostObj | ||
from scripts.python import pyShodan | ||
from ui.ancillaryDialog import ProgressWidget, time | ||
|
||
|
||
class PythonImporter(QtCore.QThread): | ||
tick = QtCore.pyqtSignal(int, name="changed") # New style signal | ||
done = QtCore.pyqtSignal(name="done") # New style signal | ||
schedule = QtCore.pyqtSignal(object, bool, name="schedule") # New style signal | ||
log = QtCore.pyqtSignal(str, name="log") | ||
|
||
def __init__(self): | ||
QtCore.QThread.__init__(self, parent=None) | ||
self.output = '' | ||
self.hostIp = '' | ||
self.pythonScriptDispatch = {'pyShodan': pyShodan.PyShodanScript()} | ||
self.pythonScriptObj = None | ||
self.importProgressWidget = ProgressWidget('Importing shodan data..') | ||
|
||
def tsLog(self, msg): | ||
self.log.emit(str(msg)) | ||
|
||
def setDB(self, db): | ||
self.db = db | ||
|
||
def setHostIp(self, hostIp): | ||
self.hostIp = hostIp | ||
|
||
def setPythonScript(self, pythonScript): | ||
self.pythonScriptObj = self.pythonScriptDispatch[pythonScript] | ||
|
||
def setOutput(self, output): | ||
self.output = output | ||
|
||
def run(self): # it is necessary to get the qprocess because we need to send it back to the scheduler when we're done importing | ||
try: | ||
session = self.db.session() | ||
startTime = time() | ||
self.db.dbsemaphore.acquire() # ensure that while this thread is running, no one else can write to the DB | ||
#self.setPythonScript(self.pythonScript) | ||
db_host = session.query(hostObj).filter_by(ip = self.hostIp).first() | ||
self.pythonScriptObj.setDbHost(db_host) | ||
self.pythonScriptObj.setSession(session) | ||
self.pythonScriptObj.run() | ||
session.commit() | ||
self.db.dbsemaphore.release() # we are done with the DB | ||
self.tsLog('Finished in ' + str(time() - startTime) + ' seconds.') | ||
self.done.emit() | ||
|
||
except Exception as e: | ||
self.tsLog(e) | ||
raise | ||
self.done.emit() |
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,17 @@ | ||
""" | ||
LEGION (https://govanguard.io) | ||
Copyright (c) 2018 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/>. | ||
Author(s): Dmitriy Dubson (d.dubson@gmail.com) | ||
""" |
Oops, something went wrong.