summaryrefslogtreecommitdiff
path: root/admin.pl
blob: b747d65b384e9d99702fdc8786056c1ffeac2c18 (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" if $ENV{HTTP_USER_AGENT};
  60. print "\nLogin disabled!\n";
  61. exit;
  62. }
  63. if ($form{path}) {
  64. $form{path} =~ s/%2f/\//gi;
  65. $form{path} =~ s/\.\.\///g;
  66. if ($form{path} !~ /^bin\//) {
  67. print "Content-Type: text/html\n\n" if $ENV{HTTP_USER_AGENT};
  68. print "\nInvalid path!\n";
  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" if $ENV{HTTP_USER_AGENT};
  96. print qq|\nUnknown terminal\n|;
  97. }
  98. }
  99. # end of main