Added some code cleanup.
[racktables] / wwwroot / inc / slb-interface.php
CommitLineData
defd92d8
AA
1<?php
2
cddbb9fd
DO
3# This file is a part of RackTables, a datacenter and server room management
4# framework. See accompanying file "COPYING" for the full copyright and
5# licensing information.
6
defd92d8
AA
7function renderSLBDefConfig()
8{
9 $defaults = getSLBDefaults ();
10 startPortlet ('SLB default configs');
11 echo '<table cellspacing=0 cellpadding=5 align=center>';
12 printOpFormIntro ('save');
13 echo '<tr><th class=tdright>VS config</th><td colspan=2><textarea tabindex=103 name=vsconfig rows=10 cols=80>' . htmlspecialchars($defaults['vs']) . '</textarea></td>';
14 echo '<td rowspan=2>';
15 printImageHREF ('SAVE', 'Save changes', TRUE);
16 echo '</td></tr>';
17 echo '<tr><th class=tdright>RS config</th><td colspan=2><textarea tabindex=104 name=rsconfig rows=10 cols=80>' . htmlspecialchars($defaults['rs']) . '</textarea></td></tr>';
18 echo '</form></table>';
19 finishPortlet();
20}
21
22function renderSLBEntityCell ($cell, $highlighted = FALSE)
23{
24 $class = "slbcell realm-${cell['realm']} id-${cell['id']}";
6c7a45b4 25 $a_class = $highlighted ? 'highlight' : '';
defd92d8
AA
26
27 echo "<table class='$class'>";
28 switch ($cell['realm']) {
29 case 'object':
30 echo "<tr><td><a class='$a_class' href='index.php?page=object&object_id=${cell['id']}'>${cell['dname']}</a>";
31 echo "</td></tr><tr><td>";
32 printImageHREF ('LB');
33 echo "</td></tr>";
34 break;
35 case 'ipv4vs':
36 echo "<tr><td rowspan=3 width='5%'>";
37 printImageHREF ('VS');
38 echo "</td><td>";
39 echo "<a class='$a_class' href='index.php?page=ipv4vs&vs_id=${cell['id']}'>";
40 echo $cell['dname'] . "</a></td></tr><tr><td>";
41 echo $cell['name'] . '</td></tr>';
42 break;
43 case 'ipv4rspool':
44 echo "<tr><td>";
45 echo "<a class='$a_class' href='index.php?page=ipv4rspool&pool_id=${cell['id']}'>";
46 echo !strlen ($cell['name']) ? "ANONYMOUS pool [${cell['id']}]" : niftyString ($cell['name']);
47 echo "</a></td></tr><tr><td>";
48 printImageHREF ('RS pool');
49 if ($cell['rscount'])
50 echo ' <small>(' . $cell['rscount'] . ')</small>';
51 echo "</td></tr>";
52 break;
53 }
54 echo "<tr><td>";
55 echo count ($cell['etags']) ? ("<small>" . serializeTags ($cell['etags']) . "</small>") : '&nbsp;';
56 echo "</td></tr></table>";
57
58}
59
60function renderSLBEditTab ($entity_id)
61{
62 global $pageno;
63 renderSLBTripletsEdit (spotEntity ($pageno, $entity_id));
64}
65
66// called exclusively by renderSLBTripletsEdit. Renders form to add new SLB link.
67// realms 1 and 2 are realms to draw inputs for
68function renderNewSLBItemForm ($realm1, $realm2)
69{
573f5dc1
HG
70 /**
71 * Returns a list of values, a human readable name and options
72 * for the selecttag for a given realm.
73 */
74 function get_realm_data ($realm)
defd92d8 75 {
573f5dc1
HG
76 $name = NULL;
77 $list = array();
78 $options = array();
defd92d8
AA
79 switch ($realm)
80 {
81 case 'object':
573f5dc1
HG
82 $name = 'Load balancer';
83 $list = getNarrowObjectList ('IPV4LB_LISTSRC');
84 $options = array ('name' => 'object_id', 'tabindex' => 100);
defd92d8
AA
85 break;
86 case 'ipv4vs':
573f5dc1 87 $name = 'Virtual service';
89762db5 88 $list = formatEntityList (listCells ('ipv4vs'));
573f5dc1 89 $options = array ('name' => 'vs_id', 'tabindex' => 101);
defd92d8
AA
90 break;
91 case 'ipv4rspool':
573f5dc1 92 $name = 'RS pool';
89762db5 93 $list = formatEntityList (listCells ('ipv4rspool'));
573f5dc1 94 $options = array ('name' => 'pool_id', 'tabindex' => 102);
defd92d8
AA
95 break;
96 default:
97 throw new InvalidArgException('realm', $realm);
98 }
573f5dc1 99 return array ('name' => $name, 'list' => $list, 'options' => $options);
defd92d8
AA
100 }
101
573f5dc1
HG
102 $realm1_data = get_realm_data ($realm1);
103 $realm2_data = get_realm_data ($realm2);
defd92d8
AA
104 startPortlet ('Add new');
105 echo "<table cellspacing=0 cellpadding=5 align=center>";
573f5dc1
HG
106 if (count ($realm1_data['list']) && count ($realm2_data['list']))
107 printOpFormIntro ('addLB');
108 echo "<tr valign=top><th class=tdright>{$realm1_data['name']}</th><td class=tdleft>";
109 printSelect ($realm1_data['list'], $realm1_data['options']);
defd92d8 110 echo '</td><td class=tdcenter valign=middle rowspan=2>';
573f5dc1
HG
111 if (count ($realm1_data['list']) && count ($realm2_data['list']))
112 printImageHREF ('ADD', 'Configure LB', TRUE, 120);
113 else
114 {
115 $names = array();
116 if (! count ($realm1_data['list']))
117 $names[] = 'a ' . $realm1_data['name'];
118 if (! count ($realm2_data['list']))
119 $names[] = 'a ' . $realm2_data['name'];
120 $message = 'Please create ' . (implode (' and ', $names)) . '.';
121 showNotice ($message);
122 printImageHREF ('DENIED', $message, FALSE);
123 }
124 echo "<tr valign=top><th class=tdright>{$realm2_data['name']}</th><td class=tdleft>";
125 printSelect ($realm2_data['list'], $realm2_data['options']);
defd92d8
AA
126 echo "</td></tr>\n";
127 echo "<tr><th class=tdright>VS config</th><td colspan=2><textarea tabindex=110 name=vsconfig rows=10 cols=80></textarea></td></tr>";
128 echo "<tr><th class=tdright>RS config</th><td colspan=2><textarea tabindex=111 name=rsconfig rows=10 cols=80></textarea></td></tr>";
129 echo "<tr><th class=tdright>Priority</th><td class=tdleft colspan=2><input tabindex=112 name=prio size=10></td></tr>";
130 echo "</form></table>\n";
131 finishPortlet();
132}
133
134// supports object, ipv4vs, ipv4rspool, ipaddress cell types
135function renderSLBTriplets ($cell)
136{
71066ef1 137 $is_cell_ip = (isset ($cell['ip_bin']) && isset ($cell['vslist']));
defd92d8
AA
138 $additional_js_params = $is_cell_ip ? '' : ", {'" . $cell['realm'] . "': " . $cell['id'] . '}';
139 $triplets = SLBTriplet::getTriplets ($cell);
140 if (count ($triplets))
141 {
142 $cells = array();
143 foreach ($triplets[0]->display_cells as $field)
144 $cells[] = $triplets[0]->$field;
145
146 // render table header
147 startPortlet ('VS instances (' . count ($triplets) . ')');
148 echo "<table cellspacing=0 cellpadding=5 align=center class=widetable><tr>";
149 $headers = array
150 (
151 'object' => 'LB',
152 'ipv4vs' => 'VS',
153 'ipv4rspool' => 'RS pool',
154 );
155 foreach ($cells as $slb_cell)
156 echo '<th>' . $headers[$slb_cell['realm']] . '</th>';
157 foreach (array ('VS config', 'RS config', 'Prio') as $header)
158 echo "<th>$header</th>";
159 echo "</tr>";
160
161 // render table rows
162 global $nextorder;
163 $order = 'odd';
164 foreach ($triplets as $slb)
165 {
166 $cells = array();
167 foreach ($slb->display_cells as $field)
168 $cells[] = $slb->$field;
169 echo "<tr valign=top class='row_${order} triplet-row'>";
170 foreach ($cells as $slb_cell)
171 {
172 echo "<td class=tdleft>";
173 $highlighted = $is_cell_ip &&
174 (
71066ef1
AA
175 $slb_cell['realm'] == 'ipv4vs' && $slb->vs['vip_bin'] == $cell['ip_bin'] ||
176 $slb_cell['realm'] == 'ipv4rspool' && $slb->vs['vip_bin'] != $cell['ip_bin']
defd92d8
AA
177 );
178 renderSLBEntityCell ($slb_cell, $highlighted);
179 echo "</td>";
180 }
181 echo "<td class=slbconf>" . htmlspecialchars ($slb->slb['vsconfig']) . "</td>";
182 echo "<td class=slbconf>" . htmlspecialchars ($slb->slb['rsconfig']) . "</td>";
183 echo "<td class=slbconf>" . htmlspecialchars ($slb->slb['prio']) . "</td>";
184 echo "</tr>\n";
185 $order = $nextorder[$order];
186 }
187 echo "</table>\n";
188 finishPortlet();
defd92d8
AA
189 }
190}
191
192// renders a list of slb links. it is called from 3 different pages, wich compute their links lists differently.
193// each triplet in $triplets array contains balancer, pool, VS cells and config values for triplet: RS, VS configs and pair.
194function renderSLBTripletsEdit ($cell)
195{
196 list ($realm1, $realm2) = array_values (array_diff (array ('object', 'ipv4vs', 'ipv4rspool'), array ($cell['realm'])));
197 if (getConfigVar ('ADDNEW_AT_TOP') == 'yes')
89762db5 198 callHook ('renderNewSLBItemForm', $realm1, $realm2);
defd92d8
AA
199
200 $triplets = SLBTriplet::getTriplets ($cell);
201 if (count ($triplets))
202 {
203 $cells = array();
204 foreach ($triplets[0]->display_cells as $field)
205 $cells[] = $triplets[0]->$field;
206
207 startPortlet ('Manage existing (' . count ($triplets) . ')');
208 echo "<table cellspacing=0 cellpadding=5 align=center class=cooltable>\n";
209 global $nextorder;
210 $order = 'odd';
211 foreach ($triplets as $slb)
212 {
213 $cells = array();
214 foreach ($slb->display_cells as $field)
215 $cells[] = $slb->$field;
216 $ids = array
217 (
218 'object_id' => $slb->lb['id'],
219 'vs_id' => $slb->vs['id'],
220 'pool_id' => $slb->rs['id'],
221 );
222 $del_params = $ids;
223 $del_params['op'] = 'delLB';
224 printOpFormIntro ('updLB', $ids);
225 echo "<tr valign=top class=row_${order}><td rowspan=2 class=tdright valign=middle><a href='".makeHrefProcess($del_params)."'>";
226 printImageHREF ('DELETE', 'Unconfigure');
227 echo "</a></td><td class=tdleft valign=bottom>";
228 renderSLBEntityCell ($cells[0]);
229 echo "</td><td>VS config &darr;<br><textarea name=vsconfig rows=5 cols=70>" . htmlspecialchars ($slb->slb['vsconfig']) . "</textarea></td>";
230 echo '<td class=tdleft rowspan=2 valign=middle>';
231 printImageHREF ('SAVE', 'Save changes', TRUE);
232 echo "</td>";
233 echo "</tr><tr class=row_${order}><td class=tdleft valign=top>";
234 renderSLBEntityCell ($cells[1]);
235 echo '</td><td>';
236 echo "<textarea name=rsconfig rows=5 cols=70>" . htmlspecialchars ($slb->slb['rsconfig']) . "</textarea><br>RS config &uarr;";
237 echo "<div style='float:left; margin-top:10px'><label><input name=prio type=text size=10 value=\"" . htmlspecialchars ($slb->slb['prio']) . "\"> &larr; Priority</label></div>";
238 echo '</td></tr></form>';
239 $order = $nextorder[$order];
240 }
241 echo "</table>\n";
242 finishPortlet();
243 }
244
245 if (getConfigVar ('ADDNEW_AT_TOP') != 'yes')
89762db5 246 callHook ('renderNewSLBItemForm', $realm1, $realm2);
defd92d8
AA
247}
248
249function renderLBList ()
250{
251 $cells = array();
0d9f88a9
AA
252 foreach (scanRealmByText('object', getConfigVar ('IPV4LB_LISTSRC')) as $object)
253 $cells[$object['id']] = $object;
defd92d8
AA
254 renderCellList ('object', 'items', FALSE, $cells);
255}
256
257function renderRSPool ($pool_id)
258{
259 $poolInfo = spotEntity ('ipv4rspool', $pool_id);
260
261 echo "<table border=0 class=objectview cellspacing=0 cellpadding=0>";
262 if (strlen ($poolInfo['name']))
263 echo "<tr><td colspan=2 align=center><h1>{$poolInfo['name']}</h1></td></tr>";
264 echo "<tr><td class=pcleft>\n";
265
266 $summary = array();
267 $summary['Pool name'] = $poolInfo['name'];
268 $summary['Real servers'] = $poolInfo['rscount'];
269 $summary['VS instances'] = $poolInfo['refcnt'];
270 $summary['tags'] = '';
271 $summary['VS configuration'] = '<div class="dashed slbconf">' . htmlspecialchars ($poolInfo['vsconfig']) . '</div>';
272 $summary['RS configuration'] = '<div class="dashed slbconf">' . htmlspecialchars ($poolInfo['rsconfig']) . '</div>';
273 renderEntitySummary ($poolInfo, 'Summary', $summary);
274
275 if ($poolInfo['rscount'])
276 {
4ed2310e 277 $rs_list = getRSListInPool ($pool_id);
87595d74
AA
278 $rs_table = callHook ('prepareRealServersTable', $rs_list);
279 startPortlet ("Real servers ({$poolInfo['rscount']})");
defd92d8 280 echo "<table cellspacing=0 cellpadding=5 align=center class=widetable>\n";
4ed2310e 281 echo "<tr>";
87595d74 282 foreach ($rs_table['columns'] as $title)
4ed2310e
AA
283 echo "<th>$title</th>";
284 echo "</tr>";
87595d74 285 foreach ($rs_table['rows'] as $rs)
defd92d8 286 {
4ed2310e 287 echo "<tr valign=top>";
87595d74 288 foreach (array_keys ($rs_table['columns']) as $field)
4ed2310e
AA
289 {
290 switch ($field)
291 {
292 case 'inservice':
293 echo "<td align=center>";
294 if ($rs['inservice'] == 'yes')
295 printImageHREF ('inservice', 'in service');
296 else
297 printImageHREF ('notinservice', 'NOT in service');
298 break;
299 case 'rsip':
300 echo "<td class=tdleft>";
301 echo "<a href='".makeHref(array('page'=>'ipaddress', 'ip'=>$rs[$field]))."'>${rs[$field]}</a>";
302 break;
303 case 'rsconfig':
304 echo "<td class=slbconf>";
305 echo $rs[$field];
306 break;
307 default:
308 echo "<td class=tdleft>";
309 echo $rs[$field];
310 break;
311 }
312 echo '</td>';
313 }
314 echo '</tr>';
defd92d8
AA
315 }
316 echo "</table>\n";
317 finishPortlet();
318 }
319
320 echo "</td><td class=pcright>\n";
321 renderSLBTriplets ($poolInfo);
322 echo "</td></tr><tr><td colspan=2>\n";
323 renderFilesPortlet ('ipv4rspool', $pool_id);
324 echo "</td></tr></table>\n";
325}
326
87595d74 327function prepareRealServersTable ($rs_list)
4ed2310e 328{
87595d74 329 $columns = array
4ed2310e
AA
330 (
331 'inservice' => '',
332 'rsip' => 'address',
333 'rsport' => 'port',
334 'rsconfig' => 'RS config',
335 'comment' => 'comment',
336 );
87595d74 337 $not_seen = $columns;
4ed2310e
AA
338 foreach ($rs_list as $rs)
339 foreach ($rs as $key => $value)
340 if (! empty ($value) and isset ($not_seen[$key]))
341 unset ($not_seen[$key]);
342 foreach (array_keys ($not_seen) as $key)
343 if ($key != 'rsip')
87595d74
AA
344 unset ($columns[$key]);
345 return array
346 (
347 'columns' => $columns,
348 'rows' => $rs_list,
349 );
4ed2310e
AA
350}
351
defd92d8
AA
352function renderRSPoolServerForm ($pool_id)
353{
354 global $nextorder;
355 $poolInfo = spotEntity ('ipv4rspool', $pool_id);
356
357 if ($poolInfo['rscount'])
358 {
4ed2310e 359 startPortlet ("Manage RS list (${poolInfo['rscount']})");
defd92d8 360 echo "<table cellspacing=0 cellpadding=5 align=center class=cooltable>\n";
4ed2310e
AA
361 echo "<tr><th>&nbsp;</th><th>Address</th><th>Port</th><th>Comment</th><th>in service</th><th>configuration</th><th>&nbsp;</th></tr>\n";
362 // new RS form
363 printOpFormIntro ('addRS');
364 echo "<tr class=row_odd valign=top><td>";
365 printImageHREF ('add', 'Add new real server');
366 echo "</td><td><input type=text name=rsip></td>";
367 $default_port = getConfigVar ('DEFAULT_SLB_RS_PORT');
368 if ($default_port == 0)
369 $default_port = '';
370 echo "<td><input type=text name=rsport size=5 value='$default_port'></td>";
371 echo "<td><input type=text name=comment size=15></td>";
372 $checked = (getConfigVar ('DEFAULT_IPV4_RS_INSERVICE') == 'yes') ? 'checked' : '';
373 echo "<td><input type=checkbox name=inservice $checked></td>";
374 echo "<td><textarea name=rsconfig></textarea></td><td>";
375 printImageHREF ('ADD', 'Add new real server', TRUE);
376 echo "</td></tr></form>\n";
dec748f6 377
4ed2310e 378 $order = 'even';
defd92d8
AA
379 foreach (getRSListInPool ($pool_id) as $rsid => $rs)
380 {
381 printOpFormIntro ('updRS', array ('rs_id' => $rsid));
382 echo "<tr valign=top class=row_${order}><td><a href='".makeHrefProcess(array('op'=>'delRS', 'pool_id'=>$pool_id, 'id'=>$rsid))."'>";
383 printImageHREF ('delete', 'Delete this real server');
384 echo "</td><td><input type=text name=rsip value='${rs['rsip']}'></td>";
385 echo "<td><input type=text name=rsport size=5 value='${rs['rsport']}'></td>";
4ed2310e 386 echo "<td><input type=text name=comment size=15 value='${rs['comment']}'></td>";
defd92d8
AA
387 $checked = $rs['inservice'] == 'yes' ? 'checked' : '';
388 echo "<td><input type=checkbox name=inservice $checked></td>";
389 echo "<td><textarea name=rsconfig>${rs['rsconfig']}</textarea></td><td>";
390 printImageHREF ('SAVE', 'Save changes', TRUE);
391 echo "</td></tr></form>\n";
392 $order = $nextorder[$order];
393 }
394 echo "</table>\n";
395 finishPortlet();
396 }
397
defd92d8
AA
398 startPortlet ('Add many');
399 printOpFormIntro ('addMany');
400 echo "<table border=0 align=center>\n<tr><td>";
401 if (getConfigVar ('DEFAULT_IPV4_RS_INSERVICE') == 'yes')
402 printImageHREF ('inservice', 'in service');
403 else
404 printImageHREF ('notinservice', 'NOT in service');
405 echo "</td><td>Format: ";
ab8b6355
AA
406 $formats = callHook ('getBulkRealsFormats');
407 printSelect ($formats, array ('name' => 'format'));
408 echo "</td><td><input type=submit value=Parse></td></tr>\n";
409 echo "<tr><td colspan=3><textarea name=rawtext cols=100 rows=25></textarea></td></tr>\n";
410 echo "</table>\n";
411 finishPortlet();
412}
413
414function getBulkRealsFormats()
415{
416 return array
defd92d8
AA
417 (
418 'ssv_1' => 'SSV: &lt;IP address&gt;',
419 'ssv_2' => 'SSV: &lt;IP address&gt; &lt;port&gt;',
420 'ipvs_2' => 'ipvsadm -l -n (address and port)',
421 'ipvs_3' => 'ipvsadm -l -n (address, port and weight)',
422 );
defd92d8
AA
423}
424
425function renderRSPoolList ()
426{
427 renderCellList ('ipv4rspool', 'RS pools');
428}
429
430function renderRealServerList ()
431{
432 global $nextorder;
433 $rslist = getRSList ();
434 $pool_list = listCells ('ipv4rspool');
435 echo "<table class=widetable border=0 cellpadding=10 cellspacing=0 align=center>\n";
436 echo "<tr><th>RS pool</th><th>in service</th><th>real IP address</th><th>real port</th><th>RS configuration</th></tr>";
437 $order = 'even';
438 $last_pool_id = 0;
439 foreach ($rslist as $rsinfo)
440 {
441 if ($last_pool_id != $rsinfo['rspool_id'])
442 {
443 $order = $nextorder[$order];
444 $last_pool_id = $rsinfo['rspool_id'];
445 }
446 echo "<tr valign=top class=row_${order}><td><a href='".makeHref(array('page'=>'ipv4rspool', 'pool_id'=>$rsinfo['rspool_id']))."'>";
447 echo !strlen ($pool_list[$rsinfo['rspool_id']]['name']) ? 'ANONYMOUS' : $pool_list[$rsinfo['rspool_id']]['name'];
448 echo '</a></td><td align=center>';
449 if ($rsinfo['inservice'] == 'yes')
450 printImageHREF ('inservice', 'in service');
451 else
452 printImageHREF ('notinservice', 'NOT in service');
453 echo "</td><td><a href='".makeHref(array('page'=>'ipaddress', 'ip'=>$rsinfo['rsip']))."'>${rsinfo['rsip']}</a></td>";
454 echo "<td>${rsinfo['rsport']}</td>";
455 echo "<td><pre>${rsinfo['rsconfig']}</pre></td>";
456 echo "</tr>\n";
457 }
458 echo "</table>";
459}
460
461
71066ef1 462function renderNewRSPoolForm ()
defd92d8 463{
71066ef1
AA
464 startPortlet ('Add new RS pool');
465 printOpFormIntro ('add');
466 echo "<table border=0 cellpadding=10 cellspacing=0 align=center>";
467 echo "<tr><th class=tdright>Name</th>";
468 echo "<td class=tdleft><input type=text name=name tabindex=101></td><td>";
469 printImageHREF ('CREATE', 'create real server pool', TRUE, 104);
470 echo "</td><th>Assign tags</th></tr>";
471 echo "<tr><th class=tdright>VS config</th><td colspan=2><textarea name=vsconfig rows=10 cols=80 tabindex=102></textarea></td>";
472 echo "<td rowspan=2>";
473 renderNewEntityTags ('ipv4rspool');
474 echo "</td></tr>";
475 echo "<tr><th class=tdright>RS config</th><td colspan=2><textarea name=rsconfig rows=10 cols=80 tabindex=103></textarea></td></tr>";
476 echo "</table></form>";
477 finishPortlet();
defd92d8
AA
478}
479
480function renderVirtualService ($vsid)
481{
482 $vsinfo = spotEntity ('ipv4vs', $vsid);
483 echo '<table border=0 class=objectview cellspacing=0 cellpadding=0>';
484 if (strlen ($vsinfo['name']))
485 echo "<tr><td colspan=2 align=center><h1>${vsinfo['name']}</h1></td></tr>\n";
486 echo '<tr>';
487
488 echo '<td class=pcleft>';
489 $summary = array();
490 $summary['Name'] = $vsinfo['name'];
491 $summary['Protocol'] = $vsinfo['proto'];
492 $summary['Virtual IP address'] = "<a href='".makeHref(array('page'=>'ipaddress', 'tab'=>'default', 'ip'=>$vsinfo['vip']))."'>${vsinfo['vip']}</a>";
493 $summary['Virtual port'] = $vsinfo['vport'];
494 $summary['tags'] = '';
495 $summary['VS configuration'] = '<div class="dashed slbconf">' . $vsinfo['vsconfig'] . '</div>';
496 $summary['RS configuration'] = '<div class="dashed slbconf">' . $vsinfo['rsconfig'] . '</div>';
497 renderEntitySummary ($vsinfo, 'Summary', $summary);
498 echo '</td>';
499
500 echo '<td class=pcright>';
501 renderSLBTriplets ($vsinfo);
502 echo '</td></tr><tr><td colspan=2>';
503 renderFilesPortlet ('ipv4vs', $vsid);
504 echo '</tr><table>';
505}
506
507function renderVSList ()
508{
509 renderCellList ('ipv4vs', 'Virtual services');
510}
511
71066ef1 512function renderNewVSForm ()
defd92d8 513{
71066ef1
AA
514 startPortlet ('Add new virtual service');
515 printOpFormIntro ('add');
516 echo "<table border=0 cellpadding=10 cellspacing=0 align=center>\n";
517 echo "<tr valign=bottom><td>&nbsp;</td><th>VIP</th><th>port</th><th>proto</th><th>name</th><th>&nbsp;</th><th>Assign tags</th></tr>";
518 echo '<tr valign=top><td>&nbsp;</td>';
519 echo "<td><input type=text name=vip tabindex=101></td>";
520 $default_port = getConfigVar ('DEFAULT_SLB_VS_PORT');
521 if ($default_port == 0)
522 $default_port = '';
523 echo "<td><input type=text name=vport size=5 value='${default_port}' tabindex=102></td><td>";
524 global $vs_proto;
525 printSelect ($vs_proto, array ('name' => 'proto'), array_shift (array_keys ($vs_proto)));
526 echo '</td><td><input type=text name=name tabindex=104></td><td>';
527 printImageHREF ('CREATE', 'create virtual service', TRUE, 105);
528 echo "</td><td rowspan=3>";
529 renderNewEntityTags ('ipv4vs');
530 echo "</td></tr><tr><th>VS configuration</th><td colspan=5 class=tdleft><textarea name=vsconfig rows=10 cols=80></textarea></td>";
531 echo "<tr><th>RS configuration</th><td colspan=5 class=tdleft><textarea name=rsconfig rows=10 cols=80></textarea></td></tr>";
532 echo '</table></form>';
533 finishPortlet();
defd92d8
AA
534}
535
536function renderEditRSPool ($pool_id)
537{
538 $poolinfo = spotEntity ('ipv4rspool', $pool_id);
539 printOpFormIntro ('updIPv4RSP');
540 echo '<table border=0 align=center>';
541 echo "<tr><th class=tdright>name:</th><td class=tdleft><input type=text name=name value='${poolinfo['name']}'></td></tr>\n";
542 echo "<tr><th class=tdright>VS config:</th><td class=tdleft><textarea name=vsconfig rows=20 cols=80>${poolinfo['vsconfig']}</textarea></td></tr>\n";
543 echo "<tr><th class=tdright>RS config:</th><td class=tdleft><textarea name=rsconfig rows=20 cols=80>${poolinfo['rsconfig']}</textarea></td></tr>\n";
544 echo "<tr><th class=submit colspan=2>";
545 printImageHREF ('SAVE', 'Save changes', TRUE);
546 echo "</td></tr>\n";
547 echo "</table></form>\n";
d60c7760
AA
548
549 // clone link
550 echo '<p class="centered">';
551 echo getOpLink (array ('op' => 'cloneIPv4RSP', 'pool_id' => $poolinfo['id']), 'Clone RS pool', 'copy');
552 echo '</p>';
553
554 // delete link
555 echo '<p class="centered">';
556 if ($poolinfo['refcnt'] > 0)
557 echo getOpLink (NULL, 'Delete RS pool', 'nodestroy', "Could not delete: there are ${poolinfo['refcnt']} LB links");
558 else
559 echo getOpLink (array ('op' => 'del', 'id' => $poolinfo['id']), 'Delete RS pool', 'destroy');
560 echo '</p>';
defd92d8
AA
561}
562
563function renderEditVService ($vsid)
564{
565 $vsinfo = spotEntity ('ipv4vs', $vsid);
566 printOpFormIntro ('updIPv4VS');
567 echo '<table border=0 align=center>';
568 echo "<tr><th class=tdright>VIP:</th><td class=tdleft><input tabindex=1 type=text name=vip value='${vsinfo['vip']}'></td></tr>\n";
569 echo "<tr><th class=tdright>port:</th><td class=tdleft><input tabindex=2 type=text name=vport value='${vsinfo['vport']}'></td></tr>\n";
570 echo "<tr><th class=tdright>proto:</th><td class=tdleft>";
ed38c73c
AA
571 global $vs_proto;
572 printSelect ($vs_proto, array ('name' => 'proto'), $vsinfo['proto']);
defd92d8
AA
573 echo "</td></tr>\n";
574 echo "<tr><th class=tdright>name:</th><td class=tdleft><input tabindex=4 type=text name=name value='${vsinfo['name']}'></td></tr>\n";
575 echo "<tr><th class=tdright>VS config:</th><td class=tdleft><textarea tabindex=5 name=vsconfig rows=20 cols=80>${vsinfo['vsconfig']}</textarea></td></tr>\n";
576 echo "<tr><th class=tdright>RS config:</th><td class=tdleft><textarea tabindex=6 name=rsconfig rows=20 cols=80>${vsinfo['rsconfig']}</textarea></td></tr>\n";
577 echo "<tr><th class=submit colspan=2>";
578 printImageHREF ('SAVE', 'Save changes', TRUE, 7);
579 echo "</td></tr>\n";
580 echo "</table></form>\n";
71066ef1
AA
581
582 // delete link
583 echo '<p class="centered">';
584 if ($vsinfo['refcnt'] > 0)
585 echo getOpLink (NULL, 'Delete virtual service', 'nodestroy', "Could not delete: there are ${vsinfo['refcnt']} LB links");
586 else
587 echo getOpLink (array ('op' => 'del', 'id' => $vsinfo['id']), 'Delete virtual service', 'destroy');
defd92d8
AA
588}
589
590function renderLVSConfig ($object_id)
591{
6ef2215c
AA
592 printOpFormIntro ('submitSLBConfig');
593 echo "<center><input type=submit value='Submit for activation'></center>";
594 echo "</form>";
595 echo "<pre>" . buildLVSConfig ($object_id) . "</pre>";
defd92d8
AA
596}
597
598?>