Changeset 1173
- Timestamp:
- 01/17/07 00:34:12 (5 years ago)
- Location:
- trunk/wifidog-auth
- Files:
-
- 3 modified
-
CHANGELOG (modified) (1 diff)
-
wifidog/classes/Node.php (modified) (27 diffs)
-
wifidog/classes/SmartyWifidog.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wifidog-auth/CHANGELOG
r1172 r1173 5 5 * It is now possible for an administrator to manually validate or lock-out a user 6 6 * Add new SimpleString content type 7 7 * SmartyWifidog.php: Fix #282 with a slightly dirty workround to the chicken and the egg smarty variables assignment problem. 8 We now extend the fetch method and do our assignment there instead of in the constructor. 9 8 10 2007-01-15 Benoit Grégoire <bock@step.polymtl.ca> 9 11 * Sync initial schema and translations -
trunk/wifidog-auth/wifidog/classes/Node.php
r1169 r1173 64 64 { 65 65 /** Object cache for the object factory (getObject())*/ 66 private static $instanceArray = array();66 private static $instanceArray = array(); 67 67 private $mRow; 68 68 private $mdB; /**< An AbstractDb instance */ … … 93 93 static function getObject($id) 94 94 { 95 if(!isset(self::$instanceArray[$id]))96 {95 if(!isset(self::$instanceArray[$id])) 96 { 97 97 self::$instanceArray[$id] = new self($id); 98 }99 return self::$instanceArray[$id];98 } 99 return self::$instanceArray[$id]; 100 100 } 101 101 … … 106 106 static function getObjectByGatewayId($gwId) 107 107 { 108 $object = null;109 $object = new self($gwId, 'GATEWAY_ID');110 return $object;108 $object = null; 109 $object = new self($gwId, 'GATEWAY_ID'); 110 return $object; 111 111 } 112 112 /** Get the current node for which the portal is displayed or to which a user is physically connected. … … 116 116 static function getCurrentNode($real_node_only = false) 117 117 { 118 $object = null;119 if (self :: $current_node_id != null && $real_node_only == false)120 {121 $object = self::getObject(self :: $current_node_id);122 }123 else124 {125 $object = self :: getCurrentRealNode();126 }127 return $object;118 $object = null; 119 if (self :: $current_node_id != null && $real_node_only == false) 120 { 121 $object = self::getObject(self :: $current_node_id); 122 } 123 else 124 { 125 $object = self :: getCurrentRealNode(); 126 } 127 return $object; 128 128 } 129 129 … … 133 133 static function setCurrentNode(Node $node) 134 134 { 135 self :: $current_node_id = $node->GetId();136 return true;135 self :: $current_node_id = $node->GetId(); 136 return true; 137 137 } 138 138 … … 142 142 public static function getCurrentRealNode() 143 143 { 144 static $currentRealNode;145 static $currentRealNodeComputed;146 if(!isset($currentRealNodeComputed))147 {144 static $currentRealNode; 145 static $currentRealNodeComputed; 146 if(!isset($currentRealNodeComputed)) 147 { 148 148 $currentRealNodeComputed=true; 149 $db = AbstractDb::getObject();150 $sql = "SELECT node_id, last_heartbeat_ip from nodes WHERE last_heartbeat_ip='$_SERVER[REMOTE_ADDR]' ORDER BY last_heartbeat_timestamp DESC";151 $node_rows = null;152 $db->execSql($sql, $node_rows, false);153 $num_match = count($node_rows);154 if ($num_match == 0)155 {156 157 // User is not physically connected to a node158 $currentRealNode = null;159 }160 else161 if ($num_match = 1)162 {163 // Only a single node matches, the user is presumed to be there164 $currentRealNode = self::getObject($node_rows[0]['node_id']);165 }166 else167 {168 /* We have more than one node matching the IP (the nodes are behind the same NAT).169 * We will try to discriminate by finding which node the user last authenticated against.170 * If the IP matches, we can be pretty certain the user is there.171 */172 $currentRealNode = null;173 $current_user = User :: getCurrentUser();174 if ($current_user != null)175 {176 $current_user_id = $current_user->getId();177 $_SERVER['REMOTE_ADDR'];178 $sql = "SELECT node_id, last_heartbeat_ip from connections NATURAL JOIN nodes WHERE user_id='$current_user_id' ORDER BY last_updated DESC ";179 $db->execSql($sql, $node_rows, false);180 $node_row = $node_rows[0];181 if ($node_row != null && $node_row['last_heartbeat_ip'] == $_SERVER['REMOTE_ADDR'])182 {183 $currentRealNode = self::getObject($node_row['node_id']);184 }185 }186 }187 }188 189 return $currentRealNode;149 $db = AbstractDb::getObject(); 150 $sql = "SELECT node_id, last_heartbeat_ip from nodes WHERE last_heartbeat_ip='$_SERVER[REMOTE_ADDR]' ORDER BY last_heartbeat_timestamp DESC"; 151 $node_rows = null; 152 $db->execSql($sql, $node_rows, false); 153 $num_match = count($node_rows); 154 if ($num_match == 0) 155 { 156 157 // User is not physically connected to a node 158 $currentRealNode = null; 159 } 160 else 161 if ($num_match = 1) 162 { 163 // Only a single node matches, the user is presumed to be there 164 $currentRealNode = self::getObject($node_rows[0]['node_id']); 165 } 166 else 167 { 168 /* We have more than one node matching the IP (the nodes are behind the same NAT). 169 * We will try to discriminate by finding which node the user last authenticated against. 170 * If the IP matches, we can be pretty certain the user is there. 171 */ 172 $currentRealNode = null; 173 $current_user = User :: getCurrentUser(); 174 if ($current_user != null) 175 { 176 $current_user_id = $current_user->getId(); 177 $_SERVER['REMOTE_ADDR']; 178 $sql = "SELECT node_id, last_heartbeat_ip from connections NATURAL JOIN nodes WHERE user_id='$current_user_id' ORDER BY last_updated DESC "; 179 $db->execSql($sql, $node_rows, false); 180 $node_row = $node_rows[0]; 181 if ($node_row != null && $node_row['last_heartbeat_ip'] == $_SERVER['REMOTE_ADDR']) 182 { 183 $currentRealNode = self::getObject($node_row['node_id']); 184 } 185 } 186 } 187 } 188 189 return $currentRealNode; 190 190 } 191 191 192 192 public function delete(& $errmsg) 193 193 { 194 $retval = false;195 $user = User :: getCurrentUser();196 if ($user->isSuperAdmin()) {197 $db = AbstractDb::getObject();198 $id = $db->escapeString($this->getId());199 if (!$db->execSqlUpdate("DELETE FROM nodes WHERE node_id='{$id}'", false))200 {201 $errmsg = _('Could not delete node!');202 }203 else204 {205 $retval = true;206 }207 }208 else209 {210 $errmsg = _('Access denied!');211 }212 213 return $retval;194 $retval = false; 195 $user = User :: getCurrentUser(); 196 if ($user->isSuperAdmin()) { 197 $db = AbstractDb::getObject(); 198 $id = $db->escapeString($this->getId()); 199 if (!$db->execSqlUpdate("DELETE FROM nodes WHERE node_id='{$id}'", false)) 200 { 201 $errmsg = _('Could not delete node!'); 202 } 203 else 204 { 205 $retval = true; 206 } 207 } 208 else 209 { 210 $errmsg = _('Access denied!'); 211 } 212 213 return $retval; 214 214 } 215 215 … … 230 230 public static function createNewObject($gw_id = null, $network = null) 231 231 { 232 $db = AbstractDb::getObject();233 if (empty ($gw_id)) {234 $gw_id = $db->escapeString(_('PUT_GATEWAY_ID_HERE'));235 }236 else237 {238 $gw_id = $db->escapeString($gw_id);239 }240 $node_id = get_guid();241 242 243 if (empty ($network)) {244 $network = Network::getCurrentNetwork();245 }246 247 $network_id = $db->escapeString($network->getId());248 249 $node_deployment_status = $db->escapeString("IN_PLANNING");250 $node_name = _("New node");251 $duplicate = null;252 try{253 $duplicate = Node::getObjectByGatewayId($gw_id);254 }255 catch (Exception $e)256 {257 }258 if ($duplicate) {259 throw new Exception(sprintf(_('Sorry, a node for the gateway %s already exists.'),$gw_id));260 }261 262 $sql = "INSERT INTO nodes (node_id, gw_id, network_id, creation_date, node_deployment_status, name) VALUES ('$node_id', '$gw_id', '$network_id', CURRENT_TIMESTAMP,'$node_deployment_status', '$node_name')";263 264 if (!$db->execSqlUpdate($sql, false)) {265 throw new Exception(_('Unable to insert new node into database!'));266 }267 268 $object = self::getObject($node_id);269 270 return $object;232 $db = AbstractDb::getObject(); 233 if (empty ($gw_id)) { 234 $gw_id = $db->escapeString(_('PUT_GATEWAY_ID_HERE')); 235 } 236 else 237 { 238 $gw_id = $db->escapeString($gw_id); 239 } 240 $node_id = get_guid(); 241 242 243 if (empty ($network)) { 244 $network = Network::getCurrentNetwork(); 245 } 246 247 $network_id = $db->escapeString($network->getId()); 248 249 $node_deployment_status = $db->escapeString("IN_PLANNING"); 250 $node_name = _("New node"); 251 $duplicate = null; 252 try{ 253 $duplicate = Node::getObjectByGatewayId($gw_id); 254 } 255 catch (Exception $e) 256 { 257 } 258 if ($duplicate) { 259 throw new Exception(sprintf(_('Sorry, a node for the gateway %s already exists.'),$gw_id)); 260 } 261 262 $sql = "INSERT INTO nodes (node_id, gw_id, network_id, creation_date, node_deployment_status, name) VALUES ('$node_id', '$gw_id', '$network_id', CURRENT_TIMESTAMP,'$node_deployment_status', '$node_name')"; 263 264 if (!$db->execSqlUpdate($sql, false)) { 265 throw new Exception(_('Unable to insert new node into database!')); 266 } 267 268 $object = self::getObject($node_id); 269 270 return $object; 271 271 } 272 272 … … 282 282 public static function getSelectNodeUI($user_prefix, $sql_additional_join = null, $sql_additional_where = null,$selectedNodes = null, $type_interface = "select") 283 283 { 284 $db = AbstractDb::getObject();285 $html = '';286 $name = "{$user_prefix}";284 $db = AbstractDb::getObject(); 285 $html = ''; 286 $name = "{$user_prefix}"; 287 287 288 288 $_deploymentStatuses = array( … … 295 295 ); 296 296 297 $sql = "SELECT node_id, name, gw_id, node_deployment_status, is_splash_only_node from nodes $sql_additional_join WHERE 1=1 $sql_additional_where ORDER BY lower(node_id)";298 $node_rows = null;299 $db->execSql($sql, $node_rows, false);300 301 if ($node_rows != null) {302 Utils :: natsort2d($node_rows, "name");303 if ($type_interface != "table") {304 $i = 0;305 foreach ($node_rows as $node_row)306 {307 $tab[$i][0] = $node_row['node_id'];308 //$tab[$i][1] = sprintf(_("%s (gw: %s)"),$node_row['name'],$node_row['gw_id']);309 $tab[$i][1] = $node_row['name'];310 $i ++;311 }312 if($type_interface == "select_multiple"){313 $select_options="MULTIPLE SIZE=6";314 }315 else316 {317 $select_options=null;318 }319 //pretty_print_r($selectedNodes);320 if(is_array($selectedNodes)){321 $selectedPrimaryKey=array();322 foreach($selectedNodes as $node){323 $selectedPrimaryKey[]=$node->getId();324 }325 326 }327 else if($selectedNodes instanceof Node){328 $selectedPrimaryKey=$selectedNodes->getId();329 }330 else{331 $selectedPrimaryKey=null;332 }333 $html .= FormSelectGenerator :: generateFromArray($tab, $selectedPrimaryKey, $name, null, false, null, $select_options);334 } else {335 $html .= "<fieldset>\n <legend>Node List</legend>\n";336 $html .= " <span class='node_admin'>"._("Filter:")."<input type=\"text\" tabindex=\"1\" maxlength=\"40\" size=\"40\" id=\"nodes_list_filter\" name=\"nodes_list_filter\" /></span>\n <br/>\n";337 $html .= " <!--[if IE]><style type='text/css'>#node_list_div table.scrollable>tbody { height: 15px; }</style><![endif]-->\n";338 $html .= " <script src='" . BASE_URL_PATH . "js/filtertable.js' type='text/javascript' language='javascript' charset='utf-8'></script>\n";339 $html .= " <script src='" . BASE_URL_PATH . "js/sorttable.js' type='text/javascript' language='javascript' charset='utf-8'></script>\n";340 $html .= " <div id='node_list_div' class='node_admin tableContainer'>\n";341 $html .= " <table id='nodes_list' class='node_admin filterable scrollable sortable'>\n\n";342 $html .= " <thead class='fixedHeader'>\n";343 $html .= "<tr class='nofilter'>\n";344 $html .= "<th>"._("Node Name")."</th>\n";345 $html .= "<th>"._("Gateway ID")."</th>\n";346 $html .= "<th>"._("Deployment Status")."</th>\n";347 $html .= "</tr>\n";348 $html .= "</thead>\n";349 $html .= "<tbody>";350 351 $i = 0;352 foreach ($node_rows as $node_row)353 {354 $href = GENERIC_OBJECT_ADMIN_ABS_HREF."?object_id={$node_row['node_id']}&object_class=Node&action=edit";355 $_deployStatusNode = $node_row['node_deployment_status'];356 $html .= "<tr class='row' onclick=\"javascript:location.href='{$href}'\">\n";357 $html .= "<td>{$node_row['name']}<noscript>(<a href='{$href}'>edit</a>)</noscript></td>\n";358 $html .= "<td>{$node_row['gw_id']}</td>\n";359 $html .= "<td>{$_deploymentStatuses[$_deployStatusNode]}</td>\n";360 $html .= "</tr>\n";361 }362 $html .= " </tbody>\n </table>\n";363 $html .= " </div>\n";364 $html .= "</fieldset>\n";365 366 }367 } else {368 $html .= "<div class='warningmsg'>"._("Sorry, no nodes available in the database")."</div>\n";369 }370 return $html;297 $sql = "SELECT node_id, name, gw_id, node_deployment_status, is_splash_only_node from nodes $sql_additional_join WHERE 1=1 $sql_additional_where ORDER BY lower(node_id)"; 298 $node_rows = null; 299 $db->execSql($sql, $node_rows, false); 300 301 if ($node_rows != null) { 302 Utils :: natsort2d($node_rows, "name"); 303 if ($type_interface != "table") { 304 $i = 0; 305 foreach ($node_rows as $node_row) 306 { 307 $tab[$i][0] = $node_row['node_id']; 308 //$tab[$i][1] = sprintf(_("%s (gw: %s)"),$node_row['name'],$node_row['gw_id']); 309 $tab[$i][1] = $node_row['name']; 310 $i ++; 311 } 312 if($type_interface == "select_multiple"){ 313 $select_options="MULTIPLE SIZE=6"; 314 } 315 else 316 { 317 $select_options=null; 318 } 319 //pretty_print_r($selectedNodes); 320 if(is_array($selectedNodes)){ 321 $selectedPrimaryKey=array(); 322 foreach($selectedNodes as $node){ 323 $selectedPrimaryKey[]=$node->getId(); 324 } 325 326 } 327 else if($selectedNodes instanceof Node){ 328 $selectedPrimaryKey=$selectedNodes->getId(); 329 } 330 else{ 331 $selectedPrimaryKey=null; 332 } 333 $html .= FormSelectGenerator :: generateFromArray($tab, $selectedPrimaryKey, $name, null, false, null, $select_options); 334 } else { 335 $html .= "<fieldset>\n <legend>Node List</legend>\n"; 336 $html .= " <span class='node_admin'>"._("Filter:")."<input type=\"text\" tabindex=\"1\" maxlength=\"40\" size=\"40\" id=\"nodes_list_filter\" name=\"nodes_list_filter\" /></span>\n <br/>\n"; 337 $html .= " <!--[if IE]><style type='text/css'>#node_list_div table.scrollable>tbody { height: 15px; }</style><![endif]-->\n"; 338 $html .= " <script src='" . BASE_URL_PATH . "js/filtertable.js' type='text/javascript' language='javascript' charset='utf-8'></script>\n"; 339 $html .= " <script src='" . BASE_URL_PATH . "js/sorttable.js' type='text/javascript' language='javascript' charset='utf-8'></script>\n"; 340 $html .= " <div id='node_list_div' class='node_admin tableContainer'>\n"; 341 $html .= " <table id='nodes_list' class='node_admin filterable scrollable sortable'>\n\n"; 342 $html .= " <thead class='fixedHeader'>\n"; 343 $html .= "<tr class='nofilter'>\n"; 344 $html .= "<th>"._("Node Name")."</th>\n"; 345 $html .= "<th>"._("Gateway ID")."</th>\n"; 346 $html .= "<th>"._("Deployment Status")."</th>\n"; 347 $html .= "</tr>\n"; 348 $html .= "</thead>\n"; 349 $html .= "<tbody>"; 350 351 $i = 0; 352 foreach ($node_rows as $node_row) 353 { 354 $href = GENERIC_OBJECT_ADMIN_ABS_HREF."?object_id={$node_row['node_id']}&object_class=Node&action=edit"; 355 $_deployStatusNode = $node_row['node_deployment_status']; 356 $html .= "<tr class='row' onclick=\"javascript:location.href='{$href}'\">\n"; 357 $html .= "<td>{$node_row['name']}<noscript>(<a href='{$href}'>edit</a>)</noscript></td>\n"; 358 $html .= "<td>{$node_row['gw_id']}</td>\n"; 359 $html .= "<td>{$_deploymentStatuses[$_deployStatusNode]}</td>\n"; 360 $html .= "</tr>\n"; 361 } 362 $html .= " </tbody>\n </table>\n"; 363 $html .= " </div>\n"; 364 $html .= "</fieldset>\n"; 365 366 } 367 } else { 368 $html .= "<div class='warningmsg'>"._("Sorry, no nodes available in the database")."</div>\n"; 369 } 370 return $html; 371 371 } 372 372 … … 378 378 static function processSelectNodeUI($user_prefix) 379 379 { 380 $object = null;381 $name = "{$user_prefix}";382 return self::getObject($_REQUEST[$name]);380 $object = null; 381 $name = "{$user_prefix}"; 382 return self::getObject($_REQUEST[$name]); 383 383 } 384 384 … … 390 390 public static function getCreateNewObjectUI($network = null) 391 391 { 392 $html = '';393 $html .= _("Add a new node for the gateway ID")." \n";394 $name = "new_node_gw_id";395 $html .= "<input type='text' size='10' name='{$name}'>\n";396 if ($network)397 {398 $name = "new_node_network_id";399 $html .= "<input type='hidden' name='{$name}' value='{$network->getId()}'>\n";400 }401 else402 {403 $html .= " "._("in ")." \n";404 $html .= Network :: getSelectNetworkUI('new_node');405 }406 return $html;392 $html = ''; 393 $html .= _("Add a new node for the gateway ID")." \n"; 394 $name = "new_node_gw_id"; 395 $html .= "<input type='text' size='10' name='{$name}'>\n"; 396 if ($network) 397 { 398 $name = "new_node_network_id"; 399 $html .= "<input type='hidden' name='{$name}' value='{$network->getId()}'>\n"; 400 } 401 else 402 { 403 $html .= " "._("in ")." \n"; 404 $html .= Network :: getSelectNetworkUI('new_node'); 405 } 406 return $html; 407 407 408 408 } … … 417 417 { 418 418 // Init values 419 $retval = null;420 $name = "new_node_gw_id";421 422 if (!empty ($_REQUEST[$name])) {423 $gw_id = $_REQUEST[$name];424 }425 else426 {427 $gw_id = null;428 }429 $name = "new_node_network_id";430 431 if (!empty ($_REQUEST[$name])) {432 $network = Network::getObject($_REQUEST[$name]);433 } else {434 $network = Network::processSelectNetworkUI('new_node');435 }436 437 if ($network) {438 try {439 if (!$network->hasAdminAccess(User :: getCurrentUser())) {440 throw new Exception(_("Access denied"));441 }442 } catch (Exception $e) {443 $ui = MainUI::getObject();444 $ui->setToolSection('ADMIN');445 $ui->displayError($e->getMessage(), false);446 exit;447 }448 449 $retval = self::createNewObject($gw_id, $network);450 }451 452 return $retval;419 $retval = null; 420 $name = "new_node_gw_id"; 421 422 if (!empty ($_REQUEST[$name])) { 423 $gw_id = $_REQUEST[$name]; 424 } 425 else 426 { 427 $gw_id = null; 428 } 429 $name = "new_node_network_id"; 430 431 if (!empty ($_REQUEST[$name])) { 432 $network = Network::getObject($_REQUEST[$name]); 433 } else { 434 $network = Network::processSelectNetworkUI('new_node'); 435 } 436 437 if ($network) { 438 try { 439 if (!$network->hasAdminAccess(User :: getCurrentUser())) { 440 throw new Exception(_("Access denied")); 441 } 442 } catch (Exception $e) { 443 $ui = MainUI::getObject(); 444 $ui->setToolSection('ADMIN'); 445 $ui->displayError($e->getMessage(), false); 446 exit; 447 } 448 449 $retval = self::createNewObject($gw_id, $network); 450 } 451 452 return $retval; 453 453 } 454 454 … … 461 461 * @return string HTML markup 462 462 */ 463 public function getSelectDeploymentStatus($user_prefix)464 {465 466 $db = AbstractDb::getObject();467 468 // Init values469 $html = "";470 $status_list = null;471 $tab = array();472 473 $name = "{$user_prefix}";474 $db->execSql("SELECT node_deployment_status FROM node_deployment_status", $status_list, false);475 476 if ($status_list == null) {477 throw new Exception(_("No deployment statuses could be found in the database"));478 }479 480 foreach ($status_list as $status) {481 $_statusvalue = $status['node_deployment_status'];482 $tab[] = array($_statusvalue, $this->_deploymentStatuses["$_statusvalue"]);483 }484 485 $html .= FormSelectGenerator::generateFromArray($tab, $this->getDeploymentStatus(), $name, null, false);486 487 return $html;488 }463 public function getSelectDeploymentStatus($user_prefix) 464 { 465 466 $db = AbstractDb::getObject(); 467 468 // Init values 469 $html = ""; 470 $status_list = null; 471 $tab = array(); 472 473 $name = "{$user_prefix}"; 474 $db->execSql("SELECT node_deployment_status FROM node_deployment_status", $status_list, false); 475 476 if ($status_list == null) { 477 throw new Exception(_("No deployment statuses could be found in the database")); 478 } 479 480 foreach ($status_list as $status) { 481 $_statusvalue = $status['node_deployment_status']; 482 $tab[] = array($_statusvalue, $this->_deploymentStatuses["$_statusvalue"]); 483 } 484 485 $html .= FormSelectGenerator::generateFromArray($tab, $this->getDeploymentStatus(), $name, null, false); 486 487 return $html; 488 } 489 489 490 490 /** … … 500 500 public function processSelectDeploymentStatus($user_prefix) 501 501 { 502 $object = null;503 $name = "{$user_prefix}";504 return $_REQUEST[$name];502 $object = null; 503 $name = "{$user_prefix}"; 504 return $_REQUEST[$name]; 505 505 } 506 506 … … 509 509 private function __construct($id, $idType='NODE_ID') 510 510 { 511 $db = AbstractDb::getObject();512 $this->mDb = & $db;513 514 $id_str = $db->escapeString($id);515 switch ($idType) {516 case 'NODE_ID': $sqlWhere = "node_id='$id_str'";517 break;518 case 'GATEWAY_ID': $sqlWhere = "gw_id='$id_str'";519 break;520 default:521 throw new exception('Unknown idType parameter');522 }523 $sqlWhere =524 $sql = "SELECT * FROM nodes WHERE $sqlWhere";525 $row = null;526 $db->execSqlUniqueRes($sql, $row, false);527 if ($row == null)528 {529 throw new Exception(sprintf(_("The node with %s: %s could not be found in the database!"), $idType, $id_str));530 }511 $db = AbstractDb::getObject(); 512 $this->mDb = & $db; 513 514 $id_str = $db->escapeString($id); 515 switch ($idType) { 516 case 'NODE_ID': $sqlWhere = "node_id='$id_str'"; 517 break; 518 case 'GATEWAY_ID': $sqlWhere = "gw_id='$id_str'"; 519 break; 520 default: 521 throw new exception('Unknown idType parameter'); 522 } 523 $sqlWhere = 524 $sql = "SELECT * FROM nodes WHERE $sqlWhere"; 525 $row = null; 526 $db->execSqlUniqueRes($sql, $row, false); 527 if ($row == null) 528 { 529 throw new Exception(sprintf(_("The node with %s: %s could not be found in the database!"), $idType, $id_str)); 530 } 531 531 532 532 $this->_deploymentStatuses = array( … … 539 539 ); 540 540 541 $this->mRow = $row;542 $this->id = $row['node_id'];541 $this->mRow = $row; 542 $this->id = $row['node_id']; 543 543 } 544 544 545 545 function getId() 546 546 { 547 return $this->id;547 return $this->id; 548 548 } 549 549 … … 551 551 function getGatewayId() 552 552 { 553 return $this->mRow['gw_id'];553 return $this->mRow['gw_id']; 554 554 } 555 555 /** Change the gateway ID of the gateway asociated with this node. … … 561 561 function setGatewayId($id) 562 562 { 563 $id = $this->mDb->escapeString($id);564 $retval = $this->mDb->execSqlUpdate("UPDATE nodes SET gw_id = '{$id}' WHERE node_id = '{$this->getId()}'");565 if ($retval)566 {567 $this->refresh();568 }569 return $retval;563 $id = $this->mDb->escapeString($id); 564 $retval = $this->mDb->execSqlUpdate("UPDATE nodes SET gw_id = '{$id}' WHERE node_id = '{$this->getId()}'"); 565 if ($retval) 566 { 567 $this->refresh(); 568 } 569 return $retval; 570 570 } 571 571 … … 575 575 public function getNetwork() 576 576 { 577 return Network :: getObject($this->mRow['network_id']);577 return Network :: getObject($this->mRow['network_id']); 578 578 } 579 579 … … 582 582 function getGisLocation() 583 583 { 584 // Altitude is not supported yet585 return new GisPoint($this->mRow['latitude'], $this->mRow['longitude'], 0);584 // Altitude is not supported yet 585 return new GisPoint($this->mRow['latitude'], $this->mRow['longitude'], 0); 586 586 } 587 587 588 588 function setGisLocation($pt) 589 589 { 590 if (!empty ($pt))591 {592 $lat = $this->mDb->escapeString($pt->getLatitude());593 $long = $this->mDb->escapeString($pt->getLongitude());594 595 if (!empty ($lat) && !empty ($long))596 $this->mDb->execSqlUpdate("UPDATE nodes SET latitude = $lat, longitude = $long WHERE node_id = '{$this->getId()}'");597 else598 $this->mDb->execSqlUpdate("UPDATE nodes SET latitude = NULL, longitude = NULL WHERE node_id = '{$this->getId()}'");599 $this->refresh();600 }590 if (!empty ($pt)) 591 { 592 $lat = $this->mDb->escapeString($pt->getLatitude()); 593 $long = $this->mDb->escapeString($pt->getLongitude()); 594 595 if (!empty ($lat) && !empty ($long)) 596 $this->mDb->execSqlUpdate("UPDATE nodes SET latitude = $lat, longitude = $long WHERE node_id = '{$this->getId()}'"); 597 else 598 $this->mDb->execSqlUpdate("UPDATE nodes SET latitude = NULL, longitude = NULL WHERE node_id = '{$this->getId()}'"); 599 $this->refresh(); 600 } 601 601 } 602 602 … … 605 605 function getName() 606 606 { 607 return $this->mRow['name'];607 return $this->mRow['name']; 608 608 } 609 609 610 610 function setName($name) 611 611 { 612 $name = $this->mDb->escapeString($name);613 $this->mDb->execSqlUpdate("UPDATE nodes SET name = '{$name}' WHERE node_id = '{$this->getId()}'");614 $this->refresh();612 $name = $this->mDb->escapeString($name); 613 $this->mDb->execSqlUpdate("UPDATE nodes SET name = '{$name}' WHERE node_id = '{$this->getId()}'"); 614 $this->refresh(); 615 615 } 616 616 617 617 function getCreationDate() 618 618 { 619 return $this->mRow['creation_date'];619 return $this->mRow['creation_date']; 620 620 } 621 621 622 622 function setCreationDate($creation_date) 623 623 { 624 $creation_date = $this->mDb->escapeString($creation_date);625 $this->mDb->execSqlUpdate("UPDATE nodes SET creation_date = '{$creation_date}' WHERE node_id = '{$this->getId()}'");626 $this->refresh();624 $creation_date = $this->mDb->escapeString($creation_date); 625 $this->mDb->execSqlUpdate("UPDATE nodes SET creation_date = '{$creation_date}' WHERE node_id = '{$this->getId()}'"); 626 $this->refresh(); 627 627 } 628 628 629 629 function getHomePageURL() 630 630 { 631 return $this->mRow['home_page_url'];631 return $this->mRow['home_page_url']; 632 632 } 633 633 634 634 function setHomePageUrl($url) 635 635 { 636 $url = $this->mDb->escapeString($url);637 $this->mDb->execSqlUpdate("UPDATE nodes SET home_page_url = '{$url}' WHERE node_id = '{$this->getId()}'");638 $this->refresh();636 $url = $this->mDb->escapeString($url); 637 $this->mDb->execSqlUpdate("UPDATE nodes SET home_page_url = '{$url}' WHERE node_id = '{$this->getId()}'"); 638 $this->refresh(); 639 639 } 640 640 641 641 function getDescription() 642 642 { 643 return $this->mRow['description'];643 return $this->mRow['description']; 644 644 } 645 645 646 646 function setDescription($description) 647 647 { 648 $description = $this->mDb->escapeString($description);649 $this->mDb->execSqlUpdate("UPDATE nodes SET description = '{$description}' WHERE node_id = '{$this->getId()}'");650 $this->refresh();648 $description = $this->mDb->escapeString($description); 649 $this->mDb->execSqlUpdate("UPDATE nodes SET description = '{$description}' WHERE node_id = '{$this->getId()}'"); 650 $this->refresh(); 651 651 } 652 652 653 653 function getMapURL() 654 654 { 655 return $this->mRow['map_url'];655 return $this->mRow['map_url']; 656 656 } 657 657 658 658 function setMapURL($url) 659 659 { 660 $url = $this->mDb->escapeString($url);661 $this->mDb->execSqlUpdate("UPDATE nodes SET map_url = '{$url}' WHERE node_id = '{$this->getId()}'");662 $this->refresh();660 $url = $this->mDb->escapeString($url); 661 $this->mDb->execSqlUpdate("UPDATE nodes SET map_url = '{$url}' WHERE node_id = '{$this->getId()}'"); 662 $this->refresh(); 663 663 } 664 664 665 665 public function getCivicNumber() 666 666 { 667 return $this->mRow['civic_number'];667 return $this->mRow['civic_number']; 668 668 } 669 669 670 670 public function setCivicNumber($civic_number) 671 671 { 672 $civic_number = $this->mDb->escapeString($civic_number);673 $this->mDb->execSqlUpdate("UPDATE nodes SET civic_number = '{$civic_number}' WHERE node_id = '{$this->getId()}'");674 $this->refresh();672 $civic_number = $this->mDb->escapeString($civic_number); 673 $this->mDb->execSqlUpdate("UPDATE nodes SET civic_number = '{$civic_number}' WHERE node_id = '{$this->getId()}'"); 674 $this->refresh(); 675 675 } 676 676 677 677 public function getStreetName() 678 678 { 679 return $this->mRow['street_name'];679 return $this->mRow['street_name']; 680 680 } 681 681 682 682 public function setStreetName($street_name) 683 683 { 684 $street_name = $this->mDb->escapeString($street_name);685 $this->mDb->execSqlUpdate("UPDATE nodes SET street_name = '{$street_name}' WHERE node_id = '{$this->getId()}'");686 $this->refresh();684 $street_name = $this->mDb->escapeString($street_name); 685 $this->mDb->execSqlUpdate("UPDATE nodes SET street_name = '{$street_name}' WHERE node_id = '{$this->getId()}'"); 686 $this->refresh(); 687 687 } 688 688 689 689 public function getCity() 690 690 { 691 return $this->mRow['city'];691 return $this->mRow['city']; 692 692 } 693 693 694 694 public function setCity($city) 695 695 { 696 $city = $this->mDb->escapeString($city);697 $this->mDb->execSqlUpdate("UPDATE nodes SET city = '{$city}' WHERE node_id = '{$this->getId()}'");698 $this->refresh();696 $city = $this->mDb->escapeString($city); 697 $this->mDb->execSqlUpdate("UPDATE nodes SET city = '{$city}' WHERE node_id = '{$this->getId()}'"); 698 $this->refresh(); 699 699 } 700 700 701 701 public function getProvince() 702 702 { 703 return $this->mRow['province'];703 return $this->mRow['province']; 704 704 } 705 705 706 706 public function setProvince($province) 707 707 { 708 $province = $this->mDb->escapeString($province);709 $this->mDb->execSqlUpdate("UPDATE nodes SET province = '{$province}' WHERE node_id = '{$this->getId()}'");710 $this->refresh();708 $province = $this->mDb->escapeString($province); 709 $this->mDb->execSqlUpdate("UPDATE nodes SET province = '{$province}' WHERE node_id = '{$this->getId()}'"); 710 $this->refresh(); 711 711 } 712 712 713 713 public function getCountry() 714 714 { 715 return $this->mRow['country'];715 return $this->mRow['country']; 716 716 } 717 717 718 718 protected function setCountry($country) 719 719 { 720 $country = $this->mDb->escapeString($country);721 $this->mDb->execSqlUpdate("UPDATE nodes SET country = '{$country}' WHERE node_id = '{$this->getId()}'");722 $this->refresh();720 $country = $this->mDb->escapeString($country); 721 $this->mDb->execSqlUpdate("UPDATE nodes SET country = '{$country}' WHERE node_id = '{$this->getId()}'"); 722 $this->refresh(); 723 723 } 724 724 725 725 public function getPostalCode() 726 726 { 727 return $this->mRow['postal_code'];727 return $this->mRow['postal_code']; 728 728 } 729 729 730 730 public function setPostalCode($postal_code) 731 731 { 732 $postal_code = $this->mDb->escapeString($postal_code);733 $this->mDb->execSqlUpdate("UPDATE nodes SET postal_code = '{$postal_code}' WHERE node_id = '{$this->getId()}'");734 $this->refresh();732 $postal_code = $this->mDb->escapeString($postal_code); 733 $this->mDb->execSqlUpdate("UPDATE nodes SET postal_code = '{$postal_code}' WHERE node_id = '{$this->getId()}'"); 734 $this->refresh(); 735 735 } 736 736 737 737 function getTelephone() 738 738 { 739 return $this->mRow['public_phone_number'];739 return $this->mRow['public_phone_number']; 740 740 } 741 741 742 742 function setTelephone($phone) 743 743 { 744 $phone = $this->mDb->escapeString($phone);745 $this->mDb->execSqlUpdate("UPDATE nodes SET public_phone_number = '{$phone}' WHERE node_id = '{$this->getId()}'");746 $this->refresh();744 $phone = $this->mDb->escapeString($phone); 745 $this->mDb->execSqlUpdate("UPDATE nodes SET public_phone_number = '{$phone}' WHERE node_id = '{$this->getId()}'"); 746 $this->refresh(); 747 747 } 748 748 749 749 function getTransitInfo() 750 750 { 751 return $this->mRow['mass_transit_info'];751 return $this->mRow['mass_transit_info']; 752 752 } 753 753 754 754 function setTransitInfo($transit_info) 755 755 { 756 $transit_info = $this->mDb->escapeString($transit_info);757 $this->mDb->execSqlUpdate("UPDATE nodes SET mass_transit_info = '{$transit_info}' WHERE node_id = '{$this->getId()}'");758 $this->refresh();756 $transit_info = $this->mDb->escapeString($transit_info); 757 $this->mDb->execSqlUpdate("UPDATE nodes SET mass_transit_info = '{$transit_info}' WHERE node_id = '{$this->getId()}'"); 758 $this->refresh(); 759 759 } 760 760 761 761 function getEmail() 762 762 { 763 return $this->mRow['public_email'];763 return $this->mRow['public_email']; 764 764 } 765 765 766 766 function setEmail($email) 767 767 { 768 $email = $this->mDb->escapeString($email);769 $this->mDb->execSqlUpdate("UPDATE nodes SET public_email = '{$email}' WHERE node_id = '{$this->getId()}'");770 $this->refresh();768 $email = $this->mDb->escapeString($email); 769 $this->mDb->execSqlUpdate("UPDATE nodes SET public_email = '{$email}' WHERE node_id = '{$this->getId()}'"); 770 $this->refresh(); 771 771 } 772 772 773 773 function getDeploymentStatus() 774 774 { 775 return $this->mRow['node_deployment_status'];775 return $this->mRow['node_deployment_status']; 776 776 } 777 777 778 778 function setDeploymentStatus($status) 779 779 { 780 $status = $this->mDb->escapeString($status);781 $this->mDb->execSqlUpdate("UPDATE nodes SET node_deployment_status = '{$status}' WHERE node_id = '{$this->getId()}'");782 $this->refresh();780 $status = $this->mDb->escapeString($status); 781 $this->mDb->execSqlUpdate("UPDATE nodes SET node_deployment_status = '{$status}' WHERE node_id = '{$this->getId()}'"); 782 $this->refresh(); 783 783 } 784 784 785 785 function getLastPaged() 786 786 { 787 return $this->mRow['last_paged'];787 return $this->mRow['last_paged']; 788 788 } 789 789 790 790 function setLastPaged($last_paged) 791 791 { 792 $this->mDb->execSqlUpdate("UPDATE nodes SET last_paged = {$last_paged}::abstime WHERE node_id = '{$this->getId()}'");793 $this->refresh();792 $this->mDb->execSqlUpdate("UPDATE nodes SET last_paged = {$last_paged}::abstime WHERE node_id = '{$this->getId()}'"); 793 $this->refresh(); 794 794 } 795 795 796 796 function getLastHeartbeatIP() 797 797 { 798 return $this->mRow['last_heartbeat_ip'];798 return $this->mRow['last_heartbeat_ip']; 799 799 } 800 800 801 801 function getLastHeartbeatUserAgent() 802 802 { 803 return $this->mRow['last_heartbeat_user_agent'];803 return $this->mRow['last_heartbeat_user_agent']; 804 804 } 805 805 806 806 function getLastHeartbeatTimestamp() 807 807 { 808 return $this->mRow['last_heartbeat_timestamp'];808 return $this->mRow['last_heartbeat_timestamp']; 809 809 } 810 810 811 811 function setLastHeartbeatTimestamp($timestamp) 812 812 { 813 $this->mDb->execSqlUpdate("UPDATE nodes SET last_heartbeat_timestamp = '{$timestamp}' WHERE node_id = '{$this->getId()}'");814 $this->refresh();813 $this->mDb->execSqlUpdate("UPDATE nodes SET last_heartbeat_timestamp = '{$timestamp}' WHERE node_id = '{$this->getId()}'"); 814 $this->refresh(); 815 815 } 816 816 … … 819 819 public function isSplashOnly() 820 820 { 821 return $this->getNetwork()->getSplashOnlyNodesAllowed() && $this->isConfiguredSplashOnly();821 return $this->getNetwork()->getSplashOnlyNodesAllowed() && $this->isConfiguredSplashOnly(); 822 822 } 823 823 … … 829 829 public function isConfiguredSplashOnly() 830 830 { 831 return (($this->mRow['is_splash_only_node'] == 't') ? true : false);831 return (($this->mRow['is_splash_only_node'] == 't') ? true : false); 832 832 } 833 833 … … 837 837 function setIsConfiguredSplashOnly($value) 838 838 { 839 $retval = true;840 if ($value != $this->isConfiguredSplashOnly())841 {842 $db = AbstractDb::getObject();843 $value ? $value = 'TRUE' : $value = 'FALSE';844 $retval = $db->execSqlUpdate("UPDATE nodes SET is_splash_only_node = {$value} WHERE node_id = '{$this->getId()}'", false);845 $this->refresh();846 }847 return $retval;839 $retval = true; 840 if ($value != $this->isConfiguredSplashOnly()) 841 { 842 $db = AbstractDb::getObject(); 843 $value ? $value = 'TRUE' : $value = 'FALSE'; 844 $retval = $db->execSqlUpdate("UPDATE nodes SET is_splash_only_node = {$value} WHERE node_id = '{$this->getId()}'", false); 845 $this->refresh(); 846 } 847 return $retval; 848 848 } 849 849 … … 853 853 function getCustomPortalRedirectUrl() 854 854 { 855 return $this->mRow['custom_portal_redirect_url'];855 return $this->mRow['custom_portal_redirect_url']; 856 856 } 857 857 … … 861 861 function setCustomPortalRedirectUrl($value) 862 862 { 863 $retval = true;864 if ($value != $this->getCustomPortalRedirectUrl())865 {866 $db = AbstractDb::getObject();867 $value = $db->escapeString($value);868 $retval = $db->execSqlUpdate("UPDATE nodes SET custom_portal_redirect_url = '{$value}' WHERE node_id = '{$this->getId()}'", false);869 $this->refresh();870 }871 return $retval;863 $retval = true; 864 if ($value != $this->getCustomPortalRedirectUrl()) 865 { 866 $db = AbstractDb::getObject(); 867 $value = $db->escapeString($value); 868 $retval = $db->execSqlUpdate("UPDATE nodes SET custom_portal_redirect_url = '{$value}' WHERE node_id = '{$this->getId()}'", false); 869 $this->refresh(); 870 } 871 return $retval; 872 872 } 873 873 … … 886 886 require_once('classes/InterfaceElements.php'); 887 887 // Init values 888 $html = '';889 if (!User::getCurrentUser()) {890 throw new Exception(_('Access denied!'));891 }892 893 // Get information about the network894 $network = $this->getNetwork();895 896 // Check if user is a admin897 $_userIsAdmin = User::getCurrentUser()->isSuperAdmin();898 899 $node_id = $this->getId();900 901 /*888 $html = ''; 889 if (!User::getCurrentUser()) { 890 throw new Exception(_('Access denied!')); 891 } 892 893 // Get information about the network 894 $network = $this->getNetwork(); 895 896 // Check if user is a admin 897 $_userIsAdmin = User::getCurrentUser()->isSuperAdmin(); 898 899 $node_id = $this->getId(); 900 901 /* 902 902 * Check for a warning message 903 903 */ -
trunk/wifidog-auth/wifidog/classes/SmartyWifidog.php
r1159 r1173 168 168 $this->assign('base_non_ssl_path', BASE_NON_SSL_PATH); 169 169 $this->assign('common_images_url', COMMON_IMAGES_URL); 170 171 /* Other useful stuff */172 Network::assignSmartyValues($this);173 Node::assignSmartyValues($this);174 User::assignSmartyValues($this);175 170 } 176 171 … … 179 174 $this->template_dir= $template_dir; 180 175 } 181 176 /** 177 * executes & returns or displays the template results 178 * 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. 179 * @param string $resource_name 180 * @param string $cache_id 181 * @param string $compile_id 182 * @param boolean $display 183 */ 184 public function fetch($resource_name, $cache_id = null, $compile_id = null, $display = false) 185 { 186 /* Other useful variables */ 187 Network::assignSmartyValues($this); 188 Node::assignSmartyValues($this); 189 User::assignSmartyValues($this); 190 return parent::fetch($resource_name, $cache_id, $compile_id, $display); 191 } 182 192 } 183 193
