summaryrefslogtreecommitdiff
path: root/login.pl
blob: c1d16c910ca77f11190837dab09003b9e48f48bc (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. # Web: http://sourceforge.net/projects/ledger-smb/
  26. #
  27. # Contributors:
  28. #
  29. # This program is free software; you can redistribute it and/or modify
  30. # it under the terms of the GNU General Public License as published by
  31. # the Free Software Foundation; either version 2 of the License, or
  32. # (at your option) any later version.
  33. #
  34. # This program is distributed in the hope that it will be useful,
  35. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  36. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  37. # GNU General Public License for more details.
  38. # You should have received a copy of the GNU General Public License
  39. # along with this program; if not, write to the Free Software
  40. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  41. #######################################################################
  42. #
  43. # this script sets up the terminal and runs the scripts
  44. # in bin/$terminal directory
  45. # admin.pl is linked to this script
  46. #
  47. #######################################################################
  48. # setup defaults, DO NOT CHANGE
  49. $userspath = "users";
  50. $spool = "spool";
  51. $templates = "templates";
  52. $memberfile = "users/members";
  53. $sendmail = "| /usr/sbin/sendmail -t";
  54. %printer = ( Printer => 'lpr' );
  55. ########## end ###########################################
  56. $| = 1;
  57. eval { require "ledger-smb.conf"; };
  58. if ($ENV{CONTENT_LENGTH}) {
  59. read(STDIN, $_, $ENV{CONTENT_LENGTH});
  60. }
  61. if ($ENV{QUERY_STRING}) {
  62. $_ = $ENV{QUERY_STRING};
  63. }
  64. if ($ARGV[0]) {
  65. $_ = $ARGV[0];
  66. }
  67. %form = split /[&=]/;
  68. # fix for apache 2.0 bug
  69. map { $form{$_} =~ s/\\$// } keys %form;
  70. # name of this script
  71. $0 =~ tr/\\/\//;
  72. $pos = rindex $0, '/';
  73. $script = substr($0, $pos + 1);
  74. if (-e "$userspath/nologin" && $script ne 'admin.pl') {
  75. print "Content-Type: text/html\n\n<html><body><strong>" if $ENV{HTTP_USER_AGENT};
  76. print "\nLogin disabled!\n";
  77. print "\n</strong></body></html>" if $ENV{HTTP_USER_AGENT};
  78. exit;
  79. }
  80. if ($form{path}) {
  81. $form{path} =~ s/%2f/\//gi;
  82. $form{path} =~ s/\.\.\///g;
  83. if ($form{path} !~ /^bin\//) {
  84. print "Content-Type: text/html\n\n<html><body><strong>" if $ENV{HTTP_USER_AGENT};
  85. print "\nInvalid path!\n";
  86. print "\n</strong></body></html>" if $ENV{HTTP_USER_AGENT};
  87. exit;
  88. }
  89. $ARGV[0] = "$_&script=$script";
  90. require "$form{path}/$script";
  91. } else {
  92. if (!$form{terminal}) {
  93. if ($ENV{HTTP_USER_AGENT}) {
  94. # web browser
  95. $form{terminal} = "lynx";
  96. if ($ENV{HTTP_USER_AGENT} !~ /lynx/i) {
  97. $form{terminal} = "mozilla";
  98. }
  99. } else {
  100. if ($ENV{TERM} =~ /xterm/) {
  101. $form{terminal} = "xterm";
  102. }
  103. if ($ENV{TERM} =~ /(console|linux|vt.*)/i) {
  104. $form{terminal} = "console";
  105. }
  106. }
  107. }
  108. if ($form{terminal}) {
  109. $ARGV[0] = "path=bin/$form{terminal}&script=$script";
  110. map { $ARGV[0] .= "&${_}=$form{$_}" } keys %form;
  111. require "bin/$form{terminal}/$script";
  112. } else {
  113. print "Content-Type: text/html\n\n<html><body><strong>" if $ENV{HTTP_USER_AGENT};
  114. print qq|\nUnknown terminal\n|;
  115. print "\n</strong></body></html>" if $ENV{HTTP_USER_AGENT};
  116. }
  117. }
  118. # end of main