Ejemplo n.º 1
0
def scarp():
    desc = """
                        _____  _____
                  /\   |  __ \|  __ \\
      ___  ___   /  \  | |__) | |__) |
     / __|/ __| / /\ \ |  _  /|  ___/
     \__ \ (__ / ____ \| | \ \| |
     |___/\___/_/    \_\_|  \_\_|

    Scans the given interface for the mac addresses it possesses"""
    ex = 'Example of Usage:' \
         + '\n\tsudo python3 scarp.py -i enp8s0 -m 16' \
         + '\n\tsudo python3 scarp.py -m 20 -a'
    parser = argparse.ArgumentParser(description=desc, epilog=ex, formatter_class=argparse.RawDescriptionHelpFormatter)
    parser.add_argument('--interface', '-i', default='', help='Name of the interface you want to scan, optional',
                        required=False)
    parser.add_argument('--mask', '-m', default='24', help='IP mask value(1-32, default:24), optional', required=False)
    parser.add_argument('--auto-accept', '-a', default=False, action='store_true',
                        help='Add found MAC addresses to the list automatically, optional', required=False)
    args = parser.parse_args()
    interfaces = utils.get_interfaces()
    utils.ip_mask_prompt(args)
    print("Available interfaces:")
    for i in range(len(interfaces)):
        print("---" + list(interfaces.keys())[i] + ": " + list(interfaces.values())[i])
    while (args.interface not in interfaces):
        args.interface = input("Please enter a valid interface name: ")
    onlineMacs = utils.get_mac_list(interfaces[args.interface] + '/' + args.mask, args.interface)
    utils.check(onlineMacs, args.auto_accept)
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
0
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)
Ejemplo n.º 6
0
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)
Ejemplo n.º 7
0
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)