9 $dir = Cwd::getcwd() . '/' . $dir unless $dir =~ m|^/|;
12 chdir($dir) || die "Cannot change directory to ${dir}\n";
14 unshift @INC, "modules/override"; # Use our own versions of various modules (e.g. YAML).
15 push @INC, "modules/fallback"; # Only use our own versions of modules if there's no system version.
18 use CGI qw( -no_xhtml);
24 use English qw(-no_match_vars);
25 use POSIX qw(setuid setgid);
27 use SL::DB::BackgroundJob;
28 use SL::BackgroundJob::ALL;
30 use SL::Helper::DateTime;
36 # this is a cleaned up version of am.pl
37 # it lacks redirection, some html setup and most of the authentication process.
38 # it is assumed that anyone with physical access and execution rights on this script
39 # won't be hindered by authentication anyway.
41 my $login = $lx_office_conf{task_server}->{login};
46 $::userspath = "users";
47 $::templates = "templates";
48 $::sendmail = "| /usr/sbin/sendmail -t";
51 eval { require "config/lx-erp.conf"; 1; } or die $EVAL_ERROR;
52 eval { require "config/lx-erp-local.conf"; 1; } or die $EVAL_ERROR if -f "config/lx-erp-local.conf";
54 $::lxdebug = LXDebug->new;
55 $::locale = Locale->new($::language);
56 $::cgi = CGI->new qw();
58 $::auth = SL::Auth->new;
60 die 'cannot reach auth db' unless $::auth->session_tables_present;
62 $::auth->restore_session;
64 require "bin/mozilla/common.pl";
66 die "cannot find user $login" unless %::myconfig = $::auth->read_user($login);
67 die "cannot find locale for user $login" unless $::locale = Locale->new('de');
71 my $user = $lx_office_conf{task_server}->{run_as};
75 while (my @details = getpwent()) {
76 next unless $details[0] eq $user;
77 ($uid, $gid) = @details[2, 3];
83 print "Error: Cannot drop privileges to ${user}: user does not exist\n";
88 print "Error: Cannot drop group privileges to ${user} (group ID $gid): $!\n";
93 print "Error: Cannot drop user privileges to ${user} (user ID $uid): $!\n";
101 read_config $self->{configfile} => %lx_office_conf;
103 die "Missing section [task_server] in config file" unless $lx_office_conf{task_server};
104 die "Missing key 'login' in section [task_server] in config file" unless $lx_office_conf{task_server}->{login};
115 $::lxdebug->message(0, "Retrieving jobs") if $lx_office_conf{task_server}->{debug};
117 my $jobs = SL::DB::Manager::BackgroundJob->get_all_need_to_run;
119 $::lxdebug->message(0, " Found: " . join(' ', map { $_->package_name } @{ $jobs })) if $lx_office_conf{task_server}->{debug} && @{ $jobs };
121 foreach my $job (@{ $jobs }) {
122 # Provide fresh global variables in case legacy code modifies
124 $::locale = Locale->new($::language);
133 if ($lx_office_conf{task_server}->{debug}) {
134 $::lxdebug->message(0, "Exception during execution: ${EVAL_ERROR}") if !$ok;
135 $::lxdebug->message(0, "Sleeping");
138 my $seconds = 60 - (localtime)[0];
139 sleep($seconds < 30 ? $seconds + 60 : $seconds);
144 my $pidbase = "${cwd}/users/pid";
146 mkdir($pidbase) if !-d $pidbase;
148 newdaemon(configfile => "${cwd}/config/lx_office.conf",
149 progname => 'lx-office-task-server',
150 pidbase => "${pidbase}/",