You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.0 KiB

  1. #!/usr/bin/perl
  2. # Set ucp_url to something like this:
  3. # https://webserver/cgi-bin/fusionpbx_get_recording.pl?file={odoo_uuid}&start={odoo_start}&resource={user_resource}
  4. my(%args);
  5. if($ENV{'REQUEST_METHOD'} eq "GET") {
  6. $query=$ENV{'QUERY_STRING'};
  7. my(@line_args)=split(/&/,$query);
  8. for my $arg (@line_args){
  9. $arg=~ s/\+/ /g; # replace + with spaces.....
  10. ($key,$val)=split(/=/,$arg);
  11. $val =~ s/%(..)/pack("c",hex($1))/ge;
  12. if($key eq "file" || $key eq "usename" || $key eq "content" ||$key eq "remove" ){
  13. $args{$key}=$val;
  14. }
  15. }
  16. }
  17. else{
  18. print "Content-type: text/html\n\n";
  19. print "No Arguments.....";
  20. exit 1;
  21. }
  22. my $time = $start;
  23. my @months = ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
  24. my ($sec, $min, $hour, $day,$month,$year) = (gmtime($time))[0,1,2,3,4,5];
  25. print "Unix time ".$time." converts to ".$months[$month]." ".$day.", ".($year+1900);
  26. print " ".$hour.":".$min.":".$sec."\n";
  27. $resource =~ s/@/./
  28. $filename="/usr/local/freeswitch/recordings/".$resource."/".$year."/".$months[$month]."/".$day."/".$args{"file"};
  29. my(@stat)=stat $filename;
  30. binmode(STDOUT);
  31. if(open (F,"<", "$filename")){
  32. print "Connection: close\n";
  33. if($args{"content"}){
  34. print "Content-Type: ".$args{"content"}."\n\\";
  35. }
  36. else{
  37. print "Content-Type: application/octet-stream\n";
  38. }
  39. print "Content-Length: ".$stat[7]."\n";
  40. if($args{"usename"}){
  41. print "Content-Disposition: attachment; filename=\"".$args{"usename"}."\"\n\n";
  42. }
  43. else {
  44. print "Content-Disposition: attachment; filename=\"".$args{"file"}."\"\n\n";
  45. }
  46. while($len=sysread( F, $buf,512)){
  47. print $buf;
  48. }
  49. close F;
  50. if($args{"remove"}==1){
  51. unlink $filename;
  52. }
  53. }
  54. else {
  55. print "Connection: close\n";
  56. print "Content-Type: text/html\n\n";
  57. print "<H1>Error </H1>\n";
  58. print "The file ".$args{"file"}." does not exists in the server<br>\n";
  59. print "Please contact to the administrator for more info.\n\n";
  60. }