def not_found(e): logger.write(Logging.ERR, str(e) + ": " + request.base_url) config_data = DataExtraction.fix_config_data( FileManagement.read_json(config_path, log_path), colour_key, pattern_key, brightness_key, config_path, log_path) translation_json = {} if config_data['lang'] in language_set: translation_json = FileManagement.read_json( translations_dir_path + config_data['lang'] + '.json', log_path) translations_404 = {'TITLE': "", 'MESSAGE': ""} if 'TITLE_404' in translation_json: translations_404['TITLE'] = translation_json['TITLE_404'] if 'MESSAGE_404' in translation_json: translations_404['MESSAGE'] = translation_json['MESSAGE_404'] return render_template('/sub_page.html', translations=translations_404, lang=config_data['lang'], img_path='sexy_priest.gif', have_home=True)
def shutdown(): logger.write(Logging.INF, "Attempting shutdown") config_data = DataExtraction.fix_config_data( FileManagement.read_json(config_path, log_path), colour_key, pattern_key, brightness_key, config_path, log_path) try: shutdown_T = threading.Thread(target=shutdown_thread, args=(5, )) shutdown_T.start() except Exception as e: logger.write(Logging.ERR, "Failed to shutdown: " + str(e)) translation_json = {} if config_data['lang'] in language_set: translation_json = FileManagement.read_json( translations_dir_path + config_data['lang'] + '.json', log_path) translations_shutdown = {'TITLE': "", 'MESSAGE': ""} if 'TITLE_SHUTDOWN' in translation_json: translations_shutdown['TITLE'] = translation_json['TITLE_SHUTDOWN'] if 'MESSAGE_SHUTDOWN' in translation_json: translations_shutdown['MESSAGE'] = translation_json['MESSAGE_SHUTDOWN'] return render_template('/sub_page.html', translations=translations_shutdown, lang=config_data['lang'], img_path='hippie.gif')
def submit(): logger.write(Logging.INF, "Applying config") if 'apply' in request.form: try: colour = request.form.get('colour-picker') pattern_type = request.form.getlist('pattern-options') brightness = request.form.get('colour-brightness') if pattern_type is not None and len(pattern_type) > 0: pattern_type = pattern_type[0] logger.write( Logging.DEB, "Config change: " + colour + ", " + pattern_type + ", " + brightness) config_data = { colour_key: colour, pattern_key: pattern_type, 'brightness': brightness, 'ip': ip } FileManagement.update_json(config_path, config_data, log_path) except Exception as e: logger.write(Logging.ERR, "Error when saving config change: " + str(e)) config_data = DataExtraction.fix_config_data( FileManagement.read_json(config_path, log_path), colour_key, pattern_key, brightness_key, config_path, log_path) translation_json = {} if config_data['lang'] in language_set: translation_json = FileManagement.read_json( translations_dir_path + config_data['lang'] + '.json', log_path) translations_config_fail = {'TITLE': "", 'MESSAGE': ""} if 'TITLE_CONFIG_FAIL' in translation_json: translations_config_fail['TITLE'] = translation_json[ 'TITLE_CONFIG_FAIL'] if 'MESSAGE_CONFIG_FAIL' in translation_json: translations_config_fail['MESSAGE'] = translation_json[ 'MESSAGE_CONFIG_FAIL'] return render_template('/sub_page.html', translations=translations_config_fail, lang=config_data['lang'], have_home=True), 500 elif 'cancel' in request.form: logger.write(Logging.DEB, "Cancel clicked, so reseting page") return redirect('/')
def view_server_log(): logger.write(Logging.DEB, "View server logs") config_data = DataExtraction.fix_config_data( FileManagement.read_json(config_path, log_path), colour_key, pattern_key, brightness_key, config_path, log_path) translation_json = {} if config_data['lang'] in language_set: translation_json = FileManagement.read_json( translations_dir_path + config_data['lang'] + '.json', log_path) return render_template('/view_logs.html', log=logger.read(), translations=translation_json, lang=config_data['lang'])
def view_display_log(): logger.write(Logging.DEB, "View display logs") config_data = DataExtraction.fix_config_data( FileManagement.read_json(config_path, log_path), colour_key, pattern_key, brightness_key, config_path, log_path) translation_json = {} if config_data['lang'] in language_set: translation_json = FileManagement.read_json( translations_dir_path + config_data['lang'] + '.json', log_path) return render_template('/view_logs.html', log=FileManagement.read_file( str(my_path) + '/../log/visualiser_display.log'), translations=translation_json, lang=config_data['lang'])
def get_config(self, parse_ip): config_data, config_error = DataExtraction.verify_config_data( FileManagement.read_json(config_path, log_path), self.colour_key, self.pattern_key, self.brightness_key, log_path) ip = None if parse_ip: if 'ip' not in config_data or config_data['ip'] is None: logger.write( Logging.ERR, "IP address not found in config, please refer to guide to manually set config data and retrieve logs" ) ip = "No IP" else: ip = config_data['ip'] try: ip_regex = '^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$' if re.match(ip_regex, ip): logger.write(Logging.INF, "Valid IP address in config: " + ip) else: logger.write( Logging.ERR, "Config IP address does not match expected regex, please refer to guide to manually set config data and retrieve logs" ) ip = "No IP" except Exception as e: logger.write( Logging.ERR, "Config IP address regex error, please refer to guide to manually set config data and retrieve logs: " + str(e)) ip = "No IP" colour = config_data[self.colour_key] pattern = config_data[self.pattern_key] brightness = config_data[self.brightness_key] logger.write( Logging.INF, "Extracted config data- Colour: " + colour + ", Pattern: " + pattern + ", Brightness: " + brightness) return ip, colour, pattern, brightness
def libra(): logger.write(Logging.DEB, "Libra page") config_data = DataExtraction.fix_config_data( FileManagement.read_json(config_path, log_path), colour_key, pattern_key, brightness_key, config_path, log_path) if 'lang' not in config_data or not config_data['lang']: config_data['lang'] = 'it' FileManagement.update_json(config_path, config_data, log_path) translation_json = {} if config_data['lang'] in language_set: translation_json = FileManagement.read_json( translations_dir_path + config_data['lang'] + '.json', log_path) return render_template('/libra.html', colour_key=colour_key, config_data=config_data, translations=translation_json)
def download_logs(): logger.write(Logging.INF, "Downloading logs") log_zip_dir = str(my_path) + '/../' try: shutil.make_archive(base_dir='log', root_dir=log_zip_dir, format='zip', base_name=log_zip_dir + 'Visualiser_Logs') return send_file(log_zip_dir + 'Visualiser_Logs.zip', as_attachment=True) except Exception as e: logger.write(Logging.ERR, "Error when downloading logs: " + str(e)) config_data = DataExtraction.fix_config_data( FileManagement.read_json(config_path, log_path), colour_key, pattern_key, brightness_key, config_path, log_path) translation_json = {} if config_data['lang'] in language_set: translation_json = FileManagement.read_json( translations_dir_path + config_data['lang'] + '.json', log_path) translations_download_fail = {'TITLE': "", 'MESSAGE': ""} if 'TITLE_DOWNLOAD_FAIL' in translation_json: translations_download_fail['TITLE'] = translation_json[ 'TITLE_DOWNLOAD_FAIL'] if 'MESSAGE_DOWNLOAD_FAIL' in translation_json: translations_download_fail['MESSAGE'] = translation_json[ 'MESSAGE_DOWNLOAD_FAIL'] return render_template('/sub_page.html', translations=translations_download_fail, lang=config_data['lang'], img_path='huel.gif', have_home=True), 500