root/trunk/wifidog-auth/wifidog/classes/NodeList.php @ 1253

Revision 1253, 7.6 KB (checked in by benoitg, 6 years ago)
  • Node.php: Improve getCurrentRealNode()
  • Implement #4: Allow the user to easily come back to the portal by typing in the root auth server adress from a hotspot.
  • Log the system information sent with the gateway since almost forever: sys_uptime, sys_memfree, sys_load, wifidog_uptime
  • NodeStatus?.php: Include the above information
  • node_list.html: Include wifidog_uptime if the hotspot is up.
  • Menu.php: Sort menus alphabetically according to the user's locale. TODO: Implement menu weights.
  • NodeLists?: Only list node types that have dependencies met in the menu. Refactor the NodeLists? for proper object-orientation.


Line 
1<?php
2
3/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
5// +-------------------------------------------------------------------+
6// | WiFiDog Authentication Server                                     |
7// | =============================                                     |
8// |                                                                   |
9// | The WiFiDog Authentication Server is part of the WiFiDog captive  |
10// | portal suite.                                                     |
11// +-------------------------------------------------------------------+
12// | PHP version 5 required.                                           |
13// +-------------------------------------------------------------------+
14// | Homepage:     http://www.wifidog.org/                             |
15// | Source Forge: http://sourceforge.net/projects/wifidog/            |
16// +-------------------------------------------------------------------+
17// | This program is free software; you can redistribute it and/or     |
18// | modify it under the terms of the GNU General Public License as    |
19// | published by the Free Software Foundation; either version 2 of    |
20// | the License, or (at your option) any later version.               |
21// |                                                                   |
22// | This program is distributed in the hope that it will be useful,   |
23// | but WITHOUT ANY WARRANTY; without even the implied warranty of    |
24// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     |
25// | GNU General Public License for more details.                      |
26// |                                                                   |
27// | You should have received a copy of the GNU General Public License |
28// | along with this program; if not, contact:                         |
29// |                                                                   |
30// | Free Software Foundation           Voice:  +1-617-542-5942        |
31// | 59 Temple Place - Suite 330        Fax:    +1-617-542-2652        |
32// | Boston, MA  02111-1307,  USA       gnu@gnu.org                    |
33// |                                                                   |
34// +-------------------------------------------------------------------+
35
36/**
37 * @package    WiFiDogAuthServer
38 * @subpackage NodeLists
39 * @author     Max Horváth <max.horvath@freenet.de>
40 * @copyright  2006 Max Horváth, Horvath Web Consulting
41 * @version    Subversion $Id: Content.php 974 2006-02-25 15:08:12Z max-horvath $
42 * @link       http://www.wifidog.org/
43 */
44
45/**
46 * Load required classes
47 */
48require_once('classes/Cache.php');
49
50/**
51 * Defines and loads any type of node list
52 *
53 * @package    WiFiDogAuthServer
54 * @subpackage NodeLists
55 * @author     Max Horváth <max.horvath@freenet.de>
56 * @copyright  2006 Max Horváth, Horvath Web Consulting
57 */
58/**
59 * Directory of NodeList classes
60 */   define ('NODE_LIST_CLASSES_DIR', WIFIDOG_ABS_FILE_PATH . "classes/NodeLists");
61abstract class NodeList {
62
63
64    /**
65     * Constructor
66     *
67     * @param string $nodeListType Type of node list
68     * @param object $network      Object of network to generate list from
69     *
70     * @return void
71     */
72    public static function &getObject($nodeListType, &$network)
73    {
74        // Check if node list type exists
75        if (in_array($nodeListType, self::getAvailableNodeListTypes())) {
76            require_once(NODE_LIST_CLASSES_DIR . "/NodeList" . $nodeListType . ".php");
77        } else {
78            throw new Exception(_("The node list type '$nodeListType' is not supported!"));
79        }
80
81        $nodeListClass = "NodeList" . $nodeListType;
82        $nodeList = new $nodeListClass($network);
83
84        // Set header of node list if node list class supports it
85        $nodeList->setHeader();
86        return $nodeList;
87    }
88
89    /**
90     * Get the list of available node list types on the system
91     *
92     * @return array An array of class names
93
94     */
95    public static function getAvailableNodeListTypes()
96    {
97        // Init values
98        $_nodeListTypes = array();
99        $_useCache = false;
100        $_cachedData = null;
101
102        // Create new cache object with a lifetime of one week
103        $_cache = new Cache("NodeListClasses", "ClassFileCaches", 604800);
104
105        // Check if caching has been enabled.
106        if ($_cache->isCachingEnabled) {
107            $_cachedData = $_cache->getCachedData("mixed");
108
109            if ($_cachedData) {
110                // Return cached data.
111                $_useCache = true;
112                $_nodeListTypes = $_cachedData;
113            }
114        }
115
116        if (!$_useCache) {
117            $_dir = NODE_LIST_CLASSES_DIR;
118            $_dirHandle = @opendir($_dir);
119
120            if ($_dirHandle) {
121                // Loop over the directory
122                while (false !== ($_filename = readdir($_dirHandle))) {
123                    // Loop through sub-directories of Content
124                    if ($_filename != '.' && $_filename != '..') {
125                        $_matches = null;
126
127                        if (preg_match("/^NodeList(.*)\.php$/", $_filename, $_matches) > 0) {
128                            // Only add files containing a corresponding NodeList class
129                            if (is_file("{$_dir}/{$_matches[0]}")) {
130                                $_nodeListTypes[] = $_matches[1];
131                            }
132                        }
133                    }
134                }
135
136                closedir($_dirHandle);
137            } else {
138                throw new Exception(_('Unable to open directory ') . $_dir);
139            }
140
141            // Sort the result array
142            sort($_nodeListTypes);
143
144            // Check if caching has been enabled.
145            if ($_cache->isCachingEnabled) {
146                // Save results into cache, because it wasn't saved into cache before.
147                $_cache->saveCachedData($_nodeListTypes, "mixed");
148            }
149        }
150
151        return $_nodeListTypes;
152    }
153   
154    /**
155     * Sets header of output.  If not extended, doesn't touch headers.
156     *
157     * @return void
158     */
159    public function setHeader()
160    {
161        ;
162    }
163   
164    /**
165     * Does the node list have all required dependencies, etc.?  In not redefined by the child class,
166     * returns true
167     *
168     * @return true or false
169     */
170    static public function isAvailable()
171    {
172        return true;
173    }   
174    /**
175     * Displays the output of this node list.
176         *
177     * @return void
178     */
179    abstract public function getOutput();
180
181    /** Menu hook function */
182    static public function hookMenu() {
183        $items = array();
184
185        $items[] = array('path' => 'node_lists/map',
186        'title' => _("Deployed HotSpots map"),
187        'url' => BASE_URL_PATH."hotspots_map.php"
188                );
189
190        $listTypes=self::getAvailableNodeListTypes();
191        //pretty_print_r($listTypes);
192        foreach ($listTypes as $type) {
193                    $nodeListClass = "NodeList" . $type;
194                    require_once("classes/NodeLists/NodeList{$type}.php");
195            if(call_user_func(array($nodeListClass, 'isAvailable'))) {
196            $items[] = array('path' => 'node_lists/'.$type,
197            'title' => sprintf(_("List in %s format"), $type),
198            'url' => BASE_URL_PATH."hotspot_status.php?format=$type"
199            );
200            }
201        }
202        $items[] = array('path' => 'node_lists/technical_status',
203        'title' => _("Full node technical status (includes non-deployed nodes)"),
204        'url' => BASE_URL_PATH."node_list.php"
205                );
206        $items[] = array('path' => 'node_lists',
207        'title' => _('Node lists'),
208        'type' => MENU_ITEM_GROUPING);
209
210
211
212
213        return $items;
214    }
215
216}
217
218/*
219 * Local variables:
220 * tab-width: 4
221 * c-basic-offset: 4
222 * c-hanging-comment-ender-p: nil
223 * End:
224 */
225
Note: See TracBrowser for help on using the browser.