Пример #1
0
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')
Пример #2
0
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)
Пример #3
0
def set_lang():
    lang = 'it'
    if request.args.get('lang'):
        lang = request.args.get('lang')

    logger.write(Logging.DEB, "Setting language to: " + lang)
    config_data = {'lang': lang}
    FileManagement.update_json(config_path, config_data, log_path)

    return redirect('/')
Пример #4
0
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('/')
Пример #5
0
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'])
Пример #6
0
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'])
Пример #7
0
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)
Пример #8
0
def test_sub_page():
    page = request.args.get('page')

    lang = 'it'
    if request.args.get('lang'):
        lang = request.args.get('lang')

    logger.write(Logging.DEB, "Test sub page: " + page)

    translation_json = {}
    if lang in language_set:
        translation_json = FileManagement.read_json(
            translations_dir_path + lang + '.json', log_path)

    translation_sub = {'TITLE': "", 'MESSAGE': ""}
    img_path = None

    if page == "dfail":
        if 'TITLE_DOWNLOAD_FAIL' in translation_json:
            translation_sub['TITLE'] = translation_json['TITLE_DOWNLOAD_FAIL']
        if 'MESSAGE_DOWNLOAD_FAIL' in translation_json:
            translation_sub['MESSAGE'] = translation_json[
                'MESSAGE_DOWNLOAD_FAIL']

        img_path = 'huel.gif'
    elif page == "sdown":
        if 'TITLE_SHUTDOWN' in translation_json:
            translation_sub['TITLE'] = translation_json['TITLE_SHUTDOWN']
        if 'MESSAGE_SHUTDOWN' in translation_json:
            translation_sub['MESSAGE'] = translation_json['MESSAGE_SHUTDOWN']

        img_path = 'hippie.gif'
    elif page == "cfail":
        if 'TITLE_CONFIG_FAIL' in translation_json:
            translation_sub['TITLE'] = translation_json['TITLE_CONFIG_FAIL']
        if 'MESSAGE_CONFIG_FAIL' in translation_json:
            translation_sub['MESSAGE'] = translation_json[
                'MESSAGE_CONFIG_FAIL']
    else:
        if 'TITLE_404' in translation_json:
            translation_sub['TITLE'] = translation_json['TITLE_404']
        if 'MESSAGE_404' in translation_json:
            translation_sub['MESSAGE'] = translation_json['MESSAGE_404']

        img_path = 'sexy_priest.gif'

    return render_template('/sub_page.html',
                           translations=translation_sub,
                           lang=lang,
                           img_path=img_path,
                           debug=True,
                           have_home=True)
Пример #9
0
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
Пример #10
0
    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
Пример #11
0
                ip = sys.argv[1]
                logger.write(Logging.INF,
                             "IP address passed from rc.local: " + ip)

    for file in os.listdir(translations_dir_path):
        if file.endswith('.json'):
            language_set.add(os.path.splitext(file)[0])

    if ip is None:
        for attempt in range(10):
            try:
                ip = get_ip()
                if ip is not None:
                    logger.write(Logging.INF, "IP address found socket: " + ip)

                    FileManagement.update_json(config_path, {'ip': ip},
                                               log_path)
                    app.run(debug=True, host='0.0.0.0')

                    break

            except Exception as e:
                logger.write(Logging.ERR,
                             "Unable to get Hostname and IP: " + str(e))

            time.sleep(1)

        if ip is None:
            FileManagement.update_json(config_path, {'ip': ''}, log_path)


def exit_handler():