public function testModelFactory()
 {
     $netblock = factory(Netblock::class)->create();
     $netblockFromDB = Netblock::where(['first_ip' => $netblock->first_ip, 'last_ip' => $netblock->last_ip])->first();
     $this->assertEquals($netblock->first_ip, $netblockFromDB->first_ip);
     $this->assertEquals($netblock->last_ip, $netblockFromDB->last_ip);
 }
 public function testCreate()
 {
     /** @var Netblock $dummyBlock */
     $dummyBlock = factory(Netblock::class)->make();
     $exitCode = Artisan::call('netblock:create', ['contact' => $dummyBlock->contact_id, 'first_ip' => $dummyBlock->first_ip, 'last_ip' => $dummyBlock->last_ip, 'description' => $dummyBlock->description, 'enabled' => $dummyBlock->enabled]);
     $this->assertEquals(0, $exitCode);
     $this->assertContains('created', Artisan::output());
     Netblock::where(['contact_id' => $dummyBlock->contact_id, 'first_ip' => $dummyBlock->first_ip, 'last_ip' => $dummyBlock->last_ip, 'description' => $dummyBlock->description, 'enabled' => $dummyBlock->enabled])->forceDelete();
     //$this->seed('NetblocksTableSeeder');
 }
 public static function byIP($ip)
 {
     $netblock = Netblock::where('first_ip', '<=', ICF::inet_ptoi($ip))->where('last_ip', '>=', ICF::inet_ptoi($ip))->where('enabled', '=', true)->orderBy('first_ip', 'desc')->orderBy('last_ip', 'asc')->take(1)->get();
     if (isset($netblock[0])) {
         return $netblock[0]->contact;
     } elseif (class_exists('AbuseIO::Custom::FindContact') === true && is_callable('\\AbuseIO\\Custom\\FindContact->byIP') === true) {
         // Call custom function
     } else {
         return FindContact::undefined();
     }
 }
Exemple #4
0
 /**
  * Return contact by Netblock
  * @param  string $ip
  * @return object
  */
 public static function byIP($ip)
 {
     $result = Netblock::where('first_ip', '<=', ICF::inetPtoi($ip))->where('last_ip', '>=', ICF::inetPtoi($ip))->where('enabled', '=', true)->orderBy('first_ip', 'desc')->orderBy('last_ip', 'asc')->take(1)->get();
     if (isset($result[0])) {
         return $result[0]->contact;
     }
     $findContact = FindContact::getExternalResolver('ip', $ip);
     if (!empty($findContact)) {
         return $findContact;
     }
     return FindContact::undefined();
 }
Exemple #5
0
 /**
  * Return contact by Netblock
  *
  * @param  string $ip IP address
  * @return object
  */
 public static function byIP($ip)
 {
     // If local lookups are not preferred, then do the remote lookup first
     if (config('main.external.prefer_local') === false) {
         $findContact = FindContact::getExternalContact('ip', $ip);
         if (!empty($findContact)) {
             return $findContact;
         }
     }
     // Do a local lookup
     $result = Netblock::where('first_ip_int', '<=', ICF::inetPtoi($ip))->where('last_ip_int', '>=', ICF::inetPtoi($ip))->where('enabled', '=', true)->orderBy('first_ip_int', 'desc')->orderBy('last_ip_int', 'asc')->take(1)->get();
     if (isset($result[0])) {
         return $result[0]->contact;
     }
     // Do a remote lookup, if local lookups are preferred. Else skip this as this was already done.
     if (config('main.external.prefer_local') === true) {
         $findContact = FindContact::getExternalContact('ip', $ip);
         if (!empty($findContact)) {
             return $findContact;
         }
     }
     return FindContact::undefined();
 }
Exemple #6
0
 /**
  * {@inheritdoc}.
  */
 protected function findWithCondition($filter)
 {
     return Netblock::where('first_ip', 'like', "%{$filter}%")->get();
 }
Exemple #7
0
 /**
  * @param $field
  * @param $ip
  *
  * @return null $collection \Illuminate\Support\Collection||null
  */
 private function findByIp($field, $ip)
 {
     $collection = null;
     $allowedFields = ['first_ip', 'last_ip'];
     if (in_array($field, $allowedFields)) {
         $filter = '%' . $ip . '%';
         $collection = Netblock::where($field, 'like', $filter)->get();
         //->first();
     }
     return $collection;
 }
Exemple #8
0
 /**
  * @param $name
  * @return Netblock|null
  */
 private function findByIp($field, $ip)
 {
     $netblock = null;
     $allowedFields = ["first_ip", "last_ip"];
     if (in_array($field, $allowedFields)) {
         $filter = '%' . $this->option('filter') . '%';
         $netblock = Netblock::where($field, "like", $filter)->first();
     }
     return $netblock;
 }