#!/usr/bin/perl -wT # -*- 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 lib '/home/ianh/lib/perl'; use Net::SMTP; use RPC::XML; use RPC::XML::Parser; use URI::Escape; my $smtp = 'mail.dummy-blog.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 # pass it on to the real server my $mail = Net::SMTP->new($smtp, 'Timeout' => 5); $mail->mail($from); $mail->to($to); $mail->data(<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; }