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