#!/usr/bin/perl # -*- Mode: perl; tab-width: 4; indent-tabs-mode: nil; -*- # # Pingback Proxy: XML-RPC POST to e-mail # # Copyright (c) 2002 by Ian Hickson # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA use strict; #use diagnostics; #use Net::SMTP; use LWP::UserAgent; use RPC::XML; use RPC::XML::Parser; #use URI::Escape; #my $smtp = 'mail.thelackthereof.org'; # change this to your smtp server if ($ENV{'REQUEST_METHOD'} ne 'POST') { result('405 Method Not Allowed', -32300, 'Only XML-RPC POST requests recognised.', 'Allow: POST'); } if ($ENV{'CONTENT_TYPE'} ne 'text/xml') { result('415 Unsupported Media Type', -32300, 'Only XML-RPC POST requests recognised.'); } if (not defined($ENV{'PATH_INFO'})) { result('400 Bad Request', -32300, 'Missing from and to e-mail addresses (see README).'); } # get the data if (not $ENV{'PATH_INFO'} =~ m/^\/([^;]+);([^;]+)/gos) { # from, to result('400 Bad Request', -32300, 'Missing from and to e-mail addresses (see README).'); } my $from = $1; my $to = $2; local $/ = undef; my $input = ; # parse it my $parser = RPC::XML::Parser->new(); my $request = $parser->parse($input); if (not ref($request)) { result('400 Bad Request', -32700, $request); } # handle it my $name = $request->name; my $arguments = $request->args; if ($name ne 'pingback.ping') { result('501 Not Implemented', -32601, "Method $name not supported"); } if (@$arguments != 2) { result('400 Bad Request', -32602, "Wrong number of arguments (arguments must be in the form 'from', 'to')"); } my $source = $arguments->[0]->value; my $target = $arguments->[1]->value; # Store the data about the user triggering this e-mail # XXX =cut # pass it on to the real server my $mail = Net::SMTP->new($smtp, 'Timeout' => 5); $mail->mail($from); $mail->to($to); $mail->data(<quit(); =cut open(OUT,">>/home/awwaiid/tmp/pingback.txt"); print OUT <<"EOF"; From: $from To: $to Subject: Pingback $source to $target Hi, I just got notified of a pingback from: $source ...linking to: $target HTH, -- Pingback File Proxy -------------------------------------- EOF my $ua = LWP::UserAgent->new; $ua->agent("WikiPingBack/0.1 "); my $page = 'Home'; if($target =~ /wiki.pl\/(.+)/) { $page = $1; } # Create a request my $req = HTTP::Request->new(POST => 'http://thelackthereof.org/wiki.pl'); $req->content_type('application/x-www-form-urlencoded'); $req->content("title=Comments_on_$page&summary=new%20comment&aftertext=Pingback:%20$source&save=save&username=pingback"); my $res = $ua->request($req); my $out = ''; # Check the outcome of the response if ($res->is_success) { $out = $res->content; } else { $out = $res->status_line, "\n"; } result('200 OK', 0, "OK"); # result('200 OK', 0, "$out"); #result('200 OK', 0, "E-mail sent to $to"); sub result { my($status, $error, $data, $extra) = @_; my $response; if ($error) { $response = RPC::XML::response->new(RPC::XML::fault->new($error, $data)); } else { $response = RPC::XML::response->new(RPC::XML::string->new($data)); } print "Status: $status\n"; if (defined($extra)) { print "$extra\n"; } print "Content-Type: text/xml\n\n"; print $response->as_string; exit; }