Beispiel #1
0
def channel_list():
    if request.method == "POST":
        action = request.form.get('@action', '')
        if action == "new":
            name = request.form.get('name')
            module = request.form.get('module')
            if module in get_modules_names(current_app.config["PLUGINS"].keys()):
                channel = Channel(name=name, module=get_module_full_name(module), config="{}")
                db.session.add(channel)
                db.session.commit()
        elif action == "delete":
            channel_id = request.form.get("id")
            channel = Channel.query.get(channel_id)
            if channel:
                db.session.delete(channel)
                db.session.commit()
        elif action == "edit":
            channel_id = request.form.get("id")
            channel = Channel.query.get(channel_id)
            name = request.form.get('name')
            if name is not '':
                channel.name = name
                conf = json.loads(channel.config)
                conf["channel_name"] = name
                channel.config = json.dumps(conf)
                db.session.commit()

    channels = Channel.query.all()
    return render_template("channels.html", channels=channels,
                           modules=get_modules_names(current_app.config["PLUGINS"].keys()))
def add_channel(channel_name, module, config):
    channel = Channel()
    channel.name = channel_name
    channel.module = get_module_full_name(module)
    channel.config = config

    db.session.add(channel)
    db.session.commit()
def channel_list():
    if request.method == "POST":
        action = request.form.get('@action', '')
        if action == "new":
            name = request.form.get('name')
            username = request.form.get('username')
            password = request.form.get('password')
            module = request.form.get('module')
            if module in get_modules_names(
                    current_app.config["PLUGINS"].keys()):
                channel = Channel(name=name,
                                  module=get_module_full_name(module),
                                  config="{}")
                db.session.add(channel)
                db.session.flush()
                keepass.set_entry_from_data(str(channel.id), username,
                                            password)
                keepass.add_entry_in_group(module)
                db.session.commit()

        elif action == "delete":
            channel_id = request.form.get("id")
            channel = Channel.query.get(channel_id)
            if channel:
                db.session.delete(channel)
                db.session.commit()
                keepass.delete_entry(channel_id)
        elif action == "edit":
            channel_id = request.form.get("id")
            channel = Channel.query.get(channel_id)
            name = request.form.get('name')
            username = request.form.get('username')
            password = request.form.get('password')
            if name is not '':
                channel.name = name
                conf = json.loads(channel.config)
                conf["channel_name"] = name
                channel.config = json.dumps(conf)
                db.session.commit()
            if username is not '' or password is not '':
                keepass.set_entry_from_data(str(channel.id), username,
                                            password)
                keepass.modify_entry_in_group(
                    get_modules_names([channel.module])[0], channel.id)

    channels = Channel.query.all()
    mods = get_modules_names(current_app.config["PLUGINS"].keys())

    auth_fields = dict()

    for m in mods:
        full_name = get_module_full_name(m)
        clas = get_instance_from_module_path(full_name)
        fields = clas.AUTH_FIELDS
        auth_fields[m] = fields

    return render_template("channels.html",
                           channels=channels,
                           modules=get_modules_names(
                               current_app.config["PLUGINS"].keys()),
                           auth_fields=auth_fields)