198 |
198 |
if(isset($_POST["number{$x}"]) && ctype_digit($_POST["number{$x}"])) {
|
199 |
199 |
$numbervalue = array();
|
200 |
200 |
$numbervalue['number'] = htmlspecialchars($_POST["number{$x}"]);
|
201 |
|
$numbervalue['value'] = htmlspecialchars($_POST["value{$x}"]);
|
|
201 |
$numbervalue['type'] = htmlspecialchars($_POST["itemtype{$x}"]);
|
|
202 |
$numbervalue['value'] = str_replace('"', '"', htmlspecialchars($_POST["value{$x}"]));
|
202 |
203 |
$numberoptions['item'][] = $numbervalue;
|
203 |
204 |
}
|
204 |
205 |
}
|
... | ... | |
260 |
261 |
if ($_POST['staticarp'] && $noip)
|
261 |
262 |
$input_errors[] = "Cannot enable static ARP when you have static map entries without IP addresses. Ensure all static maps have IP addresses and try again.";
|
262 |
263 |
|
|
264 |
if(is_array($pconfig['numberoptions']['item'])) {
|
|
265 |
foreach ($pconfig['numberoptions']['item'] as $numberoption) {
|
|
266 |
if ( $numberoption['type'] == 'text' && strstr($numberoption['value'], '"') )
|
|
267 |
$input_errors[] = gettext("Text type cannot include quotation marks.");
|
|
268 |
else if ( $numberoption['type'] == 'string' && !preg_match('/^"[^"]*"$/', $numberoption['value']) && !preg_match('/^[0-9a-z]{2}(?:\:[0-9a-z]{2})*$/i', $numberoption['value']) )
|
|
269 |
$input_errors[] = gettext("String type must be enclosed in quotes like \"this\" or must be a series of octets specified in hexadecimal, separated by colons, like 01:23:45:67:89:ab:cd:ef");
|
|
270 |
else if ( $numberoption['type'] == 'flag' && $numberoption['value'] != 'true' && $numberoption['value'] != 'false' && $numberoption['value'] != 'on' && $numberoption['value'] != 'off' )
|
|
271 |
$input_errors[] = gettext("Boolean type must be true, false, on, or off.");
|
|
272 |
else if ( $numberoption['type'] == 'uint8' && (!is_numeric($numberoption['value']) || $numberoption['value'] < 0 || $numberoption['value'] > 255) )
|
|
273 |
$input_errors[] = gettext("Unsigned 8-bit integer type must be a number in the range 0 to 255.");
|
|
274 |
else if ( $numberoption['type'] == 'uint16' && (!is_numeric($numberoption['value']) || $numberoption['value'] < 0 || $numberoption['value'] > 65535) )
|
|
275 |
$input_errors[] = gettext("Unsigned 16-bit integer type must be a number in the range 0 to 65535.");
|
|
276 |
else if ( $numberoption['type'] == 'uint32' && (!is_numeric($numberoption['value']) || $numberoption['value'] < 0 || $numberoption['value'] > 4294967295) )
|
|
277 |
$input_errors[] = gettext("Unsigned 32-bit integer type must be a number in the range 0 to 4294967295.");
|
|
278 |
else if ( $numberoption['type'] == 'int8' && (!is_numeric($numberoption['value']) || $numberoption['value'] < -128 || $numberoption['value'] > 127) )
|
|
279 |
$input_errors[] = gettext("Signed 8-bit integer type must be a number in the range -128 to 127.");
|
|
280 |
else if ( $numberoption['type'] == 'int16' && (!is_numeric($numberoption['value']) || $numberoption['value'] < -32768 || $numberoption['value'] > 32767) )
|
|
281 |
$input_errors[] = gettext("Signed 16-bit integer type must be a number in the range -32768 to 32767.");
|
|
282 |
else if ( $numberoption['type'] == 'int32' && (!is_numeric($numberoption['value']) || $numberoption['value'] < -2147483648 || $numberoption['value'] > 2147483647) )
|
|
283 |
$input_errors[] = gettext("Signed 32-bit integer type must be a number in the range -2147483648 to 2147483647.");
|
|
284 |
else if ( $numberoption['type'] == 'ip-address' && !is_ipaddr($numberoption['value']) && !is_hostname($numberoption['value']) )
|
|
285 |
$input_errors[] = gettext("IP address or host type must be an IP address or host name.");
|
|
286 |
}
|
|
287 |
}
|
|
288 |
|
263 |
289 |
if (!$input_errors) {
|
264 |
290 |
/* make sure the range lies within the current subnet */
|
265 |
291 |
$subnet_start = ip2ulong(long2ip32(ip2long($ifcfgip) & gen_subnet_mask_long($ifcfgsn)));
|
... | ... | |
401 |
427 |
</script>
|
402 |
428 |
|
403 |
429 |
<script type="text/javascript">
|
|
430 |
function itemtype_field(fieldname, fieldsize, n) {
|
|
431 |
return '<select name="' + fieldname + n + '" class="formselect" id="' + fieldname + n + '"><?php
|
|
432 |
$customitemtypes = array('text' => gettext('Text'), 'string' => gettext('String'), 'flag' => gettext('Boolean'),
|
|
433 |
'uint8' => gettext('Unsigned 8-bit integer'), 'uint16' => gettext('Unsigned 16-bit integer'), 'uint32' => gettext('Unsigned 32-bit integer'),
|
|
434 |
'int8' => gettext('Signed 8-bit integer'), 'int16' => gettext('Signed 16-bit integer'), 'int32' => gettext('Signed 32-bit integer'), 'ip-address' => gettext('IP address or host'));
|
|
435 |
foreach ($customitemtypes as $typename => $typedescr) {
|
|
436 |
echo "<option value=\"{$typename}\">{$typedescr}</option>";
|
|
437 |
}
|
|
438 |
?></select>';
|
|
439 |
}
|
|
440 |
|
404 |
441 |
rowname[0] = "number";
|
405 |
442 |
rowtype[0] = "textbox";
|
406 |
443 |
rowsize[0] = "10";
|
407 |
|
rowname[1] = "value";
|
408 |
|
rowtype[1] = "textbox";
|
409 |
|
rowsize[1] = "55";
|
|
444 |
rowname[1] = "itemtype";
|
|
445 |
rowtype[1] = itemtype_field;
|
|
446 |
rowname[2] = "value";
|
|
447 |
rowtype[2] = "textbox";
|
|
448 |
rowsize[2] = "40";
|
410 |
449 |
</script>
|
411 |
450 |
|
412 |
451 |
<script type="text/javascript" language="JavaScript">
|
... | ... | |
768 |
807 |
</tr>
|
769 |
808 |
<tr>
|
770 |
809 |
<td><div id="onecolumn"><?=gettext("Number");?></div></td>
|
771 |
|
<td><div id="twocolumn"><?=gettext("Value");?></div></td>
|
|
810 |
<td><div id="twocolumn"><?=gettext("Type");?></div></td>
|
|
811 |
<td><div id="threecolumn"><?=gettext("Value");?></div></td>
|
772 |
812 |
</tr>
|
773 |
813 |
<?php $counter = 0; ?>
|
774 |
814 |
<?php
|
... | ... | |
777 |
817 |
?>
|
778 |
818 |
<?php
|
779 |
819 |
$number = $item['number'];
|
|
820 |
$itemtype = $item['type'];
|
780 |
821 |
$value = $item['value'];
|
781 |
822 |
?>
|
782 |
823 |
<tr>
|
... | ... | |
784 |
825 |
<input autocomplete="off" name="number<?php echo $counter; ?>" type="text" class="formfld" id="number<?php echo $counter; ?>" size="10" value="<?=htmlspecialchars($number);?>" />
|
785 |
826 |
</td>
|
786 |
827 |
<td>
|
787 |
|
<input autocomplete="off" name="value<?php echo $counter; ?>" type="text" class="formfld" id="value<?php echo $counter; ?>" size="55" value="<?=htmlspecialchars($value);?>" />
|
|
828 |
<select name="itemtype<?php echo $counter; ?>" class="formselect" id="itemtype<?php echo $counter; ?>">
|
|
829 |
<?php
|
|
830 |
foreach ($customitemtypes as $typename => $typedescr) {
|
|
831 |
echo "<option value=\"{$typename}\" ";
|
|
832 |
if ($itemtype == $typename) echo "selected";
|
|
833 |
echo ">" . $typedescr . "</option>";
|
|
834 |
}
|
|
835 |
?>
|
|
836 |
</select>
|
|
837 |
</td>
|
|
838 |
<td>
|
|
839 |
<input autocomplete="off" name="value<?php echo $counter; ?>" type="text" class="formfld" id="value<?php echo $counter; ?>" size="40" value="<?=htmlspecialchars($value);?>" />
|
788 |
840 |
</td>
|
789 |
841 |
<td>
|
790 |
842 |
<input type="image" src="/themes/<?echo $g['theme'];?>/images/icons/icon_x.gif" onclick="removeRow(this); return false;" value="<?=gettext("Delete");?>" />
|
... | ... | |
800 |
852 |
<img border="0" src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="" title="<?=gettext("add another entry");?>" />
|
801 |
853 |
</a>
|
802 |
854 |
<script type="text/javascript">
|
803 |
|
field_counter_js = 2;
|
|
855 |
field_counter_js = 3;
|
804 |
856 |
rows = 1;
|
805 |
857 |
totalrows = <?php echo $counter; ?>;
|
806 |
858 |
loaded = <?php echo $counter; ?>;
|
Add a setting for the data type of values used with DHCP option numbers and input validation for each type. Fixes #962