summaryrefslogtreecommitdiff
path: root/bin/lynx/login.pl
blob: b674b03ff36ec143aa96256c84758b7d4ba75245 (plain)
  1. ######################################################################
  2. # LedgerSMB Small Medium Business Accounting
  3. # Copyright (c) 2000
  4. #
  5. # Author: DWS Systems Inc.
  6. # Web: http://sourceforge.net/projects/ledger-smb/
  7. #
  8. #
  9. # This program is free software; you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation; either version 2 of the License, or
  12. # (at your option) any later version.
  13. #
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU General Public License for more details.
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program; if not, write to the Free Software
  20. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. ######################################################################
  22. #
  23. # login frontend
  24. #
  25. #######################################################################
  26. use DBI;
  27. use SL::User;
  28. use SL::Form;
  29. $form = new Form;
  30. $locale = new Locale $language, "login";
  31. $form->{charset} = $locale->{charset};
  32. # customization
  33. if (-f "$form->{path}/custom_$form->{script}") {
  34. eval { require "$form->{path}/custom_$form->{script}"; };
  35. $form->error($@) if ($@);
  36. }
  37. # per login customization
  38. if (-f "$form->{path}/$form->{login}_$form->{script}") {
  39. eval { require "$form->{path}/$form->{login}_$form->{script}"; };
  40. $form->error($@) if ($@);
  41. }
  42. # window title bar, user info
  43. $form->{titlebar} = "LedgerSMB ".$locale->text('Version'). " $form->{version}";
  44. if ($form->{action}) {
  45. $form->{titlebar} .= " - $myconfig{name} - $myconfig{dbname}";
  46. &{ $locale->findsub($form->{action}) };
  47. } else {
  48. &login_screen;
  49. }
  50. 1;
  51. sub login_screen {
  52. $form->{stylesheet} = "sql-ledger.css";
  53. $form->{favicon} = "sql-ledger.ico";
  54. $form->{endsession} = 1;
  55. $form->header(1);
  56. if ($form->{login}) {
  57. $sf = qq|function sf() { document.login.password.focus(); }|;
  58. } else {
  59. $sf = qq|function sf() { document.login.login.focus(); }|;
  60. }
  61. print qq|
  62. <script language="JavaScript" type="text/javascript">
  63. <!--
  64. var agt = navigator.userAgent.toLowerCase();
  65. var is_major = parseInt(navigator.appVersion);
  66. var is_nav = ((agt.indexOf('mozilla') != -1) && (agt.indexOf('spoofer') == -1)
  67. && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera') == -1)
  68. && (agt.indexOf('webtv') == -1));
  69. var is_nav4lo = (is_nav && (is_major <= 4));
  70. function jsp() {
  71. if (is_nav4lo)
  72. document.login.js.value = "0"
  73. else
  74. document.login.js.value = "1"
  75. }
  76. $sf
  77. // End -->
  78. </script>
  79. |;
  80. print qq|
  81. <body class=login onload="jsp(); sf()">
  82. <pre>
  83. </pre>
  84. <center>
  85. <table class=login border=3 cellpadding=20>
  86. <tr>
  87. <td class=login align=center><a href="http://sourceforge.net/projects/ledger-smb/" target=_top><img src=ledger-smb.png border=0></a>
  88. <h1 class=login align=center>|.$locale->text('Version').qq| $form->{version}
  89. </h1>
  90. <p>
  91. <form method=post action=$form->{script} name=login>
  92. <table width=100%>
  93. <tr>
  94. <td align=center>
  95. <table>
  96. <tr>
  97. <th align=right>|.$locale->text('Name').qq|</th>
  98. <td><input class=login name=login size=30 value=$form->{login}></td>
  99. </tr>
  100. <tr>
  101. <th align=right>|.$locale->text('Password').qq|</th>
  102. <td><input class=login type=password name=password size=30></td>
  103. </tr>
  104. <input type=hidden name=path value=$form->{path}>
  105. <input type=hidden name=js value=$form->{js}>
  106. </table>
  107. <br>
  108. <input type=submit name=action value="|.$locale->text('Login').qq|">
  109. </td>
  110. </tr>
  111. </table>
  112. </form>
  113. </td>
  114. </tr>
  115. </table>
  116. </body>
  117. </html>
  118. |;
  119. }
  120. sub selectdataset {
  121. my ($login) = @_;
  122. if (-f "css/sql-ledger.css") {
  123. $form->{stylesheet} = "sql-ledger.css";
  124. }
  125. $form->header(1);
  126. print qq|
  127. <body class=login onload="document.forms[0].password.focus()" />
  128. <pre>
  129. </pre>
  130. <center>
  131. <table class=login border=3 cellpadding=20>
  132. <tr>
  133. <td class=login align=center><a href="http://sourceforge.net/projects/ledger-smb/" target=_top><img src=ledger-smb.png border=0></a>
  134. <h1 class=login align=center>|.$locale->text('Version').qq| $form->{version}
  135. </h1>
  136. <p>
  137. <form method=post action=$form->{script}>
  138. <input type=hidden name=beenthere value=1>
  139. <table width=100%>
  140. <tr>
  141. <td align=center>
  142. <table>
  143. <tr>
  144. <th align=right>|.$locale->text('Name').qq|</th>
  145. <td>$form->{login}</td>
  146. </tr>
  147. <tr>
  148. <th align=right>|.$locale->text('Password').qq|</th>
  149. <td><input class=login type=password name=password size=30 value=$form->{password}></td>
  150. </tr>
  151. <input type=hidden name=js value=$form->{js}>
  152. <input type=hidden name=path value=$form->{path}>
  153. <tr>
  154. <th align=right>|.$locale->text('Company').qq|</th>
  155. <td>|;
  156. $checked = "checked";
  157. foreach $login (sort { $login{$a} cmp $login{$b} } keys %{ $login }) {
  158. print qq|
  159. <br><input class=login type=radio name=login value=$login $checked>$login{$login}
  160. |;
  161. $checked = "";
  162. }
  163. print qq|
  164. </td>
  165. </tr>
  166. </table>
  167. <br>
  168. <input type=submit name=action value="|.$locale->text('Login').qq|">
  169. </td>
  170. </tr>
  171. </table>
  172. </form>
  173. </td>
  174. </tr>
  175. </table>
  176. </body>
  177. </html>
  178. |;
  179. }
  180. sub login {
  181. $form->{stylesheet} = "sql-ledger.css";
  182. $form->{favicon} = "sql-ledger.ico";
  183. $form->error($locale->text('You did not enter a name!')) unless ($form->{login});
  184. if (! $form->{beenthere}) {
  185. open(FH, "$memberfile") or $form->error("$memberfile : $!");
  186. @a = <FH>;
  187. close(FH);
  188. foreach $item (@a) {
  189. if ($item =~ /^\[(.*?)\]/) {
  190. $login = $1;
  191. $found = 1;
  192. }
  193. if ($item =~ /^company=/) {
  194. if ($login =~ /$form->{login}\@/ && $found) {
  195. ($null, $name) = split /=/, $item, 2;
  196. $login{$login} = $name;
  197. }
  198. $found = 0;
  199. }
  200. }
  201. if (keys %login > 1) {
  202. &selectdataset(\%login);
  203. exit;
  204. }
  205. }
  206. $user = new User $memberfile, $form->{login};
  207. # if we get an error back, bale out
  208. if (($errno = $user->login(\%$form, $userspath)) <= -1) {
  209. $errno *= -1;
  210. $err[1] = $locale->text('Access Denied!');
  211. $err[2] = $locale->text('Incorrect Dataset version!');
  212. $err[3] = $locale->text('Dataset is newer than version!');
  213. if ($errno == 4) {
  214. # upgrade dataset and log in again
  215. open FH, ">$userspath/nologin" or $form->error($!);
  216. for (qw(dbname dbhost dbport dbdriver dbuser dbpasswd)) { $form->{$_} = $user->{$_} }
  217. $form->{dbpasswd} = unpack 'u', $form->{dbpasswd};
  218. $form->{dbupdate} = "db$user->{dbname}";
  219. $form->{$form->{dbupdate}} = 1;
  220. $form->header;
  221. print $locale->text('Upgrading to Version')." $form->{version} ... ";
  222. # required for Oracle
  223. $form->{dbdefault} = $sid;
  224. $user->dbupdate(\%$form);
  225. # remove lock file
  226. unlink "$userspath/nologin";
  227. print $locale->text('done');
  228. print "<p><a href=menu.pl?login=$form->{login}&sessionid=$form->{sessionid}&path=$form->{path}&action=display&main=company_logo&js=$form->{js}>".$locale->text('Continue')."</a>";
  229. exit;
  230. }
  231. $form->error($err[$errno]);
  232. }
  233. # made it this far, setup callback for the menu
  234. $form->{callback} = "menu.pl?action=display";
  235. for (qw(login path js)) { $form->{callback} .= "&$_=$form->{$_}" }
  236. # check for recurring transactions
  237. if ($user->{acs} !~ /Recurring Transactions/) {
  238. if ($user->check_recurring(\%$form)) {
  239. $form->{callback} .= "&main=recurring_transactions";
  240. } else {
  241. $form->{callback} .= "&main=company_logo";
  242. }
  243. } else {
  244. if ($user->{role} eq 'user') {
  245. $form->{callback} .= "&main=company_logo";
  246. } else {
  247. if ($user->check_recurring(\%$form)) {
  248. $form->{callback} .= "&main=recurring_transactions";
  249. } else {
  250. $form->{callback} .= "&main=company_logo";
  251. }
  252. }
  253. }
  254. $form->redirect;
  255. }
  256. sub logout {
  257. $form->{callback} = "$form->{script}?path=$form->{path}&login=$form->{login}";
  258. $form->{endsession} = 1;
  259. $form->redirect;
  260. }