Citrix Blogs

Creating policies greater than 255 characters

AppExpert policies allow you to invoke powerful Layer 7 manipulations.   But  lengthy policies will result in an error:

ERROR: String length exceeds maximum. Allowed maximum length is 255 bytes.

To overcome this input limitation, you can insert a “+” separator sequence every 255 characters.   And when it comes to really long text strings, which make it more difficult to accurately locate the many break points, you can easily automate the process using the shell and a simple Perl substitution.

Example #1

In this example, I’ll take a lengthy input string a add the separator sequence at the proper interval.   In this case, the interval has been reduced from 255 to 10 for illustration purposes:

> shell
# echo 'the long string you need to separate enclosed in single quotes' | perl -p -e 's/(.{10})/$1"+"/g'
the long s"+"tring you "+"need to se"+"parate enc"+"losed in s"+"ingle quot"+"es

Working with HTML:

In the next example, I’m going to leverage the Responder module to return a HTML page with some dynamic data from AppExpert policies; which I’ll embed into the page at a later time.  For the base page, I’ll use the following HTML template, which is 285 characters:

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd”>
<html lang=”en”>
<head>
<meta http-equiv=”content-type” content=”text/html; charset=utf-8″>
<title>Title Goes Here</title>
</head>
<body>
<p>This is my web page</p>
</body>
</html>

But unless the double quotation marks in the HTML code are escaped with a backslash character, you’ll get following syntax error message:

ERROR: Expression syntax error

Fortunately, I can leverage the same procedure to escape the quotes and insert the separators by using an additional Perl substitution first:

| perl -p -e 's/["]/\\"/g' | perl -p -e 's/(.{255})/$1"+"/g'
Example #2:
&gt; shell

# echo '&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;&lt;html lang="en"&gt;&lt;head&gt;&lt;meta http-equiv="content-type" content="text/html; charset=utf-8″&gt;&lt;title&gt;Title Goes Here&lt;/title&gt;&lt;/head&gt;&lt;body&gt;&lt;p&gt;This is my web page&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;' | perl -p -e 's/["]/\\"/g' | perl -p -e 's/(.{255})/$1"+"/g'

&lt;!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\"&gt;&lt;html lang=\"en\"&gt;&lt;head&gt;&lt;meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\"&gt;&lt;title&gt;Title Goes Here&lt;/title&gt;&lt;/head&gt;&lt;body&gt;&lt;p&gt;This is "+"my web page&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;

#

exit

&gt; add responder action test respondwith q{"&lt;!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\"&gt;&lt;html lang=\"en\"&gt;&lt;head&gt;&lt;meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\"&gt;&lt;title&gt;Title Goes Here&lt;/title&gt;&lt;/head&gt;&lt;body&gt;&lt;p&gt;This is "+"my web page&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;"} -bypassSafetyCheck YES

Done

References:

How to Configure a Maintenance Web Page by using the Responder Feature of the NetScaler Appliance

Serve Rich HTML Error Pages from NetScaler

Import a specified HTML page to the NetScaler appliance

Exit mobile version