def io_config(): if utils.needs_user(): return flask.redirect(flask.url_for('setup')) if ('logged_in' not in flask.session) or (not flask.session['logged_in']): return flask.redirect(flask.url_for('login')) error = None if flask.request.method == 'POST': if "delete" in flask.request.form: io_id = int(flask.request.form['id']) utils.delete_io(io_id) flask.flash('IO Deleted') else: io_type = int(flask.request.form['type']) bus = int(flask.request.form['bus']) addr = int(flask.request.form['addr'], 16) if "edit" in flask.request.form: io_id = int(flask.request.form['edit']) utils.modify_io(io_id, io_type, bus, addr) flask.flash('IO Edited') else: utils.create_io(io_type, bus, addr) flask.flash('IO Created') ios = utils.get_ios() return flask.render_template( 'io_config.j2', error=error, ios=ios, smbio=smbio)
def action_config(): if utils.needs_user(): return flask.redirect(flask.url_for('setup')) if ('logged_in' not in flask.session) or (not flask.session['logged_in']): return flask.redirect(flask.url_for('login')) error = None if flask.request.method == 'POST': if "delete" in flask.request.form: action_id = int(flask.request.form['id']) utils.delete_action(action_id) flask.flash('Action Deleted') else: code = flask.request.form['code'] cmd = flask.request.form['cmd'] reason = flask.request.form['reason'] if "edit" in flask.request.form: action_id = int(flask.request.form['edit']) utils.modify_action(action_id, code, cmd, reason) flask.flash('Action Edited') else: utils.create_action(code, cmd, reason) flask.flash('Action Created') actions = utils.get_actions() return flask.render_template( 'action_config.j2', error=error, actions=actions, commands=Alarm.ACTIONS)
def indicator_config(): if utils.needs_user(): return flask.redirect(flask.url_for('setup')) if ('logged_in' not in flask.session) or (not flask.session['logged_in']): return flask.redirect(flask.url_for('login')) error = None if flask.request.method == 'POST': if "delete" in flask.request.form: indicator_id = int(flask.request.form['id']) utils.delete_indicator(indicator_id) flask.flash('Indicaor Deleted') else: interface_id = int(flask.request.form["interface_id"]) state = int(flask.request.form["state"]) if "edit" in flask.request.form: indicator_id = int(flask.request.form['edit']) utils.modify_indicator(indicator_id, interface_id, state) flask.flash('Indicator Edited') else: utils.create_indicator(interface_id, state) flask.flash('Indicator Created') interfaces = utils.get_interfaces() indicators = utils.get_indicators() return flask.render_template( 'indicator_config.j2', error=error, interfaces=interfaces, indicators=indicators, alarm_states=Alarm.ALARM_STATES)
def logs(): if utils.needs_user(): return flask.redirect(flask.url_for('setup')) if ('logged_in' not in flask.session) or (not flask.session['logged_in']): return flask.redirect(flask.url_for('login')) logs = utils.get_logs() return flask.render_template('logs.j2', mode="logs", logs=logs)
def dashboard(): if utils.needs_user(): return flask.redirect(flask.url_for('setup')) if ('logged_in' not in flask.session) or (not flask.session['logged_in']): return flask.redirect(flask.url_for('login')) running = utils.check_pid(Config["pidfile"]) tstate = utils.get_state("alarm_thread") tutime_s = "" trunning = False if tstate: trunning, tutime = tstate tutime_s = time.strftime("%c", time.localtime(tutime)) thread_state = {"running": bool(trunning), "utime": tutime_s} utime = time.strftime("%c", time.localtime()) state_text = "Not Runnning" flags = { "alarm": False, "armed": False, "disarmed": False, "tripped": False, "faulted": False } state_data = None alarm_state_d = utils.get_state("alarm") if alarm_state_d: alarm_state, state_time_i = alarm_state_d if alarm_state is not None: utime = time.strftime("%c", time.localtime(state_time_i)) state_text = Alarm.ALARM_STATES[alarm_state] flags["alarm"] = alarm_state == Alarm.ALARMED flags["disarmed"] = alarm_state == Alarm.DISARMED flags["tripped"] = alarm_state == Alarm.TRIPPED flags["faulted"] = alarm_state == Alarm.FAULT flags["armed"] = alarm_state == Alarm.ARMED states = utils.get_states_not("alarm", "alarm_thread") state_data = { state['key']: { 'data': state['data'], 'time': time.strftime("%c", time.localtime(state['state_time'])) } for state in states } interfaces = utils.get_interfaces() return flask.render_template('dashboard.j2', flags=flags, running=running, thread_state=thread_state, state_text=state_text, state_data=state_data, utime=utime, interfaces=interfaces, smbio=smbio)
def dashboard(): if utils.needs_user(): return flask.redirect(flask.url_for('setup')) if ('logged_in' not in flask.session) or (not flask.session['logged_in']): return flask.redirect(flask.url_for('login')) running = utils.check_pid(Config["pidfile"]) tstate = utils.get_state("alarm_thread") tutime_s = "" trunning = False if tstate: trunning, tutime = tstate tutime_s = time.strftime("%c", time.localtime(tutime)) thread_state = { "running": bool(trunning), "utime": tutime_s} utime = time.strftime("%c", time.localtime()) state_text = "Not Runnning" flags = { "alarm": False, "armed": False, "disarmed": False, "tripped": False, "faulted": False} state_data = None alarm_state_d = utils.get_state("alarm") if alarm_state_d: alarm_state, state_time_i = alarm_state_d if alarm_state is not None: utime = time.strftime("%c", time.localtime(state_time_i)) state_text = Alarm.ALARM_STATES[alarm_state] flags["alarm"] = alarm_state == Alarm.ALARMED flags["disarmed"] = alarm_state == Alarm.DISARMED flags["tripped"] = alarm_state == Alarm.TRIPPED flags["faulted"] = alarm_state == Alarm.FAULT flags["armed"] = alarm_state == Alarm.ARMED states = utils.get_states_not("alarm", "alarm_thread") state_data = { state['key']: { 'data': state['data'], 'time': time.strftime("%c", time.localtime(state['state_time']))} for state in states} interfaces = utils.get_interfaces() return flask.render_template( 'dashboard.j2', flags=flags, running=running, thread_state=thread_state, state_text=state_text, state_data=state_data, utime=utime, interfaces=interfaces, smbio=smbio)
def logs_alarms(): if utils.needs_user(): return flask.redirect(flask.url_for('setup')) if ('logged_in' not in flask.session) or (not flask.session['logged_in']): return flask.redirect(flask.url_for('login')) logs = utils.get_logs_errors() return flask.render_template( 'logs.j2', mode="alarms", logs=logs)
def setup(): if not utils.needs_user(): return flask.redirect(flask.url_for('login')) error = None if flask.request.method == 'POST': username = flask.request.form['username'] password = flask.request.form['password'] password_confirm = flask.request.form['password_confirm'] if password == password_confirm: utils.create_user(username, password) flask.flash('User Created') return flask.redirect(flask.url_for('login')) error = "passwords do not match" return flask.render_template('setup.j2', error=error)
def login(): if utils.needs_user(): return flask.redirect(flask.url_for('setup')) if 'logged_in' in flask.session and flask.session['logged_in']: return flask.redirect(flask.url_for('dashboard')) error = None if flask.request.method == 'POST': username = flask.request.form['username'] user = utils.get_user(username) if user: if utils.check_user_pass(user, flask.request.form['password']): flask.session['logged_in'] = True flask.session['username'] = user flask.flash('You were logged in') return flask.redirect(flask.url_for('dashboard')) error = "Invaid username or password" return flask.render_template('login.j2', error=error)
def users(): if utils.needs_user(): return flask.redirect(flask.url_for('setup')) if ('logged_in' not in flask.session) or (not flask.session['logged_in']): return flask.redirect(flask.url_for('login')) error = None if flask.request.method == 'POST': if "delete" in flask.request.form: if len(utils.get_users()) > 1: user_id = int(flask.request.form['id']) utils.delete_user(user_id) flask.flash('User Deleted') else: flask.flash("can not delete last user") else: username = flask.request.form['username'] user = utils.get_user(username) if (not user) or ("edit" in flask.request.form): password = flask.request.form['password'] password_confirm = flask.request.form['password_confirm'] if password == password_confirm: if "edit" in flask.request.form: user_id = int(flask.request.form['edit']) utils.modify_user(user_id, username, password) flask.flash('User Edited') else: utils.create_user(username, password) flask.flash('User Created') if "setup" in flask.request.form: return flask.redirect(flask.url_for('login')) else: error = "passwords do not match" else: error = "user already exists" users = utils.get_users() return flask.render_template( 'users.j2', users=users, error=error)
def users(): if utils.needs_user(): return flask.redirect(flask.url_for('setup')) if ('logged_in' not in flask.session) or (not flask.session['logged_in']): return flask.redirect(flask.url_for('login')) error = None if flask.request.method == 'POST': if "delete" in flask.request.form: if len(utils.get_users()) > 1: user_id = int(flask.request.form['id']) utils.delete_user(user_id) flask.flash('User Deleted') else: flask.flash("can not delete last user") else: username = flask.request.form['username'] user = utils.get_user(username) if (not user) or ("edit" in flask.request.form): password = flask.request.form['password'] password_confirm = flask.request.form['password_confirm'] if password == password_confirm: if "edit" in flask.request.form: user_id = int(flask.request.form['edit']) utils.modify_user(user_id, username, password) flask.flash('User Edited') else: utils.create_user(username, password) flask.flash('User Created') if "setup" in flask.request.form: return flask.redirect(flask.url_for('login')) else: error = "passwords do not match" else: error = "user already exists" users = utils.get_users() return flask.render_template('users.j2', users=users, error=error)
def interface_config(): if utils.needs_user(): return flask.redirect(flask.url_for('setup')) if ('logged_in' not in flask.session) or (not flask.session['logged_in']): return flask.redirect(flask.url_for('login')) error = None if flask.request.method == 'POST': if "delete" in flask.request.form: interface_id = int(flask.request.form['id']) utils.delete_interface(interface_id) flask.flash('Interface Deleted') else: interface_type = int(flask.request.form['type']) io_id = int(flask.request.form['io_id']) slot = int(flask.request.form['slot']) datamap = smbio.INTERFACEDATAMAP[interface_type] data = {} for key in datamap: data[key] = flask.request.form[key] if "edit" in flask.request.form: interface_id = int(flask.request.form['edit']) utils.modify_interface( interface_id, interface_type, io_id, slot, data) flask.flash('Interface Edited') else: utils.create_interface(interface_type, io_id, slot, data) flask.flash('Interface Created') interfaces = utils.get_interfaces() ios = utils.get_ios() return flask.render_template( 'interface_config.j2', error=error, interfaces=interfaces, ios=ios, smbio=smbio)
def interface_config(): if utils.needs_user(): return flask.redirect(flask.url_for('setup')) if ('logged_in' not in flask.session) or (not flask.session['logged_in']): return flask.redirect(flask.url_for('login')) error = None if flask.request.method == 'POST': if "delete" in flask.request.form: interface_id = int(flask.request.form['id']) utils.delete_interface(interface_id) flask.flash('Interface Deleted') else: interface_type = int(flask.request.form['type']) io_id = int(flask.request.form['io_id']) slot = int(flask.request.form['slot']) datamap = smbio.INTERFACEDATAMAP[interface_type] data = {} for key in datamap: data[key] = flask.request.form[key] if "edit" in flask.request.form: interface_id = int(flask.request.form['edit']) utils.modify_interface(interface_id, interface_type, io_id, slot, data) flask.flash('Interface Edited') else: utils.create_interface(interface_type, io_id, slot, data) flask.flash('Interface Created') interfaces = utils.get_interfaces() ios = utils.get_ios() return flask.render_template('interface_config.j2', error=error, interfaces=interfaces, ios=ios, smbio=smbio)
def root(): if utils.needs_user(): return flask.redirect(flask.url_for('setup')) if 'logged_in' in flask.session and flask.session['logged_in']: return flask.redirect(flask.url_for('dashboard')) return flask.redirect(flask.url_for('login'))