| 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 | * Displays the portal page |
|---|
| 38 | * |
|---|
| 39 | * @package WiFiDogAuthServer |
|---|
| 40 | * @author Philippe April |
|---|
| 41 | * @author Benoit Gregoire <bock@step.polymtl.ca> |
|---|
| 42 | * @author Max Horvath <max.horvath@maxspot.de> |
|---|
| 43 | * @copyright 2004-2006 Philippe April |
|---|
| 44 | * @copyright 2004-2006 Benoit Gregoire, Technologies Coeus inc. |
|---|
| 45 | * @copyright 2006 Max Horvath, maxspot GmbH |
|---|
| 46 | * @version Subversion $Id$ |
|---|
| 47 | * @link http://www.wifidog.org/ |
|---|
| 48 | */ |
|---|
| 49 | |
|---|
| 50 | /** |
|---|
| 51 | * Load required files |
|---|
| 52 | */ |
|---|
| 53 | require_once('../include/common.php'); |
|---|
| 54 | |
|---|
| 55 | require_once('include/common_interface.php'); |
|---|
| 56 | require_once('classes/Node.php'); |
|---|
| 57 | require_once('classes/MainUI.php'); |
|---|
| 58 | require_once('classes/Session.php'); |
|---|
| 59 | |
|---|
| 60 | /* |
|---|
| 61 | * Check for missing URL switch |
|---|
| 62 | */ |
|---|
| 63 | if (isset($_REQUEST['missing']) && $_REQUEST['missing'] == "url") { |
|---|
| 64 | $ui = new MainUI(); |
|---|
| 65 | $ui->displayError(_('For some reason, we were unable to determine the web site you initially wanted to see. You should now enter a web address in your URL bar.'), false); |
|---|
| 66 | exit; |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | // Init values |
|---|
| 70 | $node = null; |
|---|
| 71 | $rolenames = ""; |
|---|
| 72 | $show_more_link = false; |
|---|
| 73 | |
|---|
| 74 | // Init session |
|---|
| 75 | $session = new Session(); |
|---|
| 76 | |
|---|
| 77 | // Get the current user |
|---|
| 78 | $current_user = User::getCurrentUser(); |
|---|
| 79 | |
|---|
| 80 | /* |
|---|
| 81 | * Start general request parameter processing section |
|---|
| 82 | */ |
|---|
| 83 | if (!empty($_REQUEST['gw_id'])) { |
|---|
| 84 | try { |
|---|
| 85 | $node = Node::getObject($_REQUEST['gw_id']); |
|---|
| 86 | $network = $node->getNetwork(); |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | catch (Exception $e) { |
|---|
| 90 | $ui = new MainUI(); |
|---|
| 91 | $ui->displayError($e->getMessage()); |
|---|
| 92 | exit; |
|---|
| 93 | } |
|---|
| 94 | } else { |
|---|
| 95 | $ui = new MainUI(); |
|---|
| 96 | $ui->displayError(_("No Hotspot specified!")); |
|---|
| 97 | exit; |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | /* |
|---|
| 101 | * If this node has a custom portal defined, and the network config allows it, |
|---|
| 102 | * redirect to the custom portal |
|---|
| 103 | */ |
|---|
| 104 | $custom_portal_url = $node->getCustomPortalRedirectUrl(); |
|---|
| 105 | |
|---|
| 106 | if (!empty($custom_portal_url) && $network->getCustomPortalRedirectAllowed()) { |
|---|
| 107 | header("Location: {$custom_portal_url}"); |
|---|
| 108 | } |
|---|
| 109 | |
|---|
| 110 | $node_id = $node->getId(); |
|---|
| 111 | $portal_template = $node_id.".html"; |
|---|
| 112 | Node::setCurrentNode($node); |
|---|
| 113 | |
|---|
| 114 | if (isset($session)) { |
|---|
| 115 | if (!empty($_REQUEST['gw_id'])) { |
|---|
| 116 | $session->set(SESS_GW_ID_VAR, $_REQUEST['gw_id']); |
|---|
| 117 | } |
|---|
| 118 | } |
|---|
| 119 | |
|---|
| 120 | $current_node = Node::getCurrentNode(); |
|---|
| 121 | $current_node_id = $current_node->getId(); |
|---|
| 122 | |
|---|
| 123 | // Init ALL smarty SWITCH values |
|---|
| 124 | $smarty->assign('sectionTOOLCONTENT', false); |
|---|
| 125 | $smarty->assign('sectionMAINCONTENT', false); |
|---|
| 126 | |
|---|
| 127 | // Init ALL smarty values |
|---|
| 128 | $smarty->assign('currentNode', null); |
|---|
| 129 | $smarty->assign('numOnlineUsers', 0); |
|---|
| 130 | $smarty->assign('onlineUsers', array()); |
|---|
| 131 | $smarty->assign('userIsAtHotspot', false); |
|---|
| 132 | $smarty->assign('noUrl', true); |
|---|
| 133 | $smarty->assign('url', ""); |
|---|
| 134 | $smarty->assign('currentUrl', ""); |
|---|
| 135 | $smarty->assign('accountValidation', false); |
|---|
| 136 | $smarty->assign('validationTime', 20); |
|---|
| 137 | $smarty->assign('hotspotNetworkUrl', ""); |
|---|
| 138 | $smarty->assign('hotspotNetworkName', ""); |
|---|
| 139 | $smarty->assign('networkLogoBannerUrl', ""); |
|---|
| 140 | $smarty->assign('networkContents', false); |
|---|
| 141 | $smarty->assign('networkContentArray', array()); |
|---|
| 142 | $smarty->assign('nodeHomepage', false); |
|---|
| 143 | $smarty->assign('nodeURL', ""); |
|---|
| 144 | $smarty->assign('nodeName', ""); |
|---|
| 145 | $smarty->assign('nodeContents', false); |
|---|
| 146 | $smarty->assign('nodeContentArray', array()); |
|---|
| 147 | $smarty->assign('userContents', false); |
|---|
| 148 | $smarty->assign('userContentArray', array()); |
|---|
| 149 | |
|---|
| 150 | /* |
|---|
| 151 | * Tool content |
|---|
| 152 | */ |
|---|
| 153 | |
|---|
| 154 | // Set section of Smarty template |
|---|
| 155 | $smarty->assign('sectionTOOLCONTENT', true); |
|---|
| 156 | |
|---|
| 157 | // Set details about node |
|---|
| 158 | $smarty->assign('currentNode', $current_node); |
|---|
| 159 | |
|---|
| 160 | // Set details about onlineusers |
|---|
| 161 | $online_users = $current_node->getOnlineUsers(); |
|---|
| 162 | $num_online_users = count($online_users); |
|---|
| 163 | |
|---|
| 164 | foreach ($online_users as $online_user) { |
|---|
| 165 | $roles = array(); |
|---|
| 166 | |
|---|
| 167 | if ($current_node->isOwner($online_user)) { |
|---|
| 168 | $roles[] = _("owner"); |
|---|
| 169 | } |
|---|
| 170 | |
|---|
| 171 | if ($current_node->isTechnicalOfficer($online_user)) { |
|---|
| 172 | $roles[] = _("technical officer"); |
|---|
| 173 | } |
|---|
| 174 | |
|---|
| 175 | if ($roles) { |
|---|
| 176 | $rolenames = join($roles, ","); |
|---|
| 177 | } |
|---|
| 178 | |
|---|
| 179 | $online_user_array[] = array('Username' => $online_user->getUsername(), 'showRoles' => count($roles) > 0, 'roles' => $rolenames); |
|---|
| 180 | } |
|---|
| 181 | |
|---|
| 182 | $smarty->assign('numOnlineUsers', $num_online_users); |
|---|
| 183 | |
|---|
| 184 | if ($num_online_users > 0) { |
|---|
| 185 | $smarty->assign('onlineUsers', $online_user_array); |
|---|
| 186 | } |
|---|
| 187 | |
|---|
| 188 | // Check for requested URL and if user is at a hotspot |
|---|
| 189 | $original_url_requested = $session->get(SESS_ORIGINAL_URL_VAR); |
|---|
| 190 | |
|---|
| 191 | $smarty->assign('userIsAtHotspot', Node::getCurrentRealNode() != null ? true : false); |
|---|
| 192 | |
|---|
| 193 | if (empty($original_url_requested)) { |
|---|
| 194 | $smarty->assign('noUrl', true); |
|---|
| 195 | $smarty->assign('url', "?missing=url"); |
|---|
| 196 | } else { |
|---|
| 197 | $smarty->assign('noUrl', true); |
|---|
| 198 | $smarty->assign('url', $original_url_requested); |
|---|
| 199 | } |
|---|
| 200 | |
|---|
| 201 | // Assign current request url |
|---|
| 202 | $smarty->assign('currentUrl', CURRENT_REQUEST_URL); |
|---|
| 203 | |
|---|
| 204 | // Compile HTML code |
|---|
| 205 | $tool_html = $smarty->fetch("templates/sites/portal.tpl"); |
|---|
| 206 | |
|---|
| 207 | /* |
|---|
| 208 | * Main content |
|---|
| 209 | */ |
|---|
| 210 | |
|---|
| 211 | // Reset ALL smarty SWITCH values |
|---|
| 212 | $smarty->assign('sectionTOOLCONTENT', false); |
|---|
| 213 | $smarty->assign('sectionMAINCONTENT', false); |
|---|
| 214 | |
|---|
| 215 | // Set section of Smarty template |
|---|
| 216 | $smarty->assign('sectionMAINCONTENT', true); |
|---|
| 217 | |
|---|
| 218 | // While in validation period, alert user that he should validate his account ASAP |
|---|
| 219 | if ($current_user && $current_user->getAccountStatus() == ACCOUNT_STATUS_VALIDATION) { |
|---|
| 220 | $smarty->assign('accountValidation', true); |
|---|
| 221 | $smarty->assign('validationTime', ($current_user->getNetwork()->getValidationGraceTime() / 60)); |
|---|
| 222 | } |
|---|
| 223 | |
|---|
| 224 | /* |
|---|
| 225 | * Network section |
|---|
| 226 | */ |
|---|
| 227 | |
|---|
| 228 | // Set network details |
|---|
| 229 | $smarty->assign('hotspotNetworkUrl', $network->getHomepageURL()); |
|---|
| 230 | $smarty->assign('hotspotNetworkName', $network->getName()); |
|---|
| 231 | $smarty->assign('networkLogoBannerUrl', COMMON_CONTENT_URL . NETWORK_LOGO_BANNER_NAME); |
|---|
| 232 | |
|---|
| 233 | // Get all network content and EXCLUDE user subscribed content |
|---|
| 234 | if ($current_user) { |
|---|
| 235 | $contents = Network::getCurrentNetwork()->getAllContent(true, $current_user); |
|---|
| 236 | } else { |
|---|
| 237 | $contents = Network::getCurrentNetwork()->getAllContent(); |
|---|
| 238 | } |
|---|
| 239 | |
|---|
| 240 | if ($contents) { |
|---|
| 241 | foreach ($contents as $content) { |
|---|
| 242 | $contentArray[] = array('isDisplayableAt' => $content->isDisplayableAt($node), 'userUI' => $content->getUserUI()); |
|---|
| 243 | } |
|---|
| 244 | |
|---|
| 245 | // Set all content of current node |
|---|
| 246 | $smarty->assign('networkContents', true); |
|---|
| 247 | $smarty->assign('networkContentArray', $contentArray); |
|---|
| 248 | } |
|---|
| 249 | |
|---|
| 250 | /* |
|---|
| 251 | * Node section |
|---|
| 252 | */ |
|---|
| 253 | |
|---|
| 254 | // Get all node content and EXCLUDE user subscribed content |
|---|
| 255 | if ($current_user) { |
|---|
| 256 | $contents = $node->getAllContent(true, $current_user); |
|---|
| 257 | } else { |
|---|
| 258 | $contents = $node->getAllContent(); |
|---|
| 259 | } |
|---|
| 260 | |
|---|
| 261 | // Set homepage details of node |
|---|
| 262 | $node_homepage = $node->getHomePageURL(); |
|---|
| 263 | if (!empty($node_homepage)) { |
|---|
| 264 | $smarty->assign('nodeHomepage', true); |
|---|
| 265 | $smarty->assign('nodeURL', $node_homepage); |
|---|
| 266 | $smarty->assign('nodeName', $node->getName()); |
|---|
| 267 | } |
|---|
| 268 | |
|---|
| 269 | if ($contents) { |
|---|
| 270 | foreach ($contents as $content) { |
|---|
| 271 | // Check for content requirements to show the "Show all contents" link |
|---|
| 272 | if (!$show_more_link) { |
|---|
| 273 | if ($content->getObjectType() == "ContentGroup") { |
|---|
| 274 | if (method_exists($content, "isArtisticContent") && method_exists($content, "isLocativeContent")) { |
|---|
| 275 | if ($content->isArtisticContent() && $content->isLocativeContent()) { |
|---|
| 276 | $show_more_link = true; |
|---|
| 277 | } |
|---|
| 278 | } |
|---|
| 279 | } |
|---|
| 280 | } |
|---|
| 281 | |
|---|
| 282 | $contentArray[] = array('isDisplayableAt' => $content->isDisplayableAt($node), 'userUI' => $content->getUserUI()); |
|---|
| 283 | } |
|---|
| 284 | |
|---|
| 285 | // Set all content of current node |
|---|
| 286 | $smarty->assign('nodeContents', true); |
|---|
| 287 | $smarty->assign('nodeContentArray', $contentArray); |
|---|
| 288 | } |
|---|
| 289 | |
|---|
| 290 | /* |
|---|
| 291 | * User section |
|---|
| 292 | */ |
|---|
| 293 | |
|---|
| 294 | if ($current_user) { |
|---|
| 295 | $contents = User::getCurrentUser()->getAllContent(); |
|---|
| 296 | |
|---|
| 297 | if ($contents) { |
|---|
| 298 | foreach ($contents as $content) { |
|---|
| 299 | $contentArray[] = array('userUI' => $content->getUserUI()); |
|---|
| 300 | } |
|---|
| 301 | |
|---|
| 302 | // Set all content of current node |
|---|
| 303 | $smarty->assign('userContents', true); |
|---|
| 304 | $smarty->assign('userContentArray', $contentArray); |
|---|
| 305 | } |
|---|
| 306 | } |
|---|
| 307 | |
|---|
| 308 | // Hyperlinks to full content display page |
|---|
| 309 | if ($show_more_link) { |
|---|
| 310 | $smarty->assign('showMoreLink', true); |
|---|
| 311 | $smarty->assign('currentNodeId', $current_node_id); |
|---|
| 312 | } |
|---|
| 313 | |
|---|
| 314 | // Compile HTML code |
|---|
| 315 | $html_body = $smarty->fetch("templates/sites/portal.tpl"); |
|---|
| 316 | |
|---|
| 317 | /* |
|---|
| 318 | * Render output |
|---|
| 319 | */ |
|---|
| 320 | |
|---|
| 321 | $ui = new MainUI(); |
|---|
| 322 | $ui->setToolContent($tool_html); |
|---|
| 323 | $ui->setMainContent($html_body); |
|---|
| 324 | $ui->display(); |
|---|
| 325 | |
|---|
| 326 | /* |
|---|
| 327 | * Local variables: |
|---|
| 328 | * tab-width: 4 |
|---|
| 329 | * c-basic-offset: 4 |
|---|
| 330 | * c-hanging-comment-ender-p: nil |
|---|
| 331 | * End: |
|---|
| 332 | */ |
|---|
| 333 | |
|---|
| 334 | ?> |
|---|