#!/usr/bin/perl
use strict;
# use warnings;
BEGIN {
use FindBin;
use lib ("$FindBin::Bin", "$FindBin::Bin/libs");
$ENV{TMPDIR} = $ENV{TEMP} || "";
};
delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; # Make %ENV safer =:-)
use CGI::Carp qw/fatalsToBrowser warningsToBrowser/;
use Sources::CGI;
use Sources::Global;
use Sources::Config;
use Sources::Benchmark;
my %Actions = (
first_of_all => {
libs => [
"Sources/Env.pm",
],
subs => [
\&Sources::Env::check,
],
},
admin => {
libs => [
"Sources/Session.pm",
"Sources/Env.pm",
"Sources/Admin.pm",
],
subs => [
\&Sources::Session::check,
\&Sources::Session::check_admin,
\&Sources::Env::global_set,
\&Sources::Global::write_standardhttp_header,
\&Sources::Admin::write_adminmask,
],
},
admin_global_save => {
libs => [
"Sources/Session.pm",
"Sources/Env.pm",
"Sources/Admin.pm",
],
subs => [
\&Sources::Session::check,
\&Sources::Session::check_admin,
\&Sources::Env::global_set,
\&Sources::Admin::handle_changes,
],
},
options => {
libs => [
"Sources/Session.pm",
"Sources/Env.pm",
"Sources/Options.pm",
],
subs => [
\&Sources::Session::check,
\&Sources::Env::global_set,
\&Sources::Global::write_standardhttp_header,
\&Sources::Options::write_optionsmask,
],
},
options_save => {
libs => [
"Sources/Session.pm",
"Sources/Env.pm",
"Sources/Options.pm",
],
subs => [
\&Sources::Session::check,
\&Sources::Env::global_set,
\&Sources::Options::handle_changes,
],
},
login => {
libs => [
"Sources/Env.pm",
"Sources/Authenticate.pm",
],
subs => [
\&Sources::Env::global_set,
\&Sources::Global::write_standardhttp_header,
\&Sources::Authenticate::write_loginmask,
],
},
login_auth => {
libs => [
"Sources/Authenticate.pm",
],
subs => [
\&Sources::Authenticate::auth_user,
],
},
folder_check => {
libs => [
"Sources/Session.pm",
"Sources/Env.pm",
"Sources/Cookie.pm",
"Sources/Folder.pm",
],
subs => [
\&Sources::Session::check,
\&Sources::Env::global_set,
\&Sources::Cookie::set_userdata,
# \&Sources::Global::write_standardhttp_header,
\&Sources::Folder::check_any,
],
},
folder_show => {
libs => [
"Sources/Session.pm",
"Sources/Env.pm",
"Sources/Cookie.pm",
"Sources/Folder.pm",
],
subs => [
\&Sources::Session::check,
\&Sources::Env::global_set,
\&Sources::Cookie::set_userdata,
# \&Sources::Global::write_standardhttp_header,
\&Sources::Folder::show_any,
],
},
process_msg => {
libs => [
"Sources/Session.pm",
"Sources/Env.pm",
"Sources/Folder.pm",
],
subs => [
\&Sources::Session::check,
\&Sources::Env::global_set,
\&Sources::Folder::process_msg,
],
},
mail_show => {
libs => [
"Sources/Session.pm",
"Sources/Env.pm",
"Sources/MailShow.pm",
],
subs => [
\&Sources::Session::check,
\&Sources::Env::global_set,
\&Sources::MailShow::check_exist,
\&Sources::MailShow::show,
],
},
mail_show_header => {
libs => [
"Sources/Session.pm",
"Sources/MailShow.pm",
],
subs => [
\&Sources::Benchmark::disable,
\&Sources::Session::check,
\&Sources::MailShow::check_exist,
\&Sources::MailShow::show_header,
],
},
mail_show_content => {
libs => [
"Sources/Session.pm",
"Sources/MailShow.pm",
],
subs => [
\&Sources::Benchmark::disable,
\&Sources::Session::check,
\&Sources::MailShow::check_exist,
\&Sources::MailShow::show_content,
],
},
mail_show_attachment => {
libs => [
"Sources/Session.pm",
"Sources/MailShow.pm",
],
subs => [
\&Sources::Benchmark::disable,
\&Sources::Session::check,
\&Sources::MailShow::check_exist,
\&Sources::MailShow::show_attachment,
],
},
mail_print_preview => {
libs => [
"Sources/Env.pm",
"Sources/Session.pm",
"Sources/MailShow.pm",
],
subs => [
\&Sources::Benchmark::disable,
\&Sources::Env::global_set,
\&Sources::Session::check,
\&Sources::MailShow::check_exist,
\&Sources::Global::write_standardhttp_header,
\&Sources::MailShow::print_preview,
],
},
mail_save_mail => {
libs => [
"Sources/Env.pm",
"Sources/Session.pm",
"Sources/MailShow.pm",
],
subs => [
\&Sources::Benchmark::disable,
\&Sources::Session::check,
\&Sources::Env::global_set,
\&Sources::MailShow::check_exist,
\&Sources::MailShow::save_mail,
],
},
mail_compose => {
libs => [
"Sources/Env.pm",
"Sources/Session.pm",
"Sources/MailCompose.pm",
],
subs => [
\&Sources::Session::check,
\&Sources::Env::global_set,
\&Sources::Global::write_standardhttp_header,
\&Sources::MailCompose::write_composemask,
],
},
mail_compose_submit => {
libs => [
"Sources/Env.pm",
"Sources/Session.pm",
"Sources/MailCompose.pm",
],
subs => [
\&Sources::Session::check,
\&Sources::Env::global_set,
\&Sources::MailCompose::submit,
],
},
mail_compose_attachments => {
libs => [
"Sources/Env.pm",
"Sources/Session.pm",
"Sources/MailCompose.pm",
],
subs => [
\&Sources::Session::check,
\&Sources::Env::global_set,
\&Sources::MailCompose::attachments,
],
},
mail_poller => {
libs => [
"Sources/Session.pm",
"Sources/Enc.pm",
"Sources/Folder/Inbox.pm",
],
subs => [
\&Sources::Benchmark::disable,
\&Sources::Session::check,
\&Sources::Env::global_set,
\&Sources::Folder::Inbox::poller,
],
},
logout => {
libs => [
"Sources/Cleanup.pm",
"Sources/Session.pm",
],
subs => [
\&Sources::Cleanup::start,
\&Sources::Session::logout,
],
},
);
sub handler
{
my ($obj, $defaction) = @_;
my $action = $defaction || lc($obj->{CGI}->getparam('action')) || 'login';
unless(exists $Actions{$action}->{subs}) { $action = 'login'; }
foreach my $lib (@{$Actions{$action}->{libs}})
{
# eval "require $lib";
require $lib;
}
foreach my $proc (@{$Actions{$action}->{subs}})
{
unless($proc->($obj))
{
# error in sub
last; # errorhandling
}
}
}
sub init
{
my ($obj) = @_;
Sources::Global::make_path($obj->{CFG}->lookup('foldersid'));
# Sources::Global::make_path($obj->{CFG}->lookup('folderexec'));
# Sources::Global::make_path($obj->{CFG}->lookup('foldertmp'));
Sources::Global::make_path($obj->{CFG}->lookup('folderuser'));
}
sub main
{
# Sources::Benchmark::start;
my $cfg = Sources::Config->new(-filename => Sources::Vars::FILE_GLOBALSETTINGS);
my $cgi = Sources::CGI->new();
my $obj = {};
$obj->{CGI} = $cgi;
$obj->{CFG} = $cfg;
init($obj);
handler($obj, 'first_of_all');
handler($obj);
# Sources::Benchmark::end;
# if(Sources::Benchmark::is_enabled())
# {
# Sources::Benchmark::show_stat($obj);
# }
}
main();
1;