
Post before you was made on 30th June 2002 :p
seems this is not going to be done as it was planned :p a year ago :p
Moderator: Spunkmeyer
It would be really appreciated if you published the solution once it comes back to you...Yoshi wrote:I did this a loooong time ago so it may take while to come back to me
header:-
$header_to: contains "whatever_you_want_the_address@your_domain"
destination:-
|/home/yourpath/to/cgi-bin/whateveryoucallthescriptbelow.pl -e -q
e Optional. send errors via an email reply. & -q Optional. suppresses non-error output
#!/usr/bin/perl
use CGI::Carp qw(fatalsToBrowser);
#your SMTP server if other than localhost(used for error emails using -e option)
#(set this if the system rgmp is installed on does not have it't own SMTP server)
$smtp_server = "localhost";
#need to keep the backslahs
$sender = "address\@domain";
#author name can be set here or in the email
$authorname = "";
#Password either set here or in the email
$authorpassword = "";
#Category
$ncategory="";
#I have a custom filed called CustomFiled_exurl if a url is passed the news title links offsite (use as an example of handling additional custom fileds
$nexurl="";
# Yes means you get an email back confirmin it has been processed No means you dont
$nconfirm="";
#Url path to your coranto script
$server_url = "http://www.yourdomain/your coranto_folder/coranto.cgi";
###########################################################
$version = "1.3";
use LWP::UserAgent;
use HTTP::Request::Common qw(POST);
use Mail::Sendmail;
#take input from STDIN if no file specified.
$input_file = "-";
$quiet = "0";
$moretext="";
$usage_text = <<USAGE;
\nRGMP Version $version
USAGE: $0 [options]
\tOptions:
\t\t-A author name
\t\t-P author password
\t\t-e
\t\t-f input file
\t\t-h
\t\t-n
\t\t-p http proxy
\t\t-q
\t\t-s URL to gm.cgi
\nNOTES:
\t-A Optional. Username for logging in to Greymatter,
\t if not specified here, must be given in input text.
\t-P Optional. Password, same as above.
\t-e Optional. send errors via an email reply.
\t-f Optional. if omitted, uses STDIN.
\t-h This help message.
\t-n Optional. Remove newlines from post.
\t-p Optional. format: http://proxy.my.org:8080/
\t-q Optional. suppresses non-error output
\t-s Required if not set in RGMP code.\n\n
USAGE
#####
&get_args;
&info_out("Will post to: $server_url\n");
&get_post;
#change 0 to 1 for debugging purposes.
if(0){
print "authorname: $authorname\n";
print "authorpassword: $authorpassword\n";
print "subject: $subject\n";
print "maintext: >>$maintext<<\n";
print "moretext: >>$moretext<<\n";
print "allowkarma: $allowkarma\n";
print "allowcomments: $allowcomments\n";
print "stayattop: $stayattop\n";
print "makelinks: $makelinks\n";
exit;
}
$ua = LWP::UserAgent->new;
if( $http_proxy ){
if( lc($http_proxy) eq "env"){
$ua->env_proxy; # initialize from environment variables
}else{
$ua->proxy(http => "$http_proxy");
}
}
#change the guestpost_posteremail to whatever address you want the confirmation to come from
#you may also want to remove the reference to CustomFiled_exurl
$http_request = POST "$server_url", [ action => 'login', secondaryaction => 'submitsave', uname => "$authorname", pword => "$authorpassword", Category => "$ncategory", Subject => "$subject", Text => "$maintext", CustomField_exurl,=> "$nexurl", guestpost_postername => 'yoshi', guestpost_posteremail => 'lee@0-21.co.uk' ] ;
&info_out("Posting...");
my $res = $ua->request($http_request);
# check the outcome
if ($res->is_success) {
&info_out("Post successfull\n");
&confirm_post();
}
else {
&error_out( "Post failed!\nUnknown error, this may help:\n\n".substr($post_results,0,300)."\n\n");
}
#thats it! wow, pretty simple.
exit;
##########################
sub get_args(){
# it is now possible to not need any command line arguments
if(@ARGV != 0){
@args = reverse(@ARGV);
while($arg = pop @args){
if( lc($arg) eq "-s"){ $server_url = pop(@args); }
elsif( $arg eq "-p"){ $http_proxy = pop(@args); }
elsif( lc($arg) eq "-f"){ $input_file = pop(@args); }
elsif( lc($arg) eq "-h"){ info_out($usage_text); exit; }
elsif( lc($arg) eq "-q"){ $quiet = 1; }
elsif( lc($arg) eq "-e"){ $email_errors = 1; }
elsif( lc($arg) eq "-n"){ $no_newlines = 1; }
elsif( $arg eq "-A"){ $authorname = pop(@args); }
elsif( $arg eq "-P"){ $authorpassword = pop(@args); }
else{
&error_out("\nUnknown option '$arg'\n$usage_text");
exit;
}
}
}
}
sub get_post(){
my $simple_post=0;
my $body;
if( ! open (IN,$input_file) ){
&error_out("Could not open input file: $input_file !\n");
exit;
}
while(<IN>){
if(/^From:\s+(.+)$/){
$email_from = $1;
}
if(/^Subject:\s+(.+)$/){
$subjectline = $1;
if ($subjectline =~ /^\{([^\}]*)\}\s*(.*)$/ ){
$subject=$2;
$authdata = $1;
if($authdata =~ /username\s*\=\s*(\w+)/){$authorname=$1;$simple_post=1;}
if($authdata =~ /password\s*\=\s*(\w+)/){$authorpassword=$1;$simple_post=1;}
if($authdata =~ /category\s*\=\s*(\w+)/){$ncategory=$1;$simple_post=1;}
if($authdata =~ /confirm\s*\=\s*(\w+)/){$nconfirm=$1;$simple_post=1;}
}elsif($subjectline =~ /[\{\}]/ ){
&error_out("I'm confused, check your subject line and try again\nSubject: $subjectline\n");
exit;
}else{
$subject=$subjectline;
}
#check for wrapped subject line.
$file_pos = tell(IN);
$_ = <IN>;
if( /^\s(.+)$/ ){
$subject=$subject.$1;
}else{
seek (IN,$file_pos,0);
}
}
if(/^From:\s+(.+)$/){
$email_from = $1;
}
#skip rest of headers
if(/^\n$/){ last; }
}
if( $simple_post ){
#gobble up body of message
while(<IN>){
$maintext .= $_;
}
}
else {
while(<IN>){
$altmaintext .= $_;
if( /\s*username\s*=\s*(\S+)\s*/is ){
$authorname = $1;
}
if( /\s*password\s*=\s*(\S+)\s*/is ){
$authorpassword = $1;
}
if( /\s*category\s*=\s*(\S+)\s*/is ){
$ncategory = $1;
}
if( /\s*exurl\s*=\s*(\S+)\s*/is ){
$nexurl = $1;
}
if( /\s*confirm\s*=\s*(\S+)\s*/is ){
$nconfirm = $1;
}
if ( /^\{maintext\}/i ){
$found_maintext++;
while(<IN>){
if( /^\{moretext\}/i ){
last;
}else{
if ( /^\{end\}/i ){
last;
}
$maintext .= $_;
}
}
}
if ( /^\{moretext\}/i ){
$found_moretext++;
#{moretext} goes to the end of the message
while(<IN>){
if ( /^\{end\}/i ){
last;
}
$moretext .= $_;
}
}
}
if(! $found_maintext && ! $found_moretext){
#&error_out("Could not find {maintext} in message body!?!? Check your message format and spelling.\n");
#exit;
$maintext = $altmaintext;
if( ! $maintext =~ /\S/s ) {
&error_out("E-gads, Could not find any message body!?!?\n");
exit;
}
}
}
close IN;
if(! $server_url ){
&error_out("\nNo server URL specified anywhere.\n");
exit;
}
if( ! $authorname ){
&error_out("No username specified.\n");
exit;
}
if( ! $authorpassword ){
&error_out("No password specified.\n");
exit;
}
if( ! $ncategory ){
&error_out("No category specified.\n");
exit;
}
# strip out newline chars if requested
if( $no_newlines ){
$maintext =~ s/\n/ /gs;
$moretext =~ s/\n/ /gs;
}
}
sub info_out(){
if( ! $quiet ){
print $_[0];
}
}
sub error_out()
{
if( $email_errors && $email_from ){
$rx = $Mail::Sendmail::address_rx;
# use the handy built-in, military strength regex
if ( $email_from =~ /$rx/) {
$address=$&;
}
%mail = (
To => "$email_from",
From => "$sender",
#Bcc => 'Someone <him@there.com>, Someone else her@there.com',
# only addresses are extracted from Bcc, real names disregarded
#Cc => 'Yet someone else <xz@whatever.com>',
# Cc will appear in the header. (Bcc will not)
Subject => "News Post ERROR: RE: $subject" ,
Message => "ERROR:\n$_[0]\n\n\nsubject: $subject\nmaintext: >>$maintext\n\nexternalURL: $nexurl\ncategory: $ncategory\n",
'X-Mailer' => "Mail::Sendmail version $Mail::Sendmail::VERSION",
);
$mail{Smtp} = "$smtp_server";
if( ! sendmail(%mail) ){
#can't send email, lets just dump to STDERR like we should.
print STDERR "ERROR:\n$_[0]\n\n";
print STDERR "ERROR:\n Could not send email!\n $Mail::Sendmail::error\n";
exit;
}
}
}
sub confirm_post()
{
if( $nconfirm eq "yes" && $email_from ){
$rx = $Mail::Sendmail::address_rx;
# use the handy built-in, military strength regex
if ( $email_from =~ /$rx/) {
$address=$&;
}
%mail = (
To => "$email_from",
From => "$sender",
#Bcc => 'Someone <him@there.com>, Someone else her@there.com',
# only addresses are extracted from Bcc, real names disregarded
#Cc => 'Yet someone else <xz@whatever.com>',
# Cc will appear in the header. (Bcc will not)
Subject => "News Post Success: RE: $subject" ,
Message => "\nsubject: $subject\nmaintext: >>$maintext\n\nexternalURL: $nexurl\ncategory: $ncategory\n",
'X-Mailer' => "Mail::Sendmail version $Mail::Sendmail::VERSION",
);
$mail{Smtp} = "$smtp_server";
if( ! sendmail(%mail) ){
#can't send email, lets just dump to STDERR like we should.
print STDERR "ERROR:\n$_[0]\nFor dubug sender is: $sender\nFor dubug To is: $email_from\n";
print STDERR "ERROR:\n Could not send email!\n $Mail::Sendmail::error\n";
exit;
}
}
}
username = [username as defined in guestpost addon]
password = [password as defined in guestpost addon]
category = [your category]
exurl = [you proabably dont need this]
confirm = [yes or no (get a confirmation email back or not)]
{maintext}
this is a test message
this is a test url http://www.0-21.co.uk <http://www.0-21.co.uk/> this
is a tet line break
{end}
Return to Addon Development and Requests
Users browsing this forum: No registered users and 1 guest