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