Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Dreamhost RPC users

Caoimhe Armitage
Script Witch
Join date: 7 Sep 2004
Posts: 117
07-12-2005 06:37
How do y'all get your object keys from your inbox to your servers? I confess I'm using old primitive tools like just writing a plain C program to get run from my ~/.foward.postfix file, but even at that I don;t seem to actually get any data written to the files I'm trying to populate.

I just can't figure out how to get the chain of data started here. the rest is all very straightforward. Any help you can give will be appreciated :)

- C
Satchmo Prototype
eSheep
Join date: 26 Aug 2004
Posts: 1,323
07-12-2005 19:58
I don't use Dreamhost (which I assume is a specific hosting providder) but I do have one project in which I use a plain .forward file like this:


[satchmo@shogun]# cat .forward

|~/<program-name>

That just pipes the email into the specified program name as standard in. I usually hang a perl program off the end, and recieve the email as standard in, parse it up, drop it in a database or do whatever else it needs to do.

Here's a quickie perl script that just grabs an email and writes it to a file named email.txt in my home directory. (Have not tested it, but I think it works)

#!/usr/bin/perl
#use strict;


open (SBOUT,">/home/satchmo/email.txt";) or die "Can't open test.txt: $!";

# continiously read from stdin
while( <> ) {
#read a line from stdin and decide what it contains
chomp( $line = $_ );
print SBOUT "$line\n";
}
_____________________

----------------------------------------------------------------------------------------------------------------
The Electric Sheep Company
Satchmo Blogs: The Daily Graze
Satchmo del.icio.us
Velox Severine
Network Slave
Join date: 19 May 2005
Posts: 73
07-12-2005 20:15
I use a PHP script which I pipe from Exim to this shell-based PHP script. (works with XML-RPC examples in LSL wiki).

CODE

#!/usr/bin/php
<?php
require("xml-rpc.php");

// read from stdin
$fd = fopen("php://stdin", "r");
$email = "";
while (!feof($fd)) {
$email .= fread($fd, 1024);
}
fclose($fd);
// handle email
$lines = explode("\n", $email);

// empty vars
$from = "";
$subject = "";
$headers = "";
$message = "";
$splittingheaders = true;
for ($i=0; $i<count($lines); $i++) {
if ($splittingheaders) {
// this is a header
$headers .= $lines[$i]."\n";

// look out for special headers
if (preg_match("/^Subject: (.*)/", $lines[$i], $matches)) {
$subject = $matches[1];
}
if (preg_match("/^From: (.*)/", $lines[$i], $matches)) {
$from = $matches[1];
}
} else {
// not a header, but message
$message .= $lines[$i]."\n";
}

if (trim($lines[$i])=="") {
// empty line, header section has ended
$splittingheaders = false;
}
}


$channel = explode("\n", $message); // Break apart message
llRemoteData($channel[4], "0", "How are you?"); // Open remote data channel (XML-RPC)
?>
_____________________
--BEGIN SIGNATURE STRING--
IkkgY2FtZSwgSSBzYXcsIEkgY29ucXVlcmVkLiIgLS1KdWxpdXMgQ2Flc2Fy
--END SIGNATURE STRING--
Csven Concord
*
Join date: 19 Mar 2005
Posts: 1,015
09-20-2005 18:24
I'm curious if anyone is triggering their script with the email itself. Right now I'm guessing most people run a cron job/trigger script and retrieve their email. Is triggering with the email even possible?
Adam Zaius
Deus
Join date: 9 Jan 2004
Posts: 1,483
09-20-2005 18:47
From: Csven Concord
I'm curious if anyone is triggering their script with the email itself. Right now I'm guessing most people run a cron job/trigger script and retrieve their email. Is triggering with the email even possible?


I do this exclusively, polling was eating too much CPU time, so I switched to using `aliases` (albeit all the boxes I use for SL are dedicated, which I have root on) -- see the /etc/aliases file.

-Adam
_____________________
Co-Founder / Lead Developer
GigasSecondServer
Zarf Vantongerloo
Obscure Resident
Join date: 22 Jun 2005
Posts: 110
09-20-2005 19:32
I, too, trigger the script directly from the mail server via Postfix's alias techniques. Polling really isn't viable for reasons stated above.

The mailer delivers the email in stdin to the script. In my case, it is a python script that parses the email message (thanks to lots of nice, standard python classes for mail message handling) and extracts the standard LSL encoded info, the XML-RPC channel information my object encoded, and other information from the object (If you're going to send an e-mail, might as well make the most of it!).

I have the whole thing in a reusable python class, which I can put in the LSL wiki if anyone would like.
Huns Valen
Don't PM me here.
Join date: 3 May 2003
Posts: 2,749
09-21-2005 01:53
OK, here's how to do it on Dreamhost.

Create a file in your home directory called .forward.postfix and put this line in it:

"|/usr/bin/procmail -t"

Then, edit .procmailrc and put something like this in it:

:0
* ^TO_youraddress@yourdomain\.com
|/path/to/php /home/youraccountname/path/to/your/email/handler

As stated by someone else, the email will be available through stdin. Whatever you send with llEmail() should arrive within a few seconds. Cheers.
Eggy Lippmann
Wiktator
Join date: 1 May 2003
Posts: 7,939
09-21-2005 02:24
From: Velox Severine
I use a PHP script which I pipe from Exim to this shell-based PHP script.

I do exactly the same thing :)
LSL -> email -> exim -> php -> xmlrpc -> LSL
The advantages over a purely email based solution are 4x less latency and no timers required.
Csven Concord
*
Join date: 19 Mar 2005
Posts: 1,015
09-21-2005 08:59
Nice to confirm. And I now recall what got me thinking you could do this, so glad I asked. Fortunately, it appears cPanel can pipe directly.

I know a little PERL and no PHP. Anyone tested Satchmo's code? Figure I can give it a spin. Or am I better off picking up PHP? I'm using WordPress to blog and have been looking for an additional reason to do more than hack settings.
Iron Perth
Registered User
Join date: 9 Mar 2005
Posts: 802
09-21-2005 09:32
[logic@####### logic]$ cat .forward
"|/home/logic/process.sh"
[logic@##### logic]$ cat process.sh

#!/bin/sh
awk '{if ($1=="Information:";) {if ($2=="load";) {printf "cd <dir>; ./push.sh %s %s\n", $3, $4} else {printf "mysql db --exec \"insert into channels values (null, '"'"'%s'"'"', '"'"'%s'"'"', %s)\"\n", $2,$3, $4}}}' | sh

That will call push script on the parameters sent by the email if the command is "load", otherwise insert into a db the values in the email.

I'm a big awk fan..

You need sendmail installed, but that's it..
_____________________
http://ironperth.com - Games for SecondLife and more.
Huns Valen
Don't PM me here.
Join date: 3 May 2003
Posts: 2,749
09-21-2005 16:10
From: Csven Concord
Nice to confirm. And I now recall what got me thinking you could do this, so glad I asked. Fortunately, it appears cPanel can pipe directly.

I know a little PERL and no PHP. Anyone tested Satchmo's code? Figure I can give it a spin. Or am I better off picking up PHP? I'm using WordPress to blog and have been looking for an additional reason to do more than hack settings.
If you are using DreamHost, you should either use PHP or compile your own version of perl (which, fortunately, they allow.) Here is the reason:

From: someone
$ perl -v

This is perl, v5.6.1 built for i386-linux

Copyright 1987-2001, Larry Wall
The version they have installed is so old that some newer applications, like wakaba, will not run on it. I had to help a friend of mine compile perl in order to get wakaba to run on his site.
Alondria LeFay
Registered User
Join date: 2 May 2003
Posts: 725
09-21-2005 16:42
From: Huns Valen
If you are using DreamHost, you should either use PHP or compile your own version of perl (which, fortunately, they allow.) Here is the reason:

The version they have installed is so old that some newer applications, like wakaba, will not run on it. I had to help a friend of mine compile perl in order to get wakaba to run on his site.


Yup. Ickiness. If anyone happens to be lucky and their account is on Lucky, I can provide access to my pre-compiled 5.8.6 for i686 (which I know, is technically 0.0.1 old).

On the subject at hand with dreamhost, their whole email setup is a little substandard, and I recall I had to play with it a little to get working. (most noticeably is the .forward.postfix opposed to just .forward). My .forward.postfix just contains |/home/foomyaccount/fooscript.pl (names have been replace to protect the foo).

My .procmailrc contains:
CODE

MAILDIR=$HOME/Maildir
PMDIR=$HOME/.procmail
LOGFILE=$PMDIR/log
SHELL=/bin/sh

:0
* ^TO_rpchost@secondnetworks.net
|/home/foomyaccount/local/bin/perl-static /home/foomyaccount/fooscript.pl


To be honest, I am not sure if the redundant code is necessary (defining the forward in .forward.postfix and .procmailrc) but it has been a year since it was set up and I forgot what I had for lunch today.

If you have any difficulty Caoimhe, feel free to IM me. I have quite a bit with Dreamhost and SL via RPC.
Csven Concord
*
Join date: 19 Mar 2005
Posts: 1,015
09-22-2005 10:05
From: Huns Valen
If you are using DreamHost, you should either use PHP or compile your own version of perl (which, fortunately, they allow.)

I'm not on Dreamhost but your comment did get me to check which version my host is running. Thanks for getting me to check as I'd not done that (fortunately, it's relatively new). Meanwhile, I got it working in PERL but used an array to slurp it in. I'll get into PHP a little later when I have some time... or the need.
Adam Brokken
Registered User
Join date: 16 Jun 2005
Posts: 21
what path are people using for php in their procmailrc?
11-19-2005 18:58
dreamhost support said it is uncessary to complie php in your home ... that i can use the php on the mail server and it will work fine, but... I don't know what path to use in my procmailrc?