function siemens_push_str($phone_ip, $postdata) { $prov_host = gs_get_conf('GS_PROV_HOST'); $data = "POST /server_push.html/ServerPush HTTP/1.1\r\n"; $data .= "User-Agent: Gemeinschaft\r\n"; $data .= "Host: {$phone_ip}:8085\r\n"; $data .= "Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2\r\n"; $data .= "Connection: keep-alive\r\n"; $data .= "Content-Type: application/x-www-form-urlencoded\r\n"; $data .= "Content-Length: " . strLen($postdata) . "\r\n\r\n"; $data .= $postdata; $socket = @fSockOpen($phone_ip, 8085, $error_no, $error_str, 4); if (!$socket) { gs_log(GS_LOG_NOTICE, "Siemens: Failed to open socket - IP: {$phone_ip}"); return 0; } stream_set_timeout($socket, 4); $bytes_written = (int) @fWrite($socket, $data, strLen($data)); @fFlush($socket); $response = @fGetS($socket); @fClose($socket); if (strPos($response, '200') === false) { gs_log(GS_LOG_WARNING, "Siemens: Failed to push to phone {$phone_ip}"); return 0; } gs_log(GS_LOG_DEBUG, "Siemens: Pushed {$bytes_written} bytes to phone {$phone_ip}"); return $bytes_written; }
function aastra_push_str($phone_ip, $xml) { $prov_host = gs_get_conf('GS_PROV_HOST'); //FIXME - call wget or something. this function should not block // for so long! // see _gs_prov_phone_checkcfg_by_ip_do_aastra() in // opt/gemeinschaft/inc/gs-fns/gs_prov_phone_checkcfg.php //$xml = utf8_decode($xml); if (subStr($xml, 0, 5) !== '<' . '?xml') { $xmlpi = '<' . '?xml version="1.0" encoding="UTF-8"?' . '>' . "\n"; } else { $xmlpi = ''; } $data = "POST / HTTP/1.1\r\n"; $data .= "Host: {$phone_ip}\r\n"; $data .= "Referer: {$prov_host}\r\n"; $data .= "Connection: Close\r\n"; $data .= "Content-Type: text/xml; charset=utf-8\r\n"; $data .= "Content-Length: " . (strLen('xml=') + strLen($xmlpi) + strLen($xml)) . "\r\n"; $data .= "\r\n"; $data .= 'xml=' . $xmlpi . $xml; $socket = @fSockOpen($phone_ip, 80, $error_no, $error_str, 4); if (!$socket) { gs_log(GS_LOG_NOTICE, "Aastra: Failed to open socket - IP: {$phone_ip}"); return 0; } stream_set_timeout($socket, 4); $bytes_written = (int) @fWrite($socket, $data, strLen($data)); @fFlush($socket); $response = @fGetS($socket); @fClose($socket); if (strPos($response, '200') === false) { gs_log(GS_LOG_WARNING, "Aastra: Failed to push XML to phone {$phone_ip}"); return 0; } gs_log(GS_LOG_DEBUG, "Aastra: Pushed {$bytes_written} bytes to phone {$phone_ip}"); return $bytes_written; }
function gs_agi_read_line() { $buf = ''; $i = 0; $select = array(STDIN); # needs to be passed by reference $null = null; # needs to be passed by reference stream_set_blocking(STDIN, true); stream_set_timeout(STDIN, 1); while (true) { if (stream_select($select, $null, $null, 0, 500000) > 0) { $buf .= fGetS(STDIN, 8192); if (subStr($buf, -1) === "\n") { # end of line //$buf = subStr($buf,0,-1); $buf = rTrim($buf); break; } } if (++$i > 10) { # 500000 us * 10 = 5 s gs_agi_log(GS_LOG_WARNING, "Timeout while waiting for input. Buffer is \"{$buf}\"."); if ($buf === '') { return false; } break; } } //gs_agi_log( GS_LOG_DEBUG, "LINE: $buf (".strLen($buf).")" ); return $buf; }
_fake_agi_send($pipes[0], ''); $select = array($pipes[1]); # needs to be passed by reference $null = null; # needs to be passed by reference stream_set_blocking($pipes[1], true); while (true) { $agi_cmd_line = ''; $i = 0; while (true) { if (fEof($pipes[1])) { # AGI script exited break 2; } if (stream_select($select, $null, $null, 1) > 0) { $agi_cmd_line .= fGetS($pipes[1], 8192); if (subStr($agi_cmd_line, -1) === "\n") { # end of line //$agi_cmd_line = subStr($agi_cmd_line,0,-1); $agi_cmd_line = rTrim($agi_cmd_line); break; } } if (++$i > 2) { # 1 s * 10 = 10 s gs_log(GS_LOG_WARNING, 'Timeout while waiting for AGI command.'); echo "### Timeout while waiting for AGI command. Buffer is \"{$agi_cmd_line}\".\n"; //echo "### ". (int)fEof($pipes[1]) ."\n"; if ($agi_cmd_line === '') { $agi_cmd_line = false; }
function getAllGroups($users = false, $sort = true) { global $hlaska, $pwdfname; //kontrola existence souboru hesel if (!File_Exists($pwdfname)) { $hlaska = "Nenalezen soubor hesel"; return false; } //cteni souboru hesel $fHesla = fopen($pwdfname, "r"); $groups = array(); while (!fEof($fHesla)) { $row = fGetS($fHesla); $row = explode(",", $row); $group = array(); if ($row[1]) { $group = explode(" ", $row[1]); } if ($users && $row[0]) { $group[] = $row[0]; } $groups = array_merge($groups, $group); } fclose($fHesla); $groups = array_unique($groups); if ($sort) { asort($groups); } return $groups; }