示例#1
0
 def add_group(self, req, resp, user_id):
     user = tradius_user()
     user.sql_id(user_id)
     validate_access(req, user)
     attr = obj(req, tradius_user_group)
     attr['user_id'] = user_id
     attr.commit()
示例#2
0
    def rm_prefix(self, req, resp, pool_id):
        pool = calabiyau_pool()
        pool.sql_id(pool_id)
        validate_access(req, pool)

        if not req.json.get('prefix'):
            raise ValueError('Prefix Required')

        prefix = ip_network(req.json['prefix']).with_prefixlen

        pool_delete(pool_id, prefix)
示例#3
0
 def attrs(self, req, resp, user_id):
     user = tradius_user()
     user.sql_id(user_id)
     validate_access(req, user)
     where = {'user_id': user_id}
     return sql_list(req,
                     'tradius_user_attr', (
                         'id',
                         'attribute',
                         'op',
                         'value',
                     ),
                     where=where)
示例#4
0
def obj(req, ModelClass, sql_id=None, hide=None):
    if not issubclass(ModelClass, SQLModel):
        raise ValueError('Expecting SQL Model')

    model = ModelClass(hide=hide)

    if sql_id:
        model.sql_id(sql_id)

        validate_access(req, model)

    if req.method in ['POST', 'PATCH', 'PUT']:
        model.update(req.json)
        validate_set_scope(req, model)
    elif (req.method == 'DELETE' and issubclass(ModelClass, SQLModel)
          and sql_id):
        model.delete()

    return model
示例#5
0
文件: pool.py 项目: Vuader/subscriber
    def rm_prefix(self, req, resp, id):
        pool = tradius_pool()
        pool.sql_id(id)
        validate_access(req, pool)

        if req.json.get('prefix'):
            prefix = IPNetwork(req.json['prefix']).prefix()
        else:
            prefix = None

        with rmq() as mb:
            message = {
                'type': 'delete_pool',
                'pool': {
                    'name': pool['pool_name'],
                    'prefix': prefix,
                    'domain': req.context_domain
                }
            }
            mb.distribute('tradius', **message)
示例#6
0
文件: pool.py 项目: Vuader/subscriber
    def add_prefix(self, req, resp, id):
        pool = tradius_pool()
        pool.sql_id(id)
        validate_access(req, pool)

        prefix = IPNetwork(req.json['prefix']).prefix()

        if not req.json.get('prefix'):
            raise ValueError('Prefix Required')

        with rmq() as mb:
            message = {
                'type': 'append_pool',
                'pool': {
                    'name': pool['pool_name'],
                    'prefix': prefix,
                    'domain': req.context_domain
                }
            }
            mb.distribute('tradius', **message)
示例#7
0
 def rm_attr(self, req, resp, user_id, group_id):
     user = tradius_user()
     user.sql_id(user_id)
     validate_access(req, user)
     attr = obj(req, tradius_user_attr, sql_id=group_id)
     attr.commit()
示例#8
0
 def groups(self, req, resp, user_id):
     user = tradius_user()
     user.sql_id(user_id)
     validate_access(req, user)
     user_groups = get_user_groups(user_id)
     return raw_list(req, user_groups, sql=False)