An introduction to TrafficScript

TrafficScript is the programming language that is built into the ZXTM traffic manager. With TrafficScript, you can create traffic management 'rules' to control the behaviour of ZXTM in a wide manner of ways, inspecting, modifying and routing any type of TCP or UDP traffic.

The language is a simple, procedural one - the style and syntax will be familiar to anyone who has used Perl, PHP, C, BASIC, etc. Its strength comes from the large number of built-in tools (functions) that let you perform complex tasks simply, such as controlling traffic flow, reading and parsing HTTP requests and responses, and managing XML data. These functions make it easy for you to write application-specific rules without having to consider the details of the underlying protocols.

Sample usage

Imagine that you've rebuilt your website, and the old content in the /secure part of the site has been moved to a different site. However, many users are still trying to access the old content.

The following TrafficScript rule will fix the problem for you:

$url = http.getPath();
if( string.startsWith( $url, "/secure" ) ) {
   $newurl = "https://secure.mysite.com".$url;

   http.sendResponse( "302 Redirect", 
      "", "", "Location: ".$newurl );
}

Alternatively, perhaps you need to fix up parts of your website but haven't got the time or resources to modify thousands of web pages. For example, after January 1st you'll have needed to change all the 'Copyright 2004' messages to 'Copyright 2005':

$year = sys.time.year();
if( http.getResponseHeader( "content-type" ) == "text/html" ) ) {
   $response = http.getBody();

   # replace all 'Copyright 2000' - 'Copyright 2009' messages
   $newresponse = string.regexsub( $response, 
      "Copyright 200[0-9]", "Copyright ".$year, "g" );

   http.setResponseBody( $newresponse );
}
Owen Garrett [Zeus Dev Team] 01 July 2005  Permalink  
Leave a comment ...
Your email address will not be displayed.
Your URL will be displayed.
This public messageboard is not a forum for technical support. To report technical support problems, please contact our dedicated Support team using the instructions at the bottom of this page.
Options:
 
(Line breaks become <br />)
(Set cookies for name, email & url)
Download Free ZXTM Desktop Edition

Recent Articles

Other Resources



www.zeus.com