Ignore requests from NSPlayer aka mplayer since the first delivery in iframe will...
[infodrom/phone] / phone.php
index b2dbd6d..fb9d525 100644 (file)
--- a/phone.php
+++ b/phone.php
@@ -4,7 +4,9 @@ define('SPOOL_DIR', '/var/spool/vbox/ttyI6');
 function read_info($dir, $call)
 {
   $info = array();
-  if (($f = fopen(SPOOL_DIR . '/' . $dir . '/' . $call . '.info', 'r')) !== false) {
+  $fname = SPOOL_DIR . '/' . $dir . '/' . $call . '.info';
+
+  if (is_file($fname) && ($f = fopen($fname, 'r')) !== false) {
     $line = fgets($f, 1024);
     fclose($f);
     $info = unserialize($line);
@@ -62,7 +64,7 @@ function call_cmp($a, $b)
     return -1;
   elseif ($a['timestamp'] > $b['timestamp'])
     return -1;
-  else
+  elseif ($a['timestamp'] < $b['timestamp'])
     return 1;
   return 0;
 }
@@ -73,7 +75,7 @@ function read_directory($directory)
 
   if ($dir = opendir(SPOOL_DIR . '/' . $directory)) {
     while (($filename = readdir($dir)) !== false) {
-      if (($pos = strpos($filename, '.vmsg')) !== false) {
+      if (($pos = strpos($filename, '.vmsg')) !== false || ($pos = strpos($filename, '.msg')) !== false) {
        $fname = substr($filename,0,$pos);
        $info = message_info($directory, $fname);
        $info['fname'] = $fname;
@@ -94,16 +96,27 @@ function callinfo($dir, $call)
 
 function send_call($dir, $call)
 {
+  if ($_SERVER['HTTP_USER_AGENT'] == 'NSPlayer') return;
+
   $dir = str_replace('/','x',$dir);
   $call = str_replace('/','x',$call);
-  $fname = SPOOL_DIR . '/' . $dir . '/' . $call . '.vmsg';
+
+  if ($dir == 'messages')
+    $ext = '.msg';
+  else
+    $ext = '.vmsg';
+
+  $fname = SPOOL_DIR . '/' . $dir . '/' . $call . $ext;
+  $aufile = SPOOL_DIR . '/' . $dir . '/' . $call . '.au';
 
   if (!is_file($fname)) {
     printf("<html><body><h3>Anruf %s in %s nicht gefunden!</h3></body></html>", $call, $dir);
     return;
   }
 
-  if (($p = popen('vboxtoau < ' . $fname, 'r')) === false) {
+  system('vboxtoau < ' . $fname . ' > ' . $aufile);
+
+  if (($f = fopen($aufile, 'r')) === false) {
     printf("<html><body><h3>Anruf %s in %s konnte geoeffnet werden!</h3></body></html>", $call, $dir);
     return;
   }
@@ -116,12 +129,13 @@ function send_call($dir, $call)
 
   header(sprintf('Content-disposition: inline; filename="%s.au"', $call));
   header('Content-Type: audio/basic');
-  header("Cache-Control: ");
-  header("Pragma: ");
+  header("Content-Length: " . filesize($aufile));
+  header("Cache-Control: no-cache" );
+  header("Pragma: no-cache" );
   sleep(1);
-  fpassthru($p);
-
-  pclose($p);
+  fpassthru($f);
+  fclose($f);
+  unlink($aufile);
 }
 
 function archive_call($call)
@@ -141,4 +155,12 @@ function delete_call($dir, $call)
   unlink($basename . '.info');
 }
 
+function save_call()
+{
+  $info = read_info($_POST['dir'], $_POST['call']);
+  $info['name'] = $_POST['name'];
+  $info['note'] = $_POST['note'];
+  write_info($_POST['dir'], $_POST['call'], $info);
+}
+
 ?>