/[locfinder]/locfinder/functions/func_node.php
ViewVC logotype

Diff of /locfinder/functions/func_node.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by yob, Wed Jan 15 11:19:39 2003 UTC revision 1.2 by yob, Sun Jan 19 14:41:11 2003 UTC
# Line 23  Line 23 
23   *    GNU General Public License for more details.   *    GNU General Public License for more details.
24   *   *
25   *    You should have received a copy of the GNU General Public License   *    You should have received a copy of the GNU General Public License
26   *    along with Foobar; if not, write to the Free Software   *    along with locfinder; if not, write to the Free Software
27   *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
28   *   *
29   ********************************************************************/   ********************************************************************/
# Line 44  if($in_locfinder) { Line 44  if($in_locfinder) {
44    
45      function get_node_wiki($node_id) {      function get_node_wiki($node_id) {
46    
47          GLOBAL $opt_wiki;          GLOBAL $opt_wiki_url;
         GLOBAL $opt_wiki_url;  
48          GLOBAL $opt_wiki_prefix;          GLOBAL $opt_wiki_prefix;
49    
50          return "http://" . $opt_wiki_url . $opt_wiki_prefix . $node_id;          return "http://" . $opt_wiki_url . $opt_wiki_prefix . $node_id;
# Line 66  if($in_locfinder) { Line 65  if($in_locfinder) {
65       *       *
66       */       */
67            
68      function create_node($node_owner, $node_email, $node_name, $node_suburb, $node_lat, $node_long, $area, $ospf_mode, $node_url, $node_status, $node_password, $node_password_confirm) {      function create_node($node_name, $node_suburb, $node_lat, $node_long, $area, $node_url, $node_status) {
   
         // Declare any global variables needed  
         GLOBAL $err_message;  
69    
70          // create the database class          // create the database class
71          $loc_db = new locDatabase;          $loc_db = new locDatabase;
72    
73          // if the required fields aren't fileld in          // if the required fields aren't fileld in
74          if (($node_email == "") || ($node_name == "") || ((int)$node_lat == 0) || ((int)$node_long == 0) || ($node_password == "") || ($node_password_confirm == "")) { //all values are set          if (($node_name == "") || ((int)$node_lat == 0) || ((int)$node_long == 0)) { //all values are set
75    
76              $err_message = "error. required fields were missing.";              $_SESSION["msg"] = "error. required fields were missing.";
77                $_SESSION["msg_type"] = 0;
78              return false;              return false;
79    
80          // if supplied coords are outside the state          // if supplied coords are outside the state
81          } elseif (((int)$node_lat < -39) || ((int)$node_lat > -35)) {          } elseif (((int)$node_lat < -39) || ((int)$node_lat > -35)) {
82    
83              $err_message = "error. Your coordinates seem to be _non-victorian_";              $_SESSION["msg"] = "error. Your coordinates seem to be _non-victorian_";
84                $_SESSION["msg_type"] = 0;
85    
86              return false;              return false;
87    
88          // if supplied coords are outside the state          // if supplied coords are outside the state
89          } elseif (((int)$node_long < 130) || ((int)$node_long > 150)) {          } elseif (((int)$node_long < 130) || ((int)$node_long > 150)) {
90    
91              $err_message = "error. Your coordinates seem to be _non-victorian_";              $_SESSION["msg"] = "error. Your coordinates seem to be _non-victorian_";
92              return false;              $_SESSION["msg_type"] = 0;
   
         // if the choosen password is too long  
         } elseif (strlen($node_password) > 10) {  
   
             $err_message = "error. Your password is greater than 10 characters";  
             return false;  
   
         // if the password fields don't match  
         } elseif ($node_password != $node_password_confirm) {  
93    
             $err_message = "error. The password fields don't match...";  
94              return false;              return false;
95    
         // if the mode fields don't match  
         } elseif ($ospf_mode == "--") {  
   
             $err_message = "error. -- isn't a valid area";  
             return false;  
               
96          // if we get past all that, then add the node          // if we get past all that, then add the node
97          } else {          } else {
98    
# Line 173  if($in_locfinder) { Line 156  if($in_locfinder) {
156              }              }
157    
158              // put the SQL together to insert the new node              // put the SQL together to insert the new node
159              $sql = "INSERT INTO nodes(id, owner, email, name, suburb, latitude, longitude, url, status, area, ospf_mode, password, updated) VALUES('$node_id', '$node_owner', '$node_email', '$node_name', '$node_suburb', $node_lat, $node_long, '$node_url', '$node_status', $area, '$ospf_mode', '$node_password', now())";              $sql = "INSERT INTO nodes(id, owner, name, suburb, latitude, longitude, url, status, area, updated) VALUES('$node_id', '" . $_SESSION["logged_in"] . "', '$node_name', '$node_suburb', $node_lat, $node_long, '$node_url', '$node_status', $area, now())";
160    
161              $loc_db->query( $sql );              $loc_db->query( $sql );
162    
163              // update the node shp files to show the new node              // update the node shp files to show the new node
164              update_shp_nodes();              update_shp_nodes();
165    
166                $_SESSION["msg"] = "Node successfully created";
167                $_SESSION["msg_type"] = 1;
168    
169              // return the new nodes ID              // return the new nodes ID
170              return $node_id;              return $node_id;
171    
# Line 200  if($in_locfinder) { Line 186  if($in_locfinder) {
186       *       *
187       */       */
188    
189      function update_node($node_id, $node_name, $node_owner, $node_email, $node_status, $node_suburb, $node_long, $node_lat, $area, $ospf_mode, $node_url, $notify_updates, $notify_nearby, $node_password, $node_confirm_password) {      function update_node($node_id, $node_name, $node_status, $node_suburb, $node_long, $node_lat, $area, $node_url, $notify_nearby) {
   
         // declare goxes global variables required for function  
         GLOBAL $err_message;  
         GLOBAL $success_message;  
         GLOBAL $question;  
190    
191          // create database classes          // create database classes
192          $loc_db = new locDatabase;          $loc_db = new locDatabase;
193          $loc_db_2 = new locDatabase;          $loc_db_2 = new locDatabase;
194                    
         if ($notify_updates == "on") {  
           
             $notify_updates = 1;  
           
         } else {  
           
             $notify_updates = 0;  
           
         }  
   
         // if the password and password confirmation box don't match  
         if ($node_password != $node_confirm_password) {  
   
             $err_message = "error. Passwords dont match.";  
             return false;  
   
         // if the choosen password is too long  
         } elseif (strlen($node_password) > 10) {  
   
             $err_message = "error. Your password is greater than 10 characters";  
             return false;  
   
195          // if required fields were missed          // if required fields were missed
196          } elseif (($node_email == "") || ($node_long == "") || ($node_lat == "")) {          if (($node_long == "") || ($node_lat == "")) {
197    
198              $err_message = "error. you missed a required field.";              $_SESSION["msg"] = "error. you missed a required field.";
199                $_SESSION["msg_type"] = 0;
200              return false;              return false;
201    
202          // if supplied coords are outside the state          // if supplied coords are outside the state
203          } elseif (((int)$node_lat < -39) || ((int)$node_lat > -35)) {          } elseif (((int)$node_lat < -39) || ((int)$node_lat > -35)) {
204    
205              $err_message = "error. your coordinates seem to be _non-victorian_";              $_SESSION["msg"] = "error. your coordinates appear to be _non victorian_.";
206                $_SESSION["msg_type"] = 0;
207              return false;              return false;
208    
209          // if supplied coords are outside the state          // if supplied coords are outside the state
210          } elseif (((int)$node_long < 130) || ((int)$node_long > 150)) {          } elseif (((int)$node_long < 130) || ((int)$node_long > 150)) {
211    
212              $err_message = "error. your coordinates seem to be _non-victorian_";              $_SESSION["msg"] = "error. your coordinates appear to be _non victorian_";
213              return false;              $_SESSION["msg_type"] = 0;
   
         // if the mode fields don't match  
         } elseif ($ospf_mode == "--") {  
   
             $err_message = "error. -- isn't a valid area";  
214              return false;              return false;
215    
216          // if we pass all those tests, then the data is okay!          // if we pass all those tests, then the data is okay!
# Line 269  if($in_locfinder) { Line 225  if($in_locfinder) {
225    
226              $loc_db->next_record();              $loc_db->next_record();
227                            
228                // assign the old details to variables
229              $old_status = $loc_db->f("status");              $old_status = $loc_db->f("status");
230              $old_area = (int)$loc_db->f("area");              $old_area = (int)$loc_db->f("area");
231    
# Line 280  if($in_locfinder) { Line 237  if($in_locfinder) {
237    
238                  flush_assignments($node_id, true, true, false);                  flush_assignments($node_id, true, true, false);
239    
                 $ospf_mode = "none";  
                   
240                  $tmp_success_message .= "<P>please note.. since you changed your OSPF Area, you will have to re-request IP addresses that come from your new Area";                  $tmp_success_message .= "<P>please note.. since you changed your OSPF Area, you will have to re-request IP addresses that come from your new Area";
241    
242              }              }
243    
             // if the user changes their ospf status to none when it wasn't before  
             //  the edit, they are no longer able to be router nodes or form  
             //  the backbone, so all their interfaces become regular ones, and they  
             //  lose their routing IP allocations              
             //if (($loc_db->f("ospf_mode") != "none") && ($ospf_mode == "none")) {  
               
             //     $sql = "UPDATE interfaces set class='regular' WHERE node='" . $node_id . "'";  
   
             //     $loc_db_2->query( $sql );  
                   
             //     flush_assignments($node_id, false, true, true);  
                   
             //}  
   
244              // if the node status has been operational or testing, and the user              // if the node status has been operational or testing, and the user
245              //  changes it to something lower, they can no longer have              //  changes it to something lower, they can no longer have
246              //  services, interfaces, links or IP allocations, so they must all              //  services, interfaces, links or IP allocations, so they must all
# Line 314  if($in_locfinder) { Line 255  if($in_locfinder) {
255    
256              }              }
257    
258              // if user doesn't want to change their password              $sql = "UPDATE nodes SET name='$node_name',  status='$node_status', suburb='$node_suburb', latitude=$node_lat, longitude=$node_long, area=$area, url='$node_url', notify_nearby=$notify_nearby WHERE id='$node_id'";
             if ($node_password == "") {  
                 $sql = "UPDATE nodes SET name='$node_name', owner='$node_owner', email='$node_email', status='$node_status', suburb='$node_suburb', latitude=$node_lat, longitude=$node_long, area=$area, ospf_mode='$ospf_mode', url='$node_url', notify_updates=$notify_updates, notify_nearby=$notify_nearby WHERE id='$node_id'";  
             // or if they do!  
             } else {  
                 $sql = "UPDATE nodes SET name='$node_name', owner='$node_owner', email='$node_email', status='$node_status', suburb='$node_suburb', latitude=$node_lat, longitude=$node_long, area=$area, ospf_mode='$ospf_mode', url='$node_url', notify_updates=$notify_updates, notify_nearby=$notify_nearby, password='$node_password' WHERE id='$node_id'";  
             }  
259    
260              // update the database!              // update the database!
261              $loc_db->query( $sql );              $loc_db->query( $sql );
# Line 336  if($in_locfinder) { Line 271  if($in_locfinder) {
271              }              }
272    
273              // set the message to be returned to the user              // set the message to be returned to the user
274              $success_message = "general node information updated..." . $tmp_success_message;              $_SESSION["msg"] = "general node information updated..." . $tmp_success_message;
275                            $_SESSION["msg_type"] = 1;
276    
277              // function was sucessful              // function was sucessful
278              return true;              return true;
279    
# Line 359  if($in_locfinder) { Line 295  if($in_locfinder) {
295    
296      function flush_links($node_id) {      function flush_links($node_id) {
297    
298          // create database  classes          // create database classes
299          $loc_db = new locDatabase;          $loc_db = new locDatabase;
300          $loc_db_2 = new locDatabase;          $loc_db_2 = new locDatabase;
301    
# Line 372  if($in_locfinder) { Line 308  if($in_locfinder) {
308          //  to it          //  to it
309          while ($loc_db->next_record()) {          while ($loc_db->next_record()) {
310    
311              $sql = "DELETE FROM links WHERE ((interface_1 = " . $loc_db->f("int_id") . ") OR (interface_2 = " . $loc_db->f("int_id") . "))";              // delete any links with an end that belongs to the node
312                //  we're flushing
313                $sql = "DELETE FROM links WHERE ((interface_1 = " . $loc_db->f("id") . ") OR (interface_2 = " . $loc_db->f("id") . "))";
314    
315              $loc_db_2->query( $sql );              $loc_db_2->query( $sql );
316    
# Line 460  if($in_locfinder) { Line 398  if($in_locfinder) {
398    
399      function delete_node($node_id) {      function delete_node($node_id) {
400    
         // declare global variables  
         GLOBAL $success_message;  
   
401          // create database class          // create database class
402          $loc_db = new locDatabase;          $loc_db = new locDatabase;
403    
404          // delete all the extras in the database that relate to          // delete all the extras in the database that relate to
405          //  this node          //  this node
406          flush_assignments($node_id, true, true, true);          flush_assignments($node_id, true, true);
407          flush_links($node_id);          flush_links($node_id);
408          flush_interfaces($node_id);          flush_interfaces($node_id);
409          flush_services($node_id);          flush_services($node_id);
# Line 478  if($in_locfinder) { Line 413  if($in_locfinder) {
413    
414          $loc_db->query( $sql );          $loc_db->query( $sql );
415    
416          // let the user node the deletion was successful          $_SESSION["msg"] = "node" . $node_id . " has been deleted...";
417          $success_message = "node" . $node_id . " has been deleted...";          $_SESSION["msg_type"] = 0;
418    
419          // function successful          // function successful
420          return true;          return true;
# Line 503  if($in_locfinder) { Line 438  if($in_locfinder) {
438      function touch_node($node_id, $hash) {      function touch_node($node_id, $hash) {
439    
440          // declare global variables          // declare global variables
         GLOBAL $err_message;  
441          GLOBAL $opt_server;          GLOBAL $opt_server;
442    
443          // create the database class          // create the database class
444          $loc_db = new locDatabase;          $loc_db = new locDatabase;
445    
446          // select the nodes information from the DB          // select the nodes information from the DB
447          $sql = "SELECT * FROM nodes where id='" . $node_id . "'";;          $sql = "SELECT users.password FROM nodes, users where node.id='" . $node_id . "'";;
448    
449          $loc_db->query( $sql );          $loc_db->query( $sql );
450    
451          $loc_db->next_record();          $loc_db->next_record();
452    
453          // if the hash is incorrect          // if the hash is incorrect
454          if ($hash != md5($loc_db->f("id") . $opt_server . $loc_db->f("email") . $loc_db->f("suburb"))) {          if ($hash != $loc_db->f("password")) {
455    
456              // the function failed, and inform the user why              // the function failed, and inform the user why
457              $err_message = "error. Incorrect Hash";              $_SESSION["msg"] = "error. Incorrect Hash";
458                $_SESSION["msg_type"] = 0;
459    
460              return false;              return false;
461                    
462          // otherwise, the hash ir correct          // otherwise, the hash ir correct
# Line 529  if($in_locfinder) { Line 465  if($in_locfinder) {
465              // so tell the database that the node was updated today              // so tell the database that the node was updated today
466              updated_today($node_id);              updated_today($node_id);
467    
468                $_SESSION["msg"] = "Node age successfully reset";
469                $_SESSION["msg_type"] = 1;
470    
471              // function successful              // function successful
472              return true;              return true;
473    
# Line 580  if($in_locfinder) { Line 519  if($in_locfinder) {
519    
520      function create_link($interface_1, $interface_2) {      function create_link($interface_1, $interface_2) {
521    
         // declare global variables  
         GLOBAL $success_message;  
   
522          // create DB class          // create DB class
523          $loc_db = new locDatabase;          $loc_db = new locDatabase;
524    
         // select the class of the first interface (regular or backbone)  
         $sql = "SELECT class FROM interfaces WHERE int_id=" . $interface_1;  
   
         $loc_db->query( $sql );  
   
         $loc_db->next_record();  
   
         // store this value in a variable for later reference  
         $interface_1_class = $loc_db->f("class");  
   
         // select the class of the second interface (regular or backbone)  
         $sql = "SELECT class FROM interfaces WHERE int_id=" . $interface_2;  
   
         $loc_db->query( $sql );  
   
         $loc_db->next_record();  
           
         // also store this value in a variable for later reference  
         $interface_2_class = $loc_db->f("class");  
   
         // if both interfaces that make up the link are backbones,  
         //  then the link is a backbone link (a link bewteen 2 area/system  
         //  border routers. These appear a different colour on the map  
         if (($interface_1_class == "backbone") && ($interface_2_class == "backbone")) {  
   
             $class = "backbone";  
   
         } elseif (($interface_1_class == "router") && ($interface_2_class == "router")) {  
   
             $class = "router";  
           
         } else {  
           
             $class = "regular";  
   
         }  
   
525          // build the SQL statement to insert the link into the DB          // build the SQL statement to insert the link into the DB
526          $sql = "INSERT INTO links(interface_1, interface_2, class) VALUES('$interface_1', '$interface_2', '$class')";          $sql = "INSERT INTO links(interface_1, interface_2) VALUES('$interface_1', '$interface_2')";
527    
528          $loc_db->query( $sql );          $loc_db->query( $sql );
529    
530          // rewrite the link shp files to show the new link          // rewrite the link shp files to show the new link
531          update_shp_links();          update_shp_links();
532    
533          // let the user know the creation was successful          $_SESSION["msg"] = "Link successfully created";
534          $success_message = "link successfully added...";          $_SESSION["msg_type"] = 1;
535    
536          // function successful          // function successful
537          return true;          return true;
# Line 654  if($in_locfinder) { Line 553  if($in_locfinder) {
553    
554      function delete_link($link_id) {      function delete_link($link_id) {
555    
         // declare global variables  
         GLOBAL $success_message;  
   
556          // create the DB class          // create the DB class
557          $loc_db = new locDatabase;          $loc_db = new locDatabase;
558    
559          // build SQL statement          // build SQL statement
560          $sql = "DELETE FROM links WHERE link_id=" . $link_id;          $sql = "DELETE FROM links WHERE id=" . $link_id;
561    
562          $loc_db->query( $sql );          $loc_db->query( $sql );
563    
# Line 669  if($in_locfinder) { Line 565  if($in_locfinder) {
565          update_shp_links();          update_shp_links();
566    
567          // let the user know the deletion was successful          // let the user know the deletion was successful
568          $success_message = "link successfully deleted...";          $_SESSION["msg"] = "Link succesfully deleted";
569            $_SESSION["msg_type"] = 1;
570    
571          // function successful          // function successful
572          return true;          return true;
# Line 691  if($in_locfinder) { Line 588  if($in_locfinder) {
588    
589      function create_interface($node_id, $card_power, $card_receive, $card_manufacturer, $antenna_dbi, $antenna_type, $cable_loss, $mode, $class, $mac, $channel) {      function create_interface($node_id, $card_power, $card_receive, $card_manufacturer, $antenna_dbi, $antenna_type, $cable_loss, $mode, $class, $mac, $channel) {
590    
         // declare global variables  
         GLOBAL $success_message;  
         GLOBAL $err_message;  
   
591          // create the DB class          // create the DB class
592          $loc_db = new locDatabase;          $loc_db = new locDatabase;
593    
# Line 722  if($in_locfinder) { Line 615  if($in_locfinder) {
615          // if the channel is outside valid values          // if the channel is outside valid values
616          if ((((int)$channel > 13) || ((int)$channel < 0)) && ($channel != -1)) {          if ((((int)$channel > 13) || ((int)$channel < 0)) && ($channel != -1)) {
617    
618              $err_message = "invalid channel";              $_SESSION["msg"] = "error. Invalid channel";
619                $_SESSION["msg_type"] = 0;
620    
621              return false;              return false;
622    
623          // if the card power is outside valid values          // if the card power is outside valid values
624          } elseif ((((int)$card_power > 30) || ((int)$card_power < 0)) && ($card_power != -1)) {          } elseif ((((int)$card_power > 30) || ((int)$card_power < 0)) && ($card_power != -1)) {
625    
626              $err_message = "invalid card power";              $_SESSION["msg"] = "error. Invalid card power";
627                $_SESSION["msg_type"] = 0;
628    
629              return false;              return false;
630    
631          // if the card recieve is positive          // if the card recieve is positive
# Line 737  if($in_locfinder) { Line 634  if($in_locfinder) {
634          //  and it doesn't hurt to be lenient          //  and it doesn't hurt to be lenient
635          } elseif ((int)$card_receive > 0) {          } elseif ((int)$card_receive > 0) {
636    
637              $err_message = "invalid card receive sensitivity";              $_SESSION["msg"] = "error. invalid card receive sensitivity";
638                $_SESSION["msg_type"] = 0;
639                
640              return false;              return false;
641    
642          // if the antenna's gain is outside valid values          // if the antenna's gain is outside valid values
# Line 745  if($in_locfinder) { Line 644  if($in_locfinder) {
644          //  doesn't hurt. Means less errors for the user          //  doesn't hurt. Means less errors for the user
645          } elseif ((((int)$antenna_dbi > 40) || ((int)$antenna_dbi < 0)) && ($antenna_dbi != -1)) {          } elseif ((((int)$antenna_dbi > 40) || ((int)$antenna_dbi < 0)) && ($antenna_dbi != -1)) {
646    
647              $err_message = "invalid antenna gain";              $_SESSION["msg"] = "error. invalid antenna gain";
648                $_SESSION["msg_type"] = 0;
649                
650              return false;              return false;
651    
652          // If the cable loss value is outside a valid range          // If the cable loss value is outside a valid range
653          //  if your losing 30dB of power in your cable, you have a problem!          //  if your losing 30dB of power in your cable, you have a problem!
654          } elseif ((((int)$cable_loss > 30) || ((int)$cable_loss < 0)) && ($cable_loss!= -1)) {          } elseif ((((int)$cable_loss > 30) || ((int)$cable_loss < 0)) && ($cable_loss!= -1)) {
655    
656              $err_message = "invalid cable loss";              $_SESSION["msg"] = "error. invalid cable loss";
657                $_SESSION["msg_type"] = 0;
658                
659              return false;              return false;
660    
661      // if something has been entered into the mac field, mac sure      // if something has been entered into the mac field, mac sure
662      //  it is a proper mac address\      //  it is a proper mac address\
663      } elseif ((!ereg("^([0-9|a-f]{2}:){5}[0-9|a-f]{2}$", $mac)) && ($mac != "unknown")) {      } elseif ((!ereg("^([0-9|a-f]{2}:){5}[0-9|a-f]{2}$", $mac)) && ($mac != "unknown")) {
664    
665          $err_message = "invalid mac address. Must be in the form 'xx:xx:xx:xx:xx:xx'";          $_SESSION["msg"] = "error. invalid mac address. Must be in the form 'xx:xx:xx:xx:xx:xx'";
666            $_SESSION["msg_type"] = 0;
667                
668          return false;            return false;  
669    
670          // otherwise, all the data is fine!      // otherwise, all the data is fine!
671          } else {      } else {
672    
673              // build the SQL statement to insert the new interface          // build the SQL statement to insert the new interface
674              $sql = "INSERT INTO interfaces(node, card_power, card_receive, card_manufacturer, antenna_dbi, antenna_type, cable_loss, mode, class, mac, channel) VALUES('" . strtoupper($node_id) . "', " . (int)$card_power . ", " . (int)$card_receive . ", '$card_manufacturer'," . (int)$antenna_dbi . ",  '$antenna_type'," . (int)$cable_loss . ", '$mode', '$class', '$mac', " . (int)$channel  . ")";          $sql = "INSERT INTO interfaces(node, card_power, card_receive, card_manufacturer, antenna_dbi, antenna_type, cable_loss, mode, class, mac, channel) VALUES('" . strtoupper($node_id) . "', " . (int)$card_power . ", " . (int)$card_receive . ", '$card_manufacturer'," . (int)$antenna_dbi . ",  '$antenna_type'," . (int)$cable_loss . ", '$mode', '$class', '$mac', " . (int)$channel  . ")";
675                            
676              $loc_db->query( $sql );          $loc_db->query( $sql );
677    
678              // let the user know the operation was successful          // let the user know the operation was successful
679              $success_message = "interface successfully added...";          $_SESSION["msg"] = "interface successfully added...";
680            $_SESSION["msg_type"] = 1;
681            
682              // function sucessful!          // function sucessful!
683              return true;          return true;
684    
685          } // end validation if      } // end validation if
686    
687      } // end create_interface()  } // end create_interface()
688    
689      /*      /*
690       * update_interface()       * update_interface()
# Line 795  if($in_locfinder) { Line 701  if($in_locfinder) {
701    
702      function update_interface($int_id, $node_id, $card_power, $card_receive, $card_manufacturer, $antenna_dbi, $antenna_type, $cable_loss, $mode, $class, $mac, $channel) {      function update_interface($int_id, $node_id, $card_power, $card_receive, $card_manufacturer, $antenna_dbi, $antenna_type, $cable_loss, $mode, $class, $mac, $channel) {
703    
704          // declare global variables          // create the DB class
705          GLOBAL $err_message;          $loc_db = new locDatabase;
         GLOBAL $success_message;  
706    
707          // set all the fields left blank by the user to their default          // set all the fields left blank by the user to their default
708          if ($mac == "")          if ($mac == "")
# Line 818  if($in_locfinder) { Line 723  if($in_locfinder) {
723          if ($cable_loss == "")          if ($cable_loss == "")
724              $cable_loss = -1;              $cable_loss = -1;
725    
         // create the DB class  
         $loc_db = new locDatabase;  
   
726          // if the card power is outside valid values          // if the card power is outside valid values
727          if ((((int)$channel > 13) || ((int)$channel < 0)) && ($channel != -1)) {          if ((((int)$channel > 13) || ((int)$channel < 0)) && ($channel != -1)) {
728    
729              $err_message = "error. invalid channel";              $_SESSION["msg"] = "error. Invalid channel";
730                $_SESSION["msg_type"] = 0;
731    
732              return false;              return false;
733                    
734          // if the card power is outside valid values          // if the card power is outside valid values
735          } elseif ((((int)$card_power > 30) || ((int)$card_power < 0)) && ($card_power != -1)) {          } elseif ((((int)$card_power > 30) || ((int)$card_power < 0)) && ($card_power != -1)) {
736    
737              $err_message = "error. invalid card power";              $_SESSION["msg"] = "error. Invalid card power";
738                $_SESSION["msg_type"] = 0;
739    
740              return false;              return false;
741    
742          // if the card recieve is positive          // if the card recieve is positive
# Line 839  if($in_locfinder) { Line 745  if($in_locfinder) {
745          //  and it doesn't hurt to be lenient          //  and it doesn't hurt to be lenient
746          } elseif ((int)$card_receive > 0) {          } elseif ((int)$card_receive > 0) {
747    
748              $err_message = "error. invalid card receive sensitivity";              $_SESSION["msg"] = "error. Invalid receive sensitivity";
749                $_SESSION["msg_type"] = 0;
750    
751              return false;              return false;
752    
753          // if the antenna's gain is outside valid values          // if the antenna's gain is outside valid values
# Line 847  if($in_locfinder) { Line 755  if($in_locfinder) {
755          //  doesn't hurt. Means less errors for the user          //  doesn't hurt. Means less errors for the user
756          } elseif ((((int)$antenna_dbi > 40) || ((int)$antenna_dbi < 0)) && ($antenaa_dbi != -1)) {          } elseif ((((int)$antenna_dbi > 40) || ((int)$antenna_dbi < 0)) && ($antenaa_dbi != -1)) {
757    
758              $err_message = "error. invalid antenna gain";              $_SESSION["msg"] = "error. Invalid antenna gain";
759                $_SESSION["msg_type"] = 0;
760    
761              return false;              return false;
762    
763          // If the cable loss value is outside a valid range          // If the cable loss value is outside a valid range
# Line 861  if($in_locfinder) { Line 771  if($in_locfinder) {
771          //  it is a proper mac address\          //  it is a proper mac address\
772          } elseif ((!ereg("^([0-9|a-f]{2}:){5}[0-9|a-f]{2}$", $mac)) && ($mac != "unknown")) {          } elseif ((!ereg("^([0-9|a-f]{2}:){5}[0-9|a-f]{2}$", $mac)) && ($mac != "unknown")) {
773    
774                  $err_message = "invalid mac address. Must be in the form 'xx:xx:xx:xx:xx:xx'";              $_SESSION["msg"] = "error. invalid mac address. Must be in the form 'xx:xx:xx:xx:xx:xx'";
775                  return false;              $_SESSION["msg_type"] = 0;
776    
777                return false;
778    
779          // otherwise, all the data is fine!          // otherwise, all the data is fine!
780          } else {          } else {
781    
782              // pull un-updated data from the DB so we can chec              // pull un-updated data from the DB so we can check
783              //  to see if some things have changed, and if so,              //  to see if some things have changed, and if so,
784              //  run any code that needs running              //  run any code that needs running
785              $sql = "SELECT * from interfaces WHERE int_id=" . $int_id;              $sql = "SELECT * from interfaces WHERE id=" . $int_id;
786                            
787              $loc_db->query( $sql );              $loc_db->query( $sql );
788                            
789              $loc_db->next_record();              $loc_db->next_record();
790                            
791                // if the class of the interface has changed from p2p to
792                //  something else
793              if (($loc_db->f("class") != $class) && ($loc_db->f("class") == "p2p")) {              if (($loc_db->f("class") != $class) && ($loc_db->f("class") == "p2p")) {
794                            
795                  $sql = "select address from ip_assignments where ((node_interface='" . $int_id . "') AND (type='" . $loc_db->f("class") . "'))";                  // select this interfaces ip address
796                    $sql = "select address from addresses where node_interface='" . $int_id . "'";
797    
798                  $loc_db->query( $sql );                  $loc_db->query( $sql );
799                            
800                  $loc_db->next_record();                  $loc_db->next_record();
801                                    
802                    // delete any ips assigned to this interface
803                  delete_assignment($loc_db->f("address"));                  delete_assignment($loc_db->f("address"));
804                    
805                    // delete any requests for ips to this interface
806                  delete_request($int_id, "router");                  delete_request($int_id, "router");
807                                    
808              }              }
809                            
810              // build the SQL statement to update the DB              // build the SQL statement to update the DB
811              $sql = "UPDATE interfaces SET card_power=" . (int)$card_power . ", card_receive=" . (int)$card_receive . ", card_manufacturer='$card_manufacturer', antenna_dbi=" . (int)$antenna_dbi . ", antenna_type='$antenna_type', cable_loss=" . (int)$cable_loss . ", mode='$mode', class='$class', mac='$mac', channel=" . (int)$channel . " WHERE int_id=" . $int_id;              $sql = "UPDATE interfaces SET card_power=" . (int)$card_power . ", card_receive=" . (int)$card_receive . ", card_manufacturer='$card_manufacturer', antenna_dbi=" . (int)$antenna_dbi . ", antenna_type='$antenna_type', cable_loss=" . (int)$cable_loss . ", mode='$mode', class='$class', mac='$mac', channel=" . (int)$channel . " WHERE id=" . $int_id;
812    
813              $loc_db->query( $sql );              $loc_db->query( $sql );
814    
815              // let the user know the update was successful              // let the user know the update was successful
816              $success_message = "interface successfully updated...";              $_SESSION["msg"] = "interface successfully updated";
817                $_SESSION["msg_type"] = 1;
818    
819              // function successful              // function successful
820              return true;              return true;
# Line 919  if($in_locfinder) { Line 838  if($in_locfinder) {
838    
839      function delete_interface($int_id) {      function delete_interface($int_id) {
840    
         // declare global variables  
         GLOBAL $success_message;  
   
841          // create the DB class          // create the DB class
842          $loc_db = new locDatabase;          $loc_db = new locDatabase;
843    
# Line 931  if($in_locfinder) { Line 847  if($in_locfinder) {
847          $loc_db->query( $sql );          $loc_db->query( $sql );
848    
849          // delete the interface          // delete the interface
850          $sql = "DELETE FROM interfaces WHERE int_id = " . $int_id;          $sql = "DELETE FROM interfaces WHERE id = " . $int_id;
851    
852          $loc_db->query( $sql );          $loc_db->query( $sql );
853    
854          // let the user know the deletion was successful          // let the user know the deletion was successful
855          $success_message = "interface successfully deleted";          $_SESSION["msg"] = "interface successfully deleted";
856                    $_SESSION["msg_type"] = 1;
857          
858          // function successful          // function successful
859          return true;          return true;
860    
# Line 964  if($in_locfinder) { Line 881  if($in_locfinder) {
881            
882      function create_service($node_id, $type, $ip, $port, $description) {      function create_service($node_id, $type, $ip, $port, $description) {
883    
         // declare global variables  
         GLOBAL $success_message;  
   
884          // create DB class          // create DB class
885          $loc_db = new locDatabase;          $loc_db = new locDatabase;
886    
887          // build SQL statement to insert the service into the DB          // build SQL statement to insert the service into the DB
888          $sql = "INSERT INTO services(node, service_type, service_ip, service_port, description) VALUES('$node_id', '$type', '$ip', '$port', '$description')";          $sql = "INSERT INTO services(node, type, ip, port, description) VALUES('$node_id', '$type', '$ip', '$port', '$description')";
889    
890          $loc_db->query( $sql );          $loc_db->query( $sql );
891    
892          // let the user know the creation was successful          // inform the user that function was successful
893          $success_message = "service successfully added...";          $_SESSION["msg"] = "Service successfully created";
894            $_SESSION["msg_type"] = 1;
895    
896          // function successful          // function successful
897          return true;          return true;
# Line 995  if($in_locfinder) { Line 910  if($in_locfinder) {
910       *       *
911       */       */
912            
913      function delete_service($id) {      function delete_service($service_id) {
   
         // declare global variables  
         GLOBAL $success_message;  
914    
915          // create DB class          // create DB class
916          $loc_db = new locDatabase;          $loc_db = new locDatabase;
917    
918          // build the SQL statement to delete the service          // build the SQL statement to delete the service
919          $sql = "DELETE FROM services WHERE service_id=" . $id;          $sql = "DELETE FROM services WHERE id=" . $service_id;
920    
921          $loc_db->query( $sql );          $loc_db->query( $sql );
922    
923          // let the user know the deletion was successful          $_SESSION["msg"] = "Service successfully deleted";
924          $success_message = "service successfully deleted";          $_SESSION["msg_type"] = 1;
925    
926          // function successful          // function successful
927          return true;          return true;

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26