def __do_layout(self):
        """
        Layout widgets in window.
        """
        main_vbox = HIGVBox()
        main_vbox.set_border_width(5)
        main_vbox.set_spacing(12)
        header_hbox = HIGHBox()
        schema_table = HIGTable()
        auth_table = HIGTable()
        btns_hbox = HIGHBox()

        header_hbox._pack_expand_fill(self.ttitle)
        header_hbox._pack_noexpand_nofill(self.umit_logo)

        # schema name
        schema_table.attach_label(self.schema_name_lbl, 0, 1, 0, 1)
        schema_table.attach_entry(self.schema_name, 1, 2, 0, 1)

        # smtp server
        schema_table.attach_label(self.smtp_server_lbl, 0, 1, 1, 2)
        schema_table.attach_entry(self.smtp_server, 1, 2, 1, 2)

        # smtp server port
        schema_table.attach_label(self.smtp_port_lbl, 0, 1, 2, 3)
        schema_table.attach_entry(self.smtp_port, 1, 2, 2, 3)

        # smtp mail from
        schema_table.attach_label(self.smtp_mailfrom_lbl, 0, 1, 3, 4)
        schema_table.attach_entry(self.smtp_mailfrom, 1, 2, 3, 4)

        # smtp user
        auth_table.attach_label(self.smtp_login_lbl, 0, 1, 0, 1)
        auth_table.attach_entry(self.smtp_login, 1, 2, 0, 1)

        # smtp passwd
        auth_table.attach_label(self.smtp_passwd_lbl, 0, 1, 1, 2)
        auth_table.attach_label(self.smtp_passwd, 1, 2, 1, 2)

        # bottom buttons
        btns_hbox.set_homogeneous(True)
        btns_hbox._pack_expand_fill(self.help)
        btns_hbox._pack_expand_fill(hig_box_space_holder())
        btns_hbox._pack_expand_fill(self.apply)
        btns_hbox._pack_expand_fill(self.cancel)
        btns_hbox._pack_expand_fill(self.ok)

        main_vbox._pack_noexpand_nofill(header_hbox)
        main_vbox._pack_noexpand_nofill(gtk.HSeparator())
        main_vbox._pack_noexpand_nofill(schema_table)
        main_vbox._pack_noexpand_nofill(gtk.HSeparator())
        main_vbox._pack_noexpand_nofill(self.smtp_need_auth)
        main_vbox._pack_noexpand_nofill(auth_table)
        main_vbox._pack_noexpand_nofill(gtk.HSeparator())
        main_vbox._pack_noexpand_nofill(self.smtp_encrypt_tls)
        main_vbox.pack_end(btns_hbox, False, False, 0)

        self.add(main_vbox)
Example #2
0
    def __do_layout(self):
        """
        Layout widgets in window.
        """
        main_vbox = HIGVBox()
        main_vbox.set_border_width(5)
        main_vbox.set_spacing(12)
        header_hbox = HIGHBox()
        schema_table = HIGTable()
        auth_table = HIGTable()
        btns_hbox = HIGHBox()

        header_hbox._pack_expand_fill(self.ttitle)
        header_hbox._pack_noexpand_nofill(self.umit_logo)
        
        # schema name
        schema_table.attach_label(self.schema_name_lbl, 0, 1, 0, 1)
        schema_table.attach_entry(self.schema_name, 1, 2, 0, 1)
        
        # smtp server
        schema_table.attach_label(self.smtp_server_lbl, 0, 1, 1, 2)
        schema_table.attach_entry(self.smtp_server, 1, 2, 1, 2)

        # smtp server port
        schema_table.attach_label(self.smtp_port_lbl, 0, 1, 2, 3)
        schema_table.attach_entry(self.smtp_port, 1, 2, 2, 3)
        
        # smtp mail from
        schema_table.attach_label(self.smtp_mailfrom_lbl, 0, 1, 3, 4)
        schema_table.attach_entry(self.smtp_mailfrom, 1, 2, 3, 4)
        
        # smtp user
        auth_table.attach_label(self.smtp_login_lbl, 0, 1, 0, 1)
        auth_table.attach_entry(self.smtp_login, 1, 2, 0, 1)
        
        # smtp passwd
        auth_table.attach_label(self.smtp_passwd_lbl, 0, 1, 1, 2)
        auth_table.attach_label(self.smtp_passwd, 1, 2, 1, 2)
        
        # bottom buttons
        btns_hbox.set_homogeneous(True)
        btns_hbox._pack_expand_fill(self.help)
        btns_hbox._pack_expand_fill(hig_box_space_holder())
        btns_hbox._pack_expand_fill(self.apply)
        btns_hbox._pack_expand_fill(self.cancel)
        btns_hbox._pack_expand_fill(self.ok)
                
        main_vbox._pack_noexpand_nofill(header_hbox)
        main_vbox._pack_noexpand_nofill(gtk.HSeparator())
        main_vbox._pack_noexpand_nofill(schema_table)
        main_vbox._pack_noexpand_nofill(gtk.HSeparator())
        main_vbox._pack_noexpand_nofill(self.smtp_need_auth)
        main_vbox._pack_noexpand_nofill(auth_table)
        main_vbox._pack_noexpand_nofill(gtk.HSeparator())
        main_vbox._pack_noexpand_nofill(self.smtp_encrypt_tls)
        main_vbox.pack_end(btns_hbox, False, False, 0)
        
        self.add(main_vbox)
Example #3
0
class DiffLegendWindow(HIGDialog, object):
    def __init__(self, colors):
        # Shows colors and chars legend
        HIGDialog.__init__(self,
                           title=_('Color Descriptions'),
                           buttons=(gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))

        self.colors = colors
        self._create_widgets()
        self._pack_widgets()
        self._connect_widgets()

    def _create_widgets(self):
        self.table = HIGTable()

        self.unchanged_button = gtk.ColorButton(self.colors.unchanged)
        self.unchanged_label = gtk.Label(
            _("Property remained <b>U</b>nchanged"))

        self.added_button = gtk.ColorButton(self.colors.added)
        self.added_label = gtk.Label(_("Property was <b>A</b>dded"))

        self.modified_button = gtk.ColorButton(self.colors.modified)
        self.modified_label = gtk.Label(_("Property was <b>M</b>odified"))

        self.not_present_button = gtk.ColorButton(self.colors.not_present)
        self.not_present_label = gtk.Label(_("Property is <b>N</b>ot present"))

    def _pack_widgets(self):
        self.unchanged_label.set_use_markup(True)
        self.added_label.set_use_markup(True)
        self.modified_label.set_use_markup(True)
        self.not_present_label.set_use_markup(True)

        self.table.attach_label(self.unchanged_button, 0, 1, 0, 1)
        self.table.attach_entry(self.unchanged_label, 1, 2, 0, 1)

        self.table.attach_label(self.added_button, 0, 1, 1, 2)
        self.table.attach_entry(self.added_label, 1, 2, 1, 2)

        self.table.attach_label(self.modified_button, 0, 1, 2, 3)
        self.table.attach_entry(self.modified_label, 1, 2, 2, 3)

        self.table.attach_label(self.not_present_button, 0, 1, 3, 4)
        self.table.attach_entry(self.not_present_label, 1, 2, 3, 4)

        self.vbox.pack_start(self.table)
        self.vbox.show_all()

    def _connect_widgets(self):
        self.unchanged_button.connect("color-set", self.set_color, "unchanged")
        self.added_button.connect("color-set", self.set_color, "added")
        self.modified_button.connect("color-set", self.set_color, "modified")
        self.not_present_button.connect("color-set", self.set_color,
                                        "not_present")

    def set_color(self, widget, prop):
        self.colors.__setattr__(prop, widget.get_color())
Example #4
0
class DiffColors(TabBox, object):
    def __init__(self, colors):
        self.colors = colors
        TabBox.__init__(self, _('Diff Colors'))
        self._pack_widgets()
        self._connect_widgets()

    def _create_widgets(self):
        self.vbox = HIGVBox()
        self.table = HIGTable()

        self.unchanged_button = gtk.ColorButton(self.colors.unchanged)
        self.unchanged_label = gtk.Label(
            _("Property remained <b>U</b>nchanged"))

        self.added_button = gtk.ColorButton(self.colors.added)
        self.added_label = gtk.Label(_("Property was <b>A</b>dded"))

        self.modified_button = gtk.ColorButton(self.colors.modified)
        self.modified_label = gtk.Label(_("Property was <b>M</b>odified"))

        self.not_present_button = gtk.ColorButton(self.colors.not_present)
        self.not_present_label = gtk.Label(_("Property is <b>N</b>ot present"))

    def _pack_widgets(self):
        self.unchanged_label.set_use_markup(True)
        self.added_label.set_use_markup(True)
        self.modified_label.set_use_markup(True)
        self.not_present_label.set_use_markup(True)

        self.table.attach_label(self.unchanged_button, 0, 1, 0, 1)
        self.table.attach_entry(self.unchanged_label, 1, 2, 0, 1)

        self.table.attach_label(self.added_button, 0, 1, 1, 2)
        self.table.attach_entry(self.added_label, 1, 2, 1, 2)

        self.table.attach_label(self.modified_button, 0, 1, 2, 3)
        self.table.attach_entry(self.modified_label, 1, 2, 2, 3)

        self.table.attach_label(self.not_present_button, 0, 1, 3, 4)
        self.table.attach_entry(self.not_present_label, 1, 2, 3, 4)

        self.vbox.pack_start(self.table)
        self.pack_start(self.vbox, False, False)

    def _connect_widgets(self):
        self.unchanged_button.connect("color-set", self.set_color, "unchanged")
        self.added_button.connect("color-set", self.set_color, "added")
        self.modified_button.connect("color-set", self.set_color, "modified")
        self.not_present_button.connect("color-set", self.set_color,
                                        "not_present")

    def set_color(self, widget, prop):
        self.colors.__setattr__(prop, widget.get_color())
class OSFingerprintReport(gtk.Window, object):
    def __init__(self, fingerprint, ip):
        gtk.Window.__init__(self)
        self.set_title(_("Operating System Fingerprint Report"))
        self.set_position(gtk.WIN_POS_CENTER_ALWAYS)

        self.fingerprint = fingerprint
        self.ip = ip

        self._create_widgets()
        self._set_classification_list()
        self._pack_widgets()
        self._connect_widgets()

    def _set_classification_list(self):
        class_file = open(os_classification_file, "rb")
        class_list = cPickle.load(class_file)
        class_file.close()

        for classification in class_list:
            self.classification_list.append([classification[1], classification[0]])

    def _create_widgets(self):
        self.vbox = HIGVBox()
        self.button_box = gtk.HButtonBox()

        self.submitted_label = HIGHintSectionLabel(
            _("Submitted by (optional)"),
            _(
                "Enter your name and \
e-mail address if we can contact you with any questions. (kept private, \
used for nothing else)"
            ),
        )
        self.submitted_entry = gtk.Entry()

        self.target_device_label = HIGHintSectionLabel(
            _("Target OS/device info"),
            _(
                "<b>The more details \
the better!</b> For UNIX machines, '<i>uname -a</i>' often gives the proper \
version number. On Linux, please also specify the distribution version (such as\
Redhat 9.0) if you are using a vendor-provided kernel. For Windows, the \
'<i>winver</i>' command (if available) should show you any service pack \
information. If a Windows target has no service packs installed, \
please say so explicitly. For appliances/embedded devices, please mention \
the model number and what it is (printer, webcam, DSL router, VOIP phone, \
etc). Try to provide the architecture (X86, SPARC, etc.) where appropriate."
            ),
        )
        self.target_device_entry = gtk.Entry()

        self.classification_label = HIGHintSectionLabel(
            _("Classification"),
            _(
                "Please select \
the Device/OS info from this alphabetized choosebox"
            ),
        )
        self.classification_list = gtk.ListStore(str, str)
        self.classification_combo = gtk.ComboBoxEntry(self.classification_list, 0)

        self.notes_label = HIGHintSectionLabel(
            _("Notes"),
            _(
                "Fill with further info on \
the device, any special network conditions, etc."
            ),
        )
        self.notes_scrolled = gtk.ScrolledWindow()
        self.notes_text = gtk.TextView()

        self.fingerprint_icon = gtk.Image()
        self.fingerprint_text = gtk.Label(
            _(
                "This form allows you to \
contribute new operating system fingerprints to the Nmap database. Thanks for \
helping! <b>Please do not fill this out unless you are sure that you know \
what application is running on the machine you are submitting</b>. Incorrect \
entries can pollute the database. By submitting fingerprints you are \
transfering any copyright interest in the data to Fyodor so that he \
can modify it, relicense it, incorporate it into programs such as Nmap, etc."
            )
        )

        self.btn_ok = gtk.Button(stock=gtk.STOCK_OK)
        self.btn_cancel = gtk.Button(stock=gtk.STOCK_CANCEL)

        self.hbox = HIGHBox()
        self.table = HIGTable()

    def _pack_widgets(self):
        self.notes_scrolled.add(self.notes_text)
        self.notes_scrolled.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        self.notes_scrolled.set_size_request(400, 150)
        self.notes_text.set_wrap_mode(gtk.WRAP_WORD)

        self.fingerprint_icon.set_from_stock(gtk.STOCK_DIALOG_INFO, gtk.ICON_SIZE_DIALOG)
        self.fingerprint_icon.set_padding(10, 0)
        self.fingerprint_text.set_line_wrap(True)
        self.fingerprint_text.set_use_markup(True)

        self.table.attach_label(self.submitted_label, 0, 1, 0, 1)
        self.table.attach_entry(self.submitted_entry, 1, 2, 0, 1)

        self.table.attach_label(self.target_device_label, 0, 1, 1, 2)
        self.table.attach_entry(self.target_device_entry, 1, 2, 1, 2)

        self.table.attach_label(self.classification_label, 0, 1, 2, 3)
        self.table.attach_entry(self.classification_combo, 1, 2, 2, 3)

        self.table.attach_label(self.notes_label, 0, 2, 3, 4)
        self.table.attach_entry(self.notes_scrolled, 0, 2, 4, 5)

        self.hbox.set_border_width(12)
        self.hbox._pack_noexpand_nofill(self.fingerprint_icon)
        self.hbox._pack_expand_fill(self.fingerprint_text)

        self.button_box.set_layout(gtk.BUTTONBOX_END)
        self.button_box.pack_start(self.btn_ok)
        self.button_box.pack_start(self.btn_cancel)

        self.vbox.set_border_width(6)
        self.vbox._pack_noexpand_nofill(self.hbox)
        self.vbox._pack_expand_fill(self.table)
        self.vbox._pack_noexpand_nofill(self.button_box)
        self.add(self.vbox)

    def _connect_widgets(self):
        self.btn_ok.connect("clicked", self.send_report)
        self.btn_cancel.connect("clicked", self.close)
        self.connect("delete-event", self.close)

    def close(self, widget=None, event=None):
        self.destroy()

    def send_report(self, widget):
        if self.target_device == "":
            cancel_dialog = HIGAlertDialog(
                type=gtk.MESSAGE_ERROR,
                message_format=_(
                    "Operating System \
Fingerprint report is incomplete!"
                ),
                secondary_text=_(
                    "The Operating \
System Fingerprint report is incomplete. Please, try to provide as much \
information as possible."
                ),
            )
            cancel_dialog.run()
            cancel_dialog.destroy()
            return None

        os_register = OSFingerprintRegister()

        os_register.email = self.submitted
        os_register.os = self.target_device
        os_register.classification = self.classification
        os_register.ip = self.ip
        os_register.fingerprint = self.fingerprint
        os_register.notes = self.notes

        try:
            os_register.report()
        except:
            cancel_dialog = HIGAlertDialog(
                type=gtk.MESSAGE_ERROR,
                message_format=_(
                    "Operating System \
Fingerprint not registered!"
                ),
                secondary_text=_(
                    "The Operating \
System Fingerprint could not be registered. This problem may be caused by \
the lack of Internet Access or indisponibility of the fingerprint server. \
Please, verify your internet access, and then try to register the operating \
system fingerprint once again."
                ),
            )
            cancel_dialog.run()
            cancel_dialog.destroy()
        else:
            ok_dialog = HIGAlertDialog(
                type=gtk.MESSAGE_INFO,
                message_format=_(
                    "Operating System \
Fingerprint sucessfully registered!"
                ),
                secondary_text=_(
                    "The Operating System \
Fingerprint was sucessfully registered. A web page with detailed description \
about this registration is going to be openned in your default web browser."
                ),
            )
            ok_dialog.run()
            ok_dialog.destroy()

            self.close()

    def run_unblocked(self):
        if not self.modal:
            self.set_modal(True)
        self.show_all()

    def dialog_response_cb(self, dialog, response):
        self.response_id = response

    def get_submitted(self):
        return self.submitted_entry.get_text()

    def set_submitted(self, submitted):
        self.submitted_entry.set_text(submitted)

    def get_target_device(self):
        return self.target_device_entry.get_text()

    def set_target_device(self, target_device):
        self.target_device_entry.set_text(target_device)

    def get_classification(self):
        selected = self.classification_combo.child.get_text()
        for i in self.classification_list:
            if i[0] == selected:
                return i[1]
        return ""

    def set_classification(self, classification):
        self.classification.child.set_text(classification)

    def get_notes(self):
        buff = self.notes_text.get_buffer()
        return buff.get_text(buff.get_start_iter(), buff.get_end_iter())

    def set_notes(self, notes):
        self.notes_text.get_buffer().set_text(notes)

    submitted = property(get_submitted, set_submitted)
    target_device = property(get_target_device, set_target_device)
    classification = property(get_classification, set_classification)
    notes = property(get_notes, set_notes)
    def __do_layout(self):
        """
        Layout widgets in window.
        """
        main_vbox = HIGVBox()
        main_vbox.set_border_width(5)
        main_vbox.set_spacing(12)
        header_hbox = HIGHBox()
        schema_table = HIGTable()
        schedsn_hbox = HIGHBox()
        sett_table = HIGTable()
        btns_hbox = HIGHBox()

        header_hbox._pack_expand_fill(self.ttitle)
        header_hbox._pack_noexpand_nofill(self.umit_logo)

        # schema name
        schema_table.attach_label(self.schema_name_lbl, 0, 1, 0, 1)
        schema_table.attach_entry(self.schema_name, 1, 2, 0, 1)

        # target and scan profile
        schema_table.attach_label(self.scan_name_lbl, 0, 1, 1, 2)
        schema_table.attach_entry(self.scan_name, 1, 2, 1, 2)

        # scan command
        schema_table.attach_label(self.scan_command_lbl, 0, 1, 2, 3)
        schema_table.attach_label(self.scan_command, 1, 2, 2, 3)

        # scheduling profile
        schedsn_hbox._pack_expand_fill(self.sched_name)
        schedsn_hbox._pack_noexpand_nofill(self.sched_name_edit)

        schema_table.attach_label(self.sched_name_lbl, 0, 1, 3, 4)
        schema_table.attach_entry(schedsn_hbox, 1, 2, 3, 4)

        # settings frame
        settings_align = gtk.Alignment(0.5, 0.5, 1, 1)
        settings_align.set_padding(6, 0, 12, 0)
        schemasett_hbox = HIGVBox()

        # saveto
        sett_hbox = HIGHBox()
        sett_hbox._pack_expand_fill(self.setting_saveto_entry)
        sett_hbox._pack_noexpand_nofill(self.setting_saveto_browse)
        sett_table.attach_label(self.setting_saveto, 0, 1, 0, 1)
        sett_table.attach_entry(sett_hbox, 1, 2, 0, 1)

        # mailto, smtp
        sett_hbox = HIGHBox()
        sett_hbox._pack_expand_fill(self.setting_mailto_entry)
        sett_hbox._pack_noexpand_nofill(self.setting_smtp_lbl)
        sett_hbox._pack_expand_fill(self.setting_smtp)
        sett_table.attach_label(self.setting_mailto, 0, 1, 1, 2)
        sett_table.attach_entry(sett_hbox, 1, 2, 1, 2)
        schemasett_hbox._pack_noexpand_nofill(sett_table)

        # add to inventory
        sett_hbox = HIGHBox()
        sett_hbox._pack_noexpand_nofill(self.setting_addtoinv)
        schemasett_hbox._pack_noexpand_nofill(sett_hbox)

        # enabled/disabled
        sett_hbox = HIGHBox()
        sett_hbox._pack_noexpand_nofill(self.setting_enabled)
        schemasett_hbox._pack_noexpand_nofill(sett_hbox)
        settings_align.add(schemasett_hbox)

        self.schema_sett_frame.add(settings_align)

        # bottom buttons
        btns_hbox.set_homogeneous(True)
        btns_hbox._pack_expand_fill(self.help)
        btns_hbox._pack_expand_fill(hig_box_space_holder())
        btns_hbox._pack_expand_fill(self.apply)
        btns_hbox._pack_expand_fill(self.cancel)
        btns_hbox._pack_expand_fill(self.ok)

        main_vbox._pack_noexpand_nofill(header_hbox)
        main_vbox._pack_noexpand_nofill(gtk.HSeparator())
        main_vbox._pack_noexpand_nofill(schema_table)
        main_vbox._pack_noexpand_nofill(gtk.HSeparator())
        main_vbox._pack_noexpand_nofill(self.schema_sett_frame)
        main_vbox.pack_end(btns_hbox, False, False, 0)

        self.add(main_vbox)
class BugReport(HIGDialog):
    def __init__(self, title=_('Bug Report'), summary=None, description=None,
                 category=None, crashreport=False, description_dialog=None,
                 reuse_mainloop=True):
        HIGDialog.__init__(self, title=title,
            buttons=(gtk.STOCK_OK, gtk.RESPONSE_ACCEPT,
                gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))

        # If reuse_mainloop is true, then dialogs created inside this dialog
        # will not start another mainloop.
        self._reuse_mainloop = reuse_mainloop

        self.set_position(gtk.WIN_POS_CENTER_ALWAYS)

        self.crashreport = crashreport
        self.description_dialog = description_dialog
        self._create_widgets()
        self._set_category_list()
        self._pack_widgets()
        self._connect_widgets()
        self.summary = summary or ''
        self.description_report = description
        if self.crashreport:
            self.description = _("CrashReport automatically created")
        else:
            if self.description_dialog is None:
                self.description = description or ''
            else:
                self.description = description_dialog or ''
        self.category = category or ''

    def _set_category_list(self):
        # Obtained at bug tracker page source code
        # The following two lines are commented due to component deprecation
        #self.category_list.append(["umitCore","umitCore"])
        #self.category_list.append(["umitGUI","umitGUI"])
        self.category_list.append(["Umit","Umit"])
        self.category_list.append(["CrashReport","CrashReport"])
        self.category_list.append(["Documentation", "Documentation"])
        self.category_list.append(["UmitWeb","UmitWeb"])
        self.category_list.append(["InterfaceEditor", "InterfaceEditor"])
        self.category_list.append(["NetworkInventory", "NetworkInventory"])
        self.category_list.append(["website","website"])

    def _create_widgets(self):
        self.category_label = HIGHintSectionLabel(_("Category (optional)"),
            _("If you know in which section of the program "
            "is the bug, please, select it from the choosebox. "
            "If you don't know what section to choose, leave it blank."))
        self.category_list = gtk.ListStore(str, str)
        self.category_combo = gtk.ComboBoxEntry(self.category_list, 0)

        self.email_label = HIGHintSectionLabel(_("Email"),
            _("Please inform a valid e-mail address from "
            "where you can be reached to be notified when the bug gets "
            "fixed. Not used for other purposes."))
        self.email_entry = gtk.Entry()

        self.summary_label = HIGHintSectionLabel(_("Summary"),
            _("This should be a quick description of the issue. "
            "Try to be clear and concise."))
        self.summary_entry = gtk.Entry()

        self.description_label = HIGHintSectionLabel(_("Description"),
            _("This is where you should write about the bug, "
            "describing it as clear as possible and giving as many "
            "informations as you can and how to reproduce the bug."))
        self.description_scrolled = gtk.ScrolledWindow()
        self.description_text = gtk.TextView()

        self.bug_icon = gtk.Image()
        self.bug_text = gtk.Label(_("This Bug Report dialog allows you "
            "to easily tell us about a problem that you may have found on "
            "Umit. Doing so, you help us to help you, by fixing and "
            "improving Umit faster than usual."))
        
        if self.crashreport:
            # Create a button to show details 
            self.show_details = HIGStockButton(gtk.STOCK_DIALOG_INFO,
                                           _("Show Details"))

        self.hbox = HIGHBox()
        self.table = HIGTable()

    def _pack_widgets(self):
        self.description_scrolled.add(self.description_text)
        self.description_scrolled.set_policy(gtk.POLICY_AUTOMATIC, 
            gtk.POLICY_AUTOMATIC)
        self.description_scrolled.set_size_request(400, 150)
        self.description_text.set_wrap_mode(gtk.WRAP_WORD)

        self.bug_icon.set_from_stock(gtk.STOCK_DIALOG_INFO, 
            gtk.ICON_SIZE_DIALOG)
        self.bug_icon.set_padding(10, 0)
        self.bug_text.set_line_wrap(True)

        self.hbox.set_border_width(12)
        
        nextpos = (0, 1)
        if not self.crashreport:
            self.table.attach_label(self.category_label, 0, 1, 0, 1)
            self.table.attach_entry(self.category_combo, 1, 2, 0, 1)
            nextpos = (1, 2)

        self.table.attach_label(self.email_label, 0, 1, *nextpos)
        self.table.attach_entry(self.email_entry, 1, 2, *nextpos)

        nextpos = (2, 3)
        if not self.crashreport:
            self.table.attach_label(self.summary_label, 0, 1, 2, 3)
            self.table.attach_entry(self.summary_entry, 1, 2, 2, 3)
            nextpos = (3, 4)

        self.table.attach_label(self.description_label, 0, 2, *nextpos)
        nextpos = nextpos[0] + 1, nextpos[1] + 1
        self.table.attach_entry(self.description_scrolled, 0, 2, *nextpos)

        self.hbox._pack_noexpand_nofill(self.bug_icon)
        self.hbox._pack_expand_fill(self.bug_text)

        self.vbox.pack_start(self.hbox, False, False)
        self.vbox.pack_start(self.table)
       
        # Just need because in crash report some aditional 
        # information will be show 
        if self.crashreport:
            # Add a button to action-area
            spaceholder = hig_box_space_holder()
            self.action_area.pack_end(spaceholder)
            self.action_area.pack_end(self.show_details)
            # Put "Show details" to left side respecting HIG
            self.action_area.reorder_child(self.show_details,0)
            self.action_area.reorder_child(spaceholder, 1)
        
        
        
    def _connect_widgets(self):
        self.connect('response', self.check_response)
        if self.crashreport:
            self.show_details.connect('clicked',
                                      self._show_details)
        
    def _show_details(self, widget):
        # Create info necessary
        desc = [ self.email,
                 self.summary,
                 self.description_report,
                 self.description,
                 self.category] 
        # Create another dialog to show details
        details = BugReportDescription(*desc)
        details.show_all()
        details.run()
        details.destroy()
        
        
    def check_response(self, widget, response_id):
        if response_id == gtk.RESPONSE_ACCEPT: # clicked on Ok btn
            self.send_report()
        elif response_id in (gtk.RESPONSE_DELETE_EVENT, gtk.RESPONSE_CANCEL,
                gtk.RESPONSE_NONE):
            # there are tree possibilities to being here:
            # 1) user clicked on 'x' button
            # 2) user clicked on 'cancel' button
            # 3) report was sent successfully and now we can destroy this
            self.destroy()

    def send_report(self):
        """Prepare dialog to send a bug report and then call _send_report."""
        # set cursor to busy cursor (supposing it will take some time
        # to submit the report)
        self.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))

        # disable dialog controls
        for child in self.vbox.get_children():
            child.set_sensitive(False)

        # attempt sending report
        gobject.idle_add(self._send_report)

    def restore_state(self):
        """Restore dialog state, just like it was before calling
        send_report."""
        self.window.set_cursor(None)
        for child in self.vbox.get_children():
            child.set_sensitive(True)

    def _send_report(self):
        if self.summary == "" or self.description == "" or self.email == "":
            cancel_dialog = HIGAlertDialog(type=gtk.MESSAGE_ERROR,
                message_format=_("Bug report is incomplete!"),
                secondary_text=_("The bug report is incomplete. "
                    "You must inform a description that explains clearly "
                    "what is happening and a valid e-mail, so you can be "
                    "contacted when the bug gets fixed."))
            run_dialog(self._reuse_mainloop, cancel_dialog)
            return self.restore_state()

        bug_register = BugRegister()

        bug_register.component = self.category
        bug_register.summary = self.summary
        if self.description_report is not None:
            bug_register.details = self.description_report
        else:
            bug_register.details = self.description.replace("\n", "[[BR]]")
        bug_register.reporter = self.email

        bug_page = None
        try:
            bug_page = bug_register.report()
            assert bug_page
        except:
            import traceback
            traceback.print_exc()
            cancel_dialog = HIGAlertDialog(type=gtk.MESSAGE_ERROR,
                message_format=_("Bug not reported!"),
                secondary_text=_("The bug description could not be "
                    "reported. This problem may be caused by the lack "
                    "of Internet access or indisponibility of the bug "
                    "tracker server. Please, verify your internet access, "
                    "and then try to report the bug once again."))
            run_dialog(self._reuse_mainloop, cancel_dialog)
            return self.restore_state()
        else:
            ok_dialog = HIGAlertDialog(type=gtk.MESSAGE_INFO,
                message_format=_("Bug sucessfully reported!"),
                secondary_text=_("The bug description was sucessfully "
                    "reported. A web page with detailed description about "
                    "this report will be opened in your default web browser "
                    "now."))
            run_dialog(self._reuse_mainloop, ok_dialog,
                    show_report, # callback
                    self._reuse_mainloop, bug_page) # args

        # report sent successfully
        self.response(gtk.RESPONSE_DELETE_EVENT)

    def get_category(self):
        return self.category_combo.child.get_text()

    def set_category(self, category):
        self.category_combo.child.set_text(category)

    def get_summary(self):
        return self.summary_entry.get_text()

    def set_summary(self, summary):
        self.summary_entry.set_text(summary)
    def get_description(self):
        buff = self.description_text.get_buffer()
        return buff.get_text(buff.get_start_iter(), buff.get_end_iter())
    def set_description(self, description):
        self.description_text.get_buffer().set_text(description)

    def get_email(self):
        return self.email_entry.get_text()

    def set_email(self, email):
        self.email_entry.set_text(email)


    category = property(get_category, set_category)
    summary = property(get_summary, set_summary)
    description = property(get_description, set_description)
    email = property(get_email, set_email)
class RegistrationDialog(HIGDialog):
    """"""

    #----------------------------------------------------------------------
    def __init__(self, title=_('Registration')):
        """Constructor"""
        HIGDialog.__init__(self, title=title,
                           buttons=(gtk.STOCK_OK, gtk.RESPONSE_ACCEPT,
                                    gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))

        self.set_position(gtk.WIN_POS_CENTER_ALWAYS)
        
        self._create_widgets()
        self._pack_widgets()

        # Register callbacks
        self.connect("response", self.check_response)

    def _create_widgets(self):
        self.username_label = HIGLabel(_("Username"))
        self.username_entry = gtk.Entry()

        self.password_label = HIGLabel(_("Password"))
        self.password_entry = HIGPasswordEntry()

        self.retype_password_label = HIGLabel(_("Retype password"))
        self.retype_password_entry = HIGPasswordEntry()

        self.registration_icon = gtk.Image()
        self.registration_text = gtk.Label(_("If you don't have an ICM account,"
                "please register a new account."))

        self.hbox = HIGHBox()
        self.table = HIGTable()

    def _pack_widgets(self):
        self.registration_icon.set_from_stock(gtk.STOCK_DIALOG_INFO,
            gtk.ICON_SIZE_DIALOG)
        self.registration_icon.set_padding(10, 0)
        self.registration_text.set_line_wrap(True)

        self.hbox.set_border_width(12)
        self.hbox._pack_noexpand_nofill(self.registration_icon)
        self.hbox._pack_expand_fill(self.registration_text)

        self.vbox.pack_start(self.hbox, False, False)
        self.table.attach_label(self.username_label, 0, 1, 0, 1)
        self.table.attach_entry(self.username_entry, 1, 2, 0, 1)
        self.table.attach_label(self.password_label, 0, 1, 1, 2)
        self.table.attach_entry(self.password_entry, 1, 2, 1, 2)
        self.table.attach_label(self.retype_password_label, 0, 1, 2, 3)
        self.table.attach_entry(self.retype_password_entry, 1, 2, 2, 3)
        self.vbox.pack_start(self.table)

    def check_response(self, widget, response_id):
        if response_id == gtk.RESPONSE_ACCEPT: # clicked on Ok btn
            self.register()
        elif response_id in (gtk.RESPONSE_DELETE_EVENT, gtk.RESPONSE_CANCEL,
                gtk.RESPONSE_NONE):
            self.destroy()

    def register(self):
        username = self.username_entry.get_text()
        password = self.password_entry.get_text()
        theApp.aggregator.register(username, password)
Example #9
0
class ExposeSettings(TabBox, object):
    def __init__(self):
        TabBox.__init__(self, _('Expose Settings'))

        self._pack_widgets()
        self._create_events()


        # Default propertys
        self.page_inside = expose_conf.page_inside

    def _create_widgets(self):
        #self._create_fonts_widgets()
        self._create_tabs_widgets()

    def _create_fonts_widgets(self):
        self._box_fonts_frame = HIGFrame(_('Fonts'))
    def _create_tabs_widgets(self):

        # Tabs
        self._frame_tabs = HIGFrame(_('Tabs'))
        self._box_tabs = HIGVBox()
        self._radio_inside = gtk.RadioButton(None, _('Scans inside Umit'))
        self._radio_outside = gtk.RadioButton(self._radio_inside,\
                                              _('Scans outside Umit'))


        # Toolbar:
        self._frame_toolbar = HIGFrame(_('Toolbar'))
        self._lbl_tlb_size = gtk.Label(_('Toolbar Size: '))
        self._lbl_tlb_style = gtk.Label(_('Toolbar Style: '))

        self._cmb_tlb_size = gtk.combo_box_new_text()

        self._cmb_tlb_size.append_text(_('Small'))
        self._cmb_tlb_size.append_text(_('Medium'))
        self._cmb_tlb_size.append_text(_('Larger'))
        self._cmb_tlb_size.append_text(_('System Default'))

        self._cmb_tlb_style = gtk.combo_box_new_text()
        self._cmb_tlb_style.append_text(_('Icons'))
        self._cmb_tlb_style.append_text(_('Text'))
        self._cmb_tlb_style.append_text(_('Both'))


        self._tbl_tlb = HIGTable()




    def _pack_widgets(self):

        # Pack Tabs
        self.pack_start(self._frame_tabs, False, False)
        self._frame_tabs.add(self._box_tabs)
        self._box_tabs.pack_start(self._radio_inside, False, False)
        self._box_tabs.pack_start(self._radio_outside, False, False)

        # Pack Toolbar

        self.pack_start(self._frame_toolbar, False, False)
        self._frame_toolbar.add(self._tbl_tlb)

        self._tbl_tlb.attach_label(self._lbl_tlb_size,0,1,0,1)
        self._tbl_tlb.attach_entry(self._cmb_tlb_size, 1,2,0,1)

        self._tbl_tlb.attach_label(self._lbl_tlb_style,0,1,1,2)
        self._tbl_tlb.attach_entry(self._cmb_tlb_style, 1,2,1,2)



        # Pack Fonts
        #self.pack_start(self._box_fonts_frame)

    def _create_events(self):
        self._radio_inside.connect("toggled", self.update_page)
        self._radio_outside.connect("toggled", self.update_page)

    def update_page(self, widget):
        print "lol"
        if not widget.get_active():
            return
        # Widget is enable.
        ## But which is enable?
        print "updating page!"
        if widget == self._radio_inside:
            expose_conf.page_inside = True
        elif widget == self._radio_outside:
            expose_conf.page_inside = False

    # API
    def get_page_inside(self):
        print "get page"
        if self._radio_inside.get_active():
            return True
        else:
            return False
    def set_page_inside(self, page):
        if page:
            self._radio_inside.set_active(True)
        else:
            self._radio_outside.set_active(True)

    page_inside = property(get_page_inside, set_page_inside)
    def __do_layout(self):
        """
        Layout widgets in window.
        """
        main_vbox = HIGVBox()
        main_vbox.set_border_width(5)
        main_vbox.set_spacing(12)
        header_hbox = HIGHBox()
        schema_table = HIGTable()
        schedsn_hbox = HIGHBox()
        sett_table = HIGTable()
        btns_hbox = HIGHBox()

        header_hbox._pack_expand_fill(self.ttitle)
        header_hbox._pack_noexpand_nofill(self.umit_logo)

        # schema name
        schema_table.attach_label(self.schema_name_lbl, 0, 1, 0, 1)
        schema_table.attach_entry(self.schema_name, 1, 2, 0, 1)

        # target and scan profile
        schema_table.attach_label(self.scan_name_lbl, 0, 1, 1, 2)
        schema_table.attach_entry(self.scan_name, 1, 2, 1, 2)

        # scan command
        schema_table.attach_label(self.scan_command_lbl, 0, 1, 2, 3)
        schema_table.attach_label(self.scan_command, 1, 2, 2, 3)

        # scheduling profile
        schedsn_hbox._pack_expand_fill(self.sched_name)
        schedsn_hbox._pack_noexpand_nofill(self.sched_name_edit)

        schema_table.attach_label(self.sched_name_lbl, 0, 1, 3, 4)
        schema_table.attach_entry(schedsn_hbox, 1, 2, 3, 4)

        # settings frame
        settings_align = gtk.Alignment(0.5, 0.5, 1, 1)
        settings_align.set_padding(6, 0, 12, 0)
        schemasett_hbox = HIGVBox()

        # saveto
        sett_hbox = HIGHBox()
        sett_hbox._pack_expand_fill(self.setting_saveto_entry)
        sett_hbox._pack_noexpand_nofill(self.setting_saveto_browse)
        sett_table.attach_label(self.setting_saveto, 0, 1, 0, 1)
        sett_table.attach_entry(sett_hbox, 1, 2, 0, 1)

        # mailto, smtp
        sett_hbox = HIGHBox()
        sett_hbox._pack_expand_fill(self.setting_mailto_entry)
        sett_hbox._pack_noexpand_nofill(self.setting_smtp_lbl)
        sett_hbox._pack_expand_fill(self.setting_smtp)
        sett_table.attach_label(self.setting_mailto, 0, 1, 1, 2)
        sett_table.attach_entry(sett_hbox, 1, 2, 1, 2)
        schemasett_hbox._pack_noexpand_nofill(sett_table)

        # add to inventory
        sett_hbox = HIGHBox()
        sett_hbox._pack_noexpand_nofill(self.setting_addtoinv)
        schemasett_hbox._pack_noexpand_nofill(sett_hbox)

        # enabled/disabled
        sett_hbox = HIGHBox()
        sett_hbox._pack_noexpand_nofill(self.setting_enabled)
        schemasett_hbox._pack_noexpand_nofill(sett_hbox)
        settings_align.add(schemasett_hbox)

        self.schema_sett_frame.add(settings_align)

        # bottom buttons
        btns_hbox.set_homogeneous(True)
        btns_hbox._pack_expand_fill(self.help)
        btns_hbox._pack_expand_fill(hig_box_space_holder())
        btns_hbox._pack_expand_fill(self.apply)
        btns_hbox._pack_expand_fill(self.cancel)
        btns_hbox._pack_expand_fill(self.ok)

        main_vbox._pack_noexpand_nofill(header_hbox)
        main_vbox._pack_noexpand_nofill(gtk.HSeparator())
        main_vbox._pack_noexpand_nofill(schema_table)
        main_vbox._pack_noexpand_nofill(gtk.HSeparator())
        main_vbox._pack_noexpand_nofill(self.schema_sett_frame)
        main_vbox.pack_end(btns_hbox, False, False, 0)

        self.add(main_vbox)
class OSFingerprintReport(gtk.Window, object):
    def __init__(self, fingerprint, ip):
        gtk.Window.__init__(self)
        self.set_title(_('Operating System Fingerprint Report'))
        self.set_position(gtk.WIN_POS_CENTER_ALWAYS)

        self.fingerprint = fingerprint
        self.ip = ip

        self._create_widgets()
        self._set_classification_list()
        self._pack_widgets()
        self._connect_widgets()

    def _set_classification_list(self):
        class_file = open(os_classification_file, "rb")
        class_list = cPickle.load(class_file)
        class_file.close()
        
        for classification in class_list:
            self.classification_list.append([classification[1],
                                             classification[0]])

    def _create_widgets(self):
        self.vbox = HIGVBox()
        self.button_box = gtk.HButtonBox()
        
        self.submitted_label = HIGHintSectionLabel(_("Submitted by (optional)"),
                                                   _("Enter your name and \
e-mail address if we can contact you with any questions. (kept private, \
used for nothing else)"))
        self.submitted_entry = gtk.Entry()

        self.target_device_label = HIGHintSectionLabel(_("Target OS/device info"),
                                                       _("<b>The more details \
the better!</b> For UNIX machines, '<i>uname -a</i>' often gives the proper \
version number. On Linux, please also specify the distribution version (such as\
Redhat 9.0) if you are using a vendor-provided kernel. For Windows, the \
'<i>winver</i>' command (if available) should show you any service pack \
information. If a Windows target has no service packs installed, \
please say so explicitly. For appliances/embedded devices, please mention \
the model number and what it is (printer, webcam, DSL router, VOIP phone, \
etc). Try to provide the architecture (X86, SPARC, etc.) where appropriate."))
        self.target_device_entry = gtk.Entry()

        self.classification_label = HIGHintSectionLabel(_("Classification"),
                                                        _("Please select \
the Device/OS info from this alphabetized choosebox"))
        self.classification_list = gtk.ListStore(str, str)
        self.classification_combo = gtk.ComboBoxEntry(self.classification_list,
                                                      0)

        self.notes_label = HIGHintSectionLabel(_("Notes"),
                                               _("Fill with further info on \
the device, any special network conditions, etc."))
        self.notes_scrolled = gtk.ScrolledWindow()
        self.notes_text = gtk.TextView()

        self.fingerprint_icon = gtk.Image()
        self.fingerprint_text = gtk.Label(_("This form allows you to \
contribute new operating system fingerprints to the Nmap database. Thanks for \
helping! <b>Please do not fill this out unless you are sure that you know \
what application is running on the machine you are submitting</b>. Incorrect \
entries can pollute the database. By submitting fingerprints you are \
transfering any copyright interest in the data to Fyodor so that he \
can modify it, relicense it, incorporate it into programs such as Nmap, etc."))

        self.btn_ok = gtk.Button(stock=gtk.STOCK_OK)
        self.btn_cancel = gtk.Button(stock=gtk.STOCK_CANCEL)

        self.hbox = HIGHBox()
        self.table = HIGTable()

    def _pack_widgets(self):
        self.notes_scrolled.add(self.notes_text)
        self.notes_scrolled.set_policy(gtk.POLICY_AUTOMATIC,
                                       gtk.POLICY_AUTOMATIC)
        self.notes_scrolled.set_size_request(400, 150)
        self.notes_text.set_wrap_mode(gtk.WRAP_WORD)

        self.fingerprint_icon.set_from_stock(gtk.STOCK_DIALOG_INFO,
                                             gtk.ICON_SIZE_DIALOG)
        self.fingerprint_icon.set_padding(10, 0)
        self.fingerprint_text.set_line_wrap(True)
        self.fingerprint_text.set_use_markup(True)

        self.table.attach_label(self.submitted_label, 0, 1, 0, 1)
        self.table.attach_entry(self.submitted_entry, 1, 2, 0, 1)
        
        self.table.attach_label(self.target_device_label, 0, 1, 1, 2)
        self.table.attach_entry(self.target_device_entry, 1, 2, 1, 2)

        self.table.attach_label(self.classification_label, 0, 1, 2, 3)
        self.table.attach_entry(self.classification_combo, 1, 2, 2, 3)

        self.table.attach_label(self.notes_label, 0, 2, 3, 4)
        self.table.attach_entry(self.notes_scrolled, 0, 2, 4, 5)

        self.hbox.set_border_width(12)
        self.hbox._pack_noexpand_nofill(self.fingerprint_icon)
        self.hbox._pack_expand_fill(self.fingerprint_text)

        self.button_box.set_layout(gtk.BUTTONBOX_END)
        self.button_box.pack_start(self.btn_ok)
        self.button_box.pack_start(self.btn_cancel)

        self.vbox.set_border_width(6)
        self.vbox._pack_noexpand_nofill(self.hbox)
        self.vbox._pack_expand_fill(self.table)
        self.vbox._pack_noexpand_nofill(self.button_box)
        self.add(self.vbox)

    def _connect_widgets(self):
        self.btn_ok.connect("clicked", self.send_report)
        self.btn_cancel.connect("clicked", self.close)
        self.connect("delete-event", self.close)

    def close(self, widget=None, event=None):
        self.destroy()

    def send_report(self, widget):
        if self.target_device == "":
            cancel_dialog = HIGAlertDialog(type=gtk.MESSAGE_ERROR,
                                           message_format=_("Operating System \
Fingerprint report is incomplete!"),
                                           secondary_text=_("The Operating \
System Fingerprint report is incomplete. Please, try to provide as much \
information as possible."))
            cancel_dialog.run()
            cancel_dialog.destroy()
            return None

        os_register = OSFingerprintRegister()

        os_register.email = self.submitted
        os_register.os = self.target_device
        os_register.classification = self.classification
        os_register.ip = self.ip
        os_register.fingerprint = self.fingerprint
        os_register.notes = self.notes

        try:
            os_register.report()
        except:
            cancel_dialog = HIGAlertDialog(type=gtk.MESSAGE_ERROR,
                                           message_format=_("Operating System \
Fingerprint not registered!"),
                                           secondary_text=_("The Operating \
System Fingerprint could not be registered. This problem may be caused by \
the lack of Internet Access or indisponibility of the fingerprint server. \
Please, verify your internet access, and then try to register the operating \
system fingerprint once again."))
            cancel_dialog.run()
            cancel_dialog.destroy()
        else:
            ok_dialog = HIGAlertDialog(type=gtk.MESSAGE_INFO,
                                       message_format=_("Operating System \
Fingerprint sucessfully registered!"),
                                       secondary_text=_("The Operating System \
Fingerprint was sucessfully registered. A web page with detailed description \
about this registration is going to be openned in your default web browser."))
            ok_dialog.run()
            ok_dialog.destroy()

            self.close()

    def run_unblocked(self):
        if not self.modal:
            self.set_modal(True)
        self.show_all()

    def dialog_response_cb(self, dialog, response):
        self.response_id = response

    def get_submitted(self):
        return self.submitted_entry.get_text()

    def set_submitted(self, submitted):
        self.submitted_entry.set_text(submitted)

    def get_target_device(self):
        return self.target_device_entry.get_text()

    def set_target_device(self, target_device):
        self.target_device_entry.set_text(target_device)

    def get_classification(self):
        selected = self.classification_combo.child.get_text()
        for i in self.classification_list:
            if i[0] == selected:
                return i[1]
        return ""

    def set_classification(self, classification):
        self.classification.child.set_text(classification)

    def get_notes(self):
        buff = self.notes_text.get_buffer()
        return buff.get_text(buff.get_start_iter(), buff.get_end_iter())

    def set_notes(self, notes):
        self.notes_text.get_buffer().set_text(notes)

    submitted = property(get_submitted, set_submitted)
    target_device = property(get_target_device, set_target_device)
    classification = property(get_classification, set_classification)
    notes = property(get_notes, set_notes)
class UpdatePage(HIGVBox):
    """"""
    def __init__(self):
        """Constructor"""
        HIGVBox.__init__(self)
        self.__create_widgets()
        self.__pack_widgets()
        self.__load_list()
        self.__connect_widgets()
        self.__init_db_text()

    def __create_widgets(self):
        """"""

        self.update_switch_hbox = HIGHBox()
        self.update_settings_hbox = HIGHBox()
        self.update_db_hbox = HIGHBox()

        self.update_switch_section = HIGSectionLabel(_("Update News Detect"))
        self.update_switch_table = HIGTable()
        self.update_settings_section = HIGSectionLabel(_("Update Settings"))
        self.update_settings_table = HIGTable()
        self.update_db_section = HIGSectionLabel(_("Update Database"))
        self.update_db_table = HIGTable()

        self.update_check = gtk.CheckButton(_("Automatically update"))
        self.update_switch_check = gtk.CheckButton(
            _("Software Update Detect Switch"))
        self.update_times_label = HIGEntryLabel(_("Auto detect update news"))
        self.update_method_label = HIGEntryLabel(_("Update method"))

        self.update_time_store = gtk.ListStore(str)
        self.update_time_entry = gtk.ComboBoxEntry(self.update_time_store, 0)
        self.update_method_store = gtk.ListStore(str)
        self.update_method_entry = gtk.ComboBoxEntry(self.update_method_store,
                                                     0)

        self.update_db_label = HIGEntryLabel()
        self.update_db_clear_button = gtk.Button(_("Clear Update Information"))

    def __pack_widgets(self):
        """"""
        self.set_border_width(12)

        self._pack_noexpand_nofill(self.update_switch_section)
        self._pack_noexpand_nofill(self.update_switch_hbox)
        self._pack_noexpand_nofill(hig_box_space_holder())
        self._pack_noexpand_nofill(self.update_settings_section)
        self._pack_noexpand_nofill(self.update_settings_hbox)
        self._pack_noexpand_nofill(self.update_db_section)
        self._pack_noexpand_nofill(self.update_db_hbox)

        self.update_switch_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.update_switch_hbox._pack_expand_fill(self.update_switch_table)
        self.update_settings_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.update_settings_hbox._pack_expand_fill(self.update_settings_table)
        self.update_db_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.update_db_hbox._pack_expand_fill(self.update_db_table)

        self.update_switch_table.attach_label(self.update_check, 0, 2, 0, 1)
        self.update_switch_table.attach_label(self.update_switch_check, 0, 2,
                                              1, 2)
        self.update_settings_table.attach_label(self.update_times_label, 0, 1,
                                                0, 1)
        self.update_settings_table.attach_entry(self.update_time_entry, 1, 2,
                                                0, 1)
        self.update_settings_table.attach_label(self.update_method_label, 0, 1,
                                                1, 2)
        self.update_settings_table.attach_entry(self.update_method_entry, 1, 2,
                                                1, 2)

        self.update_db_table.attach_label(self.update_db_label, 1, 3, 0, 1)
        self.update_db_table.attach(self.update_db_clear_button, 0, 1, 0, 1)

    def __init_db_text(self):
        """"""
        rs = g_db_helper.select("select * from updates")
        count = len(rs)
        self.update_db_label.set_text(
            str(_("%d records in update database now." % (count))))

    def __connect_widgets(self):
        """"""
        self.update_check.connect('toggled',
                                  lambda w: self.__change_widgets_status())
        self.update_db_clear_button.connect("clicked",
                                            lambda w: self.__clear_update_db())

    def __clear_update_db(self):
        """"""
        g_db_helper.execute("delete from updates")
        g_db_helper.commit()
        self.update_db_label.set_text(str(
            _("Clear software update database!")))

    def __change_widgets_status(self):
        """"""
        if self.update_check.get_active():
            self.__disable_widgets()
        else:
            self.__enable_widgets()

    def __load_list(self):
        """"""
        for s in update_time_str.keys():
            #print s
            self.update_time_store.append([s])
        for s in update_method_str.keys():
            #print s
            self.update_method_store.append([s])

    def __disable_widgets(self):
        """"""
        self.update_switch_check.set_sensitive(False)
        self.update_method_entry.set_sensitive(False)
        self.update_time_entry.set_sensitive(False)

    def __enable_widgets(self):
        """"""
        self.update_switch_check.set_sensitive(True)
        self.update_method_entry.set_sensitive(True)
        self.update_time_entry.set_sensitive(True)
Example #13
0
class SearchGUI(gtk.HPaned, object):
    def __init__(self, notebook):
        gtk.HPaned.__init__(self)

        self._create_widgets()
        self._pack_widgets()
        self._connect_events()

        self.any_profile = _("Any profile")
        self.any_option = _("Any option")
        self.any_target = _("Any target")
        self.any_service = _("Any service")
        self.any_product = _("Any product")
        self.any_osclass = _("Any os class")
        self.any_osmatch = _("Any os match")
        self.any = _("Any")

        # Setting default values
        self.port_open = True
        self.port_filtered = True
        self.port_closed = True
        self.profile = self.any_profile
        self.option = self.any_option
        self.target = self.any_target
        self.service = self.any_service
        self.product = self.any_product
        self.osclass = self.any_osclass
        self.osmatch = self.any_osmatch

        # Search options
        self.directory = search_config.directory
        self.file_extension = search_config.file_extension
        self.save_time = search_config.save_time
        self.save = search_config.store_results
        self.search_db = search_config.search_db

        self.parsed_results = {}
        self._set_result_view()
        self.scan_num = 1
        self.id = 0
        self.notebook = notebook

    def _create_widgets(self):
        # Main widgets
        self.hpaned = gtk.HPaned()
        self.main_vbox = HIGVBox()

        # Results section
        self.result_section = HIGSectionLabel(_("Results"))
        self.result_vbox = HIGVBox()
        self.result_hbox = HIGHBox()
        self.result_list = gtk.ListStore(str, str, int) # title, date, id
        self.result_view = gtk.TreeView(self.result_list)
        self.result_scrolled = gtk.ScrolledWindow()
        self.result_title_column = gtk.TreeViewColumn(_("Scan"))
        self.result_date_column = gtk.TreeViewColumn(_("Date"))

        # Search notebook
        self.search_vbox = HIGVBox()
        self.search_notebook = gtk.Notebook()
        self.search_button = HIGButton(stock=gtk.STOCK_FIND)

        # General page
        self.general_vbox = HIGVBox()
        self.general_hbox = HIGHBox()
        #self.general_start_hbox = HIGHBox()
        #self.general_finish_hbox = HIGHBox()
        
        self.general_section = HIGSectionLabel(_("General search parameters"))
        
        self.general_table = HIGTable()

        self.general_option_label = HIGEntryLabel(_("Option"))
        self.general_profile_label = HIGEntryLabel(_("Profile"))
        #self.general_finished_label = HIGEntryLabel(_("Finished"))
        #self.general_started_label = HIGEntryLabel(_("Started"))
        self.general_keyword_label = HIGEntryLabel(_("Keyword"))

        self.general_keyword_entry = gtk.Entry()
        self.general_option_combo = OptionCombo()
        self.general_profile_combo = ProfileCombo()
        #self.general_started_range = DateRange()
        #self.general_finished_range = DateRange()

        # Host page
        self.host_vbox = HIGVBox()
        self.host_hbox = HIGHBox()
        #self.host_uptime_hbox = HIGHBox()
        #self.host_lastboot_hbox = HIGHBox()
        
        self.host_section = HIGSectionLabel(_("Host search parameters"))
        
        self.host_table = HIGTable()

        self.host_target_label = HIGEntryLabel(_("Target"))
        self.host_mac_label = HIGEntryLabel(_("MAC"))
        self.host_ipv4_label = HIGEntryLabel(_("IPv4"))
        self.host_ipv6_label = HIGEntryLabel(_("IPv6"))
        #self.host_uptime_label = HIGEntryLabel(_("Uptime"))
        #self.host_lastboot_label = HIGEntryLabel(_("Last boot"))

        self.host_target_combo = TargetCombo()
        self.host_mac_entry = gtk.Entry()
        self.host_ipv4_entry = gtk.Entry()
        self.host_ipv6_entry = gtk.Entry()
        #self.host_uptime_range = DateRange()
        #self.host_lastboot_range = DateRange()


        # Service
        self.serv_vbox = HIGVBox()
        self.serv_hbox = HIGHBox()
        self.serv_section = HIGSectionLabel(_("Service search parameters"))
        self.serv_table = HIGTable()

        self.serv_port_label = HIGEntryLabel(_("Port number"))
        self.serv_service_label = HIGEntryLabel(_("Service"))
        self.serv_product_label = HIGEntryLabel(_("Product"))
        self.serv_portstate_label = HIGEntryLabel(_("Port state"))
        
        self.serv_port_entry = gtk.Entry()
        self.serv_service_combo = ServiceCombo()
        self.serv_product_entry = gtk.Entry()
        self.serv_portstate_check = PortState()


        # OS
        self.os_vbox = HIGVBox()
        self.os_hbox = HIGHBox()
        self.os_section = HIGSectionLabel(_("Operating System search \
parameters"))
        self.os_table = HIGTable()
        
        self.os_osclass_label = HIGEntryLabel(_("OS class"))
        self.os_osmatch_label = HIGEntryLabel(_("OS match"))
        
        self.os_osclass_combo = OSClassCombo()
        self.os_osmatch_combo = OSMatchCombo()


        # Search options page
        self.opt_vbox = HIGVBox()
        self.opt_local_hbox = HIGHBox()
        self.opt_base_hbox = HIGHBox()
        self.opt_local_section = HIGSectionLabel(_("Local files"))
        self.opt_local_table = HIGTable()
        self.opt_base_section = HIGSectionLabel(_("Database"))
        self.opt_base_table = HIGTable()

        self.opt_path_label = HIGEntryLabel(_("Directory"))
        self.opt_extension_label = HIGEntryLabel(_("File extension"))
        self.opt_savetime_label = HIGEntryLabel(_("Save results for"))

        self.opt_path_entry = PathEntry()
        self.opt_extension_entry = gtk.Entry()
        self.opt_savetime_entry = SaveTime()
        self.opt_save_check = gtk.CheckButton(_("Save scan results in data \
base for latter search"))
        self.opt_search_check = gtk.CheckButton(_("Search saved scan results \
in data base"))

        
    def _pack_widgets(self):
        # Packing result section
        self.result_vbox.set_border_width(12)
        self.result_vbox._pack_noexpand_nofill(self.result_section)
        self.result_vbox._pack_expand_fill(self.result_hbox)

        self.result_scrolled.set_size_request(185, -1)
        #self.result_scrolled.set_shadow_type(gtk.SHADOW_ETCHED_IN)
        self.result_scrolled.add(self.result_view)
        self.result_scrolled.set_policy(gtk.POLICY_AUTOMATIC,
                                        gtk.POLICY_AUTOMATIC)
        self.result_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.result_hbox._pack_expand_fill(self.result_scrolled)

        ## Search Notebook
        self.search_vbox._pack_expand_fill(self.search_notebook)
        self.search_vbox._pack_expand_fill(self.search_button)

        self.search_notebook.set_border_width(1)
        self.search_vbox.set_border_width(12)
        
        # General page
        self.general_vbox.set_border_width(12)
        self.general_vbox._pack_noexpand_nofill(self.general_section)
        self.general_vbox._pack_noexpand_nofill(self.general_hbox)
        
        #self.general_vbox._pack_noexpand_nofill(self.general_start_section)
        #self.general_vbox._pack_noexpand_nofill(self.general_start_hbox)
        
        #self.general_vbox._pack_noexpand_nofill(self.general_finish_section)
        #self.general_vbox._pack_noexpand_nofill(self.general_finish_hbox)
        
        self.general_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.general_hbox._pack_expand_fill(self.general_table)

        #self.general_start_hbox._pack_noexpand_nofill(hig_box_space_holder())
        #self.general_start_hbox._pack_noexpand_nofill(self.general_started_range)

        #self.general_finish_hbox._pack_noexpand_nofill(hig_box_space_holder())
        #self.general_finish_hbox._pack_expand_fill(self.general_finished_range)
        

        self.general_table.attach_label(self.general_keyword_label, 0, 1, 0, 1)
        self.general_table.attach_label(self.general_profile_label, 0, 1, 1, 2)
        self.general_table.attach_label(self.general_option_label, 0, 1, 2, 3)

        self.general_table.attach_entry(self.general_keyword_entry, 1, 2, 0, 1)
        self.general_table.attach_entry(self.general_profile_combo, 1, 2, 1, 2)
        self.general_table.attach_entry(self.general_option_combo, 1, 2, 2, 3)
        
        self.search_notebook.append_page(self.general_vbox,
                                         gtk.Label(_("General")))

        # Host page
        self.host_vbox.set_border_width(12)
        self.host_vbox._pack_noexpand_nofill(self.host_section)
        self.host_vbox._pack_noexpand_nofill(self.host_hbox)
        
        #self.host_vbox._pack_noexpand_nofill(self.host_uptime_section)
        #self.host_vbox._pack_noexpand_nofill(self.host_uptime_hbox)

        #self.host_vbox._pack_noexpand_nofill(self.host_lastboot_section)
        #self.host_vbox._pack_noexpand_nofill(self.host_lastboot_hbox)
        
        self.host_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.host_hbox._pack_expand_fill(self.host_table)

        #self.host_uptime_hbox._pack_noexpand_nofill(hig_box_space_holder())
        #self.host_uptime_hbox._pack_noexpand_nofill(self.host_uptime_range)

        #self.host_lastboot_hbox._pack_noexpand_nofill(hig_box_space_holder())
        #self.host_lastboot_hbox._pack_expand_fill(self.host_lastboot_range)

        self.host_table.attach_label(self.host_target_label, 0, 1, 0, 1)
        self.host_table.attach_label(self.host_mac_label, 0, 1, 1, 2)
        self.host_table.attach_label(self.host_ipv4_label, 0, 1, 2, 3)
        self.host_table.attach_label(self.host_ipv6_label, 0, 1, 3, 4)

        self.host_table.attach_entry(self.host_target_combo, 1, 2, 0, 1)
        self.host_table.attach_entry(self.host_mac_entry, 1, 2, 1, 2)
        self.host_table.attach_entry(self.host_ipv4_entry, 1, 2, 2, 3)
        self.host_table.attach_entry(self.host_ipv6_entry, 1, 2, 3, 4)
        
        self.search_notebook.append_page(self.host_vbox, gtk.Label(_("Host")))

        # Service page
        self.serv_vbox.set_border_width(12)
        self.serv_vbox._pack_noexpand_nofill(self.serv_section)
        self.serv_vbox._pack_noexpand_nofill(self.serv_hbox)
        
        self.serv_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.serv_hbox._pack_expand_fill(self.serv_table)

        self.serv_table.attach_label(self.serv_port_label, 0, 1, 0, 1)
        self.serv_table.attach_label(self.serv_portstate_label, 0, 1, 1, 2)
        self.serv_table.attach_label(self.serv_product_label, 0, 1, 2, 3)
        self.serv_table.attach_label(self.serv_service_label, 0, 1, 3, 4)

        self.serv_table.attach_entry(self.serv_port_entry, 1, 2, 0, 1)
        self.serv_table.attach_entry(self.serv_portstate_check, 1, 2, 1, 2)
        self.serv_table.attach_entry(self.serv_product_entry, 1, 2, 2, 3)
        self.serv_table.attach_entry(self.serv_service_combo, 1, 2, 3, 4)
        
        self.search_notebook.append_page(self.serv_vbox,
                                         gtk.Label(_("Service")))

        # OS page
        self.os_vbox.set_border_width(12)
        self.os_vbox._pack_noexpand_nofill(self.os_section)
        self.os_vbox._pack_noexpand_nofill(self.os_hbox)

        self.os_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.os_hbox._pack_expand_fill(self.os_table)

        self.os_table.attach_label(self.os_osclass_label, 0, 1, 0, 1)
        self.os_table.attach_label(self.os_osmatch_label, 0, 1, 1, 2)

        self.os_table.attach_entry(self.os_osclass_combo, 1, 2, 0, 1)
        self.os_table.attach_entry(self.os_osmatch_combo, 1, 2, 1, 2)

        self.search_notebook.append_page(self.os_vbox, gtk.Label(_("OS")))

        # Search options page
        self.opt_vbox.set_border_width(12)
        self.opt_vbox._pack_noexpand_nofill(self.opt_local_section)
        self.opt_vbox._pack_noexpand_nofill(self.opt_local_hbox)
        
        self.opt_vbox._pack_noexpand_nofill(self.opt_base_section)
        self.opt_vbox._pack_noexpand_nofill(self.opt_base_hbox)

        self.opt_local_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.opt_local_hbox._pack_expand_fill(self.opt_local_table)

        self.opt_base_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.opt_base_hbox._pack_expand_fill(self.opt_base_table)

        self.opt_local_table.attach_label(self.opt_path_label, 0, 1, 0, 1)
        self.opt_local_table.attach_label(self.opt_extension_label, 0, 1, 1, 2)
        
        self.opt_local_table.attach_entry(self.opt_path_entry, 1, 2, 0, 1)
        self.opt_local_table.attach_entry(self.opt_extension_entry, 1, 2, 1, 2)

        self.opt_base_table.attach_label(self.opt_savetime_label, 0, 1, 0, 1)
        self.opt_base_table.attach_label(self.opt_save_check, 0, 2, 1, 2)
        self.opt_base_table.attach_label(self.opt_search_check, 0, 2, 2, 3)

        self.opt_base_table.attach_entry(self.opt_savetime_entry, 1, 2, 0, 1)


        self.search_notebook.append_page(self.opt_vbox,
                                         gtk.Label(_("Search options")))

        self.pack1(self.search_vbox, True, False)
        self.pack2(self.result_vbox, True, False)

    def _connect_events(self):
        self.os_osclass_combo.connect("changed", self.update_osmatch)
        self.search_button.connect("clicked", self.start_search)

        self.opt_extension_entry.connect("focus-out-event",
                                         self.update_extension_entry)
        self.opt_save_check.connect("toggled", self.update_save_check)
        self.opt_search_check.connect("toggled", self.update_search_check)
        self.opt_path_entry.connect_entry_change(self.update_path_entry)
        self.opt_savetime_entry.connect_entry_change(self.update_savetime_entry)
        

    def update_path_entry(self, widget, extra=None):
        search_config.directory = widget.get_text()

    def update_savetime_entry(self, widget, extra=None):
        search_config.save_time = self.opt_savetime_entry.time

    def update_extension_entry(self, widget, extra=None):
        search_config.file_extension = widget.get_text()

    def update_save_check(self, widget):
        search_config.store_results = widget.get_active()

    def update_search_check(self, widget):
        search_config.search_db = widget.get_active()

    def start_search(self, widget):
        if not self.search_db and \
           not self.directory:
            self.search_notebook.set_current_page(-1)
            d = HIGAlertDialog(message_format=_("No search method selected!"),
                               secondary_text=_("Umit can search results on \
directories or inside it's own database. Please, select a method by choosing \
a directory or by checking the search data base option at the 'Search options' \
tab before start the search"))
            d.run()
            d.destroy()
            return
        
        search_dict = dict(keyword=self.keyword,
                           profile=self.profile,
                           option=self.option,
                           target=self.target,
                           mac=self.mac,
                           ipv4=self.ipv4,
                           ipv6=self.ipv6,
                           port=self.port,
                           port_open=self.port_open,
                           port_filtered=self.port_filtered,
                           port_closed=self.port_closed,
                           service=self.service,
                           osclass=self.osclass,
                           osmatch=self.osmatch,
                           product=self.product)

        self.clear_result_list()
        
        if self.search_db:
            search_db = SearchDB()

            for result in search_db.search(**search_dict):
                self.append_result(result)

        if self.directory:
            search_dir = SearchDir(self.directory, self.file_extension)

            for result in search_dir.search(**search_dict):
                self.append_result(result)

        search_tabs = SearchTabs(self.notebook)
        for result in search_tabs.search(**search_dict):
            self.append_result(result)  

    def clear_result_list(self):
        for i in range(len(self.result_list)):
            iter = self.result_list.get_iter_root()
            del(self.result_list[iter])

    def append_result(self, parsed_result):
        title = ""
        if parsed_result.scan_name:
            title = parsed_result.scan_name
        elif parsed_result.nmap_xml_file:
            title = os.path.split(parsed_result.nmap_xml_file)[-1]
        elif parsed_result.profile_name and parsed_result.target:
            title = "%s on %s" % (parsed_result.profile_name,
                                  parsed_result.target)
        else:
            title = "Scan %s" % (self.scan_num)
            self.scan_num += 1

        try:
            date = localtime(float(parsed_result.start))
            date_field = "%02d %s %04d" % (date[2],
                                           calendar.month_name[date[1]][:3],
                                           date[0])
        except ValueError:
            date_field = _("Unknown")


        self.parsed_results[self.id] = [title, parsed_result]
        self.result_list.append([title, date_field, self.id])
        self.id += 1

    def update_osmatch(self, widegt):
        self.os_osmatch_combo.update(self.os_osclass_combo.selected_osclass)

    def get_keyword(self):
        return self.general_keyword_entry.get_text()

    def set_keyword(self, keyword):
        self.general_keyword_entry.set_text(keyword)

    def get_profile(self):
        if self.general_profile_combo.selected_profile == self.any_profile or \
           self.general_profile_combo.selected_profile == self.any:
            return "*"
        return self.general_profile_combo.selected_profile

    def set_profile(self, profile):
        self.general_profile_combo.selected_profile = profile

    def get_option(self):
        if self.general_option_combo.selected_option == self.any_option or \
           self.general_option_combo.selected_option == self.any:
            return "*"
        return self.general_option_combo.selected_option

    def set_option(self, option):
        self.general_option_combo.selected_option = option

    def get_target(self):
        if self.host_target_combo.selected_target == self.any_target or \
           self.host_target_combo.selected_target == self.any:
            return "*"
        return self.host_target_combo.selected_target

    def set_target(self, target):
        self.host_target_combo.selected_target = target

    def get_mac(self):
        return self.host_mac_entry.get_text()

    def set_mac(self, mac):
        self.host_mac_entry.set_text(mac)

    def get_ipv4(self):
        return self.host_ipv4_entry.get_text()

    def set_ipv4(self, ipv4):
        self.host_ipv4_entry.set_text(ipv4)

    def get_ipv6(self):
        return self.host_ipv6_entry.get_text()

    def set_ipv6(self, ipv6):
        self.host_ipv6_entry.set_text(ipv6)

    def get_port(self):
        return self.serv_port_entry.get_text().split(";")

    def set_port(self, port):
        if isinstance(port, basestring):
            self.serv_port_entry.set_text(port)
        elif isinstance(port, list):
            self.serv_port_entry.set_text(";".join(port))

    def get_port_open(self):
        return self.serv_portstate_check.open

    def set_port_open(self, open):
        self.serv_portstate_check.open = open

    def get_port_filtered(self):
        return self.serv_portstate_check.filtered

    def set_port_filtered(self, filtered):
        self.serv_portstate_check.filtered = filtered

    def get_port_closed(self):
        return self.serv_portstate_check.closed

    def set_port_closed(self, closed):
        self.serv_portstate_check.closed = closed

    def get_service(self):
        if self.serv_service_combo.selected_service == self.any_service or \
           self.serv_service_combo.selected_service == self.any:
            return "*"
        return self.serv_service_combo.selected_service

    def set_service(self, service):
        self.serv_service_combo.selected_service = service

    def get_osclass(self):
        if self.os_osclass_combo.selected_osclass == self.any_osclass or \
           self.os_osclass_combo.selected_osclass == self.any:
            return "*"
        return self.os_osclass_combo.selected_osclass

    def set_osclass(self, osclass):
        self.os_osclass_combo.selected_osclass = osclass

    def get_osmatch(self):
        if self.os_osmatch_combo.selected_osmatch == self.any_osmatch or \
           self.os_osmatch_combo.selected_osmatch == self.any:
            return "*"
        return self.os_osmatch_combo.selected_osmatch

    def set_osmatch(self, osmatch):
        self.os_osmatch_combo.selected_osmatch = osmatch

    def get_product(self):
        if self.serv_product_entry.get_text() == self.any_product or \
           self.serv_product_entry.get_text() == self.any:
            return "*"
        return self.serv_product_entry.get_text()

    def set_product(self, product):
        self.serv_product_entry.set_text(product)

    def get_directory(self):
        return self.opt_path_entry.path

    def set_directory(self, directory):
        self.opt_path_entry.path = directory

    def get_file_extension(self):
        return self.opt_extension_entry.get_text().split(";")

    def set_file_extension(self, file_extension):
        if isinstance(file_extension, list):
            self.opt_extension_entry.set_text(";".join(file_extension))
        elif isinstance(file_extension, basestring):
            self.opt_extension_entry.set_text(file_extension)

    def get_save_time(self):
        return self.opt_savetime_entry.time

    def set_save_time(self, save_time):
        self.opt_savetime_entry.time = save_time

    def get_save(self):
        return self.opt_save_check.get_active()

    def set_save(self, save):
        self.opt_save_check.set_active(save)

    def get_search_db(self):
        return self.opt_search_check.get_active()

    def set_search_db(self, search_db):
        self.opt_search_check.set_active(search_db)

    def get_selected_results(self):
        selection = self.result_view.get_selection()
        rows = selection.get_selected_rows()
        list_store = rows[0]

        results = {}
        for row in rows[1]:
            r = row[0]
            results[list_store[r][2]] = self.parsed_results[list_store[r][2]]

        return results

    def _set_result_view(self):
        self.result_view.set_enable_search(True)
        self.result_view.set_search_column(0)
        
        selection = self.result_view.get_selection()
        selection.set_mode(gtk.SELECTION_MULTIPLE)

        self.result_view.append_column(self.result_title_column)
        self.result_view.append_column(self.result_date_column)
        
        self.result_title_column.set_resizable(True)
        self.result_date_column.set_resizable(True)
        
        self.result_title_column.set_sort_column_id(0)
        self.result_date_column.set_sort_column_id(1)
        
        self.result_title_column.set_reorderable(True)
        self.result_date_column.set_reorderable(True)

        cell = gtk.CellRendererText()
        
        self.result_title_column.pack_start(cell, True)
        self.result_date_column.pack_start(cell, True)
        
        self.result_title_column.set_attributes(cell, text=0)
        self.result_date_column.set_attributes(cell, text=1)
        

    keyword = property(get_keyword, set_keyword)
    profile = property(get_profile, set_profile)
    option = property(get_option, set_option)
    target = property(get_target, set_target)
    mac = property(get_mac, set_mac)
    ipv4 = property(get_ipv4, set_ipv4)
    ipv6 = property(get_ipv6, set_ipv6)
    port = property(get_port, set_port)
    port_open = property(get_port_open, set_port_open)
    port_filtered = property(get_port_filtered, set_port_filtered)
    port_closed = property(get_port_closed, set_port_closed)
    service = property(get_service, set_service)
    product = property(get_product, set_product)
    osclass = property(get_osclass, set_osclass)
    osmatch = property(get_osmatch, set_osmatch)
    directory = property(get_directory, set_directory)
    file_extension = property(get_file_extension, set_file_extension)
    save_time = property(get_save_time, set_save_time)
    save = property(get_save, set_save)
    search_db = property(get_search_db, set_search_db)
    selected_results = property(get_selected_results)
class ServiceFingerprintReport(gtk.Window, object):
    def __init__(self, service_name, fingerprint, ip):
        gtk.Window.__init__(self)
        self.set_title(_('Service Fingerprint Report'))
        self.set_position(gtk.WIN_POS_CENTER_ALWAYS)

        self._create_widgets()
        self._pack_widgets()
        self._connect_widgets()

        self.fingerprint = fingerprint
        self.ip = ip
        self.service_name = service_name

    def _create_widgets(self):
        self.vbox = HIGVBox()
        self.button_box = gtk.HButtonBox()
        
        self.submitted_label = HIGHintSectionLabel(_("Submitted by (optional)"),
                                                   _("Enter your name and \
e-mail address if we can contact you with any questions. (kept private, used \
for nothing else)"))
        self.submitted_entry = gtk.Entry()

        self.service_name_label = HIGHintSectionLabel(_("Service Name"),
                                                      _("E.g. smtp, pop-3, \
http, domain, ssh, etc. Umit tries to automaticly fill this field for you, \
based on the Nmap \"SERVICE\" output field. If it is correct, you don't need \
to worry about filling out this field. "))
        self.service_name_entry = gtk.Entry()

        self.platform_label = HIGHintSectionLabel(_("Platform/OS"),
                                                  _('The operating system \
or embedded device the service is running on - Examples are "Linux 2.4.X", \
"Windows XP", "Cisco 3640 router", "Netgear MR814 WAP"'))
        self.platform_entry = gtk.Entry()

        self.service_description_label = HIGHintSectionLabel(_("Service \
Description"),
                                                             _("Please try to \
include vendor name, app name, and version number as applicable. It is OK to \
leave this blank for embedded devices where you have described the hardware \
above and don't have any further details on the service name/version. Here \
are a few examples: ISC Bind 9.2.2, Sendmail 8.12.9/8.10.2, Microsoft Exchange \
5.5.2656.59, Network Associates WebShield 4.5"))
        self.service_description_entry = gtk.Entry()

        self.notes_label = HIGHintSectionLabel(_("Notes"),
                                               _("Further info on the device \
or service, any special customizations, etc. If it isn't obvious, please let \
me know what the service is (Virus scanning email gateway, Gnutella-protocol \
P2P app, print server web configuration port, etc"))
        self.notes_scrolled = gtk.ScrolledWindow()
        self.notes_text = gtk.TextView()

        self.fingerprint_icon = gtk.Image()
        self.fingerprint_text = gtk.Label(_("This form allows you to \
contribute new service/version fingerprints to the Nmap database. Thanks for \
helping! <b>Please do not fill this out unless you are sure that you know what \
application is running on the machine you are submitting</b>. Incorrect \
entries can pollute the database. By submitting fingerprints you are \
transfering any copyright interest in the data to Fyodor so that he \
can modify it, relicense it, incorporate it into programs such as Nmap, etc."))

        self.btn_ok = gtk.Button(stock=gtk.STOCK_OK)
        self.btn_cancel = gtk.Button(stock=gtk.STOCK_CANCEL)

        self.hbox = HIGHBox()
        self.table = HIGTable()

    def _pack_widgets(self):
        self.notes_scrolled.add(self.notes_text)
        self.notes_scrolled.set_policy(gtk.POLICY_AUTOMATIC,
                                       gtk.POLICY_AUTOMATIC)
        self.notes_scrolled.set_size_request(400, 150)
        self.notes_text.set_wrap_mode(gtk.WRAP_WORD)

        self.fingerprint_icon.set_from_stock(gtk.STOCK_DIALOG_INFO,
                                             gtk.ICON_SIZE_DIALOG)
        self.fingerprint_icon.set_padding(10, 0)
        self.fingerprint_text.set_line_wrap(True)
        self.fingerprint_text.set_use_markup(True)

        self.table.attach_label(self.submitted_label, 0, 1, 0, 1)
        self.table.attach_entry(self.submitted_entry, 1, 2, 0, 1)
        
        self.table.attach_label(self.platform_label, 0, 1, 1, 2)
        self.table.attach_entry(self.platform_entry, 1, 2, 1, 2)

        self.table.attach_label(self.service_name_label, 0, 1, 2, 3)
        self.table.attach_entry(self.service_name_entry, 1, 2, 2, 3)

        self.table.attach_label(self.service_description_label, 0, 1, 3, 4)
        self.table.attach_entry(self.service_description_entry, 1, 2, 3, 4)

        self.table.attach_label(self.notes_label, 0, 2, 4, 5)
        self.table.attach_entry(self.notes_scrolled, 0, 2, 5, 6)

        self.hbox.set_border_width(12)
        self.hbox._pack_noexpand_nofill(self.fingerprint_icon)
        self.hbox._pack_expand_fill(self.fingerprint_text)

        self.button_box.set_layout(gtk.BUTTONBOX_END)
        self.button_box.pack_start(self.btn_ok)
        self.button_box.pack_start(self.btn_cancel)

        self.vbox.set_border_width(6)
        self.vbox._pack_noexpand_nofill(self.hbox)
        self.vbox._pack_expand_fill(self.table)
        self.vbox._pack_noexpand_nofill(self.button_box)
        self.add(self.vbox)

    def _connect_widgets(self):
        self.btn_ok.connect("clicked", self.send_report)
        self.btn_cancel.connect("clicked", self.close)
        self.connect("delete-event", self.close)

    def close(self, widget=None, event=None):
        self.destroy()

    def send_report(self, widget):
        if self.service_name == "" or self.service_description == "" or \
           self.platform == "":
            cancel_dialog = HIGAlertDialog(type=gtk.MESSAGE_ERROR,
                                           message_format=_("Service \
Fingerprint report is incomplete!"),
                                           secondary_text=_("The Service \
Fingerprint report is incomplete. Please, try to provide as much information \
as possible."))
            cancel_dialog.run()
            cancel_dialog.destroy()
            return None

        service_register = ServiceFingerprintRegister()

        service_register.service = self.service_name
        service_register.platform = self.platform
        service_register.description = self.service_description
        service_register.ip = self.ip
        service_register.fingerprint = self.fingerprint
        service_register.email = self.submitted
        service_register.notes = self.notes

        try:
            service_register.report()
        except:
            cancel_dialog = HIGAlertDialog(type=gtk.MESSAGE_ERROR,
                                           message_format=_("Service \
Fingerprint not registered!"),
                                           secondary_text=_("The Service \
Fingerprint could not be registered. This problem may be caused by the lack \
of Internet Access or indisponibility of the fingerprint server. Please, \
verify your internet access, and then try to register the service fingerprint \
once again."))
            cancel_dialog.run()
            cancel_dialog.destroy()
        else:
            ok_dialog = HIGAlertDialog(type=gtk.MESSAGE_INFO,
                                       message_format=_("Service Fingerprint \
sucessfully registered!"),
                                       secondary_text=_("The Service \
Fingerprint was sucessfully registered. A web page with detailed description \
about this registration is going to be openned in your default web browser."))
            ok_dialog.run()
            ok_dialog.destroy()

            self.close()

    def run_unblocked(self):
        if not self.modal:
            self.set_modal(True)
        self.show_all()

    def get_submitted(self):
        return self.submitted_entry.get_text()

    def set_submitted(self, submitted):
        self.submitted_entry.set_text(submitted)

    def get_platform(self):
        return self.platform_entry.get_text()

    def set_platform(self, platform):
        self.platform_entry.set_text(platform)

    def get_service_name(self):
        return self.service_name_entry.get_text()

    def set_service_name(self, service_name):
        self.service_name_entry.set_text(service_name)

    def get_service_description(self):
        return self.service_description_entry.get_text()

    def set_service_description(self, service_description):
        self.service_description_entry.set_text(service_description)

    def get_notes(self):
        buff = self.notes_text.get_buffer()
        return buff.get_text(buff.get_start_iter(), buff.get_end_iter())

    def set_notes(self, notes):
        self.notes_text.get_buffer().set_text(notes)

    submitted = property(get_submitted, set_submitted)
    platform = property(get_platform, set_platform)
    service_name = property(get_service_name, set_service_name)
    service_description = property(get_service_description,
                                   set_service_description)
    notes = property(get_notes, set_notes)
class RegistrationDialog(HIGDialog):
    """"""

    #----------------------------------------------------------------------
    def __init__(self, title=_('Registration')):
        """Constructor"""
        HIGDialog.__init__(self,
                           title=title,
                           buttons=(gtk.STOCK_OK, gtk.RESPONSE_ACCEPT,
                                    gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))

        self.set_position(gtk.WIN_POS_CENTER_ALWAYS)

        self._create_widgets()
        self._pack_widgets()

        # Register callbacks
        self.connect("response", self.check_response)

    def _create_widgets(self):
        self.username_label = HIGLabel(_("Username"))
        self.username_entry = gtk.Entry()

        self.password_label = HIGLabel(_("Password"))
        self.password_entry = HIGPasswordEntry()

        self.retype_password_label = HIGLabel(_("Retype password"))
        self.retype_password_entry = HIGPasswordEntry()

        self.registration_icon = gtk.Image()
        self.registration_text = gtk.Label(
            _("If you don't have an ICM account,"
              "please register a new account."))

        self.hbox = HIGHBox()
        self.table = HIGTable()

    def _pack_widgets(self):
        self.registration_icon.set_from_stock(gtk.STOCK_DIALOG_INFO,
                                              gtk.ICON_SIZE_DIALOG)
        self.registration_icon.set_padding(10, 0)
        self.registration_text.set_line_wrap(True)

        self.hbox.set_border_width(12)
        self.hbox._pack_noexpand_nofill(self.registration_icon)
        self.hbox._pack_expand_fill(self.registration_text)

        self.vbox.pack_start(self.hbox, False, False)
        self.table.attach_label(self.username_label, 0, 1, 0, 1)
        self.table.attach_entry(self.username_entry, 1, 2, 0, 1)
        self.table.attach_label(self.password_label, 0, 1, 1, 2)
        self.table.attach_entry(self.password_entry, 1, 2, 1, 2)
        self.table.attach_label(self.retype_password_label, 0, 1, 2, 3)
        self.table.attach_entry(self.retype_password_entry, 1, 2, 2, 3)
        self.vbox.pack_start(self.table)

    def check_response(self, widget, response_id):
        if response_id == gtk.RESPONSE_ACCEPT:  # clicked on Ok btn
            self.register()
        elif response_id in (gtk.RESPONSE_DELETE_EVENT, gtk.RESPONSE_CANCEL,
                             gtk.RESPONSE_NONE):
            self.destroy()

    def register(self):
        username = self.username_entry.get_text()
        password = self.password_entry.get_text()
        theApp.aggregator.register(username, password)
class FeedbackPage(HIGVBox):
    """"""

    #----------------------------------------------------------------------
    def __init__(self):
        """Constructor"""
        HIGVBox.__init__(self)
        self.__create_widgets()
        self.__pack_widgets()
        self.__set_values()

    def __create_widgets(self):
        self.suggestion_hbox = HIGHBox()
        self.report_hbox = HIGHBox()

        self.suggestion_section = HIGSectionLabel(_("Test Suggestion"))
        self.suggestion_table = HIGTable()
        self.report_section = HIGSectionLabel(_("Bug Report"))
        self.report_table = HIGTable()

        # Website Suggestion
        self.website_suggestion_table = HIGTable()
        self.website_suggestion_slabel = HIGSectionLabel(_("Website Suggestion"))
        self.website_url_subhbox = HIGHBox()
        self.website_url_label = HIGEntryLabel(_("URL:"))
        self.website_url_entry = gtk.Entry()
        self.website_suggestion_sendbtn = HIGButton(_('Send'))
        self.website_suggestion_sendbtn.set_size_request(60, 25)
        self.website_suggestion_sendbtn.connect(
            'clicked', lambda x: self.send_website_suggestion())
        # Service Suggestion
        self.service_suggestion_table = HIGTable()
        self.service_suggestion_slabel = HIGSectionLabel(_("Service Suggestion"))
        self.service_name_subhbox = HIGHBox()
        self.service_name_label = HIGEntryLabel(_("Name:"))
        self.service_list_store = gtk.ListStore(str)
        self.service_name_entry = gtk.ComboBoxEntry(self.service_list_store, 0)
        self.service_host_subhbox = HIGHBox()
        self.service_host_label = HIGEntryLabel(_("Hostname:"))
        self.service_host_entry = gtk.Entry()
        self.service_ip_subhbox = HIGHBox()
        self.service_ip_label = HIGEntryLabel(_("IP:"))
        self.service_ip_entry = gtk.Entry()
        self.service_port_label = HIGEntryLabel(_("PORT:"))
        self.service_port_entry = gtk.Entry()        
        self.service_suggestion_sendbtn = HIGButton(_('Send'))
        self.service_suggestion_sendbtn.set_size_request(60, 25)
        self.service_suggestion_sendbtn.connect(
            'clicked', lambda x: self.send_service_suggestion())

        self.report_namelabel = HIGEntryLabel(_("Your Name:"))
        self.report_nameentry = gtk.Entry()
        #self.report_nameentry.set_has_frame(True)
        self.report_nameentry.set_size_request(100, 26)
        self.report_emaillabel = HIGEntryLabel(_("Email:"))
        self.report_emailentry = gtk.Entry()
        self.report_emailentry.set_size_request(198, 26)
        self.report_subhbox1 = HIGHBox()

        self.report_sw = gtk.ScrolledWindow()
        self.report_sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        self.report_textview = gtk.TextView()
        self.report_textbuffer = self.report_textview.get_buffer()
        self.report_textview.set_editable(True)
        self.report_textview.set_wrap_mode(True)
        self.report_textview.set_border_width(2)
        self.report_sw.add(self.report_textview)
        self.report_sw.show()
        self.report_textview.show()
        self.report_subhbox2 = HIGHBox()
        self.report_sendbtn = HIGButton(_('Send'))
        self.report_sendbtn.set_size_request(60, 25)
        self.report_sendbtn.connect('clicked', lambda x: self.send_bug_report())
        self.report_subhbox3 = HIGHBox()

    def __pack_widgets(self):
        self.set_border_width(12)

        self._pack_noexpand_nofill(self.suggestion_section)
        self._pack_noexpand_nofill(self.suggestion_hbox)
        self._pack_noexpand_nofill(self.report_section)
        self._pack_noexpand_nofill(self.report_hbox)

        #self.suggestion_hbox._pack_noexpand_nofill(hig_box_space_holder())
        #self.suggestion_hbox._pack_expand_fill(self.suggestion_table)
        #self.report_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.report_hbox._pack_expand_fill(self.report_table)


        self.suggestion_hbox._pack_expand_fill(self.suggestion_table)
        #self.suggestion_hbox._pack_expand_fill(self.service_suggestion_table)

        self.suggestion_table.attach_label(self.website_suggestion_slabel,
                                           0, 2, 0, 1)
        self.suggestion_table.attach_label(self.website_url_label,
                                           0, 1, 1, 2)
        self.suggestion_table.attach_entry(self.website_url_entry,
                                           1, 2, 1, 2)
        self.suggestion_table.attach(self.website_suggestion_sendbtn,
                                     0, 2, 2, 3, gtk.PACK_START)

        self.suggestion_table.attach_label(self.service_suggestion_slabel,
                                           2, 4, 0, 1)
        self.suggestion_table.attach_label(self.service_name_label,
                                           2, 3, 1, 2)
        self.suggestion_table.attach_entry(self.service_name_entry,
                                           3, 4, 1, 2)
        self.suggestion_table.attach_label(self.service_host_label,
                                           2, 3, 2, 3)
        self.suggestion_table.attach_entry(self.service_host_entry,
                                           3, 4, 2, 3)
        self.suggestion_table.attach_label(self.service_ip_label,
                                           2, 3, 3, 4)
        self.suggestion_table.attach_entry(self.service_ip_entry,
                                           3, 4, 3, 4)
        self.suggestion_table.attach_label(self.service_port_label,
                                           2, 3, 4, 5)
        self.suggestion_table.attach_entry(self.service_port_entry,
                                           3, 4, 4, 5)        
        
        self.suggestion_table.attach(self.service_suggestion_sendbtn,
                                     2, 4, 5, 6, gtk.PACK_START)

        self.report_subhbox1.pack_start(self.report_namelabel, True, True, 0)
        self.report_subhbox1.pack_start(self.report_nameentry, True, True, 0)
        self.report_subhbox1.pack_start(self.report_emaillabel, True, True, 0)
        self.report_subhbox1.pack_start(self.report_emailentry)
        self.report_table.attach(self.report_subhbox1, 0, 1, 0, 1)
        self.report_subhbox2.pack_start(self.report_sw)
        self.report_table.attach(self.report_subhbox2, 0, 1, 1, 2)
        self.report_subhbox3.pack_start(self.report_sendbtn)
        self.report_table.attach(self.report_subhbox3, 0, 1, 2, 3, gtk.PACK_START)

    def __set_values(self):
        from umit.icm.agent.test import SUPPORTED_SERVICES
        for each in SUPPORTED_SERVICES:
            self.service_list_store.append([each])

    def send_website_suggestion(self):
        website_url = self.website_url_entry.get_text()
        if website_url == '':
            alert = HIGAlertDialog(message_format=_("Missing fields."),
                                   secondary_text=_("Please input all fields "
                                                    "for website suggestion."))
            alert.run()
            alert.destroy()
            return
        d = theApp.aggregator.send_website_suggestion(website_url)
        d.addCallback(self.show_success)
        d.addErrback(self.show_failed)

    def send_service_suggestion(self):
        service_name = self.service_name_entry.child.get_text()
        host_name = self.service_host_entry.get_text()
        ip = self.service_ip_entry.get_text()
        port = int(self.service_port_entry.get_text())
        if service_name == '' or host_name == '' or ip == '' or port == "":
            alert = HIGAlertDialog(message_format=_("Missing fields."),
                                   secondary_text=_("Please input all fields "\
                                                    "for service suggestion."))
            alert.run()
            alert.destroy()
            return
        d = theApp.aggregator.send_service_suggestion(service_name, host_name, ip,port)
        d.addCallback(self.show_success)
        d.addErrback(self.show_failed)
        

    def send_bug_report(self):
        pass
    
    def show_failed(self,result):
        """
        """
        alert = HIGAlertDialog(message_format=_("Error."),
                                   secondary_text=_("Send to aggregaetor failed."))
        alert.run()
        alert.destroy()
        
    def show_success(self, result):
        """
        """
        if result is not None:
            alert = HIGAlertDialog(message_format=_("Succuss."),
                                   secondary_text=_("Send to aggregaetor successfully."))
            alert.run()
            alert.destroy()
        else:
            alert = HIGAlertDialog(message_format=_("Error."),
                                   secondary_text=_("Send to aggregaetor failed."))
            alert.run()
            alert.destroy()
class ServiceFingerprintReport(gtk.Window, object):
    def __init__(self, service_name, fingerprint, ip):
        gtk.Window.__init__(self)
        self.set_title(_('Service Fingerprint Report'))
        self.set_position(gtk.WIN_POS_CENTER_ALWAYS)

        self._create_widgets()
        self._pack_widgets()
        self._connect_widgets()

        self.fingerprint = fingerprint
        self.ip = ip
        self.service_name = service_name

    def _create_widgets(self):
        self.vbox = HIGVBox()
        self.button_box = gtk.HButtonBox()

        self.submitted_label = HIGHintSectionLabel(
            _("Submitted by (optional)"),
            _("Enter your name and \
e-mail address if we can contact you with any questions. (kept private, used \
for nothing else)"))
        self.submitted_entry = gtk.Entry()

        self.service_name_label = HIGHintSectionLabel(
            _("Service Name"),
            _("E.g. smtp, pop-3, \
http, domain, ssh, etc. Umit tries to automaticly fill this field for you, \
based on the Nmap \"SERVICE\" output field. If it is correct, you don't need \
to worry about filling out this field. "))
        self.service_name_entry = gtk.Entry()

        self.platform_label = HIGHintSectionLabel(
            _("Platform/OS"),
            _('The operating system \
or embedded device the service is running on - Examples are "Linux 2.4.X", \
"Windows XP", "Cisco 3640 router", "Netgear MR814 WAP"'))
        self.platform_entry = gtk.Entry()

        self.service_description_label = HIGHintSectionLabel(
            _("Service \
Description"),
            _("Please try to \
include vendor name, app name, and version number as applicable. It is OK to \
leave this blank for embedded devices where you have described the hardware \
above and don't have any further details on the service name/version. Here \
are a few examples: ISC Bind 9.2.2, Sendmail 8.12.9/8.10.2, Microsoft Exchange \
5.5.2656.59, Network Associates WebShield 4.5"))
        self.service_description_entry = gtk.Entry()

        self.notes_label = HIGHintSectionLabel(
            _("Notes"),
            _("Further info on the device \
or service, any special customizations, etc. If it isn't obvious, please let \
me know what the service is (Virus scanning email gateway, Gnutella-protocol \
P2P app, print server web configuration port, etc"))
        self.notes_scrolled = gtk.ScrolledWindow()
        self.notes_text = gtk.TextView()

        self.fingerprint_icon = gtk.Image()
        self.fingerprint_text = gtk.Label(
            _("This form allows you to \
contribute new service/version fingerprints to the Nmap database. Thanks for \
helping! <b>Please do not fill this out unless you are sure that you know what \
application is running on the machine you are submitting</b>. Incorrect \
entries can pollute the database. By submitting fingerprints you are \
transfering any copyright interest in the data to Fyodor so that he \
can modify it, relicense it, incorporate it into programs such as Nmap, etc."))

        self.btn_ok = gtk.Button(stock=gtk.STOCK_OK)
        self.btn_cancel = gtk.Button(stock=gtk.STOCK_CANCEL)

        self.hbox = HIGHBox()
        self.table = HIGTable()

    def _pack_widgets(self):
        self.notes_scrolled.add(self.notes_text)
        self.notes_scrolled.set_policy(gtk.POLICY_AUTOMATIC,
                                       gtk.POLICY_AUTOMATIC)
        self.notes_scrolled.set_size_request(400, 150)
        self.notes_text.set_wrap_mode(gtk.WRAP_WORD)

        self.fingerprint_icon.set_from_stock(gtk.STOCK_DIALOG_INFO,
                                             gtk.ICON_SIZE_DIALOG)
        self.fingerprint_icon.set_padding(10, 0)
        self.fingerprint_text.set_line_wrap(True)
        self.fingerprint_text.set_use_markup(True)

        self.table.attach_label(self.submitted_label, 0, 1, 0, 1)
        self.table.attach_entry(self.submitted_entry, 1, 2, 0, 1)

        self.table.attach_label(self.platform_label, 0, 1, 1, 2)
        self.table.attach_entry(self.platform_entry, 1, 2, 1, 2)

        self.table.attach_label(self.service_name_label, 0, 1, 2, 3)
        self.table.attach_entry(self.service_name_entry, 1, 2, 2, 3)

        self.table.attach_label(self.service_description_label, 0, 1, 3, 4)
        self.table.attach_entry(self.service_description_entry, 1, 2, 3, 4)

        self.table.attach_label(self.notes_label, 0, 2, 4, 5)
        self.table.attach_entry(self.notes_scrolled, 0, 2, 5, 6)

        self.hbox.set_border_width(12)
        self.hbox._pack_noexpand_nofill(self.fingerprint_icon)
        self.hbox._pack_expand_fill(self.fingerprint_text)

        self.button_box.set_layout(gtk.BUTTONBOX_END)
        self.button_box.pack_start(self.btn_ok)
        self.button_box.pack_start(self.btn_cancel)

        self.vbox.set_border_width(6)
        self.vbox._pack_noexpand_nofill(self.hbox)
        self.vbox._pack_expand_fill(self.table)
        self.vbox._pack_noexpand_nofill(self.button_box)
        self.add(self.vbox)

    def _connect_widgets(self):
        self.btn_ok.connect("clicked", self.send_report)
        self.btn_cancel.connect("clicked", self.close)
        self.connect("delete-event", self.close)

    def close(self, widget=None, event=None):
        self.destroy()

    def send_report(self, widget):
        if self.service_name == "" or self.service_description == "" or \
           self.platform == "":
            cancel_dialog = HIGAlertDialog(type=gtk.MESSAGE_ERROR,
                                           message_format=_("Service \
Fingerprint report is incomplete!"),
                                           secondary_text=_("The Service \
Fingerprint report is incomplete. Please, try to provide as much information \
as possible."))
            cancel_dialog.run()
            cancel_dialog.destroy()
            return None

        service_register = ServiceFingerprintRegister()

        service_register.service = self.service_name
        service_register.platform = self.platform
        service_register.description = self.service_description
        service_register.ip = self.ip
        service_register.fingerprint = self.fingerprint
        service_register.email = self.submitted
        service_register.notes = self.notes

        try:
            service_register.report()
        except:
            cancel_dialog = HIGAlertDialog(type=gtk.MESSAGE_ERROR,
                                           message_format=_("Service \
Fingerprint not registered!"),
                                           secondary_text=_("The Service \
Fingerprint could not be registered. This problem may be caused by the lack \
of Internet Access or indisponibility of the fingerprint server. Please, \
verify your internet access, and then try to register the service fingerprint \
once again."))
            cancel_dialog.run()
            cancel_dialog.destroy()
        else:
            ok_dialog = HIGAlertDialog(type=gtk.MESSAGE_INFO,
                                       message_format=_("Service Fingerprint \
sucessfully registered!"),
                                       secondary_text=_("The Service \
Fingerprint was sucessfully registered. A web page with detailed description \
about this registration is going to be openned in your default web browser."))
            ok_dialog.run()
            ok_dialog.destroy()

            self.close()

    def run_unblocked(self):
        if not self.modal:
            self.set_modal(True)
        self.show_all()

    def get_submitted(self):
        return self.submitted_entry.get_text()

    def set_submitted(self, submitted):
        self.submitted_entry.set_text(submitted)

    def get_platform(self):
        return self.platform_entry.get_text()

    def set_platform(self, platform):
        self.platform_entry.set_text(platform)

    def get_service_name(self):
        return self.service_name_entry.get_text()

    def set_service_name(self, service_name):
        self.service_name_entry.set_text(service_name)

    def get_service_description(self):
        return self.service_description_entry.get_text()

    def set_service_description(self, service_description):
        self.service_description_entry.set_text(service_description)

    def get_notes(self):
        buff = self.notes_text.get_buffer()
        return buff.get_text(buff.get_start_iter(), buff.get_end_iter())

    def set_notes(self, notes):
        self.notes_text.get_buffer().set_text(notes)

    submitted = property(get_submitted, set_submitted)
    platform = property(get_platform, set_platform)
    service_name = property(get_service_name, set_service_name)
    service_description = property(get_service_description,
                                   set_service_description)
    notes = property(get_notes, set_notes)
class FeedbackPage(HIGVBox):
    """"""

    #----------------------------------------------------------------------
    def __init__(self):
        """Constructor"""
        HIGVBox.__init__(self)
        self.__create_widgets()
        self.__pack_widgets()
        self.__set_values()

    def __create_widgets(self):
        self.suggestion_hbox = HIGHBox()
        self.report_hbox = HIGHBox()

        self.suggestion_section = HIGSectionLabel(_("Test Suggestion"))
        self.suggestion_table = HIGTable()
        self.report_section = HIGSectionLabel(_("Bug Report"))
        self.report_table = HIGTable()

        # Website Suggestion
        self.website_suggestion_table = HIGTable()
        self.website_suggestion_slabel = HIGSectionLabel(
            _("Website Suggestion"))
        self.website_url_subhbox = HIGHBox()
        self.website_url_label = HIGEntryLabel(_("URL:"))
        self.website_url_entry = gtk.Entry()
        self.website_suggestion_sendbtn = HIGButton(_('Send'))
        self.website_suggestion_sendbtn.set_size_request(60, 25)
        self.website_suggestion_sendbtn.connect(
            'clicked', lambda x: self.send_website_suggestion())
        # Service Suggestion
        self.service_suggestion_table = HIGTable()
        self.service_suggestion_slabel = HIGSectionLabel(
            _("Service Suggestion"))
        self.service_name_subhbox = HIGHBox()
        self.service_name_label = HIGEntryLabel(_("Name:"))
        self.service_list_store = gtk.ListStore(str)
        self.service_name_entry = gtk.ComboBoxEntry(self.service_list_store, 0)
        self.service_host_subhbox = HIGHBox()
        self.service_host_label = HIGEntryLabel(_("Hostname:"))
        self.service_host_entry = gtk.Entry()
        self.service_ip_subhbox = HIGHBox()
        self.service_ip_label = HIGEntryLabel(_("IP:"))
        self.service_ip_entry = gtk.Entry()
        self.service_port_label = HIGEntryLabel(_("PORT:"))
        self.service_port_entry = gtk.Entry()
        self.service_suggestion_sendbtn = HIGButton(_('Send'))
        self.service_suggestion_sendbtn.set_size_request(60, 25)
        self.service_suggestion_sendbtn.connect(
            'clicked', lambda x: self.send_service_suggestion())

        self.report_namelabel = HIGEntryLabel(_("Your Name:"))
        self.report_nameentry = gtk.Entry()
        #self.report_nameentry.set_has_frame(True)
        self.report_nameentry.set_size_request(100, 26)
        self.report_emaillabel = HIGEntryLabel(_("Email:"))
        self.report_emailentry = gtk.Entry()
        self.report_emailentry.set_size_request(198, 26)
        self.report_subhbox1 = HIGHBox()

        self.report_sw = gtk.ScrolledWindow()
        self.report_sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        self.report_textview = gtk.TextView()
        self.report_textbuffer = self.report_textview.get_buffer()
        self.report_textview.set_editable(True)
        self.report_textview.set_wrap_mode(True)
        self.report_textview.set_border_width(2)
        self.report_sw.add(self.report_textview)
        self.report_sw.show()
        self.report_textview.show()
        self.report_subhbox2 = HIGHBox()
        self.report_sendbtn = HIGButton(_('Send'))
        self.report_sendbtn.set_size_request(60, 25)
        self.report_sendbtn.connect('clicked',
                                    lambda x: self.send_bug_report())
        self.report_subhbox3 = HIGHBox()

    def __pack_widgets(self):
        self.set_border_width(12)

        self._pack_noexpand_nofill(self.suggestion_section)
        self._pack_noexpand_nofill(self.suggestion_hbox)
        self._pack_noexpand_nofill(self.report_section)
        self._pack_noexpand_nofill(self.report_hbox)

        #self.suggestion_hbox._pack_noexpand_nofill(hig_box_space_holder())
        #self.suggestion_hbox._pack_expand_fill(self.suggestion_table)
        #self.report_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.report_hbox._pack_expand_fill(self.report_table)

        self.suggestion_hbox._pack_expand_fill(self.suggestion_table)
        #self.suggestion_hbox._pack_expand_fill(self.service_suggestion_table)

        self.suggestion_table.attach_label(self.website_suggestion_slabel, 0,
                                           2, 0, 1)
        self.suggestion_table.attach_label(self.website_url_label, 0, 1, 1, 2)
        self.suggestion_table.attach_entry(self.website_url_entry, 1, 2, 1, 2)
        self.suggestion_table.attach(self.website_suggestion_sendbtn, 0, 2, 2,
                                     3, gtk.PACK_START)

        self.suggestion_table.attach_label(self.service_suggestion_slabel, 2,
                                           4, 0, 1)
        self.suggestion_table.attach_label(self.service_name_label, 2, 3, 1, 2)
        self.suggestion_table.attach_entry(self.service_name_entry, 3, 4, 1, 2)
        self.suggestion_table.attach_label(self.service_host_label, 2, 3, 2, 3)
        self.suggestion_table.attach_entry(self.service_host_entry, 3, 4, 2, 3)
        self.suggestion_table.attach_label(self.service_ip_label, 2, 3, 3, 4)
        self.suggestion_table.attach_entry(self.service_ip_entry, 3, 4, 3, 4)
        self.suggestion_table.attach_label(self.service_port_label, 2, 3, 4, 5)
        self.suggestion_table.attach_entry(self.service_port_entry, 3, 4, 4, 5)

        self.suggestion_table.attach(self.service_suggestion_sendbtn, 2, 4, 5,
                                     6, gtk.PACK_START)

        self.report_subhbox1.pack_start(self.report_namelabel, True, True, 0)
        self.report_subhbox1.pack_start(self.report_nameentry, True, True, 0)
        self.report_subhbox1.pack_start(self.report_emaillabel, True, True, 0)
        self.report_subhbox1.pack_start(self.report_emailentry)
        self.report_table.attach(self.report_subhbox1, 0, 1, 0, 1)
        self.report_subhbox2.pack_start(self.report_sw)
        self.report_table.attach(self.report_subhbox2, 0, 1, 1, 2)
        self.report_subhbox3.pack_start(self.report_sendbtn)
        self.report_table.attach(self.report_subhbox3, 0, 1, 2, 3,
                                 gtk.PACK_START)

    def __set_values(self):
        from umit.icm.agent.test import SUPPORTED_SERVICES
        for each in SUPPORTED_SERVICES:
            self.service_list_store.append([each])

    def send_website_suggestion(self):
        website_url = self.website_url_entry.get_text()
        if website_url == '':
            alert = HIGAlertDialog(message_format=_("Missing fields."),
                                   secondary_text=_("Please input all fields "
                                                    "for website suggestion."))
            alert.run()
            alert.destroy()
            return
        d = theApp.aggregator.send_website_suggestion(website_url)
        d.addCallback(self.show_success)
        d.addErrback(self.show_failed)

    def send_service_suggestion(self):
        service_name = self.service_name_entry.child.get_text()
        host_name = self.service_host_entry.get_text()
        ip = self.service_ip_entry.get_text()
        port = int(self.service_port_entry.get_text())
        if service_name == '' or host_name == '' or ip == '' or port == "":
            alert = HIGAlertDialog(message_format=_("Missing fields."),
                                   secondary_text=_("Please input all fields "\
                                                    "for service suggestion."))
            alert.run()
            alert.destroy()
            return
        d = theApp.aggregator.send_service_suggestion(service_name, host_name,
                                                      ip, port)
        d.addCallback(self.show_success)
        d.addErrback(self.show_failed)

    def send_bug_report(self):
        pass

    def show_failed(self, result):
        """
        """
        alert = HIGAlertDialog(message_format=_("Error."),
                               secondary_text=_("Send to aggregaetor failed."))
        alert.run()
        alert.destroy()

    def show_success(self, result):
        """
        """
        if result is not None:
            alert = HIGAlertDialog(
                message_format=_("Succuss."),
                secondary_text=_("Send to aggregaetor successfully."))
            alert.run()
            alert.destroy()
        else:
            alert = HIGAlertDialog(
                message_format=_("Error."),
                secondary_text=_("Send to aggregaetor failed."))
            alert.run()
            alert.destroy()
Example #19
0
class DiffColors(TabBox, object):
    def __init__(self, colors):
        self.colors = colors
        TabBox.__init__(self, _('Diff Colors'))
        self._pack_widgets()
        self._connect_widgets()



    def _create_widgets(self):
        self.vbox = HIGVBox()
        self.table = HIGTable()

        self.unchanged_button = gtk.ColorButton(self.colors.unchanged)
        self.unchanged_label = gtk.Label(_("Property remained <b>U</b>nchanged"))

        self.added_button = gtk.ColorButton(self.colors.added)
        self.added_label = gtk.Label(_("Property was <b>A</b>dded"))

        self.modified_button = gtk.ColorButton(self.colors.modified)
        self.modified_label = gtk.Label(_("Property was <b>M</b>odified"))

        self.not_present_button = gtk.ColorButton(self.colors.not_present)
        self.not_present_label = gtk.Label(_("Property is <b>N</b>ot present"))

    def _pack_widgets(self):
        self.unchanged_label.set_use_markup(True)
        self.added_label.set_use_markup(True)
        self.modified_label.set_use_markup(True)
        self.not_present_label.set_use_markup(True)

        self.table.attach_label(self.unchanged_button, 0, 1, 0, 1)
        self.table.attach_entry(self.unchanged_label, 1, 2, 0, 1)

        self.table.attach_label(self.added_button, 0, 1, 1, 2)
        self.table.attach_entry(self.added_label, 1, 2, 1, 2)

        self.table.attach_label(self.modified_button, 0, 1, 2, 3)
        self.table.attach_entry(self.modified_label, 1, 2, 2, 3)

        self.table.attach_label(self.not_present_button, 0, 1, 3, 4)
        self.table.attach_entry(self.not_present_label, 1, 2, 3, 4)

        self.vbox.pack_start(self.table)
        self.pack_start(self.vbox, False, False)


    def _connect_widgets(self):
        self.unchanged_button.connect("color-set",
                                      self.set_color,
                                      "unchanged")
        self.added_button.connect("color-set",
                                  self.set_color,
                                  "added")
        self.modified_button.connect("color-set",
                                     self.set_color,
                                     "modified")
        self.not_present_button.connect("color-set",
                                        self.set_color,
                                        "not_present")

    def set_color(self, widget, prop):
        self.colors.__setattr__(prop, widget.get_color())
class PeerInfoPage(HIGVBox):
    """"""
    
    #----------------------------------------------------------------------
    def __init__(self):
        """Constructor"""
        HIGVBox.__init__(self)
        self.__create_widgets()
        self.__pack_widgets()
        
    def __create_widgets(self):
        """"""
        self.peerinfo_hbox      = HIGHBox()
        self.cloudagg_hbox      = HIGHBox()
        self.superpeers_hbox    = HIGHBox()
        self.pref_location_hbox = HIGHBox()

        self.peerinfo_section = HIGSectionLabel(_("Peer Info"))
        self.peerinfo_table = HIGTable()
        
        self.pref_location_section = HIGSectionLabel(_("Preferred Locations"))
        self.pref_location_table = HIGTable()
        
        self.cloudagg_section = HIGSectionLabel(_("Cloud Aggregator"))
        self.cloudagg_table = HIGTable()
        self.cloudagg_subhbox = HIGHBox()
        self.superpeers_section = HIGSectionLabel(_("Super Peers"))
        self.superpeers_table = HIGTable()

        self.peerid_label = HIGEntryLabel(_("Peer ID:"))
        self.email_label = HIGEntryLabel(_("Email Address:")) 
        self.test_version_label = HIGEntryLabel(_("Test Sets Version:")) 
        self.peerid_label2 = HIGEntryLabel()
        self.email_entry = gtk.Entry()
        self.test_version_label2 = HIGEntryLabel()        

        self.longitude_label = HIGLabel(_("longitude:"))
        self.longitude_entry = gtk.Entry()
        self.latitude_label = HIGLabel(_("latitude:"))
        self.latitude_entry = gtk.Entry()                  

        self.cloudagg_entry = gtk.Entry()
        self.cloudagg_button = HIGButton(_("Reset"))
        self.cloudagg_button.connect('clicked', lambda w: self.reset_aggregator_url())
                                      
        self.cloudagg_button.set_size_request(80, 28)

        self.superpeers_ip_label = HIGLabel(_("IP:"))
        self.superpeers_ip_entry = gtk.Entry()
        self.superpeers_ip_entry.set_size_request(160, 26)
        self.superpeers_port_label = HIGLabel(_("Port:"))
        self.superpeers_port_entry = gtk.Entry()
        self.superpeers_port_entry.set_size_request(80, 26)        
        
        self.superpeers_subhbox = HIGHBox()
        self.btn_box = gtk.HButtonBox()
        self.superpeers_button1 = HIGButton(_("Add"))
        self.superpeers_button1.connect('clicked',lambda w:self.add_superpeer())
                        
        self.superpeers_button2 = HIGButton(_("Show all"))
        self.superpeers_button2.connect('clicked', lambda w:
                                        self.show_super_peer_list_window())

    def __pack_widgets(self):
        self.set_border_width(12)

        self._pack_noexpand_nofill(self.peerinfo_section)
        self._pack_noexpand_nofill(self.peerinfo_hbox)
        self._pack_noexpand_nofill(self.pref_location_section)
        self._pack_noexpand_nofill(self.pref_location_hbox)
        self._pack_noexpand_nofill(self.cloudagg_section)
        self._pack_noexpand_nofill(self.cloudagg_hbox)
        self._pack_noexpand_nofill(self.superpeers_section)
        self._pack_noexpand_nofill(self.superpeers_hbox)

        self.peerinfo_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.peerinfo_hbox._pack_expand_fill(self.peerinfo_table)
        self.pref_location_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.pref_location_hbox._pack_expand_fill(self.pref_location_table)        
        self.cloudagg_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.cloudagg_hbox._pack_expand_fill(self.cloudagg_table)
        self.superpeers_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.superpeers_hbox._pack_expand_fill(self.superpeers_table)

        self.peerinfo_table.attach_label(self.peerid_label, 0, 1, 0, 1)
        self.peerinfo_table.attach_label(self.email_label, 0, 1, 2, 3)

        self.peerinfo_table.attach_label(self.test_version_label, 0, 1, 1, 2)
        self.peerinfo_table.attach_label(self.test_version_label2, 1, 2, 1, 2)

        self.peerinfo_table.attach_label(self.peerid_label2, 1, 2, 0, 1)
        self.peerinfo_table.attach_entry(self.email_entry, 1, 2, 2, 3)

        self.pref_location_table.attach(self.longitude_label,0,1,0,1)
        self.pref_location_table.attach(self.longitude_entry,1,2,0,1)
        self.pref_location_table.attach(self.latitude_label,2,3,0,1)
        self.pref_location_table.attach(self.latitude_entry,3,4,0,1)
        
        self.cloudagg_subhbox._pack_expand_fill(self.cloudagg_entry)
        self.cloudagg_subhbox._pack_noexpand_nofill(self.cloudagg_button)
        self.cloudagg_table.attach_entry(self.cloudagg_subhbox, 0, 1, 0, 1)

        self.btn_box.set_layout(gtk.BUTTONBOX_END)
        self.btn_box.set_spacing(8)
        self.btn_box.pack_start(self.superpeers_button1)
        self.btn_box.pack_start(self.superpeers_button2)
        self.superpeers_subhbox._pack_expand_fill(self.superpeers_ip_label)
        self.superpeers_subhbox._pack_expand_fill(self.superpeers_ip_entry)
        self.superpeers_subhbox._pack_expand_fill(self.superpeers_port_label)
        self.superpeers_subhbox._pack_expand_fill(self.superpeers_port_entry)
        self.superpeers_subhbox._pack_noexpand_nofill(self.btn_box)
        self.superpeers_table.attach_label(self.superpeers_subhbox, 0, 1, 0, 1)
        

    def add_superpeer(self):
        """
        Add Super Peer by manual into database
        """
        ip = self.superpeers_ip_entry.get_text()
        port = self.superpeers_port_entry.get_text()
        
        g_db_helper.set_super_peer_manual(ip,port)
    
    def reset_aggregator_url(self):
        """
        """
        aggregator_url = 'http://east1.openmonitor.org'
        self.cloudagg_entry.set_text(aggregator_url)
        theApp.aggregator.base_url = aggregator_url
        g_config.set('network', 'aggregator_url', aggregator_url)
        g_db_helper.set_value('config','aggregator_url', aggregator_url)
        
    
            
    def show_super_peer_list_window(self):
        from umit.icm.agent.gui.Preference.SuperPeerSetting import SuperPeerListWindow,SuperPeersBox
        wnd = SuperPeerListWindow()
        wnd.show_all()
Example #21
0
class PeerInfoPage(HIGVBox):
    """"""

    #----------------------------------------------------------------------
    def __init__(self):
        """Constructor"""
        HIGVBox.__init__(self)
        self.__create_widgets()
        self.__pack_widgets()

    def __create_widgets(self):
        """"""
        self.peerinfo_hbox = HIGHBox()
        self.cloudagg_hbox = HIGHBox()
        self.superpeers_hbox = HIGHBox()
        self.pref_location_hbox = HIGHBox()

        self.peerinfo_section = HIGSectionLabel(_("Peer Info"))
        self.peerinfo_table = HIGTable()

        self.pref_location_section = HIGSectionLabel(_("Preferred Locations"))
        self.pref_location_table = HIGTable()

        self.cloudagg_section = HIGSectionLabel(_("Cloud Aggregator"))
        self.cloudagg_table = HIGTable()
        self.cloudagg_subhbox = HIGHBox()
        self.superpeers_section = HIGSectionLabel(_("Super Peers"))
        self.superpeers_table = HIGTable()

        self.peerid_label = HIGEntryLabel(_("Peer ID:"))
        self.email_label = HIGEntryLabel(_("Email Address:"))
        self.test_version_label = HIGEntryLabel(_("Test Sets Version:"))
        self.peerid_label2 = HIGEntryLabel()
        self.email_entry = gtk.Entry()
        self.test_version_label2 = HIGEntryLabel()

        self.longitude_label = HIGLabel(_("longitude:"))
        self.longitude_entry = gtk.Entry()
        self.latitude_label = HIGLabel(_("latitude:"))
        self.latitude_entry = gtk.Entry()

        self.cloudagg_entry = gtk.Entry()
        self.cloudagg_button = HIGButton(_("Reset"))
        self.cloudagg_button.connect('clicked',
                                     lambda w: self.reset_aggregator_url())

        self.cloudagg_button.set_size_request(80, 28)

        self.superpeers_ip_label = HIGLabel(_("IP:"))
        self.superpeers_ip_entry = gtk.Entry()
        self.superpeers_ip_entry.set_size_request(160, 26)
        self.superpeers_port_label = HIGLabel(_("Port:"))
        self.superpeers_port_entry = gtk.Entry()
        self.superpeers_port_entry.set_size_request(80, 26)

        self.superpeers_subhbox = HIGHBox()
        self.btn_box = gtk.HButtonBox()
        self.superpeers_button1 = HIGButton(_("Add"))
        self.superpeers_button1.connect('clicked',
                                        lambda w: self.add_superpeer())

        self.superpeers_button2 = HIGButton(_("Show all"))
        self.superpeers_button2.connect(
            'clicked', lambda w: self.show_super_peer_list_window())

    def __pack_widgets(self):
        self.set_border_width(12)

        self._pack_noexpand_nofill(self.peerinfo_section)
        self._pack_noexpand_nofill(self.peerinfo_hbox)
        self._pack_noexpand_nofill(self.pref_location_section)
        self._pack_noexpand_nofill(self.pref_location_hbox)
        self._pack_noexpand_nofill(self.cloudagg_section)
        self._pack_noexpand_nofill(self.cloudagg_hbox)
        self._pack_noexpand_nofill(self.superpeers_section)
        self._pack_noexpand_nofill(self.superpeers_hbox)

        self.peerinfo_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.peerinfo_hbox._pack_expand_fill(self.peerinfo_table)
        self.pref_location_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.pref_location_hbox._pack_expand_fill(self.pref_location_table)
        self.cloudagg_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.cloudagg_hbox._pack_expand_fill(self.cloudagg_table)
        self.superpeers_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.superpeers_hbox._pack_expand_fill(self.superpeers_table)

        self.peerinfo_table.attach_label(self.peerid_label, 0, 1, 0, 1)
        self.peerinfo_table.attach_label(self.email_label, 0, 1, 2, 3)

        self.peerinfo_table.attach_label(self.test_version_label, 0, 1, 1, 2)
        self.peerinfo_table.attach_label(self.test_version_label2, 1, 2, 1, 2)

        self.peerinfo_table.attach_label(self.peerid_label2, 1, 2, 0, 1)
        self.peerinfo_table.attach_entry(self.email_entry, 1, 2, 2, 3)

        self.pref_location_table.attach(self.longitude_label, 0, 1, 0, 1)
        self.pref_location_table.attach(self.longitude_entry, 1, 2, 0, 1)
        self.pref_location_table.attach(self.latitude_label, 2, 3, 0, 1)
        self.pref_location_table.attach(self.latitude_entry, 3, 4, 0, 1)

        self.cloudagg_subhbox._pack_expand_fill(self.cloudagg_entry)
        self.cloudagg_subhbox._pack_noexpand_nofill(self.cloudagg_button)
        self.cloudagg_table.attach_entry(self.cloudagg_subhbox, 0, 1, 0, 1)

        self.btn_box.set_layout(gtk.BUTTONBOX_END)
        self.btn_box.set_spacing(8)
        self.btn_box.pack_start(self.superpeers_button1)
        self.btn_box.pack_start(self.superpeers_button2)
        self.superpeers_subhbox._pack_expand_fill(self.superpeers_ip_label)
        self.superpeers_subhbox._pack_expand_fill(self.superpeers_ip_entry)
        self.superpeers_subhbox._pack_expand_fill(self.superpeers_port_label)
        self.superpeers_subhbox._pack_expand_fill(self.superpeers_port_entry)
        self.superpeers_subhbox._pack_noexpand_nofill(self.btn_box)
        self.superpeers_table.attach_label(self.superpeers_subhbox, 0, 1, 0, 1)

    def add_superpeer(self):
        """
        Add Super Peer by manual into database
        """
        ip = self.superpeers_ip_entry.get_text()
        port = self.superpeers_port_entry.get_text()

        g_db_helper.set_super_peer_manual(ip, port)

    def reset_aggregator_url(self):
        """
        """
        aggregator_url = 'http://east1.openmonitor.org'
        self.cloudagg_entry.set_text(aggregator_url)
        theApp.aggregator.base_url = aggregator_url
        g_config.set('network', 'aggregator_url', aggregator_url)
        g_db_helper.set_value('config', 'aggregator_url', aggregator_url)

    def show_super_peer_list_window(self):
        from umit.icm.agent.gui.Preference.SuperPeerSetting import SuperPeerListWindow, SuperPeersBox
        wnd = SuperPeerListWindow()
        wnd.show_all()
Example #22
0
class DiffLegendWindow(HIGDialog, object):
    def __init__(self, colors):
        # Shows colors and chars legend
        HIGDialog.__init__(self, title=_('Color Descriptions'),
                          buttons=(gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))

        self.colors = colors
        self._create_widgets()
        self._pack_widgets()
        self._connect_widgets()

    def _create_widgets(self):
        self.table = HIGTable()
        
        self.unchanged_button = gtk.ColorButton(self.colors.unchanged)
        self.unchanged_label = gtk.Label(_("Property remained <b>U</b>nchanged"))
        
        self.added_button = gtk.ColorButton(self.colors.added)
        self.added_label = gtk.Label(_("Property was <b>A</b>dded"))
        
        self.modified_button = gtk.ColorButton(self.colors.modified)
        self.modified_label = gtk.Label(_("Property was <b>M</b>odified"))
        
        self.not_present_button = gtk.ColorButton(self.colors.not_present)
        self.not_present_label = gtk.Label(_("Property is <b>N</b>ot present"))

    def _pack_widgets(self):
        self.unchanged_label.set_use_markup(True)
        self.added_label.set_use_markup(True)
        self.modified_label.set_use_markup(True)
        self.not_present_label.set_use_markup(True)

        self.table.attach_label(self.unchanged_button, 0, 1, 0, 1)
        self.table.attach_entry(self.unchanged_label, 1, 2, 0, 1)

        self.table.attach_label(self.added_button, 0, 1, 1, 2)
        self.table.attach_entry(self.added_label, 1, 2, 1, 2)

        self.table.attach_label(self.modified_button, 0, 1, 2, 3)
        self.table.attach_entry(self.modified_label, 1, 2, 2, 3)

        self.table.attach_label(self.not_present_button, 0, 1, 3, 4)
        self.table.attach_entry(self.not_present_label, 1, 2, 3, 4)

        self.vbox.pack_start(self.table)
        self.vbox.show_all()

    def _connect_widgets(self):
        self.unchanged_button.connect("color-set",
                                      self.set_color,
                                      "unchanged")
        self.added_button.connect("color-set",
                                  self.set_color,
                                  "added")
        self.modified_button.connect("color-set",
                                     self.set_color,
                                     "modified")
        self.not_present_button.connect("color-set",
                                        self.set_color,
                                        "not_present")

    def set_color(self, widget, prop):
        self.colors.__setattr__(prop, widget.get_color())
Example #23
0
class SearchOptions(TabBox, object):
    def __init__(self):
        TabBox.__init__(self, _('Search Options'))
        self._pack_widgets()
        self.directory = search_config.directory
        self.file_extension = search_config.file_extension
        self.save_time = search_config.save_time
        self.save = search_config.store_results
        self.search_db = search_config.search_db
        self._connect_events()

    def _create_widgets(self):
        self.opt_vbox = HIGVBox()
        self.opt_local_hbox = HIGHBox()
        self.opt_base_hbox = HIGHBox()
        self.opt_local_section = HIGSectionLabel(_("Local files"))
        self.opt_local_table = HIGTable()
        self.opt_base_section = HIGSectionLabel(_("Database"))
        self.opt_base_table = HIGTable()

        self.opt_path_label = HIGEntryLabel(_("Directory"))
        self.opt_extension_label = HIGEntryLabel(_("File extension"))
        self.opt_savetime_label = HIGEntryLabel(_("Save results for"))

        self.opt_path_entry = PathEntry()
        self.opt_extension_entry = gtk.Entry()
        self.opt_savetime_entry = SaveTime()
        self.opt_save_check = gtk.CheckButton(
            _("Save scan results in data \
base for latter search"))
        self.opt_search_check = gtk.CheckButton(
            _("Search saved scan results \
in data base"))

    def _pack_widgets(self):
        self.opt_vbox.set_border_width(12)
        self.opt_vbox._pack_noexpand_nofill(self.opt_local_section)
        self.opt_vbox._pack_noexpand_nofill(self.opt_local_hbox)

        self.opt_vbox._pack_noexpand_nofill(self.opt_base_section)
        self.opt_vbox._pack_noexpand_nofill(self.opt_base_hbox)

        self.opt_local_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.opt_local_hbox._pack_expand_fill(self.opt_local_table)

        self.opt_base_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.opt_base_hbox._pack_expand_fill(self.opt_base_table)

        self.opt_local_table.attach_label(self.opt_path_label, 0, 1, 0, 1)
        self.opt_local_table.attach_label(self.opt_extension_label, 0, 1, 1, 2)

        self.opt_local_table.attach_entry(self.opt_path_entry, 1, 2, 0, 1)
        self.opt_local_table.attach_entry(self.opt_extension_entry, 1, 2, 1, 2)

        self.opt_base_table.attach_label(self.opt_savetime_label, 0, 1, 0, 1)
        self.opt_base_table.attach_label(self.opt_save_check, 0, 2, 1, 2)
        self.opt_base_table.attach_label(self.opt_search_check, 0, 2, 2, 3)

        self.opt_base_table.attach_entry(self.opt_savetime_entry, 1, 2, 0, 1)
        self.pack_start(self.opt_vbox, False, False)

    def _connect_events(self):
        self.opt_extension_entry.connect("focus-out-event",
                                         self.update_extension_entry)
        self.opt_save_check.connect("toggled", self.update_save_check)
        self.opt_search_check.connect("toggled", self.update_search_check)
        self.opt_path_entry.connect_entry_change(self.update_path_entry)
        self.opt_savetime_entry.connect_entry_change(
            self.update_savetime_entry)

    def update_path_entry(self, widget, extra=None):
        search_config.directory = widget.get_text()

    def update_search_check(self, widget):
        search_config.search_db = widget.get_active()

    def update_savetime_entry(self, widget, extra=None):
        print "save time"
        search_config.save_time = self.opt_savetime_entry.time
        print search_config.save_time

    def update_extension_entry(self, widget, extra=None):
        print "set extension"
        search_config.file_extension = widget.get_text()

    def update_save_check(self, widget):
        search_config.store_results = widget.get_active()

    def get_directory(self):
        return self.opt_path_entry.path

    def set_directory(self, directory):
        self.opt_path_entry.path = directory

    def get_file_extension(self):
        return self.opt_extension_entry.get_text().split(";")

    def set_file_extension(self, file_extension):
        if type(file_extension) == type([]):
            self.opt_extension_entry.set_text(";".join(file_extension))
        elif type(file_extension) in StringTypes:
            self.opt_extension_entry.set_text(file_extension)

    def get_save_time(self):
        return self.opt_savetime_entry.time

    def set_save_time(self, save_time):
        print "set save"
        self.opt_savetime_entry.time = save_time

    def get_save(self):
        return self.opt_save_check.get_active()

    def set_save(self, save):
        self.opt_save_check.set_active(save)

    def get_search_db(self):
        return self.opt_search_check.get_active()

    def set_search_db(self, search_db):
        self.opt_search_check.set_active(search_db)

    directory = property(get_directory, set_directory)
    file_extension = property(get_file_extension, set_file_extension)
    save_time = property(get_save_time, set_save_time)
    save = property(get_save, set_save)
    search_db = property(get_search_db, set_search_db)
class UpdatePage(HIGVBox):
    """"""
    def __init__(self):
        """Constructor"""
        HIGVBox.__init__(self)
        self.__create_widgets()
        self.__pack_widgets()
        self.__load_list()
        self.__connect_widgets()
        self.__init_db_text()
        
    def __create_widgets(self):
        """"""
        
        self.update_switch_hbox = HIGHBox()
        self.update_settings_hbox = HIGHBox()
        self.update_db_hbox = HIGHBox()

        self.update_switch_section = HIGSectionLabel(_("Update News Detect"))        
        self.update_switch_table = HIGTable()
        self.update_settings_section = HIGSectionLabel(_("Update Settings"))        
        self.update_settings_table = HIGTable()  
        self.update_db_section = HIGSectionLabel(_("Update Database"))        
        self.update_db_table = HIGTable()
        
        self.update_check = gtk.CheckButton(_("Automatically update"))
        self.update_switch_check = gtk.CheckButton(_("Software Update Detect Switch"))
        self.update_times_label = HIGEntryLabel(_("Auto detect update news"))
        self.update_method_label = HIGEntryLabel(_("Update method"))       
        
        self.update_time_store = gtk.ListStore(str)
        self.update_time_entry = gtk.ComboBoxEntry(self.update_time_store, 0)
        self.update_method_store = gtk.ListStore(str)
        self.update_method_entry = gtk.ComboBoxEntry(self.update_method_store, 0)  
        
        self.update_db_label =  HIGEntryLabel()
        self.update_db_clear_button = gtk.Button(_("Clear Update Information")) 
         
    def __pack_widgets(self):
        """"""
        self.set_border_width(12) 
        
        self._pack_noexpand_nofill(self.update_switch_section)
        self._pack_noexpand_nofill(self.update_switch_hbox)
        self._pack_noexpand_nofill(hig_box_space_holder())
        self._pack_noexpand_nofill(self.update_settings_section)
        self._pack_noexpand_nofill(self.update_settings_hbox)
        self._pack_noexpand_nofill(self.update_db_section)
        self._pack_noexpand_nofill(self.update_db_hbox)        
        
        
        self.update_switch_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.update_switch_hbox._pack_expand_fill(self.update_switch_table)
        self.update_settings_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.update_settings_hbox._pack_expand_fill(self.update_settings_table)
        self.update_db_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.update_db_hbox._pack_expand_fill(self.update_db_table)
        
        self.update_switch_table.attach_label(self.update_check, 0, 2, 0, 1)
        self.update_switch_table.attach_label(self.update_switch_check, 0, 2, 1, 2)
        self.update_settings_table.attach_label(self.update_times_label, 0, 1, 0, 1)
        self.update_settings_table.attach_entry(self.update_time_entry, 1, 2, 0, 1)   
        self.update_settings_table.attach_label(self.update_method_label, 0, 1, 1, 2)
        self.update_settings_table.attach_entry(self.update_method_entry, 1, 2, 1, 2) 
        
        self.update_db_table.attach_label(self.update_db_label, 1, 3, 0, 1)
        self.update_db_table.attach(self.update_db_clear_button, 0, 1, 0, 1)
        
    
    def __init_db_text(self):
        """"""
        rs = g_db_helper.select("select * from updates")
        count = len(rs)
        self.update_db_label.set_text(str(_("%d records in update database now."%(count))))        
    
    def __connect_widgets(self):
        """"""
        self.update_check.connect('toggled',lambda w:self.__change_widgets_status()) 
        self.update_db_clear_button.connect("clicked", lambda w:self.__clear_update_db())
    
    def __clear_update_db(self):
        """"""
        g_db_helper.execute("delete from updates")
        g_db_helper.commit()
        self.update_db_label.set_text(str(_("Clear software update database!")))
    
    def __change_widgets_status(self):
        """"""
        if self.update_check.get_active():
            self.__disable_widgets()            
        else:
            self.__enable_widgets()
    
    def __load_list(self):
        """"""
        for s in update_time_str.keys():
            #print s
            self.update_time_store.append([s])
        for s in update_method_str.keys():
            #print s
            self.update_method_store.append([s])
    
    def __disable_widgets(self):
        """"""
        self.update_switch_check.set_sensitive(False)
        self.update_method_entry.set_sensitive(False)
        self.update_time_entry.set_sensitive(False)
        
    def __enable_widgets(self):
        """"""
        self.update_switch_check.set_sensitive(True)
        self.update_method_entry.set_sensitive(True)
        self.update_time_entry.set_sensitive(True)        
         
Example #25
0
class SearchOptions(TabBox, object):
    def __init__(self):
        TabBox.__init__(self, _('Search Options'))
        self._pack_widgets()
        self.directory = search_config.directory
        self.file_extension = search_config.file_extension
        self.save_time = search_config.save_time
        self.save = search_config.store_results
        self.search_db = search_config.search_db
        self._connect_events()
    def _create_widgets(self):
        self.opt_vbox = HIGVBox()
        self.opt_local_hbox = HIGHBox()
        self.opt_base_hbox = HIGHBox()
        self.opt_local_section = HIGSectionLabel(_("Local files"))
        self.opt_local_table = HIGTable()
        self.opt_base_section = HIGSectionLabel(_("Database"))
        self.opt_base_table = HIGTable()

        self.opt_path_label = HIGEntryLabel(_("Directory"))
        self.opt_extension_label = HIGEntryLabel(_("File extension"))
        self.opt_savetime_label = HIGEntryLabel(_("Save results for"))

        self.opt_path_entry = PathEntry()
        self.opt_extension_entry = gtk.Entry()
        self.opt_savetime_entry = SaveTime()
        self.opt_save_check = gtk.CheckButton(_("Save scan results in data \
base for latter search"))
        self.opt_search_check = gtk.CheckButton(_("Search saved scan results \
in data base"))

    def _pack_widgets(self):
        self.opt_vbox.set_border_width(12)
        self.opt_vbox._pack_noexpand_nofill(self.opt_local_section)
        self.opt_vbox._pack_noexpand_nofill(self.opt_local_hbox)

        self.opt_vbox._pack_noexpand_nofill(self.opt_base_section)
        self.opt_vbox._pack_noexpand_nofill(self.opt_base_hbox)

        self.opt_local_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.opt_local_hbox._pack_expand_fill(self.opt_local_table)

        self.opt_base_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.opt_base_hbox._pack_expand_fill(self.opt_base_table)

        self.opt_local_table.attach_label(self.opt_path_label, 0, 1, 0, 1)
        self.opt_local_table.attach_label(self.opt_extension_label, 0, 1, 1, 2)

        self.opt_local_table.attach_entry(self.opt_path_entry, 1, 2, 0, 1)
        self.opt_local_table.attach_entry(self.opt_extension_entry, 1, 2, 1, 2)

        self.opt_base_table.attach_label(self.opt_savetime_label, 0, 1, 0, 1)
        self.opt_base_table.attach_label(self.opt_save_check, 0, 2, 1, 2)
        self.opt_base_table.attach_label(self.opt_search_check, 0, 2, 2, 3)

        self.opt_base_table.attach_entry(self.opt_savetime_entry, 1, 2, 0, 1)
        self.pack_start(self.opt_vbox, False, False)
    def _connect_events(self):
        self.opt_extension_entry.connect("focus-out-event",
                                         self.update_extension_entry)
        self.opt_save_check.connect("toggled", self.update_save_check)
        self.opt_search_check.connect("toggled", self.update_search_check)
        self.opt_path_entry.connect_entry_change(self.update_path_entry)
        self.opt_savetime_entry.connect_entry_change(self.update_savetime_entry)
    def update_path_entry(self, widget, extra=None):
        search_config.directory = widget.get_text()

    def update_search_check(self, widget):
        search_config.search_db = widget.get_active()

    def update_savetime_entry(self, widget, extra=None):
        print "save time"
        search_config.save_time = self.opt_savetime_entry.time
        print search_config.save_time

    def update_extension_entry(self, widget, extra=None):
        print "set extension"
        search_config.file_extension = widget.get_text()

    def update_save_check(self, widget):
        search_config.store_results = widget.get_active()
    def get_directory(self):
        return self.opt_path_entry.path

    def set_directory(self, directory):
        self.opt_path_entry.path = directory

    def get_file_extension(self):
        return self.opt_extension_entry.get_text().split(";")

    def set_file_extension(self, file_extension):
        if type(file_extension) == type([]):
            self.opt_extension_entry.set_text(";".join(file_extension))
        elif type(file_extension) in StringTypes:
            self.opt_extension_entry.set_text(file_extension)

    def get_save_time(self):
        return self.opt_savetime_entry.time

    def set_save_time(self, save_time):
        print "set save"
        self.opt_savetime_entry.time = save_time

    def get_save(self):
        return self.opt_save_check.get_active()

    def set_save(self, save):
        self.opt_save_check.set_active(save)

    def get_search_db(self):
        return self.opt_search_check.get_active()

    def set_search_db(self, search_db):
        self.opt_search_check.set_active(search_db)


    directory = property(get_directory, set_directory)
    file_extension = property(get_file_extension, set_file_extension)
    save_time = property(get_save_time, set_save_time)
    save = property(get_save, set_save)
    search_db = property(get_search_db, set_search_db)