#!/usr/local/apache/htdocs/wappush/perl-5.6.0/bin/perl # # Send WAP Push Service Indication # # Ron Mandel # Openwave Developer Services # 3/18/02 # require HTTP::Request; require LWP::UserAgent; require HTTP::Headers; #use lib './'; use pushUtils; ### parse input string &parse_string; ### set auto-incrementing push number $id = &getid; ### create content to send to UPPushPAP &create_content($id); ### POST to the url $request = HTTP::Request->new(POST, $url, $headers, $content); $ua = LWP::UserAgent->new; ### get the response $response = $ua->request($request); ### push back some html &print_html($string, $content, $$response{_content}, $url); ###################################################################### # sub parse_string # - get info passed by HTTP POST and set it # in global variables ###################################################################### sub parse_string { # content length for string read $cl = $ENV{"CONTENT_LENGTH"}; # get string if (defined $ENV{QUERY_STRING} && $ENV{QUERY_STRING} ne "" ) { $string = $ENV{QUERY_STRING}; } else { read(STDIN, $string, $cl); } # cut string into components @string = split(/&/,$string); foreach $i (0 .. $#string) { $string[$i] =~ s/\+/ /g; $string[$i] =~ s/%(..)/pack("c",hex($1))/ge; ($name, $value) = split(/=/,$string[$i],2); $string{$name} = $value; } #print FILE "String\n$string\n\n\n"; #separate string hash into usable variables (global) $ppgaddr = $string{ppg}; $url = 'http://'.$ppgaddr.':9002/pap'; $subscriber = $string{subscriber}; $url_to_push = $string{url_to_push}; $message = $string{message}; $delivery_method = 'unconfirmed'; $bearer = 'SMS'; $bearer_required = 'true'; $content_severity = 'high'; } # end parse_string ###################################################################### # sub getid # - get the next sequence number for push ###################################################################### sub getid { my $id, $newid; # get push id from file open(ID,"/tmp/pushid"); while () { chomp; $id = $_; } close ID; # set value to 1 if no .pushid file if (!defined $id) { $id = 5 }; # set id=1 if no .pushid file # write next pushid open (ID, ">/tmp/pushid"); $newid = $id; $newid += 1; print ID "$newid\n"; # return value return "testpush-".$id; } # end sub getid ###################################################################### # sub print_html ###################################################################### sub print_html { my $string = shift; my $content = shift; my $response = shift; my $url = shift; # make it suitable for viewing in html by substituting for <, >, \n, \s $content =~ s//>\;/g; $content =~ s/\n/
/g; $content =~ s/\s{2,}?/ \;/g; $response =~ s//>\;/g; $response =~ s/\n/
/g; $response =~ s/\s{2,}?/ \;/g; # print out html print "Content-type: text/html\n\n"; print' WAP Push Response from PPG at '.$ppg.'<title> </head> <body> <p> <h1 align="center">WAP Push Results</h1> <hr> <h3>Content sent to'. $url.'</h3> <h3>Content Generated</h3> '. $content.' <br> <h3>Response Received</h3> '.$response.'</p> </body> </html>'; } # end print_html ###################################################################### # sub create_content # - create XML content to pass to PPG ###################################################################### sub create_content { my $id = shift; ### create HTTP headers $headers = new HTTP::Headers Content_Type => 'multipart/related; boundary=asdlfkjiurwghasf; type="application/xml"\;'; # add the boundary $content = '--asdlfkjiurwghasf'; $id = &getid; ### create control entity $content .= pushUtils->createControl('PushTest', $ppgaddr, $id, 'false', $subscriber, 'USER', $delivery_method, $bearer, $bearer_required); ### add boundary for multipart $content .= '--asdlfkjiurwghasf'; ### add content entity $content .= pushUtils->createContentSI($url_to_push, $content_severity, $message); } # end create_content