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