2 define('SPOOL_DIR', '/var/spool/vbox/ttyI6');
4 function read_info($dir, $call)
7 $fname = SPOOL_DIR . '/' . $dir . '/' . $call . '.info';
9 if (is_file($fname) && ($f = fopen($fname, 'r')) !== false) {
10 $line = fgets($f, 1024);
12 $info = unserialize($line);
13 if (empty($info['note'])) $info['note'] = '';
18 function write_info($dir,$fname,$info)
20 if (($f = fopen(SPOOL_DIR . '/' . $dir . '/' . $fname . '.info', 'w')) !== false) {
21 fwrite($f, serialize($info)."\n");
26 function message_info($dir,$fname)
29 $basename = SPOOL_DIR . '/' . $dir . '/' . $fname;
31 if (is_file($basename . '.vmsg')) {
32 if (!is_file($basename . '.info')) {
33 if (($p = popen('vboxmode ' . $basename . '.vmsg', 'r')) !== false) {
35 $line = chop(fgets($p, 1024));
36 $pos = strpos($line, ':')+2;
37 if (strpos($line, 'Speaker name............: ') !== false) {
38 $info['name'] = utf8_encode(substr($line, $pos));
39 } elseif (strpos($line, 'Length..................: ') !== false) {
40 $info['length'] = substr($line, $pos);
41 } elseif (strpos($line, 'Speaker caller number...: ') !== false) {
42 $info['number'] = substr($line, $pos);
43 } elseif (strpos($line, 'Creation time...........: ') !== false) {
44 $info['date'] = substr($line, $pos);
48 $s = stat($basename . '.vmsg');
49 $info['timestamp'] = $s['mtime'];
50 write_info($dir,$fname,$info);
53 $info = read_info($dir,$fname);
59 function call_cmp($a, $b)
61 if (!empty($a['read']) && empty($b['read']))
63 elseif (!empty($b['read']) && empty($a['read']))
65 elseif ($a['timestamp'] > $b['timestamp'])
72 function read_directory($directory)
76 if ($dir = opendir(SPOOL_DIR . '/' . $directory)) {
77 while (($filename = readdir($dir)) !== false) {
78 if (($pos = strpos($filename, '.vmsg')) !== false || ($pos = strpos($filename, '.msg')) !== false) {
79 $fname = substr($filename,0,$pos);
80 $info = message_info($directory, $fname);
81 $info['fname'] = $fname;
88 usort($result, "call_cmp");
92 function callinfo($dir, $call)
94 return read_info($dir, $call);
97 function send_call($dir, $call)
99 $dir = str_replace('/','x',$dir);
100 $call = str_replace('/','x',$call);
102 if ($dir == 'messages')
107 $fname = SPOOL_DIR . '/' . $dir . '/' . $call . $ext;
109 if (!is_file($fname)) {
110 printf("<html><body><h3>Anruf %s in %s nicht gefunden!</h3></body></html>", $call, $dir);
114 if (($p = popen('vboxtoau < ' . $fname, 'r')) === false) {
115 printf("<html><body><h3>Anruf %s in %s konnte geoeffnet werden!</h3></body></html>", $call, $dir);
119 $info = read_info($dir, $call);
120 if (empty($info['read'])) {
121 $info['read'] = date('U');
122 write_info($dir, $call, $info);
125 header(sprintf('Content-disposition: inline; filename="%s.au"', $call));
126 header('Content-Type: audio/basic');
127 header("Cache-Control: ");
135 function archive_call($call)
137 $basename = SPOOL_DIR . '/' . 'incoming' . '/' . $call;
138 $basenew = SPOOL_DIR . '/' . 'archive' . '/' . $call;
140 rename($basename . '.vmsg', $basenew . '.vmsg');
141 rename($basename . '.info', $basenew . '.info');
144 function delete_call($dir, $call)
146 $basename = SPOOL_DIR . '/' . $dir . '/' . $call;
148 unlink($basename . '.vmsg');
149 unlink($basename . '.info');
154 $info = read_info($_POST['dir'], $_POST['call']);
155 $info['name'] = $_POST['name'];
156 $info['note'] = $_POST['note'];
157 write_info($_POST['dir'], $_POST['call'], $info);