| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ |
|---|
| 5 | |
|---|
| 6 | // +-------------------------------------------------------------------+ |
|---|
| 7 | // | WiFiDog Authentication Server | |
|---|
| 8 | // | ============================= | |
|---|
| 9 | // | | |
|---|
| 10 | // | The WiFiDog Authentication Server is part of the WiFiDog captive | |
|---|
| 11 | // | portal suite. | |
|---|
| 12 | // +-------------------------------------------------------------------+ |
|---|
| 13 | // | PHP version 5 required. | |
|---|
| 14 | // +-------------------------------------------------------------------+ |
|---|
| 15 | // | Homepage: http://www.wifidog.org/ | |
|---|
| 16 | // | Source Forge: http://sourceforge.net/projects/wifidog/ | |
|---|
| 17 | // +-------------------------------------------------------------------+ |
|---|
| 18 | // | This program is free software; you can redistribute it and/or | |
|---|
| 19 | // | modify it under the terms of the GNU General Public License as | |
|---|
| 20 | // | published by the Free Software Foundation; either version 2 of | |
|---|
| 21 | // | the License, or (at your option) any later version. | |
|---|
| 22 | // | | |
|---|
| 23 | // | This program is distributed in the hope that it will be useful, | |
|---|
| 24 | // | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|---|
| 25 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
|---|
| 26 | // | GNU General Public License for more details. | |
|---|
| 27 | // | | |
|---|
| 28 | // | You should have received a copy of the GNU General Public License | |
|---|
| 29 | // | along with this program; if not, contact: | |
|---|
| 30 | // | | |
|---|
| 31 | // | Free Software Foundation Voice: +1-617-542-5942 | |
|---|
| 32 | // | 59 Temple Place - Suite 330 Fax: +1-617-542-2652 | |
|---|
| 33 | // | Boston, MA 02111-1307, USA gnu@gnu.org | |
|---|
| 34 | // | | |
|---|
| 35 | // +-------------------------------------------------------------------+ |
|---|
| 36 | |
|---|
| 37 | /** |
|---|
| 38 | * Displays the portal page |
|---|
| 39 | * |
|---|
| 40 | * @package WiFiDogAuthServer |
|---|
| 41 | * @author Philippe April |
|---|
| 42 | * @author Benoit Grégoire <bock@step.polymtl.ca> |
|---|
| 43 | * @author Max Horváth <max.horvath@freenet.de> |
|---|
| 44 | * @copyright 2004-2006 Philippe April |
|---|
| 45 | * @copyright 2004-2006 Benoit Grégoire, Technologies Coeus inc. |
|---|
| 46 | * @copyright 2006 Max Horváth, Horvath Web Consulting |
|---|
| 47 | * @version Subversion $Id$ |
|---|
| 48 | * @link http://www.wifidog.org/ |
|---|
| 49 | */ |
|---|
| 50 | |
|---|
| 51 | /** |
|---|
| 52 | * Load required files |
|---|
| 53 | */ |
|---|
| 54 | require_once ('../include/common.php'); |
|---|
| 55 | |
|---|
| 56 | require_once ('include/common_interface.php'); |
|---|
| 57 | require_once ('classes/Node.php'); |
|---|
| 58 | require_once ('classes/MainUI.php'); |
|---|
| 59 | require_once ('classes/Session.php'); |
|---|
| 60 | $smarty = SmartyWifidog::getObject(); |
|---|
| 61 | $db = AbstractDb::getObject(); |
|---|
| 62 | /* |
|---|
| 63 | * Check for missing URL switch |
|---|
| 64 | */ |
|---|
| 65 | if (isset ($_REQUEST['missing']) && $_REQUEST['missing'] == "url") { |
|---|
| 66 | $ui = MainUI::getObject(); |
|---|
| 67 | $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); |
|---|
| 68 | exit; |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | // Init values |
|---|
| 72 | $node = null; |
|---|
| 73 | $rolenames = ""; |
|---|
| 74 | $show_more_link = false; |
|---|
| 75 | |
|---|
| 76 | // Init session |
|---|
| 77 | $session = Session::getObject(); |
|---|
| 78 | |
|---|
| 79 | // Get the current user |
|---|
| 80 | $current_user = User :: getCurrentUser(); |
|---|
| 81 | |
|---|
| 82 | /* |
|---|
| 83 | * Start general request parameter processing section |
|---|
| 84 | */ |
|---|
| 85 | if (!empty ($_REQUEST['node_id'])) { |
|---|
| 86 | try { |
|---|
| 87 | $node = Node :: getObject($_REQUEST['node_id']); |
|---|
| 88 | $network = $node->getNetwork(); |
|---|
| 89 | } catch (Exception $e) { |
|---|
| 90 | $ui = MainUI::getObject(); |
|---|
| 91 | $ui->displayError($e->getMessage()); |
|---|
| 92 | exit; |
|---|
| 93 | } |
|---|
| 94 | } |
|---|
| 95 | else if (!empty ($_REQUEST['gw_id'])) {//This section MUST remain, the gw_id calling convention is hard_coded into the gateway |
|---|
| 96 | try { |
|---|
| 97 | $node = Node :: getObjectByGatewayId($_REQUEST['gw_id']); |
|---|
| 98 | $network = $node->getNetwork(); |
|---|
| 99 | } catch (Exception $e) { |
|---|
| 100 | $ui = MainUI::getObject(); |
|---|
| 101 | $ui->displayError($e->getMessage()); |
|---|
| 102 | exit; |
|---|
| 103 | } |
|---|
| 104 | } else { |
|---|
| 105 | $ui = MainUI::getObject(); |
|---|
| 106 | $ui->displayError(_("No Hotspot specified!")); |
|---|
| 107 | exit; |
|---|
| 108 | } |
|---|
| 109 | |
|---|
| 110 | /* |
|---|
| 111 | * If this node has a custom portal defined, and the network config allows it, |
|---|
| 112 | * redirect to the custom portal |
|---|
| 113 | */ |
|---|
| 114 | $custom_portal_url = $node->getCustomPortalRedirectUrl(); |
|---|
| 115 | |
|---|
| 116 | if (!empty ($custom_portal_url) && $network->getCustomPortalRedirectAllowed()) { |
|---|
| 117 | header("Location: {$custom_portal_url}"); |
|---|
| 118 | } |
|---|
| 119 | |
|---|
| 120 | $node_id = $node->getId(); |
|---|
| 121 | $portal_template = $node_id.".html"; |
|---|
| 122 | Node :: setCurrentNode($node); |
|---|
| 123 | |
|---|
| 124 | if (isset ($session)) { |
|---|
| 125 | if ($node) { |
|---|
| 126 | $session->set(SESS_NODE_ID_VAR, $node_id); |
|---|
| 127 | } |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| 130 | $smarty->assign('sectionTOOLCONTENT', false); |
|---|
| 131 | $smarty->assign('sectionMAINCONTENT', false); |
|---|
| 132 | |
|---|
| 133 | /* |
|---|
| 134 | * Render output |
|---|
| 135 | */ |
|---|
| 136 | |
|---|
| 137 | $ui = MainUI::getObject(); |
|---|
| 138 | $ui->setTitle(sprintf(_("%s portal for %s"), $network->getName(), $node->getName())); |
|---|
| 139 | $ui->setPageName('portal'); |
|---|
| 140 | /* |
|---|
| 141 | * Main content |
|---|
| 142 | */ |
|---|
| 143 | $welcome_msg = sprintf("<span>%s</span> <em>%s</em>",_("Welcome to"), $node->getName()); |
|---|
| 144 | $ui->addContent('page_header', "<div class='welcome_msg'><div class='welcome_msg_inner'>$welcome_msg</div></div>"); |
|---|
| 145 | // While in validation period, alert user that he should validate his account ASAP |
|---|
| 146 | if ($current_user && $current_user->getAccountStatus() == ACCOUNT_STATUS_VALIDATION) { |
|---|
| 147 | $validationMsgHtml = "<div id='warning_message_area'>\n"; |
|---|
| 148 | $validationMsgHtml .= _("An email with confirmation instructions was sent to your email address."); |
|---|
| 149 | $validationMsgHtml .= sprintf(_("Your account has been granted %s minutes of access to retrieve your email and validate your account."), ($current_user->getNetwork()->getValidationGraceTime() / 60)); |
|---|
| 150 | $validationMsgHtml .= "</div>\n"; |
|---|
| 151 | $ui->addContent('page_header', $validationMsgHtml); |
|---|
| 152 | } |
|---|
| 153 | |
|---|
| 154 | // Get all network content, but exclude user subscribed content if user is known |
|---|
| 155 | $content_rows = array (); |
|---|
| 156 | $network_id = $db->escapeString($network->getId()); |
|---|
| 157 | if ($current_user) { |
|---|
| 158 | $user_id = $db->escapeString($current_user->getId()); |
|---|
| 159 | $sql = "SELECT content_id, display_area, display_order FROM network_has_content WHERE network_id='$network_id' AND display_page='portal' AND content_id NOT IN (SELECT content_id FROM user_has_content WHERE user_id = '{$user_id}') ORDER BY display_area, display_order, subscribe_timestamp DESC"; |
|---|
| 160 | } else { |
|---|
| 161 | $sql = "SELECT content_id, display_area, display_order FROM network_has_content WHERE network_id='$network_id' AND display_page='portal' ORDER BY display_area, display_order, subscribe_timestamp DESC"; |
|---|
| 162 | } |
|---|
| 163 | $db->execSql($sql, $content_rows, false); |
|---|
| 164 | if ($content_rows) { |
|---|
| 165 | foreach ($content_rows as $content_row) { |
|---|
| 166 | $content = Content :: getObject($content_row['content_id']); |
|---|
| 167 | if ($content->isDisplayableAt($node)) { |
|---|
| 168 | $ui->addContent($content_row['display_area'], $content, $content_row['display_order']); |
|---|
| 169 | } |
|---|
| 170 | } |
|---|
| 171 | } |
|---|
| 172 | |
|---|
| 173 | // Get all node content and EXCLUDE user subscribed content |
|---|
| 174 | $content_rows = array (); |
|---|
| 175 | $node_id = $db->escapeString($node->getId()); |
|---|
| 176 | if ($current_user) { |
|---|
| 177 | $user_id = $db->escapeString($current_user->getId()); |
|---|
| 178 | $sql = "SELECT content_id, display_area, display_order FROM node_has_content WHERE node_id='$node_id' AND display_page='portal' AND content_id NOT IN (SELECT content_id FROM user_has_content WHERE user_id = '{$user_id}') ORDER BY display_area, display_order, subscribe_timestamp DESC"; |
|---|
| 179 | } else { |
|---|
| 180 | $sql = "SELECT content_id, display_area, display_order FROM node_has_content WHERE node_id='$node_id' AND display_page='portal' ORDER BY display_area, display_order, subscribe_timestamp DESC"; |
|---|
| 181 | } |
|---|
| 182 | $db->execSql($sql, $content_rows, false); |
|---|
| 183 | $showMoreLink = false; |
|---|
| 184 | if ($content_rows) { |
|---|
| 185 | foreach ($content_rows as $content_row) { |
|---|
| 186 | $content = Content :: getObject($content_row['content_id']); |
|---|
| 187 | if ($content->isDisplayableAt($node)) { |
|---|
| 188 | $ui->addContent($content_row['display_area'], $content, $content_row['display_order']); |
|---|
| 189 | } |
|---|
| 190 | } |
|---|
| 191 | } |
|---|
| 192 | |
|---|
| 193 | // Get all user content |
|---|
| 194 | $content_rows = array (); |
|---|
| 195 | if ($current_user) { |
|---|
| 196 | $user_id = $db->escapeString($current_user->getId()); |
|---|
| 197 | $sql = "SELECT content_id FROM user_has_content WHERE user_id = '{$user_id}' ORDER BY subscribe_timestamp DESC"; |
|---|
| 198 | $db->execSql($sql, $content_rows, false); |
|---|
| 199 | if ($content_rows) { |
|---|
| 200 | foreach ($content_rows as $content_row) { |
|---|
| 201 | $content = Content :: getObject($content_row['content_id']); |
|---|
| 202 | if ($content->isDisplayableAt($node)) { |
|---|
| 203 | $ui->addContent('main_area_middle', $content); |
|---|
| 204 | } |
|---|
| 205 | } |
|---|
| 206 | } |
|---|
| 207 | } |
|---|
| 208 | |
|---|
| 209 | if ($showMoreLink) { |
|---|
| 210 | $link_html = "<a href='{$base_ssl_path}content/?node_id={$currentNodeId}'>"._("Show all available contents for this hotspot")."</a>\n"; |
|---|
| 211 | $ui->addContent('main_area_middle', $link_html); |
|---|
| 212 | } |
|---|
| 213 | $ui->display(); |
|---|
| 214 | |
|---|
| 215 | /* |
|---|
| 216 | * Local variables: |
|---|
| 217 | * tab-width: 4 |
|---|
| 218 | * c-basic-offset: 4 |
|---|
| 219 | * c-hanging-comment-ender-p: nil |
|---|
| 220 | * End: |
|---|
| 221 | */ |
|---|
| 222 | ?> |
|---|