From d6e3d017da83cc3cf634188923289a34a696dc96 Mon Sep 17 00:00:00 2001 From: Jan Rude Date: Sun, 24 Aug 2014 16:07:55 +0200 Subject: [PATCH] fix for windows input --- lib/login.py | 52 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/lib/login.py b/lib/login.py index 00e5b6b..ce71ff9 100644 --- a/lib/login.py +++ b/lib/login.py @@ -10,6 +10,8 @@ import requests import urllib2 from colorama import Fore from lib import settings +if sys.platform.startswith('win32') or sys.platform.startswith('cygwin'): + import msvcrt # Searching Typo3 login page def search_login(): @@ -21,32 +23,37 @@ def search_login(): return check_title(httpResponse, r.url) elif (statusCode == 301) or (statusCode == 302): location = r.headers['location'] - redirect = raw_input('Got redirect to: ' + str(location) + '\nFollow? (y/n) ') - if redirect is 'y': + answer = '' + if sys.platform.startswith('win32') or sys.platform.startswith('cygwin'): + print 'Got redirect to: ' + str(location) + '\nFollow? (y/n) ' + answer = msvcrt.getche() + elif sys.platform.startswith('linux'): + answer = raw_input('Got redirect to: ' + str(location) + '\nFollow? (y/n) ') + if answer is 'y': locsplit = location.split('/') settings.DOMAIN = locsplit[0] + '//' + locsplit[2] - return "redirect" + return 'redirect' else: return check_title(httpResponse, r.url) elif statusCode == 404: return False else: - print "Oops! Got unhandled code:".ljust(32) + str(statusCode) + ": " + str(r.raise_for_status()) + print 'Oops! Got unhandled code:'.ljust(32) + str(statusCode) + ': ' + str(r.raise_for_status()) except requests.exceptions.Timeout: - print Fore.RED + "Connection timed out" + Fore.RESET + print Fore.RED + 'Connection timed out' + Fore.RESET except requests.exceptions.TooManyRedirects: - print Fore.RED + "Too many redirects" + Fore.RESET + print Fore.RED + 'Too many redirects' + Fore.RESET except requests.exceptions.RequestException as e: print Fore.RED + str(e) + Fore.RESET # Searching for Typo3 references in title def check_title(response, url): try: - regex = re.compile("(.*)", re.IGNORECASE) + regex = re.compile('(.*)', re.IGNORECASE) searchTitle = regex.search(response) title = searchTitle.groups()[0] if 'TYPO3' in title or 'TYPO3 SVN ID:' in response: - print "Typo3 Login:".ljust(32) + Fore.GREEN + url + Fore.RESET + print 'Typo3 Login:'.ljust(32) + Fore.GREEN + url + Fore.RESET return True except: pass @@ -65,15 +72,15 @@ def check_main_page(): if 'fe_typo_user' in cookie: return bad_url() except KeyboardInterrupt: - print Fore.RED + "\nReceived keyboard interrupt.\nQuitting..." + Fore.RESET + print Fore.RED + '\nReceived keyboard interrupt.\nQuitting...' + Fore.RESET exit(-1) except: try: - regex = re.compile("TYPO3(.*)", re.IGNORECASE) + regex = re.compile('TYPO3(.*)', re.IGNORECASE) searchHTML = regex.search(response) searchHTML.groups()[0] try: - regex = re.compile("[Tt][Yy][Pp][Oo]3 (\d{1,2}\.\d{1,2}\.[0-9][0-9]?[' '\n])") + regex = re.compile('[Tt][Yy][Pp][Oo]3 (\d{1,2}\.\d{1,2}\.[0-9][0-9]?[' '\n])') searchVersion = regex.search(response) version = searchVersion.groups() settings.TYPO_VERSION = 'Typo3 ' + version[0].split()[0] @@ -83,18 +90,23 @@ def check_main_page(): except: pass except Exception, e: - if "404" in str(e): - print Fore.RED + str(e) + "\nPlease ensure you entered the right url" + Fore.RESET + if '404' in str(e): + print Fore.RED + str(e) + '\nPlease ensure you entered the right url' + Fore.RESET else: print Fore.RED + str(e) + Fore.RESET - return "skip" + return 'skip' return False def bad_url(): - print "Typo3 Login:".ljust(32) + Fore.GREEN + "Typo3 is used, but could not find login" + Fore.RESET - print "".ljust(32) + "This could result in \"no extensions are installed\"." - print "".ljust(32) + "Seems like something is wrong with the given url." - var = raw_input("".ljust(32) + "Try anyway (y/n)? ") - if var is 'y': + print 'Typo3 Login:'.ljust(32) + Fore.GREEN + 'Typo3 is used, but could not find login' + Fore.RESET + print ''.ljust(32) + 'This could result in \'no extensions are installed\'.' + print ''.ljust(32) + 'Seems like something is wrong with the given url.' + answer = '' + if sys.platform.startswith('win32') or sys.platform.startswith('cygwin'): + print ''.ljust(32) + 'Try anyway (y/n)? ' + answer = msvcrt.getch() + elif sys.platform.startswith('linux'): + answer = raw_input(''.ljust(32) + 'Try anyway (y/n)? ') + if answer is 'y': return True - return "skip" \ No newline at end of file + return 'skip'