fix html after last commit
[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'],
c205dc54 421 'portcount' => null, // TODO prev port count
3badc888 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 1131
c205dc54 1132 $prev_port = $port[( !$back ? 'back' : 'front')];
1133 if ($prev_port['portcount'] > 1)
1134 echo '<td style="color: red;" class="hidden">+'.($prev_port['portcount'] - 1).'</td>';
1135 else
1136 echo '<td class="hidden"></td>';
1137
569219fa
CR
1138 // see interface.php renderObjectPortRow()
1139 // highlight port name with yellow if it's name is not canonical
1140 $canon_pn = shortenPortName ($port['name'], $port['object_id']);
1141 $name_class = $canon_pn == $port['name'] ? '' : 'trwarning';
1142
1143 echo "<td class='tdleft $class'>" .
1144 formatPortLink ($port['object_id'], $port['object_name'], $port['id'], NULL) .
1145 "</td>";
1146
1147 $a_class = isEthernetPort ($port) ? 'port-menu' : '';
1148 echo "<td class='tdleft $class' NOWRAP><a name='port-${port['id']}' class='interactive-portname nolink $a_class'>${port['name']}</a></td>";
1149 echo "<td class='tdleft $class'>${port['label']}</td>";
1150 echo "<td class='tdleft $class'>" . formatPortIIFOIF ($port) . "</td><td class='tdleft $class'><tt>${port['l2address']}</tt></td>";
1151
1152 $remote_port = $port[( $back ? 'back' : 'front')];
1153 if ($remote_port['remote_id'])
1154 {
3d9d3e22 1155 if($port['id'] == $this->first)
1156 {
1157 echo "<td class='tdcenter nothidden'>";
1158
1159 if( $this->linkcount == 1 )
1160 if($back)
1161 echo "=${remote_port['cableid']}=>";
1162 else
1163 echo "-${remote_port['cableid']}->";
1164 else
1165 if( $this->linkcount > 1 )
1166 echo "*".$this->linkcount."*>";
1167 echo "</td>";
1168 }
1169
569219fa 1170 $editable = permitted ('object', 'ports', 'editPort') ? 'editable' : '';
c205dc54 1171
1172 if($remote_port['portcount'] > 1)
1173 echo '<td style="color: red;" class="hidden">'.($remote_port['portcount'] - 1).'+</td>';
1174 else
1175 echo '<td class="hidden"></td>';
1176
d894f236 1177 echo "<td class='tdcenter hidden'>";
569219fa
CR
1178 if($back)
1179 echo "=${remote_port['cableid']}=>";
1180 else
1181 echo "-${remote_port['cableid']}->";
1182
d894f236 1183 echo "</td>";
569219fa
CR
1184 }
1185 else
d894f236 1186 {
1187 if(!empty($port['reservation_comment']))
1188 echo implode ('', formatPortReservation ($port));
1189 }
569219fa 1190
569219fa
CR
1191 } // getporttds
1192
3badc888 1193 // TODO
1194 // html table
1195 function getchainhtml()
1196 {
1197 $remote_id = $this->first;
1198
1199 // if not Link use LinkBackend
1200 $back = $this->ports[$remote_id]['front']['remote_id'];
1201
1202 $chain = "<table>";
1203
1204 for(;$remote_id;)
1205 {
1206 $back = !$back;
1207 $linktype = $port['linktype'];
1208
1209 if($back)
1210 {
1211 // $linktable = 'LinkBackend';
1212 $arrow = ' => ';
1213 }
1214 else
1215 {
1216 // $linktable = 'Link';
1217 $arrow = ' --> ';
1218 }
1219
1220 $port = $this->ports[$remote_id][$linktype];
1221
1222 if($this->init == $remote_id)
1223 $chain .= "<tr><td><b>".$port['object_name']."</b></td><td><b> [".$port['name']."]</b></td>";
1224 else
1225 $chain .= "<tr><td>".$port['object_name']."</td><td> [".$port['name']."]</td>";
1226
1227 if($remote_id == $this->first || $remote_id == $this->last)
1228 $chain .= "<td><div name=\"port${remote_id}-status\"></div></td>";
1229 else
1230 $chain .= "<td></td>";
1231
1232 $remote_id = $port['remote_id'];
1233
1234 if($remote_id)
1235 $chain .= "<td>$arrow</td></tr>";
1236 else
1237 $chain .= "<td></td></tr>";
1238
1239 if($this->loop && $remote_id == $this->first)
1240 {
1241 $chain .= "LOOP!<br>";
1242 break;
1243 }
1244
1245 }
1246
1247 $chain .= "</table>";
1248
1249 return $chain;
1250 }
1251
1252 function getport($id)
1253 {
1254 return $this->ports[$id];
1255 }
1256
1257 /* Iterator */
1258 function rewind() {
1259 $this->currentid = $this->first;
1260
1261 $this->back = isset($this->ports[$this->currentid]['back']['remote_id']);
1262
1263 $this->icount = 0;
1264 }
1265
1266 function current() {
1267 return $this->_getportlink($this->ports[$this->currentid]);
1268 }
1269
1270 function key() {
1271 return $this->currentid;
1272 }
1273
1274 function next() {
1275 $port = $this->current();
1276 $remote_id = $port['remote_id'];
1277
1278 if($this->loop && $remote_id == $this->first)
1279 $this->currentid = false;
1280 else
1281 $this->currentid = $remote_id;
1282
1283 $this->back = !$this->back;
1284
1285 $this->icount++;
1286 }
1287
1288 function valid() {
1289
1290 /* linkcout exceeded */
1291 if($this->icount > $this->linkcount+1)
1292 {
1293 $this->exceed = true;
1294 return false;
1295 }
1296
1297 return $this->currentid;
1298 }
1299
1300 /* for debugging only */
1301 function var_dump_html(&$var, $msg = "") {
1302 echo "<pre>------------------Start Var Dump -------------$msg------------\n";
1303 var_dump($var);
1304 echo "\n---------------------END Var Dump -----------$msg-------------</pre>";
1305 }
1306} // lm_linkchain
1307
1308/*
1309 * from RT database.php fetchPortList()
1310 * with Link table selection
1311 * and multilink changes
1312 */
1313function lm_fetchPortList ($sql_where_clause, $query_params = array(), $linktable = 'Link')
1314{
1315 $query = <<<END
1316SELECT
1317 Port.id,
1318 Port.name,
1319 Port.object_id,
1320 Object.name AS object_name,
1321 Port.l2address,
1322 Port.label,
1323 Port.reservation_comment,
1324 Port.iif_id,
1325 Port.type AS oif_id,
1326 (SELECT PortInnerInterface.iif_name FROM PortInnerInterface WHERE PortInnerInterface.id = Port.iif_id) AS iif_name,
1327 (SELECT PortOuterInterface.oif_name FROM PortOuterInterface WHERE PortOuterInterface.id = Port.type) AS oif_name,
1328
1329 lk.cable AS cableid,
1330 IF(lk.porta = Port.id, pb.id, pa.id) AS remote_id,
1331 IF(lk.porta = Port.id, pb.name, pa.name) AS remote_name,
1332 IF(lk.porta = Port.id, pb.object_id, pa.object_id) AS remote_object_id,
1333 IF(lk.porta = Port.id, ob.name, oa.name) AS remote_object_name,
1334
1335 (SELECT COUNT(*) FROM PortLog WHERE PortLog.port_id = Port.id) AS log_count,
1336 PortLog.user,
1337 UNIX_TIMESTAMP(PortLog.date) as time
1338FROM
1339 Port
1340 INNER JOIN Object ON Port.object_id = Object.id
1341
1342 LEFT JOIN $linktable AS lk ON lk.porta = Port.id or lk.portb = Port.id
1343 LEFT JOIN Port AS pa ON pa.id = lk.porta
1344 LEFT JOIN Object AS oa ON pa.object_id = oa.id
1345 LEFT JOIN Port AS pb ON pb.id = lk.portb
1346 LEFT JOIN Object AS ob ON pb.object_id = ob.id
1347
1348 LEFT JOIN PortLog ON PortLog.id = (SELECT id FROM PortLog WHERE PortLog.port_id = Port.id ORDER BY date DESC LIMIT 1)
1349WHERE
1350 $sql_where_clause
1351END;
1352
1353 $result = usePreparedSelectBlade ($query, $query_params);
1354
1355 $ret = array();
1356 while ($row = $result->fetch (PDO::FETCH_ASSOC))
1357 {
1358 $row['l2address'] = l2addressFromDatabase ($row['l2address']);
1359 $row['linked'] = isset ($row['remote_id']) ? 1 : 0;
1360
1361 // last changed log
1362 $row['last_log'] = array();
1363 if ($row['log_count'])
1364 {
1365 $row['last_log']['user'] = $row['user'];
1366 $row['last_log']['time'] = $row['time'];
1367 }
1368 unset ($row['user']);
1369 unset ($row['time']);
1370
1371 $ret[] = $row;
1372 }
1373 return $ret;
1374} /* lm_fetchPortList */
1375
1376function lm_getPortInfo ($port_id, $back = false)
1377{
1378 $linktable = ($back ? 'LinkBackend' : 'Link');
1379 if($back)
1380 $result = lm_fetchPortList ('Port.id = ?', array ($port_id), $linktable);
1381 else
1382 $result = fetchPortList ('Port.id = ?', array ($port_id));
1383
1384 //return empty ($result) ? NULL : $result[0];
1385 return $result;
1386} /* lm_getPortInfo */
1387
1388/* -------------------------------------------------------------------------- */
1389/* -------------------------------------------------- */
1390
1391function linkmgmt_opHelp() {
1392?>
1393 <table cellspacing=10><tr><th>Help</th><tr>
1394 <tr><td width=150></td><td width=150 style="font-weight:bold;color:<?php echo portlist::CURRENT_OBJECT_BGCOLOR; ?>">Current Object</td></tr>
1395 <tr><td></td><td bgcolor=<?php echo portlist::CURRENT_PORT_BGCOLOR; ?>>[current port]</td></tr>
1396 <tr><td>front link</td><td>[port]<(Object)</td><td>back link</td></tr>
1397 <tr><td>back link</td><td>(Object)>[port]</td><td>front link</td></tr>
1398 <tr><td></td><td><pre>----></pre></td><td>Front link</td></tr>
1399 <tr><td></td><td><pre>====></pre></td><td>Backend link</td></tr>
1400 <tr><td></td><td>Link Symbol</td><td>Create new link</td></tr>
1401 <tr><td></td><td>Cut Symbol</td><td>Delete link</td></tr>
1402
1403 </table>
1404
1405<?php
1406 exit;
1407} /* opHelp */
1408
1409/* -------------------------------------------------- */
1410
1411function linkmgmt_ajax_mapinfo() {
1412
1413 $object_id = NULL;
1414 $port_id = NULL;
1415 $remote_id = NULL;
1416 $linktype = NULL;
1417
1418 if(isset($_REQUEST['object_id']))
1419 $object_id = $_REQUEST['object_id'];
1420
1421 if(isset($_REQUEST['port_id']))
1422 $port_id = $_REQUEST['port_id'];
1423
1424 if(isset($_REQUEST['remote_id']))
1425 $remote_id = $_REQUEST['remote_id'];
1426
1427 if(isset($_REQUEST['linktype']))
1428 $linktype = $_REQUEST['linktype'];
1429
1430 $debug = NULL;
1431 if(isset($_REQUEST['debug']))
1432 $debug['value'] = $_REQUEST['debug'];
1433
1434 $info = array();
1435
1436 echo "<table style=\"font-size:12;\"><tr>";
1437
1438 if($port_id != NULL)
1439 {
1440 $port = new linkmgmt_RTport($port_id);
1441
1442 echo "<td>";
1443 $port->printtable('both');
1444 echo "</td>";
1445
1446 if($debug)
1447 $debug['port'] = &$port;
1448
1449 if($remote_id != NULL)
1450 {
1451
1452 $remote_port = new linkmgmt_RTport($remote_id);
1453
1454 echo "<td><table align=\"center\">";
1455
1456 // TODO cableid
1457 echo "<tr><td><pre>".($linktype == 'back' ? ' ===> ' : ' ---> ')."</pre></td></tr>";
1458
1459 $port->printunlinktr($linktype, $remote_port);
1460
1461 echo "</table></td>";
1462
1463
1464 echo "<td>";
1465 $remote_port->printtable('both');
1466 echo "</td>";
1467
1468 if($debug)
1469 $debug['remote_port'] = &$remote_port;
1470
1471 }
1472 else
1473 $port->printunlinktr();
1474
1475
1476 }
1477 echo "</tr><tr>";
1478
1479 echo "<td>";
1480 $object = linkmgmt_RTport::printobjecttable($object_id);
1481 echo "</td>";
1482
1483 if($debug)
1484 $debug['object'] = &$object;
1485
1486 if($remote_id != NULL)
1487 {
1488
1489 echo "<td></td>"; /* link */
1490 echo "<td>";
1491 $remote_object = linkmgmt_RTport::printobjecttable($remote_port->port['object_id']);
1492 echo "</td>";
1493
1494 if($debug)
1495 $debug['remote_object'] = &$remote_object;
1496 }
1497
1498 echo "</tr></table>";
1499
1500 if($debug)
1501 {
1502 echo "<pre>--- Debug ---";
1503 var_dump($debug);
1504 echo "</pre>";
1505 }
1506
1507 exit;
1508}
1509
1510/* -------------------------------------- */
1511function lm_renderObjectCell ($cell)
1512{
1513 echo "<table class='slbcell vscell'><tr><td rowspan=2 width='5%'>";
1514 printImageHREF ('OBJECT');
1515 echo '</td><td>';
1516 echo mkA ('<strong>' . niftyString ($cell['dname']) . '</strong>', 'object', $cell['id']);
1517 echo '</td></tr><tr><td>';
1518 echo count ($cell['etags']) ? ("<small>" . serializeTags ($cell['etags']) . "</small>") : '&nbsp;';
1519 echo "</td></tr></table>";
1520}
1521/* -------------------------------------- */
1522
1523// TODO replace..
1524class linkmgmt_RTport {
1525
1526 private $port_id = NULL;
1527
1528 public $port = false;
1529
1530 function __construct($port_id) {
1531
1532 $this->port = getPortInfo($port_id);
1533
1534 if($this->port === false)
1535 return;
1536
1537 /* successfully get port info */
1538 $this->port_id = $port_id;
1539
1540 } /* __construct */
1541
1542 function isvalid() {
1543 return ($port_id !== NULL);
1544 }
1545
1546 function getlinks($type = 'front') {
1547 } /* getlinks */
1548
1549 function printtable($linktype = 'front') {
1550
1551 if($this->port_id == NULL)
1552 return;
1553
1554 echo "<table>";
1555
1556 $urlparams = array(
1557 'module' => 'redirect',
1558 'page' => 'object',
1559 'tab' => 'linkmgmt',
1560 'op' => 'map',
1561 'object_id' => $this->port['object_id'],
1562 'port_id' => $this->port_id,
1563 'usemap' => 1,
1564 );
1565
1566 echo '<tr><td><a title="don\'t highlight port" href="?'.http_build_query($urlparams).'">-phl</a></td>';
1567
1568 $urlparams['hl'] = 'p';
1569 echo '<td><a title="highlight port" href="?'.http_build_query($urlparams).'">+phl</a></td></tr>';
1570
1571 $this->_printinforow($this->port,
1572 array(
1573 'id' => 'Port ID',
1574 'name' => 'Port Name',
1575 'oif_name' => 'Port Type',
1576 'l2address' => 'MAC',
1577 'reservation_comment' => 'comment',
1578 )
1579 ); /* printinforow */
1580
1581 $this->printlinktr($linktype);
1582
1583 echo "</table>";
1584 } /* printtable */
1585
1586 function printlinktr($linktype = 'front') {
1587 if($this->port_id === NULL)
1588 return;
1589
1590 $urlparams = array(
1591 'tab' => 'linkmgmt',
1592 'page' => 'object',
1593 'op'=>'PortLinkDialog',
1594 'port'=>$this->port_id,
1595 'object_id'=>$this->port['object_id'],
1596 'linktype' => $linktype,
1597 );
1598
1599 echo "<tr><td align=\"center\"><a href='".
1600 makeHrefProcess($urlparams).
1601 "'>";
1602 printImageHREF ('plug', 'Link this port');
1603 echo "</a></td></tr>";
1604 } /* link */
1605
1606 function printunlinktr($linktype = 'front', $remote_port = NULL) {
1607 if($this->port_id === NULL)
1608 return;
1609
1610 $urlparams = array(
1611 'tab' => 'linkmgmt',
1612 'op'=>'unlinkPort',
1613 'port_id'=>$this->port_id,
1614 'object_id'=>$this->port['object_id'],
1615 'linktype' => $linktype,
1616 );
1617
1618 $confirmmsg = "unlink port ".$this->port['name'];
1619
1620 if($remote_port !== NULL)
1621 {
1622 $urlparams['remote_id'] = $remote_port->port['id'];
1623 $confirmmsg .= ' -> '.$remote_port->port['name'];
1624 }
1625
1626 $confirmmsg .= " ($linktype)"; // TODO cableid
1627
1628 echo "<tr><td align=\"center\"><a href='".makeHrefProcess($urlparams).
1629 "' onclick=\"return confirm('$confirmmsg');\">";
1630 printImageHREF ('cut', 'Unlink this port');
1631 echo "</a></td></tr>";
1632
1633 } /* unlink */
1634
1635 /* TODO move to object class */
1636 static function printobjecttable($object_id = NULL) {
1637
1638 if($object_id === NULL)
1639 return;
1640
1641 $object = spotEntity ('object', $object_id);
1642
1643 if($object === false)
1644 return;
1645
1646 if($object['rack_id'])
1647 {
1648 $rack = spotEntity('rack', $object['rack_id']);
1649
1650 $object['row_name'] = $rack['row_name'];
1651 $object['rack_name'] = $rack['name'];
1652 }
1653
1654 echo "<table><tr><td>";
1655 lm_renderObjectCell($object);
1656 echo "</td></tr><tr><td><table>";
1657
1658 self::_printinforow($object,
1659 array(
1660 'id' => 'ID',
1661 'dname' => 'Name',
1662 'label' => 'Label',
1663 'rack_name' => 'Rack',
1664 'row_name' => 'Row',
1665 )
1666
1667 ); /* printinforow */
1668
1669 $urlparams = array(
1670 'module' => 'redirect',
1671 'page' => 'object',
1672 'tab' => 'linkmgmt',
1673 'op' => 'map',
1674 'object_id' => $object_id,
1675 'usemap' => 1,
1676 );
1677
1678 echo '<tr><td><a title="don\'t highlight object" href="?'.http_build_query($urlparams).'">-ohl</a></td>';
1679
1680 $urlparams['hl'] = 'o';
1681 echo '<td><a title="highlight object" href="?'.http_build_query($urlparams).'">+ohl</a></td></tr>';
1682
1683 echo "</table></td></tr></table>";
1684
1685 return $object;
1686
1687 } /* printobjecttable */
1688
1689 static function _printinforow(&$data, $config) {
1690
1691 foreach($config as $key => $name)
1692 {
1693 if(isset($data[$key]))
1694 {
1695 $value = $data[$key];
1696 if(!empty($value))
1697 echo "<tr><td align=\"right\" nowrap=\"nowrap\" style=\"font-size:10;\">$name:</td><td nowrap=\"nowrap\">$value</td></tr>";
1698 }
1699 }
1700
1701 } /* _printinforow */
1702} /* class RTport */
1703
1704/* -------------------------------------------------- */
1705
1706function linkmgmt_opmap() {
1707
1708 /* display require errors "white screen of death" */
1709 $errorlevel = error_reporting();
1710 error_reporting(E_ALL);
1711
1712 require_once 'Image/GraphViz.php';
1713
1714/*
1715 *
1716 */
1717class lm_Image_GraphViz extends Image_GraphViz {
1718
1719 /* extend renderDotFile with additional output file
1720 */
1721 function renderDotFile($dotfile, $outputfile, $format = 'svg',
1722 $command = null, $outputfile2 = null, $format2 = null)
1723 {
1724 if (!file_exists($dotfile)) {
1725 if ($this->_returnFalseOnError) {
1726 return false;
1727 }
1728 $error = PEAR::raiseError('Could not find dot file');
1729 return $error;
1730 }
1731
1732 $oldmtime = file_exists($outputfile) ? filemtime($outputfile) : 0;
1733
1734 switch ($command) {
1735 case 'dot':
1736 case 'neato':
1737 break;
1738 default:
1739 $command = $this->graph['directed'] ? 'dot' : 'neato';
1740 }
1741 $command_orig = $command;
1742
1743 $command = $this->binPath.(($command == 'dot') ? $this->dotCommand
1744 : $this->neatoCommand);
1745
1746 $command .= ' -T'.escapeshellarg($format)
1747 .' -o'.escapeshellarg($outputfile)
1748 .($format2 !== null && $outputfile2 !== null ? ' -T'.escapeshellarg($format2).' -o'.escapeshellarg($outputfile2) : '')
1749 .' '.escapeshellarg($dotfile)
1750 .' 2>&1';
1751
1752 exec($command, $msg, $return_val);
1753
1754 clearstatcache();
1755 if (file_exists($outputfile) && filemtime($outputfile) > $oldmtime
1756 && $return_val == 0) {
1757 return true;
1758 } elseif ($this->_returnFalseOnError) {
1759 return false;
1760 }
1761 $error = PEAR::raiseError($command_orig.' command failed: '
1762 .implode("\n", $msg));
1763 return $error;
1764 }
1765 // renderDotFile
1766
1767
1768 /*
1769 */
1770 function fetch($format = 'svg', $command = null, $format2 = null, &$data2 = null)
1771 {
1772
1773 $file = $this->saveParsedGraph();
1774 if (!$file || PEAR::isError($file)) {
1775 return $file;
1776 }
1777
1778 $outputfile = $file . '.' . $format;
1779
1780 if($format2 != null && $data2 !== null)
1781 $outputfile2 = $file . '.' . $format2;
1782 else
1783 $outputfile2 = null;
1784
1785 $rendered = $this->renderDotFile($file, $outputfile, $format,
1786 $command, $outputfile2, $format2);
1787 if ($rendered !== true) {
1788 return $rendered;
1789 }
1790
1791 @unlink($file);
1792
1793 if($format2 !== null && $data2 !== null) {
1794 $fp = fopen($outputfile2, 'rb');
1795
1796 if ($fp) {
1797 $data = fread($fp, filesize($outputfile2));
1798 fclose($fp);
1799 @unlink($outputfile2);
1800
1801 $data2 = $data;
1802 } else {
1803 return $error;
1804 }
1805 }
1806
1807
1808 $fp = fopen($outputfile, 'rb');
1809
1810 if (!$fp) {
1811 if ($this->_returnFalseOnError) {
1812 return false;
83b49cf7 1813 }
1814 $error = PEAR::raiseError('Could not read rendered file');
1815 return $error;
1816 }
1817
3badc888 1818 $data = fread($fp, filesize($outputfile));
1819 fclose($fp);
1820 @unlink($outputfile);
1821
1822 return $data;
1823 }
1824 // fetch
1825
1826
1827
1828} /* class lm_Image_GraphViz */
1829
1830 error_reporting($errorlevel);
1831
1832 $object_id = NULL;
1833 $port_id = NULL;
1834 $remote_id = NULL;
1835 $allports = false;
1836 $usemap = false;
1837 $command = NULL;
1838
1839 /* highlight object */
1840 $hl = NULL;
1841 if(isset($_REQUEST['hl']))
1842 {
1843 $hl = $_REQUEST['hl'];
1844 unset($_REQUEST['hl_object_id']);
1845 unset($_REQUEST['hl_port_id']);
1846
1847 if($hl == 'o')
1848 {
1849 unset($_GET['port_id']);
1850 unset($_GET['remote_id']);
1851 }
1852
1853 }
1854
1855 if(!$hl && isset($_REQUEST['hl_object_id']))
1856 {
1857 $hl = 'o';
1858 $object_id = $_REQUEST['hl_object_id'];
1859 $_REQUEST['object_id'] = $object_id;
1860 unset($_REQUEST['hl_object_id']);
1861 unset($_REQUEST['hl_port_id']);
1862 unset($_REQUEST['port_id']);
1863 }
1864
1865 if(isset($_REQUEST['object_id']))
1866 $object_id = $_REQUEST['object_id'];
1867
1868 if(isset($_REQUEST['type']))
1869 {
1870 $type = $_REQUEST['type'];
1871 }
1872 else
1873 $type = 'gif';
1874
1875 /* highlight port */
1876 if(!$hl && isset($_REQUEST['hl_port_id']))
1877 {
1878 $hl = 'p';
1879 $port_id = $_REQUEST['hl_port_id'];
1880 $_REQUEST['port_id'] = $port_id;
1881 unset($_REQUEST['hl_port_id']);
1882 }
1883
1884 if(isset($_REQUEST['allports']))
1885 {
1886 $allports = $_REQUEST['allports'];
1887 }
1888
1889 if(isset($_REQUEST['port_id']))
1890 {
1891 $port_id = $_REQUEST['port_id'];
1892 }
1893
1894 if(isset($_REQUEST['usemap']))
1895 $usemap = $_REQUEST['usemap'];
1896
1897 if($hl == 'p' && $port_id === NULL)
1898 {
1899 unset($_GET['hl']);
1900 unset($_GET['port_id']);
1901 unset($_GET['remote_id']);
1902 }
1903
1904 if($hl == 'o')
1905 unset($_GET['remote_id']);
1906
1907 if(isset($_REQUEST['remote_id']))
1908 $remote_id = $_REQUEST['remote_id'];
1909
1910 /* show all objects */
1911 if(isset($_REQUEST['all']))
1912 {
1913 $object_id = NULL;
1914 $port_id = NULL;
1915 $hl = NULL;
1916 unset($_GET['hl']);
1917 }
1918
1919 if(isset($_REQUEST['cmd']))
1920 $command = $_REQUEST['cmd'];
1921
1922 if(isset($_REQUEST['debug']))
1923 $debug = $_REQUEST['debug'];
1924 else
1925 $debug = False;
1926
1927 if($debug) echo "-- DEBUG --<br>";
1928
1929
1930 switch($type) {
1931 case 'gif':
1932 case 'png':
1933 case 'bmp':
1934 case 'jpeg':
1935 case 'tif':
1936 case 'wbmp':
1937 $ctype = "image/$type";
1938 break;
1939 case 'jpg':
1940 $ctype = "image/jpeg";
1941 break;
1942 case 'svg':
1943 $ctype = 'image/svg+xml';
1944 break;
1945 case 'pdf':
1946 $ctype = 'application/pdf';
1947 break;
1948 case 'cmapx':
1949 $ctype = 'text/plain';
1950 break;
1951 }
1952
1953 $start = microtime(true);
1954 $gvmap = new linkmgmt_gvmap($object_id, $port_id, $allports, $hl, $remote_id);
1955 $stop = microtime(true);
1956
1957 if($debug)
1958 echo "gvmap Time: ".( $stop - $start )."<br>";
1959
1960 if($debug) echo "-- after gvmap --<br>";
1961
1962 if($usemap)
1963 {
1964
1965 if($debug) echo "-- usemap --<br>";
1966
1967 /* add context menu to Ports, Objects, Links, ...
1968 */
1969
1970 echo "<script>
1971 function initcontextmenu() {
1972 var maps = document.getElementsByTagName('map');
1973 for(var i=0;i<maps.length;i++) {
1974 var areas = maps[i].childNodes;
1975
1976 for(j=0;j<areas.length;j++) {
1977 if(areas[j].nodeType == 1)
1978 {
1979 // console.log(areas[j].id);
1980 // attr = document.createAttribute('onmouseover','ahh');
1981 // areas[j].setAttribute(attr);
1982 // areas[j].onmouseover = 'menu(this);';
1983
1984 areas[j].addEventListener('contextmenu',menu,false);
1985 // areas[j].oncontextmenu = 'menu(this, event);';
1986 // console.log(areas[j].oncontextmenu);
1987 }
1988 }
1989
1990 }
1991
1992 };
1993
1994 function menu(event) {
1995
1996 // console.log('Menu');
1997
1998 if(!event)
1999 event = window.event;
2000
2001 var parent = event.target;
2002
2003 // console.log('--' + parent);
2004
2005 var ids = parent.id.split('-');
2006
2007 if(ids[0] == 'graph1')
2008 return false;
2009
2010 var object_id = ids[0];
2011
2012 var url ='?module=ajax&ac=lm_mapinfo&object_id=' + object_id;
2013
2014 // links ='<li><a href=' + object_id + '>Object</a></li>';
2015
2016 if(ids[1] != '')
2017 {
2018 var port_id = ids[1];
2019 url += '&port_id=' + port_id;
2020 // links += '<li><a href=' + port_id + '>Port</a></li>';
2021
2022 if(ids[2] != '')
2023 {
2024 var remote_id = ids[2];
2025
2026 if(ids[3] != '')
2027 {
2028 var linktype = ids[3];
2029 url += '&remote_id=' + remote_id + '&linktype=' + linktype;
2030 // links += '<li><a href=' + port_id + '_' + remote_id + '_' + linktype + '>Unlink</a></li>';
2031 }
2032 }
2033
2034 }
2035
2036
2037 var xmlHttp = new XMLHttpRequest();
2038 xmlHttp.open('GET', url, false);
2039 xmlHttp.send(null);
2040
2041 var infodiv = document.getElementById('info');
2042 infodiv.innerHTML = xmlHttp.responseText;
2043
2044 // linkdiv = document.getElementById('link');
2045 // linkdiv.innerHTML = links;
2046
2047 var menudiv = document.getElementById('menu');
2048 menudiv.style.position = 'absolute';
2049 menudiv.style.top = (event.clientY + document.body.scrollTop) + 'px';
2050 menudiv.style.left = (event.clientX + document.body.scrollLeft) + 'px';
2051 menudiv.style.display = '';
2052
2053 return false;
2054 };
2055
2056 function mousedown(event) {
2057 // console.log('mouse down');
2058
2059 if(!event)
2060 event = window.event;
2061
2062 if(event.button != 2)
2063 return true;
2064
2065 var menudiv = document.getElementById('menu');
2066
2067 menudiv.style.display = 'none';
2068
2069 return false;
2070 };
2071
2072 </script>";
2073
2074 echo "<body oncontextmenu=\"return false\" onmousedown=\"mousedown(event);\" onload=\"initcontextmenu();\">";
2075
2076 echo "<div id=\"menu\" style=\"display:none; background-color:#ffff90\">
2077 <div id=\"info\"></div>
2078 <ul id=\"link\" style=\"list-style-type:none\"></ul>
2079 </div>";
2080
2081 if($debug)
2082 $gvmap->setFalseOnError(False);
2083
2084 $data2 = '';
2085
2086 $start = microtime(true);
2087 $data = $gvmap->fetch($type, $command, 'cmapx', $data2);
2088 $stop = microtime(true);
2089
2090 if($debug)
2091 echo "DOT time: ".( $stop - $start )."<br>";
2092
2093 if($data === false)
2094 echo "ERROR Fetching image data!<br>";
2095
2096 if(PEAR::isError($data))
2097 echo $data->getMessage();
2098
2099 //echo $gvmap->fetch('cmapx', $command);
2100 echo $data2;
2101
2102 if($debug) echo "-- after map gvmap --<br>";
2103
2104 echo "<img src=\"data:$ctype;base64,".
2105 base64_encode($data).
2106 "\" usemap=#map$object_id />";
2107
2108 if($debug)
2109 {
2110 echo "<pre>";
2111 echo $gvmap->export();
2112 echo "</pre>";
2113
2114 echo "<pre>".$gvmap->parse()."</pre>";
2115 }
2116 }
2117 else
2118 {
2119 $gvmap->image($type);
2120 }
2121
2122 exit;
2123
2124} /* linkmgmt_opmap */
2125
2126class cytoscapedata
2127{
2128 public $objects = array();
2129
2130 public $pids = array();
2131
2132 public $parents = array();
2133 public $nodes = array();
2134
2135 public $edges = NULL;
2136
2137 public $debug = null;
2138
2139 function __construct()
2140 {
2141
2142 $this->edges['parents'] = array();
2143 $this->edges['nodes'] = array();
2144 }
2145
2146 function addnode($id, $values = NULL, &$arr = NULL)
2147 {
2148 $data = array( 'id' => $id );
2149
2150 if($values != NULL)
2151 $data = $data + $values;
2152
2153 $node['data'] = $data;
2154
2155 $this->objects[] = array('group' => 'nodes') + $node;
2156
2157 switch($values['type'])
2158 {
2159 case 'port':
2160 $this->nodes[$id] = array('group' => 'nodes') + $node;
2161 break;
2162 case 'object':
2163 case 'container':
2164 $this->parents[$id] = array('group' => 'nodes') + $node;
2165 break;
2166 }
2167
2168 if($arr !== NULL)
2169 $arr[] = array('group' => 'nodes') + $node;
2170 }
2171
2172 function addedge($id, $source, $target, $values = NULL, &$arr = NULL)
2173 {
2174 $data = array(
2175 'id' => $id,
2176 'source' => $source,
2177 'target' => $target
2178 );
2179
2180 if($values != NULL)
2181 $data = $data + $values;
2182
2183 $edge['data'] = $data;
2184
2185 //$this->elements['edges'][] = $edge;
2186
2187 if($arr !== NULL)
2188 {
2189 $arr[$id] = array('group' => 'edges') + $edge;
2190 }
2191 else
2192 $this->objects[] = array('group' => 'edges') + $edge;
2193
2194 //$this->edges[] = array('group' => 'edges') + $edge;
2195 }
2196
2197 function _addobjectnode($object_id, $type = 'object')
2198 {
2199 global $lc_cache;
2200
2201 if(!isset($this->parents["o$object_id"]))
2202 {
2203 $rack = null;
2204 $object = $lc_cache->getobject($object_id, $rack);
2205
2206 $clustertitle = "${object['dname']}";
2207
2208 //has_problems
2209 //if($object['has_problems'] != 'no')
2210
2211 $rack_text = "";
2212 if(!empty($rack['row_name']) || !empty($rack['name']))
2213 {
2214 $rack_text = "${rack['row_name']} / ${rack['name']}";
2215 }
2216
2217 $data = array('label' => $object['name'], 'text' => $rack_text, 'type' => $type, 'has_problems' => $object['has_problems']);
2218
2219 $container_id = $object['container_id'];
2220 if($container_id)
2221 {
2222 $data['parent'] = "o$container_id";
2223 $this->_addobjectnode($container_id, 'container');
2224 }
2225
2226 $this->addnode('o'.$object_id, $data);
2227 }
2228
2229 }
2230
2231 // cytoscape
2232 function addlinkchain($linkchain, $index) {
2233
2234 foreach($linkchain as $id => $port)
2235 {
2236
2237 if(!$linkchain->linked)
2238 continue;
2239
2240 $this->_addobjectnode($port['object_id']);
2241
2242 $text = (isset($port['portip']) ? $port['portip'] : "" );
2243 $nodedata = array('label' => $port['name'], 'parent' => 'o'.$port['object_id'], 'text' => $text, 'type' => 'port', 'index' => $index , 'loop' => ($linkchain->loop ? '1' : '0'));
2244
2245 //$this->addnode('l_'.$port['id'], array( 'label' => $port['name'], 'parent' => 'p'.$port['id'], 'text' => $text ));
2246
2247 if($port['portcount'] > 1)
2248 foreach($port['chains'] as $mlc)
2249 {
2250 $this->addlinkchain($mlc, 0); // TODO index
2251 }
2252
2253 $prevlinktype = ($port['linktype'] == 'front' ? 'back' : 'front');
2254 if($port[$prevlinktype]['portcount'] > 1)
2255 {
2256 foreach($port[$prevlinktype]['chains'] as $mlc)
2257 {
2258 $this->addlinkchain($mlc, 0, false); // TODO index
2259 }
2260 }
83b49cf7 2261
3badc888 2262 if($port['remote_id'])
2263 {
83b49cf7 2264
3badc888 2265 $this->_addobjectnode($port['remote_object_id']);
83b49cf7 2266
3badc888 2267 $linktype = $port['linktype'];
2268 $edgedata = array('label' => $port['cableid'], 'type' => $linktype, 'loop' => ($linkchain->loop ? '1' : '0'));
83b49cf7 2269
3badc888 2270 if($linkchain->loop && $port['remote_id'] == $linkchain->first)
2271 {
2272 $nodedata['loopedge'] = array('group' => 'edges', 'data' => array( 'id' => 'le'.$port['id']."_".$port['remote_id'], 'source' => 'p'.$port['id'], 'target' => 'p'.$port['remote_id']) + $edgedata);
2273 }
2274 else
2275 {
83b49cf7 2276
3badc888 2277 $this->addedge('e'.$port['id']."_".$port['remote_id'], 'p'.$port['id'], 'p'.$port['remote_id'], $edgedata);
2278 $this->addedge('e'.$port['id']."_".$port['remote_id'], 'p'.$port['id'], 'p'.$port['remote_id'], $edgedata, $this->edges['nodes']);
2279 $id1 = $port['object_id'];
2280 if($id1 > $port['remote_object_id'])
2281 {
2282 $id1 = $port['remote_object_id'];
2283 $id2 = $port['object_id'];
2284 }
2285 else
2286 $id2 = $port['remote_object_id'];
fdc74cf0 2287
3badc888 2288 $peid = "pe".$id1."_".$id2;
fdc74cf0 2289
3badc888 2290 if(isset($this->edges['parents'][$peid]))
2291 $this->edges['parents'][$peid]['data']['linkcount']++;
2292 else
2293 $this->addedge($peid, 'o'.$id1, 'o'.$id2, array('type' => $linktype, 'linkcount' => 1), $this->edges['parents']);
2294 }
2295 }
fdc74cf0 2296
3badc888 2297 $this->addnode('p'.$port['id'], $nodedata);
2298 }
2299
2300 if(0)
2301 if($linkchain->first != $linkchain->last )
fdc74cf0 2302 {
3badc888 2303 $first = $linkchain->first;
2304 $last = $linkchain->last;
2305 $this->addedge("l${first}_${last}",'p'.$first, 'p'.$last, array('type' => 'logical', 'label' => "logical"));
fdc74cf0 2306 }
2307
3badc888 2308 //portlist::var_dump_html($this->parents);
fdc74cf0 2309 }
2310
3badc888 2311 function getlinkchains($object_id) {
fdc74cf0 2312
3badc888 2313 $this->objects = array();
2314 $this->parents = array();
2315 $this->nodes = array();
2316 $this->edges['parents'] = array();
2317 $this->edges['nodes'] = array();
fdc74cf0 2318
3badc888 2319 $this->_getlinkchains($object_id);
fdc74cf0 2320 }
fdc74cf0 2321
3badc888 2322 function getelements()
fdc74cf0 2323 {
3badc888 2324 //lm_linkchain::var_dump_html($this);
2325 return array('parents' => array_values($this->parents),
2326 'nodes' => array_values($this->nodes),
2327 'edges' => array(
2328 'parents' => array_values($this->edges['parents']),
2329 'nodes' => array_values($this->edges['nodes'])
2330 ),
2331 'debug' => $this->debug
2332 );
fdc74cf0 2333
fdc74cf0 2334 }
2335
3badc888 2336 function gettest()
fdc74cf0 2337 {
3badc888 2338 return array_merge(array_values($this->parents), array_values($this->edges['parents']));
2339 //return array_merge(array_values($this->parents), array_values($this->edges['parents']), array_values($this->nodes), array_values($this->edges['nodes']));
fdc74cf0 2340 }
2341
3badc888 2342 function _getlinkchains($object_id) {
fdc74cf0 2343
fdc74cf0 2344
3badc888 2345 // container
2346 // $object = spotEntity('object', $object_id);
2347 $object['ports'] = getObjectPortsAndLinks ($object_id);
fdc74cf0 2348
3badc888 2349 $i = 0;
2350 foreach($object['ports'] as $key => $port)
2351 {
fdc74cf0 2352
3badc888 2353 if(isset($this->pids[$port['id']]))
2354 continue;
2355
2356 $i++;
2357 $lc = new lm_linkchain($port['id']);
2358
2359 $this->pids += $lc->pids;
2360
2361 $this->addlinkchain($lc, $i);
2362
2363 }
2364
2365 $children = getEntityRelatives ('children', 'object', $object_id);
2366
2367 foreach($children as $child)
2368 $this->_getlinkchains($child['entity_id']);
2369 }
2370
2371 function allobjects()
fdc74cf0 2372 {
3badc888 2373
2374 $this->objects = array();
2375 $this->parents = array();
2376 $this->nodes = array();
2377 $this->edges['parents'] = array();
2378 $this->edges['nodes'] = array();
2379
2380 $objects = listCells('object');
2381
2382 $i = 0;
2383 foreach($objects as $object)
2384 {
2385 //echo $object['id']."<br>";
2386 $this->_getlinkchains($object['id']);
2387 $i++;
2388 if($i > 20 ) break;
2389 }
fdc74cf0 2390 }
3badc888 2391}
fdc74cf0 2392
3badc888 2393function linkmgmt_cytoscapemap() {
fdc74cf0 2394
fdc74cf0 2395
3badc888 2396 $object_id = $_GET['object_id'];
fdc74cf0 2397
3badc888 2398 if(isset($_GET['json']))
2399 {
2400 ob_start();
2401 $data = new cytoscapedata();
2402 $data->getlinkchains($object_id);
2403 //$data->allobjects(); // ugly graph;
2404 //echo json_encode($data->objects);
fdc74cf0 2405
3badc888 2406 if(ob_get_length())
2407 $data->debug = ob_get_contents();
fdc74cf0 2408
3badc888 2409 ob_end_clean();
2410
2411 echo json_encode($data->getelements());
fdc74cf0 2412
3badc888 2413 exit;
fdc74cf0 2414 }
2415
3badc888 2416 echo (<<<HTMLEND
2417<!DOCTYPE html>
2418<html>
2419<head>
2420<style>
2421body {
2422 font: 14px helvetica neue, helvetica, arial, sans-serif;
2423}
fdc74cf0 2424
3badc888 2425#cy {
2426 height: 100%;
2427 width: 100%;
2428 position: absolute;
2429 left: 0;
2430 top: 0;
2431}
2432</style>
2433<meta charset=utf-8 />
2434<meta name="viewport" content="user-scalable=no, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, minimal-ui">
2435<title>Compound nodes</title>
2436<!--<script src="js/jquery-1.4.4.min.js"></script>-->
2437
383230c5 2438<script src="?module=chrome&uri=linkmgmt/jquery-1.11.3.min.js"></script>
2439<script src="?module=chrome&uri=linkmgmt/cytoscape.min.js"></script>
2440<script src="?module=chrome&uri=linkmgmt/dagre.min.js"></script>
2441<script src="?module=chrome&uri=linkmgmt/cytoscape-dagre.js"></script>
2442<link rel="stylesheet" type="text/css" href="?module=chrome&uri=linkmgmt/jquery.qtip.min.css">
2443<script src="?module=chrome&uri=linkmgmt/jquery.qtip.min.js"></script>
2444<script src="?module=chrome&uri=linkmgmt/cytoscape-qtip.js"></script>
3badc888 2445
383230c5 2446<!--<script src="?module=chrome&uri=linkmgmt/cytoscape-css-renderer_mod.js"></script>-->
2447<!--<script src="?module=chrome&uri=linkmgmt/cytoscape.js-navigator.js_mod"></script>-->
3badc888 2448<script>
2449var cy = null;
2450var cy2 = null;
2451var layout = null;
2452var data = null;
2453
2454$(function(){ // on dom ready
2455 var cystyle = [
2456 {
2457 selector: 'node',
2458 css: {
2459 'content': 'data(id)',
2460 'text-wrap': 'wrap'
2461 },
2462 style: {
2463 'background-color': '#666',
2464 'label': 'data(label)',
2465 'width': 'label',
2466 'min-zoomed-font-size' : 8,
2467 'text-valign': 'center',
2468 'text-halign': 'center',
2469 'text-wrap': 'wrap',
2470 'shape': function(ele) {
2471 if(ele.data('type') != 'port')
2472 return 'rectangle';
2473 else
2474 return 'ellipse';
2475 },
fdc74cf0 2476
3badc888 2477 }
2478 },
2479 {
2480 selector: '\$node > node',
2481 css: {
2482 'padding-top': '10px',
2483 'padding-left': '10px',
2484 'padding-bottom': '10px',
2485 'padding-right': '10px',
2486 'text-valign': 'top',
2487 'text-halign': 'center',
2488 'background-color': '#bbb',
2489 'min-zoomed-font-size' : 6,
2490 }
2491 },
2492 {
2493 selector: 'edge',
2494 css: {
2495 'target-arrow-shape': 'triangle',
2496 'line-color': function(ele){
2497 if(ele.data('type') == 'front')
2498 return 'black';
2499 else
2500 return 'grey';
2501 },
2502 'line-style': function(ele){
2503 if(ele.data('type') == 'front')
2504 return 'solid';
2505 else
2506 return 'dashed';
2507 },
2508 'width': function(ele){
2509 var ret = 1;
2510 if(ele.data('type') == 'front')
2511 ret = 3;
2512 else
2513 ret = 5;
fdc74cf0 2514
3badc888 2515 if(1)
2516 if(ele.data('linkcount'))
2517 {
2518 ret = (ele.data('linkcount') * ret);
2519 }
fdc74cf0 2520
3badc888 2521 //console.log(ele.data('id') + ret);
2522 return ret;
2523 },
2524// 'curve-style': 'segments',
2525 'font-size': '8',
2526 'min-zoomed-font-size' : 8,
2527 'label': 'data(label)',
2528 'edge-text-rotation': 'autorotate',
2529 'source-arrow-shape': 'none',
2530 'target-arrow-shape': 'none'
2531 }
2532 },
2533 {
2534 selector: '.logical',
2535 css: {
2536 'line-color': '#0000ff',
2537 'width': 5,
2538 'curve-style': 'segments',
2539 'z-index': 0
2540 }
2541 },
2542 {
2543 selector: ':selected',
2544 css: {
2545 'background-color': 'black',
2546 'line-color': 'black',
2547 'target-arrow-color': 'black',
2548 'source-arrow-color': 'black'
2549 }
2550 },
2551 {
2552 selector: '.highlighted',
2553 css: {
2554 'line-color': '#ff0000',
2555 'background-color': '#ff0000'
2556 }
2557 },
2558 {
2559 selector: '.clhighlighted',
2560 css: {
2561 'line-color': '#00ff00',
2562 'background-color': '#00ff00'
2563 }
2564 }
2565 ];
fdc74cf0 2566
3badc888 2567var cylayout = { name: 'dagre', nodeSep: 3, ready: layoutready, stop: layoutstop };
fdc74cf0 2568
3badc888 2569function highlight(evt) {
fdc74cf0 2570
3badc888 2571 //cy = evt.cy;
fdc74cf0 2572
3badc888 2573 var hlclass = evt.data.hlclass;
2574 var ele = evt.cyTarget;
fdc74cf0 2575
3badc888 2576 if(!ele.data)
2577 return;
fdc74cf0 2578
3badc888 2579 if(ele.data('source'))
2580 ele = cy.$( '#' + ele.data('source'));
fdc74cf0 2581
3badc888 2582 var id = ele.data('id');
fdc74cf0 2583
3badc888 2584 if(ele.isParent())
2585 {
2586 // var childs = cy.$('#' + id).children()
2587 // childs.layout({name:'grid', cols: 2, condense: true});
2588 return;
2589 }
fdc74cf0 2590
fdc74cf0 2591
3badc888 2592// console.log('Event ' + hlclass + ' ' + id );
fdc74cf0 2593
3badc888 2594 // remove existing highlights
2595 cy.$('.' + hlclass).removeClass(hlclass);
fdc74cf0 2596
3badc888 2597 var hleles = ele.closedNeighborhood();
fdc74cf0 2598
3badc888 2599 var hlcount = hleles.length;
fdc74cf0 2600
3badc888 2601 // max 100
2602 for(i=0;i<100;i++)
2603 {
2604 hleles = hleles.closedNeighborhood();
fdc74cf0 2605
3badc888 2606 if(hlcount == hleles.length)
2607 break;
fdc74cf0 2608
3badc888 2609 hlcount = hleles.length;
fdc74cf0 2610
3badc888 2611 }
2612 //console.log('End Loop ' + i );
2613 hleles.addClass(hlclass);
fdc74cf0 2614
3badc888 2615// console.log('Event Type: ' + evt.originalEvent.type)
2616// console.log('Event Type: ' + evt.type)
fdc74cf0 2617
3badc888 2618 if(evt.type != 'click')
2619 return;
fdc74cf0 2620
3badc888 2621 var hleles2 = hleles.clone();
2622 hleles2 = hleles2.add(hleles.parents().clone());
fdc74cf0 2623
3badc888 2624 //var cy2 = evt.data.cy2;
fdc74cf0 2625
3badc888 2626 //var ret = evt.data.ret;
fdc74cf0 2627
3badc888 2628 //var j = ret.parents.concat(ret.nodes).concat(ret.edges.nodes);
fdc74cf0 2629
3badc888 2630 cy2.remove(cy2.elements());
2631 cy2.add(hleles2);
2632 //cy2.add(j);
2633 cy2.layout({name: 'dagre', rankDir: 'LR', ready: layoutready});
2634}
fdc74cf0 2635
3badc888 2636function cytoscapeswitch(evt)
2637{
2638 var b = evt.target;
fdc74cf0 2639
3badc888 2640 var j = null;
2641 if(b.value == "1")
2642 {
2643 j = data.parents.concat(data.edges.parents);
2644 b.value = "0";
2645 b.innerHTML = "Ports";
2646 }
2647 else
2648 {
2649 j = data.parents.concat(data.nodes).concat(data.edges.nodes);
2650 b.value = "1";
2651 b.innerHTML = "Objects";
2652 }
fdc74cf0 2653
3badc888 2654 //layout.stop();
2655 cy.remove(cy.elements());
fdc74cf0 2656
3badc888 2657 cy.add(j);
fdc74cf0 2658
3badc888 2659 cy.layout(cylayout);
2660 //layout.run();
2661}
fdc74cf0 2662
3badc888 2663$.ajax({
2664 type: "GET",
2665 url: "{$_SERVER['PHP_SELF']}",
2666 data: { module: 'redirect',
2667 page: 'object',
2668 tab: 'linkmgmt',
2669 object_id: $object_id,
2670 op: 'cytoscapemap',
2671 json: 'json'
2672 },
2673 dataTye: 'json',
2674 error: function(){ alert("Error loading"); },
2675 success: function(jdata) {
2676
2677 data = JSON.parse(jdata);
2678
2679 if(data.debug)
2680 $('#debug').html(data.debug);
2681
2682 //j = data.parents.concat(data.edges.parents);
2683 j = data.parents.concat(data.nodes).concat(data.edges.nodes);
2684
2685 if(j.length == 0)
2686 {
2687 alert("No Links to display. Closing Window");
2688 window.close();
2689 return;
2690 }
fdc74cf0 2691
3badc888 2692 cy2 = cytoscape({
2693 container: document.getElementById('cy2'),
2694 //renderer: { name: 'css' },
2695
2696 boxSelectionEnabled: false,
2697 autounselectify: true,
2698 style: cystyle,
2699 wheelSensitivity: 0.1,
2700 });
2701 cy2.style().selector('node').style('label', function(node) { return node.data('label') + '\\n' + node.data('text'); });
2702
2703 cystyle.push({
2704 selector: '.loopedge',
2705 css: {
2706 'curve-style': 'segments',
2707 }
2708 });
2709
2710 cy = cytoscape({
2711 container: document.getElementById('cy'),
2712
2713 boxSelectionEnabled: false,
2714 autounselectify: true,
2715 style: cystyle,
2716 wheelSensitivity: 0.1,
2717 elements: j,
2718 layout: cylayout,
2719 });
2720
2721 cy.on('mouseover', { hlclass: 'highlighted' }, highlight );
2722 cy.on('click', { hlclass: 'clhighlighted' }, highlight );
2723
2724 $('#switch').click(cytoscapeswitch);
2725
2726 /*
2727 TODO: node ranking
2728 */
2729
2730 if(0)
2731 cy.layout({
2732 name: 'dagre',
2733 /*
2734 nodeSep: 5,
2735 rankDir: 'TB',
2736 */
2737 //edgeSep: 10,
2738 /*
2739 edgeWeight: function(edge) {
2740 if(edge.data('type') == 'front')
2741 return 10;
2742 else
2743 return 1;
2744
2745 },
2746 */
2747 ready: layoutready,
2748 stop: layoutstop
2749 });
2750
2751 if(1)
2752 cy.$(':child').qtip({
2753
2754 content: function() {
2755
2756 return this.id() + '<br>'
2757 + 'Index: ' + this.data('index') + '<br>'
2758 + 'Name: ' + this.data('label') + '<br>'
2759 + 'Text: ' + this.data('text');
2760 },
2761 position: {
2762 my: 'top center',
2763 at: 'bottom center'
2764 },
2765 style: {
2766 classes: 'qtip-bootstrap',
2767 tip: {
2768 width: 16,
2769 height: 8
2770 },
2771 }
2772 }); // qtip
2773 } // success function
2774 });
2775
2776
2777}); // on dom ready
2778
2779function layoutready(evt) {
2780 var _cy = evt.cy;
fdc74cf0 2781
3badc888 2782 // highlight current object
2783 var object = _cy.$('#o$object_id');
2784 if(object.data('has_problems') == 'no')
2785 object.style('background-color','#ffcccc');
fdc74cf0 2786
3badc888 2787 // highlight object with problems
2788 _cy.$('node[type = "object"][has_problems != "no"]').style('background-color','#ff0000');
de3d42dc 2789
3badc888 2790 var e = _cy.$('node[loop = "1"]').style('background-color','#ff6666');
83b49cf7 2791
3badc888 2792// console.log(e[0].data('loop'));
de3d42dc 2793
3badc888 2794// cy.add({group: 'edges', data: {id:'l691_2991', source: 'p691', target: 'p2991', label: 'test'}, classes: 'logical'});
de3d42dc 2795
3badc888 2796}
fdc74cf0 2797
3badc888 2798function layoutstop(evt) {
2799 var _cy = evt.cy;
2800// cy.elements().locked = true;
2801// cy.add({group: 'nodes', data: {id:'l2493', parent:'p2943', label: 'test'}});
fdc74cf0 2802
fdc74cf0 2803
3badc888 2804 var les = _cy.$('[loopedge]');
fdc74cf0 2805
3badc888 2806 if(les)
fdc74cf0 2807 {
3badc888 2808 _cy.batch( function() {
2809 les.each(function(i, ele) {
2810 var le = ele.data('loopedge');
2811 var edge = _cy.add(le);
2812 edge.addClass('loopedge');
2813 //edge.style('line-color', '#ffffff'); // TypeError text-transform undefined
2814 });
2815 });
2816 _cy.$('edge[loop = "1"]').style('line-color','#ff6666');
fdc74cf0 2817 }
3badc888 2818}
2819</script>
2820</head>
2821<body>
2822<div id="cy" style="position: absolute; height: 80%; width: 100%; left: 0; top: 20%;"></div>
2823<div id="cy2" style="position: absolute; height: 20%; width: 100%; left: 0; top: 0%;"></div>
2824<div id="debug"></div>
2825<button type="button" id="switch" style="position: absolute;" value="1">Object</button>
2826</body>
2827</html>
2828HTMLEND
2829); // echo
fdc74cf0 2830 exit;
3badc888 2831}
fdc74cf0 2832
2833/* ------------------------------------- */
2834class linkmgmt_gvmap {
2835
2836 private $object_id = NULL;
2837 private $port_id = NULL;
2838 private $remote_id = NULL;
3badc888 2839 private $hl = NULL;
fdc74cf0 2840
2841 private $gv = NULL;
2842
2843 private $ports = array();
2844
2845 private $allports = false;
2846 private $back = NULL;
2847
adc1e20b 2848 private $alpha = 'ff';
fdc74cf0 2849
2850 private $errorlevel = NULL;
2851
3badc888 2852 public $data = NULL;
2853
2854 private $pids = array();
2855
2856 function addlinkchainsobject($object_id)
2857 {
2858
2859 $object['ports'] = getObjectPortsAndLinks ($object_id);
2860
2861 if(empty($object['ports']))
2862 {
2863
2864 $hl = false;
2865 $alpha = $this->alpha;
2866 if($this->hl == 'o' && $this->object_id == $object_id)
2867 {
2868 $hl = true;
2869 $this->alpha = 'ff';
2870 }
2871
2872 $this->_addCluster($object_id, $hl, empty($object['ports']));
2873
2874 $this->alpha = $alpha;
2875 return;
2876 }
2877
2878 $i = 0;
2879 foreach($object['ports'] as $key => $port)
2880 {
2881
2882 if(isset($this->pids[$port['id']]))
2883 continue;
2884
2885 $i++;
2886 $lc = new lm_linkchain($port['id']);
2887
2888 $this->pids += $lc->pids;
2889
2890 if($this->allports ||($lc->linkcount > 0))
2891 $this->addlinkchain($lc, $i);
2892 }
2893
2894 }
2895
fdc74cf0 2896 function __construct($object_id = NULL, $port_id = NULL, $allports = false, $hl = NULL, $remote_id = NULL) {
2897 $this->allports = $allports;
2898
4eeb9282 2899 $this->object_id = $object_id;
2900 $this->port_id = $port_id;
2901 $this->remote_id = $remote_id;
3badc888 2902 $this->hl = $hl;
fdc74cf0 2903
2904 $hllabel = "";
2905
2906 /* suppress strict standards warnings for Image_GraphViz and PHP 5.4.0
2907 * output would corrupt image data
2908 */
2909 $this->errorlevel = error_reporting();
857ba778 2910 error_reporting($this->errorlevel & ~E_STRICT);
fdc74cf0 2911
2912 $graphattr = array(
3badc888 2913 'rankdir' => 'LR',
fdc74cf0 2914 // 'ranksep' => '0',
2915 'nodesep' => '0',
2916 // 'overlay' => false,
2917 );
2918
2919 unset($_GET['module']);
2920
2921 $_GET['all'] = 1;
2922
2dbca6fb 2923 $graphattr['URL'] = $this->_makeHrefProcess($_GET);
fdc74cf0 2924
2925 unset($_GET['all']);
2926
3badc888 2927 switch($hl)
2928 {
2929 case 'o':
2930 case 'p':
2931 $this->alpha = '30';
2932 break;
2933 }
2934
83b49cf7 2935 //$this->gv = new Image_GraphViz(true, $graphattr, "map".$object_id);
2936 $this->gv = new lm_Image_GraphViz(true, $graphattr, "map".$object_id);
fdc74cf0 2937
3badc888 2938 /* --------------------------- */
fdc74cf0 2939 if($object_id === NULL)
2940 {
4eeb9282 2941 /* all objects ! */
fdc74cf0 2942 unset($_GET['all']);
2943 $_GET['hl'] = 'o';
2944
2945 $this->gv->addAttributes(array(
2946 'label' => 'Showing all objects'.$hllabel,
2947 'labelloc' => 't',
2948 )
2949 );
2950
2951 $objects = listCells('object');
2952
2953 foreach($objects as $obj)
3badc888 2954 //$this->addlinkchainsobject($obj['id']); // longer runtimes !!
2955 $this->_add($this->gv, $obj['id'], NULL); // for all still faster and nicer looking graph
4eeb9282 2956
2957 return;
fdc74cf0 2958 }
2959 else
2960 {
2961 $object = spotEntity ('object', $object_id);
2962
2963 $this->gv->addAttributes(array(
2964 'label' => "Graph for ${object['dname']}$hllabel",
2965 'labelloc' => 't',
2966 )
2967 );
2968
3badc888 2969 $this->addlinkchainsobject($object_id);
2970 //$this->_add($this->gv, $object_id, $port_id);
fdc74cf0 2971
2972 $children = getEntityRelatives ('children', 'object', $object_id); //'entity_id'
2973
2974 foreach($children as $child)
3badc888 2975 $this->addlinkchainsobject($child['entity_id']);
2976 // $this->_add($this->gv, $child['entity_id'], NULL);
fdc74cf0 2977 }
2978
4eeb9282 2979 /* add hl label */
2980 $this->gv->addAttributes(array(
2981 'label' => $this->gv->graph['attributes']['label'].$hllabel,
2982 ));
2983
fdc74cf0 2984 // portlist::var_dump_html($this->gv);
3badc888 2985// portlist::var_dump_html($this->data);
2986
2987// echo json_encode($this->data);
fdc74cf0 2988
83b49cf7 2989 // $this->gv->saveParsedGraph('/tmp/graph.txt');
fdc74cf0 2990 // error_reporting( E_ALL ^ E_NOTICE);
2991 } /* __construct */
2992
2993 function __destruct() {
2994 error_reporting($this->errorlevel);
2995 }
2996
3badc888 2997 function _addCluster($object_id, $hl = false, $adddummy = false)
2998 {
2999 global $lc_cache;
3000
3001 $cluster_id = "c".$object_id;
3002
3003 if(
3004 !isset($this->gv->graph['clusters'][$cluster_id]) &&
3005 !isset($this->gv->graph['subgraphs'][$cluster_id])
3006 || $hl
3007 ) {
3008 $rack = null;
3009 $object = $lc_cache->getobject($object_id, $rack);
3010
3011 // $object['attr'] = getAttrValues($object_id);
3012
3013 $clusterattr = array();
3014
3015 $this->_getcolor('cluster', 'default', $this->alpha, $clusterattr, 'color');
3016 $this->_getcolor('cluster', 'default', $this->alpha, $clusterattr, 'fontcolor');
3017
3018 if($this->object_id == $object_id)
3019 {
3020 $clusterattr['rank'] = 'source';
3021
3022 $this->_getcolor('cluster', 'current', $this->alpha, $clusterattr, 'color');
3023 $this->_getcolor('cluster', 'current', $this->alpha, $clusterattr, 'fontcolor');
3024 }
3025
3026 $clustertitle = htmlspecialchars($object['dname']);
3027 $clusterattr['tooltip'] = $clustertitle;
3028
3029 unset($_GET['module']); // makeHrefProcess adds this
3030 unset($_GET['port_id']);
3031 unset($_GET['remote_id']);
3032 $_GET['object_id'] = $object_id;
3033 //$_GET['hl'] = 'o';
3034
3035 $clusterattr['URL'] = $this->_makeHrefProcess($_GET);
3036
3037 //has_problems
3038 if($object['has_problems'] != 'no')
3039 {
3040 $clusterattr['style'] = 'filled';
3041 $this->_getcolor('cluster', 'problem', $this->alpha, $clusterattr, 'fillcolor');
3042 }
3043
3044 if(!empty($object['container_name']))
3045 $clustertitle .= "<BR/>(${object['container_name']})";
3046
3047 if(!empty($rack['row_name']) || !empty($rack['name']))
3048 $clustertitle .= "<BR/><FONT point-size=\"10\">{$rack['row_name']} / {$rack['name']}</FONT>";
3049
3050 $embedin = $object['container_id'];
3051 if(empty($embedin))
3052 $embedin = 'default';
3053 else
3054 {
3055 $embedin = "c$embedin"; /* see cluster_id */
3056
3057 // TODO
3058 /* add container / cluster if not already exists */
3059 $this->addlinkchainsobject($object['container_id']);
3060 }
3061
3062 $clusterattr['id'] = "$object_id----"; /* used for js context menu */
3063
3064 $this->gv->addCluster($cluster_id, $clustertitle, $clusterattr, $embedin);
3065
3066 /* needed because of gv_image empty cluster bug (invalid foreach argument) */
3067 if($adddummy)
3068 $this->gv->addNode("dummy$cluster_id", array(
3069 // 'label' =>'No Ports found/connected',
3070 'label' =>'',
3071 'fontsize' => 0,
3072 'size' => 0,
3073 'width' => 0,
3074 'height' => 0,
3075 'shape' => 'point',
3076 'style' => 'invis',
3077 ), $cluster_id);
3078
3079
3080 }
3081 } // _addCluster
3082
3083 function _addEdge($port, $linkchain, $loopedge = false)
3084 {
3085 global $lm_multilink_port_types;
3086 if(
3087 !isset($this->gv->graph['edgesFrom'][$port['id']][$port['remote_id']]) &&
3088 !isset($this->gv->graph['edgesFrom'][$port['remote_id']][$port['id']])
3089 || $loopedge
3090 ) {
3091 $remote_id = $port['remote_id'];
3092
3093 $linktype = $port['linktype'];
3094
3095 $edgetooltip = $port['object_name'].':'.$port['name'].
3096 ' - '.$port['cableid'].' -> '.
3097 $port['remote_name'].':'.$port['remote_object_name'];
3098
3099 $edgeattr = array(
3100 'fontsize' => 8,
3101 'label' => htmlspecialchars($port['cableid']),
3102 'tooltip' => $edgetooltip,
3103 'sametail' => $linktype,
3104 'samehead' => $linktype,
3105 'arrowhead' => 'none',
3106 'arrowtail' => 'none',
3107 );
3108
3109 $this->_getcolor('edge', ($linkchain->loop ? 'loop' : 'default'), $this->alpha, $edgeattr, 'color');
3110 $this->_getcolor('edge', 'default', $this->alpha, $edgeattr, 'fontcolor');
3111
3112 if($linktype == 'back' )
3113 {
3114 $edgeattr['style'] = 'dashed';
3115
3116 /* multilink ports */
3117 if(in_array($port['oif_id'], $lm_multilink_port_types))
3118 {
3119 $edgeattr['dir'] = 'both';
3120 $edgeattr['arrowtail'] = 'dot';
3121 }
3122
3123 if(in_array($linkchain->ports[$remote_id]['oif_id'], $lm_multilink_port_types))
3124 {
3125 $edgeattr['dir'] = 'both';
3126 $edgeattr['arrowhead'] = 'dot';
3127 }
3128 }
3129
3130 if(
3131 ($port['id'] == $this->port_id && $port['remote_id'] == $this->remote_id) ||
3132 ($port['id'] == $this->remote_id && $port['remote_id'] == $this->port_id)
3133 )
3134 {
3135 $this->_getcolor('edge', 'highlight', 'ff', $edgeattr, 'color');
3136 $edgeattr['penwidth'] = 2; /* bold */
3137 }
3138
3139 unset($_GET['module']);
3140 $_GET['object_id'] = $port['object_id'];
3141 $_GET['port_id'] = $port['id'];
3142 $_GET['remote_id'] = $port['remote_id'];
3143
3144 $edgeattr['URL'] = $this->_makeHrefProcess($_GET);
3145
3146 $edgeattr['id'] = $port['object_id']."-".$port['id']."-".$port['remote_id']."-".$linktype; /* for js context menu */
3147
3148 if($loopedge)
3149 {
3150 $edgeattr = array_merge($edgeattr, array(
3151 'sametail' => 'loop',
3152 'samehead' => 'loop',
3153 'dir' => 'both',
3154 'arrowhead' => 'invodot',
3155 'arrowtail' => 'invodot',
3156 ));
3157 }
3158
3159 $this->gv->addEdge(array($port['id'] => $port['remote_id']),
3160 $edgeattr,
3161 array(
3162 $port['id'] => $linktype,
3163 $port['remote_id'] => $linktype,
3164 )
3165 );
3166
3167 }
3168 } // _addEdge
3169
3170 function addlinkchain($linkchain, $index)
3171 {
3172 global $lm_multilink_port_types;
3173
3174 $hl = false;
3175 $alpha = $this->alpha;
3176 if(
3177 ($this->hl == 'p' && $linkchain->hasport_id($this->port_id))
3178 || ($this->hl == 'o' && $linkchain->hasobject_id($this->object_id))
3179 )
3180 {
3181 $hl = true;
3182 $this->alpha = 'ff';
3183 }
3184
3185 $remote_id = null;
3186 foreach($linkchain as $id => $port)
3187 {
3188 $this->_addCluster($port['object_id'], $hl);
3189
3190 $nodelabel = htmlspecialchars("${port['name']}");
3191 $text = $nodelabel;
3192
3193 if($port['iif_id'] != '1' )
3194 {
3195 $nodelabel .= "<BR/><FONT POINT-SIZE=\"8\">${port['iif_name']}</FONT>";
3196 $text .= "\n".$port['iif_name'];
3197 }
3198
3199 $nodelabel .= "<BR/><FONT POINT-SIZE=\"8\">${port['oif_name']}</FONT>";
3200 $text .= "\n".$port['oif_name'];
3201
3202 // add ip address
3203 if(isset($port['portip']))
3204 $nodelabel .= "<BR/><FONT POINT-SIZE=\"8\">".$port['portip']."</FONT>";
3205
3206 $nodeattr = array(
3207 'label' => $nodelabel,
3208 );
3209
3210 $this->_getcolor('port', ($linkchain->loop ? 'loop' : 'default'),$this->alpha, $nodeattr, 'fontcolor');
3211 $this->_getcolor('oif_id', $port['oif_id'],$this->alpha, $nodeattr, 'color');
3212
3213 if($this->port_id == $port['id']) {
3214 $nodeattr['style'] = 'filled';
3215 $nodeattr['fillcolor'] = $this->_getcolor('port', 'current', $this->alpha);
3216 }
3217
3218 if($this->remote_id == $port['id']) {
3219 $nodeattr['style'] = 'filled';
3220 $nodeattr['fillcolor'] = $this->_getcolor('port', 'remote', $this->alpha);
3221 }
3222
3223 $nodeattr['tooltip'] = htmlspecialchars("${port['name']}");
3224
3225 unset($_GET['module']);
3226 unset($_GET['remote_id']);
3227 $_GET['object_id'] = $port['object_id'];
3228 $_GET['port_id'] = $port['id'];
3229 $_GET['hl'] = 'p';
3230
3231 $nodeattr['URL'] = $this->_makeHrefProcess($_GET);
3232 $nodeattr['id'] = "${port['object_id']}-${port['id']}--"; /* for js context menu */
3233
3234 $this->gv->addNode($port['id'],
3235 $nodeattr,
3236 "c${port['object_id']}"); /* see cluster_id */
3237
3238 $remote_id = $port['remote_id'];
3239
3240 if($port['portcount'] > 1)
3241 foreach($port['chains'] as $mlc)
3242 {
3243 $this->addlinkchain($mlc, 0); // TODO index
3244 }
3245
3246 $prevlinktype = ($port['linktype'] == 'front' ? 'back' : 'front');
3247 if($port[$prevlinktype]['portcount'] > 1)
3248 {
3249 foreach($port[$prevlinktype]['chains'] as $mlc)
3250 {
3251 $this->addlinkchain($mlc, 0, false); // TODO index
3252 }
3253 }
3254
3255 if($remote_id)
3256 $this->_addEdge($port, $linkchain);
3257
3258 } //foreach
3259
3260 if($linkchain->loop && $remote_id)
3261 {
3262 // TODO separate loop link
3263 // add loop edge
3264 $this->_addEdge($port, $linkchain, true);
3265 }
3266
3267 // reset alpha to start value
3268 $this->alpha = $alpha;
3269 }
3270
de3d42dc 3271 function setFalseOnError($newvalue)
3272 {
3273 $this->gv->_returnFalseOnError = $newvalue;
3274 }
3275
2dbca6fb 3276 function _makeHrefProcess($array)
3277 {
3278 return str_replace('&','&amp;',makeHrefProcess($array));
3279 }
3280
fdc74cf0 3281 // !!!recursiv !!!
3282 function _add($gv, $object_id, $port_id = NULL) {
3283 global $lm_multilink_port_types;
3284
4eeb9282 3285 if($port_id !== NULL) {
3286 if(isset($this->ports[$port_id])) {
fdc74cf0 3287 return;
4eeb9282 3288 }
fdc74cf0 3289 }
3290
2d257b3a 3291 if($this->back != 'front' || $port_id === NULL || $this->allports)
3292 $front = $this->_getObjectPortsAndLinks($object_id, 'front', $port_id, $this->allports);
3293 else
3294 $front = array();
3295
3296 if($this->back != 'back' || $port_id === NULL || $this->allports)
3297 $backend = $this->_getObjectPortsAndLinks($object_id, 'back', $port_id, $this->allports);
3298 else
3299 $backend = array();
3300
3301 $ports = array_merge($front,$backend);
3302
630a86c8 3303 /* used only for Graphviz ...
3304 * !! numeric ids cause Image_Graphviz problems on nested clusters !!
3305 */
3306 $cluster_id = "c$object_id";
3307
2d257b3a 3308 if(empty($ports))
3309 {
3310 /* needed because of gv_image empty cluster bug (invalid foreach argument) */
da6d05d0 3311 $gv->addNode("dummy$cluster_id", array(
2d257b3a 3312 // 'label' =>'No Ports found/connected',
3313 'label' =>'',
3314 'fontsize' => 0,
3315 'size' => 0,
3316 'width' => 0,
3317 'height' => 0,
3318 'shape' => 'point',
3319 'style' => 'invis',
3320 ), $cluster_id);
3321
3322 /* show objects without ports */
3323 if($object_id === NULL)
3324 return;
3325 }
3326
3badc888 3327 $object = NULL;
2d257b3a 3328 if($object_id !== NULL) {
4eeb9282 3329 if(
3330 !isset($gv->graph['clusters'][$cluster_id]) &&
3331 !isset($gv->graph['subgraphs'][$cluster_id])
3332 ) {
fdc74cf0 3333
4eeb9282 3334 $object = spotEntity ('object', $object_id);
3badc888 3335
3336 // ip addresses
3337 amplifyCell($object);
3338 $object['portip'] = array();
3339 foreach($object['ipv4'] as $ipv4)
3340 {
3341 $object['portip'][$ipv4['osif']] = $ipv4['addrinfo']['ip'];
3342 }
3343
4eeb9282 3344 // $object['attr'] = getAttrValues($object_id);
fdc74cf0 3345
4eeb9282 3346 $clusterattr = array();
fdc74cf0 3347
4eeb9282 3348 $this->_getcolor('cluster', 'default', $this->alpha, $clusterattr, 'color');
3349 $this->_getcolor('cluster', 'default', $this->alpha, $clusterattr, 'fontcolor');
fdc74cf0 3350
4eeb9282 3351 if($this->object_id == $object_id)
3352 {
3353 $clusterattr['rank'] = 'source';
fdc74cf0 3354
4eeb9282 3355 $this->_getcolor('cluster', 'current', $this->alpha, $clusterattr, 'color');
3356 $this->_getcolor('cluster', 'current', $this->alpha, $clusterattr, 'fontcolor');
3357 }
fdc74cf0 3358
4eeb9282 3359 $clustertitle = "${object['dname']}";
3badc888 3360 $text = "${object['dname']}";
4eeb9282 3361 $clusterattr['tooltip'] = $clustertitle;
fdc74cf0 3362
4eeb9282 3363 unset($_GET['module']); // makeHrefProcess adds this
3364 unset($_GET['port_id']);
3365 unset($_GET['remote_id']);
3366 $_GET['object_id'] = $object_id;
3367 //$_GET['hl'] = 'o';
fdc74cf0 3368
2dbca6fb 3369 $clusterattr['URL'] = $this->_makeHrefProcess($_GET);
fdc74cf0 3370
4eeb9282 3371 //has_problems
3372 if($object['has_problems'] != 'no')
3373 {
3374 $clusterattr['style'] = 'filled';
3375 $this->_getcolor('cluster', 'problem', $this->alpha, $clusterattr, 'fillcolor');
3376 }
fdc74cf0 3377
4eeb9282 3378 if(!empty($object['container_name']))
3badc888 3379 {
4eeb9282 3380 $clustertitle .= "<BR/>${object['container_name']}";
3badc888 3381 $text .= "\n${object['container_name']}";
3382 }
fdc74cf0 3383
4eeb9282 3384 if($object['rack_id'])
3385 {
3386 $rack = spotEntity('rack', $object['rack_id']);
fdc74cf0 3387
4eeb9282 3388 if(!empty($rack['row_name']) || !empty($rack['name']))
3badc888 3389 {
4eeb9282 3390 $clustertitle .= "<BR/>${rack['row_name']} / ${rack['name']}";
3badc888 3391 $text .= "\n${rack['row_name']} / ${rack['name']}";
3392 }
4eeb9282 3393 }
3394
3395 $embedin = $object['container_id'];
3396 if(empty($embedin))
3397 $embedin = 'default';
3398 else
3399 {
3400 $embedin = "c$embedin"; /* see cluster_id */
3401
3402 /* add container / cluster if not already exists */
3403 $this->_add($gv, $object['container_id'], NULL);
3404 }
fdc74cf0 3405
2d257b3a 3406 $clusterattr['id'] = "$object_id----"; /* used for js context menu */
fdc74cf0 3407
2d257b3a 3408 $gv->addCluster($cluster_id, $clustertitle, $clusterattr, $embedin);
fdc74cf0 3409
2d257b3a 3410 } /* isset cluster_id */
3411 } /* object_id !== NULL */
fca4e38a 3412
fdc74cf0 3413 foreach($ports as $key => $port) {
3414
3415 $this->back = $port['linktype'];
3416
4eeb9282 3417 if(!isset($this->ports[$port['id']])) {
fdc74cf0 3418
fdc74cf0 3419
c613fc73 3420 $nodelabel = htmlspecialchars("${port['name']}");
3badc888 3421 $text = $nodelabel;
fdc74cf0 3422
4eeb9282 3423 if($port['iif_id'] != '1' )
3badc888 3424 {
4eeb9282 3425 $nodelabel .= "<BR/><FONT POINT-SIZE=\"8\">${port['iif_name']}</FONT>";
3badc888 3426 $text .= "\n".$port['iif_name'];
3427 }
fdc74cf0 3428
4eeb9282 3429 $nodelabel .= "<BR/><FONT POINT-SIZE=\"8\">${port['oif_name']}</FONT>";
3badc888 3430 $text .= "\n".$port['oif_name'];
3431
3432 // add ip address
3433 if($object)
3434 if(isset($object['portip'][$port['name']]))
3435 {
3436 $nodelabel .= "<BR/><FONT POINT-SIZE=\"8\">".$object['portip'][$port['name']]."</FONT>";
3437 $text .= "\n".$object['portip'][$port['name']];
3438 }
fdc74cf0 3439
4eeb9282 3440 $nodeattr = array(
3441 'label' => $nodelabel,
3442 );
fdc74cf0 3443
4eeb9282 3444 $this->_getcolor('port', 'default',$this->alpha, $nodeattr, 'fontcolor');
3445 $this->_getcolor('oif_id', $port['oif_id'],$this->alpha, $nodeattr, 'color');
fdc74cf0 3446
4eeb9282 3447 if($this->port_id == $port['id']) {
3448 $nodeattr['style'] = 'filled';
3449 $nodeattr['fillcolor'] = $this->_getcolor('port', 'current', $this->alpha);
3450 }
fdc74cf0 3451
4eeb9282 3452 if($this->remote_id == $port['id']) {
3453 $nodeattr['style'] = 'filled';
3454 $nodeattr['fillcolor'] = $this->_getcolor('port', 'remote', $this->alpha);
3455 }
3456
c613fc73 3457 $nodeattr['tooltip'] = htmlspecialchars("${port['name']}");
4eeb9282 3458
3459 unset($_GET['module']);
3460 unset($_GET['remote_id']);
3461 $_GET['object_id'] = $port['object_id'];
3462 $_GET['port_id'] = $port['id'];
3463 $_GET['hl'] = 'p';
fdc74cf0 3464
2dbca6fb 3465 $nodeattr['URL'] = $this->_makeHrefProcess($_GET);
4eeb9282 3466 $nodeattr['id'] = "${port['object_id']}-${port['id']}--"; /* for js context menu */
fdc74cf0 3467
4eeb9282 3468 $gv->addNode($port['id'],
fdc74cf0 3469 $nodeattr,
3470 "c${port['object_id']}"); /* see cluster_id */
3471
4eeb9282 3472 $this->ports[$port['id']] = true;
2d257b3a 3473
4eeb9282 3474 } /* isset port */
fdc74cf0 3475
3476 if(!empty($port['remote_id'])) {
3477
bb000ce6 3478 if($this->object_id !== NULL)
3479 $this->_add($gv, $port['remote_object_id'], $port['remote_id']);
fdc74cf0 3480
3481 if(
3482 !isset($gv->graph['edgesFrom'][$port['id']][$port['remote_id']]) &&
3483 !isset($gv->graph['edgesFrom'][$port['remote_id']][$port['id']])
3484 ) {
3485
3486 $linktype = $port['linktype'];
3487
3488 $edgetooltip = $port['object_name'].':'.$port['name'].
3489 ' - '.$port['cableid'].' -> '.
3490 $port['remote_name'].':'.$port['remote_object_name'];
3491
3492 $edgeattr = array(
3493 'fontsize' => 8,
c613fc73 3494 'label' => htmlspecialchars($port['cableid']),
fdc74cf0 3495 'tooltip' => $edgetooltip,
3496 'sametail' => $linktype,
3497 'samehead' => $linktype,
3498 );
3499
3500 $this->_getcolor('edge', 'default', $this->alpha, $edgeattr, 'color');
3501 $this->_getcolor('edge', 'default', $this->alpha, $edgeattr, 'fontcolor');
3502
3503 if($linktype == 'back' )
3504 {
3505 $edgeattr['style'] = 'dashed';
3506 $edgeattr['arrowhead'] = 'none';
3507 $edgeattr['arrowtail'] = 'none';
3508
3509 /* multilink ports */
3510 if(in_array($port['oif_id'], $lm_multilink_port_types))
3511 {
3512 $edgeattr['dir'] = 'both';
3513 $edgeattr['arrowtail'] = 'dot';
3514 }
3515
3516 if(in_array($port['remote_oif_id'], $lm_multilink_port_types))
3517 {
3518 $edgeattr['dir'] = 'both';
3519 $edgeattr['arrowhead'] = 'dot';
3520 }
3521 }
3522
3523 if(
3524 ($port['id'] == $this->port_id && $port['remote_id'] == $this->remote_id) ||
3525 ($port['id'] == $this->remote_id && $port['remote_id'] == $this->port_id)
3526 )
3527 {
3528 $this->_getcolor('edge', 'highlight', 'ff', $edgeattr, 'color');
3529 $edgeattr['penwidth'] = 2; /* bold */
3530 }
3531
3532 unset($_GET['module']);
3533 $_GET['object_id'] = $port['object_id'];
3534 $_GET['port_id'] = $port['id'];
3535 $_GET['remote_id'] = $port['remote_id'];
3536
2dbca6fb 3537 $edgeattr['URL'] = $this->_makeHrefProcess($_GET);
fdc74cf0 3538
3539 $edgeattr['id'] = $port['object_id']."-".$port['id']."-".$port['remote_id']."-".$linktype; /* for js context menu */
3540
3541 $gv->addEdge(array($port['id'] => $port['remote_id']),
3542 $edgeattr,
3543 array(
3544 $port['id'] => $linktype,
3545 $port['remote_id'] => $linktype,
3546 )
3547 );
3badc888 3548
fdc74cf0 3549 }
3550 }
3551
3552 }
3553
3554 // portlist::var_dump_html($port);
3555 }
3556
83b49cf7 3557 function fetch($type = 'png', $command = NULL, $format2 = NULL, &$data2 = NULL) {
3558
3559 $tmpdata = $data2;
3560 $ret = $this->gv->fetch($type, $command, $format2, $tmpdata);
3561 if($data2 !== NULL)
3562 $data2 = $tmpdata;
fdc74cf0 3563 return $ret;
3564 }
3565
3566 function image($type = 'png', $command = NULL) {
3567 $this->gv->image($type, $command);
3568 }
3569
3570 function parse() {
3571 return $this->gv->parse();
3572 }
3573
3574 /* should be compatible with getObjectPortsAndLinks from RT database.php */
3575 function _getObjectPortsAndLinks($object_id, $linktype = 'front', $port_id = NULL, $allports = false) {
3576
3577 if($linktype == 'front')
3578 $linktable = 'Link';
3579 else
3580 $linktable = 'LinkBackend';
3581
3582 $qparams = array();
3583
3584 $query = "SELECT
3585 '$linktype' as linktype,
3586 Port.*,
3587 Port.type AS oif_id,
3588 PortInnerInterface.iif_name as iif_name,
262da468 3589 POI.oif_name as oif_name,
fdc74cf0 3590 Object.id as object_id, Object.name as object_name,
2a5cd259 3591 IFNULL(LinkTable_a.cable,LinkTable_b.cable) as cableid,
fdc74cf0 3592 remoteObject.id as remote_object_id, remoteObject.name as remote_object_name,
3593 remotePort.id as remote_id, remotePort.name as remote_name,
3594 remotePort.type AS remote_oif_id,
3595 remotePortInnerInterface.iif_name as remote_iif_name,
262da468 3596 remotePOI.oif_name as remote_oif_name
fdc74cf0 3597 FROM Port";
3598
3599 // JOIN
3600 $join = " LEFT JOIN PortInnerInterface on PortInnerInterface.id = Port.iif_id
262da468 3601 LEFT JOIN PortOuterInterface AS POI on POI.id = Port.type
2be16f85 3602 LEFT JOIN $linktable as LinkTable_a on Port.id = LinkTable_a.porta
2a5cd259 3603 LEFT JOIN $linktable as LinkTable_b on Port.id = LinkTable_b.portb
fdc74cf0 3604 LEFT JOIN Object on Object.id = Port.object_id
2a5cd259 3605 LEFT JOIN Port as remotePort on remotePort.id = IFNULL(LinkTable_a.portb, LinkTable_b.porta)
fdc74cf0 3606 LEFT JOIN Object as remoteObject on remoteObject.id = remotePort.object_id
3607 LEFT JOIN PortInnerInterface as remotePortInnerInterface on remotePortInnerInterface.id = remotePort.iif_id
262da468 3608 LEFT JOIN PortOuterInterface as remotePOI on remotePOI.id = remotePort.type
fdc74cf0 3609 ";
3610
3611 // WHERE
3612 if($port_id === NULL)
3613 {
3614 $where = " WHERE Object.id = ?";
3615 $qparams[] = $object_id;
3616
09749fb9 3617 if(!$allports) {
fdc74cf0 3618 $where .= " AND remotePort.id is not NULL";
09749fb9 3619
3620 if($linktype != 'front') {
2a5cd259 3621 $join .= "
3622 LEFT JOIN Link as FrontLink_a on Port.id = FrontLink_a.porta
3623 LEFT JOIN Link as FrontLink_b on Port.id = FrontLink_b.portb
3624 LEFT JOIN Link as FrontRemoteLink_a on remotePort.id = FrontRemoteLink_a.porta
3625 LEFT JOIN Link as FrontRemoteLink_b on remotePort.id = FrontRemoteLink_b.portb
09749fb9 3626 ";
2a5cd259 3627 $where .= " AND ( (FrontLink_a.porta is not NULL or FrontLink_b.portb is not NULL )
3628 OR (FrontRemoteLink_a.porta is not NULL or FrontRemoteLink_b.portb is not NULL) )";
09749fb9 3629 }
3630 }
fdc74cf0 3631 }
3632 else
3633 {
3634 // $where = " WHERE Port.id = ? and remotePort.id is not NULL";
3635 $where = " WHERE Port.id = ?";
3636 $qparams[] = $port_id;
3637 }
3638
3639 // ORDER
3640 $order = " ORDER by oif_name, Port.Name";
3641
3642 $query .= $join.$where.$order;
3643
2a5cd259 3644 //echo "$port_id: $query<br><br>";
3645
fdc74cf0 3646 $result = usePreparedSelectBlade ($query, $qparams);
3647
3648 $row = $result->fetchAll(PDO::FETCH_ASSOC);
3649
3650 $result->closeCursor();
3651
3652 return $row;
3653 }
3654
3655 function _getcolor($type = 'object', $key = 'default', $alpha = 'ff', &$array = NULL , $arraykey = 'color') {
3656
3657 $object = array(
3658 'current' => '#ff0000',