add slot display
[racktables-contribs] / LinkManagement / plugins / linkmgmt.php
CommitLineData
9276dc97 1<?php
3badc888 2// TODO linkchain cytoscape create libs?
3// linkchain all objects graph cytoscape takes ages
4// avoid create own linkchain for every port on global map
5// highlight port cytoscape maps
9276dc97 6/*
c7a681fc 7 * Link Management for RT >= 0.20.9
9276dc97 8 *
fdc74cf0 9 * Features:
10 * - create links between ports
11 * - create backend links between ports
12 * - visually display links / chains
13 * e.g.
14 * (Object)>[port] -- front --> [port]<(Object) == back == > (Object)>[port] -- front --> [port]<(Object)
15 * - Link object backend ports by name (e.g. handy for patch panels)
16ec374c 16 * - change/create CableID
17 * - change/create Port Reservation Comment
fdc74cf0 18 * - multiple backend links for supported port types (e.g. AC-in, DC)
19 * - GraphViz Maps (Objects, Ports and Links) (needs GraphViz_Image 1.3.0)
20 * - object,port or link highligthing (just click on it)
21 * - context menu to link and unlink ports
9276dc97 22 *
fdc74cf0 23 * Usage:
24 * 1. select "Link Management" tab
25 * 2. you should see link chains of all linked ports
26 * 3. to display all ports hit "Show All Ports" in the left upper corner
27 * 4. to link all ports with the same name of two different objects use "Link Object Ports by Name"
28 * a. select the other object you want to backend link to
29 * b. "show back ports" gives you the list of possible backend links
30 * !! Important port names have to be the same on both objects !!
31 * e.g. (Current Object):Portname -?-> Portname:(Selected Object)
32 * c. select all backend link to create (Ctrl + a for all)
33 * d. Enter backend CableID for all selected links
34 * e. "Link back" create the backend links
35 * 5. If you have an backend link within the same Object the link isn't shown until
36 * "Expand Backend Links on same Object" is hit
37 * 6. "Object Map" displays Graphviz Map of current object
38 * 7. To get a Graphviz Map of a single port click the port name on the left
9276dc97
ME
39 *
40 *
3badc888 41 * Changes:
42 * switch to new linkchain class
43 * - nicer looking graphviz maps
44 * - better multilink support
45 *
46 * add cytoscape.js maps
47 * - path higlighting
48 * - zooming
49 *
fdc74cf0 50 * Requirements:
51 * PHP 5 (http://php.net/)
52 * GraphViz_Image 1.3.0 or newer (http://pear.php.net/package/Image_GraphViz)
53 * GraphViz (http://www.graphviz.org/)
9276dc97 54 *
3badc888 55 * to user cytoscape js map the following is required:
383230c5 56 * create plugins/linkmgmt directory and place the following 7 files in it
3badc888 57 *
58 * Cytoscape.js (http://js.cytoscape.org/)
3badc888 59 * https://cytoscape.github.io/cytoscape.js/api/cytoscape.js-latest/cytoscape.min.js
60 * dagre.js
3badc888 61 * https://raw.githubusercontent.com/cpettitt/dagre/master/dist/dagre.min.js
62 * https://raw.githubusercontent.com/cytoscape/cytoscape.js-dagre/master/cytoscape-dagre.js
63 * qtip
3badc888 64 * https://cdnjs.cloudflare.com/ajax/libs/qtip2/2.2.1/jquery.qtip.min.css
65 *
3badc888 66 * https://cdnjs.cloudflare.com/ajax/libs/qtip2/2.2.1/jquery.qtip.min.js
67 * https://raw.githubusercontent.com/cytoscape/cytoscape.js-qtip/master/cytoscape-qtip.js
68 *
69 * jquery >= 1.10.0 (qtip requirement)
3badc888 70 * https://code.jquery.com/jquery-1.11.3.min.js
71 *
9276dc97
ME
72 * INSTALL:
73 *
fdc74cf0 74 * 1. create LinkBackend Table in your RackTables database
75 *
76 * Multilink table
9276dc97
ME
77
78CREATE TABLE `LinkBackend` (
79 `porta` int(10) unsigned NOT NULL DEFAULT '0',
80 `portb` int(10) unsigned NOT NULL DEFAULT '0',
81 `cable` char(64) DEFAULT NULL,
82 PRIMARY KEY (`porta`,`portb`),
cb15aecc 83 KEY `LinkBackend_FK_a` (`porta`),
fdc74cf0 84 KEY `LinkBackend_FK_b` (`portb`),
85 CONSTRAINT `LinkBackend_FK_a` FOREIGN KEY (`porta`) REFERENCES `Port` (`id`) ON DELETE CASCADE,
86 CONSTRAINT `LinkBackend_FK_b` FOREIGN KEY (`portb`) REFERENCES `Port` (`id`) ON DELETE CASCADE
1fb0f48b 87) ENGINE=InnoDB DEFAULT CHARSET=utf8 collate=utf8_unicode_ci;
9276dc97 88
16ec374c 89 * 2. copy linkmgmt.php to plugins directory
fdc74cf0 90 *
91 * Ready to go!
92 *
93 *
94 * UPDATE TABLE:
95 *
96 * Update from non-multilink table
97 * ALTER TABLE
98
99ALTER TABLE LinkBackend ADD KEY `LinkBackend_FK_b` (`portb`);
100ALTER TABLE LinkBackend DROP INDEX porta;
101ALTER TABLE LinkBackend DROP INDEX portb;
102
b695efd7 103 * UPDATE to RT 0.20.7
104
105ALTER TABLE LinkBackend CONVERT to CHARACTER SET utf8 COLLATE utf8_unicode_ci;
106
fdc74cf0 107 *
9276dc97
ME
108 *
109 * TESTED on FreeBSD 9.0, nginx/1.0.11, php 5.3.9
fdc74cf0 110 * GraphViz_Image 1.3.0
9276dc97 111 *
16ec374c 112 * (c)2012-2016 Maik Ehinger <m.ehinger@ltur.de>
9276dc97
ME
113 */
114
fdc74cf0 115/**
116 * The newest version of this plugin can be found at:
9276dc97 117 *
3badc888 118 * https://github.com/github138/myRT-contribs/tree/develop-0.20.x
9276dc97
ME
119 *
120 */
121
122/*************************
123 * TODO
124 *
125 * - code cleanups
126 * - bug fixing
127 *
fdc74cf0 128 * - put selected object/port top left of graph
129 * - multlink count for Graphviz maps empty or full dot
130 *
131 * - csv list
9276dc97
ME
132 *
133 */
134
fdc74cf0 135/* DEBUG */
136//error_reporting(E_ALL);
9276dc97
ME
137
138$tab['object']['linkmgmt'] = 'Link Management';
139$tabhandler['object']['linkmgmt'] = 'linkmgmt_tabhandler';
140//$trigger['object']['linkmgmt'] = 'linkmgmt_tabtrigger';
141
142$ophandler['object']['linkmgmt']['update'] = 'linkmgmt_opupdate';
143$ophandler['object']['linkmgmt']['unlinkPort'] = 'linkmgmt_opunlinkPort';
144$ophandler['object']['linkmgmt']['PortLinkDialog'] = 'linkmgmt_opPortLinkDialog';
145$ophandler['object']['linkmgmt']['Help'] = 'linkmgmt_opHelp';
146
fdc74cf0 147$ophandler['object']['linkmgmt']['map'] = 'linkmgmt_opmap';
148$ajaxhandler['lm_mapinfo'] = 'linkmgmt_ajax_mapinfo';
16ec374c 149$ajaxhandler['lm-upd-reservation-cable'] = 'linkmgmt_updateCableIdAJAX';
fdc74cf0 150
3badc888 151$ophandler['object']['linkmgmt']['cytoscapemap'] = 'linkmgmt_cytoscapemap';
152
fdc74cf0 153/* ------------------------------------------------- */
154
1e6c47e6 155define('LM_MULTILINK',TRUE);
fdc74cf0 156
157/* -------------------------------------------------- */
158
159$lm_multilink_port_types = array(
160 16, /* AC-in */
161 //1322, /* AC-out */
162 1399, /* DC */
163 );
9276dc97
ME
164
165/* -------------------------------------------------- */
166
167$lm_cache = array(
3254ec33 168 'allowcomment' => TRUE, /* RackCode {$op_set_reserve_comment} */
169 'allowlink' => TRUE, /* RackCode {$op_set_link} */
170 'allowbacklink' => TRUE, /* RackCode {$op_set_backlink} */
9276dc97
ME
171 'rackinfo' => array(),
172 );
173
174/* -------------------------------------------------- */
175
176//function linkmgmt_tabtrigger() {
177// return 'std';
178//} /* linkmgmt_tabtrigger */
179
3badc888 180/* -------------------linkchain stuff------------------------------- */
181class linkchain_cache
182{
183 public $cache = array();
9276dc97 184
3badc888 185 function getobject($object_id , &$rack = null)
186 {
187 if(!$object_id)
188 return null;
9276dc97 189
3badc888 190 if(!isset($this->cache['o'.$object_id]))
191 {
192 $object = spotEntity('object', $object_id);
193 $object['IPV4OBJ'] = considerConfiguredConstraint ($object, 'IPV4OBJ_LISTSRC');
9276dc97 194
3badc888 195 /* get more object info */
9276dc97 196
3badc888 197 if($object['IPV4OBJ'])
198 {
199 // ip addresses
200 //amplifyCell($object); /* get ports, ipv4, ipv6, nat4 and files */
201 $object['ipv4'] = getObjectIPv4Allocations ($object_id);
202 $object['portip'] = array();
203 foreach($object['ipv4'] as $ipv4)
204 {
205 $object['portip'][$ipv4['osif']] = $ipv4['addrinfo']['ip'];
206 }
207 }
9276dc97 208
3badc888 209 if($object['container_id'])
210 {
211 $container = $this->getobject($object['container_id']);
212 }
fdc74cf0 213
3badc888 214 $this->cache['o'.$object_id] = $object;
215 }
216 else
217 $object = $this->cache['o'.$object_id];
fdc74cf0 218
3badc888 219 $rack = $this->getrack($object['rack_id']);
fdc74cf0 220
3badc888 221 return $object;
222 }
fdc74cf0 223
3badc888 224 function getrack($rack_id)
225 {
226 // rack
227 if($rack_id)
228 {
229 if(!isset($this->cache['r'.$rack_id]))
230 {
231 $rack = spotEntity('rack', $rack_id);
232 $this->cache['r'.$rack_id] = $rack;
233 }
234 else
235 $rack = $this->cache['r'.$rack_id];
236 }
237 else
238 $rack = null;
fdc74cf0 239
3badc888 240 return $rack;
fdc74cf0 241
3badc888 242 }
243}
fdc74cf0 244
3badc888 245$lc_cache = new linkchain_cache();
fdc74cf0 246
3badc888 247/* recursive class */
248class lm_linkchain implements Iterator {
fdc74cf0 249
3badc888 250 const B2B_LINK_BGCOLOR = '#d8d8d8';
251 const CURRENT_PORT_BGCOLOR = '#ffff99';
252 const CURRENT_OBJECT_BGCOLOR = '#ff0000';
253 const HL_PORT_BGCOLOR = '#A0FFA0';
254 const ALTERNATE_ROW_BGCOLOR = '#f0f0f0';
255
256 public $first = null;
257 public $last = null;
258 public $init = null;
259 public $linked = null;
260 public $linkcount = 0;
261
262 public $loop = false;
263 private $lastipobjport = null;
264
265 public $ports = array();
266
267 private $currentid = null;
268 private $back = null;
269 public $initback = null;
270
271 //public $cache = null;
272 private $object_id = null;
273
274 private $icount = 0;
275 public $exceed = false;
276
277 public $initalign = true;
278
279 public $portmulti = 0;
280 public $prevportmulti = 0;
281
282 private $initport = false;
283
284 private $lids = array(); // link ids porta portb linktype
285
286 public $pids = null; // port ids
287 public $oids = null; // object ids
288
289 /* $back = null follow front and back
290 * true follow back only
291 * false follow front only
292 * $prevport first port
293 */
294 function __construct($port_id, $back = null, $prevport = null, $reverse = false, &$pids = null, &$oids = null)
fdc74cf0 295 {
3badc888 296 global $lc_cache;
fdc74cf0 297
3badc888 298 $this->init = $port_id;
fdc74cf0 299
3badc888 300 $this->initback = $back;
fdc74cf0 301
3badc888 302 if($pids === null)
303 $this->pids = array();
304 else
305 $this->pids = &$pids;
306
307 if($oids === null)
308 $this->oids = array();
309 else
310 $this->oids = &$oids;
311
312 if($back !== null)
fdc74cf0 313 {
3badc888 314 $prevport_id = $prevport['id'];
315 $prevlinktype = $this->getlinktype(!$back);
316 //if($this->setlinkid($port_id, $prevport_id, $prevlinktype))
317 {
318 $this->last = $this->_getlinks($port_id, $back, null, $reverse);
319 }
320 //else
321 {
322 // $this->loop = true;
323 // echo "SUBCHAIN LID exists $port_id $prevlinktype $prevport_id<br>";
324 }
fdc74cf0 325
3badc888 326 // TODO set previous port ..use _set... function()
327 $this->ports[$port_id][$this->getlinktype(!$back)]['portcount'] = 1;
328 $this->ports[$port_id][$this->getlinktype(!$back)]['linked'] = 1;
329 $this->ports[$port_id][$this->getlinktype(!$back)]['remote_id'] = $prevport['id'];
330 $this->ports[$port_id][$this->getlinktype(!$back)]['remote_object_id'] = $prevport['object_id'];
331 $this->ports[$port_id][$this->getlinktype(!$back)]['remote_name'] = $prevport['name'];
332 $this->ports[$port_id][$this->getlinktype(!$back)]['remote_object_name'] = $prevport['object_name'];
333 $this->ports[$port_id][$this->getlinktype(!$back)]['cableid'] = $prevport['cableid'];
fdc74cf0 334
fdc74cf0 335
3badc888 336 $prevport = $this->_setportlink($prevport, $this->getlinktype(!$back));
337 $prevport[$this->getlinktype($back)]['portcount'] = null;
338 $prevport[$this->getlinktype($back)]['remote_id'] = null;
339 $prevport[$this->getlinktype($back)]['remote_object_id'] = null;
fdc74cf0 340
3badc888 341 $this->ports[$prevport_id] = $prevport;
342 $this->first = $prevport_id;
343 $this->linkcount++;
fdc74cf0 344
3badc888 345 // self::var_dump_html($this->ports[$port_id], "PORT");
346 // self::var_dump_html($prevport, "PREVPORT");
347 $this->object_id = $_GET['object_id'];
348 }
349 else
350 {
351 // Link
352 $this->last = $this->_getlinks($port_id, false);
fdc74cf0 353
3badc888 354 if(!$this->loop)
355 $this->first = $this->_getlinks($port_id, true, null, true);
fdc74cf0 356
3badc888 357 $this->object_id = $this->ports[$this->init]['object_id'];
358 }
fdc74cf0 359
3badc888 360 if(0)
361 if($this->loop)
362 {
363 $linktype = $this->getlinktype($back);
364 $prevlinktype = $this->getlinktype(!$back);
365
366 /* set first object */
367 $object_id = $this->ports[$port_id]['object_id'];
368 $object = $lc_cache->getobject($object_id);
fdc74cf0 369
3badc888 370 if($object['IPV4OBJ'])
371 $this->lastipobjport = $port_id;
372
373 $this->first = $this->lastipobjport;
fdc74cf0 374 }
fdc74cf0 375
3badc888 376 $this->linked = ($this->linkcount > 0);
377
378 if($reverse)
379 $this->reverse();
fdc74cf0 380
381 }
fdc74cf0 382
3badc888 383 function setlinkid($porta, $portb, $linktype)
384 {
385 if($porta > $portb)
386 $lid = "${portb}_${porta}";
387 else
388 $lid = "${porta}_${portb}";
fdc74cf0 389
3badc888 390 $lid .= $linktype;
fdc74cf0 391
3badc888 392 if(isset($this->lids[$lid]))
393 return false;
fdc74cf0 394
3badc888 395 $this->lids[$lid] = true;
fdc74cf0 396
3badc888 397 return true;
fdc74cf0 398 }
399
3badc888 400 function hasport_id($port_id)
fdc74cf0 401 {
3badc888 402 if(isset($this->pids[$port_id]))
403 return true;
404 else
405 return false;
fdc74cf0 406 }
407
3badc888 408 function hasobject_id($object_id)
409 {
410 if(isset($this->oids[$object_id]))
411 return true;
412 else
413 return false;
414 }
fdc74cf0 415
3badc888 416 function _setportprevlink($port, $linktype, $prevport)
417 {
418 $port[$linktype] = array(
419 'cableid' => $prevport[$linktype]['cableid'],
420 'linked' => $prevport[$linktype]['linked'],
421 'portcount' => null, //$prevport[$linktype]['linked'],
422 'remote_id' => $prevport['id'],
423 'remote_name' => $prevport['name'],
424 'remote_object_id' => $prevport['object_id'],
425 'remote_object_name' => $prevport['object_name'],
426 );
fdc74cf0 427
3badc888 428 return $port;
429 }
fdc74cf0 430
3badc888 431 function _setportlink($port, $linktype)
432 {
433 $port[$linktype] = array(
434 'cableid' => $port['cableid'],
435 'linked' => $port['linked'],
436 'portcount' => $port['portcount'],
437 'remote_id' => $port['remote_id'],
438 'remote_name' => $port['remote_name'],
439 'remote_object_id' => $port['remote_object_id'],
440 'remote_object_name' => $port['remote_object_name'],
441 );
fdc74cf0 442
3badc888 443 unset($port['cableid']);
444 unset($port['linked']);
445 unset($port['portcount']);
446 unset($port['remote_id']);
447 unset($port['remote_name']);
448 unset($port['remote_object_id']);
449 unset($port['remote_object_name']);
fdc74cf0 450
3badc888 451 return $port;
452 }
fdc74cf0 453
3badc888 454 function _getportlink($port)
455 {
456 $linktype = $this->getlinktype($this->back);
457 return array_merge($port, $port[$linktype], array('linktype' => $linktype));
458 }
fdc74cf0 459
3badc888 460 function isback($linktable)
461 {
462 if($linktable == 'back')
463 return true;
464 else
465 return false;
466 }
fdc74cf0 467
3badc888 468 function getlinktype($back)
469 {
470 return ($back ? 'back' : 'front' );
471 }
fdc74cf0 472
3badc888 473 function reverse()
474 {
475 $tmp = $this->first;
476 $this->first = $this->last;
477 $this->last = $tmp;
fdc74cf0 478
fdc74cf0 479 }
480
fdc74cf0 481
3badc888 482 //recursive
483 function _getlinks($port_id, $back = false, $prevport_id = null, $reverse = false)
484 {
485 global $lc_cache;
486 $linktype = $this->getlinktype($back);
fdc74cf0 487
3badc888 488 if($port_id == $this->init)
489 $this->initport = true;
fdc74cf0 490
3badc888 491 $ports = lm_getPortInfo($port_id, $back);
fdc74cf0 492
3badc888 493 $portcount = count($ports);
fdc74cf0 494
3badc888 495 $port = $ports[0];
fdc74cf0 496
3badc888 497 // check for loops on multilinked ports
498 // set main port to looping one
499 if($portcount > 1)
500 foreach($ports as $mport)
501 {
502 if(isset($this->ports[$mport['remote_id']]))
503 {
504 $port = $mport;
505 break;
506 }
507 }
fdc74cf0 508
3badc888 509 $remote_id = $port['remote_id'];
fdc74cf0 510
3badc888 511 $port['portcount'] = $portcount;
fdc74cf0 512
3badc888 513 $object_id = $port['object_id'];
fdc74cf0 514
3badc888 515 $rack = null;
516 $object = $lc_cache->getobject($object_id, $rack);
fdc74cf0 517
3badc888 518 $this->oids[$object_id] = true;
fdc74cf0 519
3badc888 520 if($object['IPV4OBJ'])
521 $this->lastipobjport = $port_id;
fdc74cf0 522
3badc888 523 if($object)
524 if(isset($object['portip'][$port['name']]))
525 $port['portip'] = $object['portip'][$port['name']];
fdc74cf0 526
3badc888 527 $port = $this->_setportlink($port, $linktype);
fdc74cf0 528
3badc888 529 if($prevport_id)
fdc74cf0 530 {
3badc888 531 $prevlinktype = $this->getlinktype(!$back);
532 $port = $this->_setportprevlink($port, $prevlinktype, $this->ports[$prevport_id]);
fdc74cf0 533 }
534
3badc888 535 //if(!$back)
536 {
537 if($prevport_id)
538 {
539 /* mutlilink: multiple previous links */
540 $prevports = lm_getPortInfo($port_id, !$back);
fdc74cf0 541
3badc888 542 $prevportcount = count($prevports);
fdc74cf0 543
3badc888 544 if($prevportcount > 1)
545 {
546 if($this->initport)
547 $this->initalign = false;
fdc74cf0 548
3badc888 549 $port[$this->getlinktype(!$back)]['portcount'] = $prevportcount;
fdc74cf0 550
3badc888 551 $lcs = array();
552 foreach($prevports as $mport)
553 {
554 if($prevport_id != $mport['remote_id'])
555 {
556 if(isset($this->pids[$mport['remote_id']]))
557 continue;
fdc74cf0 558
3badc888 559 $mport['portcount'] = 1;
560 $lc = new lm_linkchain($mport['remote_id'], $back, $mport, !$reverse, $this->pids, $this->oids);
561 $lcs[$mport['remote_id']] = $lc;
562 $this->linkcount += $lc->linkcount;
563 }
564 }
fdc74cf0 565
3badc888 566 $port[$this->getlinktype(!$back)]['chains'] = $lcs;
567 }
568 }
569 }
fdc74cf0 570
3badc888 571 if($portcount > 1)
fdc74cf0 572 {
3badc888 573 /* mutlilink: multiple links */
574
575 $lcs = array();
576 foreach($ports as $mport)
577 {
578 if($remote_id != $mport['remote_id'])
579 {
580 if(isset($this->pids[$mport['remote_id']]))
581 continue;
582
583 $mport['portcount'] = 1;
584 $lc = new lm_linkchain($mport['remote_id'], !$back, $mport, $reverse, $this->pids, $this->oids);
585 $lcs[$mport['remote_id']] = $lc;
586 $this->linkcount += $lc->linkcount;
587 }
588 }
589
590 $port[$linktype]['chains'] = $lcs;
fdc74cf0 591
fdc74cf0 592 }
593
3badc888 594 if(isset($this->ports[$port_id]))
595 {
596 if(!isset($this->ports[$port_id][$linktype]))
597 {
598 $this->ports[$port_id][$linktype] = $port[$linktype];
599 }
600 }
601 else
602 $this->ports[$port_id] = $port;
fdc74cf0 603
3badc888 604 $this->pids[$port_id] = true;
fdc74cf0 605
3badc888 606 if($remote_id)
607 {
608 if($this->setlinkid($port_id, $remote_id, $linktype))
609 {
610 $this->linkcount++;
611 return $this->_getlinks($remote_id, !$back, $port_id, $reverse);
612 }
613 else
614 {
615 $prevlinktype = $this->getlinktype(!$back);
616 $this->loop = true;
617 if(isset($port[$prevlinktype]))
618 $this->ports[$port_id][$prevlinktype] = $port[$prevlinktype];
619
620 $this->first = $remote_id;
621 }
622 }
623
624 return $port_id;
625 }
626
627 // TODO
628 function getchaintext()
629 {
630 //$this::var_dump_html($this->ports);
631 $chain = "";
632 foreach($this as $id => $port)
633 {
634 $linktype = $port['linktype']; //$this->getlinktype();
635 if($linktype == 'front')
636 $arrow = ' --> ';
637 else
638 $arrow = ' => ';
639
640 $text = $port['object_name']." [".$port['name']."]";
641
642 if($id == $this->init)
643 $chain .= "*$text*";
644 else
645 $chain .= "$text";
646
647 $remote_id = $port['remote_id'];
648
649 if($remote_id)
650 $chain .= $arrow;
651
652 if($this->loop && $remote_id == $this->first)
653 {
654 $chain .= "LOOP!";
655 break;
656 }
657 }
658 return $chain;
659 }
660
661 function getchainlabeltrstart($rowbgcolor = '#ffffff')
662 {
663
664 $port_id = $this->init;
665
666 $initport = $this->ports[$port_id];
fdc74cf0 667
668 $urlparams = array(
3badc888 669 'module' => 'redirect',
670 'page' => 'object',
671 'tab' => 'linkmgmt',
672 'op' => 'map',
673 'usemap' => 1,
674 'object_id' => $initport['object_id'],
fdc74cf0 675 );
676
3badc888 677 $hl_port_id = NULL;
678 if($hl_port_id !== NULL)
679 $urlparams['hl_port_id'] = $hl_port_id;
680 else
681 $urlparams['port_id'] = $port_id;
fdc74cf0 682
3badc888 683 $title = "linkcount: ".$this->linkcount."\nTypeID: ${initport['oif_id']}\nPortID: $port_id";
fdc74cf0 684
3badc888 685 $onclick = 'onclick=window.open("'.makeHrefProcess(array_merge($_GET, $urlparams)).'","Map","height=500,width=800,scrollbars=yes");';
fdc74cf0 686
3badc888 687 if($hl_port_id == $port_id)
688 {
689 $hlbgcolor = "bgcolor=".self::HL_PORT_BGCOLOR;
690 }
691 else
692 $hlbgcolor = "bgcolor=$rowbgcolor";
fdc74cf0 693
3badc888 694 if($rowbgcolor == '#ffffff')
695 $troutlinecolor = 'grey';
696 else
697 $troutlinecolor = 'white';
fdc74cf0 698
3badc888 699 /* Current Port */
700 $chainlabel = '<tr '.$hlbgcolor.' style="outline: thin solid '.$troutlinecolor.';"><td nowrap="nowrap" bgcolor='.($this->loop ? '#ff9966' : self::CURRENT_PORT_BGCOLOR).' title="'.$title.
701 '"><a '.$onclick.'>'.
702 $initport['name'].': </a></td>';
fdc74cf0 703
3badc888 704 return $chainlabel;
705 }
706
707 function getchainrow($allback = false, $rowbgcolor = '#ffffff', $isprev = false)
708 {
709 $port_id = $this->init;
710
711 $initport = $this->ports[$port_id];
712 $portmulti = 0;
713 $prevportmulti = 0;
714
715 $chain = "";
716
717 $remote_id = null;
718 $portalign = false;
719 $portmultis = array();
720 $i=0;
721 foreach($this as $id => $port)
fdc74cf0 722 {
3badc888 723 if($this->loop && (($isprev && $id == $this->last) || ($this->initback === null && !$isprev && $id == $this->first)))
724 $chain .= '<td bgcolor=#ff9966>LOOP</td>';
725
726 $object_text = $this->getprintobject($port);
727 $port_text = $this->getprintport($port);
728
729 if($this->initback !== null && (($isprev && $id == $this->last) || (!$isprev && $id == $this->first)))
fdc74cf0 730 {
3badc888 731 $object_text = "";
732 $port_text = "";
fdc74cf0 733 }
fdc74cf0 734
3badc888 735 $linktype = $port['linktype'];
736 $prevlinktype = ($linktype == 'front' ? 'back' : 'front');
fdc74cf0 737
3badc888 738 if($port[$prevlinktype]['portcount'] > 1)
739 {
740 $prevportmulti++;
741 /* mutlilink: multiple previous links */
fdc74cf0 742
3badc888 743 $notrowbgcolor = ($rowbgcolor == lm_linkchain::ALTERNATE_ROW_BGCOLOR ? '#ffffff' : lm_linkchain::ALTERNATE_ROW_BGCOLOR );
744 if($this->prevportmulti % 2)
745 {
746 $oddbgcolor = $rowbgcolor;
747 $evenbgcolor = $notrowbgcolor;
748 }
749 else
750 {
751 $oddbgcolor = $notrowbgcolor;
752 $evenbgcolor = $rowbgcolor;
753 }
fdc74cf0 754
3badc888 755 $chain = "<td><table id=pmp frame=box><tr id=main><td><table id=pmmain align=right><tr>$chain</tr></table></td></tr><!-- main tr--><tr><td><table id=plcs align=right width=100%>"; // end table pmmain; end main tr
fdc74cf0 756
3badc888 757 $mi = 0;
758 foreach($port[$prevlinktype]['chains'] as $mlc)
759 {
760 $mbgcolor = ($mi % 2 ? $evenbgcolor : $oddbgcolor);
761 $chain .= "<tr bgcolor=$mbgcolor align=right><td><table id=plc><tr>".$mlc->getchainrow($allback,$mbgcolor, true)."</tr></table><!-- end plc --></td></tr>"; // close table plc
762 $mi++;
763 }
764 $chain .= "</table><!--plcs--></td></tr></table><!--pmp--></td><td bgcolor=#ff0000></td>"; // clode tables plcs; pmp
fdc74cf0 765
3badc888 766 }
83b49cf7 767
3badc888 768 if($port_text && !$this->loop && $id == $this->first)
769 {
770 $chain .= $this->_printlinkportsymbol($id, $prevlinktype);
83b49cf7 771
3badc888 772 if($prevlinktype == 'front')
773 $chain .= $this->printcomment($port);
774 }
83b49cf7 775
3badc888 776 // current port align
777 if($this->initback === null && $port_text && !$portmulti && !$prevportmulti && $this->initalign && $id == $port_id)
778 {
779 $portalign = true;
780 $port_text = "</tr></table><!--t1 current--></td><!--end 1st td--><td id=2nd width=100%><table id=t2><tr>$port_text"; // close table t1 current; clode 1st td
781 }
83b49cf7 782
3badc888 783 $object_id = $port['object_id'];
83b49cf7 784
3badc888 785 $prevobject_id = $port[$prevlinktype]['remote_object_id'];
786 $remote_object_id = $port['remote_object_id'];
83b49cf7 787
3badc888 788 if($linktype == 'front')
789 {
790 // $arrow = ' ---> ';
791 if($object_text)
792 {
793 if($prevobject_id != $object_id || $allback)
794 $chain .= $object_text."<td>></td>";
83b49cf7 795
3badc888 796 $chain .= $port_text;
797 }
83b49cf7 798
3badc888 799 }
800 else
801 {
802 // $arrow = ' ===> ';
803 if($object_text)
804 $chain .= $port_text."<td><</td>".$object_text;
805 }
83b49cf7 806
3badc888 807 if($port['portcount'] > 1)
808 {
809
810 /* mutlilink: multiple links */
83b49cf7 811
3badc888 812 $notrowbgcolor = ($rowbgcolor == lm_linkchain::ALTERNATE_ROW_BGCOLOR ? '#ffffff' : lm_linkchain::ALTERNATE_ROW_BGCOLOR );
813 if($this->portmulti % 2)
814 {
815 $oddbgcolor = $rowbgcolor;
816 $evenbgcolor = $notrowbgcolor;
817 }
818 else
819 {
820 $oddbgcolor = $notrowbgcolor;
821 $evenbgcolor = $rowbgcolor;
822 }
823
824 $chain .= "<td bgcolor=#ff0000></td><td><table id=mp frame=box>";
83b49cf7 825
3badc888 826 $multichain = "<tr><td><table id=mlcs width=100%>";
83b49cf7 827
3badc888 828 $mi = 0;
829 foreach($port['chains'] as $mlc)
830 {
83b49cf7 831
3badc888 832 $mbgcolor = ($mi % 2 ? $evenbgcolor : $oddbgcolor);
833 $multichain .= "<tr bgcolor=$mbgcolor><td><table id=t9><tr>".$mlc->getchainrow(false, $mbgcolor)."</tr></table></td></tr>";
834 $mi++;
835 }
83b49cf7 836
3badc888 837 $multichain .= "</table><!-- mlcs --></td></tr>"; // close table mlcs
83b49cf7 838
3badc888 839 $portmultis[] = $multichain;
840
841 // main
842 $chain .= "<tr id=mm><td><table id=pmm><tr>";
83b49cf7 843
3badc888 844 $portmulti++;
83b49cf7 845
3badc888 846 }
847
848 $remote_id = $port['remote_id'];
849
850 if($remote_id)
851 if($object_id != $remote_object_id || $allback || $linktype == 'front')
852 $chain .= $this->printlink($port, $linktype);
853 else
854 $chain .= "<td>></td>";
855
856 if($port_text && !($remote_id && $this->loop) && $id == $this->last)
857 {
858 $chain .= $this->_printlinkportsymbol($id, $linktype);
859
860 if($linktype == 'front')
861 $chain .= $this->printcomment($port);
862 }
863
864 $i++;
865 } // foreach port
866
867 if($this->loop && $remote_id)
868 {
869 $chain .= '<td bgcolor=#ff9966>LOOP</td>';
870 showWarning("Possible Loop on Port ($linktype) ".$initport['name']);
83b49cf7 871 }
83b49cf7 872
3badc888 873 if($this->exceed)
874 {
875 $chain .= '<td bgcolor=#ff9966>LINKCOUNT EXCEEDED</td>';
876 $linktype = $this->getlinktype($this->back);
877 showWarning("Possible Loop linkcount(".$this->linkcount.") exceeded on Port ($linktype) ".$initport['name']);
878 }
83b49cf7 879
3badc888 880 foreach(array_reverse($portmultis) as $multitr)
881 {
882 $chain .= "</tr><!-- tr mm --></table><!-- pmm --></td></tr>$multitr</table><!-- mp--></td>"; // close table pmm; mp
883 }
83b49cf7 884
3badc888 885 if($this->initback === null)
886 {
887 // TODO width..
888 $chain = "<td id=1st".(!$portalign ? " colspan=2" : " width=1%")."><table id=t1".(!$portalign ? "" : " align=right")."><tr>$chain";
889 $chain .= "</tr></table><!-- end t1/t2 --></td><!--1st/2nd td-->"; // close table t1/t2; close 1st/2nd td
890 }
891
892 $this->portmulti += $portmulti;
893 $this->prevportmulti += $prevportmulti;
894
895 return $chain;
896 }
897
898 /*
899 */
900 function getprintobject($port) {
901 global $lc_cache;
902
903 $object_id = $port['object_id'];
904
905 if($object_id == $this->object_id) {
906 $color='color: '.self::CURRENT_OBJECT_BGCOLOR;
907 } else {
908 $color='';
909 }
910
911 $style = "font-size: 80%;";
912
913 $rack = null;
914 $object = $lc_cache->getobject($object_id, $rack);
915
c91b2c53 916 $rackinfo = $this->_getprintrack($object_id, $rack, $style);
5ddfc8cc 917
918 if($object['container_id'])
919 {
920 $container_rack = null;
921 $container = $lc_cache->getobject($object['container_id'], $container_rack);
c91b2c53 922 $container_rackinfo = $this->_getprintrack($object['container_id'], $container_rack, $style);
5ddfc8cc 923
924 $txt = '<a style="font-weight:bold;'
925 .$color.'" href="'.makeHref(array('page'=>'object', 'tab' => 'linkmgmt', 'object_id' => $container['id']))
926 .'"><pre>'.$container['name'].'</pre></a><pre>'.$container_rackinfo
927 .'</pre>';
928
929 $txt = "<tr><td><label style=\"font-size: 60%;\">Container:</label>$txt<hr></td></tr>";
930 }
931 else
932 $txt = '';
933
934
935 return '<td><table frame=box align=center cellpadding=5 cellspacing=0>'.$txt.'<tr><td align=center><a style="font-weight:bold;'
936 .$color.'" href="'.makeHref(array('page'=>'object', 'tab' => 'linkmgmt', 'object_id' => $object_id))
937 .'"><pre>'.$object['name'].'</pre></a><pre>'.$rackinfo
938 .'</pre></td></tr></table></td>';
939
940 } /* getprintobject */
941
c91b2c53 942 function _getprintrack($object_id, $rack, $style)
5ddfc8cc 943 {
c91b2c53 944 $slot = null;
945 $attrData = getAttrValues ($object_id);
946 if (isset ($attrData['28'])) // slot number
947 {
948 $slot = $attrData['28']['value'];
949 if (preg_match ('/\d+/', $slot, $matches))
950 $slot = $matches[0];
951 }
952
953 if(!$slot)
954 $txt = 'Unmounted';
955 else
956 $txt = "Slot: $slot";
957
958
959 if($slot)
960 $rackinfo = '<span style="'.$style.'">Slot: '.$slot.'</span>';
961 else
962 $rackinfo = '';
963
964 if($rack)
3badc888 965 {
c91b2c53 966 if($slot)
967 $rackinfo .= "<br>";
968
969 $rackinfo .= '<a style="'.$style.'" href='.makeHref(array('page'=>'row', 'row_id'=>$rack['row_id'])).'>'.$rack['row_name']
3badc888 970 .'</a>/<a style="'.$style.'" href='.makeHref(array('page'=>'rack', 'rack_id'=>$rack['id'])).'>'
971 .$rack['name'].'</a>';
972 }
973
c91b2c53 974 if(!$rackinfo)
975 $rackinfo = '<span style="'.$style.'">Unmounted</span>';
976
5ddfc8cc 977 return $rackinfo;
978 }
3badc888 979
980 function getprintport($port, $multilink = false) {
981 global $lm_cache, $lm_multilink_port_types;
982
983 /* multilink port */
984 $multilink = in_array($port['oif_id'], $lm_multilink_port_types);
985
986 /* set bgcolor for current port */
987 if($this->initback === null && $port['id'] == $this->init) {
988 $bgcolor = 'bgcolor='.self::CURRENT_PORT_BGCOLOR;
989 $idtag = ' id='.$port['id'];
990 } else {
991 $bgcolor = 'bgcolor=#e0e0f8';
992 $idtag = '';
993 }
994
995 $mac = trim(preg_replace('/(..)/','$1:',$port['l2address']),':');
996
997 $title = "Label: ${port['label']}\nMAC: $mac\nTypeID: ${port['oif_id']}\nPortID: ${port['id']}";
998
999 if(isset($port['portip']))
1000 $ip = "<br><p style=\"font-size: 80%\">".$port['portip']."</p>";
1001 else
1002 $ip = "";
1003
1004 return '<td><table><tr><td'.$idtag.' align=center '.$bgcolor.' title="'.$title.'"><pre>[<a href="'
1005 .makeHref(array('page'=>'object', 'tab' => 'linkmgmt', 'object_id' => $port['object_id'], 'hl_port_id' => $port['id']))
1006 .'#'.$port['id']
1007 .'">'.$port['name'].'</a>]'.$ip.'</pre>'.($multilink && $lm_cache['allowbacklink'] ? $this->_getlinkportsymbol($port['id'], 'back') : '' ).'</td></tr></table></td>';
1008
1009 } /* printport */
1010
1011 /*
1012 */
1013 function printlink($port, $linktype) {
1014
3badc888 1015 if($linktype == 'back')
3badc888 1016 $arrow = '====>';
3badc888 1017 else
1018 $arrow = '---->';
1019
1020 $port_id = $port['id'];
1021
1022 /* link */
1023 return '<td align=center>'
16ec374c 1024 .'<pre><span class="editable id1-'.$port_id.' id2-'.$port['remote_id'].' op-lm-upd-reservation-cable linktype-'.$linktype.'">'.$port['cableid']
1025 ."</span></pre><pre>$arrow</pre>"
3badc888 1026 .$this->_printUnLinkPort($port, $linktype)
1027 .'</td>';
1028 } /* printlink */
1029
1030 /*
1031 * return link symbol
1032 */
1033 function _getlinkportsymbol($port_id, $linktype) {
1034 $retval = '<span onclick=window.open("'.makeHrefProcess(array_merge($_GET,
1035 array('op' => 'PortLinkDialog','port' => $port_id,'linktype' => $linktype ))).'","name","height=800,width=800");'
1036 .'>';
1037
1038 $img = getImageHREF ('plug', $linktype.' Link this port');
1039
1040 if($linktype == 'back')
1041 $img = str_replace('<img',
1042 '<img style="transform:rotate(180deg);-o-transform:rotate(180deg);-ms-transform:rotate(180deg);-moz-transform:rotate(180deg);-webkit-transform:rotate(180deg);"',
1043 $img);
1044
1045 $retval .= $img;
1046 $retval .= "</span>";
1047 return $retval;
1048
1049 } /* _getlinkportsymbol */
1050
1051 /*
1052 * print link symbol
1053 *
1054 */
1055 function _printlinkportsymbol($port_id, $linktype = 'front') {
1056 global $lm_cache;
1057
1058 if($linktype == 'front' && !$lm_cache['allowlink'])
1059 return;
1060
1061 if($linktype != 'front' && !$lm_cache['allowbacklink'])
1062 return;
1063
1064 return "<td align=center>"
1065 .$this->_getlinkportsymbol($port_id, $linktype)
1066 ."</td>";
1067
1068 } /* _printlinkportsymbol */
1069
1070 /*
1071 */
1072 function printcomment($port) {
1073
1074 if(!empty($port['reservation_comment'])) {
1075 $prefix = '<b>Reserved: </b>';
1076 } else
1077 $prefix = '';
1078
16ec374c 1079 return '<td>'.$prefix.'</td><td><i><span class="editable op-upd-reservation-port id-'.$port['id'].'">'.$port['reservation_comment'].'</span</i></td>';
3badc888 1080
1081 } /* printComment */
1082
1083 /*
1084 * return link cut symbol
1085 *
1086 * TODO $opspec_list
1087 */
1088 function _printUnLinkPort($src_port, $linktype) {
1089 global $lm_cache;
1090
1091 if($linktype == 'front' && !$lm_cache['allowlink'])
1092 return;
1093
1094 if($linktype != 'front' && !$lm_cache['allowbacklink'])
1095 return;
1096
1097 $dst_port = $this->ports[$src_port['remote_id']];
1098
1099 return '<a href='.
1100 makeHrefProcess(array(
1101 'op'=>'unlinkPort',
1102 'port_id'=>$src_port['id'],
1103 'remote_id' => $dst_port['id'],
1104 'object_id'=> $this->object_id, //$this->ports[$this->init]['object_id'],
1105 'tab' => 'linkmgmt',
1106 'linktype' => $linktype)).
1107 ' onclick="return confirm(\'unlink ports '.$src_port['name']. ' -> '.$dst_port['name']
1108 .' ('.$linktype.') with cable ID: '.$src_port['cableid'].'?\');">'.
1109 getImageHREF ('cut', $linktype.' Unlink this port').'</a>';
1110
1111 } /* _printUnLinkPort */
1112
3d9d3e22 1113 function printports()
1114 {
1115
1116 $back = isset($this->ports[$this->first]['back']['remote_id']);
d894f236 1117 //$this->getporttds($this->first, $back);
1118 foreach($this as $port_id => $port)
1119 {
1120 $class = 'hidden';
1121 if($port_id == $this->first || $port_id == $this->last)
1122 $class = '';
1123
1124 $this->getporttds($port, $class);
1125 }
3d9d3e22 1126 }
1127
d894f236 1128 function getporttds($port, $class = '')
569219fa 1129 {
d894f236 1130 $back = ($port['linktype'] == 'front' ? false : true );
569219fa
CR
1131
1132 // see interface.php renderObjectPortRow()
1133 // highlight port name with yellow if it's name is not canonical
1134 $canon_pn = shortenPortName ($port['name'], $port['object_id']);
1135 $name_class = $canon_pn == $port['name'] ? '' : 'trwarning';
1136
1137 echo "<td class='tdleft $class'>" .
1138 formatPortLink ($port['object_id'], $port['object_name'], $port['id'], NULL) .
1139 "</td>";
1140
1141 $a_class = isEthernetPort ($port) ? 'port-menu' : '';
1142 echo "<td class='tdleft $class' NOWRAP><a name='port-${port['id']}' class='interactive-portname nolink $a_class'>${port['name']}</a></td>";
1143 echo "<td class='tdleft $class'>${port['label']}</td>";
1144 echo "<td class='tdleft $class'>" . formatPortIIFOIF ($port) . "</td><td class='tdleft $class'><tt>${port['l2address']}</tt></td>";
1145
1146 $remote_port = $port[( $back ? 'back' : 'front')];
1147 if ($remote_port['remote_id'])
1148 {
3d9d3e22 1149 if($port['id'] == $this->first)
1150 {
1151 echo "<td class='tdcenter nothidden'>";
1152
1153 if( $this->linkcount == 1 )
1154 if($back)
1155 echo "=${remote_port['cableid']}=>";
1156 else
1157 echo "-${remote_port['cableid']}->";
1158 else
1159 if( $this->linkcount > 1 )
1160 echo "*".$this->linkcount."*>";
1161 echo "</td>";
1162 }
1163
569219fa 1164 $editable = permitted ('object', 'ports', 'editPort') ? 'editable' : '';
d894f236 1165 echo "<td class='tdcenter hidden'>";
569219fa
CR
1166 if($back)
1167 echo "=${remote_port['cableid']}=>";
1168 else
1169 echo "-${remote_port['cableid']}->";
1170
d894f236 1171 echo "</td>";
569219fa
CR
1172 }
1173 else
d894f236 1174 {
1175 if(!empty($port['reservation_comment']))
1176 echo implode ('', formatPortReservation ($port));
1177 }
569219fa 1178
569219fa
CR
1179 } // getporttds
1180
3badc888 1181 // TODO
1182 // html table
1183 function getchainhtml()
1184 {
1185 $remote_id = $this->first;
1186
1187 // if not Link use LinkBackend
1188 $back = $this->ports[$remote_id]['front']['remote_id'];
1189
1190 $chain = "<table>";
1191
1192 for(;$remote_id;)
1193 {
1194 $back = !$back;
1195 $linktype = $port['linktype'];
1196
1197 if($back)
1198 {
1199 // $linktable = 'LinkBackend';
1200 $arrow = ' => ';
1201 }
1202 else
1203 {
1204 // $linktable = 'Link';
1205 $arrow = ' --> ';
1206 }
1207
1208 $port = $this->ports[$remote_id][$linktype];
1209
1210 if($this->init == $remote_id)
1211 $chain .= "<tr><td><b>".$port['object_name']."</b></td><td><b> [".$port['name']."]</b></td>";
1212 else
1213 $chain .= "<tr><td>".$port['object_name']."</td><td> [".$port['name']."]</td>";
1214
1215 if($remote_id == $this->first || $remote_id == $this->last)
1216 $chain .= "<td><div name=\"port${remote_id}-status\"></div></td>";
1217 else
1218 $chain .= "<td></td>";
1219
1220 $remote_id = $port['remote_id'];
1221
1222 if($remote_id)
1223 $chain .= "<td>$arrow</td></tr>";
1224 else
1225 $chain .= "<td></td></tr>";
1226
1227 if($this->loop && $remote_id == $this->first)
1228 {
1229 $chain .= "LOOP!<br>";
1230 break;
1231 }
1232
1233 }
1234
1235 $chain .= "</table>";
1236
1237 return $chain;
1238 }
1239
1240 function getport($id)
1241 {
1242 return $this->ports[$id];
1243 }
1244
1245 /* Iterator */
1246 function rewind() {
1247 $this->currentid = $this->first;
1248
1249 $this->back = isset($this->ports[$this->currentid]['back']['remote_id']);
1250
1251 $this->icount = 0;
1252 }
1253
1254 function current() {
1255 return $this->_getportlink($this->ports[$this->currentid]);
1256 }
1257
1258 function key() {
1259 return $this->currentid;
1260 }
1261
1262 function next() {
1263 $port = $this->current();
1264 $remote_id = $port['remote_id'];
1265
1266 if($this->loop && $remote_id == $this->first)
1267 $this->currentid = false;
1268 else
1269 $this->currentid = $remote_id;
1270
1271 $this->back = !$this->back;
1272
1273 $this->icount++;
1274 }
1275
1276 function valid() {
1277
1278 /* linkcout exceeded */
1279 if($this->icount > $this->linkcount+1)
1280 {
1281 $this->exceed = true;
1282 return false;
1283 }
1284
1285 return $this->currentid;
1286 }
1287
1288 /* for debugging only */
1289 function var_dump_html(&$var, $msg = "") {
1290 echo "<pre>------------------Start Var Dump -------------$msg------------\n";
1291 var_dump($var);
1292 echo "\n---------------------END Var Dump -----------$msg-------------</pre>";
1293 }
1294} // lm_linkchain
1295
1296/*
1297 * from RT database.php fetchPortList()
1298 * with Link table selection
1299 * and multilink changes
1300 */
1301function lm_fetchPortList ($sql_where_clause, $query_params = array(), $linktable = 'Link')
1302{
1303 $query = <<<END
1304SELECT
1305 Port.id,
1306 Port.name,
1307 Port.object_id,
1308 Object.name AS object_name,
1309 Port.l2address,
1310 Port.label,
1311 Port.reservation_comment,
1312 Port.iif_id,
1313 Port.type AS oif_id,
1314 (SELECT PortInnerInterface.iif_name FROM PortInnerInterface WHERE PortInnerInterface.id = Port.iif_id) AS iif_name,
1315 (SELECT PortOuterInterface.oif_name FROM PortOuterInterface WHERE PortOuterInterface.id = Port.type) AS oif_name,
1316
1317 lk.cable AS cableid,
1318 IF(lk.porta = Port.id, pb.id, pa.id) AS remote_id,
1319 IF(lk.porta = Port.id, pb.name, pa.name) AS remote_name,
1320 IF(lk.porta = Port.id, pb.object_id, pa.object_id) AS remote_object_id,
1321 IF(lk.porta = Port.id, ob.name, oa.name) AS remote_object_name,
1322
1323 (SELECT COUNT(*) FROM PortLog WHERE PortLog.port_id = Port.id) AS log_count,
1324 PortLog.user,
1325 UNIX_TIMESTAMP(PortLog.date) as time
1326FROM
1327 Port
1328 INNER JOIN Object ON Port.object_id = Object.id
1329
1330 LEFT JOIN $linktable AS lk ON lk.porta = Port.id or lk.portb = Port.id
1331 LEFT JOIN Port AS pa ON pa.id = lk.porta
1332 LEFT JOIN Object AS oa ON pa.object_id = oa.id
1333 LEFT JOIN Port AS pb ON pb.id = lk.portb
1334 LEFT JOIN Object AS ob ON pb.object_id = ob.id
1335
1336 LEFT JOIN PortLog ON PortLog.id = (SELECT id FROM PortLog WHERE PortLog.port_id = Port.id ORDER BY date DESC LIMIT 1)
1337WHERE
1338 $sql_where_clause
1339END;
1340
1341 $result = usePreparedSelectBlade ($query, $query_params);
1342
1343 $ret = array();
1344 while ($row = $result->fetch (PDO::FETCH_ASSOC))
1345 {
1346 $row['l2address'] = l2addressFromDatabase ($row['l2address']);
1347 $row['linked'] = isset ($row['remote_id']) ? 1 : 0;
1348
1349 // last changed log
1350 $row['last_log'] = array();
1351 if ($row['log_count'])
1352 {
1353 $row['last_log']['user'] = $row['user'];
1354 $row['last_log']['time'] = $row['time'];
1355 }
1356 unset ($row['user']);
1357 unset ($row['time']);
1358
1359 $ret[] = $row;
1360 }
1361 return $ret;
1362} /* lm_fetchPortList */
1363
1364function lm_getPortInfo ($port_id, $back = false)
1365{
1366 $linktable = ($back ? 'LinkBackend' : 'Link');
1367 if($back)
1368 $result = lm_fetchPortList ('Port.id = ?', array ($port_id), $linktable);
1369 else
1370 $result = fetchPortList ('Port.id = ?', array ($port_id));
1371
1372 //return empty ($result) ? NULL : $result[0];
1373 return $result;
1374} /* lm_getPortInfo */
1375
1376/* -------------------------------------------------------------------------- */
1377/* -------------------------------------------------- */
1378
1379function linkmgmt_opHelp() {
1380?>
1381 <table cellspacing=10><tr><th>Help</th><tr>
1382 <tr><td width=150></td><td width=150 style="font-weight:bold;color:<?php echo portlist::CURRENT_OBJECT_BGCOLOR; ?>">Current Object</td></tr>
1383 <tr><td></td><td bgcolor=<?php echo portlist::CURRENT_PORT_BGCOLOR; ?>>[current port]</td></tr>
1384 <tr><td>front link</td><td>[port]<(Object)</td><td>back link</td></tr>
1385 <tr><td>back link</td><td>(Object)>[port]</td><td>front link</td></tr>
1386 <tr><td></td><td><pre>----></pre></td><td>Front link</td></tr>
1387 <tr><td></td><td><pre>====></pre></td><td>Backend link</td></tr>
1388 <tr><td></td><td>Link Symbol</td><td>Create new link</td></tr>
1389 <tr><td></td><td>Cut Symbol</td><td>Delete link</td></tr>
1390
1391 </table>
1392
1393<?php
1394 exit;
1395} /* opHelp */
1396
1397/* -------------------------------------------------- */
1398
1399function linkmgmt_ajax_mapinfo() {
1400
1401 $object_id = NULL;
1402 $port_id = NULL;
1403 $remote_id = NULL;
1404 $linktype = NULL;
1405
1406 if(isset($_REQUEST['object_id']))
1407 $object_id = $_REQUEST['object_id'];
1408
1409 if(isset($_REQUEST['port_id']))
1410 $port_id = $_REQUEST['port_id'];
1411
1412 if(isset($_REQUEST['remote_id']))
1413 $remote_id = $_REQUEST['remote_id'];
1414
1415 if(isset($_REQUEST['linktype']))
1416 $linktype = $_REQUEST['linktype'];
1417
1418 $debug = NULL;
1419 if(isset($_REQUEST['debug']))
1420 $debug['value'] = $_REQUEST['debug'];
1421
1422 $info = array();
1423
1424 echo "<table style=\"font-size:12;\"><tr>";
1425
1426 if($port_id != NULL)
1427 {
1428 $port = new linkmgmt_RTport($port_id);
1429
1430 echo "<td>";
1431 $port->printtable('both');
1432 echo "</td>";
1433
1434 if($debug)
1435 $debug['port'] = &$port;
1436
1437 if($remote_id != NULL)
1438 {
1439
1440 $remote_port = new linkmgmt_RTport($remote_id);
1441
1442 echo "<td><table align=\"center\">";
1443
1444 // TODO cableid
1445 echo "<tr><td><pre>".($linktype == 'back' ? ' ===> ' : ' ---> ')."</pre></td></tr>";
1446
1447 $port->printunlinktr($linktype, $remote_port);
1448
1449 echo "</table></td>";
1450
1451
1452 echo "<td>";
1453 $remote_port->printtable('both');
1454 echo "</td>";
1455
1456 if($debug)
1457 $debug['remote_port'] = &$remote_port;
1458
1459 }
1460 else
1461 $port->printunlinktr();
1462
1463
1464 }
1465 echo "</tr><tr>";
1466
1467 echo "<td>";
1468 $object = linkmgmt_RTport::printobjecttable($object_id);
1469 echo "</td>";
1470
1471 if($debug)
1472 $debug['object'] = &$object;
1473
1474 if($remote_id != NULL)
1475 {
1476
1477 echo "<td></td>"; /* link */
1478 echo "<td>";
1479 $remote_object = linkmgmt_RTport::printobjecttable($remote_port->port['object_id']);
1480 echo "</td>";
1481
1482 if($debug)
1483 $debug['remote_object'] = &$remote_object;
1484 }
1485
1486 echo "</tr></table>";
1487
1488 if($debug)
1489 {
1490 echo "<pre>--- Debug ---";
1491 var_dump($debug);
1492 echo "</pre>";
1493 }
1494
1495 exit;
1496}
1497
1498/* -------------------------------------- */
1499function lm_renderObjectCell ($cell)
1500{
1501 echo "<table class='slbcell vscell'><tr><td rowspan=2 width='5%'>";
1502 printImageHREF ('OBJECT');
1503 echo '</td><td>';
1504 echo mkA ('<strong>' . niftyString ($cell['dname']) . '</strong>', 'object', $cell['id']);
1505 echo '</td></tr><tr><td>';
1506 echo count ($cell['etags']) ? ("<small>" . serializeTags ($cell['etags']) . "</small>") : '&nbsp;';
1507 echo "</td></tr></table>";
1508}
1509/* -------------------------------------- */
1510
1511// TODO replace..
1512class linkmgmt_RTport {
1513
1514 private $port_id = NULL;
1515
1516 public $port = false;
1517
1518 function __construct($port_id) {
1519
1520 $this->port = getPortInfo($port_id);
1521
1522 if($this->port === false)
1523 return;
1524
1525 /* successfully get port info */
1526 $this->port_id = $port_id;
1527
1528 } /* __construct */
1529
1530 function isvalid() {
1531 return ($port_id !== NULL);
1532 }
1533
1534 function getlinks($type = 'front') {
1535 } /* getlinks */
1536
1537 function printtable($linktype = 'front') {
1538
1539 if($this->port_id == NULL)
1540 return;
1541
1542 echo "<table>";
1543
1544 $urlparams = array(
1545 'module' => 'redirect',
1546 'page' => 'object',
1547 'tab' => 'linkmgmt',
1548 'op' => 'map',
1549 'object_id' => $this->port['object_id'],
1550 'port_id' => $this->port_id,
1551 'usemap' => 1,
1552 );
1553
1554 echo '<tr><td><a title="don\'t highlight port" href="?'.http_build_query($urlparams).'">-phl</a></td>';
1555
1556 $urlparams['hl'] = 'p';
1557 echo '<td><a title="highlight port" href="?'.http_build_query($urlparams).'">+phl</a></td></tr>';
1558
1559 $this->_printinforow($this->port,
1560 array(
1561 'id' => 'Port ID',
1562 'name' => 'Port Name',
1563 'oif_name' => 'Port Type',
1564 'l2address' => 'MAC',
1565 'reservation_comment' => 'comment',
1566 )
1567 ); /* printinforow */
1568
1569 $this->printlinktr($linktype);
1570
1571 echo "</table>";
1572 } /* printtable */
1573
1574 function printlinktr($linktype = 'front') {
1575 if($this->port_id === NULL)
1576 return;
1577
1578 $urlparams = array(
1579 'tab' => 'linkmgmt',
1580 'page' => 'object',
1581 'op'=>'PortLinkDialog',
1582 'port'=>$this->port_id,
1583 'object_id'=>$this->port['object_id'],
1584 'linktype' => $linktype,
1585 );
1586
1587 echo "<tr><td align=\"center\"><a href='".
1588 makeHrefProcess($urlparams).
1589 "'>";
1590 printImageHREF ('plug', 'Link this port');
1591 echo "</a></td></tr>";
1592 } /* link */
1593
1594 function printunlinktr($linktype = 'front', $remote_port = NULL) {
1595 if($this->port_id === NULL)
1596 return;
1597
1598 $urlparams = array(
1599 'tab' => 'linkmgmt',
1600 'op'=>'unlinkPort',
1601 'port_id'=>$this->port_id,
1602 'object_id'=>$this->port['object_id'],
1603 'linktype' => $linktype,
1604 );
1605
1606 $confirmmsg = "unlink port ".$this->port['name'];
1607
1608 if($remote_port !== NULL)
1609 {
1610 $urlparams['remote_id'] = $remote_port->port['id'];
1611 $confirmmsg .= ' -> '.$remote_port->port['name'];
1612 }
1613
1614 $confirmmsg .= " ($linktype)"; // TODO cableid
1615
1616 echo "<tr><td align=\"center\"><a href='".makeHrefProcess($urlparams).
1617 "' onclick=\"return confirm('$confirmmsg');\">";
1618 printImageHREF ('cut', 'Unlink this port');
1619 echo "</a></td></tr>";
1620
1621 } /* unlink */
1622
1623 /* TODO move to object class */
1624 static function printobjecttable($object_id = NULL) {
1625
1626 if($object_id === NULL)
1627 return;
1628
1629 $object = spotEntity ('object', $object_id);
1630
1631 if($object === false)
1632 return;
1633
1634 if($object['rack_id'])
1635 {
1636 $rack = spotEntity('rack', $object['rack_id']);
1637
1638 $object['row_name'] = $rack['row_name'];
1639 $object['rack_name'] = $rack['name'];
1640 }
1641
1642 echo "<table><tr><td>";
1643 lm_renderObjectCell($object);
1644 echo "</td></tr><tr><td><table>";
1645
1646 self::_printinforow($object,
1647 array(
1648 'id' => 'ID',
1649 'dname' => 'Name',
1650 'label' => 'Label',
1651 'rack_name' => 'Rack',
1652 'row_name' => 'Row',
1653 )
1654
1655 ); /* printinforow */
1656
1657 $urlparams = array(
1658 'module' => 'redirect',
1659 'page' => 'object',
1660 'tab' => 'linkmgmt',
1661 'op' => 'map',
1662 'object_id' => $object_id,
1663 'usemap' => 1,
1664 );
1665
1666 echo '<tr><td><a title="don\'t highlight object" href="?'.http_build_query($urlparams).'">-ohl</a></td>';
1667
1668 $urlparams['hl'] = 'o';
1669 echo '<td><a title="highlight object" href="?'.http_build_query($urlparams).'">+ohl</a></td></tr>';
1670
1671 echo "</table></td></tr></table>";
1672
1673 return $object;
1674
1675 } /* printobjecttable */
1676
1677 static function _printinforow(&$data, $config) {
1678
1679 foreach($config as $key => $name)
1680 {
1681 if(isset($data[$key]))
1682 {
1683 $value = $data[$key];
1684 if(!empty($value))
1685 echo "<tr><td align=\"right\" nowrap=\"nowrap\" style=\"font-size:10;\">$name:</td><td nowrap=\"nowrap\">$value</td></tr>";
1686 }
1687 }
1688
1689 } /* _printinforow */
1690} /* class RTport */
1691
1692/* -------------------------------------------------- */
1693
1694function linkmgmt_opmap() {
1695
1696 /* display require errors "white screen of death" */
1697 $errorlevel = error_reporting();
1698 error_reporting(E_ALL);
1699
1700 require_once 'Image/GraphViz.php';
1701
1702/*
1703 *
1704 */
1705class lm_Image_GraphViz extends Image_GraphViz {
1706
1707 /* extend renderDotFile with additional output file
1708 */
1709 function renderDotFile($dotfile, $outputfile, $format = 'svg',
1710 $command = null, $outputfile2 = null, $format2 = null)
1711 {
1712 if (!file_exists($dotfile)) {
1713 if ($this->_returnFalseOnError) {
1714 return false;
1715 }
1716 $error = PEAR::raiseError('Could not find dot file');
1717 return $error;
1718 }
1719
1720 $oldmtime = file_exists($outputfile) ? filemtime($outputfile) : 0;
1721
1722 switch ($command) {
1723 case 'dot':
1724 case 'neato':
1725 break;
1726 default:
1727 $command = $this->graph['directed'] ? 'dot' : 'neato';
1728 }
1729 $command_orig = $command;
1730
1731 $command = $this->binPath.(($command == 'dot') ? $this->dotCommand
1732 : $this->neatoCommand);
1733
1734 $command .= ' -T'.escapeshellarg($format)
1735 .' -o'.escapeshellarg($outputfile)
1736 .($format2 !== null && $outputfile2 !== null ? ' -T'.escapeshellarg($format2).' -o'.escapeshellarg($outputfile2) : '')
1737 .' '.escapeshellarg($dotfile)
1738 .' 2>&1';
1739
1740 exec($command, $msg, $return_val);
1741
1742 clearstatcache();
1743 if (file_exists($outputfile) && filemtime($outputfile) > $oldmtime
1744 && $return_val == 0) {
1745 return true;
1746 } elseif ($this->_returnFalseOnError) {
1747 return false;
1748 }
1749 $error = PEAR::raiseError($command_orig.' command failed: '
1750 .implode("\n", $msg));
1751 return $error;
1752 }
1753 // renderDotFile
1754
1755
1756 /*
1757 */
1758 function fetch($format = 'svg', $command = null, $format2 = null, &$data2 = null)
1759 {
1760
1761 $file = $this->saveParsedGraph();
1762 if (!$file || PEAR::isError($file)) {
1763 return $file;
1764 }
1765
1766 $outputfile = $file . '.' . $format;
1767
1768 if($format2 != null && $data2 !== null)
1769 $outputfile2 = $file . '.' . $format2;
1770 else
1771 $outputfile2 = null;
1772
1773 $rendered = $this->renderDotFile($file, $outputfile, $format,
1774 $command, $outputfile2, $format2);
1775 if ($rendered !== true) {
1776 return $rendered;
1777 }
1778
1779 @unlink($file);
1780
1781 if($format2 !== null && $data2 !== null) {
1782 $fp = fopen($outputfile2, 'rb');
1783
1784 if ($fp) {
1785 $data = fread($fp, filesize($outputfile2));
1786 fclose($fp);
1787 @unlink($outputfile2);
1788
1789 $data2 = $data;
1790 } else {
1791 return $error;
1792 }
1793 }
1794
1795
1796 $fp = fopen($outputfile, 'rb');
1797
1798 if (!$fp) {
1799 if ($this->_returnFalseOnError) {
1800 return false;
83b49cf7 1801 }
1802 $error = PEAR::raiseError('Could not read rendered file');
1803 return $error;
1804 }
1805
3badc888 1806 $data = fread($fp, filesize($outputfile));
1807 fclose($fp);
1808 @unlink($outputfile);
1809
1810 return $data;
1811 }
1812 // fetch
1813
1814
1815
1816} /* class lm_Image_GraphViz */
1817
1818 error_reporting($errorlevel);
1819
1820 $object_id = NULL;
1821 $port_id = NULL;
1822 $remote_id = NULL;
1823 $allports = false;
1824 $usemap = false;
1825 $command = NULL;
1826
1827 /* highlight object */
1828 $hl = NULL;
1829 if(isset($_REQUEST['hl']))
1830 {
1831 $hl = $_REQUEST['hl'];
1832 unset($_REQUEST['hl_object_id']);
1833 unset($_REQUEST['hl_port_id']);
1834
1835 if($hl == 'o')
1836 {
1837 unset($_GET['port_id']);
1838 unset($_GET['remote_id']);
1839 }
1840
1841 }
1842
1843 if(!$hl && isset($_REQUEST['hl_object_id']))
1844 {
1845 $hl = 'o';
1846 $object_id = $_REQUEST['hl_object_id'];
1847 $_REQUEST['object_id'] = $object_id;
1848 unset($_REQUEST['hl_object_id']);
1849 unset($_REQUEST['hl_port_id']);
1850 unset($_REQUEST['port_id']);
1851 }
1852
1853 if(isset($_REQUEST['object_id']))
1854 $object_id = $_REQUEST['object_id'];
1855
1856 if(isset($_REQUEST['type']))
1857 {
1858 $type = $_REQUEST['type'];
1859 }
1860 else
1861 $type = 'gif';
1862
1863 /* highlight port */
1864 if(!$hl && isset($_REQUEST['hl_port_id']))
1865 {
1866 $hl = 'p';
1867 $port_id = $_REQUEST['hl_port_id'];
1868 $_REQUEST['port_id'] = $port_id;
1869 unset($_REQUEST['hl_port_id']);
1870 }
1871
1872 if(isset($_REQUEST['allports']))
1873 {
1874 $allports = $_REQUEST['allports'];
1875 }
1876
1877 if(isset($_REQUEST['port_id']))
1878 {
1879 $port_id = $_REQUEST['port_id'];
1880 }
1881
1882 if(isset($_REQUEST['usemap']))
1883 $usemap = $_REQUEST['usemap'];
1884
1885 if($hl == 'p' && $port_id === NULL)
1886 {
1887 unset($_GET['hl']);
1888 unset($_GET['port_id']);
1889 unset($_GET['remote_id']);
1890 }
1891
1892 if($hl == 'o')
1893 unset($_GET['remote_id']);
1894
1895 if(isset($_REQUEST['remote_id']))
1896 $remote_id = $_REQUEST['remote_id'];
1897
1898 /* show all objects */
1899 if(isset($_REQUEST['all']))
1900 {
1901 $object_id = NULL;
1902 $port_id = NULL;
1903 $hl = NULL;
1904 unset($_GET['hl']);
1905 }
1906
1907 if(isset($_REQUEST['cmd']))
1908 $command = $_REQUEST['cmd'];
1909
1910 if(isset($_REQUEST['debug']))
1911 $debug = $_REQUEST['debug'];
1912 else
1913 $debug = False;
1914
1915 if($debug) echo "-- DEBUG --<br>";
1916
1917
1918 switch($type) {
1919 case 'gif':
1920 case 'png':
1921 case 'bmp':
1922 case 'jpeg':
1923 case 'tif':
1924 case 'wbmp':
1925 $ctype = "image/$type";
1926 break;
1927 case 'jpg':
1928 $ctype = "image/jpeg";
1929 break;
1930 case 'svg':
1931 $ctype = 'image/svg+xml';
1932 break;
1933 case 'pdf':
1934 $ctype = 'application/pdf';
1935 break;
1936 case 'cmapx':
1937 $ctype = 'text/plain';
1938 break;
1939 }
1940
1941 $start = microtime(true);
1942 $gvmap = new linkmgmt_gvmap($object_id, $port_id, $allports, $hl, $remote_id);
1943 $stop = microtime(true);
1944
1945 if($debug)
1946 echo "gvmap Time: ".( $stop - $start )."<br>";
1947
1948 if($debug) echo "-- after gvmap --<br>";
1949
1950 if($usemap)
1951 {
1952
1953 if($debug) echo "-- usemap --<br>";
1954
1955 /* add context menu to Ports, Objects, Links, ...
1956 */
1957
1958 echo "<script>
1959 function initcontextmenu() {
1960 var maps = document.getElementsByTagName('map');
1961 for(var i=0;i<maps.length;i++) {
1962 var areas = maps[i].childNodes;
1963
1964 for(j=0;j<areas.length;j++) {
1965 if(areas[j].nodeType == 1)
1966 {
1967 // console.log(areas[j].id);
1968 // attr = document.createAttribute('onmouseover','ahh');
1969 // areas[j].setAttribute(attr);
1970 // areas[j].onmouseover = 'menu(this);';
1971
1972 areas[j].addEventListener('contextmenu',menu,false);
1973 // areas[j].oncontextmenu = 'menu(this, event);';
1974 // console.log(areas[j].oncontextmenu);
1975 }
1976 }
1977
1978 }
1979
1980 };
1981
1982 function menu(event) {
1983
1984 // console.log('Menu');
1985
1986 if(!event)
1987 event = window.event;
1988
1989 var parent = event.target;
1990
1991 // console.log('--' + parent);
1992
1993 var ids = parent.id.split('-');
1994
1995 if(ids[0] == 'graph1')
1996 return false;
1997
1998 var object_id = ids[0];
1999
2000 var url ='?module=ajax&ac=lm_mapinfo&object_id=' + object_id;
2001
2002 // links ='<li><a href=' + object_id + '>Object</a></li>';
2003
2004 if(ids[1] != '')
2005 {
2006 var port_id = ids[1];
2007 url += '&port_id=' + port_id;
2008 // links += '<li><a href=' + port_id + '>Port</a></li>';
2009
2010 if(ids[2] != '')
2011 {
2012 var remote_id = ids[2];
2013
2014 if(ids[3] != '')
2015 {
2016 var linktype = ids[3];
2017 url += '&remote_id=' + remote_id + '&linktype=' + linktype;
2018 // links += '<li><a href=' + port_id + '_' + remote_id + '_' + linktype + '>Unlink</a></li>';
2019 }
2020 }
2021
2022 }
2023
2024
2025 var xmlHttp = new XMLHttpRequest();
2026 xmlHttp.open('GET', url, false);
2027 xmlHttp.send(null);
2028
2029 var infodiv = document.getElementById('info');
2030 infodiv.innerHTML = xmlHttp.responseText;
2031
2032 // linkdiv = document.getElementById('link');
2033 // linkdiv.innerHTML = links;
2034
2035 var menudiv = document.getElementById('menu');
2036 menudiv.style.position = 'absolute';
2037 menudiv.style.top = (event.clientY + document.body.scrollTop) + 'px';
2038 menudiv.style.left = (event.clientX + document.body.scrollLeft) + 'px';
2039 menudiv.style.display = '';
2040
2041 return false;
2042 };
2043
2044 function mousedown(event) {
2045 // console.log('mouse down');
2046
2047 if(!event)
2048 event = window.event;
2049
2050 if(event.button != 2)
2051 return true;
2052
2053 var menudiv = document.getElementById('menu');
2054
2055 menudiv.style.display = 'none';
2056
2057 return false;
2058 };
2059
2060 </script>";
2061
2062 echo "<body oncontextmenu=\"return false\" onmousedown=\"mousedown(event);\" onload=\"initcontextmenu();\">";
2063
2064 echo "<div id=\"menu\" style=\"display:none; background-color:#ffff90\">
2065 <div id=\"info\"></div>
2066 <ul id=\"link\" style=\"list-style-type:none\"></ul>
2067 </div>";
2068
2069 if($debug)
2070 $gvmap->setFalseOnError(False);
2071
2072 $data2 = '';
2073
2074 $start = microtime(true);
2075 $data = $gvmap->fetch($type, $command, 'cmapx', $data2);
2076 $stop = microtime(true);
2077
2078 if($debug)
2079 echo "DOT time: ".( $stop - $start )."<br>";
2080
2081 if($data === false)
2082 echo "ERROR Fetching image data!<br>";
2083
2084 if(PEAR::isError($data))
2085 echo $data->getMessage();
2086
2087 //echo $gvmap->fetch('cmapx', $command);
2088 echo $data2;
2089
2090 if($debug) echo "-- after map gvmap --<br>";
2091
2092 echo "<img src=\"data:$ctype;base64,".
2093 base64_encode($data).
2094 "\" usemap=#map$object_id />";
2095
2096 if($debug)
2097 {
2098 echo "<pre>";
2099 echo $gvmap->export();
2100 echo "</pre>";
2101
2102 echo "<pre>".$gvmap->parse()."</pre>";
2103 }
2104 }
2105 else
2106 {
2107 $gvmap->image($type);
2108 }
2109
2110 exit;
2111
2112} /* linkmgmt_opmap */
2113
2114class cytoscapedata
2115{
2116 public $objects = array();
2117
2118 public $pids = array();
2119
2120 public $parents = array();
2121 public $nodes = array();
2122
2123 public $edges = NULL;
2124
2125 public $debug = null;
2126
2127 function __construct()
2128 {
2129
2130 $this->edges['parents'] = array();
2131 $this->edges['nodes'] = array();
2132 }
2133
2134 function addnode($id, $values = NULL, &$arr = NULL)
2135 {
2136 $data = array( 'id' => $id );
2137
2138 if($values != NULL)
2139 $data = $data + $values;
2140
2141 $node['data'] = $data;
2142
2143 $this->objects[] = array('group' => 'nodes') + $node;
2144
2145 switch($values['type'])
2146 {
2147 case 'port':
2148 $this->nodes[$id] = array('group' => 'nodes') + $node;
2149 break;
2150 case 'object':
2151 case 'container':
2152 $this->parents[$id] = array('group' => 'nodes') + $node;
2153 break;
2154 }
2155
2156 if($arr !== NULL)
2157 $arr[] = array('group' => 'nodes') + $node;
2158 }
2159
2160 function addedge($id, $source, $target, $values = NULL, &$arr = NULL)
2161 {
2162 $data = array(
2163 'id' => $id,
2164 'source' => $source,
2165 'target' => $target
2166 );
2167
2168 if($values != NULL)
2169 $data = $data + $values;
2170
2171 $edge['data'] = $data;
2172
2173 //$this->elements['edges'][] = $edge;
2174
2175 if($arr !== NULL)
2176 {
2177 $arr[$id] = array('group' => 'edges') + $edge;
2178 }
2179 else
2180 $this->objects[] = array('group' => 'edges') + $edge;
2181
2182 //$this->edges[] = array('group' => 'edges') + $edge;
2183 }
2184
2185 function _addobjectnode($object_id, $type = 'object')
2186 {
2187 global $lc_cache;
2188
2189 if(!isset($this->parents["o$object_id"]))
2190 {
2191 $rack = null;
2192 $object = $lc_cache->getobject($object_id, $rack);
2193
2194 $clustertitle = "${object['dname']}";
2195
2196 //has_problems
2197 //if($object['has_problems'] != 'no')
2198
2199 $rack_text = "";
2200 if(!empty($rack['row_name']) || !empty($rack['name']))
2201 {
2202 $rack_text = "${rack['row_name']} / ${rack['name']}";
2203 }
2204
2205 $data = array('label' => $object['name'], 'text' => $rack_text, 'type' => $type, 'has_problems' => $object['has_problems']);
2206
2207 $container_id = $object['container_id'];
2208 if($container_id)
2209 {
2210 $data['parent'] = "o$container_id";
2211 $this->_addobjectnode($container_id, 'container');
2212 }
2213
2214 $this->addnode('o'.$object_id, $data);
2215 }
2216
2217 }
2218
2219 // cytoscape
2220 function addlinkchain($linkchain, $index) {
2221
2222 foreach($linkchain as $id => $port)
2223 {
2224
2225 if(!$linkchain->linked)
2226 continue;
2227
2228 $this->_addobjectnode($port['object_id']);
2229
2230 $text = (isset($port['portip']) ? $port['portip'] : "" );
2231 $nodedata = array('label' => $port['name'], 'parent' => 'o'.$port['object_id'], 'text' => $text, 'type' => 'port', 'index' => $index , 'loop' => ($linkchain->loop ? '1' : '0'));
2232
2233 //$this->addnode('l_'.$port['id'], array( 'label' => $port['name'], 'parent' => 'p'.$port['id'], 'text' => $text ));
2234
2235 if($port['portcount'] > 1)
2236 foreach($port['chains'] as $mlc)
2237 {
2238 $this->addlinkchain($mlc, 0); // TODO index
2239 }
2240
2241 $prevlinktype = ($port['linktype'] == 'front' ? 'back' : 'front');
2242 if($port[$prevlinktype]['portcount'] > 1)
2243 {
2244 foreach($port[$prevlinktype]['chains'] as $mlc)
2245 {
2246 $this->addlinkchain($mlc, 0, false); // TODO index
2247 }
2248 }
83b49cf7 2249
3badc888 2250 if($port['remote_id'])
2251 {
83b49cf7 2252
3badc888 2253 $this->_addobjectnode($port['remote_object_id']);
83b49cf7 2254
3badc888 2255 $linktype = $port['linktype'];
2256 $edgedata = array('label' => $port['cableid'], 'type' => $linktype, 'loop' => ($linkchain->loop ? '1' : '0'));
83b49cf7 2257
3badc888 2258 if($linkchain->loop && $port['remote_id'] == $linkchain->first)
2259 {
2260 $nodedata['loopedge'] = array('group' => 'edges', 'data' => array( 'id' => 'le'.$port['id']."_".$port['remote_id'], 'source' => 'p'.$port['id'], 'target' => 'p'.$port['remote_id']) + $edgedata);
2261 }
2262 else
2263 {
83b49cf7 2264
3badc888 2265 $this->addedge('e'.$port['id']."_".$port['remote_id'], 'p'.$port['id'], 'p'.$port['remote_id'], $edgedata);
2266 $this->addedge('e'.$port['id']."_".$port['remote_id'], 'p'.$port['id'], 'p'.$port['remote_id'], $edgedata, $this->edges['nodes']);
2267 $id1 = $port['object_id'];
2268 if($id1 > $port['remote_object_id'])
2269 {
2270 $id1 = $port['remote_object_id'];
2271 $id2 = $port['object_id'];
2272 }
2273 else
2274 $id2 = $port['remote_object_id'];
fdc74cf0 2275
3badc888 2276 $peid = "pe".$id1."_".$id2;
fdc74cf0 2277
3badc888 2278 if(isset($this->edges['parents'][$peid]))
2279 $this->edges['parents'][$peid]['data']['linkcount']++;
2280 else
2281 $this->addedge($peid, 'o'.$id1, 'o'.$id2, array('type' => $linktype, 'linkcount' => 1), $this->edges['parents']);
2282 }
2283 }
fdc74cf0 2284
3badc888 2285 $this->addnode('p'.$port['id'], $nodedata);
2286 }
2287
2288 if(0)
2289 if($linkchain->first != $linkchain->last )
fdc74cf0 2290 {
3badc888 2291 $first = $linkchain->first;
2292 $last = $linkchain->last;
2293 $this->addedge("l${first}_${last}",'p'.$first, 'p'.$last, array('type' => 'logical', 'label' => "logical"));
fdc74cf0 2294 }
2295
3badc888 2296 //portlist::var_dump_html($this->parents);
fdc74cf0 2297 }
2298
3badc888 2299 function getlinkchains($object_id) {
fdc74cf0 2300
3badc888 2301 $this->objects = array();
2302 $this->parents = array();
2303 $this->nodes = array();
2304 $this->edges['parents'] = array();
2305 $this->edges['nodes'] = array();
fdc74cf0 2306
3badc888 2307 $this->_getlinkchains($object_id);
fdc74cf0 2308 }
fdc74cf0 2309
3badc888 2310 function getelements()
fdc74cf0 2311 {
3badc888 2312 //lm_linkchain::var_dump_html($this);
2313 return array('parents' => array_values($this->parents),
2314 'nodes' => array_values($this->nodes),
2315 'edges' => array(
2316 'parents' => array_values($this->edges['parents']),
2317 'nodes' => array_values($this->edges['nodes'])
2318 ),
2319 'debug' => $this->debug
2320 );
fdc74cf0 2321
fdc74cf0 2322 }
2323
3badc888 2324 function gettest()
fdc74cf0 2325 {
3badc888 2326 return array_merge(array_values($this->parents), array_values($this->edges['parents']));
2327 //return array_merge(array_values($this->parents), array_values($this->edges['parents']), array_values($this->nodes), array_values($this->edges['nodes']));
fdc74cf0 2328 }
2329
3badc888 2330 function _getlinkchains($object_id) {
fdc74cf0 2331
fdc74cf0 2332
3badc888 2333 // container
2334 // $object = spotEntity('object', $object_id);
2335 $object['ports'] = getObjectPortsAndLinks ($object_id);
fdc74cf0 2336
3badc888 2337 $i = 0;
2338 foreach($object['ports'] as $key => $port)
2339 {
fdc74cf0 2340
3badc888 2341 if(isset($this->pids[$port['id']]))
2342 continue;
2343
2344 $i++;
2345 $lc = new lm_linkchain($port['id']);
2346
2347 $this->pids += $lc->pids;
2348
2349 $this->addlinkchain($lc, $i);
2350
2351 }
2352
2353 $children = getEntityRelatives ('children', 'object', $object_id);
2354
2355 foreach($children as $child)
2356 $this->_getlinkchains($child['entity_id']);
2357 }
2358
2359 function allobjects()
fdc74cf0 2360 {
3badc888 2361
2362 $this->objects = array();
2363 $this->parents = array();
2364 $this->nodes = array();
2365 $this->edges['parents'] = array();
2366 $this->edges['nodes'] = array();
2367
2368 $objects = listCells('object');
2369
2370 $i = 0;
2371 foreach($objects as $object)
2372 {
2373 //echo $object['id']."<br>";
2374 $this->_getlinkchains($object['id']);
2375 $i++;
2376 if($i > 20 ) break;
2377 }
fdc74cf0 2378 }
3badc888 2379}
fdc74cf0 2380
3badc888 2381function linkmgmt_cytoscapemap() {
fdc74cf0 2382
fdc74cf0 2383
3badc888 2384 $object_id = $_GET['object_id'];
fdc74cf0 2385
3badc888 2386 if(isset($_GET['json']))
2387 {
2388 ob_start();
2389 $data = new cytoscapedata();
2390 $data->getlinkchains($object_id);
2391 //$data->allobjects(); // ugly graph;
2392 //echo json_encode($data->objects);
fdc74cf0 2393
3badc888 2394 if(ob_get_length())
2395 $data->debug = ob_get_contents();
fdc74cf0 2396
3badc888 2397 ob_end_clean();
2398
2399 echo json_encode($data->getelements());
fdc74cf0 2400
3badc888 2401 exit;
fdc74cf0 2402 }
2403
3badc888 2404 echo (<<<HTMLEND
2405<!DOCTYPE html>
2406<html>
2407<head>
2408<style>
2409body {
2410 font: 14px helvetica neue, helvetica, arial, sans-serif;
2411}
fdc74cf0 2412
3badc888 2413#cy {
2414 height: 100%;
2415 width: 100%;
2416 position: absolute;
2417 left: 0;
2418 top: 0;
2419}
2420</style>
2421<meta charset=utf-8 />
2422<meta name="viewport" content="user-scalable=no, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, minimal-ui">
2423<title>Compound nodes</title>
2424<!--<script src="js/jquery-1.4.4.min.js"></script>-->
2425
383230c5 2426<script src="?module=chrome&uri=linkmgmt/jquery-1.11.3.min.js"></script>
2427<script src="?module=chrome&uri=linkmgmt/cytoscape.min.js"></script>
2428<script src="?module=chrome&uri=linkmgmt/dagre.min.js"></script>
2429<script src="?module=chrome&uri=linkmgmt/cytoscape-dagre.js"></script>
2430<link rel="stylesheet" type="text/css" href="?module=chrome&uri=linkmgmt/jquery.qtip.min.css">
2431<script src="?module=chrome&uri=linkmgmt/jquery.qtip.min.js"></script>
2432<script src="?module=chrome&uri=linkmgmt/cytoscape-qtip.js"></script>
3badc888 2433
383230c5 2434<!--<script src="?module=chrome&uri=linkmgmt/cytoscape-css-renderer_mod.js"></script>-->
2435<!--<script src="?module=chrome&uri=linkmgmt/cytoscape.js-navigator.js_mod"></script>-->
3badc888 2436<script>
2437var cy = null;
2438var cy2 = null;
2439var layout = null;
2440var data = null;
2441
2442$(function(){ // on dom ready
2443 var cystyle = [
2444 {
2445 selector: 'node',
2446 css: {
2447 'content': 'data(id)',
2448 'text-wrap': 'wrap'
2449 },
2450 style: {
2451 'background-color': '#666',
2452 'label': 'data(label)',
2453 'width': 'label',
2454 'min-zoomed-font-size' : 8,
2455 'text-valign': 'center',
2456 'text-halign': 'center',
2457 'text-wrap': 'wrap',
2458 'shape': function(ele) {
2459 if(ele.data('type') != 'port')
2460 return 'rectangle';
2461 else
2462 return 'ellipse';
2463 },
fdc74cf0 2464
3badc888 2465 }
2466 },
2467 {
2468 selector: '\$node > node',
2469 css: {
2470 'padding-top': '10px',
2471 'padding-left': '10px',
2472 'padding-bottom': '10px',
2473 'padding-right': '10px',
2474 'text-valign': 'top',
2475 'text-halign': 'center',
2476 'background-color': '#bbb',
2477 'min-zoomed-font-size' : 6,
2478 }
2479 },
2480 {
2481 selector: 'edge',
2482 css: {
2483 'target-arrow-shape': 'triangle',
2484 'line-color': function(ele){
2485 if(ele.data('type') == 'front')
2486 return 'black';
2487 else
2488 return 'grey';
2489 },
2490 'line-style': function(ele){
2491 if(ele.data('type') == 'front')
2492 return 'solid';
2493 else
2494 return 'dashed';
2495 },
2496 'width': function(ele){
2497 var ret = 1;
2498 if(ele.data('type') == 'front')
2499 ret = 3;
2500 else
2501 ret = 5;
fdc74cf0 2502
3badc888 2503 if(1)
2504 if(ele.data('linkcount'))
2505 {
2506 ret = (ele.data('linkcount') * ret);
2507 }
fdc74cf0 2508
3badc888 2509 //console.log(ele.data('id') + ret);
2510 return ret;
2511 },
2512// 'curve-style': 'segments',
2513 'font-size': '8',
2514 'min-zoomed-font-size' : 8,
2515 'label': 'data(label)',
2516 'edge-text-rotation': 'autorotate',
2517 'source-arrow-shape': 'none',
2518 'target-arrow-shape': 'none'
2519 }
2520 },
2521 {
2522 selector: '.logical',
2523 css: {
2524 'line-color': '#0000ff',
2525 'width': 5,
2526 'curve-style': 'segments',
2527 'z-index': 0
2528 }
2529 },
2530 {
2531 selector: ':selected',
2532 css: {
2533 'background-color': 'black',
2534 'line-color': 'black',
2535 'target-arrow-color': 'black',
2536 'source-arrow-color': 'black'
2537 }
2538 },
2539 {
2540 selector: '.highlighted',
2541 css: {
2542 'line-color': '#ff0000',
2543 'background-color': '#ff0000'
2544 }
2545 },
2546 {
2547 selector: '.clhighlighted',
2548 css: {
2549 'line-color': '#00ff00',
2550 'background-color': '#00ff00'
2551 }
2552 }
2553 ];
fdc74cf0 2554
3badc888 2555var cylayout = { name: 'dagre', nodeSep: 3, ready: layoutready, stop: layoutstop };
fdc74cf0 2556
3badc888 2557function highlight(evt) {
fdc74cf0 2558
3badc888 2559 //cy = evt.cy;
fdc74cf0 2560
3badc888 2561 var hlclass = evt.data.hlclass;
2562 var ele = evt.cyTarget;
fdc74cf0 2563
3badc888 2564 if(!ele.data)
2565 return;
fdc74cf0 2566
3badc888 2567 if(ele.data('source'))
2568 ele = cy.$( '#' + ele.data('source'));
fdc74cf0 2569
3badc888 2570 var id = ele.data('id');
fdc74cf0 2571
3badc888 2572 if(ele.isParent())
2573 {
2574 // var childs = cy.$('#' + id).children()
2575 // childs.layout({name:'grid', cols: 2, condense: true});
2576 return;
2577 }
fdc74cf0 2578
fdc74cf0 2579
3badc888 2580// console.log('Event ' + hlclass + ' ' + id );
fdc74cf0 2581
3badc888 2582 // remove existing highlights
2583 cy.$('.' + hlclass).removeClass(hlclass);
fdc74cf0 2584
3badc888 2585 var hleles = ele.closedNeighborhood();
fdc74cf0 2586
3badc888 2587 var hlcount = hleles.length;
fdc74cf0 2588
3badc888 2589 // max 100
2590 for(i=0;i<100;i++)
2591 {
2592 hleles = hleles.closedNeighborhood();
fdc74cf0 2593
3badc888 2594 if(hlcount == hleles.length)
2595 break;
fdc74cf0 2596
3badc888 2597 hlcount = hleles.length;
fdc74cf0 2598
3badc888 2599 }
2600 //console.log('End Loop ' + i );
2601 hleles.addClass(hlclass);
fdc74cf0 2602
3badc888 2603// console.log('Event Type: ' + evt.originalEvent.type)
2604// console.log('Event Type: ' + evt.type)
fdc74cf0 2605
3badc888 2606 if(evt.type != 'click')
2607 return;
fdc74cf0 2608
3badc888 2609 var hleles2 = hleles.clone();
2610 hleles2 = hleles2.add(hleles.parents().clone());
fdc74cf0 2611
3badc888 2612 //var cy2 = evt.data.cy2;
fdc74cf0 2613
3badc888 2614 //var ret = evt.data.ret;
fdc74cf0 2615
3badc888 2616 //var j = ret.parents.concat(ret.nodes).concat(ret.edges.nodes);
fdc74cf0 2617
3badc888 2618 cy2.remove(cy2.elements());
2619 cy2.add(hleles2);
2620 //cy2.add(j);
2621 cy2.layout({name: 'dagre', rankDir: 'LR', ready: layoutready});
2622}
fdc74cf0 2623
3badc888 2624function cytoscapeswitch(evt)
2625{
2626 var b = evt.target;
fdc74cf0 2627
3badc888 2628 var j = null;
2629 if(b.value == "1")
2630 {
2631 j = data.parents.concat(data.edges.parents);
2632 b.value = "0";
2633 b.innerHTML = "Ports";
2634 }
2635 else
2636 {
2637 j = data.parents.concat(data.nodes).concat(data.edges.nodes);
2638 b.value = "1";
2639 b.innerHTML = "Objects";
2640 }
fdc74cf0 2641
3badc888 2642 //layout.stop();
2643 cy.remove(cy.elements());
fdc74cf0 2644
3badc888 2645 cy.add(j);
fdc74cf0 2646
3badc888 2647 cy.layout(cylayout);
2648 //layout.run();
2649}
fdc74cf0 2650
3badc888 2651$.ajax({
2652 type: "GET",
2653 url: "{$_SERVER['PHP_SELF']}",
2654 data: { module: 'redirect',
2655 page: 'object',
2656 tab: 'linkmgmt',
2657 object_id: $object_id,
2658 op: 'cytoscapemap',
2659 json: 'json'
2660 },
2661 dataTye: 'json',
2662 error: function(){ alert("Error loading"); },
2663 success: function(jdata) {
2664
2665 data = JSON.parse(jdata);
2666
2667 if(data.debug)
2668 $('#debug').html(data.debug);
2669
2670 //j = data.parents.concat(data.edges.parents);
2671 j = data.parents.concat(data.nodes).concat(data.edges.nodes);
2672
2673 if(j.length == 0)
2674 {
2675 alert("No Links to display. Closing Window");
2676 window.close();
2677 return;
2678 }
fdc74cf0 2679
3badc888 2680 cy2 = cytoscape({
2681 container: document.getElementById('cy2'),
2682 //renderer: { name: 'css' },
2683
2684 boxSelectionEnabled: false,
2685 autounselectify: true,
2686 style: cystyle,
2687 wheelSensitivity: 0.1,
2688 });
2689 cy2.style().selector('node').style('label', function(node) { return node.data('label') + '\\n' + node.data('text'); });
2690
2691 cystyle.push({
2692 selector: '.loopedge',
2693 css: {
2694 'curve-style': 'segments',
2695 }
2696 });
2697
2698 cy = cytoscape({
2699 container: document.getElementById('cy'),
2700
2701 boxSelectionEnabled: false,
2702 autounselectify: true,
2703 style: cystyle,
2704 wheelSensitivity: 0.1,
2705 elements: j,
2706 layout: cylayout,
2707 });
2708
2709 cy.on('mouseover', { hlclass: 'highlighted' }, highlight );
2710 cy.on('click', { hlclass: 'clhighlighted' }, highlight );
2711
2712 $('#switch').click(cytoscapeswitch);
2713
2714 /*
2715 TODO: node ranking
2716 */
2717
2718 if(0)
2719 cy.layout({
2720 name: 'dagre',
2721 /*
2722 nodeSep: 5,
2723 rankDir: 'TB',
2724 */
2725 //edgeSep: 10,
2726 /*
2727 edgeWeight: function(edge) {
2728 if(edge.data('type') == 'front')
2729 return 10;
2730 else
2731 return 1;
2732
2733 },
2734 */
2735 ready: layoutready,
2736 stop: layoutstop
2737 });
2738
2739 if(1)
2740 cy.$(':child').qtip({
2741
2742 content: function() {
2743
2744 return this.id() + '<br>'
2745 + 'Index: ' + this.data('index') + '<br>'
2746 + 'Name: ' + this.data('label') + '<br>'
2747 + 'Text: ' + this.data('text');
2748 },
2749 position: {
2750 my: 'top center',
2751 at: 'bottom center'
2752 },
2753 style: {
2754 classes: 'qtip-bootstrap',
2755 tip: {
2756 width: 16,
2757 height: 8
2758 },
2759 }
2760 }); // qtip
2761 } // success function
2762 });
2763
2764
2765}); // on dom ready
2766
2767function layoutready(evt) {
2768 var _cy = evt.cy;
fdc74cf0 2769
3badc888 2770 // highlight current object
2771 var object = _cy.$('#o$object_id');
2772 if(object.data('has_problems') == 'no')
2773 object.style('background-color','#ffcccc');
fdc74cf0 2774
3badc888 2775 // highlight object with problems
2776 _cy.$('node[type = "object"][has_problems != "no"]').style('background-color','#ff0000');
de3d42dc 2777
3badc888 2778 var e = _cy.$('node[loop = "1"]').style('background-color','#ff6666');
83b49cf7 2779
3badc888 2780// console.log(e[0].data('loop'));
de3d42dc 2781
3badc888 2782// cy.add({group: 'edges', data: {id:'l691_2991', source: 'p691', target: 'p2991', label: 'test'}, classes: 'logical'});
de3d42dc 2783
3badc888 2784}
fdc74cf0 2785
3badc888 2786function layoutstop(evt) {
2787 var _cy = evt.cy;
2788// cy.elements().locked = true;
2789// cy.add({group: 'nodes', data: {id:'l2493', parent:'p2943', label: 'test'}});
fdc74cf0 2790
fdc74cf0 2791
3badc888 2792 var les = _cy.$('[loopedge]');
fdc74cf0 2793
3badc888 2794 if(les)
fdc74cf0 2795 {
3badc888 2796 _cy.batch( function() {
2797 les.each(function(i, ele) {
2798 var le = ele.data('loopedge');
2799 var edge = _cy.add(le);
2800 edge.addClass('loopedge');
2801 //edge.style('line-color', '#ffffff'); // TypeError text-transform undefined
2802 });
2803 });
2804 _cy.$('edge[loop = "1"]').style('line-color','#ff6666');
fdc74cf0 2805 }
3badc888 2806}
2807</script>
2808</head>
2809<body>
2810<div id="cy" style="position: absolute; height: 80%; width: 100%; left: 0; top: 20%;"></div>
2811<div id="cy2" style="position: absolute; height: 20%; width: 100%; left: 0; top: 0%;"></div>
2812<div id="debug"></div>
2813<button type="button" id="switch" style="position: absolute;" value="1">Object</button>
2814</body>
2815</html>
2816HTMLEND
2817); // echo
fdc74cf0 2818 exit;
3badc888 2819}
fdc74cf0 2820
2821/* ------------------------------------- */
2822class linkmgmt_gvmap {
2823
2824 private $object_id = NULL;
2825 private $port_id = NULL;
2826 private $remote_id = NULL;
3badc888 2827 private $hl = NULL;
fdc74cf0 2828
2829 private $gv = NULL;
2830
2831 private $ports = array();
2832
2833 private $allports = false;
2834 private $back = NULL;
2835
adc1e20b 2836 private $alpha = 'ff';
fdc74cf0 2837
2838 private $errorlevel = NULL;
2839
3badc888 2840 public $data = NULL;
2841
2842 private $pids = array();
2843
2844 function addlinkchainsobject($object_id)
2845 {
2846
2847 $object['ports'] = getObjectPortsAndLinks ($object_id);
2848
2849 if(empty($object['ports']))
2850 {
2851
2852 $hl = false;
2853 $alpha = $this->alpha;
2854 if($this->hl == 'o' && $this->object_id == $object_id)
2855 {
2856 $hl = true;
2857 $this->alpha = 'ff';
2858 }
2859
2860 $this->_addCluster($object_id, $hl, empty($object['ports']));
2861
2862 $this->alpha = $alpha;
2863 return;
2864 }
2865
2866 $i = 0;
2867 foreach($object['ports'] as $key => $port)
2868 {
2869
2870 if(isset($this->pids[$port['id']]))
2871 continue;
2872
2873 $i++;
2874 $lc = new lm_linkchain($port['id']);
2875
2876 $this->pids += $lc->pids;
2877
2878 if($this->allports ||($lc->linkcount > 0))
2879 $this->addlinkchain($lc, $i);
2880 }
2881
2882 }
2883
fdc74cf0 2884 function __construct($object_id = NULL, $port_id = NULL, $allports = false, $hl = NULL, $remote_id = NULL) {
2885 $this->allports = $allports;
2886
4eeb9282 2887 $this->object_id = $object_id;
2888 $this->port_id = $port_id;
2889 $this->remote_id = $remote_id;
3badc888 2890 $this->hl = $hl;
fdc74cf0 2891
2892 $hllabel = "";
2893
2894 /* suppress strict standards warnings for Image_GraphViz and PHP 5.4.0
2895 * output would corrupt image data
2896 */
2897 $this->errorlevel = error_reporting();
857ba778 2898 error_reporting($this->errorlevel & ~E_STRICT);
fdc74cf0 2899
2900 $graphattr = array(
3badc888 2901 'rankdir' => 'LR',
fdc74cf0 2902 // 'ranksep' => '0',
2903 'nodesep' => '0',
2904 // 'overlay' => false,
2905 );
2906
2907 unset($_GET['module']);
2908
2909 $_GET['all'] = 1;
2910
2dbca6fb 2911 $graphattr['URL'] = $this->_makeHrefProcess($_GET);
fdc74cf0 2912
2913 unset($_GET['all']);
2914
3badc888 2915 switch($hl)
2916 {
2917 case 'o':
2918 case 'p':
2919 $this->alpha = '30';
2920 break;
2921 }
2922
83b49cf7 2923 //$this->gv = new Image_GraphViz(true, $graphattr, "map".$object_id);
2924 $this->gv = new lm_Image_GraphViz(true, $graphattr, "map".$object_id);
fdc74cf0 2925
3badc888 2926 /* --------------------------- */
fdc74cf0 2927 if($object_id === NULL)
2928 {
4eeb9282 2929 /* all objects ! */
fdc74cf0 2930 unset($_GET['all']);
2931 $_GET['hl'] = 'o';
2932
2933 $this->gv->addAttributes(array(
2934 'label' => 'Showing all objects'.$hllabel,
2935 'labelloc' => 't',
2936 )
2937 );
2938
2939 $objects = listCells('object');
2940
2941 foreach($objects as $obj)
3badc888 2942 //$this->addlinkchainsobject($obj['id']); // longer runtimes !!
2943 $this->_add($this->gv, $obj['id'], NULL); // for all still faster and nicer looking graph
4eeb9282 2944
2945 return;
fdc74cf0 2946 }
2947 else
2948 {
2949 $object = spotEntity ('object', $object_id);
2950
2951 $this->gv->addAttributes(array(
2952 'label' => "Graph for ${object['dname']}$hllabel",
2953 'labelloc' => 't',
2954 )
2955 );
2956
3badc888 2957 $this->addlinkchainsobject($object_id);
2958 //$this->_add($this->gv, $object_id, $port_id);
fdc74cf0 2959
2960 $children = getEntityRelatives ('children', 'object', $object_id); //'entity_id'
2961
2962 foreach($children as $child)
3badc888 2963 $this->addlinkchainsobject($child['entity_id']);
2964 // $this->_add($this->gv, $child['entity_id'], NULL);
fdc74cf0 2965 }
2966
4eeb9282 2967 /* add hl label */
2968 $this->gv->addAttributes(array(
2969 'label' => $this->gv->graph['attributes']['label'].$hllabel,
2970 ));
2971
fdc74cf0 2972 // portlist::var_dump_html($this->gv);
3badc888 2973// portlist::var_dump_html($this->data);
2974
2975// echo json_encode($this->data);
fdc74cf0 2976
83b49cf7 2977 // $this->gv->saveParsedGraph('/tmp/graph.txt');
fdc74cf0 2978 // error_reporting( E_ALL ^ E_NOTICE);
2979 } /* __construct */
2980
2981 function __destruct() {
2982 error_reporting($this->errorlevel);
2983 }
2984
3badc888 2985 function _addCluster($object_id, $hl = false, $adddummy = false)
2986 {
2987 global $lc_cache;
2988
2989 $cluster_id = "c".$object_id;
2990
2991 if(
2992 !isset($this->gv->graph['clusters'][$cluster_id]) &&
2993 !isset($this->gv->graph['subgraphs'][$cluster_id])
2994 || $hl
2995 ) {
2996 $rack = null;
2997 $object = $lc_cache->getobject($object_id, $rack);
2998
2999 // $object['attr'] = getAttrValues($object_id);
3000
3001 $clusterattr = array();
3002
3003 $this->_getcolor('cluster', 'default', $this->alpha, $clusterattr, 'color');
3004 $this->_getcolor('cluster', 'default', $this->alpha, $clusterattr, 'fontcolor');
3005
3006 if($this->object_id == $object_id)
3007 {
3008 $clusterattr['rank'] = 'source';
3009
3010 $this->_getcolor('cluster', 'current', $this->alpha, $clusterattr, 'color');
3011 $this->_getcolor('cluster', 'current', $this->alpha, $clusterattr, 'fontcolor');
3012 }
3013
3014 $clustertitle = htmlspecialchars($object['dname']);
3015 $clusterattr['tooltip'] = $clustertitle;
3016
3017 unset($_GET['module']); // makeHrefProcess adds this
3018 unset($_GET['port_id']);
3019 unset($_GET['remote_id']);
3020 $_GET['object_id'] = $object_id;
3021 //$_GET['hl'] = 'o';
3022
3023 $clusterattr['URL'] = $this->_makeHrefProcess($_GET);
3024
3025 //has_problems
3026 if($object['has_problems'] != 'no')
3027 {
3028 $clusterattr['style'] = 'filled';
3029 $this->_getcolor('cluster', 'problem', $this->alpha, $clusterattr, 'fillcolor');
3030 }
3031
3032 if(!empty($object['container_name']))
3033 $clustertitle .= "<BR/>(${object['container_name']})";
3034
3035 if(!empty($rack['row_name']) || !empty($rack['name']))
3036 $clustertitle .= "<BR/><FONT point-size=\"10\">{$rack['row_name']} / {$rack['name']}</FONT>";
3037
3038 $embedin = $object['container_id'];
3039 if(empty($embedin))
3040 $embedin = 'default';
3041 else
3042 {
3043 $embedin = "c$embedin"; /* see cluster_id */
3044
3045 // TODO
3046 /* add container / cluster if not already exists */
3047 $this->addlinkchainsobject($object['container_id']);
3048 }
3049
3050 $clusterattr['id'] = "$object_id----"; /* used for js context menu */
3051
3052 $this->gv->addCluster($cluster_id, $clustertitle, $clusterattr, $embedin);
3053
3054 /* needed because of gv_image empty cluster bug (invalid foreach argument) */
3055 if($adddummy)
3056 $this->gv->addNode("dummy$cluster_id", array(
3057 // 'label' =>'No Ports found/connected',
3058 'label' =>'',
3059 'fontsize' => 0,
3060 'size' => 0,
3061 'width' => 0,
3062 'height' => 0,
3063 'shape' => 'point',
3064 'style' => 'invis',
3065 ), $cluster_id);
3066
3067
3068 }
3069 } // _addCluster
3070
3071 function _addEdge($port, $linkchain, $loopedge = false)
3072 {
3073 global $lm_multilink_port_types;
3074 if(
3075 !isset($this->gv->graph['edgesFrom'][$port['id']][$port['remote_id']]) &&
3076 !isset($this->gv->graph['edgesFrom'][$port['remote_id']][$port['id']])
3077 || $loopedge
3078 ) {
3079 $remote_id = $port['remote_id'];
3080
3081 $linktype = $port['linktype'];
3082
3083 $edgetooltip = $port['object_name'].':'.$port['name'].
3084 ' - '.$port['cableid'].' -> '.
3085 $port['remote_name'].':'.$port['remote_object_name'];
3086
3087 $edgeattr = array(
3088 'fontsize' => 8,
3089 'label' => htmlspecialchars($port['cableid']),
3090 'tooltip' => $edgetooltip,
3091 'sametail' => $linktype,
3092 'samehead' => $linktype,
3093 'arrowhead' => 'none',
3094 'arrowtail' => 'none',
3095 );
3096
3097 $this->_getcolor('edge', ($linkchain->loop ? 'loop' : 'default'), $this->alpha, $edgeattr, 'color');
3098 $this->_getcolor('edge', 'default', $this->alpha, $edgeattr, 'fontcolor');
3099
3100 if($linktype == 'back' )
3101 {
3102 $edgeattr['style'] = 'dashed';
3103
3104 /* multilink ports */
3105 if(in_array($port['oif_id'], $lm_multilink_port_types))
3106 {
3107 $edgeattr['dir'] = 'both';
3108 $edgeattr['arrowtail'] = 'dot';
3109 }
3110
3111 if(in_array($linkchain->ports[$remote_id]['oif_id'], $lm_multilink_port_types))
3112 {
3113 $edgeattr['dir'] = 'both';
3114 $edgeattr['arrowhead'] = 'dot';
3115 }
3116 }
3117
3118 if(
3119 ($port['id'] == $this->port_id && $port['remote_id'] == $this->remote_id) ||
3120 ($port['id'] == $this->remote_id && $port['remote_id'] == $this->port_id)
3121 )
3122 {
3123 $this->_getcolor('edge', 'highlight', 'ff', $edgeattr, 'color');
3124 $edgeattr['penwidth'] = 2; /* bold */
3125 }
3126
3127 unset($_GET['module']);
3128 $_GET['object_id'] = $port['object_id'];
3129 $_GET['port_id'] = $port['id'];
3130 $_GET['remote_id'] = $port['remote_id'];
3131
3132 $edgeattr['URL'] = $this->_makeHrefProcess($_GET);
3133
3134 $edgeattr['id'] = $port['object_id']."-".$port['id']."-".$port['remote_id']."-".$linktype; /* for js context menu */
3135
3136 if($loopedge)
3137 {
3138 $edgeattr = array_merge($edgeattr, array(
3139 'sametail' => 'loop',
3140 'samehead' => 'loop',
3141 'dir' => 'both',
3142 'arrowhead' => 'invodot',
3143 'arrowtail' => 'invodot',
3144 ));
3145 }
3146
3147 $this->gv->addEdge(array($port['id'] => $port['remote_id']),
3148 $edgeattr,
3149 array(
3150 $port['id'] => $linktype,
3151 $port['remote_id'] => $linktype,
3152 )
3153 );
3154
3155 }
3156 } // _addEdge
3157
3158 function addlinkchain($linkchain, $index)
3159 {
3160 global $lm_multilink_port_types;
3161
3162 $hl = false;
3163 $alpha = $this->alpha;
3164 if(
3165 ($this->hl == 'p' && $linkchain->hasport_id($this->port_id))
3166 || ($this->hl == 'o' && $linkchain->hasobject_id($this->object_id))
3167 )
3168 {
3169 $hl = true;
3170 $this->alpha = 'ff';
3171 }
3172
3173 $remote_id = null;
3174 foreach($linkchain as $id => $port)
3175 {
3176 $this->_addCluster($port['object_id'], $hl);
3177
3178 $nodelabel = htmlspecialchars("${port['name']}");
3179 $text = $nodelabel;
3180
3181 if($port['iif_id'] != '1' )
3182 {
3183 $nodelabel .= "<BR/><FONT POINT-SIZE=\"8\">${port['iif_name']}</FONT>";
3184 $text .= "\n".$port['iif_name'];
3185 }
3186
3187 $nodelabel .= "<BR/><FONT POINT-SIZE=\"8\">${port['oif_name']}</FONT>";
3188 $text .= "\n".$port['oif_name'];
3189
3190 // add ip address
3191 if(isset($port['portip']))
3192 $nodelabel .= "<BR/><FONT POINT-SIZE=\"8\">".$port['portip']."</FONT>";
3193
3194 $nodeattr = array(
3195 'label' => $nodelabel,
3196 );
3197
3198 $this->_getcolor('port', ($linkchain->loop ? 'loop' : 'default'),$this->alpha, $nodeattr, 'fontcolor');
3199 $this->_getcolor('oif_id', $port['oif_id'],$this->alpha, $nodeattr, 'color');
3200
3201 if($this->port_id == $port['id']) {
3202 $nodeattr['style'] = 'filled';
3203 $nodeattr['fillcolor'] = $this->_getcolor('port', 'current', $this->alpha);
3204 }
3205
3206 if($this->remote_id == $port['id']) {
3207 $nodeattr['style'] = 'filled';
3208 $nodeattr['fillcolor'] = $this->_getcolor('port', 'remote', $this->alpha);
3209 }
3210
3211 $nodeattr['tooltip'] = htmlspecialchars("${port['name']}");
3212
3213 unset($_GET['module']);
3214 unset($_GET['remote_id']);
3215 $_GET['object_id'] = $port['object_id'];
3216 $_GET['port_id'] = $port['id'];
3217 $_GET['hl'] = 'p';
3218
3219 $nodeattr['URL'] = $this->_makeHrefProcess($_GET);
3220 $nodeattr['id'] = "${port['object_id']}-${port['id']}--"; /* for js context menu */
3221
3222 $this->gv->addNode($port['id'],
3223 $nodeattr,
3224 "c${port['object_id']}"); /* see cluster_id */
3225
3226 $remote_id = $port['remote_id'];
3227
3228 if($port['portcount'] > 1)
3229 foreach($port['chains'] as $mlc)
3230 {
3231 $this->addlinkchain($mlc, 0); // TODO index
3232 }
3233
3234 $prevlinktype = ($port['linktype'] == 'front' ? 'back' : 'front');
3235 if($port[$prevlinktype]['portcount'] > 1)
3236 {
3237 foreach($port[$prevlinktype]['chains'] as $mlc)
3238 {
3239 $this->addlinkchain($mlc, 0, false); // TODO index
3240 }
3241 }
3242
3243 if($remote_id)
3244 $this->_addEdge($port, $linkchain);
3245
3246 } //foreach
3247
3248 if($linkchain->loop && $remote_id)
3249 {
3250 // TODO separate loop link
3251 // add loop edge
3252 $this->_addEdge($port, $linkchain, true);
3253 }
3254
3255 // reset alpha to start value
3256 $this->alpha = $alpha;
3257 }
3258
de3d42dc 3259 function setFalseOnError($newvalue)
3260 {
3261 $this->gv->_returnFalseOnError = $newvalue;
3262 }
3263
2dbca6fb 3264 function _makeHrefProcess($array)
3265 {
3266 return str_replace('&','&amp;',makeHrefProcess($array));
3267 }
3268
fdc74cf0 3269 // !!!recursiv !!!
3270 function _add($gv, $object_id, $port_id = NULL) {
3271 global $lm_multilink_port_types;
3272
4eeb9282 3273 if($port_id !== NULL) {
3274 if(isset($this->ports[$port_id])) {
fdc74cf0 3275 return;
4eeb9282 3276 }
fdc74cf0 3277 }
3278
2d257b3a 3279 if($this->back != 'front' || $port_id === NULL || $this->allports)
3280 $front = $this->_getObjectPortsAndLinks($object_id, 'front', $port_id, $this->allports);
3281 else
3282 $front = array();
3283
3284 if($this->back != 'back' || $port_id === NULL || $this->allports)
3285 $backend = $this->_getObjectPortsAndLinks($object_id, 'back', $port_id, $this->allports);
3286 else
3287 $backend = array();
3288
3289 $ports = array_merge($front,$backend);
3290
630a86c8 3291 /* used only for Graphviz ...
3292 * !! numeric ids cause Image_Graphviz problems on nested clusters !!
3293 */
3294 $cluster_id = "c$object_id";
3295
2d257b3a 3296 if(empty($ports))
3297 {
3298 /* needed because of gv_image empty cluster bug (invalid foreach argument) */
da6d05d0 3299 $gv->addNode("dummy$cluster_id", array(
2d257b3a 3300 // 'label' =>'No Ports found/connected',
3301 'label' =>'',
3302 'fontsize' => 0,
3303 'size' => 0,
3304 'width' => 0,
3305 'height' => 0,
3306 'shape' => 'point',
3307 'style' => 'invis',
3308 ), $cluster_id);
3309
3310 /* show objects without ports */
3311 if($object_id === NULL)
3312 return;
3313 }
3314
3badc888 3315 $object = NULL;
2d257b3a 3316 if($object_id !== NULL) {
4eeb9282 3317 if(
3318 !isset($gv->graph['clusters'][$cluster_id]) &&
3319 !isset($gv->graph['subgraphs'][$cluster_id])
3320 ) {
fdc74cf0 3321
4eeb9282 3322 $object = spotEntity ('object', $object_id);
3badc888 3323
3324 // ip addresses
3325 amplifyCell($object);
3326 $object['portip'] = array();
3327 foreach($object['ipv4'] as $ipv4)
3328 {
3329 $object['portip'][$ipv4['osif']] = $ipv4['addrinfo']['ip'];
3330 }
3331
4eeb9282 3332 // $object['attr'] = getAttrValues($object_id);
fdc74cf0 3333
4eeb9282 3334 $clusterattr = array();
fdc74cf0 3335
4eeb9282 3336 $this->_getcolor('cluster', 'default', $this->alpha, $clusterattr, 'color');
3337 $this->_getcolor('cluster', 'default', $this->alpha, $clusterattr, 'fontcolor');
fdc74cf0 3338
4eeb9282 3339 if($this->object_id == $object_id)
3340 {
3341 $clusterattr['rank'] = 'source';
fdc74cf0 3342
4eeb9282 3343 $this->_getcolor('cluster', 'current', $this->alpha, $clusterattr, 'color');
3344 $this->_getcolor('cluster', 'current', $this->alpha, $clusterattr, 'fontcolor');
3345 }
fdc74cf0 3346
4eeb9282 3347 $clustertitle = "${object['dname']}";
3badc888 3348 $text = "${object['dname']}";
4eeb9282 3349 $clusterattr['tooltip'] = $clustertitle;
fdc74cf0 3350
4eeb9282 3351 unset($_GET['module']); // makeHrefProcess adds this
3352 unset($_GET['port_id']);
3353 unset($_GET['remote_id']);
3354 $_GET['object_id'] = $object_id;
3355 //$_GET['hl'] = 'o';
fdc74cf0 3356
2dbca6fb 3357 $clusterattr['URL'] = $this->_makeHrefProcess($_GET);
fdc74cf0 3358
4eeb9282 3359 //has_problems
3360 if($object['has_problems'] != 'no')
3361 {
3362 $clusterattr['style'] = 'filled';
3363 $this->_getcolor('cluster', 'problem', $this->alpha, $clusterattr, 'fillcolor');
3364 }
fdc74cf0 3365
4eeb9282 3366 if(!empty($object['container_name']))
3badc888 3367 {
4eeb9282 3368 $clustertitle .= "<BR/>${object['container_name']}";
3badc888 3369 $text .= "\n${object['container_name']}";
3370 }
fdc74cf0 3371
4eeb9282 3372 if($object['rack_id'])
3373 {
3374 $rack = spotEntity('rack', $object['rack_id']);
fdc74cf0 3375
4eeb9282 3376 if(!empty($rack['row_name']) || !empty($rack['name']))
3badc888 3377 {
4eeb9282 3378 $clustertitle .= "<BR/>${rack['row_name']} / ${rack['name']}";
3badc888 3379 $text .= "\n${rack['row_name']} / ${rack['name']}";
3380 }
4eeb9282 3381 }
3382
3383 $embedin = $object['container_id'];
3384 if(empty($embedin))
3385 $embedin = 'default';
3386 else
3387 {
3388 $embedin = "c$embedin"; /* see cluster_id */
3389
3390 /* add container / cluster if not already exists */
3391 $this->_add($gv, $object['container_id'], NULL);
3392 }
fdc74cf0 3393
2d257b3a 3394 $clusterattr['id'] = "$object_id----"; /* used for js context menu */
fdc74cf0 3395
2d257b3a 3396 $gv->addCluster($cluster_id, $clustertitle, $clusterattr, $embedin);
fdc74cf0 3397
2d257b3a 3398 } /* isset cluster_id */
3399 } /* object_id !== NULL */
fca4e38a 3400
fdc74cf0 3401 foreach($ports as $key => $port) {
3402
3403 $this->back = $port['linktype'];
3404
4eeb9282 3405 if(!isset($this->ports[$port['id']])) {
fdc74cf0 3406
fdc74cf0 3407
c613fc73 3408 $nodelabel = htmlspecialchars("${port['name']}");
3badc888 3409 $text = $nodelabel;
fdc74cf0 3410
4eeb9282 3411 if($port['iif_id'] != '1' )
3badc888 3412 {
4eeb9282 3413 $nodelabel .= "<BR/><FONT POINT-SIZE=\"8\">${port['iif_name']}</FONT>";
3badc888 3414 $text .= "\n".$port['iif_name'];
3415 }
fdc74cf0 3416
4eeb9282 3417 $nodelabel .= "<BR/><FONT POINT-SIZE=\"8\">${port['oif_name']}</FONT>";
3badc888 3418 $text .= "\n".$port['oif_name'];
3419
3420 // add ip address
3421 if($object)
3422 if(isset($object['portip'][$port['name']]))
3423 {
3424 $nodelabel .= "<BR/><FONT POINT-SIZE=\"8\">".$object['portip'][$port['name']]."</FONT>";
3425 $text .= "\n".$object['portip'][$port['name']];
3426 }
fdc74cf0 3427
4eeb9282 3428 $nodeattr = array(
3429 'label' => $nodelabel,
3430 );
fdc74cf0 3431
4eeb9282 3432 $this->_getcolor('port', 'default',$this->alpha, $nodeattr, 'fontcolor');
3433 $this->_getcolor('oif_id', $port['oif_id'],$this->alpha, $nodeattr, 'color');
fdc74cf0 3434
4eeb9282 3435 if($this->port_id == $port['id']) {
3436 $nodeattr['style'] = 'filled';
3437 $nodeattr['fillcolor'] = $this->_getcolor('port', 'current', $this->alpha);
3438 }
fdc74cf0 3439
4eeb9282 3440 if($this->remote_id == $port['id']) {
3441 $nodeattr['style'] = 'filled';
3442 $nodeattr['fillcolor'] = $this->_getcolor('port', 'remote', $this->alpha);
3443 }
3444
c613fc73 3445 $nodeattr['tooltip'] = htmlspecialchars("${port['name']}");
4eeb9282 3446
3447 unset($_GET['module']);
3448 unset($_GET['remote_id']);
3449 $_GET['object_id'] = $port['object_id'];
3450 $_GET['port_id'] = $port['id'];
3451 $_GET['hl'] = 'p';
fdc74cf0 3452
2dbca6fb 3453 $nodeattr['URL'] = $this->_makeHrefProcess($_GET);
4eeb9282 3454 $nodeattr['id'] = "${port['object_id']}-${port['id']}--"; /* for js context menu */
fdc74cf0 3455
4eeb9282 3456 $gv->addNode($port['id'],
fdc74cf0 3457 $nodeattr,
3458 "c${port['object_id']}"); /* see cluster_id */
3459
4eeb9282 3460 $this->ports[$port['id']] = true;
2d257b3a 3461
4eeb9282 3462 } /* isset port */
fdc74cf0 3463
3464 if(!empty($port['remote_id'])) {
3465
bb000ce6 3466 if($this->object_id !== NULL)
3467 $this->_add($gv, $port['remote_object_id'], $port['remote_id']);
fdc74cf0 3468
3469 if(
3470 !isset($gv->graph['edgesFrom'][$port['id']][$port['remote_id']]) &&
3471 !isset($gv->graph['edgesFrom'][$port['remote_id']][$port['id']])
3472 ) {
3473
3474 $linktype = $port['linktype'];
3475
3476 $edgetooltip = $port['object_name'].':'.$port['name'].
3477 ' - '.$port['cableid'].' -> '.
3478 $port['remote_name'].':'.$port['remote_object_name'];
3479
3480 $edgeattr = array(
3481 'fontsize' => 8,
c613fc73 3482 'label' => htmlspecialchars($port['cableid']),
fdc74cf0 3483 'tooltip' => $edgetooltip,
3484 'sametail' => $linktype,
3485 'samehead' => $linktype,
3486 );
3487
3488 $this->_getcolor('edge', 'default', $this->alpha, $edgeattr, 'color');
3489 $this->_getcolor('edge', 'default', $this->alpha, $edgeattr, 'fontcolor');
3490
3491 if($linktype == 'back' )
3492 {
3493 $edgeattr['style'] = 'dashed';
3494 $edgeattr['arrowhead'] = 'none';
3495 $edgeattr['arrowtail'] = 'none';
3496
3497 /* multilink ports */
3498 if(in_array($port['oif_id'], $lm_multilink_port_types))
3499 {
3500 $edgeattr['dir'] = 'both';
3501 $edgeattr['arrowtail'] = 'dot';
3502 }
3503
3504 if(in_array($port['remote_oif_id'], $lm_multilink_port_types))
3505 {
3506 $edgeattr['dir'] = 'both';
3507 $edgeattr['arrowhead'] = 'dot';
3508 }
3509 }
3510
3511 if(
3512 ($port['id'] == $this->port_id && $port['remote_id'] == $this->remote_id) ||
3513 ($port['id'] == $this->remote_id && $port['remote_id'] == $this->port_id)
3514 )
3515 {
3516 $this->_getcolor('edge', 'highlight', 'ff', $edgeattr, 'color');
3517 $edgeattr['penwidth'] = 2; /* bold */
3518 }
3519
3520 unset($_GET['module']);
3521 $_GET['object_id'] = $port['object_id'];
3522 $_GET['port_id'] = $port['id'];
3523 $_GET['remote_id'] = $port['remote_id'];
3524
2dbca6fb 3525 $edgeattr['URL'] = $this->_makeHrefProcess($_GET);
fdc74cf0 3526
3527 $edgeattr['id'] = $port['object_id']."-".$port['id']."-".$port['remote_id']."-".$linktype; /* for js context menu */
3528
3529 $gv->addEdge(array($port['id'] => $port['remote_id']),
3530 $edgeattr,
3531 array(
3532 $port['id'] => $linktype,
3533 $port['remote_id'] => $linktype,
3534 )
3535 );
3badc888 3536
fdc74cf0 3537 }
3538 }
3539
3540 }
3541
3542 // portlist::var_dump_html($port);
3543 }
3544
83b49cf7 3545 function fetch($type = 'png', $command = NULL, $format2 = NULL, &$data2 = NULL) {
3546
3547 $tmpdata = $data2;
3548 $ret = $this->gv->fetch($type, $command, $format2, $tmpdata);
3549 if($data2 !== NULL)
3550 $data2 = $tmpdata;
fdc74cf0 3551 return $ret;
3552 }
3553
3554 function image($type = 'png', $command = NULL) {
3555 $this->gv->image($type, $command);
3556 }
3557
3558 function parse() {
3559 return $this->gv->parse();
3560 }
3561
3562 /* should be compatible with getObjectPortsAndLinks from RT database.php */
3563 function _getObjectPortsAndLinks($object_id, $linktype = 'front', $port_id = NULL, $allports = false) {
3564
3565 if($linktype == 'front')
3566 $linktable = 'Link';
3567 else
3568 $linktable = 'LinkBackend';
3569
3570 $qparams = array();
3571
3572 $query = "SELECT
3573 '$linktype' as linktype,
3574 Port.*,
3575 Port.type AS oif_id,
3576 PortInnerInterface.iif_name as iif_name,
262da468 3577 POI.oif_name as oif_name,
fdc74cf0 3578 Object.id as object_id, Object.name as object_name,
2a5cd259 3579 IFNULL(LinkTable_a.cable,LinkTable_b.cable) as cableid,
fdc74cf0 3580 remoteObject.id as remote_object_id, remoteObject.name as remote_object_name,
3581 remotePort.id as remote_id, remotePort.name as remote_name,
3582 remotePort.type AS remote_oif_id,
3583 remotePortInnerInterface.iif_name as remote_iif_name,
262da468 3584 remotePOI.oif_name as remote_oif_name
fdc74cf0 3585 FROM Port";
3586
3587 // JOIN
3588 $join = " LEFT JOIN PortInnerInterface on PortInnerInterface.id = Port.iif_id
262da468 3589 LEFT JOIN PortOuterInterface AS POI on POI.id = Port.type
2be16f85 3590 LEFT JOIN $linktable as LinkTable_a on Port.id = LinkTable_a.porta
2a5cd259 3591 LEFT JOIN $linktable as LinkTable_b on Port.id = LinkTable_b.portb
fdc74cf0 3592 LEFT JOIN Object on Object.id = Port.object_id
2a5cd259 3593 LEFT JOIN Port as remotePort on remotePort.id = IFNULL(LinkTable_a.portb, LinkTable_b.porta)
fdc74cf0 3594 LEFT JOIN Object as remoteObject on remoteObject.id = remotePort.object_id
3595 LEFT JOIN PortInnerInterface as remotePortInnerInterface on remotePortInnerInterface.id = remotePort.iif_id
262da468 3596 LEFT JOIN PortOuterInterface as remotePOI on remotePOI.id = remotePort.type
fdc74cf0 3597 ";
3598
3599 // WHERE
3600 if($port_id === NULL)
3601 {
3602 $where = " WHERE Object.id = ?";
3603 $qparams[] = $object_id;
3604
09749fb9 3605 if(!$allports) {
fdc74cf0 3606 $where .= " AND remotePort.id is not NULL";
09749fb9 3607
3608 if($linktype != 'front') {
2a5cd259 3609 $join .= "
3610 LEFT JOIN Link as FrontLink_a on Port.id = FrontLink_a.porta
3611 LEFT JOIN Link as FrontLink_b on Port.id = FrontLink_b.portb
3612 LEFT JOIN Link as FrontRemoteLink_a on remotePort.id = FrontRemoteLink_a.porta
3613 LEFT JOIN Link as FrontRemoteLink_b on remotePort.id = FrontRemoteLink_b.portb
09749fb9 3614 ";
2a5cd259 3615 $where .= " AND ( (FrontLink_a.porta is not NULL or FrontLink_b.portb is not NULL )
3616 OR (FrontRemoteLink_a.porta is not NULL or FrontRemoteLink_b.portb is not NULL) )";
09749fb9 3617 }
3618 }
fdc74cf0 3619 }
3620 else
3621 {
3622 // $where = " WHERE Port.id = ? and remotePort.id is not NULL";
3623 $where = " WHERE Port.id = ?";
3624 $qparams[] = $port_id;
3625 }
3626
3627 // ORDER
3628 $order = " ORDER by oif_name, Port.Name";
3629
3630 $query .= $join.$where.$order;
3631
2a5cd259 3632 //echo "$port_id: $query<br><br>";
3633
fdc74cf0 3634 $result = usePreparedSelectBlade ($query, $qparams);
3635
3636 $row = $result->fetchAll(PDO::FETCH_ASSOC);
3637
3638 $result->closeCursor();
3639
3640 return $row;
3641 }
3642
3643 function _getcolor($type = 'object', $key = 'default', $alpha = 'ff', &$array = NULL , $arraykey = 'color') {
3644
3645 $object = array(
3646 'current' => '#ff0000',
3647 );
3648 $port = array(
3649 'current' => '#ffff90',
3650 'remote' => '#ffffD0',
3badc888 3651 'loop' => '#ff6666',
fdc74cf0 3652 );
3653
3654 $cluster = array(
3655 'current' => '#ff0000',
3656 'problem' => '#ff3030',
3657 );
3658
3659 $edge = array (