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)
54 $known_actions []= "reboot-node-with-pcu";
57 //////////////////////////////////////// interfaces
58 $known_actions []= "delete-interfaces";
59 // expects: interface_ids
60 $known_actions []="add-interface";
61 // expects: node_id & interface details
62 $known_actions []="new-interface";
64 $known_actions []="update-interface";
65 // expects: interface_id & interface details
67 //////////////////////////////////////// sites
68 $known_actions []= "delete-site";
70 $known_actions []= "expire-all-slices-in-site";
72 $known_actions []= "update-site";
73 // expects: site_id & name abbreviated_name url latitude longitude [login_base max_slices]
75 //////////////////////////////////////// slices
76 $known_actions []= "delete-slice";
78 $known_actions []= "update-slice";
79 // expects: slice_id, name, description, url
80 $known_actions []= "renew-slice";
81 // expects: slice_id & expires
82 $known_actions []= 'remove-persons-from-slice';
83 // expects: slice_id & person_ids
84 $known_actions []= 'add-persons-in-slice';
85 // expects: slice_id & person_ids
86 $known_actions []= 'remove-nodes-from-slice';
87 // expects: slice_id & node_ids
88 $known_actions []= 'add-nodes-in-slice';
89 // expects: slice_id & node_ids
90 $known_actions []= 'delete-slice-tags';
91 // expects: slice_tag_id
92 $known_actions []= 'add-slice-tag';
93 // expects: slice_id & tag_type_id & node_id & nodegroup_id
95 //////////////////////////////////////// tag types
96 $known_actions []= "update-tag-type";
97 // expects: tag_type_id & name & description & category & min_role_id
98 $known_actions []= "add-tag-type";
99 // expects: tag_type_id & tagname & description & category & min_role_id
100 $known_actions []= "delete-tag-types";
101 // expects: tag_type_ids
103 //////////////////////////////////////// tags
104 $known_actions []= "set-tag-on-node";
105 // expects: node_id tagname value
106 $known_actions []= "set-tag-on-interface";
107 // expects: interface_id tagname value
108 $known_actions []= "delete-node-tags";
109 // expects: node_id & node_tag_ids
110 $known_actions []= "delete-interface-tags";
111 // expects: interface_id & interface_tag_ids
113 //////////////////////////////////////// nodegroups
114 $known_actions []= "update-nodegroup";
115 // expects nodegroup_id groupname value
116 $known_actions []= "add-nodegroup";
117 // expects groupname, tag_type_id, value
118 $known_actions []= 'delete-nodegroups';
119 // expects nodegroup_ids
121 //////////////////////////////////////// leases
122 $known_actions []= "manage-leases";
123 // expects as 'actions' a list of 'action' of the form
124 // either [ 'add-leases', [nodenames], slicename, t_from, t_until ]
125 // or [ 'delete-leases', lease_id ]
127 ////////////////////////////////////////////////////////////
128 $interface_details= array ('method','type', 'ip', 'gateway', 'network',
129 'broadcast', 'netmask', 'dns1', 'dns2',
130 'hostname', 'mac', 'bwlimit' );
132 //////////////////////////////
133 // sometimes we don't set 'action', but use the submit button name instead
134 // so if 'action' not set, see if $_POST has one of the actions as a key
135 if ($_POST['action'])
136 $action=$_POST['action'];
138 foreach ($known_actions as $known_action)
139 if ($_POST[$known_action]) {
140 $action=$known_action;
144 //uncomment for debugging incoming data
147 $person_id = $_POST['person_id']; // usually needed
150 drupal_set_message ("actions.php: action not set or not in known_actions");
151 plc_debug('POST',$_POST);
157 case 'add-person-to-site': {
158 $site_id = $_POST['site_id'];
159 $api->AddPersonToSite( intval( $person_id ), intval( $site_id ) );
160 plc_redirect (l_person($person_id));
163 case 'remove-person-from-sites': {
164 $site_ids = $_POST['site_ids'];
166 drupal_set_message("action=$action - No site selected");
169 foreach ( $site_ids as $site_id ) {
170 $api->DeletePersonFromSite( intval( $person_id ), intval( $site_id ) );
172 plc_redirect (l_person($person_id));
175 case 'remove-roles-from-person' : {
176 $role_ids=$_POST['role_ids'];
178 drupal_set_error("You have not selected role(s) to remove");
180 foreach( $role_ids as $role_id)
181 if ( $api->DeleteRoleFromPerson( intval( $role_id ), intval( $person_id ) ) != 1 )
182 drupal_set_error ("Could not remove role $role_id from person $person_id");
184 plc_redirect (l_person_roles($person_id));
187 case 'add-role-to-person' : {
188 $role_id=$_POST['role_id'];
190 drupal_set_error ("You have not selected a role to add");
191 } else if ($api->AddRoleToPerson( intval( $role_id ), intval( $person_id ) ) != 1) {
192 drupal_set_error("Could not add role $role_id to person $person_id");
194 plc_redirect (l_person_roles($person_id));
197 case 'enable-person' : {
198 $fields = array( "enabled"=>true );
199 $api->UpdatePerson( intval( $person_id ), $fields );
200 plc_redirect (l_person($person_id));
203 case 'disable-person' : {
204 $fields = array( "enabled"=>false );
205 $api->UpdatePerson( intval( $person_id ), $fields );
206 plc_redirect (l_person($person_id));
209 case 'become-person' : {
210 $plc->BecomePerson (intval($person_id));
211 plc_redirect (l_person(intval($person_id)));
214 case 'delete-person' : {
215 $api->DeletePerson( intval( $person_id ) );
216 plc_redirect (l_persons());
219 case 'delete-keys' : {
220 $key_ids=$_POST['key_ids'];
222 drupal_set_message("action=$action - No key selected");
227 foreach( $key_ids as $key_id ) {
228 if ($api->DeleteKey( intval( $key_id )) != 1)
234 drupal_set_message ("Deleted $counter key(s)");
236 drupal_set_error ("Could not delete all selected keys, only $counter were removed");
237 plc_redirect(l_person($person_id));
241 case 'upload-key' : {
242 if ( ! isset( $_FILES['key'] ) ) {
243 drupal_set_message ("action=$action, no key file set");
247 $key_file= $_FILES['key']['tmp_name'];
249 plc_error("Please select a valid SSH key file to upload");
252 $fp = fopen( $key_file, "r" );
255 plc_error("Unable to open key file $key_file");
258 // opened the key file, read the one line of contents
259 // The POST operation always creates a file even if the filename
260 // the user specified was garbage. If there was some problem
261 // with the source file, we'll get a zero length read here.
262 $key = fread($fp, filesize($key_file));
265 $key_id = $api->AddPersonKey( intval( $person_id ), array( "key_type"=> 'ssh', "key"=> $key ) );
268 drupal_set_message ("New key added");
270 drupal_set_error("Could not add key, please verify your SSH file content\n" . $api->error());
272 plc_redirect(l_person($person_id));
275 case 'update-person': {
276 $person_id=$_POST['person_id'];
277 // attempt to update this person
278 $first_name= $_POST['first_name'];
279 $last_name= $_POST['last_name'];
280 $title= $_POST['title'];
281 $email= $_POST['email'];
282 $phone= $_POST['phone'];
284 $bio= str_replace("\r", "", $_POST['bio']);
285 $password1= $_POST['password1'];
286 $password2= $_POST['password2'];
288 if( $password1 != $password2 ) {
289 drupal_set_error ("The passwords do not match");
290 plc_redirect(l_person($person_id));
294 $fields['first_name']= $first_name;
295 $fields['last_name']= $last_name;
296 $fields['title']= $title;
297 $fields['email']= $email;
298 $fields['phone']= $phone;
299 $fields['url']= $url;
300 $fields['bio']= $bio;
302 if ( $password1 != "" )
303 $fields['password']= $password1;
305 if ( $api->UpdatePerson( intval( $person_id ), $fields) == 1 )
306 drupal_set_message("$first_name $last_name updated");
308 drupal_set_error ("Could not update person $person_id" . $api->error());
310 plc_redirect(l_person($person_id));
314 //////////////////////////////////////////////////////////// nodes
315 case 'node-boot-state': {
316 $node_id=intval($_POST['node_id']);
317 $boot_state=$_POST['boot_state'];
318 $result=$api->UpdateNode( $node_id, array( "boot_state" => $boot_state ) );
320 drupal_set_message("boot state updated");
321 plc_redirect (l_node($node_id));
323 drupal_set_error("Could not set boot_state '$boot_state'");
328 case 'delete-node': {
329 $node_id=intval($_POST['node_id']);
330 $result=$api->DeleteNode( intval( $node_id ) );
332 drupal_set_message("Node $node_id deleted");
333 plc_redirect (l_nodes());
335 drupal_set_error ("Could not delete node $node_id");
340 case 'update-node': {
341 $node_id=intval($_POST['node_id']);
342 $hostname= $_POST['hostname'];
343 $model= $_POST['model'];
345 $fields= array( "hostname"=>$hostname, "model"=>$model );
346 $api->UpdateNode( $node_id, $fields );
347 $error= $api->error();
349 if( empty( $error ) ) {
350 drupal_set_message("Update node $hostname");
351 plc_redirect(l_node($node_id));
353 drupal_set_error($error);
358 // this code will ensure that at most one PCU gets attached to the node
360 $node_id=intval($_POST['node_id']);
361 $pcu_id=intval($_POST['pcu_id']);
362 $port=intval($_POST['port']);
363 // always start with deleting former PCUs
364 $nodes = $api->GetNodes(array($node_id),array('pcu_ids'));
365 $former_pcu_ids = $nodes[0]['pcu_ids'];
366 if ($former_pcu_ids) foreach ($former_pcu_ids as $former_pcu_id) {
367 if ($api->DeleteNodeFromPCU($node_id,$former_pcu_id) == 1)
368 drupal_set_message ('Detached node ' . $node_id . ' from PCU ' . $pcu_id);
370 drupal_set_error ('Could not detach node ' . $node_id . ' from PCU ' . $pcu_id);
372 // re-attach only if provided pcu_id >=0
374 if ($api->AddNodeToPCU($node_id,$pcu_id,$port) == 1)
375 drupal_set_message ('Attached node ' . $node_id . ' to PCU ' . $pcu_id . ' on port ' . $port);
377 drupal_set_error ('Failed to attach node ' . $node_id . ' to PCU ' . $pcu_id . ' on port ' . $port);
379 drupal_set_message ('Detached node from all PCUs');
382 plc_redirect(l_node($node_id));
386 case 'reboot-node-with-pcu': {
387 $node_id=intval($_POST['node_id']);
388 $hostname= $_POST['hostname'];
390 $ret = $api->RebootNodeWithPCU( $node_id );
391 $error= $api->error();
393 if( empty( $error ) ) {
394 drupal_set_message("Reboot node $hostname: $ret");
395 plc_redirect(l_node($node_id));
397 drupal_set_error($error);
403 //////////////////////////////////////////////////////////// interfaces
404 case 'delete-interfaces' : {
405 $interface_ids=$_POST['interface_ids'];
406 if ( ! $interface_ids) {
407 drupal_set_message("action=$action - No interface selected");
412 foreach( $interface_ids as $interface_id ) {
413 if ($api->DeleteInterface( intval( $interface_id )) != 1)
419 drupal_set_message ("Deleted $counter interface(s)");
421 drupal_set_error ("Could not delete all selected interfaces, only $counter were removed");
422 plc_redirect(l_node($_POST['node_id']));
425 case 'new-interface': {
426 plc_redirect(l_interface_add($_POST['node_id']));
429 case 'add-interface': {
430 $node_id=intval($_POST['node_id']);
431 foreach ($interface_details as $field) {
432 $interface[$field]= $_POST[$field];
433 // these must be integers
434 if( in_array( $field, array( 'bwlimit', 'node_id' ) ) ) {
435 if ( empty ($interface[$field]) )
436 unset ($interface[$field]);
438 $interface[$field]= intval( $interface[$field] );
441 $interface_id =$api->AddInterface( $node_id , $interface );
442 if ($interface_id <= 0 ) {
443 drupal_set_error ("Could not create interface");
444 drupal_set_error ($api->error());
446 $ip=$interface['ip'];
447 drupal_set_message ("Interface $ip added into node $node_id");
448 if ($_POST['is-virtual']) {
449 $ifname=$_POST['ifname'];
450 if ($api->AddInterfaceTag($interface_id,"ifname",$ifname) <= 0)
451 drupal_set_error ("Could not set tag 'ifname'=$ifname");
453 drupal_set_message ("Set tag 'ifname'=$ifname");
454 $alias=$_POST['alias'];
455 // deafult to interface_id
456 if ( ! $alias ) $alias=strval($interface_id);
457 if ($api->AddInterfaceTag($interface_id,"alias",$alias) <= 0)
458 drupal_set_error ("Could not set tag 'alias'=$alias");
460 drupal_set_message ("Set tag 'alias'=$alias");
463 plc_redirect (l_node_interfaces($node_id));
466 case 'update-interface': {
467 $interface_id=$_POST['interface_id'];
468 foreach ($interface_details as $field) {
469 $interface[$field]= $_POST[$field];
470 if( in_array( $field, array( 'bwlimit', 'node_id' ) ) ) {
471 if ( intval($interface[$field]) != 0 ) {
472 $interface[$field]= intval( $interface[$field]);
473 } elseif ($field=='bwlimit' ) {
474 $interface[$field] = NULL;
478 $result=$api->UpdateInterface( intval( $interface_id ), $interface );
480 drupal_set_message ("Interface $interface_id updated");
482 drupal_set_error ("Could not update interface: " . $api->error());
483 plc_redirect (l_interface($interface_id));
486 //////////////////////////////////////////////////////////// sites
487 case 'delete-site': {
488 $site_id = intval($_POST['site_id']);
489 if ($api->DeleteSite($site_id) ==1)
490 drupal_set_message ("Site $site_id deleted");
492 drupal_set_error("Failed to delete site $site_id");
493 plc_redirect (l_sites());
497 case 'expire-all-slices-in-site': {
499 drupal_set_message("action $action not implemented in actions.php -- need tweaks and test");
502 //// old code from sites/expire.php
503 $sites = $api->GetSites( array( intval( $site_id )));
505 // xxx why not 'now?'
506 $expiration= strtotime( $_POST['expires'] );
507 // loop through all slices for site
508 foreach ($site['slice_ids'] as $slice_id) {
509 $api->UpdateSlice( $slice_id, array( "expires" => $expiration ) );
511 // update site to not allow slice creation or renewal
512 $api->UpdateSite( $site_id, array( "max_slices" => 0 )) ;
513 plc_redirect (l_site($site_id));
517 case 'update-site': {
518 $site_id=intval($_POST['site_id']);
519 $name= $_POST['name'];
520 $abbreviated_name= $_POST['abbreviated_name'];
522 $latitude= floatval($_POST['latitude']);
523 $longitude= floatval($_POST['longitude']);
524 //$max_slivers= $_POST['max_slivers'];
526 $fields= array( "name" => $name,
527 "abbreviated_name" => $abbreviated_name,
529 "latitude" => floatval( $latitude ),
530 "longitude" => floatval( $longitude ));
532 if ($_POST['login_base'])
533 $fields['login_base'] = $_POST['login_base'];
534 if (isset($_POST['max_slices']))
535 $fields['max_slices'] = intval($_POST['max_slices']);
536 if (isset($_POST['enabled'])) {
537 $fields['enabled'] = (bool)$_POST['enabled'];
540 $retcod=$api->UpdateSite( intval( $site_id ), $fields );
542 drupal_set_message("Site $name updated");
544 drupal_set_error ("Could not update site $site_id");
546 plc_redirect(l_site($site_id));
550 //////////////////////////////////////////////////////////// slices
551 case 'delete-slice': {
552 $slice_id = $_POST['slice_id'];
553 if ($api->DeleteSlice( intval( $slice_id )) == 1 ) {
554 drupal_set_message("Slice $slice_id deleted");
555 plc_redirect(l_slices());
557 drupal_set_error("Could not delete slice $slice_id " . $api->error());
562 case 'update-slice': {
563 $slice_id = $_POST['slice_id'];
564 $name = $_POST['name'];
565 $description= $_POST['description'];
568 $fields= array( "description"=>$description, "url"=>$url );
569 $api->UpdateSlice( intval( $slice_id ), $fields );
570 $error= $api->error();
572 if( empty( $error ) ) {
573 drupal_set_message("Update slice $name");
574 plc_redirect(l_slice($slice_id));
576 drupal_set_error($error);
581 case 'renew-slice': {
582 $slice_id = intval ($_POST['slice_id']);
583 $expires = intval ($_POST['expires']);
589 $MAX_FUTURE=$WEEKS*$WEEK;
590 if ( ($expires-$now) > $MAX_FUTURE) {
591 drupal_set_error("Cannot renew slice that far in the future, max is $WEEKS weeks from now");
592 plc_redirect(l_slice($slice_id));
594 if ($api->UpdateSlice ($slice_id, array('expires'=>$expires)) == 1)
595 drupal_set_message("Slice renewed");
597 drupal_set_error("Could not update slice $slice_id");
598 plc_redirect(l_slice($slice_id));
602 case 'remove-persons-from-slice': {
603 $slice_id = intval ($_POST['slice_id']);
604 $person_ids = $_POST['person_ids'];
607 $tmp_slices = $api->GetSlices($slice_id, array("name"));
608 if (count($tmp_slices) > 0) {
609 $tmp_slice = $tmp_slices[0];
610 $slice_name = $tmp_slice["name"];
612 $notify_subject = "Removed from slice: " . $slice_name;
613 $notify_body = sprintf("You have been removed from the slice %s.
615 Our support team will be glad to answer any question that you might have.
617 $notify_person_ids = array();
621 foreach( $person_ids as $person_id ) {
622 if ($api->DeletePersonFromSlice(intval($person_id),$slice_id) != 1)
625 array_push($notify_person_ids, intval($person_id));
630 $api->NotifyPersons($notify_person_ids,$notify_subject,$notify_body);
631 drupal_set_message ("Deleted $counter person(s)");
634 drupal_set_error ("Could not delete all selected persons, only $counter were removed");
635 plc_redirect(l_slice($slice_id) . " &show_persons=true");
639 case 'add-persons-in-slice': {
640 $slice_id = intval ($_POST['slice_id']);
641 $person_ids = $_POST['person_ids'];
644 $tmp_slices = $api->GetSlices($slice_id, array("name"));
645 if (count($tmp_slices) > 0) {
646 $tmp_slice = $tmp_slices[0];
647 $slice_name = $tmp_slice["name"];
649 $notify_subject = "Added to slice: " . $slice_name;
650 $notify_body = sprintf("You have been added to the slice %s as a user.
652 You can go to your slice page following the link below:
653 https://%s:%d/db/slices/index.php?id=%d
655 Our support team will be glad to answer any question that you might have.
656 ",$slice_name,PLC_WWW_HOST,PLC_WWW_SSL_PORT,$slice_id);
657 $notify_person_ids = array();
661 foreach ($person_ids as $person_id) {
662 if ($api->AddPersonToSlice(intval($person_id),$slice_id) != 1)
665 array_push($notify_person_ids, intval($person_id));
670 $api->NotifyPersons($notify_person_ids,$notify_subject,$notify_body);
671 drupal_set_message ("Added $counter person(s)");
674 drupal_set_error ("Could not add all selected persons, only $counter were added");
675 plc_redirect(l_slice($slice_id) . "&show_persons=true" );
679 case 'remove-nodes-from-slice': {
680 $slice_id = intval ($_POST['slice_id']);
681 $node_ids = array_map("intval",$_POST['node_ids']);
682 $count=count($node_ids);
684 if ($api->DeleteSliceFromNodes($slice_id,$node_ids) == 1)
685 drupal_set_message ("Removed $count node(s)");
687 drupal_set_error ("Could not remove selected nodes");
688 plc_redirect(l_slice_nodes($slice_id));
692 case 'add-nodes-in-slice': {
693 $slice_id = intval ($_POST['slice_id']);
694 $node_ids = array_map("intval",$_POST['node_ids']);
695 $count=count($node_ids);
696 if ($api->AddSliceToNodes($slice_id,$node_ids) == 1)
697 drupal_set_message ("Added $count node(s)");
699 drupal_set_error ("Could not add all selected nodes");
700 plc_redirect(l_slice_nodes($slice_id));
704 case 'delete-slice-tags': {
705 $slice_id = intval($_POST['slice_id']);
706 $slice_tag_ids = array_map("intval", $_POST['slice_tag_ids']);
709 foreach($slice_tag_ids as $slice_tag_id) {
710 if ($api->DeleteSliceTag($slice_tag_id)) $count += 1;
712 drupal_set_error("Could not delete slice tag: slice_tag_id = $slice_tag_id");
717 drupal_set_message ("Deleted $count slice tag(s)");
718 plc_redirect(l_slice($slice_id) . "&show_tags=true" );
722 case 'add-slice-tag': {
723 $slice_id = intval($_POST['slice_id']);
724 $tag_type_id = intval($_POST['tag_type_id']);
725 $value = $_POST['value'];
726 $node_id = intval($_POST['node_id']);
727 $nodegroup_id = intval($_POST['nodegroup_id']);
731 $result = $api->AddSliceTag($slice_id, $tag_type_id, $value, $node_id);
732 } elseif ($nodegroup_id) {
733 $result = $api->AddSliceTag($slice_id, $tag_type_id, $value, null, $nodegroup_id);
735 $result = $api->AddSliceTag($slice_id, $tag_type_id, $value);
738 drupal_set_message ("Added slice tag.");
740 drupal_set_error("Could not add slice tag");
741 if ($_POST['sliver_action'])
742 plc_redirect(l_sliver($node_id,$slice_id));
744 plc_redirect(l_slice($slice_id) . "&show_tags=true" );
748 //////////////////////////////////////////////////////////// tag types
750 case 'update-tag-type': {
752 $tag_type_id= intval( $_POST['tag_type_id'] );
753 $tagname = $_POST['tagname'];
754 $min_role_id= intval( $_POST['min_role_id'] );
755 $description= $_POST['description'];
756 $category= $_POST['category'];
758 // make tag_type_fields dict
759 $tag_type_fields= array( "min_role_id" => $min_role_id,
760 "tagname" => $tagname,
761 "description" => $description,
762 "category" => $category,
765 if ($api->UpdateTagType( $tag_type_id, $tag_type_fields ) == 1)
766 drupal_set_message ("Tag type $tagname updated");
768 drupal_set_error ("Could not update tag type $tag_type_id\n".$api->error());
769 plc_redirect(l_tag($tag_type_id));
773 case 'add-tag-type': {
775 $tagname = $_POST['tagname'];
776 $min_role_id= intval( $_POST['min_role_id'] );
777 $description= $_POST['description'];
778 $category= $_POST['category'];
780 // make tag_type_fields dict
781 $tag_type_fields= array( "min_role_id" => $min_role_id,
782 "tagname" => $tagname,
783 "description" => $description,
784 "category" => $category,
788 $tag_type_id=$api->AddTagType( $tag_type_fields );
789 if ($tag_type_id > 0)
790 drupal_set_message ("tag type $tag_type_id created");
792 drupal_set_error ("Could not create tag type $tagname");
793 plc_redirect( l_tags());
797 case 'delete-tag-types': {
798 $tag_type_ids = $_POST['tag_type_ids'];
799 if ( ! $tag_type_ids) {
800 drupal_set_message("action=$action - No tag selected");
805 foreach ($tag_type_ids as $tag_type_id)
806 if ($api->DeleteTagType(intval($tag_type_id)) != 1)
811 drupal_set_message ("Deleted $counter tag(s)");
813 drupal_set_error ("Could not delete all selected tags, only $counter were removed");
814 plc_redirect (l_tags());
818 //////////////////////////////////////// tags
819 case 'set-tag-on-node':
820 case 'set-tag-on-interface': {
823 if ($action == 'set-tag-on-node') $node_mode=true;
826 $node_id = intval($_POST['node_id']);
828 $interface_id=intval($_POST['interface_id']);
829 $tag_type_id = intval($_POST['tag_type_id']);
830 $value = $_POST['value'];
832 $tag_types=$api->GetTagTypes(array($tag_type_id));
833 if (count ($tag_types) != 1) {
834 drupal_set_error ("Could not locate tag_type_id $tag_type_id </br> Tag not set.");
837 $tags = $api->GetNodeTags (array('node_id'=>$node_id, 'tag_type_id'=> $tag_type_id));
839 $tags = $api->GetInterfaceTags (array('interface_id'=>$interface_id, 'tag_type_id'=> $tag_type_id));
840 if ( count ($tags) == 1) {
843 $tag_id=$tag['node_tag_id'];
844 $result=$api->UpdateNodeTag($tag_id,$value);
846 $tag_id=$tag['interface_tag_id'];
847 $result=$api->UpdateInterfaceTag($tag_id,$value);
850 drupal_set_message ("Updated tag, new value = $value");
852 drupal_set_error ("Could not update tag");
855 $tag_id = $api->AddNodeTag($node_id,$tag_type_id,$value);
857 $tag_id = $api->AddInterfaceTag($interface_id,$tag_type_id,$value);
859 drupal_set_message ("Created tag, new value = $value");
861 drupal_set_error ("Could not create tag");
866 plc_redirect (l_node_tags($node_id));
868 plc_redirect (l_interface_tags($interface_id));
871 case 'delete-node-tags' :
872 case 'delete-interface-tags' : {
875 if ($action == 'delete-node-tags') $node_mode=true;
878 $tag_ids=$_POST['node_tag_ids'];
880 $tag_ids=$_POST['interface_tag_ids'];
883 drupal_set_message("action=$action - No tag selected");
888 foreach( $tag_ids as $tag_id ) {
890 $retcod = $api->DeleteNodeTag( intval( $tag_id ));
892 $retcod = $api->DeleteInterfaceTag( intval( $tag_id ));
899 drupal_set_message ("Deleted $counter tag(s)");
901 drupal_set_error ("Could not delete all selected tags, only $counter were removed");
903 plc_redirect(l_node_tags($_POST['node_id']));
905 plc_redirect(l_interface_tags($_POST['interface_id']));
908 //////////////////////////////////////// nodegroups
909 case 'update-nodegroup': {
910 $nodegroup_id = $_POST['nodegroup_id'];
911 $groupname = $_POST['groupname'];
912 $value = $_POST['value'];
915 $fields['groupname']=$groupname;
916 $fields['value']=$value;
917 if ( $api->UpdateNodeGroup($nodegroup_id,$fields) == 1)
918 drupal_set_message ('Nodegroup updated');
920 drupal_set_error ("Could not update nodegroup $groupname");
922 plc_redirect(l_nodegroup($nodegroup_id));
926 case 'add-nodegroup': {
927 $groupname=$_POST['groupname'];
928 if ( ! $groupname ) {
929 drupal_set_error ('Empty groupname');
930 plc_redirect (l_nodegroups());
932 $tag_type_id=intval($_POST['tag_type_id']);
933 if ( ! $tag_type_id ) {
934 drupal_set_error ('You must select a tag in the dropdown list');
935 plc_redirect (l_nodegroups());
937 $value=$_POST['value'];
939 drupal_set_message ("Empty value.. let's see ..");
941 if ( $api->AddNodeGroup ($groupname,$tag_type_id,$value) > 0)
942 drupal_set_message ("Nodegroup $groupname created");
944 drupal_set_error ("Could not create nodegroup $groupname");
946 plc_redirect (l_nodegroups());
950 case 'delete-nodegroups': {
951 $nodegroup_ids=$_POST['nodegroup_ids'];
952 if ( ! $nodegroup_ids ) {
953 drupal_set_message("action=delete-nodegroups - No group selected");
954 plc_redirect(l_nodegroups());
958 foreach ($nodegroup_ids as $nodegroup_id)
959 if ($api->DeleteNodeGroup(intval($nodegroup_id)) != 1)
964 drupal_set_message ("Deleted $counter group(s)");
966 drupal_set_error ("Could not delete all selected groups, only $counter were removed");
967 plc_redirect (l_nodegroups());
971 //////////////////////////////////////// leases
972 case 'manage-leases': {
973 $actions=json_decode($_POST['actions']);
979 foreach ($actions as $action) {
980 if ($action[0] == 'add-leases') {
981 $nodenames=$action[1];
982 $add_requested += count($nodenames);
983 $slicename=$action[2];
984 $t_from=intval($action[3]);
985 $t_until=intval($action[4]);
986 $hash = $api->AddLeases($nodenames,$slicename,$t_from,$t_until);
987 // update number of added leases
988 $ids=$hash['new_ids'];
989 $add_done += count($ids);
990 // update global errors array
991 foreach ($api_errors=$hash['errors'] as $error) $errors[]=$error;
992 } else if ($action[0]=='delete-leases') {
993 $lease_id=intval($action[1]);
995 if ($api->DeleteLeases(array($lease_id)) == 1) {
998 $errors []= "Could not delete lease " . $lease_id;
1001 $errors []= "in actions.php, manage-leases, wrong action ". $action[0];
1005 if (count($errors)==0) {
1006 echo("All leases updated (" . $add_done . " added and " . $del_done . " deleted)");
1008 foreach ($errors as $error) echo($error. "\n");
1009 echo("Leases updated only partially (" .
1010 $add_done . "/" . $add_requested . " added and " .
1011 $del_done . "/" . $del_requested . " deleted)");
1017 ////////////////////////////////////////
1020 plc_debug('GET',$_GET);
1021 plc_debug('POST',$_POST);
1022 plc_debug('FILES',$_FILES);
1027 plc_error ("Unknown action $action in actions.php");