Mit diesem DokuWiki Plugin können Sie den Status von Diensten TCP/UDP anzeigen als Bild mit/ohne Text und als Textversion.
Nicht alle UDP Services werden korrekt angezeigt. Dies hängt mit dem UDP Protokoll zusammen, da UDP ein verbindungsloses Protokoll ist im gegensatz zu TCP. Bei UDP wird in der Regel keine Verbindung aufgebaut bevor nicht Daten gesendet oder empfangen werden müsssen. Bei DNS (udp/53) funktioniert die Statusanzeige. Andere UDP Services habe ich noch nicht getestet.
*/
// 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;
}
} ?>
Die URL vom Download in den Pluginmanager reinkopieren und Installieren anklicken.
Den Inhalt des .tgz in lib/plugins kopieren.
{{sos>protocol:ip_addr_oder_fqdn:port:img(y/n)|description}}
Empfehlenswert ist das Abschalten des Caches. Am Anfang der Webseite folgendes einfügen.
~~NOCACHE~~
Als Test verwende ich die IP-Adresse (FQDN) dieser Homepage und die Serviceports tcp/80 (vorhanden), tcp/801 (nicht vorhanden) und udp/53 (vorhanden), udp/3232 (nicht vorhanden).
{{sos>tcp:www.thoma.cc:80:y}}
{{sos>tcp:www.thoma.cc:801:y}}
{{sos>udp:www.thoma.cc:53:y}}
{{sos>udp:www.thoma.cc:3232:y}}
ergibt: y ( B, 0 downloads) y ( B, 0 downloads) y ( B, 0 downloads) y ( B, 0 downloads)
{{sos>tcp:www.thoma.cc:80:n}}
{{sos>tcp:www.thoma.cc:801:n}}
{{sos>udp:www.thoma.cc:53:n}}
{{sos>udp:www.thoma.cc:3232:n}}
ergibt: n ( B, 0 downloads) n ( B, 0 downloads) n ( B, 0 downloads) n ( B, 0 downloads)