| 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 | */ |
|---|
| 48 | require_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"); |
|---|
| 61 | |
|---|
| 62 | interface AcceptsNullNetwork { } |
|---|
| 63 | abstract class NodeList { |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | /** |
|---|
| 67 | * Constructor |
|---|
| 68 | * |
|---|
| 69 | * @param string $nodeListType Type of node list |
|---|
| 70 | * @param object $network Object of network to generate list from |
|---|
| 71 | * |
|---|
| 72 | * @return void |
|---|
| 73 | */ |
|---|
| 74 | public static function &getObject($nodeListType, &$network) |
|---|
| 75 | { |
|---|
| 76 | // Check if node list type exists |
|---|
| 77 | if (in_array($nodeListType, self::getAvailableNodeListTypes())) { |
|---|
| 78 | require_once(NODE_LIST_CLASSES_DIR . "/NodeList" . $nodeListType . ".php"); |
|---|
| 79 | } else { |
|---|
| 80 | throw new Exception(sprintf(_("The node list type '%s' is not supported!"), htmlspecialchars($nodeListType))); |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | $nodeListClass = "NodeList" . $nodeListType; |
|---|
| 84 | $nodeList = new $nodeListClass($network); |
|---|
| 85 | |
|---|
| 86 | // Set header of node list if node list class supports it |
|---|
| 87 | $nodeList->setHeader(); |
|---|
| 88 | 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); |
|---|
| 111 | } |
|---|
| 112 | |
|---|
| 113 | /** |
|---|
| 114 | * Get the list of available node list types on the system |
|---|
| 115 | * |
|---|
| 116 | * @return array An array of class names |
|---|
| 117 | |
|---|
| 118 | */ |
|---|
| 119 | public static function getAvailableNodeListTypes() |
|---|
| 120 | { |
|---|
| 121 | // Init values |
|---|
| 122 | $_nodeListTypes = array(); |
|---|
| 123 | $_useCache = false; |
|---|
| 124 | $_cachedData = null; |
|---|
| 125 | |
|---|
| 126 | // Create new cache object with a lifetime of one week |
|---|
| 127 | $_cache = new Cache("NodeListClasses", "ClassFileCaches", 604800); |
|---|
| 128 | |
|---|
| 129 | // Check if caching has been enabled. |
|---|
| 130 | if ($_cache->isCachingEnabled) { |
|---|
| 131 | $_cachedData = $_cache->getCachedData("mixed"); |
|---|
| 132 | |
|---|
| 133 | if ($_cachedData) { |
|---|
| 134 | // Return cached data. |
|---|
| 135 | $_useCache = true; |
|---|
| 136 | $_nodeListTypes = $_cachedData; |
|---|
| 137 | } |
|---|
| 138 | } |
|---|
| 139 | |
|---|
| 140 | if (!$_useCache) { |
|---|
| 141 | $_dir = NODE_LIST_CLASSES_DIR; |
|---|
| 142 | $_dirHandle = @opendir($_dir); |
|---|
| 143 | |
|---|
| 144 | if ($_dirHandle) { |
|---|
| 145 | // Loop over the directory |
|---|
| 146 | while (false !== ($_filename = readdir($_dirHandle))) { |
|---|
| 147 | // Loop through sub-directories of Content |
|---|
| 148 | if ($_filename != '.' && $_filename != '..') { |
|---|
| 149 | $_matches = null; |
|---|
| 150 | |
|---|
| 151 | if (preg_match("/^NodeList(.*)\.php$/", $_filename, $_matches) > 0) { |
|---|
| 152 | // Only add files containing a corresponding NodeList class |
|---|
| 153 | if (is_file("{$_dir}/{$_matches[0]}")) { |
|---|
| 154 | $_nodeListTypes[] = $_matches[1]; |
|---|
| 155 | } |
|---|
| 156 | } |
|---|
| 157 | } |
|---|
| 158 | } |
|---|
| 159 | |
|---|
| 160 | closedir($_dirHandle); |
|---|
| 161 | } else { |
|---|
| 162 | throw new Exception(_('Unable to open directory ') . $_dir); |
|---|
| 163 | } |
|---|
| 164 | |
|---|
| 165 | // Sort the result array |
|---|
| 166 | sort($_nodeListTypes); |
|---|
| 167 | |
|---|
| 168 | // Check if caching has been enabled. |
|---|
| 169 | if ($_cache->isCachingEnabled) { |
|---|
| 170 | // Save results into cache, because it wasn't saved into cache before. |
|---|
| 171 | $_cache->saveCachedData($_nodeListTypes, "mixed"); |
|---|
| 172 | } |
|---|
| 173 | } |
|---|
| 174 | |
|---|
| 175 | return $_nodeListTypes; |
|---|
| 176 | } |
|---|
| 177 | |
|---|
| 178 | /** |
|---|
| 179 | * Sets header of output. If not extended, doesn't touch headers. |
|---|
| 180 | * |
|---|
| 181 | * @return void |
|---|
| 182 | */ |
|---|
| 183 | public function setHeader() |
|---|
| 184 | { |
|---|
| 185 | ; |
|---|
| 186 | } |
|---|
| 187 | |
|---|
| 188 | /** |
|---|
| 189 | * Does the node list have all required dependencies, etc.? In not redefined by the child class, |
|---|
| 190 | * returns true |
|---|
| 191 | * |
|---|
| 192 | * @return true or false |
|---|
| 193 | */ |
|---|
| 194 | static public function isAvailable() |
|---|
| 195 | { |
|---|
| 196 | return true; |
|---|
| 197 | } |
|---|
| 198 | /** |
|---|
| 199 | * Displays the output of this node list. |
|---|
| 200 | * |
|---|
| 201 | * @return void |
|---|
| 202 | */ |
|---|
| 203 | abstract public function getOutput(); |
|---|
| 204 | |
|---|
| 205 | /** Menu hook function */ |
|---|
| 206 | static public function hookMenu() { |
|---|
| 207 | $items = array(); |
|---|
| 208 | |
|---|
| 209 | $items[] = array('path' => 'node_lists/map', |
|---|
| 210 | 'title' => _("Deployed HotSpots map"), |
|---|
| 211 | 'url' => BASE_URL_PATH."hotspots_map.php" |
|---|
| 212 | ); |
|---|
| 213 | |
|---|
| 214 | $listTypes=self::getAvailableNodeListTypes(); |
|---|
| 215 | //pretty_print_r($listTypes); |
|---|
| 216 | foreach ($listTypes as $type) { |
|---|
| 217 | $nodeListClass = "NodeList" . $type; |
|---|
| 218 | require_once("classes/NodeLists/NodeList{$type}.php"); |
|---|
| 219 | if(call_user_func(array($nodeListClass, 'isAvailable'))) { |
|---|
| 220 | $items[] = array('path' => 'node_lists/'.$type, |
|---|
| 221 | 'title' => sprintf(_("List in %s format"), $type), |
|---|
| 222 | 'url' => BASE_URL_PATH."hotspot_status.php?format=$type" |
|---|
| 223 | ); |
|---|
| 224 | } |
|---|
| 225 | } |
|---|
| 226 | $items[] = array('path' => 'node_lists/technical_status', |
|---|
| 227 | 'title' => _("Full node technical status (includes non-deployed nodes)"), |
|---|
| 228 | 'url' => BASE_URL_PATH."node_list.php" |
|---|
| 229 | ); |
|---|
| 230 | $items[] = array('path' => 'node_lists', |
|---|
| 231 | 'title' => _('Find Hotspots'), |
|---|
| 232 | 'type' => MENU_ITEM_GROUPING); |
|---|
| 233 | |
|---|
| 234 | return $items; |
|---|
| 235 | } |
|---|
| 236 | |
|---|
| 237 | } |
|---|
| 238 | |
|---|
| 239 | /* |
|---|
| 240 | * Local variables: |
|---|
| 241 | * tab-width: 4 |
|---|
| 242 | * c-basic-offset: 4 |
|---|
| 243 | * c-hanging-comment-ender-p: nil |
|---|
| 244 | * End: |
|---|
| 245 | */ |
|---|
| 246 | |
|---|