| 1 | package Lunarstorm; | ||
| 2 | |||
| 3 | $VERSION = '0.02'; | ||
| 4 | $ABSTRACT = 'Lunarstorm (www.lunarstorm.se) interface'; | ||
| 5 | |||
| 6 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 1 | ▶ | use LWP::UserAgent; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | 1 | ▶ | use HTTP::Cookies; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | 0 | ▶ | use HTML::TableExtract; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 10 | use URI::Escape; | ||
| 11 | |||
| 12 | my %Defaults = ( | ||
| 13 | Username => undef, | ||
| 14 | Password => undef, | ||
| 15 | UserID => undef, | ||
| 16 | CookiePath => '.', | ||
| 17 | AgentIdent => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows 98)' | ||
| 18 | ); | ||
| 19 | |||
| 20 | |||
| 21 | # Constructor | ||
| 22 | sub new{ | ||
| 23 | my ($class, %args) = @_; | ||
| 24 | my $self = {}; | ||
| 25 | bless $self, $class; | ||
| 26 | |||
| 27 | foreach my $key (keys %Defaults){ | ||
| 28 | $self->{$key} = defined $args{$key} ? $args{$key} : $Defaults{$key}; | ||
| 29 | } | ||
| 30 | $self->{Cookie} = HTTP::Cookies->new(file => "$self->{CookiePath}/cookies.txt", autosave => 1); | ||
| 31 | |||
| 32 | return $self; | ||
| 33 | } | ||
| 34 | |||
| 35 | # Destructor | ||
| 36 | sub DESTROY{ | ||
| 37 | |||
| 38 | } | ||
| 39 | |||
| 40 | |||
| 41 | # login() | ||
| 42 | sub login{ | ||
| 43 | my $self = shift; | ||
| 44 | |||
| 45 | $self->{Cookie}->load(); | ||
| 46 | |||
| 47 | my $ua = LWP::UserAgent->new(keep_alive => 1, timeout => 300); | ||
| 48 | $ua->agent($self->{AgentIdent}); | ||
| 49 | $ua->cookie_jar($self->{Cookie}); | ||
| 50 | |||
| 51 | my $req = HTTP::Request->new(POST => 'http://www.lunarstorm.se/log/log_login.asp'); | ||
| 52 | $req->content_type('application/x-www-form-urlencoded'); | ||
| 53 | $req->content("username=$self->{Username}&password=$self->{Password}&pejl_mood=0"); | ||
| 54 | $req->referer('http://www.lunarstorm.se/log/log_outside.asp'); | ||
| 55 | $req->header('Accept' => 'text/xml,application/xml,application/xhtml+xml,text/html,text/plain'); | ||
| 56 | $self->{Cookie}->add_cookie_header($req); | ||
| 57 | |||
| 58 | my $res = $ua->request($req); | ||
| 59 | |||
| 60 | if(not ($res->is_success || $res->code == 302)){ | ||
| 61 | return 0; | ||
| 62 | } | ||
| 63 | |||
| 64 | $self->{Cookie}->save(); | ||
| 65 | return 1; | ||
| 66 | } | ||
| 67 | |||
| 68 | |||
| 69 | # logout | ||
| 70 | sub logout{ | ||
| 71 | my $self = shift; | ||
| 72 | |||
| 73 | my $ua = LWP::UserAgent->new(keep_alive => 1, timeout => 300); | ||
| 74 | $ua->agent($self->{AgentIdent}); | ||
| 75 | $ua->cookie_jar($self->{Cookie}); | ||
| 76 | |||
| 77 | my $req = HTTP::Request->new(POST => 'http://www.lunarstorm.se/sys_exit.asp'); | ||
| 78 | $req->content_type('application/x-www-form-urlencoded'); | ||
| 79 | $req->referer('http://www.lunarstorm.se/log/log_outside.asp'); | ||
| 80 | $req->header('Accept' => 'text/xml,application/xml,application/xhtml+xml,text/html,text/plain'); | ||
| 81 | $self->{Cookie}->add_cookie_header($req); | ||
| 82 | |||
| 83 | my $res = $ua->request($req); | ||
| 84 | |||
| 85 | if(not ($res->is_success || $res->code == 302)){ | ||
| 86 | return 0; | ||
| 87 | } | ||
| 88 | |||
| 89 | return 1; | ||
| 90 | } | ||
| 91 | |||
| 92 | |||
| 93 | # visitors() | ||
| 94 | sub visitors{ | ||
| 95 | my $self = shift; | ||
| 96 | my $te = new HTML::TableExtract(depth => 2, count => 0, keep_html => 1); | ||
| 97 | |||
| 98 | my $ua = LWP::UserAgent->new(keep_alive => 1, timeout => 300); | ||
| 99 | $ua->agent($self->{AgentIdent}); | ||
| 100 | $ua->cookie_jar($self->{Cookie}); | ||
| 101 | |||
| 102 | my $req = HTTP::Request->new(POST => "http://www.lunarstorm.se/usr/usr_presentationlog.asp?username=$self->{Username}"); | ||
| 103 | $req->content_type('application/x-www-form-urlencoded'); | ||
| 104 | $req->referer('http://www.lunarstorm.se/usr/usr_presentation.asp'); | ||
| 105 | $req->header('Accept' => 'text/xml,application/xml,application/xhtml+xml,text/html,text/plain'); | ||
| 106 | $self->{Cookie}->add_cookie_header($req); | ||
| 107 | |||
| 108 | my $res = $ua->request($req); | ||
| 109 | |||
| 110 | if(not ($res->is_success || $res->code == 302)){ | ||
| 111 | return; | ||
| 112 | } | ||
| 113 | |||
| 114 | $te->parse($res->as_string); | ||
| 115 | my @items=(); | ||
| 116 | foreach my $ts ($te->table_states){ | ||
| 117 | foreach my $row ($ts->rows){ | ||
| 118 | my $item = @$row[1]; | ||
| 119 | my $userid=""; | ||
| 120 | my $nick=""; | ||
| 121 | my $sex="N"; | ||
| 122 | my $age=0; | ||
| 123 | my $city="N/A"; | ||
| 124 | my $state="N/A"; | ||
| 125 | |||
| 126 | if($item=~/userid=(%7B.*%7D)/){ | ||
| 127 | $userid=uri_unescape($1); | ||
| 128 | } | ||
| 129 | |||
| 130 | if($item=~/([\w\d_]+)\W(F|P)(\d+)/i){ | ||
| 131 | $nick=$1; | ||
| 132 | $sex=$2; | ||
| 133 | $age=$3; | ||
| 134 | } | ||
| 135 | $nick=~s/^\s//; | ||
| 136 | $nick=~s/\s$//; | ||
| 137 | |||
| 138 | my %item; | ||
| 139 | $item{NICK} = $nick; | ||
| 140 | $item{SEX} = $sex; | ||
| 141 | $item{AGE} = $age; | ||
| 142 | $item{CITY} = $city; | ||
| 143 | $item{STATE} = $state; | ||
| 144 | $item{USERID} = $userid; | ||
| 145 | push(@items, \%item); | ||
| 146 | } | ||
| 147 | } | ||
| 148 | |||
| 149 | shift(@items); | ||
| 150 | return @items; | ||
| 151 | } | ||
| 152 | |||
| 153 | |||
| 154 | # guestbook | ||
| 155 | sub guestbook{ | ||
| 156 | my ($self, $page, $userid) = @_; | ||
| 157 | |||
| 158 | $userid = $self->{UserID} if not defined $userid; | ||
| 159 | $page = 1 if not defined $page; | ||
| 160 | |||
| 161 | my $te = new HTML::TableExtract(depth => 2, count => 0, keep_html => 1); | ||
| 162 | |||
| 163 | my $ua = LWP::UserAgent->new(keep_alive => 1, timeout => 300); | ||
| 164 | $ua->agent($self->{AgentIdent}); | ||
| 165 | $ua->cookie_jar($self->{Cookie}); | ||
| 166 | |||
| 167 | my $req = HTTP::Request->new(POST => "http://www.lunarstorm.se/usr/gst_guestbook.asp?userid=$userid&page=$page"); | ||
| 168 | $req->content_type('application/x-www-form-urlencoded'); | ||
| 169 | $req->referer('http://www.lunarstorm.se/usr/usr_presentation.asp'); | ||
| 170 | $req->header('Accept' => 'text/xml,application/xml,application/xhtml+xml,text/html,text/plain'); | ||
| 171 | $self->{Cookie}->add_cookie_header($req); | ||
| 172 | |||
| 173 | my $res = $ua->request($req); | ||
| 174 | |||
| 175 | if(not ($res->is_success || $res->code == 302)){ | ||
| 176 | return; | ||
| 177 | } | ||
| 178 | |||
| 179 | $te->parse($res->as_string); | ||
| 180 | my @gb_items=(); | ||
| 181 | foreach my $ts ($te->table_states){ | ||
| 182 | foreach my $row ($ts->rows){ | ||
| 183 | my $gb_item = @$row[2]; | ||
| 184 | if(($gb_item=~/\(.*(obesvarat|oläst)\)/) || ($userid ne $self->{UserID})){ | ||
| 185 | my $userid_a; | ||
| 186 | my $guestnr=0; | ||
| 187 | my $nick=""; | ||
| 188 | my $sex="N"; | ||
| 189 | my $age=0; | ||
| 190 | my $city="N/A"; | ||
| 191 | my $state="N/A"; | ||
| 192 | |||
| 193 | if($gb_item=~/userid=({[\dA-F-]*})/){ | ||
| 194 | $userid_a=$1; | ||
| 195 | } | ||
| 196 | if($gb_item=~/guestnr=(\d*)/){ | ||
| 197 | $guestnr=$1; | ||
| 198 | } | ||
| 199 | |||
| 200 | $gb_item=~s/<br>/\n/igs; | ||
| 201 | $gb_item=~s/<(?:[^>'"]*|(['"]).*?\1)*>//gs; | ||
| 202 | |||
| 203 | my @tmp = split(/\n/, $gb_item); | ||
| 204 | shift(@tmp); | ||
| 205 | if($tmp[0]=~/([\w\d_]+)\W(F|P)(\d+) från (.+) i (.+) län/i){ | ||
| 206 | $nick=$1; $sex=$2; $age=$3; | ||
| 207 | $city=$4; $state=$5; | ||
| 208 | } | ||
| 209 | $nick=~s/^\s//; | ||
| 210 | $nick=~s/\s$//; | ||
| 211 | shift(@tmp); | ||
| 212 | $gb_item=join(' ', @tmp); | ||
| 213 | $gb_item=~s/^\s+//g; | ||
| 214 | $gb_item=~s/\s+$//g; | ||
| 215 | |||
| 216 | my %item; | ||
| 217 | $item{NICK} = $nick; | ||
| 218 | $item{SEX} = $sex; | ||
| 219 | $item{AGE} = $age; | ||
| 220 | $item{CITY} = $city; | ||
| 221 | $item{STATE} = $state; | ||
| 222 | $item{USERID} = $userid_a; | ||
| 223 | $item{GUESTNR} = $guestnr; | ||
| 224 | $item{TEXT} = $gb_item; | ||
| 225 | push(@gb_items, \%item); | ||
| 226 | } | ||
| 227 | } | ||
| 228 | } | ||
| 229 | |||
| 230 | return @gb_items; | ||
| 231 | } | ||
| 232 | |||
| 233 | |||
| 234 | # sign_guestbook | ||
| 235 | sub sign_guestbook{ | ||
| 236 | my ($self, $nick, $userid, $guestnr, $msg) = @_; | ||
| 237 | |||
| 238 | if(not $userid=~/{.*}/){ | ||
| 239 | $userid = uri_unescape($userid); | ||
| 240 | } | ||
| 241 | |||
| 242 | $msg = uri_escape($msg); | ||
| 243 | |||
| 244 | my $ua = LWP::UserAgent->new(keep_alive => 1, timeout => 300); | ||
| 245 | $ua->agent($self->{AgentIdent}); | ||
| 246 | $ua->cookie_jar($self->{Cookie}); | ||
| 247 | |||
| 248 | my $req = HTTP::Request->new(POST => 'http://www.lunarstorm.se/usr/gst_store.asp'); | ||
| 249 | $req->content_type('application/x-www-form-urlencoded'); | ||
| 250 | $req->content("guestnr=$guestnr&userid=$userid&username=$nick&source=popup&msgbody=$msg"); | ||
| 251 | $req->referer("http://www.lunarstorm.se/usr/gst_compose.asp?guestnr=$guestnr&userid=$userid&username=$nick"); | ||
| 252 | $req->header('Accept' => 'text/xml,application/xml,application/xhtml+xml,text/html,text/plain'); | ||
| 253 | $self->{Cookie}->add_cookie_header($req); | ||
| 254 | |||
| 255 | my $res = $ua->request($req); | ||
| 256 | |||
| 257 | if(not ($res->is_success || $res->code == 302)){ | ||
| 258 | return 0; | ||
| 259 | } | ||
| 260 | |||
| 261 | return 1; | ||
| 262 | } | ||
| 263 | |||
| 264 | |||
| 265 | # relations | ||
| 266 | sub relations{ | ||
| 267 | my ($self, $userid) = @_; | ||
| 268 | |||
| 269 | if(not $userid=~/{.*}/){ | ||
| 270 | $userid = uri_unescape($userid); | ||
| 271 | } | ||
| 272 | |||
| 273 | my $te = new HTML::TableExtract(depth => 2, count => 1, keep_html => 1); | ||
| 274 | |||
| 275 | my $ua = LWP::UserAgent->new(keep_alive => 1, timeout => 300); | ||
| 276 | $ua->agent($self->{AgentIdent}); | ||
| 277 | $ua->cookie_jar($self->{Cookie}); | ||
| 278 | |||
| 279 | my $req = HTTP::Request->new(POST => "http://www.lunarstorm.se/usr/fri_friends.asp?userid=$userid"); | ||
| 280 | $req->content_type('application/x-www-form-urlencoded'); | ||
| 281 | $req->referer('http://www.lunarstorm.se/usr/usr_presentation.asp'); | ||
| 282 | $req->header('Accept' => 'text/xml,application/xml,application/xhtml+xml,text/html,text/plain'); | ||
| 283 | $self->{Cookie}->add_cookie_header($req); | ||
| 284 | |||
| 285 | my $res = $ua->request($req); | ||
| 286 | |||
| 287 | if(not ($res->is_success || $res->code == 302)){ | ||
| 288 | return; | ||
| 289 | } | ||
| 290 | |||
| 291 | $te->parse($res->as_string); | ||
| 292 | my @friends=(); | ||
| 293 | foreach my $ts ($te->table_states){ | ||
| 294 | foreach my $row ($ts->rows){ | ||
| 295 | my $friend = @$row[2]; | ||
| 296 | my $userid; | ||
| 297 | if($friend=~/userid=({[\dA-F-]*})/i){ | ||
| 298 | $userid=$1; | ||
| 299 | } | ||
| 300 | |||
| 301 | $friend=~s/<(?:[^>'"]*|(['"]).*?\1)*>//gs; | ||
| 302 | |||
| 303 | if($friend=~/([\w\d_]+)\W(F|P)(\d+)/i){ | ||
| 304 | my $nick=$1; | ||
| 305 | my $sex="N"; | ||
| 306 | my $age=0; | ||
| 307 | my $city="N/A"; | ||
| 308 | my $state="N/A"; | ||
| 309 | $nick=~s/^\s//; | ||
| 310 | $nick=~s/\s$//; | ||
| 311 | |||
| 312 | my %item; | ||
| 313 | $item{NICK} = $nick; | ||
| 314 | $item{SEX} = $sex; | ||
| 315 | $item{AGE} = $age; | ||
| 316 | $item{CITY} = $city; | ||
| 317 | $item{STATE} = $state; | ||
| 318 | $item{USERID} = $userid; | ||
| 319 | push(@friends, \%item); | ||
| 320 | } | ||
| 321 | } | ||
| 322 | } | ||
| 323 | |||
| 324 | return @friends; | ||
| 325 | } | ||
| 326 | |||
| 327 | |||
| 328 | # scribbles | ||
| 329 | sub scribbles{ | ||
| 330 | my $self = shift; | ||
| 331 | |||
| 332 | my $te = new HTML::TableExtract(depth => 2, count => 0, keep_html => 1); | ||
| 333 | |||
| 334 | my $ua = LWP::UserAgent->new(keep_alive => 1, timeout => 300); | ||
| 335 | $ua->agent($self->{AgentIdent}); | ||
| 336 | $ua->cookie_jar($self->{Cookie}); | ||
| 337 | |||
| 338 | my $req = HTTP::Request->new(POST => "http://www.lunarstorm.se/bbs/bbs_main.asp"); | ||
| 339 | $req->content_type('application/x-www-form-urlencoded'); | ||
| 340 | $req->referer('http://www.lunarstorm.se/usr/usr_presentation.asp'); | ||
| 341 | $req->header('Accept' => 'text/xml,application/xml,application/xhtml+xml,text/html,text/plain'); | ||
| 342 | $self->{Cookie}->add_cookie_header($req); | ||
| 343 | |||
| 344 | my $res = $ua->request($req); | ||
| 345 | |||
| 346 | if(not ($res->is_success || $res->code == 302)){ | ||
| 347 | return; | ||
| 348 | } | ||
| 349 | |||
| 350 | $te->parse($res->as_string); | ||
| 351 | |||
| 352 | my @scribbles=(); | ||
| 353 | foreach my $ts ($te->table_states){ | ||
| 354 | foreach my $row ($ts->rows){ | ||
| 355 | my $scribble = @$row[2]; | ||
| 356 | my $userid=""; | ||
| 357 | my $nick=""; | ||
| 358 | my $sex="N"; | ||
| 359 | my $age=0; | ||
| 360 | my $city="N/A"; | ||
| 361 | my $state="N/A"; | ||
| 362 | |||
| 363 | if($scribble=~/userid=({[\dA-F-]*})/){ | ||
| 364 | $userid=$1; | ||
| 365 | } | ||
| 366 | |||
| 367 | $scribble=~s/<br>/\n/igs; | ||
| 368 | $scribble=~s/<(?:[^>'"]*|(['"]).*?\1)*>//gs; | ||
| 369 | |||
| 370 | if($scribble=~/([\w\d_]+)\W(F|P)(\d+) från (.+) i (.+) län/i){ | ||
| 371 | $nick=$1; $sex=$2; $age=$3; | ||
| 372 | $city=$4; $state=$5; | ||
| 373 | } | ||
| 374 | $nick=~s/^\s//; | ||
| 375 | $nick=~s/\s$//; | ||
| 376 | |||
| 377 | my @tmp = split(/\n/, $scribble); | ||
| 378 | shift(@tmp); | ||
| 379 | $scribble=join(' ', @tmp); | ||
| 380 | $scribble=~s/^\s+//g; | ||
| 381 | $scribble=~s/\s+$//g; | ||
| 382 | |||
| 383 | my %item; | ||
| 384 | $item{NICK} = $nick; | ||
| 385 | $item{SEX} = $sex; | ||
| 386 | $item{AGE} = $age; | ||
| 387 | $item{CITY} = $city; | ||
| 388 | $item{STATE} = $state; | ||
| 389 | $item{USERID} = $userid; | ||
| 390 | $item{TEXT} = $scribble; | ||
| 391 | push(@scribbles, \%item); | ||
| 392 | } | ||
| 393 | } | ||
| 394 | |||
| 395 | return @scribbles; | ||
| 396 | } | ||
| 397 | |||
| 398 | |||
| 399 | # scribble | ||
| 400 | sub scribble{ | ||
| 401 | my ($self, $scribble) = @_; | ||
| 402 | |||
| 403 | $scribble = uri_escape($scribble); | ||
| 404 | |||
| 405 | my $ua = LWP::UserAgent->new(keep_alive => 1, timeout => 300); | ||
| 406 | $ua->agent($self->{AgentIdent}); | ||
| 407 | $ua->cookie_jar($self->{Cookie}); | ||
| 408 | |||
| 409 | my $req = HTTP::Request->new(POST => 'http://www.lunarstorm.se/bbs/bbs_db.asp?status=insert'); | ||
| 410 | $req->content_type('application/x-www-form-urlencoded'); | ||
| 411 | $req->content("body=$scribble"); | ||
| 412 | $req->referer("http://www.lunarstorm.se/bbs/bbs_main.asp"); | ||
| 413 | $req->header('Accept' => 'text/xml,application/xml,application/xhtml+xml,text/html,text/plain'); | ||
| 414 | $self->{Cookie}->add_cookie_header($req); | ||
| 415 | |||
| 416 | my $res = $ua->request($req); | ||
| 417 | |||
| 418 | if(not ($res->is_success || $res->code == 302)){ | ||
| 419 | return 0; | ||
| 420 | } | ||
| 421 | |||
| 422 | return 1; | ||
| 423 | } | ||
| 424 | |||
| 425 | |||
| 426 | # relations_status | ||
| 427 | sub relations_status{ | ||
| 428 | my $self = shift; | ||
| 429 | |||
| 430 | my $te = new HTML::TableExtract(depth => 2, count => 0, keep_html => 1); | ||
| 431 | |||
| 432 | my $ua = LWP::UserAgent->new(keep_alive => 1, timeout => 300); | ||
| 433 | $ua->agent($self->{AgentIdent}); | ||
| 434 | $ua->cookie_jar($self->{Cookie}); | ||
| 435 | |||
| 436 | my $req = HTTP::Request->new(GET => 'http://www.lunarstorm.se/usr/fri_status.asp'); | ||
| 437 | $req->content_type('application/x-www-form-urlencoded'); | ||
| 438 | $req->referer('http://www.lunarstorm.se/usr/usr_presentation.asp'); | ||
| 439 | $req->header('Accept' => 'text/xml,application/xml,application/xhtml+xml,text/html,text/plain'); | ||
| 440 | $self->{Cookie}->add_cookie_header($req); | ||
| 441 | |||
| 442 | my $res = $ua->request($req); | ||
| 443 | |||
| 444 | if(not ($res->is_success || $res->code == 302)){ | ||
| 445 | return 0; | ||
| 446 | } | ||
| 447 | |||
| 448 | |||
| 449 | $te->parse($res->as_string); | ||
| 450 | |||
| 451 | my @relations=(); | ||
| 452 | foreach my $ts ($te->table_states){ | ||
| 453 | foreach my $row ($ts->rows){ | ||
| 454 | my $relation = @$row[0]; | ||
| 455 | my $userid=""; | ||
| 456 | my $nick=""; | ||
| 457 | my $sex="N"; | ||
| 458 | my $age=0; | ||
| 459 | my $city="N/A"; | ||
| 460 | my $state="N/A"; | ||
| 461 | my $type=""; | ||
| 462 | |||
| 463 | $relation=uri_unescape($relation); | ||
| 464 | |||
| 465 | if($relation=~/UserID=({[\dA-F-]*})/){ | ||
| 466 | $userid=$1; | ||
| 467 | } | ||
| 468 | |||
| 469 | $relation=~s/<(?:[^>'"]*|(['"]).*?\1)*>//gs; | ||
| 470 | |||
| 471 | if($relation=~/([\w\d_]+)\W(F|P)(\d+)/i){ | ||
| 472 | $nick=$1; | ||
| 473 | $sex=$2; | ||
| 474 | $age=$3; | ||
| 475 | } | ||
| 476 | $nick=~s/^\s//; | ||
| 477 | $nick=~s/\s$//; | ||
| 478 | |||
| 479 | if($relation=~/skapa relationen.(.+).med/){ | ||
| 480 | $type=$1; | ||
| 481 | }elsif($relation=~/hellre skapa relationen.(.+)\./){ | ||
| 482 | $type=$1; | ||
| 483 | }elsif($relation=~/avslutat/){ | ||
| 484 | $type="CLOSED"; | ||
| 485 | } | ||
| 486 | |||
| 487 | my %item; | ||
| 488 | $item{NICK} = $nick; | ||
| 489 | $item{SEX} = $sex; | ||
| 490 | $item{AGE} = $age; | ||
| 491 | $item{CITY} = $city; | ||
| 492 | $item{STATE} = $state; | ||
| 493 | $item{USERID} = $userid; | ||
| 494 | $item{TYPE} = $type; | ||
| 495 | if($nick){ | ||
| 496 | push(@relations, \%item); | ||
| 497 | } | ||
| 498 | } | ||
| 499 | } | ||
| 500 | |||
| 501 | return @relations; | ||
| 502 | } | ||
| 503 | |||
| 504 | |||
| 505 | # accept_relation | ||
| 506 | sub accept_relation{ | ||
| 507 | my ($self, $relation) = @_; | ||
| 508 | |||
| 509 | my $ua = LWP::UserAgent->new(keep_alive => 1, timeout => 300); | ||
| 510 | $ua->agent($self->{AgentIdent}); | ||
| 511 | $ua->cookie_jar($self->{Cookie}); | ||
| 512 | |||
| 513 | my $req; | ||
| 514 | if($relation->{TYPE} ne "CLOSED"){ | ||
| 515 | $req=HTTP::Request->new(POST => "http://www.lunarstorm.se/usr/fri_registration.asp?UserID=$relation->{USERID}&Action=ac&Part=3"); | ||
| 516 | }else{ | ||
| 517 | $req=HTTP::Request->new(POST => "http://www.lunarstorm.se/usr/fri_datamaster.asp?DMUserID=$relation->{USERID}&orgin=/usr/fri_status.asp&qs=&status=verify"); | ||
| 518 | } | ||
| 519 | $req->content_type('application/x-www-form-urlencoded'); | ||
| 520 | if($relation->{TYPE} ne "CLOSED"){ | ||
| 521 | $req->content("Stuff=1&Diary=1&Category=&Relation="); | ||
| 522 | } | ||
| 523 | $req->referer("http://www.lunarstorm.se/usr/fri_registration.asp"); | ||
| 524 | $req->header('Accept' => 'text/xml,application/xml,application/xhtml+xml,text/html,text/plain'); | ||
| 525 | $self->{Cookie}->add_cookie_header($req); | ||
| 526 | |||
| 527 | my $res = $ua->request($req); | ||
| 528 | |||
| 529 | if(not ($res->is_success || $res->code == 302)){ | ||
| 530 | return 0; | ||
| 531 | } | ||
| 532 | |||
| 533 | if($relation->{TYPE} ne "CLOSED"){ | ||
| 534 | $req=HTTP::Request->new(POST => "http://www.lunarstorm.se/usr/fri_registration.asp?UserID=$relation->{USERID}&Action=ac&Part=4"); | ||
| 535 | $req->content("COMMENT=&Category=&Relation=&Stuff=1&Diary=1"); | ||
| 536 | $res = $ua->request($req); | ||
| 537 | if(not ($res->is_success || $res->code == 302)){ | ||
| 538 | return 0; | ||
| 539 | } | ||
| 540 | } | ||
| 541 | |||
| 542 | return 1; | ||
| 543 | } | ||
| 544 | |||
| 545 | 1; | ||
| 546 | |||
| 547 | __END__ | ||