4 require_once 'plc_login.php';
6 // Get session and API handles
7 require_once 'plc_session.php';
11 require_once 'plc_drupal.php';
14 require_once 'plc_functions.php';
16 $known_actions=array();
17 ////////////////////////////////////////////////////////////
20 // (*) set 'action' to one of the following
21 //////////////////////////////////////// persons
22 $known_actions []= "add-person-to-site";
23 // expects: person_id & site_id
24 $known_actions []= "remove-person-from-sites";
25 // expects: person_id & site_ids
26 $known_actions []= "remove-roles-from-person";
27 // expects: person_id & role_ids
28 $known_actions []= "add-role-to-person";
29 // expects: role_person_id & id
30 $known_actions []= "enable-person";
32 $known_actions []= "disable-person";
34 $known_actions []= "become-person";
36 $known_actions []= "delete-person";
38 $known_actions []= "delete-keys";
39 // expects: key_ids & person_id (for redirecting to the person's page)
40 $known_actions []= "upload-key";
41 // expects: person_id & $_FILES['key']
42 $known_actions []= "update-person";
43 // expects: person_id & first_name last_name title email phone url bio + [password1 password2]
45 //////////////////////////////////////// nodes
46 $known_actions []= "node-boot-state";
47 // expects: node_id boot_state
48 $known_actions []= "delete-node";
50 $known_actions []= "update-node";
51 // expects: node_id, hostname, model
52 $known_actions []= "attach-pcu";
53 // expects: node_id, pcu_id, port (pcu_id <0 means detach)
55 //////////////////////////////////////// interfaces
56 $known_actions []= "delete-interfaces";
57 // expects: interface_ids
58 $known_actions []="add-interface";
59 // expects: node_id & interface details
60 $known_actions []="new-interface";
62 $known_actions []="update-interface";
63 // expects: interface_id & interface details
65 //////////////////////////////////////// sites
66 $known_actions []= "delete-site";
68 $known_actions []= "expire-all-slices-in-site";
70 $known_actions []= "update-site";
71 // expects: site_id & name abbreviated_name url latitude longitude [login_base max_slices]
73 //////////////////////////////////////// slices
74 $known_actions []= "delete-slice";
76 $known_actions []= "update-slice";
77 // expects: slice_id, name, description, url
78 $known_actions []= "renew-slice";
79 // expects: slice_id & expires
80 $known_actions []= 'remove-persons-from-slice';
81 // expects: slice_id & person_ids
82 $known_actions []= 'add-persons-in-slice';
83 // expects: slice_id & person_ids
84 $known_actions []= 'remove-nodes-from-slice';
85 // expects: slice_id & node_ids
86 $known_actions []= 'add-nodes-in-slice';
87 // expects: slice_id & node_ids
88 $known_actions []= 'delete-slice-tags';
89 // expects: slice_tag_id
90 $known_actions []= 'add-slice-tag';
91 // expects: slice_id & tag_type_id & node_id & nodegroup_id
93 //////////////////////////////////////// tag types
94 $known_actions []= "update-tag-type";
95 // expects: tag_type_id & name & description & category & min_role_id
96 $known_actions []= "add-tag-type";
97 // expects: tag_type_id & tagname & description & category & min_role_id
98 $known_actions []= "delete-tag-types";
99 // expects: tag_type_ids
101 //////////////////////////////////////// tags
102 $known_actions []= "set-tag-on-node";
103 // expects: node_id tagname value
104 $known_actions []= "set-tag-on-interface";
105 // expects: interface_id tagname value
106 $known_actions []= "delete-node-tags";
107 // expects: node_id & node_tag_ids
108 $known_actions []= "delete-interface-tags";
109 // expects: interface_id & interface_tag_ids
111 //////////////////////////////////////// nodegroups
112 $known_actions []= "update-nodegroup";
113 // expects nodegroup_id groupname value
114 $known_actions []= "add-nodegroup";
115 // expects groupname, tag_type_id, value
116 $known_actions []= 'delete-nodegroups';
117 // expects nodegroup_ids
119 //////////////////////////////////////// leases
120 $known_actions []= "manage-leases";
121 // expects as 'actions' a list of 'action' of the form
122 // either [ 'add-leases', [nodenames], slicename, t_from, t_until ]
123 // or [ 'delete-leases', lease_id ]
125 ////////////////////////////////////////////////////////////
126 $interface_details= array ('method','type', 'ip', 'gateway', 'network',
127 'broadcast', 'netmask', 'dns1', 'dns2',
128 'hostname', 'mac', 'bwlimit' );
130 //////////////////////////////
131 // sometimes we don't set 'action', but use the submit button name instead
132 // so if 'action' not set, see if $_POST has one of the actions as a key
133 if ($_POST['action'])
134 $action=$_POST['action'];
136 foreach ($known_actions as $known_action)
137 if ($_POST[$known_action]) {
138 $action=$known_action;
142 //uncomment for debugging incoming data
145 $person_id = $_POST['person_id']; // usually needed
148 drupal_set_message ("actions.php: action not set or not in known_actions");
149 plc_debug('POST',$_POST);
155 case 'add-person-to-site': {
156 $site_id = $_POST['site_id'];
157 $api->AddPersonToSite( intval( $person_id ), intval( $site_id ) );
158 plc_redirect (l_person($person_id));
161 case 'remove-person-from-sites': {
162 $site_ids = $_POST['site_ids'];
164 drupal_set_message("action=$action - No site selected");
167 foreach ( $site_ids as $site_id ) {
168 $api->DeletePersonFromSite( intval( $person_id ), intval( $site_id ) );
170 plc_redirect (l_person($person_id));
173 case 'remove-roles-from-person' : {
174 $role_ids=$_POST['role_ids'];
176 drupal_set_error("You have not selected role(s) to remove");
178 foreach( $role_ids as $role_id)
179 if ( $api->DeleteRoleFromPerson( intval( $role_id ), intval( $person_id ) ) != 1 )
180 drupal_set_error ("Could not remove role $role_id from person $person_id");
182 plc_redirect (l_person_roles($person_id));
185 case 'add-role-to-person' : {
186 $role_id=$_POST['role_id'];
188 drupal_set_error ("You have not selected a role to add");
189 } else if ($api->AddRoleToPerson( intval( $role_id ), intval( $person_id ) ) != 1) {
190 drupal_set_error("Could not add role $role_id to person $person_id");
192 plc_redirect (l_person_roles($person_id));
195 case 'enable-person' : {
196 $fields = array( "enabled"=>true );
197 $api->UpdatePerson( intval( $person_id ), $fields );
198 plc_redirect (l_person($person_id));
201 case 'disable-person' : {
202 $fields = array( "enabled"=>false );
203 $api->UpdatePerson( intval( $person_id ), $fields );
204 plc_redirect (l_person($person_id));
207 case 'become-person' : {
208 $plc->BecomePerson (intval($person_id));
209 plc_redirect (l_person(intval($person_id)));
212 case 'delete-person' : {
213 $api->DeletePerson( intval( $person_id ) );
214 plc_redirect (l_persons());
217 case 'delete-keys' : {
218 $key_ids=$_POST['key_ids'];
220 drupal_set_message("action=$action - No key selected");
225 foreach( $key_ids as $key_id ) {
226 if ($api->DeleteKey( intval( $key_id )) != 1)
232 drupal_set_message ("Deleted $counter key(s)");
234 drupal_set_error ("Could not delete all selected keys, only $counter were removed");
235 plc_redirect(l_person($person_id));
239 case 'upload-key' : {
240 if ( ! isset( $_FILES['key'] ) ) {
241 drupal_set_message ("action=$action, no key file set");
245 $key_file= $_FILES['key']['tmp_name'];
247 plc_error("Please select a valid SSH key file to upload");
250 $fp = fopen( $key_file, "r" );
253 plc_error("Unable to open key file $key_file");
256 // opened the key file, read the one line of contents
257 // The POST operation always creates a file even if the filename
258 // the user specified was garbage. If there was some problem
259 // with the source file, we'll get a zero length read here.
260 $key = fread($fp, filesize($key_file));
263 $key_id = $api->AddPersonKey( intval( $person_id ), array( "key_type"=> 'ssh', "key"=> $key ) );
266 drupal_set_message ("New key added");
268 drupal_set_error("Could not add key, please verify your SSH file content\n" . $api->error());
270 plc_redirect(l_person($person_id));
273 case 'update-person': {
274 $person_id=$_POST['person_id'];
275 // attempt to update this person
276 $first_name= $_POST['first_name'];
277 $last_name= $_POST['last_name'];
278 $title= $_POST['title'];
279 $email= $_POST['email'];
280 $phone= $_POST['phone'];
282 $bio= str_replace("\r", "", $_POST['bio']);
283 $password1= $_POST['password1'];
284 $password2= $_POST['password2'];
286 if( $password1 != $password2 ) {
287 drupal_set_error ("The passwords do not match");
288 plc_redirect(l_person($person_id));
292 $fields['first_name']= $first_name;
293 $fields['last_name']= $last_name;
294 $fields['title']= $title;
295 $fields['email']= $email;
296 $fields['phone']= $phone;
297 $fields['url']= $url;
298 $fields['bio']= $bio;
300 if ( $password1 != "" )
301 $fields['password']= $password1;
303 if ( $api->UpdatePerson( intval( $person_id ), $fields) == 1 )
304 drupal_set_message("$first_name $last_name updated");
306 drupal_set_error ("Could not update person $person_id" . $api->error());
308 plc_redirect(l_person($person_id));
312 //////////////////////////////////////////////////////////// nodes
313 case 'node-boot-state': {
314 $node_id=intval($_POST['node_id']);
315 $boot_state=$_POST['boot_state'];
316 $result=$api->UpdateNode( $node_id, array( "boot_state" => $boot_state ) );
318 drupal_set_message("boot state updated");
319 plc_redirect (l_node($node_id));
321 drupal_set_error("Could not set boot_state '$boot_state'");
326 case 'delete-node': {
327 $node_id=intval($_POST['node_id']);
328 $result=$api->DeleteNode( intval( $node_id ) );
330 drupal_set_message("Node $node_id deleted");
331 plc_redirect (l_nodes());
333 drupal_set_error ("Could not delete node $node_id");
338 case 'update-node': {
339 $node_id=intval($_POST['node_id']);
340 $hostname= $_POST['hostname'];
341 $model= $_POST['model'];
343 $fields= array( "hostname"=>$hostname, "model"=>$model );
344 $api->UpdateNode( $node_id, $fields );
345 $error= $api->error();
347 if( empty( $error ) ) {
348 drupal_set_message("Update node $hostname");
349 plc_redirect(l_node($node_id));
351 drupal_set_error($error);
356 // this code will ensure that at most one PCU gets attached to the node
358 $node_id=intval($_POST['node_id']);
359 $pcu_id=intval($_POST['pcu_id']);
360 $port=intval($_POST['port']);
361 // always start with deleting former PCUs
362 $nodes = $api->GetNodes(array($node_id),array('pcu_ids'));
363 $former_pcu_ids = $nodes[0]['pcu_ids'];
364 if ($former_pcu_ids) foreach ($former_pcu_ids as $former_pcu_id) {
365 if ($api->DeleteNodeFromPCU($node_id,$former_pcu_id) == 1)
366 drupal_set_message ('Detached node ' . $node_id . ' from PCU ' . $pcu_id);
368 drupal_set_error ('Could not detach node ' . $node_id . ' from PCU ' . $pcu_id);
370 // re-attach only if provided pcu_id >=0
372 if ($api->AddNodeToPCU($node_id,$pcu_id,$port) == 1)
373 drupal_set_message ('Attached node ' . $node_id . ' to PCU ' . $pcu_id . ' on port ' . $port);
375 drupal_set_error ('Failed to attach node ' . $node_id . ' to PCU ' . $pcu_id . ' on port ' . $port);
377 drupal_set_message ('Detached node from all PCUs');
380 plc_redirect(l_node($node_id));
385 //////////////////////////////////////////////////////////// interfaces
386 case 'delete-interfaces' : {
387 $interface_ids=$_POST['interface_ids'];
388 if ( ! $interface_ids) {
389 drupal_set_message("action=$action - No interface selected");
394 foreach( $interface_ids as $interface_id ) {
395 if ($api->DeleteInterface( intval( $interface_id )) != 1)
401 drupal_set_message ("Deleted $counter interface(s)");
403 drupal_set_error ("Could not delete all selected interfaces, only $counter were removed");
404 plc_redirect(l_node($_POST['node_id']));
407 case 'new-interface': {
408 plc_redirect(l_interface_add($_POST['node_id']));
411 case 'add-interface': {
412 $node_id=intval($_POST['node_id']);
413 foreach ($interface_details as $field) {
414 $interface[$field]= $_POST[$field];
415 // these must be integers
416 if( in_array( $field, array( 'bwlimit', 'node_id' ) ) ) {
417 if ( empty ($interface[$field]) )
418 unset ($interface[$field]);
420 $interface[$field]= intval( $interface[$field] );
423 $interface_id =$api->AddInterface( $node_id , $interface );
424 if ($interface_id <= 0 ) {
425 drupal_set_error ("Could not create interface");
426 drupal_set_error ($api->error());
428 $ip=$interface['ip'];
429 drupal_set_message ("Interface $ip added into node $node_id");
430 if ($_POST['is-virtual']) {
431 $ifname=$_POST['ifname'];
432 if ($api->AddInterfaceTag($interface_id,"ifname",$ifname) <= 0)
433 drupal_set_error ("Could not set tag 'ifname'=$ifname");
435 drupal_set_message ("Set tag 'ifname'=$ifname");
436 $alias=$_POST['alias'];
437 // deafult to interface_id
438 if ( ! $alias ) $alias=strval($interface_id);
439 if ($api->AddInterfaceTag($interface_id,"alias",$alias) <= 0)
440 drupal_set_error ("Could not set tag 'alias'=$alias");
442 drupal_set_message ("Set tag 'alias'=$alias");
445 plc_redirect (l_node_interfaces($node_id));
448 case 'update-interface': {
449 $interface_id=$_POST['interface_id'];
450 foreach ($interface_details as $field) {
451 $interface[$field]= $_POST[$field];
452 if( in_array( $field, array( 'bwlimit', 'node_id' ) ) ) {
453 if ( intval($interface[$field]) != 0 ) {
454 $interface[$field]= intval( $interface[$field]);
455 } elseif ($field=='bwlimit' ) {
456 $interface[$field] = NULL;
460 $result=$api->UpdateInterface( intval( $interface_id ), $interface );
462 drupal_set_message ("Interface $interface_id updated");
464 drupal_set_error ("Could not update interface: " . $api->error());
465 plc_redirect (l_interface($interface_id));
468 //////////////////////////////////////////////////////////// sites
469 case 'delete-site': {
470 $site_id = intval($_POST['site_id']);
471 if ($api->DeleteSite($site_id) ==1)
472 drupal_set_message ("Site $site_id deleted");
474 drupal_set_error("Failed to delete site $site_id");
475 plc_redirect (l_sites());
479 case 'expire-all-slices-in-site': {
481 drupal_set_message("action $action not implemented in actions.php -- need tweaks and test");
484 //// old code from sites/expire.php
485 $sites = $api->GetSites( array( intval( $site_id )));
487 // xxx why not 'now?'
488 $expiration= strtotime( $_POST['expires'] );
489 // loop through all slices for site
490 foreach ($site['slice_ids'] as $slice_id) {
491 $api->UpdateSlice( $slice_id, array( "expires" => $expiration ) );
493 // update site to not allow slice creation or renewal
494 $api->UpdateSite( $site_id, array( "max_slices" => 0 )) ;
495 plc_redirect (l_site($site_id));
499 case 'update-site': {
500 $site_id=intval($_POST['site_id']);
501 $name= $_POST['name'];
502 $abbreviated_name= $_POST['abbreviated_name'];
504 $latitude= floatval($_POST['latitude']);
505 $longitude= floatval($_POST['longitude']);
506 //$max_slivers= $_POST['max_slivers'];
508 $fields= array( "name" => $name,
509 "abbreviated_name" => $abbreviated_name,
511 "latitude" => floatval( $latitude ),
512 "longitude" => floatval( $longitude ));
514 if ($_POST['login_base'])
515 $fields['login_base'] = $_POST['login_base'];
516 if (isset($_POST['max_slices']))
517 $fields['max_slices'] = intval($_POST['max_slices']);
518 if (isset($_POST['enabled'])) {
519 $fields['enabled'] = (bool)$_POST['enabled'];
522 $retcod=$api->UpdateSite( intval( $site_id ), $fields );
524 drupal_set_message("Site $name updated");
526 drupal_set_error ("Could not update site $site_id");
528 plc_redirect(l_site($site_id));
532 //////////////////////////////////////////////////////////// slices
533 case 'delete-slice': {
534 $slice_id = $_POST['slice_id'];
535 if ($api->DeleteSlice( intval( $slice_id )) == 1 ) {
536 drupal_set_message("Slice $slice_id deleted");
537 plc_redirect(l_slices());
539 drupal_set_error("Could not delete slice $slice_id " . $api->error());
544 case 'update-slice': {
545 $slice_id = $_POST['slice_id'];
546 $name = $_POST['name'];
547 $description= $_POST['description'];
550 $fields= array( "description"=>$description, "url"=>$url );
551 $api->UpdateSlice( intval( $slice_id ), $fields );
552 $error= $api->error();
554 if( empty( $error ) ) {
555 drupal_set_message("Update slice $name");
556 plc_redirect(l_slice($slice_id));
558 drupal_set_error($error);
563 case 'renew-slice': {
564 $slice_id = intval ($_POST['slice_id']);
565 $expires = intval ($_POST['expires']);
571 $MAX_FUTURE=$WEEKS*$WEEK;
572 if ( ($expires-$now) > $MAX_FUTURE) {
573 drupal_set_error("Cannot renew slice that far in the future, max is $WEEKS weeks from now");
574 plc_redirect(l_slice($slice_id));
576 if ($api->UpdateSlice ($slice_id, array('expires'=>$expires)) == 1)
577 drupal_set_message("Slice renewed");
579 drupal_set_error("Could not update slice $slice_id");
580 plc_redirect(l_slice($slice_id));
584 case 'remove-persons-from-slice': {
585 $slice_id = intval ($_POST['slice_id']);
586 $person_ids = $_POST['person_ids'];
589 $tmp_slices = $api->GetSlices($slice_id, array("name"));
590 if (count($tmp_slices) > 0) {
591 $tmp_slice = $tmp_slices[0];
592 $slice_name = $tmp_slice["name"];
594 $notify_subject = "Removed from slice: " . $slice_name;
595 $notify_body = sprintf("You have been removed from the slice %s.
597 Our support team will be glad to answer any question that you might have.
599 $notify_person_ids = array();
603 foreach( $person_ids as $person_id ) {
604 if ($api->DeletePersonFromSlice(intval($person_id),$slice_id) != 1)
607 array_push($notify_person_ids, intval($person_id));
612 $api->NotifyPersons($notify_person_ids,$notify_subject,$notify_body);
613 drupal_set_message ("Deleted $counter person(s)");
616 drupal_set_error ("Could not delete all selected persons, only $counter were removed");
617 plc_redirect(l_slice($slice_id) . " &show_persons=true");
621 case 'add-persons-in-slice': {
622 $slice_id = intval ($_POST['slice_id']);
623 $person_ids = $_POST['person_ids'];
626 $tmp_slices = $api->GetSlices($slice_id, array("name"));
627 if (count($tmp_slices) > 0) {
628 $tmp_slice = $tmp_slices[0];
629 $slice_name = $tmp_slice["name"];
631 $notify_subject = "Added to slice: " . $slice_name;
632 $notify_body = sprintf("You have been added to the slice %s as a user.
634 You can go to your slice page following the link below:
635 https://%s:%d/db/slices/index.php?id=%d
637 Our support team will be glad to answer any question that you might have.
638 ",$slice_name,PLC_WWW_HOST,PLC_WWW_SSL_PORT,$slice_id);
639 $notify_person_ids = array();
643 foreach ($person_ids as $person_id) {
644 if ($api->AddPersonToSlice(intval($person_id),$slice_id) != 1)
647 array_push($notify_person_ids, intval($person_id));
652 $api->NotifyPersons($notify_person_ids,$notify_subject,$notify_body);
653 drupal_set_message ("Added $counter person(s)");
656 drupal_set_error ("Could not add all selected persons, only $counter were added");
657 plc_redirect(l_slice($slice_id) . "&show_persons=true" );
661 case 'remove-nodes-from-slice': {
662 $slice_id = intval ($_POST['slice_id']);
663 $node_ids = array_map("intval",$_POST['node_ids']);
664 $count=count($node_ids);
666 if ($api->DeleteSliceFromNodes($slice_id,$node_ids) == 1)
667 drupal_set_message ("Removed $count node(s)");
669 drupal_set_error ("Could not remove selected nodes");
670 plc_redirect(l_slice_nodes($slice_id));
674 case 'add-nodes-in-slice': {
675 $slice_id = intval ($_POST['slice_id']);
676 $node_ids = array_map("intval",$_POST['node_ids']);
677 $count=count($node_ids);
678 if ($api->AddSliceToNodes($slice_id,$node_ids) == 1)
679 drupal_set_message ("Added $count node(s)");
681 drupal_set_error ("Could not add all selected nodes");
682 plc_redirect(l_slice_nodes($slice_id));
686 case 'delete-slice-tags': {
687 $slice_id = intval($_POST['slice_id']);
688 $slice_tag_ids = array_map("intval", $_POST['slice_tag_ids']);
691 foreach($slice_tag_ids as $slice_tag_id) {
692 if ($api->DeleteSliceTag($slice_tag_id)) $count += 1;
694 drupal_set_error("Could not delete slice tag: slice_tag_id = $slice_tag_id");
699 drupal_set_message ("Deleted $count slice tag(s)");
700 plc_redirect(l_slice($slice_id) . "&show_tags=true" );
704 case 'add-slice-tag': {
705 $slice_id = intval($_POST['slice_id']);
706 $tag_type_id = intval($_POST['tag_type_id']);
707 $value = $_POST['value'];
708 $node_id = intval($_POST['node_id']);
709 $nodegroup_id = intval($_POST['nodegroup_id']);
713 $result = $api->AddSliceTag($slice_id, $tag_type_id, $value, $node_id);
714 } elseif ($nodegroup_id) {
715 $result = $api->AddSliceTag($slice_id, $tag_type_id, $value, null, $nodegroup_id);
717 $result = $api->AddSliceTag($slice_id, $tag_type_id, $value);
720 drupal_set_message ("Added slice tag.");
722 drupal_set_error("Could not add slice tag");
723 if ($_POST['sliver_action'])
724 plc_redirect(l_sliver($node_id,$slice_id));
726 plc_redirect(l_slice($slice_id) . "&show_tags=true" );
730 //////////////////////////////////////////////////////////// tag types
732 case 'update-tag-type': {
734 $tag_type_id= intval( $_POST['tag_type_id'] );
735 $tagname = $_POST['tagname'];
736 $min_role_id= intval( $_POST['min_role_id'] );
737 $description= $_POST['description'];
738 $category= $_POST['category'];
740 // make tag_type_fields dict
741 $tag_type_fields= array( "min_role_id" => $min_role_id,
742 "tagname" => $tagname,
743 "description" => $description,
744 "category" => $category,
747 if ($api->UpdateTagType( $tag_type_id, $tag_type_fields ) == 1)
748 drupal_set_message ("Tag type $tagname updated");
750 drupal_set_error ("Could not update tag type $tag_type_id\n".$api->error());
751 plc_redirect(l_tag($tag_type_id));
755 case 'add-tag-type': {
757 $tagname = $_POST['tagname'];
758 $min_role_id= intval( $_POST['min_role_id'] );
759 $description= $_POST['description'];
760 $category= $_POST['category'];
762 // make tag_type_fields dict
763 $tag_type_fields= array( "min_role_id" => $min_role_id,
764 "tagname" => $tagname,
765 "description" => $description,
766 "category" => $category,
770 $tag_type_id=$api->AddTagType( $tag_type_fields );
771 if ($tag_type_id > 0)
772 drupal_set_message ("tag type $tag_type_id created");
774 drupal_set_error ("Could not create tag type $tagname");
775 plc_redirect( l_tags());
779 case 'delete-tag-types': {
780 $tag_type_ids = $_POST['tag_type_ids'];
781 if ( ! $tag_type_ids) {
782 drupal_set_message("action=$action - No tag selected");
787 foreach ($tag_type_ids as $tag_type_id)
788 if ($api->DeleteTagType(intval($tag_type_id)) != 1)
793 drupal_set_message ("Deleted $counter tag(s)");
795 drupal_set_error ("Could not delete all selected tags, only $counter were removed");
796 plc_redirect (l_tags());
800 //////////////////////////////////////// tags
801 case 'set-tag-on-node':
802 case 'set-tag-on-interface': {
805 if ($action == 'set-tag-on-node') $node_mode=true;
808 $node_id = intval($_POST['node_id']);
810 $interface_id=intval($_POST['interface_id']);
811 $tag_type_id = intval($_POST['tag_type_id']);
812 $value = $_POST['value'];
814 $tag_types=$api->GetTagTypes(array($tag_type_id));
815 if (count ($tag_types) != 1) {
816 drupal_set_error ("Could not locate tag_type_id $tag_type_id </br> Tag not set.");
819 $tags = $api->GetNodeTags (array('node_id'=>$node_id, 'tag_type_id'=> $tag_type_id));
821 $tags = $api->GetInterfaceTags (array('interface_id'=>$interface_id, 'tag_type_id'=> $tag_type_id));
822 if ( count ($tags) == 1) {
825 $tag_id=$tag['node_tag_id'];
826 $result=$api->UpdateNodeTag($tag_id,$value);
828 $tag_id=$tag['interface_tag_id'];
829 $result=$api->UpdateInterfaceTag($tag_id,$value);
832 drupal_set_message ("Updated tag, new value = $value");
834 drupal_set_error ("Could not update tag");
837 $tag_id = $api->AddNodeTag($node_id,$tag_type_id,$value);
839 $tag_id = $api->AddInterfaceTag($interface_id,$tag_type_id,$value);
841 drupal_set_message ("Created tag, new value = $value");
843 drupal_set_error ("Could not create tag");
848 plc_redirect (l_node_tags($node_id));
850 plc_redirect (l_interface_tags($interface_id));
853 case 'delete-node-tags' :
854 case 'delete-interface-tags' : {
857 if ($action == 'delete-node-tags') $node_mode=true;
860 $tag_ids=$_POST['node_tag_ids'];
862 $tag_ids=$_POST['interface_tag_ids'];
865 drupal_set_message("action=$action - No tag selected");
870 foreach( $tag_ids as $tag_id ) {
872 $retcod = $api->DeleteNodeTag( intval( $tag_id ));
874 $retcod = $api->DeleteInterfaceTag( intval( $tag_id ));
881 drupal_set_message ("Deleted $counter tag(s)");
883 drupal_set_error ("Could not delete all selected tags, only $counter were removed");
885 plc_redirect(l_node_tags($_POST['node_id']));
887 plc_redirect(l_interface_tags($_POST['interface_id']));
890 //////////////////////////////////////// nodegroups
891 case 'update-nodegroup': {
892 $nodegroup_id = $_POST['nodegroup_id'];
893 $groupname = $_POST['groupname'];
894 $value = $_POST['value'];
897 $fields['groupname']=$groupname;
898 $fields['value']=$value;
899 if ( $api->UpdateNodeGroup($nodegroup_id,$fields) == 1)
900 drupal_set_message ('Nodegroup updated');
902 drupal_set_error ("Could not update nodegroup $groupname");
904 plc_redirect(l_nodegroup($nodegroup_id));
908 case 'add-nodegroup': {
909 $groupname=$_POST['groupname'];
910 if ( ! $groupname ) {
911 drupal_set_error ('Empty groupname');
912 plc_redirect (l_nodegroups());
914 $tag_type_id=intval($_POST['tag_type_id']);
915 if ( ! $tag_type_id ) {
916 drupal_set_error ('You must select a tag in the dropdown list');
917 plc_redirect (l_nodegroups());
919 $value=$_POST['value'];
921 drupal_set_message ("Empty value.. let's see ..");
923 if ( $api->AddNodeGroup ($groupname,$tag_type_id,$value) > 0)
924 drupal_set_message ("Nodegroup $groupname created");
926 drupal_set_error ("Could not create nodegroup $groupname");
928 plc_redirect (l_nodegroups());
932 case 'delete-nodegroups': {
933 $nodegroup_ids=$_POST['nodegroup_ids'];
934 if ( ! $nodegroup_ids ) {
935 drupal_set_message("action=delete-nodegroups - No group selected");
936 plc_redirect(l_nodegroups());
940 foreach ($nodegroup_ids as $nodegroup_id)
941 if ($api->DeleteNodeGroup(intval($nodegroup_id)) != 1)
946 drupal_set_message ("Deleted $counter group(s)");
948 drupal_set_error ("Could not delete all selected groups, only $counter were removed");
949 plc_redirect (l_nodegroups());
953 //////////////////////////////////////// leases
954 case 'manage-leases': {
955 $actions=json_decode($_POST['actions']);
961 foreach ($actions as $action) {
962 if ($action[0] == 'add-leases') {
963 $nodenames=$action[1];
964 $add_requested += count($nodenames);
965 $slicename=$action[2];
966 $t_from=intval($action[3]);
967 $t_until=intval($action[4]);
968 $hash = $api->AddLeases($nodenames,$slicename,$t_from,$t_until);
969 // update number of added leases
970 $ids=$hash['new_ids'];
971 $add_done += count($ids);
972 // update global errors array
973 foreach ($api_errors=$hash['errors'] as $error) $errors[]=$error;
974 } else if ($action[0]=='delete-leases') {
975 $lease_id=intval($action[1]);
977 if ($api->DeleteLeases(array($lease_id)) == 1) {
980 $errors []= "Could not delete lease " . $lease_id;
983 $errors []= "in actions.php, manage-leases, wrong action ". $action[0];
987 if (count($errors)==0) {
988 echo("All leases updated (" . $add_done . " added and " . $del_done . " deleted)");
990 foreach ($errors as $error) echo($error. "\n");
991 echo("Leases updated only partially (" .
992 $add_done . "/" . $add_requested . " added and " .
993 $del_done . "/" . $del_requested . " deleted)");
999 ////////////////////////////////////////
1002 plc_debug('GET',$_GET);
1003 plc_debug('POST',$_POST);
1004 plc_debug('FILES',$_FILES);
1009 plc_error ("Unknown action $action in actions.php");