Service Online Status

Mit diesem DokuWiki Plugin können Sie den Status von Diensten TCP/UDP anzeigen als Bild mit/ohne Text und als Textversion.

Bekannte Probleme

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.

Download

Quelltext


 */

// 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.="
\"($protocol\\$port)$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.="
\"($protocol\\$port)$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.="
\"($protocol\\$port)$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.="
\"($protocol\\$port)$description
"; } else { // Ohne Bild if($description==""){ $buffer.="
$protocol\\$port $ip_addr is reachable.
"; } else { $buffer.="
$description is reachable.
"; } } } fclose($status); } } return $buffer; } } ?>

Installation

Variante 1: Pluginmanager

Die URL vom Download in den Pluginmanager reinkopieren und Installieren anklicken.

Variante 2: Manuell

Den Inhalt des .tgz in lib/plugins kopieren.

Einbinden in die Webseite

Syntax

{{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~~

Demo / Beispiele

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).

Nur Bild

{{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)

Bild mit Beschreibung

{{sos>tcp:www.thoma.cc:80:y| www @ www.thoma.cc}}
{{sos>tcp:www.thoma.cc:801:y| xyz @ www.thoma.cc}}
{{sos>udp:www.thoma.cc:53:y| dns @ www.thoma.cc}}
{{sos>udp:www.thoma.cc:3232:y| zxy @ www.thoma.cc}}

ergibt: www @ www.thoma.cc ( B, 0 downloads) xyz @ www.thoma.cc ( B, 0 downloads) dns @ www.thoma.cc ( B, 0 downloads) zxy @ www.thoma.cc ( B, 0 downloads)

Nur Text

{{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)

Text mit Beschreibung

{{sos>tcp:www.thoma.cc:80:n| www @ www.thoma.cc}}
{{sos>tcp:www.thoma.cc:801:n| xyz @ www.thoma.cc}}
{{sos>udp:www.thoma.cc:53:n| dns @ www.thoma.cc}}
{{sos>udp:www.thoma.cc:3232:n| zxy @ www.thoma.cc}}

ergibt: www @ www.thoma.cc ( B, 0 downloads) xyz @ www.thoma.cc ( B, 0 downloads) dns @ www.thoma.cc ( B, 0 downloads) zxy @ www.thoma.cc ( B, 0 downloads)

1 Gedanke zu „Service Online Status“

  1. Hi,
    dieses Plugin ist wohl ziemlich genau, wonach ich suche. Leider kann ich es nirgends mehr zum Download finden. Gibt es vielleicht eine Möglichkeit, das Plugin noch einmal zu veröffentlichen?
    Mit freundlichen Grüßen,
    Florian

    Antworten

Schreibe einen Kommentar

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.