1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-07 05:01:29 +00:00

Fix pep8 errors in all of zenmap

This commit is contained in:
dmiller
2015-12-11 23:11:47 +00:00
parent 24f5f35d3e
commit 3567d72b17
28 changed files with 282 additions and 275 deletions

View File

@@ -265,7 +265,7 @@ if __name__ == "__main__":
# Testing application # Testing application
polar = PolarCoordinate(1, math.pi) polar = PolarCoordinate(1, math.pi)
cartesian = CartesianCoordinate(-1, 0) cartesian = CartesianCoordinate(-1, 0)
print polar.to_cartesian() print polar.to_cartesian()
print cartesian.to_polar() print cartesian.to_polar()

View File

@@ -121,8 +121,8 @@
import os import os
INFO = {'name': 'RadialNet', INFO = {'name': 'RadialNet',
'version': '0.44', 'version': '0.44',
'website': 'http://www.dca.ufrn.br/~joaomedeiros/radialnet/', 'website': 'http://www.dca.ufrn.br/~joaomedeiros/radialnet/',
'authors': ['João Paulo de Souza Medeiros'], 'authors': ['João Paulo de Souza Medeiros'],
'copyright': 'Copyright (C) 2007, 2008 Insecure.Com LLC'} 'copyright': 'Copyright (C) 2007, 2008 Insecure.Com LLC'}

View File

@@ -133,12 +133,12 @@ PORTS_HEADER = [
_('Port'), _('Protocol'), _('State'), _('Service'), _('Method')] _('Port'), _('Protocol'), _('State'), _('Service'), _('Method')]
EXTRAPORTS_HEADER = [_('Count'), _('State'), _('Reasons')] EXTRAPORTS_HEADER = [_('Count'), _('State'), _('Reasons')]
SERVICE_COLORS = {'open': '#ffd5d5', SERVICE_COLORS = {'open': '#ffd5d5', # noqa
'closed': '#d5ffd5', 'closed': '#d5ffd5', # noqa
'filtered': '#ffffd5', 'filtered': '#ffffd5', # noqa
'unfiltered': '#ffd5d5', 'unfiltered': '#ffd5d5', # noqa
'open|filtered': '#ffd5d5', 'open|filtered': '#ffd5d5', # noqa
'closed|filtered': '#d5ffd5'} 'closed|filtered': '#d5ffd5'} # noqa
UNKNOWN_SERVICE_COLOR = '#d5d5d5' UNKNOWN_SERVICE_COLOR = '#d5d5d5'
TRACE_HEADER = [_('TTL'), _('RTT'), _('IP'), _('Hostname')] TRACE_HEADER = [_('TTL'), _('RTT'), _('IP'), _('Hostname')]
@@ -148,8 +148,8 @@ TRACE_TEXT = _(
NO_TRACE_TEXT = _("No traceroute information available.") NO_TRACE_TEXT = _("No traceroute information available.")
HOP_COLOR = {'known': '#ffffff', HOP_COLOR = {'known': '#ffffff', # noqa
'unknown': '#cccccc'} 'unknown': '#cccccc'} # noqa
SYSTEM_ADDRESS_TEXT = "[%s] %s" SYSTEM_ADDRESS_TEXT = "[%s] %s"

View File

@@ -144,10 +144,10 @@ REGION_GREEN = 2
SQUARE_TYPES = ['router', 'switch', 'wap'] SQUARE_TYPES = ['router', 'switch', 'wap']
ICON_DICT = {'router': 'router', ICON_DICT = {'router': 'router',
'switch': 'switch', 'switch': 'switch',
'wap': 'wireless', 'wap': 'wireless',
'firewall': 'firewall'} 'firewall': 'firewall'}
POINTER_JUMP_TO = 0 POINTER_JUMP_TO = 0
POINTER_INFO = 1 POINTER_INFO = 1

View File

@@ -177,13 +177,14 @@ class TracerouteHostInfo(object):
def find_hop_by_ttl(hops, ttl): def find_hop_by_ttl(hops, ttl):
assert ttl >= 0, "ttl must be non-negative" assert ttl >= 0, "ttl must be non-negative"
if ttl == 0: # Same machine (i.e. localhost) if ttl == 0: # Same machine (i.e. localhost)
return {"ipaddr": "127.0.0.1/8"} return {"ipaddr": "127.0.0.1/8"}
for h in hops: for h in hops:
if ttl == int(h["ttl"]): if ttl == int(h["ttl"]):
return h return h
return None return None
def make_graph_from_hosts(hosts): def make_graph_from_hosts(hosts):
#hosts = parser.get_root().search_children('host', deep=True) #hosts = parser.get_root().search_children('host', deep=True)
graph = Graph() graph = Graph()
@@ -249,14 +250,14 @@ def make_graph_from_hosts(hosts):
else: else:
graph.set_connection(node, prev_node) graph.set_connection(node, prev_node)
else: else:
# Add an "anonymous" node only if there isn't already a node # Add an "anonymous" node only if there isn't already a
# equivalent to it (i.e. at same distance from the previous # node equivalent to it (i.e. at same distance from the
# "real" node) # previous "real" node)
pre_hop = None pre_hop = None
pre_hop_distance = 0 pre_hop_distance = 0
for i in range(1, ttl + 1): for i in range(1, ttl + 1):
pre_hop = find_hop_by_ttl(hops, ttl-i) pre_hop = find_hop_by_ttl(hops, ttl - i)
if pre_hop is not None: if pre_hop is not None:
pre_hop_distance = i pre_hop_distance = i
break break
@@ -264,29 +265,33 @@ def make_graph_from_hosts(hosts):
post_hop = None post_hop = None
post_hop_distance = 0 post_hop_distance = 0
for i in range(1, max(ttls) - ttl): for i in range(1, max(ttls) - ttl):
post_hop = find_hop_by_ttl(hops, ttl+i) post_hop = find_hop_by_ttl(hops, ttl + i)
if post_hop is not None: if post_hop is not None:
post_hop_distance = i post_hop_distance = i
break break
assert pre_hop is not None, "pre_hop should have become localhost if nothing else" assert pre_hop is not None, \
"pre_hop should have become localhost if nothing else" # noqa
ancestor_key = (pre_hop["ipaddr"], pre_hop_distance) ancestor_key = (pre_hop["ipaddr"], pre_hop_distance)
descendant_key = None descendant_key = None
if post_hop is not None: if post_hop is not None:
descendant_key = (post_hop["ipaddr"], post_hop_distance) descendant_key = \
(post_hop["ipaddr"], post_hop_distance)
if ancestor_key in ancestor_node_cache: if ancestor_key in ancestor_node_cache:
node = ancestor_node_cache[ancestor_key] node = ancestor_node_cache[ancestor_key]
elif descendant_key is not None and descendant_key in descendant_node_cache: elif (descendant_key is not None and
descendant_key in descendant_node_cache):
node = descendant_node_cache[descendant_key] node = descendant_node_cache[descendant_key]
graph.set_connection(node, prev_node) graph.set_connection(node, prev_node)
else: else:
node = NetNode() node = NetNode()
nodes.append(node) nodes.append(node)
node.set_draw_info({"valid":False}) node.set_draw_info({"valid": False})
node.set_draw_info({"color":(1,1,1), "radius":NONE_RADIUS}) node.set_draw_info(
{"color": (1, 1, 1), "radius": NONE_RADIUS})
graph.set_connection(node, prev_node) graph.set_connection(node, prev_node)

View File

@@ -381,15 +381,15 @@ for dir in dirs:
continue continue
if os.path.isdir(output): if os.path.isdir(output):
os.chmod(output, S_IRWXU | \ os.chmod(output, S_IRWXU |
S_IRGRP | \ S_IRGRP |
S_IXGRP | \ S_IXGRP |
S_IROTH | \ S_IROTH |
S_IXOTH) S_IXOTH)
else: else:
os.chmod(output, S_IRUSR | \ os.chmod(output, S_IRUSR |
S_IWUSR | \ S_IWUSR |
S_IRGRP | \ S_IRGRP |
S_IROTH) S_IROTH)
def fix_paths(self): def fix_paths(self):

View File

@@ -15,15 +15,18 @@ import xml.sax
directory = None directory = None
def escape(s): def escape(s):
return '"' + s.encode("UTF-8").replace('"', '\\"') + '"' return '"' + s.encode("UTF-8").replace('"', '\\"') + '"'
def output_msgid(msgid, locator): def output_msgid(msgid, locator):
print print
print u"#: %s:%d" % (locator.getSystemId(), locator.getLineNumber()) print u"#: %s:%d" % (locator.getSystemId(), locator.getLineNumber())
print u"msgid", escape(msgid) print u"msgid", escape(msgid)
print u"msgstr", escape(u"") print u"msgstr", escape(u"")
class Handler (xml.sax.handler.ContentHandler): class Handler (xml.sax.handler.ContentHandler):
def setDocumentLocator(self, locator): def setDocumentLocator(self, locator):
self.locator = locator self.locator = locator

View File

@@ -7,7 +7,7 @@ if __name__ == "__main__":
import glob import glob
import os import os
if not hasattr(unittest.defaultTestLoader, "discover"): if not hasattr(unittest.defaultTestLoader, "discover"):
print("Python unittest discovery missing. Requires Python 2.7 or newer.") print("Python unittest discovery missing. Requires Python 2.7 or newer.") # noqa
sys.exit(0) sys.exit(0)
os.chdir("..") os.chdir("..")

View File

@@ -256,7 +256,8 @@ class NetworkInventory(object):
#remove ports which are no longer up #remove ports which are no longer up
if old_date < new_date: if old_date < new_date:
for defunct_port in old_list: for defunct_port in old_list:
#Check if defunct_port is in ports and that the protocol matches # Check if defunct_port is in ports
# and that the protocol matches
port_number = int(defunct_port['portid']) port_number = int(defunct_port['portid'])
if port_number in ports: if port_number in ports:
if defunct_port['protocol'] in ports[port_number]: if defunct_port['protocol'] in ports[port_number]:
@@ -520,9 +521,9 @@ class FilteredNetworkInventory(NetworkInventory):
return len(self.network_inventory.hosts) return len(self.network_inventory.hosts)
def match_keyword(self, host, keyword): def match_keyword(self, host, keyword):
return self.match_os(host, keyword) or\ return (self.match_os(host, keyword) or
self.match_target(host, keyword) or\ self.match_target(host, keyword) or
self.match_service(host, keyword) self.match_service(host, keyword))
def match_target(self, host, name): def match_target(self, host, name):
return HostSearch.match_target(host, name) return HostSearch.match_target(host, name)
@@ -663,8 +664,8 @@ class FilteredNetworkInventoryTest(unittest.TestCase):
class PortChangeTest(unittest.TestCase): class PortChangeTest(unittest.TestCase):
def test_port(self): def test_port(self):
"""Verify that the port status (open/filtered/closed) is displayed """ \ """Verify that the port status (open/filtered/closed) is displayed
"""correctly when the port status changes in newer scans""" correctly when the port status changes in newer scans"""
from zenmapCore.NmapParser import NmapParser from zenmapCore.NmapParser import NmapParser
inv = NetworkInventory() inv = NetworkInventory()
scan1 = NmapParser() scan1 = NmapParser()

View File

@@ -261,10 +261,11 @@ class NmapCommand(object):
os.kill(self.command_process.pid, SIGTERM) os.kill(self.command_process.pid, SIGTERM)
for i in range(10): for i in range(10):
sleep(0.5) sleep(0.5)
if self.command_process.poll() is not None: # Process has been TERMinated if self.command_process.poll() is not None:
# Process has been TERMinated
break break
else: else:
log.debug(">>> SIGTERM has not worked even after waiting for 5 seconds. Using SIGKILL.") log.debug(">>> SIGTERM has not worked even after waiting for 5 seconds. Using SIGKILL.") # noqa
os.kill(self.command_process.pid, SIGKILL) os.kill(self.command_process.pid, SIGKILL)
self.command_process.wait() self.command_process.wait()
except: except:

View File

@@ -552,37 +552,37 @@ class NmapOptions(object):
opt, arg = result opt, arg = result
if opt in ("6", "A", "F", "h", "n", "R", "r", "V"): if opt in ("6", "A", "F", "h", "n", "R", "r", "V"):
self["-" + opt] = True self["-" + opt] = True
elif opt in (\ elif opt in (
"allports", "allports",
"append-output", "append-output",
"badsum", "badsum",
"defeat-rst-ratelimit", "defeat-rst-ratelimit",
"fuzzy", "fuzzy",
"help", "help",
"iflist", "iflist",
"log-errors", "log-errors",
"no-stylesheet", "no-stylesheet",
"open", "open",
"osscan-guess", "osscan-guess",
"osscan-limit", "osscan-limit",
"packet-trace", "packet-trace",
"privileged", "privileged",
"randomize-hosts", "randomize-hosts",
"reason", "reason",
"release-memory", "release-memory",
"script-trace", "script-trace",
"script-updatedb", "script-updatedb",
"send-eth", "send-eth",
"send-ip", "send-ip",
"system-dns", "system-dns",
"traceroute", "traceroute",
"unprivileged", "unprivileged",
"version", "version",
"version-all", "version-all",
"version-light", "version-light",
"version-trace", "version-trace",
"webxml", "webxml",
): ):
self["--" + opt] = True self["--" + opt] = True
elif opt in ("b", "D", "e", "g", "i", "iL", "m", "M", "o", "oA", "oG", elif opt in ("b", "D", "e", "g", "i", "iL", "m", "M", "o", "oA", "oG",
"oM", "oN", "oS", "oX", "p", "S", "sI"): "oM", "oN", "oS", "oX", "p", "S", "sI"):
@@ -591,43 +591,43 @@ class NmapOptions(object):
self["-" + opt] = arg self["-" + opt] = arg
else: else:
self.extras.extend(("-" + opt, arg)) self.extras.extend(("-" + opt, arg))
elif opt in (\ elif opt in (
"datadir", "datadir",
"data-length", "data-length",
"dns-servers", "dns-servers",
"exclude", "exclude",
"excludefile", "excludefile",
"host-timeout", "host-timeout",
"initial-rtt-timeout", "initial-rtt-timeout",
"ip-options", "ip-options",
"max-hostgroup", "max-hostgroup",
"max-os-tries", "max-os-tries",
"max-parallelism", "max-parallelism",
"max-rate", "max-rate",
"max-retries", "max-retries",
"max-rtt-timeout", "max-rtt-timeout",
"max-scan-delay", "max-scan-delay",
"min-hostgroup", "min-hostgroup",
"min-parallelism", "min-parallelism",
"min-rate", "min-rate",
"min-retries", "min-retries",
"min-rtt-timeout", "min-rtt-timeout",
"mtu", "mtu",
"port-ratio", "port-ratio",
"scan-delay", "scan-delay",
"scanflags", "scanflags",
"script", "script",
"script-args", "script-args",
"script-help", "script-help",
"servicedb", "servicedb",
"source-port", "source-port",
"spoof-mac", "spoof-mac",
"stylesheet", "stylesheet",
"top-ports", "top-ports",
"ttl", "ttl",
"versiondb", "versiondb",
"version-intensity", "version-intensity",
): ):
assert arg is not None assert arg is not None
if self["--" + opt] is None: if self["--" + opt] is None:
self["--" + opt] = arg self["--" + opt] = arg
@@ -795,11 +795,12 @@ class NmapOptions(object):
opt_list.extend((opt, self[opt])) opt_list.extend((opt, self[opt]))
for opt in ("--min-hostgroup", "--max-hostgroup", for opt in ("--min-hostgroup", "--max-hostgroup",
"--min-parallelism", "--max-parallelism", "--min-parallelism", "--max-parallelism",
"--min-rtt-timeout", "--max-rtt-timeout", "--initial-rtt-timeout", "--min-rtt-timeout", "--max-rtt-timeout",
"--scan-delay", "--max-scan-delay", "--initial-rtt-timeout",
"--min-rate", "--max-rate", "--scan-delay", "--max-scan-delay",
"--max-retries", "--max-os-tries", "--host-timeout"): "--min-rate", "--max-rate",
"--max-retries", "--max-os-tries", "--host-timeout"):
if self[opt] is not None: if self[opt] is not None:
opt_list.extend((opt, self[opt])) opt_list.extend((opt, self[opt]))
@@ -815,68 +816,68 @@ class NmapOptions(object):
elif self["-PB"]: elif self["-PB"]:
opt_list.append("-PB") opt_list.append("-PB")
for opt in (\ for opt in (
"--allports", "--allports",
"--append-output", "--append-output",
"--badsum", "--badsum",
"--defeat-rst-ratelimit", "--defeat-rst-ratelimit",
"--fuzzy", "--fuzzy",
"--help", "--help",
"--iflist", "--iflist",
"--log-errors", "--log-errors",
"--no-stylesheet", "--no-stylesheet",
"--open", "--open",
"--osscan-guess", "--osscan-guess",
"--osscan-limit", "--osscan-limit",
"--packet-trace", "--packet-trace",
"--privileged", "--privileged",
"-r", "-r",
"-R", "-R",
"--randomize-hosts", "--randomize-hosts",
"--reason", "--reason",
"--release-memory", "--release-memory",
"--script-trace", "--script-trace",
"--script-updatedb", "--script-updatedb",
"--send-eth", "--send-eth",
"--send-ip", "--send-ip",
"--system-dns", "--system-dns",
"--traceroute", "--traceroute",
"--unprivileged", "--unprivileged",
"--version", "--version",
"--version-all", "--version-all",
"--version-light", "--version-light",
"--version-trace", "--version-trace",
"--webxml", "--webxml",
): ):
if self[opt]: if self[opt]:
opt_list.append(opt) opt_list.append(opt)
for opt in (\ for opt in (
"-b", "-b",
"-D", "-D",
"--datadir", "--datadir",
"--data-length", "--data-length",
"--dns-servers", "--dns-servers",
"-e", "-e",
"--exclude", "--exclude",
"--excludefile", "--excludefile",
"-g", "-g",
"--ip-options", "--ip-options",
"--mtu", "--mtu",
"--port-ratio", "--port-ratio",
"-S", "-S",
"--scanflags", "--scanflags",
"--script", "--script",
"--script-args", "--script-args",
"--script-help", "--script-help",
"--servicedb", "--servicedb",
"--spoof-mac", "--spoof-mac",
"--stylesheet", "--stylesheet",
"--top-ports", "--top-ports",
"--ttl", "--ttl",
"--versiondb", "--versiondb",
"--version-intensity", "--version-intensity",
): ):
if self[opt] is not None: if self[opt] is not None:
opt_list.extend((opt, self[opt])) opt_list.extend((opt, self[opt]))

View File

@@ -133,15 +133,16 @@ class RecentScans(object):
except: except:
self.recent_scans_file = False self.recent_scans_file = False
if self.recent_scans_file and \ if (self.recent_scans_file and
(access(self.recent_scans_file, R_OK and W_OK) or \ (access(self.recent_scans_file, R_OK and W_OK) or
access(dirname(self.recent_scans_file), R_OK and W_OK)): access(dirname(self.recent_scans_file), R_OK and W_OK))):
self.using_file = True self.using_file = True
# Recovering saved targets # Recovering saved targets
recent_file = open(self.recent_scans_file, "r") recent_file = open(self.recent_scans_file, "r")
self.temp_list = [t for t in recent_file.read().split(";") \ self.temp_list = [
if t != "" and t != "\n"] t for t in recent_file.read().split(";")
if t != "" and t != "\n"]
recent_file.close() recent_file.close()
else: else:
self.using_file = False self.using_file = False

View File

@@ -233,19 +233,19 @@ def parse_script_args_dict(raw_argument):
if __name__ == '__main__': if __name__ == '__main__':
TESTS = ( TESTS = (
('', []), ('', []),
('a=b,c=d', [('a', 'b'), ('c', 'd')]), ('a=b,c=d', [('a', 'b'), ('c', 'd')]),
('a="b=c"', [('a', '"b=c"')]), ('a="b=c"', [('a', '"b=c"')]),
('a="def\\"ghi"', [('a', '"def\\"ghi"')]), ('a="def\\"ghi"', [('a', '"def\\"ghi"')]),
('a={one,{two,{three}}}', [('a', '{one,{two,{three}}}')]), ('a={one,{two,{three}}}', [('a', '{one,{two,{three}}}')]),
('a={"quoted}quoted"}', [('a', '{"quoted}quoted"}')]), ('a={"quoted}quoted"}', [('a', '{"quoted}quoted"}')]),
('a="unterminated', None), ('a="unterminated', None),
('user=foo,pass=",{}=bar",whois={whodb=nofollow+ripe},' ('user=foo,pass=",{}=bar",whois={whodb=nofollow+ripe},'
'userdb=C:\\Some\\Path\\To\\File', 'userdb=C:\\Some\\Path\\To\\File',
[('user', 'foo'), ('pass', '",{}=bar"'), [('user', 'foo'), ('pass', '",{}=bar"'),
('whois', '{whodb=nofollow+ripe}'), ('whois', '{whodb=nofollow+ripe}'),
('userdb', 'C:\\Some\\Path\\To\\File')]), ('userdb', 'C:\\Some\\Path\\To\\File')]),
) )
for test, expected in TESTS: for test, expected in TESTS:
args_dict = parse_script_args_dict(test) args_dict = parse_script_args_dict(test)

View File

@@ -277,11 +277,9 @@ class SearchResult(object):
log.debug("Match profile: %s" % profile) log.debug("Match profile: %s" % profile)
log.debug("Comparing: %s == %s ??" % ( log.debug("Comparing: %s == %s ??" % (
str(self.parsed_scan.profile_name).lower(), str(self.parsed_scan.profile_name).lower(),
"*%s*" % profile.lower())) "*%s*" % profile.lower()))
if profile == "*" or profile == "" or \ return (profile == "*" or profile == "" or
profile.lower() in str(self.parsed_scan.profile_name).lower(): profile.lower() in str(self.parsed_scan.profile_name).lower())
return True
return False
def match_option(self, option): def match_option(self, option):
log.debug("Match option: %s" % option) log.debug("Match option: %s" % option)
@@ -535,9 +533,9 @@ class SearchDir(SearchResult, object):
log.debug(">>> SearchDir initialized") log.debug(">>> SearchDir initialized")
self.search_directory = search_directory self.search_directory = search_directory
if type(file_extensions) in StringTypes: if isinstance(file_extensions, StringTypes):
self.file_extensions = file_extensions.split(";") self.file_extensions = file_extensions.split(";")
elif type(file_extensions) == type([]): elif isinstance(file_extensions, list):
self.file_extensions = file_extensions self.file_extensions = file_extensions
else: else:
raise Exception( raise Exception(

View File

@@ -134,15 +134,16 @@ class TargetList(object):
self.target_list_file = False self.target_list_file = False
#import pdb; pdb.set_trace() #import pdb; pdb.set_trace()
if self.target_list_file and \ if (self.target_list_file and
(access(self.target_list_file, R_OK and W_OK) or \ (access(self.target_list_file, R_OK and W_OK) or
access(dirname(self.target_list_file), R_OK and W_OK)): access(dirname(self.target_list_file), R_OK and W_OK))):
self.using_file = True self.using_file = True
# Recovering saved targets # Recovering saved targets
target_file = open(self.target_list_file, "r") target_file = open(self.target_list_file, "r")
self.temp_list = [t for t in target_file.read().split(";") \ self.temp_list = [
if t != "" and t != "\n"] t for t in target_file.read().split(";")
if t != "" and t != "\n"]
target_file.close() target_file.close()
else: else:
self.using_file = False self.using_file = False

View File

@@ -173,7 +173,7 @@ class SearchConfig(UmitConfigParser, object):
config_parser.set(self.section_name, p_name, value) config_parser.set(self.section_name, p_name, value)
def boolean_sanity(self, attr): def boolean_sanity(self, attr):
if attr == True or \ if attr is True or \
attr == "True" or \ attr == "True" or \
attr == "true" or \ attr == "true" or \
attr == "1": attr == "1":
@@ -192,18 +192,18 @@ class SearchConfig(UmitConfigParser, object):
return self._get_it("file_extension", "xml").split(";") return self._get_it("file_extension", "xml").split(";")
def set_file_extension(self, file_extension): def set_file_extension(self, file_extension):
if type(file_extension) == type([]): if isinstance(file_extension, list):
self._set_it("file_extension", ";".join(file_extension)) self._set_it("file_extension", ";".join(file_extension))
elif type(file_extension) in StringTypes: elif isinstance(file_extension, StringTypes):
self._set_it("file_extension", file_extension) self._set_it("file_extension", file_extension)
def get_save_time(self): def get_save_time(self):
return self._get_it("save_time", "60;days").split(";") return self._get_it("save_time", "60;days").split(";")
def set_save_time(self, save_time): def set_save_time(self, save_time):
if type(save_time) == type([]): if isinstance(save_time, list):
self._set_it("save_time", ";".join(save_time)) self._set_it("save_time", ";".join(save_time))
elif type(save_time) in StringTypes: elif isinstance(save_time, StringTypes):
self._set_it("save_time", save_time) self._set_it("save_time", save_time)
def get_store_results(self): def get_store_results(self):
@@ -413,8 +413,8 @@ class CommandProfile (Profile, object):
self._set_it(profile, 'description', description) self._set_it(profile, 'description', description)
def get_profile(self, profile_name): def get_profile(self, profile_name):
return {'profile': profile_name, \ return {'profile': profile_name,
'command': self.get_command(profile_name), \ 'command': self.get_command(profile_name),
'description': self.get_description(profile_name)} 'description': self.get_description(profile_name)}
@@ -428,10 +428,9 @@ class NmapOutputHighlight(object):
property_name = "%s_highlight" % p_name property_name = "%s_highlight" % p_name
try: try:
return self.sanity_settings([config_parser.get(property_name, return self.sanity_settings([
prop, config_parser.get(
True) \ property_name, prop, True) for prop in self.setts])
for prop in self.setts])
except: except:
settings = [] settings = []
prop_settings = self.default_highlights[p_name] prop_settings = self.default_highlights[p_name]
@@ -450,8 +449,8 @@ class NmapOutputHighlight(object):
property_name = "%s_highlight" % property_name property_name = "%s_highlight" % property_name
settings = self.sanity_settings(list(settings)) settings = self.sanity_settings(list(settings))
[config_parser.set(property_name, self.setts[pos], settings[pos]) \ for pos in xrange(len(settings)):
for pos in xrange(len(settings))] config_parser.set(property_name, self.setts[pos], settings[pos])
def sanity_settings(self, settings): def sanity_settings(self, settings):
"""This method tries to convert insane settings to sanity ones ;-) """This method tries to convert insane settings to sanity ones ;-)
@@ -481,7 +480,7 @@ class NmapOutputHighlight(object):
return settings return settings
def boolean_sanity(self, attr): def boolean_sanity(self, attr):
if attr == True or attr == "True" or attr == "true" or attr == "1": if attr is True or attr == "True" or attr == "true" or attr == "1":
return 1 return 1
return 0 return 0
@@ -546,7 +545,7 @@ class NmapOutputHighlight(object):
return True return True
def set_enable(self, enable): def set_enable(self, enable):
if enable == False or enable == "0" or enable is None or enable == "": if enable is False or enable == "0" or enable is None or enable == "":
config_parser.set( config_parser.set(
"output_highlight", "enable_highlight", str(False)) "output_highlight", "enable_highlight", str(False))
else: else:

View File

@@ -218,9 +218,9 @@ class About(HIGDialog):
self.vbox.pack_start(entry) self.vbox.pack_start(entry)
entry = _program_entry(APP_DISPLAY_NAME, APP_WEB_SITE, _( entry = _program_entry(APP_DISPLAY_NAME, APP_WEB_SITE, _(
"%s is a multi-platform graphical %s frontend and results viewer. " "%s is a multi-platform graphical %s frontend and results viewer. "
"It was originally derived from %s.") % ( "It was originally derived from %s.") % (
APP_DISPLAY_NAME, NMAP_DISPLAY_NAME, UMIT_DISPLAY_NAME)) APP_DISPLAY_NAME, NMAP_DISPLAY_NAME, UMIT_DISPLAY_NAME))
self.vbox.pack_start(entry) self.vbox.pack_start(entry)
entry = _program_entry(UMIT_DISPLAY_NAME, UMIT_WEB_SITE, _( entry = _program_entry(UMIT_DISPLAY_NAME, UMIT_WEB_SITE, _(

View File

@@ -130,7 +130,7 @@ from zenmapCore.UmitConf import is_maemo
from zenmapCore.UmitLogging import log from zenmapCore.UmitLogging import log
icon_names = ( icon_names = (
# Operating Systems # Operating Systems
'default', 'default',
'freebsd', 'freebsd',
'irix', 'irix',
@@ -142,7 +142,7 @@ icon_names = (
'ubuntu', 'ubuntu',
'unknown', 'unknown',
'win', 'win',
# Vulnerability Levels # Vulnerability Levels
'vl_1', 'vl_1',
'vl_2', 'vl_2',
'vl_3', 'vl_3',

View File

@@ -246,7 +246,7 @@ class ScanWindow(UmitScanWindow):
except: except:
about_icon = None about_icon = None
self.main_actions = [ \ self.main_actions = [
# Top level # Top level
('Scan', None, _('Sc_an'), None), ('Scan', None, _('Sc_an'), None),
@@ -580,7 +580,7 @@ class ScanWindow(UmitScanWindow):
if widget is None: if widget is None:
# Don't have a Print menu item for lack of support. # Don't have a Print menu item for lack of support.
return return
entry = self.scan_interface.scan_result.scan_result_notebook.nmap_output.get_active_entry() entry = self.scan_interface.scan_result.scan_result_notebook.nmap_output.get_active_entry() # noqa
widget.set_sensitive(entry is not None) widget.set_sensitive(entry is not None)
def _load_recent_scan(self, widget): def _load_recent_scan(self, widget):
@@ -771,8 +771,7 @@ This scan has not been run yet. Start the scan with the "Scan" button first.'))
try: try:
scan_interface.inventory.save_to_file( scan_interface.inventory.save_to_file(
saved_filename, selected_index, format) saved_filename, selected_index, format)
scan_interface.inventory.get_scans()[selected_index].unsaved = \ scan_interface.inventory.get_scans()[selected_index].unsaved = False # noqa
False
except (OSError, IOError), e: except (OSError, IOError), e:
alert = HIGAlertDialog( alert = HIGAlertDialog(
message_format=_("Can't save file"), message_format=_("Can't save file"),
@@ -916,7 +915,7 @@ This scan has not been run yet. Start the scan with the "Scan" button first.'))
def _print_cb(self, *args): def _print_cb(self, *args):
"""Show a print dialog.""" """Show a print dialog."""
entry = self.scan_interface.scan_result.scan_result_notebook.nmap_output.get_active_entry() entry = self.scan_interface.scan_result.scan_result_notebook.nmap_output.get_active_entry() # noqa
if entry is None: if entry is None:
return False return False
zenmapGUI.Print.run_print_operation( zenmapGUI.Print.run_print_operation(

View File

@@ -297,7 +297,7 @@ class HighlightProperty(object):
"clicked", self.highlight_color_dialog_ok, color_dialog) "clicked", self.highlight_color_dialog_ok, color_dialog)
color_dialog.cancel_button.connect( color_dialog.cancel_button.connect(
"clicked", self.highlight_color_dialog_cancel, "clicked", self.highlight_color_dialog_cancel,
color_dialog) color_dialog)
color_dialog.connect( color_dialog.connect(
"delete-event", self.highlight_color_dialog_close, "delete-event", self.highlight_color_dialog_close,
color_dialog) color_dialog)

View File

@@ -372,7 +372,8 @@ class NmapOutputViewer (gtk.VBox):
buf.insert(buf.get_end_iter(), new_output) buf.insert(buf.get_end_iter(), new_output)
# Highlight the new text. # Highlight the new text.
self.apply_highlighting( self.apply_highlighting(
buf.get_iter_at_mark(prev_end_mark), buf.get_end_iter()) buf.get_iter_at_mark(prev_end_mark),
buf.get_end_iter())
except MemoryError: except MemoryError:
self.show_large_output_message(self.command_execution) self.show_large_output_message(self.command_execution)
return return

View File

@@ -145,19 +145,19 @@ from zenmapGUI.ScriptInterface import *
def get_option_check_auxiliary_widget(option, ops, check): def get_option_check_auxiliary_widget(option, ops, check):
if option in ("-sI", "-b", "--script", "--script-args", "--exclude", "-p", if option in ("-sI", "-b", "--script", "--script-args", "--exclude", "-p",
"-D", "-S", "--source-port", "-e", "--ttl", "-iR", "--max-retries", "-D", "-S", "--source-port", "-e", "--ttl", "-iR", "--max-retries",
"--host-timeout", "--max-rtt-timeout", "--min-rtt-timeout", "--host-timeout", "--max-rtt-timeout", "--min-rtt-timeout",
"--initial-rtt-timeout", "--max-hostgroup", "--min-hostgroup", "--initial-rtt-timeout", "--max-hostgroup", "--min-hostgroup",
"--max-parallelism", "--min-parallelism", "--max-scan-delay", "--max-parallelism", "--min-parallelism", "--max-scan-delay",
"--scan-delay", "-PA", "-PS", "-PU", "-PO", "-PY"): "--scan-delay", "-PA", "-PS", "-PU", "-PO", "-PY"):
return OptionEntry(option, ops, check) return OptionEntry(option, ops, check)
elif option in ("-d", "-v"): elif option in ("-d", "-v"):
return OptionLevel(option, ops, check) return OptionLevel(option, ops, check)
elif option in ("--excludefile", "-iL"): elif option in ("--excludefile", "-iL"):
return OptionFile(option, ops, check) return OptionFile(option, ops, check)
elif option in ("-A", "-O", "-sV", "-n", "-6", "-Pn", "-PE", "-PP", "-PM", elif option in ("-A", "-O", "-sV", "-n", "-6", "-Pn", "-PE", "-PP", "-PM",
"-PB", "-sC", "--script-trace", "-F", "-f", "--packet-trace", "-r", "-PB", "-sC", "--script-trace", "-F", "-f", "--packet-trace", "-r",
"--traceroute"): "--traceroute"):
return None return None
elif option in ("",): elif option in ("",):
return OptionExtras(option, ops, check) return OptionExtras(option, ops, check)
@@ -496,9 +496,8 @@ class OptionBuilder(object):
return dic return dic
def __parse_groups(self): def __parse_groups(self):
return [g_name.getAttribute(u'name') for g_name in \ return [g_name.getAttribute(u'name') for g_name in
self.xml.getElementsByTagName(u'groups')[0].\ self.xml.getElementsByTagName(u'groups')[0].getElementsByTagName(u'group')] # noqa
getElementsByTagName(u'group')]
def __parse_tabs(self): def __parse_tabs(self):
dic = {} dic = {}

View File

@@ -342,7 +342,7 @@ class ProfileEditor(HIGWindow):
log.debug(">>> Tab name: %s" % tab_name) log.debug(">>> Tab name: %s" % tab_name)
log.debug(">>>Creating profile editor section: %s" % section_name) log.debug(">>>Creating profile editor section: %s" % section_name)
vbox = HIGVBox() vbox = HIGVBox()
if tab.notscripttab: # if notscripttab is set if tab.notscripttab: # if notscripttab is set
table = HIGTable() table = HIGTable()
table.set_row_spacings(2) table.set_row_spacings(2)
section = HIGSectionLabel(section_name) section = HIGSectionLabel(section_name)
@@ -374,13 +374,14 @@ class ProfileEditor(HIGWindow):
command = self.ops.render_string() command = self.ops.render_string()
buf = self.profile_description_text.get_buffer() buf = self.profile_description_text.get_buffer()
description = buf.get_text(buf.get_start_iter(),\ description = buf.get_text(
buf.get_end_iter()) buf.get_start_iter(), buf.get_end_iter())
try: try:
self.profile.add_profile(profile_name,\ self.profile.add_profile(
command=command,\ profile_name,
description=description) command=command,
description=description)
except ValueError: except ValueError:
alert = HIGAlertDialog( alert = HIGAlertDialog(
message_format=_('Disallowed profile name'), message_format=_('Disallowed profile name'),

View File

@@ -323,7 +323,7 @@ class ScanInterface(HIGVBox):
def go_to_host(self, hostname): def go_to_host(self, hostname):
"""Scroll the text output to the appearance of the named host.""" """Scroll the text output to the appearance of the named host."""
self.scan_result.scan_result_notebook.nmap_output.nmap_output.go_to_host(hostname) self.scan_result.scan_result_notebook.nmap_output.nmap_output.go_to_host(hostname) # noqa
def __create_toolbar(self): def __create_toolbar(self):
self.toolbar = ScanToolbar() self.toolbar = ScanToolbar()
@@ -456,7 +456,7 @@ class ScanInterface(HIGVBox):
def update_cancel_button(self): def update_cancel_button(self):
"""Make the Cancel button sensitive or not depending on whether the """Make the Cancel button sensitive or not depending on whether the
currently displayed scan is running.""" currently displayed scan is running."""
entry = self.scan_result.scan_result_notebook.nmap_output.get_active_entry() entry = self.scan_result.scan_result_notebook.nmap_output.get_active_entry() # noqa
if entry is None: if entry is None:
self.toolbar.cancel_button.set_sensitive(False) self.toolbar.cancel_button.set_sensitive(False)
else: else:
@@ -464,7 +464,7 @@ class ScanInterface(HIGVBox):
def _cancel_scan_cb(self, widget): def _cancel_scan_cb(self, widget):
"""Cancel the scan whose output is shown.""" """Cancel the scan whose output is shown."""
entry = self.scan_result.scan_result_notebook.nmap_output.get_active_entry() entry = self.scan_result.scan_result_notebook.nmap_output.get_active_entry() # noqa
if entry is not None and entry.running: if entry is not None and entry.running:
self.cancel_scan(entry.command) self.cancel_scan(entry.command)
@@ -472,14 +472,14 @@ class ScanInterface(HIGVBox):
"""This is like _cancel_scan_cb, but it cancels the scans that are """This is like _cancel_scan_cb, but it cancels the scans that are
currently selected in the scans list, not the one whose output is currently selected in the scans list, not the one whose output is
currently shown.""" currently shown."""
model, selection = self.scan_result.scan_result_notebook.scans_list.scans_list.get_selection().get_selected_rows() model, selection = self.scan_result.scan_result_notebook.scans_list.scans_list.get_selection().get_selected_rows() # noqa
for path in selection: for path in selection:
entry = model.get_value(model.get_iter(path), 0) entry = model.get_value(model.get_iter(path), 0)
if entry.running: if entry.running:
self.cancel_scan(entry.command) self.cancel_scan(entry.command)
def _remove_scan_cb(self, widget): def _remove_scan_cb(self, widget):
model, selection = self.scan_result.scan_result_notebook.scans_list.scans_list.get_selection().get_selected_rows() model, selection = self.scan_result.scan_result_notebook.scans_list.scans_list.get_selection().get_selected_rows() # noqa
selected_refs = [] selected_refs = []
for path in selection: for path in selection:
# Kill running scans and remove finished scans from the inventory. # Kill running scans and remove finished scans from the inventory.
@@ -656,7 +656,7 @@ class ScanInterface(HIGVBox):
try: try:
parsed.nmap_output = command.get_output() parsed.nmap_output = command.get_output()
except MemoryError: except MemoryError:
self.scan_result.scan_result_notebook.nmap_output.nmap_output.show_large_output_message(command) self.scan_result.scan_result_notebook.nmap_output.nmap_output.show_large_output_message(command) # noqa
self.update_ui() self.update_ui()
self.scans_store.finish_running_scan(command, parsed) self.scans_store.finish_running_scan(command, parsed)
@@ -839,7 +839,8 @@ class ScanInterface(HIGVBox):
host.comment = comment host.comment = comment
for scan in self.inventory.get_scans(): for scan in self.inventory.get_scans():
for h in scan.get_hosts(): for h in scan.get_hosts():
if h.get_ip() == host.get_ip() and h.get_ipv6() == host.get_ipv6(): if (h.get_ip() == host.get_ip() and
h.get_ipv6() == host.get_ipv6()):
h.set_comment(host.comment) h.set_comment(host.comment)
scan.unsaved = True scan.unsaved = True
break break
@@ -929,10 +930,10 @@ class ScanResult(gtk.HPaned):
self.pack2(self.scan_result_notebook, True, False) self.pack2(self.scan_result_notebook, True, False)
def set_nmap_output(self, msg): def set_nmap_output(self, msg):
self.scan_result_notebook.nmap_output.nmap_output.text_view.get_buffer().set_text(msg) self.scan_result_notebook.nmap_output.nmap_output.text_view.get_buffer().set_text(msg) # noqa
def clear_nmap_output(self): def clear_nmap_output(self):
self.scan_result_notebook.nmap_output.nmap_output.text_view.get_buffer().set_text("") self.scan_result_notebook.nmap_output.nmap_output.text_view.get_buffer().set_text("") # noqa
def get_host_selection(self): def get_host_selection(self):
return self.scan_host_view.host_view.get_selection() return self.scan_host_view.host_view.get_selection()

View File

@@ -358,8 +358,8 @@ class HostOpenPorts(HIGVBox):
self.port_columns['hostname'].set_visible(False) self.port_columns['hostname'].set_visible(False)
self.scroll_ports_hosts.set_policy(gtk.POLICY_AUTOMATIC,\ self.scroll_ports_hosts.set_policy(
gtk.POLICY_AUTOMATIC) gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
def port_mode(self): def port_mode(self):
child = self.scroll_ports_hosts.get_child() child = self.scroll_ports_hosts.get_child()

View File

@@ -313,16 +313,16 @@ class ScriptInterface:
status = process.scan_state() status = process.scan_state()
except: except:
status = None status = None
log.debug("Script interface: script_list_timer_callback %s" % \ log.debug("Script interface: script_list_timer_callback %s" %
repr(status)) repr(status))
if status == True: if status is True:
# Still running, schedule this timer to check again. # Still running, schedule this timer to check again.
return True return True
self.script_list_widget.set_sensitive(True) self.script_list_widget.set_sensitive(True)
if status == False: if status is False:
# Finished with success. # Finished with success.
callback(True, process) callback(True, process)
else: else:

View File

@@ -167,8 +167,8 @@ class HIGAlertDialog(gtk.MessageDialog):
# "Alert windows have no titles, as the title would usually # "Alert windows have no titles, as the title would usually
# unnecessarily duplicate the alert's primary text" # unnecessarily duplicate the alert's primary text"
self.set_title("") self.set_title("")
self.set_markup("<span weight='bold'size='larger'>%s</span>" \ self.set_markup(
% message_format) "<span weight='bold'size='larger'>%s</span>" % message_format)
if secondary_text: if secondary_text:
# GTK up to version 2.4 does not have secondary_text # GTK up to version 2.4 does not have secondary_text
try: try:

View File

@@ -198,15 +198,11 @@ class HIGSpinnerImages:
self.animated_pixbufs = new_animated self.animated_pixbufs = new_animated
for k in self.static_pixbufs: for k in self.static_pixbufs:
self.static_pixbufs[k] = self.static_pixbufs[k].\ self.static_pixbufs[k] = self.static_pixbufs[k].scale_simple(
scale_simple(width, width, height, gtk.gdk.INTERP_BILINEAR)
height,
gtk.gdk.INTERP_BILINEAR)
self.rest_pixbuf = self.rest_pixbuf.\ self.rest_pixbuf = self.rest_pixbuf.scale_simple(
scale_simple(width, width, height, gtk.gdk.INTERP_BILINEAR)
height,
gtk.gdk.INTERP_BILINEAR)
self.images_width = width self.images_width = width
self.images_height = height self.images_height = height
@@ -275,8 +271,8 @@ class HIGSpinnerCache:
for x in range(0, grid_width, size): for x in range(0, grid_width, size):
for y in range(0, grid_height, size): for y in range(0, grid_height, size):
self.spinner_images.add_animated_pixbuf(\ self.spinner_images.add_animated_pixbuf(
self.__extract_frame(grid_pixbuf, x, y, size, size)) self.__extract_frame(grid_pixbuf, x, y, size, size))
def load_static_from_lookup(self, icon_name="gnome-spinner-rest", def load_static_from_lookup(self, icon_name="gnome-spinner-rest",
key_name=None): key_name=None):