Example #1
0
def fb_ips():
    with app.app_context():
        from unifispot.superadmin.models import Account 
        from unifispot.guest.newcontroller import Controller       
        account = Account().query.first()
        settings = account.get_settings() 
        site_id = 'ieu6ek9y'
        site_code = '572a12afe4b078cda06e7e41'
        portal_ip = '139.59.192.71'
        portal_subnet = '139.59.192.71/32'
        portal_hostname = 'urbanespot.com'
        c =  Controller(settings['unifi_server'], settings['unifi_user'], settings['unifi_pass'],'8443','v4',site_id)             
        c.set_guest_access(site_id,site_code,portal_ip,portal_subnet,portal_hostname)
Example #2
0
def fb_ips():
    with app.app_context():
        from unifispot.superadmin.models import Account 
        from unifispot.guest.newcontroller import Controller       
        account = Account().query.first()
        settings = account.get_settings() 
        site_id = ''
        site_code = ''
        portal_ip = ''
        portal_subnet = ''
        portal_hostname = ''
        c =  Controller(settings['unifi_server'], settings['unifi_user'], settings['unifi_pass'],'8443','v4',site_id)             
        c.set_guest_access(site_id,site_code,portal_ip,portal_subnet,portal_hostname)
Example #3
0
def fb_ips():
    with app.app_context():
        from unifispot.superadmin.models import Account
        from unifispot.guest.newcontroller import Controller
        account = Account().query.first()
        settings = account.get_settings()
        site_id = ''
        site_code = ''
        portal_ip = ''
        portal_subnet = ''
        portal_hostname = ''
        c = Controller(settings['unifi_server'], settings['unifi_user'],
                       settings['unifi_pass'], '8443', 'v4', site_id)
        c.set_guest_access(site_id, site_code, portal_ip, portal_subnet,
                           portal_hostname)
Example #4
0
def celery_session_monitor(*args, **kwargs):
    current_app.logger.info('-----------Running celery_session_monitor-----------------------')
    sites = Wifisite.query.all()
    for site in sites:
        if site.enable_session_limit or site.voucher_login_en() :
            current_app.logger.info('celery_session_monitor processing Site:%s'%site.name)       
            account = Account().query.filter_by(id=site.account_id).first()
            settings = account.get_settings()
            try:
                c =  Controller(settings['unifi_server'], settings['unifi_user'], settings['unifi_pass'],'8443','v4',site.unifi_id)       
                #get all STAs
                stas = c.get_clients()
                for sta in stas:
                    if sta.get('is_guest') and sta.get('authorized'):
                        rx_bytes = int(sta.get('rx_bytes'))
                        tx_bytes = int(sta.get('tx_bytes'))
                        total_data = rx_bytes + tx_bytes 
                        data_mb    = int(math.ceil((total_data/1024000.0)))
                        
                        mac = sta.get('mac')
                        guest_session = Guestsession.query.filter_by(site_id=site.id,mac=mac).first()
                        if not guest_session:
                            current_app.logger.debug('MAC:%s in site:%s have no session'%(mac,site.name))
                            continue
                        current_app.logger.debug('MAC:%s in site:%s seems to have used \
                                data:%s Mb'%(mac,site.name,data_mb))                         
                        if guest_session.state == GUESTRACK_VOUCHER_AUTH:
                            #if voucher authorized check for balance data in voucher
                            current_app.logger.debug('MAC:%s in site:%s seems to have authorized via Voucher '%(mac,site.name))
                            voucher = Voucher.query.filter_by(site_id=site.id,device_id=guest_session.device_id).first()
                            if not voucher:
                                current_app.logger.error('MAC:%s in site:%s no_voucher found '%(mac,site.name))
                                continue
                            if voucher.bytes_t and data_mb > voucher.data_available():
                                current_app.logger.debug('MAC:%s in site:%s seems to have exceeded voucher:%s limit \
                                    hence disconnecting'%(mac,site.name,voucher.id))   
                        #if not voucher authorized check if device exceeded session limit if session limit is enabled
                        else:
                            if site.enable_session_limit and data_mb > int(site.daily_data_limit) :
                                current_app.logger.debug('MAC:%s in site:%s seems to have exceeded data \
                                    hence disconnecting'%(mac,site.name)) 
                                c.unauthorize_guest(mac)   
            except:
                current_app.logger.exception('Exception while monitoring site:%s'%site.name)                
Example #5
0
def celery_session_monitor(*args, **kwargs):
    current_app.logger.info(
        '-----------Running celery_session_monitor-----------------------')
    sites = Wifisite.query.all()
    for site in sites:
        if site.enable_session_limit or site.voucher_login_en():
            current_app.logger.info(
                'celery_session_monitor processing Site:%s' % site.name)
            account = Account().query.filter_by(id=site.account_id).first()
            settings = account.get_settings()
            try:
                c = Controller(settings['unifi_server'],
                               settings['unifi_user'], settings['unifi_pass'],
                               '8443', 'v4', site.unifi_id)
                #get all STAs
                stas = c.get_clients()
                for sta in stas:
                    if sta.get('is_guest') and sta.get('authorized'):
                        rx_bytes = int(sta.get('rx_bytes'))
                        tx_bytes = int(sta.get('tx_bytes'))
                        total_data = rx_bytes + tx_bytes
                        data_mb = int(math.ceil((total_data / 1024000.0)))

                        mac = sta.get('mac')
                        guest_session = Guestsession.query.filter_by(
                            site_id=site.id, mac=mac).first()
                        if not guest_session:
                            current_app.logger.debug(
                                'MAC:%s in site:%s have no session' %
                                (mac, site.name))
                            continue
                        current_app.logger.debug(
                            'MAC:%s in site:%s seems to have used \
                                data:%s Mb' % (mac, site.name, data_mb))
                        if guest_session.state == GUESTRACK_VOUCHER_AUTH:
                            #if voucher authorized check for balance data in voucher
                            current_app.logger.debug(
                                'MAC:%s in site:%s seems to have authorized via Voucher '
                                % (mac, site.name))
                            voucher = Voucher.query.filter_by(
                                site_id=site.id,
                                device_id=guest_session.device_id).first()
                            if not voucher:
                                current_app.logger.error(
                                    'MAC:%s in site:%s no_voucher found ' %
                                    (mac, site.name))
                                continue
                            if data_mb > voucher.data_available():
                                current_app.logger.debug(
                                    'MAC:%s in site:%s seems to have exceeded voucher:%s limit \
                                    hence disconnecting' %
                                    (mac, site.name, voucher.id))
                        #if not voucher authorized check if device exceeded session limit if session limit is enabled
                        else:
                            if site.enable_session_limit and data_mb > int(
                                    site.daily_data_limit):
                                current_app.logger.debug(
                                    'MAC:%s in site:%s seems to have exceeded data \
                                    hence disconnecting' % (mac, site.name))
                                c.unauthorize_guest(mac)
            except:
                current_app.logger.exception(
                    'Exception while monitoring site:%s' % site.name)