// expects: node_id
$known_actions []= "update-node";
// expects: node_id, hostname, model
+$known_actions []= "attach-pcu";
+// expects: node_id, pcu_id, port (pcu_id <0 means detach)
//////////////////////////////////////// interfaces
$known_actions []= "delete-interfaces";
// expects: interface_ids
$known_actions []="add-interface";
// expects: node_id & interface details
+$known_actions []="new-interface";
+// expects: node_id
$known_actions []="update-interface";
// expects: interface_id & interface details
$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' : {
}
case 'update-node': {
+ $node_id=intval($_POST['node_id']);
$hostname= $_POST['hostname'];
$model= $_POST['model'];
$fields= array( "hostname"=>$hostname, "model"=>$model );
- $api->UpdateNode( intval( $node_id ), $fields );
+ $api->UpdateNode( $node_id, $fields );
$error= $api->error();
if( empty( $error ) ) {
break;
}
+ // this code will ensure that at most one PCU gets attached to the node
+ case 'attach-pcu': {
+ $node_id=intval($_POST['node_id']);
+ $pcu_id=intval($_POST['pcu_id']);
+ $port=intval($_POST['port']);
+ // always start with deleting former PCUs
+ $nodes = $api->GetNodes(array($node_id),array('pcu_ids'));
+ $former_pcu_ids = $nodes[0]['pcu_ids'];
+ if ($former_pcu_ids) foreach ($former_pcu_ids as $former_pcu_id) {
+ if ($api->DeleteNodeFromPCU($node_id,$former_pcu_id) == 1)
+ drupal_set_message ('Detached node ' . $node_id . ' from PCU ' . $pcu_id);
+ else
+ drupal_set_error ('Could not detach node ' . $node_id . ' from PCU ' . $pcu_id);
+ }
+ // re-attach only if provided pcu_id >=0
+ if ($pcu_id >= 0) {
+ if ($api->AddNodeToPCU($node_id,$pcu_id,$port) == 1)
+ drupal_set_message ('Attached node ' . $node_id . ' to PCU ' . $pcu_id . ' on port ' . $port);
+ else
+ drupal_set_error ('Failed to attach node ' . $node_id . ' to PCU ' . $pcu_id . ' on port ' . $port);
+ } else {
+ drupal_set_message ('Detached node from all PCUs');
+ }
+
+ plc_redirect(l_node($node_id));
+ break;
+ }
+
+
//////////////////////////////////////////////////////////// interfaces
case 'delete-interfaces' : {
$interface_ids=$_POST['interface_ids'];
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] );
}
}
- $result=$api->AddInterface( intval( $node_id ), $interface );
- if ($result >0 )
- drupal_set_message ("Interface $result added into node $node_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));
}
foreach ($interface_details as $field) {
$interface[$field]= $_POST[$field];
if( in_array( $field, array( 'bwlimit', 'node_id' ) ) ) {
- $interface[$field]= intval( $interface[$field] );
+ if ( intval($interface[$field]) != 0 ) {
+ $interface[$field]= intval( $interface[$field]);
+ } elseif ($field=='bwlimit' ) {
+ $interface[$field] = NULL;
+ }
}
}
$result=$api->UpdateInterface( intval( $interface_id ), $interface );
if ($_POST['login_base'])
$fields['login_base'] = $_POST['login_base'];
- if ($_POST['max_slices'])
+ if (isset($_POST['max_slices']))
$fields['max_slices'] = intval($_POST['max_slices']);
+ if (isset($_POST['enabled'])) {
+ $fields['enabled'] = (bool)$_POST['enabled'];
+ }
$retcod=$api->UpdateSite( intval( $site_id ), $fields );
if ($retcod == 1)
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
$slice_id = intval ($_POST['slice_id']);
$person_ids = $_POST['person_ids'];
+ $slice_name = "";
+ $tmp_slices = $api->GetSlices($slice_id, array("name"));
+ if (count($tmp_slices) > 0) {
+ $tmp_slice = $tmp_slices[0];
+ $slice_name = $tmp_slice["name"];
+ }
+ $notify_subject = "Removed from slice: " . $slice_name;
+ $notify_body = sprintf("You have been removed from the slice %s.
+
+Our support team will be glad to answer any question that you might have.
+",$slice_name);
+ $notify_person_ids = array();
+
$success=true;
$counter=0;
foreach( $person_ids as $person_id ) {
if ($api->DeletePersonFromSlice(intval($person_id),$slice_id) != 1)
$success=false;
- else
+ else {
+ array_push($notify_person_ids, intval($person_id));
$counter++;
+ }
}
- if ($success)
+ if ($success) {
+ $api->NotifyPersons($notify_person_ids,$notify_subject,$notify_body);
drupal_set_message ("Deleted $counter person(s)");
+ }
else
drupal_set_error ("Could not delete all selected persons, only $counter were removed");
plc_redirect(l_slice($slice_id) . " &show_persons=true");
case 'add-persons-in-slice': {
$slice_id = intval ($_POST['slice_id']);
$person_ids = $_POST['person_ids'];
+
+ $slice_name = "";
+ $tmp_slices = $api->GetSlices($slice_id, array("name"));
+ if (count($tmp_slices) > 0) {
+ $tmp_slice = $tmp_slices[0];
+ $slice_name = $tmp_slice["name"];
+ }
+ $notify_subject = "Added to slice: " . $slice_name;
+ $notify_body = sprintf("You have been added to the slice %s as a user.
+
+You can go to your slice page following the link below:
+https://%s:%d/db/slices/index.php?id=%d
+
+Our support team will be glad to answer any question that you might have.
+",$slice_name,PLC_WWW_HOST,PLC_WWW_SSL_PORT,$slice_id);
+ $notify_person_ids = array();
$success=true;
$counter=0;
foreach ($person_ids as $person_id) {
if ($api->AddPersonToSlice(intval($person_id),$slice_id) != 1)
$success=false;
- else
+ else {
+ array_push($notify_person_ids, intval($person_id));
$counter++;
+ }
}
- if ($success)
+ if ($success) {
+ $api->NotifyPersons($notify_person_ids,$notify_subject,$notify_body);
drupal_set_message ("Added $counter person(s)");
+ }
else
drupal_set_error ("Could not add all selected persons, only $counter were added");
plc_redirect(l_slice($slice_id) . "&show_persons=true" );
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;
+ }
////////////////////////////////////////