Die bei Lx-Office mitgelieferten Perl-Module, die nicht zu Lx-Office selber gehören...
[kivitendo-erp.git] / login.pl
1 #!/usr/bin/perl
2 #
3 ######################################################################
4 # SQL-Ledger Accounting
5 # Copyright (C) 2001
6 #
7 #  Author: Dieter Simader
8 #   Email: dsimader@sql-ledger.org
9 #     Web: http://www.sql-ledger.org
10 #
11 #  Contributors:
12 #
13 # This program is free software; you can redistribute it and/or modify
14 # it under the terms of the GNU General Public License as published by
15 # the Free Software Foundation; either version 2 of the License, or
16 # (at your option) any later version.
17 #
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 # GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write to the Free Software
24 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #######################################################################
26 #
27 # this script sets up the terminal and runs the scripts
28 # in bin/$terminal directory
29 # admin.pl is linked to this script
30 #
31 #######################################################################
32
33 BEGIN {
34   push(@INC, "modules");
35 }
36
37 # setup defaults, DO NOT CHANGE
38 $userspath  = "users";
39 $templates  = "templates";
40 $memberfile = "users/members";
41 $sendmail   = "| /usr/sbin/sendmail -t";
42 ########## end ###########################################
43
44 $| = 1;
45
46 use SL::LXDebug;
47 $lxdebug = LXDebug->new();
48
49 eval { require "lx-erp.conf"; };
50
51 if ($ENV{CONTENT_LENGTH}) {
52   read(STDIN, $_, $ENV{CONTENT_LENGTH});
53 }
54
55 if ($ENV{QUERY_STRING}) {
56   $_ = $ENV{QUERY_STRING};
57 }
58
59 if ($ARGV[0]) {
60   $_ = $ARGV[0];
61 }
62
63 %form = split /[&=]/;
64
65 # fix for apache 2.0 bug
66 map { $form{$_} =~ s/\\$// } keys %form;
67
68 # name of this script
69 $0 =~ tr/\\/\//;
70 $pos = rindex $0, '/';
71 $script = substr($0, $pos + 1);
72
73 if (-e "$userspath/nologin" && $script ne 'admin.pl') {
74   print "content-type: text/plain
75
76 Login disabled!\n";
77
78   exit;
79 }
80
81 require "bin/mozilla/installationcheck.pl";
82 verify_installation();
83
84 if ($form{path}) {
85   $form{path} =~ s/%2f/\//gi;
86   $form{path} =~ s/\.\.\///g;
87
88   if ($form{path} !~ /^bin\//) {
89     print "content-type: text/plain
90
91 Invalid path!\n";
92     die;
93   }
94
95   $ARGV[0] = "$_&script=$script";
96   require "$form{path}/$script";
97 } else {
98
99   if (!$form{terminal}) {
100     if ($ENV{HTTP_USER_AGENT}) {
101
102       # web browser
103       if ($ENV{HTTP_USER_AGENT} =~ /(mozilla|links|opera|w3m)/i) {
104         $form{terminal} = "mozilla";
105       }
106
107     } else {
108       if ($ENV{TERM} =~ /xterm/) {
109         $form{terminal} = "xterm";
110       }
111       if ($ENV{TERM} =~ /(console|linux|vt.*)/i) {
112         $form{terminal} = "console";
113       }
114     }
115   }
116
117   if ($form{terminal}) {
118
119     $ARGV[0] = "path=bin/$form{terminal}&script=$script";
120     map { $ARGV[0] .= "&${_}=$form{$_}" } keys %form;
121
122     require "bin/$form{terminal}/$script";
123
124   } else {
125
126     print qq|
127   Unknown terminal
128   |;
129   }
130
131 }
132
133 # end of main
134