sebastiannielsen
Programmer
Im trying to make a CGI proxy, that will relay GET and POST to my firewall.
GET are working, even with a query string. I have tested it.
But POST are not working. When im trying to "POST", nothing are posted, the firewall dosent notice any changes. For example if i want to disable the SSH, the firewall leave it enabled after pressing "save". But firewall changes it if i do exactly the same thing but connect directly to firewall.
I have marked the lines where im think the problem is.
Here is my code:
GET are working, even with a query string. I have tested it.
But POST are not working. When im trying to "POST", nothing are posted, the firewall dosent notice any changes. For example if i want to disable the SSH, the firewall leave it enabled after pressing "save". But firewall changes it if i do exactly the same thing but connect directly to firewall.
I have marked the lines where im think the problem is.
Here is my code:
Code:
#!c:/perl/bin/perl.exe
use CGI ':standard';
use LWP::UserAgent;
my $ua = new LWP::UserAgent;
$ua->agent("IPCop Login client");
$dir = $ENV{'PATH_INFO'};
if ($dir =~ m/http/) {
print "Location: $dir\n\n";
}
else
{
if ($dir =~ m/^\//) {
$dir =~ s/^\///;
}
$adir = '[URL unfurl="true"]https://ipcop.localdomain:445/'.$dir;[/URL]
$ua->credentials(#Do you really think i will leave out my firewall password?);
$ua->timeout(30);
$met = $ENV{'REQUEST_METHOD'};
$req = HTTP::Request->new();
$req->method($met);
$req->header("Host", "ipcop.localdomain");
###### POSSIBLY PROBLEM SECTION ######
$len = int($ENV{'CONTENT_LENGTH'});
if ($met eq "POST") {
read(STDIN,$buffer,$len);
} else {
$buffer = $ENV{'QUERY_STRING'};
}
if ($buffer) {
if ($met eq "POST") {
$req->content($buffer);
}
else
{
$adir = $adir."?".$buffer;
}
}
$req->url($adir);
###### END OF SECTION ######
my $res = $ua->request($req);
my $headers = $res->headers_as_string."\n";
my $body = $res->content;
if ($res->is_success) {
$body =~ s/url[(]/xxc(/gi;
$body =~ s/action=/boolsend=/gi;
$body =~ s/src=/abcget=/gi;
$body =~ s/href=/linkget=/gi;
$body =~ s/xxc[(]([^()]+)*[)]/url(http:\/\/[URL unfurl="true"]www.sebpage.no-ip.com\/login.cgi\/$1)/gi;[/URL]
$body =~ s/boolsend=[ '"]*([^ '"]+)*[ '"]*/action=http:\/\/[URL unfurl="true"]www.sebpage.no-ip.com\/login.cgi\/$1[/URL] /gi;
$body =~ s/abcget=[ '"]*([^ '"]+)*[ '"]*/src=http:\/\/[URL unfurl="true"]www.sebpage.no-ip.com\/login.cgi\/$1[/URL] /gi;
$body =~ s/linkget=[ '"]*([^ '"]+)*[ '"]*/href=http:\/\/[URL unfurl="true"]www.sebpage.no-ip.com\/login.cgi\/$1[/URL] /gi;
print $headers.$body;
}
else
{
$headers =~ s/Location:[ ]?(.+)*\n/Location: http:\/\/[URL unfurl="true"]www.sebpage.no-ip.com\/login.cgi\/$1\n/gi;[/URL]
print $headers.$body;
}
}