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

Merge #2088: Update Zenmap to Python 3 and PyGObject

Note: Ndiff build will be broken until subsequent changes are made.
Deprecation warnings will need to be addressed in future changes.
Closes #2088
This commit is contained in:
dmiller
2022-12-07 20:34:03 +00:00
parent e2e55660c3
commit 24b26317c7
104 changed files with 5381 additions and 4383 deletions

View File

@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#!/usr/bin/env python3
# ***********************IMPORTANT NMAP LICENSE TERMS************************
# * *
@@ -58,8 +57,11 @@
# * *
# ***************************************************************************/
import gobject
import gtk
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, GObject, GLib
import os
import os.path
import sys
@@ -94,11 +96,12 @@ class ScanChooser(HIGVBox):
has changed."""
__gsignals__ = {
"changed": (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ())
"changed": (GObject.SignalFlags.RUN_FIRST, GObject.TYPE_NONE, ())
}
def __init__(self, scans, title):
self.__gobject_init__()
HIGVBox.__init__(self)
self.title = title
self.scan_dict = {}
@@ -126,13 +129,12 @@ class ScanChooser(HIGVBox):
self.lbl_scan = HIGSectionLabel(self.title)
self.hbox = HIGHBox()
self.table = HIGTable()
self.list_scan = gtk.ListStore(str)
self.combo_scan = gtk.ComboBoxEntry(self.list_scan, 0)
self.btn_open_scan = gtk.Button(stock=gtk.STOCK_OPEN)
self.exp_scan = gtk.Expander(_("Scan Output"))
self.scrolled = gtk.ScrolledWindow()
self.txt_scan_result = gtk.TextView()
self.txg_tag = gtk.TextTag("scan_style")
self.combo_scan = Gtk.ComboBoxText.new_with_entry()
self.btn_open_scan = Gtk.Button.new_from_stock(Gtk.STOCK_OPEN)
self.exp_scan = Gtk.Expander.new(_("Scan Output"))
self.scrolled = Gtk.ScrolledWindow()
self.txt_scan_result = Gtk.TextView()
self.txg_tag = Gtk.TextTag.new("scan_style")
def get_buffer(self):
return self.txt_scan_result.get_buffer()
@@ -166,14 +168,14 @@ class ScanChooser(HIGVBox):
self.scrolled.add_with_viewport(self.txt_scan_result)
# Setting scrolled window
self.scrolled.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
self.scrolled.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
def _set_text_view(self):
self.txg_table = self.txt_scan_result.get_buffer().get_tag_table()
self.txg_table.add(self.txg_tag)
self.txg_tag.set_property("family", "Monospace")
self.txt_scan_result.set_wrap_mode(gtk.WRAP_WORD)
self.txt_scan_result.set_wrap_mode(Gtk.WrapMode.WORD)
self.txt_scan_result.set_editable(False)
self.txt_scan_result.get_buffer().connect(
"changed", self._text_changed_cb)
@@ -187,7 +189,7 @@ class ScanChooser(HIGVBox):
response = file_chooser.run()
file_chosen = file_chooser.get_filename()
file_chooser.destroy()
if response == gtk.RESPONSE_OK:
if response == Gtk.ResponseType.OK:
try:
parser = NmapParser()
parser.parse_file(file_chosen)
@@ -214,7 +216,7 @@ class ScanChooser(HIGVBox):
scan_name = os.path.split(file_chosen)[-1]
self.add_scan(scan_name, parser)
self.combo_scan.set_active(len(self.list_scan) - 1)
self.combo_scan.set_active(len(self.combo_scan.get_model()) - 1)
def add_scan(self, scan_name, parser):
scan_id = 1
@@ -223,7 +225,7 @@ class ScanChooser(HIGVBox):
new_scan_name = "%s (%s)" % (scan_name, scan_id)
scan_id += 1
self.list_scan.append([new_scan_name])
self.combo_scan.append_text(new_scan_name)
self.scan_dict[new_scan_name] = parser
def _text_changed_cb(self, widget):
@@ -234,7 +236,7 @@ class ScanChooser(HIGVBox):
def get_parsed_scan(self):
"""Return the currently selected scan's parsed output as an NmapParser
object, or None if no valid scan is selected."""
selected_scan = self.combo_scan.child.get_text()
selected_scan = self.combo_scan.get_active_text()
return self.scan_dict.get(selected_scan)
def get_nmap_output(self):
@@ -249,9 +251,9 @@ class ScanChooser(HIGVBox):
parsed_scan = property(get_parsed_scan)
class DiffWindow(gtk.Window):
class DiffWindow(Gtk.Window):
def __init__(self, scans):
gtk.Window.__init__(self)
Gtk.Window.__init__(self)
self.set_title(_("Compare Results"))
self.ndiff_process = None
# We allow the user to start a new diff before the old one has
@@ -265,11 +267,11 @@ class DiffWindow(gtk.Window):
self.diff_view = DiffView()
self.diff_view.set_size_request(-1, 100)
self.hbox_buttons = HIGHBox()
self.progress = gtk.ProgressBar()
self.btn_close = HIGButton(stock=gtk.STOCK_CLOSE)
self.progress = Gtk.ProgressBar()
self.btn_close = HIGButton(stock=Gtk.STOCK_CLOSE)
self.hbox_selection = HIGHBox()
self.scan_chooser_a = ScanChooser(scans, _(u"A Scan"))
self.scan_chooser_b = ScanChooser(scans, _(u"B Scan"))
self.scan_chooser_a = ScanChooser(scans, _("A Scan"))
self.scan_chooser_b = ScanChooser(scans, _("B Scan"))
self._pack_widgets()
self._connect_widgets()
@@ -282,20 +284,20 @@ class DiffWindow(gtk.Window):
def _pack_widgets(self):
self.main_vbox.set_border_width(6)
self.hbox_selection.pack_start(self.scan_chooser_a, True, True)
self.hbox_selection.pack_start(self.scan_chooser_b, True, True)
self.hbox_selection.pack_start(self.scan_chooser_a, True, True, 0)
self.hbox_selection.pack_start(self.scan_chooser_b, True, True, 0)
self.main_vbox.pack_start(self.hbox_selection, False)
self.main_vbox.pack_start(self.hbox_selection, False, True, 0)
scroll = gtk.ScrolledWindow()
scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
scroll = Gtk.ScrolledWindow()
scroll.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
scroll.add(self.diff_view)
self.main_vbox.pack_start(scroll, True, True)
self.main_vbox.pack_start(scroll, True, True, 0)
self.progress.hide()
self.progress.set_no_show_all(True)
self.hbox_buttons.pack_start(self.progress, False)
self.hbox_buttons.pack_end(self.btn_close, False)
self.hbox_buttons.pack_start(self.progress, False, True, 0)
self.hbox_buttons.pack_end(self.btn_close, False, True, 0)
self.main_vbox._pack_noexpand_nofill(self.hbox_buttons)
@@ -337,7 +339,7 @@ class DiffWindow(gtk.Window):
else:
self.progress.show()
if self.timer_id is None:
self.timer_id = gobject.timeout_add(
self.timer_id = GLib.timeout_add(
NDIFF_CHECK_TIMEOUT, self.check_ndiff_process)
def check_ndiff_process(self):
@@ -362,7 +364,7 @@ class DiffWindow(gtk.Window):
if status == 0 or status == 1:
# Successful completion.
try:
diff = self.ndiff_process.get_scan_diff()
diff = self.ndiff_process.get_scan_diff().decode("utf-8")
except zenmapCore.Diff.NdiffParseException as e:
alert = HIGAlertDialog(
message_format=_("Error parsing ndiff output"),
@@ -401,13 +403,13 @@ class DiffWindow(gtk.Window):
self.destroy()
class DiffView(gtk.TextView):
class DiffView(Gtk.TextView):
REMOVE_COLOR = "#ffaaaa"
ADD_COLOR = "#ccffcc"
"""A widget displaying a zenmapCore.Diff.ScanDiff."""
def __init__(self):
gtk.TextView.__init__(self)
Gtk.TextView.__init__(self)
self.set_editable(False)
buff = self.get_buffer()
@@ -418,7 +420,7 @@ class DiffView(gtk.TextView):
buff.create_tag("+", font="Monospace", background=self.ADD_COLOR)
def clear(self):
self.get_buffer().set_text(u"")
self.get_buffer().set_text("")
def show_diff(self, diff):
self.clear()
@@ -451,6 +453,6 @@ if __name__ == "__main__":
"Parsed 4": parsed4})
dw.show_all()
dw.connect("delete-event", lambda x, y: gtk.main_quit())
dw.connect("delete-event", lambda x, y: Gtk.main_quit())
gtk.main()
Gtk.main()