Menu

Radiusdesk API : View user account using API

Help
2019-06-13
2020-02-19
  • nicko surya pratama

    I am trying to get user like the url 'http://127.0.0.1/cake2/rd_cake/permanent_users/index.json'. the only problem with this URL is it retuns all the permanent user account. what i need is only the spesific user. how can i do that? is there any URL to do that and please also give me and example how to do the request. because i have tried the URL 'http://10.253.0.2/cake2/rd_cake/permanent_users/view_basic_info.json' but not returning any result.
    thanks

     
  • Stephen Davies

    Stephen Davies - 2019-06-13

    Hi. Have you tried http://10.253.0.2:3990/json/status
    That will give you the session stats that your looking for..

     
    • nicko surya pratama

      No, i havent tried it. could you give me an example what is the parameter to sent to that url?.
      I Tried To access that url and give me error conection refused.

       

      Last edit: nicko surya pratama 2019-06-14
    • nicko surya pratama

      No, i havent tried it. could you give me an example what is the parameter to sent to that url?
      I Tried To access that url and give me error conection refused.

       

      Last edit: nicko surya pratama 2019-06-14
  • Stephen Davies

    Stephen Davies - 2019-06-14

    I might be misunderstanding. Are you trying to view user stats when logged into the portal?

     

    Last edit: Stephen Davies 2019-06-14
    • nicko surya pratama

      no. i want to see the user password. so if i forget my login password i can see it by sending my username to radiusdesk API. i use this url http://127.0.0.1/cake2/rd_cake/permanent_users/view_password.json but no luck.

       
    • Nana Korantey

      Nana Korantey - 2019-07-09

      Hello Stephen, How do I create url for the user to check is stats or alert him by email when the data is almost finished

       
      • Stephen Davies

        Stephen Davies - 2019-07-09

        Hi Nana.
        To get the users stats is quite easy. You can grab the data in the background using jquery for instance and update the stats on a stats page how you like. I have wrote some code for this and will post below. To send an email alert based on data useage would involve some programming to read the field in the table that holds the data used and trigger an email based on the threshold that you set. You could setup a cron to check the usage at intervals, send an email when data usage exceeded and update a field that the email was sent.

         
        • Nana Korantey

          Nana Korantey - 2019-07-10

          Many thanks. I will look into it and get back to you.

          Thanks

          On Tue, 9 Jul 2019 at 15:49, Stephen Davies bargee@users.sourceforge.net
          wrote:

          Hi Nana.
          To get the users stats is quite easy. You can grab the data in the
          background using jquery for instance and update the stats on a stats page
          how you like. I have wrote some code for this and will post below. To send
          an email alert based on data useage would involve some programming to read
          the field in the table that holds the data used and trigger an email based
          on the threshold that you set. You could setup a cron to check the usage at
          intervals, send an email when data usage exceeded and update a field that
          the email was sent.


          Radiusdesk API : View user account using API
          https://sourceforge.net/p/radiusdesk/discussion/help/thread/9c2b04c886/?limit=25#1ba0/d925/7253


          Sent from sourceforge.net because you indicated interest in
          https://sourceforge.net/p/radiusdesk/discussion/help/

          To unsubscribe from further messages, please visit
          https://sourceforge.net/auth/subscriptions/

           
      • Stephen Davies

        Stephen Davies - 2019-07-09

        This webpage can be used as a 'stats' page. It looks at the session usage shown on the Dynamic Login Pages in the background and allows a custom stats display.
        It's little crude and needs improvements but you get the idea.

        <?php
        function db_conn()
        {
            $host = 'localhost';
            $user = '';
            $password = '';
            $database = '';
            $pdoOptions = array(
            PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
            PDO::ATTR_EMULATE_PREPARES => false
        );
            //Connect
            return $conn = new PDO("mysql:host=$host;dbname=$database", $user, $password, $pdoOptions);
        }
        
          function filterVar($data) // Sanitise POST & GET variables
          {
              $data = filter_var(filter_var($data, FILTER_SANITIZE_MAGIC_QUOTES), FILTER_SANITIZE_STRING);
              $data = stripslashes($data);
              return $data;
          }
        
        function getNas($nasid)
        {
            $stmt = db_conn()->prepare("SELECT nas.nas_unique, nas.nas_location FROM nas WHERE nas.nas_unique = :nasid AND nas.nas_live = '1'");
            $stmt->bindValue(':nasid', filterVar($nasid));
            $stmt->execute();
            $row = $stmt -> fetch();
            return $row;
        }
        
        function getLocation($locid) // location id from nas
        {
            $stmt = db_conn()->prepare("SELECT locations.loc_about, locations.loc_unique, locations.loc_user, locations.loc_name FROM locations WHERE locations.loc_id = :locid");
            $stmt->bindValue(':locid', filterVar($locid));
            $stmt->execute();
            $row = $stmt -> fetch();
            return $row;
        }
        $nas = filterVar($_GET['nas']);
        
        $login_url = "http://YOUR-URL-HERE/cake3/rd_cake/dynamic-details/chilli-browser-detect/?";
        $login_url .= "voucher=TESTVOUCHER";
        foreach ($_GET as $key => $value) {
            $login_url .= "&".filterVar($key)."=".filterVar($value);
        }
        
        ?>
        <!DOCTYPE html>
        <html class="loading" lang="en" data-textdirection="ltr">
          <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <meta http-equiv="X-UA-Compatible" content="IE=edge">
            <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
            <title>User Login - guest WiFi</title>
            <link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
          </head>
          <body class="horizontal-layout page-header-light horizontal-menu 1-column login-bg  blank-page blank-page" data-open="click" data-menu="horizontal-menu" data-col="1-column">
            <div class="row">
              <div class="col s12">
                <div class="container"><div id="login-page" class="row">
          <div class="col s12 m6 l4 z-depth-4 card-panel border-radius-6 login-card bg-opacity-8">
            <form class="login-form">
              <div class="row">
                <div class="input-field col s12">
                  <h6 class="flow-text">Guest WiFi</h6>
                  <noscript>
                   You do not have Javascript enabled. This page will not work!
                  </noscript>
                  <?php if ($_GET['nas'] == "") { // if a hotspot?>
                    <h5 class="red-text flow-text">Not a Hotspot</h5>
                  <?php
        } ?>
                  <h5 class="flow-text"><?php echo getLocation(getNas($nas)['nas_location'])['loc_name']; ?></h5>
                  <span class="flow-text"><?php echo getLocation(getNas($nas)['nas_location'])['loc_about']; ?></span>
                </div>
              </div>
              <div id="loginbox">
              <div class="row margin">
                <div class="input-field col s12">
                  <i class="material-icons prefix pt-2">confirmation_number</i>
                  <input id="voucher" type="text">
                  <label for="voucher" class="center-align">Voucher</label>
                </div>
              </div>
              <div class="row">
                <div class="input-field col s12">
                  <a id="login" class="btn waves-effect waves-light border-round gradient-45deg-purple-deep-orange col s12">Login</a><br><br>
                  <div class="progress hide">
                   <div class="indeterminate"></div>
                  </div>
                </div>
              </div>
              </div>
              <div id="sessionbox" class="center hide">
                <h5><i class="material-icons medium">lock</i> <b>You are logged in</b></h5>
                <span class="flow-text">Session:</span> GUEST</span><br>
                <span class="flow-text">Data In:</span> <span id="datain" class="flow-text"></span><br>
                <span class="flow-text">Data Out:</span> <span id="dataout" class="flow-text"></span><br>
                <a id="logout" href="http://logout" class="btn waves-effect waves-light border-round gradient-45deg-purple-deep-orange col s12">Logout</a>
                <span class="flow-text black-text">Keep this session info window open</span>
                <a href="https://google.co.uk" target="_blank" class="btn waves-effect waves-light border-round gradient-45deg-purple-deep-orange col s12">Open new window</a>
                <br>
              </div>
              <iframe id="loginframe" src="" style="width:0;height:0;border:0; border:none;"></iframe>
            </form>
          </div>
        </div>
                </div>
              </div>
            </div>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>    
        <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
            <script>
            loginstatus();
          $("#login").click(function() {
              M.toast({html: 'Logging in'});
              $('#login').addClass('disabled');
              $('#loginframe').attr('src', '<?php echo $login_url; ?>');
              $('.progress').removeClass('hide');
              $('.progress').show();
        
              setTimeout(function(){
              loginstatus();
              },4000);
        
              setTimeout(function(){
              $('#login').removeClass('disabled');
              $('.progress').hide();
            },5000);
             });
        
          function loginstatus() {
           $.ajax({
              type:'POST',
              url:'http://NAS-IP-HERE:3990/json/status',
              dataType : 'jsonp'
            })
            .done(function(data){
              console.log(data['clientState']);
              //console.log(data['session']['userName']);
              if (data['clientState'] == 0) {
               $('#loginbox').show();
               $('#sessionbox').hide();
              } else {
               $('#loginbox').hide();
               $('.progress').hide();
               $('#sessionbox').removeClass('hide');
               $('#sessionbox').show();
               $('#vouchercode').text(data['session']['userName']);
               $('#datain').text(formatBytes(data['accounting']['inputOctets']));
               $('#dataout').text(formatBytes(data['accounting']['outputOctets']));
              }
            })
            .fail(function() {
              console.log( "Network Error!" );
            });
          };
        
          function formatBytes(bytes, decimals = 2) {
              if (bytes === 0) return '0 Bytes';
              const k = 1024;
              const dm = decimals < 0 ? 0 : decimals;
              const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
              const i = Math.floor(Math.log(bytes) / Math.log(k));
              return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
          }
        
          setInterval(loginstatus, 20000);
        
          $( "#logout" ).click(function() {
              M.toast({html: 'Logging out'});
              $('#loginframe').attr('src','');
              $('#login').removeClass('disabled');
              console.log("Log out");
             });
            </script>
          </body>
        </html>
        
         
        • Nana Korantey

          Nana Korantey - 2019-08-17

          Hello Davies,
          I'm still not able to allow the users to see their data usage and session. Do I have to copy the script above and import into my systems?

          Thanks.

           
        • certgio monasterio

          Hi
            I created a php file in the login / rd_client folder and pasted this content with the database data
          but I have not had any success
          How should I place this?

           

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.