6 sub vars
{ return $_[0]->{cgi
}->Vars(); }
7 sub upload_dirs
{ return @
{ $_[0]->{upload_dirs
} }; }
13 foreach my $k (keys(%headers)) {
14 $self->{http_headers
}->{$k} = $headers{$k};
17 return $self->{http_headers
};
24 $self->http_headers( 'Set-Cookie', shift );
27 return $ENV{HTTP_COOKIE
};
30 sub redirect
{ $_[0]->http_headers( 'Location', $_[1] ); }
31 sub status
{ $_[0]->http_headers( 'Status', $_[1] ); }
38 $self->{data
} = $data;
50 my $file = $self->{cgi
}->param($field);
51 my ($basename) = ($file =~ /([^\/\\]+)$/);
53 if (! grep(/^$dir$/, $self->upload_dirs())) {
54 croak
"Unauthorized upload directory $dir";
57 my $filename = $dir . '/' . $basename;
59 open F
, '>' . $filename or croak
"Can't write $filename";
71 my $obj = bless( { @_ }, $class );
73 $obj->{charset
} ||= 'UTF-8';
75 $obj->{http_headers
} = {
76 'Content-Type' => 'text/html; charset=' . $obj->{charset
},
77 'X-Gateway-Interface' => $ENV{'GATEWAY_INTERFACE'},
78 'X-Server-Name' => $ENV{'SERVER_NAME'}
81 $obj->{upload_dirs
} ||= [];
83 $obj->{cgi
} = CGI
->new();
92 my $data = $self->data();
93 my $vars = $self->vars();
95 $data->template->cgi_vars($vars);
97 if ($ENV{REMOTE_USER
} and my $u = $data->user($ENV{REMOTE_USER
})) {
100 elsif (my $cookie = $self->cookie()) {
101 if (my ($sid) = ($cookie =~ /^sid\s*=\s*(\d+)$/)) {
102 $data->auth_from_sid( $sid );
109 $st = uc($vars->{t
});
112 $st = 'INDEX' unless $st =~ /^[-\w0-9_]+$/;
114 # not identified nor users found?
115 if (!$data->auth() && ! $data->users()) {
117 # create the admin user
118 my $u = Gruta
::Data
::User
->new(
123 email
=> 'webmaster@localhost'
126 # set a random password (to be promptly changed)
127 $u->password(rand());
130 $data->insert_user($u);
132 # create a new session
133 my $session = Gruta
::Data
::Session
->new(user_id
=> 'admin');
134 $u->source->insert_session($session);
136 my $sid = $session->get('id');
137 $self->cookie("sid=$sid");
146 eval { $body = $data->template->process( $st ) };
150 # $self->redirect('?t=INDEX');
151 $body = "<pre>$@</pre>";
154 $self->http_headers('X-Powered-By' => 'Gruta ' . $self->data->version());
156 if (!$data->auth()) {
158 use Encode
qw(encode_utf8);
160 my $md5 = Digest
::MD5
->new();
161 $md5->add(encode_utf8
($body));
162 my $etag = $md5->hexdigest();
164 my $inm = $ENV{HTTP_IF_NONE_MATCH
} || '';
171 $self->http_headers('ETag' => $etag);
175 my $h = $self->http_headers();
176 foreach my $k (keys(%{ $h })) {
177 print $k, ': ', $h->{$k}, "\n";