summaryrefslogtreecommitdiff
path: root/lsmb.pl
blob: cdc4737cd0c97c7fa94558bbc70188ae02bab751 (plain)
  1. #!/usr/bin/perl -w
  2. use warnings;
  3. use strict;
  4. LedgerSMB::Handler->cgi_handle();
  5. package LedgerSMB::Handler;
  6. use LedgerSMB::Log;
  7. use warnings;
  8. use strict;
  9. use CGI::Carp qw(fatalsToBrowser);
  10. sub cgi_handle {
  11. my $self = shift;
  12. my $script = $ENV{PATH_INFO};
  13. $script =~ s/^\///;
  14. # TODO: we can parse out other information, such as
  15. # Company Identifier, and what not here.
  16. #return $self->debug();
  17. if($script =~ /\.pl$/) {
  18. # perl scripts should be directly executed.
  19. warn "[LedgerSMB::Handler] running $script";
  20. exec("./$script") or croak $!;
  21. } else {
  22. # redirect them back to the original url
  23. # infer the base URI, this fails unless the script is named lsmb.pl
  24. my ($base_uri) = $ENV{SCRIPT_NAME} =~ m#^(.*?)/lsmb.pl#;
  25. print "Status: 301\nLocation: $base_uri/$script\n\n";
  26. }
  27. }
  28. sub debug {
  29. my $self = shift;
  30. use Data::Dumper;
  31. print "Content-type: text/plain\n\n";
  32. print "\$0 is $0\n";
  33. print Dumper(\%ENV);
  34. }
  35. 1;