2
0

puppet.cgi 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/perl
  2. #
  3. # Used for testing, This will allow you to configure a
  4. # dialplan on a remote system for testing via X headers
  5. # in a SIP invite. DO NOT RUN IN PRODUCTION LIKE THIS.
  6. #
  7. # YOU'VE BEEN WARNED!
  8. #
  9. use CGI;
  10. use XML::Writer;
  11. use IO::File;
  12. use Data::Dumper;
  13. my $q = CGI->new;
  14. my $output = IO::File->new(*STDOUT);
  15. my $writer = XML::Writer->new(OUTPUT => $output, DATA_MODE => 1, DATA_INDENT => 2);
  16. my $params = $q->Vars;
  17. print $q->header('text/xml');
  18. $writer->xmlDecl("UTF-8");
  19. $writer->startTag("document", "type" => "freeswitch/xml");
  20. if($params->{'Hunt-Destination-Number'} eq 'puppet') {
  21. $writer->startTag("section", "name" => "dialplan");
  22. $writer->startTag("context", "name" => "$params->{'Hunt-Context'}");
  23. $writer->startTag("extension", "name" => "puppet");
  24. $writer->startTag("condition");
  25. my $count = 1;
  26. while (exists $params->{"variable_sip_h_X-DP-$count"}) {
  27. my ($app, $arg) = split(/:/, $params->{"variable_sip_h_X-DP-$count"});
  28. if($arg) {
  29. $writer->emptyTag("action", "application" => "$app", "data" => "$arg");
  30. } else {
  31. $writer->emptyTag("action", "application" => "$app");
  32. }
  33. $count++;
  34. }
  35. $writer->endTag("condition");
  36. $writer->endTag("extension");
  37. $writer->endTag("context");
  38. } else {
  39. $writer->startTag("section", "name" => "result");
  40. $writer->emptyTag("result", "status" => "not found");
  41. }
  42. $writer->endTag("section");
  43. $writer->endTag("document");
  44. $writer->end();