Changeset 789

Show
Ignore:
Timestamp:
06/12/07 04:45:14 (6 years ago)
Author:
ggpolo
Message:

fixes on new sample for timeline, added more retrieve methods in umitDB, changed umitInventory/viewer so it loads the new timeline sample and viewer also loads port and extraports data (this will change a lot, dont worry ;) )

Location:
branch/ggpolo
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • branch/ggpolo/umitDB/retrieve.py

    r767 r789  
    360360         
    361361        return fts 
     362     
     363     
     364    """ 
     365    Missing (c1) for port data retrieve: ostype in service_info. 
     366    Reason: NmapParser doesn't handle this yet. 
     367    """ 
     368     
     369    def get_portid_and_fks_for_host_from_db(self, host): 
     370        """ 
     371        Get portid and fks from port table, for a host. 
     372        """ 
     373        debug("Getting portid and foreign keys for host id %d from \ 
     374table port.." % host) 
     375         
     376        pdata = self.cursor.execute("SELECT portid, fk_service_info, \ 
     377                                    fk_protocol, fk_port_state FROM port \ 
     378                                    JOIN _host_port ON \ 
     379                                    (_host_port.fk_port=port.pk) \ 
     380                                    WHERE _host_port.fk_host=?", 
     381                                    (host, )).fetchall() 
     382         
     383        return pdata 
     384     
     385    def get_port_data_for_pdata_from_db(self, protocol_id, port_state_id, 
     386                                        service_info_id): 
     387        """ 
     388        Get port data based on data returned from 
     389        get_portid_and_fks_for_host_from_db 
     390        """ 
     391        debug("Getting port data for pdata..") 
     392         
     393        fullpdata = self.cursor.execute("SELECT protocol.name, \ 
     394                        port_state.state, service_info.product, \ 
     395                        service_info.version, service_info.extrainfo, \ 
     396                        service_info.method, service_info.conf, \ 
     397                        service_name.name FROM protocol, port_state, \ 
     398                        service_info, service_name WHERE protocol.pk = ? AND \ 
     399                        port_state.pk = ? AND service_info.pk = ? AND \ 
     400                        service_name.pk = service_info.fk_service_name", 
     401                        (protocol_id, port_state_id, service_info_id)).fetchall()[0] 
     402         
     403        return fullpdata 
     404     
     405    """ 
     406    End (c1) 
     407    """ 
     408     
     409    def get_extraports_data_for_host_from_db(self, host_id): 
     410        """ 
     411        Get extraport data for host id 
     412        """ 
     413        debug("Getting extraports data for host id %d" % host_id) 
     414         
     415        epdata = self.cursor.execute("SELECT extraports.count, \ 
     416                            port_state.state FROM extraports, port_state \ 
     417                            WHERE extraports.fk_host = ? AND \ 
     418                            port_state.pk = extraports.fk_port_state", 
     419                            (host_id, )).fetchall()[0] 
     420        return epdata 
    362421 
    363422 
  • branch/ggpolo/umitInventory/new-sample/new-sample-demo.py

    r785 r789  
    691691 
    692692        for btn in self.tlbox: 
    693             self.goodp.append((x, y - (btn.evts['good'] * 11.55))) 
    694             self.badp.append((x, y - (btn.evts['bad'] * 11.55))) 
    695             self.nonep.append((x, y - (btn.evts['none'] * 11.55))) 
    696             self.unknownp.append((x, y - (btn.evts['unknown'] * 11.55))) 
     693            self.goodp.append((x, y - (btn.evts['good'] * (end_y/9.0)) + 1)) 
     694            self.badp.append((x, y - (btn.evts['bad'] * (end_y/9.0)) + 1)) 
     695            self.nonep.append((x, y - (btn.evts['none'] * (end_y/9.0)) + 1)) 
     696            self.unknownp.append((x, y - (btn.evts['unknown'] * (end_y/9.0)) + 1)) 
    697697             
    698698            x += vdivs 
     
    716716        cr.rel_line_to(0, end_y + 10) 
    717717        cr.stroke() 
    718         cr.move_to(start_x - 10, start_y + end_y + 20) 
    719         cr.set_source_rgba(0, 0, 0, 0.6)  
    720         cr.show_text('Jan') 
     718        t = 'Jan' 
     719        x_bearing, y_bearing, width, height, x_advance, y_advance = cr.text_extents(t) 
     720        cr.move_to(start_x - width/2, start_y + end_y + 20) 
     721        cr.set_source_rgba(0, 0, 0, 0.6) 
     722        cr.show_text(t) 
    721723         
    722724        cr.set_source_rgb(0, 0, 0) 
     
    787789            cr.rel_line_to(0, 10) 
    788790            cr.stroke() 
    789             cr.move_to(start_v - 12, end_y + 30) 
    790             cr.show_text(months[h][:3]) 
     791            # need to correctly align this 
     792            t = months[h][:3] 
     793            x_bearing, y_bearing, width, height, x_advance, y_advance = cr.text_extents(t) 
     794            cr.move_to(start_v - width/2, end_y + 30) 
     795            cr.show_text(t) 
    791796             
    792797            start_v += vdivs 
     
    796801        if sel != -1: 
    797802            self.temp_level = 0 
    798             #self.painting_sel = True 
    799803            self.painting_sel = gobject.timeout_add(50, self._progressive_sel, sel, area) 
    800             #print self.painting_sel 
    801804            return True 
    802805        return False 
     
    10911094 
    10921095    def do_size_request(self, requisition): 
    1093         requisition.width = 10 
    1094         requisition.height = 10 
     1096        requisition.width = 360 
     1097        requisition.height = 90 
    10951098 
    10961099    def do_size_allocate(self, allocation): 
  • branch/ggpolo/umitInventory/viewer.py

    r777 r789  
    3636import umitInventory.tl as tl 
    3737 
     38from samplentl import samplentl_box 
     39 
    3840try: 
    3941    umitdb = Path.umitdb_ng 
     
    274276        self.add_accel_group(self.main_accel_group) 
    275277         
     278        self.viewernb = HIGNotebook() 
     279         
    276280        self.invdb = InventoryRetrieve(umitdb) 
    277281        self.invtree = InventoryTree(self) 
     
    281285        self.invnbpages_objects = [ ] 
    282286         
     287        self.newtl = samplentl_box() 
     288        self.newtl.show_all() 
     289         
     290        """ 
    283291        self.timeline = tl.main(testing_mode=True, zoom=3,  
    284292                                cell_border=False, border_on_focus=False, 
     
    290298        self.uparrow = tl.arrow(-3, self.timeline) # up arrow (zoom out) 
    291299        self.tl_dtitle = gtk.Label() # timeline title 
     300        """ 
    292301         
    293302        # statusbar 
     
    297306        
    298307        # tooltips 
     308        """ 
    299309        self.tooltips = gtk.Tooltips() 
    300310        self.tooltips.set_tip(self.tlyah, _("Timeline: You are here!")) 
     
    302312        self.tooltips.set_tip(self.rarrow, _("Go to the next date.")) 
    303313        self.tooltips.set_tip(self.timeline, _("TimeLine")) 
     314        """ 
    304315         
    305316        self._fill_tree() 
     
    307318        self.__set_props() 
    308319        self.__do_layout() 
    309  
     320        
    310321        self.connect('destroy', self._exit_ni) 
    311322        self.connect('inventory-activated', self._inventory_activated) 
    312         self.timeline.connect('date-change-notify', self._tl_date_changed) 
    313         self.timeline.connect('range-change-notify', self._tl_date_changed) 
    314         self.timeline.connect('scroll_event', self._tl_scroll_event) 
    315      
    316         self._tl_date_changed(None) 
    317          
     323        self.connect('realize', self.on_realize) 
     324        #self.timeline.connect('date-change-notify', self._tl_date_changed) 
     325        #self.timeline.connect('range-change-notify', self._tl_date_changed) 
     326        #self.timeline.connect('scroll_event', self._tl_scroll_event) 
     327     
     328        #self._tl_date_changed(None) 
     329         
     330    def on_realize(self, event): 
     331        self.viewernb.set_current_page(0) 
    318332     
    319333    def _tl_date_changed(self, event): 
     
    386400 
    387401 
     402    """ 
    388403    def _tl_view_legend(self, event): 
    389         """ 
    390         Show up TimeLine legend. 
    391         """ 
     404        #Show up TimeLine legend. 
    392405        dlg = LegendDlg(self.timeline) 
    393406        dlg.show_all() 
    394407         
    395408 
     409     
    396410    def _set_yahrange(self, min, max): 
    397         """ 
    398         Set new TimeLine year range. 
    399         """ 
     411        #Set new TimeLine year range. 
    400412        miny = min.year - 1  
    401413        maxy = max.year + 1 
     
    404416            self.timeline.year_range = (miny, maxy) 
    405417            self.timeline.emit('range-change-notify') 
     418    """ 
    406419     
    407420 
     
    532545        content = p.get_nth_page(p.get_n_pages() - 1) 
    533546             
    534         lstore = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING) 
    535                  
    536         # insert scan finish date and host status 
     547        lstore = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING, 
     548                               gobject.TYPE_STRING, gobject.TYPE_STRING) 
     549             
     550        # fill liststore 
    537551        host_count = 0 
    538552        for item in finish_data: 
    539553            iter = lstore.append() 
    540554            lstore.set(iter, 0, item[1]) 
    541                      
     555                 
     556            try:  
     557                base_hosts_data[host_count][0] 
     558            except:  
     559                lstore.set(iter, 1, "down") 
     560                continue 
     561             
    542562            if base_hosts_data[host_count][0] == item[0]: 
    543563                lstore.set(iter, 1, "up") 
     564                # get port data for this host 
     565                pdata = self.invdb.get_portid_and_fks_for_host_from_db(base_hosts_data[host_count][1]) 
     566                temp = "" 
     567                for pd in pdata: 
     568                    fpd = self.invdb.get_port_data_for_pdata_from_db(pd[2],  
     569                                                                     pd[3],  
     570                                                                     pd[1]) 
     571                    if len(pdata) > 1: 
     572                        temp += "Port No: %s, Data: %s\n" % (pd[0], fpd) 
     573                    else: 
     574                        temp += "Port No: %s, Data: %s" % (pd[0], fpd) 
     575                     
     576                lstore.set(iter, 2, temp) 
     577                 
     578                # get extraports data for this host 
     579                epdata = self.invdb.get_extraports_data_for_host_from_db(base_hosts_data[host_count][1]) 
     580                lstore.set(iter, 3, "Count: %d, State: %s" % (epdata[0], epdata[1])) 
     581                     
    544582                host_count += 1 
    545583            else: 
     
    558596        column = gtk.TreeViewColumn(_("Host status"),  
    559597                                    gtk.CellRendererText(), text=1) 
     598        treeview.append_column(column) 
     599         
     600        # column for host ports (this will be broken in several parts) 
     601        column = gtk.TreeViewColumn(_("Host ports"), 
     602                                    gtk.CellRendererText(), text=2) 
     603        treeview.append_column(column) 
     604         
     605        # column for host extraports (" ") 
     606        column = gtk.TreeViewColumn(_("Host extraports"), 
     607                                    gtk.CellRendererText(), text=3) 
    560608        treeview.append_column(column) 
    561609                 
     
    607655         
    608656        # Adjusts timeline range based on min and max timestamps from scans. 
    609         if timestamps: 
    610             self._set_yahrange(min(timestamps), max(timestamps)) 
     657        #if timestamps: 
     658        #    self._set_yahrange(min(timestamps), max(timestamps)) 
    611659     
    612660        self.invtree.treeview.expand_all() 
     
    632680            ("File", None, _("_File"), None), 
    633681            ("Edit", None, _("_Edit" ), None), 
    634             ("TimeLine", None, _("_Timeline"), None), 
     682            #("TimeLine", None, _("_Timeline"), None), 
    635683            ("ToolbarOpt", None, _("Tool_bar"), None), 
    636684            ("InvTabs", None, _("_Tabs"), None), 
     
    647695             
    648696            # Edit/Timeline 
    649             ("ViewLegend", None, _("View _Legend"), None, 
    650             _("Show up Legend for Timeline"), self._tl_view_legend), 
    651              
    652             ("ZoomIn", gtk.STOCK_ZOOM_IN, _("Zoom _In"), None, 
    653             _("Zoom In one level"), self._tl_zoom_in), 
    654              
    655             ( "ZoomOut", gtk.STOCK_ZOOM_OUT, _("Zoom _Out"), None, 
    656               _("Zoom Out one level"), self._tl_zoom_out), 
     697            #("ViewLegend", None, _("View _Legend"), None, 
     698            # _("Show up Legend for Timeline"), self._tl_view_legend), 
     699             
     700            #("ZoomIn", gtk.STOCK_ZOOM_IN, _("Zoom _In"), None, 
     701            # _("Zoom In one level"), self._tl_zoom_in), 
     702             
     703            #( "ZoomOut", gtk.STOCK_ZOOM_OUT, _("Zoom _Out"), None, 
     704            #  _("Zoom Out one level"), self._tl_zoom_out), 
    657705             
    658706            # Edit/ToolbarOpt 
     
    680728             self.write_tips), 
    681729            # Edit/Timeline 
    682             ("ShowTimeline", None, 
    683              _("Show _Timeline"), None, 
    684              _("Show/Hide Timeline"), 
    685              self._opt_timeline, 
    686              True), 
    687             ("ShowYAH", None, 
    688              _("Show \"You Are Here!\""), None, 
    689              _("Show/Hide \"You Are Here!\""), 
    690              self._opt_tlyah, 
    691              True), 
     730            #("ShowTimeline", None, 
     731            # _("Show _Timeline"), None, 
     732            # _("Show/Hide Timeline"), 
     733            # self._opt_timeline, 
     734            # True), 
     735            #("ShowYAH", None, 
     736            # _("Show \"You Are Here!\""), None, 
     737            # _("Show/Hide \"You Are Here!\""), 
     738            # self._opt_tlyah, 
     739            # True), 
     740     
    692741            # Edit/Notebooks 
    693742            ("TabCloseBtn", None, 
     
    731780            </toolbar> 
    732781            """ 
     782         
     783        default_ui = """ 
     784            <menubar> 
     785                <menu action='File'> 
     786                    <menuitem action='CloseHostTab' /> 
     787                    <menuitem action='CloseInvTab' /> 
     788                    <menuitem action='Quit' /> 
     789                </menu> 
     790                <menu action='Edit'> 
     791                    <menu action='ToolbarOpt'> 
     792                         <menuitem action='TBIcon' /> 
     793                         <menuitem action='TBText' /> 
     794                         <menuitem action='TBBoth' /> 
     795                    </menu> 
     796                    <menu action='InvTabs'> 
     797                         <menuitem action='TabCloseBtn' /> 
     798                    </menu> 
     799                    <menuitem action='ShowTips' /> 
     800                </menu> 
     801            </menubar> 
     802            """ 
    733803 
    734804        self.main_action_group.add_actions(main_actions) 
     
    756826        Set window properties. 
    757827        """ 
    758         self.set_title(_("UMIT Network Inventory 0.0.2.2")) 
     828        self.set_title(_("UMIT Network Inventory 0.0.2.3")) 
     829        # a size for testing 
     830        self.set_position(gtk.WIN_POS_CENTER) 
     831        width, height = gtk.gdk.get_default_root_window().get_size() 
     832        self.set_default_size((width*3)/4, (height*3)/4) 
    759833         
    760834 
     
    773847        main_vbox.pack_start(menubar, False, False, 0) 
    774848 
     849        """ 
    775850        toolbar = self.ui_manager.get_widget("/Toolbar") 
    776851        toolbar.set_style(gtk.TOOLBAR_ICONS) 
    777852        main_vbox.pack_start(toolbar, False, False, 0) 
     853        """ 
    778854 
    779855        left_pane_box = gtk.VBox() 
    780856        left_pane_box.pack_start(self.invtree, True, True, 0) 
    781857         
     858        """ 
    782859        self.yah_hb = gtk.HandleBox() 
    783860        self.yah_hb.add(self.tlyah) 
    784861        self.yah_hb.set_handle_position(gtk.POS_TOP) 
    785862        left_pane_box.pack_end(self.yah_hb, False, False, 0) 
     863        """ 
    786864         
    787865        main_hpaned.add1(left_pane_box) 
     
    789867 
    790868        # align left and right arrow with timeline height 
     869        """ 
    791870        tlbox2 = gtk.HBox() 
    792871        align = gtk.Alignment(0, 1, 0, 0.5) 
     
    803882         
    804883        tlbox.pack_start(tlbox2, True, True, 0) 
     884        """ 
    805885         
    806886        # place inventories notebook in a scrolledwindow 
     
    810890        nb_tl_hpaned.pack1(nbscroll, True, False) 
    811891        
    812         main_vbox.pack_start(self.tl_dtitle, False, False, 6) 
    813         main_vbox.pack_start(tlbox, False, False, 0) 
    814         main_vbox.pack_start(main_hpaned, True, True, 0) 
     892        #main_vbox.pack_start(self.tl_dtitle, False, False, 6) 
     893        #main_vbox.pack_start(tlbox, False, False, 0) 
     894 
     895        self.viewernb.append_page(main_hpaned, gtk.Label(_(" Historic "))) 
     896         
     897        self.viewernb.append_page(self.newtl, gtk.Label(_(" Timeline "))) 
     898 
     899        #main_vbox.pack_start(main_hpaned, True, True, 0) 
     900        main_vbox.pack_start(self.viewernb, True, True, 0) 
    815901        main_vbox.pack_end(self.statusbar, False, False, 0) 
    816902