[Gelöst]Captive Portal schickt mich immer auf die Logout Seite

Started by jho, January 03, 2017, 03:10:43 PM

Previous topic - Next topic
Moin Moin,

konnte in dem Forum leider noch nichts zu meinem Problem finden.

Ich habe ein Captive Portal nach folgender Anleitung aufgebaut:
https://docs.opnsense.org/manual/how-tos/guestnet.html

Jetzt zu meinem Problem.
Wenn ich mich im Captive Portal über einen beliebigen Browser anmelde und dann eine Website, z.B. heise.de, aufrufe, dann leitet mich das Captive Portal immer zur Logout Seite weiter. Das ganze passiert nicht wenn ich die Adresse der Webseite voll Ausschreibe, z.B. https://www.heise.de

Das Problem besteht sowohl für http als auch für https.

Kann mir da jmd helfen?

Problem besteht leider weiter hin.

hier nochmal der Genaue Ablauf:

Verbinden mit dem WLAN
Aufrufen eines Browsers
Aufrufen einer http Seite
Captive Portal Login erscheint
Einloggen in das Captive Portal
Weiterleitung zur Aufgerufenen Internetseite
Aufruf von einer anderen Seite ohne vollständige Adresse z.b. golem.de
Weiterleitung zum logout des CP



Hat das evtl etwas mit dem template zu tun?

anbei mal der Code aus meinem.

<!doctype html>
<html>
    <head>

        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

        <meta name="robots" content="index, follow, noodp, noydir" />
        <meta name="keywords" content="" />
        <meta name="description" content="" />
        <meta name="copyright" content="" />
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />

        <title></title>
        <!-- Bootstrap -->
        <link href="css/bootstrap.min.css" rel="stylesheet">
        <link href="css/signin.css" rel="stylesheet">

        <!-- static zone info -->
        <script type="text/javascript" src="js/zone.js"></script>

        <script type="text/javascript" src="js/jquery-1.11.2.min.js"></script>
        <script>
            function getURLparams()
            {
                var vars = [], hash;
                var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
                for(var i = 0; i < hashes.length; i++)
                {
                    hash = hashes[i].split('=');
                    vars.push(hash[0]);
                    vars[hash[0]] = hash[1];
                }
                return vars;
            }

            $( document ).ready(function() {
                /**
                 * logon action
                 */
                $("#signin").click(function (event) {
                    event.preventDefault();
                    // hide alerts
                    $("#alertMSG").addClass("hidden");
                    // try to login
                    $.ajax({
                        type: "POST",
                        url: "/api/captiveportal/access/logon/" + zoneid + "/",
                        dataType:"json",
                        data:{ user: $("#inputUsername").val(), password: $("#inputPassword").val() }
                    }).done(function(data) {
                        // redirect on successful login
                        if (data['clientState'] == 'AUTHORIZED') {
                            if (getURLparams()['redirurl'] != undefined) {
                                window.location = 'http://'+getURLparams()['redirurl']+'?refresh';
                            } else {
                                // no target, reload page
                                window.location.reload();
                            }
                        } else {
                            $("#inputUsername").val("");
                            $("#inputPassword").val("");
                            $("#errorMSGtext").html("authentication failed");
                            $("#alertMSG").removeClass("hidden");
                        }
                    }).fail(function(){
                        $("#errorMSGtext").html("unable to connect to authentication server");
                        $("#alertMSG").removeClass("hidden");
                    });
                });

                /**
                 * login anonymous, only applicable when server is configured without authentication
                 */
                $("#signin_anon").click(function (event) {
                    event.preventDefault();
                    // hide alerts
                    $("#alertMSG").addClass("hidden");
                    // try to login
                    $.ajax({
                        type: "POST",
                        url: "/api/captiveportal/access/logon/" + zoneid + "/",
                        dataType:"json",
                        data:{ user: '', password: '' }
                    }).done(function(data) {
                        // redirect on successful login
                        if (data['clientState'] == 'AUTHORIZED') {
                            if (getURLparams()['redirurl'] != undefined) {
                                window.location = 'http://'+getURLparams()['redirurl']+'?refresh';
                            } else {
                                window.location.reload();
                            }
                        } else {
                            $("#inputUsername").val("");
                            $("#inputPassword").val("");
                            $("#errorMSGtext").html("login failed");
                            $("#alertMSG").removeClass("hidden");
                        }
                    }).fail(function(){
                        $("#errorMSGtext").html("unable to connect to authentication server");
                        $("#alertMSG").removeClass("hidden");
                    });
                });

                /**
                 * logoff action
                 */
                $("#logoff").click(function (event) {
                    event.preventDefault();
                    // hide alerts
                    $("#alertMSG").addClass("hidden");
                    // try to login
                    $.ajax({
                        type: "POST",
                        url: "/api/captiveportal/access/logoff/" + zoneid + "/",
                        dataType:"json",
                        data:{ user: '', password: '' }
                    }).done(function(data) {
                        // refresh page
                        window.location.reload();
                    }).fail(function(){
                        $("#errorMSGtext").html("unable to connect to authentication server");
                        $("#alertMSG").removeClass("hidden");
                    });
                });

                /**
                 * close / hide error message
                 */
                $("#btnCloseError").click(function(){
                    $("#alertMSG").addClass("hidden");
                });

                /**
                 * execute after pageload
                 */
                 $.ajax({
                     type: "POST",
                     url: "/api/captiveportal/access/status/" + zoneid + "/",
                     dataType:"json",
                     data:{ user: $("#inputUsername").val(), password: $("#inputPassword").val() }
                 }).done(function(data) {
                    if (data['clientState'] == 'AUTHORIZED') {
                      $("#logout_frm").removeClass('hidden');
                    } else if (data['authType'] == 'none') {
                        $("#login_none").removeClass('hidden');
                    } else {
                        $("#login_password").removeClass('hidden');
                    }
                 }).fail(function(){
                     $("#errorMSGtext").html("unable to connect to authentication server");
                     $("#alertMSG").removeClass("hidden");
                 });

            });
        </script>
    </head>
    <body>
        <header class="page-head">
<div align="center">
<a href="#">
<img class="brand-logo" src="images/company-logo.png">
</a>
<h1>Willkommen im Grube Gast WLAN.</h1>
</div>
</header>
        <main class="page-content col-sm-6 col-sm-push-3">
          <!-- User option 1: login needed with name and password -->
          <div id="login_password" class="hidden">
              <form class="form-signin">
                  <h2 class="form-signin-heading">Please sign in</h2>
                  <label for="inputUsername" class="sr-only">Username</label>
                  <input type="text" id="inputUsername" class="form-control" placeholder="Username" required autofocus>
                  <label for="inputPassword" class="sr-only">Password</label>
                  <input type="password" id="inputPassword" class="form-control" placeholder="Password" required>
                  <button class="btn btn-primary btn-block" id="signin" type="button">Sign in</button>
              </form>
          </div>
          <!-- User option 2: login needed, without username, password -->
          <div id="login_none" class="hidden">
            <form class="form-signin">
                <button class="btn btn-primary btn-block" id="signin_anon" type="button">Sign in</button>
            </form>
          </div>
          <!-- User option 3: Already logged in, show logout button -->
          <div id="logout_frm" class="hidden">
            <form class="form-signin">
                <button class="btn btn-primary btn-block" id="logoff" type="button">Logout</button>
            </form>
          </div>
          <!-- Message dialog -->
          <div class="alert alert-danger alert-dismissible hidden" role="alert" id="alertMSG">
              <button type="button" class="close" id="btnCloseError" aria-label="Close"><span aria-hidden="true">&times;</span></button>
              <span id="errorMSGtext"></span>
          </div>
        </main>

        <!-- bootstrap script -->
        <script type="text/javascript" src="js/bootstrap.min.js"></script>
    </body>
</html>


Konnte das Problem lösen...

Es lag an den Cache Einstellungen in meinen Browsern. Nachdem ich die Browserdaten gelöscht hatte, funktionierte alles Super.

I am getting the same symptoms.
Clearing browser cache helps but problem just comes back  :(.

OPNsense 16.7.13

Ben.

Hi Ben,

Is this for all attached devices (Phones, PCs, Tablets) or only for a particular group?

Is there any device between the OPNsense and the attached devices like an AP or some other piece of network equipment?


Cheers,
Franco

Hi Franco,

Thought I had cracked it but not sure now!

Issue seems to be pointing to Firefox (Running OPNsense in VM environment with a Peppermint 6 client running  Firefox 40)

Start Firefox, enter URL to access CP and click continue, open another tab and connect OK to any other site, open anther tab and try and access the first URL as used to open CP and get re-direct to Logout.

Have also tried OPNsense on dedicated hardware with Win 10 and Firefox – same issues.

Went back to VM as easier to test and then tried Chromium and no issues.
Have also tried Peppermint 7 with Firefox 50.0.2 and same redirect to logout.

It may be a combination of issues as have been using www.bbc.co.uk to open the CP, which consistently with Firefox would cause a re-direct to logout on another tab.
Have now been trying www.itv.com to open the CP but that doesn't cause a re-direct.

Its late and so will have another look over the weekend.

Regards,
Ben.

Hi Ben,

We have fixes now for MAC detection failures which could be related to this:

https://github.com/opnsense/core/commit/9f950ac

You can apply this to a 17.1 install using the following console command:

# opnsense-patch 9f950ac


Cheers,
Franco