+<?
+define('SPOOL_DIR', '/var/spool/vbox/ttyI6');
+
+function read_info($dir, $call)
+{
+ $info = array();
+ if (($f = fopen(SPOOL_DIR . '/' . $dir . '/' . $call . '.info', 'r')) !== false) {
+ $line = fgets($f, 1024);
+ fclose($f);
+ $info = unserialize($line);
+ if (empty($info['note'])) $info['note'] = '';
+ }
+ return $info;
+}
+
+function write_info($dir,$fname,$info)
+{
+ if (($f = fopen(SPOOL_DIR . '/' . $dir . '/' . $fname . '.info', 'w')) !== false) {
+ fwrite($f, serialize($info)."\n");
+ fclose($f);
+ }
+}
+
+function message_info($dir,$fname)
+{
+ $info = array();
+ $basename = SPOOL_DIR . '/' . $dir . '/' . $fname;
+
+ if (is_file($basename . '.vmsg')) {
+ if (!is_file($basename . '.info')) {
+ if (($p = popen('vboxmode ' . $basename . '.vmsg', 'r')) !== false) {
+ while (!feof($p)) {
+ $line = chop(fgets($p, 1024));
+ $pos = strpos($line, ':')+2;
+ if (strpos($line, 'Speaker name............: ') !== false) {
+ $info['name'] = utf8_encode(substr($line, $pos));
+ } elseif (strpos($line, 'Length..................: ') !== false) {
+ $info['length'] = substr($line, $pos);
+ } elseif (strpos($line, 'Speaker caller number...: ') !== false) {
+ $info['number'] = substr($line, $pos);
+ } elseif (strpos($line, 'Creation time...........: ') !== false) {
+ $info['date'] = substr($line, $pos);
+ }
+ }
+ pclose($p);
+ $s = stat($basename . '.vmsg');
+ $info['timestamp'] = $s['mtime'];
+ write_info($dir,$fname,$info);
+ }
+ }
+ $info = read_info($dir,$fname);
+ }
+
+ return $info;
+}
+
+function get_incoming()
+{
+ $result = array();
+
+ if ($dir = opendir(SPOOL_DIR . '/incoming')) {
+ while (($filename = readdir($dir)) !== false) {
+ if (($pos = strpos($filename, '.vmsg')) !== false) {
+ $fname = substr($filename,0,$pos);
+ $info = message_info('incoming', $fname);
+ $info['fname'] = $fname;
+ $result[] = $info;
+ }
+ }
+ closedir($dir);
+ }
+ return $result;
+}
+
+function callinfo($dir, $call)
+{
+ return read_info($dir, $call);
+}
+
+function send_call($dir, $call)
+{
+ $dir = str_replace('/','x',$dir);
+ $call = str_replace('/','x',$call);
+ $fname = SPOOL_DIR . '/' . $dir . '/' . $call . '.vmsg';
+
+ 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) {
+ printf("<html><body><h3>Anruf %s in %s konnte geoeffnet werden!</h3></body></html>", $call, $dir);
+ return;
+ }
+
+ header(sprintf('Content-disposition: inline; filename="%s.au"', $call));
+ header('Content-Type: audio/basic');
+ header("Cache-Control: ");
+ header("Pragma: ");
+ sleep(1);
+ fpassthru($p);
+
+ pclose($p);
+}
+
+?>
\ No newline at end of file