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