iSeries EGL

All things EGL for the iSeries / i5 / Power System

Archive for August 2012

Calculate an Interval Between TimeStamps

leave a comment »

Introduction

This post shows how to use Date, Time, Intervals, and Timestamps to determine if the EGL application has been launched within the past five minutes using only the hours, minutes and seconds provided as an encoded parameter on the URL. Using the HHMMSS, a full timestamp object is created containing the current date. Using an Interval, a determination can be made about how far in the past the timestamp lies as compared to a timestamp that represents the current date and time.

 

Some Background

Without access to LDAP services that can be used to authenticate a user, alternate methods are employed to prevent users from bookmarking a web page that can be used later. The scheme chosen for this purpose relies upon encoding of the time at which the menu option was selected to launch the application. At that point the time (HHMMSS) is encrypted, encoded as a parameter and integrated within the URL string that directs the browser to the web page.

When the EGL application starts it obtains the full URL string (using document.location), isolates the parameter representing the HHMMSS, decrypts it and then performs the EGL date calculations presented below to determine if this is a “fresh” invocation of the application as opposed to a “stale” request as a consequence of using a bookmark.

 

Validate the Parameters

The task of isolating the parameters from the URL has been performed. The parameters are passed in an array and it is the second parameter that contains the HHMMSS that is the focus of the function presented below.

The first task to perform is to decrypt the parameters. This is performed using a PCML based call to the RPG program residing on the local iSeries. The HHMMSS is then decrypted from “TVWXTY” into a human readable “145617”. Now, EGL can use this as the basis for a timestamp object.

    //***************************************************************
    // Validate the parms in the string array.
    //  o The first parm is the encoding method key
    //  o The second value is the time expressed as hhmmss
    //  o The third value is the user id
    //

    private function validateParms(parms string[] in) returns(boolean)

        isValid boolean = false;
        
        PCode string = parms[1];
        hhmmssEncrypted string = parms[2];
        userIDEncrypted string = parms[3];

        hhmmss string = "";
        userId string = "";

        //**************************************************
        //Instantiate the Java encryption class with a 
        //connection to the Production iSeries to decrypt
        //the time and user id.
        //**************************************************        
        
        //*WARNING* THE MACHINE NAME, USER ID and PASSWORD SHOULD BE EXTERNALIZED TO A CONFIG FILE.
        //IN ADDITION LOGIC NEEDS TO DETERMINE IF AND WHEN THIS APPLICATION IS RUNNING ON EITHER
        //THE TOMCAT TEST SERVER OR THE TOMCAT PRODUCTION SERVER SO THAT THE CORRECT CONNECTION 
        //INFORMATION IS USED.  
        ncryp01s1 CallNCRYP01S1 = new CallNCRYP01S1("MachId", "UserId", "Password");
        
        //Decrypt the time
        hhmmss = ncryp01s1.decryptValue(hhmmssEncrypted, PCode);
        
        //Decrypt the user id
        userId = ncryp01s1.decryptValue(userIDEncrypted, PCode);
        
        
        //**************************************************
        //Determine the number of minutes that have passed 
        //between 5 minutes ago and now.
        //**************************************************
        urlTime time = DateTimeLib.timeValue(hhmmss);
        urlTimeStamp timeStamp = DateTimeLib.timestampFrom(DateTimeLib.currentDate(), urlTime);
       
        currentTime timeStamp = DateTimeLib.currentTime();
        minutesInterval interval("mm") = "05";
        timeFiveMinutesAgo timeStamp = currentTime - minutesInterval;
        
        //Create an interval expressed in minutes by subtracting time as of 5 minutes ago from the
        //time given on the URL.
        differenceInMinutes interval("mm") = urlTimeStamp - timeFiveMinutesAgo;
        if(differenceInMinutes <= 5)
        	isValid = true;
        else
        	isValid = false;
        end
        
        return(isValid);
    end

Fig.1 – Source code for the validate function

 

This section of the function decrypts the parameters passed on the URL. The HHMMSS to be decrypted is contained in the variable named ‘hhmmssEncrypted’.

        //*WARNING* THE MACHINE NAME, USER ID and PASSWORD SHOULD BE EXTERNALIZED TO A CONFIG FILE.
        //IN ADDITION LOGIC NEEDS TO DETERMINE IF AND WHEN THIS APPLICATION IS RUNNING ON EITHER
        //THE TOMCAT TEST SERVER OR THE TOMCAT PRODUCTION SERVER SO THAT THE CORRECT CONNECTION 
        //INFORMATION IS USED.  
        ncryp01s1 CallNCRYP01S1 = new CallNCRYP01S1("MachId", "UserId", "Password");
        
        //Decrypt the time
        hhmmss = ncryp01s1.decryptValue(hhmmssEncrypted, PCode);
        
        //Decrypt the user id
        userId = ncryp01s1.decryptValue(userIDEncrypted, PCode);

Fig.2 – Decrypting the URL parameters.

 

 

Now that the time parameter has been decrypted, the first thing to do is to create a timestamp. To do this the time in HHMMSS is used to create a time object which is then used as the basis for a fully formed timestamp.

Next, another timestamp is created, based upon the current time. An interval object is created representing 5 minutes which is subtracted from the current time giving a new timestamp as of 5 minutes ago

The EGL code used to do this is isolated below.

        //**************************************************
        //Determine the number of minutes that have passed 
        //between 5 minutes ago and now.
        //**************************************************
        urlTime time = DateTimeLib.timeValue(hhmmss);
        urlTimeStamp timeStamp = DateTimeLib.timestampFrom(DateTimeLib.currentDate(), urlTime);
       
        currentTime timeStamp = DateTimeLib.currentTime();
        minutesInterval interval("mm") = "05";
        timeFiveMinutesAgo timeStamp = currentTime - minutesInterval;

Fig.3 – Creating urlTime from the decrypted HHMMSS.

 

 
 

This section of the function determines if the difference between the time passed on the URL is within the last 5 minutes of the present time. It does this by determining the difference between the timestamp of the HHMMSS on the URL and the timestamp for 5 minutes ago. The answer is placed into another interval of minutes called ‘differenceInMinutes’.

A test is made to see if that difference is within 5 minutes which is the range allowed to declare a URL request as “fresh”. The boolean for true is returned to the RichUI Handler’s start function which then allows processing to continue, i.e. the user did not use a bookmark to launch the application, they used the proper menu option on an internally controlled web page that is the launch point for all applications.

        //Create an interval expressed in minutes by subtracting time as of 5 minutes ago from the
        //time given on the URL.
        differenceInMinutes interval("mm") = urlTimeStamp - timeFiveMinutesAgo;
        if(differenceInMinutes <= 5)
        	isValid = true;
        else
        	isValid = false;
        end
        
        return(isValid);

Fig.4 – Determining the time elapsed.

 

 

The values of each variable derived in the code above are shown in this variables list as seen in the IDE.

The values of the variables at end of execution. Click to enlarge.

 

The values shown above where taken during testing of the function. Astute observers will note a very stale time has been supplied. Needles to say, the boolean returned is ‘false’. Also, the weakness of the scheme is also revealed in that a bookmarked URL will always be determined to be within 5 minutes of the current time for each day.

This scheme prevents launching of applications from bookmarks.
 

Advertisements

Written by iseriesadmin

August 22, 2012 at 2:52 pm

Posted in EGL Date Math

Tagged with

Using CSS to Assign a Menu Icon

leave a comment »

Introduction

This post will show how to use EGL’s CSS Editor to create a class that will be used to assign an icon to a menu item

Images

To begin, we’ll need a place to put our images used with the application. It is common to have an images directory under the WebContent directory, shown below. However, EGL already supplies an icons directory, so we’ll put our icons there.

The icons shown above are those for a back facing arrow (“back, and to the left”) and a right facing arrow (forward).

 

Use the CSS Editor to create Classes

The image below shows RDi’s Cascading Style Sheet editor. The last two classes i.e. .backArrow and .forwardArrow define references to the .PNG files in the icons directory.

The Cascading Style Sheet (CSS) editor


At the right of the editor you can see that the back-facing arrow has been selected as denoted by the blue horizontal bar. At the upper left of the editor widow the effect of the CSS class is displayed.

 

Referencing the CSS Class on a Menu Item

Show below is the EGL code for a menu item. It references the CSS class definition for the forward and backward facing arrows. This will result in the arrows being display at the left of each menu item.

    gotoMenu DojoMenu{ layoutData = new GridLayoutData{ row = 1, column = 3 }, text = "Go to", children = [
		new DojoMenuItem {
			text = "Back", iconClass = "dijitEditorIcon backArrow", onClick ::= onBack
		},
		new DojoMenuItem {
			text = "Page1", iconClass = "dijitEditorIcon backArrow", onClick ::= onPage1
		}, 
		new DojoMenuItem {
			text = "Page3", iconClass = "dijitEditorIcon forwardArrow", onClick ::= onPage3
		},		
		new DojoMenuItem {
			text = "The next item is a separator"
		},
		new DojoMenuItem { },
		new DojoMenuItem {
			text = "Item 3, this one is disabled", disabled = true
		}
	]};

Fig.1 – EGL code defining a menu and its items that reference a CSS class.

 

The Menu Items

The menu below shows the icons as they are presented next to each of the menu items described by the EGL code, above.

Menu Items with Icons described by Cascading Style Sheet classes.

 

Summary

This post shows how to use CSS to define style classes so they can be used to show icons for specific menu items. Defining CSS styles in this manner centralizes them in a single file. This allows the developer to make a single change that effects the whole look and feel of the application.

 
 

Written by iseriesadmin

August 7, 2012 at 7:13 pm