$known_actions []= "delete-interface-tags";
// expects: interface_id & interface_tag_ids
+//////////////////////////////////////// nodegroups
+$known_actions []= "update-nodegroup";
+// expects nodegroup_id groupname value
+$known_actions []= "add-nodegroup";
+// expects groupname, tag_type_id, value
+$known_actions []= 'delete-nodegroups';
+// expects nodegroup_ids
+
////////////////////////////////////////////////////////////
$interface_details= array ('method','type', 'ip', 'gateway', 'network',
'broadcast', 'netmask', 'dns1', 'dns2',
case 'remove-roles-from-person' : {
$role_ids=$_POST['role_ids'];
if ( ! $role_ids) {
- drupal_set_message("action=$action - No role selected");
- return;
- }
- foreach( $role_ids as $role_id) {
- $api->DeleteRoleFromPerson( intval( $role_id ), intval( $person_id ) );
+ drupal_set_error("You have not selected role(s) to remove");
+ } else {
+ foreach( $role_ids as $role_id)
+ if ( $api->DeleteRoleFromPerson( intval( $role_id ), intval( $person_id ) ) != 1 )
+ drupal_set_error ("Could not remove role $role_id from person $person_id");
}
- plc_redirect (l_person($person_id));
+ plc_redirect (l_person_roles($person_id));
}
case 'add-role-to-person' : {
$role_id=$_POST['role_id'];
- $api->AddRoleToPerson( intval( $role_id ), intval( $person_id ) );
- plc_redirect (l_person($person_id));
+ if ( ! $role_id) {
+ drupal_set_error ("You have not selected a role to add");
+ } else if ($api->AddRoleToPerson( intval( $role_id ), intval( $person_id ) ) != 1) {
+ drupal_set_error("Could not add role $role_id to person $person_id");
+ }
+ plc_redirect (l_person_roles($person_id));
}
case 'enable-person' : {
drupal_set_error ("Could not delete all selected interfaces, only $counter were removed");
plc_redirect(l_node($_POST['node_id']));
}
+
case 'new-interface': {
plc_redirect(l_interface_add($_POST['node_id']));
}
+
case 'add-interface': {
- $node_id=$_POST['node_id'];
+ $node_id=intval($_POST['node_id']);
foreach ($interface_details as $field) {
$interface[$field]= $_POST[$field];
+ // these must be integers
if( in_array( $field, array( 'bwlimit', 'node_id' ) ) ) {
- $interface[$field]= intval( $interface[$field] );
+ if ( empty ($interface[$field]) )
+ unset ($interface[$field]);
+ else
+ $interface[$field]= intval( $interface[$field] );
}
}
- $interface_id =$api->AddInterface( intval( $node_id ), $interface );
- if ($interface_id >0 ) {
- $api->begin();
- $api->AddInterfaceTag($interface_id,"alias",strval($interface_id));
- $api->AddInterfaceTag($interface_id,"ifname","eth0");
- list($id1, $id2) = $api->commit();
- if ( $id1 > 0 && $id2 > 0 ) {
- drupal_set_message ("Interface $interface_id added into node $node_id");
- } else {
- drupal_set_error ("Could not add interface tags to interface $interface_id");
- }
- } else {
+ $interface_id =$api->AddInterface( $node_id , $interface );
+ if ($interface_id <= 0 ) {
drupal_set_error ("Could not create interface");
+ drupal_set_error ($api->error());
+ } else {
+ $ip=$interface['ip'];
+ drupal_set_message ("Interface $ip added into node $node_id");
}
plc_redirect (l_node($node_id));
}
drupal_set_error("Cannot renew slice that far in the future, max is $WEEKS weeks from now");
plc_redirect(l_slice($slice_id));
}
- plc_debug('slice_id',$slice_id);
- plc_debug('expires',$expires);
if ($api->UpdateSlice ($slice_id, array('expires'=>$expires)) == 1)
drupal_set_message("Slice renewed");
else
drupal_set_message ("Removed $count node(s)");
else
drupal_set_error ("Could not remove selected nodes");
- plc_redirect(l_slice($slice_id) . " &show_nodes=true");
+ plc_redirect(l_slice_nodes($slice_id));
break;
}
drupal_set_message ("Added $count node(s)");
else
drupal_set_error ("Could not add all selected nodes");
- plc_redirect(l_slice($slice_id) . "&show_nodes=true" );
+ plc_redirect(l_slice_nodes($slice_id));
break;
}
else
drupal_set_error ("Could not update tag type $tag_type_id\n".$api->error());
plc_redirect(l_tag($tag_type_id));
+ break;
}
case 'add-tag-type': {
else
drupal_set_error ("Could not create tag type $tagname");
plc_redirect( l_tags());
+ break;
}
case 'delete-tag-types': {
plc_redirect(l_interface($_POST['interface_id']));
}
+//////////////////////////////////////// nodegroups
+ case 'update-nodegroup': {
+ $nodegroup_id = $_POST['nodegroup_id'];
+ $groupname = $_POST['groupname'];
+ $value = $_POST['value'];
+
+ $fields=array();
+ $fields['groupname']=$groupname;
+ $fields['value']=$value;
+ if ( $api->UpdateNodeGroup($nodegroup_id,$fields) == 1)
+ drupal_set_message ('Nodegroup updated');
+ else
+ drupal_set_error ("Could not update nodegroup $groupname");
+
+ plc_redirect(l_nodegroup($nodegroup_id));
+
+ }
+
+ case 'add-nodegroup': {
+ $groupname=$_POST['groupname'];
+ if ( ! $groupname ) {
+ drupal_set_error ('Empty groupname');
+ plc_redirect (l_nodegroups());
+ }
+ $tag_type_id=intval($_POST['tag_type_id']);
+ if ( ! $tag_type_id ) {
+ drupal_set_error ('You must select a tag in the dropdown list');
+ plc_redirect (l_nodegroups());
+ }
+ $value=$_POST['value'];
+ if ( ! $value ) {
+ drupal_set_message ("Empty value.. let's see ..");
+ }
+ if ( $api->AddNodeGroup ($groupname,$tag_type_id,$value) > 0)
+ drupal_set_message ("Nodegroup $groupname created");
+ else
+ drupal_set_error ("Could not create nodegroup $groupname");
+
+ plc_redirect (l_nodegroups());
+ break;
+ }
+
+ case 'delete-nodegroups': {
+ $nodegroup_ids=$_POST['nodegroup_ids'];
+ if ( ! $nodegroup_ids ) {
+ drupal_set_message("action=delete-nodegroups - No group selected");
+ plc_redirect(l_nodegroups());
+ }
+ $success=true;
+ $counter=0;
+ foreach ($nodegroup_ids as $nodegroup_id)
+ if ($api->DeleteNodeGroup(intval($nodegroup_id)) != 1)
+ $success=false;
+ else
+ $counter++;
+ if ($success)
+ drupal_set_message ("Deleted $counter group(s)");
+ else
+ drupal_set_error ("Could not delete all selected groups, only $counter were removed");
+ plc_redirect (l_nodegroups());
+ break;
+ }
////////////////////////////////////////