summaryrefslogtreecommitdiff
path: root/admin.pl
blob: 03b0d37017d1f91a49a7b8583c848585a50dbe90 (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" if $ENV{HTTP_USER_AGENT};
  58. print "\nLogin disabled!\n";
  59. exit;
  60. }
  61. if ($form{path}) {
  62. $form{path} =~ s/%2f/\//gi;
  63. $form{path} =~ s/\.\.\///g;
  64. if ($form{path} !~ /^bin\//) {
  65. print "Content-Type: text/html\n\n" if $ENV{HTTP_USER_AGENT};
  66. print "\nInvalid path!\n";
  67. exit;
  68. }
  69. $ARGV[0] = "$_&script=$script";
  70. require "$form{path}/$script";
  71. } else {
  72. if (!$form{terminal}) {
  73. if ($ENV{HTTP_USER_AGENT}) {
  74. # web browser
  75. $form{terminal} = "lynx";
  76. if ($ENV{HTTP_USER_AGENT} !~ /lynx/i) {
  77. $form{terminal} = "mozilla";
  78. }
  79. } else {
  80. if ($ENV{TERM} =~ /xterm/) {
  81. $form{terminal} = "xterm";
  82. }
  83. if ($ENV{TERM} =~ /(console|linux|vt.*)/i) {
  84. $form{terminal} = "console";
  85. }
  86. }
  87. }
  88. if ($form{terminal}) {
  89. $ARGV[0] = "path=bin/$form{terminal}&script=$script";
  90. map { $ARGV[0] .= "&${_}=$form{$_}" } keys %form;
  91. require "bin/$form{terminal}/$script";
  92. } else {
  93. print "Content-Type: text/html\n\n" if $ENV{HTTP_USER_AGENT};
  94. print qq|\nUnknown terminal\n|;
  95. }
  96. }
  97. # end of main