use SL::Common;
use Form;
use List::Util qw(first);
-use Moose;
-use Rose::DB;
-use Rose::DB::Object;
use File::Basename;
# Trailing new line is added so that Perl will not add the line
use constant END_OF_REQUEST => "END-OF-REQUEST\n";
sub pre_request_checks {
- show_error('login/auth_db_unreachable') unless $::auth->session_tables_present;
+ if (!$::auth->session_tables_present) {
+ if ($::form->{script} eq 'admin.pl') {
+ ::run();
+ ::end_of_request();
+ } else {
+ show_error('login/auth_db_unreachable');
+ }
+ }
$::auth->expire_sessions;
}
require "bin/mozilla/installationcheck.pl";
} or die $EVAL_ERROR;
- # dummy globals
+ # canonial globals. if it's not here, chances are it will get refactored someday.
{
no warnings 'once';
- $::userspath = "users";
- $::templates = "templates";
- $::memberfile = "users/members";
- $::sendmail = "| /usr/sbin/sendmail -t";
- $::lxdebug = LXDebug->new;
- $::auth = SL::Auth->new;
- %::myconfig = ();
+ $::userspath = "users";
+ $::templates = "templates";
+ $::memberfile = "users/members";
+ $::menufile = "menu.ini";
+ $::sendmail = "| /usr/sbin/sendmail -t";
+ $::lxdebug = LXDebug->new;
+ $::auth = SL::Auth->new;
+ $::form = undef;
+ %::myconfig = ();
+ %::called_subs = (); # currently used for recursion detection
+ }
+
+ $SIG{__WARN__} = sub {
+ $::lxdebug->warn(@_);
}
}
}
sub require_main_code {
+ $::lxdebug->enter_sub;
my ($script, $suffix) = @_;
eval {
};
$::form->error($EVAL_ERROR) if ($EVAL_ERROR);
}
- if ($::form->{login} && -f "bin/mozilla/$::form->{login}_$::form->{script}") {
+ if ($::form->{login} && -f "bin/mozilla/$::form->{login}_$script") {
eval {
package main;
- require "bin/mozilla/$::form->{login}_$::form->{script}";
+ require "bin/mozilla/$::form->{login}_$script";
};
$::form->error($EVAL_ERROR) if ($EVAL_ERROR);
}
+ $::lxdebug->leave_sub;
}
sub handle_request {
my $interface = lc(shift || 'cgi');
my ($script_name, $action);
- if ($interface =~ m/^(?:fastcgi|fcgid|fcgi)$/) {
- $script_name = $ENV{SCRIPT_NAME};
- unrequire_bin_mozilla();
+ $script_name = $ENV{SCRIPT_NAME};
- } else {
- $script_name = $0;
- }
+ unrequire_bin_mozilla($interface);
- $::cgi = CGI->new('');
- $::locale = Locale->new($::language);
- $::form = Form->new;
+ $::cgi = CGI->new('');
+ $::locale = Locale->new($::language);
+ $::form = Form->new;
+ %::called_subs = ();
eval { ($script_name, $action) = _route_request($script_name); 1; } or return;
pre_request_checks();
eval {
+ $::form->error($::locale->text('System currently down for maintenance!')) if -e "$::userspath/nologin" && $script ne 'admin';
+
if ($script eq 'login' or $script eq 'admin' or $script eq 'kopf') {
$::form->{titlebar} = "Lx-Office " . $::locale->text('Version') . " $::form->{version}";
::run($::auth->restore_session);
- } elsif ($action) {
+ } else {
# copy from am.pl routines
- $::form->error($::locale->text('System currently down for maintenance!')) if -e "$main::userspath/nologin" && $script ne 'admin';
-
my $session_result = $::auth->restore_session;
show_error('login/password_error', 'session') if SL::Auth::SESSION_EXPIRED == $session_result;
$::auth->create_or_refresh_session;
delete $::form->{password};
- map { $::form->{$_} = $::myconfig{$_} } qw(stylesheet charset)
- unless $action eq 'save' && $::form->{type} eq 'preferences';
+ if ($action) {
+ map { $::form->{$_} = $::myconfig{$_} } qw(stylesheet charset)
+ unless $action eq 'save' && $::form->{type} eq 'preferences';
- $::form->set_standard_title;
- ::call_sub('::' . $::locale->findsub($action));
-
- } else {
- $::form->error($::locale->text('action= not defined!'));
+ $::form->set_standard_title;
+ ::call_sub('::' . $::locale->findsub($action));
+ } else {
+ $::form->error($::locale->text('action= not defined!'));
+ }
}
1;
}
sub unrequire_bin_mozilla {
+ return unless $_[0] =~ m/^(?:fastcgi|fcgid|fcgi)$/;
+
for (keys %INC) {
next unless m#^bin/mozilla/#;
next if /\bcommon.pl$/;
}
sub _route_dispatcher_request {
- my $action_re = '[a-z0-9_\-]+';
+ my $name_re = qr{[a-z]\w*};
my ($script_name, $action);
eval {
- die "Unroutable request -- inavlid module name.\n" if !$::form->{M} || ($::form->{M} !~ m/^$action_re$/);
+ die "Unroutable request -- inavlid module name.\n" if !$::form->{M} || ($::form->{M} !~ m/^${name_re}$/);
$script_name = $::form->{M} . '.pl';
if ($::form->{A}) {
$action = $::form->{A};
} else {
- $action = first { m/^A_${action_re}$/ } keys %{ $::form };
+ $action = first { m/^A_${name_re}$/ } keys %{ $::form };
die "Unroutable request -- inavlid action name.\n" if !$action;
delete $::form->{$action};