Exemplo n.º 1
0
 def decorated_function(*args, **kwargs):
     wifisite = kwargs.get('wifisite')
     guesttrack = kwargs.get('guesttrack')
     guestdevice = kwargs.get('guestdevice')
     #get the function name used
     fname = f.func_name
     #check if site is configured for emaillogin
     if not wifisite.check_login_en('auth_voucher'):
         guestlog_warn(
             'trying to access voucher login for  \
                 non configured site', wifisite, guesttrack)
         abort(404)
     #get and validated emailconfig
     voucherconfig = Voucherconfig.query.filter_by(
         siteid=wifisite.id).first()
     if not voucherconfig:
         guestlog_warn('empty voucherconfig, aborting', wifisite,
                       guesttrack)
         abort(404)
     kwargs['voucherconfig'] = voucherconfig
     #get paymentauth for this device
     voucherauth = Voucherauth.query.filter_by(
         siteid=wifisite.id, deviceid=guestdevice.id).first()
     if not voucherauth:
         guestlog_debug(
             'in %s empty Paymentauth,creating default one' % fname,
             wifisite, guesttrack)
         voucherauth = Voucherauth(siteid=wifisite.id,
                                   deviceid=guestdevice.id,
                                   account_id=wifisite.account_id)
         voucherauth.save()
     kwargs['voucherauth'] = voucherauth
     return f(*args, **kwargs)
Exemplo n.º 2
0
def guest_login(trackid,
                guesttrack,
                wifisite,
                guestdevice,
                voucherconfig,
                voucherauth,
                voucherid=None):
    ''' Function to called if the site is configured with payment login    
    
    '''
    #show the configured landing page
    voucher_form = generate_voucherform(voucherconfig)
    if voucher_form.validate_on_submit():
        voucher = Voucher.query.filter(
            and_(Voucher.siteid == wifisite.id,
                 Voucher.voucher == voucher_form.voucher.data)).first()
        if voucher:
            #check and update validity of paymentaccount
            (status, msg) = voucher.check_and_update_validity(voucherauth)
            if status:
                #assign a guest based on form
                newguest = assign_guest_entry(wifisite,
                                              guesttrack,
                                              form=voucher_form)
                #update guesttrack
                guesttrack.state = GUESTTRACK_POSTLOGIN
                guesttrack.loginauthid = voucherauth.id
                guesttrack.updatestat('auth_voucher', 1)
                guesttrack.save()
                #update guestdevice
                guestdevice.guestid = newguest.id
                guestdevice.save()
                #update guest
                newguest.demo = guesttrack.demo
                newguest.devices.append(guestdevice)
                newguest.save()
                guestlog_debug('voucher_login  new guest track ID:%s'%\
                                newguest.id,wifisite,guesttrack)
                return redirect_guest(wifisite, guesttrack)
            else:
                flash(msg, 'danger')
                guestlog_warn('in voucher.guest_login limit expired', wifisite,
                              guesttrack)
        else:
            #transaction failed! display msg
            flash(_l('Wrong voucher entry'), 'danger')
            guestlog_warn('in voucher.guest_login wrong voucher id', wifisite,
                          guesttrack)

    landingpage = Landingpage.query.filter_by(siteid=wifisite.id).first()
    return render_template('guest/%s/voucher_landing.html'%wifisite.template,\
            wifisite=wifisite,landingpage=landingpage,voucher_form=voucher_form,
            trackid=trackid)
Exemplo n.º 3
0
def get_login_config(wifisite,guesttrack):
    '''This method needs to be added to all login plugins
        Called by redirec_guest when rendering multi landing page
        return loginconfig object for the current login method

    '''
    #get and validated voucherconfig
    voucherconfig = Voucherconfig.query.filter_by(siteid=wifisite.id).first()
    if not voucherconfig:
        guestlog_warn('empty voucherconfig, aborting',wifisite,guesttrack)
        abort(404)
    return voucherconfig   
Exemplo n.º 4
0
def get_login_config(wifisite,guesttrack):
    '''This method needs to be added to all login plugins
        Called by redirec_guest when rendering multi landing page
        return loginconfig object for the current login method

    '''
    fbconfig = Fbconfig.query.filter_by(siteid=wifisite.id).first()
    if not fbconfig:
        guestlog_warn('trying to access fb_login without configuring ',
                        wifisite,guesttrack)
        abort(404)
    return fbconfig   
Exemplo n.º 5
0
def guest_auth(trackid, guesttrack, wifisite, guestdevice, account):
    #redirect to authorize a particular guest

    if not guesttrack.state == GUESTTRACK_AUTH:
        guestlog_warn('guest_auth called with unathorized track', wifisite,
                      guesttrack)
        abort(404)

    #get login auth
    loginauth = Loginauth.query.filter_by(siteid=wifisite.id,
                                          id=guesttrack.loginauthid).first()
    if not loginauth:
        guestlog_warn(
            'guest_auth called without a proper loginauth attached to track',
            wifisite, guesttrack)
        abort(404)

    time_limit = loginauth.time_available()
    duration = time_limit if time_limit else 480

    if not current_app.config['NO_UNIFI']:
        try:
            c = Controller(account=account, sitekey=wifisite.sitekey)
            if current_app.config['UNIFI_NO_AP_MAC']:
                #made sending AP MAC to be configurable
                c.authorize_guest(guesttrack.devicemac,
                                  duration,
                                  up_bandwidth=loginauth.speed_ul,
                                  down_bandwidth=loginauth.speed_dl)
            else:
                c.authorize_guest(guesttrack.devicemac,
                                  duration,
                                  ap_mac=guesttrack.apmac,
                                  up_bandwidth=loginauth.speed_ul,
                                  down_bandwidth=loginauth.speed_dl)
        except:
            guestlog_exception('exception while trying to authorize guest',
                               wifisite, guesttrack)
            abort(500)

    #create session if not already created for the track
    guestsession = Guestsession(siteid=wifisite.id,
                                deviceid=guestdevice.id,
                                loginauthid=loginauth.id)
    guestsession.mac = guestdevice.devicemac
    guestsession.trackid = guesttrack.id
    guestsession.save()

    return show_message(wifisite, guesttrack)
Exemplo n.º 6
0
def fb_like(trackid, guesttrack, wifisite, guestdevice, fbconfig, loginauth):
    auth_like = None
    auth_post = None
    if request.method == 'POST':
        auth_like = request.form['authlike']

    if auth_like == '1':
        #quick hack to test for liking and posting, guest has skipped the liking, allow
        #internet for now and ask next time
        pass

    elif auth_like == '2':
        #user has liked the page mark track and guest as liked
        guest = Guest.query.get(guestdevice.guestid)
        if not guest:
            guestlog_warn("no guest associated with guestdevice", wifisite,
                          guesttrack)
            return redirect_guest(wifisite, guesttrack)
        guest.fbliked = 1
        guest.save()

        loginauth.fbliked = 1
        loginauth.save()

        guesttrack.updatestat('fbliked', 1)

    else:
        #show page asking guest to like
        landingpage = Landingpage.query.filter_by(siteid=wifisite.id).first()
        fb_page = fbconfig.fb_page
        fb_appid = fbconfig.fb_appid
        guestlog_debug('show ask for like page', wifisite, guesttrack)
        return render_template("guest/%s/fb_like.html" % wifisite.template,
                               landingpage=landingpage,
                               fb_appid=fb_appid,
                               trackid=trackid,
                               fb_page=fb_page)

    #redirect guest to auth page
    loginauth.populate_auth_details(fbconfig)
    loginauth.reset()
    loginauth.reset_lastlogin()
    loginauth.state = LOGINAUTH_FIRST
    loginauth.save()
    #neither configured, authorize guest
    guesttrack.state = GUESTTRACK_POSTLOGIN
    guesttrack.loginauthid = loginauth.id
    guesttrack.updatestat('auth_facebook', 1)
    return redirect_guest(wifisite, guesttrack)
Exemplo n.º 7
0
def get_login_config(wifisite,guesttrack):
    '''This method needs to be added to all login plugins
        Called by redirec_guest when rendering multi landing page
        return loginconfig object for the current login method

    '''
    emailconfig = Emailconfig.query.filter_by(siteid=wifisite.id).first()
    if not emailconfig:
        guestlog_warn('empty emailconfig, creating default one',wifisite,guesttrack)
        emailconfig = Emailconfig()
        emailconfig.siteid = wifisite.id
        client = Client.query.get(wifisite.client_id)
        emailconfig.account_id = client.account_id
        emailconfig.save() 
    return emailconfig   
Exemplo n.º 8
0
 def decorated_function(*args, **kwargs):
     wifisite    =  kwargs.get('wifisite')
     guesttrack  =  kwargs.get('guesttrack')
     #get the function name used 
     fname = f.func_name
     #check if site is configured for emaillogin
     if not wifisite.check_login_en('auth_facebook'):
         guestlog_warn('trying to access fb_login for  non configured site',wifisite,guesttrack)
         abort(404)
     #get and validated fbconfig
     fbconfig = Fbconfig.query.filter_by(siteid=wifisite.id).first()
     if not fbconfig:
         guestlog_warn('trying to access fb_login without configuring ',
                     wifisite,guesttrack)
         abort(404)
     kwargs['fbconfig'] = fbconfig
     return f(*args, **kwargs)
Exemplo n.º 9
0
    def decorated_function(*args, **kwargs):
        wifisite    =  kwargs.get('wifisite')
        guesttrack  =  kwargs.get('guesttrack')
        #get the function name used 
        fname = f.func_name
        #check if site is configured for unifi backend
        if not wifisite.backend_type == 'unifi':
            guestlog_warn('guest_auth for a site which is not Unifi site',
                            wifisite,guesttrack)        
            abort(404)
        account = Account.query.get(wifisite.account_id)
        if not account:
            guestlog_warn('guest_auth for a site which is not Unifi site',
                            wifisite,guesttrack)        
            abort(404)    

        kwargs['account'] = account
        return f(*args, **kwargs)
Exemplo n.º 10
0
 def decorated_function(*args, **kwargs):
     wifisite    =  kwargs.get('wifisite')
     guesttrack  =  kwargs.get('guesttrack')
     #get the function name used 
     fname = f.func_name
     #check if site is configured for phonelogin
     if not wifisite.check_login_en('auth_phone'):
         guestlog_warn('trying to access phone_login for  non configured site',wifisite,guesttrack)
         abort(404)
     #get and validated phoneconfig
     phoneconfig = Phoneconfig.query.filter_by(siteid=wifisite.id).first()
     if not phoneconfig:
         guestlog_warn('empty phoneconfig, creating default one',wifisite,guesttrack)
         phoneconfig = Phoneconfig()
         phoneconfig.siteid = wifisite.id
         client = Client.query.get(wifisite.client_id)
         phoneconfig.account_id = client.account_id
         phoneconfig.save()
     kwargs['phoneconfig'] = phoneconfig
     return f(*args, **kwargs)
Exemplo n.º 11
0
def guest_auth(trackid,guesttrack,wifisite,guestdevice,account):  
    #redirect to authorize a particular guest

    if not guesttrack.state == GUESTTRACK_AUTH:
        guestlog_warn('guest_auth called with unathorized track',
                        wifisite,guesttrack)
        abort(404)        

    #get login auth
    loginauth = Loginauth.query.filter_by(siteid=wifisite.id,
                        id=guesttrack.loginauthid).first()
    if not loginauth:
        guestlog_warn('guest_auth called without a proper loginauth attached to track',
                        wifisite,guesttrack)
        abort(404)

    duration = loginauth.time_limit if (loginauth.time_limit < 480) else 480
    
    try:
        c = Controller(account=account,sitekey=wifisite.sitekey)  
        c.authorize_guest(guesttrack.devicemac,duration,ap_mac=guesttrack.apmac,
            up_bandwidth=loginauth.speed_ul,down_bandwidth=loginauth.speed_dl,
            byte_quota=loginauth.data_limit)    
    except:
        guestlog_exception('exception while trying to authorize guest',wifisite,guesttrack)
        abort(500)   



    #create session if not already created for the track
    guestsession = Guestsession(siteid=wifisite.id,deviceid=guestdevice.id,
                                loginauthid=loginauth.id)
    guestsession.mac =  guestdevice.devicemac
    guestsession.trackid= guesttrack.id
    guestsession.save()

    guesttrack.state = GUESTTRACK_POST_AUTH
    guesttrack.save()

    return redirect_guest(wifisite,guesttrack) 
Exemplo n.º 12
0
def fb_login_check(trackid, guesttrack, wifisite, guestdevice, fbconfig,
                   loginauth):
    '''End point for validating guest's FB login

    '''
    code = request.args.get('code')
    access_token = None
    fb_appid = fbconfig.fb_appid
    fb_app_secret = fbconfig.fb_app_secret
    if code:
        #URL called after OAuth
        redirect_uri = url_for('unifispot.modules.facebook.fb_login_check',
                               trackid=trackid,
                               _external=True)
        try:
            at = GraphAPI().get_access_token_from_code(code, redirect_uri,
                                                       fb_appid, fb_app_secret)
            access_token = at['access_token']
            graph = GraphAPI(access_token)
            profile = graph.get_object(
                "me",
                fields=
                'name,email,first_name,last_name,gender,birthday,age_range')
            if not profile:
                #
                #User is not logged into DB app, redirect to social login page
                guestlog_warn(
                    'guestdevice MAC:%s facebook_login  empty profile, \
                    should be redirected to login ' % guestdevice.devicemac,
                    wifisite, guesttrack)
                return redirect_guest(wifisite, guesttrack)
        except:
            guestlog_exception(
                'guestdevice MAC:%s facebook_login  exception , \
                    should be redirected to login ' % guestdevice.devicemac,
                wifisite, guesttrack)
            return redirect_guest(wifisite, guesttrack)
    else:
        #URL could be called by JS, check for cookies
        #
        try:
            check_user_auth = get_user_from_cookie(cookies=request.cookies,
                                                   app_id=fb_appid,
                                                   app_secret=fb_app_secret)
            access_token = check_user_auth['access_token']
            graph = GraphAPI(access_token)
            profile = graph.get_object(
                "me",
                fields=
                'name,email,first_name,last_name,gender,birthday,age_range')
            if not check_user_auth or not check_user_auth['uid'] or not profile:
                #
                #User is not logged into DB app, redirect to social login page
                guestlog_warn(
                    'guestdevice MAC:%s facebook_login  empty profile, \
                    should be redirected to login ' % guestdevice.devicemac,
                    wifisite, guesttrack)
                return redirect_guest(wifisite, guesttrack)
        except:
            guestlog_exception(
                'guestdevice MAC:%s facebook_login  exception , \
                    should be redirected to login ' % guestdevice.devicemac,
                wifisite, guesttrack)
            return redirect_guest(wifisite, guesttrack)
    #create FB AUTH
    loginauth.fbprofileid = profile['id']
    loginauth.fbtoken = access_token
    loginauth.save()

    #add/update guest
    newguest = assign_guest_entry(wifisite, guesttrack, fbprofile=profile)

    #update guesttrack

    #update guestdevice
    guestdevice.guestid = newguest.id
    guestdevice.save()
    #update guest
    newguest.demo = guesttrack.demo
    newguest.devices.append(guestdevice)
    newguest.save()

    #check if either checkin/like configured
    if fbconfig.auth_fb_post == 1:
        return redirect(
            url_for('unifispot.modules.facebook.fb_checkin', trackid=trackid))
    elif fbconfig.auth_fb_like == 1 and newguest.fbliked != 1:
        return redirect(
            url_for('unifispot.modules.facebook.fb_like', trackid=trackid))
    else:
        loginauth.populate_auth_details(fbconfig)
        loginauth.reset()
        loginauth.reset_lastlogin()
        loginauth.state = LOGINAUTH_FIRST
        loginauth.save()
        #neither configured, authorize guest
        guesttrack.state = GUESTTRACK_POSTLOGIN
        guesttrack.loginauthid = loginauth.id
        guesttrack.updatestat('auth_facebook', 1)
        return redirect_guest(wifisite, guesttrack)
Exemplo n.º 13
0
def fb_checkin(trackid, guesttrack, wifisite, guestdevice, fbconfig,
               loginauth):
    '''End point for guest to checkin

    '''
    code = request.args.get('code')
    access_token = None
    fb_appid = fbconfig.fb_appid
    fb_app_secret = fbconfig.fb_app_secret
    fb_page = fbconfig.fb_page
    redirect_uri = url_for('unifispot.modules.facebook.fb_checkin',
                           trackid=trackid,
                           _external=True)
    if code:
        #URL called after OAuth
        try:
            at  = GraphAPI().get_access_token_from_code(code, redirect_uri,\
                             fb_appid, fb_app_secret)
            access_token = at['access_token']
            graph = GraphAPI(access_token)
            permissions = graph.get_connections("me", "permissions")
        except:
            guestlog_exception(
                'fb_checkin exception while getting access_token \
                                redirecting to fb_checkin ', wifisite,
                guesttrack)
            #send back to page
            return redirect(redirect_uri, code=302)
    else:
        try:
            graph = GraphAPI(loginauth.fbtoken)
            permissions = graph.get_connections("me", "permissions")

        except:
            guestlog_exception(
                'fb_checkin exception while getting permissions \
                                redirecting to fb_checkin ', wifisite,
                guesttrack)

            return redirect_guest(wifisite, guesttrack)

    #check if the user has granted publish_permissions
    publish_permission = False
    for perm in permissions['data']:
        if perm.get('permission') == 'publish_actions' and\
                 perm.get('status') == 'granted':
            publish_permission = True

    if not publish_permission:
        guestlog_warn(
            'fb_checkin  called without guest giving publish_permission redo Oauth\
                         fbauth', wifisite, guesttrack)

        params = {
            'client_id': fb_appid,
            'redirect_uri': redirect_uri,
            'scope': 'publish_actions '
        }
        url = 'https://www.facebook.com/dialog/oauth?' + urllib.urlencode(
            params)
        return redirect(url, code=302)

    checkinform = CheckinForm()
    if checkinform.validate_on_submit():
        #try to do checkin
        try:

            page_info = graph.get_object(
                fb_page, fields='description,name,location,picture')
            graph.put_wall_post(message=checkinform.message.data,
                                attachment={'place': page_info['id']})
        except Exception as e:
            if 'Duplicate status message' in str(e):
                guestlog_warn(
                    'duplicate message exception while doing checkin, \
                                ask guest to enter some message', wifisite,
                    guesttrack)
                flash(_('Please enter some message'), 'danger')
            else:
                guestlog_exception('exception while doing checkin', wifisite,
                                   guesttrack)
        else:
            #mark fbauth with checkedin
            guesttrack.updatestat('fbcheckedin', 1)
            guest = Guest.query.get(guestdevice.guestid)
            if not guest:
                guestlog_warn("no guest associated with guestdevice", wifisite,
                              guesttrack)
                return redirect_guest(wifisite, guesttrack)

            guest.fbcheckedin = 1
            guest.save()
            #check if guest needs to be redirected to asklike
            #page
            if fbconfig.auth_fb_like and guest.fbliked != 1:
                return redirect(
                    url_for('unifispot.modules.facebook.fb_like',
                            trackid=trackid))
            else:
                #redirect guest to auth page
                loginauth.populate_auth_details(fbconfig)
                loginauth.reset()
                loginauth.reset_lastlogin()
                loginauth.state = LOGINAUTH_FIRST
                loginauth.save()
                #neither configured, authorize guest
                guesttrack.state = GUESTTRACK_POSTLOGIN
                guesttrack.loginauthid = loginauth.id
                guesttrack.updatestat('auth_facebook', 1)
                return redirect_guest(wifisite, guesttrack)

    guestlog_debug('show ask for checkin page', wifisite, guesttrack)

    landingpage = Landingpage.query.filter_by(siteid=wifisite.id).first()

    page_info = graph.get_object(fb_page, fields='location,name')
    loc = page_info['location']
    location = ' %s - %s %s %s' % (page_info.get(
        'name', ''), loc.get('street', ''), loc.get(
            'city', ''), loc.get('country', ''))
    return render_template("guest/%s/fb_checkin.html" % wifisite.template,
                           landingpage=landingpage,
                           app_id=fb_appid,
                           trackid=trackid,
                           fb_page=fb_page,
                           location=location,
                           checkinform=checkinform)