#!/usr/pkg/bin/perl 

use POSIX;
use HTML::TokeParser;
use LWP::UserAgent;
use HTTP::Request::Common qw(POST GET);
use HTTP::Cookies;



$|++;

sub getdoc {
    my $docurl = shift;


    my $req = GET  $docurl;

    $req->header(Accept => $acpthdr);

    # Pass request to the user agent and get a response back
    my $res = $ua->request($req);

    $cookie_jar->add_cookie_header( $req );
    $cookie_jar->extract_cookies( $res );
    $cookie_jar->save;


    # Check the outcome of the response
    if ($res->is_success) {
#        print "Got document for $docurl\n";
        print ".";
#        print $res->content();
    } else {
        print "x\n";
#        print $res->error_as_HTML;
        print $res->as_string();
        return ''
    }
#    undef $req;
#    undef $res;
}

sub p1 {
    my $docurl = shift;
    my $idcat = shift;
    

    my $req = POST  $docurl , [
idcategory=>$idcat,
vote=>"1",
]; 

    $req->header(Accept => $acpthdr);

    # Pass request to the user agent and get a response back
    my $res = $ua->request($req);

    $cookie_jar->add_cookie_header( $req );
    $cookie_jar->extract_cookies( $res );
    $cookie_jar->save;

    
    # Check the outcome of the response
    if ($res->is_success) {
        print ".";
    } else {
        print "x\n";
        return ''
    }
}

sub p2 {
    my $docurl = shift;
    

    my $req = POST  $docurl , [
idcategory=>"5",
vote=>"1",
]; 

    $req->header(Accept => $acpthdr);

    # Pass request to the user agent and get a response back
    my $res = $ua->request($req);

    $cookie_jar->add_cookie_header( $req );
    $cookie_jar->extract_cookies( $res );
    $cookie_jar->save;

    
    # Check the outcome of the response
    if ($res->is_success) {
        print ".";
    } else {
        print "x\n";
        return ''
    }
}

sub p3 {
    my $docurl = shift;
    

    my $req = POST  $docurl , [
idcategory=>"4",
vote=>"1",
]; 

    $req->header(Accept => $acpthdr);

    # Pass request to the user agent and get a response back
    my $res = $ua->request($req);

    $cookie_jar->add_cookie_header( $req );
    $cookie_jar->extract_cookies( $res );
    $cookie_jar->save;

    
    # Check the outcome of the response
    if ($res->is_success) {
        print ".";
    } else {
        print "x\n";
        return ''
    }
}

while (5) {
$ua = LWP::UserAgent->new( keep-alive => 1, timeout => 10);
$ua->agent("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.3) Gecko/20060426 Firefox/1.5.0.3");
$cookie_jar = HTTP::Cookies->new( 
  file => "$ENV{'HOME'}/lwp_cookies.dat",
           autosave => 1,
         );
$ua->cookie_jar($cookie_jar);

getdoc("http://thepanicchannel.myrockinprofile.com/");

print $cookie_jar->as_string;
#($phpsid=$cookie_jar->as_string) =~ s/^.*PHPSESSID=([a-f0-9]*);.*/$1/s;
#print "<<<$phpsid>>>\n";


$fucker="http://thepanicchannel.myrockinprofile.com/";

p1($fucker,"5");
p1($fucker,"4");
p1($fucker,"3");
sleep(1);
}
