5.6. Administration (Admin.rsl)

(****
 *
 * Module Admin defines the objects and operations related to maintaining the
 * Host database for the CSTutor tool.
 *
 *)

  object HostDB is
    components: HostRecord*;
    description: (*
        HostDB is the repository of Lesson Host information.
    *);
  end HostDB;

  object HostRecord is
    components: ip:IPAddress and url:URL and status:Status;
    description: (*
	A HostRecord contains a hosts information. This information includes
        IP Address, it's corresponding URL and the hosts status (Online or
	Offline)
    *);
  end HostRecord;
  
  object IPAddress is string
    description: (*
	The IP address of a host must be correctly formatted. for example:
		129.65.51.23
    *);
  end IPAddress;

  object Status is boolean
    description: (*
	The status of a host is either "Online" or "Offline." Online is
	represented by 1/true and Offline is represented by 0/false.
    *);
  end Status;


  operation AddHost is
    inputs: hdb:HostDB, hr:HostRecord;
    outputs: hdb':HostDB;

    description: (*
        Add the given HostRecord to the given HostDB.  The IP Addres of the given
        host record must not be the same as a host record already in the HostDB.
        The IP Address component is required and must be a correctly formatted IP
        Address.  The URL component is optional. There are no rules for the URL
    *);

    precondition:
	(*
	 *The IP Addres of the given host record must not be the same as a host
         *record already in the HostDB and the IP Address component is not nil. 
	 *)
	(hr.ip != nil) and
	(forall (record in hdb)
		(record.ip != hr.ip)
 	);
	

    postcondition:
	(*
	 * The given host record is in the output HostDB
	 *)
	(hr in hdb')

           and

	(*
	 * All the other host records in the output db are those from the input db,
	 * and only those.
	 *)

	forall (hr':HostRecord)
	   (hr' in hdb') iff ((hr' = hr) or (hr' in hdb));

  end AddHost;


  object InputPassword is string
    description: (*
	The InputPassword is what the user types in in order to log in to the
	system as an Administrator.
    *);
  end InputPassword;

  object CorrectPassword is string
    description: (*
	The CorrectPassword is the current password that allows a user to log in
	to the system as an Administrator.
    *);
  end CorrectPassword;

  object IsLoggedIn is boolean
    description: (*
	The IsLoggedIn flag keeps track of whether the current user is logged
	in as an administrator or not. 1/true indicates that the user is logged
	in (which means they can access Administrative Functions) and 0/false
	indicates that the user is not logged in.
    *);
  end IsLoggedIn;


  operation Login is
    inputs: inpass:InputPassword, corrpass:CorrectPassword, islog:IsLoggedIn;
    outputs: islog':IsLoggedIn;
    description: (*
	Log in the user by changing the IsLoggedIn flag to true if the
	InputPassword is the same as the CorrectPassword.
    *);
    
    precondition:
	(*
	 * IsLoggedIn must be false and InputPassword must equal CorrectPassword.
	 *)

	(not islog) and (inpass = corrpass);

    postcondition:
	(*
	 * IsLoggedIn is set to True
	 *)
	
	islog';

  end Login;

  operation Logout is
    inputs: islog:IsLoggedIn;
    outputs: islog':IsLoggedIn;

    description: (*
	Log the user out by setting IsLoggedIn to 0/false. This operation should
	never be used if IsLoggedIn is already false (i.e. a user who is not
	logged in cannot logout).
    *);

    precondition:
	(*
	 * IsLoggedIn must be true.
	 *)

	islog;

    postcondition:
	(*
	 * IsLoggedIn must be false.
	 *)
	not islog';

  end Logout;


  operation RemoveHost is
    inputs: hdb:HostDB, hr:HostRecord;
    outputs: hdb':HostDB;
    description: (*
        Remove the given host record from the given HostDB.  The given record
        must already be in the input db.
    *);

    precondition:
	(*
	 * The given HostRecord is in the HostDB
	 *)
	
	hr in hdb;

    postcondition:
	(*
	 * A host record is in the output db if and only if it is not the
	 * existing record to be deleted and it is in the input db.
	 *)

	(forall (hr':HostRecord)
		(hr' in hdb') iff ((hr' != hr) and (hr' in hdb)));

  end RemoveHost;


  object HostView is
    components: HostInfo*;
    description: (*
	The host view object contains information regarding a host.
    *);
  end HostView;

  object HostInfo is
    components: IPAddress and URL and Status;
    description: (*
	Basically the exact same information as is contained within a HostRecord.
	HostInfo is used in a HostView.
    *);
  end HostInfo;



  object PasswordChangeRequest is
    components: oldpass:OldPassword and newpass:NewPassword and confirmnp:ConfirmNewPassword;
    description: (*
	PasswordChangeRequest contains the information necessary to change the
	password required to login as an Administrator
    *);
  end PasswordChangeRequest;

  object OldPassword is string
    description: (*
	OldPassword corresponds to the "Old Password" field in the change Password
	dialog. OldPassword is used to change the current admin password.
    *);
  end OldPassword;

  object NewPassword is string
    description: (*
	NewPassword corresponds to the "New Password" field in the change Password
	dialog. NewPassword is used to change the current admin password.
    *);
  end NewPassword;

  object ConfirmNewPassword is string
    description: (*
	ConfirmNewPassword corresponds to the "Confirm New Password" field in the
	change password dialog. ConfirmNewPassword is used to change the current
	admin password
    *);
  end ConfirmNewPassword;

  operation ChangePassword is
    inputs: passcr:PasswordChangeRequest, corrpass:CorrectPassword;
    outputs: corrpass':CorrectPassword;
    description: (*
	If the OldPassword component of the PasswordChangeRequest is the same as the
	CorrectPassword AND both the NewPassword and ConfirmNewPassword components of
	PasswordChangeRequest are the same and not nil, then CorrectPassword gets changed to
	be the same as the NewPassword component in the PasswordChangeRequest.
    *);

    precondition:
	(*
	 * The old password is the same as the current correct password
	 *   and
	 * The new password and the new password confirmation are equal and not nil.
	 *)

	(passcr.oldpass = corrpass) and
		((passcr.newpass = passcr.confirmnp) and (passcr.newpass != nil));
	

    postcondition:
	(*
	 * The current correct passowrd gets changed to be the same as the
	 * new password.
	 *)
	
	corrpass' = passcr.newpass;

  end ChangePassword;