'Gildas Cotomale', 'email' => 'Gildas.Cotomale@ymagis.com', 'date' => '2020-08-27', 'name' => '{php}IPAM connector plugin', 'desc' => 'Displays a network used-or-reserved IPs', 'url' => 'http://www.dokuwiki.org/plugin:phpipam', ) ; } */ /** * What kind of syntax are we? * * @note https://www.dokuwiki.org/devel:syntax_plugins#synopsis * @note https://www.dokuwiki.org/devel:syntax_plugins#mode_types * @note https://www.dokuwiki.org/devel:syntax_plugins#syntax_types */ public function getType() { return 'container' ; } /** * What other syntax may be inside? * * @note https://www.dokuwiki.org/devel:syntax_plugins#synopsis * @note https://www.dokuwiki.org/devel:syntax_plugins#allowed_modes * @note https://www.dokuwiki.org/devel:syntax_plugins#syntax_types */ public function getAllowedType() { return array( 'formatting', 'substition', ) ; } /** * Paragraph Type * * @note https://www.dokuwiki.org/devel:syntax_plugins#synopsis * @note https://www.dokuwiki.org/devel:syntax_plugins#ptype */ public function getPType() { return 'block' ; } /** * Where to sort in? * * @note https://www.dokuwiki.org/devel:syntax_plugins#synopsis * @note https://www.dokuwiki.org/devel:syntax_plugins#sort_number * @note https://www.dokuwiki.org/devel:parser:getsort_list * @note https://www.dokuwiki.org/devel:parser#order_of_adding_modes_important */ public function getSort() { return 102 ; } /** * Connect lookup pattern to Lexer * * @note https://www.dokuwiki.org/devel:syntax_plugins#synopsis * @note https://www.dokuwiki.org/devel:syntax_plugins#patterns * @note https://www.dokuwiki.org/devel:plugin_programming_tips#use_correct_regular_expressions * @note https://forum.dokuwiki.org/thread/15542 => * @note https://www.dokuwiki.org/plugin?relativens#code */ public function connectTo($mode) { $this->Lexer->addSpecialPattern('\B<(?i)phpipam\s+?.+?\/>\E', $mode, 'plugin_phpipam') ; $this->Lexer->addSpecialPattern('\B@(?i)phpipam\s+?.+?\/@\E', $mode, 'plugin_phpipam') ; $this->Lexer->addSpecialPattern('\B@(?i)phpipam\s+?.+?@@\E', $mode, 'plugin_phpipam') ; $this->Lexer->addSpecialPattern('\B~(?)phpipam\s+?.+?\/~\E', $mode, 'plugin_phpipam') ; $this->Lexer->addSpecialPattern('\B~(?)phpipam\s+?.+?~~\E', $mode, 'plugin_phpipam') ; } /** * Handle the matches * * @note https://www.dokuwiki.org/devel:syntax_plugins#synopsis * @note https://www.dokuwiki.org/devel:syntax_plugins#handle_method */ public function handle($match, $state, $pos, Doku_Handler $handler) { // disable syntax in user comments (discussion plugin) if (isset($_REQUEST['comment'])) { return false ; } // default options $opts = array( 'cst' => array( #'links' => 0, ), ) ; // parse attributes... $params = preg_split('/\\\\.(*SKIP)(*FAIL)|[\s,;\|&]+/', substr($match,9,-2), 0, PREG_SPLIT_NO_EMPTY) ; unset($match) ; foreach ($params as $param1) { $param1 = trim($param1) ; if (preg_match("/^(cidr|add?ress?e?s?|net\w+|[\w-]*nets?|range|[\w-]*re[dst]\w*|si[et]\w*|\w*v[oe]rk\w*|cet\w+)[=:%#@]['\"]?((25[0-5]|2[0-4]\d|[01]?\d\d?.){3})(25[0-5]|2[0-4]\d|[01]?\d\d?)\/(3[0-2]|[12]?\d)['\"]?$/i", $param1, $matches)) { // SubNet search #0:: add?ress?e?s? #0:: \w+nets? #0:> subnet/address (english), sous-reseau/adresse (french), #1:: net\w* #1:> net (icelandie), #1:> nettverk (norwegian), #1:> nettverk (norwegian), #1:> netvaerk (danish), #1:> network (dutch/english/maltese/), #1:> netzwerk (german), #2:: re[dst]\w* #2:> red (spanish), #2:> rede (galician/portuguese), #2:> reseau (french), #2:> rete (italian), #2:> retea (romanian), #2:> reto (esperanto), #3:: si[et]\w? #3:> siec (polish), #3:> siet (slovak), #3:> sit (czech), #4:: \w*v[eo]r\w+ #4:> nettverk (norwegian), #4:> verkko (finnish), #4:> vork (estonian), #5:: cet\w+ #5:> cetb (rusiaan), #5:> cetka (belarusian), #6:: tin?kla?s #6:> tikls (latvian), #6:> tinklas (lithuanian), #7:: me?pex[ay] #7:> mpexa (bulgarian/macedonian/serbian), #7:> mepexy (ukranian), #8:: o?mrezj?[ae] #8:> mreza (croatian), #8:> omrezje (slovenian), #9:: #9:> halozat (hungarian), #9:> liora (irish), #9:> nat (swedish), #9:> rhwydwaith (welsh), #9:> rrjet (albanian), #9:> sarea (basque), #9:> xarxa (catalan), $opts['net'] = $matches[2] . $matches[4] . '/' .$matches[5] ; #array_splice($params,0) ; } elseif (preg_match("/^(vlanid|vnetid|vpcid|virtid|vpcid|vid)[=:%#@]['\"]?(\d+)['\"]?$/i", $param1, $matches)) { // Virtual LAN (i.e. routers l2 Network) index $opts['vid'] = $matches[2] ; #array_splice($params,0) ; } elseif (preg_match("/^(vlan|vnet|vnet|vdom|virt|vpc)[=:%#@]['\"]?(\d+)['\"]?$/i", $param1, $matches)) { // Virtual LAN (i.e. routers l2 Network) number $opts['vlan'] = $matches[2] ; #array_splice($params,0) ; } elseif (preg_match("/^([sn]?id|num[abemorsu]*|nombr[eo]|nm?br|subnetid|networkid)[=:%#@]['\"]?(\d+)['\"]?$/i", $param1, $matches)) { // SubNet index #0> Subnet/Network (specific/numeric) IDentifier (interger) #1: num[abemorsu]+ #1> numar (romanian), #1> numara (turkish), #1> number (english/estonian), #1> numer (albanian), #1> numero (finnish/galician/italian/portuguese/spanish), #1> nummer (danish/icelandic/norwegian/swedish), #1> numru (maltese), #1> numurs (latvian), #2: nombr[eo] #2> nombre (catalan/french), #2> nombro (esperanto), #2: #3> 6poj (macedonian/serbian), #3> aantal (dutch), #3> anzahl (german), #3> broj (croatian), #3> cislo (czech/slovak), #3> liczba (polish), #3> rhif (welsh), #3> skaicius (lithuanian), #3> stevilo (slovenian), #3> szam (hungarian), #3> uimhir (irish), #3> zenbakia (basque), $opts['sid'] = $matches[2] ; #array_splice($params,0) ; } elseif (preg_match("/^(did|deviceid)[=:%#@]['\"]?(\d+)['\"]?$/i", $param1, $matches)) { // Device index $opts['did'] = $matches[2] ; #array_splice($params,0) ; } elseif (preg_match("/^(eid|rackid|cabinetid)[=:%#@]['\"]?(\d+)['\"]?$/i", $param1, $matches)) { // Rack index $opts['eid'] = $matches[2] ; #array_splice($params,0) ; } elseif (preg_match("/^(tid|tagid|statusid)[=:%#@]['\"]?(\d+)['\"]?$/i", $param1, $matches)) { // IP Status index $opts['tid'] = $matches[2] ; #array_splice($params,0) ; } elseif (preg_match("/^(lid|locationid|sisiteid|placeid)[=:%#@]['\"]?(\d+)['\"]?$/i", $param1, $matches)) { // Location index $opts['lid'] = $matches[2] ; #array_splice($params,0) ; } elseif (preg_match("/^(loc|location|sisite|place|plc)[=:%#@]['\"]?(\d+)['\"]?$/i", $param1, $matches)) { // Location index $opts['loc'] = $matches[2] ; #array_splice($params,0) ; /* } elseif (preg_match("/^(ns|nameserver|dns)[=:%#@]['\"]?(\d+)['\"]?$/i", $param1, $matches)) { // Location index $opts['dns'] = $matches[2] ; #array_splice($params,0) ; } elseif (preg_match("/^(zone.*|p[ao]rt|type|z[pb]f|zid)[=:%#@]['\"]?([\w-]+)['\"]?$/i", $param1, $matches)) { // Zone Policy Firewall (for Zone-Based Firewall) $opts['zid'] = $matches[2]; // zone+mapping and module since 1.20 #array_splice($params,0) ; */ } elseif (preg_match("/^['\"]?(\d+)['\"]?$/", $param1, $matches)) { $opts['sid'] = $matches[1] ; #array_splice($params,0) ; } elseif (preg_match("/^(d2[sn])[=:%#@]['\"]?(\d+)['\"]?$/i", $param1, $matches)) { // Device to SubNet $opts['d2s'] = $matches[2] ; #array_splice($params,0) ; } elseif (preg_match("/^(f2[sn])[=:%#@]['\"]?(\d+)['\"]?$/i", $param1, $matches)) { // Folder to SubNet $opts['f2s'] = $matches[2] ; #array_splice($params,0) ; } elseif (preg_match("/^(l2[sn])[=:%#@]['\"]?(\d+)['\"]?$/i", $param1, $matches)) { // Location to SubNet $opts['l2s'] = $matches[2] ; #array_splice($params,0) ; } elseif (preg_match("/^(r2[sn])[=:%#@]['\"]?(\d+)['\"]?$/i", $param1, $matches)) { // VRF to SubNet $opts['r2s'] = $matches[2] ; #array_splice($params,0) ; } elseif (preg_match("/^(s2[sn])[=:%#@]['\"]?(\d+)['\"]?$/i", $param1, $matches)) { // Section to SubNet $opts['s2s'] = $matches[2] ; #array_splice($params,0) ; } elseif (preg_match("/^(v2[sn])[=:%#@]['\"]?(\d+)['\"]?$/i", $param1, $matches)) { // VLAN to SubNet $opts['v2s'] = $matches[2] ; #array_splice($params,0) ; } elseif (preg_match("/^(n2[sn])[=:%#@]['\"]?(\d+)['\"]?$/i", $param1, $matches)) { // VLAN# to SubNet $opts['n2s'] = $matches[2] ; #array_splice($params,0) ; } elseif (preg_match("/^(t2d)[=:%#@]['\"]?(\d+)['\"]?$/i", $param1, $matches)) { // DeviceType to Device $opts['t2d'] = $matches[2] ; #array_splice($params,0) ; } elseif (preg_match("/^(l2d)[=:%#@]['\"]?(\d+)['\"]?$/i", $param1, $matches)) { // Location to Device $opts['l2d'] = $matches[2] ; #array_splice($params,0) ; } elseif (preg_match("/^(e2d)[=:%#@]['\"]?(\d+)['\"]?$/i", $param1, $matches)) { // Rack to Device $opts['e2d'] = $matches[2] ; #array_splice($params,0) ; } elseif (preg_match("/^(l2e)[=:%#@]['\"]?(\d+)['\"]?$/i", $param1, $matches)) { // Location to Rack $opts['l2e'] = $matches[2] ; #array_splice($params,0) ; } elseif (preg_match("/^(d2e)[=:%#@]['\"]?(\d+)['\"]?$/i", $param1, $matches)) { // Device to Rack $opts['d2e'] = $matches[2] ; #array_splice($params,0) ; } elseif (preg_match("/^(22v)[=:%#@]['\"]?(\d+)['\"]?$/i", $param1, $matches)) { // l2 domain to VLAN $opts['22v'] = $matches[2] ; #array_splice($params,0) ; } elseif (preg_match("/^(2id|domainid|l2domain)[=:%#@]['\"]?(\d+)['\"]?$/i", $param1, $matches)) { // l2 domain $opts['2id'] = $matches[2] ; #array_splice($params,0) ; } elseif (preg_match("/^(rid|vrfid|)[=:%#@]['\"]?(\d+)['\"]?$/i", $param1, $matches)) { // VRF $opts['rid'] = $matches[2] ; #array_splice($params,0) ; } elseif (preg_match("/^(vrfid|)[=:%#@]['\"]?(\d+)['\"]?$/i", $param1, $matches)) { // VRF $opts['vrf'] = $matches[2] ; #array_splice($params,0) ; } elseif (preg_match("/^(form\w*|fmt|disp\w*|affich\w*|out\w*|show|x?html?|xmltag)[=:%#@]['\"]?(\w+)['\"]?$/i", $param1, $matches)) { // part to show $opts['fmt'] = $matches[2] ; #array_splice($params,0) ; } else { // custom/other parameters if (preg_match("/^(\w+)[=:%#@]['\"]?((?:.(?![\"']?(?:\w+)[=:%#@]|[>\"']))+.?)['\"]?/", $param1, $matches)) { // pair key=>value $opts['cst'][$matches[1]] = $matches[2] ; #array_splice($params,0) ; } } } unset($params) ; // set output formating switch (strtolower($opts['fmt'])) { case 'base' : case 'desc' : case 'head' : case 'info' : case 'main' : case 'meta' : case 'front' : // for racks case 'infos' : case 'description' : case 'information' : case 'presentation' : $opts['fmt'] = '-1' ; break ; case 'ip' : case 'ips' : case 'back' : // for racks case 'list' : case 'rear' : // for racks case 'tail' : case 'used' : case 'hosts' : // for subnets/locations/devices case 'subnets' : // for VLANs/VRFs/l2domains/ case 'networks' : // for VLANs/VRFs/l2domains/ case 'addresses' : // for subnets/locations/devices $opts['fmt'] = '+1' ; break ; case 'all' : case 'any' : case 'both' : $opts['fmt'] = '0' ; break ; default: $opts['fmt'] = (int)$opts['fmt'] ; break ; } // pass them around now return $opts ; } /** * Create output * * @note https://www.dokuwiki.org/devel:syntax_plugins#synopsis * @note https://www.dokuwiki.org/devel:syntax_plugins#render_method */ public function render($mode, Doku_Renderer $renderer, $opts) { if ($mode == 'xhtml' && is_array($opts) and $opts) { // init IPAM object with setting $rest_api = new phpipam_api_client( $this->getConf('api_url'), $this->getConf('api_app'), $this->getConf('api_key') ? $this->getConf('api_key') : false, $this->getConf('api_usr'), $this->getConf('api_pwd'), 'array') ; // token file $token_file = ($this->getConf('api_taf') ? 'token' : false) ; // fetch answers using: // $rest_api->execute($method, $controller, array($param1, $param2, ...), array($global1, $global2, ...) ; // that will generate request like // - 1.2 unencrypted/SSL: // $method $api-url/api/$api-name/$controller/$param1/$param2/... // - 1.3 encrypted: // GET $api-url/?app_id=$api-name&enc=$encrypted_request&global1&$global2&... if ($opts['sid']) { // Subnet index $rest_api->execute('GET', 'subnets', array($opts['sid']), array(), $token_file) ; $reply = $rest_api->get_result() ; if ($reply['data']) { $renderer->doc .= $this->showSub((array)$reply['data'], $opts['fmt']) ; } else { $renderer->doc .= $this->showErr($reply, $opts) ; } } elseif ($opts['net']) { // Subnets search by CIDR $rest_api->execute('GET', 'subnets', array('cidr', $opts['net']), $opts['cst'], $token_file) ; $reply = $rest_api->get_result() ; if ($reply['data']) { foreach ($reply['data'] as $subnet) { $renderer->doc .= $this->showSub((array)$subnet, $opts['fmt']) ; } } else { $renderer->doc .= $this->showErr($reply, $opts) ; } } elseif ($opts['d2s']) { // Subnets from Device index $rest_api->execute('GET', 'tools', array('devices', $opts['d2s'], 'subnets'), $opts['cst'], $token_file) ; $reply = $rest_api->get_result() ; if ($reply['data']) { foreach ($reply['data'] as $subnet) { $renderer->doc .= $this->showSub((array)$subnet, $opts['fmt']) ; } } else { $renderer->doc .= $this->showErr($reply, $opts) ; } } elseif ($opts['f2s']) { // Subnets from Folder index $rest_api->execute('GET', 'subnets', array($opts['f2s'], 'slave_recursive'), $opts['cst'], $token_file) ; $reply = $rest_api->get_result() ; if ($reply['data']) { foreach ($reply['data'] as $subnet) { $renderer->doc .= $this->showSub((array)$subnet, $opts['fmt']) ; } } else { $renderer->doc .= $this->showErr($reply, $opts) ; } } elseif ($opts['l2s']) { // Subnets from Location index $rest_api->execute('GET', 'tools', array('locations', $opts['l2s'], 'subnets'), $opts['cst'], $token_file) ; $reply = $rest_api->get_result() ; if ($reply['data']) { foreach ($reply['data'] as $subnet) { $renderer->doc .= $this->showSub((array)$subnet, $opts['fmt']) ; } } else { $renderer->doc .= $this->showErr($reply, $opts) ; } } elseif ($opts['r2s']) { // Subnets from VRF index $rest_api->execute('GET', 'vrf', array($opts['r2s'], 'subnets'), $opts['cst'], $token_file) ; $reply = $rest_api->get_result() ; if ($reply['data']) { foreach ($reply['data'] as $subnet) { $renderer->doc .= $this->showSub((array)$subnet, $opts['fmt']) ; } } else { $renderer->doc .= $this->showErr($reply, $opts) ; } } elseif ($opts['s2s']) { // Subnets from Section index $rest_api->execute('GET', 'sections', array($opts['s2s'], 'subnets'), $opts['cst'], $token_file) ; $reply = $rest_api->get_result() ; if ($reply['data']) { foreach ($reply['data'] as $subnet) { $renderer->doc .= $this->showSub((array)$subnet, $opts['fmt']) ; } } else { $renderer->doc .= $this->showErr($reply, $opts) ; } } elseif ($opts['v2s']) { // Subnets from VLAN index $rest_api->execute('GET', 'vlans', array($opts['v2s'], 'subnets'), $opts['cst'], $token_file) ; $reply = $rest_api->get_result() ; if ($reply['data']) { foreach ($reply['data'] as $subnet) { $renderer->doc .= $this->showSub((array)$subnet, $opts['fmt']) ; } } else { $renderer->doc .= $this->showErr($reply, $opts) ; } } elseif (isset($opts['vid'])) { // VLAN index if ($opts['vid']) { $rest_api->execute('GET', 'vlans', array($opts['vid']), array(), $token_file) ; $reply = $rest_api->get_result() ; if ($reply['data']) { $renderer->doc .= $this->showNet((array)$reply['data'], $opts['fmt']) ; } else { $renderer->doc .= $this->showErr($reply, $opts) ; } } else { $rest_api->execute('GET', 'vlans', array(), $opts['cst'], $token_file) ; $reply = $rest_api->get_result() ; if ($reply['data']) { foreach ((array)$reply['data'] as $vlan) { $renderer->doc .= $this->showNet((array)$vlan, $opts['fmt']) ; } } else { $renderer->doc .= $this->showErr($reply, $opts) ; } } } elseif (isset($opts['vlan'])) { // VLAN number $rest_api->execute('GET', 'vlans', array('search', $opts['vlan']), $opts['cst'], $token_file) ; $reply = $rest_api->get_result() ; if ($reply['data']) { foreach ($reply['data'] as $vlan) { $renderer->doc .= $this->showNet((array)$vlan, $opts['fmt']) ; } } else { $renderer->doc .= $this->showErr($reply, $opts) ; } } elseif ($opts['22v']) { // VLAN from level2 domain index $rest_api->execute('GET', 'l2domains', array($opts['22v'], 'vlans'), $opts['cst'], $token_file) ; $reply = $rest_api->get_result() ; if ($reply['data']) { foreach ($reply['data'] as $vlan) { $renderer->doc .= $this->showNet((array)$vlan, $opts['fmt']) ; } } else { $renderer->doc .= $this->showErr($reply, $opts) ; } } elseif (isset($opts['2id'])) { // level2 domain index if ($opts['2id']) { $rest_api->execute('GET', 'l2domains', array($opts['2id']), array(), $token_file) ; $reply = $rest_api->get_result() ; if ($reply['data']) { $renderer->doc .= $this->showDom((array)$reply['data'], $opts['fmt']) ; } else { $renderer->doc .= $this->showErr($reply, $opts) ; } } else { $rest_api->execute('GET', 'l2domains', array(), $opts['cst'], $token_file) ; $reply = $rest_api->get_result() ; if ($reply['data']) { foreach ($reply['data'] as $l2dom) { $renderer->doc .= $this->showDom((array)$l2dom, $opts['fmt']) ; } } else { $renderer->doc .= $this->showErr($reply, $opts) ; } } } elseif (isset($opts['rid'])) { // VRF index if ($opts['rid']) { $rest_api->execute('GET', 'vrf', array($opts['rid']), array(), $token_file) ; $reply = $rest_api->get_result() ; if ($reply['data']) { $renderer->doc .= $this->showFwd((array)$reply['data'], $opts['fmt'], 1) ; } else { $renderer->doc .= $this->showErr($reply, $opts) ; } } else { $rest_api->execute('GET', 'vrf', array(), $opts['cst'], $token_file) ; $reply = $rest_api->get_result() ; if ($reply['data']) { foreach ($reply['data'] as $vrf) { $renderer->doc .= $this->showFwd((array)$vrf, $opts['fmt'], 1) ; } } else { $renderer->doc .= $this->showErr($reply, $opts) ; } } } elseif (isset($opts['vrf'])) { // VRF index if ($opts['vrf']) { $rest_api->execute('GET', 'vrf', array($opts['vrf']), array(), $token_file) ; $reply = $rest_api->get_result() ; if ($reply['data']) { $renderer->doc .= $this->showFwd((array)$reply['data'], $opts['fmt'], 0) ; } else { $renderer->doc .= $this->showErr($reply, $opts) ; } } else { $rest_api->execute('GET', 'vrf', array(), $opts['cst'], $token_file) ; $reply = $rest_api->get_result() ; if ($reply['data']) { foreach ($reply['data'] as $vrf) { $renderer->doc .= $this->showFwd((array)$vrf, $opts['fmt'], 0) ; } } else { $renderer->doc .= $this->showErr($reply, $opts) ; } } } elseif (isset($opts['eid'])) { // Rack index if ($opts['eid']) { $rest_api->execute('GET', 'tools', array('racks', $opts['eid']), array(), $token_file) ; $reply = $rest_api->get_result() ; if ($reply['data']) { $renderer->doc .= $this->showCab((array)$reply['data'], $opts['fmt']) ; } else { $renderer->doc .= $this->showErr($reply, $opts) ; } } else { $rest_api->execute('GET', 'tools', array('racks'), $opts['cst'], $token_file) ; $reply = $rest_api->get_result() ; if ($reply['data']) { foreach ($reply['data'] as $rack) { $renderer->doc .= $this->showCab((array)$rack, $opts['fmt']) ; } } else { $renderer->doc .= $this->showErr($reply, $opts) ; } } } elseif (isset($opts['d2e'])) { // Rack from Device index if ($opts['d2e']) { $rest_api->execute('GET', 'devices', array($opts['d2e']), array(), $token_file) ; $reply = $rest_api->get_result() ; if ($reply['data']) { $device = (array)$reply['data'] ; $renderer->doc .= $this->showCab($device['rack'], $opts['fmt']) ; } else { $renderer->doc .= $this->showErr($reply, $opts) ; } } else { $rest_api->execute('GET', 'devices', array(), $opts['cst'], $token_file) ; $reply = $rest_api->get_result() ; if ($reply['data']) { $device = (array)$reply['data'] ; $renderer->doc .= $this->showCab($device['rack'], $opts['fmt']) ; } else { $renderer->doc .= $this->showErr($reply, $opts) ; } } } elseif (isset($opts['l2e'])) { // Rack from Location index $rest_api->execute('GET', 'tools', array('locations', $opts['l2e'], 'racks'), $opts['cst'], $token_file) ; $reply = $rest_api->get_result() ; if ($reply['data']) { foreach ($reply['data'] as $rack) { $renderer->doc .= $this->showCab((array)$rack, $opts['fmt']) ; } } else { $renderer->doc .= $this->showErr($reply, $opts) ; } } elseif (isset($opts['lid'])) { // Location index if ($opts['lid']) { $rest_api->execute('GET', 'tools', array('locations', $opts['lid']), array(), $token_file) ; $reply = $rest_api->get_result() ; if ($reply['data']) { $renderer->doc .= $this->showLoc((array)$reply['data'], $opts['fmt'], 0) ; } else { $renderer->doc .= $this->showErr($reply, $opts) ; } } else { $rest_api->execute('GET', 'tools', array('locations'), $opts['cst'], $token_file) ; $reply = $rest_api->get_result() ; if ($reply['data']) { foreach ($reply['data'] as $location) { $renderer->doc .= $this->showLoc((array)$location, $opts['fmt'], 0) ; } } else { $renderer->doc .= $this->showErr($reply, $opts) ; } } } elseif (isset($opts['loc'])) { // Location index if ($opts['loc']) { $rest_api->execute('GET', 'tools', array('locations', $opts['loc']), array(), $token_file) ; $reply = $rest_api->get_result() ; if ($reply['data']) { $renderer->doc .= $this->showLoc((array)$reply['data'], $opts['fmt'], 1) ; } else { $renderer->doc .= $this->showErr($reply, $opts) ; } } else { $rest_api->execute('GET', 'tools', array('locations'), $opts['cst'], $token_file) ; $reply = $rest_api->get_result() ; if ($reply['data']) { foreach ($reply['data'] as $location) { $renderer->doc .= $this->showLoc((array)$location, $opts['fmt'], 1) ; } } else { $renderer->doc .= $this->showErr($reply, $opts) ; } } } elseif ($opts['did']) { // Device index if ($opts['did']) { $rest_api->execute('GET', 'tools', array('devices', $opts['did']), array(), $token_file) ; $reply = $rest_api->get_result() ; if ($reply['data']) { $renderer->doc .= $this->showDev((array)$reply['data'], $opts['fmt']) ; } else { $renderer->doc .= $this->showErr($reply, $opts) ; } } else { $rest_api->execute('GET', 'tools', array('devices'), $opts['cst'], $token_file) ; $reply = $rest_api->get_result() ; if ($reply['data']) { foreach ($reply['data'] as $device) { $renderer->doc .= $this->showDev((array)$device, $opts['fmt']) ; } } else { $renderer->doc .= $this->showErr($reply, $opts) ; } } } elseif ($opts['l2d']) { // Devices from Location index $rest_api->execute('GET', 'tools', array('locations', $opts['l2d'], 'devices'), array(), $token_file) ; $reply = $rest_api->get_result() ; if (!empty($reply['data'])) { foreach ($reply['data'] as $device) { $renderer->doc .= $this->showDev((array)$device, $opts['fmt']) ; } } else { $renderer->doc .= $this->showErr($reply, $opts) ; } } elseif ($opts['e2d']) { // Devices from Rack index $rest_api->execute('GET', 'tools', array('racks', $opts['e2d'], 'devices'), $opts['cst'], $token_file) ; $reply = $rest_api->get_result() ; if ($reply['data']) { foreach ($reply['data'] as $device) { $renderer->doc .= $this->showDev((array)$device, $opts['fmt']) ; } } else { $renderer->doc .= $this->showErr($reply, $opts) ; } } elseif (isset($opts['tid'])) { // Tag index if ($opts['tid']) { $rest_api->execute('GET', 'tools', array('tags', $opts['tid']), array(), $token_file) ; $reply = $rest_api->get_result() ; if ($reply['data']) { $renderer->doc .= $this->showTag((array)$reply['data'], $opts['fmt']) ; } else { $renderer->doc .= $this->showErr($reply, $opts) ; } } else { $rest_api->execute('GET', 'tools', array('tags'), $opts['cst'], $token_file) ; $reply = $rest_api->get_result() ; if ($reply['data']) { foreach ($reply['data'] as $tag) { $renderer->doc .= $this->showTag((array)$tag, $opts['fmt']) ; } } else { $renderer->doc .= $this->showErr($reply, $opts) ; } } } elseif ($opts['t2d']) { // Devices from their Type index $rest_api->execute('GET', 'tools', array('device_types', $opts['t2d'], 'devices'), array(), $token_file) ; $reply = $rest_api->get_result() ; if (!$reply['data']) { $rest_api->execute('GET', 'tools', array('devicetypes', $opts['t2d'], 'devices'), array(), $token_file) ; $reply = $rest_api->get_result() ; } if ($reply['data']) { foreach ($reply['data'] as $device) { $renderer->doc .= $this->showDev((array)$device, $opts['fmt']) ; } } } else { $renderer->doc .= "
unknown controller...
" ; } return true ; } else { // $mode is 'metadata' (or some newer other value), // or $opts is unset (en empty string or zero) return false ; } } /** * Display API query Error * * @param $result mixed IPAM result data value * @param $input mixed parameters passed to rendering * @retval $web_out string HTML part for the wiki */ private function showErr($result, $input) { // TITLE if ($this->getConf('opo_dat')) { $web_out = '' . var_export($input, true) . '
' . var_export($result, true) . '
Error" . $result['code'] . ': ' . $result['message'] . '
' ; } return "$web_out" ; } /** * * @param $_path string direct link to the object page * @note two kind of links: * @note 'index.php?page=tools§ion=NAME&subnetId=1&sPage=NUMBER' * @note 'index.php?page=administration§ion=NAME&subnetId=1&sPage=NUMBER' * * @see ::showSub * @see ::showLoc * @see ::showDev */ /** * Build web link from a given address * * @param $href string destination URL * @param $clic string optional content * @retval $html string formated output */ private function setALink($href, $clic) { $html = " $_val) { if (strpos($href, strtok($_val, '{'), 0) !== false) { $_wiki = $_key ; break ; } } if ($_wiki == 'this') { if ($_href['path'] == '/doku.php') { parse_str($_href['query'], $_arg) ; $html .= 'wikilink' . (page_exists($_arg['id']) ? '1' : '2') ; $html .= "' title='" . $_arg['id'] ; unset($_arg) ; } else { if (file_exists(DOKU_INC . 'data/pages' . $_href['path'] . '.txt')) { $html .= "wikilink1' title='" . str_replace('/', ':', ltrim($_href['path'], '/')) ; } elseif (file_exists(rtrim(DOKU_INC, '/') . $_href['path'])) { $html .= "interwiki iw_this' title='" . $_href['path'] ; } else { $html .= "wikilink2' title='" . str_replace('/', ':', ltrim($_href['path'], '/')) ; } } } else { $html .= ($_wiki ? "interwiki iw_$_wiki" : 'urlextern') ; } } } else { // relative URL if ($_href['path'] == '/doku.php') { // https://www.dokuwiki.org/pagename parse_str($_href['query'], $_arg) ; $_page = $_arg['id'] ; } else { // https://www.dokuwiki.org/config:useslash $_page = str_replace('/', ':', $_href['path'], $_nbr) ; } // https://forum.dokuwiki.org/post/61789 $html .= 'wikilink' . (page_exists($_page) ? '1' : '2') ; $html .= "' title='$_page" ; } $html .= "'>" ; if ($clic) $html .= "$clic" ; return "$html" ; } /** * Display IP addresses list * * @param $list mixed IPAM result data value * @retval $html string HTML part for the wiki */ private function listAddrs($list) { if (empty($list)) { if ($this->getConf('allowdebug')) { return "" . "No Address" . '
' ; } else return '' ; } $html = '' ; $_conf = trim($this->getConf('opo_efa')) ; // open listing switch($this->getConf('opo_lst')) { case 'dl' : $html .= "\n\t" . $this->getLang('ip') . ' | ' ; $html .= "\n\t\t\t" . $this->getLang('hostname') . ' | ' ; $html .= "\n\t\t\t" . $this->getLang('description') . ' | ' ; if ($this->getConf('opo_efa')) { $_col = 3 ; $_more = array() ; foreach (explode(',', $_conf) as $_key) { $html .= "\n\t\t\t" ; $_lang = $this->getLang($_key) ; $html .= ($_lang ? "$_lang" : ucwords(strtr($_key, '_', ' '))) ; $html .= ' | ' ; $_col += 1 ; } unset($_col, $_lang, $_more) ; } $html .= "\n\t\t
---|---|---|---|
" ; $html .= $_tag1 . $_hAddr . $_tag0 . ' | ' ; $html .= "\n\t\t\t" ; $html .= $_hName . ' | ' ; $html .= "\n\t\t\t" ; $html .= hsc($infos['description']) . ' | ' ; if ($_conf) { $_col = 3 ; foreach (explode(',', $_conf) as $_key) { $html .= "\n\t\t\t" ; $html .= $_more[$_key][1] . ' | ' ; $_col += 1 ; } unset($_col) ; } $html .= "\n\t\t
" . "No Property" . '
' ; } else return '' ; } $_row = 0 ; switch($this->getConf('opo_dsc')) { case 'dl' : $html = "\n\t" . $_val[0] . ' | ' ; $html .= "\n\t\t\t" . $_val[1] . ' | ' ; $html .= "\n\t\t
---|
" ; $html .= "\n\t\t" . $_val[0] . ':' ; $html .= " " . $_val[1] . '' ; $html .= "\n\t\t
" ; $_row += 1 ; } $html .= "\n\t" ;
foreach ($list as $_key => $_val) {
$html .= "" ;
$html .= "" . $_val[0] . '' ;
$html .= "\t" . $_val[1] . '' ;
$html .= "\n" ;
$_row += 1 ;
}
$html .= "
\n" ;
break ;
}
unset($_row) ;
return "$html" ;
}
/**
* Diplay Subnetwork and/or linked addresses
*
* @param $hash_in mixed IPAM result data value
* @param $show_it integer for part to display
* @retval $web_out string HTML part for the wiki
*/
private function showSub($hash_in, $show_it) {
$web_out = "\n' . $reply['message'] . '
' ; } } $web_out .= "\n' . $reply['message'] . '
' ; } } $web_out .= "\n' . $reply['message'] . '
' ; } } if ($show_it >= 0 && $alternate) { $rest_api->execute('GET', 'tools', array('locations', $hash_in['id'], 'subnets'), array(), $token_file) ; $reply = $rest_api->get_result() ; if (isset($reply['data'])) { $_count = 1 ; $_more = array( 0 => array('subnet', 'description'), ) ; foreach ((array)$reply['data'] as $subnet) { $_infos = (array)$subnet ; $_more[$_count][1] = hsc($_infos['description']) ; $_path = 'index.php?page=' ; $_path .= ($_infos['isFolder'] ? 'folders' : 'subnets') ; $_path .= '§ion=' . $_infos['sectionId'] ; $_path .= '&subnetId=' . $_infos['id'] ; if ($_infos['isFolder']) $_subnet = $this->getLang('isFolder') ; else $_subnet = $_infos['subnet'] . '/' . $_infos['mask'] ; if ($_host) $_subnet = $this->setALink("$_host$_path", $_subnet) ; $_more[$_count][0] = "$_subnet" ; $_count += 1 ; } $web_out .= $this->listNets($_more, 'subnet') ; unset($_more) ; } elseif ($this->getConf('allowdebug')) { $web_out .= '' . $reply['message'] . '
' ; } } $web_out .= "\n' . $reply['message'] . '
' ; } } $web_out .= "\n" . "No Network" . '
' ; } else return '' ; } $_row = 1 ; $_key = $list[0] ; switch($this->getConf('opo_lst')) { case 'dl' : $_css = "width: 29em; float: left; margin: 0; padding: .5em; border-top: 1px solid #999;" ; $html = "\n\t" ; $html .= $this->getLang($_key[0]) . ' | ' ; $html .= "\n\t\t\t" ; $html .= $this->getLang($_key[1]) . ' | ' ; $html .= "\n\t\t
---|---|
" ; $html .= $_val[0] . ' | ' ; $html .= "\n\t\t\t" ; $html .= $_val[1] . ' | ' ; $html .= "\n\t\t
" ; $html .= "" ; $html .= $this->getLang($_key[0]) . '' ; $html .= ' ↔ ' ; $html .= "" ; $html .= $this->getLang($_key[1]) . '' ; $html .= "\n\t\t
" ; unset($list[0]) ; foreach ($list as $_val) { $html .= "\n\t\t" ; $html .= "" ; $html .= $_val[0] . '' ; $html .= ' ↔ ' ; $html .= "" ; $html .= $_val[1] . '' ; $html .= "\n\t\t
" ; $_row += 1 ; } $html .= "\n\t" ; $html .= "" ; $html .= "" ; $html .= $this->getLang($_key[0]) . '' ; $html .= "\t" ; $html .= $this->getLang($_key[1]) . '' ; $html .= "\n" ; unset($list[0]) ; foreach ($list as $_val) { $html .= "" ; $html .= "" ; $html .= $_val[0] . '' ; $html .= "\t" ; $html .= $_val[1] . '' ; $html .= "\n" ; $_row += 1 ; } $html .= "\n" ; break ; } unset($_row) ; return "$html" ; } /** * Display layer 2 Network and/or linked subnetworks * * @param $hash_in mixed IPAM result data value * @param $show_it integer for part to display * @retval $web_out string HTML part for the wiki */ private function showNet($hash_in, $show_it) { $web_out = "\n
' . $reply['message'] . '
' ; } } $web_out .= "\n' . $reply['message'] . '
' ; } } $web_out .= "\n' . $reply['message'] . '
' ; } } if ($show_it >= 0 && $alternate) { $rest_api->execute('GET', 'vrf', array($hash_in['id'], 'subnets'), array(), $token_file) ; $reply = $rest_api->get_result() ; if (isset($reply['data'])) { $_count = 1 ; $_more = array( 0 => array('subnet', 'description'), ) ; foreach ((array)$reply['data'] as $subnet) { $_infos = (array)$subnet ; $_more[$_count][1] = hsc($_infos['description']) ; $_path = 'index.php?page=' ; $_path .= ($hash_in['isFolder'] ? 'folders' : 'subnets') ; $_path .= '§ion=' . $hash_in['sectionId'] ; $_path .= '&subnetId=' . $hash_in['id'] ; if ($_infos['isFolder']) $_subnet = $this->getLang('isFolder') ; else $_subnet = $_infos['subnet'] . '/' . $_infos['mask'] ; if ($_host) $_subnet = $this->setALink("$_host$_path", $_subnet) ; $_more[$_count][0] = "$_subnet" ; $_count += 1 ; } $web_out .= $this->listNets($_more, 'subnet') ; unset($_more) ; } elseif ($this->getConf('allowdebug')) { $web_out .= '' . $reply['message'] . '
' ; } } $web_out .= "\n" ; $web_out .= '['. ($rackFrom <= $rackInfo['size'] ? $this->getLang('front') : $this->getLang('back')) . '] ' ; $web_out .= $rackInfo['name'] . ' | |
---|---|
getConf('opo_eca'))
$web_out .= "' style='background-color: " . $item['color'] . ";'" ;
else
$web_out .= "'" ;
$web_out .= ' title="' . hsc($item['comment']) . '">' ;
if ($item['link'])
$web_out .= "' ;
$web_out .= " " ;
$web_out .= $item['model'] . ($item['comment'] ? ' *' : '') ;
$web_out .= " " ;
$web_out .= $item['name'] . ' ' ;
if ($item['link'])
$web_out .= "" ;
$web_out .= ' | |
" . ($_u - $rackFrom + 1) . " |