| 1 | package AxKit::App::TABOO; | ||
| 2 | |||
| 3 | our $VERSION = '0.52'; | ||
| 4 | |||
| 5 | 1 | ▶ | use 5.7.3; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | |||
| 9 | 1 | ▶ | use Session; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | 0 | ▶ | use Apache; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 11 | use Apache::Cookie; | ||
| 12 | use Apache::Request; | ||
| 13 | use AxKit; | ||
| 14 | |||
| 15 | sub session_config { | ||
| 16 | my $r = shift; | ||
| 17 | my $prefix = $r->dir_config( 'TABOOPrefix') || 'TABOO'; | ||
| 18 | my %session_config = ( | ||
| 19 | Store => $r->dir_config( $prefix . 'DataStore' ) || 'DB_File', | ||
| 20 | Lock => $r->dir_config( $prefix . 'Lock' ) || 'Null', | ||
| 21 | Generate => $r->dir_config( $prefix . 'Generate' ) || 'MD5', | ||
| 22 | Serialize => $r->dir_config( $prefix . 'Serialize' ) || 'Storable' | ||
| 23 | ); | ||
| 24 | |||
| 25 | # When using Postgres, a different default is needed. | ||
| 26 | if ($session_config{'Store'} eq 'Postgres') { | ||
| 27 | $session_config{'Commit'} = 1; | ||
| 28 | $session_config{'Serialize'} = $r->dir_config( $prefix . 'Serialize' ) || 'Base64' | ||
| 29 | } | ||
| 30 | |||
| 31 | |||
| 32 | # Load session-type specific parameters, comma-separated, name => value pairs | ||
| 33 | foreach my $arg ( split( /\s*,\s*/, $r->dir_config($prefix . 'Args'))) { | ||
| 34 | my ($key, $value) = split( /\s*=>\s*/, $arg ); | ||
| 35 | $session_config{$key} = $value; | ||
| 36 | } | ||
| 37 | |||
| 38 | return %session_config; | ||
| 39 | } | ||
| 40 | |||
| 41 | sub session { | ||
| 42 | my $r = shift; | ||
| 43 | my $req = Apache::Request->instance($r); | ||
| 44 | my $vid = $req->param('VID'); | ||
| 45 | unless ($vid) { # Then look in the cookie | ||
| 46 | my $cookies = Apache::Cookie->fetch; | ||
| 47 | my $tmp = $cookies->{'VID'}; | ||
| 48 | return undef unless defined($tmp); | ||
| 49 | $vid = $tmp->value; | ||
| 50 | return undef unless ($vid); # No session key | ||
| 51 | } | ||
| 52 | AxKit::Debug(9, "User's visitor ID: $vid"); | ||
| 53 | return new Session $vid, session_config($r); | ||
| 54 | } | ||
| 55 | |||
| 56 | |||
| 57 | sub authlevel { | ||
| 58 | my $session = shift; | ||
| 59 | if (defined($session)) { | ||
| 60 | return $session->get('authlevel'); | ||
| 61 | } else { | ||
| 62 | return 0; | ||
| 63 | } | ||
| 64 | } | ||
| 65 | |||
| 66 | sub loggedin { | ||
| 67 | my $session = shift; | ||
| 68 | if (defined($session)) { | ||
| 69 | return $session->get('loggedin'); | ||
| 70 | } else { | ||
| 71 | return 'guest'; | ||
| 72 | } | ||
| 73 | } | ||
| 74 | |||
| 75 | 1; | ||
| 76 | __END__ | ||