本文整理汇总了PHP中Subnets::fetch_subnet方法的典型用法代码示例。如果您正苦于以下问题:PHP Subnets::fetch_subnet方法的具体用法?PHP Subnets::fetch_subnet怎么用?PHP Subnets::fetch_subnet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Subnets
的用法示例。
在下文中一共展示了Subnets::fetch_subnet方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Subnets
$Subnets = new Subnets($Database);
$Tools = new Tools($Database);
$Addresses = new Addresses($Database);
# verify that user is logged in
$User->check_user_session();
# set sorting
$tmp = explode("|", $_POST['direction']);
$sort['field'] = $tmp[0];
$sort['direction'] = $tmp[1];
if ($sort['direction'] == "asc") {
$sort['directionNext'] = "desc";
} else {
$sort['directionNext'] = "asc";
}
# subnet-related variables
$subnet = (array) $Subnets->fetch_subnet(null, $_POST['subnetId']);
//subnet details
$subnet_detailed = $Subnets->get_network_boundaries($subnet['subnet'], $subnet['mask']);
//set network boundaries
$slaves = $Subnets->has_slaves($subnet['id']) ? true : false;
//check if subnet has slaves and set slaves flag true/false
# fetch all addresses - sorted
if ($slaves) {
$addresses = $Addresses->fetch_subnet_addresses_recursive($subnet['id'], false, $sort['field'], $sort['direction']);
$slave_subnets = (array) $Subnets->fetch_subnet_slaves($subnet['id']);
} else {
$addresses = $Addresses->fetch_subnet_addresses($subnet['id'], $sort['field'], $sort['direction']);
}
# set permissions
$subnet_permission = $Subnets->check_permission($User->user, $subnet['id']);
}
示例2: Admin
# reinitialize objects
$Database = new Database_PDO();
$Admin = new Admin($Database, false);
$Addresses = new Addresses($Database);
$Subnets = new Subnets($Database);
$DNS = new DNS($Database);
$Scan = new Scan($Database);
$Result = new Result();
# insert to database
$discovered = 0;
//for mailing
foreach ($scan_subnets as $s) {
if (sizeof(@$s->discovered) > 0) {
foreach ($s->discovered as $ip) {
// fetch subnet
$subnet = $Subnets->fetch_subnet("id", $s->id);
$nsid = $subnet === false ? false : $subnet->nameserverId;
// try to resolve hostname
$hostname = $DNS->resolve_address($ip, false, true, $nsid);
//set update query
$values = array("subnetId" => $s->id, "ip_addr" => $Subnets->transform_address($ip, "decimal"), "dns_name" => $hostname['name'], "description" => "-- autodiscovered --", "note" => "This host was autodiscovered on " . $nowdate, "lastSeen" => $nowdate, "state" => "2", "action" => "add");
//insert
$Addresses->modify_address($values);
//set discovered
$discovered++;
}
}
}
# update scan time
$Scan->ping_update_scanagent_checktime(1, $nowdate);
# send mail
示例3: foreach
foreach ($custom_address_fields as $myField) {
$worksheet->write($lineCount, $x, $myField['name'], $format_title);
$x++;
}
}
//new line
$lineCount++;
//Write IP addresses
foreach ($result_addresses as $ip) {
//cast
$ip = (array) $ip;
# check permission
$subnet_permission = $Subnets->check_permission($User->user, $ip['subnetId']);
if ($subnet_permission > 0) {
//get the Subnet details
$subnet = (array) $Subnets->fetch_subnet(null, $ip['subnetId']);
//get section
$section = (array) $Sections->fetch_section(null, $subnet['sectionId']);
//get VLAN for subnet
$vlan = (array) (array) $Tools->fetch_object("vlans", "vlanId", $subnet['vlanId']);
//format vlan
if (sizeof($vlan) > 0) {
if (strlen($vlan['number']) > 0) {
$vlanText = " (vlan: " . $vlan['number'];
if (strlen($vlan['name']) > 0) {
$vlanText .= ' - ' . $vlan['name'] . ')';
} else {
$vlanText .= ")";
}
}
} else {
示例4: trim
if (@$_POST['showName'] == 1 && strlen($_POST['description']) == 0) {
$Result->show("danger", _("Please enter subnet description to show as name!"), true);
}
# verify that user has permissions to add subnet
if ($_POST['action'] == "add") {
if ($Sections->check_permission($User->user, $_POST['sectionId']) != 3) {
$Result->show("danger", _('You do not have permissions to add new subnet in this section') . "!", true, true);
}
} else {
if ($Subnets->check_permission($User->user, $_POST['subnetId']) != 3) {
$Result->show("danger", _('You do not have permissions to add edit/delete this subnet') . "!", true, true);
}
}
# we need old values for mailing
if ($_POST['action'] == "edit" || $_POST['action'] == "delete") {
$subnet_old_details = (array) $Subnets->fetch_subnet(null, $_POST['subnetId']);
}
# get mask and subnet
$_POST['mask'] = trim(strstr($_POST['subnet'], "/"), "/");
$_POST['subnet'] = strstr($_POST['subnet'], "/", true);
$_POST['id'] = $_POST['subnetId'];
//set cidr
$_POST['cidr'] = $_POST['subnet'] . "/" . $_POST['mask'];
# get section details
$section = (array) $Sections->fetch_section(null, $_POST['sectionId']);
# fetch custom fields
$custom = $Tools->fetch_custom_fields('subnets');
# get master subnet details for folder overrides
if ($_POST['masterSubnetId'] != 0) {
$master_section = (array) $Subnets->fetch_subnet(null, $_POST['masterSubnetId']);
if ($master_section['isFolder'] == 1) {
示例5:
?>
</div>
<!-- content -->
<div class="pContent">
<!-- form -->
<form id="networkEdit">
<!-- table -->
<table class="table table-noborder table-condensed">
<?php
if ($_POST['action'] == 'delete') {
?>
<!-- delete warning and network information-->
<tr>
<td style="width:150px;">
<?php
$subnet = $Subnets->fetch_subnet('id', $_POST['subnetId']);
# display network information with or without description
if ($subnet->description) {
$network = $Subnets->transform_to_dotted($subnet->subnet) . '/' . $subnet->mask . ' (' . $subnet->description . ')';
} else {
$network = $Subnets->transform_to_dotted($subnet->subnet) . '/' . $subnet->mask;
}
$Result->show("warning", "<strong>" . _('Warning') . ":</strong><br>" . _("You are about to remove the following Network from the firewall zone:<br>" . $network), false);
?>
<input type="hidden" name="masterSubnetId" value="<?php
print $_POST['subnetId'];
?>
">
</td>
<?php
} else {
示例6: foreach
<th><?php
print _('Description');
?>
</th>
<th><?php
print _('Requested by');
?>
</th>
</tr>
<?php
# print requests
foreach ($requests as $request) {
# cast
$request = (array) $request;
# get subnet details
$subnet = $Subnets->fetch_subnet("id", $request['subnetId']);
print '<tr>' . "\n";
print "\t<td><button class='btn btn-xs btn-default' data-requestid='{$request['id']}'><i class='fa fa-pencil'></i></button></td>";
print ' <td>' . $subnet->ip . '/' . $subnet->mask . ' (' . $subnet->description . ')</td>' . "\n";
print ' <td>' . $request['dns_name'] . '</td>' . "\n";
print ' <td>' . $request['description'] . '</td>' . "\n";
print ' <td>' . $request['requester'] . '</td>' . "\n";
print '</tr>' . "\n";
}
?>
</table>
<?php
}
示例7: search_subnets_inside_v6
/**
* Search inside subnets if host address is provided! ipv6
*
* @access private
* @param mixed $search_term
* @param number $high
* @param number $low
* @return array
*/
private function search_subnets_inside_v6($high, $low, $search_req)
{
// same
if ($low == $high) {
# Initialize PEAR NET object
$this->initialize_pear_net_IPv6();
// validate
if ($this->Net_IPv6->checkIPv6($search_req)) {
# ifmask remove it
if (strpos($search_req, "/") > 0) {
$search_req = $this->Net_IPv6->removeNetmaskSpec($search_req);
}
# subnets class
$Subnets = new Subnets($this->Database);
# fetch all subnets
$subnets = $Subnets->fetch_all_subnets_search("IPv6");
# loop and search
foreach ($subnets as $s) {
# cast
$s = (array) $s;
# parse address
$net = $this->Net_IPv6->parseAddress($this->transform_address($s['subnet'], "dotted") . '/' . $s['mask']);
if (gmp_cmp($low, $this->transform_address(@$net['start'], "decimal")) == 1 && gmp_cmp($low, $this->transform_address($net['end'], "decimal")) == -1) {
$ids[] = $s['id'];
}
}
# filter
$ids = sizeof(@$ids) > 0 ? array_filter($ids) : array();
# search
if (sizeof($ids) > 0) {
foreach ($ids as $id) {
$result[] = $Subnets->fetch_subnet(null, $id);
}
}
# return
return sizeof(@$result) > 0 ? array_filter($result) : array();
} else {
return array();
}
} else {
return array();
}
}
示例8: _
$Database = new Database_PDO();
$User = new User($Database);
$Admin = new Admin($Database, false);
$Subnets = new Subnets($Database);
$Addresses = new Addresses($Database);
$Result = new Result();
# verify that user is logged in
$User->check_user_session();
# create csrf token
$csrf = $User->create_csrf_cookie();
# id must be numeric
if (!is_numeric($_POST['subnetId'])) {
$Result->show("danger", _("Invalid ID"), true, true);
}
# get subnet details
$subnet = $Subnets->fetch_subnet(null, $_POST['subnetId']);
# verify that user has write permissions for subnet
$subnetPerm = $Subnets->check_permission($User->user, $subnet->id);
if ($subnetPerm < 3) {
$Result->show("danger", _('You do not have permissions to resize subnet') . '!', true, true);
}
?>
<!-- header -->
<div class="pHeader"><?php
print _('Truncate subnet');
?>
</div>
<!-- content -->
<div class="pContent">
示例9: explode
$User->check_user_session();
# permissions
$permission = $Subnets->check_permission($User->user, $_POST['subnetId']);
# die if write not permitted
if ($permission < 2) {
$Result->show("danger", _('You cannot write to this subnet'), true);
}
# check integer
is_numeric($_POST['subnetId']) ?: $Result->show("danger", _("Invalid subnet ID"), true);
# set filetype
$filetype = explode(".", $_POST['filetype']);
$filetype = end($filetype);
# get custom fields
$custom_address_fields = $Tools->fetch_custom_fields('ipaddresses');
# fetch subnet
$subnet = $Subnets->fetch_subnet("id", $_POST['subnetId']);
if ($subnet === false) {
$Result->show("danger", _("Invalid subnet ID"), true);
}
# Parse file
$outFile = $Tools->parse_import_file($filetype, $subnet, $custom_address_fields);
# Fetch all devices
$devices = $Tools->fetch_all_objects("devices", "hostname");
# cnt
$edit = 0;
$add = 0;
$invalid_lines = array();
$errors = 0;
# import each value
foreach ($outFile as $k => $line) {
// if not error
示例10: empty
if (isset($_GET['VRF']) && $_GET['VRF'] == "on") {
// get vrf
if (!empty($subnet['vrfId'])) {
$vrf = (array) $Tools->fetch_vrf(null, $subnet['vrfId']);
$worksheet->write($lineCount, $rowCount, $vrf['name'], $format_text);
} else {
$worksheet->write($lineCount, $rowCount, '', $format_text);
}
$rowCount++;
}
if (isset($_GET['master']) && $_GET['master'] == "on") {
// get master subnet
// zet - could optimize here and reference the already loaded subnets, with the help of a dictionary variable
$masterSubnet = $subnet['masterSubnetId'] == 0 || empty($subnet['masterSubnetId']) ? false : true;
if ($masterSubnet) {
$master = (array) $Subnets->fetch_subnet(null, $subnet['masterSubnetId']);
if ($master['isFolder']) {
$worksheet->write($lineCount, $rowCount, $master['description'] . " [folder]", $format_text);
} else {
$worksheet->write($lineCount, $rowCount, $master['ip'] . "/" . $master['mask'], $format_text);
}
} else {
$worksheet->write($lineCount, $rowCount, "/", $format_text);
}
$rowCount++;
}
if (isset($_GET['requests']) && $_GET['requests'] == "on") {
$worksheet->write($lineCount, $rowCount, $subnet['allowRequests'], $format_text);
$rowCount++;
}
if (isset($_GET['hostscheck']) && $_GET['hostscheck'] == "on") {
示例11: prepare_addresses_to_discover_subnetId
/**
* Returns array of all addresses to be scanned inside subnet defined with subnetId
*
* @access public
* @param mixed $subnetId
* @return void
*/
public function prepare_addresses_to_discover_subnetId($subnetId, $die)
{
# initialize classes
$Subnets = new Subnets($this->Database);
//subnet ID is provided, fetch subnet
$subnet = $Subnets->fetch_subnet(null, $subnetId);
if ($subnet === false) {
if ($die) {
die(json_encode(array("status" => 1, "error" => "Invalid subnet ID provided")));
} else {
return array();
}
}
// we should support only up to 4094 hosts!
if ($Subnets->get_max_hosts($subnet->mask, "IPv4") > 4094 && php_sapi_name() != "cli") {
if ($die) {
die(json_encode(array("status" => 1, "error" => "Scanning from GUI is only available for subnets up to /20 or 4094 hosts!")));
} else {
return array();
}
}
# set array of addresses to scan, exclude existing!
$ip = $this->get_all_possible_subnet_addresses($subnet->subnet, $subnet->mask);
# remove existing
$ip = $this->remove_existing_subnet_addresses($ip, $subnetId);
//none to scan?
if (sizeof($ip) == 0) {
if ($die) {
die(json_encode(array("status" => 1, "error" => "Didn't find any address to scan!")));
} else {
return array();
}
}
//return
return $ip;
}
示例12: die
}
//verify cidr
if (!is_numeric($argv[2])) {
if ($Subnets->verify_cidr_address($argv[2]) !== true) {
die(json_encode(array("status" => 1, "error" => "Invalid subnet CIDR address provided")));
}
}
/**
* Select how to scan based on scan type.
*
* if ping/pear make threads, if fping than just check since it has built-in threading !
*/
# fping
if ($Scan->settings->scanPingType == "fping" && $argv[1] == "discovery") {
# fetch subnet
$subnet = $Subnets->fetch_subnet(null, $argv[2]);
$subnet !== false ?: die(json_encode(array("status" => 1, "error" => "Invalid subnet ID provided")));
//set exit flag to true
$Scan->ping_set_exit(false);
# set cidr
$subnet_cidr = $Subnets->transform_to_dotted($subnet->subnet) . "/" . $subnet->mask;
# execute
$retval = $Scan->ping_address_method_fping_subnet($subnet_cidr);
# errors
if ($retval == 3) {
die(json_encode(array("status" => 1, "error" => "invalid command line arguments")));
}
if ($retval == 4) {
die(json_encode(array("status" => 1, "error" => "system call failure")));
}
# parse result
示例13: count
$Zones->get_zone_network($_POST['netZoneId']);
} else {
$Result->show('danger', _('Invalid netZone ID.'), true);
}
}
# deliver networkinformations about a specific zone
if ($_POST['noZone'] == 1) {
if ($_POST['masterSubnetId']) {
$_POST['network'][] = $_POST['masterSubnetId'];
}
if ($_POST['network']) {
$rowspan = count($_POST['network']);
$i = 1;
print '<table class="table table-noborder table-condensed" style="padding-bottom:20px;">';
foreach ($_POST['network'] as $key => $network) {
$network = $Subnets->fetch_subnet(null, $network);
print '<tr>';
if ($i === 1) {
print '<td rowspan="' . $rowspan . '" style="width:150px;">Network</td>';
}
print '<td>';
print '<span alt="' . _('Delete Network') . '" title="' . _('Delete Network') . '" class="deleteTempNetwork" style="color:red;margin-bottom:10px;margin-top: 10px;margin-right:15px;" data-action="delete" data-subnetArrayKey="' . $key . '"><i class="fa fa-close"></i></span>';
if ($network->isFolder == 1) {
print 'Folder: ' . $network->description . '</td>';
} else {
# display network information with or without description
if ($network->description) {
print $Subnets->transform_to_dotted($network->subnet) . '/' . $network->mask . ' (' . $network->description . ')</td>';
} else {
print $Subnets->transform_to_dotted($network->subnet) . '/' . $network->mask . '</td>';
}
示例14:
$Result->show("danger", _("Invalid ID"), true, true);
}
}
# verify that user has permissions to add subnet
if ($_POST['action'] == "add") {
if ($Sections->check_permission($User->user, $_POST['sectionId']) != 3) {
$Result->show("danger", _('You do not have permissions to add new subnet in this section') . "!", true, true);
}
} else {
if ($Subnets->check_permission($User->user, $_POST['subnetId']) != 3) {
$Result->show("danger", _('You do not have permissions to add edit/delete this subnet') . "!", true, true);
}
}
# we are editing or deleting existing subnet, get old details
if ($_POST['action'] != "add") {
$folder_old_details = (array) $Subnets->fetch_subnet(null, $_POST['subnetId']);
} else {
# for selecting master subnet if added from subnet details!
if (strlen($_POST['subnetId']) > 0) {
$subnet_old_temp = (array) $Subnets->fetch_subnet(null, $_POST['subnetId']);
$subnet_old_details['masterSubnetId'] = @$subnet_old_temp['id'];
// same master subnet ID for nested
$subnet_old_details['vlanId'] = @$subnet_old_temp['vlanId'];
// same default vlan for nested
$subnet_old_details['vrfId'] = @$subnet_old_temp['vrfId'];
// same default vrf for nested
}
}
# fetch custom fields
$custom_fields = $Tools->fetch_custom_fields('subnets');
# fetch all sections
示例15: implode
}
}
# get ony ip's with empty DNS
if ($resolve_config['emptyonly'] == 1) {
$query[] = ' and `dns_name` like "" ';
}
$query[] = 'order by `ip_addr` ASC;';
//join
$query = implode("\n", $query);
}
# fetch records
$ipaddresses = $Database->getObjectsQuery($query);
# try to update dns records
foreach ($ipaddresses as $ip) {
# fetch subnet
$subnet = $Subnets->fetch_subnet("id", $ip->subnetId);
$nsid = $subnet === false ? false : $subnet->nameserverId;
# try to resolve
$hostname = $DNS->resolve_address($ip->ip_addr, null, true, $nsid);
# update if change
if ($hostname['name'] != $Subnets->transform_to_dotted($ip->ip_addr)) {
# values
$values = array("dns_name" => $hostname['name'], "id" => $ip->id);
# execute
if (!$Admin->object_modify("ipaddresses", "edit", "id", $values)) {
$Result->show_cli("Failed to update address " . $Subnets->transform_to_dotted($ip->ip_addr));
}
# set text
$res[] = 'updated ip address ' . $Subnets->transform_to_dotted($ip->ip_addr) . ' with hostname ' . $hostname['name'];
}
}