| 1 |
101 |
dpavlin |
#!/usr/bin/perl -w |
| 2 |
|
|
|
| 3 |
|
|
use strict; |
| 4 |
|
|
use lib './lib'; |
| 5 |
|
|
use Webnote; |
| 6 |
|
|
use PHP::Session; |
| 7 |
|
|
use Data::Dumper; |
| 8 |
|
|
|
| 9 |
|
|
my $wn = new Webnote( |
| 10 |
136 |
dpavlin |
dsn => 'dbi:Pg:dbname=strix', |
| 11 |
|
|
db_user => 'web', |
| 12 |
101 |
dpavlin |
db_passwd => '', |
| 13 |
|
|
db_codepage => 'ISO-8859-2', |
| 14 |
136 |
dpavlin |
adminEmail => 'nobody@localhost', |
| 15 |
|
|
debug => 0, |
| 16 |
101 |
dpavlin |
); |
| 17 |
|
|
|
| 18 |
|
|
my $session_name = 'PLIVAweb'; |
| 19 |
|
|
|
| 20 |
|
|
$wn->run( default => sub { |
| 21 |
|
|
my $self = shift; |
| 22 |
|
|
|
| 23 |
|
|
my $cgi = $wn->{'cgi'} || die "no cgi?"; |
| 24 |
|
|
if (my $cookie = $cgi->cookie( $session_name )) { |
| 25 |
|
|
my $session = PHP::Session->new($cookie); |
| 26 |
|
|
my $nick = $session->get('_s_pod')->{'nick'} || |
| 27 |
|
|
die "can't find nick!"; |
| 28 |
136 |
dpavlin |
my $sth = $self->{'dbh'}->prepare(qq{ |
| 29 |
|
|
select UserCanDoOnObject(?, 'PERM_WRITE', 'kats', ?) |
| 30 |
|
|
}) || die $self->{'dbh'}->errstr(); |
| 31 |
|
|
$sth->execute( |
| 32 |
|
|
$session->get('_s_pod')->{'uid'}, |
| 33 |
|
|
$session->get('_s_pod')->{'kid'}, |
| 34 |
|
|
) || die $sth->errstr(); |
| 35 |
|
|
|
| 36 |
|
|
my ($access_ok) = $sth->fetchrow_array; |
| 37 |
|
|
|
| 38 |
|
|
if ($access_ok) { |
| 39 |
|
|
$self->load($nick); |
| 40 |
|
|
} else { |
| 41 |
|
|
print $cgi->header, |
| 42 |
|
|
"You need to be logged in to access this resource"; |
| 43 |
|
|
} |
| 44 |
101 |
dpavlin |
} else { |
| 45 |
|
|
print $cgi->header, |
| 46 |
|
|
"can't find session cookie $session_name"; |
| 47 |
|
|
} |
| 48 |
|
|
return 1; |
| 49 |
|
|
} ); |
| 50 |
|
|
|