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; }
public function accept($extractionResult) { foreach (new ArrayObject($extractionResult->getTriples()) as $triple) { // TODO: make sure that https://sourceforge.net/tracker/?func=detail&aid=2901137&group_id=190976&atid=935520 is fixed $tripleString = explode(">", $triple->toStringNoEscape()); $s = trim(str_replace("<", "", $tripleString[0])); $s = preg_replace('~^' . DB_RESOURCE_NS . '~', "", $s); $p = trim(str_replace("<", "", $tripleString[1])); $p = preg_replace('~^' . DB_PROPERTY_NS . '~', "", $p); if (preg_match('/^<http:/', $tripleString[2])) { $object_is = 'r'; } else { $object_is = 'l'; } $o = trim(str_replace("<", "", $tripleString[2])); $dtypePos = strpos($o, "^^"); $langPos = strpos($o, "@"); if ($dtypePos) { $o = substr($o, 0, $dtypePos); } if ($langPos) { $o = substr($o, 0, $langPos); } $o = preg_replace('/(^")|("$)/', "", $o); $o = preg_replace('~^' . DB_RESOURCE_NS . '~', "", $o); #if ( !preg_match('/^[0-9\.,]+$/', $o) ) $o = "\"" . $o . "\""; #print("\"" . $s . "\"" . $this->delimiter . "\"" . $p . "\"" . $this->delimiter . $o . "\n"); //triple in Datei schreiben fWrite($this->DumpFile, $s . $this->delimiter . $p . $this->delimiter . $o . $this->delimiter . $object_is . "\n"); } $this->counter++; echo $this->counter . "\n"; }
function send_sip_packet($ip, $port, $packet, $source_ip = false) { $spoof = $source_ip ? '-s \'' . $source_ip . '\'' : ''; $p = pOpen('netcat -u -n -p 5060 -w 1 -q 0 ' . $spoof . ' ' . $ip . ' ' . $port . ' >>/dev/null', 'wb'); fWrite($p, $packet, strLen($packet)); fClose($p); }
function InitRecordCall($filename, $index, $comment) { //FIXME $user = gs_user_get($_SESSION['sudo_user']['name']); $call = "Channel: SIP/" . $_SESSION['sudo_user']['info']['ext'] . "\n" . "MaxRetries: 0\n" . "WaitTime: 15\n" . "Context: vm-rec-multiple\n" . "Extension: webdialrecord\n" . "Callerid: {$comment} <Aufnahme>\n" . "Setvar: __user_id=" . $_SESSION['sudo_user']['info']['id'] . "\n" . "Setvar: __user_name=" . $_SESSION['sudo_user']['info']['ext'] . "\n" . "Setvar: CHANNEL(language)=" . gs_get_conf('GS_INTL_ASTERISK_LANG', 'de') . "\n" . "Setvar: __is_callfile_origin=1\n" . "Setvar: __callfile_from_user="******"\n" . "Setvar: __record_file=" . $filename . "\n"; $filename = '/tmp/gs-' . $_SESSION['sudo_user']['info']['id'] . '-' . _pack_int(time()) . rand(100, 999) . '.call'; $cf = @fOpen($filename, 'wb'); if (!$cf) { gs_log(GS_LOG_WARNING, 'Failed to write call file "' . $filename . '"'); echo 'Failed to write call file.'; die; } @fWrite($cf, $call, strLen($call)); @fClose($cf); @chmod($filename, 0666); $spoolfile = '/var/spool/asterisk/outgoing/' . baseName($filename); if (!gs_get_conf('GS_INSTALLATION_TYPE_SINGLE')) { $our_host_ids = @gs_get_listen_to_ids(); if (!is_array($our_host_ids)) { $our_host_ids = array(); } $user_is_on_this_host = in_array($_SESSION['sudo_user']['info']['host_id'], $our_host_ids); } else { $user_is_on_this_host = true; } if ($user_is_on_this_host) { # the Asterisk of this user and the web server both run on this host $err = 0; $out = array(); @exec('sudo mv ' . qsa($filename) . ' ' . qsa($spoolfile) . ' 1>>/dev/null 2>>/dev/null', $out, $err); if ($err != 0) { @unlink($filename); gs_log(GS_LOG_WARNING, 'Failed to move call file "' . $filename . '" to "' . '/var/spool/asterisk/outgoing/' . baseName($filename) . '"'); echo 'Failed to move call file.'; die; } } else { $cmd = 'sudo scp -o StrictHostKeyChecking=no -o BatchMode=yes ' . qsa($filename) . ' ' . qsa('root@' . $user['host'] . ':' . $filename); //echo $cmd, "\n"; @exec($cmd . ' 1>>/dev/null 2>>/dev/null', $out, $err); @unlink($filename); if ($err != 0) { gs_log(GS_LOG_WARNING, 'Failed to scp call file "' . $filename . '" to ' . $user['host']); echo 'Failed to scp call file.'; die; } //remote_exec( $user['host'], $cmd, 10, $out, $err ); // <-- does not use sudo! $cmd = 'sudo ssh -o StrictHostKeyChecking=no -o BatchMode=yes -l root ' . qsa($user['host']) . ' ' . qsa('mv ' . qsa($filename) . ' ' . qsa($spoolfile)); //echo $cmd, "\n"; @exec($cmd . ' 1>>/dev/null 2>>/dev/null', $out, $err); if ($err != 0) { gs_log(GS_LOG_WARNING, 'Failed to mv call file "' . $filename . '" on ' . $user['host'] . ' to "' . $spoolfile . '"'); echo 'Failed to mv call file on remote host.'; die; } } }
public function accept($extractionResult) { foreach (new ArrayObject($extractionResult->getTriples()) as $triple) { //triple in Datei schreiben fWrite($this->DumpFile, $triple->toString()); //print($triple->toString()); } $this->counter++; echo $this->counter . "\n"; }
/** * @see \dns\system\cache\source\ICacheSource::set() */ public function set($cacheName, $value, $maxLifetime) { $filename = $this->getFilename($cacheName); $content = "<?php exit; /* cache: " . $cacheName . " (generated at " . gmdate('r') . ") DO NOT EDIT THIS FILE */ ?>\n"; $content .= serialize($value); if (!file_exists($filename)) { @touch($filename); } $handler = fOpen($filename, "a+"); fWrite($handler, $content); fClose($handler); }
function gs_hylafax_authfile_create($authfile) { # connect to db # $db = gs_db_master_connect(); if (!$db) { return new GsError('Could not connect to database.'); } # get user list # $rs = $db->execute('SELECT `id`, `user`, `pin` FROM `users` WHERE `nobody_index` IS NULL ORDER BY `id`'); if (!$rs) { return new GsError('Error.'); } # create temporary hylafax host/user authentication file # if (file_exists($authfile) && !is_writable($authfile)) { @exec('sudo rm -f ' . qsa($authfile) . ' 2>>/dev/null'); } $fh = @fOpen($authfile, 'w'); if (!$fh) { return new GsError('Failed to open HylaFax authfile.'); } # create localhost access without authentication first, if enabled # if (gs_get_conf('GS_FAX_NOAUTH_LOCALHOST') === true) { fWrite($fh, "127.0.0.1\n", strLen("127.0.0.1\n")); } # create admin entry first # if (gs_get_conf('GS_FAX_HYLAFAX_ADMIN') != '') { $crypted = crypt(gs_get_conf('GS_FAX_HYLAFAX_PASS'), 'pF'); $user_entry = '^' . preg_quote(gs_get_conf('GS_FAX_HYLAFAX_ADMIN')) . '@:' . '0' . ':' . $crypted . ':' . $crypted . "\n"; fWrite($fh, $user_entry, strLen($user_entry)); } # create user entries # while ($user = $rs->fetchRow()) { $crypted = crypt($user['pin'], 'ml'); $user_entry = '^' . preg_quote($user['user']) . '@:' . $user['id'] . ':' . $crypted . "\n"; fWrite($fh, $user_entry, strLen($user_entry)); } # close file # if (@fclose($fh)) { return true; } else { return new GsError('Error.'); } }
function gs_write_error($data) { if (!defined('STDERR')) { define('STDERR', @fOpen('php://stderr', 'wb')); } if (php_sapi_name() === 'cli' && STDERR) { @fWrite(STDERR, $data, strLen($data)); @fFlush(STDERR); } else { echo $data; } }
function gif_outputAsPng($gif, $lpszFileName, $bgColor = -1) { if (!isset($gif) || @get_class($gif) != "cgif" || !$gif->loaded() || $lpszFileName == "") { return false; } $fd = $gif->getPng($bgColor); if (strlen($fd) <= 0) { return false; } if (!($fh = @fOpen($lpszFileName, "wb"))) { return false; } @fWrite($fh, $fd, strlen($fd)); @fFlush($fh); @fClose($fh); return true; }
public function ami_send_command($command) { @fWrite($this->_socket, $command, strLen($command)); @fFlush($this->_socket); $data = array(); while (!fEof($this->_socket)) { $tmp = @fgets($this->_socket, 8192); if (strlen(trim($tmp)) <= 0) { break; } list($first, $last) = explode(':', $tmp); $data[trim($first)] = trim($last); usleep(1000); # sleep 0.001 secs } return $data; }
public function ami_send_command($command) { @fWrite($this->_socket, $command, strLen($command)); @fFlush($this->_socket); $data = array(); while (!fEof($this->_socket)) { $tmp = @fRead($this->_socket, 8192); list($first, $last) = explode(':', $tmp); $data[trim($first)] = trim($last); if (@preg_match('/\\r\\n\\r\\n/S', $tmp)) { break; } usleep(1000); # sleep 0.001 secs } return $data; }
function gs_send_phone_desktop_msg($ip, $port, $ext, $registrar, $text, $extra = array()) { static $sock = null; static $lAddr = '0.0.0.0'; static $lPort = 0; static $have_sockets = null; if ($have_sockets === null) { $have_sockets = function_exists('socket_create'); // about 15 to 45 % faster } if (is_array($extra) && array_key_exists('fake_callid', $extra)) { $fake_callid = $extra['fake_callid']; } else { $fake_callid = rand(1000000000, 2000000000); } if ($have_sockets) { if (!$sock) { $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); if (!$sock) { return false; } //socket_set_option($sock, SOL_SOCKET, SO_REUSEADDR, 1); //socket_bind($sock, '0.0.0.0', 12345); @socket_getSockName($sock, $lAddr, $lPort); //echo "Local socket is at $lAddr:$lPort\n"; @socket_set_nonblock($sock); } } else { $sock = @fSockOpen('udp://' . $ip, $port, $err, $errmsg, 1); if (!$sock) { return false; } @stream_set_blocking($sock, 0); @stream_set_timeout($sock, 1); } $sipmsg = 'MESSAGE sip:' . $ext . '@' . $ip . ' SIP/2.0' . "\r\n" . 'Via: SIP/2.0/UDP ' . $registrar . ':' . $lPort . "\r\n" . 'To: sip:' . $ext . '@' . $ip . '' . "\r\n" . 'Call-ID: ' . $fake_callid . '@' . $registrar . "\r\n" . 'CSeq: 1 MESSAGE' . "\r\n" . 'Content-Type: text/plain; charset=utf-8' . "\r\n" . 'Max-Forwards: 9' . "\r\n" . 'From: sip:fake@' . $registrar . ':' . $lPort . ';tag=fake' . "\r\n" . 'Content-Length: ' . strLen($text) . "\r\n" . 'Content-Disposition: desktop' . "\r\n" . "\r\n" . $text; if ($have_sockets) { return @socket_sendto($sock, $sipmsg, strLen($sipmsg), 0, $ip, $port); } else { $written = @fWrite($sock, $sipmsg, strlen($sipmsg)); @fClose($sock); return $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_queue_status($host, $ext, $getMembers, $getCallers) { static $hosts = array(); if (gs_get_conf('GS_INSTALLATION_TYPE_SINGLE')) { $host = '127.0.0.1'; } if (!isset($hosts[$host])) { $hosts[$host] = array('sock' => null, 'lasttry' => 0); } if (!is_resource($hosts[$host]['sock'])) { if ($hosts[$host]['lasttry'] > time() - 60) { # we have tried less than a minute ago $hosts[$host]['lasttry'] = time(); return false; } $hosts[$host]['lasttry'] = time(); $sock = @fSockOpen($host, 5038, $err, $errMsg, 2); if (!is_resource($sock)) { gs_log(GS_LOG_WARNING, 'Connection to AMI on ' . $host . ' failed'); return false; } $data = _sock_read($sock, 3, '/[\\r\\n]/'); if (!preg_match('/^Asterisk [^\\/]+\\/(\\d(?:\\.\\d)?)/mis', $data, $m)) { gs_log(GS_LOG_WARNING, 'Incompatible Asterisk manager interface on ' . $host); $m = array(1 => '0.0'); } else { if ($m[1] > '1.1') { # Asterisk 1.4: manager 1.0 # Asterisk 1.6: manager 1.1 gs_log(GS_LOG_NOTICE, 'Asterisk manager interface on ' . $host . ' speaks a new protocol version (' . $m[1] . ')'); # let's try anyway and hope to understand it } } $hosts[$host]['sock'] = $sock; $req = "Action: Login\r\n" . "Username: "******"gscc" . "\r\n" . "Secret: " . "gspass" . "\r\n" . "Events: off\r\n" . "\r\n"; @fWrite($sock, $req, strLen($req)); @fFlush($sock); $data = _sock_read2($sock, 5, '/\\r\\n\\r\\n/S'); if (!preg_match('/Authentication accepted/i', $data)) { gs_log(GS_LOG_WARNING, 'Authentication to AMI on ' . $host . ' failed'); $hosts[$host]['sock'] = null; return false; } } else { $sock = $hosts[$host]['sock']; } $queue_stats = array('maxlen' => null, 'calls' => null, 'holdtime' => null, 'completed' => null, 'abandoned' => null, 'sl' => null, 'slp' => null); if ($getMembers) { $queue_stats['members'] = array(); } if ($getCallers) { $queue_stats['callers'] = array(); } $default_member = array('dynamic' => null, 'calls' => null, 'lastcall' => null, 'devstate' => null, 'paused' => null); $default_caller = array('channel' => null, 'cidnum' => null, 'cidname' => null, 'wait' => null); $req = "Action: QueueStatus\r\n" . "Queue: " . $ext . "\r\n" . "\r\n"; @fWrite($sock, $req, strLen($req)); @fFlush($sock); $resp = trim(_sock_read2($sock, 2, '/Event:\\s*QueueStatusComplete\\r\\n\\r\\n/i')); //echo "\n$resp\n\n"; if (!preg_match('/^Response:\\s*Success/is', $resp)) { return false; } $resp = preg_split('/\\r\\n\\r\\n/S', $resp); /* echo "<pre>"; print_r($resp); echo "</pre>"; */ $manager_ok = false; foreach ($resp as $pkt) { $pkt = lTrim($pkt); if (preg_match('/^Event:\\s*QueueParams/is', $pkt)) { if (!preg_match('/^Queue:\\s*' . $ext . '/mis', $pkt)) { continue; } //echo $pkt, "\n\n"; if (preg_match('/^Max:\\s*(\\d+)/mis', $pkt, $m)) { $queue_stats['maxlen'] = (int) $m[1] > 0 ? (int) $m[1] : null; } if (preg_match('/^Calls:\\s*(\\d+)/mis', $pkt, $m)) { $queue_stats['calls'] = (int) $m[1]; } if (preg_match('/^Holdtime:\\s*(\\d+)/mis', $pkt, $m)) { $queue_stats['holdtime'] = (int) $m[1]; } if (preg_match('/^Completed:\\s*(\\d+)/mis', $pkt, $m)) { $queue_stats['completed'] = (int) $m[1]; } if (preg_match('/^Abandoned:\\s*(\\d+)/mis', $pkt, $m)) { $queue_stats['abandoned'] = (int) $m[1]; } if (preg_match('/^ServiceLevel:\\s*(\\d+)/mis', $pkt, $m)) { $queue_stats['sl'] = (int) $m[1]; } if (preg_match('/^ServiceLevelPerf:\\s*(\\d+?(\\.\\d+)?)/mis', $pkt, $m)) { $queue_stats['slp'] = (double) $m[1]; } $manager_ok = true; } elseif ($getMembers && preg_match('/^Event:\\s*QueueMember/is', $pkt)) { if (!preg_match('/^Queue:\\s*' . $ext . '/mis', $pkt)) { continue; } if (!preg_match('/^Location:\\s*([A-Z\\d\\/]+)/mis', $pkt, $m)) { continue; } $loc = $m[1]; $queue_stats['members'][$loc] = $default_member; //echo $pkt, "\n\n"; if (preg_match('/^Membership:\\s*([a-z]+)/mis', $pkt, $m)) { $queue_stats['members'][$loc]['dynamic'] = $m[1] != 'static'; } if (preg_match('/^CallsTaken:\\s*(\\d+)/mis', $pkt, $m)) { $queue_stats['members'][$loc]['calls'] = (int) $m[1]; } if (preg_match('/^LastCall:\\s*(\\d+)/mis', $pkt, $m)) { $queue_stats['members'][$loc]['lastcall'] = (int) $m[1]; } if (preg_match('/^Status:\\s*(\\d+)/mis', $pkt, $m)) { $queue_stats['members'][$loc]['devstate'] = (int) $m[1]; } if (preg_match('/^Paused:\\s*(\\d+)/mis', $pkt, $m)) { $queue_stats['members'][$loc]['paused'] = (int) $m[1] > 0; } } elseif ($getCallers && preg_match('/^Event:\\s*QueueEntry/is', $pkt)) { if (!preg_match('/^Queue:\\s*' . $ext . '/mis', $pkt)) { continue; } if (!preg_match('/^Position:\\s*(\\d+)/mis', $pkt, $m)) { continue; } $pos = (int) $m[1]; $queue_stats['callers'][$pos] = $default_caller; //echo $pkt, "\n\n"; if (preg_match('/^Channel:\\s*([^\\n\\r]+)/mis', $pkt, $m)) { $queue_stats['callers'][$pos]['dynamic'] = trim($m[1]); } if (preg_match('/^CallerID:\\s*([^\\n\\r]+)/mis', $pkt, $m)) { $queue_stats['callers'][$pos]['cidnum'] = strToLower(trim($m[1])) != 'unknown' ? trim($m[1]) : null; } if (preg_match('/^CallerIDName:\\s*([^\\n\\r]+)/mis', $pkt, $m)) { $queue_stats['callers'][$pos]['cidname'] = strToLower(trim($m[1])) != 'unknown' ? trim($m[1]) : null; } if (preg_match('/^Wait:\\s*(\\d+)/mis', $pkt, $m)) { $queue_stats['callers'][$pos]['wait'] = (int) $m[1]; } } } if (!$manager_ok && $getMembers) { # failed to get information about the queue from the manager # interface. this happens after a reload of Asterisk when # no call has entered the queue using Queue() yet $queue_stats['calls'] = 0; $queue_stats['completed'] = 0; $queue_stats['abandoned'] = 0; $queue_stats['holdtime'] = 0; include_once GS_DIR . 'inc/db_connect.php'; $db = @gs_db_slave_connect(); if (!$db) { return $queue_stats; } $maxlen = (int) $db->executeGetOne('SELECT `maxlen` FROM `ast_queues` WHERE `name`=\'' . $db->escape($ext) . '\''); $queue_stats['maxlen'] = $maxlen > 0 ? $maxlen : null; $rs = $db->execute('SELECT `interface` FROM `ast_queue_members` WHERE `queue_name`=\'' . $db->escape($ext) . '\''); $queue_members = array(); while ($r = $rs->fetchRow()) { if (strToUpper(subStr($r['interface'], 0, 4)) == 'SIP/') { $queue_members[] = subStr($r['interface'], 4); } else { $queue_members[] = $r['interface']; } } if (count($queue_members) < 1) { return $queue_stats; } foreach ($queue_members as $queue_member) { $queue_stats['members']['SIP/' . $queue_member] = $default_member; } $ext_states = @gs_extstate($host, $queue_members); if (!is_array($ext_states)) { return $queue_stats; } foreach ($queue_members as $queue_member) { $queue_stats['members']['SIP/' . $queue_member]['devstate'] = extstate_to_devstate(@$ext_states[$queue_member]); } } /* echo "<pre>"; print_r($queue_stats); echo "</pre>"; */ return $queue_stats; }
function gs_callwaiting_activate($user, $active) { if (!preg_match('/^[a-z0-9\\-_.]+$/', $user)) { return new GsError('User must be alphanumeric.'); } $active = !!$active; # connect to db # $db = gs_db_master_connect(); if (!$db) { return new GsError('Could not connect to database.'); } # get user_id # $user_id = $db->executeGetOne('SELECT `id` FROM `users` WHERE `user`=\'' . $db->escape($user) . '\''); if (!$user_id) { return new GsError('Unknown user.'); } # get user_ext $user_ext = $db->executeGetOne('SELECT `s`.`name` `ext` FROM `users` `u` JOIN `ast_sipfriends` `s` ON (`s`.`_user_id`=`u`.`id`) WHERE `u`.`user`=\'' . $db->escape($user) . '\''); if (!$user_ext) { return new GsError('Unknown user.'); } # (de)activate # $num = $db->executeGetOne('SELECT COUNT(*) FROM `callwaiting` WHERE `user_id`=' . $user_id); if ($num < 1) { $ok = $db->execute('INSERT INTO `callwaiting` (`user_id`, `active`) VALUES (' . $user_id . ', 0)'); } else { $ok = true; } $ok = $ok && $db->execute('UPDATE `callwaiting` SET `active`=' . (int) $active . ' WHERE `user_id`=' . $user_id); if (!$ok) { return new GsError('Failed to set call waiting.'); } $call = "Channel: local/toggle@toggle-cwait-hint\n" . "MaxRetries: 0\n" . "WaitTime: 15\n" . "Context: toggle-cwait-hint\n" . "Extension: toggle\n" . "Callerid: {$user} <Toggle>\n" . "Setvar: __user_id=" . $user_id . "\n" . "Setvar: __user_name=" . $user_ext . "\n" . "Setvar: CHANNEL(language)=" . gs_get_conf('GS_INTL_ASTERISK_LANG', 'de') . "\n" . "Setvar: __is_callfile_origin=1\n" . "Setvar: __callfile_from_user="******"\n" . "Setvar: __record_file=" . $filename . "\n"; $filename = '/tmp/gs-' . $user_id . '-' . time() . '-' . rand(10000, 99999) . '.call'; $cf = @fOpen($filename, 'wb'); if (!$cf) { gs_log(GS_LOG_WARNING, 'Failed to write call file "' . $filename . '"'); return new GsError('Failed to write call file.'); } @fWrite($cf, $call, strLen($call)); @fClose($cf); @chmod($filename, 0666); $spoolfile = '/var/spool/asterisk/outgoing/' . baseName($filename); if (!gs_get_conf('GS_INSTALLATION_TYPE_SINGLE')) { $our_host_ids = @gs_get_listen_to_ids(); if (!is_array($our_host_ids)) { $our_host_ids = array(); } $user_is_on_this_host = in_array($_SESSION['sudo_user']['info']['host_id'], $our_host_ids); } else { $user_is_on_this_host = true; } if ($user_is_on_this_host) { # the Asterisk of this user and the web server both run on this host $err = 0; $out = array(); @exec('sudo mv ' . qsa($filename) . ' ' . qsa($spoolfile) . ' 1>>/dev/null 2>>/dev/null', $out, $err); if ($err != 0) { @unlink($filename); gs_log(GS_LOG_WARNING, 'Failed to move call file "' . $filename . '" to "' . $spoolfile . '"'); return new GsError('Failed to move call file.'); } } else { $cmd = 'sudo scp -o StrictHostKeyChecking=no -o BatchMode=yes ' . qsa($filename) . ' ' . qsa('root@' . $user['host'] . ':' . $filename); //echo $cmd, "\n"; @exec($cmd . ' 1>>/dev/null 2>>/dev/null', $out, $err); @unlink($filename); if ($err != 0) { gs_log(GS_LOG_WARNING, 'Failed to scp call file "' . $filename . '" to ' . $user['host']); return new GsError('Failed to scp call file.'); } //remote_exec( $user['host'], $cmd, 10, $out, $err ); // <-- does not use sudo! $cmd = 'sudo ssh -o StrictHostKeyChecking=no -o BatchMode=yes -l root ' . qsa($user['host']) . ' ' . qsa('mv ' . qsa($filename) . ' ' . qsa($spoolfile)); //echo $cmd, "\n"; @exec($cmd . ' 1>>/dev/null 2>>/dev/null', $out, $err); if ($err != 0) { gs_log(GS_LOG_WARNING, 'Failed to mv call file "' . $filename . '" on ' . $user['host'] . ' to "' . $spoolfile . '"'); return new GsError('Failed to mv call file on remote host.'); } } # reload phone config # //$user_name = $db->executeGetOne( 'SELECT `name` FROM `ast_sipfriends` WHERE `_user_id`='. $user_id ); //@ exec( 'asterisk -rx \'sip notify snom-reboot '. $user_name .'\'' ); //@ gs_prov_phone_checkcfg_by_user( $user, false ); //FIXME return true; }
function gs_callforward_activate($user, $source, $case, $active) { if (!preg_match('/^[a-z0-9\\-_.]+$/', $user)) { return new GsError('User must be alphanumeric.'); } if (!in_array($source, array('internal', 'external'), true)) { return new GsError('Source must be internal|external.'); } if (!in_array($case, array('always', 'busy', 'unavail', 'offline'), true)) { return new GsError('Case must be always|busy|unavail|offline.'); } if (!in_array($active, array('no', 'std', 'var', 'vml', 'ano', 'trl', 'par'), true)) { return new GsError('Active must be no|std|var|vml|ano|trl|par.'); } # connect to db # $db = gs_db_master_connect(); if (!$db) { return new GsError('Could not connect to database.'); } # get user_id # $user_id = $db->executeGetOne('SELECT `id` FROM `users` WHERE `user`=\'' . $db->escape($user) . '\''); if (!$user_id) { return new GsError('Unknown user.'); } # get user_ext # $user_ext = $db->executeGetOne('SELECT `name` FROM `ast_sipfriends` WHERE `_user_id`=\'' . $db->escape($user_id) . '\''); if (!$user_ext) { return new GsError('Unknown user extension.'); } # check if user has an entry # $num = $db->executeGetOne('SELECT COUNT(*) FROM `callforwards` WHERE `user_id`=' . $user_id . ' AND `source`=\'' . $db->escape($source) . '\' AND `case`=\'' . $db->escape($case) . '\''); if ($num < 1) { $ok = $db->execute('INSERT INTO `callforwards` (`user_id`, `source`, `case`, `number_std`, `number_var`, `number_vml`, `active`) VALUES (' . $user_id . ', \'' . $db->escape($source) . '\', \'' . $db->escape($case) . '\', \'\', \'\', \'\', \'no\')'); } else { $ok = true; } # do not allow time rules if no time rules are defined # if ($active == 'trl') { $id = (int) $db->executeGetOne('SELECT `_user_id` from `cf_timerules` WHERE `_user_id`=' . $user_id); if (!$id) { return new GsError('No time rules defined. Cannot activate call forward.'); } } else { if ($active == 'par') { $id = (int) $db->executeGetOne('SELECT `_user_id` from `cf_parallelcall` WHERE `_user_id`=' . $user_id); if (!$id) { return new GsError('No parsllel call tragets. Cannot activate call forward.'); } } } # set state # $ok = $ok && $db->execute('UPDATE `callforwards` SET `active`=\'' . $db->escape($active) . '\' WHERE `user_id`=' . $user_id . ' AND `source`=\'' . $db->escape($source) . '\' AND `case`=\'' . $db->escape($case) . '\' LIMIT 1'); if (!$ok) { return new GsError('Failed to set call forwarding status.'); } # do not allow an empty number to be active # if ($active == 'std' || $active == 'var') { $field = 'number_' . $active; $number = $db->executeGetOne('SELECT `' . $field . '` FROM `callforwards` WHERE `user_id`=' . $user_id . ' AND `source`=\'' . $db->escape($source) . '\' AND `case`=\'' . $db->escape($case) . '\''); if (trim($number) == '') { $db->execute('UPDATE `callforwards` SET `active`=\'no\' WHERE `user_id`=' . $user_id . ' AND `source`=\'' . $db->escape($source) . '\' AND `case`=\'' . $db->escape($case) . '\''); return new GsError('Number is empty. Cannot activate call forward.'); } } if ($case === 'always') { $filename = '/tmp/gs-' . $user_id . '-' . time() . '-' . rand(10000, 99999) . '.call'; $call = "Channel: local/toggle@toggle-cfwd-hint\n" . "MaxRetries: 0\n" . "WaitTime: 15\n" . "Context: toggle-cfwd-hint\n" . "Extension: toggle\n" . "Callerid: {$user} <Toggle>\n" . "Setvar: __user_id=" . $user_id . "\n" . "Setvar: __user_name=" . $user_ext . "\n" . "Setvar: CHANNEL(language)=" . gs_get_conf('GS_INTL_ASTERISK_LANG', 'de') . "\n" . "Setvar: __is_callfile_origin=1\n" . "Setvar: __callfile_from_user="******"\n" . "Setvar: __record_file=" . $filename . "\n"; $cf = @fOpen($filename, 'wb'); if (!$cf) { gs_log(GS_LOG_WARNING, 'Failed to write call file "' . $filename . '"'); return new GsError('Failed to write call file.'); } @fWrite($cf, $call, strLen($call)); @fClose($cf); @chmod($filename, 0666); $spoolfile = '/var/spool/asterisk/outgoing/' . baseName($filename); if (!gs_get_conf('GS_INSTALLATION_TYPE_SINGLE')) { $our_host_ids = @gs_get_listen_to_ids(); if (!is_array($our_host_ids)) { $our_host_ids = array(); } $user_is_on_this_host = in_array($_SESSION['sudo_user']['info']['host_id'], $our_host_ids); } else { $user_is_on_this_host = true; } if ($user_is_on_this_host) { # the Asterisk of this user and the web server both run on this host $err = 0; $out = array(); @exec('sudo mv ' . qsa($filename) . ' ' . qsa($spoolfile) . ' 1>>/dev/null 2>>/dev/null', $out, $err); if ($err != 0) { @unlink($filename); gs_log(GS_LOG_WARNING, 'Failed to move call file "' . $filename . '" to "' . $spoolfile . '"'); return new GsError('Failed to move call file.'); } } else { $cmd = 'sudo scp -o StrictHostKeyChecking=no -o BatchMode=yes ' . qsa($filename) . ' ' . qsa('root@' . $user['host'] . ':' . $filename); //echo $cmd, "\n"; @exec($cmd . ' 1>>/dev/null 2>>/dev/null', $out, $err); @unlink($filename); if ($err != 0) { gs_log(GS_LOG_WARNING, 'Failed to scp call file "' . $filename . '" to ' . $user['host']); return new GsError('Failed to scp call file.'); } //remote_exec( $user['host'], $cmd, 10, $out, $err ); // <-- does not use sudo! $cmd = 'sudo ssh -o StrictHostKeyChecking=no -o BatchMode=yes -l root ' . qsa($user['host']) . ' ' . qsa('mv ' . qsa($filename) . ' ' . qsa($spoolfile)); //echo $cmd, "\n"; @exec($cmd . ' 1>>/dev/null 2>>/dev/null', $out, $err); if ($err != 0) { gs_log(GS_LOG_WARNING, 'Failed to mv call file "' . $filename . '" on ' . $user['host'] . ' to "' . $spoolfile . '"'); return new GsError('Failed to mv call file on remote host.'); } } } return true; }
/** * build language files from database * * @param boolean $force */ public static function buildlanguage($force = false) { $availableLanguages = array("de", "en"); foreach ($availableLanguages as $languageID => $languageCode) { $file = DNS_DIR . "/lang/" . $languageCode . ".lang.php"; if (!file_exists($file) || filemtime($file) + 86400 < time() || $force === true) { if (file_exists($file)) { @unlink($file); } @touch($file); $items = self::getDB()->query("select * from dns_language where languageID = ?", array($languageID)); $content = "<?php\n/**\n* language: " . $languageCode . "\n* encoding: UTF-8\n* generated at " . gmdate("r") . "\n* \n* DO NOT EDIT THIS FILE\n*/\n"; $content .= "\$lang = array();\n"; while ($row = self::getDB()->fetch_array($items)) { print_r($row); $content .= "\$lang['" . $row['languageItem'] . "'] = '" . str_replace("\$", '$', $row['languageValue']) . "';\n"; } $handler = fOpen($file, "a+"); fWrite($handler, $content); fClose($handler); } } }
function writeDataFile($data_file) { global $node; $save_struct = serialize($node); $datafilep = @fOpen($data_file, 'wb'); if (!$datafilep) { write_log("Cannot open {$data_file} for writing! Bad things will happen!"); return 1; } @fWrite($datafilep, $save_struct, strLen($save_struct)); fClose($datafilep); write_log("Data file {$data_file} written."); }
fWrite($handler, $out); fClose($handler); $signed = false; if ($sign === true) { shell_exec("cd /srv/bind/ && /usr/sbin/dnssec-signzone -r /dev/urandom -A -N INCREMENT -K /srv/bind/dnssec/" . $zone['soa']['origin'] . "/ -o " . $zone['soa']['origin'] . " -t " . $zone['soa']['origin'] . "db"); if (file_exists("/srv/bind/" . $zone['soa']['origin'] . "db.signed")) { $signed = true; } } $cout = "zone \"" . $zone['soa']['origin'] . "\" {\n"; $cout .= "\ttype master;\n"; $cout .= "\tnotify no;\n"; $cout .= "\tfile \"/srv/bind/" . $zone['soa']['origin'] . "db" . ($signed === true ? ".signed" : "") . "\";\n"; $cout .= "};\n\n"; $handler = fOpen("/srv/bind/domains.cfg", "a+"); fWrite($handler, $cout); fClose($handler); } shell_exec("/etc/init.d/bind9 reload"); } function getFileName($zone, $algo, $id, $type) { $len = strlen($id); if ($len == "1") { $id = "0000" . $id; } else { if ($len == "2") { $id = "000" . $id; } else { if ($len == "3") { $id = "00" . $id;
function gs_extstate($host, $exts) { static $hosts = array(); if (!is_array($exts)) { $exts = array($exts); $return_single = true; } else { $return_single = false; } if (gs_get_conf('GS_INSTALLATION_TYPE_SINGLE')) { $host = '127.0.0.1'; } if (!isset($hosts[$host])) { $hosts[$host] = array('sock' => null, 'lasttry' => 0); } if (!is_resource($hosts[$host]['sock'])) { if ($hosts[$host]['lasttry'] > time() - 60) { # we have tried less than a minute ago $hosts[$host]['lasttry'] = time(); return $return_single ? AST_MGR_EXT_UNKNOWN : array(); } $hosts[$host]['lasttry'] = time(); $sock = @fSockOpen($host, 5038, $err, $errMsg, 2); if (!is_resource($sock)) { gs_log(GS_LOG_WARNING, 'Connection to AMI on ' . $host . ' failed'); return $return_single ? AST_MGR_EXT_UNKNOWN : array(); } $data = _sock_read($sock, 3, '/[\\r\\n]/'); if (!preg_match('/^Asterisk [^\\/]+\\/(\\d(?:\\.\\d)?)/mis', $data, $m)) { gs_log(GS_LOG_WARNING, 'Incompatible Asterisk manager interface on ' . $host); $m = array(1 => '0.0'); } else { if ($m[1] > '1.1') { # Asterisk 1.4: manager 1.0 # Asterisk 1.6: manager 1.1 gs_log(GS_LOG_NOTICE, 'Asterisk manager interface on ' . $host . ' speaks a new protocol version (' . $m[1] . ')'); # let's try anyway and hope to understand it } } $hosts[$host]['sock'] = $sock; $req = "Action: Login\r\n" . "Username: "******"gscc" . "\r\n" . "Secret: " . "gspass" . "\r\n" . "Events: off\r\n" . "\r\n"; @fWrite($sock, $req, strLen($req)); @fFlush($sock); $data = _sock_read($sock, 3, '/\\r\\n\\r\\n/S'); if ($data === false) { gs_log(GS_LOG_WARNING, 'Authentication to AMI on ' . $host . ' failed (timeout)'); $hosts[$host]['sock'] = null; return $return_single ? AST_MGR_EXT_UNKNOWN : array(); } elseif (!preg_match('/Authentication accepted/i', $data)) { gs_log(GS_LOG_WARNING, 'Authentication to AMI on ' . $host . ' failed'); $hosts[$host]['sock'] = null; return $return_single ? AST_MGR_EXT_UNKNOWN : array(); } } else { $sock = $hosts[$host]['sock']; } $states = array(); foreach ($exts as $ext) { $req = "Action: ExtensionState\r\n" . "Context: to-internal-users\r\n" . "Exten: " . $ext . "\r\n" . "\r\n"; @fWrite($sock, $req, strLen($req)); @fFlush($sock); $resp = trim(_sock_read($sock, 3, '/\\r\\n\\r\\n/S')); //echo "\n$resp\n\n"; $states[$ext] = AST_MGR_EXT_UNKNOWN; if (!preg_match('/^Response:\\s*Success/is', $resp)) { continue; } if (!preg_match('/^Exten:\\s*([\\da-z]+)/mis', $resp, $m)) { continue; } $resp_ext = $m[1]; if (!preg_match('/^Status:\\s*(-?\\d+)/mis', $resp, $m)) { continue; } $resp_state = (int) $m[1]; $states[$resp_ext] = $resp_state; } if ($return_single) { return array_key_exists($exts[0], $states) ? $states[$exts[0]] : AST_MGR_EXT_UNKNOWN; } else { return $states; } }
public static function writeFile($file, $content) { $success = false; if ($handle = @fOpen($file, "w")) { if (fWrite($handle, $content)) { $success = true; self::log(sprintf(ERR_NONE, self::bold($file)), self::LOG_OK); } else { self::log(sprintf(ERR_WRITE_FILE, self::bold($file)), self::LOG_ERROR); } fClose($handle); } else { self::log(sprintf(ERR_CREATE_FILE, self::bold($file)), self::LOG_ERROR); } if ($success) { @chmod($file, Util::FILE_ACCESS); } return $success; }
public function extractPage($pageID, $pageTitle, $pageSource) { include "databaseconfig.php"; $this->counter++; echo $this->counter . "\n"; $result = new ExtractionResult($pageID, $this->language, $this->getExtractorID()); if ($this->decode_title($pageTitle) == NULL) { return $result; } // Remove comments $text = Util::removeComments($pageSource); // Search {{....}} preg_match_all('/\\{{2}((?>[^\\{\\}]+)|(?R))*\\}{2}/x', $text, $rawTemplates); foreach ($rawTemplates[0] as $rawTemplate) { if ($rawTemplate[0] != '{') { return $result; } // Delete {{ and }} $rawTemplate = substr($rawTemplate, 2, -2); // get template name preg_match_all("/([^|]*)/", $rawTemplate, $templateNames, PREG_SET_ORDER); $templateName = strtolower(trim($templateNames[0][0])); // Remove comments $rawTemplate = Util::removeComments($rawTemplate); // Replace "|" inside subtemplates to avoid splitting them like triples $rawTemplate = preg_replace_callback("/(\\{{2})([^\\}\\|]+)(\\|)([^\\}]+)(\\}{2})/", array($this, 'replaceBarInSubTemplate'), $rawTemplate); // Replace "|" inside labeled links to avoid splitting them like triples $check = false; while ($check === false) { $rawTemplate1 = preg_replace('/\\[\\[([^\\]]+)\\|([^\\]]*)\\]\\]/', '[[\\1***@@@***@@@***@@@***@@@\\2]]', $rawTemplate, -1, $count); if ($rawTemplate == $rawTemplate1) { $check = true; $rawTemplate = $rawTemplate1; } else { $rawTemplate = $rawTemplate1; } } // Find template keyvalue pairs preg_match_all("/\\|\\s*\\|?\\s*([^=|<>]+)\\s*=([^|]*)/", $rawTemplate, $keyvalues, PREG_SET_ORDER); // my original //preg_match_all("/\|\s*([^=]+)\s*=?([^|]*)/", $rawTemplate, $keyvalues, PREG_SET_ORDER); // new MBE //preg_match_all("/\|\s*([^=]+)\s*=([^|]*)/", $rawTemplate, $keyvalues, PREG_SET_ORDER); // orginal // Next template if there are no keyvalue pairs if (count($keyvalues) == 0) { return $result; } foreach ($keyvalues as $keyvalue) { $keyvalue = str_replace('***@@@***@@@***@@@***@@@', '|', $keyvalue); $keyvalue = str_replace('***---***---***---***---', '|', $keyvalue); $propkey = trim($keyvalue[1]); $propvalue = trim($keyvalue[2]); if ($propvalue == '') { continue; } $s = "http://dbpedia.org/resource/" . URI::wikipediaEncode($pageID); $p = "http://dbpedia.org/property/" . $this->propertyToCamelCase($propkey); $o = $propvalue; $line = "INSERT INTO propertietriples (resourceURI, propertiyURI, propertyValue) VALUES ('{$s}','" . mysql_escape_string($p) . "','" . mysql_escape_string($o) . "')"; fWrite($this->DumpFile, $line . "\n"); } // add wikiPageUsesTemplate $p = "http://dbpedia.org/property/wikiPageUsesTemplate"; $o = "http://dbpedia.org/resource/Template:" . $this->encodeLocalName($templateName); $line = "INSERT INTO propertietriples (resourceURI, propertiyURI, propertyValue) VALUES ('{$s}','" . mysql_escape_string($p) . "','" . mysql_escape_string($o) . "')"; fWrite($this->DumpFile, $line . "\n"); } return $result; }
public static function generate($key, array $updateIds = []) { $success = false; $reqDBC = []; if (file_exists('setup/tools/filegen/' . $key . '.func.php')) { require_once 'setup/tools/filegen/' . $key . '.func.php'; } else { if (empty(self::$tplFiles[$key])) { CLISetup::log(sprintf(ERR_MISSING_INCL, $key, 'setup/tools/filegen/' . $key . '.func.php', CLISetup::LOG_ERROR)); return false; } } CLISetup::log('FileGen::generate() - gathering data for ' . $key); if (!empty(self::$tplFiles[$key])) { list($file, $destPath, $deps) = self::$tplFiles[$key]; if ($content = file_get_contents(FileGen::$tplPath . $file . '.in')) { if ($dest = @fOpen($destPath . $file, "w")) { // replace constants $content = strtr($content, FileGen::$txtConstants); // check for required auxiliary DBC files foreach ($reqDBC as $req) { if (!CLISetup::loadDBC($req)) { continue 2; } } // must generate content // PH format: /*setup:<setupFunc>*/ $funcOK = true; if (preg_match_all('/\\/\\*setup:([\\w\\-_]+)\\*\\//i', $content, $m)) { foreach ($m[1] as $func) { if (function_exists($func)) { $content = str_replace('/*setup:' . $func . '*/', $func(), $content); } else { $funcOK = false; CLISetup::log('No function for was registered for placeholder ' . $func . '().', CLISetup::LOG_ERROR); if (!array_reduce(get_included_files(), function ($inArray, $itr) use($func) { return $inArray || false !== strpos($itr, $func); }, false)) { CLISetup::log('Also, expected include setup/tools/filegen/' . $name . '.func.php was not found.'); } } } } if (fWrite($dest, $content)) { CLISetup::log(sprintf(ERR_NONE, CLISetup::bold($destPath . $file)), CLISetup::LOG_OK); if ($content && $funcOK) { $success = true; } } else { CLISetup::log(sprintf(ERR_WRITE_FILE, CLISetup::bold($destPath . $file)), CLISetup::LOG_ERROR); } fClose($dest); } else { CLISetup::log(sprintf(ERR_CREATE_FILE, CLISetup::bold($destPath . $file)), CLISetup::LOG_ERROR); } } else { CLISetup::log(sprintf(ERR_READ_FILE, CLISetup::bold(FileGen::$tplPath . $file . '.in')), CLISetup::LOG_ERROR); } } else { if (!empty(self::$datasets[$key])) { if (function_exists($key)) { // check for required auxiliary DBC files foreach ($reqDBC as $req) { if (!CLISetup::loadDBC($req)) { return false; } } $success = $key($updateIds); } else { CLISetup::log(' - subscript \'' . $key . '\' not defined in included file', CLISetup::LOG_ERROR); } } } set_time_limit(FileGen::$defaultExecTime); // reset to default for the next script return $success; }
function log($text, $data = '') { if (empty($this->isActive) || empty($text)) { return; } // sometimes some system plugins can use the router. If we use // print_r in this situatation, this generates an error // Cannot use output buffering in output buffering display handlers // so we must check first that no handler is being used $logData = ''; if (!empty($data)) { $handlers = ob_list_handlers(); if (empty($handlers)) { $logData = ":\t" . print_r($data, true); } else { // we can't use print_r if (is_object($data)) { $logData .= $this->logObject($data); } else { if (is_array($data)) { $logData .= ":\n"; $logData .= $this->logArray($data); } else { $logData .= ":\t" . $data; } } } } fWrite($this->logFile, $this->logTime() . "\t" . $text . $logData . "\n"); }
} else { $callerid = 'Anonymous <anonymous>'; } if (!$is_foreign) { //FIXME? - is this code correct for numbers in the same area? $to_num = subStr($to_num_obj->dial, 0, 1) === '0' ? '0' . $to_num_obj->dial : $to_num_obj->dial; $from_num_dial = subStr($from_num_effective_obj->dial, 0, 1) === '0' ? '0' . $from_num_effective_obj->dial : $from_num_effective_obj->dial; $call = "Channel: Local/urldial-" . $from_num_dial . "@to-internal-users-self\n" . "MaxRetries: 0\n" . "WaitTime: 15\n" . "Context: urldial\n" . "Extension: {$prvPrefix}{$to_num}\n" . "Callerid: Rufaufbau <call>\n" . "Setvar: __user_id=" . $user['id'] . "\n" . "Setvar: __user_name=" . $user['ext'] . "\n" . "Setvar: CHANNEL(language)=" . gs_get_conf('GS_INTL_ASTERISK_LANG', 'de') . "\n" . "Setvar: __is_callfile_origin=1\n" . "Setvar: __saved_callerid=" . $callerid . "\n" . "Setvar: __callfile_from_user="******"\n"; //echo $call; $filename = '/tmp/gs-' . $user['id'] . '-' . _pack_int(time()) . rand(100, 999) . '.call'; $cf = @fOpen($filename, 'wb'); if (!$cf) { gs_log(GS_LOG_WARNING, 'Failed to write call file "' . $filename . '"'); die_error('Failed to write call file.'); } @fWrite($cf, $call, strLen($call)); @fClose($cf); @chmod($filename, 0666); $spoolfile = '/var/spool/asterisk/outgoing/' . baseName($filename); if (!gs_get_conf('GS_INSTALLATION_TYPE_SINGLE')) { $our_host_ids = @gs_get_listen_to_ids(); if (!is_array($our_host_ids)) { $our_host_ids = array(); } $user_is_on_this_host = in_array($user['host_id'], $our_host_ids); } else { $user_is_on_this_host = true; } if ($user_is_on_this_host) { # the Asterisk of this user and the web server both run on this host //$ok = @rename( $filename, $spoolfile );
function execFFMPEG($i = '', $o = '', $p = '', $pkey = '') { if ($pkey == '') { $pkey = rand(); } $fpath = FFMPEG_PATH; if (empty($fpath)) { $this->logError('ffmpeg-progressbar: missing ffmpeg path', date("d-m-y") . '.error.log'); exit('ffmpeg-progressbar: missing ffmpeg path'); } else { if (!file_exists($fpath)) { $this->logError('ffmpeg-progressbar: wrong ffmpeg path \'' . FFMPEG_PATH . '\'', date("d-m-y") . '.error.log'); exit('ffmpeg-progressbar: wrong ffmpeg path \'' . FFMPEG_PATH . '\''); } } if (empty($i)) { $this->logError('ffmpeg: missing argument for option \'i\'', date("d-m-y") . '.error.log'); exit('ffmpeg: missing argument for option \'i\''); } elseif (!file_exists($i)) { $this->logError($i . ': no such file or directory', date("d-m-y") . '.error.log'); exit($i . ': no such file or directory'); } elseif (empty($o)) { $this->logError('ffmpeg: At least one output file must be specified', date("d-m-y") . '.error.log'); exit('ffmpeg: At least one output file must be specified'); } elseif (file_exists($o)) { $this->logError('ffmpeg: File \'' . $o . '\' already exists.', date("d-m-y") . '.error.log'); exit('ffmpeg: File \'' . $o . '\' already exists.'); } elseif (empty($p)) { $this->logError('ffmpeg: No Param has been specified... use default settings for converting...', date("d-m-y") . '.warn.log'); } else { //Executing FFMPEG $handler = fOpen(dirname(__FILE__) . '/../log/' . $pkey . '.ffmpeg.file', "w"); fWrite($handler, $i . "\n" . $o . "\n" . $p . "\n"); fClose($handler); $this->logError("Sending FFMPEG exec command to " . $_SERVER["HTTP_HOST"] . "..."); $curdir = getcwd(); $cmd = " -i '" . $i . "' " . $p . " '" . $o . "' 2> " . $curdir . "/log/" . $pkey . ".ffmpeg"; $postdata = "cmd=" . $cmd . "&ffmpegpw=" . FFMPEG_PW; $fp = fsockopen($_SERVER["HTTP_HOST"], 80, $errno, $errstr, 30); fputs($fp, "POST " . dirname($_SERVER["SCRIPT_NAME"]) . "/inc/execFFMPEG.php HTTP/1.0\n"); fputs($fp, "Host: " . $_SERVER["HTTP_HOST"] . "\n"); fputs($fp, "Content-type: application/x-www-form-urlencoded\n"); fputs($fp, "Content-length: " . strlen($postdata) . "\n"); // Faking User-Agent to Microsoft Internet Explorer 7 fputs($fp, "User-agent: Mozilla/4.0 (compatible: MSIE 7.0; Windows NT 6.0)\n"); fputs($fp, "Connection: close\n\n"); fputs($fp, $postdata); fclose($fp); } }
function shLogToSecFile($logData) { $shNum = 12 * (intval(date('Y')) - 2000) + intval(date('m')); // number current month $shFileName = sh404SEF_ADMIN_ABS_PATH . 'logs/' . date('Y') . '-' . date('m') . '-' . 'sh404SEF_security_log.' . $shNum . '.log'; $fileIsThere = file_exists($shFileName); if (!$fileIsThere) { // create file $fileHeader = "Date\tTime\tCause\tIP\tName\tUser agent\tRequest method\tRequest URI\tComment\n"; } else { $fileHeader = ''; } if (!$fileIsThere || $fileIsThere && is_writable($shFileName)) { $logFile = fopen($shFileName, 'ab'); if ($logFile) { if (!empty($fileHeader)) { fWrite($logFile, $fileHeader); } fWrite($logFile, $logData); fClose($logFile); } } }
public function accept($extractionResult) { // $extractedTriples = new ArrayObject($extractionResult->getTriples()); $extractedTriples = $extractionResult->getTriples(); foreach ($extractedTriples as $triple) { // TODO: make sure that https://sourceforge.net/tracker/?func=detail&aid=2901137&group_id=190976&atid=935520 is fixed $array_1 = array('\\', '"', " ", " "); $array_2 = array('\\\\', '\\"', "_", "_"); $subj = urldecode($triple->getSubject()); for ($i = 0; $i < count($array_1); $i++) { $subj = str_replace($array_1[$i], $array_2[$i], $subj); } $tString = $subj . " "; $pred = urldecode($triple->getPredicate()); if (substr($pred, -2) == "_>" || substr($pred, -2) == ">_") { $pred = substr($pred, 0, -2) . ">"; } for ($i = 0; $i < count($array_1); $i++) { $pred = str_replace($array_1[$i], $array_2[$i], $pred); } $tString .= $pred . " "; $obj = $triple->getObject(); if ($obj instanceof RDFliteral) { $tmp = $obj->getLexicalForm(); $array_1 = array('\\', '"'); $array_2 = array('\\\\', '\\"'); for ($i = 0; $i < count($array_1); $i++) { $tmp = str_replace($array_1[$i], $array_2[$i], $tmp); } $tString .= "\"" . $tmp . "\""; if ($obj->getDatatype()) { $tString .= "^^<" . $obj->getDatatype() . ">"; } else { $lang = $obj->getLanguage(); if ($lang) { $tString .= "@" . $obj->getLanguage(); } } } else { $obj = urldecode($obj); for ($i = 0; $i < count($array_1); $i++) { $obj = str_replace($array_1[$i], $array_2[$i], $obj); } $tString .= $obj . " "; } fWrite($this->DumpFileA, preg_replace("/\r|\n/s", "", $tString) . " .\n"); $tripleString = explode(">", $triple->toStringNoEscape()); $s = trim(str_replace("<", "", $tripleString[0])); $s = preg_replace('~^' . DB_RESOURCE_NS . '~', "", $s); $p = trim(str_replace("<", "", $tripleString[1])); $p = preg_replace('~^' . DB_PROPERTY_NS . '~', "", $p); if (preg_match('/^<http:/', $tripleString[2])) { $object_is = 'r'; } else { $object_is = 'l'; } $o = trim(str_replace("<", "", $tripleString[2])); $dtypePos = strpos($o, "^^"); $langPos = strpos($o, "@"); if ($dtypePos) { $o = substr($o, 0, $dtypePos); } if ($langPos) { $o = substr($o, 0, $langPos); } $o = preg_replace('/(^")|("$)/', "", $o); $o = preg_replace('~^' . DB_RESOURCE_NS . '~', "", $o); #if ( !preg_match('/^[0-9\.,]+$/', $o) ) $o = "\"" . $o . "\""; #print("\"" . $s . "\"" . $this->delimiter . "\"" . $p . "\"" . $this->delimiter . $o . "\n"); //triple in Datei schreiben fWrite($this->DumpFileB, urldecode($s) . $this->delimiter . urldecode($p) . $this->delimiter . urldecode($o) . $this->delimiter . $object_is . "\n"); } $this->counter++; if ($this->counter % 1000 == 0) { echo $this->counter, PHP_EOL; } }
private function streamWrite($data) { $result = fWrite($this->fp, $data); if ($result === false) { throw new TSimpleHttpClientException('streamwrite_failed', $data, $this->getHost(), $this->getPort(), $this->getPath()); } return $result; }
foreach ($pofiles as $pofile) { $domain = baseName($pofile, '.po'); $lang = baseName(dirName(dirName($pofile))); /* # build .mo file for gettext # echo "Building $lang $domain.mo ...\n"; $mofile = preg_replace('/\.po$/', '.mo', $pofile); passThru( 'msgfmt -o '. qsa($mofile) .' '. qsa($pofile), $err ); if ($err !== 0) { echo " Failed."; if ($err === 127) echo " (msgfmt not found. gettext not installed?)"; echo "\n"; } */ # build .php file for php # echo "Building {$lang} {$domain}.php ...\n"; $phpout = _po_to_php($pofile); if (!is_array($phpout)) { $phpout = array(); } $phpout = '<' . "?php\n" . "// AUTO-GENERATED FILE. TO MAKE CHANGES EDIT\n" . "// " . $domain . ".po AND REBUILD\n\n" . $copyright . "\n\n" . '$g_gs_LANG[\'' . $lang . '\'][\'' . $domain . '\'] = ' . var_export($phpout, true) . ";\n\n" . '?' . '>'; $phpfile = preg_replace('/\\.po$/', '.php', $pofile); $f = fOpen($phpfile, 'wb'); fWrite($f, $phpout, strLen($phpout)); fClose($f); } } } }