Changeset 742
- Timestamp:
- 09/10/05 20:05:18 (8 years ago)
- Location:
- trunk/wifidog-auth
- Files:
-
- 10 modified
-
ChangeLog (modified) (1 diff)
-
wifidog/admin/content_admin.php (modified) (1 diff)
-
wifidog/admin/generic_object_admin.php (modified) (4 diffs)
-
wifidog/classes/Content.php (modified) (1 diff)
-
wifidog/classes/GenericObject.php (modified) (1 diff)
-
wifidog/classes/MainUI.php (modified) (7 diffs)
-
wifidog/classes/Network.php (modified) (34 diffs)
-
wifidog/classes/Node.php (modified) (22 diffs)
-
wifidog/classes/User.php (modified) (1 diff)
-
wifidog/include/schema_validate.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wifidog-auth/ChangeLog
r741 r742 1 2005-09-10 Benoit Grégoire <bock@step.polymtl.ca> 2 * Add UI to add a new Network 3 * Improve UI to add a new Node and new Content 4 1 5 2005-09-10 Philippe April <philippe@ilesansfil.org> 2 6 * signup.php: Fixed bug in detecting is the user is already part of the -
trunk/wifidog-auth/wifidog/admin/content_admin.php
r737 r742 34 34 $html .= '<form action="'.GENERIC_OBJECT_ADMIN_ABS_HREF.'" method="get">'; 35 35 $html .= "<input type=submit name='new_submit' value='"._("Add new content")."'>\n"; 36 $html .= "<input type='hidden' name='action' value='new '>\n";36 $html .= "<input type='hidden' name='action' value='new_ui'>\n"; 37 37 $html .= "<input type='hidden' name='object_class' value='Content'>\n"; 38 38 $html .= '</form>'; -
trunk/wifidog-auth/wifidog/admin/generic_object_admin.php
r734 r742 21 21 /**@file generic_object_admin.php 22 22 * A simple interface to edit any object that implements the GenericObject interface. The php file takes the following params: 23 * $_REQUEST['action']: new, edit, delete, preview (also save, but not meant for calling from outside this file) 24 * $_REQUEST['object_id']: The id of the object ot be edited 25 * $_REQUEST['object_class']: The class name of the object ot be edited 26 * $_REQUEST['node_id']: In preview mode, the current node to simulate display 27 * $_REQUEST['debug']: If present and non empty, the $_REQUEST variables will be displayed 23 * $_REQUEST['action']: new, edit, delete, preview, process_new_ui, new_ui (also 24 * save, but not meant for calling from outside this file) $_REQUEST 25 * ['object_id']: The id of the object ot be edited $_REQUEST['object_class']: 26 * The class name of the object ot be edited $_REQUEST['node_id']: In preview 27 * mode, the current node to simulate display $_REQUEST['debug']: If present 28 * and non empty, the $_REQUEST variables will be displayed 28 29 * @author Copyright (C) 2005 Benoit Grégoire <bock@step.polymtl.ca>, 29 30 * Technologies Coeus inc. … … 50 51 $object = call_user_func(array ($class, 'createNewObject')); 51 52 $_REQUEST['action'] = 'edit'; 52 } else { 53 if (empty ($_REQUEST['object_id'])) { 54 echo "<div class='errormsg'>"._("Sorry, the 'object_id' parameter must be specified")."</div>\n"; 53 } 54 else if ($_REQUEST['action'] == 'process_new_ui') { 55 $object = call_user_func(array ($class, 'processCreateNewObjectUI')); 56 if (!$object) { 57 echo "<div class='errormsg'>"._("Sorry, the object couldn't be created. You probably didn't fill the form properly")."</div>\n"; 55 58 exit; 56 59 } 60 $_REQUEST['action'] = 'edit'; 61 } 62 else if ($_REQUEST['action'] == 'new_ui') { 63 //No need for an object 64 } 65 else { 57 66 $object = call_user_func(array ($class, 'getObject'), $_REQUEST['object_id']); 58 67 } 59 68 60 69 if ($_REQUEST['action'] == 'save') { 61 $ html .= $object->processAdminUI();62 $object = call_user_func(array ($class, 'getObject'), $_REQUEST['object_id']);70 $object->processAdminUI(); 71 //$object = call_user_func(array ($class, 'getObject'), $_REQUEST['object_id']); 63 72 $_REQUEST['action'] = 'edit'; 64 73 } … … 74 83 } 75 84 } 85 if ($_REQUEST['action'] == 'new_ui') { 86 87 $html .= "<form action='".GENERIC_OBJECT_ADMIN_ABS_HREF."' method='post'>"; 88 $html .= "<input type='hidden' name='object_class' value='".$class."'>\n"; 89 $html .= call_user_func(array ($class, 'getCreateNewObjectUI')); 90 $html .= "<input type='hidden' name='action' value='process_new_ui'>\n"; 91 $html .= "<input type=submit name='new_ui_submit' value='"._("Create")." ".$class."'>\n"; 92 $html .= '</form>'; 93 76 94 77 if ($_REQUEST['action'] == 'edit') { 95 } 96 else if ($_REQUEST['action'] == 'edit') { 97 if (!$object) { 98 echo "<div class='errormsg'>"._("Sorry, the 'object_id' parameter must be specified")."</div>\n"; 99 exit; 100 } 78 101 $common_input = ''; 79 102 if (!empty ($_REQUEST['debug'])) { … … 102 125 $html .= '</form>'; 103 126 } 104 105 if ($_REQUEST['action'] == 'preview') { 127 else if ($_REQUEST['action'] == 'preview') { 106 128 if (empty ($_REQUEST['node_id'])) { 107 129 $node_id = null; -
trunk/wifidog-auth/wifidog/classes/Content.php
r708 r742 77 77 return $object; 78 78 } 79 80 /** Get an interface to create a new object. 81 * @return html markup 82 */ 83 public static function getCreateNewObjectUI() 84 { 85 $html =''; 86 $html .= _("You must select a content type: "); 87 $i = 0; 88 foreach (self :: getAvailableContentTypes() as $classname) 89 { 90 $tab[$i][0] = $classname; 91 $tab[$i][1] = $classname; 92 $i ++; 93 } 94 $name = "new_content_content_type"; 95 $default = 'TrivialLangstring'; 96 $html .= FormSelectGenerator :: generateFromArray($tab, $default, $name, "Content", false); 97 98 return $html; 99 } 100 101 /** Process the new object interface. 102 * Will return the new object if the user has the credentials 103 * necessary (Else an exception is thrown) and and the form was fully 104 * filled (Else the object returns null). 105 * @return the node object or null if no new node was created. 106 */ 107 static function processCreateNewObjectUI() 108 { 109 $retval = null; 110 $name = "new_content_content_type"; 111 $content_type = FormSelectGenerator :: getResult($name, "Content"); 112 if($content_type) 113 { 114 $retval = self::createNewObject($content_type); 115 } 116 117 return $retval; 118 } 119 79 120 /** Get the Content object, specific to it's content type 80 121 * @param $content_id The content id -
trunk/wifidog-auth/wifidog/classes/GenericObject.php
r705 r742 37 37 */ 38 38 static public function getObject($id); 39 /** Create a new Contentobject in the database39 /** Create a new object in the database 40 40 * @see GenericObject 41 41 * @return the newly created object, or null if there was an error 42 42 */ 43 43 static function createNewObject(); 44 45 /** Get an interface to create a new object. 46 * @return html markup 47 */ 48 public static function getCreateNewObjectUI(); 49 50 /** Process the new object interface. 51 * Will return the new object if the user has the credentials 52 * necessary (Else an exception is thrown) and and the form was fully 53 * filled (Else the object returns null). 54 * @return the node object or null if no new node was created. 55 */ 56 static function processCreateNewObjectUI(); 57 44 58 45 59 /** Retreives the id of the object -
trunk/wifidog-auth/wifidog/classes/MainUI.php
r736 r742 25 25 */ 26 26 require_once BASEPATH.'include/common.php'; 27 /** @note We put a call to validate_schema() here so it systematically called28 * from any UI page, but not from any machine readable pages29 */ 30 require_once BASEPATH.'include/schema_validate.php';31 validate_schema();32 27 /** @note We put a call to validate_schema() here so it systematically called 28 * from any UI page, but not from any machine readable pages 29 */ 30 require_once BASEPATH.'include/schema_validate.php'; 31 validate_schema(); 32 33 33 if (CONF_USE_CRON_FOR_DB_CLEANUP == false) 34 34 { … … 55 55 $this->title = Network :: getCurrentNetwork()->getName().' '._("authentication server"); //Default title 56 56 } 57 57 58 58 /** Check if the tool section is enabled 59 59 * … … 63 63 return $this->tool_section_enabled; 64 64 } 65 65 66 66 public function setToolSectionEnabled($status) 67 67 { … … 103 103 $html = ''; 104 104 105 if ($current_user && $current_user->isNobody()) 106 { 107 $html .= _("You do not have permissions to access any administration functions."); 108 } else { 109 110 $html .= "<ul class='admin_menu_list'>\n"; 111 112 if ($current_user && $current_user->isSuperAdmin()) 113 { 114 $html .= "<li><a href='user_log.php'>"._("User logs")."</a></li>\n"; 115 $html .= "<li><a href='online_users.php'>"._("Online Users")."</a></li>\n"; 116 $html .= "<li><a href='stats.php'>"._("Statistics")."</a></li>\n"; 117 $html .= "<li><a href='import_user_database.php'>"._("Import NoCat user database")."</a></li>\n"; 118 $html .= "<li><a href='content_admin.php'>"._("Content manager")."</a></li>\n"; 119 } 120 121 $html .= "</ul>\n"; 122 123 // If the user is super admin OR owner of at least one hotspot show the menu 124 if ($current_user && ($current_user->isSuperAdmin() || $current_user->isOwner())) 125 { 126 /* Node admin */ 127 $html .= "<div class='admin_section_container'>\n"; 128 $html .= '<form action="'.GENERIC_OBJECT_ADMIN_ABS_HREF.'" method="post">'; 129 $html .= "<div class='admin_section_title'>"._("Node administration:")." </div>\n"; 130 131 $html .= "<div class='admin_section_data'>\n"; 132 133 if ($current_user->isSuperAdmin()) 134 $sql_additional_where = ''; 135 else 136 $sql_additional_where = "AND node_id IN (SELECT node_id from node_stakeholders WHERE is_owner = true AND user_id='".$current_user->getId()."')"; 137 $html .= "<div id='NodeSelector'>\n"; 138 $html .= Node :: getSelectNodeUI('object_id', $sql_additional_where); 139 $html .= "</div>\n"; 140 $html .= "</div>\n"; 141 $html .= "<div class='admin_section_tools'>\n"; 142 143 $html .= "<input type='hidden' name='object_class' value='Node'>\n"; 144 $html .= "<input type='hidden' name='action' value='edit'>\n"; 145 $html .= "<input type='submit' name='edit_submit' value='"._("Edit")."'>\n"; 146 147 $html .= "</div>\n"; 148 $html .= '</form>'; 149 $html .= "</div>\n"; 150 } 151 152 /* Network admin */ 153 if ($current_user && $current_user->isSuperAdmin()) 154 { 155 $html .= "<div class='admin_section_container'>\n"; 156 $html .= '<form action="'.GENERIC_OBJECT_ADMIN_ABS_HREF.'" method="post">'; 157 $html .= "<div class='admin_section_title'>"._("Network administration:")." </div>\n"; 158 159 $html .= "<div class='admin_section_data'>\n"; 160 $html .= "<input type='hidden' name='action' value='edit'>\n"; 161 $html .= "<input type='hidden' name='object_class' value='Network'><br>\n"; 162 $html .= Network :: getSelectNetworkUI('object_id'); 163 $html .= "</div>\n"; 164 $html .= "<div class='admin_section_tools'>\n"; 165 166 $html .= "<input type=submit name='edit_submit' value='"._("Edit")."'>\n"; 167 $html .= "</div>\n"; 168 $html .= '</form>'; 169 $html .= "</div>\n"; 170 } 171 } 105 if ($current_user && $current_user->isNobody()) 106 { 107 $html .= _("You do not have permissions to access any administration functions."); 108 } 109 else 110 { 111 112 if ($current_user && $current_user->isSuperAdmin()) 113 { 114 $html .= "<li><a href='user_log.php'>"._("User logs")."</a></li>\n"; 115 $html .= "<li><a href='online_users.php'>"._("Online Users")."</a></li>\n"; 116 $html .= "<li><a href='stats.php'>"._("Statistics")."</a></li>\n"; 117 $html .= "<li><a href='import_user_database.php'>"._("Import NoCat user database")."</a></li>\n"; 118 $html .= "<li><a href='content_admin.php'>"._("Content manager")."</a></li>\n"; 119 } 120 121 $html .= "</ul>\n"; 122 123 // If the user is super admin OR owner of at least one hotspot show the menu 124 if ($current_user && ($current_user->isSuperAdmin() || $current_user->isOwner())) 125 { 126 /* Node admin */ 127 $html .= "<div class='admin_section_container'>\n"; 128 $html .= '<form action="'.GENERIC_OBJECT_ADMIN_ABS_HREF.'" method="post">'; 129 $html .= "<div class='admin_section_title'>"._("Node administration:")." </div>\n"; 130 131 $html .= "<div class='admin_section_data'>\n"; 132 133 if ($current_user->isSuperAdmin()) 134 $sql_additional_where = ''; 135 else 136 $sql_additional_where = "AND node_id IN (SELECT node_id from node_stakeholders WHERE is_owner = true AND user_id='".$current_user->getId()."')"; 137 $html .= "<div id='NodeSelector'>\n"; 138 $html .= Node :: getSelectNodeUI('object_id', $sql_additional_where); 139 $html .= "</div>\n"; 140 $html .= "</div>\n"; 141 $html .= "<div class='admin_section_tools'>\n"; 142 143 $html .= "<input type='hidden' name='object_class' value='Node'>\n"; 144 $html .= "<input type='hidden' name='action' value='edit'>\n"; 145 $html .= "<input type='submit' name='edit_submit' value='"._("Edit")."'>\n"; 146 147 $html .= "</div>\n"; 148 $html .= '</form>'; 149 $html .= "<div class='admin_section_tools'>\n"; 150 $html .= '<form action="'.GENERIC_OBJECT_ADMIN_ABS_HREF.'" method="post">'; 151 $html .= "<input type='hidden' name='action' value='new_ui'>\n"; 152 $html .= "<input type='hidden' name='object_class' value='Node'><br>\n"; 153 $html .= "<input type=submit name='new_submit' value='"._("Create")."'>\n"; 154 $html .= "</form>\n"; 155 $html .= "</div>\n"; 156 $html .= "</div>\n"; 157 } 158 159 /* Network admin */ 160 if ($current_user && $current_user->isSuperAdmin()) 161 { 162 $html .= "<div class='admin_section_container'>\n"; 163 $html .= '<form action="'.GENERIC_OBJECT_ADMIN_ABS_HREF.'" method="post">'; 164 $html .= "<div class='admin_section_title'>"._("Network administration:")." </div>\n"; 165 166 $html .= "<div class='admin_section_data'>\n"; 167 $html .= "<input type='hidden' name='action' value='edit'>\n"; 168 $html .= "<input type='hidden' name='object_class' value='Network'><br>\n"; 169 $html .= Network :: getSelectNetworkUI('object_id'); 170 $html .= "</div>\n"; 171 $html .= "<div class='admin_section_tools'>\n"; 172 173 $html .= "<input type=submit name='edit_submit' value='"._("Edit")."'>\n"; 174 $html .= "</div>\n"; 175 $html .= "</form>\n"; 176 $html .= "<div class='admin_section_tools'>\n"; 177 $html .= '<form action="'.GENERIC_OBJECT_ADMIN_ABS_HREF.'" method="post">'; 178 $html .= "<input type='hidden' name='action' value='new_ui'>\n"; 179 $html .= "<input type='hidden' name='object_class' value='Network'><br>\n"; 180 $html .= "<input type=submit name='new_submit' value='"._("Create")."'>\n"; 181 $html .= "</form>\n"; 182 $html .= "</div>\n"; 183 $html .= "</div>\n"; 184 } 185 } 172 186 break; 173 187 default : … … 327 341 328 342 $html .= "<body>"."\n"; 329 if (isset($_REQUEST['debug_request']))343 if (isset ($_REQUEST['debug_request'])) 330 344 { 331 345 $html .= '<pre>'; 332 $html .= print_r($_REQUEST, true);346 $html .= print_r($_REQUEST, true); 333 347 $html .= '</pre>'; 334 348 } 335 349 $html .= '<div class="outer_container">'."\n"; 336 350 337 338 if($this->isToolSectionEnabled()) 351 if ($this->isToolSectionEnabled()) 339 352 { 340 353 /**** Tools ******/ 341 354 $html .= $this->getToolContent(); 342 355 343 356 /**** Main section ****/ 344 357 $html .= "<div id='main_section'>"."\n"; … … 367 380 { 368 381 $html = "<p>$errmsg</p>\n"; 369 $email = Network ::getCurrentNetwork()->getTechSupportEmail();370 if (!empty($email))371 { 372 $html .= "<p>"._("Please get in touch with ")."<a href='{$email}'>{$email}</a></p>";382 $email = Network :: getCurrentNetwork()->getTechSupportEmail(); 383 if (!empty ($email)) 384 { 385 $html .= "<p>"._("Please get in touch with ")."<a href='{$email}'>{$email}</a></p>"; 373 386 } 374 387 $this->setMainContent($html); … … 378 391 } //End class 379 392 ?> 393 -
trunk/wifidog-auth/wifidog/classes/Network.php
r733 r742 1 1 <?php 2 2 3 3 4 /********************************************************************\ … … 72 73 { 73 74 $retval = null; 74 global $db;75 $sql = "SELECT network_id FROM networks WHERE is_default_network=TRUE ORDER BY creation_date LIMIT 1";76 $network_row = null;77 $db->ExecSqlUniqueRes($sql, $network_row, false);78 if ($network_row == null)79 {80 throw new Exception(_("Network::getDefaultNetwork: Fatal error: Unable to find the default network!"));81 }82 $retval = new self($network_row['network_id']);83 return $retval; 84 } 85 75 global $db; 76 $sql = "SELECT network_id FROM networks WHERE is_default_network=TRUE ORDER BY creation_date LIMIT 1"; 77 $network_row = null; 78 $db->ExecSqlUniqueRes($sql, $network_row, false); 79 if ($network_row == null) 80 { 81 throw new Exception(_("Network::getDefaultNetwork: Fatal error: Unable to find the default network!")); 82 } 83 $retval = new self($network_row['network_id']); 84 return $retval; 85 } 86 86 87 /** Get the current network for which the portal is displayed or to which a user is physically connected. 87 88 * @param $real_network_only NOT IMPLEMENTED YET true or false. If true, … … 100 101 else 101 102 { 102 $retval = Network ::getDefaultNetwork();103 $retval = Network :: getDefaultNetwork(); 103 104 } 104 105 return $retval; … … 107 108 /** Create a new Content object in the database 108 109 * @see GenericObject 110 * @param $network_id The network id of the new network. If absent, will be 111 * assigned a guid. 109 112 * @return the newly created object, or null if there was an error 110 113 */ 111 static function createNewObject() 112 { 113 return null; /* Unsupported */ 114 static function createNewObject($network_id = null) 115 { 116 global $db; 117 if(empty($network_id)) 118 { 119 $network_id = get_guid(); 120 } 121 $network_id = $db->EscapeString($network_id); 122 123 $sql = "INSERT INTO networks (network_id, network_authenticator_class) VALUES ('$network_id', 'AuthenticatorLocalUser')"; 124 125 if (!$db->ExecSqlUpdate($sql, false)) 126 { 127 throw new Exception(_('Unable to insert the new network in the database!')); 128 } 129 $object = new self($network_id); 130 return $object; 131 114 132 } 115 133 … … 172 190 } 173 191 192 /** Get an interface to create a new network. 193 * @return html markup 194 */ 195 public static function getCreateNewObjectUI() 196 { 197 $html = ''; 198 $html .= _("Create new network with id")." \n"; 199 $name = "new_network_id"; 200 $html .= "<input type='text' size='10' name='{$name}'>\n"; 201 return $html; 202 203 } 204 205 /** Process the new object interface. 206 * Will return the new object if the user has the credentials and the form was fully filled. 207 * @return the Network object or null if no new Network was created. 208 */ 209 static function processCreateNewObjectUI() 210 { 211 $retval = null; 212 $name = "new_network_id"; 213 if (!empty ($_REQUEST[$name])) 214 { 215 $network_id = $_REQUEST[$name]; 216 if ($network_id) 217 { 218 if (!User :: getCurrentUser()->isSuperAdmin()) 219 { 220 throw new Exception(_("Access denied")); 221 } 222 $retval = self :: createNewObject($network_id); 223 } 224 } 225 return $retval; 226 } 227 174 228 private function __construct($p_network_id) 175 229 { … … 217 271 return $retval; 218 272 } 219 273 220 274 /** 221 * Retrieves the network name275 * Retrieves the network name 222 276 * @return A string 223 */277 */ 224 278 public function getName() 225 279 { … … 230 284 * @param $value The new value 231 285 * @return true on success, false on failure 232 */286 */ 233 287 function setName($value) 234 288 { … … 245 299 246 300 /** 247 * Retrieves the network's creation date301 * Retrieves the network's creation date 248 302 * @return A string 249 */303 */ 250 304 public function getCreationDate() 251 305 { … … 298 352 return $retval; 299 353 } 300 354 301 355 /** Retreives the authenticator's parameters 302 356 * @return A string */ … … 321 375 return $retval; 322 376 } 323 377 324 378 /** Get the Authenticator object for this network 379 * @todo: Reimplement this using the muich safer call_user_func_array 380 * instead of eval() Benoitg 2005-09-10 325 381 * @return a subclass of Authenticator */ 326 382 public function getAuthenticator() … … 336 392 return eval ($objstring); 337 393 } 338 394 339 395 /** Is the network the default network? 340 396 * @return true or false */ 341 397 public function isDefaultNetwork() 342 398 { 343 ($this->mRow['is_default_network'] =='t')?$retval=true:$retval=false;399 ($this->mRow['is_default_network'] == 't') ? $retval = true : $retval = false; 344 400 return $retval; 345 401 } … … 383 439 return $retval; 384 440 } 385 441 386 442 /** Retreives the FROM adress of the validation email 387 443 * @return A string */ … … 406 462 return $retval; 407 463 } 408 464 409 465 /** Can an account be connected more than once at the same time? 410 466 * @return true or false */ … … 423 479 { 424 480 global $db; 425 $value ?$value='TRUE':$value='FALSE';481 $value ? $value = 'TRUE' : $value = 'FALSE'; 426 482 $retval = $db->ExecSqlUpdate("UPDATE networks SET allow_multiple_login = {$value} WHERE network_id = '{$this->getId()}'", false); 427 483 $this->refresh(); … … 434 490 public function getSplashOnlyNodesAllowed() 435 491 { 436 return (($this->mRow['allow_splash_only_nodes'] =='t') ? true : false);492 return (($this->mRow['allow_splash_only_nodes'] == 't') ? true : false); 437 493 } 438 494 … … 446 502 { 447 503 global $db; 448 $value ?$value='TRUE':$value='FALSE';504 $value ? $value = 'TRUE' : $value = 'FALSE'; 449 505 $retval = $db->ExecSqlUpdate("UPDATE networks SET allow_splash_only_nodes = {$value} WHERE network_id = '{$this->getId()}'", false); 450 506 $this->refresh(); 451 507 } 452 508 return $retval; 453 } 454 455 /** Get's the splash-only user. This is the user that people logged-in at a splash-only hotspot will show up as. This user always has multiple-login capabilities.456 * @param $username The username of the user457 * @param $account_origin The account origin458 * @return a User object459 */509 } 510 511 /** Get's the splash-only user. This is the user that people logged-in at a splash-only hotspot will show up as. This user always has multiple-login capabilities. 512 * @param $username The username of the user 513 * @param $account_origin The account origin 514 * @return a User object 515 */ 460 516 public function getSplashOnlyUser() 461 517 { 462 518 $username = 'SPLASH_ONLY_USER'; 463 519 464 $user = User ::getUserByUsernameAndOrigin($username, $this);465 if (!$user)466 { 467 $user = User ::createUser(get_guid(), $username, $this, '', '');468 $user->setAccountStatus(ACCOUNT_STATUS_ALLOWED); 469 } 520 $user = User :: getUserByUsernameAndOrigin($username, $this); 521 if (!$user) 522 { 523 $user = User :: createUser(get_guid(), $username, $this, '', ''); 524 $user->setAccountStatus(ACCOUNT_STATUS_ALLOWED); 525 } 470 526 return $user; 471 527 } … … 474 530 public function getCustomPortalRedirectAllowed() 475 531 { 476 return (($this->mRow['allow_custom_portal_redirect'] =='t') ? true : false);532 return (($this->mRow['allow_custom_portal_redirect'] == 't') ? true : false); 477 533 } 478 534 … … 486 542 { 487 543 global $db; 488 $value ?$value='TRUE':$value='FALSE';544 $value ? $value = 'TRUE' : $value = 'FALSE'; 489 545 $retval = $db->ExecSqlUpdate("UPDATE networks SET allow_custom_portal_redirect = {$value} WHERE network_id = '{$this->getId()}'", false); 490 546 $this->refresh(); 491 547 } 492 548 return $retval; 493 } 549 } 550 551 /** Does the user have admin access to this network? 552 * @return true our false*/ 553 function hasAdminAccess(User $user) 554 { 555 global $db; 556 $retval = false; 557 if ($user != null) 558 { 559 $user_id = $user->getId(); 560 $retval = false; 561 $db->ExecSqlUniqueRes("SELECT * FROM network_stakeholders WHERE is_admin = true AND network_id='{$this->id}' AND user_id='{$user_id}'", $row, false); 562 if ($row != null) 563 { 564 $retval = true; 565 } 566 else 567 if ($user->isSuperAdmin()) 568 { 569 $retval = true; 570 } 571 } 572 return $retval; 573 } 494 574 495 575 /**Get an array of all Content linked to the network … … 538 618 $html .= "</div>\n"; 539 619 $html .= "</div>\n"; 540 620 541 621 // name 542 622 $html .= "<div class='admin_section_container'>\n"; … … 569 649 $html .= "</div>\n"; 570 650 571 572 651 // network_authenticator_class 573 652 $html .= "<div class='admin_section_container'>\n"; … … 588 667 $html .= "<input type='text' size ='50' value='$value' name='$name'>\n"; 589 668 $html .= "</div>\n"; 590 $html .= "</div>\n"; 591 669 $html .= "</div>\n"; 670 592 671 // is_default_network 593 672 $html .= "<div class='admin_section_container'>\n"; … … 595 674 $html .= "<div class='admin_section_data'>\n"; 596 675 $name = "network_".$this->getId()."_is_default_network"; 597 $this->isDefaultNetwork() ? $checked='CHECKED': $checked='';676 $this->isDefaultNetwork() ? $checked = 'CHECKED' : $checked = ''; 598 677 $html .= "<input type='checkbox' name='$name' $checked>\n"; 599 678 $html .= "</div>\n"; 600 $html .= "</div>\n"; 601 679 $html .= "</div>\n"; 680 602 681 // validation_grace_time 603 682 $html .= "<div class='admin_section_container'>\n"; … … 609 688 $html .= "</div>\n"; 610 689 $html .= "</div>\n"; 611 690 612 691 // validation_email_from_address 613 692 $html .= "<div class='admin_section_container'>\n"; … … 619 698 $html .= "</div>\n"; 620 699 $html .= "</div>\n"; 621 700 622 701 // allow_multiple_login 623 702 $html .= "<div class='admin_section_container'>\n"; … … 625 704 $html .= "<div class='admin_section_data'>\n"; 626 705 $name = "network_".$this->getId()."_allow_multiple_login"; 627 $this->getMultipleLoginAllowed() ? $checked='CHECKED': $checked='';706 $this->getMultipleLoginAllowed() ? $checked = 'CHECKED' : $checked = ''; 628 707 $html .= "<input type='checkbox' name='$name' $checked>\n"; 629 708 $html .= "</div>\n"; 630 709 $html .= "</div>\n"; 631 710 632 711 // allow_splash_only_nodes 633 712 $html .= "<div class='admin_section_container'>\n"; … … 635 714 $html .= "<div class='admin_section_data'>\n"; 636 715 $name = "network_".$this->getId()."_allow_splash_only_nodes"; 637 $this->getSplashOnlyNodesAllowed() ? $checked='CHECKED': $checked='';716 $this->getSplashOnlyNodesAllowed() ? $checked = 'CHECKED' : $checked = ''; 638 717 $html .= "<input type='checkbox' name='$name' $checked>\n"; 639 718 $html .= "</div>\n"; 640 719 $html .= "</div>\n"; 641 720 642 721 // allow_custom_portal_redirect 643 722 $html .= "<div class='admin_section_container'>\n"; … … 645 724 $html .= "<div class='admin_section_data'>\n"; 646 725 $name = "network_".$this->getId()."_allow_custom_portal_redirect"; 647 $this->getCustomPortalRedirectAllowed() ? $checked='CHECKED': $checked='';726 $this->getCustomPortalRedirectAllowed() ? $checked = 'CHECKED' : $checked = ''; 648 727 $html .= "<input type='checkbox' name='$name' $checked>\n"; 649 728 $html .= "</div>\n"; 650 729 $html .= "</div>\n"; 651 730 652 731 // network_stakeholders 653 732 $html .= "<div class='admin_section_container'>\n"; … … 659 738 $html .= "WRITEME!"; 660 739 $html .= "</div>\n"; 661 $html .= "</div>\n"; 662 740 $html .= "</div>\n"; 741 663 742 // Create new nodes 664 743 $html .= "<div class='admin_section_container'>\n"; … … 666 745 667 746 $html .= "<div class='admin_section_data'>\n"; 668 $name = "network_{$this->getId()}_new_node_id"; 669 $html .= "<input type='text' size='10' name='{$name}'>\n";747 748 $html .= Node :: getCreateNewObjectUI($this); 670 749 671 750 $html .= "<div class='admin_section_tools'>\n"; … … 714 793 //pretty_print_r($_REQUEST); 715 794 $user = User :: getCurrentUser(); 716 if (!$ user->isSuperAdmin())795 if (!$this->hasAdminAccess($user)) 717 796 { 718 797 throw new Exception(_('Access denied!')); … … 722 801 $name = "network_".$this->getId()."_name"; 723 802 $this->setName($_REQUEST[$name]); 724 803 725 804 // homepage_url 726 805 $name = "network_".$this->getId()."_homepage_url"; 727 806 $this->setHomepageURL($_REQUEST[$name]); 728 807 729 730 808 // tech_support_email 731 809 $name = "network_".$this->getId()."_tech_support_email"; … … 739 817 $name = "network_".$this->getId()."_network_authenticator_params"; 740 818 $this->setAuthenticatorConstructorParams($_REQUEST[$name]); 741 819 742 820 // is_default_network 743 821 $name = "network_".$this->getId()."_is_default_network"; 744 if ($_REQUEST[$name]=='on')822 if ($_REQUEST[$name] == 'on') 745 823 $this->setAsDefaultNetwork(); 746 824 747 825 // validation_grace_time 748 826 $name = "network_".$this->getId()."_validation_grace_time"; 749 827 $this->setValidationGraceTime($_REQUEST[$name]); 750 828 751 829 // validation_email_from_address 752 830 $name = "network_".$this->getId()."_validation_email_from_address"; 753 $this->setValidationEmailFromAddress($_REQUEST[$name]); 754 831 $this->setValidationEmailFromAddress($_REQUEST[$name]); 832 755 833 // allow_multiple_login 756 834 $name = "network_".$this->getId()."_allow_multiple_login"; 757 $this->setMultipleLoginAllowed(empty ($_REQUEST[$name])?false:true);758 835 $this->setMultipleLoginAllowed(empty ($_REQUEST[$name]) ? false : true); 836 759 837 // allow_splash_only_nodes 760 838 $name = "network_".$this->getId()."_allow_splash_only_nodes"; 761 $this->setSplashOnlyNodesAllowed(empty ($_REQUEST[$name])?false:true);839 $this->setSplashOnlyNodesAllowed(empty ($_REQUEST[$name]) ? false : true); 762 840 763 841 // allow_custom_portal_redirect 764 842 $name = "network_".$this->getId()."_allow_custom_portal_redirect"; 765 $this->setCustomPortalRedirectAllowed(empty ($_REQUEST[$name])?false:true);766 843 $this->setCustomPortalRedirectAllowed(empty ($_REQUEST[$name]) ? false : true); 844 767 845 // Node creation 768 $create_new_node = "network_{$this->getId()}_create_node"; 769 $new_node_id = "network_{$this->getId()}_new_node_id"; 770 if (!empty ($_REQUEST[$create_new_node])) 771 if (!empty ($_REQUEST[$new_node_id])) 772 { 773 Node :: createNewNode($_REQUEST[$new_node_id], $this); 774 $url = GENERIC_OBJECT_ADMIN_ABS_HREF."?".http_build_query(array ("object_class" => "Node", "action" => "edit", "object_id" => $_REQUEST[$new_node_id])); 775 header("Location: {$url}"); 776 } 777 else 778 echo _("You MUST enter a node ID."); 779 846 $new_node = Node :: processCreateNewObjectUI(); 847 if ($new_node) 848 { 849 $url = GENERIC_OBJECT_ADMIN_ABS_HREF."?".http_build_query(array ("object_class" => "Node", "action" => "edit", "object_id" => $new_node->getId())); 850 header("Location: {$url}"); 851 } 780 852 // Content management 781 853 foreach ($this->getAllContent() as $content) … … 821 893 public function delete(& $errmsg) 822 894 { 823 $errmsg = _("Network::delete() not supported"); 824 return false; 825 } 826 895 $retval = false; 896 $user = User :: getCurrentUser(); 897 if (!$user->isSuperAdmin()) 898 { 899 $errmsg = _('Access denied (must have super admin access)'); 900 } 901 else 902 { 903 global $db; 904 $id = $db->EscapeString($this->getId()); 905 if (!$db->ExecSqlUpdate("DELETE FROM networks WHERE network_id='{$id}'", false)) 906 { 907 $errmsg = _('Could not delete network!'); 908 } 909 else 910 { 911 $retval = true; 912 } 913 } 914 return $retval; 915 } 827 916 /** Reloads the object from the database. Should normally be called after a set operation */ 828 917 protected function refresh() … … 833 922 } //End class 834 923 ?> 924 -
trunk/wifidog-auth/wifidog/classes/Node.php
r733 r742 1 1 <?php 2 3 2 4 /********************************************************************\ 3 5 * This program is free software; you can redistribute it and/or * … … 128 130 $user = User :: getCurrentUser(); 129 131 if ($this->isOwner($user) || $user->isSuperAdmin()) 130 { 131 $errmsg = _('Access denied!'); 132 } 133 132 { 134 133 global $db; 135 134 $id = $db->EscapeString($this->getId()); … … 142 141 $retval = true; 143 142 } 143 } 144 else 145 { 146 $errmsg = _('Access denied!'); 147 } 144 148 145 149 return $retval; 146 150 } 147 151 148 /** Create a new Node in the database 149 * @param $id The id to be given to the new node 152 /** Create a new Node in the database 153 * @param $node_id The id to be given to the new node. If not present, a 154 * guid will be assigned. 155 * @param $network Network object. The node's network. If not present, 156 * the current Network will be assigned 157 * 150 158 * @return the newly created Node object, or null if there was an error 151 159 */ 152 static function createNewObject() 153 { 154 global $db; 155 156 $node_id = $db->EscapeString(get_guid()); 157 $object = self::createNewNode($node_id, Network::getCurrentNetwork()); 158 return $object; 159 } 160 161 /** Create a new Node in the database 162 * @param $node_id The id to be given to the new node 163 * @param $network Network object. The node's network 164 * @todo Implement network 165 * @return the newly created Node object, or null if there was an error 166 */ 167 static function createNewNode($node_id, Network $network) 168 { 169 global $db; 160 static function createNewObject($node_id = null, $network = null) 161 { 162 global $db; 163 if(empty($node_id)) 164 { 165 $node_id = get_guid(); 166 } 170 167 $node_id = $db->EscapeString($node_id); 168 169 if(empty($network)) 170 { 171 $network = Network :: getCurrentNetwork(); 172 } 173 $network_id = $db->EscapeString($network->getId()); 174 171 175 $node_deployment_status = $db->EscapeString("IN_PLANNING"); 172 176 $node_name = _("New node"); … … 174 178 throw new Exception(_('This node already exists.')); 175 179 176 $sql = "INSERT INTO nodes (node_id, creation_date, node_deployment_status, name) VALUES ('$node_id', NOW(),'$node_deployment_status', '$node_name')";180 $sql = "INSERT INTO nodes (node_id, network_id, creation_date, node_deployment_status, name) VALUES ('$node_id', '$network_id', NOW(),'$node_deployment_status', '$node_name')"; 177 181 178 182 if (!$db->ExecSqlUpdate($sql, false)) … … 222 226 } 223 227 228 /** Get an interface to create a new node. 229 * @param $network Optional: The network to which the new node will belong, 230 * if absent, the user will be prompted. 231 * @return html markup 232 */ 233 public static function getCreateNewObjectUI($network = null) 234 { 235 $html = ''; 236 $html .= _("Create new node with id")." \n"; 237 $name = "new_node_id"; 238 $html .= "<input type='text' size='10' name='{$name}'>\n"; 239 if ($network) 240 { 241 $name = "new_node_network_id"; 242 $html .= "<input type='hidden' name='{$name}' value='{$network->getId()}'>\n"; 243 } 244 else 245 { 246 $html .= " "._("in network:")." \n"; 247 $html .= Network :: getSelectNetworkUI('new_node'); 248 } 249 return $html; 250 251 } 252 253 /** Process the new object interface. 254 * Will return the new object if the user has the credentials and the form was fully filled. 255 * @return the node object or null if no new node was created. 256 */ 257 static function processCreateNewObjectUI() 258 { 259 $retval = null; 260 $name = "new_node_id"; 261 if (!empty ($_REQUEST[$name])) 262 { 263 $node_id = $_REQUEST[$name]; 264 $name = "new_node_network_id"; 265 if (!empty ($_REQUEST[$name])) 266 { 267 $network = Network :: getObject($_REQUEST[$name]); 268 } 269 else 270 { 271 $network = Network :: processSelectNetworkUI('new_node'); 272 } 273 if ($node_id && $network) 274 { 275 if (!$network->hasAdminAccess(User :: getCurrentUser())) 276 { 277 throw new Exception(_("Access denied")); 278 } 279 $retval = self :: createNewObject($node_id, $network); 280 } 281 } 282 return $retval; 283 } 284 224 285 /** Get an interface to select the deployment status 225 286 * @param $user_prefix A identifier provided by the programmer to recognise it's generated html form … … 258 319 global $db; 259 320 $this->mDb = & $db; 260 321 261 322 $node_id_str = $db->EscapeString($node_id); 262 323 $sql = "SELECT * FROM nodes WHERE node_id='$node_id_str'"; … … 280 341 public function getNetwork() 281 342 { 282 return Network::getObject($this->mRow['network_id']);343 return Network :: getObject($this->mRow['network_id']); 283 344 } 284 345 … … 320 381 } 321 382 322 function getCreationDate()323 {324 return $this->mRow['creation_date'];325 }383 function getCreationDate() 384 { 385 return $this->mRow['creation_date']; 386 } 326 387 327 388 function getHomePageURL() … … 527 588 public function isConfiguredSplashOnly() 528 589 { 529 return (($this->mRow['is_splash_only_node'] =='t') ? true : false);590 return (($this->mRow['is_splash_only_node'] == 't') ? true : false); 530 591 } 531 592 … … 539 600 { 540 601 global $db; 541 $value ?$value='TRUE':$value='FALSE';602 $value ? $value = 'TRUE' : $value = 'FALSE'; 542 603 $retval = $db->ExecSqlUpdate("UPDATE nodes SET is_splash_only_node = {$value} WHERE node_id = '{$this->getId()}'", false); 543 604 $this->refresh(); 544 605 } 545 606 return $retval; 546 } 547 548 607 } 608 549 609 /** The url to show instead of the portal. If empty, the portal is shown 550 610 Must be enabled in the Network configuration to have any effect … … 554 614 return $this->mRow['custom_portal_redirect_url']; 555 615 } 556 616 557 617 /** The url to show instead of the portal. If empty, the portal is shown 558 618 Must be enabled in the Network configuration to have any effect … … 570 630 return $retval; 571 631 } 572 632 573 633 /** Retrieves the admin interface of this object. 574 634 * @return The HTML fragment for this interface */ … … 577 637 //TODO: Most of this code will be moved to Hotspot class when the abtraction will be completed 578 638 579 //pretty_print_r($_REQUEST);580 //pretty_print_r($this->mRow);639 //pretty_print_r($_REQUEST); 640 //pretty_print_r($this->mRow); 581 641 $html = ''; 582 642 $html .= "<div class='admin_container'>\n"; … … 600 660 // Hashed node_id (this is a workaround since PHP auto-converts HTTP vars var periods, spaces or underscores ) 601 661 $hashed_node_id = md5($this->getId()); 602 662 603 663 // Name 604 664 $html .= "<div class='admin_section_container'>\n"; … … 794 854 $html .= "<div class='admin_section_container'>\n"; 795 855 $html .= "<div class='admin_section_title'>"._("Node configuration:")."</div>\n"; 796 856 797 857 $network = $this->getNetwork(); 798 858 799 859 // Deployment status 800 860 $html .= "<div class='admin_section_container'>\n"; … … 807 867 808 868 // is_splash_only_node 809 if($network->getSplashOnlyNodesAllowed()) 810 { 811 $html .= "<div class='admin_section_container'>\n"; 812 $html .= "<div class='admin_section_title'>"._("Is this node splash-only (no login)?")." : </div>\n"; 813 $html .= "<div class='admin_section_data'>\n"; 814 $name = "node_".$hashed_node_id."_is_splash_only_node"; 815 $this->isConfiguredSplashOnly()? $checked='CHECKED': $checked=''; 816 $html .= "<input type='checkbox' name='$name' $checked>\n"; 817 $html .= "</div>\n"; 818 $html .= "</div>\n"; 819 } 820 821 // custom_portal_redirect_url 822 if($network->getCustomPortalRedirectAllowed()) 869 if ($network->getSplashOnlyNodesAllowed()) 823 870 { 824 871 $html .= "<div class='admin_section_container'>\n"; 825 $html .= "<div class='admin_section_title'>"._("URL to show instead of the portal (if this is not empty, the portal will be disabled and this URL will be shown instead)")." : </div>\n"; 826 $html .= "<div class='admin_section_data'>\n"; 827 $name = "node_".$hashed_node_id."_custom_portal_redirect_url"; 828 $value = htmlspecialchars($this->getCustomPortalRedirectUrl(), ENT_QUOTES); 829 $html .= "<input type='text' size ='50' value='$value' name='$name'>\n"; 830 $html .= "</div>\n"; 831 $html .= "</div>\n"; 872 $html .= "<div class='admin_section_title'>"._("Is this node splash-only (no login)?")." : </div>\n"; 873 $html .= "<div class='admin_section_data'>\n"; 874 $name = "node_".$hashed_node_id."_is_splash_only_node"; 875 $this->isConfiguredSplashOnly() ? $checked = 'CHECKED' : $checked = ''; 876 $html .= "<input type='checkbox' name='$name' $checked>\n"; 877 $html .= "</div>\n"; 878 $html .= "</div>\n"; 879 } 880 881 // custom_portal_redirect_url 882 if ($network->getCustomPortalRedirectAllowed()) 883 { 884 $html .= "<div class='admin_section_container'>\n"; 885 $html .= "<div class='admin_section_title'>"._("URL to show instead of the portal (if this is not empty, the portal will be disabled and this URL will be shown instead)")." : </div>\n"; 886 $html .= "<div class='admin_section_data'>\n"; 887 $name = "node_".$hashed_node_id."_custom_portal_redirect_url"; 888 $value = htmlspecialchars($this->getCustomPortalRedirectUrl(), ENT_QUOTES); 889 $html .= "<input type='text' size ='50' value='$value' name='$name'>\n"; 890 $html .= "</div>\n"; 891 $html .= "</div>\n"; 832 892 } 833 893 // End Node configuration section 834 894 $html .= "</div>\n"; 835 895 836 896 // Owners management 837 897 $html .= "<div class='admin_section_container'>\n"; … … 936 996 937 997 // Information about the node 938 998 939 999 // Hashed node_id (this is a workaround since PHP auto-converts HTTP vars var periods, spaces or underscores ) 940 1000 $hashed_node_id = md5($this->getId()); 941 1001 942 1002 // Name 943 1003 $name = "node_".$hashed_node_id."_name"; … … 1029 1089 1030 1090 // Node configuration section 1031 1091 1032 1092 $network = $this->getNetwork(); 1033 1093 … … 1037 1097 1038 1098 // is_splash_only_node 1039 if ($network->getSplashOnlyNodesAllowed())1040 { 1041 $name = "node_".$hashed_node_id."_is_splash_only_node";1042 $this->setIsConfiguredSplashOnly(empty($_REQUEST[$name])?false:true);1043 } 1044 1099 if ($network->getSplashOnlyNodesAllowed()) 1100 { 1101 $name = "node_".$hashed_node_id."_is_splash_only_node"; 1102 $this->setIsConfiguredSplashOnly(empty ($_REQUEST[$name]) ? false : true); 1103 } 1104 1045 1105 // custom_portal_redirect_url 1046 if ($network->getCustomPortalRedirectAllowed())1047 { 1048 $name = "node_".$hashed_node_id."_custom_portal_redirect_url";1049 $this->setCustomPortalRedirectUrl($_REQUEST[$name]);1050 } 1051 1106 if ($network->getCustomPortalRedirectAllowed()) 1107 { 1108 $name = "node_".$hashed_node_id."_custom_portal_redirect_url"; 1109 $this->setCustomPortalRedirectUrl($_REQUEST[$name]); 1110 } 1111 1052 1112 // End Node configuration section 1053 1113 … … 1065 1125 } 1066 1126 } 1067 1127 1068 1128 $name = "node_{$this->getId()}_new_owner_submit"; 1069 1129 if (!empty ($_REQUEST[$name])) … … 1405 1465 $sql = "SELECT * FROM nodes WHERE node_id='{$id_str}'"; 1406 1466 $db->ExecSqlUniqueRes($sql, $row, false); 1407 if ($row!=null)1467 if ($row != null) 1408 1468 { 1409 1469 $retval = true; … … 1430 1490 } // End class 1431 1491 ?> 1492 1493 -
trunk/wifidog-auth/wifidog/classes/User.php
r739 r742 47 47 echo "<h1>Use User::createUser() instead</h1>"; 48 48 } 49 49 /** Get an interface to create a new object. 50 * @return html markup 51 */ 52 public static function getCreateNewObjectUI() 53 { 54 return null; 55 } 56 57 /** Process the new object interface. 58 * Will return the new object if the user has the credentials 59 * necessary (Else an exception is thrown) and and the form was fully 60 * filled (Else the object returns null). 61 * @return the node object or null if no new node was created. 62 */ 63 static function processCreateNewObjectUI() 64 { 65 return self::createNewObject(); 66 } 50 67 /** Instantiate the current user 51 68 * @return a User object, or null if there was an error -
trunk/wifidog-auth/wifidog/include/schema_validate.php
r716 r742 616 616 617 617 } 618 619 $new_schema_version = 28; 620 if ($schema_version < $new_schema_version) 621 { 622 echo "<h2>Preparing SQL statements to update schema to version $new_schema_version</h2>\n"; 623 $sql .= "\n\nUPDATE schema_info SET value='$new_schema_version' WHERE tag='schema_version';\n"; 624 $sql .= "ALTER TABLE nodes ADD COLUMN is_splash_only_node boolean;\n"; 625 $sql .= "ALTER TABLE nodes ALTER COLUMN is_splash_only_node SET DEFAULT FALSE;\n"; 626 $sql .= "ALTER TABLE nodes ADD COLUMN custom_portal_redirect_url text;\n"; 627 628 } 629 618 630 $db->ExecSqlUpdate("BEGIN;\n$sql\nCOMMIT;\n", true); 619 631 //$db->ExecSqlUpdate("BEGIN;\n$sql\nROLLBACK;\n", true);
