Eine Funktion zum "sicheren" Aufrufen von Unterfunktionen eingebaut, damit &{ $form...
[kivitendo-erp.git] / bin / mozilla / login.pl
1 #=====================================================================
2 # LX-Office ERP
3 # Copyright (C) 2004
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
6 #
7 ######################################################################
8 # SQL-Ledger Accounting
9 # Copyright (c) 1998-2002
10 #
11 #  Author: Dieter Simader
12 #   Email: dsimader@sql-ledger.org
13 #     Web: http://www.sql-ledger.org
14 #
15 #
16 # This program is free software; you can redistribute it and/or modify
17 # it under the terms of the GNU General Public License as published by
18 # the Free Software Foundation; either version 2 of the License, or
19 # (at your option) any later version.
20 #
21 # This program is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #######################################################################
29
30 use DBI;
31 use SL::User;
32 use SL::Form;
33
34 require "bin/mozilla/common.pl";
35
36 $form = new Form;
37
38 $locale = new Locale $language, "login";
39
40 # customization
41 if (-f "$form->{path}/custom_$form->{script}") {
42   eval { require "$form->{path}/custom_$form->{script}"; };
43   $form->error($@) if ($@);
44 }
45
46 # per login customization
47 if (-f "$form->{path}/$form->{login}_$form->{script}") {
48   eval { require "$form->{path}/$form->{login}_$form->{script}"; };
49   $form->error($@) if ($@);
50 }
51
52 # window title bar, user info
53 $form->{titlebar} =
54   "Lx-Office " . $locale->text('Version') . " $form->{version}";
55
56 if ($form->{action}) {
57   $form->{titlebar} .= " - $myconfig{name} - $myconfig{dbname}";
58   call_sub($locale->findsub($form->{action}));
59 } else {
60   &login_screen;
61 }
62
63 1;
64
65 sub login_screen {
66   $lxdebug->enter_sub();
67
68   if (-f "css/lx-office-erp.css") {
69     $form->{stylesheet} = "lx-office-erp.css";
70   }
71
72   $form->{fokus} = "loginscreen.login";
73   $form->header;
74
75   print qq|
76
77
78 <body class=login onLoad="fokus()">
79
80 <pre>
81
82 </pre>
83
84 <center>
85 <table class=login border=3 cellpadding=20>
86   <tr>
87     <td class=login align=center><a href="http://www.lx-office.org" target=_top><img src="image/lx-office-erp.png" border=0></a>
88 <h1 class=login align=center>|
89     . $locale->text('Version') . qq| $form->{version}
90 </h1>
91
92 <p>
93
94 <form method=post name=loginscreen action=$form->{script}>
95
96   <input type="hidden" name="show_dbupdate_warning" value="1">
97
98       <table width=100%>
99         <tr>
100           <td align=center>
101             <table>
102               <tr>
103                 <th align=right>| . $locale->text('Login Name') . qq|</th>
104                 <td><input class=login name=login size=30 tabindex="1"></td>
105               </tr>
106               <tr>
107                 <th align=right>| . $locale->text('Password') . qq|</th>
108                 <td><input class=login type=password name=password size=30 tabindex="2"></td>
109               </tr>
110               <input type=hidden name=path value=$form->{path}>
111             </table>
112
113             <br>
114             <input type=submit name=action value="| . $locale->text('Login') . qq|" tabindex="3">
115
116           </td>
117         </tr>
118       </table>
119
120 </form>
121
122     </td>
123   </tr>
124 </table>
125
126 </body>
127 </html>
128 |;
129
130   $lxdebug->leave_sub();
131 }
132
133 sub login {
134   $lxdebug->enter_sub();
135
136   $form->error($locale->text('You did not enter a name!'))
137     unless ($form->{login});
138
139   $user = new User $memberfile, $form->{login};
140
141   # if we get an error back, bale out
142   if (($errno = $user->login(\%$form, $userspath)) <= -1) {
143     $errno *= -1;
144     $err[1] = $err[3] = $locale->text('Incorrect username or password!');
145
146     if ($errno == 2) {
147       exit;
148     }
149
150     $form->error($err[$errno]);
151   }
152
153   # made it this far, execute the menu
154   if ($user->{menustyle} eq "v3") {
155     $form->{callback} =
156       "menuv3.pl?login=$form->{login}&password=$form->{password}&path=$form->{path}&action=display";
157   } elsif ($user->{menustyle} eq "neu") {
158     $form->{callback} =
159       "menunew.pl?login=$form->{login}&password=$form->{password}&path=$form->{path}&action=display";
160   } else {
161     $form->{callback} =
162       "menu.pl?login=$form->{login}&password=$form->{password}&path=$form->{path}&action=display";
163   }
164
165   $form->redirect;
166
167   $lxdebug->leave_sub();
168 }
169
170 sub logout {
171   $lxdebug->enter_sub();
172
173   unlink "$userspath/$form->{login}.conf";
174
175   # remove the callback to display the message
176   $form->{callback} = "login.pl?path=$form->{path}&action=&login=";
177   $form->redirect($locale->text('You are logged out!'));
178
179   $lxdebug->leave_sub();
180 }
181
182 sub company_logo {
183   $lxdebug->enter_sub();
184
185   require "$userspath/$form->{login}.conf";
186   $locale = new Locale $myconfig{countrycode}, "login"
187     unless ($language eq $myconfig{countrycode});
188
189   $myconfig{address} =~ s/\\n/<br>/g;
190   $myconfig{dbhost} = $locale->text('localhost') unless $myconfig{dbhost};
191
192   map { $form->{$_} = $myconfig{$_} } qw(charset stylesheet);
193
194   $form->{title} = $locale->text('About');
195
196   # create the logo screen
197   $form->header unless $form->{noheader};
198
199   print qq|
200 <body>
201 <center>
202 <a href="http://www.lx-office.org" target=_top><img src="image/lx-office-erp.png" border=0></a>
203 <h2 class=login>| . $locale->text('Version') . qq| $form->{version}</h2>
204
205 | . $locale->text('Licensed to') . qq|
206 <p>
207 <b>
208 $myconfig{company}
209 <br>$myconfig{address}
210 </b>
211
212
213 <br>
214 <table border=0>
215   <tr>
216     <th align=left>| . $locale->text('User') . qq|</th>
217     <td>$myconfig{name}</td>
218   </tr>
219   <tr>
220     <th align=left>| . $locale->text('Dataset') . qq|</th>
221     <td>$myconfig{dbname}</td>
222   </tr>
223   <tr>
224     <th align=left>| . $locale->text('Database Host') . qq|</th>
225     <td>$myconfig{dbhost}</td>
226   </tr>
227   <tr>
228   </tr>
229   <tr>
230   </tr>
231   <tr>
232     <th colspan="2" align="center"><a href="http://lx-office.org" target="blank">http://lx-office.org</a></th>
233   </tr>
234   <tr>
235     <th colspan="2" align="center"><a href="mailto:info&#064;lx-office.org" target="blank">info&#064;lx-office.org</a></th>
236   </tr>
237 </table>
238
239 </center>
240
241 </body>
242 </html>
243 |;
244
245   $lxdebug->leave_sub();
246 }