| 1 | #!/usr/bin/perl |
|---|
| 2 | use strict; |
|---|
| 3 | use HTTP::Request::Common; |
|---|
| 4 | use LWP::UserAgent; |
|---|
| 5 | use HTTP::Cookies; |
|---|
| 6 | $|++; |
|---|
| 7 | |
|---|
| 8 | print "addpost.pl <accounts> <content> <proxies> [picture.jpg]\n" |
|---|
| 9 | if (@ARGV != 3 && @ARGV != 4); |
|---|
| 10 | exit |
|---|
| 11 | if (@ARGV != 3 && @ARGV != 4); |
|---|
| 12 | |
|---|
| 13 | if (@ARGV == 4) |
|---|
| 14 | { |
|---|
| 15 | open(JPEGFILE, $ARGV[3]) or die "Cannot open $ARGV[3]"; |
|---|
| 16 | close JPEGFILE; |
|---|
| 17 | } |
|---|
| 18 | |
|---|
| 19 | open(CONTENT, $ARGV[1]) or die "Cannot open $ARGV[1]"; |
|---|
| 20 | my @content = <CONTENT>; |
|---|
| 21 | my $content = join('<br>', @content); |
|---|
| 22 | |
|---|
| 23 | open(PROXIES, $ARGV[2]) |
|---|
| 24 | or die "Cannot open $ARGV[2]"; |
|---|
| 25 | |
|---|
| 26 | open(ACCOUNTS, $ARGV[0]) |
|---|
| 27 | or die "Cannot open $ARGV[0]"; |
|---|
| 28 | |
|---|
| 29 | my $ua = LWP::UserAgent->new; |
|---|
| 30 | $ua->timeout(3); |
|---|
| 31 | push @{$ua->requests_redirectable}, 'POST'; |
|---|
| 32 | |
|---|
| 33 | sub GetViewState($) |
|---|
| 34 | { |
|---|
| 35 | foreach my $l (split /\n/, $_[0]->content) |
|---|
| 36 | { |
|---|
| 37 | if ($l =~ /name=\"__VIEWSTATE\" value=\"([^\"]+)\"/i) |
|---|
| 38 | { |
|---|
| 39 | return $1; |
|---|
| 40 | } |
|---|
| 41 | } |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | ACCOUNTS: |
|---|
| 45 | { |
|---|
| 46 | while (<ACCOUNTS>) |
|---|
| 47 | { |
|---|
| 48 | chomp; |
|---|
| 49 | my $account = $_; |
|---|
| 50 | while (<PROXIES>) |
|---|
| 51 | { |
|---|
| 52 | my $vs; |
|---|
| 53 | $ua->cookie_jar(HTTP::Cookies->new); |
|---|
| 54 | $ua->proxy('http', "http://$_/"); |
|---|
| 55 | my $username; |
|---|
| 56 | my $password; |
|---|
| 57 | ($username, $password) = split(/ /, $account); |
|---|
| 58 | print "Trying $username"; |
|---|
| 59 | my $request = $ua->request(GET 'http://www.xanga.com/'); |
|---|
| 60 | chomp; |
|---|
| 61 | |
|---|
| 62 | unless ($request->is_success && $request->content =~ /Xanga News/) |
|---|
| 63 | { |
|---|
| 64 | print " || Failed to load xanga.com: $_\n"; |
|---|
| 65 | next; |
|---|
| 66 | } |
|---|
| 67 | $vs = GetViewState($request); |
|---|
| 68 | if (not defined $vs) |
|---|
| 69 | { |
|---|
| 70 | print " || Unable to get VIEWSTATE: $_\n"; |
|---|
| 71 | next; |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | $request = |
|---|
| 75 | $ua->request( |
|---|
| 76 | POST 'http://www.xanga.com/Default.aspx', |
|---|
| 77 | [ |
|---|
| 78 | __VIEWSTATE => $vs, |
|---|
| 79 | "SigninModule:txtSigninUsername" => $username, |
|---|
| 80 | "SigninModule:txtSigninPassword" => $password, |
|---|
| 81 | "SigninModule:btnSignin" => "Go%21", |
|---|
| 82 | ] |
|---|
| 83 | ); |
|---|
| 84 | undef($vs); |
|---|
| 85 | if ($request->is_success && $request->content =~ /PLEASE SIGN IN/) |
|---|
| 86 | { |
|---|
| 87 | print |
|---|
| 88 | "Error with $username: Invalid username and/or password\n"; |
|---|
| 89 | goto ACCOUNTS; |
|---|
| 90 | } |
|---|
| 91 | elsif ( $request->is_success |
|---|
| 92 | && $request->content =~ /Welcome back!/) |
|---|
| 93 | { |
|---|
| 94 | print " || Logged in..."; |
|---|
| 95 | } |
|---|
| 96 | else |
|---|
| 97 | { |
|---|
| 98 | print " || Unable to log in: $_\n"; |
|---|
| 99 | next; |
|---|
| 100 | } |
|---|
| 101 | $request = |
|---|
| 102 | $ua->request(GET |
|---|
| 103 | 'http://www.xanga.com/private/xtools/xtoolsclassic.aspx?plain=1' |
|---|
| 104 | ); |
|---|
| 105 | unless ( $request->is_success |
|---|
| 106 | && $request->content =~ /Weblog Entry/) |
|---|
| 107 | { |
|---|
| 108 | print " || Error trying to open new post page\n"; |
|---|
| 109 | next; |
|---|
| 110 | } |
|---|
| 111 | $vs = GetViewState($request); |
|---|
| 112 | if (not defined $vs) |
|---|
| 113 | { |
|---|
| 114 | print " || Unable to get VIEWSTATE: $_\n"; |
|---|
| 115 | next; |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | my $userid; |
|---|
| 119 | foreach my $l (split /\n/, $request->content) |
|---|
| 120 | { |
|---|
| 121 | if ($l =~ |
|---|
| 122 | /<input name=\"txtUserId\" type=\"text\" value=\"([0-9]+)\"/ |
|---|
| 123 | ) |
|---|
| 124 | { |
|---|
| 125 | $userid = $1; |
|---|
| 126 | } |
|---|
| 127 | } |
|---|
| 128 | if (not defined $userid) |
|---|
| 129 | { |
|---|
| 130 | print " || Unable to get txtUserId: $_\n"; |
|---|
| 131 | next; |
|---|
| 132 | } |
|---|
| 133 | $request = |
|---|
| 134 | $ua->request( |
|---|
| 135 | POST |
|---|
| 136 | 'http://www.xanga.com/private/xtools/xtoolsclassic.aspx?plain=1', |
|---|
| 137 | [ |
|---|
| 138 | __VIEWSTATE => $vs, |
|---|
| 139 | txtPlainText => $content, |
|---|
| 140 | txtProfImageName => "", |
|---|
| 141 | proftitle1 => "", |
|---|
| 142 | proftitle2 => "", |
|---|
| 143 | proftitle3 => "", |
|---|
| 144 | xztitle1 => "", |
|---|
| 145 | xztitle2 => "", |
|---|
| 146 | xzasin1 => "", |
|---|
| 147 | radAccess => "1", |
|---|
| 148 | chkComments => "on", |
|---|
| 149 | btnSubmit => "Submit", |
|---|
| 150 | txtUserId => $userid, |
|---|
| 151 | xbgcolor => "", |
|---|
| 152 | xbordercolor => "", |
|---|
| 153 | xcontent => "", |
|---|
| 154 | xcopypost => "", |
|---|
| 155 | ] |
|---|
| 156 | ); |
|---|
| 157 | if (!$request->is_success) |
|---|
| 158 | { |
|---|
| 159 | print " || some sort of failure during posting\n"; |
|---|
| 160 | next; |
|---|
| 161 | } |
|---|
| 162 | else |
|---|
| 163 | { |
|---|
| 164 | print " || Posted (probably)\n"; |
|---|
| 165 | } |
|---|
| 166 | if (@ARGV == 4) |
|---|
| 167 | { |
|---|
| 168 | $request = |
|---|
| 169 | $ua->request( |
|---|
| 170 | GET 'http://premium.xanga.com/private/wizardpicture.aspx?'); |
|---|
| 171 | $vs = GetViewState($request); |
|---|
| 172 | if (not defined $vs) |
|---|
| 173 | { |
|---|
| 174 | print " || Unable to get VIEWSTATE: $_\n"; |
|---|
| 175 | next; |
|---|
| 176 | } |
|---|
| 177 | $request = |
|---|
| 178 | $ua->request( |
|---|
| 179 | POST 'http://premium.xanga.com/private/wizardpicture.aspx', |
|---|
| 180 | Content_Type => 'form-data', |
|---|
| 181 | Content => [ |
|---|
| 182 | __VIEWSTATE => $vs, |
|---|
| 183 | txtFile => [$ARGV[3]], |
|---|
| 184 | "ProfileUploadControl1_btnWizardBack" => " Back ", |
|---|
| 185 | "ProfileUploadControl1:btnWizardNext" => " Upload ", |
|---|
| 186 | ] |
|---|
| 187 | ); |
|---|
| 188 | if ($request->is_success) |
|---|
| 189 | { |
|---|
| 190 | print " || Avatar uploaded"; |
|---|
| 191 | |
|---|
| 192 | } |
|---|
| 193 | else |
|---|
| 194 | { |
|---|
| 195 | print " || Error uploading avatar\n"; |
|---|
| 196 | next; |
|---|
| 197 | } |
|---|
| 198 | } |
|---|
| 199 | print "\n"; |
|---|
| 200 | goto ACCOUNTS; |
|---|
| 201 | |
|---|
| 202 | } |
|---|
| 203 | } |
|---|
| 204 | } |
|---|