Changeset 516

Show
Ignore:
Timestamp:
03/29/05 17:13:28 (8 years ago)
Author:
fproulx
Message:

2005-03-28 Fran�ois Proulx <francois.proulx@…>

  • schema_validate.php : Modified schema : dropped e-mail + account unique index, dropped email not empty constraint
  • Schema is now at version 3
  • Coded RADIUS authentication
  • Modified templates to show a select box when more than one server is configured
  • Coded RADIUS accounting and backward compatibility accounting
  • Modified many statistics SQL queries to match new Users table
  • modified statistics templates to match user_id and account_origin
  • TODO : Fix lost_username and lost_password ( issue since we dropped the unique constraint on emails... )
  • TODO : Heavy testing possibly with remote RADIUS servers
Location:
trunk/wifidog-auth
Files:
24 modified

Legend:

Unmodified
Added
Removed
  • trunk/wifidog-auth/ChangeLog

    r514 r516  
    11# $Header$ 
     22005-03-28 Fran�ois Proulx  <francois.proulx@gmail.com> 
     3        * schema_validate.php : Modified schema : dropped e-mail + account unique index, dropped email not empty constraint 
     4        * Schema is now at version 3 
     5        * Coded RADIUS authentication 
     6        * Modified templates to show a select box when more than one server is configured 
     7        * Coded RADIUS accounting and backward compatibility accounting 
     8        * Modified many statistics SQL queries to match new Users table 
     9        * modified statistics templates to match user_id and account_origin 
     10        * TODO : Fix lost_username and lost_password ( issue since we dropped the unique constraint on emails... ) 
     11        * TODO : Heavy testing possibly with remote RADIUS servers 
     12         
    2132005-03-28 Benoit Gr�goire  <bock@step.polymtl.ca> 
    314        * sql:  Put initial data in a transaction, and specify the wifidog user so you do not have to su to it while using sync_sql_for_svs 
  • trunk/wifidog-auth/wifidog/admin/templates/online_users.html

    r398 r516  
    1111<tr> 
    1212        <th>Node</th> 
    13         <th>Users</th> 
     13        <th>Username</th> 
     14        <th>Origin</th> 
     15        <th>User ID</th> 
    1416        <th>Logged in Since</th> 
    1517        <th>Traffic IN/OUT</th> 
     
    1820<tr> 
    1921    <td>{$users_array[i].name}</td> 
     22    <td>{$users_array[i].username}</td> 
     23    <td>{$users_array[i].account_origin}</td> 
    2024    <td><a href="user_log.php?user_id={$users_array[i].user_id}">{$users_array[i].user_id}</a></td> 
    2125    <td>{$users_array[i].timestamp_in|date_format:"%Y/%m/%d %H:%M:%S"}</td> 
  • trunk/wifidog-auth/wifidog/admin/templates/user_log.html

    r398 r516  
    1717<table> 
    1818<tr> 
    19         <th>Users</th> 
     19        <th>Username</th> 
     20        <th>Origin</th> 
     21        <th>User IDs</th> 
    2022        <th>Registered On</th> 
    2123        <th>Account Status</th> 
     
    2325{section name=i loop=$users_array} 
    2426<tr> 
    25     <td><a href="?user_id={$users_array[i].user_id}">{$users_array[i].user_id}</a></td> 
     27        <td>{$users_array[i].username}</a></td> 
     28        <td>{$users_array[i].account_origin}</td> 
     29        <td><a href="?user_id={$users_array[i].user_id}">{$users_array[i].user_id}</a></td> 
    2630    <td>{$users_array[i].reg_date|date_format:"%Y/%m/%d"}</td> 
    2731    {* hack, need to put info in variable before we can use $account_status_to_text *} 
  • trunk/wifidog-auth/wifidog/admin/templates/user_log_detailed.html

    r376 r516  
    2222<tr> 
    2323        <th>User email:</th> 
    24         <td>{$userinfo.email}</td> 
     24        <td>{if $userinfo.email} {$userinfo.email} {else} Unknown e-mail {/if}</td> 
     25</tr> 
     26<tr> 
     27        <th>Username:</th> 
     28        <td>{$userinfo.username}</td> 
     29</tr> 
     30<tr> 
     31        <th>Account origin:</th> 
     32        <td>{$userinfo.account_origin}</td> 
    2533</tr> 
    2634<tr> 
  • trunk/wifidog-auth/wifidog/admin/templates/user_stats.html

    r411 r516  
    3535    <table> 
    3636    <tr> 
    37         <th>User</th> 
     37        <th>User ID</th> 
    3838        <th>Number of hotspots visited</th> 
    3939    </tr> 
     
    4141    {section name=i loop=$most_mobile_users} 
    4242    <tr> 
    43         <td>{$most_mobile_users[i].user_id}</td> 
     43        <td><a href="user_log.php?user_id={$most_mobile_users[i].user_id}">{$most_mobile_users[i].user_id}</a></td> 
    4444        <td>{$most_mobile_users[i].num_hotspots_visited}</td> 
    4545    </tr> 
     
    5656    <table> 
    5757    <tr> 
    58         <th>User</th> 
     58        <th>User ID</th> 
    5959        <th>Number of distinct days user has used the network</th> 
    6060    </tr> 
     
    6262    {section name=i loop=$most_frequent_users} 
    6363    <tr> 
    64         <td>{$most_frequent_users[i].user_id}</td> 
     64        <td><a href="user_log.php?user_id={$most_frequent_users[i].user_id}">{$most_frequent_users[i].user_id}</a></td> 
    6565        <td>{$most_frequent_users[i].active_days}</td> 
    6666    </tr> 
     
    7777    <table> 
    7878    <tr> 
    79         <th>User</th> 
     79        <th>User ID</th> 
    8080        <th>Total (MB)</th> 
    8181        <th>Incoming (MB)</th> 
     
    8585    {section name=i loop=$most_greedy_users} 
    8686    <tr> 
    87         <td>{$most_greedy_users[i].user_id}</td> 
     87        <td><a href="user_log.php?user_id={$most_greedy_users[i].user_id}">{$most_greedy_users[i].user_id}</a></td> 
    8888        <td>{$most_greedy_users[i].total}</td> 
    8989        <td>{$most_greedy_users[i].total_incoming}</td> 
  • trunk/wifidog-auth/wifidog/admin/user_log.php

    r512 r516  
    11<?php 
    2   /********************************************************************\ 
    3    * This program is free software; you can redistribute it and/or    * 
    4    * modify it under the terms of the GNU General Public License as   * 
    5    * published by the Free Software Foundation; either version 2 of   * 
    6    * the License, or (at your option) any later version.              * 
    7    *                                                                  * 
    8    * This program is distributed in the hope that it will be useful,  * 
    9    * but WITHOUT ANY WARRANTY; without even the implied warranty of   * 
    10    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    * 
    11    * GNU General Public License for more details.                     * 
    12    *                                                                  * 
    13    * You should have received a copy of the GNU General Public License* 
    14    * along with this program; if not, contact:                        * 
    15    *                                                                  * 
    16    * Free Software Foundation           Voice:  +1-617-542-5942       * 
    17    * 59 Temple Place - Suite 330        Fax:    +1-617-542-2652       * 
    18    * Boston, MA  02111-1307,  USA       gnu@gnu.org                   * 
    19    *                                                                  * 
    20    \********************************************************************/ 
    21   /**@file 
    22    * @author Copyright (C) 2004 Philippe April. 
    23    */ 
    24 define('BASEPATH','../'); 
     2 
     3/********************************************************************\ 
     4 * This program is free software; you can redistribute it and/or    * 
     5 * modify it under the terms of the GNU General Public License as   * 
     6 * published by the Free Software Foundation; either version 2 of   * 
     7 * the License, or (at your option) any later version.              * 
     8 *                                                                  * 
     9 * This program is distributed in the hope that it will be useful,  * 
     10 * but WITHOUT ANY WARRANTY; without even the implied warranty of   * 
     11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    * 
     12 * GNU General Public License for more details.                     * 
     13 *                                                                  * 
     14 * You should have received a copy of the GNU General Public License* 
     15 * along with this program; if not, contact:                        * 
     16 *                                                                  * 
     17 * Free Software Foundation           Voice:  +1-617-542-5942       * 
     18 * 59 Temple Place - Suite 330        Fax:    +1-617-542-2652       * 
     19 * Boston, MA  02111-1307,  USA       gnu@gnu.org                   * 
     20 *                                                                  * 
     21 \********************************************************************/ 
     22/**@file 
     23 * @author Copyright (C) 2004 Philippe April. 
     24 */ 
     25define('BASEPATH', '../'); 
    2526require_once 'admin_common.php'; 
    2627require_once BASEPATH.'classes/User.php'; 
    2728 
    28 $total = array(); 
     29$total = array (); 
    2930$total['incoming'] = 0; 
    3031$total['outgoing'] = 0; 
    3132 
    32 if (!empty($_REQUEST['user_id'])) { 
    33     try { 
    34         $user = User::getUserByID($_REQUEST['user_id']); 
    35         $userinfo = $user->getInfoArray(); 
    36         $userinfo['account_status_description'] = $account_status_to_text[$userinfo['account_status']];  
    37             $smarty->assign("userinfo", $userinfo); 
     33if (!empty ($_REQUEST['user_id'])) 
     34{ 
     35        try 
     36        { 
     37                $user = User :: getUserByID($_REQUEST['user_id']); 
     38                $userinfo = $user->getInfoArray(); 
     39                $userinfo['account_status_description'] = $account_status_to_text[$userinfo['account_status']]; 
     40                $smarty->assign("userinfo", $userinfo); 
    3841 
    39         $connections = $user->getConnections(); 
    40         if ($connections) { 
    41             foreach($connections as $connection) { 
    42                 $total['incoming'] += $connection['incoming']; 
    43              $total['outgoing'] += $connection['outgoing']; 
    44                 $connection['token_status_description'] = $token_to_text[$connection['token_status']]; 
    45                 $smarty->append("connections", $connection); 
    46             } 
    47         } 
    48             $smarty->assign("total", $total); 
    49     } catch (Exception $e) { 
    50         $smarty->assign("error", $e->getMessage()); 
    51     } 
    52     $smarty->display("admin/templates/user_log_detailed.html"); 
    53 } else { 
    54     $smarty->assign('sort_ids', array('username','reg_date')); 
    55     $smarty->assign('direction_ids', array('asc','desc')); 
     42                $connections = $user->getConnections(); 
     43                if ($connections) 
     44                { 
     45                        foreach ($connections as $connection) 
     46                        { 
     47                                $total['incoming'] += $connection['incoming']; 
     48                                $total['outgoing'] += $connection['outgoing']; 
     49                                $connection['token_status_description'] = $token_to_text[$connection['token_status']]; 
     50                                $smarty->append("connections", $connection); 
     51                        } 
     52                } 
     53                $smarty->assign("total", $total); 
     54        } 
     55        catch (Exception $e) 
     56        { 
     57                $smarty->assign("error", $e->getMessage()); 
     58        } 
     59        $smarty->display("admin/templates/user_log_detailed.html"); 
     60} 
     61else 
     62{ 
     63        $smarty->assign('sort_ids', array ('username', 'account_origin', 'reg_date')); 
     64        $smarty->assign('direction_ids', array ('asc', 'desc')); 
    5665 
    57     $sort      = isset($_REQUEST['sort'])      ? $_REQUEST['sort']      : "user_id"; 
    58     $direction = isset($_REQUEST['direction']) ? $_REQUEST['direction'] : "asc"; 
     66        $sort = isset ($_REQUEST['sort']) ? $_REQUEST['sort'] : "user_id"; 
     67        $direction = isset ($_REQUEST['direction']) ? $_REQUEST['direction'] : "asc"; 
    5968 
    60     $smarty->assign("sort",      $sort); 
    61     $smarty->assign("direction", $direction); 
     69        $smarty->assign("sort", $sort); 
     70        $smarty->assign("direction", $direction); 
    6271 
    63     if (isset($_REQUEST["page"]) && is_numeric($_REQUEST["page"])) { 
    64         $current_page = $_REQUEST["page"]; 
    65     } else { 
    66         $current_page = 1; 
    67     } 
    68     $smarty->assign("page", $current_page); 
     72        if (isset ($_REQUEST["page"]) && is_numeric($_REQUEST["page"])) 
     73        { 
     74                $current_page = $_REQUEST["page"]; 
     75        } 
     76        else 
     77        { 
     78                $current_page = 1; 
     79        } 
     80        $smarty->assign("page", $current_page); 
    6981 
    70     $per_page = 100; 
    71     $offset = (($current_page * $per_page) - $per_page + 1); 
    72     $pages = $stats->getNumUsers() / $per_page; 
    73     for ($i = 1; $i <= $pages+1; $i++) { 
    74         $smarty->append("pages", array( 
    75                 'number' => $i, 
    76                 'selected' => ($i == $current_page), 
    77             )); 
    78     } 
     82        $per_page = 100; 
     83        $offset = (($current_page * $per_page) - $per_page); 
     84        $pages = $stats->getNumUsers() / $per_page; 
     85        for ($i = 1; $i <= $pages +1; $i ++) 
     86        { 
     87                $smarty->append("pages", array ('number' => $i, 'selected' => ($i == $current_page),)); 
     88        } 
    7989 
    80     $db->ExecSql("SELECT user_id,username,reg_date,account_status FROM users ORDER BY $sort $direction LIMIT $per_page OFFSET $offset", $users_res); 
    81     if ($users_res) { 
    82             $smarty->assign("users_array", $users_res); 
    83     } else { 
    84         $smarty->assign("error", _('Internal error.')); 
    85     } 
     90        $db->ExecSql("SELECT user_id,username,account_origin,reg_date,account_status FROM users ORDER BY $sort $direction LIMIT $per_page OFFSET $offset", $users_res); 
     91        if ($users_res) 
     92        { 
     93                $smarty->assign("users_array", $users_res); 
     94        } 
     95        else 
     96        { 
     97                $smarty->assign("error", _('Internal error.')); 
     98        } 
    8699 
    87     $smarty->assign("account_status_to_text", $account_status_to_text); 
    88     $smarty->display("admin/templates/user_log.html"); 
     100        $smarty->assign("account_status_to_text", $account_status_to_text); 
     101        $smarty->display("admin/templates/user_log.html"); 
    89102} 
    90103?> 
     104 
  • trunk/wifidog-auth/wifidog/auth/index.php

    r305 r516  
    11<?php 
    2   // $Id$ 
    3   /********************************************************************\ 
    4    * This program is free software; you can redistribute it and/or    * 
    5    * modify it under the terms of the GNU General Public License as   * 
    6    * published by the Free Software Foundation; either version 2 of   * 
    7    * the License, or (at your option) any later version.              * 
    8    *                                                                  * 
    9    * This program is distributed in the hope that it will be useful,  * 
    10    * but WITHOUT ANY WARRANTY; without even the implied warranty of   * 
    11    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    * 
    12    * GNU General Public License for more details.                     * 
    13    *                                                                  * 
    14    * You should have received a copy of the GNU General Public License* 
    15    * along with this program; if not, contact:                        * 
    16    *                                                                  * 
    17    * Free Software Foundation           Voice:  +1-617-542-5942       * 
    18    * 59 Temple Place - Suite 330        Fax:    +1-617-542-2652       * 
    19    * Boston, MA  02111-1307,  USA       gnu@gnu.org                   * 
    20    *                                                                  * 
    21    \********************************************************************/ 
    22   /**@file index.php 
    23    * This is the main auth handler, be very carefull while editing this file. 
    24    * @author Copyright (C) 2004 Benoit Gr�goire et Philippe April 
    25    */ 
    26 define('BASEPATH','../'); 
     2 
     3 
     4// $Id$ 
     5/********************************************************************\ 
     6 * This program is free software; you can redistribute it and/or    * 
     7 * modify it under the terms of the GNU General Public License as   * 
     8 * published by the Free Software Foundation; either version 2 of   * 
     9 * the License, or (at your option) any later version.              * 
     10 *                                                                  * 
     11 * This program is distributed in the hope that it will be useful,  * 
     12 * but WITHOUT ANY WARRANTY; without even the implied warranty of   * 
     13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    * 
     14 * GNU General Public License for more details.                     * 
     15 *                                                                  * 
     16 * You should have received a copy of the GNU General Public License* 
     17 * along with this program; if not, contact:                        * 
     18 *                                                                  * 
     19 * Free Software Foundation           Voice:  +1-617-542-5942       * 
     20 * 59 Temple Place - Suite 330        Fax:    +1-617-542-2652       * 
     21 * Boston, MA  02111-1307,  USA       gnu@gnu.org                   * 
     22 *                                                                  * 
     23 \********************************************************************/ 
     24/**@file index.php 
     25 * This is the main auth handler, be very carefull while editing this file. 
     26 * @author Copyright (C) 2004 Benoit Gr�goire et Philippe April 
     27 */ 
     28define('BASEPATH', '../'); 
    2729require_once BASEPATH.'include/common.php'; 
    2830 
     
    3133 
    3234$token = $db->EscapeString($_REQUEST['token']); 
    33 $db->ExecSqlUniqueRes("SELECT *, CASE WHEN ((NOW() - reg_date) > interval '".VALIDATION_GRACE_TIME." minutes') THEN true ELSE false END AS validation_grace_time_expired FROM users,connections WHERE users.user_id=connections.user_id AND connections.token='$token'", $info, false); 
     35$db->ExecSqlUniqueRes("SELECT NOW(), *, CASE WHEN ((NOW() - reg_date) > interval '".VALIDATION_GRACE_TIME." minutes') THEN true ELSE false END AS validation_grace_time_expired FROM users,connections WHERE users.user_id=connections.user_id AND connections.token='$token'", $info, false); 
    3436if ($info != null) 
    35   { 
    36     if ($_REQUEST['stage']== STAGE_LOGIN) 
    37       { 
    38         if ($info['token_status'] == TOKEN_UNUSED)  
    39           { 
    40                 /* 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! */ 
    41                 if (($info['account_status'] == ACCOUNT_STATUS_VALIDATION) && ($info['validation_grace_time_expired']=='t'))  
    42                   { 
    43                     $auth_response = ACCOUNT_STATUS_VALIDATION_FAILED; 
    44                     $auth_message .= "| The validation grace period which began at ".$info['reg_date']." has now expired. "; 
    45                   } 
     37{ 
     38        // Retrieve the associated authenticator 
     39        $authenticator = $AUTH_SOURCE_ARRAY[$info['account_origin']]['authenticator']; 
     40 
     41        if ($_REQUEST['stage'] == STAGE_LOGIN) 
     42        { 
     43                if ($info['token_status'] == TOKEN_UNUSED) 
     44                { 
     45                        /* 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! */ 
     46                        if (($info['account_status'] == ACCOUNT_STATUS_VALIDATION) && ($info['validation_grace_time_expired'] == 't')) 
     47                        { 
     48                                $auth_response = ACCOUNT_STATUS_VALIDATION_FAILED; 
     49                                $auth_message .= "| The validation grace period which began at ".$info['reg_date']." has now expired. "; 
     50                        } 
     51                        else 
     52                        { 
     53                                // Start accounting 
     54                                if($authenticator->acctStart($info, $auth_message)) 
     55                                        $auth_response = ACCOUNT_STATUS_ALLOWED; 
     56                                else 
     57                                        $auth_response = ACCOUNT_STATUS_DENIED; 
     58                                 
     59                        } 
     60                } 
    4661                else 
    47                   { 
     62                { 
     63                        $auth_message .= "| Tried to login with a token that wasn't TOKEN_UNUSED. "; 
     64                } 
     65        } 
     66        else 
     67                if ($_REQUEST['stage'] == STAGE_LOGOUT || $_REQUEST['stage'] == STAGE_COUNTERS) 
     68                { 
     69                        if ($_REQUEST['stage'] == STAGE_LOGOUT) 
     70                        { 
     71                                $authenticator->logout($info); 
     72                                $auth_message .= "| User is now logged out. "; 
     73                        } 
    4874 
     75                        if ($_REQUEST['stage'] == STAGE_COUNTERS) 
     76                        { 
     77                                if ($info['token_status'] == TOKEN_INUSE) 
     78                                { 
     79                                        /* This is for the 15 minutes validation period, the exact same code is also present in when the stage is login.  If you update this one don't forget to update the other one! */ 
     80                                        if (($info['account_status'] == ACCOUNT_STATUS_VALIDATION) && ($info['validation_grace_time_expired'] == 't')) 
     81                                        { 
     82                                                $auth_response = ACCOUNT_STATUS_VALIDATION_FAILED; 
     83                                                $auth_message .= "| The validation grace period which began at ".$info['reg_date']." has now expired. "; 
     84                                        } 
     85                                        else 
     86                                        { 
     87                                                $auth_response = $info['account_status']; 
     88                                        } 
     89                                } 
    4990 
    50             $auth_response = $info['account_status']; 
    51             /* Login the user */ 
    52             $mac = $db->EscapeString($_REQUEST['mac']); 
    53             $ip = $db->EscapeString($_REQUEST['ip']); 
    54             $sql = "UPDATE connections SET " . 
    55               "token_status='" . TOKEN_INUSE . "'," . 
    56               "user_mac='$mac'," . 
    57               "user_ip='$ip'," . 
    58               "last_updated=NOW()" . 
    59               "WHERE conn_id='{$info['conn_id']}';\n"; 
    60             $db->ExecSqlUpdate($sql, false); 
    61              
    62             /* Logging in with a new token implies that all other active tokens should expire */ 
    63             $sql = "UPDATE connections SET " . 
    64               "timestamp_out=NOW(), token_status='" . TOKEN_USED . "' " . 
    65               "WHERE user_id = '{$info['user_id']}' AND token_status='" . TOKEN_INUSE . "' AND token!='$token';\n"; 
    66             $db->ExecSqlUpdate($sql, false); 
    67             /* Delete all unused tokens for this user, so we don't fill the database with them */ 
    68             $sql = "DELETE FROM connections " 
    69               . "WHERE token_status='" . TOKEN_UNUSED . "' AND user_id = '{$info['user_id']}';\n"; 
    70             $db->ExecSqlUpdate($sql, false); 
    71                           } 
    72           } 
    73         else 
    74           { 
    75             $auth_message .= "| Tried to login with a token that wasn't TOKEN_UNUSED. "; 
    76           } 
    77       } 
    78     else if($_REQUEST['stage']==STAGE_LOGOUT || $_REQUEST['stage']==STAGE_COUNTERS) 
    79       { 
    80         if($_REQUEST['stage']==STAGE_LOGOUT) 
    81           { 
    82             $db->ExecSqlUpdate("UPDATE connections SET " . 
    83                                "timestamp_out=NOW()," . 
    84                                "token_status='" . TOKEN_USED . "' " . 
    85                                "WHERE conn_id='{$info['conn_id']}';\n"); 
    86             $auth_message .= "| User is now logged out. "; 
    87           } 
    88          
    89         if( $_REQUEST['stage']==STAGE_COUNTERS) 
    90           { 
    91             if ($info['token_status'] == TOKEN_INUSE) 
    92               { 
    93                 /* This is for the 15 minutes validation period, the exact same code is also present in when the stage is login.  If you update this one don't forget to update the other one! */ 
    94                 if (($info['account_status'] == ACCOUNT_STATUS_VALIDATION) && ($info['validation_grace_time_expired']=='t'))  
    95                   { 
    96                     $auth_response = ACCOUNT_STATUS_VALIDATION_FAILED; 
    97                     $auth_message .= "| The validation grace period which began at ".$info['reg_date']." has now expired. "; 
    98                   } 
     91                        } 
     92 
     93                        if (!empty ($_REQUEST['incoming']) || !empty ($_REQUEST['outgoing'])) 
     94                        { 
     95                                $incoming = $db->EscapeString($_REQUEST['incoming']); 
     96                                $outgoing = $db->EscapeString($_REQUEST['outgoing']); 
     97 
     98                                if (($incoming >= $info['incoming']) && ($outgoing >= $info['outgoing'])) 
     99                                { 
     100                                        $authenticator->acctUpdate($info, $incoming, $outgoing); 
     101                                        $auth_message .= "| Updated counters. "; 
     102                                } 
     103                                else 
     104                                { 
     105                                        $auth_message .= "| Warning:  Incoming or outgoing counter is smaller than what is stored in the database; counters not updated. "; 
     106 
     107                                } 
     108                        } 
     109                        else 
     110                        { 
     111                                $auth_message .= "| Incoming or outgoing counter is missing; counters not updated. "; 
     112                        } 
     113                } 
    99114                else 
    100                   { 
    101                     $auth_response = $info['account_status']; 
    102                   } 
    103               } 
    104  
    105           } 
    106          
    107         if (!empty($_REQUEST['incoming']) || !empty($_REQUEST['outgoing'])) 
    108           { 
    109             $incoming = $db->EscapeString($_REQUEST['incoming']); 
    110             $outgoing = $db->EscapeString($_REQUEST['outgoing']); 
    111  
    112             if (($incoming >= $info['incoming']) && 
    113                 ($outgoing >= $info['outgoing']))  
    114               { 
    115                 $db->ExecSqlUpdate("UPDATE connections SET " . 
    116                                    "incoming='$incoming'," . 
    117                                    "outgoing='$outgoing'," . 
    118                                    "last_updated=NOW() " . 
    119                                    "WHERE conn_id='{$info['conn_id']}'" 
    120                                    ); 
    121                     $auth_message .= "| Updated counters. "; 
    122               } 
    123             else 
    124               { 
    125                     $auth_message .= "| Warning:  Incoming or outgoing counter is smaller than what is stored in the database; counters not updated. "; 
    126  
    127               } 
    128           } 
    129         else 
    130           { 
    131             $auth_message .= "| Incoming or outgoing counter is missing; counters not updated. "; 
    132           } 
    133       } 
    134     else 
    135       { 
    136         $auth_message .= "| Error: Unknown stage. "; 
     115                { 
     116                        $auth_message .= "| Error: Unknown stage. "; 
     117                        $auth_response = ACCOUNT_STATUS_ERROR; 
     118                } 
     119} 
     120else 
     121{ 
     122        $auth_message .= "| Error: couldn't find the requested token. "; 
    137123        $auth_response = ACCOUNT_STATUS_ERROR; 
    138       } 
    139   } 
    140 else 
    141   { 
    142     $auth_message .= "| Error: couldn't find the requested token. "; 
    143     $auth_response = ACCOUNT_STATUS_ERROR; 
    144   } 
     124} 
    145125 
    146126echo "Auth: $auth_response\n"; 
  • trunk/wifidog-auth/wifidog/classes/Authenticator.php

    r513 r516  
    11<?php 
    2   /********************************************************************\ 
    3    * This program is free software; you can redistribute it and/or    * 
    4    * modify it under the terms of the GNU General Public License as   * 
    5    * published by the Free Software Foundation; either version 2 of   * 
    6    * the License, or (at your option) any later version.              * 
    7    *                                                                  * 
    8    * This program is distributed in the hope that it will be useful,  * 
    9    * but WITHOUT ANY WARRANTY; without even the implied warranty of   * 
    10    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    * 
    11    * GNU General Public License for more details.                     * 
    12    *                                                                  * 
    13    * You should have received a copy of the GNU General Public License* 
    14    * along with this program; if not, contact:                        * 
    15    *                                                                  * 
    16    * Free Software Foundation           Voice:  +1-617-542-5942       * 
    17    * 59 Temple Place - Suite 330        Fax:    +1-617-542-2652       * 
    18    * Boston, MA  02111-1307,  USA       gnu@gnu.org                   * 
    19    *                                                                  * 
    20    \********************************************************************/ 
    21   /**@file Authenticator.php 
    22    * @author Copyright (C) 2005 Benoit Gr�goire <bock@step.polymtl.ca>, Technologies Coeus inc. 
    23    */ 
     2 
     3 
     4/********************************************************************\ 
     5 * This program is free software; you can redistribute it and/or    * 
     6 * modify it under the terms of the GNU General Public License as   * 
     7 * published by the Free Software Foundation; either version 2 of   * 
     8 * the License, or (at your option) any later version.              * 
     9 *                                                                  * 
     10 * This program is distributed in the hope that it will be useful,  * 
     11 * but WITHOUT ANY WARRANTY; without even the implied warranty of   * 
     12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    * 
     13 * GNU General Public License for more details.                     * 
     14 *                                                                  * 
     15 * You should have received a copy of the GNU General Public License* 
     16 * along with this program; if not, contact:                        * 
     17 *                                                                  * 
     18 * Free Software Foundation           Voice:  +1-617-542-5942       * 
     19 * 59 Temple Place - Suite 330        Fax:    +1-617-542-2652       * 
     20 * Boston, MA  02111-1307,  USA       gnu@gnu.org                   * 
     21 *                                                                  * 
     22 \********************************************************************/ 
     23/**@file Authenticator.php 
     24 * @author Copyright (C) 2005 Benoit Gr�goire <bock@step.polymtl.ca>, 
     25 * Technologies Coeus inc. 
     26 */ 
    2427 
    2528/** Abstract class to represent an authentication source */ 
    26 abstract class Authenticator { 
    27 private mAccountOrigin; 
     29abstract class Authenticator 
     30{ 
     31        protected $mAccountOrigin; 
    2832 
    29  function __construct($account_orgin) 
    30  { 
    31    $this->mAccountOrigin=$account_orgin; 
    32  } 
    33   
    34 /** Attempts to login a user against the authentication source.  If successfull, returns a User object */ 
    35   function login() 
    36   { 
    37   } 
     33        function __construct($account_orgin) 
     34        { 
     35                $this->mAccountOrigin = $account_orgin; 
     36        } 
    3837 
    39 /** Logs out the user */ 
    40   function logout() 
    41   { 
    42   } 
     38        /** Attempts to login a user against the authentication source.  If successfull, returns a User object */ 
     39        function login() 
     40        { 
     41        } 
    4342 
    44 /** Start accounting traffic for the user */ 
    45   function acctStart() 
    46   { 
    47   } 
     43        /** Logs out the user */ 
     44        function logout() 
     45        { 
     46        } 
    4847 
    49 /** Update traffic counters */ 
    50   function acctUpdate() 
    51   { 
    52   } 
     48        /** Start accounting traffic for the user */ 
     49        function acctStart($info) 
     50        { 
     51                global $db; 
     52                $auth_response = $info['account_status']; 
     53                /* Login the user */ 
     54                $mac = $db->EscapeString($_REQUEST['mac']); 
     55                $ip = $db->EscapeString($_REQUEST['ip']); 
     56                $sql = "UPDATE connections SET "."token_status='".TOKEN_INUSE."',"."user_mac='$mac',"."user_ip='$ip',"."last_updated=NOW()"."WHERE conn_id='{$info['conn_id']}';\n"; 
     57                $db->ExecSqlUpdate($sql, false); 
    5358 
    54 /** Final update and stop accounting */ 
    55   function acctStop() 
    56   { 
    57   } 
     59                /* Logging in with a new token implies that all other active tokens should expire */ 
     60                $token = $db->EscapeString($_REQUEST['token']); 
     61                $sql = "UPDATE connections SET "."timestamp_out=NOW(), token_status='".TOKEN_USED."' "."WHERE user_id = '{$info['user_id']}' AND token_status='".TOKEN_INUSE."' AND token!='$token';\n"; 
     62                $db->ExecSqlUpdate($sql, false); 
     63                /* Delete all unused tokens for this user, so we don't fill the database with them */ 
     64                $sql = "DELETE FROM connections "."WHERE token_status='".TOKEN_UNUSED."' AND user_id = '{$info['user_id']}';\n"; 
     65                $db->ExecSqlUpdate($sql, false); 
     66        } 
    5867 
    59 }// End class 
     68        /** Update traffic counters */ 
     69        function acctUpdate($info, $incoming, $outgoing) 
     70        { 
     71                // Write traffic counters to database 
     72                global $db; 
     73                $db->ExecSqlUpdate("UPDATE connections SET "."incoming='$incoming',"."outgoing='$outgoing',"."last_updated=NOW() "."WHERE conn_id='{$info['conn_id']}'"); 
     74        } 
     75 
     76        /** Final update and stop accounting */ 
     77        function acctStop($info) 
     78        { 
     79                // Stop traffic counters update 
     80                global $db; 
     81                $db->ExecSqlUpdate("UPDATE connections SET "."timestamp_out=NOW(),"."token_status='".TOKEN_USED."' "."WHERE conn_id='{$info['conn_id']}';\n"); 
     82        } 
     83 
     84} // End class 
    6085?> 
     86 
     87 
  • trunk/wifidog-auth/wifidog/classes/AuthenticatorLocalUser.php

    r513 r516  
    11<?php 
    2   /********************************************************************\ 
    3    * This program is free software; you can redistribute it and/or    * 
    4    * modify it under the terms of the GNU General Public License as   * 
    5    * published by the Free Software Foundation; either version 2 of   * 
    6    * the License, or (at your option) any later version.              * 
    7    *                                                                  * 
    8    * This program is distributed in the hope that it will be useful,  * 
    9    * but WITHOUT ANY WARRANTY; without even the implied warranty of   * 
    10    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    * 
    11    * GNU General Public License for more details.                     * 
    12    *                                                                  * 
    13    * You should have received a copy of the GNU General Public License* 
    14    * along with this program; if not, contact:                        * 
    15    *                                                                  * 
    16    * Free Software Foundation           Voice:  +1-617-542-5942       * 
    17    * 59 Temple Place - Suite 330        Fax:    +1-617-542-2652       * 
    18    * Boston, MA  02111-1307,  USA       gnu@gnu.org                   * 
    19    *                                                                  * 
    20    \********************************************************************/ 
    21   /**@file AuthenticatorLocalUser.php 
    22    * @author Copyright (C) 2005 Benoit Gr�goire <bock@step.polymtl.ca>, Technologies Coeus inc. 
    23    */ 
    24     
     2 
     3/********************************************************************\ 
     4 * This program is free software; you can redistribute it and/or    * 
     5 * modify it under the terms of the GNU General Public License as   * 
     6 * published by the Free Software Foundation; either version 2 of   * 
     7 * the License, or (at your option) any later version.              * 
     8 *                                                                  * 
     9 * This program is distributed in the hope that it will be useful,  * 
     10 * but WITHOUT ANY WARRANTY; without even the implied warranty of   * 
     11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    * 
     12 * GNU General Public License for more details.                     * 
     13 *                                                                  * 
     14 * You should have received a copy of the GNU General Public License* 
     15 * along with this program; if not, contact:                        * 
     16 *                                                                  * 
     17 * Free Software Foundation           Voice:  +1-617-542-5942       * 
     18 * 59 Temple Place - Suite 330        Fax:    +1-617-542-2652       * 
     19 * Boston, MA  02111-1307,  USA       gnu@gnu.org                   * 
     20 *                                                                  * 
     21 \********************************************************************/ 
     22/**@file AuthenticatorLocalUser.php 
     23 * @author Copyright (C) 2005 Benoit Gr�goire <bock@step.polymtl.ca>, 
     24 * Technologies Coeus inc. 
     25 */ 
     26 
    2527require_once BASEPATH.'classes/Authenticator.php'; 
    2628 
    2729/** Internal wifidog user database authentication source */ 
    28 class AuthenticatorLocalUser extends Authenticator { 
     30class AuthenticatorLocalUser extends Authenticator 
     31{ 
    2932 
    30   __construct($account_orgin) 
    31     { 
    32       parent->__construct($account_orgin); 
    33     } 
     33        function __construct($account_orgin) 
     34        { 
     35                parent :: __construct($account_orgin); 
     36        } 
    3437 
     38        /** Returns the hash of the password suitable for storing or comparing in the database.  This hash is the same one as used in NoCat 
     39         * @return The 32 character hash. 
     40         */ 
     41        public static function passwordHash($password) 
     42        { 
     43                return base64_encode(pack("H*", md5($password))); 
     44        } 
    3545 
    36 /** Returns the hash of the password suitable for storing or comparing in the database.  This hash is the same one as used in NoCat 
    37  * @return The 32 character hash. 
    38  */ 
    39   public static function passwordHash($password) { 
    40     return base64_encode(pack("H*", md5($password))); 
    41   } 
     46        /** Attempts to login a user against the authentication source.  If successfull, returns a User object 
     47         * @param username:  A valid identifying token for the source.  Not necessarily unique.  For local user, bots username and email are valid. 
     48         * @param password:  Clear text password. 
     49         * @retval The actual User object if sogin was successfull, false otherwise. 
     50         */ 
     51        function login($username, $password, &$errmsg = null) 
     52        { 
     53                global $db; 
     54                $security = new Security(); 
     55                $retval = false; 
     56                $username = $db->EscapeString($username); 
     57                $password = $db->EscapeString($password); 
     58                $password_hash = self :: passwordHash($_REQUEST['password']); 
    4259 
    43   /** Attempts to login a user against the authentication source.  If successfull, returns a User object 
    44    * @param username:  A valid identifying token for the source.  Not necessarily unique.  For local user, bots username and email are valid. 
    45    * @param password:  Clear text password. 
    46    * @retval The actual User object if sogin was successfull, false otherwise. 
    47    */ 
    48   function login($username, $password, &$errmsg=null) 
    49   { 
    50     global $db; 
    51   $security = new Security(); 
    52     $retval=false; 
    53     $username = $db->EscapeString($username); 
    54     $password = $db->EscapeString($password); 
    55     $password_hash = self::passwordHash($_REQUEST['password']); 
     60                $sql = "SELECT user_id FROM users WHERE (username='$username' OR email='$username') AND account_origin='".LOCAL_USER_ACCOUNT_ORIGIN."' AND pass='$password_hash'"; 
     61                $db->ExecSqlUniqueRes($sql, $user_info, false); 
    5662 
    57     $sql = "SELECT user_id FROM users WHERE (username='$username' OR email='$username') AND account_origin='".LOCAL_USER_ACCOUNT_ORIGIN."' AND pass='$password_hash'"; 
    58     $db->ExecSqlUniqueRes($sql,  $user_info, false); 
    59      
    60     if ($user_info != null)  
    61       { 
    62         $user = new User($user_info['user_id']); 
    63         if($user->isUserValid($errmsg)) 
    64           { 
    65             $retval=&$user; 
    66             $security->login($user->getId(), $password_hash); 
    67             $errmsg = _("Login successfull"); 
    68           } 
    69         else 
    70           { 
    71             $retval=false; 
    72             //Reason for refusal is already in $errmsg 
    73           } 
    74       }  
    75     else  
    76       { 
    77         $user_info = null; 
    78         /* This is only used to discriminate if the problem was a non-existent user of a wrong password. */ 
    79         $db->ExecSqlUniqueRes("SELECT * FROM users WHERE (username='$username' OR email='$username') AND account_origin='".LOCAL_USER_ACCOUNT_ORIGIN."'", $user_info, false); 
    80         if ($user_info == null)  
    81           { 
    82             $errmsg = _('Unknown username or email'); 
    83           } 
    84         else 
    85           { 
    86             $errmsg = _('Incorrect password (Maybe you have CAPS LOCK on?)'); 
    87           } 
    88         $retval=false; 
    89       } 
    90     return $retval; 
    91   } 
    92    
    93   /** Logs out the user */ 
    94   function logout() 
    95   { 
    96   } 
    97    
    98   /** Start accounting traffic for the user */ 
    99   function acctStart() 
    100   { 
    101   } 
    102    
    103   /** Update traffic counters */ 
    104   function acctUpdate() 
    105   { 
    106   } 
     63                if ($user_info != null) 
     64                { 
     65                        $user = new User($user_info['user_id']); 
     66                        if ($user->isUserValid($errmsg)) 
     67                        { 
     68                                $retval = & $user; 
     69                                $security->login($user->getId(), $password_hash); 
     70                                $errmsg = _("Login successfull"); 
     71                        } 
     72                        else 
     73                        { 
     74                                $retval = false; 
     75                                //Reason for refusal is already in $errmsg 
     76                        } 
     77                } 
     78                else 
     79                { 
     80                        $user_info = null; 
     81                        /* This is only used to discriminate if the problem was a non-existent user of a wrong password. */ 
     82                        $db->ExecSqlUniqueRes("SELECT * FROM users WHERE (username='$username' OR email='$username') AND account_origin='".LOCAL_USER_ACCOUNT_ORIGIN."'", $user_info, false); 
     83                        if ($user_info == null) 
     84                        { 
     85                                $errmsg = _('Unknown username or email'); 
     86                        } 
     87                        else 
     88                        { 
     89                                $errmsg = _('Incorrect password (Maybe you have CAPS LOCK on?)'); 
     90                        } 
     91                        $retval = false; 
     92                } 
     93                return $retval; 
     94        } 
    10795 
    108 /** Final update and stop accounting */ 
    109   function acctStop() 
    110   { 
    111   } 
     96        /** Logs out the user */ 
     97        function logout($info, &$errmsg = null) 
     98        { 
     99                $this->acctStop($info); 
     100                return true; 
     101        } 
    112102 
    113 }// End class 
     103        /** Start accounting traffic for the user */ 
     104        function acctStart($info, &$errmsg = null) 
     105        { 
     106                parent :: acctStart($info); 
     107                return true; 
     108        } 
     109 
     110        /** Update traffic counters */ 
     111        function acctUpdate($info, $incoming, $outgoing, &$errmsg = null) 
     112        { 
     113                // Just call the generic counters update 
     114                parent :: acctUpdate($info, $incoming, $outgoing); 
     115                return true; 
     116        } 
     117 
     118        /** Final update and stop accounting */ 
     119        function acctStop($info, &$errmsg = null) 
     120        { 
     121                parent :: acctStop($info); 
     122                return true; 
     123        } 
     124 
     125} // End class 
    114126?> 
     127 
  • trunk/wifidog-auth/wifidog/classes/AuthenticatorRadius.php

    r513 r516  
    11<?php 
    2   /********************************************************************\ 
    3    * This program is free software; you can redistribute it and/or    * 
    4    * modify it under the terms of the GNU General Public License as   * 
    5    * published by the Free Software Foundation; either version 2 of   * 
    6    * the License, or (at your option) any later version.              * 
    7    *                                                                  * 
    8    * This program is distributed in the hope that it will be useful,  * 
    9    * but WITHOUT ANY WARRANTY; without even the implied warranty of   * 
    10    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    * 
    11    * GNU General Public License for more details.                     * 
    12    *                                                                  * 
    13    * You should have received a copy of the GNU General Public License* 
    14    * along with this program; if not, contact:                        * 
    15    *                                                                  * 
    16    * Free Software Foundation           Voice:  +1-617-542-5942       * 
    17    * 59 Temple Place - Suite 330        Fax:    +1-617-542-2652       * 
    18    * Boston, MA  02111-1307,  USA       gnu@gnu.org                   * 
    19    *                                                                  * 
    20    \********************************************************************/ 
    21   /**@file AuthenticatorRadius.php 
    22    * @author Copyright (C) 2005 Benoit Gr�goire <bock@step.polymtl.ca>, Technologies Coeus inc. 
    23    */ 
    24     
     2 
     3 
     4/********************************************************************\ 
     5 * This program is free software; you can redistribute it and/or    * 
     6 * modify it under the terms of the GNU General Public License as   * 
     7 * published by the Free Software Foundation; either version 2 of   * 
     8 * the License, or (at your option) any later version.              * 
     9 *                                                                  * 
     10 * This program is distributed in the hope that it will be useful,  * 
     11 * but WITHOUT ANY WARRANTY; without even the implied warranty of   * 
     12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    * 
     13 * GNU General Public License for more details.                     * 
     14 *                                                                  * 
     15 * You should have received a copy of the GNU General Public License* 
     16 * along with this program; if not, contact:                        * 
     17 *                                                                  * 
     18 * Free Software Foundation           Voice:  +1-617-542-5942       * 
     19 * 59 Temple Place - Suite 330        Fax:    +1-617-542-2652       * 
     20 * Boston, MA  02111-1307,  USA       gnu@gnu.org                   * 
     21 *                                                                  * 
     22 \********************************************************************/ 
     23/**@file AuthenticatorRadius.php 
     24 * @author Copyright (C) 2005 Benoit Gr�goire <bock@step.polymtl.ca>, Technologies Coeus inc. 
     25* @author Copyright (C) 2005 Fran�ois Proulx <francois.proulx@gmail.com>,Technologies Coeus inc. 
     26* */ 
     27 
     28/** 
     29 * Portions of this code are based on PEAR RADIUS Auth class examples provided 
     30 * Copyright (c) 2003, Michael Bretterklieber <michael@bretterklieber.com>  
     31 * All rights reserved. 
     32 */ 
    2533require_once BASEPATH.'classes/Authenticator.php'; 
     34// Including PEAR RADIUS and CHAP MD5 interface classes 
     35require_once 'Auth/RADIUS.php'; 
     36require_once 'Crypt/CHAP.php'; 
    2637 
    2738/** Internal wifidog user database authentication source */ 
    28 class AuthenticatorRadius extends Authenticator { 
    29  
    30   __construct($account_orgin, $other_params_go_here) 
    31     { 
    32       parent->__construct($account_orgin); 
    33     } 
    34  
    35   /** Attempts to login a user against the authentication source.  If successfull, returns a User object 
    36    * @param username:  A valid identifying token for the source.  Not necessarily unique.  For local user, bots username and email are valid. 
    37    * @param password:  Clear text password. 
    38    * @retval The actual User object if sogin was successfull, false otherwise. 
    39    */ 
    40   function login($username, $password, &$errmsg=null) 
    41   { 
    42     global $db; 
    43     $security = new Security(); 
    44     $retval=false; 
    45     $username = $db->EscapeString($username); 
    46     $password = $db->EscapeString($password); 
    47     $password_hash = self::passwordHash($_REQUEST['password']); 
    48  
    49 //VALIDATE AGAINST RADIUS HERE.  If successfull, find user in user table.  If unsuccessfull create it. 
    50  
    51 //When creating user, make sure to update the creatuser function and all references to it to store the account origin. 
    52  
    53     $sql = "SELECT user_id FROM users WHERE (username='$username') AND account_origin='".LOCAL_USER_ACCOUNT_ORIGIN."' AND pass='$password_hash'"; 
    54     $db->ExecSqlUniqueRes($sql,  $user_info, false); 
    55      
    56     if ($user_info != null)  
    57       { 
    58         $user = new User($user_info['user_id']); 
    59         if($user->isUserValid($errmsg)) 
    60           { 
    61             $retval=&$user; 
    62             $security->login($user->getId(), $password_hash); 
    63             $errmsg = _("Login successfull"); 
    64           } 
    65         else 
    66           { 
    67             $retval=false; 
    68             //Reason for refusal is already in $errmsg 
    69           } 
    70       }  
    71     else  
    72       { 
    73         $user_info = null; 
    74         /* This is only used to discriminate if the problem was a non-existent user of a wrong password. */ 
    75         $db->ExecSqlUniqueRes("SELECT * FROM users WHERE (username='$username' OR email='$username') AND account_origin='".LOCAL_USER_ACCOUNT_ORIGIN."'", $user_info, false); 
    76         if ($user_info == null)  
    77           { 
    78             $errmsg = _('Unknown username or email'); 
    79           } 
    80         else 
    81           { 
    82             $errmsg = _('Incorrect password (Maybe you have CAPS LOCK on?)'); 
    83           } 
    84         $retval=false; 
    85       } 
    86     return $retval; 
    87   } 
    88    
    89   /** Logs out the user */ 
    90   function logout() 
    91   { 
    92   } 
    93    
    94   /** Start accounting traffic for the user */ 
    95   function acctStart() 
    96   { 
    97   } 
    98    
    99   /** Update traffic counters */ 
    100   function acctUpdate() 
    101   { 
    102   } 
    103  
    104 /** Final update and stop accounting */ 
    105   function acctStop() 
    106   { 
    107   } 
    108  
    109 }// End class 
     39class AuthenticatorRadius extends Authenticator 
     40{ 
     41        private $mRadius_hostname; 
     42        private $mRadius_auth_port; 
     43        private $mRadius_acct_port; 
     44        private $mRadius_secret_key; 
     45        private $mRadius_encryption_method; 
     46 
     47        /** Returns the hash of the password suitable for storing or comparing in the database.  This hash is the same one as used in NoCat 
     48         * @return The 32 character hash. 
     49         */ 
     50        public static function passwordHash($password) 
     51        { 
     52                return base64_encode(pack("H*", md5($password))); 
     53        } 
     54 
     55        function __construct($account_orgin, $host = "localhost", $auth_port = 1812, $acct_port = 1813, $secret_key = "", $encryption_method = "CHAP_MD5") 
     56        { 
     57                parent :: __construct($account_orgin); 
     58 
     59                // Store RADIUS server parameters 
     60                // Defaults to localhost:0 with MD5 CHAP encryption 
     61                // Setting port to 0 will get default RADIUS Auth service port ( either 1645 or 1812 ) 
     62                $this->mRadius_hostname = $host; 
     63                $this->mRadius_auth_port = $auth_port; 
     64                $this->mRadius_acct_port = $acct_port; 
     65                $this->mRadius_secret_key = $secret_key; 
     66                $this->mRadius_encryption_method = $encryption_method; 
     67        } 
     68 
     69        /** Attempts to login a user against the authentication source.  If successfull, returns a User object 
     70         * @param username:  A valid identifying token for the source.  Not necessarily unique.  For local user, bots username and email are valid. 
     71         * @param password:  Clear text password. 
     72         * @retval The actual User object if sogin was successfull, false otherwise. 
     73         */ 
     74        function login($username, $password, & $errmsg = null) 
     75        { 
     76                global $db; 
     77                $security = new Security(); 
     78                $retval = false; 
     79                $username = $db->EscapeString($username); 
     80                $password = $db->EscapeString($password); 
     81                // Local database password hashing is based on an empty string ( we are not storing remote pwd ) 
     82                $password_hash = self :: passwordHash(""); 
     83 
     84                /* 
     85                 * Supported encryption methods are : 
     86                 *  
     87                 * CHAP_MD5 :Challenge-Handshake Authentication Protocol with MD5 
     88                 * MSCHAPv1 and MSCHAPv2 : Microsoft's CHAP implementation 
     89                 */ 
     90                switch ($this->mRadius_encryption_method) 
     91                { 
     92                        case "CHAP_MD5" : 
     93                        case "MSCHAPv1" : 
     94                        case "MSCHAPv2" : 
     95                                // Instanciate PEAR class 
     96                                $classname = 'Auth_RADIUS_'.$this->mRadius_encryption_method; 
     97                                $radius_server = new $classname ($username, $password); 
     98                                $radius_server->addServer($this->mRadius_hostname, $this->mRadius_auth_port, $this->mRadius_secret_key); 
     99                                break; 
     100                        default : 
     101                                // Invalid encryption method 
     102                                $errmsg = _("Invalid RADIUS encryption method."); 
     103                                return false; 
     104                } 
     105 
     106                // Instructing PEAR RADIUS class auth parameters 
     107                $radius_server->username = $username; 
     108                // Depending on the auth method, generate challenge response 
     109                switch ($this->mRadius_encryption_method) 
     110                { 
     111                        case 'CHAP_MD5' : 
     112                        case 'MSCHAPv1' : 
     113                                $classname = $this->mRadius_encryption_method == 'MSCHAPv1' ? 'Crypt_CHAP_MSv1' : 'Crypt_CHAP_MD5'; 
     114                                $crypt_class = new $classname; 
     115                                $crypt_class->password = $password; 
     116                                $radius_server->challenge = $crypt_class->challenge; 
     117                                $radius_server->chapid = $crypt_class->chapid; 
     118                                $radius_server->response = $crypt_class->challengeResponse(); 
     119                                $radius_server->flags = 1; 
     120                                break; 
     121                        case 'MSCHAPv2' : 
     122                                $crypt_class = new Crypt_CHAP_MSv2; 
     123                                $crypt_class->username = $username; 
     124                                $crypt_class->password = $password; 
     125                                $radius_server->challenge = $crypt_class->authChallenge; 
     126                                $radius_server->peerChallenge = $crypt_class->peerChallenge; 
     127                                $radius_server->chapid = $crypt_class->chapid; 
     128                                $radius_server->response = $crypt_class->challengeResponse(); 
     129                                break; 
     130                        default : 
     131                                $radius_server->password = $password; 
     132                                break; 
     133                } 
     134 
     135                if (!$radius_server->start()) 
     136                { 
     137                        $errmsg = _("Could not initiate PEAR RADIUS Auth class : ".$radius_server->getError()); 
     138                        return false; 
     139                } 
     140 
     141                // Send the authentication request to the RADIUS server 
     142                $result = $radius_server->send(); 
     143 
     144                if (PEAR :: isError($result)) 
     145                { 
     146                        $errmsg = _("Failed to send authentication request to the RADIUS server. : ".$result->getMessage()); 
     147                        return false; 
     148                } 
     149                else 
     150                        if ($result === true) 
     151                        { 
     152                                // RADIUS authentication succeeded ! 
     153                                // Now checking for local copy of this user 
     154                                $sql = "SELECT user_id FROM users WHERE (username='$username') AND account_origin='".$this->mAccountOrigin."' AND pass='$password_hash'"; 
     155                                $db->ExecSqlUniqueRes($sql, $user_info, false); 
     156 
     157                                if ($user_info != null) 
     158                                { 
     159                                        $user = new User($user_info['user_id']); 
     160                                        if ($user->isUserValid($errmsg)) 
     161                                        { 
     162                                                $retval = & $user; 
     163                                                $security->login($user->getId(), $password_hash); 
     164                                                $errmsg = _("Login successfull"); 
     165                                        } 
     166                                        else 
     167                                        { 
     168                                                $retval = false; 
     169                                                //Reason for refusal is already in $errmsg 
     170                                        } 
     171                                } 
     172                                else 
     173                                { 
     174                                        // This user has been succcessfully authenticated through remote RADIUS, but it's not yet in our local database 
     175                                        // Creating the user with a Global Unique ID, empty email and password 
     176                                        $user = User :: createUser(get_guid(), $username, $this->mAccountOrigin, "", ""); 
     177                                        $retval = & $user; 
     178                                        // Validate the user right away ! 
     179                                        $user->setAccountStatus(ACCOUNT_STATUS_ALLOWED); 
     180                                        $security->login($user->getId(), $password_hash); 
     181                                        $errmsg = _("Login successfull"); 
     182                                } 
     183                                return $retval; 
     184                        } 
     185                        else 
     186                        { 
     187                                $errmsg = _("The RADIUS server rejected this username/password combination."); 
     188                                return false; 
     189                        } 
     190 
     191                $radius_server->close(); 
     192        } 
     193 
     194        /** Logs out the user */ 
     195        function logout($info, &$errmsg = null) 
     196        { 
     197                // RADIUS logout actually means to stop accounting 
     198                return $this->acctStop($info); 
     199        } 
     200 
     201        /** Start accounting traffic for the user */ 
     202        function acctStart($info, &$errmsg = null) 
     203        { 
     204                // RADIUS accounting start 
     205                $radius_acct = new Auth_RADIUS_Acct_Start; 
     206                $radius_acct->addServer($this->mRadius_hostname, $this->mRadius_acct_port, $this->mRadius_secret_key); 
     207                // Specify the user for which accounting will be done 
     208                $radius_acct->username = $info['username']; 
     209                // Specify the way the user has been authenticated ( via RADIUS, the class did it ) 
     210                $radius_acct->authentic = RADIUS_AUTH_RADIUS; 
     211 
     212                $status = $radius_acct->start(); 
     213                if (PEAR :: isError($status)) 
     214                        return false; 
     215 
     216                $result = $radius_acct->send(); 
     217                if (PEAR :: isError($result)) 
     218                { 
     219                        $errmsg = "Could not send accounting request to RADIUS server."; 
     220                        return false; 
     221                } 
     222                else 
     223                        if ($result !== true) 
     224                        { 
     225                                $radius_acct->close(); 
     226                                $errmsg = "Accounting request rejected by RADIUS server."; 
     227                                return false; 
     228                        } 
     229 
     230                $radius_acct->close(); 
     231 
     232                // Run generic accounting ( local traffic counters ) only if RADIUS went OK 
     233                parent :: acctStart($info); 
     234                return true; 
     235        } 
     236 
     237        /** Update traffic counters */ 
     238        function acctUpdate($info, $incoming, $outgoing, &$errmsg = null) 
     239        { 
     240                // Call generic traffic updater ( local database ) 
     241                parent :: acctUpdate($info, $incoming, $outgoing); 
     242                 
     243                // RADIUS accounting ping 
     244                // Session is completely based on Database time 
     245                $session_time = strtotime($info['now']) - strtotime($info['timestamp_in']); 
     246 
     247                $radius_acct = new Auth_RADIUS_Acct_Update; 
     248                $radius_acct->addServer($this->mRadius_hostname, $this->mRadius_acct_port, $this->mRadius_secret_key); 
     249                // Specify the user for which accounting will be done 
     250                $radius_acct->username = $info['username']; 
     251                $racct->session_time = $session_time; 
     252 
     253                $status = $radius_acct->start(); 
     254                if (PEAR :: isError($status)) 
     255                        return false; 
     256 
     257                // Send traffic data along with the request 
     258                $radius_acct->putAttribute(RADIUS_ACCT_INPUT_PACKETS, $incoming); 
     259                $radius_acct->putAttribute(RADIUS_ACCT_OUTPUT_PACKETS, $outgoing); 
     260 
     261                $result = $radius_acct->send(); 
     262                if (PEAR :: isError($result)) 
     263                { 
     264                        $errmsg = "Could not send accounting request to RADIUS server."; 
     265                        return false; 
     266                } 
     267                else 
     268                        if ($result !== true) 
     269                        { 
     270                                $radius_acct->close(); 
     271                                $errmsg = "Accounting request rejected by RADIUS server."; 
     272                                return false; 
     273                        } 
     274 
     275                $radius_acct->close(); 
     276                return true; 
     277        } 
     278 
     279        /** Final update and stop accounting */ 
     280        function acctStop($info, &$errmsg = null) 
     281        { 
     282                parent :: acctStop($info); 
     283                 
     284                // RADIUS accounting stop 
     285                // Session is completely based on Database time 
     286                $session_time = strtotime($info['now']) - strtotime($info['timestamp_in']); 
     287 
     288                $radius_acct = new Auth_RADIUS_Acct_Stop; 
     289                $radius_acct->addServer($this->mRadius_hostname, $this->mRadius_acct_port, $this->mRadius_secret_key); 
     290                // Specify the user for which accounting will be done 
     291                $radius_acct->username = $info['username']; 
     292                $racct->session_time = $session_time; 
     293 
     294                $status = $radius_acct->start(); 
     295                if (PEAR :: isError($status)) 
     296                { 
     297                        $errmsg = "Could not initiate PEAR RADIUS class."; 
     298                        return false; 
     299                } 
     300 
     301                // Cause of session termination 
     302                $radius_acct->putAttribute(RADIUS_ACCT_TERMINATE_CAUSE, RADIUS_TERM_SESSION_TIMEOUT); 
     303                $result = $radius_acct->send(); 
     304                 
     305                if (PEAR :: isError($result)) 
     306                { 
     307                        $errmsg = "Could not send accounting request to RADIUS server."; 
     308                        return false; 
     309                } 
     310                else 
     311                        if ($result !== true) 
     312                        { 
     313                                $radius_acct->close(); 
     314                                $errmsg = "Accounting request rejected by RADIUS server."; 
     315                                return false; 
     316                        } 
     317 
     318                $radius_acct->close(); 
     319                return true; 
     320        } 
     321 
     322} // End class 
    110323?> 
     324 
     325 
     326 
     327 
     328 
     329 
     330 
     331 
     332 
  • trunk/wifidog-auth/wifidog/classes/Node.php

    r436 r516  
    239239    global $db; 
    240240 
    241     $db->ExecSql("SELECT users.user_id FROM users,connections WHERE connections.token_status='". TOKEN_INUSE. "' AND users.user_id=connections.user_id AND connections.node_id='{$this->mId}'", $users, false); 
     241    $db->ExecSql("SELECT users.user_id, users.username, users.account_origin FROM users,connections WHERE connections.token_status='". TOKEN_INUSE. "' AND users.user_id=connections.user_id AND connections.node_id='{$this->mId}'", $users, false); 
    242242    return $users; 
    243243  } 
  • trunk/wifidog-auth/wifidog/classes/Security.php

    r512 r516  
    4040    $user_id = $db->EscapeString($user_id); 
    4141    $hash = $db->EscapeString($hash); 
    42     $db->ExecSqlUniqueRes("SELECT * FROM users WHERE user_id='$user_id' AND pass='$hash'", $user_info, true); 
     42    $db->ExecSqlUniqueRes("SELECT * FROM users WHERE user_id='$user_id' AND pass='$hash'", $user_info, false); 
    4343    if (empty($user_info)) { 
    4444        echo '<p class=error>'._("Your user_id and password do not match")."</p>\n"; 
  • trunk/wifidog-auth/wifidog/classes/Statistics.php

    r512 r516  
    9999  public static function getMostMobileUsers($limit) { 
    100100    global $db; 
    101     $db->ExecSql("SELECT COUNT(DISTINCT node_id) AS num_hotspots_visited, user_id, username, account_origin FROM users NATURAL JOIN connections WHERE (incoming!=0 OR outgoing!=0) GROUP BY user_id ORDER BY num_hotspots_visited DESC LIMIT $limit", $results, false); 
     101    $db->ExecSql("SELECT COUNT(DISTINCT node_id) AS num_hotspots_visited, user_id, username, account_origin FROM users NATURAL JOIN connections WHERE (incoming!=0 OR outgoing!=0) GROUP BY account_origin, username,user_id ORDER BY num_hotspots_visited DESC LIMIT $limit", $results, false); 
    102102    return $results; 
    103103  } 
     
    105105  public static function getMostFrequentUsers($limit) { 
    106106    global $db; 
    107     $db->ExecSql("SELECT COUNT(user_id) AS active_days, user_id, username, account_origin FROM (SELECT DISTINCT user_id, date_trunc('day', timestamp_in) AS date, username, account_origin FROM connections WHERE (incoming!=0 OR outgoing!=0) GROUP BY date,user_id) as user_active_days GROUP BY user_id ORDER BY active_days DESC LIMIT $limit",$results, false); 
     107    $db->ExecSql("SELECT COUNT(user_active_days.user_id) AS active_days, user_active_days.user_id, username, account_origin FROM (SELECT DISTINCT user_id, date_trunc('day', timestamp_in) AS date FROM connections WHERE (incoming!=0 OR outgoing!=0) GROUP BY date,user_id) user_active_days JOIN users ON (users.user_id = user_active_days.user_id) GROUP BY account_origin, username, user_active_days.user_id ORDER BY active_days DESC LIMIT $limit",$results, false); 
    108108    return $results; 
    109109  } 
     
    111111  public static function getMostGreedyUsers($limit) { 
    112112    global $db; 
    113     $db->ExecSql("SELECT DISTINCT user_id, SUM((incoming+outgoing)/1048576) AS total, SUM((incoming/1048576)) AS total_incoming, SUM((outgoing/1048576)) AS total_outgoing, username, account_origin FROM connections WHERE incoming IS NOT NULL AND outgoing IS NOT NULL GROUP BY user_id ORDER BY total DESC limit $limit", $results, false); 
     113    $db->ExecSql("SELECT DISTINCT connections.user_id, SUM((incoming+outgoing)/1048576) AS total, SUM((incoming/1048576)) AS total_incoming, SUM((outgoing/1048576)) AS total_outgoing, username, account_origin FROM connections JOIN users ON (users.user_id = connections.user_id) WHERE incoming IS NOT NULL AND outgoing IS NOT NULL GROUP BY account_origin, username,connections.user_id ORDER BY total DESC limit $limit", $results, false); 
    114114    return $results; 
    115115  } 
  • trunk/wifidog-auth/wifidog/classes/User.php

    r512 r516  
    11<?php 
    2   /********************************************************************\ 
    3    * This program is free software; you can redistribute it and/or    * 
    4    * modify it under the terms of the GNU General Public License as   * 
    5    * published by the Free Software Foundation; either version 2 of   * 
    6    * the License, or (at your option) any later version.              * 
    7    *                                                                  * 
    8    * This program is distributed in the hope that it will be useful,  * 
    9    * but WITHOUT ANY WARRANTY; without even the implied warranty of   * 
    10    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    * 
    11    * GNU General Public License for more details.                     * 
    12    *                                                                  * 
    13    * You should have received a copy of the GNU General Public License* 
    14    * along with this program; if not, contact:                        * 
    15    *                                                                  * 
    16    * Free Software Foundation           Voice:  +1-617-542-5942       * 
    17    * 59 Temple Place - Suite 330        Fax:    +1-617-542-2652       * 
    18    * Boston, MA  02111-1307,  USA       gnu@gnu.org                   * 
    19    *                                                                  * 
    20    \********************************************************************/ 
    21   /**@file User.php 
    22    * @author Copyright (C) 2005 Benoit Gr�goire <bock@step.polymtl.ca> 
    23    */ 
    24     
     2 
     3/********************************************************************\ 
     4 * This program is free software; you can redistribute it and/or    * 
     5 * modify it under the terms of the GNU General Public License as   * 
     6 * published by the Free Software Foundation; either version 2 of   * 
     7 * the License, or (at your option) any later version.              * 
     8 *                                                                  * 
     9 * This program is distributed in the hope that it will be useful,  * 
     10 * but WITHOUT ANY WARRANTY; without even the implied warranty of   * 
     11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    * 
     12 * GNU General Public License for more details.                     * 
     13 *                                                                  * 
     14 * You should have received a copy of the GNU General Public License* 
     15 * along with this program; if not, contact:                        * 
     16 *                                                                  * 
     17 * Free Software Foundation           Voice:  +1-617-542-5942       * 
     18 * 59 Temple Place - Suite 330        Fax:    +1-617-542-2652       * 
     19 * Boston, MA  02111-1307,  USA       gnu@gnu.org                   * 
     20 *                                                                  * 
     21 \********************************************************************/ 
     22/**@file User.php 
     23 * @author Copyright (C) 2005 Benoit Gr�goire <bock@step.polymtl.ca> 
     24 */ 
     25 
    2526require_once BASEPATH.'include/common.php'; 
    2627 
    2728/** Abstract a User. */ 
    2829class User { 
    29   private $mRow; 
    30   private $mId; 
    31    
    32   /** Instantiate a user object  
    33    * @param $id The id of the requested user  
    34    * @return a User object, or null if there was an error 
    35    */ 
    36   static function getUserByID($id) { 
    37       $object = null; 
    38       $object = new self("user_id", $id); 
    39       return $object; 
    40     } 
    41  
    42   /** Create a new User in the database  
    43    * @param $id The id to be given to the new user 
    44    * @return the newly created User object, or null if there was an error 
    45    */ 
    46   static function createUser($id, $username, $account_origin, $email, $password) { 
    47       global $db; 
    48  
    49       $object = null; 
    50       $id_str = $db->EscapeString($id); 
    51       $username_str = $db->EscapeString($username); 
    52       $account_origin_str= $db->EscapeString($account); 
    53       $email_str = $db->EscapeString($email); 
    54       $password_hash = $db->EscapeString(User::passwordHash($password)); 
    55       $status = ACCOUNT_STATUS_VALIDATION; 
    56       $token = User::generateToken(); 
    57        
    58       $db->ExecSqlUpdate("INSERT INTO users (user_id,username, account_origin,email,pass,account_status,validation_token,reg_date) VALUES ('$id_str','$username_str','$account_origin_str','$email_str','$password_hash','$status','$token',NOW())"); 
    59        
    60       $object = new self('user_id', $id_str); 
    61       return $object; 
    62   } 
    63    
    64   /** @param $object_id The id of the user */ 
    65   function __construct($object_id) { 
    66     global $db; 
    67     $object_id_str = $db->EscapeString($object_id); 
    68     $sql = "SELECT * FROM users WHERE user_id='{$object_id_str}'"; 
    69     $db->ExecSqlUniqueRes($sql, $row, false); 
    70     if ($row == null) { 
    71       throw new Exception(_("user_id '{$object_id_str}' could not be found in the database")); 
    72     } 
    73     $this->mRow = $row;   
    74     $this->mId  = $row['user_id']; 
    75   }//End class 
    76    
    77   function getId() { 
    78     return $this->mId; 
    79   } 
    80    
    81   function getUsername() { 
    82     return $this->mRow['username']; 
    83   } 
    84    
    85   private function getEmail() { 
    86     return $this->mRow['email']; 
    87   } 
    88    
    89   private function getPasswordHash() { 
    90     return $this->mRow['pass']; 
    91   } 
    92    
    93 /** Get the account status.   
    94  * @return Possible values are listed in common.php 
    95 */ 
    96   function getAccountStatus() { 
    97     return $this->mRow['account_status']; 
    98   } 
    99  
    100   function setAccountStatus($status) { 
    101     global $db; 
    102      
    103     $status_str = $db->EscapeString($status); 
    104     if (!($update = $db->ExecSqlUpdate("UPDATE users SET account_status='{$status_str}' WHERE user_id='{$this->mId}'"))) { 
    105       throw new Exception(_("Could not update status.")); 
    106     } 
    107     $this->mRow['account_status'] = $status; 
    108   } 
    109   
    110 /** Is the user valid?  Valid means that the account is validated or hasn't exhausted it's validation period.  
    111  $errmsg: Returs the reason why the account is or isn't valid */ 
    112   function isUserValid(&$errmsg=null) 
    113   { 
    114     $retval = false; 
    115     $account_status=$this->getAccountStatus(); 
    116     if($account_status==ACCOUNT_STATUS_ALLOWED) 
    117       { 
    118         $retval=true; 
    119       } 
    120     else if($account_status==ACCOUNT_STATUS_VALIDATION) 
    121       { 
    122         $sql = "SELECT CASE WHEN ((NOW() - reg_date) > interval '".VALIDATION_GRACE_TIME." minutes') THEN true ELSE false END AS validation_grace_time_expired FROM users WHERE (user_id='{$this->mId}'"; 
    123         $db->ExecSqlUniqueRes($sql,  $user_info, false); 
     30        private $mRow; 
     31        private $mId; 
     32 
     33        /** Instantiate a user object  
     34         * @param $id The id of the requested user  
     35         * @return a User object, or null if there was an error 
     36         */ 
     37        static function getUserByID($id) { 
     38                $object = null; 
     39                $object = new self($id); 
     40                return $object; 
     41        } 
    12442         
    125         if ($user_info['validation_grace_time_expired']=='t') 
    126           { 
    127             $errmsg = _("Sorry, your ").$validation_grace_time._(" minutes grace period to retrieve your email and validate your account has now expired. You will have to connect to the internet and validate your account from another location or create a new account. For help, please ") . '<a href="'.BASEPATH.'faq.php'.'">'. _("click here.") .'</a>'; 
    128             $retval=false; 
    129           } 
    130         else 
    131           { 
    132             $errmsg = _("Your account is currently valid."); 
    133             $retval=true; 
    134           } 
    135       }  
    136     else 
    137       { 
    138         $errmsg = _("Sorry, your account is not valid: ").$account_status_to_text[$account_status]; 
    139         $retval=false; 
    140       } 
    141     return $retval; 
    142   } 
    143    
    144   function getValidationToken() { 
    145     return $this->mRow['validation_token']; 
    146   } 
    147    
    148   function getInfoArray() { 
    149     return $this->mRow; 
    150   } 
    151    
    152 /** Generate a token in the connection table so the user can actually use the internet  
    153 @return true on success, false on failure  
    154 */ 
    155   function generateConnectionToken() 
    156  { 
    157    if($this->isUserValid()) 
    158      { 
    159        global $db; 
    160        $token=self::generateToken(); 
    161        if ($_SERVER['REMOTE_ADDR']) 
    162          { 
    163            $node_ip = $db->EscapeString($_SERVER['REMOTE_ADDR']); 
    164          } 
    165        if (isset($_REQUEST['gw_id']) && $_REQUEST['gw_id']) 
    166          { 
    167            $node_id = $db->EscapeString($_REQUEST['gw_id']); 
    168            $db->ExecSqlUpdate("INSERT INTO connections (user_id, token, token_status, timestamp_in, node_id, node_ip, last_updated) VALUES ('".$this->getId()."', '$token', '" . TOKEN_UNUSED . "', NOW(), '$node_id', '$node_ip', NOW())",true); 
    169          } 
    170        $retval=true; 
    171      } 
    172    else 
    173      { 
    174        $retval=false; 
    175      } 
    176    return $retval; 
    177  } 
    178    
    179   function setPassword($password) { 
    180     global $db; 
    181      
    182     $new_password_hash = $this->passwordHash($password); 
    183     if (!($update = $db->ExecSqlUpdate("UPDATE users SET pass='$new_password_hash' WHERE user_id='{$this->mId}'"))) { 
    184       throw new Exception(_("Could not change user's password.")); 
    185     } 
    186     $this->mRow['pass'] = $password; 
    187   } 
    188    
    189   function getConnections() { 
    190     global $db; 
    191     $db->ExecSql("SELECT * FROM connections,nodes WHERE user_id='{$this->mId}' AND nodes.node_id=connections.node_id ORDER BY timestamp_in", $connections, false); 
    192     return $connections; 
    193   } 
    194    
    195  
    196   /** Return all the users 
    197    */ 
    198   static function getAllUsers() { 
    199     global $db; 
    200  
    201     $db->ExecSql("SELECT * FROM users", $objects, false); 
    202     if ($objects == null) { 
    203         throw new Exception(_("No users could not be found in the database")); 
    204     } 
    205     return $objects; 
    206   } 
    207  
    208   function sendLostUsername() { 
    209     $username = $this->getUsername(); 
    210     $subject = LOST_USERNAME_EMAIL_SUBJECT; 
    211     $from = "From: " . VALIDATION_EMAIL_FROM_ADDRESS; 
    212     $body = "Hello, 
    213  
    214 You have requested that the authentication server send you your username: 
    215  
    216 Username: $username 
    217  
    218 Have a nice day, 
    219  
    220 The Team"; 
    221  
    222     mail($this->getEmail(), $subject, $body, $from); 
    223   } 
    224  
    225  
    226   function sendValidationEmail() { 
    227     if ($this->getAccountStatus() != ACCOUNT_STATUS_VALIDATION) { 
    228         throw new Exception(_("The user is not in validation period.")); 
    229         } else { 
    230         if ($this->getValidationToken() == "") { 
    231             throw new Exception(_("The validation token is empty.")); 
    232         } else { 
    233             $subject = VALIDATION_EMAIL_SUBJECT; 
    234             $url = "http://" . $_SERVER["SERVER_NAME"] . "/validate.php?username=" . $this->getName() . "&token=" . $this->getValidationToken(); 
    235             $body = "Hello! 
    236  
    237 Please follow the link below to validate your account. 
    238  
    239 $url 
    240  
    241 Thank you, 
    242  
    243 The Team"; 
    244             $from = "From: " . VALIDATION_EMAIL_FROM_ADDRESS; 
    245  
    246             mail($this->getEmail(), $subject, $body, $from); 
    247         } 
    248     } 
    249   } 
    250  
    251  
    252  
    253   function sendLostPasswordEmail() { 
    254     global $db; 
    255  
    256     $new_password = $this->randomPass(); 
    257     $this->setPassword($new_password); 
    258  
    259     $username = $this->getUsername(); 
    260  
    261     $subject = LOST_PASSWORD_EMAIL_SUBJECT; 
    262     $body = "Hello, 
    263  
    264 You have requested that the authentication server send you a new password: 
    265  
    266 Username: $username 
    267 Password: $new_password 
    268  
    269 Have a nice day, 
    270  
    271 The Team"; 
    272     $from = "From: ".VALIDATION_EMAIL_FROM_ADDRESS; 
    273  
    274     mail($this->getEmail(), $subject, $body, $from); 
    275   } 
    276  
    277   static function userExists($id) { 
    278     global $db; 
    279     $id_str = $db->EscapeString($id); 
    280     $sql = "SELECT * FROM users WHERE user_id='{$id_str}'"; 
    281     $db->ExecSqlUniqueRes($sql, $row, false); 
    282     return $row; 
    283   } 
    284  
    285   function emailExists($id) { 
    286     global $db; 
    287     $id_str = $db->EscapeString($id); 
    288     $sql = "SELECT * FROM users WHERE email='{$id_str}'"; 
    289     $db->ExecSqlUniqueRes($sql, $row, false); 
    290     return $row; 
    291   } 
    292  
    293   public static function randomPass() { 
    294    $rand_pass = ''; // makes sure the $pass var is empty. 
    295    for ($j = 0; $j < 3; $j++) { 
    296        $startnend = array( 
    297            'b','c','d','f','g','h','j','k','l','m','n', 
    298            'p','q','r','s','t','v','w','x','y','z', 
    299        ); 
    300        $mid = array( 
    301            'a','e','i','o','u','y', 
    302        ); 
    303        $count1 = count($startnend) - 1; 
    304        $count2 = count($mid) - 1; 
    305  
    306        for ($i = 0; $i < 3; $i++) { 
    307            if ($i != 1) { 
    308                $rand_pass .= $startnend[rand(0, $count1)]; 
    309            } else { 
    310                $rand_pass .= $mid[rand(0, $count2)]; 
    311            } 
    312        } 
    313    } 
    314    return $rand_pass; 
    315   } 
    316  
    317     public static function generateToken() { 
    318         return md5(uniqid(rand(),1)); 
    319     } 
    320  
    321 }// End class 
     43        /** Instantiate a user object  
     44         * @param $username The username of the user 
     45         * @param $account_origin The account origin 
     46         * @return a User object, or null if there was an error 
     47         */ 
     48        static function getUserByUsernameAndOrigin($username, $account_origin) { 
     49                global $db; 
     50                $object = null; 
     51                 
     52                $username_str = $db->EscapeString($username); 
     53                $account_origin_str = $db->EscapeString($account_origin); 
     54                $db->ExecSqlUniqueRes("SELECT user_id FROM users WHERE username = '$username_str' AND account_origin = '$account_origin_str'", $user_info, false); 
     55                 
     56                $object = new self($user_info['user_id']); 
     57                return $object; 
     58        } 
     59 
     60        /** Returns the hash of the password suitable for storing or comparing in the database.  This hash is the same one as used in NoCat 
     61         * @return The 32 character hash. 
     62         */ 
     63        public static function passwordHash($password) { 
     64                return base64_encode(pack("H*", md5($password))); 
     65        } 
     66 
     67        /** Create a new User in the database  
     68         * @param $id The id to be given to the new user 
     69         * @return the newly created User object, or null if there was an error 
     70         */ 
     71        static function createUser($id, $username, $account_origin, $email, $password) { 
     72                global $db; 
     73 
     74                $object = null; 
     75                $id_str = $db->EscapeString($id); 
     76                $username_str = $db->EscapeString($username); 
     77                $account_origin_str = $db->EscapeString($account_origin); 
     78                $email_str = $db->EscapeString($email); 
     79                $password_hash = $db->EscapeString(User :: passwordHash($password)); 
     80                $status = ACCOUNT_STATUS_VALIDATION; 
     81                $token = User :: generateToken(); 
     82 
     83                $db->ExecSqlUpdate("INSERT INTO users (user_id,username, account_origin,email,pass,account_status,validation_token,reg_date) VALUES ('$id_str','$username_str','$account_origin_str','$email_str','$password_hash','$status','$token',NOW())"); 
     84 
     85                $object = new self($id); 
     86                return $object; 
     87        } 
     88 
     89        /** @param $object_id The id of the user */ 
     90        function __construct($object_id) { 
     91                global $db; 
     92                $object_id_str = $db->EscapeString($object_id); 
     93                $sql = "SELECT * FROM users WHERE user_id='{$object_id_str}'"; 
     94                $db->ExecSqlUniqueRes($sql, $row, false); 
     95                if ($row == null) { 
     96                        throw new Exception(_("user_id '{$object_id_str}' could not be found in the database")); 
     97                } 
     98                $this->mRow = $row; 
     99                $this->mId = $row['user_id']; 
     100        } //End class 
     101 
     102        function getId() { 
     103                return $this->mId; 
     104        } 
     105 
     106        function getUsername() { 
     107                return $this->mRow['username']; 
     108        } 
     109 
     110        private function getEmail() { 
     111                return $this->mRow['email']; 
     112        } 
     113 
     114        private function getPasswordHash() { 
     115                return $this->mRow['pass']; 
     116        } 
     117 
     118        /** Get the account status.   
     119         * @return Possible values are listed in common.php 
     120        */ 
     121        function getAccountStatus() { 
     122                return $this->mRow['account_status']; 
     123        } 
     124 
     125        function setAccountStatus($status) { 
     126                global $db; 
     127 
     128                $status_str = $db->EscapeString($status); 
     129                if (!($update = $db->ExecSqlUpdate("UPDATE users SET account_status='{$status_str}' WHERE user_id='{$this->mId}'"))) { 
     130                        throw new Exception(_("Could not update status.")); 
     131                } 
     132                $this->mRow['account_status'] = $status; 
     133        } 
     134 
     135        /** Is the user valid?  Valid means that the account is validated or hasn't exhausted it's validation period.  
     136         $errmsg: Returs the reason why the account is or isn't valid */ 
     137        function isUserValid(& $errmsg = null) { 
     138                $retval = false; 
     139                $account_status = $this->getAccountStatus(); 
     140                if ($account_status == ACCOUNT_STATUS_ALLOWED) { 
     141                        $retval = true; 
     142                } else 
     143                        if ($account_status == ACCOUNT_STATUS_VALIDATION) { 
     144                                $sql = "SELECT CASE WHEN ((NOW() - reg_date) > interval '".VALIDATION_GRACE_TIME." minutes') THEN true ELSE false END AS validation_grace_time_expired FROM users WHERE (user_id='{$this->mId}'"; 
     145                                $db->ExecSqlUniqueRes($sql, $user_info, false); 
     146 
     147                                if ($user_info['validation_grace_time_expired'] == 't') { 
     148                                        $errmsg = _("Sorry, your ").$validation_grace_time._(" minutes grace period to retrieve your email and validate your account has now expired. You will have to connect to the internet and validate your account from another location or create a new account. For help, please ").'<a href="'.BASEPATH.'faq.php'.'">'._("click here.").'</a>'; 
     149                                        $retval = false; 
     150                                } else { 
     151                                        $errmsg = _("Your account is currently valid."); 
     152                                        $retval = true; 
     153                                } 
     154                        } else { 
     155                                $errmsg = _("Sorry, your account is not valid: ").$account_status_to_text[$account_status]; 
     156                                $retval = false; 
     157                        } 
     158                return $retval; 
     159        } 
     160 
     161        function getValidationToken() { 
     162                return $this->mRow['validation_token']; 
     163        } 
     164 
     165        function getInfoArray() { 
     166                return $this->mRow; 
     167        } 
     168 
     169        /** Generate a token in the connection table so the user can actually use the internet  
     170        @return true on success, false on failure  
     171        */ 
     172        function generateConnectionToken() { 
     173                if ($this->isUserValid()) { 
     174                        global $db; 
     175                        $token = self :: generateToken(); 
     176                        if ($_SERVER['REMOTE_ADDR']) { 
     177                                $node_ip = $db->EscapeString($_SERVER['REMOTE_ADDR']); 
     178                        } 
     179                        if (isset ($_REQUEST['gw_id']) && $_REQUEST['gw_id']) { 
     180                                $node_id = $db->EscapeString($_REQUEST['gw_id']); 
     181                                $db->ExecSqlUpdate("INSERT INTO connections (user_id, token, token_status, timestamp_in, node_id, node_ip, last_updated) VALUES ('".$this->getId()."', '$token', '".TOKEN_UNUSED."', NOW(), '$node_id', '$node_ip', NOW())", false); 
     182                                $retval = $token; 
     183                        } 
     184                        else 
     185                                $retval = false; 
     186                } else { 
     187                        $retval = false; 
     188                } 
     189                return $retval; 
     190        } 
     191 
     192        function setPassword($password) { 
     193                global $db; 
     194 
     195                $new_password_hash = $this->passwordHash($password); 
     196                if (!($update = $db->ExecSqlUpdate("UPDATE users SET pass='$new_password_hash' WHERE user_id='{$this->mId}'"))) { 
     197                        throw new Exception(_("Could not change user's password.")); 
     198                } 
     199                $this->mRow['pass'] = $password; 
     200        } 
     201 
     202        function getConnections() { 
     203                global $db; 
     204                $db->ExecSql("SELECT * FROM connections,nodes WHERE user_id='{$this->mId}' AND nodes.node_id=connections.node_id ORDER BY timestamp_in", $connections, false); 
     205                return $connections; 
     206        } 
     207 
     208        /** Return all the users 
     209         */ 
     210        static function getAllUsers() { 
     211                global $db; 
     212 
     213                $db->ExecSql("SELECT * FROM users", $objects, false); 
     214                if ($objects == null) { 
     215                        throw new Exception(_("No users could not be found in the database")); 
     216                } 
     217                return $objects; 
     218        } 
     219 
     220        function sendLostUsername() { 
     221                $username = $this->getUsername(); 
     222                $subject = LOST_USERNAME_EMAIL_SUBJECT; 
     223                $from = "From: ".VALIDATION_EMAIL_FROM_ADDRESS; 
     224                $body = "Hello, 
     225                 
     226                You have requested that the authentication server send you your username: 
     227                 
     228                Username: $username 
     229                 
     230                Have a nice day, 
     231                 
     232                The Team"; 
     233 
     234                mail($this->getEmail(), $subject, $body, $from); 
     235        } 
     236 
     237        function sendValidationEmail() { 
     238                if ($this->getAccountStatus() != ACCOUNT_STATUS_VALIDATION) { 
     239                        throw new Exception(_("The user is not in validation period.")); 
     240                } else { 
     241                        if ($this->getValidationToken() == "") { 
     242                                throw new Exception(_("The validation token is empty.")); 
     243                        } else { 
     244                                $subject = VALIDATION_EMAIL_SUBJECT; 
     245                                $url = "http://".$_SERVER["SERVER_NAME"]."/validate.php?username=".$this->getUsername()."&token=".$this->getValidationToken(); 
     246                                $body = "Hello! 
     247                                 
     248                                Please follow the link below to validate your account. 
     249                                 
     250                                $url 
     251                                 
     252                                Thank you, 
     253                                 
     254                                The Team"; 
     255                                $from = "From: ".VALIDATION_EMAIL_FROM_ADDRESS; 
     256 
     257                                mail($this->getEmail(), $subject, $body, $from); 
     258                        } 
     259                } 
     260        } 
     261 
     262        function sendLostPasswordEmail() { 
     263                global $db; 
     264 
     265                $new_password = $this->randomPass(); 
     266                $this->setPassword($new_password); 
     267 
     268                $username = $this->getUsername(); 
     269 
     270                $subject = LOST_PASSWORD_EMAIL_SUBJECT; 
     271                $body = "Hello, 
     272                 
     273                You have requested that the authentication server send you a new password: 
     274                 
     275                Username: $username 
     276                Password: $new_password 
     277                 
     278                Have a nice day, 
     279                 
     280                The Team"; 
     281                $from = "From: ".VALIDATION_EMAIL_FROM_ADDRESS; 
     282 
     283                mail($this->getEmail(), $subject, $body, $from); 
     284        } 
     285 
     286        static function userExists($id) { 
     287                global $db; 
     288                $id_str = $db->EscapeString($id); 
     289                $sql = "SELECT * FROM users WHERE user_id='{$id_str}'"; 
     290                $db->ExecSqlUniqueRes($sql, $row, false); 
     291                return $row; 
     292        } 
     293 
     294        function emailExists($id) { 
     295                global $db; 
     296                $id_str = $db->EscapeString($id); 
     297                $sql = "SELECT * FROM users WHERE email='{$id_str}'"; 
     298                $db->ExecSqlUniqueRes($sql, $row, false); 
     299                return $row; 
     300        } 
     301 
     302        public static function randomPass() { 
     303                $rand_pass = ''; // makes sure the $pass var is empty. 
     304                for ($j = 0; $j < 3; $j ++) { 
     305                        $startnend = array ('b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z',); 
     306                        $mid = array ('a', 'e', 'i', 'o', 'u', 'y',); 
     307                        $count1 = count($startnend) - 1; 
     308                        $count2 = count($mid) - 1; 
     309 
     310                        for ($i = 0; $i < 3; $i ++) { 
     311                                if ($i != 1) { 
     312                                        $rand_pass .= $startnend[rand(0, $count1)]; 
     313                                } else { 
     314                                        $rand_pass .= $mid[rand(0, $count2)]; 
     315                                } 
     316                        } 
     317                } 
     318                return $rand_pass; 
     319        } 
     320 
     321        public static function generateToken() { 
     322                return md5(uniqid(rand(), 1)); 
     323        } 
     324 
     325} // End class 
    322326?> 
     327 
  • trunk/wifidog-auth/wifidog/config.php

    r512 r516  
    77 * 
    88 *     $Log$ 
     9 *     Revision 1.23  2005/03/29 22:13:27  fproulx 
     10 *     2005-03-28 Fran�ois Proulx  <francois.proulx@gmail.com> 
     11 *      * schema_validate.php : Modified schema : dropped e-mail + account unique index, dropped email not empty constraint 
     12 *      * Schema is now at version 3 
     13 *      * Coded RADIUS authentication 
     14 *      * Modified templates to show a select box when more than one server is configured 
     15 *      * Coded RADIUS accounting and backward compatibility accounting 
     16 *      * Modified many statistics SQL queries to match new Users table 
     17 *      * modified statistics templates to match user_id and account_origin 
     18 *      * TODO : Fix lost_username and lost_password ( issue since we dropped the unique constraint on emails... ) 
     19 *      * TODO : Heavy testing possibly with remote RADIUS servers 
     20 * 
    921 *     Revision 1.22  2005/03/28 19:49:52  benoitg 
    1022 *     2005-03-28 Benoit Gr�goire  <bock@step.polymtl.ca> 
     
    132144 define('LOCAL_USER_ACCOUNT_ORIGIN', 'LOCAL_USER'); 
    133145require_once BASEPATH.'classes/AuthenticatorLocalUser.php'; 
     146define('IDRC_ACCOUNT_ORIGIN', 'IDRC_RADIUS_USER'); 
     147require_once BASEPATH.'classes/AuthenticatorRadius.php'; 
    134148 
    135149/* The array index for the source must match the account_origin in the user table */ 
     
    137151                                                     'name'=>HOTSPOT_NETWORK_NAME, 
    138152                                                     'authenticator'=>new AuthenticatorLocalUser(LOCAL_USER_ACCOUNT_ORIGIN)); 
    139  
     153$AUTH_SOURCE_ARRAY[IDRC_ACCOUNT_ORIGIN]=array( 
     154                                                     'name'=>"IDRC RADIUS", 
     155                                                     'authenticator'=>new AuthenticatorRadius(IDRC_ACCOUNT_ORIGIN, "localhost", 1812, 1813, "secret_key")); 
    140156 
    141157 
  • trunk/wifidog-auth/wifidog/hotspot_status.php

    r510 r516  
    11<?php 
    2   /********************************************************************\ 
    3    * This program is free software; you can redistribute it and/or    * 
    4    * modify it under the terms of the GNU General Public License as   * 
    5    * published by the Free Software Foundation; either version 2 of   * 
    6    * the License, or (at your option) any later version.              * 
    7    *                                                                  * 
    8    * This program is distributed in the hope that it will be useful,  * 
    9    * but WITHOUT ANY WARRANTY; without even the implied warranty of   * 
    10    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    * 
    11    * GNU General Public License for more details.                     * 
    12    *                                                                  * 
    13    * You should have received a copy of the GNU General Public License* 
    14    * along with this program; if not, contact:                        * 
    15    *                                                                  * 
    16    * Free Software Foundation           Voice:  +1-617-542-5942       * 
    17    * 59 Temple Place - Suite 330        Fax:    +1-617-542-2652       * 
    18    * Boston, MA  02111-1307,  USA       gnu@gnu.org                   * 
    19    *                                                                  * 
    20    \********************************************************************/ 
    21   /**@file hotspot_status.php 
    22    * Network status page 
    23    * @author Copyright (C) 2004 Benoit Gr�goire 
    24    */ 
    25  
    26 define('BASEPATH','./'); 
     2 
     3/********************************************************************\ 
     4 * This program is free software; you can redistribute it and/or    * 
     5 * modify it under the terms of the GNU General Public License as   * 
     6 * published by the Free Software Foundation; either version 2 of   * 
     7 * the License, or (at your option) any later version.              * 
     8 *                                                                  * 
     9 * This program is distributed in the hope that it will be useful,  * 
     10 * but WITHOUT ANY WARRANTY; without even the implied warranty of   * 
     11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    * 
     12 * GNU General Public License for more details.                     * 
     13 *                                                                  * 
     14 * You should have received a copy of the GNU General Public License* 
     15 * along with this program; if not, contact:                        * 
     16 *                                                                  * 
     17 * Free Software Foundation           Voice:  +1-617-542-5942       * 
     18 * 59 Temple Place - Suite 330        Fax:    +1-617-542-2652       * 
     19 * Boston, MA  02111-1307,  USA       gnu@gnu.org                   * 
     20 *                                                                  * 
     21 \********************************************************************/ 
     22/**@file hotspot_status.php 
     23 * Network status page 
     24 * @author Copyright (C) 2004 Benoit Gr�goire 
     25 */ 
     26 
     27define('BASEPATH', './'); 
    2728require_once BASEPATH.'include/common.php'; 
    2829require_once BASEPATH.'include/common_interface.php'; 
    2930 
    30 if(!empty($_REQUEST['format'])) { 
    31   $format = $_REQUEST['format']; 
    32  } else { 
    33   $format = null; 
    34  } 
     31if (!empty ($_REQUEST['format'])) { 
     32        $format = $_REQUEST['format']; 
     33} else { 
     34        $format = null; 
     35} 
    3536 
    3637$db->ExecSql("SELECT *, (NOW()-last_heartbeat_timestamp) AS since_last_heartbeat, EXTRACT(epoch FROM creation_date) as creation_date_epoch, CASE WHEN ((NOW()-last_heartbeat_timestamp) < interval '5 minutes') THEN true ELSE false END AS is_up FROM nodes WHERE node_deployment_status = 'DEPLOYED' OR node_deployment_status = 'NON_WIFIDOG_NODE' ORDER BY creation_date", $node_results, false); 
    3738if ($format == 'RSS') { 
    38   Header("Cache-control: private, no-cache, must-revalidate"); 
    39   Header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); # Past date 
    40   Header("Pragma: no-cache"); 
    41   Header("Content-Type: text/xml; charset=UTF-8"); 
    42  
    43   $xmldoc = new DOMDocument(); 
    44   $xmldoc->formatOutput = true; 
    45   //$xmldoc->encoding="iso-8859-15"; 
    46   $rss = $xmldoc->createElement("rss"); 
    47   $xmldoc->appendChild($rss); 
    48   $rss->setAttribute('version', '2.0'); 
    49  
    50   /* channel */ 
    51   $channel = $xmldoc->createElement("channel"); 
    52   $rss->appendChild($channel); 
    53  
    54   /**************** Required channel elements ********************/ 
    55   /* title */ 
    56   $title = $xmldoc->createElement("title"); 
    57   $title = $channel->appendChild($title); 
    58  
    59   $textnode = $xmldoc->createTextNode(utf8_encode(HOTSPOT_NETWORK_NAME._(": Newest HotSpots"))); 
    60   $title->appendChild($textnode); 
    61  
    62   /* link */ 
    63   $link = $xmldoc->createElement("link"); 
    64   $channel->appendChild($link); 
    65   $textnode = $xmldoc->createTextNode(utf8_encode(HOTSPOT_NETWORK_URL)); 
    66   $link->appendChild($textnode); 
    67  
    68   /* description */ 
    69   $description = $xmldoc->createElement("description"); 
    70   $channel->appendChild($description); 
    71   $textnode = $xmldoc->createTextNode(utf8_encode(_("WiFiDog list of the most recent HotSpots opened by the network: ").HOTSPOT_NETWORK_NAME)); 
    72   $description->appendChild($textnode); 
    73  
    74   /****************** Optional channel elements *******************/ 
    75   /* language */ 
    76   /**@todo Make language selectable */ 
    77   $language = $xmldoc->createElement("language"); 
    78   $channel->appendChild($language); 
    79   $textnode = $xmldoc->createTextNode("en-CA"); 
    80   $language->appendChild($textnode); 
    81  
    82   /* copyright */ 
    83   $copyright = $xmldoc->createElement("copyright"); 
    84   $channel->appendChild($copyright); 
    85   $textnode = $xmldoc->createTextNode(utf8_encode(_("Copyright ").HOTSPOT_NETWORK_NAME)); 
    86   $copyright->appendChild($textnode); 
    87  
    88   /* managingEditor */ 
    89                  
    90   /* webMaster */ 
    91                  
    92   $webMaster = $xmldoc->createElement("webMaster"); 
    93   $channel->appendChild($webMaster); 
    94   $textnode = $xmldoc->createTextNode(utf8_encode(TECH_SUPPORT_EMAIL)); 
    95   $webMaster->appendChild($textnode); 
    96  
    97   /* pubDate */ 
    98   $pubDate = $xmldoc->createElement("pubDate"); 
    99   $channel->appendChild($pubDate); 
    100   $textnode = $xmldoc->createTextNode(utf8_encode(gmdate("D, d M Y H:i:s \G\M\T", time()))); 
    101   $pubDate->appendChild($textnode); 
    102  
    103   /* lastBuildDate */ 
    104   //<lastBuildDate> -- The date-time the last time the content of the channel changed. 
    105   /* Make a request through the database for the latest modification date of an object.   
    106    * Maybe it should be an object property? */ 
    107   $db->ExecSqlUniqueRes("SELECT EXTRACT(epoch FROM MAX(creation_date)) as date_last_hotspot_opened FROM nodes WHERE node_deployment_status = 'DEPLOYED' OR node_deployment_status = 'NON_WIFIDOG_NODE' ", $last_hotspot_row, false); 
    108  
    109   $lastBuildDate = $xmldoc->createElement("lastBuildDate"); 
    110   $channel->appendChild($lastBuildDate); 
    111   $textnode = $xmldoc->createTextNode(gmdate("D, d M Y H:i:s \G\M\T", $last_hotspot_row['date_last_hotspot_opened'])); 
    112   $lastBuildDate->appendChild($textnode); 
    113                  
    114   /* category */ 
    115   /* Specify one or more categories that the channel belongs to. 
    116    *  Follows the same rules as the <item>-level category element.*/ 
    117                   
    118   /* generator */ 
    119   $generator = $xmldoc->createElement("generator"); 
    120   $channel->appendChild($generator); 
    121   $textnode = $xmldoc->createTextNode(utf8_encode(WIFIDOG_NAME . " " . WIFIDOG_VERSION)); 
    122   $generator->appendChild($textnode); 
    123                  
    124   /* docs */ 
    125   $docs = $xmldoc->createElement("docs"); 
    126   $channel->appendChild($docs); 
    127   $textnode = $xmldoc->createTextNode(utf8_encode("http://blogs.law.harvard.edu/tech/rss")); 
    128   $docs->appendChild($textnode); 
    129                  
    130   /* cloud */ 
    131   /* Allows processes to register with a cloud to be notified of updates to the channel, implementing a lightweight publish-subscribe protocol for RSS feeds.*/ 
    132  
    133   /* ttl */ 
    134   /* ttl stands for time to live. It's a number of minutes that indicates how long a channel can be cached before refreshing from the source.*/ 
    135  
    136   /* image */ 
    137   $image = $xmldoc->createElement("image"); 
    138   $channel->appendChild($image); 
    139                  
    140   /* title */ 
    141   $title = $xmldoc->createElement("title"); 
    142   $image->appendChild($title); 
    143   $textnode = $xmldoc->createTextNode(utf8_encode(HOTSPOT_NETWORK_NAME)); 
    144   $title->appendChild($textnode); 
    145   /* url */ 
    146   $url = $xmldoc->createElement("url"); 
    147   $image->appendChild($url); 
    148   $textnode = $xmldoc->createTextNode(utf8_encode(COMMON_CONTENT_URL.NETWORK_LOGO_NAME)); 
    149   $url->appendChild($textnode); 
    150   /* link */ 
    151   $link = $xmldoc->createElement("link"); 
    152   $image->appendChild($link); 
    153   $textnode = $xmldoc->createTextNode(utf8_encode(HOTSPOT_NETWORK_URL)); 
    154   $link->appendChild($textnode); 
    155   /* width */ 
    156   /* 
    157    $width = $xmldoc->createElement("width"); 
    158    $image->appendChild($width); 
    159    $textnode = $xmldoc->createTextNode('135'); 
    160    $width->appendChild($textnode); 
    161   */ 
    162   /* height */ 
    163   /* 
    164    $height = $xmldoc->createElement("height"); 
    165    $image->appendChild($height); 
    166    $textnode = $xmldoc->createTextNode('109'); 
    167    $height->appendChild($textnode); 
    168   */ 
    169   /* description */ 
    170   /* 
    171    $description = $xmldoc->createElement("description"); 
    172    $image->appendChild($description); 
    173    $textnode = $xmldoc->createTextNode("Le portail des TIC"); 
    174    $description->appendChild($textnode); 
    175   */ 
    176  
    177   /* rating */ 
    178   /* textInput */ 
    179   /* skipHours */ 
    180   /* skipDays */ 
    181                  
    182   $i=0; 
    183  
    184   foreach($node_results as $node_row) { 
    185  
    186     $item = $xmldoc->createElement("item"); 
    187     $item = $channel->appendChild($item); 
    188  
    189     /* title */ 
    190     /* lom_1_2_title_langstrings_id */ 
    191     $title = $xmldoc->createElement("title"); 
    192     $item->appendChild($title); 
    193     $title_str = $node_row['name']; 
    194     $textnode = $xmldoc->createTextNode(utf8_encode($title_str)); 
    195     $title->appendChild($textnode); 
    196  
    197     /* link */ 
    198     if(!empty($node_row['home_page_url'])) 
    199       { 
     39        Header("Cache-control: private, no-cache, must-revalidate"); 
     40        Header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); # Past date 
     41        Header("Pragma: no-cache"); 
     42        Header("Content-Type: text/xml; charset=UTF-8"); 
     43 
     44        $xmldoc = new DOMDocument(); 
     45        $xmldoc->formatOutput = true; 
     46        //$xmldoc->encoding="iso-8859-15"; 
     47        $rss = $xmldoc->createElement("rss"); 
     48        $xmldoc->appendChild($rss); 
     49        $rss->setAttribute('version', '2.0'); 
     50 
     51        /* channel */ 
     52        $channel = $xmldoc->createElement("channel"); 
     53        $rss->appendChild($channel); 
     54 
     55        /**************** Required channel elements ********************/ 
     56        /* title */ 
     57        $title = $xmldoc->createElement("title"); 
     58        $title = $channel->appendChild($title); 
     59 
     60        $textnode = $xmldoc->createTextNode(utf8_encode(HOTSPOT_NETWORK_NAME._(": Newest HotSpots"))); 
     61        $title->appendChild($textnode); 
     62 
     63        /* link */ 
    20064        $link = $xmldoc->createElement("link"); 
    201         $item->appendChild($link); 
    202         $textnode = $xmldoc->createTextNode(utf8_encode($node_row['home_page_url'])); 
     65        $channel->appendChild($link); 
     66        $textnode = $xmldoc->createTextNode(utf8_encode(HOTSPOT_NETWORK_URL)); 
    20367        $link->appendChild($textnode); 
    204       } 
    205  
    206     /* description */ 
    207     $description = $xmldoc->createElement("description"); 
    208     $item->appendChild($description); 
    209     $description_text='<p>'; 
    210      
    211     if($node_row['node_deployment_status'] != 'NON_WIFIDOG_NODE') 
    212       { 
    213         if($node_row['is_up']=='t') 
    214           { 
    215             $description_text .= "<img src='".BASE_URL_PATH."images/hotspot_status_up.png'> "; 
    216           } 
    217         else 
    218           { 
    219             $description_text .= "<img src='".BASE_URL_PATH."images/hotspot_status_down.png'> "; 
    220           } 
    221       } 
    222  
    223     if(!empty($node_row['description'])) 
    224       { 
    225         $description_text.= $node_row['description']; 
    226       } 
    227     $description_text.= "</p>\n"; 
    228     $description_text.="<p>\n"; 
    229     if(!empty($node_row['street_address'])) 
    230       { 
    231         $description_text.= ""._("Address:")." ".$node_row['street_address']." "; 
    232       } 
    233     if(!empty($node_row['map_url'])) 
    234       { 
    235         $description_text.=" <a href='".$node_row['map_url']."'>"._("See Map")."</a> "; 
    236       } 
    237     $description_text.= "<br/>\n"; 
    238     if(!empty($node_row['mass_transit_info'])) 
    239       { 
    240         $description_text.=""._("Mass transit:")." ".$node_row['mass_transit_info']."<br/>\n"; 
    241       } 
    242     $description_text.= "</p>\n"; 
    243     if(!empty($node_row['public_email']) || !empty($node_row['public_phone_number'])) 
    244       { 
    245         $description_text.="<p>"._("Contact:"); 
    246  
    247         if(!empty($node_row['public_phone_number'])) 
    248           { 
    249             $description_text.=" $node_row[public_phone_number] "; 
    250           } 
    251         if(!empty($node_row['public_email'])) 
    252           { 
    253             $description_text.=" <a href='".$node_row['public_email']."'>$node_row[public_email]</a> "; 
    254           } 
    255         $description_text.="</p>\n"; 
    256       } 
    257     $textnode = $xmldoc->createTextNode(utf8_encode($description_text)); 
    258     $description->appendChild($textnode); 
    259        
    260     /* author */ 
    261     /* 
    262      $author = $xmldoc->createElement("author"); 
    263      $item->appendChild($author); 
    264      $textnode = $xmldoc->createTextNode($author_vcard->GetEmail().' ('.$author_vcard->GetName().')'); 
    265      $author->appendChild($textnode); 
    266     */ 
    267     /* category */ 
    268  
    269     /* comments */ 
    270     /** Link to page once page is available **/ 
    271     /* enclosure */ 
    272     /* guid */ 
    273  
    274     $guid = $xmldoc->createElement("guid"); 
    275     $guid->setAttribute('isPermaLink', 'false'); 
    276     $item->appendChild($guid); 
    277     $textnode = $xmldoc->createTextNode(utf8_encode(HOTSPOT_NETWORK_URL.$node_row['node_id'])); 
    278     $guid->appendChild($textnode); 
    279  
    280     /* pubDate */ 
    281     $pubDate = $xmldoc->createElement("pubDate"); 
    282     $item->appendChild($pubDate); 
    283     $textnode = $xmldoc->createTextNode(utf8_encode(gmdate("D, d M Y H:i:s \G\M\T", $node_row['creation_date_epoch']))); 
    284     $pubDate->appendChild($textnode); 
    285  
    286     /* source */ 
    287   } 
    288   @ob_clean(); 
    289   echo $xmldoc->saveXML(); 
    290  } 
    291  else if ($format == 'WIFI411_CSV') { 
    292  /* Header("Cache-control: private, no-cache, must-revalidate"); 
    293   Header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); # Past date 
    294   Header("Pragma: no-cache"); 
    295   Header("Content-Type: text/xml; charset=UTF-8");*/ 
    296  
    297   $xmldoc = new DOMDocument(); 
    298   $xmldoc->formatOutput = true; 
    299   //$xmldoc->encoding="iso-8859-15"; 
    300   $rss = $xmldoc->createElement("rss"); 
    301   $xmldoc->appendChild($rss); 
    302   $rss->setAttribute('version', '2.0'); 
    303  
    304   /* channel */ 
    305   $channel = $xmldoc->createElement("channel"); 
    306   $rss->appendChild($channel); 
    307  
    308   /**************** Required channel elements ********************/ 
    309   /* title */ 
    310   $title = $xmldoc->createElement("title"); 
    311   $title = $channel->appendChild($title); 
    312  
    313   $textnode = $xmldoc->createTextNode(utf8_encode(HOTSPOT_NETWORK_NAME._(": Newest HotSpots"))); 
    314   $title->appendChild($textnode); 
    315  
    316   /* link */ 
    317   $link = $xmldoc->createElement("link"); 
    318   $channel->appendChild($link); 
    319   $textnode = $xmldoc->createTextNode(utf8_encode(HOTSPOT_NETWORK_URL)); 
    320   $link->appendChild($textnode); 
    321  
    322   /* description */ 
    323   $description = $xmldoc->createElement("description"); 
    324   $channel->appendChild($description); 
    325   $textnode = $xmldoc->createTextNode(utf8_encode(_("WiFiDog list of the most recent HotSpots opened by the network: ").HOTSPOT_NETWORK_NAME)); 
    326   $description->appendChild($textnode); 
    327  
    328   /****************** Optional channel elements *******************/ 
    329   /* language */ 
    330   /**@todo Make language selectable */ 
    331   $language = $xmldoc->createElement("language"); 
    332   $channel->appendChild($language); 
    333   $textnode = $xmldoc->createTextNode("en-CA"); 
    334   $language->appendChild($textnode); 
    335  
    336   /* copyright */ 
    337   $copyright = $xmldoc->createElement("copyright"); 
    338   $channel->appendChild($copyright); 
    339   $textnode = $xmldoc->createTextNode(utf8_encode(_("Copyright ").HOTSPOT_NETWORK_NAME)); 
    340   $copyright->appendChild($textnode); 
    341  
    342   /* managingEditor */ 
    343                  
    344   /* webMaster */ 
    345                  
    346   $webMaster = $xmldoc->createElement("webMaster"); 
    347   $channel->appendChild($webMaster); 
    348   $textnode = $xmldoc->createTextNode(utf8_encode(TECH_SUPPORT_EMAIL)); 
    349   $webMaster->appendChild($textnode); 
    350  
    351   /* pubDate */ 
    352   $pubDate = $xmldoc->createElement("pubDate"); 
    353   $channel->appendChild($pubDate); 
    354   $textnode = $xmldoc->createTextNode(utf8_encode(gmdate("D, d M Y H:i:s \G\M\T", time()))); 
    355   $pubDate->appendChild($textnode); 
    356  
    357   /* lastBuildDate */ 
    358   //<lastBuildDate> -- The date-time the last time the content of the channel changed. 
    359   /* Make a request through the database for the latest modification date of an object.   
    360    * Maybe it should be an object property? */ 
    361   $db->ExecSqlUniqueRes("SELECT EXTRACT(epoch FROM MAX(creation_date)) as date_last_hotspot_opened FROM nodes WHERE node_deployment_status = 'DEPLOYED' OR node_deployment_status = 'NON_WIFIDOG_NODE' ", $last_hotspot_row, false); 
    362  
    363   $lastBuildDate = $xmldoc->createElement("lastBuildDate"); 
    364   $channel->appendChild($lastBuildDate); 
    365   $textnode = $xmldoc->createTextNode(gmdate("D, d M Y H:i:s \G\M\T", $last_hotspot_row['date_last_hotspot_opened'])); 
    366   $lastBuildDate->appendChild($textnode); 
    367                  
    368   /* category */ 
    369   /* Specify one or more categories that the channel belongs to. 
    370    *  Follows the same rules as the <item>-level category element.*/ 
    371                   
    372   /* generator */ 
    373   $generator = $xmldoc->createElement("generator"); 
    374   $channel->appendChild($generator); 
    375   $textnode = $xmldoc->createTextNode(utf8_encode(WIFIDOG_NAME . " " . WIFIDOG_VERSION)); 
    376   $generator->appendChild($textnode); 
    377                  
    378   /* docs */ 
    379   $docs = $xmldoc->createElement("docs"); 
    380   $channel->appendChild($docs); 
    381   $textnode = $xmldoc->createTextNode(utf8_encode("http://blogs.law.harvard.edu/tech/rss")); 
    382   $docs->appendChild($textnode); 
    383                  
    384   /* cloud */ 
    385   /* Allows processes to register with a cloud to be notified of updates to the channel, implementing a lightweight publish-subscribe protocol for RSS feeds.*/ 
    386  
    387   /* ttl */ 
    388   /* ttl stands for time to live. It's a number of minutes that indicates how long a channel can be cached before refreshing from the source.*/ 
    389  
    390   /* image */ 
    391   $image = $xmldoc->createElement("image"); 
    392   $channel->appendChild($image); 
    393                  
    394   /* title */ 
    395   $title = $xmldoc->createElement("title"); 
    396   $image->appendChild($title); 
    397   $textnode = $xmldoc->createTextNode(utf8_encode(HOTSPOT_NETWORK_NAME)); 
    398   $title->appendChild($textnode); 
    399   /* url */ 
    400   $url = $xmldoc->createElement("url"); 
    401   $image->appendChild($url); 
    402   $textnode = $xmldoc->createTextNode(utf8_encode(COMMON_CONTENT_URL.NETWORK_LOGO_NAME)); 
    403   $url->appendChild($textnode); 
    404   /* link */ 
    405   $link = $xmldoc->createElement("link"); 
    406   $image->appendChild($link); 
    407   $textnode = $xmldoc->createTextNode(utf8_encode(HOTSPOT_NETWORK_URL)); 
    408   $link->appendChild($textnode); 
    409   /* width */ 
    410   /* 
    411    $width = $xmldoc->createElement("width"); 
    412    $image->appendChild($width); 
    413    $textnode = $xmldoc->createTextNode('135'); 
    414    $width->appendChild($textnode); 
    415   */ 
    416   /* height */ 
    417   /* 
    418    $height = $xmldoc->createElement("height"); 
    419    $image->appendChild($height); 
    420    $textnode = $xmldoc->createTextNode('109'); 
    421    $height->appendChild($textnode); 
    422   */ 
    423   /* description */ 
    424   /* 
    425    $description = $xmldoc->createElement("description"); 
    426    $image->appendChild($description); 
    427    $textnode = $xmldoc->createTextNode("Le portail des TIC"); 
    428    $description->appendChild($textnode); 
    429   */ 
    430  
    431   /* rating */ 
    432   /* textInput */ 
    433   /* skipHours */ 
    434   /* skipDays */ 
    435                  
    436   $i=0; 
    437  
    438   foreach($node_results as $node_row) { 
    439  
    440     $item = $xmldoc->createElement("item"); 
    441     $item = $channel->appendChild($item); 
    442  
    443     /* title */ 
    444     /* lom_1_2_title_langstrings_id */ 
    445     $title = $xmldoc->createElement("title"); 
    446     $item->appendChild($title); 
    447     $title_str = $node_row['name']; 
    448     $textnode = $xmldoc->createTextNode(utf8_encode($title_str)); 
    449     $title->appendChild($textnode); 
    450  
    451     /* link */ 
    452     if(!empty($node_row['home_page_url'])) 
    453       { 
     68 
     69        /* description */ 
     70        $description = $xmldoc->createElement("description"); 
     71        $channel->appendChild($description); 
     72        $textnode = $xmldoc->createTextNode(utf8_encode(_("WiFiDog list of the most recent HotSpots opened by the network: ").HOTSPOT_NETWORK_NAME)); 
     73        $description->appendChild($textnode); 
     74 
     75        /****************** Optional channel elements *******************/ 
     76        /* language */ 
     77        /**@todo Make language selectable */ 
     78        $language = $xmldoc->createElement("language"); 
     79        $channel->appendChild($language); 
     80        $textnode = $xmldoc->createTextNode("en-CA"); 
     81        $language->appendChild($textnode); 
     82 
     83        /* copyright */ 
     84        $copyright = $xmldoc->createElement("copyright"); 
     85        $channel->appendChild($copyright); 
     86        $textnode = $xmldoc->createTextNode(utf8_encode(_("Copyright ").HOTSPOT_NETWORK_NAME)); 
     87        $copyright->appendChild($textnode); 
     88 
     89        /* managingEditor */ 
     90 
     91        /* webMaster */ 
     92 
     93        $webMaster = $xmldoc->createElement("webMaster"); 
     94        $channel->appendChild($webMaster); 
     95        $textnode = $xmldoc->createTextNode(utf8_encode(TECH_SUPPORT_EMAIL)); 
     96        $webMaster->appendChild($textnode); 
     97 
     98        /* pubDate */ 
     99        $pubDate = $xmldoc->createElement("pubDate"); 
     100        $channel->appendChild($pubDate); 
     101        $textnode = $xmldoc->createTextNode(utf8_encode(gmdate("D, d M Y H:i:s \G\M\T", time()))); 
     102        $pubDate->appendChild($textnode); 
     103 
     104        /* lastBuildDate */ 
     105        //<lastBuildDate> -- The date-time the last time the content of the channel changed. 
     106        /* Make a request through the database for the latest modification date of an object.   
     107         * Maybe it should be an object property? */ 
     108        $db->ExecSqlUniqueRes("SELECT EXTRACT(epoch FROM MAX(creation_date)) as date_last_hotspot_opened FROM nodes WHERE node_deployment_status = 'DEPLOYED' OR node_deployment_status = 'NON_WIFIDOG_NODE' ", $last_hotspot_row, false); 
     109 
     110        $lastBuildDate = $xmldoc->createElement("lastBuildDate"); 
     111        $channel->appendChild($lastBuildDate); 
     112        $textnode = $xmldoc->createTextNode(gmdate("D, d M Y H:i:s \G\M\T", $last_hotspot_row['date_last_hotspot_opened'])); 
     113        $lastBuildDate->appendChild($textnode); 
     114 
     115        /* category */ 
     116        /* Specify one or more categories that the channel belongs to. 
     117         *  Follows the same rules as the <item>-level category element.*/ 
     118 
     119        /* generator */ 
     120        $generator = $xmldoc->createElement("generator"); 
     121        $channel->appendChild($generator); 
     122        $textnode = $xmldoc->createTextNode(utf8_encode(WIFIDOG_NAME." ".WIFIDOG_VERSION)); 
     123        $generator->appendChild($textnode); 
     124 
     125        /* docs */ 
     126        $docs = $xmldoc->createElement("docs"); 
     127        $channel->appendChild($docs); 
     128        $textnode = $xmldoc->createTextNode(utf8_encode("http://blogs.law.harvard.edu/tech/rss")); 
     129        $docs->appendChild($textnode); 
     130 
     131        /* cloud */ 
     132        /* Allows processes to register with a cloud to be notified of updates to the channel, implementing a lightweight publish-subscribe protocol for RSS feeds.*/ 
     133 
     134        /* ttl */ 
     135        /* ttl stands for time to live. It's a number of minutes that indicates how long a channel can be cached before refreshing from the source.*/ 
     136 
     137        /* image */ 
     138        $image = $xmldoc->createElement("image"); 
     139        $channel->appendChild($image); 
     140 
     141        /* title */ 
     142        $title = $xmldoc->createElement("title"); 
     143        $image->appendChild($title); 
     144        $textnode = $xmldoc->createTextNode(utf8_encode(HOTSPOT_NETWORK_NAME)); 
     145        $title->appendChild($textnode); 
     146        /* url */ 
     147        $url = $xmldoc->createElement("url"); 
     148        $image->appendChild($url); 
     149        $textnode = $xmldoc->createTextNode(utf8_encode(COMMON_CONTENT_URL.NETWORK_LOGO_NAME)); 
     150        $url->appendChild($textnode); 
     151        /* link */ 
    454152        $link = $xmldoc->createElement("link"); 
    455         $item->appendChild($link); 
    456         $textnode = $xmldoc->createTextNode(utf8_encode($node_row['home_page_url'])); 
     153        $image->appendChild($link); 
     154        $textnode = $xmldoc->createTextNode(utf8_encode(HOTSPOT_NETWORK_URL)); 
    457155        $link->appendChild($textnode); 
    458       } 
    459  
    460     /* description */ 
    461     $description = $xmldoc->createElement("description"); 
    462     $item->appendChild($description); 
    463     $description_text='<p>'; 
    464     if($node_row['node_deployment_status'] != 'NON_WIFIDOG_NODE') 
    465       { 
    466         if($node_row['is_up']=='t') 
    467           { 
    468             $description_text .= "<img src='".BASE_URL_PATH."images/hotspot_status_up.png'> "; 
    469           } 
    470         else 
    471           { 
    472             $description_text .= "<img src='".BASE_URL_PATH."images/hotspot_status_down.png'> "; 
    473           } 
    474       } 
    475  
    476     if(!empty($node_row['description'])) 
    477       { 
    478         $description_text.= $node_row['description']; 
    479       } 
    480     $description_text.= "</p>\n"; 
    481     $description_text.="<p>\n"; 
    482     if(!empty($node_row['street_address'])) 
    483       { 
    484         $description_text.= ""._("Address:")." ".$node_row['street_address']." "; 
    485       } 
    486     if(!empty($node_row['map_url'])) 
    487       { 
    488         $description_text.=" <a href='".$node_row['map_url']."'>"._("See Map")."</a> "; 
    489       } 
    490     $description_text.= "<br/>\n"; 
    491     if(!empty($node_row['mass_transit_info'])) 
    492       { 
    493         $description_text.=""._("Mass transit:")." ".$node_row['mass_transit_info']."<br/>\n"; 
    494       } 
    495     $description_text.= "</p>\n"; 
    496     if(!empty($node_row['public_email']) || !empty($node_row['public_phone_number'])) 
    497       { 
    498         $description_text.="<p>"._("Contact:"); 
    499  
    500         if(!empty($node_row['public_phone_number'])) 
    501           { 
    502             $description_text.=" $node_row[public_phone_number] "; 
    503           } 
    504         if(!empty($node_row['public_email'])) 
    505           { 
    506             $description_text.=" <a href='".$node_row['public_email']."'>$node_row[public_email]</a> "; 
    507           } 
    508         $description_text.="</p>\n"; 
    509       } 
    510     $textnode = $xmldoc->createTextNode(utf8_encode($description_text)); 
    511     $description->appendChild($textnode); 
    512        
    513     /* author */ 
    514     /* 
    515      $author = $xmldoc->createElement("author"); 
    516      $item->appendChild($author); 
    517      $textnode = $xmldoc->createTextNode($author_vcard->GetEmail().' ('.$author_vcard->GetName().')'); 
    518      $author->appendChild($textnode); 
    519     */ 
    520     /* category */ 
    521  
    522     /* comments */ 
    523     /** Link to page once page is available **/ 
    524     /* enclosure */ 
    525     /* guid */ 
    526  
    527     $guid = $xmldoc->createElement("guid"); 
    528     $guid->setAttribute('isPermaLink', 'false'); 
    529     $item->appendChild($guid); 
    530     $textnode = $xmldoc->createTextNode(utf8_encode(HOTSPOT_NETWORK_URL.$node_row['node_id'])); 
    531     $guid->appendChild($textnode); 
    532  
    533     /* pubDate */ 
    534     $pubDate = $xmldoc->createElement("pubDate"); 
    535     $item->appendChild($pubDate); 
    536     $textnode = $xmldoc->createTextNode(utf8_encode(gmdate("D, d M Y H:i:s \G\M\T", $node_row['creation_date_epoch']))); 
    537     $pubDate->appendChild($textnode); 
    538  
    539     /* source */ 
    540   } 
    541   ob_clean(); 
    542   echo $xmldoc->saveXML(); 
    543  } 
    544   else { 
    545   foreach($node_results as $node_row) { 
    546     $node_row['num_online_users'] = $stats->getNumOnlineUsers($node_row['node_id']); 
    547     $smarty->append("nodes", $node_row); 
    548   } 
    549   $smarty->assign("num_deployed_nodes", count($node_results)); 
    550   $smarty->assign("title", "hotspot_status"); 
    551   $smarty->display("templates/hotspot_status.html"); 
    552  } 
     156        /* width */ 
     157        /* 
     158         $width = $xmldoc->createElement("width"); 
     159         $image->appendChild($width); 
     160         $textnode = $xmldoc->createTextNode('135'); 
     161         $width->appendChild($textnode); 
     162        */ 
     163        /* height */ 
     164        /* 
     165         $height = $xmldoc->createElement("height"); 
     166         $image->appendChild($height); 
     167         $textnode = $xmldoc->createTextNode('109'); 
     168         $height->appendChild($textnode); 
     169        */ 
     170        /* description */ 
     171        /* 
     172         $description = $xmldoc->createElement("description"); 
     173         $image->appendChild($description); 
     174         $textnode = $xmldoc->createTextNode("Le portail des TIC"); 
     175         $description->appendChild($textnode); 
     176        */ 
     177 
     178        /* rating */ 
     179        /* textInput */ 
     180        /* skipHours */ 
     181        /* skipDays */ 
     182 
     183        $i = 0; 
     184 
     185        foreach ($node_results as $node_row) { 
     186 
     187                $item = $xmldoc->createElement("item"); 
     188                $item = $channel->appendChild($item); 
     189 
     190                /* title */ 
     191                /* lom_1_2_title_langstrings_id */ 
     192                $title = $xmldoc->createElement("title"); 
     193                $item->appendChild($title); 
     194                $title_str = $node_row['name']; 
     195                $textnode = $xmldoc->createTextNode(utf8_encode($title_str)); 
     196                $title->appendChild($textnode); 
     197 
     198                /* link */ 
     199                if (!empty ($node_row['home_page_url'])) { 
     200                        $link = $xmldoc->createElement("link"); 
     201                        $item->appendChild($link); 
     202                        $textnode = $xmldoc->createTextNode(utf8_encode($node_row['home_page_url'])); 
     203                        $link->appendChild($textnode); 
     204                } 
     205 
     206                /* description */ 
     207                $description = $xmldoc->createElement("description"); 
     208                $item->appendChild($description); 
     209                $description_text = '<p>'; 
     210 
     211                if ($node_row['node_deployment_status'] != 'NON_WIFIDOG_NODE') { 
     212                        if ($node_row['is_up'] == 't') { 
     213                                $description_text .= "<img src='".BASE_URL_PATH."images/hotspot_status_up.png'> "; 
     214                        } else { 
     215                                $description_text .= "<img src='".BASE_URL_PATH."images/hotspot_status_down.png'> "; 
     216                        } 
     217                } 
     218 
     219                if (!empty ($node_row['description'])) { 
     220                        $description_text .= $node_row['description']; 
     221                } 
     222                $description_text .= "</p>\n"; 
     223                $description_text .= "<p>\n"; 
     224                if (!empty ($node_row['street_address'])) { 
     225                        $description_text .= ""._("Address:")." ".$node_row['street_address']." "; 
     226                } 
     227                if (!empty ($node_row['map_url'])) { 
     228                        $description_text .= " <a href='".$node_row['map_url']."'>"._("See Map")."</a> "; 
     229                } 
     230                $description_text .= "<br/>\n"; 
     231                if (!empty ($node_row['mass_transit_info'])) { 
     232                        $description_text .= ""._("Mass transit:")." ".$node_row['mass_transit_info']."<br/>\n"; 
     233                } 
     234                $description_text .= "</p>\n"; 
     235                if (!empty ($node_row['public_email']) || !empty ($node_row['public_phone_number'])) { 
     236                        $description_text .= "<p>"._("Contact:"); 
     237 
     238                        if (!empty ($node_row['public_phone_number'])) { 
     239                                $description_text .= " $node_row[public_phone_number] "; 
     240                        } 
     241                        if (!empty ($node_row['public_email'])) { 
     242                                $description_text .= " <a href='".$node_row['public_email']."'>$node_row[public_email]</a> "; 
     243                        } 
     244                        $description_text .= "</p>\n"; 
     245                } 
     246                $textnode = $xmldoc->createTextNode(utf8_encode($description_text)); 
     247                $description->appendChild($textnode); 
     248 
     249                /* author */ 
     250                /* 
     251                 $author = $xmldoc->createElement("author"); 
     252                 $item->appendChild($author); 
     253                 $textnode = $xmldoc->createTextNode($author_vcard->GetEmail().' ('.$author_vcard->GetName().')'); 
     254                 $author->appendChild($textnode); 
     255                */ 
     256                /* category */ 
     257 
     258                /* comments */ 
     259                /** Link to page once page is available **/ 
     260                /* enclosure */ 
     261                /* guid */ 
     262 
     263                $guid = $xmldoc->createElement("guid"); 
     264                $guid->setAttribute('isPermaLink', 'false'); 
     265                $item->appendChild($guid); 
     266                $textnode = $xmldoc->createTextNode(utf8_encode(HOTSPOT_NETWORK_URL.$node_row['node_id'])); 
     267                $guid->appendChild($textnode); 
     268 
     269                /* pubDate */ 
     270                $pubDate = $xmldoc->createElement("pubDate"); 
     271                $item->appendChild($pubDate); 
     272                $textnode = $xmldoc->createTextNode(utf8_encode(gmdate("D, d M Y H:i:s \G\M\T", $node_row['creation_date_epoch']))); 
     273                $pubDate->appendChild($textnode); 
     274 
     275                /* source */ 
     276        } 
     277        @ ob_clean(); 
     278        echo $xmldoc->saveXML(); 
     279} else 
     280        if ($format == 'WIFI411_CSV') { 
     281                /* Header("Cache-control: private, no-cache, must-revalidate"); 
     282                 Header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); # Past date 
     283                 Header("Pragma: no-cache"); 
     284                 Header("Content-Type: text/xml; charset=UTF-8");*/ 
     285 
     286                $xmldoc = new DOMDocument(); 
     287                $xmldoc->formatOutput = true; 
     288                //$xmldoc->encoding="iso-8859-15"; 
     289                $rss = $xmldoc->createElement("rss"); 
     290                $xmldoc->appendChild($rss); 
     291                $rss->setAttribute('version', '2.0'); 
     292 
     293                /* channel */ 
     294                $channel = $xmldoc->createElement("channel"); 
     295                $rss->appendChild($channel); 
     296 
     297                /**************** Required channel elements ********************/ 
     298                /* title */ 
     299                $title = $xmldoc->createElement("title"); 
     300                $title = $channel->appendChild($title); 
     301 
     302                $textnode = $xmldoc->createTextNode(utf8_encode(HOTSPOT_NETWORK_NAME._(": Newest HotSpots"))); 
     303                $title->appendChild($textnode); 
     304 
     305                /* link */ 
     306                $link = $xmldoc->createElement("link"); 
     307                $channel->appendChild($link); 
     308                $textnode = $xmldoc->createTextNode(utf8_encode(HOTSPOT_NETWORK_URL)); 
     309                $link->appendChild($textnode); 
     310 
     311                /* description */ 
     312                $description = $xmldoc->createElement("description"); 
     313                $channel->appendChild($description); 
     314                $textnode = $xmldoc->createTextNode(utf8_encode(_("WiFiDog list of the most recent HotSpots opened by the network: ").HOTSPOT_NETWORK_NAME)); 
     315                $description->appendChild($textnode); 
     316 
     317                /****************** Optional channel elements *******************/ 
     318                /* language */ 
     319                /**@todo Make language selectable */ 
     320                $language = $xmldoc->createElement("language"); 
     321                $channel->appendChild($language); 
     322                $textnode = $xmldoc->createTextNode("en-CA"); 
     323                $language->appendChild($textnode); 
     324 
     325                /* copyright */ 
     326                $copyright = $xmldoc->createElement("copyright"); 
     327                $channel->appendChild($copyright); 
     328                $textnode = $xmldoc->createTextNode(utf8_encode(_("Copyright ").HOTSPOT_NETWORK_NAME)); 
     329                $copyright->appendChild($textnode); 
     330 
     331                /* managingEditor */ 
     332 
     333                /* webMaster */ 
     334 
     335                $webMaster = $xmldoc->createElement("webMaster"); 
     336                $channel->appendChild($webMaster); 
     337                $textnode = $xmldoc->createTextNode(utf8_encode(TECH_SUPPORT_EMAIL)); 
     338                $webMaster->appendChild($textnode); 
     339 
     340                /* pubDate */ 
     341                $pubDate = $xmldoc->createElement("pubDate"); 
     342                $channel->appendChild($pubDate); 
     343                $textnode = $xmldoc->createTextNode(utf8_encode(gmdate("D, d M Y H:i:s \G\M\T", time()))); 
     344                $pubDate->appendChild($textnode); 
     345 
     346                /* lastBuildDate */ 
     347                //<lastBuildDate> -- The date-time the last time the content of the channel changed. 
     348                /* Make a request through the database for the latest modification date of an object.   
     349                 * Maybe it should be an object property? */ 
     350                $db->ExecSqlUniqueRes("SELECT EXTRACT(epoch FROM MAX(creation_date)) as date_last_hotspot_opened FROM nodes WHERE node_deployment_status = 'DEPLOYED' OR node_deployment_status = 'NON_WIFIDOG_NODE' ", $last_hotspot_row, false); 
     351 
     352                $lastBuildDate = $xmldoc->createElement("lastBuildDate"); 
     353                $channel->appendChild($lastBuildDate); 
     354                $textnode = $xmldoc->createTextNode(gmdate("D, d M Y H:i:s \G\M\T", $last_hotspot_row['date_last_hotspot_opened'])); 
     355                $lastBuildDate->appendChild($textnode); 
     356 
     357                /* category */ 
     358                /* Specify one or more categories that the channel belongs to. 
     359                 *  Follows the same rules as the <item>-level category element.*/ 
     360 
     361                /* generator */ 
     362                $generator = $xmldoc->createElement("generator"); 
     363                $channel->appendChild($generator); 
     364                $textnode = $xmldoc->createTextNode(utf8_encode(WIFIDOG_NAME." ".WIFIDOG_VERSION)); 
     365                $generator->appendChild($textnode); 
     366 
     367                /* docs */ 
     368                $docs = $xmldoc->createElement("docs"); 
     369                $channel->appendChild($docs); 
     370                $textnode = $xmldoc->createTextNode(utf8_encode("http://blogs.law.harvard.edu/tech/rss")); 
     371                $docs->appendChild($textnode); 
     372 
     373                /* cloud */ 
     374                /* Allows processes to register with a cloud to be notified of updates to the channel, implementing a lightweight publish-subscribe protocol for RSS feeds.*/ 
     375 
     376                /* ttl */ 
     377                /* ttl stands for time to live. It's a number of minutes that indicates how long a channel can be cached before refreshing from the source.*/ 
     378 
     379                /* image */ 
     380                $image = $xmldoc->createElement("image"); 
     381                $channel->appendChild($image); 
     382 
     383                /* title */ 
     384                $title = $xmldoc->createElement("title"); 
     385                $image->appendChild($title); 
     386                $textnode = $xmldoc->createTextNode(utf8_encode(HOTSPOT_NETWORK_NAME)); 
     387                $title->appendChild($textnode); 
     388                /* url */ 
     389                $url = $xmldoc->createElement("url"); 
     390                $image->appendChild($url); 
     391                $textnode = $xmldoc->createTextNode(utf8_encode(COMMON_CONTENT_URL.NETWORK_LOGO_NAME)); 
     392                $url->appendChild($textnode); 
     393                /* link */ 
     394                $link = $xmldoc->createElement("link"); 
     395                $image->appendChild($link); 
     396                $textnode = $xmldoc->createTextNode(utf8_encode(HOTSPOT_NETWORK_URL)); 
     397                $link->appendChild($textnode); 
     398                /* width */ 
     399                /* 
     400                 $width = $xmldoc->createElement("width"); 
     401                 $image->appendChild($width); 
     402                 $textnode = $xmldoc->createTextNode('135'); 
     403                 $width->appendChild($textnode); 
     404                */ 
     405                /* height */ 
     406                /* 
     407                 $height = $xmldoc->createElement("height"); 
     408                 $image->appendChild($height); 
     409                 $textnode = $xmldoc->createTextNode('109'); 
     410                 $height->appendChild($textnode); 
     411                */ 
     412                /* description */ 
     413                /* 
     414                 $description = $xmldoc->createElement("description"); 
     415                 $image->appendChild($description); 
     416                 $textnode = $xmldoc->createTextNode("Le portail des TIC"); 
     417                 $description->appendChild($textnode); 
     418                */ 
     419 
     420                /* rating */ 
     421                /* textInput */ 
     422                /* skipHours */ 
     423                /* skipDays */ 
     424 
     425                $i = 0; 
     426 
     427                foreach ($node_results as $node_row) { 
     428 
     429                        $item = $xmldoc->createElement("item"); 
     430                        $item = $channel->appendChild($item); 
     431 
     432                        /* title */ 
     433                        /* lom_1_2_title_langstrings_id */ 
     434                        $title = $xmldoc->createElement("title"); 
     435                        $item->appendChild($title); 
     436                        $title_str = $node_row['name']; 
     437                        $textnode = $xmldoc->createTextNode(utf8_encode($title_str)); 
     438                        $title->appendChild($textnode); 
     439 
     440                        /* link */ 
     441                        if (!empty ($node_row['home_page_url'])) { 
     442                                $link = $xmldoc->createElement("link"); 
     443                                $item->appendChild($link); 
     444                                $textnode = $xmldoc->createTextNode(utf8_encode($node_row['home_page_url'])); 
     445                                $link->appendChild($textnode); 
     446                        } 
     447 
     448                        /* description */ 
     449                        $description = $xmldoc->createElement("description"); 
     450                        $item->appendChild($description); 
     451                        $description_text = '<p>'; 
     452                        if ($node_row['node_deployment_status'] != 'NON_WIFIDOG_NODE') { 
     453                                if ($node_row['is_up'] == 't') { 
     454                                        $description_text .= "<img src='".BASE_URL_PATH."images/hotspot_status_up.png'> "; 
     455                                } else { 
     456                                        $description_text .= "<img src='".BASE_URL_PATH."images/hotspot_status_down.png'> "; 
     457                                } 
     458                        } 
     459 
     460                        if (!empty ($node_row['description'])) { 
     461                                $description_text .= $node_row['description']; 
     462                        } 
     463                        $description_text .= "</p>\n"; 
     464                        $description_text .= "<p>\n"; 
     465                        if (!empty ($node_row['street_address'])) { 
     466                                $description_text .= ""._("Address:")." ".$node_row['street_address']." "; 
     467                        } 
     468                        if (!empty ($node_row['map_url'])) { 
     469                                $description_text .= " <a href='".$node_row['map_url']."'>"._("See Map")."</a> "; 
     470                        } 
     471                        $description_text .= "<br/>\n"; 
     472                        if (!empty ($node_row['mass_transit_info'])) { 
     473                                $description_text .= ""._("Mass transit:")." ".$node_row['mass_transit_info']."<br/>\n"; 
     474                        } 
     475                        $description_text .= "</p>\n"; 
     476                        if (!empty ($node_row['public_email']) || !empty ($node_row['public_phone_number'])) { 
     477                                $description_text .= "<p>"._("Contact:"); 
     478 
     479                                if (!empty ($node_row['public_phone_number'])) { 
     480                                        $description_text .= " $node_row[public_phone_number] "; 
     481                                } 
     482                                if (!empty ($node_row['public_email'])) { 
     483                                        $description_text .= " <a href='".$node_row['public_email']."'>$node_row[public_email]</a> "; 
     484                                } 
     485                                $description_text .= "</p>\n"; 
     486                        } 
     487                        $textnode = $xmldoc->createTextNode(utf8_encode($description_text)); 
     488                        $description->appendChild($textnode); 
     489 
     490                        /* author */ 
     491                        /* 
     492                         $author = $xmldoc->createElement("author"); 
     493                         $item->appendChild($author); 
     494                         $textnode = $xmldoc->createTextNode($author_vcard->GetEmail().' ('.$author_vcard->GetName().')'); 
     495                         $author->appendChild($textnode); 
     496                        */ 
     497                        /* category */ 
     498 
     499                        /* comments */ 
     500                        /** Link to page once page is available **/ 
     501                        /* enclosure */ 
     502                        /* guid */ 
     503 
     504                        $guid = $xmldoc->createElement("guid"); 
     505                        $guid->setAttribute('isPermaLink', 'false'); 
     506                        $item->appendChild($guid); 
     507                        $textnode = $xmldoc->createTextNode(utf8_encode(HOTSPOT_NETWORK_URL.$node_row['node_id'])); 
     508                        $guid->appendChild($textnode); 
     509 
     510                        /* pubDate */ 
     511                        $pubDate = $xmldoc->createElement("pubDate"); 
     512                        $item->appendChild($pubDate); 
     513                        $textnode = $xmldoc->createTextNode(utf8_encode(gmdate("D, d M Y H:i:s \G\M\T", $node_row['creation_date_epoch']))); 
     514                        $pubDate->appendChild($textnode); 
     515 
     516                        /* source */ 
     517                } 
     518                ob_clean(); 
     519                echo $xmldoc->saveXML(); 
     520        } else { 
     521                if ($node_results) 
     522                        foreach ($node_results as $node_row) { 
     523                                $node_row['num_online_users'] = $stats->getNumOnlineUsers($node_row['node_id']); 
     524                                $smarty->append("nodes", $node_row); 
     525                        } 
     526                $smarty->assign("num_deployed_nodes", count($node_results)); 
     527                $smarty->assign("title", "hotspot_status"); 
     528                $smarty->display("templates/hotspot_status.html"); 
     529        } 
    553530?> 
     531 
  • trunk/wifidog-auth/wifidog/local_content/default/header.html

    r417 r516  
    2222<ul> 
    2323{foreach from=$online_users item=user_info} 
    24 <li>{$user_info.user_id}</li> 
     24<li>{$user_info.username}</li> 
    2525{/foreach} 
    2626</ul> 
  • trunk/wifidog-auth/wifidog/login/index.php

    r512 r516  
    11<?php 
    2   // $Id$ 
    3   /********************************************************************\ 
    4    * This program is free software; you can redistribute it and/or    * 
    5    * modify it under the terms of the GNU General Public License as   * 
    6    * published by the Free Software Foundation; either version 2 of   * 
    7    * the License, or (at your option) any later version.              * 
    8    *                                                                  * 
    9    * This program is distributed in the hope that it will be useful,  * 
    10    * but WITHOUT ANY WARRANTY; without even the implied warranty of   * 
    11    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    * 
    12    * GNU General Public License for more details.                     * 
    13    *                                                                  * 
    14    * You should have received a copy of the GNU General Public License* 
    15    * along with this program; if not, contact:                        * 
    16    *                                                                  * 
    17    * Free Software Foundation           Voice:  +1-617-542-5942       * 
    18    * 59 Temple Place - Suite 330        Fax:    +1-617-542-2652       * 
    19    * Boston, MA  02111-1307,  USA       gnu@gnu.org                   * 
    20    *                                                                  * 
    21    \********************************************************************/ 
    22   /**@file 
    23    * Login page 
    24    * @author Copyright (C) 2004 Benoit Gr�goire et Philippe April 
    25    */ 
    26 define('BASEPATH','../'); 
     2 
     3// $Id$ 
     4/********************************************************************\ 
     5 * This program is free software; you can redistribute it and/or    * 
     6 * modify it under the terms of the GNU General Public License as   * 
     7 * published by the Free Software Foundation; either version 2 of   * 
     8 * the License, or (at your option) any later version.              * 
     9 *                                                                  * 
     10 * This program is distributed in the hope that it will be useful,  * 
     11 * but WITHOUT ANY WARRANTY; without even the implied warranty of   * 
     12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    * 
     13 * GNU General Public License for more details.                     * 
     14 *                                                                  * 
     15 * You should have received a copy of the GNU General Public License* 
     16 * along with this program; if not, contact:                        * 
     17 *                                                                  * 
     18 * Free Software Foundation           Voice:  +1-617-542-5942       * 
     19 * 59 Temple Place - Suite 330        Fax:    +1-617-542-2652       * 
     20 * Boston, MA  02111-1307,  USA       gnu@gnu.org                   * 
     21 *                                                                  * 
     22 \********************************************************************/ 
     23/**@file 
     24 * Login page 
     25 * @author Copyright (C) 2004 Benoit Gr�goire et Philippe April 
     26 */ 
     27define('BASEPATH', '../'); 
    2728require_once BASEPATH.'include/common.php'; 
    2829require_once BASEPATH.'include/common_interface.php'; 
     
    3132require_once BASEPATH.'classes/User.php'; 
    3233 
    33 if (!empty($_REQUEST['url'])) { 
    34   $session->set(SESS_ORIGINAL_URL_VAR, $_REQUEST['url']); 
    35  } 
     34if (!empty ($_REQUEST['url'])) { 
     35        $session->set(SESS_ORIGINAL_URL_VAR, $_REQUEST['url']); 
     36} 
    3637 
    37 if (!empty($_REQUEST['username']) && !empty($_REQUEST['password']))  
    38   { 
    39     $errmsg=''; 
    40     $username = $db->EscapeString($_REQUEST['username']); 
    41     //print_r($AUTH_SOURCE_ARRAY); 
    42     $user=$AUTH_SOURCE_ARRAY[0]['authenticator']->login($_REQUEST['username'], $_REQUEST['password'],$errmsg); 
    43     if ($user != null) 
    44       {  
    45         if (isset($_REQUEST['gw_address']) && isset($_REQUEST['gw_port']))  
    46           { 
    47             $token = $user->generateConnectionToken(); 
    48             header("Location: http://" . $_REQUEST['gw_address'] . ":" . $_REQUEST['gw_port'] . "/wifidog/auth?token=$token"); 
    49           }  
    50         else 
    51           { 
    52             /* Virtual login */ 
    53             header("Location: ".BASE_NON_SSL_PATH); 
    54           } 
     38if (!empty ($_REQUEST['username']) && !empty ($_REQUEST['password']) && !empty ($_REQUEST['auth_source'])) { 
     39        $errmsg = ''; 
     40        $username = $db->EscapeString($_REQUEST['username']); 
     41        $auth_source = $db->EscapeString($_REQUEST['auth_source']); 
     42 
     43        // Authenticating the user through the sselected auth source. 
     44        $user = $AUTH_SOURCE_ARRAY[$auth_source]['authenticator']->login($_REQUEST['username'], $_REQUEST['password'], $errmsg); 
     45 
     46        if ($user != null) { 
     47                if (isset ($_REQUEST['gw_address']) && isset ($_REQUEST['gw_port']) && ($token = $user->generateConnectionToken())) { 
     48                        header("Location: http://".$_REQUEST['gw_address'].":".$_REQUEST['gw_port']."/wifidog/auth?token=$token"); 
     49                } else { 
     50                        /* Virtual login */ 
     51                        header("Location: ".BASE_NON_SSL_PATH); 
     52                } 
     53                exit; 
     54        } else { 
     55                $smarty->assign("error", $errmsg); 
     56        } 
     57} else { 
     58 
     59        $smarty->assign("error", _('Your must specify your username and password')); 
     60} 
     61 
     62// Add the auth servers list to smarty variables 
     63isset ($AUTH_SOURCE_ARRAY) && $smarty->assign('auth_sources', $AUTH_SOURCE_ARRAY); 
     64 
     65if (isset ($_REQUEST['gw_id'])) { 
     66        $smarty->assign("gw_id", $_REQUEST['gw_id']); 
     67 
     68        try { 
     69                $node = Node :: getNode($db->EscapeString(CURRENT_NODE_ID)); 
     70                $smarty->assign('hotspot_name', $node->getName()); 
     71        } catch (Exception $e) { 
     72                $smarty->assign("error", $e->getMessage()); 
     73                $smarty->display("templates/generic_error.html"); 
     74                exit; 
     75        } 
     76} else { 
     77        /* Gateway ID is not set... Virtual login */ 
     78        $smarty->display("templates/login_virtual.html"); 
    5579        exit; 
    56       } 
    57     else 
    58       { 
    59      $smarty->assign("error", $errmsg); 
    60       } 
    61   }  
    62  else  
    63    { 
    64       
    65      $smarty->assign("error",  _('Your must specify your username and password')); 
    66    } 
     80} 
    6781 
    68 if (isset($_REQUEST['gw_id'])) { 
    69   $smarty->assign("gw_id", $_REQUEST['gw_id']); 
     82isset ($_REQUEST["username"]) && $smarty->assign('username', $_REQUEST["username"]); 
     83isset ($_REQUEST["gw_address"]) && $smarty->assign('gw_address', $_REQUEST['gw_address']); 
     84isset ($_REQUEST["gw_port"]) && $smarty->assign('gw_port', $_REQUEST['gw_port']); 
     85isset ($_REQUEST["gw_id"]) && $smarty->assign('gw_id', $_REQUEST['gw_id']); 
    7086 
    71   try { 
    72     $node = Node::getNode($db->EscapeString(CURRENT_NODE_ID)); 
    73     $smarty->assign('hotspot_name', $node->getName()); 
    74   } catch (Exception $e) { 
    75     $smarty->assign("error", $e->getMessage()); 
    76     $smarty->display("templates/generic_error.html"); 
    77     exit; 
    78   } 
    79  } else { 
    80   /* Gateway ID is not set... Virtual login */ 
    81   $smarty->display("templates/login_virtual.html"); 
    82   exit; 
    83  } 
    84  
    85 isset($_REQUEST["username"]) && $smarty->assign('username', $_REQUEST["username"]); 
    86 isset($_REQUEST["gw_address"]) && $smarty->assign('gw_address', $_REQUEST['gw_address']); 
    87 isset($_REQUEST["gw_port"]) && $smarty->assign('gw_port', $_REQUEST['gw_port']); 
    88 isset($_REQUEST["gw_id"]) && $smarty->assign('gw_id', $_REQUEST['gw_id']); 
    89  
    90 isset($_REQUEST["gw_address"]) && $session->set(SESS_GW_ADDRESS_VAR, $_REQUEST['gw_address']); 
    91 isset($_REQUEST["gw_port"]) && $session->set(SESS_GW_PORT_VAR, $_REQUEST['gw_port']); 
    92 isset($_REQUEST["gw_id"]) && $session->set(SESS_GW_ID_VAR, $_REQUEST['gw_id']); 
     87isset ($_REQUEST["gw_address"]) && $session->set(SESS_GW_ADDRESS_VAR, $_REQUEST['gw_address']); 
     88isset ($_REQUEST["gw_port"]) && $session->set(SESS_GW_PORT_VAR, $_REQUEST['gw_port']); 
     89isset ($_REQUEST["gw_id"]) && $session->set(SESS_GW_ID_VAR, $_REQUEST['gw_id']); 
    9390 
    9491$smarty->display("templates/".LOGIN_PAGE_NAME); 
    9592?> 
     93 
  • trunk/wifidog-auth/wifidog/resend_validation.php

    r402 r516  
    3434    } else { 
    3535        try { 
    36             $user = User::getUserById($_REQUEST['username']); 
     36                // Get a local user 
     37            $user = User::getUserByUsernameAndOrigin($_REQUEST['username'], LOCAL_USER_ACCOUNT_ORIGIN); 
    3738            $user->sendValidationEmail(); 
    3839            $smarty->assign('message', _("An email with confirmation instructions was sent to your email address.")); 
  • trunk/wifidog-auth/wifidog/signup.php

    r501 r516  
    8686            throw new Exception(_("Sorry, a user account is already associated to this email address.")); 
    8787 
    88         $user = User::CreateUser($username, $email, $password); 
     88        $user = User::CreateUser(get_guid(), $username, LOCAL_USER_ACCOUNT_ORIGIN, $email, $password); 
    8989        $user->sendValidationEmail(); 
    9090        $smarty->assign('message', _('An email with confirmation instructions was sent to your email address.  Your account has been granted 15 minutes of access to retrieve your email and validate your account.  You may now open a browser window and go to any remote Internet address to obtain the login page.')); 
  • trunk/wifidog-auth/wifidog/templates/login.html

    r415 r516  
    1111            <input type="hidden" name="gw_id" value="{$gw_id}"> 
    1212        <table> 
     13        {if count($auth_sources) > 1} 
     14        <tr> 
     15                <td>{"Network"|_}:</td> 
     16                <td> 
     17                        <select name="auth_source"> 
     18                        {foreach key=key item=source from=$auth_sources} 
     19                                <option label="{$source.name}" value="{$key}">{$source.name}</option> 
     20                                {/foreach} 
     21                                </select> 
     22                </td> 
     23        </tr> 
     24        {/if} 
    1325        <tr> 
    1426            <td>{"Username (or email)"|_}:</td> 
  • trunk/wifidog-auth/wifidog/templates/login_virtual.html

    r404 r516  
    11{include file="templates/header_small.html"} 
    22    <div id="form"> 
    3  
    43        <h3>{"Welcome!"|_}</h3> 
    54 
     
    109        <form name="login_form" method="post"> 
    1110        <table> 
     11        {if count($auth_sources) > 1} 
     12        <tr> 
     13                <td>{"Network"|_}:</td> 
     14                <td> 
     15                        <select name="auth_source"> 
     16                        {foreach key=key item=source from=$auth_sources} 
     17                                <option label="{$source.name}" value="{$key}">{$source.name}</option> 
     18                                {/foreach} 
     19                                </select> 
     20                </td> 
     21        </tr> 
     22        {/if} 
    1223        <tr> 
    1324            <td>{"Username (or email)"|_}:</td> 
  • trunk/wifidog-auth/wifidog/templates/portal_users.html

    r498 r516  
    5555<p class="indent"> 
    5656{section name=i loop=$online_users} 
    57     <li><a class="underlinepointer" onMouseOver="showuserdiv('{$online_users[i].user_id}')" onMouseOut="hideuserdiv('{$online_users[i].user_id}')">{$online_users[i].user_id}</a> 
     57    <li><a class="underlinepointer" onMouseOver="showuserdiv('{$online_users[i].username}')" onMouseOut="hideuserdiv('{$online_users[i].username}')">{$online_users[i].username}</a> 
    5858    <div id="user_{$online_users[i].user_id}" style="display: none;"> 
    5959        <div id="user_profile"> 
     
    6666            <tr> 
    6767            <td class="item">{"Username"|_}:</th> 
    68             <td>{$online_users[i].user_id}</td> 
     68            <td>{$online_users[i].username}</td> 
    6969            </tr> 
    7070        </table> 
  • trunk/wifidog-auth/wifidog/validate.php

    r402 r516  
    3434        throw new Exception(_('No username specified!')); 
    3535 
    36     $user = User::getUserById($_REQUEST['username']); 
     36    $user = User::getUserByUsernameAndOrigin($_REQUEST['username'], LOCAL_USER_ACCOUNT_ORIGIN); 
    3737 
    3838    if ($db->EscapeString($_REQUEST['token']) != $user->getValidationToken())