<?php /** * Script to print subnets ***************************/ /* verify that user is authenticated! */ isUserAuthenticated(); /* get custom fields */ $custom = getCustomSubnetFields(); /* get all site settings */ $settings = getAllSettings(); # title print "<h4>" . _('Available subnets') . "</h4>"; # check permission $permission = checkSectionPermission($_REQUEST['section']); if ($permission != "0") { # print table structure print "<table id='manageSubnets' class='table table-striped table-condensed table-top table-absolute'>"; # set colcount if ($settings['enableVRF'] == 1) { $colCount = 8; } else { $colCount = 7; } # get all subnets in section $subnets = fetchSubnets($_REQUEST['section']); # remove custom fields if all empty! */ foreach ($custom as $field) { $sizeMyFields[$field['name']] = 0; // default value # check against each IP address
/** * Add new subnet - set query */ function setModifySubnetDetailsQuery($subnetDetails) { # add new subnet if ($subnetDetails['action'] == "add") { # remove netmask and calculate decimal values! $subnetDetails['subnet_temp'] = explode("/", $subnetDetails['subnet']); $subnetDetails['subnet'] = Transform2decimal($subnetDetails['subnet_temp'][0]); $subnetDetails['mask'] = $subnetDetails['subnet_temp'][1]; # custom fields $myFields = getCustomSubnetFields(); $myFieldsInsert['query'] = ''; $myFieldsInsert['values'] = ''; if (sizeof($myFields) > 0) { /* set inserts for custom */ foreach ($myFields as $myField) { $myFieldsInsert['query'] .= ', `' . $myField['name'] . '`'; $myFieldsInsert['values'] .= ", '" . $subnetDetails[$myField['name']] . "'"; } } $query = 'insert into subnets ' . "\n"; $query .= '(`subnet`, `mask`, `sectionId`, `description`, `vlanId`, `vrfId`, `masterSubnetId`, `allowRequests`, `showName`, `permissions`, `pingSubnet` ' . $myFieldsInsert['query'] . ') ' . "\n"; $query .= 'values (' . "\n"; $query .= ' "' . $subnetDetails['subnet'] . '", ' . "\n"; $query .= ' "' . $subnetDetails['mask'] . '", ' . "\n"; $query .= ' "' . $subnetDetails['sectionId'] . '", ' . "\n"; $query .= ' "' . htmlentities($subnetDetails['description']) . '", ' . "\n"; $query .= ' "' . $subnetDetails['vlanId'] . '", ' . "\n"; $query .= ' "' . $subnetDetails['vrfId'] . '", ' . "\n"; $query .= ' "' . $subnetDetails['masterSubnetId'] . '", ' . "\n"; $query .= '' . isCheckbox($subnetDetails['allowRequests']) . ',' . "\n"; $query .= '' . isCheckbox($subnetDetails['showName']) . ',' . "\n"; $query .= ' "' . $subnetDetails['permissions'] . '", ' . "\n"; $query .= '' . isCheckbox($subnetDetails['pingSubnet']) . '' . "\n"; $query .= $myFieldsInsert['values']; $query .= ' );'; } else { if ($subnetDetails['action'] == "delete") { /* get ALL slave subnets, then remove all subnets and IP addresses */ global $removeSlaves; getAllSlaves($subnetDetails['subnetId']); $removeSlaves = array_unique($removeSlaves); $query = ""; foreach ($removeSlaves as $slave) { $query .= 'delete from `subnets` where `id` = "' . $slave . '"; ' . "\n"; $query .= 'delete from `ipaddresses` where `subnetId` = "' . $slave . '"; ' . "\n"; } } else { if ($subnetDetails['action'] == "edit") { # custom fields $myFields = getCustomSubnetFields(); $myFieldsInsert['query'] = ''; if (sizeof($myFields) > 0) { /* set inserts for custom */ foreach ($myFields as $myField) { $myFieldsInsert['query'] .= ', `' . $myField['name'] . '` = "' . $subnetDetails[$myField['name']] . '" '; } } $query = 'update subnets set ' . "\n"; $query .= '`description` = "' . htmlentities($subnetDetails['description']) . '", ' . "\n"; if ($subnetDetails['sectionId'] != $subnetDetails['sectionIdNew']) { $query .= '`sectionId` = "' . $subnetDetails['sectionIdNew'] . '", ' . "\n"; } $query .= '`vlanId` = "' . $subnetDetails['vlanId'] . '", ' . "\n"; $query .= '`vrfId` = "' . $subnetDetails['vrfId'] . '", ' . "\n"; $query .= '`masterSubnetId` = "' . $subnetDetails['masterSubnetId'] . '", ' . "\n"; $query .= '`allowRequests` = "' . isCheckbox($subnetDetails['allowRequests']) . '", ' . "\n"; $query .= '`showName` = "' . isCheckbox($subnetDetails['showName']) . '", ' . "\n"; $query .= '`pingSubnet` = "' . isCheckbox($subnetDetails['pingSubnet']) . '" ' . "\n"; $query .= $myFieldsInsert['query']; $query .= 'where id = "' . $subnetDetails['subnetId'] . '"; ' . "\n"; # if section changes if ($subnetDetails['sectionId'] != $subnetDetails['sectionIdNew']) { # add querry to change slaves! global $removeSlaves; getAllSlaves($subnetDetails['subnetId']); $removeSlaves = array_unique($removeSlaves); foreach ($removeSlaves as $slave) { if ($subnetDetails['subnetId'] != $slave) { $query .= 'update `subnets` set `sectionId` = "' . $subnetDetails['sectionIdNew'] . '" where `id` = "' . $slave . '"; ' . "\n"; } } } # if vrf changes if ($subnetDetails['vrfId'] != $subnetDetails['vrfIdOld']) { # add querry to change vrfId! global $removeSlaves; getAllSlaves($subnetDetails['subnetId']); $removeSlaves = array_unique($removeSlaves); foreach ($removeSlaves as $slave) { $query .= 'update `subnets` set `vrfId` = "' . $subnetDetails['vrfId'] . '" where `id` = "' . $slave . '"; ' . "\n"; } } } else { } } } # return query return $query; }
/** * Search subnets */ function searchSubnets($searchterm, $searchTermEdited = "") { global $db; # get variables from config file $database = new database($db['host'], $db['user'], $db['pass'], $db['name']); # get custom subnet fields $myFields = getCustomSubnetFields(); $custom = ''; if (sizeof($myFields) > 0) { /* set inserts for custom */ foreach ($myFields as $myField) { $custom .= ' or `' . $myField['name'] . '` like "%' . $searchterm . '%" '; } } /* set query */ $query[] = 'select * from `subnets` where `description` like "%' . $searchterm . '%" or `subnet` between "' . $searchTermEdited['low'] . '" and "' . $searchTermEdited['high'] . '" ' . $custom . ';'; /* search inside subnets even if IP does not exist! */ if ($searchTermEdited['low'] == $searchTermEdited['high']) { $allSubnets = fetchAllSubnets(); foreach ($allSubnets as $s) { // first verify address type $type = IdentifyAddress($s['subnet']); if ($type == "IPv4") { require_once 'PEAR/Net/IPv4.php'; $net = Net_IPv4::parseAddress(transform2long($s['subnet']) . '/' . $s['mask']); if ($searchTermEdited['low'] > transform2decimal($net->network) && $searchTermEdited['low'] < transform2decimal($net->broadcast)) { $query[] = "select * from `subnets` where `id` = {$s['id']}; \n"; } } } } /* execute each query */ foreach ($query as $q) { try { $search[] = $database->getArray($q); } catch (Exception $e) { $error = $e->getMessage(); } } /* filter results - remove blank */ $search = array_filter($search); /* die if errors */ if (isset($error)) { print "<div class='alert alert-error'>" . _('Error') . ": {$error}</div>"; return false; } /* return result */ return $search; }
<?php /** * Script tomanage custom IP fields ****************************************/ /* verify that user is admin */ checkAdmin(); /* get all custom fields */ $myFields = getCustomIPaddrFields(); /* Custom fields by number */ $myFieldsNum = getCustomIPaddrFieldsNumArr(); /* get all custom subnet fields */ $myFieldsSubnets = getCustomSubnetFields(); /* Custom fields by number */ $myFieldsNumSubnets = getCustomSubnetsFieldsNumArr(); /* get all custom VLAN fields */ $myFieldsVLAN = getCustomVLANFields(); /* Custom VLAN fields by number */ $myFieldsNumVLAN = getCustomVLANFieldsNumArr(); /* get all custom User fields */ $myFieldsUser = getCustomUserFields(); /* Custom VLAN fields by number */ $myFieldsNumUser = getCustomUserFieldsNumArr(); ?> <h4><?php print _('Custom fields'); ?> </h4> <hr>