/** * Resolves hostname * * @access public * @param mixed $address address object * @param boolena $override override DNS resolving flag * @return void */ public function resolve_address($address, $override = false) { # settings $this->get_settings(); # addresses object $Address = new Addresses($this->Database); # make sure it is dotted format $address->ip = $Address->transform_address($address->ip_addr, "dotted"); # if dns_nameis set try to check if (empty($address->dns_name) || is_null($address->dns_name)) { # if permitted in settings if ($this->settings->enableDNSresolving == 1 || $override) { # resolve $resolved = gethostbyaddr($address->ip); if ($resolved == $address->ip) { $resolved = ""; } //resolve fails return array("class" => "resolved", "name" => $resolved); } else { return array("class" => "", "name" => ""); } } else { return array("class" => "", "name" => $address->dns_name); } }
# if errors are present print them, else execute query! if ($verify) { $Result->show("danger", _('Error') . ": {$verify} ({$address['ip_addr']})", true); } else { # set update type for update to single $address['type'] = "single"; # check for duplicate entryon adding new address if ($action == "add") { if ($Addresses->address_exists($address['ip_addr'], $address['subnetId'])) { $Result->show("danger", _('IP address') . " {$address['ip_addr']} " . _('already existing in selected network') . '!', true); } } # check for duplicate entry on edit! if ($action == "edit") { # if IP is the same than it can already exist! if ($Addresses->transform_address($address['ip_addr'], "decimal") != $address['ip_addr_old']) { if ($Addresses->address_exists($address['ip_addr'], $address['subnetId'])) { $Result->show("danger", _('IP address') . " {$address['ip_addr']} " . _('already existing in selected network') . '!', true); } } } # move checks if ($action == "move") { # check if not already used in new subnet if ($Addresses->address_exists($address['ip_addr'], $address['newSubnet'])) { $Result->show("danger", _('IP address') . " {$address['ip_addr']} " . _('already existing in selected network') . '!', true); } } # multicast check if ($User->settings->enableMulticast == 1 && $subnet_is_multicast) { if (!$User->is_admin(false)) {
/* if action is reject set processed and accepted to 1 and 0 */ if ($_POST['action'] == "reject") { //set reject values $values = array("id" => $_POST['requestId'], "processed" => 1, "accepted" => 0, "adminComment" => @$_POST['adminComment']); if (!$Admin->object_modify("requests", "edit", "id", $values)) { $Result->show("danger", _("Failed to reject IP request"), true); } else { $Result->show("success", _("Request has beed rejected"), false); } # send mail $Tools->ip_request_send_mail("reject", $_POST); } else { // fetch subnet $subnet_temp = $Addresses->transform_to_dotted($subnet['subnet']) . "/" . $subnet['mask']; //verify IP and subnet $Addresses->verify_address($Addresses->transform_address($_POST['ip_addr'], "dotted"), $subnet_temp, false, true); //check if already existing and die if ($Addresses->address_exists($Addresses->transform_address($_POST['ip_addr'], "decimal"), $subnet['id'])) { $Result->show("danger", _('IP address already exists'), true); } //insert to ipaddresses table $values = array("action" => "add", "ip_addr" => $Addresses->transform_address($_POST['ip_addr'], "decimal"), "subnetId" => $_POST['subnetId'], "description" => @$_POST['description'], "dns_name" => @$_POST['dns_name'], "mac" => @$_POST['mac'], "owner" => @$_POST['owner'], "state" => @$_POST['state'], "switch" => @$_POST['switch'], "port" => @$_POST['port'], "note" => @$_POST['note']); if (!$Addresses->modify_address($values)) { $Result->show("danger", _("Failed to create IP address"), true); } //accept message $values2 = array("id" => $_POST['requestId'], "processed" => 1, "accepted" => 1, "adminComment" => $comment); if (!$Admin->object_modify("requests", "edit", "id", $values2)) { $Result->show("danger", _("Cannot confirm IP address"), true); } else { $Result->show("success", _("IP request accepted/rejected"), false);
} $dns_records[] = "</ul>"; // if none ignore $dns_records = sizeof($dns_records) == 3 ? "" : implode(" ", $dns_records); } else { $dns_records = ""; } } else { $dns_records = ""; $button = ""; } // add button if ($User->settings->enablePowerDNS == 1) { // add new button if ($Subnets->validate_hostname($addresses[$n]->dns_name) && ($User->isadmin || @$User->user->pdns == "Yes")) { $button = "<i class='fa fa-plus-circle fa-gray fa-href editRecord' data-action='add' data-id='" . $Addresses->transform_address($addresses[$n]->ip_addr, "dotted") . "' data-domain_id='" . $addresses[$n]->dns_name . "'></i>"; } else { $button = ""; } } # resolve dns name $resolve = $DNS->resolve_address($addresses[$n]->ip_addr, $addresses[$n]->dns_name, false, $subnet['nameserverId']); print "<td class='{$resolve['class']} hostname'>{$resolve['name']} {$button} {$dns_records}</td>"; # print firewall address object - mandatory if enabled if (in_array('firewallAddressObject', $selected_ip_fields) && $zone) { print "<td class='fwzone'>" . $addresses[$n]->firewallAddressObject . "</td>"; } # print description - mandatory print "<td class='description'>" . $addresses[$n]->description . "</td>"; # Print mac address icon! if (in_array('mac', $selected_ip_fields)) {
# fetch subnet $subnet = (array) $Admin->fetch_object("subnets", "id", $_POST['subnetId']); /* if action is reject set processed and accepted to 1 and 0 */ if ($_POST['action'] == "reject") { //set reject values $values = array("id" => $_POST['requestId'], "processed" => 1, "accepted" => 0, "adminComment" => @$_POST['adminComment']); if (!$Admin->object_modify("requests", "edit", "id", $values)) { $Result->show("danger", _("Failed to reject IP request"), true); } else { $Result->show("success", _("Request has beed rejected"), false); } } else { // fetch subnet $subnet_temp = $Addresses->transform_to_dotted($subnet['subnet']) . "/" . $subnet['mask']; //verify IP and subnet $Addresses->verify_address($Addresses->transform_address($_POST['ip_addr'], "dotted"), $subnet_temp, false, true); //check if already existing and die if ($Addresses->address_exists($Addresses->transform_address($_POST['ip_addr'], "decimal"), $subnet['id'])) { $Result->show("danger", _('IP address already exists'), true); } //insert to ipaddresses table $values = array("action" => "add", "ip_addr" => $Addresses->transform_address($_POST['ip_addr'], "decimal"), "subnetId" => $_POST['subnetId'], "description" => @$_POST['description'], "dns_name" => @$_POST['dns_name'], "mac" => @$_POST['mac'], "owner" => @$_POST['owner'], "state" => @$_POST['state'], "switch" => @$_POST['switch'], "port" => @$_POST['port'], "note" => @$_POST['note']); if (!$Addresses->modify_address($values)) { $Result->show("danger", _("Failed to create IP address"), true); } //accept message $values = array("id" => $_POST['requestId'], "processed" => 1, "accepted" => 1, "adminComment" => $comment); if (!$Admin->object_modify("requests", "edit", "id", $values)) { $Result->show("danger", _("Cannot confirm IP address"), true); } else { $Result->show("success", _("IP request accepted/rejected"), false);