#!/usr/bin/perl require 5.002; use strict; use IO::Socket; #$encoded = encode_base64('Aladdin:open sesame'); my $DEBUG = 1; my $bloghost = "plant.blogger.com"; my $blogserverip = "66.102.15.100"; my $ctype = "text/xml"; my $appkey = $ARGV[0]; $appkey =~ s/^\w+\=//; my $blogid = $ARGV[1]; $blogid =~ s/^\w+\=//; my $blogus = $ARGV[2]; $blogus =~ s/^\w+\=//; my $blogpw = $ARGV[3]; $blogpw =~ s/^\w+\=//; my $title = $ARGV[4]; $title =~ s/^\w+\=//; my $link = $ARGV[5]; $link =~ s/^\w+\=//; my $author = $ARGV[6]; $author =~ s/^\w+\=//; my $messageBody = $ARGV[7]; $messageBody =~ s/^\w+\=//; $messageBody =~ s/\'//g; my $blogtype = $ARGV[8]; $blogtype =~ s/^\w+\=//; $bloghost = $ARGV[9]; $bloghost =~ s/^\w+\=//; my $blogurl = $ARGV[10]; $blogurl =~ s/^\w+\=//; $blogserverip = $ARGV[11]; $blogserverip =~ s/^\w+\=//; my $blogserverport = $ARGV[12]; $blogserverport =~ s/^\w+\=//; if ($DEBUG) { open (OUTFILE, ">/tmp/konfab.log"); print OUTFILE $bloghost . " / " . $blogserverip . "\n"; #close OUTFILE; #print "-4\n"; #exit -1; } if ((!$appkey) || (!$blogid) || (!$blogus) || (!$blogpw) || (!$messageBody)) { if (!$appkey) { print "-4\n"; } elsif (!$blogid) { print "-5\n"; } elsif (!$blogus) { print "-6\n"; } elsif (!$blogpw) { print "-7\n"; } elsif (!$messageBody) { print "-8\n"; } else { print "-13\n"; } if ($DEBUG) { close OUTFILE; } exit -1; } # unescape routine: my $escapedMessage = "$messageBody"; $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 { $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); if ($DEBUG) { print OUTFILE "making socket with $blogserverip|$blogserverport\n"; #close OUTFILE; #print "-4\n"; #exit -1; } my $socket = IO::Socket::INET->new(PeerAddr => $blogserverip, PeerPort => $blogserverport, Proto => "tcp", Type => SOCK_STREAM, Timeout => 30); my ($uname,$upasswd,$uuid,$ugid,$uquota,$ucomment,$ugcos,$udir,$ushell,$uexpire) = getpwuid($>); if (!$socket) { # queue open (QFILE, ">>" . $udir . "/.konfabblogqueue"); print QFILE "$appkey:;:$blogid:;:$blogus:;:$blogpw:;:$escapedMessage:;:$title:;:$link:;:$author\n"; close QFILE; print "2\n"; exit 2; } $blogurl =~ s/%([0-9a-fA-F]{2})/pack("c",hex($1))/ge; 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"; #close OUTFILE; #print "-4\n"; #exit -1; } my $r; if (($answer =~ m/faultcode/i) || ($answer !~ m/200/i)) # 200 Acc is URL GET success code { print STDOUT "-3\n"; # error $r = "-3"; } else { if ($DEBUG) { print OUTFILE "1\n"; } print "1\n"; # success $r = "1"; } if ($DEBUG) { close OUTFILE; } exit $r; ############ 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__