class ProfileName(HIGDialog):
    def __init__(self, text):
        HIGDialog.__init__(self, _('Profile\'s Name'))

        dialog_label = HIGDialogLabel(text)
        dialog_label.show()
        self.vbox.pack_start(dialog_label)
        self.entry_text = HIGTextEntry()
        self.entry_text.show()
        self.vbox.pack_start(self.entry_text)
        self.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
        self.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)

    def run(self):
        """
        Returns text of entry
        and None if someone clicked Cancel.
        """
        text = None
        response = HIGDialog.run(self)
        text = self.entry_text.get_text()
        if response==gtk.RESPONSE_CANCEL:
            text = None
        self.destroy()
        return text
 def __init__(self):
     self.qs_data = QSData()
     self.entry = HIGTextEntry()
     self.entry.set_visibility(True)
     self.status = Status()
     self.status.set_empty()
     self.scan_result = Result()
     self.b_text = ""
     self.rgx_is_domain = "^((ht|f)tp(s?)\:\/\/|~/|/)?([\w]+:\w+@)?([a-zA-Z]{1}"
     self.rgx_is_domain += "([\w\-]+\.)+([\w]{2,5}))(:[\d]{1,5})?((/?\w+/)+|/?)"
     self.rgx_is_domain += "(\w+\.[\w]{3,4})?((\?\w+=\w+)?(&\w+=\w+)*)?"
     
     self.completion = gtk.EntryCompletion()
     self.entry.set_max_length(1000)
     
     # add button to launch result in umit
     self.btn_umit = gtk.Button ("Open Result")
     
     self.results_opened = False
     self.nmap_output = None
     
     self.load_data(None)
      
     self.btn_umit.connect("clicked", self._launch_umit, None)
     
     self.entry.show()
    def create_and_attach_widgets(self):
        self.option_label = HIGSectionLabel('New Option')
        self.attach(self.option_label, 0, 3, 0, 1)

        self.name_label = HIGEntryLabel(_('Name:'))
        self.name_entry = HIGTextEntry()
        self.attach(self.name_label, 0,1,1,2)
        self.attach(self.name_entry, 1,3,1,2)

        self.hint_label = HIGEntryLabel(_('Hint:'))
        self.hint_entry = HIGTextEntry()
        self.attach(self.hint_label, 0,1,2,3)
        self.attach(self.hint_entry,1,3,2,3)

        self.need_root = gtk.CheckButton(_('Need root'))
        self.attach(self.need_root, 0,1,3,4)	



        self.options_label = HIGEntryLabel(_('Options:'))
        hbox = HIGHBox()
        self.options_entry = HIGTextEntry()
        self.insert_arg_button = HIGButton(title='Args', stock='gtk-add')
        self.insert_arg_button.connect('clicked', self.update_args)
        self.attach(self.options_label,0,1,4,5)
        self.attach(self.options_entry, 1,2,4,5)
        self.attach(self.insert_arg_button, 2,3, 4, 5)

        self.aguments_label = HIGEntryLabel(_('Arguments:'))
        self.arguments_entry = HIGTextEntry()
        self.arguments_entry.set_editable(False)
        self.attach(self.aguments_label, 0,1, 5,6)
        self.attach(self.arguments_entry, 1,3,5,6)
class ProfileName(HIGDialog):
    def __init__(self, text):
        HIGDialog.__init__(self, _('Profile\'s Name'))

        dialog_label = HIGDialogLabel(text)
        dialog_label.show()
        self.vbox.pack_start(dialog_label)
        self.entry_text = HIGTextEntry()
        self.entry_text.show()
        self.vbox.pack_start(self.entry_text)
        self.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
        self.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)

    def run(self):
        """
        Returns text of entry
        and None if someone clicked Cancel.
        """
        text = None
        response = HIGDialog.run(self)
        text = self.entry_text.get_text()
        if response == gtk.RESPONSE_CANCEL:
            text = None
        self.destroy()
        return text
Beispiel #5
0
    def _create_widgets(self):

        #Username
        self.username_label = HIGLabel(_("Username"))
        self.username_entry = HIGTextEntry()
        self.username_entry.set_activates_default(True)

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

        #Logo
        self.logo_openmonitor = gtk.gdk.pixbuf_new_from_file\
                                    (os.path.join(IMAGES_DIR, 'logoOM.png'))
        self.logo_image = gtk.Image()
        self.logo_image.set_from_pixbuf(self.logo_openmonitor)
        #self.login_text = gtk.Label(_("Log into your ICM agent."))

        #Register
        #self.register_button = HIGStockButton(gtk.STOCK_DIALOG_INFO,_("Register"))
        self.register_label = \
            gtk.Label(_("<span foreground='blue'>" \
                        "Register id</span>"))
        self.register_label.set_use_markup(True)
        self.register_button = gtk.Button()
        self.register_button.add(self.register_label)
        self.register_button.set_relief(gtk.RELIEF_NONE)

        #Forget Password
        self.forgot_password_label = \
            gtk.Label(_("<span foreground='blue'>" \
                        "Forgot password?</span>"))
        self.forgot_password_label.set_use_markup(True)
        self.forgot_password = gtk.Button()
        self.forgot_password.add(self.forgot_password_label)
        self.forgot_password.set_relief(gtk.RELIEF_NONE)

        #Auto Login
        self.auto_login_checkbtn = gtk.CheckButton(_("Auto login"))

        #Settings
        self.settings_button = HIGStockButton(gtk.STOCK_DIALOG_INFO,
                                              _("settings"))

        #Container
        self.hbox = HIGHBox(False, 2)
        self.table = HIGTable(8, 4, False)
        self.table.set_row_spacings(5)
        self.table.set_col_spacings(10)
        self.action_area.set_homogeneous(False)

        #tab orders
        self.orders = [
            self.username_entry, self.password_entry, self.register_button,
            self.forgot_password
        ]
    def __init__(self, text):
        HIGDialog.__init__(self, _('Profile\'s Name'))

        dialog_label = HIGDialogLabel(text)
        dialog_label.show()
        self.vbox.pack_start(dialog_label)
        self.entry_text = HIGTextEntry()
        self.entry_text.show()
        self.vbox.pack_start(self.entry_text)
        self.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
        self.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
    def __create_widgets(self):
        
        #box
        self.all_box = HIGVBox()
        self.input_box = HIGHBox()
        self.buttom_box = HIGHBox()
        self.check_btn_box = gtk.HButtonBox()
        
        #Add input
        self.title_text = HIGLabel(_("Locations"))
        self.longitude_text = HIGLabel(_("longitude:"))
        self.longitude_entry = HIGTextEntry()
        self.latitude_text = HIGLabel(_("latitude:"))
        self.latitude_entry = HIGTextEntry()         
        
        #Add buttons
        self.get_event_btn = gtk.Button(_("Get Events"))
        self.refresh_btn = gtk.Button(_("Refresh"))
          
        #status bar
        self.statusbar = gtk.Statusbar()
        self.statusbar.push(0,'Events in Database')        
                                
        self.listmodel = gtk.ListStore(str, str, str, str, str)

        # create the TreeView
        self.treeview = gtk.TreeView()

        # create the TreeViewColumns to display the data
        self.tvcolumn = [None] * len(self.column_names)
        cellpb = gtk.CellRendererText()

        self.tvcolumn[0] = gtk.TreeViewColumn(self.column_names[0], cellpb)
        self.tvcolumn[0].add_attribute(cellpb, 'text', 0)
        #cell = gtk.CellRendererText()
        #self.tvcolumn[0].set_cell_data_func(cell, self.test_type)
        self.treeview.append_column(self.tvcolumn[0])

        for n in range(1, len(self.column_names)):
            cell = gtk.CellRendererText()
            self.tvcolumn[n] = gtk.TreeViewColumn(self.column_names[n], cell)
            self.tvcolumn[n].add_attribute(cell, 'text', n)
            if n == 1:
                cell.set_property('xalign', 1.0)
            #self.tvcolumn[n].set_cell_data_func(cell, cell_data_funcs[n])
            self.treeview.append_column(self.tvcolumn[n])

        #self.treeview.connect('row-activated', self.open_file)
        self.scrolledwindow = gtk.ScrolledWindow()
        self.scrolledwindow.add(self.treeview)
        self.treeview.set_model(self.listmodel)
    def __create_widgets(self):

        #box
        self.all_box = HIGVBox()
        self.input_box = HIGHBox()
        self.buttom_box = HIGHBox()
        self.check_btn_box = gtk.HButtonBox()

        #Add input
        self.title_text = HIGLabel(_("Locations"))
        self.longitude_text = HIGLabel(_("longitude:"))
        self.longitude_entry = HIGTextEntry()
        self.latitude_text = HIGLabel(_("latitude:"))
        self.latitude_entry = HIGTextEntry()

        #Add buttons
        self.get_event_btn = gtk.Button(_("Get Events"))
        self.refresh_btn = gtk.Button(_("Refresh"))

        #status bar
        self.statusbar = gtk.Statusbar()
        self.statusbar.push(0, 'Events in Database')

        self.listmodel = gtk.ListStore(str, str, str, str, str)

        # create the TreeView
        self.treeview = gtk.TreeView()

        # create the TreeViewColumns to display the data
        self.tvcolumn = [None] * len(self.column_names)
        cellpb = gtk.CellRendererText()

        self.tvcolumn[0] = gtk.TreeViewColumn(self.column_names[0], cellpb)
        self.tvcolumn[0].add_attribute(cellpb, 'text', 0)
        #cell = gtk.CellRendererText()
        #self.tvcolumn[0].set_cell_data_func(cell, self.test_type)
        self.treeview.append_column(self.tvcolumn[0])

        for n in range(1, len(self.column_names)):
            cell = gtk.CellRendererText()
            self.tvcolumn[n] = gtk.TreeViewColumn(self.column_names[n], cell)
            self.tvcolumn[n].add_attribute(cell, 'text', n)
            if n == 1:
                cell.set_property('xalign', 1.0)
            #self.tvcolumn[n].set_cell_data_func(cell, cell_data_funcs[n])
            self.treeview.append_column(self.tvcolumn[n])

        #self.treeview.connect('row-activated', self.open_file)
        self.scrolledwindow = gtk.ScrolledWindow()
        self.scrolledwindow.add(self.treeview)
        self.treeview.set_model(self.listmodel)
    def create_and_attach_widgets(self):
        self.option_label = HIGSectionLabel('New Option')
        self.attach(self.option_label, 0, 3, 0, 1)

        self.name_label = HIGEntryLabel(_('Name:'))
        self.name_entry = HIGTextEntry()
        self.attach(self.name_label, 0, 1, 1, 2)
        self.attach(self.name_entry, 1, 3, 1, 2)

        self.hint_label = HIGEntryLabel(_('Hint:'))
        self.hint_entry = HIGTextEntry()
        self.attach(self.hint_label, 0, 1, 2, 3)
        self.attach(self.hint_entry, 1, 3, 2, 3)

        self.need_root = gtk.CheckButton(_('Need root'))
        self.attach(self.need_root, 0, 1, 3, 4)

        self.options_label = HIGEntryLabel(_('Options:'))
        hbox = HIGHBox()
        self.options_entry = HIGTextEntry()
        self.insert_arg_button = HIGButton(title='Args', stock='gtk-add')
        self.insert_arg_button.connect('clicked', self.update_args)
        self.attach(self.options_label, 0, 1, 4, 5)
        self.attach(self.options_entry, 1, 2, 4, 5)
        self.attach(self.insert_arg_button, 2, 3, 4, 5)

        self.aguments_label = HIGEntryLabel(_('Arguments:'))
        self.arguments_entry = HIGTextEntry()
        self.arguments_entry.set_editable(False)
        self.attach(self.aguments_label, 0, 1, 5, 6)
        self.attach(self.arguments_entry, 1, 3, 5, 6)
    def __create_widgets(self):

        self.vbox_main = HIGVBox()

        self.main_frame = HIGFrame("Profiles")
        #self.main_frame.set_shadow_type(gtk.SHADOW_ETCHED_OUT)

        self.align = gtk.Alignment(0.0, 0.0, 1.0, 1.0)
        self.align.set_padding(0, 0, 12, 0)

        self.vbox = HIGVBox()
        self.profiles_sw = HIGScrolledWindow()
        #TreeView
        self.model = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING)
        #self.modelfilter = self.model.filter_new()
        self.profiles_tv = gtk.TreeView(self.model)
        renderer = gtk.CellRendererText()
        column = gtk.TreeViewColumn(_("Name"), renderer, text=0)
        self.profiles_tv.append_column(column)
        renderer_hint = gtk.CellRendererText()
        column_hint = gtk.TreeViewColumn(_("Hint"), renderer_hint, text=1)
        self.profiles_tv.append_column(column_hint)
        #self.profiles_tv.set_model(self.modelfilter)
        #Info
        self.hbox_info = HIGHBox()
        self.command_label = HIGEntryLabel('Command: ')
        self.command_entry = HIGTextEntry()
        self.command_entry.set_editable(False)

        #Buttons
        self.hbox_buttons = HIGHBox()

        self.wiz_button = HIGButton(title='Wizard', stock='gtk-convert')
        self.wiz_button.connect("clicked", self.new_wiz)

        self.edit_button = HIGButton(stock='gtk-edit')
        self.edit_button.connect("clicked", self.open_peditor)
        self.new_button = HIGButton(stock='gtk-new')
        self.new_button.connect("clicked", self.open_peditor)
        self.copy_button = HIGButton(stock='gtk-copy')
        self.copy_button.connect("clicked", self.copy_profiles)
        self.delete_button = HIGButton(stock=gtk.STOCK_DELETE)
        self.delete_button.connect('clicked', self.delete_profile)
        #Apply Buttons
        self.cancel_button = HIGButton(stock='gtk-close')
        self.cancel_button.connect("clicked", self.quit)

        self.connect("delete-event", self.quit)
Beispiel #11
0
    def _create_widgets(self):
        '''
        Create the main entrys of the option 
        '''
        self._box = HIGVBox()


        self._table = HIGTable()


        #Name
        self._label_name  = HIGEntryLabel(_('Name'))
        self._entry_name = HIGTextEntry()

        self._entry_name.connect('activate', self._update_label)

        #Type 
        self._label_type = HIGEntryLabel(_('Type'))	
        self._combo_type = gtk.combo_box_new_text()
        self._combo_type.append_text('')
        self._combo_type.append_text('Option List')
        self._combo_type.append_text('Option Check')
        self._combo_type.set_active(0)
        self._combo_type.connect('changed', self.change_combo)

        self._label_opt = HIGEntryLabel(_('Option'))
        self._entry_opt = HIGTextEntry()
        self._entry_opt.set_sensitive(False)

        #For option list open a dialog to add/remove options
        self._button_list = HIGButton('Edit Option List')
        img = gtk.Image()
        img_dir =  os.path.join(pixmaps_dir, 'uie', 'combo.png')
        img.set_from_file(img_dir)
        self._button_list.set_image(img)
        self._button_list.connect('button-press-event', self._button_list_clicked)


        self._table.attach(self._label_name, 0,1,0, 1)
        self._table.attach(self._entry_name, 1,2,0,1)
        self._table.attach(self._label_type, 0,1,1,2)
        self._table.attach(self._combo_type, 1,2,1, 2)

        self._table.attach(self._button_list, 0,2, 3,4)
        self._table.attach(self._label_opt, 0,1, 4,5)
        self._table.attach(self._entry_opt, 1,2,4,5)

        self._box.pack_start(self._table, False, False)
Beispiel #12
0
 def __init__(self, type_ = None, path = None):
     if type_ and path:
         title = _("Edit Source")
     else:
         type_ = "FILE"
         path = ""
         title = _("Add Source")
     HIGDialog.__init__(self, title, None,
                        gtk.DIALOG_MODAL,
                        (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
                         gtk.STOCK_OK, gtk.RESPONSE_OK))
     hbox = HIGHBox()
     self.combo = gtk.combo_box_new_text()
     types = sorted(self.types.keys())
     for t in types:
         self.combo.append_text(t)
     self.combo.set_active(types.index(type_))
     self.combo.connect("changed", self._changed_cb)
     hbox.pack_start(self.combo, False, False)
     self.entry = HIGTextEntry()
     self.entry.set_text(path)
     hbox.pack_start(self.entry)
     self.btn = HIGButton(_("Browse..."), stock=gtk.STOCK_OPEN)
     self.btn.connect("clicked", self._clicked_cb)
     hbox.pack_start(self.btn, False, False)
     self.vbox.add(hbox)
     self.show_all()
     self.update()
Beispiel #13
0
class SearchFilterDialog(HIGDialog):
    def __init__(self, parent = None):
        HIGDialog.__init__(self, _("Find"), parent,
                           gtk.DIALOG_MODAL | gtk.DIALOG_NO_SEPARATOR,
                           (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
                            gtk.STOCK_FIND, gtk.RESPONSE_OK))
        self.set_default_response(gtk.RESPONSE_OK)
        hbox = HIGHBox()
        hbox.pack_start(gtk.Label(_("Search:")))
        self.entry = HIGTextEntry()
        self.entry.set_activates_default(True)
        hbox.pack_start(self.entry)
        self.vbox.add(hbox)
        self.show_all()

    def get_pattern(self):
        return self.entry.get_text()
Beispiel #14
0
    def _create_widgets(self):
        '''
        Create the main entrys of the option 
        '''
        self._box = HIGVBox()

        self._table = HIGTable()

        #Name
        self._label_name = HIGEntryLabel(_('Name'))
        self._entry_name = HIGTextEntry()

        self._entry_name.connect('activate', self._update_label)

        #Type
        self._label_type = HIGEntryLabel(_('Type'))
        self._combo_type = gtk.combo_box_new_text()
        self._combo_type.append_text('')
        self._combo_type.append_text('Option List')
        self._combo_type.append_text('Option Check')
        self._combo_type.set_active(0)
        self._combo_type.connect('changed', self.change_combo)

        self._label_opt = HIGEntryLabel(_('Option'))
        self._entry_opt = HIGTextEntry()
        self._entry_opt.set_sensitive(False)

        #For option list open a dialog to add/remove options
        self._button_list = HIGButton('Edit Option List')
        img = gtk.Image()
        img_dir = os.path.join(pixmaps_dir, 'uie', 'combo.png')
        img.set_from_file(img_dir)
        self._button_list.set_image(img)
        self._button_list.connect('button-press-event',
                                  self._button_list_clicked)

        self._table.attach(self._label_name, 0, 1, 0, 1)
        self._table.attach(self._entry_name, 1, 2, 0, 1)
        self._table.attach(self._label_type, 0, 1, 1, 2)
        self._table.attach(self._combo_type, 1, 2, 1, 2)

        self._table.attach(self._button_list, 0, 2, 3, 4)
        self._table.attach(self._label_opt, 0, 1, 4, 5)
        self._table.attach(self._entry_opt, 1, 2, 4, 5)

        self._box.pack_start(self._table, False, False)
    def __init__(self, text):
        HIGDialog.__init__(self, _('Profile\'s Name'))

        dialog_label = HIGDialogLabel(text)
        dialog_label.show()
        self.vbox.pack_start(dialog_label)
        self.entry_text = HIGTextEntry()
        self.entry_text.show()
        self.vbox.pack_start(self.entry_text)
        self.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
        self.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
Beispiel #16
0
    def _create_widgets(self):
        
        #Username
        self.username_label = HIGLabel(_("Username"))
        self.username_entry = HIGTextEntry()
        self.username_entry.set_activates_default(True)

        #Password
        self.password_label = HIGLabel(_("Password"))
        self.password_entry = HIGPasswordEntry()
        self.password_entry.set_activates_default(True)
        
        #Logo
        self.logo_openmonitor = gtk.gdk.pixbuf_new_from_file\
                                    (os.path.join(IMAGES_DIR, 'logoOM.png'))
        self.logo_image = gtk.Image()
        self.logo_image.set_from_pixbuf(self.logo_openmonitor)
        #self.login_text = gtk.Label(_("Log into your ICM agent."))
        
        #Register
        #self.register_button = HIGStockButton(gtk.STOCK_DIALOG_INFO,_("Register"))
        self.register_label = \
            gtk.Label(_("<span foreground='blue'>" \
                        "Register id</span>"))
        self.register_label.set_use_markup(True)
        self.register_button = gtk.Button()
        self.register_button.add(self.register_label)
        self.register_button.set_relief(gtk.RELIEF_NONE)
        
        #Forget Password
        self.forgot_password_label = \
            gtk.Label(_("<span foreground='blue'>" \
                        "Forgot password?</span>"))
        self.forgot_password_label.set_use_markup(True)
        self.forgot_password = gtk.Button()
        self.forgot_password.add(self.forgot_password_label)
        self.forgot_password.set_relief(gtk.RELIEF_NONE)
        
        #Auto Login
        self.auto_login_checkbtn = gtk.CheckButton(_("Auto login"))
        
        #Settings
        self.settings_button = HIGStockButton(gtk.STOCK_DIALOG_INFO,_("settings"))
        
        #Container
        self.hbox = HIGHBox(False,2)
        self.table = HIGTable(8,4,False)
        self.table.set_row_spacings(5)
        self.table.set_col_spacings(10)
        self.action_area.set_homogeneous(False)
        
        #tab orders
        self.orders = [self.username_entry, self.password_entry, self.register_button, self.forgot_password]
Beispiel #17
0
    def _create_widgets(self):
        """ Create widgets"""

        self._frm_option = HIGFrame(_('Options'))
        self._box_option = HIGHBox()
        self.__lbl_file_opt = HIGEntryLabel(_('File:'))
        self.__entry_file_opt = HIGTextEntry()
        self.__entry_file_opt.set_editable(False)
        self.__file_browser_opt = HIGButton(_('Browse file'), \
                                            gtk.STOCK_DIRECTORY)

        self._frm_profile = HIGFrame(_('Profile'))
        self._box_profile = HIGHBox()
        self.__lbl_file_profile = HIGEntryLabel(_('File:'))
        self.__entry_file_profile = HIGTextEntry()
        self.__entry_file_profile.set_editable(False)
        self.__file_browser_profile = HIGButton(_('Browse file'), \
                                            gtk.STOCK_DIRECTORY)

        self._frm_wizard = HIGFrame(_('Wizard'))
        self._box_wizard = HIGHBox()

        self.__lbl_file_wizard = HIGEntryLabel(_('File:'))
        self.__entry_file_wizard = HIGTextEntry()
        self.__entry_file_wizard.set_editable(False)
        self.__file_browser_wizard = HIGButton(_('Browse file'), \
                                            gtk.STOCK_DIRECTORY)

        self.__btn_restore = HIGButton(_('Restore Defaults'), gtk.STOCK_CLEAR)
Beispiel #18
0
    def _create_widgets_error(self):

        # Create Widgets
        self._box_error_frame = HIGFrame('Error')

        self._box_error = HIGTable(5, 2)
        self._box_error.set_border_width(10)
        self._box_error_frame.add(self._box_error)
        self.__crash_report = gtk.CheckButton(_('Enable Crash Report'))
        # Radio Button List
        self.__log_no = gtk.RadioButton(None, _('No log'))
        self.__log_terminal = gtk.RadioButton(self.__log_no, _('Enable log in terminal'))
        self.__log_file = gtk.RadioButton(self.__log_terminal,\
                                         _('Enable log file'))

        self.__log_file_label = HIGEntryLabel(_('Log file'))
        self.__log_file_entry = HIGTextEntry()
        self.__log_file_entry.set_editable(False)
        # FIXME: Do default file ~/.umit/umit.log
        self.__log_file_browser = HIGButton(_('Browse file'), \
                                            gtk.STOCK_DIRECTORY)

        tmpbox = HIGHBox()
        tmpbox.pack_start(self.__log_file_entry, False, False)
        tmpbox.pack_start(self.__log_file_browser, False, False)


        # attach table
        self._box_error.attach(self.__crash_report, 0,1,0,1,\
                               gtk.FILL|gtk.EXPAND| gtk.SHRINK, gtk.FILL)
        self._box_error.attach(self.__log_no, 0,1,1,2,\
                               gtk.FILL|gtk.EXPAND| gtk.SHRINK, gtk.FILL)
        self._box_error.attach(self.__log_terminal, 0,1,2,3,\
                               gtk.FILL|gtk.EXPAND| gtk.SHRINK, gtk.FILL)
        self._box_error.attach(self.__log_file, 0,1,3,4,\
                               gtk.FILL|gtk.EXPAND| gtk.SHRINK, gtk.FILL)
        self._box_error.attach(self.__log_file_label, 0,1,4,5,\
                               gtk.FILL|gtk.EXPAND| gtk.SHRINK, gtk.FILL)
        self._box_error.attach(tmpbox, 1,2,4,5,\
                               gtk.FILL|gtk.EXPAND| gtk.SHRINK, gtk.FILL)
Beispiel #19
0
    def create_proxy_row(self, table, level, name, default = ""):
	host, port = self.parse_proxy(default)
	try:
	    port = float(port)
	except ValueError:
	    port = 3128

	lbl = HIGEntryLabel(name + " " + _("proxy") + ":")
	lbl.set_justify(gtk.JUSTIFY_LEFT)
	host_entry = HIGTextEntry()
	host_entry.set_text(host)
	lbl.set_mnemonic_widget(host_entry)
	table.attach(lbl, 0, 1, level, level + 1, 0, 0)
	table.attach(host_entry, 1, 2, level, level + 1)
	
	lbl = HIGEntryLabel(_("Port") + ":")
	lbl.set_justify(gtk.JUSTIFY_LEFT)
	port_entry = gtk.SpinButton(gtk.Adjustment(port, 0, 65536, 1, 100), 1.0, 0)
	lbl.set_mnemonic_widget(port_entry)
	table.attach(lbl, 2, 3, level, level + 1, 0, 0)
	table.attach(port_entry, 3, 4, level, level + 1, 0, 0)
	return host_entry, port_entry
Beispiel #20
0
    def _create_widgets_common(self):
        """ generally tab """
        self._box_common = HIGVBox() # pack main section
        self.__check_splash = gtk.CheckButton(_('Enable Splash on start'))
        self.__check_silent_root = gtk.CheckButton(\
            _('Silent Warning Non-Root'))
        self.__check_warning_extensions = gtk.CheckButton(\
            _('Set/Check extensions - Windows only'))
        self._box_common.pack_start(self.__check_splash, False, False)
        #self._box_common.pack_start(self.__check_warning_extensions, False, \
        #                            False)
        self._box_common.pack_start(self.__check_silent_root, False, False)
        self.__label_nmap = HIGEntryLabel(_('Nmap Command'))
        self.__entry_nmap = HIGTextEntry()
        # Files usr saved on predefined directory:
        self.__label_path = HIGEntryLabel(_('Nmap Command'))
        self.__entry_path = HIGTextEntry()
        self.__button_path = HIGButton(_('Choose'))
        self.__box_path = HIGHBox()
        self.__box_path.pack_start(self.__label_path, False, False)
        self.__box_path.pack_end(self.__button_path, False, False)

        self._box_common.set_border_width(0)
    def __create_widgets(self):

        self.vbox_main = HIGVBox()

        self.main_frame = HIGFrame("Profiles")
        #self.main_frame.set_shadow_type(gtk.SHADOW_ETCHED_OUT)

        self.align = gtk.Alignment(0.0, 0.0, 1.0, 1.0)
        self.align.set_padding(0,0,12,0)

        self.vbox = HIGVBox()
        self.profiles_sw = HIGScrolledWindow()
        #TreeView
        self.model = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING)
        #self.modelfilter = self.model.filter_new()
        self.profiles_tv = gtk.TreeView(self.model)
        renderer = gtk.CellRendererText()
        column = gtk.TreeViewColumn(_("Name"), renderer, text=0)
        self.profiles_tv.append_column(column)
        renderer_hint = gtk.CellRendererText()
        column_hint = gtk.TreeViewColumn(_("Hint"), renderer_hint, text=1)
        self.profiles_tv.append_column(column_hint)
        #self.profiles_tv.set_model(self.modelfilter)
        #Info 
        self.hbox_info = HIGHBox()
        self.command_label = HIGEntryLabel('Command: ')
        self.command_entry = HIGTextEntry()
        self.command_entry.set_editable(False)

        #Buttons
        self.hbox_buttons = HIGHBox()

        self.wiz_button = HIGButton(title='Wizard', stock='gtk-convert')
        self.wiz_button.connect("clicked", self.new_wiz)

        self.edit_button = HIGButton(stock='gtk-edit')
        self.edit_button.connect("clicked", self.open_peditor)
        self.new_button = HIGButton(stock='gtk-new')
        self.new_button.connect("clicked", self.open_peditor)
        self.copy_button = HIGButton(stock='gtk-copy')
        self.copy_button.connect("clicked", self.copy_profiles)
        self.delete_button = HIGButton(stock=gtk.STOCK_DELETE)
        self.delete_button.connect('clicked', self.delete_profile)	
        #Apply Buttons
        self.cancel_button = HIGButton(stock='gtk-close')
        self.cancel_button.connect("clicked", self.quit)
        
        self.connect("delete-event", self.quit)
    def dialog_args(self):
        '''
        Create a dialog
        '''

        d = HIGDialog(_('Arguments'))
        description_label = HIGEntryLabel(
            _('Insert the description to argument:'))
        description_label.show()
        description_entry = HIGTextEntry()
        text = self.arguments_entry.get_text()
        description_entry.set_text(text)
        description_entry.show()

        combo_box = gtk.combo_box_new_text()
        combo_box.set_wrap_width(1)
        index = -1
        j = 0
        for i in ARG_TYPES:
            combo_box.append_text(ARG_TYPES[i])
            if i == self.arg_type:
                index = j
            j = j + 1
        if index > -1:
            combo_box.set_active(index)
        combo_box.show()
        d.vbox.pack_start(description_label, False, False)
        d.vbox.pack_start(description_entry, False, False)
        d.vbox.pack_start(combo_box, False, False)
        d.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
        d.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
        resp = d.run()
        result = None, None
        if resp == gtk.RESPONSE_OK:
            model = combo_box.get_model()
            active = combo_box.get_active()
            if active < 0:
                return None, None
            combo_selected = model[active][0]

            for i in ARG_TYPES:
                if combo_selected == ARG_TYPES[i]:
                    combo_selected = i

            result = description_entry.get_text(), combo_selected
            #self.insert_arg_button.set_label('Edit args')
            #self.insert_arg_button.
        d.destroy()
        return result
Beispiel #23
0
    def dialog_args(self):
        '''
        Create a dialog
        '''

        d = HIGDialog(_('Arguments'))
        description_label = HIGEntryLabel(
            _('Insert the description to argument:'))
        description_label.show()
        description_entry = HIGTextEntry()
        text = self.arguments_entry.get_text()
        description_entry.set_text(text)
        description_entry.show()

        combo_box = gtk.combo_box_new_text()
        combo_box.set_wrap_width(1)
        index = -1 
        j = 0 
        for i in ARG_TYPES:
            combo_box.append_text(ARG_TYPES[i])
            if i == self.arg_type:
                index = j 
            j = j + 1
        if index > -1 : 
            combo_box.set_active(index)
        combo_box.show()
        d.vbox.pack_start(description_label, False, False)
        d.vbox.pack_start(description_entry, False, False)
        d.vbox.pack_start(combo_box, False, False)
        d.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
        d.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
        resp = d.run()
        result  = None, None 
        if resp == gtk.RESPONSE_OK:
            model = combo_box.get_model()
            active = combo_box.get_active()
            if active < 0:
                return None, None 
            combo_selected =  model[active][0]

            for i in ARG_TYPES:
                if combo_selected == ARG_TYPES[i]:
                    combo_selected = i

            result = description_entry.get_text(), combo_selected
            #self.insert_arg_button.set_label('Edit args')
            #self.insert_arg_button.
        d.destroy()
        return result 
Beispiel #24
0
    def _create_widgets_proxy(self):

        self.__frame = TabFrame(_("Proxy Settings"))
        self.__frame.set_shadow_type(gtk.SHADOW_NONE)
        self.__frame_box = HIGTable(6, 2, True)
        self._radio_no_proxy = gtk.RadioButton(None, _('No proxy server'))
        self._radio_proxy = gtk.RadioButton(self._radio_no_proxy,
                                            _('Configure server'))

        # Core Structure of data of proxy:

        fields = []
        fields.append({
            'name': 'hostname',
            'label': _('Hostname'),
            'values': network_conf.hostname,
            'entry': None
        })

        fields.append({
            'name': 'port',
            'label': _('Port'),
            'values': network_conf.port,
            'entry': None,
            'type': 'spin'
        })

        fields.append({
            'name': 'username',
            'label': _('Username'),
            'values': network_conf.username,
            'entry': None
        })

        fields.append({
            'name': 'password',
            'label': _('Password'),
            'values': network_conf.password,
            'entry': None,
            'type': 'password'
        })

        self.__proxy_fields = fields
        # Create, attach and set values of widgets of proxy

        xopt = gtk.FILL | gtk.EXPAND | gtk.SHRINK
        yopt = gtk.FILL

        self.__frame_box.attach(self._radio_no_proxy, 0, 1, 0, 1, xopt, yopt)
        self.__frame_box.attach(self._radio_proxy, 0, 1, 1, 2)

        row = 2

        # Create list of labels/entrys
        self.__label_list = []
        self.__entry_list = []

        for field in fields:

            # Create widgets
            label = gtk.Label(field['label'])
            if field.has_key('type') and field['type'] == 'spin':
                entry = IntSpin()
            else:
                entry = HIGTextEntry()

            # Add widgets to lists
            self.__label_list.append(label)
            self.__entry_list.append(entry)
            field['entry'] = entry

            # Customize
            label.set_alignment(1.0, 0.0)

            # Attachment Table
            self.__frame_box.attach(label, 0,1,row,row+1, \
                                    xopt, yopt)
            self.__frame_box.attach(entry, 1, 2, row, row + 1)

            # Increment row
            row = row + 1

        self.__frame.add(self.__frame_box)
class ProfileManager(HIGWindow):
    """
    Create a Profile Manager 
    """
    def __init__(self, daddy=None):
        HIGWindow.__init__(self, type=gtk.WINDOW_TOPLEVEL)
        self.set_title('Profile Manager')
        self.set_position(gtk.WIN_POS_CENTER)
        self.__create_widgets()
        self.add(self.vbox_main)
        self.__fill_widgets()
        self.__pack_widgets()
        self.__scan_notebook = None

        self.daddy = daddy

    def __create_widgets(self):

        self.vbox_main = HIGVBox()

        self.main_frame = HIGFrame("Profiles")
        #self.main_frame.set_shadow_type(gtk.SHADOW_ETCHED_OUT)

        self.align = gtk.Alignment(0.0, 0.0, 1.0, 1.0)
        self.align.set_padding(0, 0, 12, 0)

        self.vbox = HIGVBox()
        self.profiles_sw = HIGScrolledWindow()
        #TreeView
        self.model = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING)
        #self.modelfilter = self.model.filter_new()
        self.profiles_tv = gtk.TreeView(self.model)
        renderer = gtk.CellRendererText()
        column = gtk.TreeViewColumn(_("Name"), renderer, text=0)
        self.profiles_tv.append_column(column)
        renderer_hint = gtk.CellRendererText()
        column_hint = gtk.TreeViewColumn(_("Hint"), renderer_hint, text=1)
        self.profiles_tv.append_column(column_hint)
        #self.profiles_tv.set_model(self.modelfilter)
        #Info
        self.hbox_info = HIGHBox()
        self.command_label = HIGEntryLabel('Command: ')
        self.command_entry = HIGTextEntry()
        self.command_entry.set_editable(False)

        #Buttons
        self.hbox_buttons = HIGHBox()

        self.wiz_button = HIGButton(title='Wizard', stock='gtk-convert')
        self.wiz_button.connect("clicked", self.new_wiz)

        self.edit_button = HIGButton(stock='gtk-edit')
        self.edit_button.connect("clicked", self.open_peditor)
        self.new_button = HIGButton(stock='gtk-new')
        self.new_button.connect("clicked", self.open_peditor)
        self.copy_button = HIGButton(stock='gtk-copy')
        self.copy_button.connect("clicked", self.copy_profiles)
        self.delete_button = HIGButton(stock=gtk.STOCK_DELETE)
        self.delete_button.connect('clicked', self.delete_profile)
        #Apply Buttons
        self.cancel_button = HIGButton(stock='gtk-close')
        self.cancel_button.connect("clicked", self.quit)

        self.connect("delete-event", self.quit)

    def __fill_widgets(self):

        self.profiles = CommandProfile()
        self._reload_profile_list()

        #selection = self.profiles_tv.get_selection()
        #selection.connect("changed", self.change_nmap_command)
        self.profiles_tv.connect("cursor-changed", self.change_nmap_command)

    def __pack_widgets(self):
        """
        Pack all widgets of windows 
        """
        self.vbox_main.pack_start(self.main_frame, True, True)
        self.main_frame.add(self.align)
        self.align.add(self.vbox)
        self.vbox.set_border_width(6)

        self.vbox.pack_start(self.profiles_sw, True, True, 0)

        self.hbox_info.pack_start(self.command_label, False, False, 0)
        self.hbox_info.pack_start(self.command_entry, True, True, 0)
        self.vbox.pack_start(self.hbox_info, False, False, 0)

        self.hbox_buttons.pack_end(self.cancel_button)
        self.hbox_buttons.pack_end(self.copy_button, True, True)
        self.hbox_buttons.pack_end(self.edit_button, True, True)
        self.hbox_buttons.pack_end(self.delete_button, True, True)
        self.hbox_buttons.pack_end(self.new_button, True, True)
        self.hbox_buttons.pack_end(self.wiz_button, True, True)
        self.hbox_buttons.set_spacing(6)
        self.vbox_main.pack_start(self.hbox_buttons, False, False)

        self.profiles_sw.set_size_request(400, 170)
        self.profiles_sw.add(self.profiles_tv)

    def get_selected_profile(self):
        """
        Returns the string with name of selected profile 
        """
        try:
            treeselection = self.profiles_tv.get_selection()
            (model, iter) = treeselection.get_selected()
            return model.get_value(iter, 0)
        except:
            return None

    def change_nmap_command(self, widget_tv):
        """
        Change a nmap command at command entry
        """
        assert widget_tv is not None
        # it call __init__ because when wizard or profile are open,
        # need update profiles
        self.profiles.__init__()
        # update text entry of command
        self.command_entry.set_text(
            self.profiles.get_command(self.get_selected_profile()))

    def new_wiz(self, widget):
        w = Wizard()
        w.set_notebook(None)
        w.set_profilemanager(self.model)
        w.show_all()

    def open_peditor(self, widget):
        """
        Open Profile Editor with a Selected or Non-Selected(New) Item
        """
        assert widget is not None

        if widget.get_label() == "gtk-edit":
            # Edit profile selected
            if self.get_selected_profile() is not None:
                pe = ProfileEditor(self.get_selected_profile())
                pe.set_notebook(self.__scan_notebook)
                pe.set_profilemanager(self.model)
                pe.show_all()
        else:
            # New Profile
            pe = ProfileEditor()
            pe.set_notebook(self.__scan_notebook)
            pe.set_profilemanager(self.model)
            pe.show_all()
            self._reload_profile_list()

    def copy_profiles(self, widget):
        """
        Copy selected Profile
        """
        if self.get_selected_profile() is None:
            return None
        d = ProfileName(_("Insert a profile name"))
        profile_name = d.run()
        if profile_name is None or profile_name == "":
            return None
        #get commands of selected profile
        profile_selected = self.get_selected_profile()
        command = self.profiles.get_command(profile_selected)
        hint = self.profiles.get_hint(profile_selected)
        description = self.profiles.get_description(profile_selected)
        annotation = self.profiles.get_annotation(profile_selected)
        #Options
        prof = self.profiles.get_profile(profile_selected)
        options_used = prof['options']
        options = CommandConstructor(options_used)

        self.profiles.add_profile(profile_name,\
                                  command=command,\
                                  hint=hint,\
                                  description=description,\
                                  annotation=annotation,\
                                  options=options.get_options())

        myiter = self.model.insert_before(None, None)
        self.model.set_value(myiter, 0, profile_name)
        self.model.set_value(myiter, 1, self.profiles.get_hint(profile_name))
        treeselection = self.profiles_tv.get_selection()
        treeselection.select_iter(myiter)
        #(model,iter) = treeselection.get_selected()
        #model.get_value(iter,0)

    def delete_profile(self, widget=None):
        """
        delete profile 
        """
        if self.get_selected_profile() is None:
            return None
        self.profiles.remove_profile(self.get_selected_profile())
        #Update treeview
        treeselection = self.profiles_tv.get_selection()
        (model, iter) = treeselection.get_selected()
        model.remove(iter)
        # update text entry of command
        self.command_entry.set_text('')

    def _reload_profile_list(self):
        """
        Reload a list of profiles
        """
        profiles = []
        all_profiles = self.profiles.sections()
        for profile in all_profiles:
            if self.profiles.get(profile, 'tool') == 'nmap':
                profiles.append(profile)
        profiles.sort()
        self.model.clear()

        for command in profiles:
            myiter = self.model.insert_before(None, None)
            self.model.set_value(myiter, 0, command)
            self.model.set_value(myiter, 1, self.profiles.get_hint(command))
            #self.model.append([command,self.profiles.get_hint(command)])

    def set_notebook(self, notebook):
        self.__scan_notebook = notebook

    def quit(self, widget):
        self.destroy()

    def quit(self, widget, data=None):
        if self.daddy:
            self.daddy.running_pm = False
            self.destroy()
        else:
            gtk.main_quit()
class OptionDisplay(HIGTable):
    def __init__(self, option=None):
        HIGTable.__init__(self)
        self.create_and_attach_widgets()
        self.set_border_width(5)
        self.arg_type = None

    def create_and_attach_widgets(self):
        self.option_label = HIGSectionLabel('New Option')
        self.attach(self.option_label, 0, 3, 0, 1)

        self.name_label = HIGEntryLabel(_('Name:'))
        self.name_entry = HIGTextEntry()
        self.attach(self.name_label, 0, 1, 1, 2)
        self.attach(self.name_entry, 1, 3, 1, 2)

        self.hint_label = HIGEntryLabel(_('Hint:'))
        self.hint_entry = HIGTextEntry()
        self.attach(self.hint_label, 0, 1, 2, 3)
        self.attach(self.hint_entry, 1, 3, 2, 3)

        self.need_root = gtk.CheckButton(_('Need root'))
        self.attach(self.need_root, 0, 1, 3, 4)

        self.options_label = HIGEntryLabel(_('Options:'))
        hbox = HIGHBox()
        self.options_entry = HIGTextEntry()
        self.insert_arg_button = HIGButton(title='Args', stock='gtk-add')
        self.insert_arg_button.connect('clicked', self.update_args)
        self.attach(self.options_label, 0, 1, 4, 5)
        self.attach(self.options_entry, 1, 2, 4, 5)
        self.attach(self.insert_arg_button, 2, 3, 4, 5)

        self.aguments_label = HIGEntryLabel(_('Arguments:'))
        self.arguments_entry = HIGTextEntry()
        self.arguments_entry.set_editable(False)
        self.attach(self.aguments_label, 0, 1, 5, 6)
        self.attach(self.arguments_entry, 1, 3, 5, 6)

    def update_args(self, widget):
        '''
        Update aguments entry and option entry
        '''

        cursor_index = self.options_entry.get_position()
        text_entry = self.options_entry.get_text()
        arg_description, arg_key = self.dialog_args()
        if arg_key != None:
            #Update arguments

            self.arg_type = arg_key
            if text_entry.find('%s') == -1:
                left = text_entry[0:cursor_index]
                right = text_entry[cursor_index:len(text_entry)]
                final = left + "%s" + right
                self.options_entry.set_text(final)
            self.arguments_entry.set_text(arg_description)

    def dialog_args(self):
        '''
        Create a dialog
        '''

        d = HIGDialog(_('Arguments'))
        description_label = HIGEntryLabel(
            _('Insert the description to argument:'))
        description_label.show()
        description_entry = HIGTextEntry()
        text = self.arguments_entry.get_text()
        description_entry.set_text(text)
        description_entry.show()

        combo_box = gtk.combo_box_new_text()
        combo_box.set_wrap_width(1)
        index = -1
        j = 0
        for i in ARG_TYPES:
            combo_box.append_text(ARG_TYPES[i])
            if i == self.arg_type:
                index = j
            j = j + 1
        if index > -1:
            combo_box.set_active(index)
        combo_box.show()
        d.vbox.pack_start(description_label, False, False)
        d.vbox.pack_start(description_entry, False, False)
        d.vbox.pack_start(combo_box, False, False)
        d.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
        d.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
        resp = d.run()
        result = None, None
        if resp == gtk.RESPONSE_OK:
            model = combo_box.get_model()
            active = combo_box.get_active()
            if active < 0:
                return None, None
            combo_selected = model[active][0]

            for i in ARG_TYPES:
                if combo_selected == ARG_TYPES[i]:
                    combo_selected = i

            result = description_entry.get_text(), combo_selected
            #self.insert_arg_button.set_label('Edit args')
            #self.insert_arg_button.
        d.destroy()
        return result

    def clear(self):
        """ 
        Clear Option Display
        """
        self.option_label.set_new_text('New Option')
        self.name_entry.set_text('')
        self.hint_entry.set_text('')
        self.arguments_entry.set_text('')
        self.need_root.set_active(False)
        self.options_entry.set_text('')

    def set_option_list(self, list):
        """
        set option list from a dictionarie 

        @param list: Elements of a option
        @type list: Dictionarie with elements
        """
        self.clear()
        self.option_label.set_new_text(list['name'])
        self.name_entry.set_text(list['name'])
        self.hint_entry.set_text(list['hint'])

        for i in list['arguments']:
            i = self.arguments_entry.get_text() + i
            self.arguments_entry.set_text(i)

        self.options_entry.set_text(list['option'])
        self.need_root.set_active(list['need_root'])
        self.arg_type = list['arg_type']

    def set_option(self, name, hint, arguments, need_root, options, arg_type):
        """
        fill fields
        buggy arguments.
        """
        self.clear()
        self.options_entry.set_label(name)
        self.name_entry.set_text(name)
        self.hint_entry.set_text(hint)
        self.arguments_entry.set_text(arguments)
        self.need_root.set_active(need_root)
        self.arg_type = arg_type
class ProfileManager(HIGWindow):
    """
    Create a Profile Manager 
    """
    def __init__(self, daddy=None):
        HIGWindow.__init__(self, type=gtk.WINDOW_TOPLEVEL)
        self.set_title('Profile Manager')
        self.set_position(gtk.WIN_POS_CENTER)
        self.__create_widgets()
        self.add(self.vbox_main)
        self.__fill_widgets()
        self.__pack_widgets()
        self.__scan_notebook = None
        
        self.daddy = daddy


    def __create_widgets(self):

        self.vbox_main = HIGVBox()

        self.main_frame = HIGFrame("Profiles")
        #self.main_frame.set_shadow_type(gtk.SHADOW_ETCHED_OUT)

        self.align = gtk.Alignment(0.0, 0.0, 1.0, 1.0)
        self.align.set_padding(0,0,12,0)

        self.vbox = HIGVBox()
        self.profiles_sw = HIGScrolledWindow()
        #TreeView
        self.model = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING)
        #self.modelfilter = self.model.filter_new()
        self.profiles_tv = gtk.TreeView(self.model)
        renderer = gtk.CellRendererText()
        column = gtk.TreeViewColumn(_("Name"), renderer, text=0)
        self.profiles_tv.append_column(column)
        renderer_hint = gtk.CellRendererText()
        column_hint = gtk.TreeViewColumn(_("Hint"), renderer_hint, text=1)
        self.profiles_tv.append_column(column_hint)
        #self.profiles_tv.set_model(self.modelfilter)
        #Info 
        self.hbox_info = HIGHBox()
        self.command_label = HIGEntryLabel('Command: ')
        self.command_entry = HIGTextEntry()
        self.command_entry.set_editable(False)

        #Buttons
        self.hbox_buttons = HIGHBox()

        self.wiz_button = HIGButton(title='Wizard', stock='gtk-convert')
        self.wiz_button.connect("clicked", self.new_wiz)

        self.edit_button = HIGButton(stock='gtk-edit')
        self.edit_button.connect("clicked", self.open_peditor)
        self.new_button = HIGButton(stock='gtk-new')
        self.new_button.connect("clicked", self.open_peditor)
        self.copy_button = HIGButton(stock='gtk-copy')
        self.copy_button.connect("clicked", self.copy_profiles)
        self.delete_button = HIGButton(stock=gtk.STOCK_DELETE)
        self.delete_button.connect('clicked', self.delete_profile)	
        #Apply Buttons
        self.cancel_button = HIGButton(stock='gtk-close')
        self.cancel_button.connect("clicked", self.quit)
        
        self.connect("delete-event", self.quit)

    def __fill_widgets(self):


        self.profiles = CommandProfile()
        self._reload_profile_list()

        #selection = self.profiles_tv.get_selection()
        #selection.connect("changed", self.change_nmap_command)
        self.profiles_tv.connect("cursor-changed", self.change_nmap_command)

    def __pack_widgets(self):
        """
        Pack all widgets of windows 
        """
        self.vbox_main.pack_start(self.main_frame, True, True)
        self.main_frame.add(self.align)
        self.align.add(self.vbox)
        self.vbox.set_border_width(6)

        self.vbox.pack_start(self.profiles_sw, True, True, 0)

        self.hbox_info.pack_start(self.command_label, False,False,0)
        self.hbox_info.pack_start(self.command_entry, True, True, 0)
        self.vbox.pack_start(self.hbox_info, False,False,0)



        self.hbox_buttons.pack_end(self.cancel_button)    
        self.hbox_buttons.pack_end(self.copy_button, True, True)
        self.hbox_buttons.pack_end(self.edit_button, True, True)
        self.hbox_buttons.pack_end(self.delete_button, True, True)
        self.hbox_buttons.pack_end(self.new_button, True, True)
        self.hbox_buttons.pack_end(self.wiz_button, True, True)
        self.hbox_buttons.set_spacing(6)
        self.vbox_main.pack_start(self.hbox_buttons, False, False)

        self.profiles_sw.set_size_request(400,170)
        self.profiles_sw.add(self.profiles_tv) 


    def get_selected_profile(self):
        """
        Returns the string with name of selected profile 
        """
        try:
            treeselection = self.profiles_tv.get_selection()
            (model,iter) = treeselection.get_selected()	
            return model.get_value(iter,0)
        except:
            return None

    def change_nmap_command(self,widget_tv):
        """
        Change a nmap command at command entry
        """
        assert widget_tv is not None
        # it call __init__ because when wizard or profile are open,  
        # need update profiles
        self.profiles.__init__()
        # update text entry of command
        self.command_entry.set_text(self.profiles.get_command(
            self.get_selected_profile()))	

    def new_wiz(self,widget):
        w = Wizard()
        w.set_notebook(None)
        w.set_profilemanager(self.model)
        w.show_all()

    def open_peditor(self, widget):
        """
        Open Profile Editor with a Selected or Non-Selected(New) Item
        """
        assert widget is not None

        if widget.get_label() == "gtk-edit":
            # Edit profile selected    
            if self.get_selected_profile() is not None:
                pe = ProfileEditor(self.get_selected_profile())
                pe.set_notebook(self.__scan_notebook)
                pe.set_profilemanager(self.model)
                pe.show_all()
        else:
            # New Profile
            pe = ProfileEditor()
            pe.set_notebook(self.__scan_notebook)
            pe.set_profilemanager(self.model)
            pe.show_all()
            self._reload_profile_list()

    def copy_profiles(self, widget):
        """
        Copy selected Profile
        """
        if self.get_selected_profile() is None:
            return None
        d = ProfileName(_("Insert a profile name"))
        profile_name = d.run()
        if profile_name is None or profile_name=="":
            return None
        #get commands of selected profile
        profile_selected = self.get_selected_profile()
        command = self.profiles.get_command(profile_selected)
        hint = self.profiles.get_hint(profile_selected)
        description = self.profiles.get_description(profile_selected)
        annotation = self.profiles.get_annotation(profile_selected)
        #Options
        prof = self.profiles.get_profile(profile_selected)
        options_used = prof['options']
        options = CommandConstructor(options_used)

        self.profiles.add_profile(profile_name,\
                                  command=command,\
                                  hint=hint,\
                                  description=description,\
                                  annotation=annotation,\
                                  options=options.get_options())



        myiter = self.model.insert_before(None, None)
        self.model.set_value(myiter, 0, profile_name)
        self.model.set_value(myiter,1, self.profiles.get_hint(profile_name))
        treeselection = self.profiles_tv.get_selection()
        treeselection.select_iter(myiter)
        #(model,iter) = treeselection.get_selected()	
        #model.get_value(iter,0)


    def delete_profile(self, widget=None):
        """
        delete profile 
        """
        if self.get_selected_profile() is None:
            return None
        self.profiles.remove_profile(self.get_selected_profile())
        #Update treeview
        treeselection = self.profiles_tv.get_selection()
        (model,iter) = treeselection.get_selected()
        model.remove(iter)
        # update text entry of command
        self.command_entry.set_text('')	



    def _reload_profile_list(self):
        """
        Reload a list of profiles
        """
        profiles = []
        all_profiles = self.profiles.sections()
        for profile in all_profiles:
            if self.profiles.get(profile, 'tool') == 'nmap':
                profiles.append(profile)
        profiles.sort()
        self.model.clear()


        for command in profiles:
            myiter = self.model.insert_before(None, None)
            self.model.set_value(myiter, 0, command)
            self.model.set_value(myiter,1, self.profiles.get_hint(command))
            #self.model.append([command,self.profiles.get_hint(command)])

    def set_notebook(self, notebook):
        self.__scan_notebook = notebook
    def quit(self, widget):
        self.destroy()

    def quit(self, widget, data=None):
        if self.daddy:
            self.daddy.running_pm = False
            self.destroy()
        else:
            gtk.main_quit()
class EventWindow(HIGWindow):
    column_names = [
        'Event Type', 'Test Type', 'Time', 'Since Time', 'Locations'
    ]

    def __init__(self):
        HIGWindow.__init__(self, type=gtk.WINDOW_TOPLEVEL)

        self.location_user = Location()  #user location information
        self.location_user.longitude = 0.0
        self.location_user.latitude = 0.0

        self.set_title(_('Events List'))
        self.set_size_request(720, 580)
        self.set_position(gtk.WIN_POS_CENTER_ALWAYS)

        self.__create_widgets()
        self.__pack_widgets()
        self.__connect_widgets()

        self.__load_events()

    def __connect_widgets(self):

        self.get_event_btn.connect("clicked", lambda w: self._get_event())
        self.refresh_btn.connect("clicked", lambda w: self._refresh_list())

    def __create_widgets(self):

        #box
        self.all_box = HIGVBox()
        self.input_box = HIGHBox()
        self.buttom_box = HIGHBox()
        self.check_btn_box = gtk.HButtonBox()

        #Add input
        self.title_text = HIGLabel(_("Locations"))
        self.longitude_text = HIGLabel(_("longitude:"))
        self.longitude_entry = HIGTextEntry()
        self.latitude_text = HIGLabel(_("latitude:"))
        self.latitude_entry = HIGTextEntry()

        #Add buttons
        self.get_event_btn = gtk.Button(_("Get Events"))
        self.refresh_btn = gtk.Button(_("Refresh"))

        #status bar
        self.statusbar = gtk.Statusbar()
        self.statusbar.push(0, 'Events in Database')

        self.listmodel = gtk.ListStore(str, str, str, str, str)

        # create the TreeView
        self.treeview = gtk.TreeView()

        # create the TreeViewColumns to display the data
        self.tvcolumn = [None] * len(self.column_names)
        cellpb = gtk.CellRendererText()

        self.tvcolumn[0] = gtk.TreeViewColumn(self.column_names[0], cellpb)
        self.tvcolumn[0].add_attribute(cellpb, 'text', 0)
        #cell = gtk.CellRendererText()
        #self.tvcolumn[0].set_cell_data_func(cell, self.test_type)
        self.treeview.append_column(self.tvcolumn[0])

        for n in range(1, len(self.column_names)):
            cell = gtk.CellRendererText()
            self.tvcolumn[n] = gtk.TreeViewColumn(self.column_names[n], cell)
            self.tvcolumn[n].add_attribute(cell, 'text', n)
            if n == 1:
                cell.set_property('xalign', 1.0)
            #self.tvcolumn[n].set_cell_data_func(cell, cell_data_funcs[n])
            self.treeview.append_column(self.tvcolumn[n])

        #self.treeview.connect('row-activated', self.open_file)
        self.scrolledwindow = gtk.ScrolledWindow()
        self.scrolledwindow.add(self.treeview)
        self.treeview.set_model(self.listmodel)

    def __pack_widgets(self):

        self.all_box._pack_noexpand_nofill(self.input_box)
        self.all_box._pack_expand_fill(self.scrolledwindow)
        self.all_box._pack_noexpand_nofill(self.buttom_box)

        self.input_box.pack_start(self.title_text)
        self.input_box.pack_start(self.longitude_text)
        self.input_box.pack_start(self.longitude_entry)
        self.input_box.pack_start(self.latitude_text)
        self.input_box.pack_start(self.latitude_entry)

        self.buttom_box.pack_start(self.statusbar, True, True, 0)
        self.buttom_box.pack_end(self.check_btn_box, False, False, 0)

        self.check_btn_box.set_layout(gtk.BUTTONBOX_END)
        self.check_btn_box.set_spacing(8)
        self.check_btn_box.pack_start(self.get_event_btn)
        self.check_btn_box.pack_start(self.refresh_btn)

        self.add(self.all_box)

    def __load_events(self):
        for event_entry in theApp.event_manager.event_repository:
            if event_entry.EventType == 'CENSOR':
                pass
            elif event_entry.EventType == 'THROTTLING':
                pass
            elif event_entry.EventType == 'OFF_LINE':
                pass
            self.listmodel.append([
                event_entry.EventType, event_entry.TestType,
                time.strftime("%Y-%m-%d %H:%M:%S",
                              time.gmtime(event_entry.TimeUTC)),
                time.strftime("%Y-%m-%d %H:%M:%S",
                              time.gmtime(event_entry.SinceTimeUTC)),
                event_entry.Locations
            ])

    def _get_event(self):
        """
        get events from aggregator by using Aggregator API:get_events
        """
        longtitude = self.longitude_entry.get_text()
        latitude = self.latitude_entry.get_text()

        if longtitude != "" and latitude != "":
            self.location_user.longitude = float(longtitude)
            self.location_user.latitude = float(latitude)
        else:
            #There we should add user preference logitude
            self.location_user.longitude = 0.0
            self.location_user.latitude = 0.0

        defer_ = theApp.aggregator.get_events(self.location_user)
        defer_.addCallback(self.finish_get_events)
        defer_.addErrback(self.handler_error)

    def _refresh_list(self):
        """
        clear and load
        """
        self.listmodel.clear()
        self.__load_events()
        self.statusbar.push(0, _("Refresh the Events List!"))

    def handler_error(self, failure):
        g_logger.error("Error in get events %s" % str(failure))
        self.statusbar.push(0, _("Error in Get Events From Aggregator!"))

    def finish_get_events(self, message):
        if message is None:
            self.statusbar.push(0, _("No new Events from Aggregator!"))
            return

        self.statusbar.push(
            0, _("Get %d Events from Aggregator" % (len(message.events))))

    def test_type(self, column, cell, model, iter):
        #cell.set_property('text', model.get_value(iter, 0))
        return

    def event_type(self, column, cell, model, iter):
        #filename = os.path.join(self.dirname, model.get_value(iter, 0))
        #filestat = os.stat(filename)
        #cell.set_property('text', filestat.st_size)
        return

    def time(self, column, cell, model, iter):
        #filename = os.path.join(self.dirname, model.get_value(iter, 0))
        #filestat = os.stat(filename)
        #cell.set_property('text', oct(stat.S_IMODE(filestat.st_mode)))
        return

    def location(self, column, cell, model, iter):
        #filename = os.path.join(self.dirname, model.get_value(iter, 0))
        #filestat = os.stat(filename)
        #cell.set_property('text', time.ctime(filestat.st_mtime))
        return

    def report(self, column, cell, model, iter):
        return
Beispiel #29
0
class ExposeProfiles(TabBox, object):

    def __init__(self, name):
        """ Create defaults Widget """
        TabBox.__init__(self, name)
        self._pack_widgets()
        self._connect_events()
    def _create_widgets(self):
        """ Create widgets"""

        self._frm_option = HIGFrame(_('Options'))
        self._box_option = HIGHBox()
        self.__lbl_file_opt = HIGEntryLabel(_('File:'))
        self.__entry_file_opt = HIGTextEntry()
        self.__entry_file_opt.set_editable(False)
        self.__file_browser_opt = HIGButton(_('Browse file'), \
                                            gtk.STOCK_DIRECTORY)

        self._frm_profile = HIGFrame(_('Profile'))
        self._box_profile = HIGHBox()
        self.__lbl_file_profile = HIGEntryLabel(_('File:'))
        self.__entry_file_profile = HIGTextEntry()
        self.__entry_file_profile.set_editable(False)
        self.__file_browser_profile = HIGButton(_('Browse file'), \
                                            gtk.STOCK_DIRECTORY)

        self._frm_wizard = HIGFrame(_('Wizard'))
        self._box_wizard = HIGHBox()

        self.__lbl_file_wizard = HIGEntryLabel(_('File:'))
        self.__entry_file_wizard = HIGTextEntry()
        self.__entry_file_wizard.set_editable(False)
        self.__file_browser_wizard = HIGButton(_('Browse file'), \
                                            gtk.STOCK_DIRECTORY)

        self.__btn_restore = HIGButton(_('Restore Defaults'), gtk.STOCK_CLEAR)

    def _pack_widgets(self):

        # Options
        self._box_option._pack_noexpand_nofill(self.__lbl_file_opt)
        self._box_option._pack_noexpand_nofill(self.__entry_file_opt)
        self._box_option._pack_noexpand_nofill(self.__file_browser_opt)
        self._frm_option.add(self._box_option)

        # Profile
        self._box_profile._pack_noexpand_nofill(self.__lbl_file_profile)
        self._box_profile._pack_noexpand_nofill(self.__entry_file_profile)
        self._box_profile._pack_noexpand_nofill(self.__file_browser_profile)
        self._frm_profile.add(self._box_profile)

        # Wizard
        self._box_wizard._pack_noexpand_nofill(self.__lbl_file_wizard)
        self._box_wizard._pack_noexpand_nofill(self.__entry_file_wizard)
        self._box_wizard._pack_noexpand_nofill(self.__file_browser_wizard)
        self._frm_wizard.add(self._box_wizard)

        # Pack Frames
        self.pack_start(self._frm_option, False,False)
        self.pack_start(self._frm_profile, False, False)
        self.pack_start(self._frm_wizard, False, False)
    
    def _connect_events(self):
        self.__entry_file_opt.connect("changed", self.update_file_opt)
        self.__entry_file_profile.connect("changed", self.update_file_profile)
        self.__entry_file_wizard.connect("changed", self.update_file_wizard)
    # Callbacks
    
    # Should be merged callback based on a dict or whatever.
    def update_file_opt(self):
        profile_conf.options = self.__entry_file_opt.get_text()
    
    def update_file_profile(self):
        profile_conf.profile = self.__entry_file_wizard.get_text()
        
    def update_file_wizard(self):
        profile_conf.wizard = self.__entry_file_wizard.get_text()
        
        
    # API 
    def get_profile(self):
        return self.__entry_file_profile.get_text()
    def set_profile(self, profile):
        self.__entry_file_profile.set_text(profile)
    
    def get_wizard(self):
        return self.__entry_file_wizard.get_text()
    def set_wizard(self, wizard):
        self.__entry_file_wizard.set_text(wizard)
    
    def set_options(self, options):
        self.__entry_file_opt.set_text(options)
    def get_options(self):
        return self.__entry_file_opt.get_text()
    
    profile = property(get_profile, set_profile)
    wizard = property(get_wizard, set_wizard)
    options = property(get_options, set_options)
Beispiel #30
0
class Proprieties(HIGScrolledWindow):
    '''

    This box should be configurable 
    if widget is of a type all configuration should be change to this type

    #tricks: option_list have a icon to fill with options
    and option_check have a list of options in combo to change

    '''
    def __init__(self):
        HIGScrolledWindow.__init__(self)
        self._boxeditable = None
        vp = gtk.Viewport()
        self._create_widgets()
        vp.add(self._box)
        vp.set_shadow_type(gtk.SHADOW_NONE)
        self.add(vp)
        self._profilecore = None
        self._selected = None

    def set_profilecore(self, profilecore):
        self._profilecore = profilecore

    def _create_widgets(self):
        '''
        Create the main entrys of the option 
        '''
        self._box = HIGVBox()

        self._table = HIGTable()

        #Name
        self._label_name = HIGEntryLabel(_('Name'))
        self._entry_name = HIGTextEntry()

        self._entry_name.connect('activate', self._update_label)

        #Type
        self._label_type = HIGEntryLabel(_('Type'))
        self._combo_type = gtk.combo_box_new_text()
        self._combo_type.append_text('')
        self._combo_type.append_text('Option List')
        self._combo_type.append_text('Option Check')
        self._combo_type.set_active(0)
        self._combo_type.connect('changed', self.change_combo)

        self._label_opt = HIGEntryLabel(_('Option'))
        self._entry_opt = HIGTextEntry()
        self._entry_opt.set_sensitive(False)

        #For option list open a dialog to add/remove options
        self._button_list = HIGButton('Edit Option List')
        img = gtk.Image()
        img_dir = os.path.join(pixmaps_dir, 'uie', 'combo.png')
        img.set_from_file(img_dir)
        self._button_list.set_image(img)
        self._button_list.connect('button-press-event',
                                  self._button_list_clicked)

        self._table.attach(self._label_name, 0, 1, 0, 1)
        self._table.attach(self._entry_name, 1, 2, 0, 1)
        self._table.attach(self._label_type, 0, 1, 1, 2)
        self._table.attach(self._combo_type, 1, 2, 1, 2)

        self._table.attach(self._button_list, 0, 2, 3, 4)
        self._table.attach(self._label_opt, 0, 1, 4, 5)
        self._table.attach(self._entry_opt, 1, 2, 4, 5)

        self._box.pack_start(self._table, False, False)

    def _button_list_clicked(self, widget, event):
        section_name = self._boxeditable.get_name()
        lm = ListManager(self._entry_name.get_text(), section_name,
                         self._profilecore, self._selected, _('List of items'))

    def _update_label(self, widget):
        #XXX Replace by Command
        log.debug("Update Label")
        selected = self._selected
        cmd = CommandChangeLabel(selected, self._entry_name.get_text(),
                                 self._profilecore, self._boxeditable, True)
        command_manager.add_command(cmd)

    def change_combo(self, combo):
        model = combo.get_model()
        index = combo.get_active()
        if index:
            if model[index][0] == 'Option List':

                log.debug('Show Button List ')
                self._button_list.show()

            else:

                log.debug('Hide Button List ')
                self._button_list.hide()
        return

    def show_notebook_label(self):
        '''
        show proprieties of notebook label and hide others
        '''
        pass

    def show_item(self):
        pass

    def hide_item(self):
        self._label_opt.hide()
        self._entry_opt.hide()
        self._button_list.hide()
        self._combo_type.hide()
        self._label_type.hide()
        self._entry_name.hide()
        self._label_name.hide()

    def set_notebooklabel(self, selected):
        self._entry_name.show()
        self._label_name.show()
        self._entry_name.set_text(selected.get_text())
        self._button_list.hide()
        self._combo_type.hide()
        self._label_type.hide()
        self._label_opt.hide()
        self._entry_opt.hide()
        self._selected = selected

    def set_item(self, selected):
        self._entry_name.show()
        self._label_name.show()

        self._selected = selected
        if selected.get_name() != None:
            self._entry_name.set_text(selected.get_name())
        else:
            self.hide_item()
            return
        childs = selected.get_children()
        self._combo_type.show()
        self._label_type.show()
        child_label = childs[0]
        if isinstance(child_label, gtk.HBox):
            #OptionCheck
            self._label_opt.show()
            self._entry_opt.show()
            opt_ = self._profilecore.get_opt_check(
                self._boxeditable.get_name(), selected.get_name())
            self._entry_opt.set_text(opt_)
            self._button_list.hide()
            child_label.cbutton.set_label(self._entry_name.get_text())
            self._combo_type.set_active(2)
            #XXX: Put other widget that sensitible = False with option name

        elif isinstance(child_label, gtk.EventBox):
            #OptionList
            self._button_list.show()
            other = child_label.get_children()[0]
            other.set_label(self._entry_name.get_text())
            self._combo_type.set_active(1)
        #Disable Combo to change OptionList/OptionChange
        self._combo_type.set_sensitive(False)

    def set_boxeditable(self, boxeditable):
        self._boxeditable = boxeditable

    def update(self):
        pass

    def disable_all(self):
        self._label_opt.hide()
        self._entry_opt.hide()
        self._button_list.hide()
        self._combo_type.hide()
        self._label_type.hide()
        self._entry_name.hide()
        self._label_name.hide()

    def load_data(self, option):
        pass

    def unload(self, option):
        pass
Beispiel #31
0
class GeneralSettings(TabBox, object):
    """
    General Settings
    - Splash enable/disable
    - Warnings
    - Erros, log, configure bugreport
    - Autosave: clean up, define folder etc
    - Define Nmap Command
    """

    def __init__(self, name):
        TabBox.__init__(self, name)


    def _create_widgets(self):
        """
        Design all
        """
        # Create general widgets
        self._create_widgets_common()
        self._create_widgets_autosave()
        self._create_widgets_error()
        # Packing main section
        self.pack_start(self._box_common, False, False)
        self.pack_start(self._box_error_frame, False, False)
        self.pack_start(self._box_save_frame, False, False)
        self._box_error_frame.set_shadow_type(gtk.SHADOW_NONE)
        self._box_error_frame.set_shadow_type(gtk.SHADOW_NONE)


        # Settings Values

        self.splash = general_settings.splash
        self.warnings_extensions = general_settings.warnings_extensions
        self.silent_root = general_settings.silent_root
        self.crash_report = general_settings.crash_report
        self.log = general_settings.log
        self.log_file = general_settings.log_file
        self.warnings_save = general_settings.warnings_save

        self._connect_events()
    def _create_widgets_common(self):
        """ generally tab """
        self._box_common = HIGVBox() # pack main section
        self.__check_splash = gtk.CheckButton(_('Enable Splash on start'))
        self.__check_silent_root = gtk.CheckButton(\
            _('Silent Warning Non-Root'))
        self.__check_warning_extensions = gtk.CheckButton(\
            _('Set/Check extensions - Windows only'))
        self._box_common.pack_start(self.__check_splash, False, False)
        #self._box_common.pack_start(self.__check_warning_extensions, False, \
        #                            False)
        self._box_common.pack_start(self.__check_silent_root, False, False)
        self.__label_nmap = HIGEntryLabel(_('Nmap Command'))
        self.__entry_nmap = HIGTextEntry()
        # Files usr saved on predefined directory:
        self.__label_path = HIGEntryLabel(_('Nmap Command'))
        self.__entry_path = HIGTextEntry()
        self.__button_path = HIGButton(_('Choose'))
        self.__box_path = HIGHBox()
        self.__box_path.pack_start(self.__label_path, False, False)
        self.__box_path.pack_end(self.__button_path, False, False)

        self._box_common.set_border_width(0)




    def _create_widgets_error(self):

        # Create Widgets
        self._box_error_frame = HIGFrame('Error')

        self._box_error = HIGTable(5, 2)
        self._box_error.set_border_width(10)
        self._box_error_frame.add(self._box_error)
        self.__crash_report = gtk.CheckButton(_('Enable Crash Report'))
        # Radio Button List
        self.__log_no = gtk.RadioButton(None, _('No log'))
        self.__log_terminal = gtk.RadioButton(self.__log_no, _('Enable log in terminal'))
        self.__log_file = gtk.RadioButton(self.__log_terminal,\
                                         _('Enable log file'))

        self.__log_file_label = HIGEntryLabel(_('Log file'))
        self.__log_file_entry = HIGTextEntry()
        self.__log_file_entry.set_editable(False)
        # FIXME: Do default file ~/.umit/umit.log
        self.__log_file_browser = HIGButton(_('Browse file'), \
                                            gtk.STOCK_DIRECTORY)

        tmpbox = HIGHBox()
        tmpbox.pack_start(self.__log_file_entry, False, False)
        tmpbox.pack_start(self.__log_file_browser, False, False)


        # attach table
        self._box_error.attach(self.__crash_report, 0,1,0,1,\
                               gtk.FILL|gtk.EXPAND| gtk.SHRINK, gtk.FILL)
        self._box_error.attach(self.__log_no, 0,1,1,2,\
                               gtk.FILL|gtk.EXPAND| gtk.SHRINK, gtk.FILL)
        self._box_error.attach(self.__log_terminal, 0,1,2,3,\
                               gtk.FILL|gtk.EXPAND| gtk.SHRINK, gtk.FILL)
        self._box_error.attach(self.__log_file, 0,1,3,4,\
                               gtk.FILL|gtk.EXPAND| gtk.SHRINK, gtk.FILL)
        self._box_error.attach(self.__log_file_label, 0,1,4,5,\
                               gtk.FILL|gtk.EXPAND| gtk.SHRINK, gtk.FILL)
        self._box_error.attach(tmpbox, 1,2,4,5,\
                               gtk.FILL|gtk.EXPAND| gtk.SHRINK, gtk.FILL)
    def _create_widgets_autosave(self):

        # Create Widgets
        self._box_save_frame = HIGFrame('Auto-save')

        self._box_save = HIGVBox()
        self._box_save_frame.add(self._box_save)
        self._box_save.set_border_width(10)

        self._warnings_save = gtk.CheckButton(
            _('Enable warnings without saving'))
        self._clean_b = HIGButton(_('Delete saved files'), gtk.STOCK_CLEAR)
        self._clean_b_box = HIGHBox()
        self._clean_b_box.pack_start(self._clean_b, False, True)

        # pack

        self._box_save.pack_start(self._warnings_save, False, False)
        self._box_save.pack_start(self._clean_b_box, False, False)
    def _connect_events(self):
        """
        connect call backs
        """

        self.__check_splash.connect('toggled', self.update_splash)
        self.__check_silent_root.connect('toggled', self.update_silent_root)
        self.__crash_report.connect('toggled', self.update_crash_report)


        self.__log_file.connect('toggled', self.update_log)
        self.__log_file.connect('toggled', self.update_log_file)
        self.__log_terminal.connect('toggled', self.update_log)
        self.__log_no.connect('toggled', self.update_log)

        self.__log_file_browser.connect('clicked', self.read_file)
        self.__log_file_entry.connect('changed', self.update_log_file_text)

        self._warnings_save.connect('toggled', self.update_save_warn)
        
        self._clean_b.connect('clicked', self.delete_files)
        
        self.update_log_file(None)
    # Callbacks
    def delete_files(self, widget):
        # NOTE: This method should be adapted in umit.core.UserConf
        # Creating an empty recent_scans file
        
        log.debug('>>> Reset store files:  -  %s' % base_paths['user_dir'])

        reset_user_dir(base_paths['user_dir'])
        
    
    def update_save_warn(self, widget):
        general_settings.warnings_save = self.warnings_save

    def read_file(self, widget):
        dialog = gtk.FileChooserDialog("Open..",
                                       None,
                                       gtk.FILE_CHOOSER_ACTION_SAVE,
                                       (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
                                        gtk.STOCK_SAVE_AS, gtk.RESPONSE_OK))
        dialog.set_default_response(gtk.RESPONSE_OK)
        response = dialog.run()
        if response == gtk.RESPONSE_OK:
            # Get name of file
            self.__log_file_entry.set_text(dialog.get_filename())
        dialog.destroy()

    def update_crash_report(self, widget):
        general_settings.crash_report = self.crash_report
    def update_splash(self, widget):
        general_settings.splash = self.splash
    def update_silent_root(self, widget):
        general_settings.silent_root = self.silent_root
    def update_log_file_text(self, widget):
        general_settings.log_file = self.log_file
    def update_log_file(self, widget):
        if not self.__log_file.get_active():
            self.__log_file_active(False)
        else:
            self.__log_file_active(True)
    def update_log(self, widget):
        """ Verify if is enable, if it is not enable nothing to do """
        if not widget.get_active():
            return
        # Widget is enable.
        ## But which is enable?

        # Setting kind of log
        if widget == self.__log_no:
            general_settings.log = "None"
        elif widget == self.__log_terminal:
            general_settings.log = "Debug"
        elif widget == self.__log_file:
            general_settings.log = "File"


    # API
    def get_splash(self):
        return self.__check_splash.get_active()
    def set_splash(self, splash):
        self.__check_splash.set_active(splash)

    def set_warnings_extensions(self, extensions):
        self.__check_warning_extensions.set_active(extensions)
    def get_warnings_extensions(self):
        return self.__check_warning_extensions.get_active()
    def set_silent_root(self, root):
        self.__check_silent_root.set_active(root)
    def get_silent_root(self):
        return self.__check_silent_root.get_active()


    def set_crash_report(self, crash):
        self.__crash_report.set_active(crash)
    def get_crash_report(self):
        return self.__crash_report.get_active()

    def get_log(self):
        """
        filter a str with None, Debug or File
        return: int (means 0 - No debug, 1 - debug, 2 - debug file)
        """
        if self.__log_no.get_active():
            return "None"
        elif self.__log_terminal.get_active():
            return "Debug"
        elif self.__log_file.get_active():
            return "File"
        else:
            raise LogException()



    def set_log(self, log):
        if log == "None":
            self.__log_no.set_active(True)
        elif log == "Debug":
            self.__log_terminal.set_active(True)
        elif log == "File":
            self.__log_file.set_active(True)


    def __log_file_active(self, bool):
        self.__log_file_label.set_sensitive(bool)
        self.__log_file_entry.set_sensitive(bool)
        self.__log_file_browser.set_sensitive(bool)

    def set_log_file(self, filename):
        self.__log_file_entry.set_text(filename)
    def get_log_file(self):
        return self.__log_file_entry.get_text()

    def set_warnings_save(self, save):
        self._warnings_save.set_active(save)
    def get_warnings_save(self):
        return self._warnings_save.get_active()

    # Propertys
    splash = property(get_splash, set_splash)
    warnings_extensions = property(get_warnings_extensions, \
                                   set_warnings_extensions)
    silent_root = property(get_silent_root, set_silent_root)
    crash_report = property(get_crash_report, set_crash_report)
    log = property(get_log, set_log)
    log_file = property(get_log_file, set_log_file)
    warnings_save = property(get_warnings_save, set_warnings_save)
class EventWindow(HIGWindow):
    column_names = ['Event Type',
                    'Test Type',
                    'Time',
                    'Since Time',
                    'Locations']

    def __init__(self):
        HIGWindow.__init__(self, type=gtk.WINDOW_TOPLEVEL)
        
        self.location_user = Location() #user location information
        self.location_user.longitude = 0.0
        self.location_user.latitude  = 0.0
         
        self.set_title(_('Events List'))
        self.set_size_request(720, 580)
        self.set_position(gtk.WIN_POS_CENTER_ALWAYS)
        
        self.__create_widgets()
        self.__pack_widgets()
        self.__connect_widgets()
        
        self.__load_events()

    def __connect_widgets(self):
        
        self.get_event_btn.connect("clicked",lambda w:self._get_event())
        self.refresh_btn.connect("clicked",lambda w:self._refresh_list())
        
    def __create_widgets(self):
        
        #box
        self.all_box = HIGVBox()
        self.input_box = HIGHBox()
        self.buttom_box = HIGHBox()
        self.check_btn_box = gtk.HButtonBox()
        
        #Add input
        self.title_text = HIGLabel(_("Locations"))
        self.longitude_text = HIGLabel(_("longitude:"))
        self.longitude_entry = HIGTextEntry()
        self.latitude_text = HIGLabel(_("latitude:"))
        self.latitude_entry = HIGTextEntry()         
        
        #Add buttons
        self.get_event_btn = gtk.Button(_("Get Events"))
        self.refresh_btn = gtk.Button(_("Refresh"))
          
        #status bar
        self.statusbar = gtk.Statusbar()
        self.statusbar.push(0,'Events in Database')        
                                
        self.listmodel = gtk.ListStore(str, str, str, str, str)

        # create the TreeView
        self.treeview = gtk.TreeView()

        # create the TreeViewColumns to display the data
        self.tvcolumn = [None] * len(self.column_names)
        cellpb = gtk.CellRendererText()

        self.tvcolumn[0] = gtk.TreeViewColumn(self.column_names[0], cellpb)
        self.tvcolumn[0].add_attribute(cellpb, 'text', 0)
        #cell = gtk.CellRendererText()
        #self.tvcolumn[0].set_cell_data_func(cell, self.test_type)
        self.treeview.append_column(self.tvcolumn[0])

        for n in range(1, len(self.column_names)):
            cell = gtk.CellRendererText()
            self.tvcolumn[n] = gtk.TreeViewColumn(self.column_names[n], cell)
            self.tvcolumn[n].add_attribute(cell, 'text', n)
            if n == 1:
                cell.set_property('xalign', 1.0)
            #self.tvcolumn[n].set_cell_data_func(cell, cell_data_funcs[n])
            self.treeview.append_column(self.tvcolumn[n])

        #self.treeview.connect('row-activated', self.open_file)
        self.scrolledwindow = gtk.ScrolledWindow()
        self.scrolledwindow.add(self.treeview)
        self.treeview.set_model(self.listmodel)
        
    def __pack_widgets(self):
        
        self.all_box._pack_noexpand_nofill(self.input_box)
        self.all_box._pack_expand_fill(self.scrolledwindow) 
        self.all_box._pack_noexpand_nofill(self.buttom_box)  
                
        self.input_box.pack_start(self.title_text)
        self.input_box.pack_start(self.longitude_text)
        self.input_box.pack_start(self.longitude_entry)
        self.input_box.pack_start(self.latitude_text)
        self.input_box.pack_start(self.latitude_entry)
       
        self.buttom_box.pack_start(self.statusbar,True,True,0)
        self.buttom_box.pack_end(self.check_btn_box,False,False,0)
        
        self.check_btn_box.set_layout(gtk.BUTTONBOX_END)
        self.check_btn_box.set_spacing(8)       
        self.check_btn_box.pack_start(self.get_event_btn)
        self.check_btn_box.pack_start(self.refresh_btn)   
        
        self.add(self.all_box)
        
    def __load_events(self):
        for event_entry in theApp.event_manager.event_repository:
            if event_entry.EventType == 'CENSOR':
                pass
            elif event_entry.EventType == 'THROTTLING':
                pass
            elif event_entry.EventType == 'OFF_LINE':
                pass
            self.listmodel.append(
                [event_entry.EventType,
                 event_entry.TestType,
                 time.strftime("%Y-%m-%d %H:%M:%S",
                               time.gmtime(event_entry.TimeUTC)),
                 time.strftime("%Y-%m-%d %H:%M:%S",
                               time.gmtime(event_entry.SinceTimeUTC)),
                 event_entry.Locations])

    
    def _get_event(self):
        """
        get events from aggregator by using Aggregator API:get_events
        """
        longtitude = self.longitude_entry.get_text()
        latitude   = self.latitude_entry.get_text()
        
        if longtitude != "" and latitude != "":
            self.location_user.longitude = float(longtitude)
            self.location_user.latitude  = float(latitude)
        else:
            #There we should add user preference logitude
            self.location_user.longitude = 0.0
            self.location_user.latitude  = 0.0
        
        defer_ = theApp.aggregator.get_events(self.location_user)
        defer_.addCallback(self.finish_get_events)
        defer_.addErrback(self.handler_error)
    
    def _refresh_list(self):
        """
        clear and load
        """
        self.listmodel.clear()
        self.__load_events()
        self.statusbar.push(0,_("Refresh the Events List!"))  
     
    def handler_error(self,failure):
        g_logger.error("Error in get events %s"%str(failure))
        self.statusbar.push(0,_("Error in Get Events From Aggregator!"))         
            
    def finish_get_events(self,message):
        if message is None:
            self.statusbar.push(0,_("No new Events from Aggregator!"))  
            return
        
        self.statusbar.push(0,_("Get %d Events from Aggregator"%(len(message.events))))  
        

    def test_type(self, column, cell, model, iter):
        #cell.set_property('text', model.get_value(iter, 0))
        return

    def event_type(self, column, cell, model, iter):
        #filename = os.path.join(self.dirname, model.get_value(iter, 0))
        #filestat = os.stat(filename)
        #cell.set_property('text', filestat.st_size)
        return

    def time(self, column, cell, model, iter):
        #filename = os.path.join(self.dirname, model.get_value(iter, 0))
        #filestat = os.stat(filename)
        #cell.set_property('text', oct(stat.S_IMODE(filestat.st_mode)))
        return

    def location(self, column, cell, model, iter):
        #filename = os.path.join(self.dirname, model.get_value(iter, 0))
        #filestat = os.stat(filename)
        #cell.set_property('text', time.ctime(filestat.st_mtime))
        return

    def report(self, column, cell, model, iter):
        return
Beispiel #33
0
class OptionDisplay(HIGTable):
    def __init__(self, option=None):
        HIGTable.__init__(self)
        self.create_and_attach_widgets()
        self.set_border_width(5)
        self.arg_type=None

    def create_and_attach_widgets(self):
        self.option_label = HIGSectionLabel('New Option')
        self.attach(self.option_label, 0, 3, 0, 1)

        self.name_label = HIGEntryLabel(_('Name:'))
        self.name_entry = HIGTextEntry()
        self.attach(self.name_label, 0,1,1,2)
        self.attach(self.name_entry, 1,3,1,2)

        self.hint_label = HIGEntryLabel(_('Hint:'))
        self.hint_entry = HIGTextEntry()
        self.attach(self.hint_label, 0,1,2,3)
        self.attach(self.hint_entry,1,3,2,3)

        self.need_root = gtk.CheckButton(_('Need root'))
        self.attach(self.need_root, 0,1,3,4)	



        self.options_label = HIGEntryLabel(_('Options:'))
        hbox = HIGHBox()
        self.options_entry = HIGTextEntry()
        self.insert_arg_button = HIGButton(title='Args', stock='gtk-add')
        self.insert_arg_button.connect('clicked', self.update_args)
        self.attach(self.options_label,0,1,4,5)
        self.attach(self.options_entry, 1,2,4,5)
        self.attach(self.insert_arg_button, 2,3, 4, 5)

        self.aguments_label = HIGEntryLabel(_('Arguments:'))
        self.arguments_entry = HIGTextEntry()
        self.arguments_entry.set_editable(False)
        self.attach(self.aguments_label, 0,1, 5,6)
        self.attach(self.arguments_entry, 1,3,5,6)


    def update_args(self, widget):
        '''
        Update aguments entry and option entry
        '''

        cursor_index = self.options_entry.get_position()
        text_entry = self.options_entry.get_text()
        arg_description, arg_key = self.dialog_args()
        if arg_key != None :
            #Update arguments

            self.arg_type = arg_key
            if text_entry.find('%s') == -1: 
                left = text_entry[0:cursor_index]
                right = text_entry[cursor_index:len(text_entry)]
                final = left + "%s" + right
                self.options_entry.set_text(final)
            self.arguments_entry.set_text(arg_description)


    def dialog_args(self):
        '''
        Create a dialog
        '''

        d = HIGDialog(_('Arguments'))
        description_label = HIGEntryLabel(
            _('Insert the description to argument:'))
        description_label.show()
        description_entry = HIGTextEntry()
        text = self.arguments_entry.get_text()
        description_entry.set_text(text)
        description_entry.show()

        combo_box = gtk.combo_box_new_text()
        combo_box.set_wrap_width(1)
        index = -1 
        j = 0 
        for i in ARG_TYPES:
            combo_box.append_text(ARG_TYPES[i])
            if i == self.arg_type:
                index = j 
            j = j + 1
        if index > -1 : 
            combo_box.set_active(index)
        combo_box.show()
        d.vbox.pack_start(description_label, False, False)
        d.vbox.pack_start(description_entry, False, False)
        d.vbox.pack_start(combo_box, False, False)
        d.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
        d.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
        resp = d.run()
        result  = None, None 
        if resp == gtk.RESPONSE_OK:
            model = combo_box.get_model()
            active = combo_box.get_active()
            if active < 0:
                return None, None 
            combo_selected =  model[active][0]

            for i in ARG_TYPES:
                if combo_selected == ARG_TYPES[i]:
                    combo_selected = i

            result = description_entry.get_text(), combo_selected
            #self.insert_arg_button.set_label('Edit args')
            #self.insert_arg_button.
        d.destroy()
        return result 

    def clear(self):
        """ 
        Clear Option Display
        """
        self.option_label.set_new_text('New Option')
        self.name_entry.set_text('')
        self.hint_entry.set_text('')
        self.arguments_entry.set_text('')
        self.need_root.set_active(False)
        self.options_entry.set_text('')


    def set_option_list(self, list):
        """
        set option list from a dictionarie 

        @param list: Elements of a option
        @type list: Dictionarie with elements
        """
        self.clear()
        self.option_label.set_new_text(list['name'])
        self.name_entry.set_text(list['name'])
        self.hint_entry.set_text(list['hint'])

        for i in list['arguments']:
            i = self.arguments_entry.get_text() + i
            self.arguments_entry.set_text(i)

        self.options_entry.set_text(list['option'])
        self.need_root.set_active(list['need_root'])
        self.arg_type = list['arg_type']


    def set_option(self,name, hint,
                   arguments, need_root,
                   options, arg_type):
        """
        fill fields
        buggy arguments.
        """
        self.clear()
        self.options_entry.set_label(name)
        self.name_entry.set_text(name)
        self.hint_entry.set_text(hint)
        self.arguments_entry.set_text(arguments)
        self.need_root.set_active(need_root)
        self.arg_type = arg_type
Beispiel #34
0
class AddSourceDialog(HIGDialog):
    def __init__(self, type_ = None, path = None):
        if type_ and path:
            title = _("Edit Source")
        else:
            type_ = "FILE"
            path = ""
            title = _("Add Source")
        HIGDialog.__init__(self, title, None,
                           gtk.DIALOG_MODAL,
                           (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
                            gtk.STOCK_OK, gtk.RESPONSE_OK))
        hbox = HIGHBox()
        self.combo = gtk.combo_box_new_text()
        types = sorted(self.types.keys())
        for t in types:
            self.combo.append_text(t)
        self.combo.set_active(types.index(type_))
        self.combo.connect("changed", self._changed_cb)
        hbox.pack_start(self.combo, False, False)
        self.entry = HIGTextEntry()
        self.entry.set_text(path)
        hbox.pack_start(self.entry)
        self.btn = HIGButton(_("Browse..."), stock=gtk.STOCK_OPEN)
        self.btn.connect("clicked", self._clicked_cb)
        hbox.pack_start(self.btn, False, False)
        self.vbox.add(hbox)
        self.show_all()
        self.update()

    def update(self):
         callback, = self.types[self.combo.get_active_text()]
         self.btn.set_sensitive(not callback is None)

    def _browse_file(self, p):
        file_chooser = AllFilesFileChooserDialog(_("Select Script"))
        response = file_chooser.run()
        filename = file_chooser.get_filename()
        file_chooser.destroy()
        if not response == gtk.RESPONSE_OK:
            return
        self.entry.set_text(filename)

    def _browse_folder(self, p):
        file_chooser = DirectoryChooserDialog(_("Select Scripts Directory"))
        response = file_chooser.run()
        dirname = file_chooser.get_filename()
        file_chooser.destroy()
        if not response == gtk.RESPONSE_OK:
            return False
        self.entry.set_text(dirname)

    types = {
        "FILE" : (_browse_file, ),
        "DIR" : (_browse_folder, ),
        "URL" : (None, ), 
        "URLBASE" : (None, ),
        "INSTALLDIR" : (_browse_folder, )
    }

    def _clicked_cb(self, p):
         callback, = self.types[self.combo.get_active_text()]
         if callback:
             callback(self, p)

    def _changed_cb(self, p):
        self.update()

    def get_result(self):
        (type_, path) = (self.combo.get_active_text(), self.entry.get_text())
        if type_ not in ('FILE', 'DIR'):
            return (type_, path)
        # test existence
        if os.path.exists(path):
            return (type_, path)
        else:
            message = gtk.MessageDialog(type=gtk.MESSAGE_QUESTION,
                                        buttons=gtk.BUTTONS_YES_NO,
                                        message_format=_("The path don't exists. Append it?"))
            message.set_title(_("No such path"))
            response = message.run()
            message.destroy()
            if response == gtk.RESPONSE_YES:
                return (type_, path)
        return None
Beispiel #35
0
class Proprieties(HIGScrolledWindow):
    '''

    This box should be configurable 
    if widget is of a type all configuration should be change to this type

    #tricks: option_list have a icon to fill with options
    and option_check have a list of options in combo to change

    '''

    def __init__(self):
        HIGScrolledWindow.__init__(self)
        self._boxeditable = None 
        vp = gtk.Viewport()
        self._create_widgets()
        vp.add(self._box)
        vp.set_shadow_type(gtk.SHADOW_NONE)
        self.add(vp)
        self._profilecore = None 
        self._selected = None 

    def set_profilecore(self, profilecore):
        self._profilecore = profilecore


    def _create_widgets(self):
        '''
        Create the main entrys of the option 
        '''
        self._box = HIGVBox()


        self._table = HIGTable()


        #Name
        self._label_name  = HIGEntryLabel(_('Name'))
        self._entry_name = HIGTextEntry()

        self._entry_name.connect('activate', self._update_label)

        #Type 
        self._label_type = HIGEntryLabel(_('Type'))	
        self._combo_type = gtk.combo_box_new_text()
        self._combo_type.append_text('')
        self._combo_type.append_text('Option List')
        self._combo_type.append_text('Option Check')
        self._combo_type.set_active(0)
        self._combo_type.connect('changed', self.change_combo)

        self._label_opt = HIGEntryLabel(_('Option'))
        self._entry_opt = HIGTextEntry()
        self._entry_opt.set_sensitive(False)

        #For option list open a dialog to add/remove options
        self._button_list = HIGButton('Edit Option List')
        img = gtk.Image()
        img_dir =  os.path.join(pixmaps_dir, 'uie', 'combo.png')
        img.set_from_file(img_dir)
        self._button_list.set_image(img)
        self._button_list.connect('button-press-event', self._button_list_clicked)


        self._table.attach(self._label_name, 0,1,0, 1)
        self._table.attach(self._entry_name, 1,2,0,1)
        self._table.attach(self._label_type, 0,1,1,2)
        self._table.attach(self._combo_type, 1,2,1, 2)

        self._table.attach(self._button_list, 0,2, 3,4)
        self._table.attach(self._label_opt, 0,1, 4,5)
        self._table.attach(self._entry_opt, 1,2,4,5)

        self._box.pack_start(self._table, False, False)
    def _button_list_clicked(self, widget, event):
        section_name = self._boxeditable.get_name()
        lm = ListManager(self._entry_name.get_text(),section_name, 
                         self._profilecore, self._selected, _('List of items'))
    def _update_label(self, widget):
        #XXX Replace by Command
        log.debug("Update Label")
        selected = self._selected
        cmd = CommandChangeLabel(selected, self._entry_name.get_text(), 
                                 self._profilecore,self._boxeditable, True)
        command_manager.add_command(cmd)
        
    def change_combo(self,combo):
        model = combo.get_model()
        index = combo.get_active()
        if index:
            if model[index][0]=='Option List':

                log.debug('Show Button List ')
                self._button_list.show()

            else:

                log.debug('Hide Button List ')
                self._button_list.hide()
        return
    def show_notebook_label(self):
        '''
        show proprieties of notebook label and hide others
        '''
        pass


    def show_item(self):
        pass
    def hide_item(self):
        self._label_opt.hide()
        self._entry_opt.hide()
        self._button_list.hide()
        self._combo_type.hide()
        self._label_type.hide()
        self._entry_name.hide()
        self._label_name.hide()
    def set_notebooklabel(self, selected):
        self._entry_name.show()
        self._label_name.show()
        self._entry_name.set_text(selected.get_text())
        self._button_list.hide()
        self._combo_type.hide()
        self._label_type.hide()
        self._label_opt.hide()
        self._entry_opt.hide()
        self._selected = selected
    def set_item(self, selected):
        self._entry_name.show()
        self._label_name.show()

        self._selected = selected
        if selected.get_name()!=None:
            self._entry_name.set_text(selected.get_name())
        else: 
            self.hide_item()
            return
        childs = selected.get_children()
        self._combo_type.show()
        self._label_type.show()
        child_label = childs[0]
        if isinstance(child_label, gtk.HBox):
            #OptionCheck
            self._label_opt.show()
            self._entry_opt.show()
            opt_ = self._profilecore.get_opt_check(self._boxeditable.get_name(),
                                                   selected.get_name())
            self._entry_opt.set_text(opt_)
            self._button_list.hide()
            child_label.cbutton.set_label(self._entry_name.get_text())
            self._combo_type.set_active(2)
            #XXX: Put other widget that sensitible = False with option name


        elif isinstance(child_label, gtk.EventBox):
            #OptionList
            self._button_list.show()
            other = child_label.get_children()[0]
            other.set_label(self._entry_name.get_text())
            self._combo_type.set_active(1)
        #Disable Combo to change OptionList/OptionChange
        self._combo_type.set_sensitive(False)

    def set_boxeditable(self, boxeditable):
        self._boxeditable = boxeditable
    def update(self):
        pass

    def disable_all(self):
        self._label_opt.hide()
        self._entry_opt.hide()
        self._button_list.hide()
        self._combo_type.hide()
        self._label_type.hide()
        self._entry_name.hide()
        self._label_name.hide()
    def load_data(self, option):
        pass 
    def unload(self,option):
        pass 
class EntryField(object):
    """
    This class is responsible by the main part of QS: the EntryField.
    All logic of completion, data handling and interface is here.
    """
    
    def __init__(self):
        self.qs_data = QSData()
        self.entry = HIGTextEntry()
        self.entry.set_visibility(True)
        self.status = Status()
        self.status.set_empty()
        self.scan_result = Result()
        self.b_text = ""
        self.rgx_is_domain = "^((ht|f)tp(s?)\:\/\/|~/|/)?([\w]+:\w+@)?([a-zA-Z]{1}"
        self.rgx_is_domain += "([\w\-]+\.)+([\w]{2,5}))(:[\d]{1,5})?((/?\w+/)+|/?)"
        self.rgx_is_domain += "(\w+\.[\w]{3,4})?((\?\w+=\w+)?(&\w+=\w+)*)?"
        
        self.completion = gtk.EntryCompletion()
        self.entry.set_max_length(1000)
        
        # add button to launch result in umit
        self.btn_umit = gtk.Button ("Open Result")
        
        self.results_opened = False
        self.nmap_output = None
        
        self.load_data(None)
         
        self.btn_umit.connect("clicked", self._launch_umit, None)
        
        self.entry.show()

        
    def show_results(self):
        """
        Show scan output
        """
        if not self.results_opened:
            self.nmap_output = NmapOutputViewer()
            # remove some buttons
            self.nmap_output.hbox_buttons.remove(self.nmap_output.btn_output_properties)
            self.nmap_output.hbox_buttons.remove(self.nmap_output.btn_refresh)
            self.nmap_output.hbox_buttons.pack_start(self.btn_umit)
            self.vbox.pack_end(self.nmap_output)
            self.vbox.show_all()
            self.results_opened = True
        
    def hide_results(self):
        """
        Hide scan output
        """
        if self.results_opened:
            self.nmap_output.hbox_buttons.remove(self.btn_umit)
            self.vbox.remove(self.nmap_output)
            self.results_opened = False
        
    def menu_to_umit(self, widget, button, time, data=None):
        """
        Here will be the small menu responsible to call Network Scanner.
        """
        if button == 3:
            data.show_all()
            
    def _launch_umit(self, widget, event):
        """
        Here will go the call to NetWork Scanner to display results previously
        loaded here.
        """
        nscanner_call = "umit -f %s" % self.command_execution.get_xml_output_file()
        args = shlex.split(nscanner_call)
        self.command_process = Popen(args, bufsize=1, stdin=PIPE,
                                         stdout=PIPE, stderr=PIPE)

    def load_data(self, option=None):
        """
        Load the data on gtk.ListStore, generate the model and set functions of
        match and signals.
        """
        liststore = gtk.ListStore(str)
            
        if option == "host":
            for _d in self.qs_data.get_target_list():
                liststore.append([_d])
        elif option == "profile":
            for _d in self.qs_data.get_profiles("profile_name"):
                liststore.append([_d])
        elif option == "nmap_options":
            for _d in self.qs_data.get_nmap_options():
                liststore.append([_d])
        else:
            for _d in self.qs_data.get_all().values():
                for _i in _d:
                    liststore.append([_i])
            
        self.completion.set_model(liststore)
        self.completion.set_match_func(self.match_func)
        self.completion.connect('match-selected', self.on_completion_match)
        self.entry.connect('activate', self.on_completion_not_match)
        self.entry.connect('backspace', self.on_backspace)
        self.entry.set_completion(self.completion)
        self.completion.set_text_column(0)

    
    #def load_if_not_complete(self, widget, event):
        #self.load_data("host")
        
  
    def match_func(self, completion, key, iter):
        """
        This function have the job to match and compare the words that was entered 
        on the entry field.
        """
        model = self.completion.get_model()
        modelstr = model[iter][0]
        
        if ' ' in key:
            last_word = " ".join(key.split()[1:])
            if last_word != "":
                return modelstr.lower().startswith(last_word.lower()) or modelstr.lower().startswith(key.lower())
        
        return modelstr.lower().startswith(key.lower())
    
    
    def on_completion_not_match(self, widget):
        """
        This method is called when the autocompletion don't match any result
        or user press Enter.
        """
        target_list = TargetList()

        entered_text = self.entry.get_text()

        # If has a profile
        if len(entered_text) > 1 and entered_text.find(" ") != -1:
            possible_host = entered_text.split(" ")[0]
            possible_profile = " ".join(entered_text.split(" ")[1:])
        else:
            # If is just a domain
            self.b_text = entered_text + " "
            self.entry.set_text(self.b_text)
            possible_host = entered_text
            possible_profile = None

        # Saving the target
        target_list.add_target(possible_host)
            
        self.entry.set_position(-1)
                        
#        if len(self.b_text.split(" ")) > 1:
#            host = self.b_text.split(" ")[0]
#            profile = " ".join(self.b_text.split(" ")[1:])
#        else:
#            host = entered_text
#            profile = None

            
        #Launch the scan
        self.run_scan(possible_host, possible_profile)
        
        #TODO: get the end of the scan here?
        try:
            alive = self.command_execution.scan_state()
            
            while alive:
                alive = self.command_execution.scan_state()

            file = self.command_execution.get_normal_output_file()
            self.show_results()
            self.nmap_output.show_nmap_output(file)
            self.nmap_output.refresh_output()
 
            
            #text_out = self.scan_result.set_nmap_output(possible_host, 
            #                        self.command_execution.get_normal_output(),
            #                        possible_profile)
                    
            #self.buffer.set_text(text_out)
            #self.vbox.pack_start(self.result_text, False, False, 0)
            #self.result_text.show()
        
            self.save_scan(possible_host)
            #del entered_text
        
            #self.load_data("profile")
        
            return True
        
        except:
            pass

        
    def on_completion_match(self, completion, model, iter):
        #get the text entered by the user
        entered_text = self.entry.get_text()
        
        if model[iter][0]:
            
            current_text = model[iter][0]
            # If has a profile
            if len(entered_text) > 1 and entered_text.find(" ") != -1:
                self.b_text = entered_text.split(" ")[0] + " " + current_text + " "
                self.entry.set_text(self.b_text)
                possible_host = entered_text.split(" ")[0]
                possible_profile = current_text
            #elif self.entry.get_text()
            else:
                # If is just a domain
                self.b_text = current_text + " "
                self.entry.set_text(self.b_text)
                possible_host = current_text
                possible_profile = None
                
            self.entry.set_position(-1)    
            data_from_db = self.qs_data.get_from_db()
            
            if current_text in data_from_db.keys():
                text_out = ""
                for _t in data_from_db[current_text]:
                    if _t[0] == "ports" or _t[0] == "stats":
                        pass
                    else:
                        text_out += "%s: %s\n" % (_t[0], _t[1])
                        
                #self.buffer.set_text(text_out)
                #self.vbox.pack_start(self.result_text, False, False, 0)
                #self.result_text.show()
                
    
            self.run_scan(possible_host, possible_profile)
            try:
                alive = self.command_execution.scan_state()
                
                while alive:
                    alive = self.command_execution.scan_state()
                    if not alive:
                        break
                    
                self.show_results()
                file = self.command_execution.get_normal_output_file()
                print "scan finished - %s" % file
                self.nmap_output.show_nmap_output(file)
                self.nmap_output.refresh_output()
                
                #text_out = self.scan_result.set_nmap_output(possible_host, 
                #                self.command_execution.get_normal_output(),
                #                possible_profile)
        
                #self.buffer.set_text(text_out)
                #self.vbox.pack_start(self.result_text, False, False, 0)
                #self.result_text.show()
        
                self.save_scan(possible_host)
        
                #self.load_data("profile")
        
                return True
        
            except:
                print("exception")
                traceback.print_exc(file=sys.stdout)
            
            del data_from_db
                        
            #self.load_data("profile")
            return True
            
    def on_backspace(self, entry):
        self.hide_results()
        self.resize(500,30)
        self.b_text = ""

    def disable_widgets(self):
        self.scan_result.set_sensitive(False)
    
    def enable_widgets(self):
        self.scan_result.set_sensitive(True)
    
    def kill_scan(self):
        try:
            self.command_execution.kill()
        except AttributeError:
            pass

        self.entry.set_text("")
        self.status.set_empty()
        self.disable_widgets()
    
    def run_scan(self, host, profile):
        if re.match(self.rgx_is_domain, host):

            commands = self.qs_data.get_profiles("profile_commands")
            try:
                nmap_option = commands[profile]
            except:
                nmap_option = "-T Aggressive -v -n"

            print "QuickScan: running scan: %s on %s" % (nmap_option, host)
            
            if Ipv6.is_ipv6(host):
            	namp_option = nmap_option + " -6"
            
            self.command_execution = NmapCommand('%s %s %s' % (Path.nmap_command_path,
                                                               nmap_option,
                                                               host))
            
            try:
                alive = self.command_execution.scan_state()
                if alive:
                    warn_dialog = HIGAlertDialog(
                    message_format="Scan has not finished yet",
                    secondary_text="Another scan is running in the background.",
                    type=gtk.MESSAGE_QUESTION, buttons=gtk.BUTTONS_OK_CANCEL)
                response = warn_dialog.run()
                warn_dialog.destroy()
                
                if response == gtk.RESPONSE_OK:
                    self.kill_scan()
                else:
                    return
            
            except:
                pass
                        
            try:
                self.command_execution.run_scan()
                self.status.set_scanning()
            except OSError, msg:
                warn_dialog = HIGAlertDialog(
                    message_format="Nmap couldn't be found",
                    secondary_text="Umit Quick Scan couldn't find Nmap. " 
                    "Please check your Nmap instalation.",
                    type=gtk.MESSAGE_ERROR)
                warn_dialog.run()
                warn_dialog.destroy()
            except Exception, msg:
                warn_dialog = HIGAlertDialog(
                    message_format="Command is missing!",
                    secondary_text="Please check your profile's command.",
                    type=gtk.MESSAGE_ERROR)
                warn_dialog.run()
                warn_dialog.destroy()
                
                
            self.verify_thread_timeout_id = gobject.timeout_add(2000, 
                self.verify_execution)
            
            return
Beispiel #37
0
class LoginDialog(HIGDialog):
    """"""

    #----------------------------------------------------------------------
    def __init__(self, title=_('Open Monitor 2012')):
        """Constructor"""
        HIGDialog.__init__(self, title=title, flags=gtk.DIALOG_MODAL,
                           buttons=(gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))

        self.set_position(gtk.WIN_POS_CENTER_ALWAYS)
        self.set_default_response(gtk.RESPONSE_ACCEPT)
        self.set_keep_above(True)
        self.set_size_request(480, 240)
        self.set_border_width(2)

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

    def _create_widgets(self):
        
        #Username
        self.username_label = HIGLabel(_("Username"))
        self.username_entry = HIGTextEntry()
        self.username_entry.set_activates_default(True)

        #Password
        self.password_label = HIGLabel(_("Password"))
        self.password_entry = HIGPasswordEntry()
        self.password_entry.set_activates_default(True)
        
        #Logo
        self.logo_openmonitor = gtk.gdk.pixbuf_new_from_file\
                                    (os.path.join(IMAGES_DIR, 'logoOM.png'))
        self.logo_image = gtk.Image()
        self.logo_image.set_from_pixbuf(self.logo_openmonitor)
        #self.login_text = gtk.Label(_("Log into your ICM agent."))
        
        #Register
        #self.register_button = HIGStockButton(gtk.STOCK_DIALOG_INFO,_("Register"))
        self.register_label = \
            gtk.Label(_("<span foreground='blue'>" \
                        "Register id</span>"))
        self.register_label.set_use_markup(True)
        self.register_button = gtk.Button()
        self.register_button.add(self.register_label)
        self.register_button.set_relief(gtk.RELIEF_NONE)
        
        #Forget Password
        self.forgot_password_label = \
            gtk.Label(_("<span foreground='blue'>" \
                        "Forgot password?</span>"))
        self.forgot_password_label.set_use_markup(True)
        self.forgot_password = gtk.Button()
        self.forgot_password.add(self.forgot_password_label)
        self.forgot_password.set_relief(gtk.RELIEF_NONE)
        
        #Auto Login
        self.auto_login_checkbtn = gtk.CheckButton(_("Auto login"))
        
        #Settings
        self.settings_button = HIGStockButton(gtk.STOCK_DIALOG_INFO,_("settings"))
        
        #Container
        self.hbox = HIGHBox(False,2)
        self.table = HIGTable(8,4,False)
        self.table.set_row_spacings(5)
        self.table.set_col_spacings(10)
        self.action_area.set_homogeneous(False)
        
        #tab orders
        self.orders = [self.username_entry, self.password_entry, self.register_button, self.forgot_password]

    def _pack_widgets(self):

        self.hbox.set_border_width(8)
        
        self.table.set_focus_chain(self.orders)
        
        self.table.attach(self.logo_image,0,7,0,5,gtk.FILL,gtk.FILL,0,0)
        self.table.attach(self.username_label,0,1,5,6,gtk.FILL,gtk.FILL,0,0)
        self.table.attach(self.username_entry,1,5,5,6,gtk.FILL|gtk.EXPAND,gtk.FILL|gtk.EXPAND,0,0)
        self.table.attach(self.password_label,0,1,6,7,gtk.FILL,gtk.FILL,0,0)
        self.table.attach(self.password_entry,1,5,6,7,gtk.FILL|gtk.EXPAND,gtk.FILL|gtk.EXPAND,0,0) 
        self.table.attach(self.register_button,5,6,5,6,gtk.FILL,gtk.FILL,0,0)  
        self.table.attach(self.forgot_password,5,6,6,7,gtk.FILL,gtk.FILL,0,0)
        self.table.attach(self.auto_login_checkbtn,1,3,7,8,gtk.FILL,gtk.FILL,0,0)   
 
        self.hbox._pack_expand_fill(self.table)
        self.vbox.pack_start(self.hbox, False, False)                                  

        spaceholder1 = hig_box_space_holder()
        spaceholder2 = hig_box_space_holder()
        spaceholder3 = hig_box_space_holder()
        self.action_area.pack_end(spaceholder1)
        self.action_area.pack_end(spaceholder2)
        self.action_area.pack_end(spaceholder3)
        self.action_area.pack_end(self.settings_button)
        self.action_area.reorder_child(self.settings_button, 0)
        self.action_area.reorder_child(spaceholder1, 1)        
        self.action_area.reorder_child(spaceholder2, 2)
        self.action_area.reorder_child(spaceholder3, 2)
        
    def _connect_widgets(self):
        self.connect('response', self.check_response)
        self.register_button.connect('clicked', self._register)
        self.forgot_password.connect('clicked', self._forgot_password)
        self.settings_button.connect('clicked', self._settings)

    def _register(self, widget):
        #registration_form = RegistrationDialog()
        #registration_form.show_all()
        webbrowser.open(theApp.aggregator.base_url + "/accounts/register/")

    def _forgot_password(self, widget):
        webbrowser.open(theApp.aggregator.base_url + "/accounts/password/reset/")

    def check_response(self, widget, response_id):
        #There should collect the error information: help the user to check problem
        if response_id == gtk.RESPONSE_ACCEPT: # clicked on Ok btn
            username = self.username_entry.get_text()
            password = self.password_entry.get_text()
            save_login = self.auto_login_checkbtn.get_active()
            
            #Bug in this: If the user go to this window, the theApp.peer_info cannot is_registered
            
            #if not theApp.peer_info.is_registered:
            defer_ = theApp.login(username, password, save_login)   
            #    defer_ = theApp.register_agent(username, password)
            #    defer_.addCallback(
            #        lambda x: theApp.login(username, password, save_login))
            #else:
            #    defer_ = theApp.login(username, password, save_login)
            self.destroy()
            theApp.gtk_main.login_dlg = None
        elif response_id in (gtk.RESPONSE_DELETE_EVENT, gtk.RESPONSE_CANCEL,
                gtk.RESPONSE_NONE):
            self.destroy()
            theApp.gtk_main.login_dlg = None
            
    def _settings(self,widget):
        '''
        configure settings: Server IP/Port: popup a new window
        '''
        settings_form = SettingsDialog()
        settings_form.show_all()