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