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