Rad2f5 TMSH
Rad2f5 TMSH
/usr/bin/perl"
#
#
#
# Script to convert radware command line configuration files to F5 Big-ip.
#
# Written by: John Alam
# January-07.
#
# Modified/Updated:
# June-2010
#
# Usage: perl rad2f5 radwareconfigfile >bigip.conf
# Where the radwareconfigfile is the filename
# of the radware configuration which must be in command line format. BER
# format will not work. To get command line config execute the following
# command on radware "sys config immediate".
#
# This script sends output to stdout. To capture output, direct the stdout
# to a file like this. perl rad2f5 radwareconfigfile >F5-configfile
#
#
#This script only converts WSD text file. It does not convert ".ber" files. We
may add AppDirector support at some point.
#Here is an explanation of the different file from one of our radware experts
"Harry Kleinbourg":
$LBmethods{"Cyclic"}="Round Robin";
$LBmethods{"Least Amount of Traffic"}="least conn";
$LBmethods{"Weighted Cyclic"}="Ratio";
$LBmethods{"Response Time"}="Fastest";
$LBmethods{"Fewest Number of Users"}="least conn";
@pool_list=();
@virt_list=();
@pools=();
@pool_ports=();
@pool_names=();
@virtuals=();
@routes=();
$policy_count=0;
$virt_count=0;
$pool_count=0;
$policy_count=0;
$line="";
while (<inhndl>) {
$line = $line.$_;
if ($line=~/.*\\/ ) {
chop($line);
chop($line);
#chop($line);
next;
}
$pool_count++;
# $pool_index=~s/\./_/g;
# $pool_index="pool_".$pool_index;
@pool_list[$pool_count] = $pool_index ;
$pool_ports{$pool_index}[0] = $pool_port ;
# $virt_count++;
$virt_name=~s/\./_/g;
$virt_name="VS_".$virt_name;
# @virt_list[$virt_count] = $virt_name ;
if ($line =~ m/-n (\S+)/i ) {
$pool_names{$pool_index}[0] = $1 ;
$pl_name = $1;
} else {
$pl_name = $pool_index;
}
$line="";
next;
}
# $pool_index=~s/\./_/g;
# $pool_index="pool_".$pool_index;
given ($expression_qualifier) {
when "File Type" {
$expressions{$expression_name}='[http::uri] ends_with "'.
$qualifier_value.'" ';
}
when "Regular Expression" {
$expressions{$expression_name}='[http::uri] matches_regex
"'.$4.'" ';
}
when '"Cookie"' {
$expressions{$expression_name}='[http::cookie] $4 contains
$5';
}
when '"Header Field"' {
$expressions{$expression_name}='[http::header] $4 equals
$5';
}
when '"URL"' {
$expressions{$expression_name}='[HTTP::host] equals $4 and
[HTTP:URI] equals $5' }
}
$line="";
next;
}
$pol_name=$1;
$pol_expression=$3;
if ($pol_name ne @policies[$policy_count]) {
$policy_count++;
@policies[$policy_count] = $pol_name ;
$pol_expr_count=0;
}
push @{ $pol_priority{$pol_name} }, $2 ;
$line="";
next;
}
$line="";
next;
}
# if ($line =~ m/[wsd,appdirector] l4-policy table (?:set)?create (\S+) (\S+)
(\S+) (\S+) (\S+) -fn (\S+)(?: -ta (\S+))?/i) {
# print $ine."\n";
# print "$1 - $2 - $3 - $4 - $5 - $6 - $7\n";
# }
if ($line =~ m/[wsd,appdirector] l4-policy table (?:set)?create (\S+) (\S+)
(\S+) (\S+) (\S+) -fn (\S+)(?: -ta (\S+))?/i ) {
$profiles=$2;
$virt_name=$5;
$virt_dest=$1.":".$3;
$pool_name=$6;
$protocol=$7;
$virt_name=~s/\./_/g;
$pool_name=~s/\./_/g;
# print "$line \n";
# print "->$virt_name - $6 - $1\n";
push @{ $virtuals{$virt_name} } , "ltm virtual $virt_name {";
push @{ $virtuals{$virt_name} } , " snat automap";
push @{ $virtuals{$virt_name} } , " destination $virt_dest";
if ($protocol =~ m/^HTTP/i) {
$profiles = $profiles." "."custom_HTTP" ;
push @{ $virtuals{$virt_name} } , " persist custom_cookie";
} else {
push @{ $virtuals{$virt_name} } , " persist source_addr";
}
push @{ $virtuals{$virt_name} } , " pool $pool_name";
push @{ $virtuals{$virt_name} } , " profiles { $profiles }";
$virt_count++;
@virt_list[$virt_count] = $virt_name ;
$line="";
next;
}
$virt_name=~s/\./_/g;
#$pool_name=~s/\./_/g;
push @{ $virtuals{$virt_name} } , "ltm virtual $pool_name {";
push @{ $virtuals{$virt_name} } , " # old Virtual name: $virt_name";
push @{ $virtuals{$virt_name} } , " snat automap";
push @{ $virtuals{$virt_name} } , " destination $virt_dest";
push @{ $virtuals{$virt_name} } , " persist custom_cookie";
push @{ $virtuals{$virt_name} } , " # Old Pool reference: $pl_ref";
push @{ $virtuals{$virt_name} } , " pool $pool_name";
push @{ $virtuals{$virt_name} } , " profiles { custom_HTTP }";
$virt_count++;
@virt_list[$virt_count] = $virt_name ;
$line="";
next;
}
$line="";
}
print "\n";
print "\n\n#************** Protocol profiles ********************\n\n";
print "ltm profile tcp custom_client_TCP { defaults-from tcp }\n";
print "ltm profile tcp custom_server_TCP { defaults-from tcp }\n";
print "\n";
print "\n\n#************** Persistence profiles ********************\n\n";
print "ltm persistence cookie custom_cookie { defaults-from cookie }\n";
print "ltm persistence cookie session_cookie_insert { \
defaults-from cookie \
timeout 0 \
expiration 1\
} ";
print "\n";
print "\n\n#************** Standard Redirect Irule******************\n\n";
print "ltm rule standard_HTTP_to_HTTPS_redirect {\n";
print "when HTTP_REQUEST {\n";
print "HTTP::redirect https://[HTTP::header host][HTTP::uri]\n}\n}\n";
print "\n\n";
print "\n";
# The "for" loops below sort each policy expressions in order of ascending
priority.
for ($i=1; $i<@policies; $i++) {
$pol_name=@policies[$i];
for $j ( 1 ..$#{ $pol_priority{$pol_name} } ) {
for $k ( 1 ..$#{ $pol_priority{$pol_name} } ) {
$tmp=$pol_priority{$pol_name}[$k];
$pol_priority{$pol_name}[$k]=$pol_priority{$pol_name}[$k-
1];
$pol_priority{$pol_name}[$k-1] = $tmp;
$tmp=$pol_expr{$pol_name}[$k];
$pol_expr{$pol_name}[$k]=$pol_expr{$pol_name}[$k-1];
$pol_expr{$pol_name}[$k-1] = $tmp;
$tmp=$pol_farm{$pol_name}[$k];
$pol_farm{$pol_name}[$k]=$pol_farm{$pol_name}[$k-1];
$pol_farm{$pol_name}[$k-1] = $tmp;
}
}
}
}