| 1 | #!/usr/bin/env python |
|---|
| 2 | # Copyright (C) 2005 Insecure.Com LLC. |
|---|
| 3 | # |
|---|
| 4 | # Author: Luis A. Bastiao Silva <luis.kop@gmail.com> |
|---|
| 5 | # |
|---|
| 6 | # This program is free software; you can redistribute it and/or modify |
|---|
| 7 | # it under the terms of the GNU General Public License as published by |
|---|
| 8 | # the Free Software Foundation; either version 2 of the License, or |
|---|
| 9 | # (at your option) any later version. |
|---|
| 10 | # |
|---|
| 11 | # This program is distributed in the hope that it will be useful, |
|---|
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | # GNU General Public License for more details. |
|---|
| 15 | # |
|---|
| 16 | # You should have received a copy of the GNU General Public License |
|---|
| 17 | # along with this program; if not, write to the Free Software |
|---|
| 18 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 19 | |
|---|
| 20 | import gtk |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | from higwidgets.higtables import HIGTable |
|---|
| 24 | from higwidgets.higboxes import HIGVBox, HIGHBox |
|---|
| 25 | from higwidgets.higscrollers import HIGScrolledWindow |
|---|
| 26 | from higwidgets.higlabels import HIGSectionLabel, HIGEntryLabel |
|---|
| 27 | from higwidgets.higentries import HIGTextEntry |
|---|
| 28 | from higwidgets.hignotebooks import HIGNotebook |
|---|
| 29 | from higwidgets.higbuttons import HIGButton |
|---|
| 30 | |
|---|
| 31 | from umitCore.I18N import _ |
|---|
| 32 | # Testing at devel |
|---|
| 33 | from os.path import split, join |
|---|
| 34 | |
|---|
| 35 | from umitCore.Paths import Path |
|---|
| 36 | Path.set_umit_conf(join(split(__file__)[0], 'config', 'umit.conf')) |
|---|
| 37 | #END DEV TEST |
|---|
| 38 | options = Path.options |
|---|
| 39 | |
|---|
| 40 | import gobject |
|---|
| 41 | |
|---|
| 42 | from umitGUI.OptionBuilder import OptionBuilder |
|---|
| 43 | from umitCore.NmapOptions import NmapOptions |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | class OptionDisplay(HIGTable): |
|---|
| 47 | def __init__(self, option=None): |
|---|
| 48 | HIGTable.__init__(self) |
|---|
| 49 | self.create_and_attach_widgets() |
|---|
| 50 | self.set_border_width(5) |
|---|
| 51 | def create_and_attach_widgets(self): |
|---|
| 52 | self.option_label = HIGSectionLabel('New Option') |
|---|
| 53 | self.option_label.set_width_chars(10) |
|---|
| 54 | self.attach(self.option_label, 0, 1, 0, 1) |
|---|
| 55 | |
|---|
| 56 | self.name_label = HIGEntryLabel(_('Name:')) |
|---|
| 57 | self.name_entry = HIGTextEntry() |
|---|
| 58 | self.attach(self.name_label, 0,1,1,2) |
|---|
| 59 | self.attach(self.name_entry, 1,2,1,2) |
|---|
| 60 | |
|---|
| 61 | self.hint_label = HIGEntryLabel(_('Hint:')) |
|---|
| 62 | self.hint_entry = HIGTextEntry() |
|---|
| 63 | self.attach(self.hint_label, 0,1,2,3) |
|---|
| 64 | self.attach(self.hint_entry,1,2,2,3) |
|---|
| 65 | |
|---|
| 66 | self.aguments_label = HIGEntryLabel(_('Arguments:')) |
|---|
| 67 | self.arguments_entry = HIGTextEntry() |
|---|
| 68 | self.attach(self.aguments_label, 0,1, 3,4) |
|---|
| 69 | self.attach(self.arguments_entry, 1,2,3,4) |
|---|
| 70 | |
|---|
| 71 | self.need_root = gtk.CheckButton(_('Need root')) |
|---|
| 72 | self.attach(self.need_root, 0,1,4,5) |
|---|
| 73 | |
|---|
| 74 | self.options_label = HIGEntryLabel(_('Options:')) |
|---|
| 75 | self.options_entry = HIGTextEntry() |
|---|
| 76 | self.attach(self.options_label,0,1,5,6) |
|---|
| 77 | self.attach(self.options_entry, 1,2,5,6) |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | def clear(self): |
|---|
| 82 | """ |
|---|
| 83 | Clear Option Display |
|---|
| 84 | """ |
|---|
| 85 | self.options_label.set_label('') |
|---|
| 86 | self.name_entry.set_text('') |
|---|
| 87 | self.hint_entry.set_text('') |
|---|
| 88 | self.arguments_entry.set_text('') |
|---|
| 89 | self.need_root.set_active(False) |
|---|
| 90 | self.options_entry.set_text('') |
|---|
| 91 | |
|---|
| 92 | |
|---|
| 93 | def set_option_list(self, list): |
|---|
| 94 | """ |
|---|
| 95 | set option list from a dictionarie |
|---|
| 96 | |
|---|
| 97 | @param list: Elements of a option |
|---|
| 98 | @type list: Dictionarie with elements |
|---|
| 99 | """ |
|---|
| 100 | self.clear() |
|---|
| 101 | self.option_label.set_new_text(list['name']) |
|---|
| 102 | self.name_entry.set_text(list['name']) |
|---|
| 103 | self.hint_entry.set_text(list['hint']) |
|---|
| 104 | |
|---|
| 105 | for i in list['arguments']: |
|---|
| 106 | i = self.arguments_entry.get_text() + ", " + i |
|---|
| 107 | self.arguments_entry.set_text(i) |
|---|
| 108 | |
|---|
| 109 | self.options_entry.set_text(list['option']) |
|---|
| 110 | self.need_root.set_active(list['need_root']) |
|---|
| 111 | |
|---|
| 112 | |
|---|
| 113 | def set_option(self,name, hint, |
|---|
| 114 | arguments, need_root, |
|---|
| 115 | options): |
|---|
| 116 | """ |
|---|
| 117 | fill fields |
|---|
| 118 | buggy arguments. |
|---|
| 119 | """ |
|---|
| 120 | self.clear() |
|---|
| 121 | self.options_label.set_label(name) |
|---|
| 122 | self.name_entry.set_text(name) |
|---|
| 123 | self.hint_entry.set_text(hint) |
|---|
| 124 | self.arguments_entry.set_text(arguments) |
|---|
| 125 | self.need_root.set_active(need_root) |
|---|
| 126 | |
|---|
| 127 | class OptionDisplayMainFrame(OptionDisplay): |
|---|
| 128 | def __init__(self, option=None): |
|---|
| 129 | OptionDisplay.__init__(self, option) |
|---|
| 130 | hbox = HIGHBox() |
|---|
| 131 | hbox.set_border_width(12) |
|---|
| 132 | self.delete_button = HIGButton(stock='gtk-delete') |
|---|
| 133 | self.delete_button.connect('clicked', self.delete_option) |
|---|
| 134 | self.new_button = HIGButton(stock='gtk-new') |
|---|
| 135 | self.new_button.connect('clicked', self.new_option) |
|---|
| 136 | self.update_button = HIGButton(stock='gtk-refresh') |
|---|
| 137 | self.update_button.connect('clicked', self.update_option) |
|---|
| 138 | self.add_button = HIGButton(stock='gtk-add') |
|---|
| 139 | self.add_button.connect('clicked', self.add_option) |
|---|
| 140 | hbox.pack_end(self.delete_button,False,False) |
|---|
| 141 | hbox.pack_end(self.update_button, False, False) |
|---|
| 142 | hbox.pack_end(self.add_button, False, False) |
|---|
| 143 | hbox.pack_end(self.new_button, False,False) |
|---|
| 144 | self.attach(hbox, 1,2,6,7) |
|---|
| 145 | |
|---|
| 146 | def delete_option(self, widget): |
|---|
| 147 | """ |
|---|
| 148 | Delete option |
|---|
| 149 | @param widget: widget from connect |
|---|
| 150 | @type widget: HIGButton |
|---|
| 151 | """ |
|---|
| 152 | def update_option(self, widget): |
|---|
| 153 | """ |
|---|
| 154 | Update option |
|---|
| 155 | @param widget: widget from connect |
|---|
| 156 | @type widget: HIGButton |
|---|
| 157 | """ |
|---|
| 158 | def new_option(self, widget): |
|---|
| 159 | """ |
|---|
| 160 | Clean Option Display |
|---|
| 161 | @param widget: widget from connect |
|---|
| 162 | @type widget: HIGButton |
|---|
| 163 | """ |
|---|
| 164 | def add_option(self, widget): |
|---|
| 165 | """ |
|---|
| 166 | Add option |
|---|
| 167 | @param widget: widget from connect |
|---|
| 168 | @type widget: HIGButton |
|---|
| 169 | """ |
|---|
| 170 | |
|---|
| 171 | class OptionList(HIGVBox): |
|---|
| 172 | """ |
|---|
| 173 | A treeview with a list of actual options |
|---|
| 174 | """ |
|---|
| 175 | |
|---|
| 176 | def __init__(self, optiondisplay=None): |
|---|
| 177 | HIGVBox.__init__(self) |
|---|
| 178 | self.__model = gtk.TreeStore(gobject.TYPE_STRING) |
|---|
| 179 | self.__treeview = gtk.TreeView(self.__model) |
|---|
| 180 | self.__treeview.set_headers_visible(False) |
|---|
| 181 | renderer = gtk.CellRendererText() |
|---|
| 182 | column = gtk.TreeViewColumn("Option List", renderer, text=0) |
|---|
| 183 | self.__treeview.append_column(column) |
|---|
| 184 | self.options = NmapOptions(options) |
|---|
| 185 | self.__scrolledwindow = HIGScrolledWindow() |
|---|
| 186 | hbox = HIGHBox() |
|---|
| 187 | hbox.pack_start(self.__treeview, True, True) |
|---|
| 188 | self.__scrolledwindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) |
|---|
| 189 | self.__scrolledwindow.add_with_viewport(hbox) |
|---|
| 190 | self.notebook = HIGNotebook() |
|---|
| 191 | self.notebook.append_page(self.__scrolledwindow, HIGEntryLabel(_('Option List'))) |
|---|
| 192 | |
|---|
| 193 | |
|---|
| 194 | self.pack_start(self.notebook, True, True) |
|---|
| 195 | self.optiondisplay = optiondisplay |
|---|
| 196 | |
|---|
| 197 | self.exists_display = (self.optiondisplay != None ) #True or False |
|---|
| 198 | self.set_option_display(optiondisplay) |
|---|
| 199 | |
|---|
| 200 | |
|---|
| 201 | def set_option_display(self, optiondisplay): |
|---|
| 202 | """ |
|---|
| 203 | Set a option display to change fields when cursor change |
|---|
| 204 | |
|---|
| 205 | @param optiondisplay: it's a mainframe that contains fields to set |
|---|
| 206 | @type optiondisplay: OptionDisplay |
|---|
| 207 | """ |
|---|
| 208 | |
|---|
| 209 | self.optiondisplay = optiondisplay |
|---|
| 210 | self.exists_display = (self.optiondisplay != None ) #True or False |
|---|
| 211 | if self.exists_display: |
|---|
| 212 | print "cursor-changed" |
|---|
| 213 | self.__treeview.connect("cursor-changed",self.update_option_display) |
|---|
| 214 | |
|---|
| 215 | |
|---|
| 216 | |
|---|
| 217 | def get_selected(self): |
|---|
| 218 | """ |
|---|
| 219 | Returns the string with name of selected option |
|---|
| 220 | """ |
|---|
| 221 | try: |
|---|
| 222 | treeselection = self.__treeview.get_selection() |
|---|
| 223 | (model,iter) = treeselection.get_selected() |
|---|
| 224 | return model.get_value(iter,0) |
|---|
| 225 | except: |
|---|
| 226 | return None |
|---|
| 227 | |
|---|
| 228 | def update_option_display(self, widget): |
|---|
| 229 | """ |
|---|
| 230 | Update option display contents |
|---|
| 231 | """ |
|---|
| 232 | option = self.options.get_option(self.get_selected()) |
|---|
| 233 | self.optiondisplay.set_option_list(option) |
|---|
| 234 | self.optiondisplay.add_button.set_sensitive(False) |
|---|
| 235 | |
|---|
| 236 | |
|---|
| 237 | |
|---|
| 238 | def reload(self): |
|---|
| 239 | """ |
|---|
| 240 | Reload items of treeview |
|---|
| 241 | """ |
|---|
| 242 | |
|---|
| 243 | list = self.options.get_options_list() |
|---|
| 244 | for i in list: |
|---|
| 245 | myiter = self.__model.insert_before(None, None) |
|---|
| 246 | self.__model.set_value(myiter, 0, i) |
|---|
| 247 | |
|---|
| 248 | def add(self, option): |
|---|
| 249 | """ |
|---|
| 250 | Add a new option |
|---|
| 251 | """ |
|---|
| 252 | def remove(self, option): |
|---|
| 253 | """ |
|---|
| 254 | Remove current option |
|---|
| 255 | """ |
|---|
| 256 | def save(self, option): |
|---|
| 257 | """ |
|---|
| 258 | Save from option treeview to xml file |
|---|
| 259 | """ |
|---|
| 260 | |
|---|
| 261 | |
|---|
| 262 | if __name__ == "__main__": |
|---|
| 263 | o = OptionList() |
|---|
| 264 | |
|---|
| 265 | |
|---|