Ticket #409: umitBTin_2.patch
| File umitBTin_2.patch, 44.8 kB (added by luis, 3 years ago) |
|---|
-
share/umit/config/scan_profile.usp
54 54 annotation = 55 55 command = nmap -PN -p80 --traceroute %s 56 56 options = Disable ping,Ports to scan,Traceroute 57 58 [umitbluetooth] 59 description = 60 hint = 61 options = Umit Bluetooth Scan 62 command = umitbluetooth 63 annotation =''' 64 -
umit/gui/MainWindow.py
38 38 39 39 from umit.gui.FileChoosers import ResultsFileChooserDialog 40 40 from umit.gui.FileChoosers import SaveResultsFileChooserDialog 41 from umit.gui.ScanNotebook import ScanNotebook, ScanNotebookPage 41 from umit.gui.ScanNotebook import ScanNotebook, ScanNotebookPage, ScanNotebookPageBT 42 42 from umit.gui.ProfileEditor import ProfileEditor 43 43 from umit.gui.ProfileManager import ProfileManager 44 44 from umit.gui.Wizard import Wizard … … 243 243 244 244 ('New Scan', 245 245 gtk.STOCK_NEW, 246 _('_New Scan'),246 _('_New nmap Scan'), 247 247 "<Control>T", 248 _('Create a new Scan Tab'),248 _('Create a new nmap Scan Tab'), 249 249 self._new_scan_cb), 250 250 251 251 ('Close Scan', … … 995 995 log.debug(">>> Permissions to access file? %s" % os.access(filename, 996 996 os.R_OK)) 997 997 998 base, ext = os.path.splitext(filename) 999 if ext==".ubt" : 1000 current_page.toolbar.profile_entry.set_selected_profile("umitbluetooth") 1001 #scan_page.scan_result = ScanNotebookPageBT() 1002 scan_page.scan_result.on_load(filename) 1003 return 998 1004 # Parse result 999 1005 f = open(filename) 1000 1006 scan_page.parse_result(f) … … 1040 1046 def _save_scan_results_cb(self, saving_page): 1041 1047 current_page = self.scan_notebook.get_nth_page(self.scan_notebook.\ 1042 1048 get_current_page()) 1049 if current_page.toolbar.selected_profile=="umitbluetooth": 1050 current_page.scan_result.on_save() 1043 1051 1044 1052 try: 1045 1053 status = current_page.status … … 1179 1187 # page.target_focus() 1180 1188 1181 1189 # return page 1182 1190 1183 1191 def _uie(self, p): 1184 1192 """ 1185 1193 Show Interface Editor -
umit/gui/ScanNotebook.py
43 43 from umit.core.NmapCommand import NmapCommand 44 44 from umit.core.UmitConf import CommandProfile, ProfileNotFound 45 45 from umit.core.NmapParser import NmapParser 46 from umit.core.umitbluetooth.ubt_parser import XMLDocument 47 from umit.core.umitbluetooth import btcore 46 48 from umit.core.Paths import Path 47 49 from umit.core.UmitLogging import log 48 50 from umit.core.I18N import _ … … 305 307 service.get('service_product', ''), 306 308 service.get('service_version', '')) 307 309 310 class ScanNotebookPageBT(HIGVBox): 311 __gsignals__ = { 312 'scan-finished' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()) 313 } 314 315 def __init__(self): 316 HIGVBox.__init__(self) 317 # The borders are consuming too much space on Maemo. Setting it to 318 # 0 pixels while on Maemo 319 if is_maemo(): 320 self.set_border_width(0) 321 322 self.set_spacing(0) 323 self.status = PageStatus() 324 self.status.set_empty() 325 326 self.changes = False 327 self.comments = {} 328 self.hosts = {} 329 self.services = {} 330 331 self.parsed = XMLDocument()#XXX file to be included for this ubt_parser.py 332 self.vpaned = gtk.VPaned() 333 334 self.__create_topbar() 335 self.__create_BT_MAP() 336 self.__create_SDPview() 337 self.__create_statusbar() 338 339 self.saved = False 340 self.saved_filename = '' 341 342 self._pack_expand_fill(self.vpaned) 343 self._pack_expand_fill(self.status_bar) 344 345 PluginEngine().core.emit('ScanNotebookPage-created', self) 346 347 def __create_topbar(self): 348 hbox1 = gtk.HBox() 349 #Progressbar 350 self.progb = gtk.ProgressBar() 351 self.progb.set_text("") 352 self.progb.set_fraction(0) 353 hbox1.pack_end(self.progb, False, False, 5) 354 355 #Button 356 self.scanbutton = gtk.Button("Probe Devices") 357 self.scanbutton.connect("clicked", self.enter_cb) 358 hbox1.pack_end(self.scanbutton, False, False, 0) 359 360 #toggle button 361 self.sdp_borwsing= gtk.ToggleButton(label="SDP Browsing", use_underline=False) 362 self.sdp_borwsing.connect("toggled", self.sdp_cb) 363 364 hbox1.pack_end(self.sdp_borwsing, False, False, 0) 365 self._pack_noexpand_nofill(hbox1) 366 367 def __create_BT_MAP(self): 368 369 # BT Map 370 self.scrolled_map = gtk.ScrolledWindow() 371 self.scrolled_map.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) 372 self.mapmodel = gtk.ListStore(str, gtk.gdk.Pixbuf) 373 self.btmap = gtk.IconView(self.mapmodel) 374 self.btmap.connect("item-activated", self.iconclick_cb) 375 self.btmap.set_text_column(0) 376 self.btmap.set_pixbuf_column(1) 377 self.scrolled_map.add(self.btmap) 378 self.vpaned.pack1(self.scrolled_map, True, True) 379 380 def __create_SDPview(self): 381 hbox2 = gtk.HBox() 382 # Labels 383 self.label = gtk.Label("Device Details\t\t\t\t\n\nName: " + "\nMAC: " + "\nManufacturer: ") 384 self.label.set_selectable(True) 385 self.label.set_alignment(0.4,0) 386 hbox2.pack_start(self.label, False) 387 388 # SDP View 389 self.scrolled_info = gtk.ScrolledWindow() 390 self.scrolled_info.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) 391 self.sdpview = gtk.TextView() 392 self.sdpview.set_editable(False) 393 self.sdpview.get_buffer().set_text("SDP Info\n\nNote: Option Disabled by Default. To enable SDP, select the SDP option under the Preference tab.") 394 self.scrolled_info.add(self.sdpview) 395 hbox2.pack_start(self.scrolled_info, True) 396 self.vpaned.pack2(hbox2, True, True) 397 398 def __create_statusbar(self): 399 # Statusbar 400 self.status_bar = gtk.Statusbar() 401 self.context_id = self.status_bar.get_context_id("Scan Status") 402 message_id = self.status_bar.push(self.context_id, "Idle") 403 self.status_bar.set_has_resize_grip(True) 404 405 def enter_cb(self, widget): 406 btcore.btcore().scan(self) 407 408 def iconclick_cb(self, path, action): 409 iter = self.btmap.get_cursor() 410 buffer = str(iter[0])[:2].replace("(","") 411 btid = int(buffer) 412 print "Clicked Icon: "+ str(buffer) 413 btcore.btcore().set_info(self, btid) 414 #outputs the location of the icon numerically 415 416 def sdp_cb(self, action): 417 # action has not toggled yet 418 text = ('Enabled', 'Disabled')[self.sdp_borwsing.get_active()==False] 419 message_id = self.status_bar.push(self.context_id, "SDP Browsing is %s"%text) 420 btcore.btcore().set_sdp(text) 421 return 422 423 def on_load(self, filename): 424 btcore.btcore().load_scan(self, filename) 425 426 def on_save(self): 427 btcore.btcore().save_scan(self) 428 429 ############################################################################################################################ 308 430 class ScanNotebookPage(HIGVBox): 309 431 __gsignals__ = { 310 432 'scan-finished' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()) … … 489 611 #log.debug(">>> Refresh Command") 490 612 profile = self.toolbar.selected_profile 491 613 target = self.toolbar.selected_target.strip() 492 614 493 615 #log.debug(">>> Profile: %s" % profile) 494 616 #log.debug(">>> Target: %s" % target) 495 496 try: 497 cmd_profile = CommandProfile() 498 command = cmd_profile.get_command(profile) % target 499 del(cmd_profile) 500 501 # scan button must be enable if -iR or -iL options are passed 502 if command.find('-iR') != -1 or command.find('-iL') != -1: 503 self.toolbar.scan_button.set_sensitive(True) 617 if profile == "umitbluetooth": 618 self.scan_result = ScanNotebookPageBT() 619 self.remove(self.get_children()[1]) 620 self.command_toolbar.command="umitbluetooth" 621 self.command_toolbar.set_sensitive(False) 622 self.toolbar.target_entry.set_sensitive(False) 623 self.toolbar.scan_button.set_sensitive(False) 624 self._pack_expand_fill(self.scan_result) 625 self.show_all() 626 else: 627 self.scan_result = ScanResult() 628 self.remove(self.get_children()[1]) 629 self.command_toolbar.set_sensitive(True) 630 self.toolbar.target_entry.set_sensitive(True) 631 self._pack_expand_fill(self.scan_result) 632 self.show_all() 633 try: 634 cmd_profile = CommandProfile() 635 command = cmd_profile.get_command(profile) % target 636 del(cmd_profile) 637 638 # scan button must be enable if -iR or -iL options are passed 639 if command.find('-iR') != -1 or command.find('-iL') != -1: 640 self.toolbar.scan_button.set_sensitive(True) 504 641 505 # For these nmap options, target is unecessary.506 # Removes unnecessary target from the command507 command = command.replace(target,'').strip()508 elif target:509 self.toolbar.scan_button.set_sensitive(True)510 else:511 self.toolbar.scan_button.set_sensitive(False)642 # For these nmap options, target is unecessary. 643 # Removes unnecessary target from the command 644 command = command.replace(target,'').strip() 645 elif target: 646 self.toolbar.scan_button.set_sensitive(True) 647 else: 648 self.toolbar.scan_button.set_sensitive(False) 512 649 513 self.command_toolbar.command = command514 except ProfileNotFound:515 pass516 #self.profile_not_found_dialog()517 except TypeError:518 pass # That means that the command string convertion "%" didn't work650 self.command_toolbar.command = command 651 except ProfileNotFound: 652 pass 653 #self.profile_not_found_dialog() 654 except TypeError: 655 pass # That means that the command string convertion "%" didn't work 519 656 520 657 def profile_not_found_dialog(self): 521 658 warn_dialog = HIGAlertDialog(message_format=_("Profile not found!"), … … 749 886 """Called when scan is done. Verify if any host were found.""" 750 887 log.debug(">>> XML output file that is going to be " 751 888 "parsed: %s" % file_to_parse) 752 889 753 890 # All hosts details pages 754 891 self.host_pages = [] 755 892 self.changes = True -
umit/gui/FileChoosers.py
40 40 self.add_pattern(pattern) 41 41 self.set_name(_("Umit Scan Profile (%s)") % pattern) 42 42 43 class ResultUmitBluetooth(gtk.FileFilter): 44 def __init__(self): 45 gtk.FileFilter.__init__(self) 46 47 pattern = "*.ubt" 48 self.add_pattern(pattern) 49 self.set_name(_("Umit bluetooth (%s)") % pattern) 50 43 51 class ResultsFileFilter(gtk.FileFilter): 44 52 def __init__(self): 45 53 gtk.FileFilter.__init__(self) … … 96 104 gtk.FileChooserDialog.__init__(self, title, parent, 97 105 action, buttons) 98 106 99 for f in (ResultsFileFilter(), AllFilesFileFilter()):107 for f in (ResultsFileFilter(), ResultUmitBluetooth(), AllFilesFileFilter()): 100 108 self.add_filter(f) 101 109 102 110 class SaveResultsFileChooserDialog(gtk.FileChooserDialog): -
umit/core/umitbluetooth/about.py
1 #!/usr/bin/env python 2 # Copyright (C) 2008 Adriano Monteiro Marques. 3 # 4 # Author: Devtar Singh <devtar@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 pygtk 21 pygtk.require('2.0') 22 import gtk 23 import os 24 25 import path 26 27 class about_dialog: 28 29 def __init__(self): 30 self.about = gtk.AboutDialog() 31 self.about.set_title("About Umit Bluetooth") 32 self.about.set_position(gtk.WIN_POS_CENTER) 33 self.about.set_name("Umit Bluetooth") 34 self.about.set_version("0.8") 35 self.about.set_authors(["Devtar Singh <devtar@gmail.com>"]) 36 self.about.set_website("umitbt.umitproject.org") 37 umit_logo = gtk.gdk.pixbuf_new_from_file(os.path.abspath(os.path.join(path.paths, "UmitBT", "share", "icons", "umit_16.ico"))) 38 self.about.set_icon(umit_logo) 39 self.about.set_copyright("License: GNU GPL") 40 self.about.set_license("This program is free software; you can redistribute it\n" + 41 "and/or modify it under the terms of the\n" + 42 "GNU General Public License as published by\n" + 43 "the Free Software Foundation; either version 2 of \n" + 44 "the License, or (at your option) any later version.\n\n" + 45 "This program is distributed in the hope that it will\n" + 46 "be useful, but WITHOUT ANY WARRANTY;\n" + 47 "without even the implied warranty of\n" + 48 "MERCHANTABILITY or FITNESS FOR A PARTICULAR\n" + 49 "PURPOSE. See the GNU General Public License for more details.\n\n" + 50 "You should have received a copy of the \n" + 51 "GNU General Public License\n" + 52 "along with this program; if not, write to the: \n" 53 "Free Software\n" + 54 "Foundation, Inc.,\n" + 55 "59 Temple Place, \n"+ 56 "Suite 330, Boston,\n" + 57 "MA 02111-1307 USA") 58 self.about.set_wrap_license(True) 59 self.hide_about() 60 self.about.connect('response', self.on_close) 61 62 def get_about(self): 63 print "get about" 64 self.about.show() 65 66 def hide_about(self): 67 print "hide about" 68 self.about.hide() 69 70 def on_close(self, dialog, response): 71 self.about.hide() 72 73 -
umit/core/umitbluetooth/path.py
1 #!/usr/bin/env python 2 # Copyright (C) 2008 Adriano Monteiro Marques. 3 # 4 # Author: Devtar Singh <devtar@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 platform 21 22 PLATFORM = platform.system() 23 paths = "" 24 25 if(PLATFORM=="Linux"): 26 paths = "/usr" 27 elif(PLATFORM=="Darwin"): 28 paths = "/System/Library/Frameworks/Python.framework/Versions/Current/" -
umit/core/umitbluetooth/btcore.py
1 #!/usr/bin/env python 2 # Copyright (C) 2008 Adriano Monteiro Marques. 3 # 4 # Author: Devtar Singh <devtar@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 platform 21 import os 22 import sys 23 24 import pygtk 25 pygtk.require('2.0') 26 import gtk 27 28 if(platform.system()=="Darwin"): 29 try: 30 import lightblue 31 except ImportError: 32 print >> sys.stderr, "Error loading LightBlue dependency.Exiting UmitBT..." 33 raise 34 else: 35 try: 36 import bluetooth 37 except ImportError: 38 print >> sys.stderr, "Error loading PyBluez dependency. Exiting UmitBT..." 39 raise 40 41 #from umitCore.I18N import _ 42 from higwidgets.higdialogs import HIGDialog, HIGAlertDialog 43 44 import io 45 import path 46 47 # globals used due to functions such as set_info and ease of access in io.py. needs redesigning 48 btname = [""] 49 btmac = [""] 50 btmanu = [""] 51 btmanumac = [""] 52 btmanuname = [""] 53 btsdp = [""] 54 sdpstatus = "" 55 56 class btcore: 57 58 def __init__(self): 59 global btname 60 global btmac 61 global btmanu 62 global btmanumac 63 global btmanuname 64 global btsdp 65 global sdpstatus 66 67 def scan(self, ScanNotebookPageBT): 68 print "Refresh ScanNotebookPageBT and Clear Cache" 69 self.clear(ScanNotebookPageBT) 70 global btname 71 global btmac 72 global btsdp 73 global sdpstatus 74 count = 1 75 # Use Lightblue backend on OSX 76 if(platform.system()=="Darwin"): 77 try: 78 btdevices = lightblue.finddevices(getnames=True, length=10) 79 for btfield in btdevices: 80 if(btfield[1] == ""): 81 btfield[1] = "N/A" 82 #encode btname to utf-8 83 try: 84 btfield[1].encode("utf-8") 85 except: 86 btfiled[1] = "N/A" 87 btname.append(btfield[1]) 88 btmac.append(btfield[0]) 89 if (sdpstatus == "Enabled" and (len(btname) > 1)): 90 self.sdp_scan(count) 91 else: 92 btsdp.append({"name":"SDP Disabled"}) 93 count+=1 94 except: 95 dlg = HIGAlertDialog(type=gtk.MESSAGE_ERROR, 96 message_format=('Scan Process'), 97 secondary_text=("One or more Bluetooth devices could not be found")) 98 dlg.run() 99 dlg.destroy() 100 return 101 # Use PyBluez on Win32 or Linux 102 else: 103 try: 104 btdevices = bluetooth.discover_devices(flush_cache = True, lookup_names = True) 105 # first entry of btdevice is at index 1 106 for addr, name in btdevices: 107 if (name == ""): 108 name = "N/A" 109 #encode btname to utf-8 110 try: 111 name.encode("utf-8") 112 except: 113 name = "N/A" 114 btname.append(name) 115 btmac.append(addr) 116 if (sdpstatus == "Enabled" and (len(btname) > 1)): 117 self.sdp_scan(count) 118 else: 119 btsdp.append({"name":"SDP Disabled"}) 120 count+=1 121 except: 122 dlg = HIGAlertDialog(type=gtk.MESSAGE_ERROR, 123 message_format=('Scan Process'), 124 secondary_text=("One or more Bluetooth devices could not be found")) 125 dlg.run() 126 dlg.destroy() 127 return 128 129 ScanNotebookPageBT.progb.set_text("40%") 130 ScanNotebookPageBT.progb.set_fraction(.4) 131 self.manufac() 132 ScanNotebookPageBT.progb.set_text("75%") 133 ScanNotebookPageBT.progb.set_fraction(.75) 134 self.map(ScanNotebookPageBT) 135 ScanNotebookPageBT.progb.set_text("100%") 136 ScanNotebookPageBT.progb.set_fraction(1) 137 message_id = ScanNotebookPageBT.status_bar.push(ScanNotebookPageBT.context_id, "Scanning Completed") 138 139 def sdp_scan(self, btid): 140 global btmac 141 global btsdp 142 print "BTID: " + str(btid) + "\n" + btmac[btid] 143 if(platform.system()=="Darwin"): 144 # Lightblue Output: [('00:0D:93:19:C8:68', 10, 'OBEX Object Push')]. Yet to be tested. 145 sdpservices = lightblue.findservices(address=btmac[btid]) 146 else: 147 sdpservices = bluetooth.find_service(address=btmac[btid]) 148 btsdp.append(sdpservices) 149 150 def load_db(self): 151 global btmanumac 152 global btmanuname 153 count = 0 154 if(os.path.exists(os.path.join(path.paths, "UmitBT", "config", "db", "btdb.db"))): 155 print "load database" 156 btdb_dir = os.path.abspath(os.path.join(path.paths, "UmitBT", "config", "db", "btdb.db")) 157 btdb = open(btdb_dir, "rb") 158 for line in btdb: 159 count+=1 160 btbuf1, btbuf2 = line.split(";") 161 btmanumac.append(btbuf1) 162 btmanuname.append(btbuf2) 163 btdb.close() 164 else: 165 print "ERROR: Can't open btdb!" 166 dlg = HIGAlertDialog(None, message_format=('I/O Error'), secondary_text=("Cant open btdb.db")) 167 dlg.run() 168 dlg.destroy() 169 170 def manufac(self): 171 global btname 172 global btmac 173 global btmanu 174 global btmacsearch 175 global btnamesearch 176 print "manufacturer detection" 177 print btmac[1] 178 count = 1 179 # Load btdb 180 self.load_db() 181 print "Len : " + str(len(btname)) 182 while ((len(btname)) > count): 183 print "Count"+str(count) 184 if(btmanumac.count(btmac[count][:8]) > 0): 185 manuindex = btmanumac.index(btmac[count][:8]) 186 btmanuname[manuindex] = btmanuname[manuindex].replace("\n", "") 187 btmanu.append(btmanuname[manuindex]) 188 else: 189 print "Null: " + btmac[count][:8] 190 btmanu.append("null") 191 count+= 1 192 193 def map(self, ScanNotebookPageBT): 194 global btname 195 global btmac 196 global btmanu 197 count = 1 198 while ((len(btname)) > count): 199 if(btmanu[count].find("Apple") > -1 and btmanu[count].find("Applera") == -1): 200 pixbuf = gtk.gdk.pixbuf_new_from_file(os.path.abspath(os.path.join(path.paths, "UmitBT", "share", "pixmaps", "apple.png"))) 201 ScanNotebookPageBT.mapmodel.append([btname[count], pixbuf]) 202 elif(btmanu[count].find("Google") > -1 ): 203 pixbuf = gtk.gdk.pixbuf_new_from_file(os.path.abspath(os.path.join(path.paths, "UmitBT", "share", "pixmaps", "google.png"))) 204 ScanNotebookPageBT.mapmodel.append([btname[count], pixbuf]) 205 elif(btmanu[count].find("Nokia") > -1 ): 206 pixbuf = gtk.gdk.pixbuf_new_from_file(os.path.abspath(os.path.join(path.paths, "UmitBT", "share", "pixmaps", "nokia.png"))) 207 ScanNotebookPageBT.mapmodel.append([btname[count], pixbuf]) 208 elif(btmanu[count].find("Microsoft") > -1 or btmanu[count].find("MICROSOFT") > -1): 209 pixbuf = gtk.gdk.pixbuf_new_from_file(os.path.abspath(os.path.join(path.paths, "UmitBT", "share", "pixmaps", "microsoft.png"))) 210 ScanNotebookPageBT.mapmodel.append([btname[count], pixbuf]) 211 elif(btmanu[count].find("Motorola") > -1): 212 pixbuf = gtk.gdk.pixbuf_new_from_file(os.path.abspath(os.path.join(path.paths, "UmitBT", "share", "pixmaps", "moto.png"))) 213 ScanNotebookPageBT.mapmodel.append([btname[count], pixbuf]) 214 elif(btmanu[count].find("INTEL CORPORATION") > -1): 215 pixbuf = gtk.gdk.pixbuf_new_from_file(os.path.abspath(os.path.join(path.paths, "UmitBT", "share", "pixmaps", "intel.png"))) 216 ScanNotebookPageBT.mapmodel.append([btname[count], pixbuf]) 217 elif(btmanu[count].find("Cisco") > -1 ): 218 pixbuf = gtk.gdk.pixbuf_new_from_file(os.path.abspath(os.path.join(path.paths, "UmitBT", "share", "pixmaps", "cisco.png"))) 219 ScanNotebookPageBT.mapmodel.append([btname[count], pixbuf]) 220 elif(btmanu[count].find("LG Electronics") > -1 ): 221 pixbuf = gtk.gdk.pixbuf_new_from_file(os.path.abspath(os.path.join(path.paths, "UmitBT", "share", "pixmaps", "lg.png"))) 222 ScanNotebookPageBT.mapmodel.append([btname[count], pixbuf]) 223 elif(btmanu[count].find("Dell") > -1 ): 224 pixbuf = gtk.gdk.pixbuf_new_from_file(os.path.abspath(os.path.join(path.paths, "UmitBT", "share", "pixmaps", "dell.png"))) 225 ScanNotebookPageBT.mapmodel.append([btname[count], pixbuf]) 226 elif(btmanu[count].find("D-Link") > -1 ): 227 pixbuf = gtk.gdk.pixbuf_new_from_file(os.path.abspath(os.path.join(path.paths, "UmitBT", "share", "pixmaps", "dlink.png"))) 228 ScanNotebookPageBT.mapmodel.append([btname[count], pixbuf]) 229 elif(btmanu[count].find("DoCoMo") > -1 ): 230 pixbuf = gtk.gdk.pixbuf_new_from_file(os.path.abspath(os.path.join(path.paths, "UmitBT", "share", "pixmaps", "docomo.png"))) 231 ScanNotebookPageBT.mapmodel.append([btname[count], pixbuf]) 232 elif(btmanu[count].find("Samsung") > -1): 233 pixbuf = gtk.gdk.pixbuf_new_from_file(os.path.abspath(os.path.join(path.paths, "UmitBT", "share", "pixmaps", "samsung.png"))) 234 ScanNotebookPageBT.mapmodel.append([btname[count], pixbuf]) 235 #Filter Sony Erricson, Sony Computer Entertainment, then Sony Microsoft 236 elif(btmanu[count].find("Sony Ericsson") > -1): 237 pixbuf = gtk.gdk.pixbuf_new_from_file(os.path.abspath(os.path.join(path.paths, "UmitBT", "share", "pixmaps", "sony-eric.png"))) 238 ScanNotebookPageBT.mapmodel.append([btname[count], pixbuf]) 239 elif(btmanu[count].find("Sony Computer Entertainment") > -1): 240 pixbuf = gtk.gdk.pixbuf_new_from_file(os.path.abspath(os.path.join(path.paths, "UmitBT", "share", "pixmaps", "sony-play.png"))) 241 ScanNotebookPageBT.mapmodel.append([btname[count], pixbuf]) 242 elif(btmanu[count].find("Sony") > -1): 243 pixbuf = gtk.gdk.pixbuf_new_from_file(os.path.abspath(os.path.join(path.paths, "UmitBT", "share", "pixmaps", "sony.png"))) 244 ScanNotebookPageBT.mapmodel.append([btname[count], pixbuf]) 245 elif(btmanu[count].find("Blaupunkt") > -1 ): 246 pixbuf = gtk.gdk.pixbuf_new_from_file(os.path.abspath(os.path.join(path.paths, "UmitBT", "share", "pixmaps", "blaupunkt.png"))) 247 ScanNotebookPageBT.mapmodel.append([btname[count], pixbuf]) 248 else: 249 pixbuf = gtk.gdk.pixbuf_new_from_file(os.path.abspath(os.path.join(path.paths, "UmitBT", "share", "pixmaps", "bt.png"))) 250 ScanNotebookPageBT.mapmodel.append([btname[count], pixbuf]) 251 count+=1 252 253 def set_info(self, ScanNotebookPageBT, btid): 254 global btname 255 global btmac 256 global btmanu 257 global btsdp 258 global sdpstatus 259 sdpbrowseinfo = "" 260 btid+=1 261 print "Selected: " + str(ScanNotebookPageBT.btmap.get_selected_items()) + "\n" + str(btid) 262 ScanNotebookPageBT.label.set_text("Device Details\t\t\t\t\n\nName: " + btname[btid] + "\nMAC: " + btmac[btid] + "\nManufacturer: " + btmanu[btid]) 263 print "Status_select: " + sdpstatus 264 print "Found " + str(len(btsdp[btid])) + " Services" 265 if (sdpstatus == "Enabled"): 266 if (len(btsdp[btid]) < 1): 267 ScanNotebookPageBT.sdpview.get_buffer().set_text("no services found") 268 return 269 sdpbrowseinfo = "\nFound " + str(len(btsdp[btid])) + " Services" 270 for svc in btsdp[btid]: 271 try: 272 if(str(svc["name"])=="no services found" or str(svc["name"])== ""): 273 ScanNotebookPageBT.sdpview.get_buffer().set_text("no services found") 274 else: 275 try: 276 sdpbrowseinfo += "\n\nService Name: " + str(svc["name"]) + "\n Description: " + str(svc["description"]) 277 sdpbrowseinfo += "\n Provided By: " + str(svc["provider"]) + "\n Protocol: " + str(svc["protocol"]) 278 sdpbrowseinfo += "\n channel/PSM: " + str(svc["port"]) + "\n svc classes: " + str(svc["service-classes"]) 279 sdpbrowseinfo += "\n profiles: " + str(svc["profiles"]) + "\n service id: " + str(svc["service-id"]) 280 ScanNotebookPageBT.sdpview.get_buffer().set_text(sdpbrowseinfo) 281 except: 282 ScanNotebookPageBT.sdpview.get_buffer().set_text("N/A") 283 dlg = HIGAlertDialog(None, message_format=('Error'), secondary_text=("An error occurred while parsing SDP data")) 284 dlg.run() 285 dlg.destroy() 286 except: 287 ScanNotebookPageBT.sdpview.get_buffer().set_text("no services found") 288 289 def set_sdp(self, status): 290 # Status of Enabled or Disabled 291 global sdpstatus 292 sdpstatus = status 293 294 def clear(self, ScanNotebookPageBT): 295 global btname 296 global btmac 297 global btmanu 298 global btsdp 299 300 btname = [""] 301 btmac = [""] 302 btmanu = [""] 303 btsdp = [""] 304 ScanNotebookPageBT.progb.set_text("") 305 ScanNotebookPageBT.progb.set_fraction(0) 306 ScanNotebookPageBT.mapmodel.clear() 307 308 def save_scan(self, ScanNotebookPageBT): 309 io.io().save() 310 ScanNotebookPageBT.progb.set_text("100%") 311 ScanNotebookPageBT.progb.set_fraction(1) 312 message_id = ScanNotebookPageBT.status_bar.push(ScanNotebookPageBT.context_id, "File Saved") 313 314 def load_scan(self, ScanNotebookPageBT, filename): 315 #clear previous entries before loading *ubt 316 self.clear(ScanNotebookPageBT) 317 status = io.io().load(filename) 318 if(str(status)!="None"): 319 ScanNotebookPageBT.progb.set_text("0%") 320 ScanNotebookPageBT.progb.set_fraction(0) 321 message_id = ScanNotebookPageBT.status_bar.push(ScanNotebookPageBT.context_id, "File Load Error Encountered") 322 return 323 self.map(ScanNotebookPageBT) 324 ScanNotebookPageBT.progb.set_text("100%") 325 ScanNotebookPageBT.progb.set_fraction(1) 326 message_id = ScanNotebookPageBT.status_bar.push(ScanNotebookPageBT.context_id, "File Loaded") -
umit/core/umitbluetooth/__init__.py
1 #!/usr/bin/env python 2 # Copyright (C) 2008 Adriano Monteiro Marques. 3 # 4 # Author: Devtar Singh <devtar@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 __author__ = "Devtar Singh <devtar@gmail.com>" 21 __date__ = "1 September 2008" 22 __version__ = "0.7RC2" -
umit/core/umitbluetooth/ubt_parser.py
1 #!/usr/bin/env python 2 # Copyright (C) 2008 Adriano Monteiro Marques. 3 # 4 # Author: Devtar Singh <devtar@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 from xml.dom import minidom 21 from xml.dom.minidom import Document, parse, parseString 22 from types import StringType, UnicodeType 23 import string 24 25 enc = "utf-8" 26 27 def _encode(v): 28 if isinstance(v, UnicodeType): 29 v = v.encode(enc) 30 return v 31 32 class XMLElement: 33 34 def __init__(self, doc, el): 35 self.doc = doc 36 self.el = el 37 38 def __getitem__(self, name): 39 a = self.el.getAttributeNode(name) 40 if a: 41 return _encode(a.value) 42 return None 43 44 def __setitem__(self, name, value): 45 self.el.setAttribute(name, _encode(value)) 46 47 def __delitem__(self, name): 48 self.el.removeAttribute(name) 49 50 def __str__(self): 51 return _encode(self.doc.toprettyxml()) 52 53 def toString(self): 54 return _encode(self.doc.toxml()) 55 56 def _inst(self, el): 57 return XMLElement(self.doc, el) 58 59 def get(self, name, default=None): 60 a = self.el.getAttributeNode(name) 61 if a: 62 return _encode(a.value) 63 return _encode(default) 64 65 def add(self, tag, **kwargs): 66 el = self.doc.createElement(tag) 67 for k, v in kwargs.items(): 68 el.setAttribute(k, _encode(str(v))) 69 return self._inst(self.el.appendChild(el)) 70 71 def addText(self, data): 72 return self._inst( 73 self.el.appendChild( 74 self.doc.createTextNode(_encode(data)))) 75 76 def addComment(self, data): 77 return self._inst( 78 self.el.appendChild( 79 self.doc.createComment(data))) 80 81 def getText(self, sep=" "): 82 rc = [] 83 for node in self.el.childNodes: 84 if node.nodeType == node.TEXT_NODE: 85 rc.append(node.data) 86 return _encode(string.join(rc, sep)) 87 88 def getAll(self, tag): 89 return map(self._inst, self.el.getElementsByTagName(tag)) 90 91 class _Document(Document): 92 93 def writexml(self, writer, indent="", addindent="", newl=""): 94 for node in self.childNodes: 95 node.writexml(writer, indent, addindent, newl, _encode) 96 97 98 class XMLDocument(XMLElement): 99 100 def __init__(self, tag=None, **kwargs): 101 self.doc = Document() 102 XMLElement.__init__(self, self.doc, self.doc) 103 if tag: 104 self.el = self.add(tag, **kwargs).el 105 106 def parse(self, d): 107 self.doc = self.el = parse(d) 108 return self 109 110 def parseString(self, d): 111 self.doc = self.el = parseString(_encode(d)) 112 return self 113 ubt_Parser = XMLDocument -
umit/core/umitbluetooth/io.py
1 #!/usr/bin/env python 2 # Copyright (C) 2008 Adriano Monteiro Marques. 3 # 4 # Author: Devtar Singh <devtar@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 os 21 import string 22 import sys 23 24 import pygtk 25 pygtk.require('2.0') 26 import gtk 27 28 from higwidgets.higdialogs import HIGAlertDialog 29 30 import btcore 31 import ubt_parser 32 33 34 class io: 35 36 def __init__(self): 37 self.count = 0 38 39 def save(self): 40 print "save ubt" 41 count = self.count 42 save_file = self.file_browse(gtk.FILE_CHOOSER_ACTION_SAVE) 43 if (save_file == None): 44 print "error creating file to save" 45 save_file, extension = os.path.splitext(save_file) 46 save_file = save_file + ".ubt" 47 string = "" 48 doc = ubt_parser.XMLDocument("UmitBT", version="2.0") 49 while (len(btcore.btname)-1) > count: 50 count += 1 51 table = doc.add("table", name="device"+str(count)) 52 table.add("device"+str(count), name="BTname", value=btcore.btname[count]) 53 table.add("device"+str(count), name="BTmac", value=btcore.btmac[count]) 54 table.add("device"+str(count), name="BTmanu", value=btcore.btmanu[count]) 55 print "LEN : " + str(len(btcore.btsdp)) 56 if len(btcore.btsdp[count]) > 2: 57 for svc in btcore.btsdp[count]: 58 table.add("device"+str(count), name="BTsdpname", value=str(svc["name"])) 59 table.add("device"+str(count), name="BTsdpdesc", value=str(svc["description"])) 60 table.add("device"+str(count), name="BTsdpprov", value=str(svc["provider"])) 61 table.add("device"+str(count), name="BTsdpproto", value=str(svc["protocol"])) 62 table.add("device"+str(count), name="BTsdppsm", value=str(svc["port"])) 63 table.add("device"+str(count), name="BTsdpclass", value=str(svc["service-classes"])) 64 table.add("device"+str(count), name="BTsdpprof", value=str(svc["profiles"])) 65 table.add("device"+str(count), name="BTsdpservid", value=str(svc["service-id"])) 66 else: 67 table.add("device"+str(count), name="BTsdpname", value="no services found") 68 string = doc 69 outfile = open (save_file, "w") 70 outfile.write(string.doc.toprettyxml(" ")) 71 outfile.close() 72 print "UBT file saved" 73 74 def load(self, filename): 75 try: 76 load_file = filename#self.file_browse(gtk.FILE_CHOOSER_ACTION_OPEN)#TODO give load file from during function al 77 inFile = open(load_file, "rb") 78 buffer, extension = os.path.splitext(load_file) 79 except: 80 dlg = HIGAlertDialog(None, message_format=('I/O Error'), secondary_text=("Cant open UmitBT file")) 81 dlg.run() 82 dlg.destroy() 83 print sys.exc_info()[0] 84 return sys.exc_info()[0] 85 print "clear memory then load ubt file" 86 self.clear_buffer() 87 count = self.count 88 print "OPEN FILENAME : " + load_file 89 if(load_file and extension == ".ubt"): 90 xml_load = inFile.read() 91 ndoc = ubt_parser.XMLDocument() 92 ndoc.parseString(str(xml_load)) 93 root = ndoc.getAll("UmitBT") 94 if root: 95 db = root[0] 96 print "Database:", db["ubt"] 97 for table in db.getAll("table"): 98 print "Table:", table["name"] 99 count+=1 100 svc = {} 101 for field in db.getAll("device"+str(count)): 102 print "Field:", field["name"], "- Type:", field["value"] 103 if(field["value"]==""): 104 field["value"]=="-" 105 if(field["name"] == "BTname"): 106 btcore.btname.append(field["value"]) 107 elif(field["name"] == "BTmac"): 108 btcore.btmac.append(field["value"]) 109 elif(field["name"] == "BTmanu"): 110 btcore.btmanu.append(field["value"]) 111 elif(field["name"] == "BTsdpname"): 112 svc["name"] = str(field["value"]) 113 elif(field["name"] == "BTsdpdesc"): 114 svc["description"] = str(field["value"]) 115 elif(field["name"] == "BTsdpprov"): 116 svc["provider"] = str(field["value"]) 117 elif(field["name"] == "BTsdpproto"): 118 svc["protocol"] = str(field["value"]) 119 elif(field["name"] == "BTsdppsm"): 120 svc["port"] = str(field["value"]) 121 elif(field["name"] == "BTsdpclass"): 122 svc["service-classes"] = str(field["value"]) 123 elif(field["name"] == "BTsdpprof"): 124 svc["profiles"] = str(field["value"]) 125 elif(field["name"] == "BTsdpservid"): 126 svc["service-id"] = str(field["value"]) 127 else: 128 print "I/O error encountered!" 129 btcore.btsdp.append(svc) 130 else: 131 print "File Load error!" 132 dlg = HIGAlertDialog(None, message_format=('I/O Error'), secondary_text=("The file isn't a valid UmitBT file")) 133 dlg.run() 134 dlg.destroy() 135 print "UBT file loaded" 136 137 138 139 def file_browse(self, dialog_action, file_name=""): 140 if (dialog_action==gtk.FILE_CHOOSER_ACTION_OPEN): 141 dialog_buttons = (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK) 142 dlg_title = "Open File" 143 else: 144 dialog_buttons = (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_SAVE, gtk.RESPONSE_OK) 145 dlg_title = "Save File" 146 147 file_dialog = gtk.FileChooserDialog(title=dlg_title, action=dialog_action, buttons=dialog_buttons) 148 149 if (dialog_action==gtk.FILE_CHOOSER_ACTION_SAVE): 150 file_dialog.set_current_name(file_name) 151 filter = gtk.FileFilter() 152 filter.set_name("Umit Bluetooth") 153 filter.add_pattern("*.ubt") 154 file_dialog.add_filter(filter) 155 156 if (dialog_action==gtk.FILE_CHOOSER_ACTION_OPEN): 157 """Create and add the 'all files' filter""" 158 filter1 = gtk.FileFilter() 159 filter2 = gtk.FileFilter() 160 filter1.set_name("Umit Bluetooth") 161 filter1.add_pattern("*.ubt") 162 file_dialog.add_filter(filter1) 163 filter2.set_name("All files") 164 filter2.add_pattern("*") 165 file_dialog.add_filter(filter2) 166 167 result = None 168 if file_dialog.run() == gtk.RESPONSE_OK: 169 result = file_dialog.get_filename() 170 if (dialog_action==gtk.FILE_CHOOSER_ACTION_SAVE): 171 result, extension = os.path.splitext(result) 172 result = result + ".ubt" 173 file_dialog.destroy() 174 return result 175 176 def clear_buffer(self): 177 btcore.btname = [""] 178 btcore.btmac = [""] 179 btcore.btmanu = [""] 180 btcore.btsdp = [""] 181 -
umit/core/UserConf.py
98 98 hint = 99 99 options = Operating system detection,Aggressive,Verbose 100 100 command = nmap -T Aggressive -O -v %s 101 annotation = '''101 annotation = 102 102 103 [umitbluetooth] 104 description = 105 hint = 106 options = Umit Bluetooth Scan 107 command = umitbluetooth 108 annotation =''' 109 103 110 profile_editor_content = '''<?xml version="1.0"?> 104 111 <interface> 105 112 <groups>
