コード例 #1
0
ファイル: service.py プロジェクト: lizter/EIT_ORK
def configuration():
    form = ConfigForm()
    db = get_db()

    if request.method == 'POST':
        if form.validate_on_submit():
            db.execute('UPDATE configuration SET width=?, height=?, area=?, hinge=?, angle=?, draftthreshold=?, enginepower=? WHERE window_id=?',[
                form.window_width.data, 
                form.window_height.data, 
                form.area.data, 
                form.window_hinge.data, 
                form.window_direction.data, 
                form.draft.data,
                form.enginepower.data,
                ACTIVE_WINDOW])
            db.commit()
            flash('Configuration updated', 'success')
        else:
            flash('Invalid input', 'danger')

    config = query_db('SELECT * FROM configuration WHERE window_id=?', [ACTIVE_WINDOW], one=True)
    if config is None:
        flash('No configuration set', 'danger')
        return render_template('configuration.html', form=form)

    form = ConfigForm(
        window_width=config['width'], 
        window_height=config['height'], 
        area=config['area'], 
        window_direction=config['angle'], 
        draft=config['draftthreshold'], 
        window_hinge=config['hinge'],
        enginepower=config['enginepower'])
    return render_template('configuration.html', form = form)
コード例 #2
0
def config():
    if not is_admin():
        return redirect(url_for("bp_main.home"))

    pcfg = {"title": "Application Config"}

    _config = Config.query.one()
    if not _config:
        flash("Config not found", "error")
        return redirect(url_for("bp_main.home"))

    form = ConfigForm(request.form, obj=_config)

    if form.validate_on_submit():
        _config.clublog_api_key = form.clublog_api_key.data
        _config.eqsl_download_url = form.eqsl_download_url.data
        _config.eqsl_rcvd_mark = form.eqsl_rcvd_mark.data
        _config.eqsl_upload_url = form.eqsl_upload_url.data
        _config.lotw_download_url = form.lotw_download_url.data
        _config.lotw_upload_url = form.lotw_upload_url.data
        _config.lotw_login_url = form.lotw_login_url.data
        _config.lotw_rcvd_mark = form.lotw_rcvd_mark.data

        db.session.commit()
        flash("Configuration updated", "info")
        return redirect(url_for("bp_admin.config"))

    return render_template("admin/config.jinja2", pcfg=pcfg, form=form)
コード例 #3
0
ファイル: app.py プロジェクト: Xen0n6291/ExaBGPmon
def config():

    config_form = ConfigForm()
    peer_form = BGPPeer()
    
    if config_form.validate_on_submit():
        
        bgp_config.update(bgp_config.find_one(), 
            {'$set': {
                'local-as': int(config_form.asn.data),
                'router-id': config_form.router_id.data,
                'local-address': config_form.local_ip.data
            }
        })

        flash('Config successfully updated.', 'success')
        return redirect(url_for('config', _anchor='exabgp'))

    if peer_form.validate_on_submit():
            
        try:
            # Create the new peer
            new_peer = {
                'ip': peer_form.ip_address.data,
                'asn': int(peer_form.asn.data),
                'state': 'down',
                'enabled': peer_form.enabled.data
            }

            bgp_peers.insert_one(new_peer)
        except:
            flash('Error adding peer %s.' % peer_form.ip_address.data, 'warning')
        else:
            flash('Peer %s added' % peer_form.ip_address.data, 'success')

        return redirect(url_for('config', _anchor='peers'))

    else:

        peers = list(bgp_peers.find())
        config = bgp_config.find_one()
        prefix_counts = {}
        for peer in bgp_peers.find():
            prefix_counts[peer['ip']] = {
                'received': len(bgp_peers.distinct('current_prefixes', {'ip': {'$eq': peer['ip']}})),
                'advertised': len(adv_routes.distinct('prefix', {'peer': {'$eq': peer['ip']}}))
            }

        config_form.asn.data = config['local-as']
        config_form.router_id.data = config['router-id']
        config_form.local_ip.data = config['local-address']

        return render_template('config.html', peers=peers, config=config, 
            config_form=config_form, peer_form=peer_form, prefix_counts=prefix_counts)
コード例 #4
0
ファイル: app.py プロジェクト: DDecoene/ExaBGPmon
def config():
    config_form = ConfigForm()
    peer_form = BGPPeer()

    if config_form.validate_on_submit():
        bgp_config.update(bgp_config.find_one(),
                          {'$set': {
                              'local-as': int(config_form.asn.data),
                              'router-id': config_form.router_id.data,
                              'local-address': config_form.local_ip.data
                          }
                          })

        flash('Config successfully updated.', 'success')
        return redirect(url_for('config', _anchor='exabgp'))

    if peer_form.validate_on_submit():

        try:
            # Create the new peer
            new_peer = {
                'ip': peer_form.ip_address.data,
                'asn': int(peer_form.asn.data),
                'state': 'down',
                'enabled': peer_form.enabled.data
            }

            bgp_peers.insert_one(new_peer)
        except:
            flash('Error adding peer %s.' % peer_form.ip_address.data, 'warning')
        else:
            flash('Peer %s added' % peer_form.ip_address.data, 'success')

        return redirect(url_for('config', _anchor='peers'))

    else:

        peers = list(bgp_peers.find())
        config = bgp_config.find_one()
        prefix_counts = {}
        for peer in bgp_peers.find():
            prefix_counts[peer['ip']] = {
                'received': len(bgp_peers.distinct('current_prefixes', {'ip': {'$eq': peer['ip']}})),
                'advertised': len(adv_routes.distinct('prefix', {'peer': {'$eq': peer['ip']}}))
            }

        config_form.asn.data = config['local-as']
        config_form.router_id.data = config['router-id']
        config_form.local_ip.data = config['local-address']

        return render_template('config.html', peers=peers, config=config,
                               config_form=config_form, peer_form=peer_form, prefix_counts=prefix_counts)
コード例 #5
0
ファイル: app.py プロジェクト: tmuehl/saiki-pemetaan
def topics_config():
    """Docstring."""
    if only_check():
        if request.method == 'POST':
            cform = ConfigForm()
            cform.validate_on_submit()  # to get error messages to the browser
            # if cform.validate() is False:
            #     flash('Please check that all the fields are valid!.',
            #           'critical')
            #     return check_and_render('topics_config.html',
            #                             form=cform)
            # else:
            update_config(cform)
            flash('updated Config for Topic : ' + cform.topic.data)
            return redirect(url_for('topics'))
        elif request.method == 'GET':
            topic_name = request.args.get('topic')
            config = get_config(topic_name)
            conv_config = config_convert_to_python(config)
            cform = ConfigForm(topic=topic_name, **conv_config)
            return check_and_render('topics_config.html',
                                    form=cform)
    else:
        return check_and_render('index.html')
コード例 #6
0
ファイル: views.py プロジェクト: avr39-ripe/tut
def config():
    form = ConfigForm()
    if form.validate_on_submit():
#        flash("" + str(form.temp_set.data) + " " +  str(form.temp_delta.data) + " " + str(form.valve_work.data) + " " + str(form.valve_delta.data))
        app.cfg['temp_set'] = float(form.temp_set.data)
        app.cfg['temp_delta'] = float(form.temp_delta.data)
        app.cfg['valve_work'] = float(form.valve_work.data)
        app.cfg['valve_delta'] = float(form.valve_delta.data)

        f=open('/home/pi/reletherm.cfg', 'w')
        yaml.dump(app.cfg,f)
        f.close()
        os.system('/home/pi/reletherm.py restart')
	
        return render_template('config.html', form = form, cfg = app.cfg, success = True)
    return render_template('config.html', form = form, cfg = app.cfg)
コード例 #7
0
def config_page():
    form = ConfigForm()
    if form.validate_on_submit():
        flash('requested for user {}, {}'.format(form.ssid.data,
                                                 form.email.data))
        print(form.ssid.data, form.email.data, form.ip_address.data)
        ssid = form.ssid.data
        password = form.password.data
        if on_raspi:
            wifi_connect(ssid, password)
            sys.exit(0)
        return redirect('/')
    else:
        for field, error in form.errors.items():
            flash(
                f'Troubles with field {getattr(form, field).label.text}: {" ".join(error)}'
            )
    return render_template('config.html', title='config', form=form)
コード例 #8
0
def config():
    if not is_admin():
        return redirect(url_for("bp_main.home"))

    pcfg = {"title": gettext("Application Config")}

    _config = Config.query.one()
    if not _config:
        flash(gettext("Config not found"), "error")
        return redirect(url_for("bp_main.home"))

    form = ConfigForm(request.form, obj=_config)

    if form.validate_on_submit():
        _config.app_name = form.app_name.data
        _config.app_description = form.app_description.data

        db.session.commit()
        flash(gettext("Configuration updated"), "info")
        return redirect(url_for("bp_admin.config"))

    return render_template("admin/config.jinja2", pcfg=pcfg, form=form)
コード例 #9
0
    def set_config():
        # return the response generated along with the specific media
        # type (mime type)
        form = ConfigForm()

        if request.method == 'POST':
            if form.validate_on_submit():
                spectro_pointer_config = {}
                spectro_pointer_config[
                    'use_raspberry'] = form.use_raspberry.data
                spectro_pointer_config[
                    'correct_vertical_camera'] = form.correct_vertical_camera.data
                spectro_pointer_config[
                    'correct_horizontal_camera'] = form.correct_horizontal_camera.data
                spectro_pointer_config[
                    'center_radius'] = form.center_radius.data
                spectro_pointer_config[
                    'show_center_circle'] = form.show_center_circle.data
                spectro_pointer_config['enable_photo'] = form.enable_photo.data
                spectro_pointer_config['enable_video'] = form.enable_video.data
                spectro_pointer_config[
                    'record_seconds'] = form.record_seconds.data
                spectro_pointer_config['threshold'] = form.threshold.data

                spectro_pointer_config['resolution'] = form.resolution.data
                spectro_pointer_config['framerate'] = form.framerate.data
                spectro_pointer_config['sensor_mode'] = form.sensor_mode.data
                spectro_pointer_config[
                    'shutter_speed'] = form.shutter_speed.data
                spectro_pointer_config['iso'] = form.iso.data

                with lock:
                    set_sp_config(app, **spectro_pointer_config)
                    update_params(app, set_camera_attr_en=True)

            return redirect(url_for('set_config'))
        else:
            form.use_raspberry.render_kw = {
                'value': get_sp_config('USE_RASPBERRY', app)
            }
            form.correct_vertical_camera.render_kw = {
                'value': get_sp_config('CORRECT_VERTICAL_CAMERA', app)
            }
            form.correct_horizontal_camera.render_kw = {
                'value': get_sp_config('CORRECT_HORIZONTAL_CAMERA', app)
            }
            form.center_radius.render_kw = {
                'value': get_sp_config('CENTER_RADIUS', app)
            }
            form.show_center_circle.render_kw = {
                'value': get_sp_config('SHOW_CENTER_CIRCLE', app)
            }
            form.enable_photo.render_kw = {
                'value': get_sp_config('ENABLE_PHOTO', app)
            }
            form.enable_video.render_kw = {
                'value': get_sp_config('ENABLE_VIDEO', app)
            }
            form.record_seconds.render_kw = {
                'value': get_sp_config('RECORD_SECONDS', app)
            }
            form.threshold.render_kw = {
                'value': get_sp_config('THRESHOLD', app)
            }

            form.resolution.data = get_sp_config('RESOLUTION', app)
            form.framerate.render_kw = {
                'value': get_sp_config('FRAMERATE', app)
            }
            form.sensor_mode.render_kw = {
                'value': get_sp_config('SENSOR_MODE', app)
            }
            form.shutter_speed.render_kw = {
                'value': get_sp_config('SHUTTER_SPEED', app)
            }
            form.iso.render_kw = {'value': get_sp_config('ISO', app)}

            form.use_raspberry.label = 'USE RASPBERRY:'
            form.correct_vertical_camera.label = 'CORRECT VERTICAL CAMERA:'
            form.correct_horizontal_camera.label = 'CORRECT HORIZONTAL CAMERA:'
            form.center_radius.label = 'CENTER RADIUS:'
            form.show_center_circle.label = 'SHOW CENTER CIRCLE:'
            form.enable_photo.label = 'ENABLE PHOTO:'
            form.enable_video.label = 'ENABLE VIDEO:'
            form.record_seconds.label = 'RECORD SECONDS:'
            form.threshold.label = 'THRESHOLD:'

            form.resolution.label = 'RESOLUTION:'
            form.framerate.label = 'FRAMERATE:'
            form.sensor_mode.label = 'SENSOR_MODE:'
            form.shutter_speed.label = 'SHUTTER_SPEED:'
            form.iso.label = 'ISO:'

        return render_template("config.html", form=form)