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