Sunday, December 18, 2016

Adding Text, Links and Other Elements to the NetScaler Logon Page - Part 2


As we discussed in Part 1 of this post, there are three categories of NetScaler customizations:

1) Customizations that do not require any rewrite policies/actions (“policies”) or source code modifications (“modifications”),

2) Customizations that can be accomplished using either policies or modification, and

3) Customizations that will most probably need modification of the source code.

In Part 1, we focused on the DefaultGreen Bubble, and X1 (the "original") themes. In part 2, we will discuss the newest theme - Receiver for Web UI (RfWebUI), which uses a completely new mechanism.

While the logon page looks like the X1 theme:

... if you will be using the RfWebUI theme, you can forget pretty much everything you've learned about customizing the NetScaler logon page.  

Let's begin with the location of the logon page. When using the original themes, the logon page (index.html) was served from the  /netscaler/ns_gui/vpn/ directory. With the RfWebUI theme, the file is now served from /var/netscaler/logon/LogonPoint/. The good news is that since the page is now in the /var partition, any modifications to the page (or copies of the logon page) are automatically persisted across a reboot. No longer do you need to add lines to rc.netscaler to copy modified files into the flash partition.

The next major change is how you modify text. The portal wizard allows you to easily make changes to commonly updated text. Let's say you wanted to change the labels on the logon screen. After clicking OK at the bottom of the wizard, you will then be prompted for the language you wish to use:
After clicking OK, you will see the pages you can modify on the right-hand side of the page.   
Click Login Page. You are presented with the default labels for the page:

Let's modify them as follows:



Click Ok.


Finally, click Done. Now, let's refresh the page (you may need to clear your cache).

If you've had experience customizing the original NetScaler themes, at this point you are probably thinking "Tell me something that I don't already know ... this is no different than modifying any of the other themes"! Not quite ... The portal wizard functions differently depending on which theme has been chosen. For the original themes, the portal wizard would modify the values in the appropriate XML file in the resources directory (e.g. /var/netscaler/logon/themes/<theme>/resources/en.xml). The keys affected are located under the Partition ID of Logon. Now, what if you wished to modify the text of the logon button above, which you can't do from the portal wizard? No problem. In the same file, as few lines down, we find:
<Property id="Log_On" property="value">Log On</Property>
Simply change it to:
<Property id="Log_On" property="value">Click to log on</Property>


... and then save the file.

Try that with a theme based on RfWebUI and you will find that it doesn't work. In fact, if you look at the en.xml file in the resources directory of a theme based on RfWebUI, you will notice that the portal wizard did *not* modify ANY of the keys in that file. What gives??

For RfWebUI-based themes, those text changes are written to /var/netscaler/logon/themes/<theme>/strings.<language code>.json:



The portal wizard writes all the values on a single line. I would suggest placing each override on a separate line for readability and maintainability. Also note that this "key":"value" format differs from the XML format of the other themes. 

In order to change other text elements on the page, you will need to get the key to be placed in the override file. The keys may be found in the file /var/netscaler/logon/LogonPoint/receiver/js/localization/<language code>/ctxs.strings.js. The key for the logon button is nsg_LogOnbutton. Let's add an override for it in the above file:

Then save the file, and refresh the page. In addition to clearing the cache on your PC, it may take 2-3 minutes for the cache to be cleared on the NetScaler.



Now, let's try to add our own custom text fields as we did with the X1 theme in part 1.

Here we come to another major difference. In the original themes, we would:

- Add a <div> with a unique id (either via a rewrite action/policy or a modified gateway_login_form_view.js file),

- Add a string with the <div>'s id to the XML file in the resources directory, and finally 

- Add a CSS selector with the <div>'s id to the custom.css file in the selected theme.

Note that everything is keyed off the id of the <div>.

With RfWebUI-based themes, text is keyed off of class names, and the class name must begin with _ctxstxt_. So, to add the "authorized users only" warning (see Part 1), we make a copy of the index.html file (let's call it custom.html), and add our custom <div>:



We then add an entry with the text into strings.en.json:



We also need to add style information, but instead of adding it to custom.css, for RfWebUI-based themes, it must go into theme.css. Here you can either use the <div>'s id (if specified), or the class name, which is required (include the _ctxstxt_ prefix).



We can test by browsing to our custom.html file.



Let's not forget our footer ... add another custom <div>:



Then add the text:



... and then the CSS:



Browsing to our custom page:



Our final step is to create a responder policy and bind it to our AG vServer. This will automatically invoke our custom page when we browse to the AG vServer FQDN:

> add responder action "Logon Page Redirect Action" redirect "\"custom.html\"" -responseStatusCode 302
> add responder policy "Logon Page Redirect Policy" "HTTP.REQ.URL.PATH_AND_QUERY.CONTAINS(\"LogonPoint/index.html\")" "Logon Page Redirect Action"
> bind vpn vserver "AG vServer" -policy "Logon Page Redirect Policy" -priority 100 -gotoPriorityExpression END -type REQUEST
> save config

To remove the customizations, simply unbind the responder policy.

Here’s a handy cheat-sheet summarizing all of the above:


Original Themes
(Default, Green Bubble, X1)
Receiver for Web UI
(RfWebUI) Theme
Logon page directory
/netscaler/ns_gui/vpn/
/var/netscaler/logon/LogonPoint/
Updates to text strings
/var/netscaler/logon/themes/<theme>/
      resources/<language code>.xml
/var/netscaler/logon/themes/
      <theme>/strings/<language code>.json
String format
<String id=”key”>Value</String>    OR
<Property id="key"
      property="property">Value</Property>

“key” : “value”
Custom text based on
<div> ID
class name (existing keys are in /var/netscaler/
   logon/LogonPoint/receiver/js/localization/
   <language code>/ctxs.strings.js
CSS file
custom.css
theme.css


Thanks to the NetScaler development team for their help, and especially Bidyut H.

No comments:

Post a Comment