import sql-ledger 2.4.4
[freeside.git] / sql-ledger / 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 $spool = "spool";
37 $templates = "templates";
38 $memberfile = "users/members";
39 $sendmail = "| /usr/sbin/sendmail -t";
40 %printer = ( Printer => 'lpr' );
41 ########## end ###########################################
42
43
44 $| = 1;
45
46 eval { require "sql-ledger.conf"; };
47
48 if ($ENV{CONTENT_LENGTH}) {
49   read(STDIN, $_, $ENV{CONTENT_LENGTH});
50 }
51
52 if ($ENV{QUERY_STRING}) {
53   $_ = $ENV{QUERY_STRING};
54 }
55
56 if ($ARGV[0]) {
57   $_ = $ARGV[0];
58 }
59
60
61 %form = split /[&=]/;
62
63 # fix for apache 2.0 bug
64 map { $form{$_} =~ s/\\$// } keys %form;
65
66 # name of this script
67 $0 =~ tr/\\/\//;
68 $pos = rindex $0, '/';
69 $script = substr($0, $pos + 1);
70
71
72 if (-e "$userspath/nologin" && $script ne 'admin.pl') {
73   print "Content-Type: text/html\n\n" if $ENV{HTTP_USER_AGENT};
74   print "\nLogin disabled!\n";
75   exit;
76 }
77
78
79 if ($form{path}) {
80   $form{path} =~ s/%2f/\//gi;
81   $form{path} =~ s/\.\.\///g;
82
83   if ($form{path} !~ /^bin\//) {
84     print "Content-Type: text/html\n\n" if $ENV{HTTP_USER_AGENT};
85     print "\nInvalid path!\n";
86     exit;
87   }
88
89
90   $ARGV[0] = "$_&script=$script";
91   require "$form{path}/$script";
92 } else {
93
94   if (!$form{terminal}) {
95     if ($ENV{HTTP_USER_AGENT}) {
96       # web browser
97       $form{terminal} = "lynx";
98       if ($ENV{HTTP_USER_AGENT} !~ /lynx/i) {
99         $form{terminal} = "mozilla";
100         $form{jsc} = 1;
101       }
102     } else {
103       if ($ENV{TERM} =~ /xterm/) {
104         $form{terminal} = "xterm";
105       }
106       if ($ENV{TERM} =~ /(console|linux|vt.*)/i) {
107         $form{terminal} = "console";
108       }
109     }
110   }
111
112
113   if ($form{terminal}) {
114
115     $ARGV[0] = "path=bin/$form{terminal}&script=$script";
116     map { $ARGV[0] .= "&${_}=$form{$_}" } keys %form;
117
118     require "bin/$form{terminal}/$script";
119     
120   } else {
121
122     print "Content-Type: text/html\n\n" if $ENV{HTTP_USER_AGENT};
123     print qq|\nUnknown terminal\n|;
124   }
125
126 }
127
128 # end of main
129