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 status
{ $_[0]->http_headers( 'Status', $_[1] ); }
36 $self->http_headers( 'Location', $self->data->base_url() . $dir );
44 $self->{data
} = $data;
56 my $file = $self->{cgi
}->param($field);
57 my ($basename) = ($file =~ /([^\/\\]+)$/);
59 if (! grep(/^$dir$/, $self->upload_dirs())) {
60 croak
"Unauthorized upload directory $dir";
63 my $filename = $dir . '/' . $basename;
65 open F
, '>' . $filename or croak
"Can't write $filename";
77 my $obj = bless( { @_ }, $class );
79 $obj->{charset
} ||= 'UTF-8';
81 $obj->{http_headers
} = {
82 'Content-Type' => 'text/html; charset=' . $obj->{charset
},
83 'X-Gateway-Interface' => $ENV{'GATEWAY_INTERFACE'},
84 'X-Server-Name' => $ENV{'SERVER_NAME'}
87 $obj->{upload_dirs
} ||= [];
89 $obj->{cgi
} = CGI
->new();
98 my $data = $self->data();
99 my $vars = $self->vars();
101 $data->template->cgi_vars($vars);
103 if ($ENV{REMOTE_USER
} and my $u = $data->user($ENV{REMOTE_USER
})) {
106 elsif (my $cookie = $self->cookie()) {
107 if (my ($sid) = ($cookie =~ /^sid\s*=\s*(\d+)$/)) {
108 $data->auth_from_sid( $sid );
115 $st = uc($vars->{t
});
118 $st = 'INDEX' unless $st =~ /^[-\w0-9_]+$/;
120 # not identified nor users found?
121 if (!$data->auth() && ! $data->users()) {
123 # create the admin user
124 my $u = Gruta
::Data
::User
->new(
129 email
=> 'webmaster@localhost'
132 # set a random password (to be promptly changed)
133 $u->password(rand());
136 $data->insert_user($u);
138 # create a new session
139 my $session = Gruta
::Data
::Session
->new(user_id
=> 'admin');
140 $u->source->insert_session($session);
142 my $sid = $session->get('id');
143 $self->cookie("sid=$sid");
152 eval { $body = $data->template->process( $st ) };
156 # $self->redirect('?t=INDEX');
159 $body = "<h1>500 Internal Server Error</h1><p>$@</p>";
162 $self->http_headers('X-Powered-By' => 'Gruta ' . $self->data->version());
164 if (!$data->auth()) {
166 use Encode
qw(encode_utf8);
168 my $md5 = Digest
::MD5
->new();
169 $md5->add(encode_utf8
($body));
170 my $etag = $md5->hexdigest();
172 my $inm = $ENV{HTTP_IF_NONE_MATCH
} || '';
179 $self->http_headers('ETag' => $etag);
183 # does the client accept compression?
184 if (length($body) > 10000 && $ENV{HTTP_ACCEPT_ENCODING
} =~ /gzip/) {
188 if (my $cbody = Compress
::Zlib
::memGzip
($body)) {
189 $self->http_headers('Content-encoding' => 'gzip');
194 my $h = $self->http_headers();
195 foreach my $k (keys(%{ $h })) {
196 print $k, ': ', $h->{$k}, "\n";