root/trunk/wifidog-auth/wifidog/auth/index.php @ 1018

Revision 1018, 7.9 KB (checked in by rob_janes, 7 years ago)

* javascript for validating and navigating forms.
* help text (untranslated).
* EVENT_LOGGING enabling/disabling flag.
* use SYSTEM_PATH instead of BASE_URL_PATH and BASE_SSL_PATH where ever appropriate.
* standardize Smarty variables for Network and User info by adding assignSmartyValues($smarty, $self) to Network and User.
* change_password only allowed if logged in.
* non-superadmin can only use change_password to change their own password.
* superadmin can use change_password to change any user password by entering in their password for the old password.
* page_header div defined and positioned in MainUI

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
1<?php
2
3/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
5// +-------------------------------------------------------------------+
6// | WiFiDog Authentication Server                                     |
7// | =============================                                     |
8// |                                                                   |
9// | The WiFiDog Authentication Server is part of the WiFiDog captive  |
10// | portal suite.                                                     |
11// +-------------------------------------------------------------------+
12// | PHP version 5 required.                                           |
13// +-------------------------------------------------------------------+
14// | Homepage:     http://www.wifidog.org/                             |
15// | Source Forge: http://sourceforge.net/projects/wifidog/            |
16// +-------------------------------------------------------------------+
17// | This program is free software; you can redistribute it and/or     |
18// | modify it under the terms of the GNU General Public License as    |
19// | published by the Free Software Foundation; either version 2 of    |
20// | the License, or (at your option) any later version.               |
21// |                                                                   |
22// | This program is distributed in the hope that it will be useful,   |
23// | but WITHOUT ANY WARRANTY; without even the implied warranty of    |
24// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     |
25// | GNU General Public License for more details.                      |
26// |                                                                   |
27// | You should have received a copy of the GNU General Public License |
28// | along with this program; if not, contact:                         |
29// |                                                                   |
30// | Free Software Foundation           Voice:  +1-617-542-5942        |
31// | 59 Temple Place - Suite 330        Fax:    +1-617-542-2652        |
32// | Boston, MA  02111-1307,  USA       gnu@gnu.org                    |
33// |                                                                   |
34// +-------------------------------------------------------------------+
35
36/**
37 * This is the main auth handler, be very carefull while editing this file!
38 *
39 * @package    WiFiDogAuthServer
40 * @author     Benoit Gregoire <bock@step.polymtl.ca>
41 * @author     Philippe April
42 * @copyright  2004-2006 Benoit Gregoire, Technologies Coeus inc.
43 * @copyright  2004-2006 Philippe April
44 * @version    Subversion $Id$
45 * @link       http://www.wifidog.org/
46 */
47
48/**
49 * Load common include file
50 */
51require_once('../include/common.php');
52
53require_once('classes/Network.php');
54
55$auth_response = ACCOUNT_STATUS_DENIED;
56$auth_message = '';
57
58$token = null;
59if (!empty ($_REQUEST['token']))
60{
61    $token = $db->escapeString($_REQUEST['token']);
62}
63
64$db->execSqlUniqueRes("SELECT NOW(), *, CASE WHEN ((NOW() - reg_date) > networks.validation_grace_time) THEN true ELSE false END AS validation_grace_time_expired FROM connections JOIN users ON (users.user_id=connections.user_id) JOIN networks ON (users.account_origin = networks.network_id) WHERE connections.token='$token'", $info, false);
65
66if ($info != null)
67{
68    // Retrieve the associated authenticator
69    $network = Network :: getObject($info['account_origin']);
70    $authenticator = $network->getAuthenticator();
71    if (!$authenticator)
72    {
73        $auth_message .= "| Error: Unable to instantiate authenticator. ";
74        $auth_response = ACCOUNT_STATUS_ERROR;
75    }
76    else
77    {
78        if ($_REQUEST['stage'] == STAGE_LOGIN)
79        {
80            if ($info['token_status'] == TOKEN_UNUSED)
81            {
82                /* This is for the 15 minutes validation period, the exact same code is also present in when the stage is counters.  If you update this one don't forget to update the other one! */
83                if (($info['account_status'] == ACCOUNT_STATUS_VALIDATION) && ($info['validation_grace_time_expired'] == 't'))
84                {
85                    $auth_response = ACCOUNT_STATUS_VALIDATION_FAILED;
86                    $auth_message .= "| The validation grace period which began at ".$info['reg_date']." has now expired. ";
87                }
88                else
89                {
90                    // Start accounting
91                    if ($authenticator->acctStart($info['conn_id'], $auth_message))
92                        $auth_response = ACCOUNT_STATUS_ALLOWED;
93                    else
94                        $auth_response = ACCOUNT_STATUS_DENIED;
95
96                }
97            }
98            else
99                if ($info['token_status'] == TOKEN_INUSE &&
100                                        isset($info['gw_id']) && isset($_REQUEST['gw_id']) && $info['gw_id'] == $_REQUEST['gw_id'] &&
101                                        isset($info['mac']) && isset($_REQUEST['mac']) && $info['mac'] == $_REQUEST['mac'] &&
102                                        isset($info['ip']) && isset($_REQUEST['ip']) && $info['ip'] == $_REQUEST['ip'])
103                {
104                    // This solves the bug where the user clicks twice before getting the portal page
105                    $auth_response = ACCOUNT_STATUS_ALLOWED;
106                }
107                else
108                {
109                    $auth_message .= "| Tried to login with a token that wasn't TOKEN_UNUSED. ";
110                }
111        }
112        else
113            if ($_REQUEST['stage'] == STAGE_LOGOUT || $_REQUEST['stage'] == STAGE_COUNTERS)
114            {
115                if ($_REQUEST['stage'] == STAGE_LOGOUT)
116                {
117                    $authenticator->logout($info['conn_id']);
118                    $auth_message .= "| User is now logged out. ";
119                }
120
121                if ($_REQUEST['stage'] == STAGE_COUNTERS)
122                {
123                    if ($info['token_status'] == TOKEN_INUSE)
124                    {
125                        /* This is for the 15 minutes validation period, the exact same code is also present when the stage is login.  If you update this one don't forget to update the other one! */
126                        if (($info['account_status'] == ACCOUNT_STATUS_VALIDATION) && ($info['validation_grace_time_expired'] == 't'))
127                        {
128                            $auth_response = ACCOUNT_STATUS_VALIDATION_FAILED;
129                            $auth_message .= "| The validation grace period which began at ".$info['reg_date']." has now expired. ";
130                        }
131                        else
132                        {
133                            $auth_response = $info['account_status'];
134                        }
135                    }
136
137                }
138
139                if (!empty ($_REQUEST['incoming']) || !empty ($_REQUEST['outgoing']))
140                {
141                    $incoming = $db->escapeString($_REQUEST['incoming']);
142                    $outgoing = $db->escapeString($_REQUEST['outgoing']);
143
144                    if (($incoming >= $info['incoming']) && ($outgoing >= $info['outgoing']))
145                    {
146                        $authenticator->acctUpdate($info['conn_id'], $incoming, $outgoing);
147                        $auth_message .= "| Updated counters. ";
148                    }
149                    else
150                    {
151                        $auth_message .= "| Warning:  Incoming or outgoing counter is smaller than what is stored in the database; counters not updated. ";
152
153                    }
154                }
155                else
156                {
157                    $auth_message .= "| Incoming or outgoing counter is missing; counters not updated. ";
158                }
159            }
160            else
161            {
162                $auth_message .= "| Error: Unknown stage. ";
163                $auth_response = ACCOUNT_STATUS_ERROR;
164            }
165    }
166}
167else
168{
169    $auth_message .= "| Error: couldn't find the requested token. ";
170    $auth_response = ACCOUNT_STATUS_ERROR;
171}
172
173echo "Auth: $auth_response\n";
174echo "Messages: $auth_message\n";
175
176/*
177 * Local variables:
178 * tab-width: 4
179 * c-basic-offset: 4
180 * c-hanging-comment-ender-p: nil
181 * End:
182 */
183
184?>
Note: See TracBrowser for help on using the browser.