1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-06 12:41: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,10 +57,12 @@
# * *
# ***************************************************************************/
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, Gdk, Pango, GLib
import gobject
import gtk
import gtk.gdk
import pango
import re
import zenmapCore.I18N # lgtm[py/unused-import]
@@ -71,13 +72,13 @@ from zenmapCore.UmitConf import NmapOutputHighlight
from zenmapGUI.NmapOutputProperties import NmapOutputProperties
class NmapOutputViewer (gtk.VBox):
class NmapOutputViewer(Gtk.Box):
HIGHLIGHT_PROPERTIES = ["details", "date", "hostname", "ip", "port_list",
"open_port", "closed_port", "filtered_port"]
def __init__(self, refresh=1, stop=1):
self.nmap_highlight = NmapOutputHighlight()
gtk.VBox.__init__(self)
Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL)
# Creating widgets
self.__create_widgets()
@@ -95,7 +96,7 @@ class NmapOutputViewer (gtk.VBox):
self.refreshing = True
# Adding widgets to the VBox
self.pack_start(self.scrolled, expand=True, fill=True)
self.pack_start(self.scrolled, True, True, 0)
# The NmapCommand instance, if any, whose output is shown in this
# display.
@@ -105,17 +106,17 @@ class NmapOutputViewer (gtk.VBox):
def __create_widgets(self):
# Creating widgets
self.scrolled = gtk.ScrolledWindow()
self.text_view = gtk.TextView()
self.scrolled = Gtk.ScrolledWindow()
self.text_view = Gtk.TextView()
def __set_scrolled_window(self):
# Seting scrolled window
self.scrolled.set_border_width(5)
self.scrolled.add(self.text_view)
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.text_view.set_wrap_mode(gtk.WRAP_WORD)
self.text_view.set_wrap_mode(Gtk.WrapMode.WORD)
self.text_view.set_editable(False)
self.tag_font = self.text_view.get_buffer().create_tag(None)
@@ -125,29 +126,27 @@ class NmapOutputViewer (gtk.VBox):
tag = self.text_view.get_buffer().create_tag(property)
if settings[0]:
tag.set_property("weight", pango.WEIGHT_HEAVY)
tag.set_property("weight", Pango.Weight.HEAVY)
else:
tag.set_property("weight", pango.WEIGHT_NORMAL)
tag.set_property("weight", Pango.Weight.NORMAL)
if settings[1]:
tag.set_property("style", pango.STYLE_ITALIC)
tag.set_property("style", Pango.Style.ITALIC)
else:
tag.set_property("style", pango.STYLE_NORMAL)
tag.set_property("style", Pango.Style.NORMAL)
if settings[2]:
tag.set_property("underline", pango.UNDERLINE_SINGLE)
tag.set_property("underline", Pango.Underline.SINGLE)
else:
tag.set_property("underline", pango.UNDERLINE_NONE)
tag.set_property("underline", Pango.Underline.NONE)
text_color = settings[3]
highlight_color = settings[4]
tag.set_property(
"foreground", gtk.color_selection_palette_to_string(
[gtk.gdk.Color(*text_color), ]))
"foreground", Gdk.Color(*text_color).to_string())
tag.set_property(
"background", gtk.color_selection_palette_to_string(
[gtk.gdk.Color(*highlight_color), ]))
"background", Gdk.Color(*highlight_color).to_string())
def go_to_host(self, host):
"""Go to host line on nmap output result"""
@@ -155,7 +154,7 @@ class NmapOutputViewer (gtk.VBox):
start_iter = buff.get_start_iter()
found_tuple = start_iter.forward_search(
"\nNmap scan report for %s\n" % host, gtk.TEXT_SEARCH_TEXT_ONLY
"\nNmap scan report for %s\n" % host, Gtk.TextSearchFlags.TEXT_ONLY
)
if found_tuple is None:
return
@@ -219,7 +218,7 @@ class NmapOutputViewer (gtk.VBox):
if not self.nmap_highlight.enable:
return
text = buf.get_text(start_iter, end_iter)
text = buf.get_text(start_iter, end_iter, include_hidden_chars=True)
for property in self.HIGHLIGHT_PROPERTIES:
settings = self.nmap_highlight.__getattribute__(property)
@@ -243,7 +242,7 @@ class NmapOutputViewer (gtk.VBox):
The current output is extracted from the command object."""
self.command_execution = command
if command is not None:
self.text_view.get_buffer().set_text(u"")
self.text_view.get_buffer().set_text("")
self.output_file_pointer = 0
else:
self.output_file_pointer = None
@@ -297,7 +296,7 @@ class NmapOutputViewer (gtk.VBox):
v_adj = self.scrolled.get_vadjustment()
if new_output and v_adj is not None:
# Find out if the view is already scrolled to the bottom.
at_end = (v_adj.value >= v_adj.upper - v_adj.page_size)
at_end = (v_adj.get_value() >= v_adj.get_upper() - v_adj.get_page_size())
buf = self.text_view.get_buffer()
prev_end_mark = buf.create_mark(
@@ -318,6 +317,6 @@ class NmapOutputViewer (gtk.VBox):
# text causes a scroll bar to appear and reflow the text,
# making the text a bit taller.
self.text_view.scroll_mark_onscreen(self.end_mark)
gobject.idle_add(
GLib.idle_add(
lambda: self.text_view.scroll_mark_onscreen(
self.end_mark))