Exemple #1
0
 /**
  * Returns first available subnet address, false if none
  *
  * @access public
  * @param int $subnetId
  * @param obj $Subnets
  * @return int / false
  */
 public function get_first_available_address($subnetId, $Subnets)
 {
     # fetch all addresses in subnet and subnet
     $addresses = $this->fetch_subnet_addresses($subnetId, "ip_addr", "asc");
     $subnet = (array) $Subnets->fetch_subnet(null, $subnetId);
     # get max hosts
     $max_hosts = $Subnets->get_max_hosts($subnet['mask'], $this->identify_address($subnet['subnet']));
     # full subnet?
     if (sizeof($addresses) >= $max_hosts) {
         return false;
     }
     //full subnet
     # set type
     $ip_version = $this->identify_address($subnet['subnet']);
     # get first diff > 1
     if (sizeof($addresses) > 0) {
         foreach ($addresses as $k => $ipaddress) {
             # check subnet and first IP
             if ($k == 0) {
                 # /31 fix
                 if ($subnet['mask'] == 31) {
                     if (gmp_strval(gmp_sub($addresses[$k]->ip_addr, $subnet['subnet'])) > 0) {
                         return gmp_strval($subnet['subnet']);
                     }
                 } else {
                     if (gmp_strval(gmp_sub($addresses[$k]->ip_addr, $subnet['subnet'])) > 1) {
                         return gmp_strval(gmp_add($subnet['subnet'], 1));
                     } elseif ($ip_version == "IPv6") {
                         if (sizeof($addresses) == 1) {
                             if (gmp_strval(gmp_sub($addresses[$k]->ip_addr, $subnet['subnet'])) == 0) {
                                 return gmp_strval(gmp_add($subnet['subnet'], 1));
                             }
                         }
                     }
                 }
             } else {
                 if (gmp_strval(gmp_sub($addresses[$k]->ip_addr, $addresses[$k - 1]->ip_addr)) > 1) {
                     return gmp_strval(gmp_add($addresses[$k - 1]->ip_addr, 1));
                 }
             }
         }
         return gmp_strval(gmp_add($addresses[$k]->ip_addr, 1));
     } else {
         # /32, /31
         if ($subnet['mask'] == 32 || $subnet['mask'] == 31 || $ip_version == "IPv6") {
             return $subnet['subnet'];
         } else {
             return gmp_strval(gmp_add($subnet['subnet'], 1));
         }
     }
 }
 /**
  * Print folder breadcrumbs
  *
  * @access private
  * @param obj $Section
  * @param obj $Subnet
  * @param mixed $req
  * @return void
  */
 private function print_folder_breadcrumbs($Section, $Subnet, $req)
 {
     if (isset($req['subnetId'])) {
         # get all parents
         $parents = $Subnet->fetch_parents_recursive($req['subnetId']);
         print "<ul class='breadcrumb'>";
         # remove root - 0
         array_shift($parents);
         # section details
         $section = (array) $Section->fetch_section(null, $req['section']);
         # section name
         print "\t<li><a href='" . create_link("subnets", $section['id']) . "'>{$section['name']}</a> <span class='divider'></span></li>";
         # all parents
         foreach ($parents as $parent) {
             $parent = (array) $parent;
             $subnet = (array) $Subnet->fetch_subnet(null, $parent[0]);
             if ($subnet['isFolder'] == "1") {
                 print "\t<li><a href='" . create_link("folder", $section['id'], $parent[0]) . "'><i class='icon-folder-open icon-gray'></i> {$subnet['description']}</a> <span class='divider'></span></li>";
             } else {
                 print "\t<li><a href='" . create_link("subnets", $section['id'], $parent[0]) . "'><i class='icon-folder-open icon-gray'></i> {$subnet['description']}</a> <span class='divider'></span></li>";
             }
         }
         # parent subnet
         $subnet = (array) $Subnet->fetch_subnet(null, $req['subnetId']);
         print "\t<li>{$subnet['description']}</li>";
         # active subnet
         print "</ul>";
     }
 }