Update graph.php
[racktables-contribs] / python-graph-topology / graph.php
1 <?php
2 // =====================================
3 // Frontend for GraphTopo python script
4 // =====================================
5 //
6 // Author: Lucas Scola
7 // e-mail: lucas.scola@hotmail.com.ar
8 //
9 // Version: 1.0
10 //
11 // =====================================
12 // Changelog:
13 //
14 // *1.0: First implementation.
15 //
16
17
18 //Inserting plugin page into RackTables index
19 global $indexlayout;
20 global $page;
21 global $tab;
22 global $tabHandler;
23 global $image;
24
25 array_push($indexlayout, array('graphtopo'));
26
27 $page['graphtopo']['title'] = 'Topology';
28 $page['graphtopo']['parent'] = 'index';
29
30 $tab['graphtopo']['default'] = 'View';
31 registerTabHandler ('graphtopo', 'default', 'renderGraphTopo');
32
33 $image['graphtopo']['path'] = 'pix/logo.png';
34 $image['graphtopo']['width'] = 218;
35 $image['graphtopo']['height'] = 200;
36
37 function renderGraphTopo()
38 {
39 //variables intialization:
40 $topo = $router_mode = $out = $svgName = "";
41 $exitCode= -2;
42 $scriptOutput = array();
43
44 //check if it's a POST method:
45 if ($_SERVER["REQUEST_METHOD"] == "POST") {
46 //take the arguments from HTML form:
47 $topo = $_POST["topo"];
48 $router_mode = $_POST["router_mode"];
49 $out = $_POST["out"];
50 }
51 ?>
52 <div class="settings" style="width: 98%;padding-top:10px;margin: auto;overflow: hidden;">
53 <!-- HTML menu formatting -->
54 <div class="parameters" style="float:left;clear:both;">
55 <form method="post" action="">
56 <fieldset>
57 <legend> Parameters:</legend>
58 Topology: <input type="text" name="topo" value="<?php echo $topo;?>"> <br>
59 Router_mode: <select name="router_mode">
60 <option <?php if ($router_mode == "0") {?>selected="true" <?php }; ?>value="0">Router as cluster</option>
61 <option <?php if ($router_mode == "1") {?>selected="true" <?php }; ?>value="1">Router as node, one-line</option>
62 <option <?php if ($router_mode == "2") {?>selected="true" <?php }; ?>value="2">Router as node, two-line</option>
63 <option <?php if ($router_mode == "3") {?>selected="true" <?php }; ?>value="3">Router as node, only with name</option>
64 </select> <br>
65 Output action: <select name="out">
66 <option <?php if ($out == "0") {?>selected="true" <?php }; ?>value="0">Default0</option>
67 <option <?php if ($out == "1") {?>selected="true" <?php }; ?>value="1">Default1</option>
68 <option <?php if ($out == "2") {?>selected="true" <?php }; ?>value="2">Default2</option>
69 <option <?php if ($out == "3") {?>selected="true" <?php }; ?>value="3">Default3</option>
70 <option <?php if ($out == "4") {?>selected="true" <?php }; ?>value="4">Default4</option>
71 <option <?php if ($out == "5") {?>selected="true" <?php }; ?>value="5">Default5</option>
72 <option <?php if ($out == "6") {?>selected="true" <?php }; ?>value="6">Default6</option>
73 <option <?php if ($out == "7") {?>selected="true" <?php }; ?>value="7">Default7</option>
74 </select> <br>
75 <input type="submit" value="Execute">
76 </fieldset>
77 </form>
78 </div>
79
80 <div class="info" style="float:right;border: 1px dashed;padding: 5px;">
81 <p>Output Action:</p>
82 <ul>
83 <li>Default0: DOT, Left-to-Right, curved, group-mid-high-ran</li>
84 <li>Default1: DOT, Top-to-Bottom, curved, group-mid-high-ran</li>
85 <li>Default2: FDP, Top-to-Bottom, curved, no-grouping</li>
86 <li>Default3: DOT, Top-to-Bottom, curved, no-grouping</li>
87 <li>Default4: CIRCO, Top-to-Bottom, curved, no-grouping</li>
88 <li>Default5: CIRCO, Left-to-rigth, curved, no-grouping</li>
89 <li>Default6: TWOPI, Left-to-rigth, curved, no-grouping</li>
90 <li>Default7: NEATO, Left-to-rigth, curved, no-grouping</li>
91 </ul>
92 </div>
93 </div>
94 <div class="result" style="width: 98%;margin: auto;">
95 <!-- Results display -->
96 <h2>Topology:</h2>
97 <?php
98
99 if ($_SERVER["REQUEST_METHOD"] == "POST") {
100 if (empty($topo)) //Python script needs this parameter in order to work
101 {
102 echo "<p> Please specify the desired topology.</p>";
103 } else
104 {
105 exec("python ../plugins/draw_topology.py " . $topo . " " . $router_mode . " " . $out, $scriptOutput, $exitCode); //PHP waits until the called program is done
106
107 switch($exitCode)
108 {
109 case 255:
110 echo "<h3>Topology not found!</h3>";
111 echo "<img src=\"pix/not.gif\">";
112 break;
113 case 0:
114 echo "<img class=\"topo\" style=\"margin: auto;display: block;max-height: 100%;max-width: 80%;height: auto;\" src=\"" . $scriptOutput[count($scriptOutput)-1] . "\">";
115 break;
116 }
117 }
118
119 }
120 ?>
121 </div>
122 <?php
123 }
124 ?>