summaryrefslogtreecommitdiff
path: root/lsmb.pl
blob: d74f714d2e9c39a64910b7b041ad48f42bf8a01b (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. }
  22. else {
  23. # redirect them back to the original url
  24. # infer the base URI, this fails unless the script is named lsmb.pl
  25. my ($base_uri) = $ENV{SCRIPT_NAME} =~ m#^(.*?)/lsmb.pl#;
  26. print "Status: 301\nLocation: $base_uri/$script\n\n";
  27. }
  28. }
  29. sub debug {
  30. my $self = shift;
  31. use Data::Dumper;
  32. print "Content-type: text/plain\n\n";
  33. print "\$0 is $0\n";
  34. print Dumper( \%ENV );
  35. }
  36. 1;