Technical data
Table Of Contents

ServerIron ADX OpenScript Guide 23
53-1002445-01
Chapter
4
Script Example
Overview
The following sections of this chapter describe the entire process of writing a script, copying it to
the ServerIron ADX and binding it to a virtual server port
Use case
This script is created in this example is designed to perform the following action on any SSL or HTTP
traffic:
• It there is no X-Forwarded-For header, an X-forwarded-For header is added with the client
source IP address: e.g. 4.4.4.4
• If a X-Forwarded-For header exists, the source IP address 4.4.4.4 is appended. For example,
existing X-forwarded-For address: 1.1.1.1, 2.2.2.2, 3.3.3.3 + appended source address:
4.4.4.4, results in new source address: 1.1.1.1, 2.2.2.2, 3.3.3.3, 4.4.4.4.
Script for use case
The following script implements the example described in “Use case”.
Example 1:
use OS_HTTP_REQUEST;
use OS_IP;
use OS_SLB;
BEGIN {
$group1 = 10;
}
sub HTTP_REQUEST{
$x_forward = OS_HTTP_REQUEST::header("X-Forwarded-For");
$src_addr = OS_IP::src;
if( defined $x_forward){
$x_forward = $x_forward.", ".$src_addr;
OS_HTTP_REQUEST::header("X-Forwarded-For", $x_forward);
}else{
OS_HTTP_REQUEST::push_header("X-Forwarded-For", $src_addr);
}
OS_SLB::forward($group1);
}










