OpenScript

Reply
Occasional Contributor
Posts: 11
Registered: ‎10-31-2011

First-time Openscripter

I'm a noob. I need some help to get my first script done. I have a web site which contains 2 sets of contents, i.e. basic and advanced. If http requests come from "internal" subnet networks, give them the advanced contents. If they come from the rest of the world, send them the basic contents. Initially, I would assume my requirements could be achieved by using CSW policies. However, after talking with TAC, it turns out that it's not possible. They have recommended me to try OpenScript which is new to me which TAC also doesn't support it currently.

My internal networks are known variables. So I think I would need to define them in the BEGIN sub routine. However, I couldn't find any examples so that I can see the syntax. Is is something that can be done or not?

Occasional Contributor
Posts: 50
Registered: ‎12-14-2011

Re: First-time Openscripter

Welcome aboard to OpenScript world!

I'd like to suggest you to go through this OpenScript tutorial deck, http://community.brocade.com/docs/DOC-3198. You don't have to understand every slides. Foucs on the workflow of creating a script and layout of the script. If you're not familar with Perl, just skim through some Perl syntax in the slides.

Then, please, let me know your L7 switching requirements. I may be able to provide some code snippets for you!

Occasional Contributor
Posts: 11
Registered: ‎10-31-2011

Re: First-time Openscripter

Thanks for sharing the ppt. It would take me sometime to learn a new programming language. So please bear with me. I guess the best way for me to learn is to understand how things are put together. It's still a learning curve for me. My requirements are simple.

Check source IP

If in a subnet range;

   Direct the client to the page with advanced contents (e.g. https://mysite.com/advanced)

else;

  Direct the client to the page with basic contents (e.g. https://mysite.com/basic)

It would be greatly appreciated if you could share your code.

Occasional Contributor
Posts: 50
Registered: ‎12-14-2011

Re: First-time Openscripter

Please, refer to the following code. Note that I didn't test the code but it may provide a good idea how it works. I assumed that you want to redirect HTTP pages instead of to send a request to a real server directly.

use strict;

use OS_IP;
use OS_SLB;
use OS_HTTP_REQUEST;

my $subnet_1;
my $subnet_2;
my $url_1;
my $url_2;

sub BEGIN {
$subnet_1 = “10.1.”;
$subnet_2 = "10.2.";
$url_1 = "advanced";
$url_2 = "basic";
}

sub HTTP_REQUEST {
my $client_ip = OS_IP::src;

if (($client_ip =~ m/^$subnet_1/)) {
  OS_SLB::redirect("url"=>$advanced);
} elsif (($client_ip =~ m/^$subnet_2/)) {
  OS_SLB::redirect("url"=>$basic);
} else
  OS_SLB::reset;
}
}

Occasional Contributor
Posts: 11
Registered: ‎10-31-2011

Re: First-time Openscripter

I'm getting the following error messages when compile:

S_my_exit_jump being called

Compile Errors found :

  Bareword "OS_SLB::reset" not allowed while "strict subs" in use at -e line 27.

Execution aborted due to compilation errors.

Any idea?

UPDATE: the ppt (page 28) says: "* the strict option in the compilation CLI and Sub:StrictDecl require 12.4.00f or later"

Looks like I have to upgrade the code for my ADX (currently on ASR12400c)


UPDATE: OK I upgraded the code to ASR12400g and still getting the same error message above.

Highlighted
Occasional Contributor
Posts: 11
Registered: ‎10-31-2011

Re: First-time Openscripter

Derek,

I could finally compile it. However, I'm not getting hit at all. Here's my final script. Any idea as to why this script is not working?

use strict;

use Sub::StrictDecl;

use OS_IP;

use OS_SLB;

use OS_HTTP_REQUEST;

my $subnet_1;

my $subnet_2;

my $url_1;

my $url_2;

sub BEGIN {

$subnet_1 = "x.x.x.";

$subnet_2 = "y.y.y.";

$url_basic = "mysite.com/basic";

$url_advanced = "mysite.com/advanced";

}

sub HTTP_REQUEST {

my $client_ip = OS_IP::src;

if ($client_ip =~ m/^$subnet_1/) {

  OS_SLB::redirect("url"=>"$url_basic");

} elsif ($client_ip =~ m/^$subnet_2/) {

  OS_SLB::redirect("url"=>"$url_advanced");

}

Join the Community

Get quick and easy access to valuable resource designed to help you manage your Brocade Network.

Download FREE NVMe eBook