本文整理汇总了PHP中Subnets::transform_address方法的典型用法代码示例。如果您正苦于以下问题:PHP Subnets::transform_address方法的具体用法?PHP Subnets::transform_address怎么用?PHP Subnets::transform_address使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Subnets
的用法示例。
在下文中一共展示了Subnets::transform_address方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: explode
# set and check permissions
$subnet_permission = $Subnets->check_permission($User->user, $subnet['id']);
$subnet_permission > 1 ?: $Result->show("danger", _('Cannot edit IP address details') . '! <br>' . _('You do not have write access for this network'), true, true);
# set selected address fields array
$selected_ip_fields = $User->settings->IPfilter;
$selected_ip_fields = explode(";", $selected_ip_fields);
//format to array
# get all custom fields
$custom_fields = $Tools->fetch_custom_fields('ipaddresses');
# if subnet is full we cannot any more ip addresses
if (($action == "add" || $action == "all-add") && $subnet['isFull'] == 1) {
$Result->show("warning", _("Cannot add address as subnet is market as used"), true, true);
}
# if action is not add then fetch current details, otherwise fetch first available IP address
if ($action == "all-add") {
$address['ip_addr'] = $Subnets->transform_address($id, "dotted");
} else {
if ($action == "add") {
# get first available IP address
$first = $Addresses->get_first_available_address($subnetId, $Subnets);
$first = !$first ? "" : $Subnets->transform_address($first, "dotted");
$address['ip_addr'] = $first;
} else {
$address = (array) $Addresses->fetch_address(null, $id);
}
}
# Set action and button text
if ($action == "add") {
$btnName = _("add");
$act = "add";
} else {
示例2: elseif
if ($l['isFolder'] == 1) {
$l['ctype'] = "Folder";
} else {
$l['ctype'] = "Subnet";
}
break;
case "section":
$l['ctype'] = "Section";
break;
}
print "<tr>";
print "\t<td>{$l['real_name']}</td>";
print "\t<td>{$l['ctype']} / {$l['caction']} {$l['cresult']}</td>";
# subnet, section or ip address
if ($l['ctype'] == "IP address") {
print "\t<td><a href='" . create_link("subnets", $l['sectionId'], $l['subnetId'], "address-details", $l['tid']) . "'>" . $Subnets->transform_address($l['ip_addr'], "dotted") . "</a></td>";
} elseif ($l['ctype'] == "Subnet") {
print "\t<td><a href='" . create_link("subnets", $l['sectionId'], $l['tid']) . "'>" . $Subnets->transform_address($l['ip_addr'], "dotted") . "/{$l['mask']}</a></td>";
} elseif ($l['ctype'] == "Folder") {
print "\t<td><a href='" . create_link("folder", $l['sectionId'], $l['tid']) . "'>{$l['sDescription']}</a></td>";
} elseif ($l['ctype'] == "Section") {
print "\t<td><a href='" . create_link("subnets", $l['tid']) . "'>{$l['sDescription']}</a></td>";
}
print "\t<td>{$l['cdate']}</td>";
print "\t<td class='hidden-xs'>" . implode("<br>", $diff) . "</td>";
print "</tr>";
// next item
$pc++;
}
}
}
示例3: strlen
$User->check_user_session();
# id must be numeric
is_numeric($_POST['id']) || strlen($_POST['id']) == 0 ?: $Result->show("danger", _("Invalid ID"), true);
# get IP address id
$id = $_POST['id'];
# fetch subnet, vlan and nameservers
$subnet = (array) $Subnets->fetch_subnet(null, $_POST['id']);
$vlan = (array) $Tools->fetch_object("vlans", "vlanId", $subnet['vlanId']);
$vrf = (array) $Tools->fetch_object("vrf", "vrfId", $subnet['vrfId']);
$nameservers = (array) $Tools->fetch_object("nameservers", "id", $subnet['nameserverId']);
# get all custom fields
$custom_fields = $Tools->fetch_custom_fields('subnets');
# checks
sizeof($subnet) > 0 ?: $Result->show("danger", _("Invalid subnet"), true);
# set title
$title = _('Subnet details') . ' :: ' . $Subnets->transform_address($subnet['subnet'], "dotted") . "/" . $subnet['mask'];
# address
$content[] = "• " . _('Subnet') . ": \t\t " . $Subnets->transform_address($subnet['subnet'], "dotted") . "/" . $subnet['mask'];
# description
empty($subnet['description']) ?: ($content[] = "• " . _('Description') . ":\t\t {$subnet['description']}");
# gateway
$gateway = $Subnets->find_gateway($subnet['id']);
if ($gateway !== false) {
$content[] = "• " . _('Gateway') . ": \t\t" . $Subnets->transform_to_dotted($gateway->ip_addr);
}
# VLAN
empty($subnet['vlanId']) ?: ($content[] = "• " . _('VLAN') . ": \t\t\t {$vlan['number']} ({$vlan['name']})");
# VLAN
empty($subnet['vlanId']) ?: ($content[] = "• " . _('VRF') . ": \t\t\t {$vrf['name']} ({$vrf['description']})");
# Nameserver sets
if (!empty($subnet['nameserverId'])) {
示例4: Subnets
$Subnets = new Subnets($Database);
$Addresses = new Addresses($Database);
$Tools = new Tools($Database);
$Result = new Result();
# fetch all subnets
$all_subnets = $Tools->fetch_all_objects("subnets");
# loop and check usage for each, make sure it does not have any parent
foreach ($all_subnets as $k => $s) {
// marked as full should not be checked
if ($s->isFull != 1) {
// parent check
if (!$Subnets->has_slaves($s->id)) {
// count number of addresses
$cnt = $Addresses->count_subnet_addresses($s->id);
// calculate usage
$usage = $Subnets->calculate_subnet_usage($cnt, $s->mask, $s->subnet, $s->isFull);
// if more than $threshold report
if ($usage['freehosts_percent'] < 100 - $limit) {
// this subnet has high usage, save it to array
$out[$k]['subnet'] = $Subnets->transform_address($s->subnet, "dotted") . "/" . $s->mask;
$out[$k]['description'] = $s->description;
$out[$k]['usage'] = $usage;
}
}
}
}
# any fount
if (isset($out)) {
// do something with output
print_r($out);
}
示例5: foreach
print "</tr>";
print "<tbody id=device-{$deviceid}>";
foreach ($query_result as $ip) {
//get bitmask
foreach ($masks as $k => $n) {
if ($n->netmask == $ip['mask']) {
$ip['bitmask'] = $k;
break;
}
}
$overlap = false;
// check for overlapping
if (isset($subnet)) {
if ($subnet->isFolder != "1") {
// check
if ($Subnets->is_subnet_inside_subnet("{$ip['subnet']}/{$ip['bitmask']}", $Subnets->transform_address($subnet->subnet, "dotted") . "/" . $subnet->mask) === false) {
$overlap = true;
}
// same mask
if ($ip['subnet'] == $Subnets->transform_address($subnet->subnet, "dotted") && $ip['bitmask'] == $subnet->mask) {
$overlap = true;
}
}
}
// check overlapping
if ($overlap === false) {
$dc++;
print "<tr id='tr-{$m}'>";
//ip
print "<td>{$ip['subnet']}/{$ip['bitmask']}</td>";
//section, description, hidden
示例6: _
print "<table class='ipaddress_subnet table table-noborder table-condensed' style='margin-top:10px;'>";
print "<tr>";
print "\t<th>" . _('Hostname') . "</th>";
print " <td>" . $resolve['name'] . "</td>\n";
print "</tr>";
print "<tr>";
print "\t<th>" . _('Address') . "</th>";
print " <td>" . $address['ip'] . "</td>\n";
print "</tr>";
print "<tr>";
print "\t<th>" . _('Subnet Mask') . "</th>";
print " <td>" . $mask . "</td>\n";
print "</tr>";
print "<tr>";
print "\t<th>" . _('Default Gateway') . "</th>";
print " <td>" . $Subnets->transform_address($gateway->ip_addr, "dotted") . "</td>\n";
print "</tr>";
print "</table>";
?>
</div>
<!-- footer -->
<div class="pFooter">
<div class="btn-group">
<button class="btn btn-sm btn-default hidePopups"><?php
print _('Close');
?>
</button>
</div>
<div class="manageSubnetEditResult"></div>
示例7: _
<!-- divider -->
<tr>
<td colspan="2"><hr></td>
</tr>
<tr>
<td><?php
print _('Select new subnet');
?>
:</td>
<td>
<select name="newSubnet" class="ip_addr form-control input-sm input-w-auto">
<?php
foreach ($Subnets->slaves as $slave) {
$slave_subnet = (array) $Subnets->fetch_subnet(null, $slave);
print "<option value='{$slave_subnet['id']}'>{$slave_subnet['description']} (" . $Subnets->transform_address($slave_subnet['subnet'], "dotted") . "/{$slave_subnet['mask']})</option>";
}
?>
</select>
</td>
</tr>
</table> <!-- end edit ip address table -->
</form> <!-- end IP address edit form -->
</div>
<!-- footer -->
<div class="pFooter">
<div class="btn-group">
示例8: while
print "</div>";
} else {
$c = 0;
# for each IP in range modify
while (gmp_cmp($m, $n) != 0) {
# remove gateway if not 0
if ($c != 0) {
unset($address['is_gateway']);
}
$c++;
# reset IP address field
$address['ip_addr'] = $m;
# set multicast MAC
if ($User->settings->enableMulticast == 1) {
if ($Subnets->is_multicast($address['ip_addr'])) {
$address['mac'] = $Subnets->create_multicast_mac($Subnets->transform_address($address['ip_addr'], "dotted"));
}
}
# multicast check
if ($User->settings->enableMulticast == 1) {
if ($Subnets->is_multicast($address['ip_addr'])) {
if (!$User->is_admin(false)) {
$mtest = $Subnets->validate_multicast_mac($address['mac'], $subnet['sectionId'], $subnet['vlanId'], MCUNIQUE);
if ($mtest !== true) {
$Result->show("danger", _($mtest), true);
}
}
}
}
# validate and normalize MAC address
if ($action !== "delete") {
示例9: Result
$Result = new Result();
# verify that user is logged in
$User->check_user_session();
# validate csrf cookie
$_POST['csrf_cookie'] == $_SESSION['csrf_cookie'] ?: $Result->show("danger", _("Invalid CSRF cookie"), true);
# ID must be numeric
if (!is_numeric($_POST['subnetId'])) {
$Result->show("danger", _("Invalid ID"), true);
}
# verify that user has write permissions for subnet
if ($Subnets->check_permission($User->user, $_POST['subnetId']) < 3) {
$Result->show("danger", _('You do not have permissions to resize subnet') . '!', true);
}
# fetch old subnet details and set new
$subnet_old = (array) $Subnets->fetch_subnet(null, $_POST['subnetId']);
# verify resizing
$Subnets->verify_subnet_resize($subnet_old['subnet'], $_POST['newMask'], $subnet_old['id'], $subnet_old['vrfId'], $subnet_old['masterSubnetId'], $subnet_old['mask'], $subnet_old['sectionId']);
# we need to recalculate subnet address if needed
if ($subnet_old['mask'] < $_POST['newMask']) {
$subnet_new['subnet'] = $subnet_old['subnet'];
} else {
$new_boundaries = $Subnets->get_network_boundaries($Subnets->transform_address($subnet_old['subnet'], "dotted"), $_POST['newMask']);
$subnet_new['subnet'] = $Subnets->transform_address($new_boundaries['network'], "decimal");
}
# set update values
$values = array("id" => $_POST['subnetId'], "subnet" => $subnet_new['subnet'], "mask" => $_POST['newMask']);
if (!$Subnets->modify_subnet("resize", $values)) {
$Result->show("danger", _("Error resizing subnet") . "!", true);
} else {
$Result->show("success", _("Subnet resized successfully") . "!", true);
}
示例10: get_all_possible_subnet_addresses
/**
* Fetches all possible subnet addresses
*
* @access private
* @param $subnet //subnet in decimal format
* @param int $mask //subnet mask
* @return void //array of ip addresses in decimal format
*/
private function get_all_possible_subnet_addresses($subnet, $mask)
{
# initialize classes
$Subnets = new Subnets($this->Database);
# make sure we have proper subnet format
$subnet = $Subnets->transform_address($subnet, "decimal");
//fetch start and stop addresses
$boundaries = (object) $Subnets->get_network_boundaries($subnet, $mask);
//create array
if ($mask == 32) {
$ip[] = $Subnets->transform_to_decimal($boundaries->network);
} elseif ($mask == 31) {
$ip[] = $Subnets->transform_to_decimal($boundaries->network);
$ip[] = $Subnets->transform_to_decimal($boundaries->broadcast);
} else {
//set loop limits
$start = gmp_strval(gmp_add($Subnets->transform_to_decimal($boundaries->network), 1));
$stop = gmp_strval($Subnets->transform_to_decimal($boundaries->broadcast));
//loop
for ($m = $start; $m < $stop; $m++) {
$ip[] = $m;
}
}
//return
return $ip;
}
示例11: elseif
# error - none found but not permitted
if ($inactive_hosts === false) {
print "<blockquote style='margin-top:20px;margin-left:20px;'>";
print "<p>" . _("No inactive hosts found") . "</p>";
print "</blockquote>";
} elseif (!isset($out)) {
print "<blockquote style='margin-top:20px;margin-left:20px;'>";
print "<p>" . _("No inactive hosts found") . "</p>";
print "</blockquote>";
} else {
// table
print "<table class='table table-top table-threshold'>";
print "<tr>";
print " <th></th>";
print " <th>" . _("Address") . "</th>";
print " <th>" . _("Subnet") . "</th>";
print " <th>" . _("Hostname") . "</th>";
print " <th>" . _("Last seen") . "</th>";
print "</tr>";
// print
foreach ($out as $s) {
print "<tr>";
print " <td><span class='status status-error'></span></td>";
print " <td><a href='" . create_link("subnets", $s->sectionId, $s->subnetId, "address-details", $s->id) . "'>" . $Subnets->transform_address($s->ip_addr) . "</a></td>";
print " <td><a href='" . create_link("subnets", $s->sectionId, $s->subnetId) . "'>" . $Subnets->transform_address($s->subnet) . "/" . $s->mask . "</a></td>";
print " <td>{$s->dns_name}</td>";
print " <td>{$s->lastSeen}</td>";
print "</tr>";
}
print "</table>";
}
示例12: foreach
}
array_multisort($used, SORT_DESC, $out);
// table
print "<table class='table table-threshold table-noborder'>";
// print
$m = 0;
foreach ($out as $s) {
if ($m < $slimit) {
# set class
$aclass = $s->usage->usedhosts_percent > $s->threshold ? "progress-bar-danger" : "progress-bar-info";
# limit description
$s->description = strlen($s->description) > 10 ? substr($s->description, 0, 10) . "..." : $s->description;
$s->description = strlen($s->description) > 0 ? " (" . $s->description . ")" : "";
# limit class
$limit_class = $s->usage->until_threshold < 0 ? "progress-limit-negative" : "progress-limit";
print "<tr>";
print " <td><i class='fa fa-sfolder fa-sitemap' style='border-right: 1px solid #ccc;padding-right:4px;'></i> <a href='" . create_link("subnets", $s->sectionId, $s->id) . "'>" . $Subnets->transform_address($s->subnet) . "/" . $s->mask . "</a> " . $s->description . "</td>";
print " <td>";
print " <div class='progress'>";
print " <div class='progress-bar {$aclass}' role='progressbar' rel='tooltip' title='" . _('Current usage') . ": " . $s->usage->usedhosts_percent . "%' aria-valuenow='" . $s->usage->usedhosts_percent . "' aria-valuemin='0' style='width: " . $s->usage->usedhosts_percent . "%;'>" . $s->usage->usedhosts_percent . "%</div>";
print " <div class='{$limit_class}' rel='tooltip' title='" . _('Threshold') . ": " . $s->threshold . "%' style='margin-left:" . $s->usage->until_threshold . "%;'> </div>";
print " </div>";
print " </td>";
print "</tr>";
// next index
$m++;
}
}
print "</table>";
print "</div>";
}
示例13: foreach
# ignore folders
if ($subnet['isFolder']) {
continue;
}
# store needed subnet information
$subnet_data[$section['id']][$subnet['vrfId']][$subnet['ip']][$subnet['mask']] = $subnet;
$subnet_data[$section['id']][$subnet['vrfId']][$subnet['ip']][$subnet['mask']]['type'] = $Subnets->identify_address($subnet['ip']);
# grab IP addresses
$ipaddresses = $Addresses->fetch_subnet_addresses($subnet['id']);
if (sizeof($ipaddresses) == 0) {
continue;
}
foreach ($ipaddresses as $ip) {
//cast
$ip = (array) $ip;
$edata[$section['id']][$subnet['vrfId']][$subnet['ip']][$subnet['mask']][$Subnets->transform_address($ip['ip_addr'], "dotted")] = $ip;
}
}
}
# Load available tags
$tag_data = array();
$ip_tags = (array) $Addresses->addresses_types_fetch();
foreach ($ip_tags as $c_tag) {
$tag_data[$c_tag['type']] = $c_tag;
}
# Load available devices
$device_data = array();
$devices = $Tools->fetch_all_objects("devices", "hostname");
if ($devices !== false) {
foreach ($devices as $c_dev) {
$c_dev = (array) $c_dev;
示例14: strlen
$format_right =& $workbook->addFormat();
$format_right->setRight(1);
$format_left =& $workbook->addFormat();
$format_left->setLeft(1);
$format_top =& $workbook->addFormat();
$format_top->setTop(1);
// Create a worksheet
//$worksheet =& $workbook->addWorksheet($subnet['description']);
$worksheet_name = $subnet['description'];
$worksheet_name = strlen($worksheet_name) > 30 ? substr($worksheet_name, 0, 27) . '...' : $worksheet_name;
$worksheet =& $workbook->addWorksheet($worksheet_name);
$lineCount = 0;
# Write title - subnet details
$worksheet->write($lineCount, $rowCount, $subnet['description'], $format_header);
$lineCount++;
$worksheet->write($lineCount, $rowCount, $Subnets->transform_address($subnet['subnet'], "dotted") . "/" . $subnet['mask'], $format_header);
$lineCount++;
# write VLAN details
$vlan = (array) $Tools->fetch_object("vlans", "vlanId", $subnet['vlanId']);
if ($vlan != false) {
$vlan_text = strlen($vlan['name']) > 0 ? "vlan: {$vlan['number']} - {$vlan['name']}" : "vlan: {$vlan['number']}";
$worksheet->write($lineCount, $rowCount, $vlan_text, $format_vlan);
$lineCount++;
}
$lineCount++;
//set row count
$rowCount = 0;
//write headers
if (isset($_GET['ip_addr']) && $_GET['ip_addr'] == "on") {
$worksheet->write($lineCount, $rowCount, _('ip address'), $format_title);
$rowCount++;
示例15:
print "<div style='display:none'>alert alert-danger</div>";
# result
print "<div class='alert alert-warning'>";
print "<strong>" . _("Warning") . "</strong>: " . _("Are you sure you want to delete IP address") . "?";
print "<hr><div style='text-align:right'>";
print "<div class='btn-group'>";
print "\t<a class='btn btn-sm btn-danger editIPSubmitDelete' id='editIPSubmitDelete'>" . _("Confirm") . "</a>";
print "</div>";
print "</div>";
print "</div>";
} else {
//fail
if (!$Addresses->modify_address($address)) {
$Result->show("danger", _('Error inserting IP address') . "!", false);
} else {
$Result->show("success", _("IP {$action} successful"), false);
// try to ping
if ($subnet['pingSubnet'] == "1" && $action == "add") {
$Ping->ping_address($Subnets->transform_address($address['ip_addr'], "dotted"));
// update status
if ($pingRes == 0) {
// print alive
$Result->show("success", _("IP address") . " " . $Subnets->transform_address($address['ip_addr'], "dotted") . " " . _("is alive"), false);
// update status
@$Ping->ping_update_lastseen($Addresses->lastId);
}
}
}
}
}
}