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