fix for windows input

This commit is contained in:
Jan Rude
2014-08-24 16:07:55 +02:00
parent 25b91fa41c
commit d6e3d017da

View File

@@ -10,6 +10,8 @@ import requests
import urllib2 import urllib2
from colorama import Fore from colorama import Fore
from lib import settings from lib import settings
if sys.platform.startswith('win32') or sys.platform.startswith('cygwin'):
import msvcrt
# Searching Typo3 login page # Searching Typo3 login page
def search_login(): def search_login():
@@ -21,32 +23,37 @@ def search_login():
return check_title(httpResponse, r.url) return check_title(httpResponse, r.url)
elif (statusCode == 301) or (statusCode == 302): elif (statusCode == 301) or (statusCode == 302):
location = r.headers['location'] location = r.headers['location']
redirect = raw_input('Got redirect to: ' + str(location) + '\nFollow? (y/n) ') answer = ''
if redirect is 'y': 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('/') locsplit = location.split('/')
settings.DOMAIN = locsplit[0] + '//' + locsplit[2] settings.DOMAIN = locsplit[0] + '//' + locsplit[2]
return "redirect" return 'redirect'
else: else:
return check_title(httpResponse, r.url) return check_title(httpResponse, r.url)
elif statusCode == 404: elif statusCode == 404:
return False return False
else: 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: except requests.exceptions.Timeout:
print Fore.RED + "Connection timed out" + Fore.RESET print Fore.RED + 'Connection timed out' + Fore.RESET
except requests.exceptions.TooManyRedirects: 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: except requests.exceptions.RequestException as e:
print Fore.RED + str(e) + Fore.RESET print Fore.RED + str(e) + Fore.RESET
# Searching for Typo3 references in title # Searching for Typo3 references in title
def check_title(response, url): def check_title(response, url):
try: try:
regex = re.compile("<title>(.*)</title>", re.IGNORECASE) regex = re.compile('<title>(.*)</title>', re.IGNORECASE)
searchTitle = regex.search(response) searchTitle = regex.search(response)
title = searchTitle.groups()[0] title = searchTitle.groups()[0]
if 'TYPO3' in title or 'TYPO3 SVN ID:' in response: 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 return True
except: except:
pass pass
@@ -65,15 +72,15 @@ def check_main_page():
if 'fe_typo_user' in cookie: if 'fe_typo_user' in cookie:
return bad_url() return bad_url()
except KeyboardInterrupt: except KeyboardInterrupt:
print Fore.RED + "\nReceived keyboard interrupt.\nQuitting..." + Fore.RESET print Fore.RED + '\nReceived keyboard interrupt.\nQuitting...' + Fore.RESET
exit(-1) exit(-1)
except: except:
try: try:
regex = re.compile("TYPO3(.*)", re.IGNORECASE) regex = re.compile('TYPO3(.*)', re.IGNORECASE)
searchHTML = regex.search(response) searchHTML = regex.search(response)
searchHTML.groups()[0] searchHTML.groups()[0]
try: 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) searchVersion = regex.search(response)
version = searchVersion.groups() version = searchVersion.groups()
settings.TYPO_VERSION = 'Typo3 ' + version[0].split()[0] settings.TYPO_VERSION = 'Typo3 ' + version[0].split()[0]
@@ -83,18 +90,23 @@ def check_main_page():
except: except:
pass pass
except Exception, e: except Exception, e:
if "404" in str(e): if '404' in str(e):
print Fore.RED + str(e) + "\nPlease ensure you entered the right url" + Fore.RESET print Fore.RED + str(e) + '\nPlease ensure you entered the right url' + Fore.RESET
else: else:
print Fore.RED + str(e) + Fore.RESET print Fore.RED + str(e) + Fore.RESET
return "skip" return 'skip'
return False return False
def bad_url(): def bad_url():
print "Typo3 Login:".ljust(32) + Fore.GREEN + "Typo3 is used, but could not find login" + Fore.RESET 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) + 'This could result in \'no extensions are installed\'.'
print "".ljust(32) + "Seems like something is wrong with the given url." print ''.ljust(32) + 'Seems like something is wrong with the given url.'
var = raw_input("".ljust(32) + "Try anyway (y/n)? ") answer = ''
if var is 'y': 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 True
return "skip" return 'skip'