Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 201 lines (154 sloc) 4.658 kB
d64413f @ledger123 Initialized ledger123 git repos with 2.6.0
ledger123 authored
1 #!/usr/bin/perl
2 #
3 ######################################################################
7e8bc58 @ledger123 1. Version 2.8.0
ledger123 authored
4 # SQL-Ledger ERP
5 # Copyright (C) 2006
d64413f @ledger123 Initialized ledger123 git repos with 2.6.0
ledger123 authored
6 #
7e8bc58 @ledger123 1. Version 2.8.0
ledger123 authored
7 # Author: DWS Systems Inc.
8 # Web: http://www.sql-ledger.com
d64413f @ledger123 Initialized ledger123 git repos with 2.6.0
ledger123 authored
9 #
10 #######################################################################
11 #
12 # this script is the frontend called from bin/$terminal/$script
13 # all the accounting modules are linked to this script which in
14 # turn execute the same script in bin/$terminal/
15 #
16 #######################################################################
17
18 # setup defaults, DO NOT CHANGE
19 $userspath = "users";
20 $spool = "spool";
21 $templates = "templates";
22 $memberfile = "users/members";
23 $sendmail = "| /usr/sbin/sendmail -t";
1940bf6 @ledger123 Upgraded to 2.6.9
ledger123 authored
24 $latex = 0;
25 %printer = ();
d64413f @ledger123 Initialized ledger123 git repos with 2.6.0
ledger123 authored
26 ########## end ###########################################
27
28
29 $| = 1;
30
31 use SL::Form;
32
33 eval { require "sql-ledger.conf"; };
34
35 $form = new Form;
36
37
38 # name of this script
39 $0 =~ tr/\\/\//;
40 $pos = rindex $0, '/';
41 $script = substr($0, $pos + 1);
42
43 # we use $script for the language module
44 $form->{script} = $script;
45 # strip .pl for translation files
46 $script =~ s/\.pl//;
47
48 # pull in DBI
49 use DBI qw(:sql_types);
50
a0a6af0 @ledger123 1. Version 2.6.27
ledger123 authored
51 $form->{login} =~ s/(\.\.|\/|\\|\x00)//g;
52
d64413f @ledger123 Initialized ledger123 git repos with 2.6.0
ledger123 authored
53 # check for user config file, could be missing or ???
54 eval { require("$userspath/$form->{login}.conf"); };
7e8bc58 @ledger123 1. Version 2.8.0
ledger123 authored
55
d64413f @ledger123 Initialized ledger123 git repos with 2.6.0
ledger123 authored
56 if ($@) {
57 $locale = new Locale "$language", "$script";
58
59 $form->{callback} = "";
60 $msg1 = $locale->text('You are logged out!');
61 $msg2 = $locale->text('Login');
62 $form->redirect("$msg1 <p><a href=login.pl target=_top>$msg2</a>");
9a09dc6 @ledger123 1. Version 2.6.18
ledger123 authored
63 exit;
d64413f @ledger123 Initialized ledger123 git repos with 2.6.0
ledger123 authored
64 }
65
66 # locale messages
67 $locale = new Locale "$myconfig{countrycode}", "$script";
68 $form->{charset} = $locale->{charset};
69
70 # send warnings to browser
71 $SIG{__WARN__} = sub { $form->info($_[0]) };
72
73 # send errors to browser
1940bf6 @ledger123 Upgraded to 2.6.9
ledger123 authored
74 $SIG{__DIE__} = sub { $form->error($_[0]) };
d64413f @ledger123 Initialized ledger123 git repos with 2.6.0
ledger123 authored
75
76 $myconfig{dbpasswd} = unpack 'u', $myconfig{dbpasswd};
77 map { $form->{$_} = $myconfig{$_} } qw(stylesheet timeout) unless ($form->{type} eq 'preferences');
78
79 $form->{path} =~ s/\.\.\///g;
80 if ($form->{path} !~ /^bin\//) {
81 $form->error($locale->text('Invalid path!')."\n");
82 }
83
84 # did sysadmin lock us out
85 if (-f "$userspath/nologin") {
86 $form->error($locale->text('System currently down for maintenance!'));
87 }
88
89 # pull in the main code
90 require "$form->{path}/$form->{script}";
91
92 # customized scripts
93 if (-f "$form->{path}/custom_$form->{script}") {
94 eval { require "$form->{path}/custom_$form->{script}"; };
95 }
96
97 # customized scripts for login
98 if (-f "$form->{path}/$form->{login}_$form->{script}") {
99 eval { require "$form->{path}/$form->{login}_$form->{script}"; };
100 }
101
7e8bc58 @ledger123 1. Version 2.8.0
ledger123 authored
102
d64413f @ledger123 Initialized ledger123 git repos with 2.6.0
ledger123 authored
103 if ($form->{action}) {
104 # window title bar, user info
105 $form->{titlebar} = "SQL-Ledger ".$locale->text('Version'). " $form->{version} - $myconfig{name} - $myconfig{dbname}";
106
107 &check_password;
108
109 if (substr($form->{action}, 0, 1) =~ /( |\.)/) {
110 &{ $form->{nextsub} };
111 } else {
112 &{ $locale->findsub($form->{action}) };
113 }
114 } else {
115 $form->error($locale->text('action= not defined!'));
116 }
117
118 1;
119 # end
120
121
122 sub check_password {
7e8bc58 @ledger123 1. Version 2.8.0
ledger123 authored
123
d64413f @ledger123 Initialized ledger123 git repos with 2.6.0
ledger123 authored
124 if ($myconfig{password}) {
125
126 require "$form->{path}/pw.pl";
127
128 if ($form->{password}) {
129 if ((crypt $form->{password}, substr($form->{login}, 0, 2)) ne $myconfig{password}) {
1940bf6 @ledger123 Upgraded to 2.6.9
ledger123 authored
130 if ($ENV{HTTP_USER_AGENT}) {
131 &getpassword;
132 } else {
133 $form->error($locale->text('Access Denied!'));
134 }
d64413f @ledger123 Initialized ledger123 git repos with 2.6.0
ledger123 authored
135 exit;
9a09dc6 @ledger123 1. Version 2.6.18
ledger123 authored
136 } else {
137 # password checked out, create session
138 if ($ENV{HTTP_USER_AGENT}) {
139 # create new session
140 use SL::User;
141 $user = new User $memberfile, $form->{login};
142 $user->{password} = $form->{password};
143 $user->create_config("$userspath/$form->{login}.conf");
144 $form->{sessioncookie} = $user->{sessioncookie};
145 }
d64413f @ledger123 Initialized ledger123 git repos with 2.6.0
ledger123 authored
146 }
147 } else {
7e8bc58 @ledger123 1. Version 2.8.0
ledger123 authored
148
d64413f @ledger123 Initialized ledger123 git repos with 2.6.0
ledger123 authored
149 if ($ENV{HTTP_USER_AGENT}) {
150 $ENV{HTTP_COOKIE} =~ s/;\s*/;/g;
d18c0e8 @ledger123 Upgraded to 2.6.3
ledger123 authored
151 @cookies = split /;/, $ENV{HTTP_COOKIE};
7e8bc58 @ledger123 1. Version 2.8.0
ledger123 authored
152 %cookie = ();
d18c0e8 @ledger123 Upgraded to 2.6.3
ledger123 authored
153 foreach (@cookies) {
154 ($name,$value) = split /=/, $_, 2;
155 $cookie{$name} = $value;
156 }
7e8bc58 @ledger123 1. Version 2.8.0
ledger123 authored
157
9a09dc6 @ledger123 1. Version 2.6.18
ledger123 authored
158 if ($cookie{"SL-$form->{login}"}) {
7e8bc58 @ledger123 1. Version 2.8.0
ledger123 authored
159
9a09dc6 @ledger123 1. Version 2.6.18
ledger123 authored
160 $form->{sessioncookie} = $cookie{"SL-$form->{login}"};
7e8bc58 @ledger123 1. Version 2.8.0
ledger123 authored
161
9a09dc6 @ledger123 1. Version 2.6.18
ledger123 authored
162 $s = "";
163 %ndx = ();
164 $l = length $form->{sessioncookie};
7e8bc58 @ledger123 1. Version 2.8.0
ledger123 authored
165
9a09dc6 @ledger123 1. Version 2.6.18
ledger123 authored
166 for $i (0 .. $l - 1) {
167 $j = substr($myconfig{sessionkey}, $i * 2, 2);
168 $ndx{$j} = substr($cookie{"SL-$form->{login}"}, $i, 1);
169 }
170
171 for (sort keys %ndx) {
172 $s .= $ndx{$_};
173 }
174
175 $l = length $form->{login};
176 $login = substr($s, 0, $l);
177 $password = substr($s, $l, (length $s) - ($l + 10));
178
7e8bc58 @ledger123 1. Version 2.8.0
ledger123 authored
179 # validate cookie
d8a6d40 @ledger123 1. Version 2.6.20
ledger123 authored
180 if (($login ne $form->{login}) || ($myconfig{password} ne crypt $password, substr($form->{login}, 0, 2))) {
d64413f @ledger123 Initialized ledger123 git repos with 2.6.0
ledger123 authored
181 &getpassword(1);
182 exit;
183 }
9a09dc6 @ledger123 1. Version 2.6.18
ledger123 authored
184
185 } else {
186
187 if ($form->{action} ne 'display') {
7e8bc58 @ledger123 1. Version 2.8.0
ledger123 authored
188 &getpassword(1);
9a09dc6 @ledger123 1. Version 2.6.18
ledger123 authored
189 exit;
190 }
191
d64413f @ledger123 Initialized ledger123 git repos with 2.6.0
ledger123 authored
192 }
1940bf6 @ledger123 Upgraded to 2.6.9
ledger123 authored
193 } else {
194 exit;
d64413f @ledger123 Initialized ledger123 git repos with 2.6.0
ledger123 authored
195 }
196 }
197 }
198 }
199
200
Something went wrong with that request. Please try again.