예제 #1
0
 public function allocation()
 {
     if (isset($this->attributes['allocation']) !== true) {
         $ipUtils = new IpUtils();
         $this->attributes['allocation'] = $ipUtils->getAllocationEntry($this->ip, $this->cidr);
     }
     return $this->attributes['allocation'];
 }
예제 #2
0
파일: ASN.php 프로젝트: BGPView/Backend-API
 private static function getStreams($as_number, $direction = 'upstreams', $asnMeta)
 {
     if ($direction == 'upstreams') {
         $searchKey = 'asn';
         $oderKey = 'upstream_asn';
     } else {
         $searchKey = 'upstream_asn';
         $oderKey = 'asn';
     }
     $client = ClientBuilder::create()->setHosts(config('elasticquent.config.hosts'))->build();
     $ipUtils = new IpUtils();
     $params = ['search_type' => 'scan', 'scroll' => '30s', 'size' => 10000, 'index' => 'bgp_data', 'type' => 'full_table', 'body' => ['sort' => [$oderKey => ['order' => 'asc']], 'query' => ['match' => [$searchKey => $as_number]]]];
     $docs = $client->search($params);
     $scroll_id = $docs['_scroll_id'];
     $steams = [];
     while (true) {
         $response = $client->scroll(array("scroll_id" => $scroll_id, "scroll" => "30s"));
         if (count($response['hits']['hits']) > 0) {
             $results = $ipUtils->cleanEsResults($response);
             $steams = array_merge($steams, $results);
             // Get new scroll_id
             $scroll_id = $response['_scroll_id'];
         } else {
             // All done scrolling over data
             break;
         }
     }
     $output['ipv4_' . $direction] = [];
     $output['ipv6_' . $direction] = [];
     foreach ($steams as $steam) {
         if (isset($output['ipv' . $steam->ip_version . '_' . $direction][$steam->{$oderKey}]) === true) {
             if (in_array($steam->bgp_path, $output['ipv' . $steam->ip_version . '_' . $direction][$steam->{$oderKey}]['bgp_paths']) === false) {
                 $output['ipv' . $steam->ip_version . '_' . $direction][$steam->{$oderKey}]['bgp_paths'][] = $steam->bgp_path;
             }
             continue;
         }
         $asnOutput['asn'] = $steam->{$oderKey};
         if ($asnMeta === true) {
             $asnData = self::where('asn', $steam->{$oderKey})->first();
             if (is_null($asnData) === true) {
                 $assignment = $ipUtils->getIanaAssignmentEntry($steam->{$oderKey});
             }
             $asnOutput['name'] = is_null($asnData) ? 'IANA-' . strtoupper($assignment->status) : $asnData->name;
             $asnOutput['description'] = is_null($asnData) ? $assignment->description : $asnData->description;
             $asnOutput['country_code'] = is_null($asnData) ? null : $asnData->counrty_code;
         }
         $asnOutput['bgp_paths'][] = $steam->bgp_path;
         $output['ipv' . $steam->ip_version . '_' . $direction][$steam->{$oderKey}] = $asnOutput;
         $asnOutput = null;
         $upstreamAsn = null;
     }
     $output['ipv4_' . $direction] = array_values($output['ipv4_' . $direction]);
     $output['ipv6_' . $direction] = array_values($output['ipv6_' . $direction]);
     // Get Graph images
     if ($direction === 'upstreams') {
         $imagePathv4 = '/assets/graphs/' . 'AS' . $as_number . '_IPv4.svg';
         $imagePathv6 = '/assets/graphs/' . 'AS' . $as_number . '_IPv6.svg';
         $imageCombinedPath = '/assets/graphs/' . 'AS' . $as_number . '_Combined.svg';
         if (file_exists(public_path() . $imagePathv4) === true) {
             $output['ipv4_graph'] = config('app.url') . $imagePathv4;
         } else {
             $output['ipv4_graph'] = null;
         }
         if (file_exists(public_path() . $imagePathv6) === true) {
             $output['ipv6_graph'] = config('app.url') . $imagePathv6;
         } else {
             $output['ipv6_graph'] = null;
         }
         if (file_exists(public_path() . $imageCombinedPath) === true) {
             $output['combined_graph'] = config('app.url') . $imageCombinedPath;
         } else {
             $output['combined_graph'] = null;
         }
     }
     return $output;
 }