1<?php 2/** 3 * Plugin iphelper: Provides automatic links to HTML reports on your server, by searching the wikitext. 4 * 5 * Thanks to Jonas Berg for the chiplink plugin, on which this plugin is based. 6 * 7 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 8 * @author An-dir 9 */ 10 11 // must be run within Dokuwiki 12if (!defined('DOKU_INC')) die(); 13 14if (!defined('DOKU_LF')) define('DOKU_LF', "\n"); 15if (!defined('DOKU_TAB')) define('DOKU_TAB', "\t"); 16if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 17 18require_once DOKU_PLUGIN.'syntax.php'; 19 20class syntax_plugin_iphelper extends DokuWiki_Syntax_Plugin { 21 22 public function getInfo(){ 23 return array( 24 'author' => 'An-Dir', 25 'email' => '1.c-j@gmx.de', 26 'date' => '2018-10-29', 27 'name' => 'iphelper plugin', 28 'desc' => 'Provides tools on automatically detected ipadresses within the wiki text. searches for IP adresses like 123.45.67.89 and inserts a customizeable menu. Secondly searches for Network Adresses like 123.45.67.89/24 and inserts a link to a subnet calculator', 29 'url' => 'http://www.dokuwiki.org/plugin:iphelper', 30 ); 31 } 32 33 public function getType(){ 34 return 'substition'; 35 } 36 37 public function getSort(){ 38 return 920; 39 } 40 41 /** 42 * Search for the pattern 43 */ 44 public function connectTo($mode) { 45 $this->Lexer->addSpecialPattern('(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(?:\/(?:(?:(?:($:0\.0\.0\.0|0\.0\.0\.1|0\.0\.0\.3|0\.0\.0\.7|0\.0\.0\.15|0\.0\.0\.31|0\.0\.0\.63|0\.0\.0\.127|0\.0\.0\.255|0\.0\.1\.255|0\.0\.3\.255|0\.0\.7\.255|0\.0\.15\.255|0\.0\.31\.255|0\.0\.63\.255|0\.0\.127\.255|0\.0\.255\.255|0\.1\.255\.255|0\.3\.255\.255|0\.7\.255\.255|0\.15\.255\.255|0\.31\.255\.255|0\.63\.255\.255|0\.127\.255\.255|0\.255\.255\.255|1\.255\.255\.255|3\.255\.255\.255|7\.255\.255\.255|15\.255\.255\.255|31\.255\.255\.255|63\.255\.255\.255|127\.255\.255\.255|255\.255\.255\.255|255\.255\.255\.255|255\.255\.255\.254|255\.255\.255\.252|255\.255\.255\.248|255\.255\.255\.240|255\.255\.255\.224|255\.255\.255\.192|255\.255\.255\.128|255\.255\.255\.0|255\.255\.254\.0|255\.255\.252\.0|255\.255\.248\.0|255\.255\.240\.0|255\.255\.224\.0|255\.255\.192\.0|255\.255\.128\.0|255\.255\.0\.0|255\.254\.0\.0|255\.252\.0\.0|255\.248\.0\.0|255\.240\.0\.0|255\.224\.0\.0|255\.192\.0\.0|255\.128\.0\.0|255\.0\.0\.0|254\.0\.0\.0|252\.0\.0\.0|248\.0\.0\.0|240\.0\.0\.0|224\.0\.0\.0|192\.0\.0\.0|128\.0\.0\.0|0\.0\.0\.0|[1-2][0-9])|(?:3[0-2])|[0-9]))){0,1}\b', $mode, 'plugin_iphelper'); 46 } 47 48 /** 49 * Read the information from the matched wiki text 50 */ 51 public function handle($match, $state, $pos, Doku_Handler $handler){ 52 $stripped = substr($match, 0); 53 $tmp = explode("-", $stripped,2); 54 $tmp = array_pad($tmp, 2, null); 55 list($ip, $type) = $tmp; 56 if(preg_match("[\/]",$match)) { $type = "cidr" ;} else { $type = "ip";}; 57 return array($ip, $type); 58 } 59 60 /** 61 * Generate HTML output 62 */ 63 public function render($mode, Doku_Renderer $renderer, $data) { 64 if($mode != 'xhtml'){ 65 return false; 66 } 67 list($ip, $type) = $data; 68 $printmode = false; 69 if(isset($_GET["vecdo"]) && htmlspecialchars($_GET["vecdo"]) == 'print'){ 70 $printmode = true; 71 } 72 73 if(isset($_GET["do"]) && htmlspecialchars($_GET["do"]) == 'export_pdf'){ 74 $printmode = true; 75 } 76 if ($printmode == true) { 77 $renderer->doc .= "".$ip.""; 78 } else { 79 if ($type == "cidr") { 80 // subnetcalc nun für alle gültigen cidr adressen 81 $renderer->doc .= "<span class=\"iphelper\" title=\"iphelper: $ip\">".$ip."</span>"; 82 } 83 if ($type == "ip") { 84 if (preg_match("/^($:0\.0\.0\.0|0\.0\.0\.1|0\.0\.0\.3|0\.0\.0\.7|0\.0\.0\.15|0\.0\.0\.31|0\.0\.0\.63|0\.0\.0\.127|0\.0\.0\.255|0\.0\.1\.255|0\.0\.3\.255|0\.0\.7\.255|0\.0\.15\.255|0\.0\.31\.255|0\.0\.63\.255|0\.0\.127\.255|0\.0\.255\.255|0\.1\.255\.255|0\.3\.255\.255|0\.7\.255\.255|0\.15\.255\.255|0\.31\.255\.255|0\.63\.255\.255|0\.127\.255\.255|0\.255\.255\.255|1\.255\.255\.255|3\.255\.255\.255|7\.255\.255\.255|15\.255\.255\.255|31\.255\.255\.255|63\.255\.255\.255|127\.255\.255\.255|255\.255\.255\.255|255\.255\.255\.255|255\.255\.255\.254|255\.255\.255\.252|255\.255\.255\.248|255\.255\.255\.240|255\.255\.255\.224|255\.255\.255\.192|255\.255\.255\.128|255\.255\.255\.0|255\.255\.254\.0|255\.255\.252\.0|255\.255\.248\.1|255\.255\.240\.0|255\.255\.224\.0|255\.255\.192\.0|255\.255\.128\.0|255\.255\.0\.0|255\.254\.0\.0|255\.252\.0\.0|255\.248\.0\.0|255\.240\.0\.0|255\.224\.0\.0|255\.192\.0\.0|255\.128\.0\.0|255\.0\.0\.0|254\.0\.0\.0|252\.0\.0\.0|248\.0\.0\.0|240\.0\.0\.0|224\.0\.0\.0|192\.0\.0\.0|128\.0\.0\.0|0\.0\.0\.0)$/",$ip)) { # der string wurde angepasst, damit subnetmasken nicht gefunden werden (am anfang 0-4 anstelle von 0-5 85 $renderer->doc .= "<span class=\"iphelper\" title=\"Subnetmask or Wildcardmask: $ip\">" . $ip . "</span>"; 86 } else { 87 $renderer->doc .= "<span class=\"iphelper\" title=\"iphelper: $ip\">" . $ip . "</span>"; 88 } 89 } 90 } 91 return true; 92 } 93}