예제 #1
0
    def data_usage(self, req, resp, user_id):
        content = []
        user = obj(req, calabiyau_subscriber, sql_id=user_id)

        if user['volume_used_bytes']:
            used = user['volume_used_bytes'] / 1024 / 1024 / 1024
        else:
            used = 0

        f_user_id = sql.Field('user_id')
        v_user_id = sql.Value(user['id'])
        f_volume_gb = sql.Field('sum(volume_gb) as volume_gb')

        select = sql.Select('calabiyau_topup')
        select.fields = f_volume_gb
        select.where = f_user_id == v_user_id
        with db() as conn:
            result = conn.execute(select.query, select.values).fetchone()
            if result:
                topups = result['volume_gb']
                if topups is None:
                    topups = 0
            else:
                topups = 0

            if not user['volume_used']:
                f_pkg_id = sql.Field('id')
                v_pkg_id = sql.Value(user['package_id'])
                f_volume_gb = sql.Field('volume_gb')
                select = sql.Select('calabiyau_package')
                select.where = f_pkg_id == v_pkg_id
                result = conn.execute(select.query, select.values).fetchone()
                if result:
                    pkg_volume = result['volume_gb']
                    if pkg_volume is None:
                        pkg_volume = 0
                    pkg_volume = pkg_volume - used
                    if pkg_volume < 0:
                        pkg_volume = 0
                else:
                    pkg_volume = 0
            else:
                pkg_volume = 0
                topups = float(topups) - float(used)
                if topups < 0:
                    topups = 0

        content.append({'type': 'Topups',
                        'gb': round(float(topups), 2)})
        content.append({'type': 'Used',
                        'gb': round(float(used), 2)})
        content.append({'type': 'Package',
                        'gb': round(float(pkg_volume), 2)})

        return raw_list(req, content)
예제 #2
0
    def accounting(self, req, resp):
        limit = int(req.query_params.get('limit', 10))
        page = int(req.query_params.get('page', 1))

        tenant_id = req.context_tenant_id
        domain = req.context_domain

        search = {}
        for field, value in search_params(req):
            search['tradius_accounting.' + field] = value

        results = get_cdr(tenant_id=tenant_id,
                          domain=domain,
                          page=page,
                          limit=limit * 2,
                          search=search)

        return raw_list(req, results, limit=limit, context=False, sql=True)
예제 #3
0
    def vendors(self, req, resp):
        nas_types = []

        for vendor in vendors:
            nas_types.append(vendor.upper())

        with db() as conn:
            result = conn.execute("SELECT nas_type FROM calabiyau_nas" +
                                  " GROUP by nas_type").fetchall()
            for row in result:
                nas_types.append(row['nas_type'])

            result = conn.execute("SELECT nas_type FROM" +
                                  " calabiyau_package_attr" +
                                  " GROUP by nas_type").fetchall()
            for row in result:
                nas_types.append(row['nas_type'])

            conn.commit()

        nas_types = list(set(nas_types))

        return raw_list(req, nas_types)
예제 #4
0
 def avps(self, req, resp):
     return raw_list(req, avps)
예제 #5
0
파일: users.py 프로젝트: Vuader/subscriber
 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)