unstable-Zweig als Kopie des "alten" trunks erstellt.
[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
34 # setup defaults, DO NOT CHANGE
35 $userspath = "users";
36 $templates = "templates";
37 $memberfile = "users/members";
38 $sendmail = "| /usr/sbin/sendmail -t";
39 ########## end ###########################################
40
41
42 $| = 1;
43
44 use SL::LXDebug;
45 $lxdebug = LXDebug->new();
46
47 eval { require "lx-erp.conf"; };
48
49 if ($ENV{CONTENT_LENGTH}) {
50   read(STDIN, $_, $ENV{CONTENT_LENGTH});
51 }
52
53 if ($ENV{QUERY_STRING}) {
54   $_ = $ENV{QUERY_STRING};
55 }
56
57 if ($ARGV[0]) {
58   $_ = $ARGV[0];
59 }
60
61
62 %form = split /[&=]/;
63
64 # fix for apache 2.0 bug
65 map { $form{$_} =~ s/\\$// } keys %form;
66
67 # name of this script
68 $0 =~ tr/\\/\//;
69 $pos = rindex $0, '/';
70 $script = substr($0, $pos + 1);
71
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
82 if ($form{path}) {
83   $form{path} =~ s/%2f/\//gi;
84   $form{path} =~ s/\.\.\///g;
85
86   if ($form{path} !~ /^bin\//) {
87     print "content-type: text/plain
88
89 Invalid path!\n";
90     die;
91   }
92
93
94   $ARGV[0] = "$_&script=$script";
95   require "$form{path}/$script";
96 } else {
97
98   if (!$form{terminal}) {
99     if ($ENV{HTTP_USER_AGENT}) {
100       # web browser
101       if ($ENV{HTTP_USER_AGENT} =~ /(mozilla|links|opera|w3m)/i) {
102         $form{terminal} = "mozilla";
103       }
104
105       if ($ENV{HTTP_USER_AGENT} =~ /lynx/i) {
106         $form{terminal} = "lynx";
107       }
108     } else {
109       if ($ENV{TERM} =~ /xterm/) {
110         $form{terminal} = "xterm";
111       }
112       if ($ENV{TERM} =~ /(console|linux|vt.*)/i) {
113         $form{terminal} = "console";
114       }
115     }
116   }
117
118
119   if ($form{terminal}) {
120
121     $ARGV[0] = "path=bin/$form{terminal}&script=$script";
122     map { $ARGV[0] .= "&${_}=$form{$_}" } keys %form;
123
124     require "bin/$form{terminal}/$script";
125     
126   } else {
127
128     print qq|
129   Unknown terminal
130   |;
131   }
132
133 }
134
135 # end of main
136