Here is my problem:
I have a CGI script that generates data. From this script, I want to call a second script, and pass it the data. That second script uses CGI.pm to access the posted data.
This works well, using LWP::UserAgent, building a request that includes a file and getting back the result:
sub upload { my( $data)= @_; my $ua = LWP::UserAgent->new; my $req= POST $SCRIPT_URL, Content_Type => 'form-data', Content => [ status => 'ok', uploaded_file => [ undef, # conte +nt provided below $basename, Content_Type = +> 'text/html', Content = +> $data ], ], ; # this might be wrong, the real code uses a callback to output the + results # as they come back from $SCRIPT my $result= $ua->request($req)->content; }
Now my problem is that both scripts are in protected areas, and are used by users whose passwords I do not know. So even if the above code works well on my test machine, I can't actually use it on the live server, because I cannot pass the credentials to the second script. And I cannot modify that script to bypass the authentication process.
The solution I have found, as both scripts are on the same machine, is to call directly the script, without going through the server. So I thought I would just set $ENV{REMOTE_USER}, build the same HTTP::Request as previously and pass the request content to the script. But none of this seems to work. The second script does not pick up the parameters, and the REMOTE_USER is not set.
Here is the code I have so far:
sub exe_script { my( $data)= @_; my $req= POST $SCRIPT, Content_Type => 'form-data', Content => [ status => 'ok', uploaded_file => [ undef, # cont +ent provided below 'whatever', Content_Type +=> 'text/html', Content +=> $data, ], ], ; open( my $script, "| $SCRIPT") or exit_status( Error => "cannot ca +ll script: $!"); my $user= remote_user(); $ENV{REMOTE_USER}= $user; my $content= $req->content; print {$script} $content; exit; }
Am I missing something obvious? Should I forget about HTTP::Request in this case, just RTFR (Read The Fine RFC) and build the request myself? And how can I get the REMOTE_USER variable set in $SCRIPT? Save the query in a file, set the environment variable and exec the script? That's my next experiment anyway.
Any help would be greatly appreciated
In reply to HTTP::Request to local script by mirod
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |