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