Advertisement
Guest User

Untitled

a guest
Nov 9th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.   <script>
  2.             function getURLparams()
  3.             {
  4.                 var vars = [], hash;
  5.                 var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
  6.                 for(var i = 0; i < hashes.length; i++)
  7.                 {
  8.                     hash = hashes[i].split('=');
  9.                     vars.push(hash[0]);
  10.                     vars[hash[0]] = hash[1];
  11.                 }
  12.                 return vars;
  13.             }
  14.  
  15.             $( document ).ready(function() {
  16.                 /**
  17.                  * logon action
  18.                  */
  19.                 $("#signin").click(function (event) {
  20.                     event.preventDefault();
  21.                     // hide alerts
  22.                     $("#alertMSG").addClass("hidden");
  23.                     // try to login
  24.                     $.ajax({
  25.                         type: "POST",
  26.                         url: "/api/captiveportal/access/logon/" + zoneid + "/",
  27.                         dataType:"json",
  28.                         data:{ user: $("#inputUsername").val(), password: $("#inputPassword").val() }
  29.                     }).done(function(data) {
  30.                         // redirect on successful login
  31.                         if (data['clientState'] == 'AUTHORIZED') {
  32.                             if (getURLparams()['redirurl'] != undefined) {
  33.                                 window.location = 'http://'+getURLparams()['redirurl']+'?refresh';
  34.                             } else {
  35.                                 // no target, reload page
  36.                                 window.location.reload();
  37.                             }
  38.                         } else {
  39.                             $("#inputUsername").val("");
  40.                             $("#inputPassword").val("");
  41.                             $("#errorMSGtext").html("authentication failed");
  42.                             $("#alertMSG").removeClass("hidden");
  43.                         }
  44.                     }).fail(function(){
  45.                         $("#errorMSGtext").html("unable to connect to authentication server");
  46.                         $("#alertMSG").removeClass("hidden");
  47.                     });
  48.                 });
  49.  
  50.                 /**
  51.                  * login anonymous, only applicable when server is configured without authentication
  52.                  */
  53.                 $("#signin_anon").click(function (event) {
  54.                     event.preventDefault();
  55.                     // hide alerts
  56.                     $("#alertMSG").addClass("hidden");
  57.                     // try to login
  58.                     $.ajax({
  59.                         type: "POST",
  60.                         url: "/api/captiveportal/access/logon/" + zoneid + "/",
  61.                         dataType:"json",
  62.                         data:{ user: '', password: '' }
  63.                     }).done(function(data) {
  64.                         // redirect on successful login
  65.                         if (data['clientState'] == 'AUTHORIZED') {
  66.                             if (getURLparams()['redirurl'] != undefined) {
  67.                                 window.location = 'http://'+getURLparams()['redirurl']+'?refresh';
  68.                             } else {
  69.                                 window.location.reload();
  70.                             }
  71.                         } else {
  72.                             $("#inputUsername").val("");
  73.                             $("#inputPassword").val("");
  74.                             $("#errorMSGtext").html("login failed");
  75.                             $("#alertMSG").removeClass("hidden");
  76.                         }
  77.                     }).fail(function(){
  78.                         $("#errorMSGtext").html("unable to connect to authentication server");
  79.                         $("#alertMSG").removeClass("hidden");
  80.                     });
  81.                 });
  82.  
  83.                 /**
  84.                  * logoff action
  85.                  */
  86.                 $("#logoff").click(function (event) {
  87.                     event.preventDefault();
  88.                     // hide alerts
  89.                     $("#alertMSG").addClass("hidden");
  90.                     // try to login
  91.                     $.ajax({
  92.                         type: "POST",
  93.                         url: "/api/captiveportal/access/logoff/" + zoneid + "/",
  94.                         dataType:"json",
  95.                         data:{ user: '', password: '' }
  96.                     }).done(function(data) {
  97.                         // refresh page
  98.                         window.location.reload();
  99.                     }).fail(function(){
  100.                         $("#errorMSGtext").html("unable to connect to authentication server");
  101.                         $("#alertMSG").removeClass("hidden");
  102.                     });
  103.                 });
  104.  
  105.                 /**
  106.                  * close / hide error message
  107.                  */
  108.                 $("#btnCloseError").click(function(){
  109.                     $("#alertMSG").addClass("hidden");
  110.                 });
  111.  
  112.                 /**
  113.                  * execute after pageload
  114.                  */
  115.                  $.ajax({
  116.                      type: "POST",
  117.                      url: "/api/captiveportal/access/status/" + zoneid + "/",
  118.                      dataType:"json",
  119.                      data:{ user: $("#inputUsername").val(), password: $("#inputPassword").val() }
  120.                  }).done(function(data) {
  121.                     if (data['clientState'] == 'AUTHORIZED') {
  122.                       $("#logout_frm").removeClass('hidden');
  123.                     } else if (data['authType'] == 'none') {
  124.                         $("#login_none").removeClass('hidden');
  125.                     } else {
  126.                         $("#login_password").removeClass('hidden');
  127.                     }
  128.                  }).fail(function(){
  129.                      $("#errorMSGtext").html("unable to connect to authentication server");
  130.                      $("#alertMSG").removeClass("hidden");
  131.                  });
  132.  
  133.             });
  134.         </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement