Menu

Timed vouchers that deplete based on first login time

Help
2013-10-30
2013-11-11
  • fridaystreet

    fridaystreet - 2013-10-30

    Hi Dirk,

    How do I setup time based vouchers that will deplete based on first login time and not logged in usage time? I'm sure it must just be a setting I'm missing. The standard timed voucher setup has an attribute called fall-through. Which kind of sounds like it should run on real time not usage time, but it doesn't seem to.

    Any advice as always is greatly appreciated

    Cheers
    Paul

     
  • fridaystreet

    fridaystreet - 2013-11-04

    I think I've tracked down what's going on here. It's checking depleted time against the voucher expiry not against the time allowed by the profile.

    The cron call to UsageTask.php has the following function, which IMO should drill down further in to the radcheck profile attribute and retrieve the RD-Total-Time attribute from the profile component.

    Then if (current_time-login_time) is > Rd-Total-Time, the voucher should be depleted. As it currently operates, with Rd-Voucher attribute being set to a minimum of 1 day, the time is available to be used on and off for the whole day. It's not a true realtime depletion based on the allowed time (ie regardless of if you are logged in the clock is still ticking). There may be cases for both methods, so an option to deplete from first login as describe here or use the expiry as it currently does would probably be the best outcome.

    I'm going to attempt to implement this myself as I really need it to only allow the time of the profile regardless of if someone logs out. If you are happy to add it to the enhancements list that would be greatly appreciated though.

    Kind regards
    Paul

    public function time_left_from_login($username){
    $time_left =false;
    //See if it has an exprire from first login value
    $q_r = $this->Radcheck->find('first',array('conditions' => array('Radcheck.username' => $username,'Radcheck.attribute' => 'Rd-Voucher')));
    if($q_r){

            $expire     = $q_r['Radcheck']['value'];
            $pieces     = explode("-", $expire);
            $time_avail = ($pieces[0] * 86400)+($pieces[1] * 3600)+($pieces[2] * 60)+($pieces[3]);
            $time_since_logon = $this->Radacct->query("SELECT (UNIX_TIMESTAMP(now()) - UNIX_TIMESTAMP(acctstarttime)) as time_since_login from radacct where username='$username' order by acctstarttime ASC LIMIT 1");
            if(!$time_since_logon){
                $time_since_logon = 0;
            }
    
            $time_left  = $time_avail - $time_since_logon[0][0]['time_since_login'];
    
            if($time_left <= 0){
                $time_left = 'depleted';  
            }
        }
        return $time_left;
    }
    
     
  • fridaystreet

    fridaystreet - 2013-11-04

    Not sure if you take submissions of updated code or not Dirk, but I had to fix this for myself so thought I would share for you to consider.

    I've modified the 2 functions perc_used_from_login & time_left_from_login to work from the rd-Total-Time attribute retrieved via the counters. It only uses this updated method of calculation if the Rd-voucher value is set to 0 days (ie it equates to 0 seconds). Otherwise it will use your original method.

    updated UsageTask.php attached. In order to get it to work you need to change the minimum allowed value in the 'days to expire' setting in the RD voucher edit GUI and voucher wizard gui so people can set that to 0 days. I haven't been able to find where this is yet. Maybe you could shed some light.

    Cheers
    Paul

     
  • Freddy FALANGA

    Freddy FALANGA - 2013-11-04

    Hello Paul,

    I experience the same problem with time based voucher (also for a batch generated refer to https://sourceforge.net/p/radiusdesk/discussion/general/thread/2ef8e9a9/).

    I want to know where is located this file to make the same modification ?

    Cheers Freddy

     
  • Freddy FALANGA

    Freddy FALANGA - 2013-11-04

    Hi Paul,

    I saw where it is. I'm going to test and I'll let you know.

    Freddy

     
  • Dirk van der Walt

    Hi Paul,

    Sorry for the slow response (though it seems to be fruitful in a way ;-) ). We moved house so it was quite a busy time the last few days.

    Thanks also for sharing the fix with us, this is indeed much appreciated, and yes I appreciate this type of involvement from the community! This allows the product to reach maturity much faster. In fact I also want to ping you for the modifications you did on the passcode instead of a username / password on the vouchers as this also seems to be a requirement from other members as well.

    I will work the fix into the latest SVN and keep you posted when it is added.

    Kind regards

     
  • fridaystreet

    fridaystreet - 2013-11-04

    Hi Dirk,

    No worries at all, I knew you would surface at some point. Hope the move went well, We're also moving this week so I feel your pain LOL! OK that's great thanks for including it. You will need to change the gui so days to expire can be set to 0 when creating / editing. As I said haven't quite got my head round your rd interface yet.

    I'll sort out the other mods and drop them too you as soon as I can. I'll try and work out how to mod the gui to have a single field option checkbox or something, but may need you to do that or give me a little insight.

    I know I've said it a few times, but it really can't be said enough. This is a truly amazing platform, having access to this much flexibility has meant all our ideas for our custom hotspot service are now within our reach.

    Thanks again

    @Freddy, just remember that it won't work when creating vouchers through the RD GUI. The code in that updated file get's activated if you set the days to expire to 0. Which you can't do through the gui by default as it forces a minimum of 1. I'm not using the gui I have written a wrapper for the API for my own purposes.
    I haven't got my head around the rd interface yet, so I haven't been able to work out where that minimum is being enforced.

    If you want it to work in the mean time just comment out the initial Rd-Voucher check block in the get_time_avail function at the bottom of that file. I've attached another version of the file with it already commented out in case you're not familiar with the code.

    Cheers
    Paul

     
  • Freddy FALANGA

    Freddy FALANGA - 2013-11-04

    Hi Paul,

    Thanks for your help. I've applied your recommandations and all things are going well now. Depletion for used vouchers and voucher's batch are showing the usage status correctly.

    Thank you so much.

    Best regards

     
  • fridaystreet

    fridaystreet - 2013-11-05

    I found the corresponding rd GUI code to allow you to set days to expire to 0 (ie to enable my updated realtime depletion calculation).

    for creating vouchers in /usr/share/nginx/www/rd/app/view/vouchers/winVoucherAddWizard.js

    change line 222 from "minValue : 1," to "minValue : 0,"

    for editing vouchers in
    /usr/share/nginx/www/rd/app/view/vouchers/pnlVoucher.js

    change line 66 from "minValue : 1," to "minValue : 0,"

    ps. if you use chrome you need to clear your browser cache!

     

    Last edit: fridaystreet 2013-11-05
  • Freddy FALANGA

    Freddy FALANGA - 2013-11-05

    Hello Paul,

    I thank you for this precisions and I'm going to modify on my Installation.

    But I'll amaze you by informing you that I'm running RD on Centos 6.4 with nginx web server based and it is functionning properly. You can go to this URL: https://sourceforge.net/p/radiusdesk/discussion/general/thread/30b326b1/

    Thanks for all

     
  • Freddy FALANGA

    Freddy FALANGA - 2013-11-07

    Hi Paul,

    I make all modifications but for this file /usr/share/nginx/www/rd/app/view/vouchers/winVoucherAddWizard.js minValue is not on line 222 but line 213

    Thank you so much.

    Cheers

     
  • Dirk van der Walt

    Hi Paul, Freddy,

    Sorry for being absent on this one during the last few days.

    I think we may have a better solution. Let me just recap on the problem. Correct me where I'm wrong.

    • You want a voucher that have just a time based counter, e.g. one hour. The person can log in and leave at any time but once the voucher is depleted (total time exceeds one hour), no more connection.
    • You don't worry about the "Expire voucher x days after first login".
    • You want the usage to reflect on the progress bar of the voucher grid.

    Is that correct?

     
  • fridaystreet

    fridaystreet - 2013-11-11

    Hi Dirk,

    That's correct. The mods I made above seem to be doing the trick, but it was just a quick fix so I can't say how robust it is. Certainly if you have some time to look at it that would be great.

    Cheers
    Paul

     
  • Freddy FALANGA

    Freddy FALANGA - 2013-11-11

    Hi Dirk,

    You are not wrong.

    Best regards

     

Log in to post a comment.