Exemplo n.º 1
0
def m_metadata_clear(info):
    ctx = get_context()
    restricted_keys = ctx.conf.metadata.get('restricted_keys', [])

    source = info['source']
    target = info['target']
    target_name = info['target_name']
    keys = info['keys']

    monitor_list = get_monitor_list(source, target)

    # we dump numerics to the source here instead of in the 'delete' event
    #   below so the 'end of metadata' numeric gets put in the right place
    for key, kinfo in keys.items():
        visibility = kinfo['visibility']

        args = [target_name, key, visibility]
        source.dump_numeric('761', args, add_target=False)

        # create event to actually remove key and dump notify
        info = {
            'key': key,
            'source': source,
            'target': target,
            'target_name': target_name,
            'visibility': visibility,
        }
        eventmgr_core.dispatch('metadata delete', info)

    source.dump_numeric('762', ['end of metadata'], add_target=False)
Exemplo n.º 2
0
def m_privmsg_client(info):
    ctx = get_context()
    if ctx.conf.name == info["target"].servername:
        msg = RFC1459Message.from_data(
            "PRIVMSG", source=info["source"].hostmask, params=[info["target_name"], info["message"]]
        )
        info["target"].dump_message(msg)
Exemplo n.º 3
0
def m_privmsg_client(info):
    ctx = get_context()
    if ctx.conf.name == info['target'].servername:
        msg = RFC1459Message.from_data(
            'PRIVMSG',
            source=info['source'],
            params=[info['target_name'], info['message']])
        info['target'].dump_message(msg)
Exemplo n.º 4
0
def m_monitor_status(info):
    ctx = get_context()
    client = info['client']

    online = []
    offline = []

    for target in client.monitoring:
        if validate_nick(target):
            if target in ctx.clients:
                online.append(target)
            else:
                offline.append(target)

    if online:
        client.dump_numeric('730', [info['client'].nickname, ','.join(online)])
    if offline:
        client.dump_numeric('731', [info['client'].nickname, ','.join(offline)])
Exemplo n.º 5
0
def m_monitor_status(info):
    ctx = get_context()
    cli = info['client']

    online = []
    offline = []

    for target in cli.monitoring:
        if validate_nick(target):
            if target in ctx.clients:
                online.append(target)
            else:
                offline.append(target)

    if online:
        cli.dump_numeric('730', [','.join(online)])
    if offline:
        cli.dump_numeric('731', [','.join(offline)])
Exemplo n.º 6
0
def set_key(target, key, value=None):
    ctx = get_context()

    # clearing key
    if value is None:
        try:
            del target.metadata[key]
            target.user_set_metadata.remove(key)
        except (KeyError, ValueError):
            pass

    # setting key
    else:
        target.metadata[key] = value

        restricted_keys = ctx.conf.metadata.get('restricted_keys', [])
        if key not in target.user_set_metadata and key not in restricted_keys:
            target.user_set_metadata.append(key)

        target.metadata[key] = value
Exemplo n.º 7
0
def m_metadata_set(info):
    ctx = get_context()

    source = info['source']
    target = info['target']
    key = info['key']
    value = info['value']

    args = [info['target_name'], key, info['visibility']]
    if value:
        args.append(value)

    set_key(target, key, value)

    # if local client, dump numerics
    if source.servername == ctx.conf.name:
        source.dump_numeric('761', args, add_target=False)
        source.dump_numeric('762', ['end of metadata'], add_target=False)

    # sendto monitoring clients
    dump_metadata_notify(source, target, key, args)
Exemplo n.º 8
0
def dump_metadata_notify(source,
                         target,
                         key,
                         args,
                         monitor_list=None,
                         restricted_keys=None):
    if monitor_list is None:
        monitor_list = get_monitor_list(source, target)

    if restricted_keys is None:
        ctx = get_context()
        restricted_keys = ctx.conf.metadata.get('restricted_keys', [])

    for cli in monitor_list:
        if key in restricted_keys and (not cli.role
                                       or key not in cli.role.metakeys_get):
            continue
        if cli == source or cli == target:
            continue
        if cli.servername == ctx.conf.name:
            cli.dump_verb('METADATA', args)
Exemplo n.º 9
0
def m_monitor_edit(info):
    ctx = get_context()
    cli = info['client']
    if info['command'] == '+':
        online = []
        offline = []

    for target in info['targets']:
        if target not in monitored:
            monitored[target] = []

        if info['command'] == '+':
            if cli not in monitored[target]:
                monitored[target].append(cli)
            if target not in cli.monitoring:
                cli.monitoring.append(target)

            if target in ctx.clients:
                online.append(target)
            else:
                offline.append(target)

        elif info['command'] == '-':
            try:
                monitored[target].remove(cli)
            except ValueError:
                pass
            try:
                cli.monitoring.remove(target)
            except ValueError:
                pass

    if info['command'] == '+':
        if online:
            cli.dump_numeric('730', [','.join(online)])
        if offline:
            cli.dump_numeric('731', [','.join(offline)])
Exemplo n.º 10
0
def m_monitor_handle_quit(info):
    ctx = get_context()
    nick = info['client'].nickname
    for client in monitored.get(nick, []):
        if client.servername == ctx.conf.name:
            client.dump_numeric('731', [info['client'].nickname, info['client'].nickname])
Exemplo n.º 11
0
def m_monitor_handle_quit(info):
    ctx = get_context()
    nick = info['client'].nickname
    for client in monitored.get(nick, []):
        if client.servername == ctx.conf.name:
            client.dump_numeric('731', [nick])