1 |
8 |
ahitrov@rambler.ru |
<%ARGS> |
2 |
|
|
$_URL => 'rate/ok.html' |
3 |
|
|
$id => undef |
4 |
|
|
$vote => undef |
5 |
|
|
</%ARGS> |
6 |
|
|
<%ONCE> |
7 |
|
|
use Apache::Cookie; |
8 |
|
|
use Rate::Main; |
9 |
|
|
</%ONCE> |
10 |
|
|
<%INIT> |
11 |
|
|
&abort404() unless ($id); |
12 |
|
|
&abort404() unless ($vote=~/^[1-5]$/); |
13 |
|
|
|
14 |
|
|
my $document; |
15 |
|
|
foreach (@{$state->rate->allowed_classes}) { |
16 |
|
|
$document = $keeper->get_document_by_id($id,class=>$_); |
17 |
|
|
last if $document; |
18 |
|
|
} |
19 |
|
|
&abort404() unless $document; |
20 |
|
|
|
21 |
|
|
my $ip = $r->header_in("X-Real-IP"); |
22 |
|
|
my (@ip_list) = split(/\s*,\s*/, $ip); |
23 |
|
|
my $real_ip = shift @ip_list; |
24 |
|
|
|
25 |
|
|
my $referer = $r->header_in("Referer"); |
26 |
|
|
|
27 |
|
|
|
28 |
|
|
my $cookie_name = $state->rate->cookie; |
29 |
|
|
my $cookie = Apache::Cookie->new($r); |
30 |
|
|
my $cookies = $cookie->parse; |
31 |
|
|
my $key = $cookies->{$cookie_name} ? $cookies->{$cookie_name}->value() : $real_ip; |
32 |
|
|
|
33 |
|
|
#here we have user key and both values |
34 |
|
|
Rate::Main->write_one($key, $id, $vote, $real_ip, $referer, time()); |
35 |
|
|
|
36 |
|
|
$_URL =~ s/^\///; |
37 |
|
|
$r->header_out("Location", "/".$_URL); |
38 |
|
|
$r->status(302); |
39 |
|
|
$r->send_http_header(); |
40 |
|
|
$m->out('<html><body>redirect</body></html>'); |
41 |
|
|
$m->abort(); |
42 |
|
|
</%INIT> |