*/ // must be run within Dokuwiki if(!defined('DOKU_INC')) die(); if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); require_once(DOKU_PLUGIN.'syntax.php'); /** * All DokuWiki plugins to extend the parser/rendering mechanism * need to inherit from this class */ class syntax_plugin_sos extends DokuWiki_Syntax_Plugin { function getInfo(){ return array( 'author' => 'Maximilian Thoma', 'email' => 'info@thoma.cc', 'date' => '2007-12-18', 'name' => 'Service Online Status', 'desc' => 'Service Online Status Plugin, -TCP fully supported, UDP experimental- usage: {{sos>protocol:ip_addr:port:img(y/n)|Description}}', 'url' => 'http://www.thoma.cc', ); } function getType() { return 'substition'; } //function getPType() { return 'block'; } function getSort() { return 309; } function connectTo($mode) { $this->Lexer->addSpecialPattern('\{\{sos>.+?\}\}', $mode, 'plugin_sos'); } function handle($match, $state, $pos, &$handler){ $data = substr($match, 6, -2); $pos = strpos($data, '|'); if ($pos === FALSE) { $description = ''; $target = $data; } else { $description = substr($data, $pos + 1); $target = substr($data, 0, $pos); } return array(target => $target, description => $description); } function render($mode, &$renderer, $data) { if($mode == 'xhtml'){ $renderer->doc .= $this->_sos($data); return true; } return false; } function _sos($data){ global $ID; // Explode Data protocol:ip_addr:port:img(y/n) $data_tmp=explode(":",$data[target]); $protocol=$data_tmp[0]; $ip_addr=$data_tmp[1]; $port=$data_tmp[2]; $img=$data_tmp[3]; $description=$data[description]; // TCP or UDP $status = @fsockopen("$protocol://$ip_addr", $port, $errno, $errstr, 5); if (!$status) { // Offline TCP if($img=="y"){ // Mit Bild $src = DOKU_URL.'lib/plugins/sos/images/off.png'; $buffer.="
\$description
"; } else { // Ohne Bild if($description==""){ $buffer.="
$protocol\\$port $ip_addr not reachable.
"; } else { $buffer.="
$description not reachable.
"; } } @fclose($status); } else { // Online oder UDP if($protocol=="tcp"){ if($img=="y"){ // Mit Bild $src = DOKU_URL.'lib/plugins/sos/images/on.png'; $buffer.="
\$description
"; } else { // Ohne Bild if($description==""){ $buffer.="
$protocol\\$port $ip_addr is reachable.
"; } else { $buffer.="
$description is reachable.
"; } } @fclose($status); } // oder UDP if($protocol=="udp"){ fwrite($status, "\n"); if(fread($status, 26)==""){ // Offline if($img=="y"){ // Mit Bild $src = DOKU_URL.'lib/plugins/sos/images/off.png'; $buffer.="
\$description
"; } else { // Ohne Bild if($description==""){ $buffer.="
$protocol\\$port $ip_addr not reachable.
"; } else { $buffer.="
$description not reachable.
"; } } } else { //Online if($img=="y"){ // Mit Bild $src = DOKU_URL.'lib/plugins/sos/images/on.png'; $buffer.="
\$description
"; } else { // Ohne Bild if($description==""){ $buffer.="
$protocol\\$port $ip_addr is reachable.
"; } else { $buffer.="
$description is reachable.
"; } } } fclose($status); } } return $buffer; } } ?>