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'] = str_replace(' seconds', 's', 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);
54 } elseif (is_file($basename . '.msg')) {
55 if (is_file($basename . '.info'))
56 $info = read_info($dir,$fname);
62 function call_cmp($a, $b)
64 if (!empty($a['read']) && empty($b['read']))
66 elseif (!empty($b['read']) && empty($a['read']))
68 elseif ($a['timestamp'] > $b['timestamp'])
70 elseif ($a['timestamp'] < $b['timestamp'])
75 function read_directory($directory)
79 if ($dir = opendir(SPOOL_DIR . '/' . $directory)) {
80 while (($filename = readdir($dir)) !== false) {
81 if (($pos = strpos($filename, '.vmsg')) !== false || ($pos = strpos($filename, '.msg')) !== false) {
82 $fname = substr($filename,0,$pos);
83 $info = message_info($directory, $fname);
84 $info['fname'] = $fname;
90 error_log('Cannot open directory ' . SPOOL_DIR . '/' . $directory);
93 usort($result, "call_cmp");
97 function callinfo($dir, $call)
99 return read_info($dir, $call);
102 function send_call($dir, $call)
104 if ($_SERVER['HTTP_USER_AGENT'] == 'NSPlayer') return;
106 $dir = str_replace('/','x',$dir);
107 $call = str_replace('/','x',$call);
109 if ($dir == 'messages')
114 $fname = SPOOL_DIR . '/' . $dir . '/' . $call . $ext;
115 $aufile = SPOOL_DIR . '/' . $dir . '/' . $call . '.au';
117 if (!is_file($fname)) {
118 printf("<html><body><h3>Anruf %s in %s nicht gefunden!</h3></body></html>", $call, $dir);
122 system('vboxtoau < ' . $fname . ' > ' . $aufile);
124 if (($f = fopen($aufile, 'r')) === false) {
125 printf("<html><body><h3>Anruf %s in %s konnte geoeffnet werden!</h3></body></html>", $call, $dir);
129 $info = read_info($dir, $call);
130 if (empty($info['read'])) {
131 $info['read'] = date('U');
132 write_info($dir, $call, $info);
135 header(sprintf('Content-disposition: inline; filename="%s.au"', $call));
136 header('Content-Type: audio/basic');
137 header("Content-Length: " . filesize($aufile));
138 header("Cache-Control: no-cache" );
139 header("Pragma: no-cache" );
146 function archive_call($call)
148 $basename = SPOOL_DIR . '/' . 'incoming' . '/' . $call;
149 $basenew = SPOOL_DIR . '/' . 'archive' . '/' . $call;
151 rename($basename . '.vmsg', $basenew . '.vmsg');
152 rename($basename . '.info', $basenew . '.info');
155 function delete_call($dir, $call)
157 $basename = SPOOL_DIR . '/' . $dir . '/' . $call;
159 unlink($basename . '.vmsg');
160 unlink($basename . '.info');
165 $info = read_info($_POST['dir'], $_POST['call']);
166 $info['name'] = $_POST['name'];
167 $info['note'] = $_POST['note'];
168 write_info($_POST['dir'], $_POST['call'], $info);
173 error_log(var_export($_POST,true));
175 $fname = str_replace(array('$',' ','/'),
179 $info = read_info('incoming', $_POST['call']);
180 $info['note'] = $_POST['note'];
181 write_info('incoming', $_POST['call'], $info);
183 error_log('fname -> ' . $fname);
185 $basename = SPOOL_DIR . '/incoming/' . $_POST['call'];
186 $newbase = SPOOL_DIR . '/messages/' . $fname;
188 rename($basename . '.vmsg', $newbase . '.msg');
189 rename($basename . '.info', $newbase . '.info');