summaryrefslogtreecommitdiff
path: root/menu.pl
blob: 4469138f43bebfe92156d999ad78713676b199c1 (plain)
  1. #!/usr/bin/perl
  2. #
  3. ######################################################################
  4. # LedgerSMB Accounting and ERP
  5. # Copyright (C) 2001
  6. #
  7. # Author: Dieter Simader
  8. # Email: dsimader@sql-ledger.org
  9. # Web: http://sourceforge.net/projects/ledger-smb/
  10. #
  11. # Contributors:
  12. #
  13. # This program is free software; you can redistribute it and/or modify
  14. # it under the terms of the GNU General Public License as published by
  15. # the Free Software Foundation; either version 2 of the License, or
  16. # (at your option) any later version.
  17. #
  18. # This program is distributed in the hope that it will be useful,
  19. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. # GNU General Public License for more details.
  22. # You should have received a copy of the GNU General Public License
  23. # along with this program; if not, write to the Free Software
  24. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  25. #######################################################################
  26. #
  27. # this script is the frontend called from bin/$terminal/$script
  28. # all the accounting modules are linked to this script which in
  29. # turn execute the same script in bin/$terminal/
  30. #
  31. #######################################################################
  32. # setup defaults, DO NOT CHANGE
  33. $userspath = "users";
  34. $spool = "spool";
  35. $templates = "templates";
  36. $memberfile = "users/members";
  37. $sendmail = "| /usr/sbin/sendmail -t";
  38. $latex = 0;
  39. %printer = ();
  40. ########## end ###########################################
  41. $| = 1;
  42. use LedgerSMB::Form;
  43. use LedgerSMB::Session;
  44. eval { require "ledger-smb.conf"; };
  45. $form = new Form;
  46. # name of this script
  47. $0 =~ tr/\\/\//;
  48. $pos = rindex $0, '/';
  49. $script = substr($0, $pos + 1);
  50. # we use $script for the language module
  51. $form->{script} = $script;
  52. # strip .pl for translation files
  53. $script =~ s/\.pl//;
  54. # pull in DBI
  55. use DBI qw(:sql_types);
  56. # check for user config file, could be missing or ???
  57. eval { require("$userspath/$form->{login}.conf"); };
  58. if ($@) {
  59. $locale = new Locale "$language", "$script";
  60. $form->{callback} = "";
  61. $msg1 = $locale->text('You are logged out!');
  62. $msg2 = $locale->text('Login');
  63. $form->redirect("$msg1 <p><a href=\"login.pl\" target=\"_top\">$msg2</a></p>");
  64. }
  65. # locale messages
  66. $locale = new Locale "$myconfig{countrycode}", "$script";
  67. $form->{charset} = $locale->{charset};
  68. # send warnings to browser
  69. $SIG{__WARN__} = sub { $form->info($_[0]) };
  70. # send errors to browser
  71. $SIG{__DIE__} = sub { $form->error($_[0]) };
  72. $myconfig{dbpasswd} = unpack 'u', $myconfig{dbpasswd};
  73. map { $form->{$_} = $myconfig{$_} } qw(stylesheet timeout) unless ($form->{type} eq 'preferences');
  74. $form->{path} =~ s/\.\.\///g;
  75. if ($form->{path} !~ /^bin\//) {
  76. $form->error($locale->text('Invalid path!')."\n");
  77. }
  78. # did sysadmin lock us out
  79. if (-f "$userspath/nologin") {
  80. $form->error($locale->text('System currently down for maintenance!'));
  81. }
  82. # pull in the main code
  83. require "$form->{path}/$form->{script}";
  84. # customized scripts
  85. if (-f "$form->{path}/custom_$form->{script}") {
  86. eval { require "$form->{path}/custom_$form->{script}"; };
  87. }
  88. # customized scripts for login
  89. if (-f "$form->{path}/$form->{login}_$form->{script}") {
  90. eval { require "$form->{path}/$form->{login}_$form->{script}"; };
  91. }
  92. if ($form->{action}) {
  93. # window title bar, user info
  94. $form->{titlebar} = "LedgerSMB ".$locale->text('Version'). " $form->{version} - $myconfig{name} - $myconfig{dbname}";
  95. &check_password;
  96. if (substr($form->{action}, 0, 1) =~ /( |\.)/) {
  97. &{ $form->{nextsub} };
  98. } else {
  99. &{ $locale->findsub($form->{action}) };
  100. }
  101. } else {
  102. $form->error($locale->text('action= not defined!'));
  103. }
  104. 1;
  105. # end
  106. sub check_password {
  107. if ($myconfig{password}) {
  108. require "$form->{path}/pw.pl";
  109. if ($form->{password}) {
  110. if ((crypt $form->{password}, substr($form->{login}, 0, 2)) ne $myconfig{password}) {
  111. if ($ENV{HTTP_USER_AGENT}) {
  112. &getpassword;
  113. } else {
  114. $form->error($locale->text('Access Denied!'));
  115. }
  116. exit;
  117. } else {
  118. Session::session_create($form, %myconfig);
  119. }
  120. } else {
  121. if ($ENV{HTTP_USER_AGENT}) {
  122. $ENV{HTTP_COOKIE} =~ s/;\s*/;/g;
  123. @cookies = split /;/, $ENV{HTTP_COOKIE};
  124. foreach (@cookies) {
  125. ($name,$value) = split /=/, $_, 2;
  126. $cookie{$name} = $value;
  127. }
  128. if ($form->{action} ne 'display') {
  129. if ((! $cookie{"LedgerSMB-$form->{login}"}) || $cookie{"LedgerSMB-$form->{login}"} ne $form->{sessionid}) {
  130. &getpassword(1);
  131. exit;
  132. }
  133. }
  134. #check for valid session
  135. if(!Session::session_check($cookie{"LedgerSMB"}, $form, %myconfig)){
  136. &getpassword(1);
  137. exit;
  138. }
  139. } else {
  140. exit;
  141. }
  142. }
  143. }
  144. }