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