# # {{{EMULAB-LICENSE# # This file is part of the Emulab network testbed software.# # This file is free software: you can redistribute it and/or modify it# under the terms of the GNU Affero General Public License as published by# the Free Software Foundation, either version 3 of the License, or (at# your option) any later version.# # This file is distributed in the hope that it will be useful, but WITHOUT# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public# License for more details.# # You should have received a copy of the GNU Affero General Public License# along with this file. If not, see <http://www.gnu.org/licenses/>.# # }}}#chdir("..");chdir("apt");include_once("profile_defs.php");include_once("instance_defs.php");include_once("ajax-routines.ajax");# We set this in CheckPageArgs$target_user=null;## Need to check the permission, since we allow admins to mess with# other accounts.#functionCheckPageArgs(){global$this_user,$target_user;global$ajax_args;global$TB_USERINFO_READINFO;if(!isset($ajax_args["uid"])){SPITAJAX_ERROR(-1,"Missing target uid");return-1;}$uid=$ajax_args["uid"];if(!TBvalid_uid($uid)){SPITAJAX_ERROR(-1,"Invalid target uid");return-1;}$target_user=User::Lookup($uid);if(!$target_user){sleep(2);SPITAJAX_ERROR(-1,"Unknown target uid");return-1;}if($uid==$this_user->uid())return0;

## Usage for the user, in pnode hours. #functionDo_UsageSummary(){global$this_user,$target_user;global$ajax_args;if(CheckPageArgs()){return;}list($pcount,$phours)=Instance::CurrentUsage($target_user);list($weekpcount,$weekphours)=Instance::WeeksUsage($target_user);list($monthpcount,$monthphours)=Instance::MonthsUsage($target_user);list($rank,$ranktotal)=Instance::Ranking($target_user,30);if($phours<2){$phours=sprintf("%.1f",$phours);}else{$phours=sprintf("%.0f",$phours);}if($weekphours<2){$weekphours=sprintf("%.1f",$weekphours);}else{$weekphours=sprintf("%.0f",$weekphours);}if($monthphours<2){$monthphours=sprintf("%.1f",$monthphours);}else{$monthphours=sprintf("%.0f",$monthphours);}$blob=array("pnodes"=>$pcount,"phours"=>$phours,"weekpnodes"=>$weekpcount,"weekphours"=>$weekphours,

## Freeze or Thaw.#functionDo_FreezeOrThaw(){global$this_user,$target_user;global$ajax_args,$suexec_output;global$TBADMINGROUP;if(CheckPageArgs()){return;}if(!ISADMIN()){SPITAJAX_ERROR(-1,"Not enough permission");return;}if($target_user->status()!=TBDB_USERSTATUS_ACTIVE&&$target_user->status()!=TBDB_USERSTATUS_FROZEN){SPITAJAX_ERROR(-1,"User is not active or frozen!");return;}$target_idx=$target_user->uid_idx();$target_uid=$target_user->uid();$this_uid=$this_user->uid();if(!isset($ajax_args["which"])){SPITAJAX_ERROR(-1,"What am I supposed to do?");return-1;}$which=strtolower($ajax_args["which"]);if($which!="freeze"&&$which!="thaw"){SPITAJAX_ERROR(-1,"Cannot do that: $which");return-1;}# Use -u (update) and -f (force) to make it happen.if(SUEXEC($this_uid,$TBADMINGROUP,"webtbacct -u -f $which$target_uid",SUEXEC_ACTION_CONTINUE)){SPITAJAX_ERROR(-1,$suexec_output);return-1;}SPITAJAX_RESPONSE(1);}

## Send a reset password link, no cookie required.#functionDo_SendPasswordReset(){global$this_user,$target_user;global$ajax_args,$APTBASE,$APTMAIL,$TBMAIL_WWW,$TBMAIL_AUDIT;if(CheckPageArgs()){return;}if(!ISADMIN()){SPITAJAX_ERROR(-1,"Not enough permission");return;}if($target_user->status()!=TBDB_USERSTATUS_ACTIVE&&$target_user->status()!=TBDB_USERSTATUS_FROZEN){SPITAJAX_ERROR(-1,"User is not active or frozen!");return;}$target_idx=$target_user->uid_idx();$target_uid=$target_user->uid();$target_name=$target_user->name();$target_email=$target_user->email();## Generate a random key and send the user an email message with a URL# that will allow them to change their password. #$key=GENHASH();$target_user->SetChangePassword($key,"UNIX_TIMESTAMP(now())+(60*10)");TBMAIL("$target_name <$target_email>","Password reset for '$target_uid'","\n"."Here is your password reset authorization URL. Click on this\n"."link within the next 10 minutes, and you will be allowed to\n"."reset your password.\n"."\n"." ${APTBASE}/changepswd.php?user=$target_uid&reset=$key\n"."\n"."\n"."Thanks!\n","From: $APTMAIL\n"."Bcc: $TBMAIL_AUDIT\n"."Errors-To: $TBMAIL_WWW");SPITAJAX_RESPONSE(1);}

functionDo_SendTestMessage(){global$this_user,$target_user;global$APTMAIL;if(CheckPageArgs()){return;}if(!ISADMIN()){SPITAJAX_ERROR(1,"Only administrators can do this.");return;}$target_idx=$target_user->uid_idx();$target_uuid=$target_user->uuid();$target_email=$target_user->email();$target_name=$target_user->name();$target_uid=$target_user->uid();$adminemail=$target_user->adminEmail();TBMAIL("$target_name '$target_uid' <$target_email>","This is a test","\n"."Dear $target_name ($target_uid):\n"."\n"."This is a test message to validate the email address that we\n"."have in our database. Please respond to this message\n"."as soon as you receive it. If we do not hear back from you, we\n"."may be forced to freeze your account.\n"."\n"."Thank you very much!\n","From: $adminemail\n"."Bcc: stoller");SPITAJAX_RESPONSE(1);}

functionDo_NagPI(){global$this_user,$ajax_args;if(!isset($ajax_args["pid"])){SPITAJAX_ERROR(-1,"Missing project name");return-1;}if(!TBvalid_pid($ajax_args["pid"])){SPITAJAX_ERROR(-1,"Invalid project name");return-1;}$project=Project::Lookup($ajax_args["pid"]);if(!$project){SPITAJAX_ERROR(-1,"No such project");return-1;}$group=$project->DefaultGroup();if(!$group){SPITAJAX_ERROR(-1,"Internal error getting group");return-1;}$membership=$group->MemberShipInfo($this_user);if($membership["date_approved"]){SPITAJAX_ERROR(1,"You have already been approved, please refresh "."the page to see your updated status.");return-1;}if($membership["date_nagged"]){$nagged=strtotime($membership["date_nagged"]);if(time()-$nagged<3600*24){SPITAJAX_ERROR(1,"You recently reminded the project leader, "."lets give him/her a chance to respond before "."sending another reminder.");return-1;}}# Chalk an error up to a double click, do not bother to do anything.$group->NewMemberNotify($this_user,true);SPITAJAX_RESPONSE("nagged");}