fs_passwd.cgi
[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, these are overidden by sql-ledger.conf
35 # DO NOT CHANGE
36 $userspath = "users";
37 $templates = "templates";
38 $memberfile = "users/members";
39 $sendmail = "| /usr/sbin/sendmail -t";
40 ########## end ###########################################
41
42
43 $| = 1;
44
45 eval { require "sql-ledger.conf"; };
46
47 if (-e "$userspath/nologin") {
48   print "
49 Login disabled!\n";
50
51   exit;
52 }
53
54
55 if ($ENV{CONTENT_LENGTH}) {
56   read(STDIN, $_, $ENV{CONTENT_LENGTH});
57 }
58
59 if ($ENV{QUERY_STRING}) {
60   $_ = $ENV{QUERY_STRING};
61 }
62
63 if ($ARGV[0]) {
64   $_ = $ARGV[0];
65 }
66
67
68 %form = split /[&=]/;
69
70 # fix for apache 2.0
71 map { $form{$_} =~ s/\\$// } keys %form;
72
73 # name of this script
74 $0 =~ tr/\\/\//;
75 $pos = rindex $0, '/';
76 $script = substr($0, $pos + 1);
77
78
79 if ($form{path}) {
80   $form{path} =~ s/%2[fF]/\//g;
81   $form{path} =~ s/\.\.\///g;
82
83   if ($form{path} !~ /^bin\//) {
84     print "
85 Invalid path!\n";
86     die;
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       if ($ENV{HTTP_USER_AGENT} =~ /(mozilla|links|opera|w3m)/i) {
98         $form{terminal} = "mozilla";
99       }
100
101       if ($ENV{HTTP_USER_AGENT} =~ /lynx/i) {
102         $form{terminal} = "lynx";
103       }
104     } else {
105       if ($ENV{TERM} =~ /xterm/) {
106         $form{terminal} = "xterm";
107       }
108       if ($ENV{TERM} =~ /(console|linux|vt.*)/i) {
109         $form{terminal} = "console";
110       }
111     }
112   }
113
114
115   if ($form{terminal}) {
116
117     $ARGV[0] = "path=bin/$form{terminal}&script=$script";
118     map { $ARGV[0] .= "&${_}=$form{$_}" } keys %form;
119
120     require "bin/$form{terminal}/$script";
121     
122   } else {
123
124     print qq|
125   Unknown terminal
126   |;
127   }
128
129 }
130
131 # end of main
132