Changeset 946

Show
Ignore:
Timestamp:
02/14/06 14:31:10 (7 years ago)
Author:
max-horvath
Message:

"2006-02-14 Max Horvath <max.horvath@…>

  • converted Session class to PHP5 style
  • moved code used used to init PHP into wifidog/include/init_php.php
  • fixed bug regarding APC (super globals weren't initialized before their first use
  • in an attemp to enter the administration interface of WiFiDog and not being logged in you'll be redirected to the administration interface after a successful login, if you are an admin or owner of a node. This only works for a virtual login, as it isn't needed to be done when logging in via a WiFiDog node (then you have to login anyway on the splash page first)
  • fixed preview of network in administration interface as content for a network as is isn't available in the code, yet"
Location:
trunk/wifidog-auth
Files:
8 added
7 removed
10 modified

Legend:

Unmodified
Added
Removed
  • trunk/wifidog-auth/CHANGELOG

    r945 r946  
     12006-02-14 Max Horváth <max.horvath@maxspot.de> 
     2        * converted Session class to PHP5 style 
     3        * moved code used used to init PHP into wifidog/include/init_php.php 
     4        * fixed bug regarding APC (super globals weren't initialized before their 
     5          first use 
     6        * in an attemp to enter the administration interface of WiFiDog and not 
     7          being logged in you'll be redirected to the administration interface after 
     8          a successful login, if you are an admin or owner of a node. This only works 
     9          for a virtual login, as it isn't needed to be done when logging in via a 
     10          WiFiDog node (then you have to login anyway on the splash page first) 
     11        * fixed preview of network in administration interface as content for a 
     12          network as is isn't available in the code, yet 
     13 
    1142006-02-13 Rob Janes <janes.rob@gmail.com> 
    215    * cron/cleanup.php needed new way to call common.php 
     
    417 
    5182006-02-07 Benoit Grégoire  <bock@step.polymtl.ca> 
    6         * Fix a bunch of file inclusion bugs in the statistics subsystem.   
    7         This is only a ad-hac fix.  It seems the requires for just about every class have been stripped off. 
    8         This must be fixed, all classes should require_once all classes or include that they need that isn't  
    9         included by a parent class. 
    10          
     19        * Fix a bunch of file inclusion bugs in the statistics subsystem. 
     20          This is only a ad-hac fix. It seems the requires for just about every class 
     21          have been stripped off. This must be fixed, all classes should require_once 
     22          all classes or include that they need that isn't included by a parent class. 
     23 
    11242006-02-06 Benoit Grégoire  <bock@step.polymtl.ca> 
    1225        * wifidog/local_content/default/hotspot_logo.jpg: Delete deprecated file 
     
    3952        * updated installation file to represent all the new modules that can be 
    4053          installed to use all WiFiDog features 
    41          
     54 
    42552006-01-31 Benoit Grégoire  <bock@step.polymtl.ca> 
    4356        * path_defines_base.php:  Fix syntax errors in the exception thrown.  Add more meaningfull output 
  • trunk/wifidog-auth/wifidog/admin/generic_object_admin.php

    r914 r946  
    6262require_once('classes/GenericObject.php'); 
    6363require_once('classes/MainUI.php'); 
     64require_once('classes/Network.php'); 
    6465 
    6566if (!empty ($_REQUEST['debug'])) { 
     
    179180    $html .= Node :: getSelectNodeUI($name); 
    180181 
    181     $html .= $object->getUserUI(); 
     182    if (method_exists($object, "getUserUI")) { 
     183        $html .= $object->getUserUI(); 
     184    } 
     185 
    182186    $html .= "<input type='hidden' name='action' value='preview'>\n"; 
    183187    $html .= "<input type='submit' name='preview_submit' value='"._("Preview")." ".get_class($object)."'>\n"; 
  • trunk/wifidog-auth/wifidog/admin/index.php

    r914 r946  
    5050require_once('classes/MainUI.php'); 
    5151 
    52 $ui=new MainUI(); 
     52// Init values 
    5353$html = ''; 
    54 $current_user = User :: getCurrentUser(); 
    55 if(!$current_user) 
    56 { 
     54 
     55// Load MainUI class 
     56$ui = new MainUI(); 
     57 
     58// Get information about curent user 
     59$current_user = User::getCurrentUser(); 
     60 
     61if(!$current_user) { 
    5762    // Redirect to login form automatically 
    58     header("Location: ../login/"); 
     63    header("Location: ../login/?origin=admin"); 
    5964    exit; 
    60 } 
    61 else 
    62 { 
     65} else { 
    6366    $ui->setToolSection('ADMIN'); 
    6467} 
  • trunk/wifidog-auth/wifidog/classes/Session.php

    r915 r946  
    4949 * @copyright  2004-2006 Benoit Gregoire, Technologies Coeus inc. 
    5050 */ 
    51 class Session{ 
     51class Session 
     52{ 
    5253 
    53   function Session() { 
    54     $session_id = session_id(); 
    55     if(empty($session_id)) { 
    56     session_start(); 
    57       } 
    58   } 
     54    /** 
     55     * Constructor 
     56     * 
     57     * @return void 
     58     * 
     59     * @access public 
     60     */ 
     61    public function __construct() 
     62    { 
     63        $session_id = session_id(); 
    5964 
    60   /** 
    61    * Sets a session variable 
    62    * @param string name of variable 
    63    * @param mixed value of variable 
    64    * @return void 
    65    */ 
    66   function set($name,$value) { 
    67     $_SESSION[$name] = $value; 
    68   } 
     65        if (empty($session_id)) { 
     66            session_start(); 
     67        } 
     68    } 
    6969 
    70   /** 
    71    * Fetches a session variable 
    72    * @param string name of variable 
    73    * @return mixed value of session varaible 
    74    */ 
    75   function get($name) { 
    76     if (isset($_SESSION[$name])) { 
    77     return $_SESSION[$name]; 
    78     } else { 
    79     return false; 
     70    /** 
     71     * Sets a session variable 
     72     * 
     73     * @param string $name Name of variable 
     74     * @param mixed $value value of variable 
     75     * 
     76     * @return void 
     77     * 
     78     * @access public 
     79     */ 
     80    public function set($name, $value) 
     81    { 
     82        $_SESSION[$name] = $value; 
    8083    } 
    81   } 
    8284 
    83   /** 
    84    * Deletes a session variable 
    85    * @param string name of variable 
    86    * @return boolean 
    87    */ 
    88   function remove($name) { 
    89     if (isset($_SESSION[$name])) { 
    90     unset($_SESSION[$name]); 
    91     return true; 
    92     } else { 
    93     return false; 
     85    /** 
     86     * Fetches a session variable 
     87     * 
     88     * @param string $name Name of variable 
     89     * 
     90     * @return mixed Value of session varaible or false if unable to get value 
     91     * 
     92     * @access public 
     93     */ 
     94    public function get($name) 
     95    { 
     96        if (isset($_SESSION[$name])) { 
     97            return $_SESSION[$name]; 
     98        } else { 
     99            return false; 
     100        } 
    94101    } 
    95   } 
    96102 
    97   /** 
    98    * Delete the whole session 
    99    * @return void 
    100    */ 
    101   function destroy() { 
    102     $_SESSION = array(); 
    103     session_destroy(); 
    104   } 
     103    /** 
     104     * Deletes a session variable 
     105     * 
     106     * @param string $name Name of variable 
     107     * 
     108     * @return bool True if successful 
     109     * 
     110     * @access public 
     111     */ 
     112    public function remove($name) 
     113    { 
     114        if (isset($_SESSION[$name])) { 
     115            unset($_SESSION[$name]); 
    105116 
    106   /** 
    107    * Delete the whole session 
    108    * @return void 
    109    */ 
    110   function dump() { 
    111     echo "<pre>"; 
    112     print_r($_SESSION); 
    113     echo "</pre>\n"; 
    114   } 
     117            return true; 
     118        } else { 
     119            return false; 
     120        } 
     121    } 
     122 
     123    /** 
     124     * Delete the whole session 
     125     * 
     126     * @return void 
     127     * 
     128     * @access public 
     129     */ 
     130    public function destroy() 
     131    { 
     132        $_SESSION = array(); 
     133        session_destroy(); 
     134    } 
     135 
     136    /** 
     137     * Reinitializes the whole session 
     138     * 
     139     * @return void 
     140     * 
     141     * @access public 
     142     */ 
     143    public function restart() 
     144    { 
     145        $_SESSION = array(); 
     146        session_unset(); 
     147        session_destroy(); 
     148 
     149        session_start(); 
     150    } 
     151 
     152    /** 
     153     * Dump the whole session 
     154     * 
     155     * @param bool $print If true session will be printed 
     156     * 
     157     * @return mixed If $print is false the session data will be returned 
     158     * 
     159     * @access public 
     160     */ 
     161    public function dump($print = true) 
     162    { 
     163        if ($print) { 
     164            echo "<pre>" . print_r($_SESSION, true) . "</pre>"; 
     165        } else { 
     166            return $_SESSION; 
     167        } 
     168    } 
     169 
    115170} 
    116171 
  • trunk/wifidog-auth/wifidog/cron/vacuum.php

    r945 r946  
    3636/** 
    3737 * @package    WiFiDogAuthServer 
    38  * @author     Benoit Gregoire <bock@step.polymtl.ca> 
    39  * @copyright  2005-2006 Benoit Gregoire, Technologies Coeus inc. 
     38 * @author     Rob Janes <janes.rob@gmail.com> 
     39 * @copyright  2006 Rob Janes 
    4040 * @version    Subversion $Id: cleanup.php 916 2006-01-23 05:28:15Z max-horvath $ 
    4141 * @link       http://www.wifidog.org/ 
     
    4747require_once(dirname(__FILE__) . '/../include/common.php'); 
    4848 
     49// Define globals 
    4950global $db; 
    5051 
    51 // $db->execSqlUpdate("VACUUM ANALYZE;", false); 
    52 $db->execSqlUpdate("VACUUM ANALYZE;", true); // verbose 
     52// Run vacuum 
     53$db->execSqlUpdate("VACUUM ANALYZE;", true); 
    5354 
    5455/* 
  • trunk/wifidog-auth/wifidog/include/common.php

    r927 r946  
    11<?php 
    2  
    32 
    43/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ 
     
    4443 
    4544/** 
    46  * Disable APC cache (in case it has been installed) 
    47  */ 
    48 if (function_exists("apc_clear_cache")) { 
    49     ini_set("apc.enabled", 0); 
    50 } 
    51  
    52 /** 
    53  * Disable eAccelerator cache (in case it has been installed) 
    54  */ 
    55 if (function_exists("eaccelerator_rm")) { 
    56     ini_set("eaccelerator.enable", 0); 
    57 } 
     45 * Include PHP initialization file file 
     46 */ 
     47require_once('init_php.php'); 
    5848 
    5949/** 
     
    6353 
    6454/** 
     55 * Filter super globals 
     56 */ 
     57undo_magic_quotes(); 
     58 
     59/** 
     60 * Set default timezone 
     61 */ 
     62dateFix(); 
     63 
     64/** 
    6565 * Include path detection code 
    6666 */ 
    67 require_once ('path_defines_base.php'); 
    68  
    69 require_once ('path_defines_url_content.php'); 
    70  
    71  
    72 undo_magic_quotes(); 
    73  
    74 require_once ('classes/EventLogging.php'); 
    75 require_once ('classes/AbstractDb.php'); 
    76 require_once ('classes/Locale.php');//Must be included for gettext handling 
    77 require_once ('classes/Dependencies.php'); 
    78 // require_once('classes/Session.php'); 
     67require_once('path_defines_base.php'); 
     68require_once('path_defines_url_content.php'); 
     69 
     70/** 
     71 * Load required classes 
     72 */ 
     73require_once('classes/EventLogging.php'); 
     74require_once('classes/AbstractDb.php'); 
     75require_once('classes/Locale.php'); 
     76require_once('classes/Dependencies.php'); 
    7977 
    8078global $db; 
    8179 
    82 // $db = AbstractDb::Connect('DEFAULT'); 
    8380$db = new AbstractDb(); 
    8481 
     
    126123/* End session constants */ 
    127124 
    128  
    129 function stripslashes_cb(&$item, $key) 
    130 { 
    131    $item = stripslashes($item); 
    132 } 
    133  
    134 function undo_magic_quotes() { 
    135     if (get_magic_quotes_gpc()) { 
    136         array_walk_recursive($_GET, 'stripslashes_cb'); 
    137         array_walk_recursive($_POST, 'stripslashes_cb'); 
    138         array_walk_recursive($_COOKIE, 'stripslashes_cb'); 
    139         array_walk_recursive($_REQUEST, 'stripslashes_cb'); 
    140     } 
    141 } 
    142  
    143125/** Convert a password hash form a NoCat passwd file into the same format as get_password_hash(). 
    144126* @return The 32 character hash. 
     
    149131 
    150132function iso8601_date($unix_timestamp) { 
    151     /** 
    152      * Set timezone if PHP version >= 5.1.0 
    153      */ 
    154     if (str_replace(".", "", phpversion()) >= 510) { 
    155         date_default_timezone_set(defined(DATE_TIMEZONE) ? DATE_TIMEZONE : "Canada/Eastern"); 
    156     } 
    157  
    158133    $tzd = date('O', $unix_timestamp); 
    159134    $tzd = substr(chunk_split($tzd, 3, ':'), 0, 6); 
     
    332307 * End: 
    333308 */ 
     309 
    334310?> 
  • trunk/wifidog-auth/wifidog/include/common_interface.php

    r927 r946  
    5151 
    5252/** 
    53  * Disable APC cache (in case it has been installed) 
     53 * Include PHP initialization file file 
    5454 */ 
    55 if (function_exists("apc_clear_cache")) { 
    56     ini_set("apc.enabled", 0); 
    57 } 
    58  
    59 /** 
    60  * Disable eAccelerator cache (in case it has been installed) 
    61  */ 
    62 if (function_exists("eaccelerator_rm")) { 
    63     ini_set("eaccelerator.enable", 0); 
    64 } 
     55require_once('init_php.php'); 
    6556 
    6657/** 
  • trunk/wifidog-auth/wifidog/login/index.php

    r933 r946  
    5858require_once('classes/Network.php'); 
    5959 
    60 /* Start general request parameter processing section */ 
     60// Init values 
    6161$node = null; 
    62 if (!empty ($_REQUEST['gw_id'])) 
    63 { 
     62$continueToAdmin = false; 
     63 
     64/* 
     65 * Start general request parameter processing section 
     66 */ 
     67if (!empty ($_REQUEST['gw_id'])) { 
    6468    $gw_id = $_REQUEST['gw_id']; 
    6569 
    66     try 
    67     { 
    68         $node = Node :: getObject($_REQUEST['gw_id']); 
     70    try { 
     71        $node = Node::getObject($_REQUEST['gw_id']); 
    6972        $hotspot_name = $node->getName(); 
    7073        $network = $node->getNetwork(); 
    7174    } 
    72     catch (Exception $e) 
    73     { 
     75 
     76    catch (Exception $e) { 
    7477        $smarty->assign("error", $e->getMessage()); 
    7578        $smarty->assign("tech_support_email", Network::getCurrentNetwork()->getTechSupportEmail()); 
     
    7780        exit; 
    7881    } 
    79 } 
    80 else 
    81 { 
    82     /* Gateway ID is not set... Virtual login */ 
    83     $network = Network :: getCurrentNetwork(); 
     82} else { 
     83    // Gateway ID is not set ... virtual login 
     84    $network = Network::getCurrentNetwork(); 
    8485} 
    8586 
     
    9394isset ($_REQUEST["gw_id"]) && $session->set(SESS_GW_ID_VAR, $_REQUEST['gw_id']); 
    9495 
    95 // Store original URL typed by user. 
    96 //TODO: manage this... 
    97 if (!empty ($_REQUEST['url'])) 
    98 { 
     96/* 
     97 * General request parameter processing section 
     98 */ 
     99 
     100/** 
     101 * Store original URL typed by user 
     102 * 
     103 * @todo Manage storing of original URL typed by user 
     104 */ 
     105if (!empty($_REQUEST['url'])) { 
    99106    $session->set(SESS_ORIGINAL_URL_VAR, $_REQUEST['url']); 
    100107} 
    101 /* End general request parameter processing section */ 
    102  
    103 /* Start login process section. 
    104  * If  successfull, the browser is redirected to another page */ 
    105  
    106 /*  If this is a splash-only node, skip the login interface and log-in using the splash_only user */ 
    107 if ($node && $node->isSplashOnly()) 
    108 { 
     108 
     109// Check if user wanted to enter the administration interface 
     110if (!empty($_REQUEST['origin']) && $_REQUEST['origin'] = "admin") { 
     111    $continueToAdmin = true; 
     112} 
     113 
     114/* 
     115 * Start login process section. 
     116 * 
     117 * If  successfull, the browser is redirected to another page 
     118 */ 
     119 
     120/* 
     121 * If this is a splash-only node, skip the login interface and log-in using 
     122 * the splash_only user 
     123 */ 
     124if ($node && $node->isSplashOnly()) { 
    109125    $user = $network->getSplashOnlyUser(); 
    110126    $token = $user->generateConnectionToken(); 
    111     User :: setCurrentUser($user); 
    112     header("Location: http://".$_REQUEST['gw_address'].":".$_REQUEST['gw_port']."/wifidog/auth?token=$token"); 
    113 } 
    114  
    115 /* Normal login process */ 
    116 if (!empty ($_REQUEST['username']) && !empty ($_REQUEST['password']) && !empty ($_REQUEST['auth_source'])) 
    117 { 
     127    User::setCurrentUser($user); 
     128 
     129    header("Location: http://" . $_REQUEST['gw_address'] . ":" . $_REQUEST['gw_port'] . "/wifidog/auth?token=" . $token); 
     130} 
     131 
     132/* 
     133 * Normal login process 
     134 */ 
     135if (!empty ($_REQUEST['username']) && !empty ($_REQUEST['password']) && !empty ($_REQUEST['auth_source'])) { 
     136    // Init values 
    118137    $errmsg = ''; 
     138 
    119139    $username = $db->escapeString($_REQUEST['username']); 
    120140 
    121141    // Authenticating the user through the selected auth source. 
    122     $network = Network :: processSelectNetworkUI('auth_source'); 
     142    $network = Network::processSelectNetworkUI('auth_source'); 
    123143 
    124144    $user = $network->getAuthenticator()->login($_REQUEST['username'], $_REQUEST['password'], $errmsg); 
    125     if ($user != null) 
    126     { 
    127         if (isset ($_REQUEST['gw_address']) && isset ($_REQUEST['gw_port'])) 
    128         { 
    129             /* Login from a gateway, redirect to the gateway to activate the token */ 
     145 
     146    if ($user != null) { 
     147        if (isset ($_REQUEST['gw_address']) && isset ($_REQUEST['gw_port'])) { 
     148            // Login from a gateway, redirect to the gateway to activate the token 
    130149            $token = $user->generateConnectionToken(); 
    131             header("Location: http://".$_REQUEST['gw_address'].":".$_REQUEST['gw_port']."/wifidog/auth?token=$token"); 
     150 
     151            header("Location: http://" . $_REQUEST['gw_address'] . ":" . $_REQUEST['gw_port'] . "/wifidog/auth?token=" . $token); 
     152        } else { 
     153            // Virtual login, redirect to the auth server homepage 
     154            header("Location: " . BASE_SSL_PATH . ($continueToAdmin ? "admin/" : "")); 
    132155        } 
    133         else 
    134         { 
    135             /* Virtual login, redirect to the auth server homepage */ 
    136             header("Location: ".BASE_SSL_PATH); 
    137         } 
     156 
    138157        exit; 
    139     } 
    140     else 
    141     { 
     158    } else { 
    142159        $error = $errmsg; 
    143160    } 
    144 } 
    145 else 
    146 { 
    147     //Note that this is executed even when we have just arrived at the login page, so the user is reminded to supply a username and password 
     161} else { 
     162    /* 
     163     * Note that this is executed even when we have just arrived at the login 
     164     * page, so  the user is reminded to supply a username and password 
     165     */ 
    148166    $error = _('Your must specify your username and password'); 
    149167} 
    150 /* End login process section.*/ 
    151  
    152 /* Start logout process section. 
    153  * Once logged out, we display the login page */ 
    154 if ((!empty ($_REQUEST['logout']) && $_REQUEST['logout'] == true) && ($user = User :: getCurrentUser()) != null) 
    155 { 
     168 
     169/* 
     170 * Start logout process section 
     171 * 
     172 * Once logged out, we display the login page 
     173 */ 
     174if ((!empty ($_REQUEST['logout']) && $_REQUEST['logout'] == true) && ($user = User::getCurrentUser()) != null) { 
    156175    $network->getAuthenticator()->logout(); 
    157176} 
    158 /* End logout process section. */ 
    159  
    160 /* Start login interface section */ 
     177 
     178/* 
     179 * Start login interface section 
     180 */ 
    161181$html = ''; 
    162182$html .= '<div id="login_form">'."\n"; 
  • trunk/wifidog-auth/wifidog/portal/index.php

    r930 r946  
    5454require_once('classes/Node.php'); 
    5555require_once('classes/MainUI.php'); 
     56require_once('classes/Session.php'); 
    5657 
    5758/** 
    5859 * Define width of toolbar 
    59  */ 
    60 define('TOOLBAR_WIDTH','250'); //Must match the stylesheet for the tool section width 
    61  
     60 * 
     61 * Must match the stylesheet for the tool section width 
     62 */ 
     63define('TOOLBAR_WIDTH', '250'); 
     64 
     65// Init values 
    6266$node = null; 
    63 if (!empty ($_REQUEST['gw_id'])) 
     67 
     68// Init session 
     69$session = new Session(); 
     70 
     71// Get the current user 
     72$current_user = User::getCurrentUser(); 
     73 
     74if (!empty ($_REQUEST['gw_id'])) { 
    6475    $node = Node :: getObject($_REQUEST['gw_id']); 
    65  
    66 if ($node == null) 
    67 { 
     76} 
     77 
     78if ($node == null) { 
    6879    $smarty->display("templates/message_unknown_hotspot.html"); 
    6980    exit; 
    7081} 
     82 
     83// Get information about current network 
    7184$network = $node->getNetwork(); 
    7285 
    73 /*  If this node has a custom portal defined, and the network config allows it, redirect to the custom portal */ 
     86/* 
     87 * If this node has a custom portal defined, and the network config allows it, 
     88 * redirect to the custom portal 
     89 */ 
    7490$custom_portal_url = $node->getCustomPortalRedirectUrl(); 
    75 if(!empty($custom_portal_url) && $network->getCustomPortalRedirectAllowed()) 
    76 { 
     91if (!empty($custom_portal_url) && $network->getCustomPortalRedirectAllowed()) { 
    7792    header("Location: {$custom_portal_url}"); 
    7893} 
    79  
    8094 
    8195$node_id = $node->getId(); 
     
    252266$network_logo_banner_url = COMMON_CONTENT_URL.NETWORK_LOGO_BANNER_NAME; 
    253267 
    254 // Get the current user 
    255 $current_user = User :: getCurrentUser(); 
    256  
    257268$html = ''; 
    258269 
  • trunk/wifidog-auth/wifidog/templates/classes/MainUI_ToolContent.tpl

    r938 r946  
    7676        <div class="language"> 
    7777            <form class="language" name="lang_form" method="post" action="{$formAction}"> 
    78                 {"Language:"|_} 
     78                {"Language"|_}: 
    7979                <select name="wifidog_language" onchange="javascript: document.lang_form.submit();"> 
    8080                    {foreach from=$languageChooser item=currLanguage}