Private GIT

Skip to content
Snippets Groups Projects
Commit 2bc3317b authored by phpipam's avatar phpipam
Browse files

Added selectable popup masks

parent 189f8201
No related branches found
No related tags found
No related merge requests found
......@@ -37,6 +37,6 @@ $_POST = $User->strip_input_tags ($_POST);
<!-- footer -->
<div class="pFooter">
<div class="btn-group">
<button class="btn btn-sm btn-default <?php print @$_POST['closeClass']; ?>"><?php print _('Close'); ?></button>
<button class="btn btn-sm btn-default <?php print @$_REQUEST['closeClass']; ?>"><?php print _('Close'); ?></button>
</div>
</div>
......@@ -4,16 +4,36 @@
* print subnet masks
*/
# default mask
$posted_mask = "10";
# get masks
if(isset($_GET['mask'])) {
if($_GET['mask']<10 || $_GET['mask']>32) {
$masks = $Subnets->get_ipv4_masks ();
}
else {
$masks = $Subnets->get_ipv4_masks_for_subnet ($_GET['mask']);
$posted_mask = $_GET['mask'];
}
}
else {
$masks = $Subnets->get_ipv4_masks ();
}
?>
<?php
if(!$popup) {
print "<h4>"._('Subnet masks')."</h4><hr>";
$colspan = "8";
}
else {
$colspan = "6";
}
?>
<div class='subnet_table_overlay'>
<table class="<?php if(!$popup) print "subnet-mask-table sorted";?> table nosearch nopagination table-noborder1 table-hover table-condensed table-top <?php if(!$popup) print 'table-auto'; ?>" data-cookie-id-table="masks">
<!-- headers -->
......@@ -36,6 +56,7 @@ if(!$popup) {
<!-- values -->
<tbody>
<?php
foreach($masks as $m) {
if($m->bitmask<31 && $m->bitmask>7) {
......@@ -55,5 +76,32 @@ foreach($masks as $m) {
}
}
?>
<tr>
<td colspan="<?php print $colspan; ?>">
<form>
<div class="input-group pull-right">
<input type="text" class="form-control input-sm" name='mask' placeholder="<?php print _("Enter mask"); ?>" value='<?php print $posted_mask; ?>'>
<span class="input-group-btn">
<button class="btn btn-default input-sm" type="submit"><?php print _("Update"); ?></button>
</span>
</div>
</form>
</td>
</tr>
</tbody>
</table>
</div>
<?php if($popup) { ?>
<script type="text/javascript">
$(document).ready(function () {
$('form').submit(function () {
$('#popupOverlay2 div.popup_wmasks').load("app/tools/subnet-masks/popup.php?mask="+$('input[name=mask]').val()+"&closeClass=hidePopup2");
return false;
})
});
</script>
<?php } ?>
\ No newline at end of file
......@@ -940,7 +940,40 @@ class Subnets extends Common_functions {
return $out;
}
/**
* Returns all IPv4 subnet masks with different presentations
*
* @access public
* @return array
*/
public function get_ipv4_masks_for_subnet ($subnet_mask = "32") {
$out = array();
# loop masks
for($mask=32; $mask>=$subnet_mask; $mask--) {
// initialize
$out[$mask] = new StdClass ();
// fake cidr
$this->initialize_pear_net_IPv4 ();
$net = $this->Net_IPv4->parseAddress("10.0.0.0/$mask");
// set
$out[$mask]->bitmask = $mask; // bitmask
$out[$mask]->netmask = $net->netmask; // netmask
$out[$mask]->host_bits = 32-$mask; // host bits
$out[$mask]->subnet_bits = 32-$out[$mask]->host_bits; // network bits
$out[$mask]->hosts = number_format( $this->max_hosts(['subnet'=>'10.0.0.0', 'mask'=>$mask]) , 0, ",", "."); // max hosts
$out[$mask]->subnets = number_format(pow(2,($mask-$subnet_mask)), 0, ",", ".");
$out[$mask]->wildcard = long2ip(~ip2long($net->netmask)); //0.0.255.255
// binary
$parts = explode(".", $net->netmask);
foreach($parts as $k=>$p) { $parts[$k] = str_pad(decbin($p),8, 0); }
$out[$mask]->binary = implode(".", $parts);
}
# return result
return $out;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment