#!/usr/bin/perl -w # Perl script to post to the co.umist wwwboard. # Author: Chris Ball use strict; use HTTP::Request; use LWP::UserAgent; use URI::Escape; my ($name_raw, $email_raw, $subject_raw, $body_raw); my ($name, $email, $subject, $body); my $filename = $ENV{HOME} . "/.umistrc"; # Open the config file. print "Your .umistrc should be at: $filename\n"; open (CONF, "<$filename") or die "Couldn't open .umistrc: $!"; # Data stored in "$name\t$email" format. while () { ($name, $email) = split (/\t/, $_); chomp $email; } print ".umistrc found. Posting as: ($name/$email)\n\n"; # { Get, chomp } subject and body. print "Enter subject: "; $subject_raw = ; chomp $subject_raw; local $/ = "\n.\n"; print "Enter message body, end with a . on a line by itself:\n"; $body_raw = ; chomp $body_raw; # URI::Escape everything. $name = uri_escape($name_raw); $email = uri_escape($email_raw); $subject = uri_escape($subject_raw); $body = uri_escape($body_raw); # Send it all over to the web server. my $ua = new LWP::UserAgent; my $req = new HTTP::Request POST => 'http://www.co.umist.ac.uk/cgi-bin/wwwboard.pl'; $req->content_type("application/x-www-form-urlencoded"); $req->content("name=$name&email=$email&subject=$subject&body=$body"); my $res = $ua->request($req); if ($req->is_success) { print "\nPost sent to server succesfully.\n"; } else { print "\nThere was an error communicating with the server.\n"; } # And we're done. print "$0 finished.\n";