Changeset 1391

Show
Ignore:
Timestamp:
06/09/09 21:16:53 (4 years ago)
Author:
benoitg
Message:

* Commit slightly modified patch contributed by Zap Sherbrooke: Allow using the multiple account feature while keeping a common userbase. Enabled in server configuration.

Location:
trunk/wifidog-auth
Files:
1 added
20 modified

Legend:

Unmodified
Added
Removed
  • trunk/wifidog-auth/CHANGELOG

    r1387 r1391  
    11# $Id$ 
     22009-06-09 Benoit Grégoire <benoitg@coeus.ca> 
     3        * Commit slightly modified patch contributed by Zap Sherbrooke:  Allow using the multiple account feature while keeping a common userbase.  Enabled in server configuration. 
     4 
     5 
    262008-10-13 Robin Jones 
    37        * fixed #498 curley brace missing in portal.php 
  • trunk/wifidog-auth/wifidog/classes/Authenticator.php

    r1351 r1391  
    143143        $smarty=SmartyWiFiDog::getObject(); 
    144144        // Set network selector 
    145         $smarty->assign('selectNetworkUI', Network::getSelectUI('auth_source', $networkUserData)); 
     145        $network_array = Network::getAllNetworks(); 
     146        $default_network = Network::getDefaultNetwork(); 
     147  
     148        foreach ($network_array as $network) { 
     149                if ($network->getName() == $default_network) 
     150                        $default_network_param = $network->getId(); 
     151        } 
     152        if (Server::getServer()->getUseGlobalUserAccounts()) 
     153                $smarty->assign('selectNetworkUI', "<input type=\"hidden\" name=\"auth_source\" value='$default_network_param' />"); 
     154        else 
     155                $smarty->assign('selectNetworkUI', Network::getSelectUI('auth_source', $networkUserData)); 
     156 
    146157        // Set user details 
    147158        $smarty->assign('user_id', $selectedUser ? $selectedUser->getId() : ""); 
  • trunk/wifidog-auth/wifidog/classes/FormSelectGenerator.php

    r1170 r1391  
    193193         * @return string The HTML SELECT element definition string For example: "onclick='submit();' 
    194194         */ 
    195         public static function generateFromArray($array, $selectedPrimaryKey, $userPrefix, $objectPrefix, $allowNullValues, $nullCaptionString = ' - - - ', $additionalSelectAttribute = "", $max_length = -1) 
    196         { 
     195        public static function generateFromArray($array, $selectedPrimaryKey, $userPrefix, $objectPrefix, $allowNullValues, $nullCaptionString = null, $additionalSelectAttribute = "", $max_length = -1) 
     196        { 
     197        $nullCaptionString = $nullCaptionString===null?' - - - ':$nullCaptionString; 
    197198            $retval = ""; 
    198199            $retval .= "<select id='{$userPrefix}{$objectPrefix}' name='{$userPrefix}{$objectPrefix}' {$additionalSelectAttribute}>\n"; 
  • trunk/wifidog-auth/wifidog/classes/MainUI.php

    r1364 r1391  
    229229 
    230230        // Set default title 
    231         $this->title = Network :: getCurrentNetwork()->getName() . ' ' . _("authentication server"); 
     231        if(Server::getServer()->getUseGlobalUserAccounts()) { 
     232            $this->title = _("authentication server"); 
     233        } else { 
     234            $this->title = Network :: getCurrentNetwork()->getName() . ' ' . _("authentication server"); 
     235        } 
    232236        // Init the content array 
    233237        $current_content_sql = "SELECT display_area FROM content_available_display_areas\n"; 
  • trunk/wifidog-auth/wifidog/classes/Network.php

    r1384 r1391  
    236236    public static function getSelectUI($user_prefix, $userData=null) 
    237237    { 
     238        $userData=$userData===null?array():$userData; 
    238239        $html = ''; 
    239240        $name = $user_prefix; 
    240241        //pretty_print_r($userData); 
    241         !empty($userData['preSelectedObject'])?$selected_id=$userData['preSelectedObject']->getId():$selected_id=self::getDefaultNetwork()->getId(); 
     242        array_key_exists('preSelectedObject',$userData)?(empty($userData['preSelectedObject'])?$selected_id=null:$selected_id=$userData['preSelectedObject']->getId()):$selected_id=self::getDefaultNetwork()->getId(); 
    242243        !empty($userData['additionalWhere'])?$additional_where=$userData['additionalWhere']:$additional_where=null; 
    243244        !empty($userData['allowEmpty'])?$allow_empty=$userData['allowEmpty']:$allow_empty=false; 
     245        !empty($userData['nullCaptionString'])?$nullCaptionString=$userData['nullCaptionString']:$nullCaptionString=null; 
     246        !empty($userData['onChange'])?$onChangeString=$userData['onChange']:$onChangeString=""; 
    244247 
    245248        $db = AbstractDb::getObject(); 
     
    260263            } 
    261264            $html .= _("Network:")." \n"; 
    262             $html .= FormSelectGenerator :: generateFromArray($tab, $selected_id, $name, null, $allow_empty); 
     265            $html .= FormSelectGenerator :: generateFromArray($tab, $selected_id, $name, null, $allow_empty, $nullCaptionString, "onchange='$onChangeString'"); 
    263266 
    264267        } else { 
     
    355358        $db = AbstractDb::getObject(); 
    356359        $network_id_str = $db->escapeString($p_network_id); 
     360        if ($network_id_str == "") 
     361            $network_id_str = $db->escapeString(self::getDefaultNetwork()->getId()); 
     362 
    357363        $sql = "SELECT *, EXTRACT(EPOCH FROM validation_grace_time) as validation_grace_time_seconds FROM networks WHERE network_id='$network_id_str'"; 
    358364        $row = null; 
  • trunk/wifidog-auth/wifidog/classes/Node.php

    r1384 r1391  
    629629    } 
    630630 
     631    /** 
     632     * Get the selected network ID 
     633     * 
     634     * @param string $user_prefix An identifier provided by the programmer to 
     635     *                            recognise it's generated form 
     636     * 
     637     * @return string The deployment status 
     638 
     639     */ 
     640    public function processSelectNetworkId($user_prefix) 
     641    { 
     642        $object = null; 
     643        $name = "{$user_prefix}"; 
     644        return $_REQUEST[$name]; 
     645    } 
     646 
    631647    /** @param $id The id of the node 
    632648     * @param $idType 'NODE_ID' or 'GATEWAY_ID'*/ 
     
    706722    } 
    707723 
     724     
     725    function setNetwork(Network $network) 
     726    { 
     727        $net = $this->mDb->escapeString($network->getId()); 
     728        $this->mDb->execSqlUpdate("UPDATE nodes SET network_id = '{$net}' WHERE node_id = '{$this->getId()}'"); 
     729        $this->refresh(); 
     730    } 
     731     
     732     
    708733    /** Get a GisPoint object ; altide is not supported yet 
    709734     */ 
     
    10201045    } 
    10211046 
    1022    /** redirect users to the original requested web page instead of portal  
    1023       Must be enabled in the Network configuration to have any effect  
    1024       @return a string */  
    1025      function getPortalOriginalUrlAllowed()  
    1026      {  
    1027          return (($this->_row['allow_original_url_redirect'] == 't') ? true : false);  
    1028      }  
    1029    
    1030      /** redirect users to the original requested web page instead of portal  
    1031       Must be enabled in the Network configuration to have any effect  
    1032       @return true on success, false on failure */  
    1033      function setPortalOriginalUrlAllowed($value)  
    1034      {  
    1035          $retval = true;  
    1036          if ($value != $this->getPortalOriginalUrlAllowed())  
    1037          {  
    1038              $db = AbstractDb::getObject();  
    1039              $value ? $value = 'TRUE' : $value = 'FALSE'; 
    1040              $retval = $db->execSqlUpdate("UPDATE nodes SET allow_original_url_redirect = '{$value}' WHERE node_id = '{$this->getId()}'", false);  
    1041              $this->refresh();  
    1042          }  
    1043          return $retval;  
    1044      }  
     1047    /** redirect users to the original requested web page instead of portal 
     1048     Must be enabled in the Network configuration to have any effect 
     1049     @return a string */ 
     1050    function getPortalOriginalUrlAllowed() 
     1051    { 
     1052        return (($this->_row['allow_original_url_redirect'] == 't') ? true : false); 
     1053    } 
     1054 
     1055    /** redirect users to the original requested web page instead of portal 
     1056     Must be enabled in the Network configuration to have any effect 
     1057     @return true on success, false on failure */ 
     1058    function setPortalOriginalUrlAllowed($value) 
     1059    { 
     1060        $retval = true; 
     1061        if ($value != $this->getPortalOriginalUrlAllowed()) 
     1062        { 
     1063            $db = AbstractDb::getObject(); 
     1064            $value ? $value = 'TRUE' : $value = 'FALSE'; 
     1065            $retval = $db->execSqlUpdate("UPDATE nodes SET allow_original_url_redirect = '{$value}' WHERE node_id = '{$this->getId()}'", false); 
     1066            $this->refresh(); 
     1067        } 
     1068        return $retval; 
     1069    } 
    10451070 
    10461071 
     
    10711096        // Get information about the network 
    10721097        $network = $this->getNetwork(); 
    1073          
     1098 
    10741099        $node_id = $this->getId(); 
    10751100 
     
    12511276        $_data = $this->getSelectDeploymentStatus("node_" . $node_id . "_deployment_status"); 
    12521277        $_html_node_config[] = InterfaceElements::generateAdminSectionContainer("node_deployment_status", $_title, $_data); 
     1278 
     1279        // Network selection 
     1280        $_title = _("Node Network"); 
     1281        $_data = Network::getSelectUI("node_" . $node_id . "_network_id", array('preSelectedObject'=>$this->getNetwork())); 
     1282        $_html_node_config[] = InterfaceElements::generateAdminSectionContainer("node_network", $_title, $_data); 
    12531283 
    12541284        //  is_splash_only_node 
     
    14431473        $this->setDeploymentStatus(self :: processSelectDeploymentStatus($name)); 
    14441474 
     1475        // Network selection 
     1476        $name = "node_".$node_id."_network_id"; 
     1477        $new_network=Network :: processSelectUI($name); 
     1478        if($new_network!=$this->getNetwork()) { 
     1479            Security::requirePermission(Permission::P('NETWORK_PERM_ADD_NODE'), $new_network); 
     1480            $this->setNetwork($new_network); 
     1481        } 
     1482 
    14451483        //  is_splash_only_node 
    14461484        if ($network->getSplashOnlyNodesAllowed()) 
     
    16101648    /** 
    16111649     * Find out how many users are online this specific Node 
    1612      * Counts every user account connected (once for every account), except the splash-only user + every mac adresses connecting as the splash-only user 
     1650     * Counts every user account connected (once for every connection) 
    16131651     * @return int Number of online users 
    16141652     * 
     
    16271665        return $row['count']; 
    16281666    } 
     1667 
    16291668 
    16301669    /** The list of all Technical officers of this node. 
  • trunk/wifidog-auth/wifidog/classes/NodeList.php

    r1256 r1391  
    5959 * Directory of NodeList classes 
    6060 */   define ('NODE_LIST_CLASSES_DIR', WIFIDOG_ABS_FILE_PATH . "classes/NodeLists"); 
     61 
     62interface AcceptsNullNetwork { } 
    6163abstract class NodeList { 
    6264 
     
    8587        $nodeList->setHeader(); 
    8688        return $nodeList; 
     89    } 
     90 
     91    /** 
     92     * Indicates if the specified type of node list accepts null as the network 
     93     * argument in the constructor 
     94     * 
     95     * @param string $nodeListType Type of node list 
     96     * 
     97     * @return bool 
     98     */ 
     99    public static function getAllowsNullNetwork($nodeListType) 
     100    { 
     101        // Check if node list type exists 
     102        if (in_array($nodeListType, self::getAvailableNodeListTypes())) { 
     103            require_once(NODE_LIST_CLASSES_DIR . "/NodeList" . $nodeListType . ".php"); 
     104        } else { 
     105            return false; 
     106        } 
     107 
     108        $nodeListClass = "NodeList" . $nodeListType; 
     109        $ifaces = class_implements($nodeListClass); 
     110        return in_array("AcceptsNullNetwork", $ifaces); 
    87111    } 
    88112 
  • trunk/wifidog-auth/wifidog/classes/NodeLists/NodeListHTML.php

    r1316 r1391  
    6464 * @copyright  2006 Max Horváth, Horvath Web Consulting 
    6565 */ 
    66 class NodeListHTML extends NodeList{ 
     66class NodeListHTML extends NodeList implements AcceptsNullNetwork { 
    6767 
    6868    /** 
     
    122122        // Init network 
    123123        $this->_network = $network; 
    124  
     124         
    125125        // Init user 
    126126        $this->_currentUser = User::getCurrentUser(); 
     
    129129        $this->_mainUI = MainUI::getObject(); 
    130130 
     131        $network_where_sql = $network === null?"":"network_id = '" . $db->escapeString($this->_network->getId()) . "' AND "; 
     132 
    131133        // Query the database, sorting by node name 
    132         $db->execSql("SELECT *, (CURRENT_TIMESTAMP-last_heartbeat_timestamp) AS since_last_heartbeat, EXTRACT(epoch FROM creation_date) as creation_date_epoch, CASE WHEN ((CURRENT_TIMESTAMP-last_heartbeat_timestamp) < interval '5 minutes') THEN true ELSE false END AS is_up FROM nodes WHERE network_id = '" . $db->escapeString($this->_network->getId()) . "' AND (node_deployment_status = 'DEPLOYED' OR node_deployment_status = 'NON_WIFIDOG_NODE') ORDER BY lower(name)", $this->_nodes, false); 
     134        $db->execSql("SELECT *, (CURRENT_TIMESTAMP-last_heartbeat_timestamp) AS since_last_heartbeat, EXTRACT(epoch FROM creation_date) as creation_date_epoch, CASE WHEN ((CURRENT_TIMESTAMP-last_heartbeat_timestamp) < interval '5 minutes') THEN true ELSE false END AS is_up FROM nodes WHERE $network_where_sql (node_deployment_status = 'DEPLOYED' OR node_deployment_status = 'NON_WIFIDOG_NODE') ORDER BY lower(name)", $this->_nodes, false); 
    133135    } 
    134136 
     
    166168        $this->_smarty->assign('num_deployed_nodes', 0); 
    167169        $this->_smarty->assign('PdfSupported', false); 
     170 
     171        $userData['preSelectedObject'] = $this->_network; 
     172        $userData['allowEmpty'] = true; 
     173        $userData['nullCaptionString'] = _("All"); 
     174        $userData['onChange'] = "submit.click();"; 
     175        $this->_smarty->assign('selectNetworkUI', Network::getSelectUI('network_id', $userData) . (count(Network::getAllNetworks()) > 1 ? '<input class="submit" type="submit" name="submit" value="' . _("Change network") . '">' : "")); 
     176        $this->_smarty->assign('selectedNetworkName', $this->_network === null?_("All networks"):$this->_network->getName()); 
     177 
    168178 
    169179        /** 
     
    209219         */ 
    210220        $this->_mainUI->setTitle(_("Hotspot list")); 
    211         $this->_mainUI->appendHtmlHeadContent('<link rel="alternate" type="application/rss+xml" title="' . $this->_network->getName() . ": " . _("Newest Hotspots") . '" href="' . BASE_SSL_PATH . 'hotspot_status.php?format=RSS">'); 
     221        $this->_mainUI->appendHtmlHeadContent('<link rel="alternate" type="application/rss+xml" title="' . ($this->_network === null?_("All networks"):$this->_network->getName()) . ": " . _("Newest Hotspots") . '" href="' . BASE_SSL_PATH . 'hotspot_status.php?format=RSS">'); 
    212222        $this->_mainUI->addContent('left_area_middle', $_html); 
    213223        $this->_mainUI->addContent('main_area_middle', $_html_body); 
  • trunk/wifidog-auth/wifidog/classes/Server.php

    r1328 r1391  
    265265        $html .= "</li>\n"; 
    266266 
    267  
    268  
     267        /* 
     268         * Authentication options 
     269         */ 
     270        $title = _("Authentication"); 
     271        $data = InterfaceElements::generateInputCheckbox("use_global_auth","", _("Use the users of default Virtual Host's network across all networks on the server."), $this->getUseGlobalUserAccounts(), "use_global_auth"); 
     272 
     273        $html .= InterfaceElements::generateAdminSectionContainer("server_authentication_options",$title, $data); 
     274         
    269275        /* 
    270276         * Access rights 
     
    275281            $html .= InterfaceElements::generateAdminSectionContainer("access_rights", _("Access rights"), $html_access_rights); 
    276282        } 
    277  
     283         
    278284        $html .= "</ul>\n"; 
    279285        $html .= "</fieldset>\n"; 
     
    290296        require_once('classes/User.php'); 
    291297        Security::requirePermission(Permission::P('SERVER_PERM_EDIT_SERVER_CONFIG'), $this); 
     298        // Authentication 
     299        if (isset($_REQUEST['use_global_auth'])) 
     300                $this->setUseGlobalUserAccounts($_REQUEST['use_global_auth']); 
     301        else 
     302                $this->setUseGlobalUserAccounts(false); 
    292303        // Access rights 
    293304        require_once('classes/Stakeholder.php'); 
     
    317328        { 
    318329            $items[] = array('path' => 'server/admin', 
    319             'title' => _("Server access control"), 
     330            'title' => _("Server configuration"), 
    320331            'url' => BASE_URL_PATH.htmlspecialchars("admin/generic_object_admin.php?object_class=Server&action=edit&object_id=".SERVER_ID."") 
    321332                ); 
     
    338349    } 
    339350 
     351    /** 
     352     * Getter for UseGlobalUserAccounts 
     353     * 
     354     * @return bool 
     355     */ 
     356    public function getUseGlobalUserAccounts() 
     357    { 
     358        if (array_key_exists('use_global_auth',$this->_row)) 
     359                return $this->_row['use_global_auth']=='t'; 
     360        else 
     361                return False; 
     362    }  
     363 
     364    /** 
     365     * Setter for UseGlobalUserAccounts 
     366     * 
     367     * @param bool $value       New value 
     368     * 
     369     * @return bool True on success, false on failure 
     370     */ 
     371    public function setUseGlobalUserAccounts($value) 
     372    { 
     373        $db = AbstractDb::getObject(); 
     374        $value = $value? true:false; 
     375        // Init values 
     376        $retVal = true; 
     377 
     378        if ($value != $this->getUseGlobalUserAccounts()) { 
     379            $value = $value ? 'true' : 'false'; 
     380            $retVal = $db->execSqlUpdate("UPDATE server SET use_global_auth = {$value} WHERE server_id = '{$this->getId()}'", false); 
     381            $this->refresh(); 
     382        } 
     383 
     384        return $retVal; 
     385    }  
     386 
     387    /** 
     388     * Find out how many users are online on the whole server 
     389     * Counts every user account connected (once for every connection) 
     390     * @return int Number of online users 
     391     * 
     392     * @access public 
     393     */ 
     394    public function getTotalNumOnlineUsers() 
     395    { 
     396        $db = AbstractDb::getObject(); 
     397        // Init values 
     398        $retval = array (); 
     399        $row = null; 
     400        $sql = "SELECT COUNT(*) FROM active_connections;"; 
     401        $db->execSqlUniqueRes($sql, $row, false); 
     402 
     403        return $row['count']; 
     404    } 
     405 
     406    /** 
     407     * Find out how many users are valid in this server's database 
     408     * 
     409     * @return int Number of valid users 
     410     */ 
     411    public function getTotalNumValidUsers() 
     412    { 
     413 
     414        $db = AbstractDb::getObject(); 
     415 
     416        // Init values 
     417        $retval = 0; 
     418        $row = null; 
     419        $useCache = false; 
     420        $cachedData = null; 
     421 
     422        // Create new cache objects (valid for 1 minute) 
     423        $cache = new Cache('server_num_valid_users', "default", 60); 
     424 
     425        // Check if caching has been enabled. 
     426        if ($cache->isCachingEnabled) { 
     427            $cachedData = $cache->getCachedData(); 
     428 
     429            if ($cachedData) { 
     430                // Return cached data. 
     431                $useCache = true; 
     432                $retval = $cachedData; 
     433            } 
     434        } 
     435 
     436        if (!$useCache) { 
     437            // Get number of valid users 
     438            $network_id = $db->escapeString($this->_id); 
     439            $db->execSqlUniqueRes("SELECT COUNT(user_id) FROM users WHERE account_status = ".ACCOUNT_STATUS_ALLOWED, $row, false); 
     440            // String has been found 
     441            $retval = $row['count']; 
     442 
     443            // Check if caching has been enabled. 
     444            if ($cache->isCachingEnabled) { 
     445                // Save data into cache, because it wasn't saved into cache before. 
     446                $cache->saveCachedData($retval); 
     447            } 
     448        } 
     449 
     450        return $retval; 
     451    } 
     452 
     453    /** 
     454     * Find out how many nodes are deployed in this server's database 
     455     * 
     456     * @return int Number of deployed nodes 
     457     */ 
     458    public function getTotalNumDeployedNodes() 
     459    { 
     460 
     461        $db = AbstractDb::getObject(); 
     462 
     463        // Init values 
     464        $retval = 0; 
     465        $row = null; 
     466        $useCache = false; 
     467        $cachedData = null; 
     468 
     469        // Create new cache objects (valid for 5 minutes) 
     470        $cache = new Cache('server_num_deployed_nodes', "default", 300); 
     471 
     472        // Check if caching has been enabled. 
     473        if ($cache->isCachingEnabled) { 
     474            $cachedData = $cache->getCachedData(); 
     475 
     476            if ($cachedData) { 
     477                // Return cached data. 
     478                $useCache = true; 
     479                $retval = $cachedData; 
     480            } 
     481        } 
     482 
     483        if (!$useCache) { 
     484            // Get number of deployed nodes 
     485            $network_id = $db->escapeString($this->_id); 
     486            $db->execSqlUniqueRes("SELECT COUNT(node_id) FROM nodes WHERE (node_deployment_status = 'DEPLOYED' OR node_deployment_status = 'NON_WIFIDOG_NODE')", $row, false); 
     487 
     488            // String has been found 
     489            $retval = $row['count']; 
     490 
     491            // Check if caching has been enabled. 
     492            if ($cache->isCachingEnabled) { 
     493                // Save data into cache, because it wasn't saved into cache before. 
     494                $cache->saveCachedData($retval); 
     495            } 
     496        } 
     497 
     498        return $retval; 
     499    } 
     500 
     501    /** 
     502     * Find out how many deployed nodes are online in this server's database 
     503     * 
     504     * @param bool $nonMonitoredOnly Return number of non-monitored nodes only 
     505     * 
     506     * @return int Number of deployed nodes which are online 
     507     */ 
     508    public function getNumOnlineNodes($nonMonitoredOnly = false) 
     509    { 
     510 
     511        $db = AbstractDb::getObject(); 
     512 
     513        // Init values 
     514        $retval = 0; 
     515        $row = null; 
     516        $useCache = false; 
     517        $cachedData = null; 
     518 
     519        // Create new cache objects (valid for 5 minutes) 
     520        if ($nonMonitoredOnly) { 
     521            $cache = new Cache('server_num_online_nodes_non_monitored', "default", 300); 
     522        } else { 
     523            $cache = new Cache('server_num_online_nodes', "default", 300); 
     524        } 
     525 
     526        // Check if caching has been enabled. 
     527        if ($cache->isCachingEnabled) { 
     528            $cachedData = $cache->getCachedData(); 
     529 
     530            if ($cachedData) { 
     531                // Return cached data. 
     532                $useCache = true; 
     533                $retval = $cachedData; 
     534            } 
     535        } 
     536 
     537        if (!$useCache) { 
     538            // Get number of online nodes 
     539            $network_id = $db->escapeString($this->_id); 
     540 
     541            if ($nonMonitoredOnly) { 
     542                $db->execSqlUniqueRes("SELECT COUNT(node_id) FROM nodes WHERE node_deployment_status = 'NON_WIFIDOG_NODE' AND ((CURRENT_TIMESTAMP-last_heartbeat_timestamp) >= interval '5 minutes')", $row, false); 
     543            } else { 
     544                $db->execSqlUniqueRes("SELECT COUNT(node_id) FROM nodes WHERE (node_deployment_status = 'DEPLOYED' OR node_deployment_status = 'NON_WIFIDOG_NODE') AND ((CURRENT_TIMESTAMP-last_heartbeat_timestamp) < interval '5 minutes')", $row, false); 
     545            } 
     546 
     547            // String has been found 
     548            $retval = $row['count']; 
     549 
     550            // Check if caching has been enabled. 
     551            if ($cache->isCachingEnabled) { 
     552                // Save data into cache, because it wasn't saved into cache before. 
     553                $cache->saveCachedData($retval); 
     554            } 
     555        } 
     556 
     557        return $retval; 
     558    } 
    340559} 
    341560 
  • trunk/wifidog-auth/wifidog/hotspot_status.php

    r1338 r1391  
    6464} 
    6565 
    66 if (!empty ($_REQUEST['network_id'])) { 
    67     $network = Network::getObject($db->escapeString($_REQUEST['network_id'])); 
     66if (isset ($_REQUEST["network_id"])) { 
     67        $network_id = $_REQUEST["network_id"]; 
     68    if($network_id == ""){ 
     69        $network = null; 
     70    } else { 
     71        try { 
     72            $network = Network::getObject($network_id); 
     73        } catch (Exception $e) { 
     74            $network = Network::getDefaultNetwork(); 
     75        } 
     76    } 
    6877} else { 
    69     $network = Network::getDefaultNetwork(true); 
     78        $network = Network::getDefaultNetwork(); 
    7079} 
    7180 
    72 if ($network) { 
     81if ($network or NodeList::getAllowsNullNetwork($format)) { 
    7382    // Init node list type 
    7483    $nodeList = NodeList::getObject($format, $network); 
  • trunk/wifidog-auth/wifidog/hotspots_map.php

    r1316 r1391  
    110110// Set network selector 
    111111$preSelectedObject = (!empty($_REQUEST['network_map']) ? Network::getObject($_REQUEST['network_map']) : Network::getCurrentNetwork()); 
    112 $selectNetworkUI = Network::getSelectUI('network_map', array('preSelectedObject' => $preSelectedObject)); 
     112//$selectNetworkUI = Network::getSelectUI('network_map', array('preSelectedObject' => $preSelectedObject, 'onChange' => "javascript: document.lang_form.submit();")); 
     113$selectNetworkUI = Network::getSelectUI('network_map', array('preSelectedObject' => $preSelectedObject, 'onChange' => "submit.click();")); 
    113114$smarty->assign('selectNetworkUI', $selectNetworkUI . (count(Network::getAllNetworks()) > 1 ? '<input class="submit" type="submit" name="submit" value="' . _("Change network") . '">' : "")); 
    114115 
  • trunk/wifidog-auth/wifidog/include/schema_validate.php

    r1384 r1391  
    4848 * Define current database schema version 
    4949 */ 
    50 define('REQUIRED_SCHEMA_VERSION', 63); 
     50define('REQUIRED_SCHEMA_VERSION', 64); 
    5151/** Used to test a new shecma version before modyfying the database */ 
    5252define('SCHEMA_UPDATE_TEST_MODE', false); 
     
    13671367 
    13681368        $sql .= "INSERT INTO tokens (token_id, token_status, token_creation_date, token_issuer, token_owner) SELECT token AS token_id, token_status, timestamp_in AS token_creation_date, user_id AS token_issuer, user_id AS token_owner FROM connections; \n"; 
    1369         $sql .= "CREATE INDEX idx_token_status ON tokens (token_status);\n";    
     1369        $sql .= "CREATE INDEX idx_token_status ON tokens (token_status);\n"; 
    13701370        $sql .= "ALTER TABLE connections ADD CONSTRAINT fk_tokens FOREIGN KEY (token) REFERENCES tokens (token_id) ON UPDATE CASCADE ON DELETE RESTRICT; \n"; 
    13711371 
     
    13811381        $sql .= "ALTER TABLE connections ADD COLUMN logout_reason integer;\n"; 
    13821382        $sql .= "ALTER TABLE connections ALTER COLUMN logout_reason SET DEFAULT NULL;\n"; 
    1383         $sql .= "ALTER TABLE connections RENAME COLUMN token TO token_id;\n";      
     1383        $sql .= "ALTER TABLE connections RENAME COLUMN token TO token_id;\n"; 
    13841384    } 
    13851385    $new_schema_version = 61; 
     
    14031403        $sql .= "ALTER TABLE nodes ADD COLUMN connection_limit_node_max_usage_duration_override interval;\n"; 
    14041404        $sql .= "ALTER TABLE nodes ALTER COLUMN connection_limit_node_max_usage_duration_override SET DEFAULT NULL;\n"; 
    1405          
     1405 
    14061406    } 
    14071407    $new_schema_version = 62; 
     
    14141414 
    14151415        $sql .= "ALTER TABLE nodes ALTER COLUMN connection_limit_node_max_total_bytes_override TYPE bigint;\n"; 
    1416          
     1416 
    14171417    } 
    14181418    $new_schema_version = 63; 
    14191419    if ($schema_version < $new_schema_version && $new_schema_version <= $targetSchema) { 
    14201420        printUpdateVersion($new_schema_version); 
    1421      $sql .= "\n\nUPDATE schema_info SET value='$new_schema_version' WHERE tag='schema_version';\n"; 
     1421        $sql .= "\n\nUPDATE schema_info SET value='$new_schema_version' WHERE tag='schema_version';\n"; 
    14221422 
    14231423        $sql .= "ALTER TABLE networks ADD column allow_original_url_redirect bool; \n"; 
     
    14261426        $sql .= "ALTER TABLE nodes ADD column allow_original_URL_redirect bool; \n"; 
    14271427        $sql .= "ALTER TABLE nodes ALTER COLUMN allow_original_URL_redirect SET DEFAULT FALSE;\n"; 
     1428    } 
     1429    $new_schema_version = 64; 
     1430    if ($schema_version < $new_schema_version && $new_schema_version <= $targetSchema) { 
     1431        printUpdateVersion($new_schema_version); 
     1432        $sql .= "\n\nUPDATE schema_info SET value='$new_schema_version' WHERE tag='schema_version';\n"; 
     1433        $sql .= "ALTER TABLE server ADD use_global_auth bool NOT NULL DEFAULT FALSE;\n"; 
    14281434    } 
    14291435    /* 
  • trunk/wifidog-auth/wifidog/index.php

    r1253 r1391  
    7474$smarty->assign('googleMapsEnabled', defined('GMAPS_HOTSPOTS_MAP_ENABLED') && GMAPS_HOTSPOTS_MAP_ENABLED); 
    7575 
    76 $net = Network::getCurrentNetwork(); 
    77 $smarty->assign('networkNumValidUsers', $net ? $net->getNumValidUsers() : 0); 
     76if(Server::getServer()->getUseGlobalUserAccounts()) { 
     77    $server = Server::getServer(); 
     78    $smarty->assign('serverNumValidUsers', $server ? $server->getTotalNumValidUsers() : 0); 
     79    $smarty->assign('serverNumOnlineUsers', $server ? $server->getTotalNumOnlineUsers() : 0); 
     80    $smarty->assign('serverNumDeployedNodes', $server ? $server->getTotalNumDeployedNodes() : 0); 
     81    $smarty->assign('serverNumOnlineNodes', $server ? $server->getNumOnlineNodes() : 0); 
     82    $smarty->assign('serverNumNonMonitoredNodes', $server ? $server->getNumOnlineNodes(true) : 0); 
     83    // Compile HTML code 
     84    $html_body = $smarty->fetch("templates/sites/indexglobaluser.tpl"); 
     85} else { 
     86    $net = Network::getCurrentNetwork(); 
     87    $smarty->assign('networkNumValidUsers', $net ? $net->getNumValidUsers() : 0); 
     88    // Compile HTML code 
     89    $html_body = $smarty->fetch("templates/sites/index.tpl"); 
     90} 
    7891 
    79 // Compile HTML code 
    80 $html_body = $smarty->fetch("templates/sites/index.tpl"); 
    81  
     92/* 
     93 * Don't redirect on the index page 
     94 * 
    8295$currentNode = Node::getCurrentRealNode(); 
    8396if($currentNode){ 
     
    8598    exit(); 
    8699} 
     100*/ 
    87101/* 
    88102 * Render output 
  • trunk/wifidog-auth/wifidog/lost_password.php

    r1249 r1391  
    202202} 
    203203 
    204 $smarty->assign('SelectNetworkUI', Network::getSelectUI('auth_source')); 
     204if (Server::getServer()->getUseGlobalUserAccounts()) { 
     205    $default_network_param = Network::getDefaultNetwork()->getId(); 
     206    $smarty->assign('SelectNetworkUI', "<input type=\"hidden\" name=\"auth_source\" value='$default_network_param' />"); 
     207} else { 
     208    $smarty->assign('SelectNetworkUI', Network::getSelectUI('auth_source')); 
     209} 
    205210 
    206211// Compile HTML code 
  • trunk/wifidog-auth/wifidog/lost_username.php

    r1249 r1391  
    185185} 
    186186 
    187 $smarty->assign('SelectNetworkUI', Network::getSelectUI('auth_source')); 
     187if (Server::getServer()->getUseGlobalUserAccounts()) { 
     188    $default_network_param = Network::getDefaultNetwork()->getId(); 
     189    $smarty->assign('SelectNetworkUI', "<input type=\"hidden\" name=\"auth_source\" value='$default_network_param' />"); 
     190} else { 
     191    $smarty->assign('SelectNetworkUI', Network::getSelectUI('auth_source')); 
     192} 
    188193 
    189194// Compile HTML code 
  • trunk/wifidog-auth/wifidog/node_list.php

    r1259 r1391  
    9898        $sort_by_param_sql = $sort_by_param; 
    9999    } 
    100     $sql = "SELECT node_id, gw_id, name, last_heartbeat_user_agent, (CURRENT_TIMESTAMP-last_heartbeat_timestamp) AS since_last_heartbeat, last_heartbeat_ip, CASE WHEN ((CURRENT_TIMESTAMP-last_heartbeat_timestamp) < interval '5 minutes') THEN true ELSE false END AS online, creation_date, node_deployment_status, last_heartbeat_wifidog_uptime, last_heartbeat_sys_uptime FROM nodes WHERE node_deployment_status != 'PERMANENTLY_CLOSED' ORDER BY {$sort_by_param_sql}"; 
     100} else { 
     101        $sort_by_param_sql = DEFAULT_SORT_BY_PARAM; 
    101102} 
    102 else { 
    103     $sql = "SELECT node_id, gw_id, name, last_heartbeat_user_agent, (CURRENT_TIMESTAMP-last_heartbeat_timestamp) AS since_last_heartbeat, last_heartbeat_ip, CASE WHEN ((CURRENT_TIMESTAMP-last_heartbeat_timestamp) < interval '5 minutes') THEN true ELSE false END AS online, creation_date, node_deployment_status, last_heartbeat_wifidog_uptime, last_heartbeat_sys_uptime FROM nodes WHERE node_deployment_status != 'PERMANENTLY_CLOSED' ORDER BY " . DEFAULT_SORT_BY_PARAM; 
     103 
     104if (isset ($_REQUEST["network_id"])) { 
     105        $network_id = $_REQUEST["network_id"]; 
     106    if($network_id == ""){ 
     107        $network = null; 
     108    } else { 
     109        try { 
     110            $network = Network::getObject($network_id); 
     111        } catch (Exception $e) { 
     112            $network = Network::getDefaultNetwork(); 
     113        } 
     114    } 
     115} else { 
     116        $network = Network::getDefaultNetwork(); 
    104117} 
     118$network_id_sql = $network===null?"":"AND network_id = '{$network->getId()}'"; 
     119 
     120$sql = "SELECT node_id, gw_id, name, last_heartbeat_user_agent, (CURRENT_TIMESTAMP-last_heartbeat_timestamp) AS since_last_heartbeat, last_heartbeat_ip, CASE WHEN ((CURRENT_TIMESTAMP-last_heartbeat_timestamp) < interval '5 minutes') THEN true ELSE false END AS online, creation_date, node_deployment_status, last_heartbeat_wifidog_uptime, last_heartbeat_sys_uptime FROM nodes WHERE node_deployment_status != 'PERMANENTLY_CLOSED' $network_id_sql ORDER BY {$sort_by_param_sql}"; 
    105121$nodes_results = null; 
    106122$db->execSql($sql, $nodes_results, false); 
    107123 
    108 if ($nodes_results == null) 
    109 throw new Exception(_("No nodes could not be found in the database")); 
     124//Possible to select empty networks, not an error 
     125if ($nodes_results === null) 
     126    $nodes_results = array(); 
     127//throw new Exception(_("No nodes could not be found in the database")); 
     128 
    110129 
    111130$deploymentStatuses = array ( 
     
    148167 
    149168// Pass values to Smarty 
     169$smarty->assign('selectNetworkUI', Network::getSelectUI('network_id', array('preSelectedObject' => $network, 'allowEmpty' => true, 'nullCaptionString' => _("All"), 'onChange' => "submit.click();") ) . (count(Network::getAllNetworks()) > 1 ? '<input class="submit" type="submit" name="submit" value="' . _("Change network") . '">' : "")); 
     170if ($network !== null ) { 
     171    $smarty->assign('selectedNetwork', $network->getName()); 
     172} else { 
     173    $smarty->assign('allNetworks', _("All networks")); 
     174} 
    150175$smarty->assign("nodes", $nodes_list); 
    151176$smarty->assign("sort_by_param", $sort_by_param); 
  • trunk/wifidog-auth/wifidog/resend_validation.php

    r1249 r1391  
    184184} 
    185185 
    186 $smarty->assign('SelectNetworkUI', Network::getSelectUI('auth_source')); 
     186if (Server::getServer()->getUseGlobalUserAccounts()) { 
     187    $default_network_param = Network::getDefaultNetwork()->getId(); 
     188    $smarty->assign('SelectNetworkUI', "<input type=\"hidden\" name=\"auth_source\" value='$default_network_param' />"); 
     189} else { 
     190    $smarty->assign('SelectNetworkUI', Network::getSelectUI('auth_source')); 
     191} 
    187192 
    188193// Compile HTML code 
  • trunk/wifidog-auth/wifidog/signup.php

    r1249 r1391  
    320320// Preserve keys 
    321321$network_array = Network::getAllNetworks(); 
     322$default_network = Network::getDefaultNetwork(); 
     323 
    322324 
    323325foreach ($network_array as $network) { 
     
    325327        $sources[$network->getId()] = $network->getName(); 
    326328    } 
     329     if ($network->getName() == $default_network) 
     330        $default_network_param = $network->getId(); 
     331        //$default_network_param = $network->getAuthenticatorConstructorParams(); 
     332 
    327333} 
    328334 
     
    336342} 
    337343 
    338 $smarty->assign('SelectNetworkUI', Network::getSelectUI('auth_source')); 
     344if (Server::getServer()->getUseGlobalUserAccounts()) 
     345        $smarty->assign('SelectNetworkUI', "<input type=\"hidden\" name=\"auth_source\" value='$default_network_param' />"); 
     346else 
     347        $smarty->assign('SelectNetworkUI', Network::getSelectUI('network_id', array('preSelectedObject' => $network)) ); 
    339348 
    340349// Compile HTML code 
  • trunk/wifidog-auth/wifidog/templates/node_list.html

    r1257 r1391  
     1{if $selectNetworkUI} 
     2<form name="hotspots_form" method="post"> 
     3        {$selectNetworkUI} 
     4</form> 
     5{/if} 
    16<div id="node_list"> 
    2         <h3>{"Status of all nodes of the"|_} {$networkName} {"network"|_}</h3> 
     7    {if $allNetworks } 
     8        <h3>{"Status of all nodes on "|_} {$allNetworks}</h3> 
     9    {else} 
     10        {if $selectedNetwork} 
     11            <h3>{"Status of all nodes of the "|_} {$selectedNetwork} {"network"|_}</h3> 
     12        {else} 
     13            <h3>{"Status of all nodes of the"|_} {$networkName} {"network"|_}</h3> 
     14        {/if} 
     15    {/if} 
    316        <table> 
    417                <thead> 
  • trunk/wifidog-auth/wifidog/templates/sites/hotspot_status.tpl

    r1249 r1391  
    5151    BEGIN section MAINCONTENT 
    5252*} 
     53 
     54    <form name="hotspots_form" method="post"> 
     55        <input type="hidden" name="format" value="HTML" /> 
     56        {$selectNetworkUI} 
     57    </form> 
     58    <br /> 
     59 
    5360    <div id="hotspot_status"> 
    5461        <table> 
    5562            <thead> 
    5663                <tr> 
    57                     <th colspan="6">{"Status of the %d open %s Hotspots"|_|sprintf:$num_deployed_nodes:$networkName}</th> 
     64                        <th colspan="6">{"Status of the %d open %s Hotspots"|_|sprintf:$num_deployed_nodes:$selectedNetworkName}</th> 
    5865                </tr> 
    5966                <tr>