Show
Ignore:
Timestamp:
10/05/05 22:57:30 (8 years ago)
Author:
benoitg
Message:

it Gr�goire <bock@…>

  • Remove a bunch of deprecated methods from the Node object, document undocumented methods.
  • Make the node id editable. This allows the gateway "MAC address as node ID" patch by London wireless to be usable with the standard auth server, and to transition to using MAC address as node ID.
  • Fix a saving problem with all the content types with some versions of PHP
  • Add a new Content type: IFrameRest. This allows the result of a REST style query returning HTML to be displayed in a HTML iframeset. Currently supported are substitution of the node_id, the user_id and the last display date in the get query.
  • CVS version of the auth server should now be "reasonnably" safe to use in production, so the 2005-09-01 notice is no longuer in effect.
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/wifidog-auth/wifidog/classes/Node.php

    r779 r788  
    2121 \********************************************************************/ 
    2222/**@file Node.php 
    23  * @author Copyright (C) 2005 Benoit Grgoire <bock@step.polymtl.ca> 
     23 * @author Copyright (C) 2005 Benoit Grégoire <bock@step.polymtl.ca> 
    2424 */ 
    2525 
     
    8686                $retval = null; 
    8787                $sql = "SELECT node_id, last_heartbeat_ip from nodes WHERE last_heartbeat_ip='$_SERVER[REMOTE_ADDR]' ORDER BY last_heartbeat_timestamp DESC"; 
     88                $node_rows = null; 
    8889                $db->ExecSql($sql, $node_rows, false); 
    8990                $num_match = count($node_rows); 
     
    292293                $html = ''; 
    293294                $name = "{$user_prefix}"; 
    294                 $status_list = self :: getAllDeploymentStatus(); 
    295                 if ($status_list != null) 
    296                 { 
     295                $status_list = null; 
     296                $db->ExecSql("SELECT node_deployment_status FROM node_deployment_status", $status_list, false); 
     297                if ($status_list == null) 
     298                        throw new Exception(_("No deployment statues  could be found in the database")); 
     299 
    297300                        $tab = array (); 
    298301                        foreach ($status_list as $status) 
    299                                 $tab[] = array ($status, $status); 
     302                                $tab[] = array ($status['node_deployment_status'], $status['node_deployment_status']); 
    300303                        $html .= FormSelectGenerator :: generateFromArray($tab, $this->getDeploymentStatus(), $name, null, false); 
    301                 } 
    302304                return $html; 
    303305        } 
     
    322324                $node_id_str = $db->EscapeString($node_id); 
    323325                $sql = "SELECT * FROM nodes WHERE node_id='$node_id_str'"; 
     326                $row = null; 
    324327                $db->ExecSqlUniqueRes($sql, $row, false); 
    325328                if ($row == null) 
     
    336339        } 
    337340 
     341/** Changing the id of a Node is supported.  
     342 *  Be carefull to anly call this when all other changes are processed,  
     343 * or the id used to generate the form names may no longer match. 
     344 * @param $id, string, the new node id. 
     345 * @return true on success, false on failure. Check this,  
     346 * as it's possible that someone will enter an existing id, especially 
     347 * if the MAC address is used and hardware is recycled. 
     348 */ 
     349        function setId($id) 
     350        { 
     351                $id = $this->mDb->EscapeString($id); 
     352                $retval = $this->mDb->ExecSqlUpdate("UPDATE nodes SET node_id = '{$id}' WHERE node_id = '{$this->getId()}'"); 
     353                if($retval) 
     354                { 
     355                $this->id = $id; 
     356                $this->refresh(); 
     357                } 
     358                return $retval; 
     359        } 
     360         
    338361        /** Gets the Network to which the node belongs  
    339362         * @return Network object (never returns null) 
     
    657680                $html .= "<div class='admin_section_title'>"._("Information about the node:")."</div>\n"; 
    658681 
     682 
     683                // Hashed node_id (this is a workaround since PHP auto-converts HTTP vars var periods, spaces or underscores ) 
     684                $hashed_node_id = md5($this->getId()); 
     685 
    659686                // Node ID 
    660687                $value = htmlspecialchars($this->getId(), ENT_QUOTES); 
    661688                $html .= "<div class='admin_section_container'>\n"; 
    662                 $html .= "<div class='admin_section_title'>"._("ID")." : {$value}</div>\n"; 
    663                 //$html .= "<div class='admin_section_data'>\n"; 
    664                 //$name = "node_".$this->getId()."_id"; 
    665                 //$html .= "<input type='text' readonly='' size='10' value='$value' name='$name'>\n"; 
    666                 //$html .= "</div>\n"; 
    667                 $html .= "</div>\n"; 
    668  
    669                 // Hashed node_id (this is a workaround since PHP auto-converts HTTP vars var periods, spaces or underscores ) 
    670                 $hashed_node_id = md5($this->getId()); 
     689                $html .= "<div class='admin_section_title'>"._("ID")." : </div>\n"; 
     690                $html .= "<div class='admin_section_data'>\n"; 
     691                $name = "node_".$hashed_node_id."_id"; 
     692                $html .= "<input type='text' size='20' value='$value' name='$name'>\n"; 
     693                $html .= "</div>\n"; 
     694                $html .= "</div>\n"; 
    671695 
    672696                // Name 
     
    11601184Content::processLinkedContentUI($name, 'node_has_content', 'node_id', $this->id); 
    11611185 
    1162         } 
     1186                // Name 
     1187                $name = "node_".$hashed_node_id."_id"; 
     1188                $this->setId($_REQUEST[$name]); 
     1189                                        } 
    11631190 
    11641191        // Redirect to this node's portal page 
     
    11961223                global $db; 
    11971224                $retval = array (); 
     1225                $content_rows = null; 
    11981226                // Get all network, but exclude user subscribed content if asked 
    11991227                if ($exclude_subscribed_content == true && $subscriber) 
     
    12201248                $retval = array (); 
    12211249                $sql = "SELECT * FROM content_group JOIN content ON (content.content_id = content_group.content_group_id) JOIN node_has_content ON (node_has_content.content_id = content_group.content_group_id AND node_has_content.node_id = '{$this->getId()}') WHERE is_persistent = true AND is_artistic_content = true AND is_locative_content = true ORDER BY subscribe_timestamp DESC"; 
     1250                $content_rows = null; 
    12221251                $db->ExecSql($sql, $content_rows, false); 
    12231252                if ($content_rows != null) 
     
    12421271        } 
    12431272 
    1244         /** Return all the nodes 
    1245          */ 
    1246         static function getAllNodes() 
    1247         { 
    1248                 global $db; 
    1249  
    1250                 $db->ExecSql("SELECT * FROM nodes", $nodes, false); 
    1251  
    1252                 if ($nodes == null) 
    1253                         throw new Exception(_("No nodes could not be found in the database")); 
    1254  
    1255                 return $nodes; 
    1256         } 
    1257  
    1258         static function getAllNodesOrdered($order_by) 
    1259         { 
    1260                 global $db; 
    1261  
    1262                 $nodes = null; 
    1263                 $db->ExecSql("SELECT * FROM nodes ORDER BY $order_by", $nodes, false); 
    1264  
    1265                 if ($nodes == null) 
    1266                         throw new Exception(_("No nodes could not be found in the database")); 
    1267  
    1268                 return $nodes; 
    1269         } 
    1270  
    1271         static function getAllDeploymentStatus() 
    1272         { 
    1273                 global $db; 
    1274  
    1275                 $statuses = null; 
    1276                 $db->ExecSql("SELECT * FROM node_deployment_status", $statuses, false); 
    1277                 if ($statuses == null) 
    1278                         throw new Exception(_("No deployment statues  could be found in the database")); 
    1279  
    1280                 $statuses_array = array (); 
    1281                 foreach ($statuses as $status) 
    1282                         array_push($statuses_array, $status['node_deployment_status']); 
    1283  
    1284                 return $statuses_array; 
    1285         } 
    1286  
    12871273        /** The list of users online at this node 
    12881274         * @return An array of User object, or en empty array */ 
     
    12911277                global $db; 
    12921278                $retval = array (); 
     1279                $users = null; 
    12931280                $db->ExecSql("SELECT users.user_id FROM users,connections WHERE connections.token_status='".TOKEN_INUSE."' AND users.user_id=connections.user_id AND connections.node_id='{$this->id}'", $users, false); 
    12941281                if ($users != null) 
     
    13051292         * @return Number of online users 
    13061293         */ 
    1307         function getNumOnlineUsers($node_id = null) 
     1294        function getNumOnlineUsers() 
    13081295        { 
    13091296                global $db; 
    13101297                $retval = array (); 
     1298                $row = null; 
    13111299                $db->ExecSqlUniqueRes("SELECT COUNT(DISTINCT users.user_id) as count FROM users,connections WHERE connections.token_status='".TOKEN_INUSE."' AND users.user_id=connections.user_id AND connections.node_id='{$this->id}'", $row, false); 
    13121300                return $row['count']; 
    13131301        } 
    13141302 
     1303        /** The list of all real owners of this node 
     1304         * @return An array of User object, or en empty array */ 
    13151305        function getOwners() 
    13161306        { 
    13171307                global $db; 
    13181308                $retval = array (); 
     1309                $owners = null; 
    13191310                $db->ExecSql("SELECT user_id FROM node_stakeholders WHERE is_owner = true AND node_id='{$this->id}'", $owners, false); 
    13201311                if ($owners != null) 
     
    13281319        } 
    13291320 
     1321        /** The list of all Technical officers of this node.   
     1322         * Technical officers are displayed highlited and in the online user's list,  
     1323         * and are contacted when the Node goes down. 
     1324         * @return An array of User object, or en empty array */ 
    13301325        function getTechnicalOfficers() 
    13311326        { 
    13321327                global $db; 
    13331328                $retval = array (); 
     1329                $officers = null; 
    13341330                $db->ExecSql("SELECT user_id FROM node_stakeholders WHERE is_tech_officer = true AND node_id='{$this->id}'", $officers, false); 
    13351331                if ($officers != null) 
     
    13491345        { 
    13501346                global $db; 
     1347                $rows = null; 
    13511348                $db->ExecSql("SELECT * FROM node_stakeholders WHERE node_id = '{$this->getId()}' AND user_id = '{$user->getId()}'", $rows, false); 
    13521349                if (!$rows) 
     
    13661363        { 
    13671364                global $db; 
     1365                $rows = null; 
    13681366                $db->ExecSql("SELECT * FROM node_stakeholders WHERE node_id = '{$this->getId()}' AND user_id = '{$user->getId()}'", $rows, false); 
    13691367                if (!$rows) 
     
    13741372                else 
    13751373                        if (!$db->ExecSqlUpdate("UPDATE node_stakeholders SET is_tech_officer = true WHERE node_id = '{$this->getId()}' AND user_id = '{$user->getId()}';", false)) 
    1376                                 throw new Exception(_('Could not add tech officer')); 
    1377         } 
    1378  
    1379         /** Remove a technical officer ( tech support ) from this node 
     1374                                throw new Exception(_('Could not set existing user as tech officer')); 
     1375        } 
     1376 
     1377        /** Remove owner flag for a stakeholder of this node 
    13801378         * @param User 
    13811379         */ 
     
    13871385        } 
    13881386 
    1389         /** Remove a technical officer ( tech support ) from this node 
     1387        /** Remove technical officer flag for a stakeholder of this node 
    13901388         * @param User 
    13911389         */ 
     
    14061404                        $user_id = $user->getId(); 
    14071405                        $retval = false; 
     1406                        $row = null; 
    14081407                        $db->ExecSqlUniqueRes("SELECT * FROM node_stakeholders WHERE is_owner = true AND node_id='{$this->id}' AND user_id='{$user_id}'", $row, false); 
    14091408                        if ($row != null) 
     
    14241423                        $user_id = $user->getId(); 
    14251424                        $retval = false; 
     1425                        $row = null; 
    14261426                        $db->ExecSqlUniqueRes("SELECT * FROM node_stakeholders WHERE is_tech_officer = true AND node_id='{$this->id}' AND user_id='{$user_id}'", $row, false); 
    14271427                        if ($row != null) 
     
    14401440                $id_str = $db->EscapeString($id); 
    14411441                $sql = "SELECT * FROM nodes WHERE node_id='{$id_str}'"; 
     1442                $row = null; 
    14421443                $db->ExecSqlUniqueRes($sql, $row, false); 
    14431444                if ($row != null) 
     
    14481449        } 
    14491450 
    1450         /** Warning, the semantics of this function will change * 
    1451          * @deprecated version - 2005-04-29 USE getOnlineUsers instead 
    1452          * */ 
    1453         public static function getAllOnlineUsers() 
    1454         { 
    1455                 global $db; 
    1456                 $db->ExecSql("SELECT * FROM connections,users,nodes WHERE token_status='".TOKEN_INUSE."' AND users.user_id=connections.user_id AND nodes.node_id=connections.node_id ORDER BY timestamp_in DESC", $online_users); 
    1457                 return $online_users; 
    1458         } 
    1459  
    14601451        /** Reloads the object from the database.  Should normally be called after a set operation */ 
    14611452        protected function refresh()