Project

General

Profile

« Previous | Next » 

Revision 0162f9a1

Added by Phil Davis about 10 years ago

Code style Load Balancer

View differences:

usr/local/www/load_balancer_monitor.php
101 101
<?php print_info_box_np(gettext("The load balancer configuration has been changed") . ".<br />" . gettext("You must apply the changes in order for them to take effect."));?><br />
102 102
<?php endif; ?>
103 103
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="load balancer monitor">
104
  <tr><td class="tabnavtbl">
105
  <?php
106
        /* active tabs */
107
        $tab_array = array();
108
        $tab_array[] = array(gettext("Pools"), false, "load_balancer_pool.php");
109
        $tab_array[] = array(gettext("Virtual Servers"), false, "load_balancer_virtual_server.php");
110
        $tab_array[] = array(gettext("Monitors"), true, "load_balancer_monitor.php");
111
        $tab_array[] = array(gettext("Settings"), false, "load_balancer_setting.php");
112
        display_top_tabs($tab_array);
113
  ?>
114
  </td></tr>
115
  <tr>
116
    <td>
117
	<div id="mainarea">
104
	<tr><td class="tabnavtbl">
105
	<?php
106
		/* active tabs */
107
		$tab_array = array();
108
		$tab_array[] = array(gettext("Pools"), false, "load_balancer_pool.php");
109
		$tab_array[] = array(gettext("Virtual Servers"), false, "load_balancer_virtual_server.php");
110
		$tab_array[] = array(gettext("Monitors"), true, "load_balancer_monitor.php");
111
		$tab_array[] = array(gettext("Settings"), false, "load_balancer_setting.php");
112
		display_top_tabs($tab_array);
113
	?>
114
	</td></tr>
115
	<tr>
116
		<td>
117
			<div id="mainarea">
118 118
<?php
119
			$t = new MainTable();
120
			$t->edit_uri('load_balancer_monitor_edit.php');
121
			$t->my_uri('load_balancer_monitor.php');
122
			$t->add_column(gettext('Name'),'name',20);
123
			$t->add_column(gettext('Type'),'type',10);
124
			$t->add_column(gettext('Description'),'descr',30);
125
			$t->add_button('edit');
126
			$t->add_button('dup');
127
			$t->add_button('del');
128
			$t->add_content_array($a_monitor);
129
			$t->display();
119
				$t = new MainTable();
120
				$t->edit_uri('load_balancer_monitor_edit.php');
121
				$t->my_uri('load_balancer_monitor.php');
122
				$t->add_column(gettext('Name'),'name',20);
123
				$t->add_column(gettext('Type'),'type',10);
124
				$t->add_column(gettext('Description'),'descr',30);
125
				$t->add_button('edit');
126
				$t->add_button('dup');
127
				$t->add_button('del');
128
				$t->add_content_array($a_monitor);
129
				$t->display();
130 130
?>
131
	</div>
132
    </td>
133
  </tr>
131
			</div>
132
		</td>
133
	</tr>
134 134
</table>
135 135
</form>
136 136
<?php include("fend.inc"); ?>
usr/local/www/load_balancer_monitor_edit.php
49 49
}
50 50
$a_monitor = &$config['load_balancer']['monitor_type'];
51 51

  
52
if (is_numericint($_GET['id']))
52
if (is_numericint($_GET['id'])) {
53 53
	$id = $_GET['id'];
54
if (isset($_POST['id']) && is_numericint($_POST['id']))
54
}
55
if (isset($_POST['id']) && is_numericint($_POST['id'])) {
55 56
	$id = $_POST['id'];
57
}
56 58

  
57 59
if (isset($id) && $a_monitor[$id]) {
58 60
	$pconfig['name'] = $a_monitor[$id]['name'];
......
76 78
	$pconfig = $_POST;
77 79

  
78 80
	/* turn $_POST['http_options_*'] into $pconfig['options'][*] */
79
	foreach($_POST as $key => $val) {
81
	foreach ($_POST as $key => $val) {
80 82
		if (stristr($key, 'options') !== false) {
81 83
			if (stristr($key, $pconfig['type'].'_') !== false) {
82 84
				$opt = explode('_',$key);
......
93 95
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
94 96

  
95 97
	/* Ensure that our monitor names are unique */
96
	for ($i=0; isset($config['load_balancer']['monitor_type'][$i]); $i++)
97
		if (($_POST['name'] == $config['load_balancer']['monitor_type'][$i]['name']) && ($i != $id))
98
	for ($i=0; isset($config['load_balancer']['monitor_type'][$i]); $i++) {
99
		if (($_POST['name'] == $config['load_balancer']['monitor_type'][$i]['name']) && ($i != $id)) {
98 100
			$input_errors[] = gettext("This monitor name has already been used.  Monitor names must be unique.");
101
		}
102
	}
99 103

  
100
	if (preg_match('/[ \/]/', $_POST['name']))
104
	if (preg_match('/[ \/]/', $_POST['name'])) {
101 105
		$input_errors[] = gettext("You cannot use spaces or slashes in the 'name' field.");
106
	}
102 107

  
103
	if (strlen($_POST['name']) > 16)
108
	if (strlen($_POST['name']) > 16) {
104 109
		$input_errors[] = gettext("The 'name' field must be 16 characters or less.");
110
	}
105 111

  
106
	switch($_POST['type']) {
112
	switch ($_POST['type']) {
107 113
		case 'icmp': {
108 114
			break;
109 115
		}
......
120 126
				}
121 127
				if (isset($pconfig['options']['code']) && $pconfig['options']['code'] != "") {
122 128
					// Check code
123
					if(!is_rfc2616_code($pconfig['options']['code'])) {
129
					if (!is_rfc2616_code($pconfig['options']['code'])) {
124 130
						$input_errors[] = gettext("HTTP(s) codes must be from RFC2616.");
125 131
					}
126 132
				}
......
145 151

  
146 152
	if (!$input_errors) {
147 153
		$monent = array();
148
		if(isset($id) && $a_monitor[$id])
154
		if (isset($id) && $a_monitor[$id]) {
149 155
			$monent = $a_monitor[$id];
150
		if($monent['name'] != "")
156
		}
157
		if ($monent['name'] != "") {
151 158
			$changedesc .= " " . sprintf(gettext("modified '%s' monitor:"), $monent['name']);
152
		
159
		}
160

  
153 161
		update_if_changed("name", $monent['name'], $pconfig['name']);
154 162
		update_if_changed("type", $monent['type'], $pconfig['type']);
155 163
		update_if_changed("description", $monent['descr'], $pconfig['descr']);
156
		if($pconfig['type'] == "http" || $pconfig['type'] == "https" ) {
164
		if ($pconfig['type'] == "http" || $pconfig['type'] == "https") {
157 165
			/* log updates, then clear array and reassign - dumb, but easiest way to have a clear array */
158 166
			update_if_changed("path", $monent['options']['path'], $pconfig['options']['path']);
159 167
			update_if_changed("host", $monent['options']['host'], $pconfig['options']['host']);
......
163 171
			$monent['options']['host'] = $pconfig['options']['host'];
164 172
			$monent['options']['code'] = $pconfig['options']['code'];
165 173
		}
166
		if($pconfig['type'] == "send" ) {
174
		if ($pconfig['type'] == "send") {
167 175
			/* log updates, then clear array and reassign - dumb, but easiest way to have a clear array */
168 176
			update_if_changed("send", $monent['options']['send'], $pconfig['options']['send']);
169 177
			update_if_changed("expect", $monent['options']['expect'], $pconfig['options']['expect']);
......
171 179
			$monent['options']['send'] = $pconfig['options']['send'];
172 180
			$monent['options']['expect'] = $pconfig['options']['expect'];
173 181
		}
174
		if($pconfig['type'] == "tcp" || $pconfig['type'] == "icmp") {
182
		if ($pconfig['type'] == "tcp" || $pconfig['type'] == "icmp") {
175 183
			$monent['options'] = array();
176 184
		}
177 185

  
178 186
		if (isset($id) && $a_monitor[$id]) {
179 187
			/* modify all pools with this name */
180 188
			for ($i = 0; isset($config['load_balancer']['lbpool'][$i]); $i++) {
181
				if ($config['load_balancer']['lbpool'][$i]['monitor'] == $a_monitor[$id]['name'])
189
				if ($config['load_balancer']['lbpool'][$i]['monitor'] == $a_monitor[$id]['name']) {
182 190
					$config['load_balancer']['lbpool'][$i]['monitor'] = $monent['name'];
191
				}
183 192
			}
184 193
			$a_monitor[$id] = $monent;
185
		} else
194
		} else {
186 195
			$a_monitor[] = $monent;
187
		
196
		}
197

  
188 198
		if ($changecount > 0) {
189 199
			/* Mark config dirty */
190 200
			mark_subsystem_dirty('loadbalancer');
......
208 218
<?php include("fbegin.inc"); ?>
209 219
<script type="text/javascript">
210 220
//<![CDATA[
211
function updateType(t){
212
	switch(t) {
221
function updateType(t) {
222
	switch (t) {
213 223
<?php
214 224
	/* OK, so this is sick using php to generate javascript, but it needed to be done */
215 225
	foreach ($types as $key => $val) {
......
231 241

  
232 242
<?php if ($input_errors) print_input_errors($input_errors); ?>
233 243

  
234
	<form action="load_balancer_monitor_edit.php" method="post" name="iform" id="iform">
244
<form action="load_balancer_monitor_edit.php" method="post" name="iform" id="iform">
235 245
	<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="monitor entry">
236
 		<tr>
246
		<tr>
237 247
			<td colspan="2" valign="top" class="listtopic"><?=gettext("Edit Load Balancer - Monitor entry"); ?></td>
238
                </tr>
248
		</tr>
239 249
		<tr align="left">
240 250
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Name"); ?></td>
241 251
			<td width="78%" class="vtable" colspan="2">
242
				<input name="name" type="text" <?if(isset($pconfig['name'])) echo "value=\"" . htmlspecialchars($pconfig['name']) . "\"";?> size="16" maxlength="16" />
252
				<input name="name" type="text" <?if (isset($pconfig['name'])) echo "value=\"" . htmlspecialchars($pconfig['name']) . "\"";?> size="16" maxlength="16" />
243 253
			</td>
244 254
		</tr>
245 255
		<tr align="left">
246 256
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Description"); ?></td>
247 257
			<td width="78%" class="vtable" colspan="2">
248
				<input name="descr" type="text" <?if(isset($pconfig['descr'])) echo "value=\"" . htmlspecialchars($pconfig['descr']) . "\"";?> size="64" />
258
				<input name="descr" type="text" <?if (isset($pconfig['descr'])) echo "value=\"" . htmlspecialchars($pconfig['descr']) . "\"";?> size="64" />
249 259
			</td>
250 260
		</tr>
251 261
		<tr align="left">
......
254 264
				<select id="type" name="type">
255 265
<?
256 266
					foreach ($types as $key => $val) {
257
						if(isset($pconfig['type']) && $pconfig['type'] == $key) {
267
						if (isset($pconfig['type']) && $pconfig['type'] == $key) {
258 268
							$selected = " selected=\"selected\"";
259 269
						} else {
260 270
							$selected = "";
......
265 275
				</select>
266 276
			</td>
267 277
		</tr>
268
		<tr align="left" id="icmp"<?= $pconfig['type'] == "icmp" ? "" : " style=\"display:none;\""?>><td></td>
278
		<tr align="left" id="icmp"<?= $pconfig['type'] == "icmp" ? "" : " style=\"display:none;\""?>>
279
			<td></td>
269 280
		</tr>
270
		<tr align="left" id="tcp"<?= $pconfig['type'] == "tcp" ? "" : " style=\"display:none;\""?>><td></td>
281
		<tr align="left" id="tcp"<?= $pconfig['type'] == "tcp" ? "" : " style=\"display:none;\""?>>
282
			<td></td>
271 283
		</tr>
272 284
		<tr align="left" id="http"<?= $pconfig['type'] == "http" ? "" : " style=\"display:none;\""?>>
273 285
			<td width="22%" valign="top" class="vncellreq"><?=gettext("HTTP"); ?></td>
......
276 288
					<tr align="left">
277 289
						<td valign="top" align="right" class="vtable"><?=gettext("Path"); ?></td>
278 290
						<td class="vtable" colspan="2">
279
							<input name="http_options_path" type="text" <?if(isset($pconfig['options']['path'])) echo "value=\"" . htmlspecialchars($pconfig['options']['path']) . "\"";?> size="64" />
291
							<input name="http_options_path" type="text" <?if (isset($pconfig['options']['path'])) echo "value=\"" . htmlspecialchars($pconfig['options']['path']) . "\"";?> size="64" />
280 292
						</td>
281 293
					</tr>
282 294
					<tr align="left">
283 295
						<td valign="top"  align="right" class="vtable"><?=gettext("Host"); ?></td>
284 296
						<td class="vtable" colspan="2">
285
							<input name="http_options_host" type="text" <?if(isset($pconfig['options']['host'])) echo "value=\"" . htmlspecialchars($pconfig['options']['host']) . "\"";?> size="64" /><br /><?=gettext("Hostname for Host: header if needed."); ?>
297
							<input name="http_options_host" type="text" <?if (isset($pconfig['options']['host'])) echo "value=\"" . htmlspecialchars($pconfig['options']['host']) . "\"";?> size="64" /><br /><?=gettext("Hostname for Host: header if needed."); ?>
286 298
						</td>
287 299
					</tr>
288 300
					<tr align="left">
......
295 307
					<tr align="left">
296 308
						<td width="22%" valign="top" class="vncell">MD5 Page Digest</td>
297 309
						<td width="78%" class="vtable" colspan="2">
298
							<input name="digest" type="text" <?if(isset($pconfig['digest'])) echo "value=\"" . htmlspecialchars($pconfig['digest']) . "\"";?>size="32"><br /><b>TODO: add fetch functionality here</b>
310
							<input name="digest" type="text" <?if (isset($pconfig['digest'])) echo "value=\"" . htmlspecialchars($pconfig['digest']) . "\"";?>size="32"><br /><b>TODO: add fetch functionality here</b>
299 311
						</td>
300 312
					</tr>
301 313
-->
......
309 321
					<tr align="left">
310 322
						<td valign="top"  align="right" class="vtable"><?=gettext("Path"); ?></td>
311 323
						<td class="vtable" colspan="2">
312
							<input name="https_options_path" type="text" <?if(isset($pconfig['options']['path'])) echo "value=\"" . htmlspecialchars($pconfig['options']['path']) ."\"";?> size="64" />
324
							<input name="https_options_path" type="text" <?if (isset($pconfig['options']['path'])) echo "value=\"" . htmlspecialchars($pconfig['options']['path']) ."\"";?> size="64" />
313 325
						</td>
314 326
					</tr>
315 327
					<tr align="left">
316 328
						<td valign="top"  align="right" class="vtable"><?=gettext("Host"); ?></td>
317 329
						<td class="vtable" colspan="2">
318
							<input name="https_options_host" type="text" <?if(isset($pconfig['options']['host'])) echo "value=\"" . htmlspecialchars($pconfig['options']['host']) . "\"";?> size="64" /><br /><?=gettext("Hostname for Host: header if needed."); ?>
330
							<input name="https_options_host" type="text" <?if (isset($pconfig['options']['host'])) echo "value=\"" . htmlspecialchars($pconfig['options']['host']) . "\"";?> size="64" /><br /><?=gettext("Hostname for Host: header if needed."); ?>
319 331
						</td>
320 332
					</tr>
321 333
					<tr align="left">
......
329 341
					<tr align="left">
330 342
						<td width="22%" valign="top" class="vncellreq">MD5 Page Digest</td>
331 343
						<td width="78%" class="vtable" colspan="2">
332
							<input name="digest" type="text" <?if(isset($pconfig['digest'])) echo "value=\"" . htmlspecialchars($pconfig['digest']) . "\"";?>size="32"><br /><b>TODO: add fetch functionality here</b>
344
							<input name="digest" type="text" <?if (isset($pconfig['digest'])) echo "value=\"" . htmlspecialchars($pconfig['digest']) . "\"";?>size="32"><br /><b>TODO: add fetch functionality here</b>
333 345
						</td>
334 346
					</tr>
335 347
-->
......
343 355
					<tr align="left">
344 356
						<td valign="top"  align="right" class="vtable"><?=gettext("Send string"); ?></td>
345 357
						<td class="vtable" colspan="2">
346
							<input name="send_options_send" type="text" <?if(isset($pconfig['options']['send'])) echo "value=\"" . htmlspecialchars($pconfig['options']['send']) . "\"";?> size="64" />
358
							<input name="send_options_send" type="text" <?if (isset($pconfig['options']['send'])) echo "value=\"" . htmlspecialchars($pconfig['options']['send']) . "\"";?> size="64" />
347 359
						</td>
348 360
					</tr>
349 361
					<tr align="left">
350 362
						<td valign="top" align="right"  class="vtable"><?=gettext("Expect string"); ?></td>
351 363
						<td class="vtable" colspan="2">
352
							<input name="send_options_expect" type="text" <?if(isset($pconfig['options']['expect'])) echo "value=\"" . htmlspecialchars($pconfig['options']['expect']) . "\"";?> size="64" />
364
							<input name="send_options_expect" type="text" <?if (isset($pconfig['options']['expect'])) echo "value=\"" . htmlspecialchars($pconfig['options']['expect']) . "\"";?> size="64" />
353 365
						</td>
354 366
					</tr>
355 367
				</table>
......
366 378
			</td>
367 379
		</tr>
368 380
	</table>
369
	</form>
381
</form>
370 382
<br />
371 383
<?php include("fend.inc"); ?>
372 384
</body>
usr/local/www/load_balancer_pool.php
110 110
<?php print_info_box_np(sprintf(gettext("The load balancer configuration has been changed%sYou must apply the changes in order for them to take effect."), "<br />"));?><br />
111 111
<?php endif; ?>
112 112
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="load balancer pools">
113
  <tr><td class="tabnavtbl">
114
  <?php
115
        /* active tabs */
116
        $tab_array = array();
117
        $tab_array[] = array(gettext("Pools"), true, "load_balancer_pool.php");
118
        $tab_array[] = array(gettext("Virtual Servers"), false, "load_balancer_virtual_server.php");
119
        $tab_array[] = array(gettext("Monitors"), false, "load_balancer_monitor.php");
120
        $tab_array[] = array(gettext("Settings"), false, "load_balancer_setting.php");
121
        display_top_tabs($tab_array);
122
  ?>
123
  </td></tr>
124
  <tr>
125
    <td>
126
	<div id="mainarea">
113
	<tr><td class="tabnavtbl">
114
	<?php
115
		/* active tabs */
116
		$tab_array = array();
117
		$tab_array[] = array(gettext("Pools"), true, "load_balancer_pool.php");
118
		$tab_array[] = array(gettext("Virtual Servers"), false, "load_balancer_virtual_server.php");
119
		$tab_array[] = array(gettext("Monitors"), false, "load_balancer_monitor.php");
120
		$tab_array[] = array(gettext("Settings"), false, "load_balancer_setting.php");
121
		display_top_tabs($tab_array);
122
	?>
123
	</td></tr>
124
	<tr>
125
		<td>
126
			<div id="mainarea">
127 127
<?php
128
			$t = new MainTable();
129
			$t->edit_uri('load_balancer_pool_edit.php');
130
			$t->my_uri('load_balancer_pool.php');
131
			$t->add_column(gettext('Name'),'name',10);
132
			$t->add_column(gettext('Mode'),'mode',10);
133
			$t->add_column(gettext('Servers'),'servers',15);
134
			$t->add_column(gettext('Port'),'port',10);
135
			$t->add_column(gettext('Monitor'),'monitor',10);
136
			$t->add_column(gettext('Description'),'descr',25);
137
			$t->add_button('edit');
138
			$t->add_button('dup');
139
			$t->add_button('del');
140
			$t->add_content_array($a_pool);
141
			$t->display();
128
				$t = new MainTable();
129
				$t->edit_uri('load_balancer_pool_edit.php');
130
				$t->my_uri('load_balancer_pool.php');
131
				$t->add_column(gettext('Name'),'name',10);
132
				$t->add_column(gettext('Mode'),'mode',10);
133
				$t->add_column(gettext('Servers'),'servers',15);
134
				$t->add_column(gettext('Port'),'port',10);
135
				$t->add_column(gettext('Monitor'),'monitor',10);
136
				$t->add_column(gettext('Description'),'descr',25);
137
				$t->add_button('edit');
138
				$t->add_button('dup');
139
				$t->add_button('del');
140
				$t->add_content_array($a_pool);
141
				$t->display();
142 142
?>
143

  
144
	</div>
145
    </td>
146
  </tr>
147
  <tr><td>
148
	<br /><span class="red"><strong><?=gettext("Hint:");?></strong></span><br />
149
	<?= sprintf(gettext("The Load Balancer in %s 2.0 is for server load balancing, not Multi-WAN. For load balancing or failover for multiple WANs, use "), $g['product_name']);?>
150
	<a href="/system_gateway_groups.php"><?= gettext("Gateway Groups"); ?></a>
151
  </td></tr>
143
			</div>
144
		</td>
145
	</tr>
146
	<tr>
147
		<td>
148
			<br />
149
			<span class="red"><strong><?=gettext("Hint:");?></strong></span>
150
			<br />
151
			<?= sprintf(gettext("The Load Balancer in %s 2.0 is for server load balancing, not Multi-WAN. For load balancing or failover for multiple WANs, use "), $g['product_name']);?>
152
			<a href="/system_gateway_groups.php"><?= gettext("Gateway Groups"); ?></a>
153
		</td>
154
	</tr>
152 155
</table>
153 156
</form>
154 157
<?php include("fend.inc"); ?>
usr/local/www/load_balancer_pool_edit.php
51 51
}
52 52
$a_pool = &$config['load_balancer']['lbpool'];
53 53

  
54
if (is_numericint($_GET['id']))
54
if (is_numericint($_GET['id'])) {
55 55
	$id = $_GET['id'];
56
if (isset($_POST['id']) && is_numericint($_POST['id']))
56
}
57
if (isset($_POST['id']) && is_numericint($_POST['id'])) {
57 58
	$id = $_POST['id'];
59
}
58 60

  
59 61
if (isset($id) && $a_pool[$id]) {
60 62
	$pconfig['name'] = $a_pool[$id]['name'];
......
83 85
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
84 86

  
85 87
	/* Ensure that our pool names are unique */
86
	for ($i=0; isset($config['load_balancer']['lbpool'][$i]); $i++)
87
		if (($_POST['name'] == $config['load_balancer']['lbpool'][$i]['name']) && ($i != $id))
88
	for ($i=0; isset($config['load_balancer']['lbpool'][$i]); $i++) {
89
		if (($_POST['name'] == $config['load_balancer']['lbpool'][$i]['name']) && ($i != $id)) {
88 90
			$input_errors[] = gettext("This pool name has already been used.  Pool names must be unique.");
91
		}
92
	}
89 93

  
90
	if (preg_match('/[ \/]/', $_POST['name']))
94
	if (preg_match('/[ \/]/', $_POST['name'])) {
91 95
		$input_errors[] = gettext("You cannot use spaces or slashes in the 'name' field.");
96
	}
92 97

  
93
	if (strlen($_POST['name']) > 16)
98
	if (strlen($_POST['name']) > 16) {
94 99
		$input_errors[] = gettext("The 'name' field must be 16 characters or less.");
100
	}
95 101

  
96
	if (in_array($_POST['name'], $reserved_table_names))
102
	if (in_array($_POST['name'], $reserved_table_names)) {
97 103
		$input_errors[] = sprintf(gettext("The name '%s' is a reserved word and cannot be used."), $_POST['name']);
104
	}
98 105

  
99
	if (is_alias($_POST['name']))
106
	if (is_alias($_POST['name'])) {
100 107
		$input_errors[] = sprintf(gettext("Sorry, an alias is already named %s."), $_POST['name']);
108
	}
101 109

  
102
	if (!is_portoralias($_POST['port']))
110
	if (!is_portoralias($_POST['port'])) {
103 111
		$input_errors[] = gettext("The port must be an integer between 1 and 65535, or a port alias.");
112
	}
104 113

  
105 114
	// May as well use is_port as we want a positive integer and such.
106
	if (!empty($_POST['retry']) && !is_port($_POST['retry']))
115
	if (!empty($_POST['retry']) && !is_port($_POST['retry'])) {
107 116
		$input_errors[] = gettext("The retry value must be an integer between 1 and 65535.");
117
	}
108 118

  
109 119
	if (is_array($_POST['servers'])) {
110
		foreach($pconfig['servers'] as $svrent) {
120
		foreach ($pconfig['servers'] as $svrent) {
111 121
			if (!is_ipaddr($svrent) && !is_subnetv4($svrent)) {
112 122
				$input_errors[] = sprintf(gettext("%s is not a valid IP address or IPv4 subnet (in \"enabled\" list)."), $svrent);
113
			}
114
			else if (is_subnetv4($svrent) && subnet_size($svrent) > 64) {
123
			} else if (is_subnetv4($svrent) && subnet_size($svrent) > 64) {
115 124
				$input_errors[] = sprintf(gettext("%s is a subnet containing more than 64 IP addresses (in \"enabled\" list)."), $svrent);
116 125
			}
117 126
		}
118 127
	}
119 128
	if (is_array($_POST['serversdisabled'])) {
120
		foreach($pconfig['serversdisabled'] as $svrent) {
129
		foreach ($pconfig['serversdisabled'] as $svrent) {
121 130
			if (!is_ipaddr($svrent) && !is_subnetv4($svrent)) {
122 131
				$input_errors[] = sprintf(gettext("%s is not a valid IP address or IPv4 subnet (in \"disabled\" list)."), $svrent);
123
			}
124
			else if (is_subnetv4($svrent) && subnet_size($svrent) > 64) {
132
			} else if (is_subnetv4($svrent) && subnet_size($svrent) > 64) {
125 133
				$input_errors[] = sprintf(gettext("%s is a subnet containing more than 64 IP addresses (in \"disabled\" list)."), $svrent);
126 134
			}
127 135
		}
128 136
	}
129 137
	$m = array();
130
	for ($i=0; isset($config['load_balancer']['monitor_type'][$i]); $i++)
138
	for ($i=0; isset($config['load_balancer']['monitor_type'][$i]); $i++) {
131 139
		$m[$config['load_balancer']['monitor_type'][$i]['name']] = $config['load_balancer']['monitor_type'][$i];
140
	}
132 141

  
133
	if (!isset($m[$_POST['monitor']]))
142
	if (!isset($m[$_POST['monitor']])) {
134 143
		$input_errors[] = gettext("Invalid monitor chosen.");
144
	}
135 145

  
136 146
	if (!$input_errors) {
137 147
		$poolent = array();
138
		if(isset($id) && $a_pool[$id])
148
		if (isset($id) && $a_pool[$id]) {
139 149
			$poolent = $a_pool[$id];
140
		if($poolent['name'] != "")
150
		}
151
		if ($poolent['name'] != "") {
141 152
			$changedesc .= sprintf(gettext(" modified '%s' pool:"), $poolent['name']);
142
		
153
		}
154

  
143 155
		update_if_changed("name", $poolent['name'], $_POST['name']);
144 156
		update_if_changed("mode", $poolent['mode'], $_POST['mode']);
145 157
		update_if_changed("description", $poolent['descr'], $_POST['descr']);
......
152 164
		if (isset($id) && $a_pool[$id]) {
153 165
			/* modify all virtual servers with this name */
154 166
			for ($i = 0; isset($config['load_balancer']['virtual_server'][$i]); $i++) {
155
				if ($config['load_balancer']['virtual_server'][$i]['lbpool'] == $a_pool[$id]['name'])
167
				if ($config['load_balancer']['virtual_server'][$i]['lbpool'] == $a_pool[$id]['name']) {
156 168
					$config['load_balancer']['virtual_server'][$i]['lbpool'] = $poolent['name'];
169
				}
157 170
			}
158 171
			$a_pool[$id] = $poolent;
159
		} else
172
		} else {
160 173
			$a_pool[] = $poolent;
161
		
174
		}
175

  
162 176
		if ($changecount > 0) {
163 177
			/* Mark pool dirty */
164 178
			mark_subsystem_dirty('loadbalancer');
......
181 195
<?php include("fbegin.inc"); ?>
182 196
<script type="text/javascript">
183 197
//<![CDATA[
184
function clearcombo(){
185
  for (var i=document.iform.serversSelect.options.length-1; i>=0; i--){
186
    document.iform.serversSelect.options[i] = null;
187
  }
188
  document.iform.serversSelect.selectedIndex = -1;
198
function clearcombo() {
199
	for (var i=document.iform.serversSelect.options.length-1; i>=0; i--) {
200
		document.iform.serversSelect.options[i] = null;
201
	}
202
	document.iform.serversSelect.selectedIndex = -1;
189 203
}
190 204
//]]>
191 205
</script>
......
195 209

  
196 210
<?php if ($input_errors) print_input_errors($input_errors); ?>
197 211

  
198
	<form action="load_balancer_pool_edit.php" method="post" name="iform" id="iform">
212
<form action="load_balancer_pool_edit.php" method="post" name="iform" id="iform">
199 213
	<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="load balancer pool entry">
200 214
		<tr>
201 215
			<td colspan="2" valign="top" class="listtopic"><?=gettext("Add/edit Load Balancer - Pool entry"); ?></td>
......
203 217
		<tr align="left">
204 218
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Name"); ?></td>
205 219
			<td width="78%" class="vtable" colspan="2">
206
				<input name="name" type="text" <?if(isset($pconfig['name'])) echo "value=\"" . htmlspecialchars($pconfig['name']) . "\"";?> size="16" maxlength="16" />
220
				<input name="name" type="text" <?if (isset($pconfig['name'])) echo "value=\"" . htmlspecialchars($pconfig['name']) . "\"";?> size="16" maxlength="16" />
207 221
			</td>
208 222
		</tr>
209 223
		<tr align="left">
210 224
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Mode"); ?></td>
211 225
			<td width="78%" class="vtable" colspan="2">
212 226
				<select id="mode" name="mode" onchange="enforceFailover(); checkPoolControls();">
213
					<option value="loadbalance" <?if(!isset($pconfig['mode']) || ($pconfig['mode'] == "loadbalance")) echo "selected=\"selected\"";?>><?=gettext("Load Balance");?></option>
214
					<option value="failover"  <?if($pconfig['mode'] == "failover") echo "selected=\"selected\"";?>><?=gettext("Manual Failover");?></option>
227
					<option value="loadbalance" <?if (!isset($pconfig['mode']) || ($pconfig['mode'] == "loadbalance")) echo "selected=\"selected\"";?>><?=gettext("Load Balance");?></option>
228
					<option value="failover"  <?if ($pconfig['mode'] == "failover") echo "selected=\"selected\"";?>><?=gettext("Manual Failover");?></option>
215 229
				</select>
216 230
			</td>
217 231
		</tr>
218 232
		<tr align="left">
219 233
			<td width="22%" valign="top" class="vncell"><?=gettext("Description"); ?></td>
220 234
			<td width="78%" class="vtable" colspan="2">
221
				<input name="descr" type="text" <?if(isset($pconfig['descr'])) echo "value=\"" . htmlspecialchars($pconfig['descr']) . "\"";?> size="64" />
235
				<input name="descr" type="text" <?if (isset($pconfig['descr'])) echo "value=\"" . htmlspecialchars($pconfig['descr']) . "\"";?> size="64" />
222 236
			</td>
223 237
		</tr>
224 238

  
225 239
		<tr align="left">
226 240
			<td width="22%" valign="top" id="monitorport_text" class="vncellreq"><?=gettext("Port"); ?></td>
227 241
			<td width="78%" class="vtable" colspan="2">
228
				<input class="formfldalias" id="port" name="port" type="text" <?if(isset($pconfig['port'])) echo "value=\"{$pconfig['port']}\"";?> size="16" maxlength="16" /><br />
242
				<input class="formfldalias" id="port" name="port" type="text" <?if (isset($pconfig['port'])) echo "value=\"{$pconfig['port']}\"";?> size="16" maxlength="16" /><br />
229 243
				<div id="monitorport_desc">
230 244
					<?=gettext("This is the port your servers are listening on."); ?><br />
231 245
					<?=gettext("You may also specify a port alias listed in Firewall -&gt; Aliases here."); ?>
......
241 255
		<tr align="left">
242 256
			<td width="22%" valign="top" id="retry_text" class="vncell"><?=gettext("Retry"); ?></td>
243 257
			<td width="78%" class="vtable" colspan="2">
244
				<input name="retry" type="text" <?if(isset($pconfig['retry'])) echo "value=\"{$pconfig['retry']}\"";?> size="16" maxlength="16" /><br />
258
				<input name="retry" type="text" <?if (isset($pconfig['retry'])) echo "value=\"{$pconfig['retry']}\"";?> size="16" maxlength="16" /><br />
245 259
				<div id="retry_desc"><?=gettext("Optionally specify how many times to retry checking a server before declaring it down."); ?></div>
246 260
			</td>
247 261
		</tr>
......
254 268
		<tr align="left">
255 269
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Monitor"); ?></td>
256 270
			<td width="78%" class="vtable" colspan="2">
257
				<?php if(count($config['load_balancer']['monitor_type'])): ?>
271
				<?php if (count($config['load_balancer']['monitor_type'])): ?>
258 272
				<select id="monitor" name="monitor">
259 273
					<?php
260 274
						foreach ($config['load_balancer']['monitor_type'] as $monitor) {
......
275 289
		<tr align="left">
276 290
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Server IP Address"); ?></td>
277 291
			<td width="78%" class="vtable" colspan="2">
278
				<input name="ipaddr" type="text" size="16" style="float: left;" /> 
292
				<input name="ipaddr" type="text" size="16" style="float: left;" />
279 293
				<input class="formbtn" type="button" name="button1" value="<?=gettext("Add to pool"); ?>" onclick="AddServerToPool(document.iform); enforceFailover(); checkPoolControls();" /><br />
280 294
			</td>
281 295
		</tr>
......
292 306
					<tbody>
293 307
					<tr>
294 308
						<td align="center">
295
								<b><?=gettext("Pool Disabled"); ?></b>
309
							<b><?=gettext("Pool Disabled"); ?></b>
296 310
							<br/>
297 311
							<select id="serversDisabledSelect" name="serversdisabled[]" multiple="multiple" size="5">
298 312
<?php
299 313
	if (is_array($pconfig['serversdisabled'])) {
300
		foreach($pconfig['serversdisabled'] as $svrent) {
301
			if($svrent != '') echo "    <option value=\"{$svrent}\">{$svrent}</option>\n";
314
		foreach ($pconfig['serversdisabled'] as $svrent) {
315
			if ($svrent != '') echo "    <option value=\"{$svrent}\">{$svrent}</option>\n";
302 316
		}
303 317
	}
304 318
?>
......
312 326
						</td>
313 327

  
314 328
						<td align="center">
315
								<b><?=gettext("Enabled (default)"); ?></b>
329
							<b><?=gettext("Enabled (default)"); ?></b>
316 330
							<br/>
317 331
							<select id="serversSelect" name="servers[]" multiple="multiple" size="5">
318 332
<?php
319
if (is_array($pconfig['servers'])) {
320
	foreach($pconfig['servers'] as $svrent) {
321
		echo "    <option value=\"{$svrent}\">{$svrent}</option>\n";
333
	if (is_array($pconfig['servers'])) {
334
		foreach ($pconfig['servers'] as $svrent) {
335
			echo "    <option value=\"{$svrent}\">{$svrent}</option>\n";
336
		}
322 337
	}
323
}
324 338
?>
325 339
							</select>
326 340
							<input class="formbtn" type="button" name="removeEnabled" value="<?=gettext("Remove"); ?>" onclick="RemoveServerFromPool(document.iform, 'servers[]');" />
......
334 348
			<td width="22%" valign="top">&nbsp;</td>
335 349
			<td width="78%">
336 350
				<br />
337
				<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" onclick="AllServers('serversSelect', true); AllServers('serversDisabledSelect', true);" /> 
351
				<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" onclick="AllServers('serversSelect', true); AllServers('serversDisabledSelect', true);" />
338 352
				<input type="button" class="formbtn" value="<?=gettext("Cancel");?>" onclick="window.location.href='<?=$referer;?>'" />
339 353
				<?php if (isset($id) && $a_pool[$id] && $_GET['act'] != 'dup'): ?>
340 354
				<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
......
342 356
			</td>
343 357
		</tr>
344 358
	</table>
345
	</form>
359
</form>
346 360
<br />
347 361
<?php include("fend.inc"); ?>
348 362
</body>
usr/local/www/load_balancer_relay_action.php
70 70
		/* make sure no relay protocols reference this entry */
71 71
		if (is_array($config['load_balancer']['lbprotocol'])) {
72 72
			foreach ($config['load_balancer']['lbprotocol'] as $lbp) {
73
				foreach($lbp['lbaction'] as $lba) {
73
				foreach ($lbp['lbaction'] as $lba) {
74 74
					if ($lba['name'] == $a_action[$_GET['id']]['name']) {
75 75
						$input_errors[] = gettext("This entry cannot be deleted because it is still referenced by at least one relay protocol.");
76 76
						break;
......
90 90
}
91 91

  
92 92
/* Index lbpool array for easy hyperlinking */
93
/* for ($i = 0; isset($config['load_balancer']['lbprotocol'][$i]); $i++) {
93
/*
94
for ($i = 0; isset($config['load_balancer']['lbprotocol'][$i]); $i++) {
94 95
	for ($o = 0; isset($config['load_balancer']['lbprotocol'][$i]['options'][$o]); o++) {
95
		$a_vs[$i]['options'][$o] = "	
96
	$a_vs[$i]['poolname'] = "<a href=\"/load_balancer_pool_edit.php?id={$poodex[$a_vs[$i]['poolname']]}\">{$a_vs[$i]['poolname']}</a>";
97
	if ($a_vs[$i]['sitedown'] != '') {
98
		$a_vs[$i]['sitedown'] = "<a href=\"/load_balancer_pool_edit.php?id={$poodex[$a_vs[$i]['sitedown']]}\">{$a_vs[$i]['sitedown']}</a>";
99
	} else {
100
		$a_vs[$i]['sitedown'] = 'none';
96
		$a_vs[$i]['options'][$o] = "
97
		$a_vs[$i]['poolname'] = "<a href=\"/load_balancer_pool_edit.php?id={$poodex[$a_vs[$i]['poolname']]}\">{$a_vs[$i]['poolname']}</a>";
98
		if ($a_vs[$i]['sitedown'] != '') {
99
			$a_vs[$i]['sitedown'] = "<a href=\"/load_balancer_pool_edit.php?id={$poodex[$a_vs[$i]['sitedown']]}\">{$a_vs[$i]['sitedown']}</a>";
100
		} else {
101
			$a_vs[$i]['sitedown'] = 'none';
102
		}
101 103
	}
102 104
}
103 105
*/
......
117 119
<?php print_info_box_np(gettext("The load balancer configuration has been changed.<br />You must apply the changes in order for them to take effect."));?><br />
118 120
<?php endif; ?>
119 121
<table width="100%" border="0" cellpadding="0" cellspacing="0">
120
  <tr><td class="tabnavtbl">
121
  <?php
122
        /* active tabs */
123
        $tab_array = array();
124
        $tab_array[] = array(gettext("Monitors"), false, "load_balancer_monitor.php");
125
        $tab_array[] = array(gettext("Pools"), false, "load_balancer_pool.php");
126
        $tab_array[] = array(gettext("Virtual Servers"), false, "load_balancer_virtual_server.php");
127
        $tab_array[] = array(gettext("Relay Actions"), true, "load_balancer_relay_action.php");
128
        $tab_array[] = array(gettext("Relay Protocols"), false, "load_balancer_relay_protocol.php");
129
        display_top_tabs($tab_array);
130
  ?>
131
  </td></tr>
132
  <tr>
133
    <td>
134
	<div id="mainarea">
122
	<tr><td class="tabnavtbl">
123
	<?php
124
		/* active tabs */
125
		$tab_array = array();
126
		$tab_array[] = array(gettext("Monitors"), false, "load_balancer_monitor.php");
127
		$tab_array[] = array(gettext("Pools"), false, "load_balancer_pool.php");
128
		$tab_array[] = array(gettext("Virtual Servers"), false, "load_balancer_virtual_server.php");
129
		$tab_array[] = array(gettext("Relay Actions"), true, "load_balancer_relay_action.php");
130
		$tab_array[] = array(gettext("Relay Protocols"), false, "load_balancer_relay_protocol.php");
131
		display_top_tabs($tab_array);
132
	?>
133
	</td></tr>
134
	<tr>
135
		<td>
136
			<div id="mainarea">
135 137
<?
136
			$t = new MainTable();
137
			$t->edit_uri('load_balancer_relay_action_edit.php');
138
			$t->my_uri('load_balancer_relay_action.php');
139
			$t->add_column(gettext('Name'),'name',20);
140
			$t->add_column(gettext('Type'),'type',10);
141
			$t->add_column(gettext('Options'),'options',30);
142
			$t->add_column(gettext('Description'),'descr',30);
143
			$t->add_button('edit');
144
			$t->add_button('dup');
145
			$t->add_button('del');
146
			$t->add_content_array($a_action);
147
			$t->display();
138
				$t = new MainTable();
139
				$t->edit_uri('load_balancer_relay_action_edit.php');
140
				$t->my_uri('load_balancer_relay_action.php');
141
				$t->add_column(gettext('Name'),'name',20);
142
				$t->add_column(gettext('Type'),'type',10);
143
				$t->add_column(gettext('Options'),'options',30);
144
				$t->add_column(gettext('Description'),'descr',30);
145
				$t->add_button('edit');
146
				$t->add_button('dup');
147
				$t->add_button('del');
148
				$t->add_content_array($a_action);
149
				$t->display();
148 150
?>
149
	</div>
150
    </td>
151
  </tr>
151
			</div>
152
		</td>
153
	</tr>
152 154
</table>
153 155
</form>
154 156
<?php include("fend.inc"); ?>
usr/local/www/load_balancer_relay_action_edit.php
49 49
}
50 50
$a_action = &$config['load_balancer']['lbaction'];
51 51

  
52
if (is_numericint($_GET['id']))
52
if (is_numericint($_GET['id'])) {
53 53
	$id = $_GET['id'];
54
if (isset($_POST['id']) && is_numericint($_POST['id']))
54
}
55
if (isset($_POST['id']) && is_numericint($_POST['id'])) {
55 56
	$id = $_POST['id'];
57
}
56 58

  
57 59
if (isset($id) && $a_action[$id]) {
58
  $pconfig = array();
60
	$pconfig = array();
59 61
	$pconfig = $a_action[$id];
60 62
} else {
61
  // XXX - TODO, this isn't sane for this page :)
63
	// XXX - TODO, this isn't sane for this page :)
62 64
	/* Some sane page defaults */
63 65
	$pconfig['protocol'] = 'http';
64 66
	$pconfig['direction'] = 'request';
65
	$pconfig['type'] = 'cookie';	
67
	$pconfig['type'] = 'cookie';
66 68
	$pconfig['action'] = 'change';
67 69
}
68 70

  
......
102 104
//$action['http']['tcp'] = array();
103 105
//$action['http']['ssl'] = array();
104 106

  
105

  
106

  
107 107
if ($_POST) {
108 108
	$changecount++;
109 109

  
110 110
	unset($input_errors);
111 111
	$pconfig = $_POST;
112 112

  
113
  // Peel off the action and type from the post and fix $pconfig
114
  $action = explode('_', $pconfig['action']);
115
  $pconfig['action'] = $action[2];
116
  $pconfig['type'] = $action[1];
117
  unset($pconfig["type_{$pconfig['direction']}"]);
113
	// Peel off the action and type from the post and fix $pconfig
114
	$action = explode('_', $pconfig['action']);
115
	$pconfig['action'] = $action[2];
116
	$pconfig['type'] = $action[1];
117
	unset($pconfig["type_{$pconfig['direction']}"]);
118 118

  
119 119
	/* input validation */
120 120
	$reqdfields = explode(" ", "name protocol direction action descr");
......
123 123
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
124 124

  
125 125
	/* Ensure that our monitor names are unique */
126
	for ($i=0; isset($config['load_balancer']['lbactions'][$i]); $i++)
127
		if (($_POST['name'] == $config['load_balancer']['lbactions'][$i]['name']) && ($i != $id))
126
	for ($i=0; isset($config['load_balancer']['lbactions'][$i]); $i++) {
127
		if (($_POST['name'] == $config['load_balancer']['lbactions'][$i]['name']) && ($i != $id)) {
128 128
			$input_errors[] = gettext("This action name has already been used.  Action names must be unique.");
129
		}
130
	}
129 131

  
130
	if (strpos($_POST['name'], " ") !== false)
132
	if (strpos($_POST['name'], " ") !== false) {
131 133
		$input_errors[] = gettext("You cannot use spaces in the 'name' field.");
134
	}
132 135

  
133 136
	if (!$input_errors) {
134 137
		$actent = array();
135
		if(isset($id) && $a_action[$id])
138
		if (isset($id) && $a_action[$id]) {
136 139
			$actent = $a_action[$id];
137
		if($actent['name'] != "")
140
		}
141
		if ($actent['name'] != "") {
138 142
			$changedesc .= " " . sprintf(gettext("modified '%s' action:"), $actent['name']);
139
		
143
		}
144

  
140 145
		update_if_changed("name", $actent['name'], $pconfig['name']);
141 146
		update_if_changed("protocol", $actent['protocol'], $pconfig['protocol']);
142 147
		update_if_changed("type", $actent['type'], $pconfig['type']);
143 148
		update_if_changed("direction", $actent['direction'], $pconfig['direction']);
144 149
		update_if_changed("description", $actent['descr'], $pconfig['descr']);
145
    update_if_changed("action", $actent['action'], $pconfig['action']);
146
    switch ($pconfig['action']) {
147
      case "append":
148
      case "change":
149
      case "expect":
150
      case "filter": {
151
        update_if_changed("value", $actent['options']['value'], $pconfig['option_action_value']);
152
        update_if_changed("key", $actent['options']['akey'], $pconfig['option_action_key']);
153
        break; 
154
      }
155
      case "hash":
156
      case "log": {
157
        update_if_changed("key", $actent['options']['akey'], $pconfig['option_action_key']);
158
        break;
159
      }
160
    }
161
    
150
		update_if_changed("action", $actent['action'], $pconfig['action']);
151
		switch ($pconfig['action']) {
152
			case "append":
153
			case "change":
154
			case "expect":
155
			case "filter": {
156
				update_if_changed("value", $actent['options']['value'], $pconfig['option_action_value']);
157
				update_if_changed("key", $actent['options']['akey'], $pconfig['option_action_key']);
158
				break;
159
			}
160
			case "hash":
161
			case "log": {
162
				update_if_changed("key", $actent['options']['akey'], $pconfig['option_action_key']);
163
				break;
164
			}
165
		}
166

  
162 167
		if (isset($id) && $a_action[$id]) {
163
//    XXX - TODO
168
//		XXX - TODO
164 169
			/* modify all virtual servers with this name */
165 170
//			for ($i = 0; isset($config['load_balancer']['virtual_server'][$i]); $i++) {
166
//				if ($config['load_balancer']['virtual_server'][$i]['protocol'] == $a_protocol[$id]['name'])
171
//				if ($config['load_balancer']['virtual_server'][$i]['protocol'] == $a_protocol[$id]['name']) {
167 172
//					$config['load_balancer']['virtual_server'][$i]['protocol'] = $protent['name'];
173
//				}
168 174
//			}
169 175
			$a_action[$id] = $actent;
170 176
		} else {
......
185 191
$shortcut_section = "relayd";
186 192

  
187 193
include("head.inc");
188
	$types = array("http" => gettext("HTTP"), "tcp" => gettext("TCP"), "dns" => gettext("DNS"));
194
$types = array("http" => gettext("HTTP"), "tcp" => gettext("TCP"), "dns" => gettext("DNS"));
189 195
?>
190 196

  
191 197
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
......
193 199
<script type="text/javascript">
194 200

  
195 201
function updateProtocol(m) {
196
  // Default to HTTP
197
  if (m == "") {
198
    m = "http";
199
  }
202
	// Default to HTTP
203
	if (m == "") {
204
		m = "http";
205
	}
200 206
	switch (m) {
201 207
		case "dns": {
202 208
			jQuery('#type_row').hide();
......
228 234
   * based on what's been either preconfigured or "defaults"
229 235
   * This really did have to be done in PHP.
230 236
   */
231
  if (isset($pconfig['type'])) {
232
    $dtype = $pconfig['type'];
233
    $ddir = $pconfig['direction'];
234
  } else {
235
    $dtype = "cookie";
236
    $ddir = "request";
237
  }
237
	if (isset($pconfig['type'])) {
238
		$dtype = $pconfig['type'];
239
		$ddir = $pconfig['direction'];
240
	} else {
241
		$dtype = "cookie";
242
		$ddir = "request";
243
	}
238 244
	foreach ($actions['direction'][$ddir] as $type => $tv) {
239
		foreach ($actions['direction'][$ddir][$type] as $action => $av ) {
240
			if($dtype == $type) {
245
		foreach ($actions['direction'][$ddir][$type] as $action => $av) {
246
			if ($dtype == $type) {
241 247
				echo "jQuery('#{$ddir}_{$type}_{$action}').show();";
242
 			}
248
			}
243 249
		}
244 250
	}
245 251
?>
......
250 256
}
251 257

  
252 258
function updateDirection(d) {
253
  // Default to request
254
  if (d == "") {
255
    d = "request";
256
  }
257

  
258
  switch (d) {
259
    case "request": {
260
      jQuery('#type_response').prop('disabled',true);
261
      jQuery('#type_response').hide();
262
      jQuery('#type_request').prop('disabled',false);
263
      jQuery('#type_request').show();
264
      break;
265
    }
266
    case "response": {
267
      jQuery('#type_request').prop('disabled',true);
268
      jQuery('#type_request').hide();
269
      jQuery('#type_response').prop('disabled',false);
270
      jQuery('#type_response').show();
271
      break;
272
    }
273
  }
259
	// Default to request
260
	if (d == "") {
261
		d = "request";
262
	}
263

  
264
	switch (d) {
265
		case "request": {
266
			jQuery('#type_response').prop('disabled',true);
267
			jQuery('#type_response').hide();
268
			jQuery('#type_request').prop('disabled',false);
269
			jQuery('#type_request').show();
270
			break;
271
		}
272
		case "response": {
273
			jQuery('#type_request').prop('disabled',true);
274
			jQuery('#type_request').hide();
275
			jQuery('#type_response').prop('disabled',false);
276
			jQuery('#type_response').show();
277
			break;
278
		}
279
	}
274 280
}
275 281

  
276 282

  
277
function updateType(t){
278
  // Default to action_row
279
  // XXX - does this actually make any sense?
280
  if (t == "") {
281
    t = "action_row";
282
  }
283
function updateType(t) {
284
	// Default to action_row
285
	// XXX - does this actually make any sense?
286
	if (t == "") {
287
		t = "action_row";
288
	}
283 289

  
284
	switch(t) {
290
	switch (t) {
285 291
<?php
286 292
	/* OK, so this is sick using php to generate javascript, but it needed to be done */
287 293
	foreach ($types as $key => $val) {
......
301 307

  
302 308

  
303 309
function updateAction(a) {
304
  // Default to change
305
  if (a == "") {
306
    a = "change";
307
  }
308
  switch(a) {
309
    case "append": {
310
      jQuery('#input_action_value').show();
311
      jQuery('#option_action_value').prop('disabled',false);
312
      jQuery('#input_action_key').show();
313
      jQuery('#option_action_key').prop('disabled',false);
314
      jQuery('#input_action_id').hide();
315
      jQuery('#option_action_id').prop('disabled',true);
316
      jQuery('#action_action_value').html("&nbsp;to&nbsp;");
317
      jQuery('#action_action_id').html("");
318
      break;
319
    }
320
    case "change": {
321
      jQuery('#input_action_value').show();
322
      jQuery('#option_action_value').prop('disabled',false);
323
      jQuery('#input_action_key').show();
324
      jQuery('#option_action_key').prop('disabled',false);
325
      jQuery('#input_action_id').hide();
326
      jQuery('#option_action_id').prop('disabled',true);
327
      jQuery('#action_action_value').html("&nbsp;of&nbsp;");
328
      jQuery('#action_action_id').html("");
329
      break;
330
    }
331
    case "expect": {
332
      jQuery('#input_action_value').show();
333
      jQuery('#option_action_value').prop('disabled',false);
334
      jQuery('#input_action_key').show();
335
      jQuery('#option_action_key').prop('disabled',false);
336
      jQuery('#input_action_id').hide();
337
      jQuery('#option_action_id').prop('disabled',true);
338
      jQuery('#action_action_value').html("&nbsp;from&nbsp;");
339
      jQuery('#action_action_id').html("");
340
      break;
341
    }
342
    case "filter": {
343
      jQuery('#input_action_value').show();
344
      jQuery('#option_action_value').prop('disabled',false);
345
      jQuery('#input_action_key').show();
346
      jQuery('#option_action_key').prop('disabled',false);
347
      jQuery('#input_action_id').hide();
348
      jQuery('#option_action_id').prop('disabled',true);
349
      jQuery('#action_action_value').html("&nbsp;from&nbsp;");
350
      jQuery('#action_action_id').html("");
351
      break;
352
    }
353
    case "hash": {
354
      jQuery('#input_action_value').hide();
355
      jQuery('#option_action_value').prop('disabled',true);
356
      jQuery('#input_action_key').show();
357
      jQuery('#option_action_key').prop('disabled',false);
358
      jQuery('#input_action_id').hide();
359
      jQuery('#option_action_id').prop('disabled',true);
360
      jQuery('#action_action_value').html("");
361
      jQuery('#action_action_id').html("");
362
      break;
363
    }
364
    case "log": {
365
      jQuery('#input_action_value').hide();
366
      jQuery('#option_action_value').prop('disabled',true);
367
      jQuery('#input_action_key').show();
368
      jQuery('#option_action_key').prop('disabled',false);
369
      jQuery('#input_action_id').hide();
370
      jQuery('#option_action_id').prop('disabled',true);
371
      jQuery('#action_action_value').html("");
372
      jQuery('#action_action_id').html("");
373
      break;
374
    }
375
    case "mark": {
376
      jQuery('#input_action_value').show();
377
      jQuery('#option_action_value').prop('disabled',false);
378
      jQuery('#input_action_key').show();
379
      jQuery('#option_action_key').prop('disabled',false);
380
      jQuery('#input_action_id').show();
381
      jQuery('#option_action_id').prop('disabled',false);
382
      jQuery('#action_action_value').html("&nbsp;from&nbsp;");
383
      jQuery('#action_action_id').html("&nbsp;with&nbsp;");
384
      break;
385
    }
386
  }
310
	// Default to change
311
	if (a == "") {
312
		a = "change";
313
	}
314
	switch (a) {
315
		case "append": {
316
			jQuery('#input_action_value').show();
317
			jQuery('#option_action_value').prop('disabled',false);
318
			jQuery('#input_action_key').show();
319
			jQuery('#option_action_key').prop('disabled',false);
320
			jQuery('#input_action_id').hide();
321
			jQuery('#option_action_id').prop('disabled',true);
322
			jQuery('#action_action_value').html("&nbsp;to&nbsp;");
323
			jQuery('#action_action_id').html("");
324
			break;
325
		}
326
		case "change": {
327
			jQuery('#input_action_value').show();
328
			jQuery('#option_action_value').prop('disabled',false);
329
			jQuery('#input_action_key').show();
330
			jQuery('#option_action_key').prop('disabled',false);
331
			jQuery('#input_action_id').hide();
332
			jQuery('#option_action_id').prop('disabled',true);
333
			jQuery('#action_action_value').html("&nbsp;of&nbsp;");
334
			jQuery('#action_action_id').html("");
335
			break;
336
		}
337
		case "expect": {
338
			jQuery('#input_action_value').show();
339
			jQuery('#option_action_value').prop('disabled',false);
340
			jQuery('#input_action_key').show();
341
			jQuery('#option_action_key').prop('disabled',false);
342
			jQuery('#input_action_id').hide();
343
			jQuery('#option_action_id').prop('disabled',true);
344
			jQuery('#action_action_value').html("&nbsp;from&nbsp;");
345
			jQuery('#action_action_id').html("");
346
			break;
347
		}
348
		case "filter": {
349
			jQuery('#input_action_value').show();
350
			jQuery('#option_action_value').prop('disabled',false);
351
			jQuery('#input_action_key').show();
352
			jQuery('#option_action_key').prop('disabled',false);
353
			jQuery('#input_action_id').hide();
354
			jQuery('#option_action_id').prop('disabled',true);
355
			jQuery('#action_action_value').html("&nbsp;from&nbsp;");
356
			jQuery('#action_action_id').html("");
357
			break;
358
		}
359
		case "hash": {
360
			jQuery('#input_action_value').hide();
361
			jQuery('#option_action_value').prop('disabled',true);
362
			jQuery('#input_action_key').show();
363
			jQuery('#option_action_key').prop('disabled',false);
364
			jQuery('#input_action_id').hide();
365
			jQuery('#option_action_id').prop('disabled',true);
366
			jQuery('#action_action_value').html("");
367
			jQuery('#action_action_id').html("");
368
			break;
369
		}
370
		case "log": {
371
			jQuery('#input_action_value').hide();
372
			jQuery('#option_action_value').prop('disabled',true);
373
			jQuery('#input_action_key').show();
374
			jQuery('#option_action_key').prop('disabled',false);
375
			jQuery('#input_action_id').hide();
376
			jQuery('#option_action_id').prop('disabled',true);
377
			jQuery('#action_action_value').html("");
378
			jQuery('#action_action_id').html("");
379
			break;
380
		}
381
		case "mark": {
382
			jQuery('#input_action_value').show();
383
			jQuery('#option_action_value').prop('disabled',false);
384
			jQuery('#input_action_key').show();
385
			jQuery('#option_action_key').prop('disabled',false);
386
			jQuery('#input_action_id').show();
387
			jQuery('#option_action_id').prop('disabled',false);
388
			jQuery('#action_action_value').html("&nbsp;from&nbsp;");
389
			jQuery('#action_action_id').html("&nbsp;with&nbsp;");
390
			break;
391
		}
392
	}
387 393
}
388 394

  
389 395

  
......
393 399

  
394 400

  
395 401
jQuery(document).ready(function() {
396
  updateProtocol('<?=htmlspecialchars($pconfig['protocol'])?>');  
397
  updateDirection('<?=htmlspecialchars($pconfig['direction'])?>');  
398
  updateType('<?=htmlspecialchars($pconfig['type'])?>');  
399
  updateAction('<?=htmlspecialchars($pconfig['action'])?>');  
402
	updateProtocol('<?=htmlspecialchars($pconfig['protocol'])?>');
403
	updateDirection('<?=htmlspecialchars($pconfig['direction'])?>');
404
	updateType('<?=htmlspecialchars($pconfig['type'])?>');
405
	updateAction('<?=htmlspecialchars($pconfig['action'])?>');
400 406
});
401 407

  
402 408
</script>
403 409

  
404 410
<?php include("fbegin.inc"); ?>
405 411
<?php if ($input_errors) print_input_errors($input_errors); ?>
406
	<form action="load_balancer_relay_action_edit.php" method="post" name="iform" id="iform">
412
<form action="load_balancer_relay_action_edit.php" method="post" name="iform" id="iform">
407 413
	<table width="100%" border="0" cellpadding="6" cellspacing="0">
408 414
		<tr>
409 415
			<td colspan="2" valign="top" class="listtopic"><?=gettext("Edit Load Balancer - Relay Action entry"); ?></td>
......
411 417
		<tr align="left" id="name">
412 418
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Name"); ?></td>
413 419
			<td width="78%" class="vtable" colspan="2">
414
				<input name="name" type="text" <?if(isset($pconfig['name'])) echo "value=\"{$pconfig['name']}\"";?> size="16" maxlength="16">
420
				<input name="name" type="text" <?if (isset($pconfig['name'])) echo "value=\"{$pconfig['name']}\"";?> size="16" maxlength="16">
415 421
			</td>
416 422
		</tr>
417 423
		<tr align="left">
418 424
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Description"); ?></td>
419 425
			<td width="78%" class="vtable" colspan="2">
420
				<input name="descr" type="text" <?if(isset($pconfig['descr'])) echo "value=\"{$pconfig['descr']}\"";?>size="64">
426
				<input name="descr" type="text" <?if (isset($pconfig['descr'])) echo "value=\"{$pconfig['descr']}\"";?>size="64">
421 427
			</td>
422 428
		</tr>
423 429
<!-- Protocol -->
......
427 433
				<select id="protocol" name="protocol">
428 434
<?
429 435
	foreach ($actions['protocol'] as $key => $val) {
430
		if(isset($pconfig['protocol']) && $pconfig['protocol'] == $key) {
436
		if (isset($pconfig['protocol']) && $pconfig['protocol'] == $key) {
431 437
			$selected = " selected";
432 438
		} else {
433 439
			$selected = "";
......
446 452
				<select id="direction" name="direction" style="disabled">
447 453
<?
448 454
	foreach ($actions['direction'] as $key => $val) {
449
		if(isset($pconfig['direction']) && $pconfig['direction'] == $key) {
455
		if (isset($pconfig['direction']) && $pconfig['direction'] == $key) {
450 456
			$selected = " selected";
451 457
		} else {
452 458
			$selected = "";
......
455 461
	}
456 462
?>
457 463
				</select>
458

  
459 464
			</td>
460 465
		</tr>
461 466

  
462 467
<!-- Type -->
463
    <tr align="left" id="type_row"<?= $pconfig['protocol'] == "http" ? "" : " style=\"display:none;\""?>>
468
		<tr align="left" id="type_row"<?= $pconfig['protocol'] == "http" ? "" : " style=\"display:none;\""?>>
464 469
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Type"); ?></td>
465 470
			<td width="78%" class="vtable" colspan="2">
466 471
<?
467 472
	foreach ($actions['direction'] as $dir => $v) {
468
		echo"		<select id=\"type_{$dir}\" name=\"type_{$dir}\" style=\"display:none; disabled;\">";
473
		echo "<select id=\"type_{$dir}\" name=\"type_{$dir}\" style=\"display:none; disabled;\">";
469 474
		foreach ($actions['direction'][$dir] as $key => $val) {
470
			if(isset($pconfig['type']) && $pconfig['type'] == $key) {
475
			if (isset($pconfig['type']) && $pconfig['type'] == $key) {
471 476
				$selected = " selected";
472 477
			} else {
473 478
				$selected = "";
474 479
			}
475 480
			echo "<option value=\"{$key}\" onclick=\"updateDirection('$key');\"{$selected}>{$key}</option>\n";
476 481
		}
482
		echo "</select>";
477 483
	}
478
?>
479
				</select>
484
?>	
480 485
			</td>
481 486
		</tr>
482 487

  
483 488
<!-- Action -->
484
    <tr align="left" id="action_row"<?= $pconfig['protocol'] == "http" ? "" : " style=\"display:none;\""?>>
489
		<tr align="left" id="action_row"<?= $pconfig['protocol'] == "http" ? "" : " style=\"display:none;\""?>>
485 490
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Action"); ?></td>
486 491
			<td width="78%" class="vtable" colspan="2">
487 492
				<select id="action" name="action" style=\"display: none;\">
488 493
<?
489 494
	foreach ($actions['direction'] as $dir => $dv) {
490 495
		foreach ($actions['direction'][$dir] as $type => $tv) {
491
			foreach ($actions['direction'][$dir][$type] as $action => $av ) {
492
				if(isset($pconfig['action']) && $pconfig['action'] == $action) {
496
			foreach ($actions['direction'][$dir][$type] as $action => $av) {
497
				if (isset($pconfig['action']) && $pconfig['action'] == $action) {
498
					$selected = " selected";
499
				} else if ($action == "change") {
493 500
					$selected = " selected";
494
				} else if ($action == "change" ){
495
  					$selected = " selected";
496
  				} else {
497
  					$selected = "";
501
				} else {
502
					$selected = "";
498 503
				}
499 504
				echo "<option id=\"{$dir}_{$type}_{$action}\" value=\"{$dir}_{$type}_{$action}\" onClick=\"updateAction('$action');\" style=\"display: none;\"{$selected}>{$action}</option>\n";
500 505
			}
......
502 507
	}
503 508
?>
504 509
				</select>
505
<br />
506
<table><tr>
507
<td><div id="input_action_value"><?=gettext("Value"); ?>&nbsp;<input id="option_action_value" name="option_action_value" type="text" <?if(isset($pconfig['options']['value'])) echo "value=\"{$pconfig['options']['value']}\"";?>size="20"></div></td>
508
<td><div id="action_action_value"></div></td>
509
<td><div id="input_action_key"><?=gettext("Key"); ?>&nbsp;<input id="option_action_key" name="option_action_key" type="text" <?if(isset($pconfig['options']['akey'])) echo "value=\"{$pconfig['options']['akey']}\"";?>size="20"></div></td>
510
<td><div id="action_action_id"></div></td>
511
<td><div id="input_action_id"><?=gettext("ID"); ?>&nbsp;<input id="option_action_id" name="option_action_id" type="text" <?if(isset($pconfig['options']['id'])) echo "value=\"{$pconfig['options']['id']}\"";?>size="20"></div></td>
512
</tr></table>
510
				<br />
511
				<table>
512
					<tr>
513
						<td><div id="input_action_value"><?=gettext("Value"); ?>&nbsp;<input id="option_action_value" name="option_action_value" type="text" <?if (isset($pconfig['options']['value'])) echo "value=\"{$pconfig['options']['value']}\"";?>size="20"></div></td>
514
						<td><div id="action_action_value"></div></td>
515
						<td><div id="input_action_key"><?=gettext("Key"); ?>&nbsp;<input id="option_action_key" name="option_action_key" type="text" <?if (isset($pconfig['options']['akey'])) echo "value=\"{$pconfig['options']['akey']}\"";?>size="20"></div></td>
516
						<td><div id="action_action_id"></div></td>
517
						<td><div id="input_action_id"><?=gettext("ID"); ?>&nbsp;<input id="option_action_id" name="option_action_id" type="text" <?if (isset($pconfig['options']['id'])) echo "value=\"{$pconfig['options']['id']}\"";?>size="20"></div></td>
518
					</tr>
519
				</table>
513 520
			</td>
514 521
		</tr>
515 522
		<tr align="left" id="tcp_options_row"<?= $pconfig['protocol'] == "tcp" ? "" : " style=\"display:none;\""?>>
......
520 527
<!-- XXX TODO >
521 528
<?
522 529
	foreach ($types as $key => $val) {
523
		if(isset($pconfig['protocol']) && $pconfig['protocol'] == $key) {
530
		if (isset($pconfig['protocol']) && $pconfig['protocol'] == $key) {
524 531
			$selected = " selected";
525 532
		} else {
526 533
			$selected = "";
......
528 535
		echo "<option value=\"{$key}\" onclick=\"updateType('{$key}');\"{$selected}>{$val}</option>\n";
529 536
	}
530 537
?>
531
				</select>
532 538
< XXX TODO -->
539
				</select>
533 540
			</td>
534 541
		</tr>
535 542
		<tr align="left" id="ssl_options_row"<?= $pconfig['protocol'] == "http" ? "" : " style=\"display:none;\""?>>
......
540 547
				<select id="options" name="options">
541 548
<?
542 549
	foreach ($types as $key => $val) {
543
		if(isset($pconfig['protocol']) && $pconfig['protocol'] == $key) {
550
		if (isset($pconfig['protocol']) && $pconfig['protocol'] == $key) {
544 551
			$selected = " selected";
545 552
		} else {
546 553
			$selected = "";
......
563 570
			</td>
564 571
		</tr>
565 572
	</table>
566
	</form>
573
</form>
567 574
<br />
568 575
<?php include("fend.inc"); ?>
569 576
</body>
usr/local/www/load_balancer_relay_protocol.php
86 86
}
87 87

  
88 88
/* Index lbpool array for easy hyperlinking */
89
/* for ($i = 0; isset($config['load_balancer']['lbprotocol'][$i]); $i++) {
89
/*
90
for ($i = 0; isset($config['load_balancer']['lbprotocol'][$i]); $i++) {
90 91
	for ($o = 0; isset($config['load_balancer']['lbprotocol'][$i]['options'][$o]); o++) {
91
		$a_vs[$i]['options'][$o] = "	
92
	$a_vs[$i]['poolname'] = "<a href=\"/load_balancer_pool_edit.php?id={$poodex[$a_vs[$i]['poolname']]}\">{$a_vs[$i]['poolname']}</a>";
93
	if ($a_vs[$i]['sitedown'] != '') {
94
		$a_vs[$i]['sitedown'] = "<a href=\"/load_balancer_pool_edit.php?id={$poodex[$a_vs[$i]['sitedown']]}\">{$a_vs[$i]['sitedown']}</a>";
95
	} else {
96
		$a_vs[$i]['sitedown'] = 'none';
92
		$a_vs[$i]['options'][$o] = "
93
		$a_vs[$i]['poolname'] = "<a href=\"/load_balancer_pool_edit.php?id={$poodex[$a_vs[$i]['poolname']]}\">{$a_vs[$i]['poolname']}</a>";
94
		if ($a_vs[$i]['sitedown'] != '') {
95
			$a_vs[$i]['sitedown'] = "<a href=\"/load_balancer_pool_edit.php?id={$poodex[$a_vs[$i]['sitedown']]}\">{$a_vs[$i]['sitedown']}</a>";
96
		} else {
97
			$a_vs[$i]['sitedown'] = 'none';
98
		}
97 99
	}
98 100
}
99 101
*/
......
113 115
<?php print_info_box_np(gettext("The load balancer configuration has been changed") . ".<br />" . gettext("You must apply the changes in order for them to take effect."));?><br />
114 116
<?php endif; ?>
115 117
<table width="100%" border="0" cellpadding="0" cellspacing="0">
116
  <tr><td class="tabnavtbl">
117
  <?php
118
        /* active tabs */
119
        $tab_array = array();
120
        $tab_array[] = array(gettext("Monitors"), false, "load_balancer_monitor.php");
121
        $tab_array[] = array(gettext("Pools"), false, "load_balancer_pool.php");
122
        $tab_array[] = array(gettext("Virtual Servers"), false, "load_balancer_virtual_server.php");
123
        display_top_tabs($tab_array);
124
  ?>
125
  </td></tr>
126
  <tr>
127
    <td>
128
	<div id="mainarea">
118
	<tr><td class="tabnavtbl">
119
	<?php
120
		/* active tabs */
121
		$tab_array = array();
122
		$tab_array[] = array(gettext("Monitors"), false, "load_balancer_monitor.php");
123
		$tab_array[] = array(gettext("Pools"), false, "load_balancer_pool.php");
124
		$tab_array[] = array(gettext("Virtual Servers"), false, "load_balancer_virtual_server.php");
125
		display_top_tabs($tab_array);
126
	?>
127
	</td></tr>
128
	<tr>
129
		<td>
130
			<div id="mainarea">
129 131
<?
130
			$t = new MainTable();
131
			$t->edit_uri('load_balancer_relay_protocol_edit.php');
132
			$t->my_uri('load_balancer_relay_protocol.php');
133
			$t->add_column(gettext('Name'),'name',20);
134
			$t->add_column(gettext('Type'),'type',10);
135
			$t->add_column(gettext('Options'),'options',30);
136
			$t->add_column(gettext('Description'),'descr',30);
137
			$t->add_button('edit');
138
			$t->add_button('dup');
139
			$t->add_button('del');
140
			$t->add_content_array($a_protocol);
141
			$t->display();
132
				$t = new MainTable();
133
				$t->edit_uri('load_balancer_relay_protocol_edit.php');
134
				$t->my_uri('load_balancer_relay_protocol.php');
135
				$t->add_column(gettext('Name'),'name',20);
136
				$t->add_column(gettext('Type'),'type',10);
137
				$t->add_column(gettext('Options'),'options',30);
138
				$t->add_column(gettext('Description'),'descr',30);
139
				$t->add_button('edit');
140
				$t->add_button('dup');
141
				$t->add_button('del');
142
				$t->add_content_array($a_protocol);
143
				$t->display();
142 144
?>
143
	</div>
144
    </td>
145
  </tr>
145
			</div>
146
		</td>
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff