summaryrefslogtreecommitdiff
path: root/menu.pl
blob: f1adbb587bb212a351261b606ee3071c070ab107 (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. use Digest::MD5;
  49. $| = 1;
  50. use LedgerSMB::User;
  51. use LedgerSMB::Form;
  52. use LedgerSMB::Locale;
  53. use LedgerSMB::Session;
  54. use Data::Dumper;
  55. # for custom preprocessing logic
  56. eval { require "custom.pl"; };
  57. $form = new Form;
  58. # name of this script
  59. $0 =~ tr/\\/\//;
  60. $pos = rindex $0, '/';
  61. $script = substr($0, $pos + 1);
  62. # we use $script for the language module
  63. $form->{script} = $script;
  64. # strip .pl for translation files
  65. $script =~ s/\.pl//;
  66. # pull in DBI
  67. use DBI qw(:sql_types);
  68. # grab user config. This is ugly and unecessary if/when
  69. # we get rid of myconfig and use User as a real object
  70. %myconfig = %{LedgerSMB::User->fetch_config($form->{login})};
  71. if ($@) {
  72. $locale = LedgerSMB::Locale->get_handle($myconfig{countrycode}) or
  73. $form->error(__FILE__.':'.__LINE__.": Locale not loaded: $!\n");
  74. $form->{charset} = $locale->encoding;
  75. $form->{charset} = 'UTF-8';
  76. $locale->encoding('UTF-8');
  77. $form->{callback} = "";
  78. $msg1 = $locale->text('You are logged out!');
  79. $msg2 = $locale->text('Login');
  80. $form->redirect("$msg1 <p><a href=\"login.pl\" target=\"_top\">$msg2</a></p>");
  81. }
  82. # locale messages
  83. $locale = LedgerSMB::Locale->get_handle($myconfig{countrycode}) or
  84. $form->error(__FILE__.':'.__LINE__.": Locale not loaded: $!\n");
  85. #$form->{charset} = $locale->encoding;
  86. $form->{charset} = 'UTF-8';
  87. $locale->encoding('UTF-8');
  88. # send warnings to browser
  89. $SIG{__WARN__} = sub { $form->info($_[0]) };
  90. # send errors to browser
  91. $SIG{__DIE__} = sub { $form->error(__FILE__.':'.__LINE__.': '.$_[0]) };
  92. map { $form->{$_} = $myconfig{$_} } qw(stylesheet timeout) unless ($form->{type} eq 'preferences');
  93. $form->db_init(\%myconfig);
  94. if ($form->{path} ne 'bin/lynx'){ $form->{path} = 'bin/mozilla';}
  95. # did sysadmin lock us out
  96. if (-f "${LedgerSMB::Sysconfig::userspath}/nologin") {
  97. $form->error(__FILE__.':'.__LINE__.': '.$locale->text('System currently down for maintenance!'));
  98. }
  99. # pull in the main code
  100. require "bin/$form->{script}";
  101. # customized scripts
  102. if (-f "bin/custom/$form->{script}") {
  103. eval { require "bin/custom/$form->{script}"; };
  104. }
  105. # customized scripts for login
  106. if (-f "bin/custom/$form->{login}_$form->{script}") {
  107. eval { require "bin/custom/$form->{login}_$form->{script}"; };
  108. }
  109. if ($form->{action}) {
  110. # window title bar, user info
  111. $form->{titlebar} = "LedgerSMB ".$locale->text('Version'). " $form->{version} - $myconfig{name} - $myconfig{dbname}";
  112. &check_password;
  113. if (substr($form->{action}, 0, 1) =~ /( |\.)/) {
  114. &{ $form->{nextsub} };
  115. } else {
  116. &{ $form->{action} };
  117. }
  118. } else {
  119. $form->error(__FILE__.':'.__LINE__.': '.$locale->text('action= not defined!'));
  120. }
  121. 1;
  122. # end
  123. sub check_password {
  124. if ($myconfig{password}) {
  125. require "bin/pw.pl";
  126. if ($form->{password}) {
  127. if ($myconfig{password} ne (Digest::MD5::md5_hex $form->{password})) {
  128. if ($ENV{HTTP_USER_AGENT}) {
  129. &getpassword;
  130. } else {
  131. $form->error(__FILE__.':'.__LINE__.': '.$locale->text('Access Denied!'));
  132. }
  133. exit;
  134. } else {
  135. Session::session_create($form);
  136. }
  137. } else {
  138. if ($ENV{HTTP_USER_AGENT}) {
  139. $ENV{HTTP_COOKIE} =~ s/;\s*/;/g;
  140. @cookies = split /;/, $ENV{HTTP_COOKIE};
  141. foreach (@cookies) {
  142. ($name,$value) = split /=/, $_, 2;
  143. $cookie{$name} = $value;
  144. }
  145. if ($form->{action} ne 'display') {
  146. if ((! $cookie{"LedgerSMB-$form->{login}"}) || $cookie{"LedgerSMB-$form->{login}"} ne $form->{sessionid}) {
  147. &getpassword(1);
  148. exit;
  149. }
  150. }
  151. #check for valid session
  152. if(!Session::session_check($cookie{"LedgerSMB"}, $form)){
  153. &getpassword(1);
  154. exit;
  155. }
  156. } else {
  157. exit;
  158. }
  159. }
  160. }
  161. }