if ($_POST['type'] !== "src" && $_POST['type'] !== "dst") {
    $Result->show("danger", _("Invalid type"), true);
}
# if type (subnets, ipaddresses) is set and id than just link
if (isset($_POST['object_type']) && isset($_POST['object_id'])) {
    // parameters
    $obj_type = $_POST['object_type'];
    // subnets, ipaddresses
    $obj_id = $_POST['object_id'];
    // object identifier
    $nat_id = $_POST['id'];
    // nat id
    $nat_type = $_POST['type'];
    // src, dst
    // validate object
    $item = $Tools->fetch_object($obj_type, "id", $obj_id);
    if ($item !== false) {
        // update
        if ($nat_type == "src") {
            $nat_array = json_decode($nat->src, true);
        } else {
            $nat_array = json_decode($nat->dst, true);
        }
        if (is_array($nat_array[$obj_type])) {
            $nat_array[$obj_type] = array_merge($nat_array[$obj_type], array($obj_id));
        } else {
            $nat_array[$obj_type] = array($obj_id);
        }
        // to json
        if ($nat_type == "src") {
            $nat->src = json_encode($nat_array);
Example #2
0
# include funtions
require dirname(__FILE__) . '/../../functions/functions.php';
// functions and objects from phpipam
require dirname(__FILE__) . '/controllers/Common.php';
// common methods
require dirname(__FILE__) . '/controllers/Responses.php';
// exception, header and response handling
# settings
$enable_authentication = true;
# database object
$Database = new Database_PDO();
$Tools = new Tools($Database);
# exceptions/result object
$Response = new Responses();
# get phpipam settings
$settings = $Tools->fetch_object("settings", "id", 1);
# set empty controller for options
if ($_SERVER['REQUEST_METHOD'] == "OPTIONS") {
    if (!isset($_GET['controller']) || $_GET['controller'] == "") {
        $_GET['controller'] = "Tools";
    }
}
/* wrap in a try-catch block to catch exceptions */
try {
    /* Validate application ---------- */
    // verify that API is enabled on server
    if ($settings->api != 1) {
        $Response->throw_exception(503, "API server disabled");
    }
    # fetch app
    $app = $Tools->fetch_object("api", "app_id", $_GET['app_id']);
Example #3
0
$Database = new Database_PDO();
$Result = new Result();
$User = new User($Database);
$Subnets = new Subnets($Database);
$Tools = new Tools($Database);
$Addresses = new Addresses($Database);
# verify that user is logged in
$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 address, subnet, vlan and nameservers
$address = (array) $Addresses->fetch_address(null, $id);
$subnet = (array) $Subnets->fetch_subnet(null, $address['subnetId']);
$vlan = (array) $Tools->fetch_object("vlans", "vlanId", $subnet['vlanId']);
$nameservers = (array) $Tools->fetch_object("nameservers", "id", $subnet['nameserverId']);
# get all custom fields
$custom_fields = $Tools->fetch_custom_fields('ipaddresses');
# checks
sizeof($address) > 0 ?: $Result->show("danger", _("Invalid ID"), true);
sizeof($subnet) > 0 ?: $Result->show("danger", _("Invalid subnet"), true);
# set title
$title = _('IP address details') . ' :: ' . $address['ip'];
# address
$content[] = "• " . _('IP address') . ": \t\t {$address['ip']}/{$subnet['mask']}";
# description
empty($address['description']) ?: ($content[] = "• " . _('Description') . ":\t\t {$address['description']}");
# hostname
empty($address['dns_name']) ?: ($content[] = "• " . _('Hostname') . ": \t {$address['dns_name']}");
# subnet desc
Example #4
0
 /**
  * Print all subnets in section
  *
  * @access public
  * @param array $user
  * @param array $subnets
  * @param array $custom_fields
  * @return none - print
  */
 public function print_subnets_tools($user, $subnets, $custom_fields)
 {
     # tools object
     $Tools = new Tools($this->Database);
     # set hidden fields
     $this->get_settings();
     $hidden_fields = json_decode($this->settings->hiddenCustomFields, true);
     $hidden_fields = is_array($hidden_fields['subnets']) ? $hidden_fields['subnets'] : array();
     # set html array
     $html = array();
     # root is 0
     $rootId = 0;
     # remove all not permitted!
     if (sizeof($subnets) > 0) {
         foreach ($subnets as $k => $s) {
             $permission = $this->check_permission($user, $s->id);
             if ($permission == 0) {
                 unset($subnets[$k]);
             }
         }
     }
     # create loop array
     if (sizeof($subnets) > 0) {
         foreach ($subnets as $item) {
             $item = (array) $item;
             $children_subnets[$item['masterSubnetId']][] = $item;
         }
     } else {
         return false;
     }
     # loop will be false if the root has no children (i.e., an empty menu!)
     $loop = !empty($children_subnets[$rootId]);
     # initializing $parent as the root
     $parent = $rootId;
     $parent_stack = array();
     # return table content (tr and td's)
     while ($loop && (($option = each($children_subnets[$parent])) || $parent > $rootId)) {
         # repeat
         $repeat = str_repeat(" - ", count($parent_stack));
         # dashes
         if (count($parent_stack) == 0) {
             $dash = "";
         } else {
             $dash = "-";
         }
         if (count($parent_stack) == 0) {
             $margin = "0px";
             $padding = "0px";
         } else {
             # padding
             $padding = "10px";
             # margin
             $margin = count($parent_stack) * 10 - 10;
             $margin = $margin * 2;
             $margin = $margin . "px";
         }
         # count levels
         $count = count($parent_stack) + 1;
         # get VLAN
         $vlan = (array) $Tools->fetch_object("vlans", "vlanId", $option['value']['vlanId']);
         if (@$vlan[0] === false) {
             $vlan['number'] = "";
         }
         # no VLAN
         # description
         $description = strlen($option['value']['description']) == 0 ? "/" : $option['value']['description'];
         # print table line
         if (strlen($option['value']['subnet']) > 0) {
             $html[] = "<tr>";
             //which level?
             if ($count == 1) {
                 # is folder?
                 if ($option['value']['isFolder'] == 1) {
                     $html[] = "\t<td class='level{$count}'><span class='structure' style='padding-left:{$padding}; margin-left:{$margin};'></span><i class='fa fa-sfolder fa-pad-right-3 fa-folder-open'></i> <a href='" . create_link("folder", $option['value']['sectionId'], $option['value']['id']) . "'> {$description}</a></td>";
                     $html[] = "\t<td class='level{$count}'><span class='structure' style='padding-left:{$padding}; margin-left:{$margin};'></span><i class='fa fa-sfolder fa-pad-right-3 fa-folder-open'></i>  {$description}</td>";
                 } else {
                     # last?
                     if (!empty($children_subnets[$option['value']['id']])) {
                         $html[] = "\t<td class='level{$count}'><span class='structure' style='padding-left:{$padding}; margin-left:{$margin};'></span><i class='fa fa-gray fa-pad-right-3 fa-folder-open-o'></i><a href='" . create_link("subnets", $option['value']['sectionId'], $option['value']['id']) . "'>  " . $this->transform_to_dotted($option['value']['subnet']) . "/" . $option['value']['mask'] . "</a></td>";
                         $html[] = "\t<td class='level{$count}'><span class='structure' style='padding-left:{$padding}; margin-left:{$margin};'></span><i class='fa fa-gray fa-pad-right-3 fa-folder-open-o'></i> {$description}</td>";
                     } else {
                         $html[] = "\t<td class='level{$count}'><span class='structure' style='padding-left:{$padding}; margin-left:{$margin};'></span><i class='fa fa-gray fa-pad-right-3 fa-angle-right'></i><a href='" . create_link("subnets", $option['value']['sectionId'], $option['value']['id']) . "'>  " . $this->transform_to_dotted($option['value']['subnet']) . "/" . $option['value']['mask'] . "</a></td>";
                         $html[] = "\t<td class='level{$count}'><span class='structure' style='padding-left:{$padding}; margin-left:{$margin};'></span><i class='fa fa-gray fa-pad-right-3 fa-angle-right'></i> {$description}</td>";
                     }
                 }
             } else {
                 # is folder?
                 if ($option['value']['isFolder'] == 1) {
                     # last?
                     $html[] = "\t<td class='level{$count}'><span class='structure' style='padding-left:{$padding}; margin-left:{$margin};'></span><i class='fa fa-gray fa-pad-right-3 fa-folder-open'></i> <a href='" . create_link("folder", $option['value']['sectionId'], $option['value']['id']) . "'> {$description}</a></td>";
                     $html[] = "\t<td class='level{$count}'><span class='structure' style='padding-left:{$padding}; margin-left:{$margin};'></span><i class='fa fa-gray fa-pad-right-3 fa-folder-open'></i> {$description}</td>";
                 } else {
                     # last?
                     if (!empty($children_subnets[$option['value']['id']])) {
                         $html[] = "\t<td class='level{$count}'><span class='structure' style='padding-left:{$padding}; margin-left:{$margin};'></span><i class='fa fa-gray fa-pad-right-3 fa-folder-open-o'></i> <a href='" . create_link("subnets", $option['value']['sectionId'], $option['value']['id']) . "'>  " . $this->transform_to_dotted($option['value']['subnet']) . "/" . $option['value']['mask'] . "</a></td>";
                         $html[] = "\t<td class='level{$count}'><span class='structure' style='padding-left:{$padding}; margin-left:{$margin};'></span><i class='fa fa-gray fa-pad-right-3 fa-folder-open-o'></i> {$description}</td>";
                     } else {
                         $html[] = "\t<td class='level{$count}'><span class='structure' style='padding-left:{$padding}; margin-left:{$margin};'></span><i class='fa fa-gray fa-pad-right-3 fa-angle-right'></i> <a href='" . create_link("subnets", $option['value']['sectionId'], $option['value']['id']) . "'>  " . $this->transform_to_dotted($option['value']['subnet']) . "/" . $option['value']['mask'] . "</a></td>";
                         $html[] = "\t<td class='level{$count}'><span class='structure' style='padding-left:{$padding}; margin-left:{$margin};'></span><i class='fa fa-gray fa-pad-right-3 fa-angle-right'></i> {$description}</td>";
                     }
                 }
             }
             //vlan
             $html[] = "\t<td>{$vlan['number']}</td>";
             //vrf
             if ($this->settings->enableVRF == 1) {
                 # fetch vrf
                 $vrf = $Tools->fetch_vrf(null, $option['value']['vrfId']);
                 $html[] = !$vrf ? "<td></td>" : "<td>{$vrf->name}</td>";
             }
             //masterSubnet
             $masterSubnet = $option['value']['masterSubnetId'] == 0 || empty($option['value']['masterSubnetId']) ? true : false;
             if ($masterSubnet) {
                 $html[] = '	<td>/</td>' . "\n";
             } else {
                 $master = (array) $this->fetch_subnet(null, $option['value']['masterSubnetId']);
                 if ($master['isFolder'] == 1) {
                     $html[] = "\t<td><i class='fa fa-gray fa-folder-open-o'></i> <a href='" . create_link("folder", $option['value']['sectionId'], $master['id']) . "'>{$master['description']}</a></td>" . "\n";
                 } else {
                     $html[] = "\t<td><a href='" . create_link("subnets", $option['value']['sectionId'], $master['id']) . "'>" . $this->transform_to_dotted($master['subnet']) . '/' . $master['mask'] . '</a></td>' . "\n";
                 }
             }
             //device
             $device = $option['value']['device'] == 0 || empty($option['value']['device']) ? false : true;
             if ($device === false) {
                 $html[] = '	<td>/</td>' . "\n";
             } else {
                 $device = $Tools->fetch_object("devices", "id", $option['value']['device']);
                 if ($device !== false) {
                     $html[] = "\t<td><a href='" . create_link("tools", "devices", "hosts", $option['value']['device']) . "'>" . $device->hostname . '</a></td>' . "\n";
                 } else {
                     $html[] = '	<td>/</td>' . "\n";
                 }
             }
             //requests
             $requests = $option['value']['allowRequests'] == 1 ? "<i class='fa fa-gray fa-check'></i>" : "";
             $html[] = "\t<td class='hidden-xs hidden-sm'>{$requests}</td>";
             //custom
             if (sizeof($custom_fields) > 0) {
                 foreach ($custom_fields as $field) {
                     # hidden?
                     if (!in_array($field['name'], $hidden_fields)) {
                         $html[] = "<td class='hidden-xs hidden-sm hidden-md'>";
                         //booleans
                         if ($field['type'] == "tinyint(1)") {
                             if ($option['value'][$field['name']] == "0") {
                                 $html[] = _("No");
                             } elseif ($option['value'][$field['name']] == "1") {
                                 $html[] = _("Yes");
                             }
                         } elseif ($field['type'] == "text") {
                             if (strlen($option['value'][$field['name']]) > 0) {
                                 $html[] = "<i class='fa fa-gray fa-comment' rel='tooltip' data-container='body' data-html='true' title='" . str_replace("\n", "<br>", $option['value'][$field['name']]) . "'>";
                             } else {
                                 $html[] = "";
                             }
                         } else {
                             $html[] = $option['value'][$field['name']];
                         }
                         $html[] = "</td>";
                     }
                 }
             }
             # set permission
             $permission = $this->check_permission($user, $option['value']['id']);
             $html[] = "\t<td class='actions' style='padding:0px;'>";
             $html[] = "\t<div class='btn-group'>";
             if ($permission > 1) {
                 if ($option['value']['isFolder'] == 1) {
                     $html[] = "\t\t<button class='btn btn-xs btn-default add_folder'     data-action='edit'   data-subnetid='" . $option['value']['id'] . "'  data-sectionid='" . $option['value']['sectionId'] . "'><i class='fa fa-gray fa-pencil'></i></button>";
                     $html[] = "\t\t<button class='btn btn-xs btn-default showSubnetPerm' data-action='show'   data-subnetid='" . $option['value']['id'] . "'  data-sectionid='" . $option['value']['sectionId'] . "'><i class='fa fa-gray fa-tasks'></i></button>";
                     $html[] = "\t\t<button class='btn btn-xs btn-default add_folder'     data-action='delete' data-subnetid='" . $option['value']['id'] . "'  data-sectionid='" . $option['value']['sectionId'] . "'><i class='fa fa-gray fa-times'></i></button>";
                 } else {
                     $html[] = "\t\t<button class='btn btn-xs btn-default editSubnet'     data-action='edit'   data-subnetid='" . $option['value']['id'] . "'  data-sectionid='" . $option['value']['sectionId'] . "'><i class='fa fa-gray fa-pencil'></i></button>";
                     $html[] = "\t\t<button class='btn btn-xs btn-default showSubnetPerm' data-action='show'   data-subnetid='" . $option['value']['id'] . "'  data-sectionid='" . $option['value']['sectionId'] . "'><i class='fa fa-gray fa-tasks'></i></button>";
                     $html[] = "\t\t<button class='btn btn-xs btn-default editSubnet'     data-action='delete' data-subnetid='" . $option['value']['id'] . "'  data-sectionid='" . $option['value']['sectionId'] . "'><i class='fa fa-gray fa-times'></i></button>";
                 }
             } else {
                 $html[] = "\t\t<button class='btn btn-xs btn-default disabled'><i class='fa fa-gray fa-pencil'></i></button>";
                 $html[] = "\t\t<button class='btn btn-xs btn-default disabled'><i class='fa fa-gray fa-tasks'></i></button>";
                 $html[] = "\t\t<button class='btn btn-xs btn-default disabled'><i class='fa fa-gray fa-times'></i></button>";
             }
             $html[] = "\t</div>";
             $html[] = "\t</td>";
             $html[] = "</tr>";
         }
         if ($option === false) {
             $parent = array_pop($parent_stack);
         } elseif (!empty($children_subnets[$option['value']['id']])) {
             array_push($parent_stack, $option['value']['masterSubnetId']);
             $parent = $option['value']['id'];
         } else {
         }
     }
     # print
     print implode("\n", $html);
 }
Example #5
0
    # classes
    $Database = new Database_PDO();
    $User = new User($Database);
    $Tools = new Tools($Database);
    $Subnets = new Subnets($Database);
    $Result = new Result();
}
# user must be authenticated
$User->check_user_session();
# set size parameters
$height = 200;
$slimit = 10;
# if direct request include plot JS
if ($_SERVER['HTTP_X_REQUESTED_WITH'] != "XMLHttpRequest") {
    # get widget details
    if (!($widget = $Tools->fetch_object("widgets", "wfile", $_REQUEST['section']))) {
        $Result->show("danger", _("Invalid widget"), true);
    }
    # reset size and limit
    $height = 350;
    $slimit = 20;
    # include flot JS
    print '<script language="javascript" type="text/javascript" src="js/1.2/flot/jquery.flot.js"></script>';
    print '<script language="javascript" type="text/javascript" src="js/1.2/flot/jquery.flot.categories.js"></script>';
    print '<!--[if lte IE 8]><script language="javascript" type="text/javascript" src="js/1.2/flot/excanvas.min.js"></script><![endif]-->';
    # and print title
    print "<div class='container'>";
    print "<h4 style='margin-top:40px;'>{$widget->wtitle}</h4><hr>";
    print "</div>";
}
$type = "IPv4";
Example #6
0
    }
    //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);
    }
    # send mail
    //save subnt
    $tmp['subnetId'] = $_POST['subnetId'];
    unset($_POST['subnetId']);
    // gateway
    $gateway = $Subnets->find_gateway($tmp['subnetId']);
    if ($gateway !== false) {
        $tmp['gateway'] = $Subnets->transform_address($gateway->ip_addr, "dotted");
    }
    //set vlan
    $vlan = $Tools->fetch_object("vlans", "vlanId", $subnet['vlanId']);
    $tmp['vlan'] = $vlan == false ? "" : $vlan->number . " - " . $vlan->description;
    //set dns
    $dns = $Tools->fetch_object("nameservers", "id", $subnet['nameserverId']);
    $tmp['dns'] = $dns == false ? "" : $dns->description . " <br> " . str_replace(";", ", ", $dns->namesrv1);
    $_POST = array_merge($tmp, $_POST);
    $Tools->ip_request_send_mail("accept", $_POST);
}
# initialize required objects
$Database = new Database_PDO();
$Result = new Result();
$User = new User($Database);
$Subnets = new Subnets($Database);
$Tools = new Tools($Database);
$Addresses = new Addresses($Database);
# verify that user is logged in
$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[] = "&bull; " . _('Subnet') . ": \t\t " . $Subnets->transform_address($subnet['subnet'], "dotted") . "/" . $subnet['mask'];
# description
empty($subnet['description']) ?: ($content[] = "&bull; " . _('Description') . ":\t\t {$subnet['description']}");
# gateway
$gateway = $Subnets->find_gateway($subnet['id']);
if ($gateway !== false) {
Example #8
0
$Database = new Database_PDO();
$Result = new Result();
$User = new User($Database);
$Subnets = new Subnets($Database);
$Tools = new Tools($Database);
$Addresses = new Addresses($Database);
# verify that user is logged in
$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 address, subnet and vlan
$address = (array) $Addresses->fetch_address(null, $id);
$subnet = (array) $Subnets->fetch_subnet(null, $address['subnetId']);
$vlan = (array) $Tools->fetch_object("vlans", "vlanId", @$address['vlanId']);
# get all custom fields
$custom_fields = $Tools->fetch_custom_fields('ipaddresses');
# checks
sizeof($address) > 0 ?: $Result->show("danger", _("Invalid ID"), true);
sizeof($subnet) > 0 ?: $Result->show("danger", _("Invalid subnet"), true);
# set title
$title = _('IP address details') . ' :: ' . $address['ip'];
# address
$content[] = "&bull; " . _('IP address') . ": \t {$address['ip']}/{$subnet['mask']}";
# description
empty($address['description']) ?: ($content[] = "&bull; " . _('Description') . ":\t {$address['description']}");
# hostname
empty($address['dns_name']) ?: ($content[] = "&bull; " . _('Hostname') . ": \t {$address['dns_name']}");
# subnet desc
$s_descrip = empty($address['description']) ? "" : " (" . $subnet['description'] . ")";
Example #9
0
# initialize install class
$Database = new Database_PDO();
$Result = new Result();
$Tools = new Tools($Database);
$Install = new Install($Database);
# reset url for base
$url = $Result->createURL();
# If User is not available create fake user object for create_link!
if (!is_object(@$User)) {
    $User = new StdClass();
    @($User->settings->prettyLinks = "No");
}
# if already installed than redirect !
if ($Install->check_db_connection(false) && $Install->check_table("vrf", false)) {
    # check if installation parts 2 and 3 are running, otherwise die!
    $admin = $Tools->fetch_object("users", "id", 1);
    if ($admin->password != '$6$rounds=3000$JQEE6dL9NpvjeFs4$RK5X3oa28.Uzt/h5VAfdrsvlVe.7HgQUYKMXTJUsud8dmWfPzZQPbRbk8xJn1Kyyt4.dWm4nJIYhAV2mbOZ3g.') {
        header("Location: " . create_link("dashboard"));
        die;
    }
}
# printout
?>

<!DOCTYPE HTML>
<html lang="en">

<head>
	<base href="<?php 
print $url . BASE;
?>
Example #10
0
if ($_POST['type'] !== "src" && $_POST['type'] !== "dst") {
    $Result->show("danger", _("Invalid NAT direction"), true);
}
# set searchterm
if (isset($_REQUEST['ip'])) {
    // trim
    $_REQUEST['ip'] = trim($_REQUEST['ip']);
    // escape
    $_REQUEST['ip'] = htmlspecialchars($_REQUEST['ip']);
    $search_term = @$search_term == "search" ? "" : $_REQUEST['ip'];
}
# change * to % for database wildchar
$search_term = trim($search_term);
$search_term = str_replace("*", "%", $search_term);
# fetch old details
$nat = $Tools->fetch_object("nat", "id", $_POST['id']);
$nat->src = json_decode($nat->src, true);
$nat->dst = json_decode($nat->dst, true);
// identify
$type = $Admin->identify_address($search_term);
//identify address type
# reformat if IP address for search
if ($type == "IPv4") {
    $search_term_edited = $Tools->reformat_IPv4_for_search($search_term);
} elseif ($type == "IPv6") {
    $search_term_edited = $Tools->reformat_IPv6_for_search($search_term);
}
//reformat the IPv4 address!
# search addresses
$result_addresses = $Tools->search_addresses($search_term, $search_term_edited['high'], $search_term_edited['low'], array());
# search subnets
Example #11
0
$custom = $Tools->fetch_custom_fields('vlans');
//if it already exist die
if ($User->settings->vlanDuplicate == 0 && $_POST['action'] == "add") {
    $check_vlan = $Admin->fetch_multiple_objects("vlans", "domainId", $_POST['domainId'], "vlanId");
    if ($check_vlan !== false) {
        foreach ($check_vlan as $v) {
            if ($v->number == $_POST['number']) {
                $Result->show("danger", _("VLAN already exists"), true);
            }
        }
    }
}
// if unique required
if (isset($_POST['unique'])) {
    if ($_POST['unique'] == "on") {
        if ($Tools->fetch_object("vlans", "number", $_POST['number']) !== false) {
            $Result->show("danger", _("VLAN already exists in another domain!"), true);
        }
    }
}
//if number too high
if ($_POST['number'] > $User->settings->vlanMax && $_POST['action'] != "delete") {
    $Result->show("danger", _('Highest possible VLAN number is ') . $settings['vlanMax'] . '!', true);
}
if ($_POST['action'] == "add") {
    if ($_POST['number'] < 0) {
        $Result->show("danger", _('VLAN number cannot be negative') . '!', true);
    } elseif (!is_numeric($_POST['number'])) {
        $Result->show("danger", _('Not number') . '!', true);
    }
}
        $errors[] = $e->getMessage();
    }
}
# none and errors
if (sizeof($found) == 0 && isset($errors)) {
    $Result->show("info", _("No new subnets found") . "</div><hr><div class='alert alert-warning'>" . implode("<hr>", $errors) . "</div>", true, $ajax_loaded);
} elseif (sizeof($found) == 0) {
    $Result->show("info", _("No new subnets found") . "!", true, $ajax_loaded);
} else {
    # fetch all permitted domains
    $permitted_domains = $Sections->fetch_section_domains($_POST['sectionId']);
    # fetch all belonging vlans
    $cnt = 0;
    foreach ($permitted_domains as $k => $d) {
        //fetch domain
        $domain = $Tools->fetch_object("vlanDomains", "id", $d);
        // fetch vlans and append
        $vlans = $Tools->fetch_multiple_objects("vlans", "domainId", $domain->id, "number");
        //save to array
        $out[$d]['domain'] = $domain;
        $out[$d]['vlans'] = $vlans;
        //count add
        $cnt++;
    }
    //filter out empty
    $permitted_domains = array_filter($out);
    # fetch all permitted domains
    $permitted_nameservers = $Sections->fetch_section_nameserver_sets($_POST['sectionId']);
    # fetch all belonging nameserver set
    $cnt = 0;
    # Only parse nameserver if any exists
Example #13
0
# scan disabled
if ($User->settings->enableSNMP != "1") {
    $Result->show("danger", _("SNMP module disbled"), true);
}
# admin check
if ($User->is_admin() !== true) {
    $Result->show("danger", _('Admin privileges required'), true);
}
# set class
$Snmp = new phpipamSNMP();
# domain Id must be int
if (!is_numeric($_POST['domainId'])) {
    $Result->show("danger", _("Invalid domain Id"), true);
}
# fetch domain
$domain = $Tools->fetch_object("vlanDomains", "id", $_POST['domainId']);
if ($domain === false) {
    $Result->show("danger", _("Invalid domain Id"), true);
}
# get existing vlans
$existing_vlans = $Tools->fetch_multiple_objects("vlans", "domainId", $domain->id, "vlanId");
if ($existing_vlans !== false) {
    foreach ($existing_vlans as $v) {
        $ex_vlans[$v->number] = $name;
    }
}
// no errors
error_reporting(E_ERROR);
# set devices
foreach ($_POST as $k => $p) {
    if (strpos($k, "device-") !== false) {
Example #14
0
}
if ($_POST['action'] == "add" || $_POST['action'] == "edit") {
    // name
    if (strlen($_POST['name']) < 3) {
        $Result->show("danger", _("Name must have at least 3 characters"), true);
    }
    // number
    if (!is_numeric($_POST['start'])) {
        $Result->show("danger", _("Start must be numeric"), true);
    }
    if (!is_numeric($_POST['stop'])) {
        $Result->show("danger", _("Stop must be numeric"), true);
    }
    // check master
    if ($_POST['master'] != 0) {
        $master_prefix = $Tools->fetch_object("pstnPrefixes", "id", $_POST['master']);
        if ($master_prefix === false) {
            $Result->show("danger", _("Invalid master prefix"), true);
        }
        // ranges
        $master_prefix->prefix_raw = $Tools->prefix_normalize($master_prefix->prefix);
        $master_prefix->prefix_raw_start = $Tools->prefix_normalize($master_prefix->prefix . $master_prefix->start);
        $master_prefix->prefix_raw_stop = $Tools->prefix_normalize($master_prefix->prefix . $master_prefix->stop);
        $_POST['prefix_raw'] = $Tools->prefix_normalize($_POST['prefix']);
        $_POST['prefix_raw_start'] = $Tools->prefix_normalize($_POST['prefix'] . $_POST['start']);
        $_POST['prefix_raw_stop'] = $Tools->prefix_normalize($_POST['prefix'] . $_POST['stop']);
        // prefix must be inside range
        if ($_POST['prefix_raw_start'] == $master_prefix->prefix_raw_start && $_POST['prefix_raw_stop'] == $master_prefix->prefix_raw_stop) {
            $Result->show("danger", _("Prefix cannot be same as master"), true);
        }
        if ($_POST['prefix_raw_start'] < $master_prefix->prefix_raw_start || $_POST['prefix_raw_stop'] > $master_prefix->prefix_raw_stop) {
Example #15
0
     $subnet_text = '';
     if ($subnet['isFolder']) {
         $subnet_text = $subnet['description'] . " (folder)";
     } else {
         $subnet_text = $subnet['ip'] . "/" . $subnet['mask'];
     }
     $worksheet->write($lineCount, $rowCount, $subnet_text, $format_text);
     $rowCount++;
 }
 if (isset($_GET['description']) && $_GET['description'] == "on") {
     $worksheet->write($lineCount, $rowCount, $subnet['description'], $format_text);
     $rowCount++;
 }
 if (isset($_GET['VLAN']) && $_GET['VLAN'] == "on") {
     // get VLAN
     $vlan = (array) $Tools->fetch_object("vlans", "vlanId", $subnet['vlanId']);
     /* if(@$vlan[0]===false) 	{ $vlan['number'] = "NA"; $vlan['name'] = "NA"; }			# no VLAN
     			$worksheet->write($lineCount, $rowCount, $vlan['number']." [".$vlan['name']."]", $format_text); */
     if (@$vlan[0] === false) {
         $vlan['number'] = "NA";
     }
     # no VLAN
     $worksheet->write($lineCount, $rowCount, $vlan['number'], $format_text);
     $rowCount++;
     // VLAN Domain
     $vlan_domain = (array) $Tools->fetch_object("vlanDomains", "id", $vlan['domainId']);
     $worksheet->write($lineCount, $rowCount, $vlan_domain['name'], $format_text);
     $rowCount++;
 }
 if (isset($_GET['VRF']) && $_GET['VRF'] == "on") {
     // get vrf
Example #16
0
require dirname(__FILE__) . '/../../../functions/functions.php';
require dirname(__FILE__) . '/../../../functions/PEAR/Spreadsheet/Excel/Writer.php';
# initialize required objects
$Database = new Database_PDO();
$Result = new Result();
$User = new User($Database);
$Subnets = new Subnets($Database);
$Tools = new Tools($Database);
$Addresses = new Addresses($Database);
# verify that user is logged in
$User->check_user_session();
# we dont need any errors!
ini_set('display_errors', 1);
error_reporting(E_ALL ^ E_NOTICE ^ E_STRICT);
# fetch subnet details
$subnet = (array) $Tools->fetch_object("subnets", "id", $_GET['subnetId']);
# fetch all IP addresses in subnet
$addresses = $Addresses->fetch_subnet_addresses($_GET['subnetId'], "ip_addr", "asc");
# get all custom fields
$custom_fields = $Tools->fetch_custom_fields('ipaddresses');
# Create a workbook
$filename = isset($_GET['filename']) && strlen(@$_GET['filename']) > 0 ? $_GET['filename'] : "phpipam_subnet_export.xls";
$workbook = new Spreadsheet_Excel_Writer();
$workbook->setVersion(8);
//formatting headers
$format_header =& $workbook->addFormat();
$format_header->setBold();
$format_header->setColor('black');
$format_header->setSize(12);
//format vlan
$format_vlan =& $workbook->addFormat();
Example #17
0
 $m = 0;
 //to count success subnets because of permissions
 /** subnet results **/
 if (sizeof($result_subnets) > 0) {
     # loop
     foreach ($result_subnets as $line) {
         # cast
         $line = (array) $line;
         # check permission
         $subnet_permission = $Subnets->check_permission($User->user, $line['id']);
         if ($subnet_permission > 0) {
             $m++;
             //get section details
             $section = (array) $Sections->fetch_section(null, $line['sectionId']);
             //get vlan number
             $vlan = (array) $Tools->fetch_object("vlans", "vlanId", $line['vlanId']);
             //format requests
             $line['allowRequests'] = $line['allowRequests'] == 1 ? "enabled" : "disabled";
             //format master subnet
             if ($line['masterSubnetId'] == 0) {
                 $master_text = "/";
             } else {
                 $master_subnet = (array) $Subnets->fetch_subnet(null, $line['masterSubnetId']);
                 # folder?
                 if ($master_subnet['isFolder'] == 1) {
                     $master_text = "<i class='fa fa-folder-o fa fa-gray'></i> {$master_subnet['description']}";
                 } else {
                     $master_text = "{$master_subnet['ip']}/{$master_subnet['mask']}";
                 }
             }
             //tr
 /**
  * Checks if subnet usage is over threshold and sends alert
  *
  * @access private
  * @param mixed $address
  * @return void
  */
 private function threshold_check($address)
 {
     $address = (object) $address;
     $content = array();
     $content_plain = array();
     # fetch settings
     $this->get_settings();
     # enabled ?
     if ($this->settings->enableThreshold == "1") {
         # object
         if (!is_object($this->Subnets)) {
             $this->Subnets = new Subnets($this->Database);
         }
         # fetch subnet
         $subnet = $this->Subnets->fetch_subnet("id", $address->subnetId);
         # threshold set ?
         if ($subnet->threshold > 0) {
             # count number of hosts in subnet
             $used_hosts = $this->count_subnet_addresses($address->subnetId);
             # calculate subnet usage
             $subnet_usage = $this->Subnets->calculate_subnet_usage($used_hosts, $subnet->mask, $subnet->subnet, $subnet->isFull);
             # if over send mail
             if (gmp_strval(gmp_sub(100, (int) round($subnet_usage['freehosts_percent'], 0))) > $subnet->threshold) {
                 // fetch mail settings
                 $Tools = new Tools($this->Database);
                 $admins = $Tools->fetch_multiple_objects("users", "role", "Administrator");
                 // if some recipients
                 if ($admins !== false) {
                     // mail settings
                     $mail_settings = $Tools->fetch_object("settingsMail", "id", 1);
                     // mail class
                     $phpipam_mail = new phpipam_mail($this->settings, $mail_settings);
                     // send
                     $phpipam_mail->initialize_mailer();
                     // set parameters
                     $subject = "Subnet threshold limit reached" . " (" . $this->transform_address($subnet->subnet, "dotted") . "/" . $subnet->mask . ")";
                     $content[] = "<table style='margin-left:10px;margin-top:5px;width:auto;padding:0px;border-collapse:collapse;'>";
                     $content[] = "<tr><td style='padding:5px;margin:0px;color:#333;font-size:16px;text-shadow:1px 1px 1px white;border-bottom:1px solid #eeeeee;' colspan='2'>{$this->mail_font_style}<strong>{$subject}</font></td></tr>";
                     $content[] = '<tr><td style="padding: 0px;padding-left:10px;margin:0px;line-height:18px;text-align:left;">' . $this->mail_font_style . '' . _('Subnet') . '</a></font></td>	<td style="padding: 0px;padding-left:15px;margin:0px;line-height:18px;text-align:left;padding-top:10px;"><a href="' . $this->createURL() . '' . create_link("subnets", $subnet->sectionId, $subnet->id) . '">' . $this->mail_font_style_href . $this->transform_address($subnet->subnet, "dotted") . "/" . $subnet->mask . '</font></a></td></tr>';
                     $content[] = '<tr><td style="padding: 0px;padding-left:10px;margin:0px;line-height:18px;text-align:left;">' . $this->mail_font_style . '' . _('Description') . '</font></td>	  	<td style="padding: 0px;padding-left:15px;margin:0px;line-height:18px;text-align:left;">' . $this->mail_font_style . '' . $subnet->description . '</font></td></tr>';
                     $content[] = '<tr><td style="padding: 0px;padding-left:10px;margin:0px;line-height:18px;text-align:left;">' . $this->mail_font_style . '' . _('Usage') . ' (%)</font></td>	<td style="padding: 0px;padding-left:15px;margin:0px;line-height:18px;text-align:left;">' . $this->mail_font_style . '' . gmp_strval(gmp_sub(100, (int) round($subnet_usage['freehosts_percent'], 0))) . '</font></td></tr>';
                     $content[] = "</table>";
                     // plain
                     $content_plain[] = "{$subject}" . "\r\n------------------------------\r\n";
                     $content_plain[] = _("Subnet") . ": " . $this->transform_address($subnet->subnet, "dotted") . "/" . $subnet->mask;
                     $content_plain[] = _("Usage") . " (%) : " . gmp_strval(gmp_sub(100, (int) round($subnet_usage['freehosts_percent'], 0)));
                     # set content
                     $content = $phpipam_mail->generate_message(implode("\r\n", $content));
                     $content_plain = implode("\r\n", $content_plain);
                     # try to send
                     try {
                         $phpipam_mail->Php_mailer->setFrom($mail_settings->mAdminMail, $mail_settings->mAdminName);
                         //add all admins to CC
                         $recipients = $this->changelog_mail_get_recipients($subnet->id);
                         if ($recipients !== false) {
                             foreach ($recipients as $a) {
                                 $phpipam_mail->Php_mailer->addAddress($a->email);
                             }
                             $phpipam_mail->Php_mailer->Subject = $subject;
                             $phpipam_mail->Php_mailer->msgHTML($content);
                             $phpipam_mail->Php_mailer->AltBody = $content_plain;
                             //send
                             $phpipam_mail->Php_mailer->send();
                         } else {
                             return true;
                         }
                     } catch (phpmailerException $e) {
                         $this->Result->show("danger", "Mailer Error: " . $e->errorMessage(), true);
                     } catch (Exception $e) {
                         $this->Result->show("danger", "Mailer Error: " . $e->errorMessage(), true);
                     }
                 }
             }
         } else {
             return true;
         }
     } else {
         return true;
     }
 }
Example #19
0
$Tools = new Tools($Database);
$Result = new Result();
# verify that user is logged in
$User->check_user_session();
# checks
if ($User->settings->tempShare != 1) {
    $Result->show("danger", _("Temporary sharing disabled"), true, true);
}
if ($_POST['type'] != "subnets" && $_POST['type'] != "ipaddresses") {
    $Result->show("danger", _("Invalid type"), true, true);
}
if (!is_numeric($_POST['id'])) {
    $Result->show("danger", _("Invalid ID"), true, true);
}
//fetch object details
$object = $Tools->fetch_object($_POST['type'], "id", $_POST['id']);
# set share details
$share = new StdClass();
//set details
if ($_POST['type'] == "subnets") {
    $tmp[] = "Share type: subnet";
    $tmp[] = $Subnets->transform_to_dotted($object->subnet) . "/{$object->mask}";
    $tmp[] = $object->description;
} else {
    $tmp[] = "Share type: IP address";
    $tmp[] = $Subnets->transform_to_dotted($object->ip_addr);
    $tmp[] = $object->description;
}
$share->details = implode("<br>", $tmp);
//set code and timeframe
@($share->code = md5(time()));
Example #20
0
    $User = new User($Database);
    $Tools = new Tools($Database);
    $Sections = new Sections($Database);
    $Result = new Result();
}
# verify that user is logged in
$User->check_user_session();
# fetch all permitted domains
$permitted_domains = $Sections->fetch_section_domains($_POST['sectionId']);
# fetch all belonging vlans
$cnt = 0;
foreach ($permitted_domains as $k => $d) {
    // fetch vlans and append
    $vlans = $Tools->fetch_multiple_objects("vlans", "domainId", $d, "number");
    //fetch domain
    $domain = $Tools->fetch_object("vlanDomains", "id", $d);
    //save to array
    $out[$d]['domain'] = $domain;
    $out[$d]['vlans'] = $vlans;
    //count add
    $cnt++;
}
//filter out empty
$permitted_domains = array_filter($out);
?>

<select name="vlanId" class="form-control input-sm input-w-auto">
	<option disabled="disabled"><?php 
print _('Select VLAN');
?>
:</option>
Example #21
0
 /**
  * Checks section permissions and returns group privilege for each section
  *
  * @access public
  * @param mixed $permissions
  * @return void
  */
 public function parse_section_permissions($permissions)
 {
     # save to array
     $permissions = json_decode($permissions, true);
     # start Tools object
     $Tools = new Tools($this->Database);
     if (sizeof($permissions) > 0) {
         foreach ($permissions as $key => $p) {
             $group = $Tools->fetch_object("userGroups", "g_id", $key);
             $out[$group->g_id] = $p;
         }
     }
     # return array of groups
     return isset($out) ? $out : array();
 }
Example #22
0
$format_left->setLeft(1);
$format_top =& $workbook->addFormat();
$format_top->setTop(1);
// Create a worksheet
$worksheet_name = strlen($subnet['description']) > 30 ? substr($subnet['description'], 0, 27) . '...' : $subnet['description'];
$worksheet =& $workbook->addWorksheet($worksheet_name);
$worksheet->setInputEncoding("utf-8");
$lineCount = 0;
$rowCount = 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 = $Tools->fetch_object("vlans", "vlanId", $subnet['vlanId']);
if ($vlan != false) {
    $vlan = (array) $vlan;
    $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++;
}
if (isset($_GET['state']) && $_GET['state'] == "on") {
Example #23
0
# get NAT object
$nat = $Admin->fetch_object("nat", "id", $_POST['id']);
$nat !== false ?: $Result->show("danger", _("Invalid ID"), true);
# static NAT checks
if ($nat->type == "static") {
    // static NAT can only have IP address
    if ($_POST['object_type'] != "ipaddresses") {
        $Result->show("danger", _("Static NAT can only contain IP address"), true);
    }
    // decode
    $nat_src = json_decode($nat->src, true);
    $nat_dst = json_decode($nat->dst, true);
    // validate all objects
    if (sizeof(@$nat_src['ipaddresses']) > 0) {
        foreach ($nat_src['ipaddresses'] as $ik => $iv) {
            if ($Tools->fetch_object("ipaddresses", "id", $iv) === false) {
                unset($nat_src['ipaddresses'][$ik]);
            }
        }
    }
    if (sizeof(@$nat_dst['ipaddresses']) > 0) {
        foreach ($nat_dst['ipaddresses'] as $ik => $iv) {
            if ($Tools->fetch_object("ipaddresses", "id", $iv) === false) {
                unset($nat_dst['ipaddresses'][$ik]);
            }
        }
    }
    // check
    if (is_array($nat_src) && $_POST['type'] == "src") {
        $nat_src = array_filter($nat_src);
        if (isset($nat_src['ipaddresses'])) {
Example #24
0
 // set exit flag to true
 $Scan->ping_set_exit(true);
 // set debugging
 $Scan->reset_debugging(false);
 # check for recipients
 foreach ($Tools->fetch_multiple_objects("users", "role", "Administrator") as $admin) {
     if ($admin->mailNotify == "Yes") {
         $recepients[] = array("name" => $admin->real_name, "email" => $admin->email);
     }
 }
 # none?
 if (!isset($recepients)) {
     die;
 }
 # fetch mailer settings
 $mail_settings = $Tools->fetch_object("settingsMail", "id", 1);
 # fake user object, needed for create_link
 $User = new StdClass();
 @($User->settings->prettyLinks = $Scan->settings->prettyLinks);
 # initialize mailer
 $phpipam_mail = new phpipam_mail($Scan->settings, $mail_settings);
 $phpipam_mail->initialize_mailer();
 // set subject
 $subject = "phpIPAM IP state change " . $nowdate;
 //html
 $content[] = "<p style='margin-left:10px;'>{$Subnets->mail_font_style} <font style='font-size:16px;size:16px;'>phpIPAM host changes</font></font></p><br>";
 $content[] = "<table style='margin-left:10px;margin-top:5px;width:auto;padding:0px;border-collapse:collapse;border:1px solid #ccc;'>";
 $content[] = "<tr>";
 $content[] = "\t<th style='padding:3px 8px;border:1px solid #ccc;border-bottom:2px solid gray;white-space:nowrap;'>{$Subnets->mail_font_style} IP</font></th>";
 $content[] = "\t<th style='padding:3px 8px;border:1px solid #ccc;border-bottom:2px solid gray;'>{$Subnets->mail_font_style} Description</font></th>";
 $content[] = "\t<th style='padding:3px 8px;border:1px solid #ccc;border-bottom:2px solid gray;'>{$Subnets->mail_font_style} Hostname</font></th>";
 }
 //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 {
             $vlanText = "";
         }
         //section change
         if ($result_addresses[$m]->subnetId != $result_addresses[$m - 1]->subnetId) {
 }
 //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 {
             $vlanText = "";
         }
         //section change
         if ($result_addresses[$m]->subnetId != $result_addresses[$m - 1]->subnetId) {
Example #27
0
# set class
$Snmp = new phpipamSNMP();
# get existing vrfs
$existing_vrfs = $Tools->fetch_all_objects("vrf", "vrfId");
if ($existing_vrfs !== false) {
    foreach ($existing_vrfs as $v) {
        $ex_vrfs[$v->name] = $v->rd;
    }
}
// no errors
error_reporting(E_ERROR);
# set devices
foreach ($_POST as $k => $p) {
    if (strpos($k, "device-") !== false) {
        # fetch device
        $device = $Tools->fetch_object("devices", "id", str_replace("device-", "", $k));
        if ($device !== false) {
            $scan_devices[] = $device;
        }
    }
}
// if none set die
if (!isset($scan_devices)) {
    $Result->show("danger", _("No devices for SNMP VRF query available"), true);
}
// init result array
$new_vrfs = array();
// ok, we have devices, connect to each device and do query
foreach ($scan_devices as $d) {
    // init
    $Snmp->set_snmp_device($d);
Example #28
0
// translate json to array, links etc
$sources = $Tools->translate_nat_objects_for_display($n->src, NULL, NULL, "subnets", $subnet['id']);
$destinations = $Tools->translate_nat_objects_for_display($n->dst, NULL, NULL, "subnets", $subnet['id']);
// no src/dst
if ($sources === false) {
    $sources = array("<span class='badge badge1 badge5 alert-danger'>" . _("None") . "</span>");
}
if ($destinations === false) {
    $destinations = array("<span class='badge badge1 badge5 alert-danger'>" . _("None") . "</span>");
}
// description
$n->description = strlen($n->description) > 0 ? "({$n->description})" : "";
// device
if (strlen($n->device)) {
    if ($n->device !== 0) {
        $device = $Tools->fetch_object("devices", "id", $n->device);
        $description = strlen($device->description) > 0 ? "({$device->description})" : "";
        $n->device = $device === false ? "/" : "<a href='" . create_link("tools", "devices", $device->id) . "'>{$device->hostname}</a> ({$device->ip_addr}), <span class='text-muted'>{$description}</span>";
    }
} else {
    $n->device = "/";
}
// port
if (strlen($n->port) == 0) {
    $n->port = "/";
}
// icon
$icon = $n->type == "static" ? "fa-arrows-h" : "fa-long-arrow-right";
?>

<!-- header -->
Example #29
0
     $Scan->ping_set_exit(true);
     // set debugging
     $Scan->reset_debugging(false);
 }
 # check for recipients
 foreach ($Tools->fetch_multiple_objects("users", "role", "Administrator") as $admin) {
     if ($admin->mailNotify == "Yes") {
         $recepients[] = array("name" => $admin->real_name, "email" => $admin->email);
     }
 }
 # none?
 if (!isset($recepients)) {
     die;
 }
 # fetch mailer settings
 $mail_settings = $Tools->fetch_object("settingsMail", "id", 1);
 # fake user object, needed for create_link
 $User = new StdClass();
 @($User->settings->prettyLinks = $Scan->settings->prettyLinks);
 # initialize mailer
 $phpipam_mail = new phpipam_mail($Scan->settings, $mail_settings);
 $phpipam_mail->initialize_mailer();
 // set subject
 $subject = "phpIPAM IP state change " . date("Y-m-d H:i:s");
 //html
 $content[] = "<h3>phpIPAM host changes</h3>";
 $content[] = "<table style='margin-left:10px;margin-top:5px;width:auto;padding:0px;border-collapse:collapse;border:1px solid gray;'>";
 $content[] = "<tr>";
 $content[] = "\t<th style='padding:3px 8px;border:1px solid silver;border-bottom:2px solid gray;'>IP</th>";
 $content[] = "\t<th style='padding:3px 8px;border:1px solid silver;border-bottom:2px solid gray;'>Description</th>";
 $content[] = "\t<th style='padding:3px 8px;border:1px solid silver;border-bottom:2px solid gray;'>Subnet</th>";
<div class="pContent">
        <?php 
    //table
    print "<table class='table table-striped table-top table-condensed'>";
    // titles
    print "<tr>";
    print "\t<th>" . _("Subnet") . "</th>";
    print "\t<th>" . _("Bitmask") . "</th>";
    print "\t<th>" . _("Mask") . "</th>";
    print "\t<th style='width:5px;'></th>";
    print "</tr>";
    // alive
    $m = 0;
    foreach ($found as $deviceid => $device) {
        // fetch device
        $device_details = $Tools->fetch_object("devices", "id", $deviceid);
        foreach ($device as $query_result) {
            if ($query_result !== false) {
                print "<tr>";
                print " <th colspan='6'><i class='fa fa-times btn btn-xs btn-danger remove-snmp-results' data-target='device-{$deviceid}'></i> " . $device_details->hostname . "</th>";
                print "</tr>";
                print "<tbody id=device-{$deviceid}>";
                foreach ($query_result as $ip) {
                    //get bitmask
                    foreach ($masks as $k => $m) {
                        if ($m->netmask == $ip['mask']) {
                            $ip['bitmask'] = $k;
                            break;
                        }
                    }
                    print "<tr>";