I am trying to build a Web Page and struggle to forward some data into a Perl Script in order to PUSH content to a Destination.
I have a HTML Page:
- Code: Select all
<html>
<head>
<title>Polycom Text Push</title>
</head>
<body>
<form method="post" action="http://10.222.22.221/cgi-bin/test.pl">
<h2>Enter the details of the Phone you would like below content being pushed to?</h2>
Realm: <input type="text" name="realm" value="PUSH Authentication"><br>
Username: <input type="text" name="user" value="steff"><br>
Password: <input type="text" name="pw" value="ge1c0"><br>
IP Address: <input type="text" name="ip"><br>
Text: <input type="text" name="reluri" value="Hello!" ><br>
Importance: <input type="text" name="priority" value="critical" ><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
Above calls the test.pl Perl Script below:
- Code: Select all
#!c:/xampplite/perl/bin/perl.exe
print "Content-type: text/html\n\n";
# *** Perl distribution libwww-perl is REQUIRED ***
#
&getFormData;
print "<h2>Here are all the Details that need submitting:</h2>";
print "<br>\n";
print "Realm: $request{'realm'}";
print "<br>\n";
print "Username: $request{'user'}";
print "<br>\n";
print "Password: $request{'pw'}";
print "<br>\n";
print "IP Address: $request{'ip'}";
print "<br>\n";
print "Text: $request{'reluri'}";
print "<br>\n";
print "Importance: $request{'priority'}";
print "<br>\n";
print "\n\n";
my $phoneuri = 'http://'.$request{'ip'}.'/push';
my $httpcontent = '<PolycomIPPhone><URL';
if ($priority) {
$httpcontent = $request{'reluri'}.' priority="'.$request{'priority'}.'"';
}
$httpcontent = $httpcontent.'>'.$request{'reluri'}."</URL></PolycomIPPhone>\n";
print "<br>\n";
print "Push Content:\n".$httpcontent."\n";
print "<br>\n";
print "\nSending POST to ", $phoneuri, "\n";
require LWP::UserAgent;
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
$ua->credentials($request{'ip'}.':80', $request{'realm'}, $request{'user'}, $request{'pw'});
exit;
# Subroutine below this line.
sub getFormData {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/\n/ /g;
$request{$name} = $value;
}
}
All I would like to do is for this script to push the following to the specified IP Addess:
- Code: Select all
<PolycomIPPhone><Data priority="critical">Hello!</Data></PolycomIPPhone>
Above Perl Script results in a new Web Page with this:
- Code: Select all
Here are all the Details that need submitting:
Realm: PUSH Authentication
Username: steff
Password: ge1c0
IP Address: 10.222.22.222
Text: Hello!
Importance: critical
Push Content: Hello!
Sending POST to http://10.222.22.222/push
The Push Content is just the Data from reluri but the below command line Perl Script combines the priority and the reluri:
- Code: Select all
#!C:/xampplite/perl/bin/perl.exe
use strict;
use warnings;
# *** Perl distribution libwww-perl is REQUIRED ***
require LWP::UserAgent;
if (scalar @ARGV < 5) {
print "\nSends an authenticated POST request, containing a URI to fetch, to an IP phone.\n\n";
print "Usage:\n";
print "digest-uripush-ua.pl <auth_realm> <auth_user> <auth_pw> <phone_ip> <relative_uri> [<priority>]\n";
print "\n";
print "e.g. digest-uripush-ua.pl \"PUSH Authentication\" JoeUser MyPassword 172.24.44.135 apps/apptest.plcm critical\n";
print " Sends a POST to 172.24.44.135 with content <URI priority=\"critical\">apps/apptest.plcm</URI>\n\n";
exit;
}
my $realm = $ARGV[0];
my $user = $ARGV[1];
my $pw = $ARGV[2];
my $phoneip = $ARGV[3];
my $reluri = $ARGV[4];
my $priority = 0;
if (defined $ARGV[5]) {
$priority = $ARGV[5];
}
print "\nAuthentication Realm: ", $realm;
print "\nAuthentication Username: ", $user;
print "\nAuthentication Password: ", $pw;
print "\nTarget Phone IP: ", $phoneip;
print "\nPush URI: ", $reluri;
print "\nPriority: ";
if ($priority) {
print $priority;
} else {
print '<default>';
}
print "\n\n";
my $phoneuri = 'http://'.$phoneip.'/push';
my $httpcontent = '<PolycomIPPhone><URL';
if ($priority) {
$httpcontent = $httpcontent.' priority="'.$priority.'"';
}
$httpcontent = $httpcontent.'>'.$reluri."</URL></PolycomIPPhone>\n";
print "Push Content:\n".$httpcontent."\n";
print "\nSending POST to ", $phoneuri, "\n";
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
$ua->credentials($phoneip.':80', $realm, $user, $pw);
my $response = $ua->post($phoneuri, Content => $httpcontent);
print "- Response from host: ------------------------------------\n";
print $response->as_string;
print "----------------------------------------------------------\n";
exit;
Any Hints ..?
As above Command Line Example works ...