#!/usr/bin/env python # -*- coding: utf-8 -*- # Author : Steven Harper # License : GNU GENERAL PUBLIC LICENSE # TODO : change print for logger import pygtk pygtk.require('2.0') import gtk import commands import time import os import sys import warnings from threading import Thread import xmllangs import USBAdslModemPopupMenu import USBAdslModemConfig import USBAdslModemStatus SECRETS_PATH="/var/tmp/secrets" PPPOE_STARTUP_PATH="/var/tmp/pppoe" PPPOA_STARTUP_PATH="/var/tmp/pppoa" PPP_PATH="/var/tmp/usbadslmodem" APP_PATH="/usr/share/applications/usbadslmodemmanager.desktop" INITD_PATH="/etc/init.d/usbadslmodem" RC2_PATH="/etc/rc2.d/S95usbadslmodem" WEBSITE="https://launchpad.net/usb-adsl-modem-manager" class AuthThread(Thread): def __init__ (self, manager): Thread.__init__(self) self.returnString="" self.manager = manager def run(self): print "AuthThread Started" self.returnString = commands.getoutput(self.manager.sudo_command+" pppd call usbadslmodem") print "AuthThread results length : ",self.returnString class USBAdslModemManager: langs_parser=None #root = __file__ #if os.path.islink (root): # root = os.path.realpath (root) #root = os.path.dirname (os.path.abspath (root)) #I hate this hack root="/usr/share/apps/usbadslmodemmanager" LANGSXML_PATH=root+"/data/langs.xml" IMAGE_ABOUT_SPLASH=root+"/icons/about_splash.png" ICON_PATH_WINDOW=root+"/icons/window_icon.png" ICON_PATH_NOMODEM=root+"/icons/modem_not_connected.png" ICON_PATH_NOTCONNECTED=root+"/icons/modem_detected.png" ICON_PATH_SYNCING=root+"/icons/modem_syncing.png" ICON_PATH_SYNCED=root+"/icons/modem_synced.png" ICON_PATH_CONNECTED=root+"/icons/modem_connected.png" ICON_PATH_CONNECTED_WITH_IP=root+"/icons/modem_connected_with_ip.png" ICON_PATH_WRONGFIRMWARE=root+"/icons/tray_icon_wrong.png" ICON_PATH_UNPLUGPLEASE=root+"/icons/tray_icon_red.png" ICON_PATH_REBOOTPLEASE=root+"/icons/tray_icon_red.png" FIRMWARE_PATH=root+"/firmware" US_FULLPATH=__file__ def __init__(self): self.version = "0.5.7" print "USB Adsl Modem Manager V"+self.version+" ("+time.strftime("%Y/%m/%d %H:%M:%S", time.localtime())+")" print "Root is " + self.root self.curr_tray_icon = self.ICON_PATH_NOMODEM self.debug = True self.atteptedInstallOfFirmware = False self.lastConnectionState = False self.isConnecting = False self.current_connection_PID = "" self.firmware_grace = True self.sudo_command = "gksudo" sudo = commands.getoutput("which gksudo") if len(sudo) > 0: self.sudo_command = "gksudo" else : sudo = commands.getoutput("which kdesud") if len(sudo) > 0: self.sudo_command = "kdesud" print "sudo command will be", self.sudo_command # Load or default the config self.connectionConfig = USBAdslModemConfig.USBAdslModemConfig() # Load Language print "about to load path : " + self.LANGSXML_PATH self.langs_parser = xmllangs.LangsParser(self.LANGSXML_PATH) self.langs = self.langs_parser.get_all_langs() if self.debug: print "Language selected is : " + self.connectionConfig.getOption("lang") self.lang = self.langs_parser.find_lang(self.connectionConfig.getOption("lang")) print "test language is working:",self.lang.get_string("MESSAGE_FIRMWARE_NEW_INSTALLED") # Create the status icon object self.status_icon = gtk.StatusIcon() self.status_icon.set_tooltip("USB Adsl Modem Manager V"+self.version) self.status_icon.set_from_file( self.curr_tray_icon) #self.status_icon.connect('activate', self.on_activate) self.status_icon.connect('popup-menu', self.trayIconClicked) self.popup_menu = USBAdslModemPopupMenu.USBAdslModemPopupMenu(self) self.status_icon.set_visible(True) # Prepare badger thats goint to Detect what going on With Modem self.statusMonitor = USBAdslModemStatus.USBAdslModemStatus(self); self.lastStatusString = self.lang.get_string("TRAY_STATUS_STARTINGUP") self.status_icon.set_tooltip(self.lastStatusString) # If deafult options then lets Show then the Config Window if self.connectionConfig.getOption("username") == "default": self.showConfigWindow(True) # Lets just check to see if a ppp is running if it is : lets Hijack it authPID = commands.getoutput("ps -ef | awk '/pppd call us[b]adslmodem/ {print $2}'") if len(authPID) > 0: self.current_connection_PID = authPID if self.debug: print "Found a pppd running, Hijacking PID : "+authPID # Start the Ticker! self.maintimer=gtk.timeout_add(1000,self.updateStatus) self.unplugtimer=None self.dialtimer=None def update_labels(self): if self.debug: print "Updating all Labels - lang : " + self.connectionConfig.getOption("lang") self.popup_menu = USBAdslModemPopupMenu.USBAdslModemPopupMenu(self) def changeTrayIcon(self, newIconPath): if self.debug: print "Changing tray to : " + newIconPath if self.curr_tray_icon == newIconPath: if (self.debug): print "Change not needed" return self.curr_tray_icon = newIconPath self.status_icon.set_from_file(self.curr_tray_icon) # popup text if poss def showAboutWindow(self): self.about_window = gtk.Window( gtk.WINDOW_TOPLEVEL ) self.about_window.set_title(self.lang.get_string("ABOUT_WINDOW_NAME")) self.about_window.set_border_width( 5 ) self.about_window.set_position( gtk.WIN_POS_CENTER ) self.about_window.set_modal( gtk.TRUE ) self.about_window.set_resizable(gtk.FALSE) icon = gtk.gdk.pixbuf_new_from_file(self.ICON_PATH_WINDOW) gtk.window_set_default_icon_list( (icon) ) # Register eventsICON_PATH_WRONGFIRMWAR self.about_window.connect( "delete_event", self.onDelete_about ) #window.show() self.about_window.resize(380,150) table = gtk.Table( rows=5, columns=1, homogeneous=gtk.FALSE ) self.about_window.add(table) label_title = gtk.Label() label_title.set_markup('USB ADSL Modem Manager\nVersion '+self.version) table.attach(label_title, 0, 1, 0, 1,xpadding=2,ypadding=1) label_title.show() splash = gtk.Image() splash.set_from_file(self.IMAGE_ABOUT_SPLASH) table.attach(splash, 0, 1, 1, 2,xpadding=2,ypadding=1) splash.show() # Add 'Website' button button_visit = gtk.Button( label="Visit _Website" ) button_visit.set_use_underline(True) table.attach( button_visit, 0, 1, 2, 3, ypadding=1 ) button_visit.connect( "clicked", self.gotourl ) button_visit.show() label_blurb = gtk.Label() label_blurb.set_markup('\nWritten by Steven Harper\n\nWith help from:\n Richard Harper\n Juan Grande\n\nTranslations:\n Turkish : Abdullah Kahraman\n Spanish : Alejandro Riveira Fernández\n French : Yann Verry\n Polish : jacekowski\n German : Atreju Tauschinsky\n Hebrew : Yotam Benshalom\n Finnish : Simo Niiranen\n Greek : Nikolaos Romanos\n Romanian : Alexandru Eftimie\n Portuguese : Rui Pais\n Dutch : Mark Kaptein\n Indonesian : Heri Susanto\n Italian : Atlantis Carciofone\n') table.attach(label_blurb, 0, 1, 3, 4,xpadding=2,ypadding=1) label_blurb.show() # Add 'Close' button button_close = gtk.Button( stock=gtk.STOCK_CLOSE ) table.attach( button_close, 0, 1, 4, 5, ypadding=1 ) button_close.connect( "clicked", self.onDelete_about ) button_close.show() table.show() self.about_window.show() def gotourl( self, pie=None): os.system("firefox "+WEBSITE+" &") def showConfigWindow(self, showConnectInfo): self.config_window = gtk.Window( gtk.WINDOW_TOPLEVEL ) self.config_window.set_title(self.lang.get_string("CONFIG_WINDOW_NAME")) self.config_window.set_border_width( 5 ) self.config_window.set_position( gtk.WIN_POS_CENTER ) self.config_window.set_modal( gtk.TRUE ) self.config_window.set_resizable(gtk.FALSE) icon = gtk.gdk.pixbuf_new_from_file(self.ICON_PATH_WINDOW) gtk.window_set_default_icon_list( (icon) ) # Register eventsICON_PATH_WRONGFIRMWAR self.config_window.connect( "delete_event", self.onDelete_config ) #window.show() self.config_window.resize(380,10) table = gtk.Table( rows=10, columns=2, homogeneous=gtk.FALSE ) self.config_window.add(table) # Add combobox to select language #self.lbl_langs=gtk.Label(self.lang.get_string(4)) self.lbl_langs=gtk.Label(self.lang.get_string("CONFIG_WINDOW_LANGUAGE")) self.lbl_langs.set_alignment(0, 0.5) self.cbo_langs=gtk.combo_box_new_text() #self.cbo_langs.connect( 'changed', self.update_labels) for one_lang in self.langs: if one_lang==self.lang: self.cbo_langs.prepend_text( one_lang.get_name()) else: self.cbo_langs.append_text( one_lang.get_name()) self.cbo_langs.set_active(0) # Attach combobox and label table.attach( self.lbl_langs, 0, 1, 0, 1 ) self.lbl_langs.show() table.attach( self.cbo_langs, 1, 2, 0, 1, ypadding=5 ) self.cbo_langs.show() label_user = gtk.Label(self.lang.get_string("CONFIG_WINDOW_USERNAME") + " (xxx@yyy.com)") label_user.set_alignment(0, 0.5) self.textbox_user = gtk.Entry( max=0 ) self.textbox_user.set_text(self.connectionConfig.getOption("username")) table.attach(label_user, 0, 1, 1, 2,xpadding=2,ypadding=1) table.attach(self.textbox_user,1, 2, 1, 2,xpadding=2,ypadding=1) label_user.show() self.textbox_user.show() label_password = gtk.Label(self.lang.get_string("CONFIG_WINDOW_PASSWORD")) label_password.set_alignment(0, 0.5) self.textbox_password = gtk.Entry( max=0 ) self.textbox_password.set_text(self.connectionConfig.getOption("password")) self.textbox_password.set_visibility( gtk.FALSE ) self.textbox_password.set_invisible_char( '*' ) table.attach(label_password, 0, 1, 2, 3,xpadding=2,ypadding=1) table.attach(self.textbox_password,1, 2, 2, 3,xpadding=2,ypadding=1) label_password.show() self.textbox_password.show() label_vp = gtk.Label(self.lang.get_string("CONFIG_WINDOW_VP")) label_vp.set_alignment(0, 0.5) self.textbox_vp = gtk.Entry( max=0 ) self.textbox_vp.set_text(self.connectionConfig.getOption("vp")) table.attach(label_vp, 0, 1, 3, 4,xpadding=2,ypadding=1) table.attach(self.textbox_vp,1, 2, 3, 4,xpadding=2,ypadding=1) label_vp.show() self.textbox_vp.show() label_vc = gtk.Label(self.lang.get_string("CONFIG_WINDOW_VC")) label_vc.set_alignment(0, 0.5) self.textbox_vc = gtk.Entry( max=0 ) self.textbox_vc.set_text(self.connectionConfig.getOption("vc")) table.attach(label_vc, 0, 1, 4, 5,xpadding=2,ypadding=1) table.attach(self.textbox_vc,1, 2, 4, 5,xpadding=2,ypadding=1) label_vc.show() self.textbox_vc.show() # authtype here self.lbl_authtype=gtk.Label(self.lang.get_string("CONFIG_WINDOW_AUTHTYPE")) self.lbl_authtype.set_alignment(0, 0.5) self.cbo_authtype=gtk.combo_box_new_text() #self.cbo_langs.connect( 'changed', self.update_labels) if (self.connectionConfig.getOption("authtype") == "pppoa"): self.cbo_authtype.append_text("pppoa") self.cbo_authtype.append_text("pppoe") else: self.cbo_authtype.append_text("pppoe") self.cbo_authtype.append_text("pppoa") self.cbo_authtype.set_active(0) # Attach combobox and label table.attach( self.lbl_authtype, 0, 1, 5, 6 ) self.lbl_authtype.show() table.attach( self.cbo_authtype, 1, 2, 5, 6, ypadding=5 ) self.cbo_authtype.show() # Checkbox for Autostart on login alignment = gtk.Alignment( 0.0, 0.0, 0.0, 0.0 ) self.autostart_on_login = gtk.CheckButton( self.lang.get_string("CONFIG_WINDOW_AUTOSTART_MAN") ) alignment.add( self.autostart_on_login ) table.attach( alignment, 0, 2, 6, 7 ) alignment.show() if self.connectionConfig.getOption("autostart_on_login") == "true": self.autostart_on_login.set_active( gtk.TRUE ) else: self.autostart_on_login.set_active( gtk.FALSE ) self.autostart_on_login.show() # connect_on_boot alignment = gtk.Alignment( 0.0, 0.0, 0.0, 0.0 ) self.connect_on_boot = gtk.CheckButton( self.lang.get_string("CONFIG_WINDOW_CONNECT_ON_BOOT") ) alignment.add( self.connect_on_boot ) table.attach( alignment, 0, 2, 7, 8 ) alignment.show() if self.connectionConfig.getOption("connect_on_boot") == "true": self.connect_on_boot.set_active( gtk.TRUE ) else: self.connect_on_boot.set_active( gtk.FALSE ) self.connect_on_boot.show() # leave_connected_on_exit alignment = gtk.Alignment( 0.0, 0.0, 0.0, 0.0 ) self.leave_connected_on_exit = gtk.CheckButton( self.lang.get_string("CONFIG_WINDOW_LEAVE_CONNECTED") ) alignment.add( self.leave_connected_on_exit ) table.attach( alignment, 0, 2, 8, 9 ) alignment.show() if self.connectionConfig.getOption("leave_connected_on_exit") == "true": self.leave_connected_on_exit.set_active( gtk.TRUE ) else: self.leave_connected_on_exit.set_active( gtk.FALSE ) self.leave_connected_on_exit.show() # Add 'Save' button button_close = gtk.Button( stock=gtk.STOCK_CLOSE ) table.attach( button_close, 0, 1, 9, 10, ypadding=1 ) button_close.connect( "clicked", self.onDelete_config ) button_close.show() # Add 'Save' button button_save = gtk.Button( stock=gtk.STOCK_OK ) table.attach( button_save, 1, 2, 9, 10, ypadding=1 ) button_save.connect( "clicked", self.saveConfig ) button_save.show() table.show() self.config_window.show() if showConnectInfo: dialog = gtk.MessageDialog( None, gtk.DIALOG_MODAL, gtk.MESSAGE_INFO, gtk.BUTTONS_OK, self.lang.get_string("MESSAGE_HOW_TO_CONNECT")) dialog.width, dialog.height = dialog.get_size() icon = gtk.gdk.pixbuf_new_from_file(self.ICON_PATH_WINDOW) gtk.window_set_default_icon_list( (icon) ) ret = dialog.run() dialog.destroy() def saveConfig(self, event): if self.debug:print "Saving Configuration" self.connectionConfig.setOption("username",self.textbox_user.get_text()) self.connectionConfig.setOption("password",self.textbox_password.get_text()) self.connectionConfig.setOption("vp",self.textbox_vp.get_text()) self.connectionConfig.setOption("vc",self.textbox_vc.get_text()) iter = self.cbo_langs.get_active_iter() self.connectionConfig.setOption("lang",self.cbo_langs.get_model().get_value(iter, 0)) iter = self.cbo_authtype.get_active_iter() self.connectionConfig.setOption("authtype",self.cbo_authtype.get_model().get_value(iter, 0)) if self.autostart_on_login.get_active() == gtk.TRUE : self.connectionConfig.setOption("autostart_on_login","true") else: self.connectionConfig.setOption("autostart_on_login","false") if self.connect_on_boot.get_active() == gtk.TRUE : self.connectionConfig.setOption("connect_on_boot","true") else: self.connectionConfig.setOption("connect_on_boot","false") if self.leave_connected_on_exit.get_active() == gtk.TRUE : self.connectionConfig.setOption("leave_connected_on_exit","true") else: self.connectionConfig.setOption("leave_connected_on_exit","false") # Now Save self.connectionConfig.writeConfig() # Load Language self.lang = self.langs_parser.find_lang(self.connectionConfig.getOption("lang")) # Now inform Bits they Need to Update thier Labels self.update_labels() if self.autostart_on_login.get_active() == gtk.TRUE : self.connectionConfig.setOption("autostart_on_login","true") else: self.connectionConfig.setOption("autostart_on_login","false") # Now do Any actions needed if self.connectionConfig.getOption("autostart_on_login") == "true": self.createAutoStartOnLoginFile() else : self.removeAutoStartOnLoginFile() if self.connectionConfig.getOption("connect_on_boot") == "true": self.createRC2SimLink() else : self.removeRC2SimLink() self.onDelete_config(None, None) def createPPPoAStartup(self): if self.debug:print "Making PPPoA Startup" pppoaFile = open(PPPOA_STARTUP_PATH,"w") pppoaFile.writelines("#!/bin/bash\nmodprobe ppp_generic\nmodprobe pppoatm\ncount=0\nwhile [[ $((count++)) -lt 40 ]]\ndo\n sync=$(dmesg | grep 'ADSL line is up')\n if [ ! -z \"$sync\" ]\n then\n pppd call usbadslmodem\n exit 0\n fi\n sleep 1\ndone\necho \"The firmware did not load\"") pppoaFile.close() exportingPPPoA = commands.getoutput(self.sudo_command+" \"install -m 744 "+PPPOA_STARTUP_PATH+" /etc/init.d/usbadslmodem_pppoa.sh\"") if len(exportingPPPoA) > 0:print exportingPPPoA # Now delete it outputString = commands.getoutput(self.sudo_command+" rm "+PPPOA_STARTUP_PATH) if len(outputString) > 0 and self.debug:print outputString def createPPPoEStartup(self): if self.debug:print "Making PPPoE Startup" pppoeFile = open(PPPOE_STARTUP_PATH,"w") pppoeFile.writelines("#!/bin/bash\nmodprobe ppp_generic\nmodprobe pppoatm\nmodprobe br2684\ncount=0\nwhile [[ $((count++)) -lt 40 ]]\ndo\n sync=$(dmesg | grep 'ADSL line is up')\n if [ ! -z \"$sync\" ]\n then\n br2684ctl -b -c 0 -a "+self.connectionConfig.getOption("vp")+"."+self.connectionConfig.getOption("vc")+"\n sleep 3\n ifconfig nas0 192.168.0.1 netmask 255.255.255.0 up\n sleep 10\n pppd call usbadslmodem\n exit 0\n fi\n sleep 1\ndone\necho \"The firmware did not load\"") pppoeFile.close() exportingPPPoE = commands.getoutput(self.sudo_command+" \"install -m 744 "+PPPOE_STARTUP_PATH+" /etc/init.d/usbadslmodem_pppoe.sh\"") if len(exportingPPPoE) > 0:print exportingPPPoE # Now delete it outputString = commands.getoutput(self.sudo_command+" rm "+PPPOE_STARTUP_PATH) if len(outputString) > 0 and self.debug:print outputString def createRC2SimLink(self): # Remove it first just incase its duff self.removeRC2SimLink() if (self.connectionConfig.getOption("authtype") == "pppoe"): self.createPPPoEStartup() else: self.createPPPoAStartup() outputString = commands.getoutput(self.sudo_command+" \"ln -s "+INITD_PATH+"_"+self.connectionConfig.getOption("authtype")+ ".sh "+RC2_PATH+"\"") if len(outputString) > 0 and self.debug:print outputString if self.debug:print "Made RC2 link (" + self.connectionConfig.getOption("authtype") + ")" def removeRC2SimLink(self): outputString = commands.getoutput(self.sudo_command+" rm "+RC2_PATH) if len(outputString) > 0 and self.debug:print outputString if self.debug:print "Removed RC2 link" def removeAutoStartOnLoginFile(self): autoThere = False outputString = commands.getoutput("ls ~/.config/autostart/usbadslmodemmanager.desktop | grep \"No such File\"") if len(outputString) == 0: if self.debug:print "Found one!" autoThere = True if autoThere : #Replace this with proper Python one if self.debug:print "Removing old autostart on login" outputString = commands.getoutput("rm ~/.config/autostart/usbadslmodemmanager.desktop") if self.debug and len(outputString) > 0 :print outputString def createAutoStartOnLoginFile(self): if self.debug:print "Making a Auto Start on Login" outputString = commands.getoutput("ls ~/.config/ | grep autostart") if self.debug and len(outputString) > 0 :print outputString if len(outputString) == 0: outputString = commands.getoutput("mkdir ~/.config/autostart") if self.debug and len(outputString) > 0 :print outputString outputString = commands.getoutput("cp "+APP_PATH+" ~/.config/autostart/") if self.debug and len(outputString) > 0 :print outputString def removeFirmware(self): if self.debug:print "Tell User to re-extract" dialog = gtk.MessageDialog( None, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, self.lang.get_string("MESSAGE_FIRMWARE_CONFLICT")) dialog.width, dialog.height = dialog.get_size() icon = gtk.gdk.pixbuf_new_from_file(self.ICON_PATH_WINDOW) gtk.window_set_default_icon_list( (icon) ) ret = dialog.run() dialog.destroy() def installFirmware(self, force): if self.statusMonitor.actual_modemConnected and (not self.statusMonitor.actual_firmwareOk or force): if self.statusMonitor.wrong_firmware and not force: self.removeFirmware() # See if firmware is There firmwareAlreadyDeployed = False try: open("/lib/firmware/speedtch-1.bin") open("/lib/firmware/speedtch-2.bin") firmwareAlreadyDeployed = True except IOError: if self.debug:print "Firmware not there" if firmwareAlreadyDeployed: if (self.debug):print "Firmware is already installed" dialog = gtk.MessageDialog( None, gtk.DIALOG_MODAL, gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, self.lang.get_string("MESSAGE_FIRMWARE_REINSTALL_QUESTION")) dialog.width, dialog.height = dialog.get_size() icon = gtk.gdk.pixbuf_new_from_file(self.ICON_PATH_WINDOW) gtk.window_set_default_icon_list( (icon) ) ret = dialog.run() dialog.destroy() if ret == gtk.RESPONSE_NO: if self.debug:print "They Said NO!" if not force: self.atteptedInstallOfFirmware = True; self.status_icon.set_tooltip(self.lang.get_string("TRAY_STATUS_UNPLUG")) self.changeTrayIcon(self.ICON_PATH_UNPLUGPLEASE) self.unplugtimer = gtk.timeout_add(500,self.waitForUnplug) return # Make sure any connection is dropped self.killConnection() # If they Said Yes # Extract Firmware if self.statusMonitor.status_modemIdAsInt > -1 and self.statusMonitor.status_modemIdAsInt < 3: outputString = commands.getoutput(self.sudo_command+" \"chmod +x "+self.FIRMWARE_PATH+"/firmware-extractor\"") outputString = commands.getoutput(self.sudo_command+" "+self.FIRMWARE_PATH+"/firmware-extractor "+self.FIRMWARE_PATH+"/KQD6_3.012") if self.debug:print outputString else : if self.statusMonitor.status_modemIdAsInt >= 3 and self.statusMonitor.status_modemIdAsInt < 5: outputString = commands.getoutput(self.sudo_command+" \"chmod +x "+self.FIRMWARE_PATH+"/firmware-extractor\"") outputString = commands.getoutput(self.sudo_command+" "+self.FIRMWARE_PATH+"/firmware-extractor "+self.FIRMWARE_PATH+"/ZZZL_3.012") if self.debug:print outputString else : if self.debug:print "Modem not in range" dialog = gtk.MessageDialog( None, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, self.lang.get_string("MESSAGE_FIRMWARE_MODEM_NOT_SUPPORTED")) dialog.width, dialog.height = dialog.get_size() icon = gtk.gdk.pixbuf_new_from_file(self.ICON_PATH_WINDOW) gtk.window_set_default_icon_list( (icon) ) ret = dialog.run() dialog.destroy() return # Warn them that were about to ASK for root priviliges if self.debug:print "copying firmware to hotplug" dialog = gtk.MessageDialog( None, gtk.DIALOG_MODAL, gtk.MESSAGE_INFO, gtk.BUTTONS_OK, self.lang.get_string("MESSAGE_FIRMWARE_NEEDS_ROOT")) dialog.width, dialog.height = dialog.get_size() icon = gtk.gdk.pixbuf_new_from_file(self.ICON_PATH_WINDOW) gtk.window_set_default_icon_list( (icon) ) ret = dialog.run() dialog.destroy() outputString = commands.getoutput(self.sudo_command+" cp speedtch* /lib/firmware") if self.debug:print outputString outputString = commands.getoutput(self.sudo_command+" rm speedtch-1.bin") if self.debug:print outputString outputString = commands.getoutput(self.sudo_command+" rm speedtch-2.bin") if self.debug:print outputString self.atteptedInstallOfFirmware = True; if self.statusMonitor.wrong_firmware: # BIG REBOOT MESSAGE self.changeTrayIcon(self.ICON_PATH_REBOOTPLEASE) self.unplugtimer = gtk.timeout_add(500,self.waitForUnplug) self.status_icon.set_tooltip(self.lang.get_string("TRAY_STATUS_NEW_UNPLUG")) dialog = gtk.MessageDialog( None, gtk.DIALOG_MODAL, gtk.MESSAGE_WARNING, gtk.BUTTONS_OK,self.lang.get_string("MESSAGE_FIRMWARE_NEW_INSTALLED") ) dialog.width, dialog.height = dialog.get_size() icon = gtk.gdk.pixbuf_new_from_file(self.ICON_PATH_WINDOW) gtk.window_set_default_icon_list( (icon) ) ret = dialog.run() dialog.destroy() else : self.changeTrayIcon(self.ICON_PATH_UNPLUGPLEASE) self.unplugtimer = gtk.timeout_add(500,self.waitForUnplug) # BIG MESSAGE TO REPLUG self.status_icon.set_tooltip(self.lang.get_string("TRAY_STATUS_NEW_UNPLUG")) dialog = gtk.MessageDialog( None, gtk.DIALOG_MODAL, gtk.MESSAGE_INFO, gtk.BUTTONS_OK, self.lang.get_string("MESSAGE_FIRMWARE_NEW_INSTALLED")) dialog.width, dialog.height = dialog.get_size() icon = gtk.gdk.pixbuf_new_from_file(self.ICON_PATH_WINDOW) gtk.window_set_default_icon_list( (icon) ) ret = dialog.run() dialog.destroy() else : if force: dialog = gtk.MessageDialog( None, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, self.lang.get_string("MESSAGE_MODEM_NO_SUPPORTED")) dialog.width, dialog.height = dialog.get_size() icon = gtk.gdk.pixbuf_new_from_file(self.ICON_PATH_WINDOW) gtk.window_set_default_icon_list( (icon) ) ret = dialog.run() dialog.destroy() def waitForUnplug(self): noModemVersion = commands.getoutput(self.sudo_command+" \"lsusb -vvv\" | grep -A 1 4061 | tail -1 | awk '{print $2}'") if len(noModemVersion) > 0: if self.debug:print "awaiting unplug" self.unplugtimer = gtk.timeout_add(500,self.waitForUnplug) else : if self.debug:print "unplug detected" removeDrivers = commands.getoutput(self.sudo_command+" rmmod speedtch") if len(removeDrivers): if self.debug:print removeDrivers self.changeTrayIcon(self.ICON_PATH_NOMODEM) self.atteptedInstallOfFirmware = False self.firmware_grace = True def makeNDeployAuth(self) : if self.debug:print "Making Secrets" secretsFile = open(SECRETS_PATH,"w") secretsFile.writelines("\""+self.connectionConfig.getOption("username")+"\" \"*\" \""+self.connectionConfig.getOption("password")+"\"") secretsFile.close() exportingSecrets = commands.getoutput(self.sudo_command+" \"install -m 600 "+SECRETS_PATH+" /etc/ppp/chap-secrets\"") if len(exportingSecrets) > 0:print exportingSecrets exportingSecrets = commands.getoutput(self.sudo_command+" \"install -m 600 "+SECRETS_PATH+" /etc/ppp/pap-secrets\"") if len(exportingSecrets) > 0:print exportingSecrets # Now delete it outputString = commands.getoutput(self.sudo_command+" rm "+SECRETS_PATH) if len(outputString) > 0 and self.debug:print outputString def makePPPoAFile(self): pppFile = open(PPP_PATH,"w") pppFile.writelines("noipdefault\ndefaultroute\nuser '"+self.connectionConfig.getOption("username")+"'\nnoauth\nupdetach\npersist\nusepeerdns\nplugin pppoatm.so\n"+self.connectionConfig.getOption("vp")+"."+self.connectionConfig.getOption("vc")+"\ndebug\n") pppFile.close() def makePPPoEFile(self): # Drop the Bridge in authOutput = commands.getoutput(self.sudo_command+" \"install -m 755 "+self.FIRMWARE_PATH+"/br2684ctl /usr/sbin\"") if len(authOutput) > 0 and self.debug:print authOutput pppFile = open(PPP_PATH,"w") pppFile.writelines("linkname 'ppp0'\nnoipdefault\ndefaultroute\nuser '"+self.connectionConfig.getOption("username")+"'\nnoauth\nupdetach\npersist\nholdoff 4\nmaxfail 25\nusepeerdns\nplugin rp-pppoe.so\nnas0\ndebug\n") pppFile.close() def doExtraPPPoEStuff(self): makeBr = commands.getoutput(self.sudo_command+" \"br2684ctl -b -c 0 -a "+self.connectionConfig.getOption("vp")+"."+self.connectionConfig.getOption("vc")+"\"") if len(makeBr) > 0 and self.debug:print makeBr commands.getoutput("sleep 3") makeAdaptor = commands.getoutput(self.sudo_command+" \"ifconfig nas0 192.168.0.1 netmask 255.255.255.0 up\"") if len(makeAdaptor) > 0 and self.debug:print makeAdaptor def makeNDeployPPPConfig(self): if self.debug:print "Making PPP Script" if self.connectionConfig.getOption("authtype") == "pppoe" : self.makePPPoEFile() self.doExtraPPPoEStuff() else : self.makePPPoAFile() exportingPPP = commands.getoutput(self.sudo_command+" \"install -m 600 "+PPP_PATH+" /etc/ppp/peers\"") if len(exportingPPP) > 0: if self.debug:print exportingPPP #now delete it outputString = commands.getoutput(self.sudo_command+" rm "+PPP_PATH) if len(outputString) > 0 and self.debug:print outputString def attemptToAuth(self): if self.debug:print "-------Attempting Auth-------" authOutput = ""; current = AuthThread(self) current.start() time.sleep(10) if self.debug:print "After sleep AuthResponse length is :",len(current.returnString) if len(current.returnString) > 0: if self.debug:print "seems OK" authOutput = current.returnString else : if self.debug:print "Auth seems Hung!" self.changeTrayIcon(self.ICON_PATH_SYNCED) authPID = commands.getoutput("ps -ef | awk '/pppd call us[b]adslmodem/ {print $2}'") if len(authPID) > 0: self.current_connection_PID = authPID if self.debug:print "Auth process there:", authPID self.killConnection() else: if self.debug:print "Auth process cant be found" dialog = gtk.MessageDialog( None, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, self.lang.get_string("MESSAGE_CONNECT_FAILED_AUTH")) dialog.width, dialog.height = dialog.get_size() icon = gtk.gdk.pixbuf_new_from_file(self.ICON_PATH_WINDOW) gtk.window_set_default_icon_list( (icon) ) ret = dialog.run() dialog.destroy() if len(authOutput) > 0: if self.debug:print "results of Auth:",authOutput if authOutput.find("Failed to authenticate") > -1: dialog = gtk.MessageDialog( None, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, self.lang.get_string("MESSAGE_CONNECT_FAILED_AUTH")) dialog.width, dialog.height = dialog.get_size() icon = gtk.gdk.pixbuf_new_from_file(self.ICON_PATH_WINDOW) gtk.window_set_default_icon_list( (icon) ) ret = dialog.run() dialog.destroy() self.changeTrayIcon(self.ICON_PATH_SYNCED) if authOutput.find("LCP terminated by peer") > -1: dialog = gtk.MessageDialog( None, gtk.DIALOG_MODAL, gtk.MESSAGE_WARNING, gtk.BUTTONS_OK, self.lang.get_string("MESSAGE_CONNECT_FAILED_LCP")) dialog.width, dialog.height = dialog.get_size() icon = gtk.gdk.pixbuf_new_from_file(self.ICON_PATH_WINDOW) gtk.window_set_default_icon_list( (icon) ) ret = dialog.run() dialog.destroy() self.changeTrayIcon(self.ICON_PATH_SYNCED) authPID = commands.getoutput("ps -ef | awk '/pppd call us[b]adslmodem/ {print $2}'") if len(authPID) > 0: self.current_connection_PID = authPID if self.debug:print "Auth process there:", authPID else: if self.debug:print "cant find Auth PID" self.current_connection_PID = "" dialog = gtk.MessageDialog( None, gtk.DIALOG_MODAL, gtk.MESSAGE_WARNING, gtk.BUTTONS_OK, self.lang.get_string("MESSAGE_CONNECT_FAILED")) dialog.width, dialog.height = dialog.get_size() icon = gtk.gdk.pixbuf_new_from_file(self.ICON_PATH_WINDOW) gtk.window_set_default_icon_list( (icon) ) ret = dialog.run() dialog.destroy() self.changeTrayIcon(self.ICON_PATH_SYNCED) if len(authPID) > 0: self.modifyResolveConf() if len(self.current_connection_PID) > 0: self.status_icon.set_tooltip(self.lastStatusString+self.lang.get_string("TRAY_STATUS_ADDITION_AUTHENTICATED")) self.changeTrayIcon(self.ICON_PATH_CONNECTED) else: self.status_icon.set_tooltip(self.lastStatusString+self.lang.get_string("TRAY_STATUS_ADDITION_FAILED")) self.changeTrayIcon(self.ICON_PATH_SYNCED) def modifyResolveConf(self): if self.debug:print "Modifying Resolve Conf" change_resolve= commands.getoutput(self.sudo_command+" \"ln -sf /etc/ppp/resolv.conf /etc/resolv.conf\"") if len(change_resolve) > 0: if self.debug:print change_resolve def killConnection(self): if self.debug:print "Into kill connection" if len(self.current_connection_PID) > 0: if self.debug:print "Killing Connection : "+ self.current_connection_PID self.status_icon.set_tooltip(self.lang.get_string("TRAY_STATUS_DISCONNECTING")) words = self.current_connection_PID.split() if self.debug:print "words:",words for item in words: if self.debug:print "killing:",item attempt_kill= commands.getoutput(self.sudo_command+" kill " + item) if self.debug:print attempt_kill self.current_connection_PID = "" def startConnecting(self): if self.debug:print "--------Starting Connecting Stuff--------" self.isConnecting = True self.killConnection() self.makeNDeployAuth() self.makeNDeployPPPConfig() self.status_icon.set_tooltip(self.lastStatusString+self.lang.get_string("TRAY_STATUS_ADDITION_AUTHENTICATING")) ## XXXXXXXXXXX self.dialtimer=gtk.timeout_add(500,self.attemptToAuth) def updateStatus(self): if self.debug:print "Updating Status!" if self.atteptedInstallOfFirmware: if self.debug:print "awaiting unplug" else : # UPDATE the Status Monitor self.lastStatusString = self.statusMonitor.updateStatus() if self.debug: print "----------Tool Tip-----------" print self.lastStatusString self.status_icon.set_tooltip(self.lastStatusString) if self.statusMonitor.actual_modemConnected: if (self.statusMonitor.actual_connected): if len(self.statusMonitor.connection_ip_detail) > 0: self.changeTrayIcon(self.ICON_PATH_CONNECTED_WITH_IP) else: self.changeTrayIcon(self.ICON_PATH_SYNCED) else: if self.statusMonitor.actual_syncronizing: self.changeTrayIcon( self.ICON_PATH_SYNCING ) else : self.changeTrayIcon( self.ICON_PATH_NOTCONNECTED ) if self.lastConnectionState: self.statusMonitor.lastConnectionState = False else : self.changeTrayIcon(self.ICON_PATH_NOMODEM) if self.lastConnectionState: self.killConnection() self.statusMonitor.lastConnectionState = False # This bit is so we can tell if we have just disconnected : so we can try to Auth if not self.statusMonitor.actual_connected : self.statusMonitor.lastConnectionState = False if self.statusMonitor.actual_connected and not self.lastConnectionState: #self.startConnecting() self.lastConnectionState = True self.firmware_grace = True if self.statusMonitor.actual_modemConnected and not self.statusMonitor.actual_firmwareOk: if not self.firmware_grace: # ACE we have a modem : lets try some firmware self.changeTrayIcon(self.ICON_PATH_WRONGFIRMWARE) self.installFirmware(False) else : if self.debug:print "In Firmware Grace period" self.firmware_grace = False # alway do this self.maintimer=gtk.timeout_add(5000,self.updateStatus) def installFirmwareEvent(self,menuItem): if self.debug:print "Re-Extract Firmware Event!" self.installFirmware(True) def showAboutWindowEvent(self,menuItem): if self.debug:print "Show About Event!" self.showAboutWindow() def showConfigWindowEvent(self,menuItem): if self.debug:print "Show Config Event!" self.showConfigWindow(False) def doConnectEvent(self,menuItem): if self.debug:print "Connect pushed" if self.statusMonitor.actual_modemConnected and self.statusMonitor.actual_connected: self.startConnecting() def doDisconnectEvent(self,menuItem): if self.debug:print "Disconnect pushed PID:", self.current_connection_PID if self.statusMonitor.actual_modemConnected and self.statusMonitor.actual_connected : self.changeTrayIcon(self.ICON_PATH_SYNCED) self.dialtimer=gtk.timeout_add(500,self.killConnection) def trayIconClicked(self, status_icon, button, activate_time): if button==3: self.popup_menu.menu.popup(None, None, gtk.status_icon_position_menu, button, activate_time, self.status_icon) def hide(self): self.window.hide() def onDelete_about( self, widget, data=None ): self.about_window.hide() def onDelete_config( self, widget, data=None ): self.config_window.hide() def onDelete(self, widget, data=None ): event = ""; self.exit(event) return gtk.TRUE def checkWeAreAlone(self): print "checking : " + "ps -ef | grep \"pyt[h]on "+self.US_FULLPATH+"\"" checkAnother = commands.getoutput("ps -ef | grep \"pyt[h]on "+self.US_FULLPATH+"\"") lines = checkAnother.splitlines(False) if len(lines) > 1: print "We are not alone, another usbadslmanager appears to be running!\n" + checkAnother return True return False def exit(self, event): if self.connectionConfig.getOption("leave_connected_on_exit") == "false": dialog = gtk.MessageDialog( None, gtk.DIALOG_MODAL, gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, self.lang.get_string("MESSAGE_EXIT_WARN")) dialog.width, dialog.height = dialog.get_size() ret = dialog.run() if ret==gtk.RESPONSE_YES: self.killConnection() gtk.main_quit(0) dialog.destroy() else: dialog.destroy() return gtk.main_quit(0) def main(self): gtk.main() def start(): warnings.filterwarnings( action="ignore", category=DeprecationWarning) theUSBAdslModemManager = USBAdslModemManager() if theUSBAdslModemManager.checkWeAreAlone(): exit(0) try: theUSBAdslModemManager.main() except KeyboardInterrupt: theUSBAdslModemManager.killConnection() if __name__ == "__main__": start()