Sie sind auf Seite 1von 8

#!

/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":

#For some years, wsd has been replaced by AppDirector product.


#WSD config files could be saved in a specific format .ber. Then with an external
tool, the ber file could be transform into an ascii file.
#Now, with AppDirector, there's only one format which is a text file.
#The system config-immediate isn't a config file. It's a command which shows the
running config but it doesn't replace the config file.
#An easy way to check if you have a wsd or an appdirector is to run the command
system device-info or to look into the system config-immediate : if the lines begin
with "wsd" then it is a wsd, if the lines begin with appdirector then it's an
appdirector. Obvious, isn't it ?

if ($#ARGV < 0) { print "Usage: perl rad2f5 radwareconfigfile "; exit };

use Switch 'Perl6';


open (inhndl, "<$ARGV[0]") or die "can't read file $ARGV[0].";
open (exceptions, ">exceptions") or die "can't open exceptions file.";

print "############ Please check the exceptions file. #################\n\n";

$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;
}

if ($line =~ /net route table create (\S+) (\S+) (\S+)/i) {


if ( $1 == '0.0.0.0' ) {
push @{ $routes{"$1$2"} }, "route default inet { gateway $3 }";
} else {
push @{ $routes{"$1$2"} }, "route $1 mask $2 { gateway $3 }";
}
$line="";
next;
}

if ($line =~ m/[wsd,appdirector] farm connectivity-check (\S+) (?:set)?create


(\S+) (.*)/i) {
if ( $1 eq "httpcode" ) {
# print "$1 - $2 - $3 - $pools{$2}[3]\n";
$pools{$2}[2] = " monitor all my_HTTP";
}
}

if ($line =~ m/[wsd,appdirector] farm table (?:set)?create (\S+).*/i) {


# print "->$line\n-->$1\n";
$pool_index=$1;
if ($line =~ m/-cp (\S+)/i) { $pool_port = $1 } else
{ $pool_port = "80";
print exceptions "Farm table $pool_index
assumed to have port 80.\n";
}
if ($line =~ m/-as (\S+)/i) { $pool_status = $1 }
if ($line =~ m/-dm "(\D+)"/i) { $1=~/(.*)" /; $lb_method =
$LBmethods{$1} } else { $lb_method = "round robin" }
$virt_dest=$pool_name.":".$pool_port;

$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;
}

push @{ $pools{$pool_index} } , "ltm pool $pl_name \{";


#push @{ $pools{$pool_index} } , " #old pool name $pool_index";

push @{ $pools{$pool_index} } , " lb method $lb_method";


push @{ $pools{$pool_index} } , " monitor all tcp";

# push @{ $virtuals{$virt_name} } , "virtual $virt_name {";


# push @{ $virtuals{$virt_name} } , " destination $virt_dest";
# push @{ $virtuals{$virt_name} } , " pool $pool_index";

$line="";
next;
}

if ($line =~ m/[wsd,appdirector] farm server table (?:set)?create (\S+)


(\S+)/i) {
$pool_index = $1;
$member_IP = $2;

# $pool_index=~s/\./_/g;
# $pool_index="pool_".$pool_index;

#if ($line =~ m/-mp (\S+)/i) { $member_port = $1 } else


# { $member_port = "HTTP";
# print exceptions "Farm serrver $member_IP
assumed to have port HTTP.\n";
#}
$member_port = $pool_ports{$pool_index}[0];

push @{ $pools{$pool_index} } , " members { $member_IP".":".


$member_port." { address ".$member_IP." }}" ;
$line="";
next;
}

if ($line =~ m/[wsd,appdirector] L7 farm-selection method-table (?:set)?


create (\S+) +-cm +"(.*)" +-ma +(.*)=(.*)(?:|...=(.*)?)?/i) {
$expression_name=$1;
$expression_qualifier=$2;
$qualifier_value=$4;

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;
}

if ($line =~ m/[wsd,appdirector] L7 farm-selection policy-table (?:set)?


create (\S+) ([0-9]+) -m1 (\S+)(?: -m2 (\S+)?)? -pa +(\S+)=(\S+) -f (\S+)/i) {

$pol_name=$1;
$pol_expression=$3;
if ($pol_name ne @policies[$policy_count]) {
$policy_count++;
@policies[$policy_count] = $pol_name ;
$pol_expr_count=0;
}

#print "\n $policy_count ".@pol_priority[$pol_name]."- $pol_name $1\n";

push @{ $pol_priority{$pol_name} }, $2 ;

if ($4 eq "") {push @{ $pol_expr{$pol_name} }, $expressions{$3}} else


{push @{ $pol_expr{$pol_name} }, $expressions{$3} ." and ".
$expressions{$4}
}

push @{ $pol_farm{$pol_name} }, $7;

$line="";
next;
}

if ($line =~ m/[wsd,appdirector] super-farm (?:set)?create (\S+) (\S+) (\S+)


"(.*)" -po (.*)/i ) {
$pool_name="pool_".$4;
$virt_name=~s/\./_/g;
$pool_name=~s/\./_/g;
push @{ $virtuals{$virt_name} } , "ltm virtual $virt_name {";
push @{ $virtuals{$virt_name} } , " snat automap";
push @{ $virtuals{$virt_name} } , " destination $virt_name";
push @{ $virtuals{$virt_name} } , " persist custom_cookie";
push @{ $virtuals{$virt_name} } , " rule $5";
push @{ $virtuals{$virt_name} } , " profiles { custom_HTTP }";
$virt_count++;
@virt_list[$virt_count] = $virt_name ;

$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;
}

if ($line =~ m/[wsd,appdirector] super-farm (?:set)?create (\S+) ([0-9]+)


(\S+) (\S+)/i ) {
$virt_dest=$1.":".$2;
$virt_name="vs_".$1."_".$2;
#$pool_name="pool_".$4;
$pl_ref=$4;
$pool_name=$pool_names{$4}[0];

$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 "ltm persistence my_source_addr { defaults-from source-addr timeout 240 }\n";

print "\n\n#************** Protocol profiles ********************\n\n";


print "ltm profile http custom_HTTP { defaults-from http }\n";

print "ltm profile client-ssl custom_client_ssl { defaults-from client-ssl }\n";


print "ltm profile server-ssl custom_server_ssl { defaults-from serverssl-insecure-
compatible }\n";

print "ltm profile stream stream_profile_http_to_https_rewrite {\n source


http://\n target https:// \n}\n";

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#************** Routes ***********************************\n\n";

foreach $key (keys %routes)


{
print "$routes{$key}[0]\n";
}

print "\n\n";

print "\n\n#************** Pools ***********************************\n\n";

for ($i=1; $i<@pool_list; $i++) {


$index=@pool_list[$i];
for $j ( 0 ..$#{ $pools{$index} } ) {
print $pools{$index}[$j]."\n";
}
print "\}\n";
}

print "\n\n#************** Virtuals ***********************************\n\n";

for ($i=1; $i<@virt_list; $i++) {


$index=@virt_list[$i];
for $j ( 0 ..$#{ $virtuals{$index} } ) {
print $virtuals{$index}[$j]."\n";
}
print "\}\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} } ) {

if ($pol_priority{$pol_name}[$k] < $pol_priority{$pol_name}[$k-


1]) {

$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;
}
}
}
}

for ($i=1; $i<@policies; $i++) {


$index=@policies[$i];
print "\n#\n";
print "# Policy # $i: $index. \n";
print "#\n";
print "ltm rule $index {\nwhen HTTP_REQUEST {\n";
print " if {" ;
for $j ( 0 ..$#{ $pol_priority{$index} } ) {
print " ".$pol_expr{$index}[$j]." } {\n";
print " node ".$pol_farm{$index}[$j]." }";
if (defined $pol_farm{$index}[$j+1]) { print " \n elseif {"}
}
print "\n}\n}\n\n";
}

Das könnte Ihnen auch gefallen