#!/usr/bin/perl require 5.002; use IO::Socket; use strict; my $DEBUG = 0; my $bloghost = "plant.blogger.com"; my $blogserverip = "66.102.15.100"; my $ctype = "text/xml"; my $blogtype = $ARGV[0]; $blogtype =~ s/^\w+\=//; $bloghost = $ARGV[1]; $bloghost =~ s/^\w+\=//; my $blogurl = $ARGV[2]; $blogurl =~ s/^\w+\=//; $blogserverip = $ARGV[3]; $blogserverip =~ s/^\w+\=//; my $blogserverport = $ARGV[4]; $blogserverport =~ s/^\w+\=//; if ($DEBUG) { open (OUTFILE, ">/tmp/processqueue.log"); } my ($uname,$upasswd,$uuid,$ugid,$uquota,$ucomment,$ugcos,$udir,$ushell,$uexpire) = getpwuid($>); open (INFILE, "<" . $udir . "/.konfabblogqueue"); open (TMPFILE, ">" . $udir . "/.konfabblogqueue.tmp"); my $wrotetmp = 0; while (my $line = ) { my $queuefailcode = ""; chomp($line); if ($line =~ m/^\+/) { $line =~ s/^\+//; $queuefailcode = "1"; } my ($appkey, $blogid, $blogus, $blogpw, $messageBody, $title, $link, $author) = split(':;:', $line); if ((!$appkey) || (!$blogid) || (!$blogus) || (!$blogpw) || (!$messageBody)) { $DEBUG && print OUTFILE "queued entry missing data, skipped and dequeued (won't try again)\n"; if (!$appkey) { next; } elsif (!$blogid) { next; } elsif (!$blogus) { next; } elsif (!$blogpw) { next; } elsif (!$messageBody) { next; } else { next; } } # unescape routine: $messageBody =~ s/%([0-9a-fA-F]{2})/pack("c",hex($1))/ge; my $txaBody; if ($blogtype eq "blogger") { $txaBody = <blogger.newPost${appkey}${blogid}${blogus}${blogpw}1 End ; } else { # unescape routine: $title =~ s/%([0-9a-fA-F]{2})/pack("c",hex($1))/ge; $link =~ s/%([0-9a-fA-F]{2})/pack("c",hex($1))/ge; $author =~ s/%([0-9a-fA-F]{2})/pack("c",hex($1))/ge; my $bmessageBody = &encode_base64($messageBody); my $btitle = &encode_base64($title); my $bauthor = &encode_base64($author); my $blink = &encode_base64($link); $txaBody = <metaWeblog.newPost${blogid}${blogus}${blogpw}title${btitle}link${blink}author${bauthor}description${bmessageBody}1 End ; } my $clen = length($txaBody); my $socket = IO::Socket::INET->new(PeerAddr => $blogserverip, PeerPort => $blogserverport, Proto => "tcp", Type => SOCK_STREAM, Timeout => 30); if (!$socket) { # queue $DEBUG && print OUTFILE "queue entry requeued (still offline)\n"; print TMPFILE $line . "\n"; $wrotetmp = 1; next; } my $request = < reads in # everything that's returned by authd via the socket. my $old_input_separator = $/; undef $/; my $answer = <$socket>; $/ = $old_input_separator; # Restore original separator. # We're done listening to the socket. close($socket); if ($DEBUG) { print OUTFILE $answer . "\n"; } my $r; if (($answer =~ m/faultcode/i) || ($answer !~ /200/i)) { if ($queuefailcode) { $DEBUG && print OUTFILE "entry failed to post a *second* time, not requeuing\n"; } else { $DEBUG && print OUTFILE "entry failed to post, requeued (will be removed from the queue next time if it fails again)\n"; print TMPFILE "+" . $line . "\n"; # save it! $wrotetmp = 1; } next; } else { if ($DEBUG) { print OUTFILE "entry successfully sent from queue\n"; } } } close INFILE; close TMPFILE; unlink "$udir/.konfabblogqueue"; if ($wrotetmp) { $DEBUG && print OUTFILE "still queued entries were written, moving to a new queue file\n"; `mv $udir/.konfabblogqueue.tmp $udir/.konfabblogqueue`; } else { unlink "$udir/.konfabblogqueue.tmp"; } if ($DEBUG) { close OUTFILE; } exit; ############ sub encode_base64() { my $res = ""; my $eol = $_[1]; $eol = "\n" unless defined $eol; pos($_[0]) = 0; # ensure start at the beginning $res = join '', map( pack('u',$_)=~ /^.(\S*)/, ($_[0]=~/(.{1,45})/gs)); $res =~ tr|` -_|AA-Za-z0-9+/|; # `# help emacs # fix padding at the end my $padding = (3 - length($_[0]) % 3) % 3; $res =~ s/.{$padding}$/'=' x $padding/e if $padding; # break encoded string into lines of no more than 76 characters each if (length $eol) { $res =~ s/(.{1,76})/$1$eol/g; } return $res; } ############ __END__