File controller.py
has 748 lines of code (exceeds 250 allowed). Consider refactoring. Open
#!/usr/bin/env python
"""
LEGION (https://shanewilliamscott.com)
Copyright (c) 2024 Shane Scott
Function handleHostAction
has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring. Open
def handleHostAction(self, ip, hostid, actions, action):
repositoryContainer = self.logic.activeProject.repositoryContainer
if action.text() == 'Mark as checked' or action.text() == 'Mark as unchecked':
repositoryContainer.hostRepository.toggleHostCheckStatus(ip)
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Controller
has 73 functions (exceeds 50 allowed). Consider refactoring. Open
class Controller:
# initialisations that will happen once - when the program is launched
@timing
def __init__(self, view, logic):
Function handleServiceNameAction
has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring. Open
def handleServiceNameAction(self, targets, actions, action, restoring=True):
if action.text() == 'Take screenshot':
for ip in targets:
url = ip[0] + ':' + ip[1]
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function runToolsFor
has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring. Open
def runToolsFor(self, service, hostname, ip, port, protocol='tcp'):
log.info('Running tools for: ' + service + ' on ' + ip + ':' + port)
if service.endswith("?"): # when nmap is not sure it will append a ?, so we need to remove it
service=service[:-1]
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function handleProcessAction
has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring. Open
def handleProcessAction(self, selectedProcesses, action):
if action.text() == 'Kill':
if self.view.killProcessConfirmation():
for p in selectedProcesses:
if p[1] != "Running":
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function runStagedNmap
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
def runStagedNmap(self, targetHosts, discovery = True, stage = 1, stop = False):
log.info("runStagedNmap called for stage {0}".format(str(stage)))
runningFolder = self.logic.activeProject.properties.runningFolder
if not stop:
textbox = self.view.createNewTabForHost(str(targetHosts), 'nmap (stage ' + str(stage) + ')', True)
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function processFinished
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
def processFinished(self, qProcess):
processRepository = self.logic.activeProject.repositoryContainer.processRepository
try:
if not processRepository.isKilledProcess(
str(qProcess.id)): # if process was not killed
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function scheduler
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
def scheduler(self, parser, isNmapImport):
if isNmapImport and self.settings.general_enable_scheduler_on_import == 'False':
return
if self.settings.general_enable_scheduler == 'True':
log.info('Scheduler started!')
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function addHosts
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
def addHosts(self, targetHosts, runHostDiscovery, runStagedNmap, nmapSpeed, scanMode, nmapOptions = []):
if targetHosts == '':
log.info('No hosts entered..')
return
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function handlePortAction
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
def handlePortAction(self, targets, *args):
actions = args[0]
terminalActions = args[1]
action = args[2]
restoring = args[3]
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function runCommand
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
def runCommand(self, *args, discovery=True, stage=0, stop=False):
def handleProcStop(*vargs):
updateElapsed.stop()
self.processTimers[qProcess.id] = None
procTime = timer.elapsed() / 1000
Function getContextMenuForHost
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def getContextMenuForHost(self, isChecked, showAll=True):
menu = QMenu()
self.nmapSubMenu = QMenu('Portscan')
actions = []
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function addHosts
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
def addHosts(self, targetHosts, runHostDiscovery, runStagedNmap, nmapSpeed, scanMode, nmapOptions = []):
Avoid deeply nested control flow statements. Open
if tool[0] == a[1]:
tabTitle = a[1] + " (" + port + "/" + protocol + ")"
# Cheese
outputfile = self.logic.activeProject.properties.runningFolder + "/" + \
re.sub("[^0-9a-zA-Z]", "", str(tool[0])) + \
Avoid deeply nested control flow statements. Open
if isWsl():
command = "{0} -oA {1}".format(command, unixPath2Win(outputfile))
else:
command = "{0} -oA {1}".format(command, outputfile)
Avoid deeply nested control flow statements. Open
if p[1] == "Waiting":
if str(self.logic.activeProject.repositoryContainer.processRepository.getStatusByProcessId(
p[2])) == 'Running':
self.killProcess(self.view.ProcessesTableModel.getProcessPidForId(p[2]), p[2])
self.logic.activeProject.repositoryContainer.processRepository.storeProcessCancelStatus(
Function checkProcessQueue
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def checkProcessQueue(self):
log.debug('Queue maximum concurrent processes: {0}'.format(str(self.settings.general_max_fast_processes)))
log.debug('Queue processes running: {0}'.format(str(self.fastProcessesRunning)))
log.debug('Queue processes waiting: {0}'.format(str(self.fastProcessQueue.qsize())))
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid deeply nested control flow statements. Open
if not (s is None):
self.runToolsFor(s.name, h.hostname, h.ip, p.portId, p.protocol)
Function runToolsFor
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def runToolsFor(self, service, hostname, ip, port, protocol='tcp'):
Function getContextMenuForServiceName
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def getContextMenuForServiceName(self, serviceName='*', menu=None):
if menu == None: # if no menu was given, create a new one
menu = QMenu()
if serviceName == '*' or serviceName in self.settings.general_web_services.split(","):
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid too many return
statements within this function. Open
return