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