Add option to upload crash details

* Disabled by default, enabled via main.py ENABLE_UPLOAD_DATA
* Upload destination set via main.py CRASH_SERVER variable
This commit is contained in:
2Shirt 2018-01-28 17:48:42 -07:00
parent 8e05cb0e40
commit c24554720f
2 changed files with 139 additions and 84 deletions

View file

@ -255,7 +255,20 @@ def major_exception():
print_warning(SUPPORT_MESSAGE)
print(traceback.format_exc())
print_log(traceback.format_exc())
sleep(30)
try:
upload_crash_details()
except GenericAbort:
# User declined upload
print_warning('Upload: Aborted')
sleep(30)
except GenericError:
# No log file or uploading disabled
sleep(30)
except:
print_error('Upload: NS')
sleep(30)
else:
print_success('Upload: CS')
pause('Press Enter to exit...')
exit_script(1)
@ -515,6 +528,42 @@ def try_and_print(message='Trying...',
else:
return {'CS': not bool(err), 'Error': err, 'Out': out}
def upload_crash_details():
if not ENABLED_UPLOAD_DATA:
raise GenericError
import requests
if 'LogFile' in global_vars and global_vars['LogFile']:
if ask('Upload crash details to {}?'.format(CRASH_SERVER['Name'])):
with open(global_vars['LogFile']) as f:
data = '''{}
#############################
Runtime Details:
sys.argv: {}
global_vars: {}'''.format(f.read(), sys.argv, global_vars)
filename = global_vars.get('LogFile', 'Unknown')
filename = re.sub(r'.*(\\|/)', '', filename)
filename += '.txt'
url = '{}/Crash_{}__{}'.format(
CRASH_SERVER['Url'],
global_vars.get('Date-Time', 'Unknown Date-Time'),
filename)
r = requests.put(url, data=data,
headers = {'X-Requested-With': 'XMLHttpRequest'},
auth = (CRASH_SERVER['User'], CRASH_SERVER['Pass']))
# Raise exception if upload NS
if not r.ok:
raise Exception
else:
# User said no
raise GenericAbort
else:
# No LogFile defined (or invalid LogFile)
raise GenericError
def upload_data(path, file):
"""Add CLIENT_INFO_SERVER to authorized connections and upload file."""
if not ENABLED_UPLOAD_DATA:

View file

@ -54,6 +54,12 @@ CLIENT_INFO_SERVER = {
'Share': '/srv/ClientInfo',
'User': 'upload',
}
CRASH_SERVER = {
'Name': 'CrashServer',
'Url': '',
'User': '',
'Pass': '',
}
OFFICE_SERVER = {
'IP': OFFICE_SERVER_IP,
'Name': 'ServerOne',