#!/usr/bin/perl # use: perl radio_post.pl Internet and server settings" # (not needed if you run this script on the same computer as radio) $username = 'your_user_id_for_radio'; $password = 'your_radio_password'; # get text from standard in { local $/; $itemtext = ; } #strip trailing whitespace $itemtext =~ s|\s*$||s; # url encode it use URI::Escape; $itemtext = uri_escape($itemtext); # this is for the home page: $cat = "flPostToHomePage=on"; # to use more than one category, put this line between them #$cat .= '&'; # categories would look something like this: # a category name like "Political/Political Humor" # needs: #$cat .= uri_escape("cat:Political/Political Humor"); #$cat .= "=xxx"; # this is the whole string to post to Radio $post = "referer=&itemtext=$itemtext&$cat&postToWeblog=Post+to+Weblog"; # # you shouldn't need to change anything below this point # use LWP; #if you wanted to send a referer, uncomment and adjust: #use HTTP::Headers; #$h = new HTTP::Headers; #$h->referer('http://192.168.0.16:5335/'); # lifted and tweaked from lwp-request: # We make our own specialization of LWP::UserAgent that asks for # user/password if document is protected. { package RequestAgent; @ISA = qw(LWP::UserAgent); sub new { my $self = LWP::UserAgent::new(@_); $self->agent("lwp-request/$main::VERSION"); $self; } sub get_basic_credentials { my($self, $realm, $uri) = @_; if ($main::options{'C'}) { return split(':', $main::options{'C'}, 2); } elsif ($main::username) { return ($main::username, $main::password); } elsif (-t) { my $netloc = $uri->host_port; print "Enter username for $realm at $netloc: "; my $user = ; chomp($user); return (undef, undef) unless length $user; print "Password: "; system("stty -echo"); my $password = ; system("stty echo"); print "\n"; # because we disabled echo chomp($password); return ($user, $password); } else { return (undef, undef) } } } # Create a user agent object # use LWP::UserAgent; # $ua = new LWP::UserAgent; $ua = RequestAgent->new; $ua->agent("RadioPoster/0.1 " . $ua->agent); # to lie like a dog... uncomment below, and comment out above # $ua->agent("Mozilla/4.77 [en] (X11; U; Linux 2.4.4-4GB i686)"); # Create a request my $req = new HTTP::Request POST => $radio_url; # for debugging, if you have ENV.pl. (comment out the $req line above) # my $req = new HTTP::Request POST => $radio_url . 'cgi-bin/ENV.pl'; $req->content_type('application/x-www-form-urlencoded'); $req->content($post); # Pass request to the user agent and get a response back my $res = $ua->request($req); # Check the outcome of the response if ($res->is_success) { print $res->content; } else { print "script probably timed out, but comment was probably posted\n"; }