summaryrefslogtreecommitdiff
path: root/menu.pl
blob: 1aa451940be58b0a303724ff96f586f9cfd99379 (plain)
  1. #!/usr/bin/perl
  2. #
  3. ######################################################################
  4. # LedgerSMB Accounting and ERP
  5. # http://www.ledgersmb.org/
  6. #
  7. # Copyright (C) 2006
  8. # This work contains copyrighted information from a number of sources all used
  9. # with permission.
  10. #
  11. # This file contains source code included with or based on SQL-Ledger which
  12. # is Copyright Dieter Simader and DWS Systems Inc. 2000-2005 and licensed
  13. # under the GNU General Public License version 2 or, at your option, any later
  14. # version. For a full list including contact information of contributors,
  15. # maintainers, and copyright holders, see the CONTRIBUTORS file.
  16. #
  17. # Original Copyright Notice from SQL-Ledger 2.6.17 (before the fork):
  18. # Copyright (C) 2001
  19. #
  20. # Author: Dieter Simader
  21. # Email: dsimader@sql-ledger.org
  22. # Web: http://www.sql-ledger.org
  23. #
  24. # Contributors:
  25. #
  26. #
  27. #
  28. # This program is free software; you can redistribute it and/or modify
  29. # it under the terms of the GNU General Public License as published by
  30. # the Free Software Foundation; either version 2 of the License, or
  31. # (at your option) any later version.
  32. #
  33. # This program is distributed in the hope that it will be useful,
  34. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  35. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  36. # GNU General Public License for more details.
  37. # You should have received a copy of the GNU General Public License
  38. # along with this program; if not, write to the Free Software
  39. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  40. #######################################################################
  41. #
  42. # this script is the frontend called from bin/$terminal/$script
  43. # all the accounting modules are linked to this script which in
  44. # turn execute the same script in bin/$terminal/
  45. #
  46. #######################################################################
  47. use LedgerSMB::Sysconfig;
  48. $| = 1;
  49. use LedgerSMB::Form;
  50. use LedgerSMB::Locale;
  51. use LedgerSMB::Session;
  52. # for custom preprocessing logic
  53. eval { require "custom.pl"; };
  54. $form = new Form;
  55. # name of this script
  56. $0 =~ tr/\\/\//;
  57. $pos = rindex $0, '/';
  58. $script = substr($0, $pos + 1);
  59. # we use $script for the language module
  60. $form->{script} = $script;
  61. # strip .pl for translation files
  62. $script =~ s/\.pl//;
  63. # pull in DBI
  64. use DBI qw(:sql_types);
  65. # check for user config file, could be missing or ???
  66. eval { require("${LedgerSMB::Sysconfig::userspath}/$form->{login}.conf"); };
  67. if ($@) {
  68. $locale = LedgerSMB::Locale->get_handle($myconfig{countrycode}) or
  69. $form->error("Locale not loaded: $!\n");
  70. $form->{charset} = $locale->encoding;
  71. $form->{charset} = 'UTF-8';
  72. $locale->encoding('UTF-8');
  73. $form->{callback} = "";
  74. $msg1 = $locale->text('You are logged out!');
  75. $msg2 = $locale->text('Login');
  76. $form->redirect("$msg1 <p><a href=\"login.pl\" target=\"_top\">$msg2</a></p>");
  77. }
  78. # locale messages
  79. $locale = LedgerSMB::Locale->get_handle($myconfig{countrycode}) or
  80. $form->error("Locale not loaded: $!\n");
  81. #$form->{charset} = $locale->encoding;
  82. $form->{charset} = 'UTF-8';
  83. $locale->encoding('UTF-8');
  84. # send warnings to browser
  85. $SIG{__WARN__} = sub { $form->info($_[0]) };
  86. # send errors to browser
  87. $SIG{__DIE__} = sub { $form->error($_[0]) };
  88. $myconfig{dbpasswd} = unpack 'u', $myconfig{dbpasswd};
  89. map { $form->{$_} = $myconfig{$_} } qw(stylesheet timeout) unless ($form->{type} eq 'preferences');
  90. $form->db_init(\%myconfig);
  91. if ($form->{path} ne 'bin/lynx'){ $form->{path} = 'bin/mozilla';}
  92. # did sysadmin lock us out
  93. if (-f "${LedgerSMB::Sysconfig::userspath}/nologin") {
  94. $form->error($locale->text('System currently down for maintenance!'));
  95. }
  96. # pull in the main code
  97. require "bin/$form->{script}";
  98. # customized scripts
  99. if (-f "bin/custom/$form->{script}") {
  100. eval { require "bin/custom/$form->{script}"; };
  101. }
  102. # customized scripts for login
  103. if (-f "bin/custom/$form->{login}_$form->{script}") {
  104. eval { require "bin/custom/$form->{login}_$form->{script}"; };
  105. }
  106. if ($form->{action}) {
  107. # window title bar, user info
  108. $form->{titlebar} = "LedgerSMB ".$locale->text('Version'). " $form->{version} - $myconfig{name} - $myconfig{dbname}";
  109. &check_password;
  110. if (substr($form->{action}, 0, 1) =~ /( |\.)/) {
  111. &{ $form->{nextsub} };
  112. } else {
  113. &{ $form->{action} };
  114. }
  115. } else {
  116. $form->error($locale->text('action= not defined!'));
  117. }
  118. 1;
  119. # end
  120. sub check_password {
  121. if ($myconfig{password}) {
  122. require "bin/pw.pl";
  123. if ($form->{password}) {
  124. if ((crypt $form->{password}, substr($form->{login}, 0, 2)) ne $myconfig{password}) {
  125. if ($ENV{HTTP_USER_AGENT}) {
  126. &getpassword;
  127. } else {
  128. $form->error($locale->text('Access Denied!'));
  129. }
  130. exit;
  131. } else {
  132. Session::session_create($form, %myconfig);
  133. }
  134. } else {
  135. if ($ENV{HTTP_USER_AGENT}) {
  136. $ENV{HTTP_COOKIE} =~ s/;\s*/;/g;
  137. @cookies = split /;/, $ENV{HTTP_COOKIE};
  138. foreach (@cookies) {
  139. ($name,$value) = split /=/, $_, 2;
  140. $cookie{$name} = $value;
  141. }
  142. if ($form->{action} ne 'display') {
  143. if ((! $cookie{"LedgerSMB-$form->{login}"}) || $cookie{"LedgerSMB-$form->{login}"} ne $form->{sessionid}) {
  144. &getpassword(1);
  145. exit;
  146. }
  147. }
  148. #check for valid session
  149. if(!Session::session_check($cookie{"LedgerSMB"}, $form, %myconfig)){
  150. &getpassword(1);
  151. exit;
  152. }
  153. } else {
  154. exit;
  155. }
  156. }
  157. }
  158. }