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