| 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 | * @author Benoit Grégoire <bock@step.polymtl.ca> |
|---|
| 39 | * @copyright 2004-2006 Benoit Grégoire, Technologies Coeus inc. |
|---|
| 40 | * @version Subversion $Id$ |
|---|
| 41 | * @link http://www.wifidog.org/ |
|---|
| 42 | */ |
|---|
| 43 | |
|---|
| 44 | /** |
|---|
| 45 | * Load required classes |
|---|
| 46 | */ |
|---|
| 47 | require_once("classes/Locale.php"); |
|---|
| 48 | require_once("classes/Utils.php"); |
|---|
| 49 | require_once("include/smarty.resource.string.php"); |
|---|
| 50 | |
|---|
| 51 | // Check if Smarty installed, if not redirect user to web-base installation |
|---|
| 52 | if (Dependencies::check("Smarty", $errmsg)) { |
|---|
| 53 | // Load Smarty library |
|---|
| 54 | require_once('lib/smarty/Smarty.class.php'); |
|---|
| 55 | } else { |
|---|
| 56 | // Build the system_path for the auth-server |
|---|
| 57 | print "Redirecting to Wifidog web-based install script since Smarty is missing (Error was: $errmsg)<META HTTP-EQUIV=Refresh CONTENT=\"5; URL=".BASE_URL_PATH."/install.php\">"; |
|---|
| 58 | exit(); |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | /* |
|---|
| 62 | * Smarty plugin |
|---|
| 63 | * ------------------------------------------------------------- |
|---|
| 64 | * Type: modifier |
|---|
| 65 | * Name: fsize_format |
|---|
| 66 | * Version: 0.2 |
|---|
| 67 | * Date: 2003-05-15 |
|---|
| 68 | * Author: Joscha Feth, joscha@feth.com |
|---|
| 69 | * Purpose: formats a filesize (in bytes) to human-readable format |
|---|
| 70 | * Usage: In the template, use |
|---|
| 71 | {$filesize|fsize_format} => 123.45 B|KB|MB|GB|TB |
|---|
| 72 | or |
|---|
| 73 | {$filesize|fsize_format:"MB"} => 123.45 MB |
|---|
| 74 | or |
|---|
| 75 | {$filesize|fsize_format:"TB":4} => 0.0012 TB |
|---|
| 76 | * Params: |
|---|
| 77 | int size the filesize in bytes |
|---|
| 78 | string format the format, the output shall be: B, KB, MB, GB or TB |
|---|
| 79 | int precision the rounding precision |
|---|
| 80 | string dec_point the decimal separator |
|---|
| 81 | string thousands_sep the thousands separator |
|---|
| 82 | * Install: Drop into the plugin directory |
|---|
| 83 | * Version: |
|---|
| 84 | * 2003-05-15 Version 0.2 - added dec_point and thousands_sep thanks to Thomas Brandl, tbrandl@barff.de |
|---|
| 85 | * - made format always uppercase |
|---|
| 86 | * - count sizes "on-the-fly" |
|---|
| 87 | * 2003-02-21 Version 0.1 - initial release |
|---|
| 88 | * ------------------------------------------------------------- |
|---|
| 89 | */ |
|---|
| 90 | function smarty_modifier_fsize_format($size,$format = '',$precision = 2, $dec_point = ".", $thousands_sep = ",") |
|---|
| 91 | { |
|---|
| 92 | $format = strtoupper($format); |
|---|
| 93 | |
|---|
| 94 | static $sizes = array(); |
|---|
| 95 | |
|---|
| 96 | if(!count($sizes)) { |
|---|
| 97 | $b = 1024; |
|---|
| 98 | $sizes["B"] = 1; |
|---|
| 99 | $sizes["KB"] = $sizes["B"] * $b; |
|---|
| 100 | $sizes["MB"] = $sizes["KB"] * $b; |
|---|
| 101 | $sizes["GB"] = $sizes["MB"] * $b; |
|---|
| 102 | $sizes["TB"] = $sizes["GB"] * $b; |
|---|
| 103 | |
|---|
| 104 | $sizes = array_reverse($sizes,true); |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | //~ get "human" filesize |
|---|
| 108 | foreach($sizes AS $unit => $bytes) { |
|---|
| 109 | if($size > $bytes || $unit == $format) { |
|---|
| 110 | //~ return formatted size |
|---|
| 111 | return number_format($size / $bytes,$precision,$dec_point,$thousands_sep)." ".$unit; |
|---|
| 112 | } //~ end if |
|---|
| 113 | } //~ end foreach |
|---|
| 114 | } //~ end function |
|---|
| 115 | |
|---|
| 116 | // The setup.php file is a good place to load |
|---|
| 117 | // required application library files, and you |
|---|
| 118 | // can do that right here. An example: |
|---|
| 119 | // require('guestbook/guestbook.lib.php'); |
|---|
| 120 | |
|---|
| 121 | /** |
|---|
| 122 | * @package WiFiDogAuthServer |
|---|
| 123 | * @author Benoit Grégoire <bock@step.polymtl.ca> |
|---|
| 124 | * @copyright 2004-2006 Benoit Grégoire, Technologies Coeus inc. |
|---|
| 125 | */ |
|---|
| 126 | class SmartyWifidog extends Smarty { |
|---|
| 127 | public static function getObject() { |
|---|
| 128 | return new self(); |
|---|
| 129 | } |
|---|
| 130 | private function __construct() |
|---|
| 131 | { |
|---|
| 132 | |
|---|
| 133 | // Class Constructor. These automatically get set with each new instance. |
|---|
| 134 | |
|---|
| 135 | $this->Smarty(); |
|---|
| 136 | //Now that we have user-definable templates, we must turn on security |
|---|
| 137 | $this->security = true; |
|---|
| 138 | //pretty_print_r($this->security_settings); |
|---|
| 139 | $this->security_settings['MODIFIER_FUNCS'][] = 'sprintf'; |
|---|
| 140 | $this->template_dir = WIFIDOG_ABS_FILE_PATH; |
|---|
| 141 | $this->compile_dir = $this->template_dir . 'tmp/smarty/templates_c/'; |
|---|
| 142 | $this->config_dir = $this->template_dir . 'tmp/smarty/configs/'; |
|---|
| 143 | $this->cache_dir = $this->template_dir . 'tmp/smarty/cache/'; |
|---|
| 144 | |
|---|
| 145 | /* Register the _ smarty modifier to call the _() |
|---|
| 146 | * PHP function which is the gettext() function |
|---|
| 147 | */ |
|---|
| 148 | $this->register_modifier("_","_"); |
|---|
| 149 | $this->register_modifier("urlencode","urlencode"); |
|---|
| 150 | $this->register_modifier("remove_accents",array('Utils', "remove_accents")); |
|---|
| 151 | $this->register_modifier("fsize_format", "smarty_modifier_fsize_format"); |
|---|
| 152 | |
|---|
| 153 | // register the resource name "string" |
|---|
| 154 | $this->register_resource("string", array("smarty_resource_string_source", |
|---|
| 155 | "smarty_resource_string_timestamp", |
|---|
| 156 | "smarty_resource_string_secure", |
|---|
| 157 | "smarty_resource_string_trusted")); |
|---|
| 158 | $this->caching = false; |
|---|
| 159 | //$this->compile_check = true; |
|---|
| 160 | |
|---|
| 161 | /* Common content */ |
|---|
| 162 | $network = Network::GetCurrentNetwork(); |
|---|
| 163 | |
|---|
| 164 | /* Useful stuff from config.php */ |
|---|
| 165 | |
|---|
| 166 | $this->assign('base_url_path', BASE_URL_PATH); |
|---|
| 167 | $this->assign('base_ssl_path', BASE_SSL_PATH); |
|---|
| 168 | $this->assign('base_non_ssl_path', BASE_NON_SSL_PATH); |
|---|
| 169 | $this->assign('common_images_url', COMMON_IMAGES_URL); |
|---|
| 170 | $this->assign('base_theme_url', BASE_THEME_URL); |
|---|
| 171 | $this->assign('hotspot_network_name',$network->getName()); |
|---|
| 172 | $this->assign('hotspot_network_url',$network->getWebSiteURL()); |
|---|
| 173 | } |
|---|
| 174 | |
|---|
| 175 | function SetTemplateDir( $template_dir) |
|---|
| 176 | { |
|---|
| 177 | $this->template_dir= $template_dir; |
|---|
| 178 | } |
|---|
| 179 | /** |
|---|
| 180 | * executes & returns or displays the template results |
|---|
| 181 | * This is extended by wifidog to make sure that the variables influenced by state (such as the current node) are as up to date as humanly possible. |
|---|
| 182 | * @param string $resource_name |
|---|
| 183 | * @param string $cache_id |
|---|
| 184 | * @param string $compile_id |
|---|
| 185 | * @param boolean $display |
|---|
| 186 | */ |
|---|
| 187 | public function fetch($resource_name, $cache_id = null, $compile_id = null, $display = false) |
|---|
| 188 | { |
|---|
| 189 | /* Other useful variables */ |
|---|
| 190 | Network::assignSmartyValues($this); |
|---|
| 191 | Node::assignSmartyValues($this); |
|---|
| 192 | User::assignSmartyValues($this); |
|---|
| 193 | return parent::fetch($resource_name, $cache_id, $compile_id, $display); |
|---|
| 194 | } |
|---|
| 195 | } |
|---|
| 196 | |
|---|
| 197 | /* |
|---|
| 198 | * Local variables: |
|---|
| 199 | * tab-width: 4 |
|---|
| 200 | * c-basic-offset: 4 |
|---|
| 201 | * c-hanging-comment-ender-p: nil |
|---|
| 202 | * End: |
|---|
| 203 | */ |
|---|
| 204 | |
|---|
| 205 | |
|---|