Commits

Toby Inkster committed d65d5ce

updates

Comments (0)

Files changed (4)

http-mbox.php

-<?php
-
-// Destination mailbox - you need to change this.
-$__to = 'alice@example.net';
-
-// Gateway mailbox - set to NULL if you want to force people to include
-// a From header with their POSTs.
-$__from = 'http-mbox-gateway@example.net';
-
-
-#############################################
-### No need to change anything below here ###
-#############################################
-
-if ($_SERVER['REQUEST_METHOD'] != 'POST')
-{
-	header("HTTP/1.1 405 Forbidden");
-	header("Content-Type: text/plain");
-	print "Please use HTTP POST.\r\n";
-	exit;
-}
-
-// Get raw POST data.
-$data = file_get_contents('php://input');
-$type = $_SERVER['CONTENT_TYPE'];
-
-// PHP doesn't allow access to raw data if type if multipart/form-data.
-// Fake it.
-if ($type == 'multipart/form-data')
-{
-	$data = json_encode($_POST);
-	$type = 'application/json';
-}
-
-$from = isset($_SERVER['HTTP_FROM']) ? $_SERVER['HTTP_FROM'] : $__from;
-if (!$from)
-{
-	header("HTTP/1.1 403 Forbidden");
-	header("Content-Type: text/plain");
-	print "Please include a From header in your HTTP POST.\r\n";
-	exit;
-}
-
-$messageid = "<http-mbox-gateway." . md5(uniqid(microtime())) . "@" . $_SERVER['SERVER_ADDR'] . ">";
-
-$subject = isset($_SERVER['HTTP_SUBJECT']) ?
-	$_SERVER['HTTP_SUBJECT'] :
-	('Communication from '.$_SERVER['REMOTE_ADDR']);
-
-$headers = "From: $from\r\n"
-	. "Content-Type: $type\r\n"
-	. "Message-ID: $messageid\r\n"
-	. "Received: from [${_SERVER['REMOTE_ADDR']}] by [${_SERVER['SERVER_ADDR']}] via HTTP; ".date('r')."\r\n";
-
-if (!empty($_SERVER['HTTP_USER_AGENT']))
-	$headers .= "X-Mailer: ".preg_replace('/[\t\r\n]/', ' ', $_SERVER['HTTP_USER_AGENT']);
-
-if( @mail($__to, $subject, $data, $headers) )
-{
-	header("Content-Type: text/plain");
-	print $messageid . "\r\n";
-	exit;
-}
-else
-{
-	header("HTTP/1.1 400 Error Sending Message");
-	header("Content-Type: text/plain");
-	print "Please try again later.\r\n";
-	exit;
-}
-

inc_http-mbox-gateway.php

+<?php
+
+// Only accept POSTed data.
+if ($_SERVER['REQUEST_METHOD'] != 'POST')
+{
+	header("HTTP/1.1 405 Forbidden");
+	header("Content-Type: text/plain");
+	print "Please use HTTP POST.\r\n";
+	exit;
+}
+
+// Get raw POST data.
+$data = file_get_contents('php://input');
+$type = $_SERVER['CONTENT_TYPE'];
+
+// PHP doesn't allow access to raw data if type if multipart/form-data.
+// Fake it.
+if ($type == 'multipart/form-data')
+{
+	if (function_exists('json_encode'))
+	{
+		$data = json_encode($_POST);
+		$type = 'application/json';
+	}
+	else
+	{
+		$data = print_r($_POST, true);
+		$type = 'text/plain';
+	}
+}
+
+if ($__webid)
+{
+	$descriptorspec = array(
+		0 => array("pipe", "r"),  // stdin is a pipe that the child will read from
+		1 => array("pipe", "w"),  // stdout is a pipe that the child will write to
+		2 => array("pipe", "w")   // stderr 
+	);
+	$proc = proc_open('./webid.pl', $descriptorspec, $pipes, null, null);
+	if (is_resource($proc))
+	{
+		fwrite($pipes[0], $_SERVER['SSL_CLIENT_CERT']);
+		fclose($pipes[0]);
+		list($_SERVER['WEBID'], $_SERVER['WEBID_NAME'], $_SERVER['WEBID_MAIL']) = explode("\n", stream_get_contents($pipes[1]));
+		fclose($pipes[1]);
+		fclose($pipes[2]);
+		proc_close($proc);
+	}
+}
+
+if ($__webid === 'force' && !$_SERVER['WEBID'])
+{
+	header("HTTP/1.1 403 Forbidden");
+	header("Content-Type: text/plain");
+	print "Please authenticate using WebID.\r\n";
+	exit;
+}
+
+// Process HTTP "From" header.
+$from = $__from;
+if ($_SERVER['SSL_CLIENT_S_DN_Email'])
+	$from = $_SERVER['SSL_CLIENT_S_DN_Email'];
+if ($_SERVER['WEBID_MBOX'])
+	$from = preg_replace('/^mailto:/i', '', $_SERVER['WEBID_MBOX']);
+if ($_SERVER['HTTP_FROM'])
+	$from = $_SERVER['HTTP_FROM'];
+if (!$from)
+{
+	header("HTTP/1.1 403 Forbidden");
+	header("Content-Type: text/plain");
+	print "Please include a From header in your HTTP POST.\r\n";
+	exit;
+}
+
+// Process HTTP "Subject" header - not an official RFC 2616 header.
+$subject = isset($_SERVER['HTTP_SUBJECT']) ?
+	$_SERVER['HTTP_SUBJECT'] :
+	('Communication from '.$_SERVER['REMOTE_ADDR']);
+
+// Generate a Message-ID.
+$messageid = "<http-mbox-gateway." . md5(uniqid(microtime())) . "@" . $_SERVER['SERVER_ADDR'] . ">";
+
+// Assemble message headers.
+$headers = "From: $from\r\n"
+	. "Content-Type: $type\r\n"
+	. "Message-ID: $messageid\r\n"
+	. "Received: from [${_SERVER['REMOTE_ADDR']}] by [${_SERVER['SERVER_ADDR']}] via HTTP; ".date('r')."\r\n";
+if (!empty($_SERVER['HTTP_USER_AGENT']))
+	$headers .= "X-Mailer: ".preg_replace('/[\t\r\n]/', ' ', $_SERVER['HTTP_USER_AGENT']);
+if ($_SERVER['WEBID'])
+	$headers .= "Link: <${_SERVER[WEBID]}>; rel=\"http://xmlns.com/foaf/0.1/maker\"";
+
+// Send message and respond appropriately.
+if( @mail($__to, $subject, $data, $headers) )
+{
+	header("Content-Type: text/plain");
+	header("X-Generated-Message-ID: $messageid");
+	print "Message sent with Message-ID: ${messageid}.\r\n";
+	exit;
+}
+else
+{
+	header("HTTP/1.1 400 Error Sending Message");
+	header("Content-Type: text/plain");
+	print "Please try again later.\r\n";
+	exit;
+}
+
+<?php
+
+// Destination mailbox - you need to change this.
+$__to = 'you@example.net';
+
+// Default "from" address - set to NULL if you want to force people to include
+// a From header with their POSTs.
+$__from = null;
+
+// Set to TRUE to enable WebID support via webid.pl. Set to 'force' to force
+// people to authenticate via WebID.
+$__webid = true;
+
+require 'inc_http-mbox-gateway.php';
+#!/usr/bin/perl
+
+use 5.010;
+use lib '/home/tai/src/perlmods/CGI-Auth-FOAF_SSL/lib';
+use CGI::Auth::FOAF_SSL;
+
+local $/ = undef;
+my $pem = <>;
+my $auth = CGI::Auth::FOAF_SSL->new( $pem );
+if(defined $auth && $auth->is_secure)
+{
+	say $auth->agent->identity;
+	say $auth->agent->name;
+	say $auth->agent->mbox;
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.