()
Checks for new version, prompts to upgrade, then
        replaces this script with the latest from the repo
Checks for new version, prompts to upgrade, then
        replaces this script with the latest from the repo
Checks for new version prompts to upgrade then replaces this script with the latest from the repo
def upgrade():
    """
        Checks for new version, prompts to upgrade, then
        replaces this script with the latest from the repo
    """
    global RUN_CONFIG
    try:
        print GR+' [!]'+W+' upgrading requires an '+G+'internet connection'+W
        print GR+' [+]'+W+' checking for latest version...'
        revision = get_revision()
        if revision == -1:
            print R+' [!]'+O+' unable to access GitHub'+W
        elif revision > RUN_CONFIG.REVISION:
            print GR+' [!]'+W+' a new version is '+G+'available!'+W
            print GR+' [-]'+W+'   revision:    '+G+str(revision)+W
            response = raw_input(GR+' [+]'+W+' do you want to upgrade to the latest version? (y/n): ')
            if not response.lower().startswith('y'):
                print GR+' [-]'+W+' upgrading '+O+'aborted'+W
                exit_gracefully(0)
                return
            # Download script, replace with this one
            print GR+' [+] '+G+'downloading'+W+' update...'
            try:
                sock = urllib.urlopen('https://github.com/derv82/wifite/raw/master/wifite.py')
                page = sock.read()
            except IOError:
                page = ''
            if page == '':
                print R+' [+] '+O+'unable to download latest version'+W
                exit_gracefully(1)
            
            # Create/save the new script
            f=open('wifite_new.py','w')
            f.write(page)
            f.close()
            
            # The filename of the running script
            this_file = __file__
            if this_file.startswith('./'):
                this_file = this_file[2:]
            
            # create/save a shell script that replaces this script with the new one
            f = open('update_wifite.sh','w')
            f.write('''#!/bin/sh\n
                       rm -rf ''' + this_file + '''\n
                       mv wifite_new.py ''' + this_file + '''\n
                       rm -rf update_wifite.sh\n
                       chmod +x ''' + this_file + '''\n
                      ''')
            f.close()
            
            # Change permissions on the script
            returncode = call(['chmod','+x','update_wifite.sh'])
            if returncode != 0:
                print R+' [!]'+O+' permission change returned unexpected code: '+str(returncode)+W
                exit_gracefully(1)
            # Run the script
            returncode = call(['sh','update_wifite.sh'])
            if returncode != 0:
                print R+' [!]'+O+' upgrade script returned unexpected code: '+str(returncode)+W
                exit_gracefully(1)
            
            print GR+' [+] '+G+'updated!'+W+' type "./' + this_file + '" to run again'
            
        else:
            print GR+' [-]'+W+' your copy of wifite is '+G+'up to date'+W
            
    except KeyboardInterrupt:
        print R+'\n (^C)'+O+' wifite upgrade interrupted'+W
    exit_gracefully(0)
def upgrade ( ) : global RUN_CONFIG try : print GR + ' [!]' + W + ' upgrading requires an ' + G + 'internet connection' + W print GR + ' [+]' + W + ' checking for latest version...' revision = get_revision ( ) if revision == - 1 : print R + ' [!]' + O + ' unable to access GitHub' + W elif revision > RUN_CONFIG . REVISION : print GR + ' [!]' + W + ' a new version is ' + G + 'available!' + W print GR + ' [-]' + W + '   revision:    ' + G + str ( revision ) + W response = raw_input ( GR + ' [+]' + W + ' do you want to upgrade to the latest version? (y/n): ' ) if not response . lower ( ) . startswith ( 'y' ) : print GR + ' [-]' + W + ' upgrading ' + O + 'aborted' + W exit_gracefully ( 0 ) return # Download script, replace with this one print GR + ' [+] ' + G + 'downloading' + W + ' update...' try : sock = urllib . urlopen ( 'https://github.com/derv82/wifite/raw/master/wifite.py' ) page = sock . read ( ) except IOError : page = '' if page == '' : print R + ' [+] ' + O + 'unable to download latest version' + W exit_gracefully ( 1 ) # Create/save the new script f = open ( 'wifite_new.py' , 'w' ) f . write ( page ) f . close ( ) # The filename of the running script this_file = __file__ if this_file . startswith ( './' ) : this_file = this_file [ 2 : ] # create/save a shell script that replaces this script with the new one f = open ( 'update_wifite.sh' , 'w' ) f . write ( '''#!/bin/sh\n
                       rm -rf ''' + this_file + '''\n
                       mv wifite_new.py ''' + this_file + '''\n
                       rm -rf update_wifite.sh\n
                       chmod +x ''' + this_file + '''\n
                      ''' ) f . close ( ) # Change permissions on the script returncode = call ( [ 'chmod' , '+x' , 'update_wifite.sh' ] ) if returncode != 0 : print R + ' [!]' + O + ' permission change returned unexpected code: ' + str ( returncode ) + W exit_gracefully ( 1 ) # Run the script returncode = call ( [ 'sh' , 'update_wifite.sh' ] ) if returncode != 0 : print R + ' [!]' + O + ' upgrade script returned unexpected code: ' + str ( returncode ) + W exit_gracefully ( 1 ) print GR + ' [+] ' + G + 'updated!' + W + ' type "./' + this_file + '" to run again' else : print GR + ' [-]' + W + ' your copy of wifite is ' + G + 'up to date' + W except KeyboardInterrupt : print R + '\n (^C)' + O + ' wifite upgrade interrupted' + W exit_gracefully ( 0 )