├── public
├── favicon.ico
├── assets
│ └── graphs
│ │ └── .gitignore
├── robots.txt
├── .htaccess
└── index.php
├── app
├── Listeners
│ └── .gitkeep
├── Policies
│ └── .gitkeep
├── Events
│ └── Event.php
├── Http
│ ├── Requests
│ │ └── Request.php
│ ├── Middleware
│ │ ├── EncryptCookies.php
│ │ ├── VerifyCsrfToken.php
│ │ ├── RedirectIfAuthenticated.php
│ │ └── Authenticate.php
│ ├── Controllers
│ │ ├── Controller.php
│ │ └── ApiBaseController.php
│ └── Kernel.php
├── Models
│ ├── ApiApplication.php
│ ├── IanaAssignment.php
│ ├── Rir.php
│ ├── ROA.php
│ ├── IPv4Peer.php
│ ├── IPv6Peer.php
│ ├── ASNEmail.php
│ ├── IPv4PrefixWhoisEmail.php
│ ├── IPv6PrefixWhoisEmail.php
│ ├── IXMember.php
│ ├── IPv6BgpPrefix.php
│ ├── IPv4BgpPrefix.php
│ ├── DNSRecord.php
│ ├── IX.php
│ ├── IPv6PrefixWhois.php
│ └── IPv4PrefixWhois.php
├── Providers
│ ├── AppServiceProvider.php
│ ├── EventServiceProvider.php
│ ├── AuthServiceProvider.php
│ └── RouteServiceProvider.php
├── Jobs
│ ├── Job.php
│ ├── ClearCaches.php
│ ├── ResolveDnsQuery.php
│ ├── UpdateASNs.php
│ ├── UpdatePrefixes.php
│ ├── EnterASNs.php
│ ├── EnterPrefixes.php
│ └── ReindexES.php
├── Console
│ ├── Commands
│ │ ├── ClearCaches.php
│ │ ├── UpdateMaxmindDB.php
│ │ ├── ReindexES.php
│ │ ├── GenerateGraphs.php
│ │ ├── UpdateRoaTable.php
│ │ ├── ReindexRIRWhois.php
│ │ └── UpdateASNWhoisInfo.php
│ └── Kernel.php
├── Exceptions
│ └── Handler.php
└── Services
│ ├── Domains.php
│ ├── Dns.php
│ └── BgpParser.php
├── database
├── seeds
│ ├── .gitkeep
│ ├── DatabaseSeeder.php
│ └── RIRs.php
├── migrations
│ ├── .gitkeep
│ ├── 2016_03_04_090911_nullable_rir_id_asn.php
│ ├── 2016_03_13_095736_alter_table_nullable_asn.php
│ ├── 2016_02_15_064309_create_ipv4_peers_table.php
│ ├── 2016_02_15_064315_create_ipv6_peers_table.php
│ ├── 2015_10_24_045853_CreateAsnEmails.php
│ ├── 2015_10_16_210329_rirs.php
│ ├── 2015_11_02_101146_createIPv4PrefixWhoisEmails.php
│ ├── 2015_11_02_101146_createIPv6PrefixWhoisEmails.php
│ ├── 2018_09_25_211546_create_failed_jobs_table.php
│ ├── 2016_03_04_221146_create_iana_assignment_table.php
│ ├── 2016_06_19_211348_add_iana_reserved_fields.php
│ ├── 2015_11_02_100805_createIpv4BgpPrefixTable.php
│ ├── 2015_11_02_100816_createIpv6BgpPrefixTable.php
│ ├── 2016_04_17_102828_create_roa_table.php
│ ├── 2016_02_27_054440_api_applications_table.php
│ ├── 2016_04_17_005847_add_roa_status_to_bgpprefixes.php
│ ├── 2015_11_02_100907_createIPv4PrefixWhoisTable.php
│ ├── 2015_11_02_100907_createIPv6PrefixWhoisTable.php
│ ├── 2016_02_14_091342_ix_members.php
│ ├── 2016_02_14_041446_ix_table.php
│ ├── 2016_07_07_015420_add_ip_dec_ip_whois.php
│ ├── 2015_10_24_045027_CreateAsnInfoTable.php
│ ├── 2017_01_08_013716_remove_the_desc_single_field.php
│ ├── 2016_03_13_094810_alter_table_nullable_whois.php
│ ├── 2016_04_03_010547_addParentFieldsToPrefixWhois.php
│ └── 2016_03_20_082928_MakeAsnBigInt.php
├── .gitignore
└── factories
│ └── ModelFactory.php
├── resources
├── views
│ ├── vendor
│ │ └── .gitkeep
│ ├── api
│ │ ├── email.blade.php
│ │ └── register-application-done.blade.php
│ ├── welcome.blade.php
│ └── errors
│ │ ├── 503.blade.php
│ │ └── 404.blade.php
├── assets
│ └── sass
│ │ └── app.scss
└── lang
│ └── en
│ ├── pagination.php
│ ├── auth.php
│ ├── passwords.php
│ └── validation.php
├── storage
├── app
│ └── .gitignore
├── debugbar
│ └── .gitignore
├── logs
│ └── .gitignore
├── framework
│ ├── cache
│ │ └── .gitignore
│ ├── views
│ │ └── .gitignore
│ ├── sessions
│ │ └── .gitignore
│ └── .gitignore
└── .gitignore
├── bootstrap
├── cache
│ └── .gitignore
├── autoload.php
└── app.php
├── .gitattributes
├── scripts
├── bgpdump
├── bgpdump2
├── go-bgpparse
├── add_ips.php
├── go-bgpparse-src
│ └── docker-compose.yml
├── pch.awk
├── birdc_output_routes.sh
├── update_bgp_ribs.sh
└── parse_as42.php
├── config
├── wwws.php
├── clickhouse.php
├── elasticsearch.php
├── elasticquent.php
├── compile.php
├── services.php
├── view.php
├── broadcasting.php
├── cache.php
├── queue.php
├── filesystems.php
├── logging.php
├── auth.php
├── mail.php
├── database.php
└── session.php
├── package.json
├── .gitignore
├── tests
├── ExampleTest.php
└── TestCase.php
├── gulpfile.js
├── server.php
├── .env.example
├── phpunit.xml
├── routes
├── web.php
└── api.php
├── artisan
├── readme.md
└── composer.json
/public/favicon.ico:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/Listeners/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/Policies/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/database/seeds/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/database/migrations/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/database/.gitignore:
--------------------------------------------------------------------------------
1 | *.sqlite
2 |
--------------------------------------------------------------------------------
/resources/views/vendor/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/storage/app/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !.gitignore
--------------------------------------------------------------------------------
/bootstrap/cache/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !.gitignore
3 |
--------------------------------------------------------------------------------
/storage/debugbar/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !.gitignore
--------------------------------------------------------------------------------
/storage/logs/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !.gitignore
3 |
--------------------------------------------------------------------------------
/public/assets/graphs/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !.gitignore
3 |
--------------------------------------------------------------------------------
/public/robots.txt:
--------------------------------------------------------------------------------
1 | User-agent: *
2 | Disallow:
3 |
--------------------------------------------------------------------------------
/storage/framework/cache/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !.gitignore
--------------------------------------------------------------------------------
/storage/framework/views/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !.gitignore
3 |
--------------------------------------------------------------------------------
/storage/framework/sessions/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !.gitignore
3 |
--------------------------------------------------------------------------------
/storage/.gitignore:
--------------------------------------------------------------------------------
1 | /temp_rib.gz
2 | /temp_rib.gz.st
3 | /bgp_lines.txt
4 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto
2 | *.css linguist-vendored
3 | *.less linguist-vendored
4 |
--------------------------------------------------------------------------------
/scripts/bgpdump:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BGPView/Backend-API/HEAD/scripts/bgpdump
--------------------------------------------------------------------------------
/scripts/bgpdump2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BGPView/Backend-API/HEAD/scripts/bgpdump2
--------------------------------------------------------------------------------
/scripts/go-bgpparse:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BGPView/Backend-API/HEAD/scripts/go-bgpparse
--------------------------------------------------------------------------------
/resources/assets/sass/app.scss:
--------------------------------------------------------------------------------
1 | // @import "node_modules/bootstrap-sass/assets/stylesheets/bootstrap";
2 |
3 |
--------------------------------------------------------------------------------
/app/Events/Event.php:
--------------------------------------------------------------------------------
1 | env('WWWS_EMAIL'),
5 | 'password' => env('WWWS_PASSWORD'),
6 | ];
--------------------------------------------------------------------------------
/config/clickhouse.php:
--------------------------------------------------------------------------------
1 | env('CLICKHOUSE_HOST', 'localhost'),
5 | 'port' => 8123,
6 | ];
7 |
--------------------------------------------------------------------------------
/resources/views/api/email.blade.php:
--------------------------------------------------------------------------------
1 | Hello
2 |
3 | Your new API Key is: {{ $key }}
4 |
5 | Regards,
6 |
7 |
--------------------------------------------------------------------------------
/storage/framework/.gitignore:
--------------------------------------------------------------------------------
1 | config.php
2 | routes.php
3 | compiled.php
4 | services.json
5 | events.scanned.php
6 | routes.scanned.php
7 | down
8 |
--------------------------------------------------------------------------------
/config/elasticsearch.php:
--------------------------------------------------------------------------------
1 | [
5 | env('ES_HOST', 'localhost') . ':' . env('ES_PORT', 9200),
6 | ],
7 | ];
8 |
--------------------------------------------------------------------------------
/scripts/add_ips.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | API Docs
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/app/Http/Middleware/EncryptCookies.php:
--------------------------------------------------------------------------------
1 | call(RirSeeder::class);
18 |
19 | Model::reguard();
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/app/Models/Rir.php:
--------------------------------------------------------------------------------
1 |
2 |
3 | Options -MultiViews
4 |
5 |
6 | RewriteEngine On
7 |
8 | # Redirect Trailing Slashes If Not A Folder...
9 | RewriteCond %{REQUEST_FILENAME} !-d
10 | RewriteRule ^(.*)/$ /$1 [L,R=301]
11 |
12 | # Handle Front Controller...
13 | RewriteCond %{REQUEST_FILENAME} !-d
14 | RewriteCond %{REQUEST_FILENAME} !-f
15 | RewriteRule ^ index.php [L]
16 |
17 |
--------------------------------------------------------------------------------
/tests/ExampleTest.php:
--------------------------------------------------------------------------------
1 | visit('/')
17 | ->see('Laravel 5');
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/app/Models/IPv4Peer.php:
--------------------------------------------------------------------------------
1 | belongsTo('App\Models\ASN');
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/resources/lang/en/pagination.php:
--------------------------------------------------------------------------------
1 | '« Previous',
17 | 'next' => 'Next »',
18 |
19 | ];
20 |
--------------------------------------------------------------------------------
/scripts/go-bgpparse-src/docker-compose.yml:
--------------------------------------------------------------------------------
1 | version: '3.4'
2 | services:
3 | database:
4 | image: mysql:5.7
5 | restart: always
6 | command: --max_allowed_packet=1073741824
7 | environment:
8 | - MYSQL_ROOT_PASSWORD=bananas
9 | - MYSQL_DATABASE=api
10 | ports:
11 | - 3306:3306
12 | networks:
13 | - yts
14 |
15 | elasticsearch:
16 | image: docker.elastic.co/elasticsearch/elasticsearch:6.3.1
17 | container_name: elasticsearch
18 | environment: ['http.host=0.0.0.0', 'transport.host=127.0.0.1']
19 | ports: ['127.0.0.1:9200:9200']
20 | networks: ['yts']
21 |
22 | networks:
23 | yts:
24 |
--------------------------------------------------------------------------------
/tests/TestCase.php:
--------------------------------------------------------------------------------
1 | make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
22 |
23 | return $app;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/server.php:
--------------------------------------------------------------------------------
1 |
8 | */
9 |
10 | $uri = urldecode(
11 | parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
12 | );
13 |
14 | // This file allows us to emulate Apache's "mod_rewrite" functionality from the
15 | // built-in PHP web server. This provides a convenient way to test a Laravel
16 | // application without having installed a "real" web server software here.
17 | if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) {
18 | return false;
19 | }
20 |
21 | require_once __DIR__.'/public/index.php';
22 |
--------------------------------------------------------------------------------
/app/Http/Middleware/RedirectIfAuthenticated.php:
--------------------------------------------------------------------------------
1 | check()) {
21 | return redirect('/');
22 | }
23 |
24 | return $next($request);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/resources/lang/en/auth.php:
--------------------------------------------------------------------------------
1 | 'These credentials do not match our records.',
17 | 'throttle' => 'Too many login attempts. Please try again in :seconds seconds.',
18 |
19 | ];
20 |
--------------------------------------------------------------------------------
/app/Models/IPv4PrefixWhoisEmail.php:
--------------------------------------------------------------------------------
1 | belongsTo('App\Models\IPv4PrefixWhois', 'id', 'prefix_whois_id');
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/app/Models/IPv6PrefixWhoisEmail.php:
--------------------------------------------------------------------------------
1 | belongsTo('App\Models\IPv6PrefixWhois', 'id', 'prefix_whois_id');
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/app/Providers/EventServiceProvider.php:
--------------------------------------------------------------------------------
1 | [
16 | 'App\Listeners\EventListener',
17 | ],
18 | ];
19 | /**
20 | * Register any events for your application.
21 | *
22 | * @return void
23 | */
24 | public function boot()
25 | {
26 | parent::boot();
27 | //
28 | }
29 | }
--------------------------------------------------------------------------------
/database/factories/ModelFactory.php:
--------------------------------------------------------------------------------
1 | define(App\User::class, function (Faker\Generator $faker) {
15 | return [
16 | 'name' => $faker->name,
17 | 'email' => $faker->email,
18 | 'password' => bcrypt(str_random(10)),
19 | 'remember_token' => str_random(10),
20 | ];
21 | });
22 |
--------------------------------------------------------------------------------
/app/Http/Middleware/Authenticate.php:
--------------------------------------------------------------------------------
1 | guest()) {
21 | if ($request->ajax()) {
22 | return response('Unauthorized.', 401);
23 | } else {
24 | return redirect()->guest('login');
25 | }
26 | }
27 |
28 | return $next($request);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/database/migrations/2016_03_04_090911_nullable_rir_id_asn.php:
--------------------------------------------------------------------------------
1 | integer('rir_id')->nullable()->change();
18 | });
19 | }
20 |
21 | /**
22 | * Reverse the migrations.
23 | *
24 | * @return void
25 | */
26 | public function down()
27 | {
28 | Schema::table('asns', function($table)
29 | {
30 | $table->integer('rir_id')->nullable(false)->change();
31 | });
32 |
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/database/migrations/2016_03_13_095736_alter_table_nullable_asn.php:
--------------------------------------------------------------------------------
1 | string('name')->nullable()->change();
18 | });
19 | }
20 |
21 | /**
22 | * Reverse the migrations.
23 | *
24 | * @return void
25 | */
26 | public function down()
27 | {
28 | Schema::table('asns', function($table)
29 | {
30 | $table->string('name')->nullable(false)->change();
31 | });
32 |
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/app/Providers/AuthServiceProvider.php:
--------------------------------------------------------------------------------
1 | 'App\Policies\ModelPolicy',
17 | ];
18 |
19 | /**
20 | * Register any application authentication / authorization services.
21 | *
22 | * @param \Illuminate\Contracts\Auth\Access\Gate $gate
23 | * @return void
24 | */
25 | public function boot(GateContract $gate)
26 | {
27 | $this->registerPolicies($gate);
28 |
29 | //
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/database/migrations/2016_02_15_064309_create_ipv4_peers_table.php:
--------------------------------------------------------------------------------
1 | increments('id')->unique();
18 | $table->integer('asn_1')->unsigned()->index();
19 | $table->integer('asn_2')->unsigned()->index();
20 | $table->timestamps();
21 | });
22 | }
23 |
24 | /**
25 | * Reverse the migrations.
26 | *
27 | * @return void
28 | */
29 | public function down()
30 | {
31 | Schema::dropIfExists('ipv4_peers');
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/database/migrations/2016_02_15_064315_create_ipv6_peers_table.php:
--------------------------------------------------------------------------------
1 | increments('id')->unique();
18 | $table->integer('asn_1')->unsigned()->index();
19 | $table->integer('asn_2')->unsigned()->index();
20 | $table->timestamps();
21 | });
22 | }
23 |
24 | /**
25 | * Reverse the migrations.
26 | *
27 | * @return void
28 | */
29 | public function down()
30 | {
31 | Schema::dropIfExists('ipv6_peers');
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/resources/lang/en/passwords.php:
--------------------------------------------------------------------------------
1 | 'Passwords must be at least six characters and match the confirmation.',
17 | 'reset' => 'Your password has been reset!',
18 | 'sent' => 'We have e-mailed your password reset link!',
19 | 'token' => 'This password reset token is invalid.',
20 | 'user' => "We can't find a user with that e-mail address.",
21 |
22 | ];
23 |
--------------------------------------------------------------------------------
/database/migrations/2015_10_24_045853_CreateAsnEmails.php:
--------------------------------------------------------------------------------
1 | increments('id')->unique();
18 | $table->integer('asn_id')->unsigned()->index();
19 | $table->string('email_address')->index();
20 | $table->boolean('abuse_email')->default(false);
21 | $table->timestamps();
22 | });
23 | }
24 |
25 | /**
26 | * Reverse the migrations.
27 | *
28 | * @return void
29 | */
30 | public function down()
31 | {
32 | Schema::dropIfExists('asn_emails');
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/.env.example:
--------------------------------------------------------------------------------
1 | APP_ENV=local
2 | APP_DEBUG=true
3 | APP_KEY=SomeRandomString
4 |
5 | WHOIS_QUERY_URL=http://whois.example.com/proc.php
6 | RPKI_SERVER_URL=http://whois.example.com/rpki_export.json
7 |
8 | API_DOCS_URL=http://api-docs.example.com/
9 | MAIL_FROM_ADDRESS=admin@example.com
10 | MAIL_FROM_NAME="BGP Admin Name [NoReply]"
11 |
12 | DB_HOST=localhost
13 | DB_DATABASE=homestead
14 | DB_USERNAME=homestead
15 | DB_PASSWORD=secret
16 |
17 | CACHE_DRIVER=file
18 | SESSION_DRIVER=file
19 | QUEUE_DRIVER=sync
20 |
21 | REDIS_HOST=localhost
22 | REDIS_PASSWORD=null
23 | REDIS_PORT=6379
24 |
25 | MAIL_DRIVER=mailgun
26 | MAILGUN_DOMAIN=XXXXXXXXXXX.XX
27 | MAILGUN_SECRET=key-XXXXXXXXXXXXXXXXXX
28 |
29 | WWWS_EMAIL=XXXXXXX@XXXX.XX
30 | WWWS_PASSWORD=XXXXXXX
31 |
32 | ES_HOST=localhost
33 | ES_PORT=9200
34 |
35 | WHOIS_DB_ARIN_KEY=XXXXXXXXXXX
36 | WHOIS_DB_APNIC_BASE_URL=XXXXXXXXXXX
37 | WHOIS_DB_AFRINIC_BASE_URL=XXXXXXXXXXX
38 |
39 | CLICKHOUSE_HOST=localhost
40 |
--------------------------------------------------------------------------------
/app/Jobs/ClearCaches.php:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
13 | ./tests/
14 |
15 |
16 |
17 |
18 | app/
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/database/migrations/2015_10_16_210329_rirs.php:
--------------------------------------------------------------------------------
1 | increments('id')->unique();
19 | $table->string('name');
20 | $table->string('full_name');
21 | $table->string('website');
22 | $table->string('whois_server');
23 | $table->text('allocation_list_url');
24 | $table->timestamps();
25 | });
26 | }
27 |
28 | /**
29 | * Reverse the migrations.
30 | *
31 | * @return void
32 | */
33 | public function down()
34 | {
35 | Schema::dropIfExists('rirs');
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/database/migrations/2015_11_02_101146_createIPv4PrefixWhoisEmails.php:
--------------------------------------------------------------------------------
1 | increments('id')->unique();
18 | $table->integer('prefix_whois_id')->unsigned()->index();
19 | $table->string('email_address')->index();
20 | $table->boolean('abuse_email')->default(false);
21 | $table->timestamps();
22 | });
23 | }
24 |
25 | /**
26 | * Reverse the migrations.
27 | *
28 | * @return void
29 | */
30 | public function down()
31 | {
32 | Schema::dropIfExists('ipv4_prefix_whois_emails');
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/database/migrations/2015_11_02_101146_createIPv6PrefixWhoisEmails.php:
--------------------------------------------------------------------------------
1 | increments('id')->unique();
18 | $table->integer('prefix_whois_id')->unsigned()->index();
19 | $table->string('email_address')->index();
20 | $table->boolean('abuse_email')->default(false);
21 | $table->timestamps();
22 | });
23 | }
24 |
25 | /**
26 | * Reverse the migrations.
27 | *
28 | * @return void
29 | */
30 | public function down()
31 | {
32 | Schema::dropIfExists('ipv6_prefix_whois_emails');
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/database/migrations/2018_09_25_211546_create_failed_jobs_table.php:
--------------------------------------------------------------------------------
1 | bigIncrements('id');
18 | $table->text('connection');
19 | $table->text('queue');
20 | $table->longText('payload');
21 | $table->longText('exception');
22 | $table->timestamp('failed_at')->useCurrent();
23 | });
24 | }
25 |
26 | /**
27 | * Reverse the migrations.
28 | *
29 | * @return void
30 | */
31 | public function down()
32 | {
33 | Schema::dropIfExists('failed_jobs');
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/app/Console/Commands/ClearCaches.php:
--------------------------------------------------------------------------------
1 | dispatch(new \App\Jobs\ClearCaches());
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/database/migrations/2016_03_04_221146_create_iana_assignment_table.php:
--------------------------------------------------------------------------------
1 | increments('id')->unique();
18 | $table->string('type')->index();
19 | $table->decimal('start', 39, 0)->unsigned()->index();
20 | $table->decimal('end', 39, 0)->unsigned()->index();
21 | $table->string('whois_server');
22 | $table->timestamps();
23 | });
24 | }
25 |
26 | /**
27 | * Reverse the migrations.
28 | *
29 | * @return void
30 | */
31 | public function down()
32 | {
33 | Schema::dropIfExists('iana_assignments');
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/database/migrations/2016_06_19_211348_add_iana_reserved_fields.php:
--------------------------------------------------------------------------------
1 | string('description')->nullable();
18 | $table->date('date_allocated')->nullable();
19 | $table->string('status')->index();
20 | });
21 |
22 | }
23 |
24 | /**
25 | * Reverse the migrations.
26 | *
27 | * @return void
28 | */
29 | public function down()
30 | {
31 | Schema::table('iana_assignments', function($table)
32 | {
33 | $table->dropColumn('description');
34 | $table->dropColumn('date_allocated');
35 | $table->dropColumn('status');
36 | });
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/config/elasticquent.php:
--------------------------------------------------------------------------------
1 | [
17 | 'hosts' => [env('ES_HOST', 'localhost').':'.env('ES_PORT', 9200)],
18 | 'retries' => 1,
19 | ],
20 |
21 | /*
22 | |--------------------------------------------------------------------------
23 | | Default Index Name
24 | |--------------------------------------------------------------------------
25 | |
26 | | This is the index name that Elasticquent will use for all
27 | | Elasticquent models.
28 | */
29 |
30 | 'default_index' => 'main_index',
31 |
32 | );
33 |
--------------------------------------------------------------------------------
/routes/web.php:
--------------------------------------------------------------------------------
1 | 'register.application', 'uses' => 'ApiBaseController@registerApplication']);
30 |
--------------------------------------------------------------------------------
/database/migrations/2015_11_02_100805_createIpv4BgpPrefixTable.php:
--------------------------------------------------------------------------------
1 | increments('id')->unique();
18 | $table->string('ip', 40)->index();
19 | $table->integer('cidr')->unsigned()->index();
20 | $table->decimal('ip_dec_start', 39, 0)->unsigned()->index();
21 | $table->decimal('ip_dec_end', 39, 0)->unsigned()->index();
22 | $table->integer('asn')->unsigned()->index();
23 | $table->timestamps();
24 | });
25 | }
26 |
27 | /**
28 | * Reverse the migrations.
29 | *
30 | * @return void
31 | */
32 | public function down()
33 | {
34 | Schema::dropIfExists('ipv4_bgp_prefixes');
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/database/migrations/2015_11_02_100816_createIpv6BgpPrefixTable.php:
--------------------------------------------------------------------------------
1 | increments('id')->unique();
18 | $table->string('ip', 40)->index();
19 | $table->integer('cidr')->unsigned()->index();
20 | $table->decimal('ip_dec_start', 39, 0)->unsigned()->index();
21 | $table->decimal('ip_dec_end', 39, 0)->unsigned()->index();
22 | $table->integer('asn')->unsigned()->index();
23 | $table->timestamps();
24 | });
25 | }
26 |
27 | /**
28 | * Reverse the migrations.
29 | *
30 | * @return void
31 | */
32 | public function down()
33 | {
34 | Schema::dropIfExists('ipv6_bgp_prefixes');
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/config/compile.php:
--------------------------------------------------------------------------------
1 | [
17 | //
18 | ],
19 |
20 | /*
21 | |--------------------------------------------------------------------------
22 | | Compiled File Providers
23 | |--------------------------------------------------------------------------
24 | |
25 | | Here you may list service providers which define a "compiles" function
26 | | that returns additional files that should be compiled, providing an
27 | | easy way to get common files from any packages you are utilizing.
28 | |
29 | */
30 |
31 | 'providers' => [
32 | //
33 | ],
34 |
35 | ];
36 |
--------------------------------------------------------------------------------
/database/migrations/2016_04_17_102828_create_roa_table.php:
--------------------------------------------------------------------------------
1 | increments('id')->unique();
18 | $table->string('ip', 40)->index();
19 | $table->integer('cidr')->unsigned()->index();
20 | $table->decimal('ip_dec_start', 39, 0)->unsigned()->index();
21 | $table->decimal('ip_dec_end', 39, 0)->unsigned()->index();
22 | $table->integer('asn')->unsigned()->index();
23 | $table->integer('max_length')->unsigned()->index();
24 | $table->timestamps();
25 | });
26 | }
27 |
28 | /**
29 | * Reverse the migrations.
30 | *
31 | * @return void
32 | */
33 | public function down()
34 | {
35 | Schema::dropIfExists('roa_table');
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/database/migrations/2016_02_27_054440_api_applications_table.php:
--------------------------------------------------------------------------------
1 | increments('id')->unsigned();
17 | $table->string('name');
18 | $table->string('url')->nullable();
19 | $table->string('email');
20 | $table->text('use');
21 | $table->string('key', 40);
22 | $table->timestamps();
23 | });
24 |
25 | Schema::table('api_applications', function ($table) {
26 | $table->unique('id');
27 | $table->unique('key');
28 | });
29 | }
30 |
31 | /**
32 | * Reverse the migrations.
33 | *
34 | * @return void
35 | */
36 | public function down()
37 | {
38 | Schema::dropIfExists('api_applications');
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/config/services.php:
--------------------------------------------------------------------------------
1 | [
18 | 'domain' => env('MAILGUN_DOMAIN'),
19 | 'secret' => env('MAILGUN_SECRET'),
20 | ],
21 |
22 | 'mandrill' => [
23 | 'secret' => env('MANDRILL_SECRET'),
24 | ],
25 |
26 | 'ses' => [
27 | 'key' => env('SES_KEY'),
28 | 'secret' => env('SES_SECRET'),
29 | 'region' => 'us-east-1',
30 | ],
31 |
32 | 'stripe' => [
33 | 'model' => App\User::class,
34 | 'key' => env('STRIPE_KEY'),
35 | 'secret' => env('STRIPE_SECRET'),
36 | ],
37 |
38 | ];
39 |
--------------------------------------------------------------------------------
/config/view.php:
--------------------------------------------------------------------------------
1 | [
17 | realpath(base_path('resources/views')),
18 | ],
19 |
20 | /*
21 | |--------------------------------------------------------------------------
22 | | Compiled View Path
23 | |--------------------------------------------------------------------------
24 | |
25 | | This option determines where all the compiled Blade templates will be
26 | | stored for your application. Typically, this is within the storage
27 | | directory. However, as usual, you are free to change this value.
28 | |
29 | */
30 |
31 | 'compiled' => realpath(storage_path('framework/views')),
32 |
33 | ];
34 |
--------------------------------------------------------------------------------
/database/migrations/2016_04_17_005847_add_roa_status_to_bgpprefixes.php:
--------------------------------------------------------------------------------
1 | integer('roa_status')->default(0)->index();
18 | });
19 |
20 | Schema::table('ipv6_bgp_prefixes', function($table)
21 | {
22 | $table->integer('roa_status')->default(0)->index();
23 | });
24 | }
25 |
26 | /**
27 | * Reverse the migrations.
28 | *
29 | * @return void
30 | */
31 | public function down()
32 | {
33 | Schema::table('ipv4_bgp_prefixes', function($table)
34 | {
35 | $table->dropColumn('roa_status');
36 | });
37 |
38 | Schema::table('ipv6_bgp_prefixes', function($table)
39 | {
40 | $table->dropColumn('roa_status');
41 | });
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/database/migrations/2015_11_02_100907_createIPv4PrefixWhoisTable.php:
--------------------------------------------------------------------------------
1 | increments('id')->unique();
18 | $table->string('ip', 40)->index();
19 | $table->integer('cidr')->unsigned()->index();
20 | $table->string('name');
21 | $table->string('description')->nullable();
22 | $table->text('description_full')->nullable();
23 | $table->string('counrty_code', 2)->index();
24 | $table->text('owner_address')->nullable();
25 | $table->text('raw_whois')->nullable();
26 | $table->timestamps();
27 | });
28 | }
29 |
30 | /**
31 | * Reverse the migrations.
32 | *
33 | * @return void
34 | */
35 | public function down()
36 | {
37 | Schema::dropIfExists('ipv4_prefix_whois');
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/database/migrations/2015_11_02_100907_createIPv6PrefixWhoisTable.php:
--------------------------------------------------------------------------------
1 | increments('id')->unique();
18 | $table->string('ip', 40)->index();
19 | $table->integer('cidr')->unsigned()->index();
20 | $table->string('name');
21 | $table->string('description')->nullable();
22 | $table->text('description_full')->nullable();
23 | $table->string('counrty_code', 2)->index();
24 | $table->text('owner_address')->nullable();
25 | $table->text('raw_whois')->nullable();
26 | $table->timestamps();
27 | });
28 | }
29 |
30 | /**
31 | * Reverse the migrations.
32 | *
33 | * @return void
34 | */
35 | public function down()
36 | {
37 | Schema::dropIfExists('ipv6_prefix_whois');
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/bootstrap/autoload.php:
--------------------------------------------------------------------------------
1 | increments('id')->unique();
18 | $table->integer('ix_peeringdb_id')->unsigned()->index();
19 | $table->integer('asn')->unsigned()->index();
20 | $table->integer('speed')->unsigned()->index()->default(0);
21 | $table->string('ipv4_address')->nullable();
22 | $table->decimal('ipv4_dec', 39, 0)->unsigned()->nullable()->index();
23 | $table->string('ipv6_address')->nullable();
24 | $table->decimal('ipv6_dec', 39, 0)->unsigned()->nullable()->index();
25 | $table->timestamps();
26 | });
27 | }
28 |
29 | /**
30 | * Reverse the migrations.
31 | *
32 | * @return void
33 | */
34 | public function down()
35 | {
36 | Schema::dropIfExists('ix_members');
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/scripts/pch.awk:
--------------------------------------------------------------------------------
1 | BEGIN{
2 | prefix = "";
3 | }
4 | {
5 | # prefixregex="^[0-9a-f:\\./]+(:\.)[0-9a-f:\\./]*$"
6 | prefixregex = "^([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3})(/[0-9]{1,3})?$"
7 | # we have a prefix, let's see if we have an as path
8 | aspath = "";
9 | if (NF == 0 || $0 ~ "^Total number of prefixes ") {
10 | # skip
11 | } else if ($2 ~ prefixregex && $3 == "") {
12 | prefix = $2;
13 | } else if ($2 ~ prefixregex && $3 ~ prefixregex) {
14 | prefix = $2;
15 | for (pos = 6; pos < NF; pos++) {
16 | aspath = aspath" "$pos;
17 | }
18 | } else if ($2 ~ prefixregex && $3 !~ prefixregex) {
19 | for (pos = 5; pos < NF; pos++) {
20 | aspath = aspath" "$pos;
21 | }
22 | } else if ($1 ~ prefixregex && $2 !~ prefixregex) {
23 | prefix = $1
24 | for (pos = 4; pos < NF; pos++) {
25 | aspath = aspath" "$pos
26 | }
27 | } else {
28 | if (prefix != "") {
29 | print "UNKNOWN", NR, prefix;
30 | print $0;
31 | exit;
32 | }
33 | }
34 | if (prefix != "" && prefix !~ "/") {
35 | if (prefix ~ ":") {
36 | prefix = prefix"/128";
37 | } else {
38 | prefix = prefix"/32";
39 | }
40 | }
41 | if (prefix != "" && aspath != "") {
42 | print "|||||"prefix"|"aspath"||||||||";
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/app/Console/Commands/UpdateMaxmindDB.php:
--------------------------------------------------------------------------------
1 | info('Downloading a new copy of the maxmind DB');
35 | $gzipDb = file_get_contents($this->maxmindDbUrl);
36 | $data = gzdecode($gzipDb);
37 |
38 | if (file_exists($maxmindDbPath) === true) {
39 | unlink($maxmindDbPath);
40 | }
41 |
42 | file_put_contents($maxmindDbPath, $data);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/resources/views/errors/503.blade.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Be right back.
5 |
6 |
7 |
8 |
39 |
40 |
41 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/database/migrations/2016_02_14_041446_ix_table.php:
--------------------------------------------------------------------------------
1 | increments('id')->unique();
18 | $table->integer('peeringdb_id')->unsigned()->index();
19 | $table->string('name')->index();
20 | $table->string('name_full');
21 | $table->string('website')->nullable();
22 | $table->string('tech_email')->nullable();
23 | $table->string('tech_phone')->nullable();
24 | $table->string('policy_email')->nullable();
25 | $table->string('policy_phone')->nullable();
26 | $table->string('city')->nullable();
27 | $table->string('counrty_code', 2)->index();
28 | $table->string('url_stats')->nullable();
29 | $table->timestamps();
30 | });
31 | }
32 |
33 | /**
34 | * Reverse the migrations.
35 | *
36 | * @return void
37 | */
38 | public function down()
39 | {
40 | Schema::dropIfExists('ixs');
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/resources/views/errors/404.blade.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 404 - Not Found.
5 |
6 |
7 |
8 |
39 |
40 |
41 |
42 |
43 |
404 - Page Not Found.
44 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/app/Console/Commands/ReindexES.php:
--------------------------------------------------------------------------------
1 | bench = $bench;
28 | }
29 |
30 | /**
31 | * The console command description.
32 | *
33 | * @var string
34 | */
35 | protected $description = 'Reindex Elastic Search from the MySQL DB';
36 |
37 | /**
38 | * Execute the console command.
39 | *
40 | * @return mixed
41 | */
42 | public function handle()
43 | {
44 | $this->bench->start();
45 |
46 | $this->dispatch(new \App\Jobs\ReindexES());
47 |
48 | $this->output->newLine(1);
49 | $this->bench->end();
50 | $this->info(sprintf(
51 | 'Time: %s, Memory: %s',
52 | $this->bench->getTime(),
53 | $this->bench->getMemoryPeak()
54 | ));
55 |
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/database/migrations/2016_07_07_015420_add_ip_dec_ip_whois.php:
--------------------------------------------------------------------------------
1 | decimal('ip_dec_start', 39, 0)->unsigned()->index();
18 | $table->decimal('ip_dec_end', 39, 0)->unsigned()->index();
19 | });
20 |
21 | Schema::table('ipv6_prefix_whois', function($table)
22 | {
23 | $table->decimal('ip_dec_start', 39, 0)->unsigned()->index();
24 | $table->decimal('ip_dec_end', 39, 0)->unsigned()->index();
25 | });
26 | }
27 |
28 | /**
29 | * Reverse the migrations.
30 | *
31 | * @return void
32 | */
33 | public function down()
34 | {
35 | Schema::table('ipv4_prefix_whois', function($table)
36 | {
37 | $table->dropColumn('ip_dec_start');
38 | $table->dropColumn('ip_dec_end');
39 | });
40 |
41 | Schema::table('ipv6_prefix_whois', function($table)
42 | {
43 | $table->dropColumn('ip_dec_start');
44 | $table->dropColumn('ip_dec_end');
45 | });
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/database/migrations/2015_10_24_045027_CreateAsnInfoTable.php:
--------------------------------------------------------------------------------
1 | increments('id')->unique();
18 | $table->integer('rir_id')->unsigned()->index();
19 | $table->integer('asn')->unique();
20 | $table->string('name');
21 | $table->string('website')->nullable();
22 | $table->string('looking_glass')->nullable();
23 | $table->string('traffic_estimation')->nullable();
24 | $table->string('traffic_ratio')->nullable();
25 | $table->string('description')->nullable();
26 | $table->text('description_full')->nullable();
27 | $table->string('counrty_code', 2)->index();
28 | $table->text('owner_address')->nullable();
29 | $table->text('raw_whois')->nullable();
30 |
31 | $table->timestamps();
32 | });
33 | }
34 |
35 | /**
36 | * Reverse the migrations.
37 | *
38 | * @return void
39 | */
40 | public function down()
41 | {
42 | Schema::dropIfExists('asns');
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/database/migrations/2017_01_08_013716_remove_the_desc_single_field.php:
--------------------------------------------------------------------------------
1 | dropColumn('description');
18 | });
19 |
20 | Schema::table('ipv6_prefix_whois', function($table)
21 | {
22 | $table->dropColumn('description');
23 | });
24 |
25 | Schema::table('asns', function($table)
26 | {
27 | $table->dropColumn('description');
28 | });
29 | }
30 |
31 | /**
32 | * Reverse the migrations.
33 | *
34 | * @return void
35 | */
36 | public function down()
37 | {
38 | Schema::table('ipv4_prefix_whois', function($table)
39 | {
40 | $table->string('description')->nullable();
41 | });
42 |
43 | Schema::table('ipv6_prefix_whois', function($table)
44 | {
45 | $table->string('description')->nullable();
46 | });
47 |
48 | Schema::table('asns', function($table)
49 | {
50 | $table->string('description')->nullable();
51 | });
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/resources/views/api/register-application-done.blade.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | API Application
5 |
6 |
7 |
8 |
43 |
44 |
45 |
46 |
47 |
We sent your new API Key to your email!
48 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/database/migrations/2016_03_13_094810_alter_table_nullable_whois.php:
--------------------------------------------------------------------------------
1 | string('name')->nullable()->change();
18 | $table->string('counrty_code')->nullable()->change();
19 | });
20 |
21 | Schema::table('ipv6_prefix_whois', function($table)
22 | {
23 | $table->string('name')->nullable()->change();
24 | $table->string('counrty_code')->nullable()->change();
25 | });
26 | }
27 |
28 | /**
29 | * Reverse the migrations.
30 | *
31 | * @return void
32 | */
33 | public function down()
34 | {
35 | Schema::table('ipv4_prefix_whois', function($table)
36 | {
37 | $table->string('name')->nullable(false)->change();
38 | $table->string('counrty_code')->nullable(false)->change();
39 | });
40 |
41 | Schema::table('ipv6_prefix_whois', function($table)
42 | {
43 | $table->string('name')->nullable(false)->change();
44 | $table->string('counrty_code')->nullable(false)->change();
45 | });
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/app/Console/Kernel.php:
--------------------------------------------------------------------------------
1 | command('inspire')->hourly();
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/app/Http/Kernel.php:
--------------------------------------------------------------------------------
1 | [
27 | \App\Http\Middleware\EncryptCookies::class,
28 | \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
29 | \Illuminate\Session\Middleware\StartSession::class,
30 | \Illuminate\View\Middleware\ShareErrorsFromSession::class,
31 | ],
32 |
33 | 'api' => [
34 |
35 | ],
36 | ];
37 |
38 | /**
39 | * The application's route middleware.
40 | *
41 | * These middleware may be assigned to groups or used individually.
42 | *
43 | * @var array
44 | */
45 | protected $routeMiddleware = [
46 | 'auth' => \App\Http\Middleware\Authenticate::class,
47 | 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
48 | 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
49 | 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
50 | ];
51 | }
52 |
--------------------------------------------------------------------------------
/config/broadcasting.php:
--------------------------------------------------------------------------------
1 | env('BROADCAST_DRIVER', 'pusher'),
17 |
18 | /*
19 | |--------------------------------------------------------------------------
20 | | Broadcast Connections
21 | |--------------------------------------------------------------------------
22 | |
23 | | Here you may define all of the broadcast connections that will be used
24 | | to broadcast events to other systems or over websockets. Samples of
25 | | each available type of connection are provided inside this array.
26 | |
27 | */
28 |
29 | 'connections' => [
30 |
31 | 'pusher' => [
32 | 'driver' => 'pusher',
33 | 'key' => env('PUSHER_KEY'),
34 | 'secret' => env('PUSHER_SECRET'),
35 | 'app_id' => env('PUSHER_APP_ID'),
36 | 'options' => [
37 | //
38 | ],
39 | ],
40 |
41 | 'redis' => [
42 | 'driver' => 'redis',
43 | 'connection' => 'default',
44 | ],
45 |
46 | 'log' => [
47 | 'driver' => 'log',
48 | ],
49 |
50 | ],
51 |
52 | ];
53 |
--------------------------------------------------------------------------------
/database/migrations/2016_04_03_010547_addParentFieldsToPrefixWhois.php:
--------------------------------------------------------------------------------
1 | integer('rir_id')->nullable()->unsigned()->index();
18 | $table->string('parent_ip', 40)->nullable()->index();
19 | $table->integer('parent_cidr')->nullable()->unsigned()->index();
20 | });
21 |
22 | Schema::table('ipv6_prefix_whois', function($table)
23 | {
24 | $table->integer('rir_id')->nullable()->unsigned()->index();
25 | $table->string('parent_ip', 40)->nullable()->index();
26 | $table->integer('parent_cidr')->nullable()->unsigned()->index();
27 | });
28 | }
29 |
30 | /**
31 | * Reverse the migrations.
32 | *
33 | * @return void
34 | */
35 | public function down()
36 | {
37 | Schema::table('ipv4_prefix_whois', function($table)
38 | {
39 | $table->dropColumn('rir_id');
40 | $table->dropColumn('parent_ip');
41 | $table->dropColumn('parent_cidr');
42 | });
43 |
44 | Schema::table('ipv6_prefix_whois', function($table)
45 | {
46 | $table->dropColumn('rir_id');
47 | $table->dropColumn('parent_ip');
48 | $table->dropColumn('parent_cidr');
49 | });
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/app/Jobs/ResolveDnsQuery.php:
--------------------------------------------------------------------------------
1 | domain = trim($domain);
28 | $this->ipUtils = new IpUtils;
29 | }
30 |
31 | /**
32 | * Execute the job.
33 | *
34 | * @return void
35 | */
36 | public function handle(Dns $dns)
37 | {
38 | $domainRecords = $dns->getDomainRecords($this->domain);
39 |
40 | foreach ($domainRecords as $type => $records) {
41 | foreach ($records as $record) {
42 | /*
43 | $dnsEntry = new DNSRecord;
44 | $dnsEntry->input = $this->domain;
45 | $dnsEntry->type = $type;
46 | $dnsEntry->entry = $record;
47 | */
48 | if ($type === 'A' || $type === 'AAAA') {
49 | $this->ipUtils->ip2dec($record);
50 | }
51 |
52 | dump($this->domain, $type, $record,'=======================================');
53 | //$dnsEntry->save();
54 | }
55 | }
56 |
57 | echo 'Done: '.$this->domain.PHP_EOL;
58 |
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/app/Models/IXMember.php:
--------------------------------------------------------------------------------
1 | belongsTo('App\Models\IX', 'ix_peeringdb_id', 'peeringdb_id');
26 | }
27 |
28 | public function asn_info()
29 | {
30 | return $this->belongsTo('App\Models\ASN', 'asn', 'asn');
31 | }
32 |
33 | public static function getMembers($asn)
34 | {
35 | $ixs = [];
36 | foreach (self::where('asn', $asn)->get() as $ixMember) {
37 | $ixInfo = $ixMember->ix;
38 |
39 | if (is_null($ixInfo) === true) {
40 | continue;
41 | }
42 |
43 | $ix_data['ix_id'] = $ixInfo->id;
44 | $ix_data['name'] = $ixInfo->name;
45 | $ix_data['name_full'] = $ixInfo->name_full;
46 | $ix_data['country_code'] = $ixInfo->counrty_code;
47 | $ix_data['city'] = $ixInfo->city;
48 | $ix_data['ipv4_address'] = $ixMember->ipv4_address;
49 | $ix_data['ipv6_address'] = $ixMember->ipv6_address;
50 | $ix_data['speed'] = $ixMember->speed;
51 |
52 | $ixs[] = $ix_data;
53 | }
54 |
55 | return $ixs;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/app/Exceptions/Handler.php:
--------------------------------------------------------------------------------
1 | getMessage(), [
40 | 'url' => Request::url(),
41 | 'input' => Request::all()
42 | ]);
43 |
44 | return parent::report($e);
45 | }
46 |
47 | /**
48 | * Render an exception into an HTTP response.
49 | *
50 | * @param \Illuminate\Http\Request $request
51 | * @param \Exception $e
52 | * @return \Illuminate\Http\Response
53 | */
54 | public function render($request, Exception $e)
55 | {
56 | return parent::render($request, $e);
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/app/Models/IPv6BgpPrefix.php:
--------------------------------------------------------------------------------
1 | whois();
27 | }
28 |
29 | public function whois()
30 | {
31 | if (isset($this->attributes['whois']) !== true) {
32 | $this->attributes['whois'] = IPv6PrefixWhois::where('ip', $this->ip)->where('cidr', $this->cidr)->first();
33 | }
34 |
35 | return $this->attributes['whois'];
36 | }
37 |
38 | public function getAllocationAttribute()
39 | {
40 | return $this->allocation();
41 | }
42 |
43 | public function allocation()
44 | {
45 | if (isset($this->attributes['allocation']) !== true) {
46 | $ipUtils = new IpUtils();
47 | $this->attributes['allocation'] = $ipUtils->getAllocationEntry($this->ip, $this->cidr);
48 | }
49 |
50 | return $this->attributes['allocation'];
51 | }
52 |
53 | public function getRoaStatusAttribute($value)
54 | {
55 | if ($value == 1) {
56 | return 'Valid';
57 | } elseif ($value == -1) {
58 | return 'Invalid';
59 | } else {
60 | return 'None';
61 | }
62 | }
63 |
64 | public function asn()
65 | {
66 | return $this->belongsTo('App\Models\ASN', 'asn', 'asn');
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/app/Models/IPv4BgpPrefix.php:
--------------------------------------------------------------------------------
1 | whois();
27 | }
28 |
29 | public function whois()
30 | {
31 | if (isset($this->attributes['whois']) !== true) {
32 | $this->attributes['whois'] = IPv4PrefixWhois::where('ip', $this->ip)->where('cidr', $this->cidr)->first();
33 | }
34 |
35 | return $this->attributes['whois'];
36 | }
37 |
38 | public function getAllocationAttribute()
39 | {
40 | return $this->allocation();
41 | }
42 |
43 | public function getRoaStatusAttribute($value)
44 | {
45 | if ($value == 1) {
46 | return 'Valid';
47 | } elseif ($value == -1) {
48 | return 'Invalid';
49 | } else {
50 | return 'None';
51 | }
52 | }
53 |
54 | public function allocation()
55 | {
56 | if (isset($this->attributes['allocation']) !== true) {
57 | $ipUtils = new IpUtils();
58 | $this->attributes['allocation'] = $ipUtils->getAllocationEntry($this->ip, $this->cidr);
59 | }
60 |
61 | return $this->attributes['allocation'];
62 | }
63 |
64 | public function asn_info()
65 | {
66 | return $this->belongsTo('App\Models\ASN', 'asn', 'asn');
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/bootstrap/app.php:
--------------------------------------------------------------------------------
1 | singleton(
30 | Illuminate\Contracts\Http\Kernel::class,
31 | App\Http\Kernel::class
32 | );
33 |
34 | $app->singleton(
35 | Illuminate\Contracts\Console\Kernel::class,
36 | App\Console\Kernel::class
37 | );
38 |
39 | $app->singleton(
40 | Illuminate\Contracts\Debug\ExceptionHandler::class,
41 | App\Exceptions\Handler::class
42 | );
43 |
44 | /*
45 | |--------------------------------------------------------------------------
46 | | Return The Application
47 | |--------------------------------------------------------------------------
48 | |
49 | | This script returns the application instance. The instance is given to
50 | | the calling script so we can separate the building of the instances
51 | | from the actual running of the application and sending responses.
52 | |
53 | */
54 |
55 | return $app;
56 |
--------------------------------------------------------------------------------
/artisan:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env php
2 | make(Illuminate\Contracts\Console\Kernel::class);
32 |
33 | $status = $kernel->handle(
34 | $input = new Symfony\Component\Console\Input\ArgvInput,
35 | new Symfony\Component\Console\Output\ConsoleOutput
36 | );
37 |
38 | /*
39 | |--------------------------------------------------------------------------
40 | | Shutdown The Application
41 | |--------------------------------------------------------------------------
42 | |
43 | | Once Artisan has finished running. We will fire off the shutdown events
44 | | so that any final work may be done by the application before we shut
45 | | down the process. This is the last thing to happen to the request.
46 | |
47 | */
48 |
49 | $kernel->terminate($input, $status);
50 |
51 | exit($status);
52 |
--------------------------------------------------------------------------------
/app/Models/DNSRecord.php:
--------------------------------------------------------------------------------
1 | 8,
20 | 'analysis' => [
21 | 'analyzer' => [
22 | 'string_lowercase' => [
23 | 'tokenizer' => 'keyword',
24 | 'filter' => [ 'asciifolding', 'lowercase', 'custom_replace' ],
25 | ],
26 | ],
27 | 'filter' => [
28 | 'custom_replace' => [
29 | 'type' => 'pattern_replace',
30 | 'pattern' => "[^a-z0-9 ]",
31 | 'replacement' => "",
32 | ],
33 | ],
34 | ],
35 | ];
36 |
37 | /**
38 | * The elasticsearch mappings.
39 | *
40 | * @var array
41 | */
42 | protected $mappingProperties = [
43 | 'input' => [
44 | 'type' => 'string',
45 | 'analyzer' => 'string_lowercase'
46 | ],
47 | 'ip_dec' => [
48 | 'type' => 'double',
49 | ],
50 | ];
51 |
52 | // To save on space we will use the ints instead of a char byte on ES storage
53 | public static $rrTypes = [
54 | 'A' => 1,
55 | 'AAAA' => 2,
56 | 'CNAME' => 3,
57 | 'NS' => 4,
58 | 'MX' => 5,
59 | 'SOA' => 6,
60 | 'TXT' => 7,
61 | ];
62 |
63 | public function getTable()
64 | {
65 | return 'dns_records';
66 | }
67 |
68 | public function getKey()
69 | {
70 | return $this->getTable();
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/app/Services/Domains.php:
--------------------------------------------------------------------------------
1 | config('clickhouse.host'),
19 | 'port' => config('clickhouse.port'),
20 | 'username' => 'default',
21 | 'password' => ''
22 | ];
23 | $this->clickhouse = new ClickHouseClient($config);
24 | $this->clickhouse->database('default');
25 | $this->clickhouse->setTimeout(20);
26 | $this->clickhouse->setConnectTimeOut(30);
27 |
28 |
29 | $ipUtils = new IpUtils();
30 |
31 | foreach ($prefixes['ipv4_prefixes'] as $prefix) {
32 | $this->ranges[] = [
33 | $startIpDec = $ipUtils->ip2dec($prefix['ip']),
34 | $startIpDec + $ipUtils->IPv4cidrIpCount()[$prefix['cidr']] - 1,
35 | ];
36 | }
37 |
38 | foreach ($prefixes['ipv6_prefixes'] as $prefix) {
39 | $this->ranges[] = [
40 | $startIpDec = $ipUtils->ip2dec($prefix['ip']),
41 | $startIpDec + $ipUtils->IPv6cidrIpCount()[$prefix['cidr']] - 1,
42 | ];
43 | }
44 |
45 | }
46 |
47 | public function get()
48 | {
49 | $query = '';
50 | foreach ($this->ranges as $range) {
51 | $query .= '(ip >= '.$range[0].' AND ip <= '.$range[1].') OR ';
52 | }
53 |
54 | $query = preg_replace('/\W\w+\s*(\W*)$/', '$1', $query);
55 |
56 | $statement = $this->clickhouse->select('SELECT name, ip_address FROM dns WHERE '.$query);
57 | $domains = [];
58 |
59 | foreach ($statement->rows() as $row){
60 | $domains[$row['ip_address']] = $row['name'];
61 | }
62 |
63 | return $domains;
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/app/Providers/RouteServiceProvider.php:
--------------------------------------------------------------------------------
1 | mapApiRoutes();
39 |
40 | $this->mapWebRoutes();
41 |
42 | //
43 | }
44 |
45 | /**
46 | * Define the "web" routes for the application.
47 | *
48 | * These routes all receive session state, CSRF protection, etc.
49 | *
50 | * @return void
51 | */
52 | protected function mapWebRoutes()
53 | {
54 | Route::group([
55 | 'middleware' => 'web',
56 | 'namespace' => $this->namespace,
57 | ], function ($router) {
58 | require base_path('routes/web.php');
59 | });
60 | }
61 |
62 | /**
63 | * Define the "api" routes for the application.
64 | *
65 | * These routes are typically stateless.
66 | *
67 | * @return void
68 | */
69 | protected function mapApiRoutes()
70 | {
71 | Route::group([
72 | 'middleware' => 'api',
73 | 'namespace' => $this->namespace,
74 | ], function ($router) {
75 | require base_path('routes/api.php');
76 | });
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | ## Laravel PHP Framework
2 |
3 | [](https://travis-ci.org/laravel/framework)
4 | [](https://packagist.org/packages/laravel/framework)
5 | [](https://packagist.org/packages/laravel/framework)
6 | [](https://packagist.org/packages/laravel/framework)
7 | [](https://packagist.org/packages/laravel/framework)
8 |
9 | Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable, creative experience to be truly fulfilling. Laravel attempts to take the pain out of development by easing common tasks used in the majority of web projects, such as authentication, routing, sessions, queueing, and caching.
10 |
11 | Laravel is accessible, yet powerful, providing powerful tools needed for large, robust applications. A superb inversion of control container, expressive migration system, and tightly integrated unit testing support give you the tools you need to build any application with which you are tasked.
12 |
13 | ## Official Documentation
14 |
15 | Documentation for the framework can be found on the [Laravel website](http://laravel.com/docs).
16 |
17 | ## Contributing
18 |
19 | Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the [Laravel documentation](http://laravel.com/docs/contributions).
20 |
21 | ## Security Vulnerabilities
22 |
23 | If you discover a security vulnerability within Laravel, please send an e-mail to Taylor Otwell at taylor@laravel.com. All security vulnerabilities will be promptly addressed.
24 |
25 | ### License
26 |
27 | The Laravel framework is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)
28 |
--------------------------------------------------------------------------------
/public/index.php:
--------------------------------------------------------------------------------
1 |
8 | */
9 |
10 | /*
11 | |--------------------------------------------------------------------------
12 | | Register The Auto Loader
13 | |--------------------------------------------------------------------------
14 | |
15 | | Composer provides a convenient, automatically generated class loader for
16 | | our application. We just need to utilize it! We'll simply require it
17 | | into the script here so that we don't have to worry about manual
18 | | loading any of our classes later on. It feels nice to relax.
19 | |
20 | */
21 |
22 | require __DIR__.'/../bootstrap/autoload.php';
23 |
24 | /*
25 | |--------------------------------------------------------------------------
26 | | Turn On The Lights
27 | |--------------------------------------------------------------------------
28 | |
29 | | We need to illuminate PHP development, so let us turn on the lights.
30 | | This bootstraps the framework and gets it ready for use, then it
31 | | will load up this application so that we can run it and send
32 | | the responses back to the browser and delight our users.
33 | |
34 | */
35 |
36 | $app = require_once __DIR__.'/../bootstrap/app.php';
37 |
38 | /*
39 | |--------------------------------------------------------------------------
40 | | Run The Application
41 | |--------------------------------------------------------------------------
42 | |
43 | | Once we have the application, we can handle the incoming request
44 | | through the kernel, and send the associated response back to
45 | | the client's browser allowing them to enjoy the creative
46 | | and wonderful application we have prepared for them.
47 | |
48 | */
49 |
50 | $kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
51 |
52 | $response = $kernel->handle(
53 | $request = Illuminate\Http\Request::capture()
54 | );
55 |
56 | $response->send();
57 |
58 | $kernel->terminate($request, $response);
59 |
--------------------------------------------------------------------------------
/scripts/birdc_output_routes.sh:
--------------------------------------------------------------------------------
1 | show route all | awk -vts=$(date +%s) '
2 | BEGIN {
3 | OFS = "|";
4 | ORS = "\n";
5 | route = "";
6 | peer = "";
7 | path = "";
8 | split(path, path_hops, " ");
9 | origin = "";
10 | next_hop = "";
11 | community = "";
12 | }
13 | function printroute() {
14 | if (route != "" && peer != "" && path != "" && origin != "" && next_hop != "") {
15 | print "BGP4MP", ts, "A", peer, path_hops[1], route, path, origin, next_hop, "0", "0", community, "NAG", "", "";
16 | peer = "";
17 | path = "";
18 | split(path, path_hops, " ");
19 | origin = "";
20 | next_hop = "";
21 | community = "";
22 | }
23 | }
24 | {
25 | if ($2 == "unreachable") {
26 | printroute();
27 | route = $1;
28 | peer = $(NF-3);
29 | gsub("\\]", "", peer);
30 | } else if ($2 == "via") {
31 | printroute();
32 | route = $1;
33 | peer = $3;
34 | } else if ($1 == "unreachable") {
35 | printroute();
36 | peer = $(NF-2);
37 | gsub("\\]", "", peer);
38 | } else if ($1 == "via") {
39 | printroute();
40 | peer = $2;
41 | } else if ($1 == "BGP.as_path:") {
42 | path = $0;
43 | gsub("^.*BGP\\.as_path: ", "", path);
44 | split(path, path_hops, " ");
45 | } else if ($1 == "BGP.origin:") {
46 | origin = $2;
47 | } else if ($1 == "BGP.next_hop:") {
48 | next_hop = $2;
49 | } else if ($1 == "BGP.community:") {
50 | community = $0;
51 | gsub("^.*BGP\\.community: ", "", community);
52 | gsub("\\(", "", community);
53 | gsub("\\)", "", community);
54 | gsub(",", ":", community);
55 | }
56 | }
57 | END {
58 | printroute();
59 | }
60 | '
61 |
62 |
--------------------------------------------------------------------------------
/database/seeds/RIRs.php:
--------------------------------------------------------------------------------
1 | 'AfriNIC',
17 | 'full_name' => 'African Network Information Center',
18 | 'website' => 'afrinic.net',
19 | 'whois_server' => 'whois.afrinic.net',
20 | 'allocation_list_url' => 'ftp://ftp.afrinic.net/stats/afrinic/delegated-afrinic-extended-latest',
21 | ]);
22 |
23 | Rir::create([
24 | 'name' => 'ARIN',
25 | 'full_name' => 'American Registry for Internet Numbers',
26 | 'website' => 'arin.net',
27 | 'whois_server' => 'whois.arin.net',
28 | 'allocation_list_url' => 'ftp://ftp.arin.net/pub/stats/arin/delegated-arin-extended-latest',
29 | ]);
30 |
31 | Rir::create([
32 | 'name' => 'APNIC',
33 | 'full_name' => 'Asia-Pacific Network Information Centre',
34 | 'website' => 'apnic.net',
35 | 'whois_server' => 'whois.apnic.net',
36 | 'allocation_list_url' => 'ftp://ftp.apnic.net/pub/stats/apnic/delegated-apnic-extended-latest',
37 | ]);
38 |
39 | Rir::create([
40 | 'name' => 'Lacnic',
41 | 'full_name' => 'Latin America and Caribbean Network Information Centre',
42 | 'website' => 'lacnic.net',
43 | 'whois_server' => 'whois.lacnic.net',
44 | 'allocation_list_url' => 'ftp://ftp.lacnic.net/pub/stats/lacnic/delegated-lacnic-extended-latest',
45 | ]);
46 |
47 | Rir::create([
48 | 'name' => 'RIPE',
49 | 'full_name' => 'Reseaux IP Européens Network Coordination Centre',
50 | 'website' => 'ripe.net',
51 | 'whois_server' => 'whois.ripe.net',
52 | 'allocation_list_url' => 'ftp://ftp.ripe.net/ripe/stats/delegated-ripencc-extended-latest',
53 | ]);
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/app/Models/IX.php:
--------------------------------------------------------------------------------
1 | [
19 | 'analyzer' => [
20 | 'string_lowercase' => [
21 | 'tokenizer' => 'keyword',
22 | 'filter' => [ 'asciifolding', 'lowercase', 'custom_replace' ],
23 | ],
24 | ],
25 | 'filter' => [
26 | 'custom_replace' => [
27 | 'type' => 'pattern_replace',
28 | 'pattern' => "[^a-z0-9 ]",
29 | 'replacement' => "",
30 | ],
31 | ],
32 | ],
33 | ];
34 |
35 | /**
36 | * The elasticsearch mappings.
37 | *
38 | * @var array
39 | */
40 | protected $mappingProperties = [
41 | 'name' => [
42 | 'type' => 'text',
43 | 'analyzer' => 'string_lowercase',
44 | 'fielddata' => true,
45 | ],
46 | 'name_full' => [
47 | 'type' => 'text',
48 | 'analyzer' => 'string_lowercase',
49 | 'fielddata' => true,
50 | ],
51 | 'ip' => [
52 | 'type' => 'keyword',
53 | 'index' => true,
54 | ],
55 | ];
56 |
57 | /**
58 | * The database table used by the model.
59 | *
60 | * @var string
61 | */
62 | protected $table = 'ixs';
63 |
64 | /**
65 | * The attributes excluded from the model's JSON form.
66 | *
67 | * @var array
68 | */
69 | protected $hidden = ['id', 'peeringdb_id', 'created_at', 'updated_at'];
70 |
71 | public function getIndexName()
72 | {
73 | if (substr_count(config('elasticquent.default_index'), '_') > 1) {
74 | return config('elasticquent.default_index');
75 | }
76 |
77 | return config('elasticquent.default_index'). '_ix';
78 | }
79 |
80 | public function members()
81 | {
82 | return $this->hasMany('App\Models\IXMember', 'ix_peeringdb_id', 'peeringdb_id');
83 | }
84 |
85 | }
86 |
--------------------------------------------------------------------------------
/app/Console/Commands/GenerateGraphs.php:
--------------------------------------------------------------------------------
1 | bench = $bench;
35 | $this->ipUtils = $ipUtils;
36 | $this->esClient = ClientBuilder::create()->setHosts(config('elasticsearch.hosts'))->build();
37 |
38 | }
39 |
40 | /**
41 | * The console command description.
42 | *
43 | * @var string
44 | */
45 | protected $description = 'Generate all ASN relation graphes';
46 |
47 | /**
48 | * Execute the console command.
49 | *
50 | * @return mixed
51 | */
52 | public function handle()
53 | {
54 | $this->bench->start();
55 |
56 | $asns = $this->getAsns();
57 | $this->generateGraphs($asns);
58 |
59 | $this->output->newLine(1);
60 | $this->bench->end();
61 | $this->info(sprintf(
62 | 'Time: %s, Memory: %s',
63 | $this->bench->getTime(),
64 | $this->bench->getMemoryPeak()
65 | ));
66 |
67 | }
68 |
69 | private function generateGraphs($asns)
70 | {
71 | $this->info('Generating graph images per ASN');
72 | foreach ($asns as $asnObj) {
73 | $this->dispatch(new GenerateAsnGraphs($asnObj->asn));
74 | }
75 | }
76 |
77 | private function getAsns()
78 | {
79 | $this->info('Getting all ASNs from ES');
80 |
81 | $bgpAsns = $this->ipUtils->getBgpAsns();
82 |
83 | $this->info('Found ' . number_format(count($bgpAsns)) . ' unique ASNs in BGP table');
84 | return $bgpAsns;
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "laravel/laravel",
3 | "description": "The Laravel Framework.",
4 | "keywords": ["framework", "laravel"],
5 | "license": "MIT",
6 | "type": "project",
7 | "require": {
8 | "php": ">=5.5.9",
9 | "ext-bcmath": "*",
10 | "ext-curl": "*",
11 | "ext-bz2": "*",
12 | "laravel/framework": "5.8.*",
13 | "webpatser/laravel-countries": "dev-master",
14 | "league/climate": "^3.2",
15 | "devster/ubench": "1.2.*",
16 | "guzzlehttp/guzzle": "~5.3|~6.0",
17 | "doctrine/dbal": "^2.5",
18 | "predis/predis": "~1.0",
19 | "pear/net_dns2": "^1.4",
20 | "elasticquent/elasticquent": "dev-master",
21 | "laravel/tinker": "^1.0",
22 | "smi2/phpclickhouse": "^1.3",
23 | "barryvdh/laravel-debugbar": "^3.2",
24 | "jeremykendall/php-domain-parser": "^5.6",
25 | "geoip2/geoip2": "2.9.0"
26 | },
27 | "require-dev": {
28 | "fzaninotto/faker": "~1.4",
29 | "mockery/mockery": "0.9.*",
30 | "phpunit/phpunit": "~5.7",
31 | "symfony/css-selector": "2.8.*|3.1.*",
32 | "symfony/dom-crawler": "2.8.*|3.1.*"
33 | },
34 | "autoload": {
35 | "classmap": [
36 | "database"
37 | ],
38 | "psr-4": {
39 | "App\\": "app/"
40 | },
41 | "files": [
42 | "app/helpers.php"
43 | ]
44 | },
45 | "autoload-dev": {
46 | "classmap": [
47 | "tests/TestCase.php"
48 | ]
49 | },
50 | "scripts": {
51 | "post-root-package-install": [
52 | "php -r \"copy('.env.example', '.env');\""
53 | ],
54 | "post-create-project-cmd": [
55 | "php artisan key:generate"
56 | ],
57 | "post-install-cmd": [
58 | "php artisan clear-compiled",
59 | "\\Pdp\\Installer::updateLocalCache",
60 | "php artisan zBGPView:update-maxmind-database",
61 | "php artisan optimize"
62 | ],
63 | "pre-update-cmd": [
64 | "php artisan clear-compiled"
65 | ],
66 | "post-update-cmd": [
67 | "\\Pdp\\Installer::updateLocalCache",
68 | "php artisan zBGPView:update-maxmind-database",
69 | "php artisan optimize"
70 | ]
71 | },
72 | "config": {
73 | "preferred-install": "dist"
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/config/cache.php:
--------------------------------------------------------------------------------
1 | env('CACHE_DRIVER', 'file'),
17 |
18 | /*
19 | |--------------------------------------------------------------------------
20 | | Cache Stores
21 | |--------------------------------------------------------------------------
22 | |
23 | | Here you may define all of the cache "stores" for your application as
24 | | well as their drivers. You may even define multiple stores for the
25 | | same cache driver to group types of items stored in your caches.
26 | |
27 | */
28 |
29 | 'stores' => [
30 |
31 | 'apc' => [
32 | 'driver' => 'apc',
33 | ],
34 |
35 | 'array' => [
36 | 'driver' => 'array',
37 | ],
38 |
39 | 'database' => [
40 | 'driver' => 'database',
41 | 'table' => 'cache',
42 | 'connection' => null,
43 | ],
44 |
45 | 'file' => [
46 | 'driver' => 'file',
47 | 'path' => storage_path('framework/cache'),
48 | ],
49 |
50 | 'memcached' => [
51 | 'driver' => 'memcached',
52 | 'servers' => [
53 | [
54 | 'host' => '127.0.0.1', 'port' => 11211, 'weight' => 100,
55 | ],
56 | ],
57 | ],
58 |
59 | 'redis' => [
60 | 'driver' => 'redis',
61 | 'connection' => 'default',
62 | ],
63 |
64 | ],
65 |
66 | /*
67 | |--------------------------------------------------------------------------
68 | | Cache Key Prefix
69 | |--------------------------------------------------------------------------
70 | |
71 | | When utilizing a RAM based store such as APC or Memcached, there might
72 | | be other applications utilizing the same cache. So, we'll specify a
73 | | value to get prefixed to all our keys so we can avoid collisions.
74 | |
75 | */
76 |
77 | 'prefix' => 'laravel',
78 |
79 | ];
80 |
--------------------------------------------------------------------------------
/database/migrations/2016_03_20_082928_MakeAsnBigInt.php:
--------------------------------------------------------------------------------
1 | bigInteger('asn')->unsigned()->change();
18 | });
19 |
20 | Schema::table('ipv4_bgp_prefixes', function($table)
21 | {
22 | $table->bigInteger('asn')->unsigned()->change();
23 | });
24 |
25 | Schema::table('ipv6_bgp_prefixes', function($table)
26 | {
27 | $table->bigInteger('asn')->unsigned()->change();
28 | });
29 |
30 | Schema::table('ix_members', function($table)
31 | {
32 | $table->bigInteger('asn')->unsigned()->change();
33 | });
34 |
35 | Schema::table('ipv4_peers', function($table)
36 | {
37 | $table->bigInteger('asn_1')->unsigned()->change();
38 | $table->bigInteger('asn_2')->unsigned()->change();
39 | });
40 |
41 | Schema::table('ipv6_peers', function($table)
42 | {
43 | $table->bigInteger('asn_1')->unsigned()->change();
44 | $table->bigInteger('asn_2')->unsigned()->change();
45 | });
46 | }
47 |
48 | /**
49 | * Reverse the migrations.
50 | *
51 | * @return void
52 | */
53 | public function down()
54 | {
55 | Schema::table('asns', function($table)
56 | {
57 | $table->integer('asn')->change();
58 | });
59 |
60 | Schema::table('ipv4_bgp_prefixes', function($table)
61 | {
62 | $table->integer('asn')->change();
63 | });
64 |
65 | Schema::table('ix_members', function($table)
66 | {
67 | $table->integer('asn')->change();
68 | });
69 |
70 | Schema::table('ipv6_bgp_prefixes', function($table)
71 | {
72 | $table->integer('asn')->change();
73 | });
74 |
75 | Schema::table('ipv4_peers', function($table)
76 | {
77 | $table->integer('asn_1')->change();
78 | $table->integer('asn_2')->change();
79 | });
80 |
81 | Schema::table('ipv6_peers', function($table)
82 | {
83 | $table->integer('asn_1')->change();
84 | $table->integer('asn_2')->change();
85 | });
86 |
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/app/Jobs/UpdateASNs.php:
--------------------------------------------------------------------------------
1 | oldAsn = $oldAsn;
30 | $this->peeringDBData = $peeringDBData;
31 | $this->cli = new CLImate();
32 | }
33 |
34 | /**
35 | * Execute the job.
36 | *
37 | * @return void
38 | */
39 | public function handle()
40 | {
41 | $oldAsn = $this->oldAsn;
42 |
43 | $oldAsn->emails()->delete();
44 |
45 | $this->cli->br()->comment('Updating: AS' . $oldAsn->asn);
46 | $asnWhois = new Whois($oldAsn->asn);
47 | $parsedWhois = $asnWhois->parse();
48 |
49 | // Skip null results
50 | if (is_null($parsedWhois) === true) {
51 | $oldAsn->touch();
52 | return;
53 | }
54 |
55 | $oldAsn->name = $parsedWhois->name;
56 | $oldAsn->description_full = count($parsedWhois->description) > 0 ? json_encode($parsedWhois->description) : json_encode([$oldAsn->description]);
57 |
58 | // If we have the PeerDB info lets update it.
59 | if ($peerDb = $this->peeringDBData) {
60 | $oldAsn->website = $peerDb->website;
61 | $oldAsn->looking_glass = $peerDb->looking_glass;
62 | $oldAsn->traffic_estimation = $peerDb->info_traffic;
63 | $oldAsn->traffic_ratio = $peerDb->info_ratio;
64 | }
65 |
66 | $oldAsn->counrty_code = $parsedWhois->counrty_code;
67 | $oldAsn->owner_address = json_encode($parsedWhois->address);
68 | $oldAsn->raw_whois = $asnWhois->raw();
69 | $oldAsn->save();
70 |
71 | // Save ASN Emails
72 | foreach ($parsedWhois->emails as $email) {
73 | $asnEmail = new ASNEmail();
74 | $asnEmail->asn_id = $oldAsn->id;
75 | $asnEmail->email_address = $email;
76 |
77 | // Check if its an abuse email
78 | if (in_array($email, $parsedWhois->abuse_emails)) {
79 | $asnEmail->abuse_email = true;
80 | }
81 |
82 | $asnEmail->save();
83 | }
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/app/Jobs/UpdatePrefixes.php:
--------------------------------------------------------------------------------
1 | ipVersion = $ipVersion;
30 | $this->ipPrefix = $ipPrefix;
31 | $this->cli = new CLImate();
32 | }
33 |
34 | /**
35 | * Execute the job.
36 | *
37 | * @return void
38 | */
39 | public function handle()
40 | {
41 | $oldPrefix = $this->ipPrefix;
42 | $ipVersion = $this->ipVersion;
43 |
44 | $ipWhois = new Whois($oldPrefix->ip, $oldPrefix->cidr);
45 | $parsedWhois = $ipWhois->parse();
46 |
47 | // If null, lets skip
48 | if (is_null($parsedWhois) === true) {
49 | $this->cli->br()->error('Seems that whois server returned no results for prefix: '.$oldPrefix->ip.'/'.$oldPrefix->cidr);
50 | return;
51 | }
52 |
53 | $oldPrefix->name = $parsedWhois->name;
54 | $oldPrefix->description_full = json_encode($parsedWhois->description);
55 | $oldPrefix->counrty_code = $parsedWhois->counrty_code;
56 | $oldPrefix->owner_address = json_encode($parsedWhois->address);
57 | $oldPrefix->raw_whois = $ipWhois->raw();
58 | $oldPrefix->save();
59 |
60 | // Save Prefix Emails
61 | $oldPrefix->emails()->delete();
62 | foreach ($parsedWhois->emails as $email) {
63 | $className = 'App\Models\IPv' . $ipVersion . 'PrefixWhoisEmail';
64 | $prefixEmail = new $className;
65 | $prefixEmail->prefix_whois_id = $oldPrefix->id;
66 | $prefixEmail->email_address = $email;
67 |
68 | // Check if its an abuse email
69 | if (in_array($email, $parsedWhois->abuse_emails)) {
70 | $prefixEmail->abuse_email = true;
71 | }
72 |
73 | $prefixEmail->save();
74 | }
75 |
76 | dump([
77 | 'name' => $oldPrefix->name,
78 | 'description' => $oldPrefix->description,
79 | 'description_full' => $oldPrefix->description_full,
80 | 'counrty_code' => $oldPrefix->counrty_code,
81 | 'owner_address' => $oldPrefix->owner_address,
82 | ]);
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/routes/api.php:
--------------------------------------------------------------------------------
1 | 'asn', 'uses' => 'ApiV1Controller@asn']);
30 | Route::get('/asn/{as_number}/prefixes', ['as' => 'asn.prefixes', 'uses' => 'ApiV1Controller@asnPrefixes']);
31 | Route::get('/asn/{as_number}/domains', ['as' => 'asn.domains', 'uses' => 'ApiV1Controller@asnDomains']);
32 | Route::get('/asn/{as_number}/peers', ['as' => 'asn.peers', 'uses' => 'ApiV1Controller@asnPeers']);
33 | Route::get('/asn/{as_number}/ixs', ['as' => 'asn.ixs', 'uses' => 'ApiV1Controller@asnIxs']);
34 | Route::get('/asn/{as_number}/upstreams', ['as' => 'asn.upstreams', 'uses' => 'ApiV1Controller@asnUpstreams']);
35 | Route::get('/asn/{as_number}/downstreams', ['as' => 'asn.downstreams', 'uses' => 'ApiV1Controller@asnDownstreams']);
36 | Route::get('/prefix/{ip}/{cidr}', ['as' => 'prefix', 'uses' => 'ApiV1Controller@prefix']);
37 | Route::get('/prefix/{ip}/{cidr}/dns', ['as' => 'prefix.dns', 'uses' => 'ApiV1Controller@prefixDns']);
38 | Route::get('/ip/{ip}', ['as' => 'ip', 'uses' => 'ApiV1Controller@ip']);
39 | Route::get('/ix/{ix_id}', ['as' => 'ix', 'uses' => 'ApiV1Controller@ix']);
40 |
41 | Route::get('/search', ['as' => 'asns', 'uses' => 'ApiV1Controller@search']);
42 |
43 | // Reporting Routes
44 | Route::group(['prefix' => 'reports'], function () {
45 | Route::get('countries', ['as' => 'reports.countries', 'uses' => 'ApiV1Controller@countriesReport']);
46 | Route::get('countries/{country_code}', ['as' => 'reports.country', 'uses' => 'ApiV1Controller@countryReport']);
47 | });
48 |
49 | // Misc Routes (Internal Use)
50 | Route::get('/dns/live/{hostname}', ['uses' => 'ApiV1Controller@getLiveDns']);
51 | Route::get('/sitemap', ['uses' => 'ApiV1Controller@sitemapUrls']);
52 | Route::get('/as-summery', ['uses' => 'ApiV1Controller@asnSummery']);
53 | Route::get('/contacts/{resource}/{cidr?}', ['uses' => 'ApiV1Controller@getContacts']);
54 | Route::get('/asn-prefixes', ['uses' => 'ApiV1Controller@getAsnPrefixes']);
55 |
--------------------------------------------------------------------------------
/config/queue.php:
--------------------------------------------------------------------------------
1 | env('QUEUE_DRIVER', 'sync'),
20 |
21 | /*
22 | |--------------------------------------------------------------------------
23 | | Queue Connections
24 | |--------------------------------------------------------------------------
25 | |
26 | | Here you may configure the connection information for each server that
27 | | is used by your application. A default configuration has been added
28 | | for each back-end shipped with Laravel. You are free to add more.
29 | |
30 | */
31 |
32 | 'connections' => [
33 |
34 | 'sync' => [
35 | 'driver' => 'sync',
36 | ],
37 |
38 | 'database' => [
39 | 'driver' => 'database',
40 | 'table' => 'jobs',
41 | 'queue' => 'default',
42 | 'retry_after' => 60,
43 | ],
44 |
45 | 'beanstalkd' => [
46 | 'driver' => 'beanstalkd',
47 | 'host' => 'localhost',
48 | 'queue' => 'default',
49 | 'retry_after' => 60,
50 | ],
51 |
52 | 'sqs' => [
53 | 'driver' => 'sqs',
54 | 'key' => 'your-public-key',
55 | 'secret' => 'your-secret-key',
56 | 'prefix' => 'https://sqs.us-east-1.amazonaws.com/your-account-id',
57 | 'queue' => 'your-queue-name',
58 | 'region' => 'us-east-1',
59 | ],
60 |
61 | 'redis' => [
62 | 'driver' => 'redis',
63 | 'connection' => 'default',
64 | 'queue' => 'default',
65 | 'retry_after' => 60,
66 | ],
67 |
68 | ],
69 |
70 | /*
71 | |--------------------------------------------------------------------------
72 | | Failed Queue Jobs
73 | |--------------------------------------------------------------------------
74 | |
75 | | These options configure the behavior of failed queue job logging so you
76 | | can control which database and table are used to store the jobs that
77 | | have failed. You may change them to any database / table you wish.
78 | |
79 | */
80 |
81 | 'failed' => [
82 | 'database' => env('DB_CONNECTION', 'mysql'),
83 | 'table' => 'failed_jobs',
84 | ],
85 |
86 | ];
87 |
--------------------------------------------------------------------------------
/config/filesystems.php:
--------------------------------------------------------------------------------
1 | 'local',
19 |
20 | /*
21 | |--------------------------------------------------------------------------
22 | | Default Cloud Filesystem Disk
23 | |--------------------------------------------------------------------------
24 | |
25 | | Many applications store files both locally and in the cloud. For this
26 | | reason, you may specify a default "cloud" driver here. This driver
27 | | will be bound as the Cloud disk implementation in the container.
28 | |
29 | */
30 |
31 | 'cloud' => 's3',
32 |
33 | /*
34 | |--------------------------------------------------------------------------
35 | | Filesystem Disks
36 | |--------------------------------------------------------------------------
37 | |
38 | | Here you may configure as many filesystem "disks" as you wish, and you
39 | | may even configure multiple disks of the same driver. Defaults have
40 | | been setup for each driver as an example of the required options.
41 | |
42 | */
43 |
44 | 'disks' => [
45 |
46 | 'local' => [
47 | 'driver' => 'local',
48 | 'root' => storage_path('app'),
49 | ],
50 |
51 | 'ftp' => [
52 | 'driver' => 'ftp',
53 | 'host' => 'ftp.example.com',
54 | 'username' => 'your-username',
55 | 'password' => 'your-password',
56 |
57 | // Optional FTP Settings...
58 | // 'port' => 21,
59 | // 'root' => '',
60 | // 'passive' => true,
61 | // 'ssl' => true,
62 | // 'timeout' => 30,
63 | ],
64 |
65 | 's3' => [
66 | 'driver' => 's3',
67 | 'key' => 'your-key',
68 | 'secret' => 'your-secret',
69 | 'region' => 'your-region',
70 | 'bucket' => 'your-bucket',
71 | ],
72 |
73 | 'rackspace' => [
74 | 'driver' => 'rackspace',
75 | 'username' => 'your-username',
76 | 'key' => 'your-key',
77 | 'container' => 'your-container',
78 | 'endpoint' => 'https://identity.api.rackspacecloud.com/v2.0/',
79 | 'region' => 'IAD',
80 | 'url_type' => 'publicURL',
81 | ],
82 |
83 | ],
84 |
85 | ];
86 |
--------------------------------------------------------------------------------
/app/Console/Commands/UpdateRoaTable.php:
--------------------------------------------------------------------------------
1 | ipUtils = $ipUtils;
36 | $this->rpkiServer = config('app.rpki_server_url');
37 | }
38 |
39 | /**
40 | * Execute the console command.
41 | *
42 | * @return mixed
43 | */
44 | public function handle()
45 | {
46 | $this->info('Downloading the full ROA cert list');
47 | $roas = json_decode(file_get_contents($this->rpkiServer));
48 | $ipv4AmountCidrArray = $this->ipUtils->IPv4cidrIpCount();
49 | $ipv6AmountCidrArray = $this->ipUtils->IPv6cidrIpCount();
50 | $mysqlTime = '"' . date('Y-m-d H:i:s') . '"';
51 |
52 | $this->info('Creating the insert query');
53 | DB::statement('DROP TABLE IF EXISTS roa_table_temp');
54 | DB::statement('DROP TABLE IF EXISTS backup_roa_table');
55 | DB::statement('CREATE TABLE roa_table_temp LIKE roa_table');
56 |
57 | $roaInsert = '';
58 | foreach ($roas->roas as $roa) {
59 | $roaParts = explode('/', $roa->prefix);
60 | $roaCidr = $roaParts[1];
61 | $roaIP = $roaParts[0];
62 | $roaAsn = str_ireplace('as', '', $roa->asn);
63 |
64 | $startDec = $this->ipUtils->ip2dec($roaIP);
65 | if ($this->ipUtils->getInputType($roaIP) == 4) {
66 | $ipAmount = $ipv4AmountCidrArray[$roaCidr];
67 | } else {
68 | $ipAmount = $ipv6AmountCidrArray[$roaCidr];
69 | }
70 | $endDec = bcsub(bcadd($startDec, $ipAmount), 1);
71 |
72 | $roaInsert .= '("'.$roaIP.'",'.$roaCidr.','.$startDec.','.$endDec.','.$roaAsn.','.$roa->maxLength.','.$mysqlTime.','.$mysqlTime.'),';
73 | }
74 |
75 | $this->info('Processing the insert query');
76 | $roaInsert = rtrim($roaInsert, ',').';';
77 | DB::statement('INSERT INTO roa_table_temp (ip,cidr,ip_dec_start,ip_dec_end,asn,max_length,updated_at,created_at) VALUES '.$roaInsert);
78 |
79 | $this->info('Hot Swapping the ROA list table');
80 | DB::statement('RENAME TABLE roa_table TO backup_roa_table, roa_table_temp TO roa_table;');
81 | DB::statement('DROP TABLE IF EXISTS backup_roa_table');
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/app/Services/Dns.php:
--------------------------------------------------------------------------------
1 | 'nsdname',
18 | 'SOA' => 'rname',
19 | 'A' => 'address',
20 | 'AAAA' => 'address',
21 | 'MX' => 'exchange',
22 | 'TXT' => 'text',
23 | 'CNAME' => 'cname',
24 | // 'PTR' => 'ptrdname', // We take this out as it does not apply for domain
25 | ];
26 |
27 | private $dns;
28 |
29 | public function __construct($resolvers = null, $timeOut = null)
30 | {
31 | $this->dns = new Net_DNS2_Resolver([
32 | 'nameservers' => $resolvers ?: $this->resolvers,
33 | 'timeout' => $timeOut ?: $this->timeout,
34 | ]);
35 | }
36 |
37 | public function getDomainRecords($input, $testNameserver = true)
38 | {
39 | $records = [];
40 | foreach ($this->recordTypes as $type => $key) {
41 | try {
42 | $result = $this->dns->query($input, $type);
43 | foreach($result->answer as $record)
44 | {
45 |
46 | if (isset($record->$key) !== true) {
47 | // If there is no SOA lets return nothing
48 | if ($type === 'NS' && $testNameserver == true) {
49 | return [];
50 | }
51 | continue;
52 | }
53 |
54 | if (is_array($record->$key) === true) {
55 | $data = array_values($record->$key)[0];
56 | } else {
57 | $data = $record->$key;
58 | }
59 |
60 | $records[$type][] = $data;
61 | }
62 | } catch(Net_DNS2_Exception $e) {
63 |
64 | // If there is no SOA lets return nothing
65 | if ($type === 'NS' && $testNameserver == true) {
66 | return [];
67 | }
68 |
69 | continue;
70 | }
71 | }
72 |
73 | return $records;
74 | }
75 |
76 | public function getPtr($ip)
77 | {
78 | if(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === $ip) {
79 | $parts = explode( '.', $ip );
80 | $arpa = sprintf( '%d.%d.%d.%d.in-addr.arpa.', $parts[3], $parts[2], $parts[1], $parts[0] );
81 | } else if(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === $ip) {
82 | $addr = inet_pton($ip);
83 | $unpack = unpack('H*hex', $addr);
84 | $hex = $unpack['hex'];
85 | $arpa = implode('.', array_reverse(str_split($hex))) . '.ip6.arpa.';
86 | } else {
87 | return null;
88 | }
89 |
90 | try {
91 | $result = $this->dns->query($arpa, 'PTR');
92 | foreach($result->answer as $record)
93 | {
94 | return $record->ptrdname;
95 | }
96 | } catch(\Exception $e) {
97 |
98 | }
99 |
100 | return null;
101 | }
102 |
103 | }
104 |
--------------------------------------------------------------------------------
/app/Jobs/EnterASNs.php:
--------------------------------------------------------------------------------
1 | as_number = $as_number;
31 | $this->rir_id = $rir_id;
32 | $this->peeringDBData = $peeringDBData;
33 | $this->cli = new CLImate();
34 | }
35 |
36 | /**
37 | * Execute the job.
38 | *
39 | * @return void
40 | */
41 | public function handle()
42 | {
43 | $rir_id = $this->rir_id;
44 | $as_number = $this->as_number;
45 |
46 | $this->cli->br()->comment('Looking up and adding: AS' . $as_number);
47 |
48 | $asnWhois = new Whois($as_number);
49 | $parsedWhois = $asnWhois->parse();
50 |
51 | $asn = new ASN();
52 |
53 | // Skip null results
54 | if (is_null($parsedWhois) === true) {
55 |
56 | // Save the null entry
57 | $asn->rir_id = $rir_id;
58 | $asn->asn = $as_number;
59 | $asn->raw_whois = $asnWhois->raw();
60 | $asn->save();
61 |
62 | return;
63 | }
64 |
65 | $asn->rir_id = $rir_id;
66 | $asn->asn = $as_number;
67 | $asn->name = empty($parsedWhois->name) !== true ? $parsedWhois->name : null;
68 | $asn->description_full = count($parsedWhois->description) > 0 ? json_encode($parsedWhois->description) : json_encode([$asn->description]);
69 |
70 | // Insert PeerDB Info if we get any
71 | if ($peerDb = $this->peeringDBData) {
72 | $asn->website = $peerDb->website;
73 | $asn->looking_glass = $peerDb->looking_glass;
74 | $asn->traffic_estimation = $peerDb->info_traffic;
75 | $asn->traffic_ratio = $peerDb->info_ratio;
76 | }
77 |
78 | $asn->counrty_code = $parsedWhois->counrty_code;
79 | $asn->owner_address = json_encode($parsedWhois->address);
80 | $asn->raw_whois = $asnWhois->raw();
81 | $asn->save();
82 |
83 | // Save ASN Emails
84 | foreach ($parsedWhois->emails as $email) {
85 | $asnEmail = new ASNEmail();
86 | $asnEmail->asn_id = $asn->id;
87 | $asnEmail->email_address = $email;
88 |
89 | // Check if its an abuse email
90 | if (in_array($email, $parsedWhois->abuse_emails)) {
91 | $asnEmail->abuse_email = true;
92 | }
93 |
94 | $asnEmail->save();
95 | }
96 |
97 | $this->cli->br()->comment($asn->asn . ' - ' . $asn->description . ' [' . $asn->name . ']');
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/config/logging.php:
--------------------------------------------------------------------------------
1 | env('LOG_CHANNEL', 'stack'),
21 |
22 | /*
23 | |--------------------------------------------------------------------------
24 | | Log Channels
25 | |--------------------------------------------------------------------------
26 | |
27 | | Here you may configure the log channels for your application. Out of
28 | | the box, Laravel uses the Monolog PHP logging library. This gives
29 | | you a variety of powerful log handlers / formatters to utilize.
30 | |
31 | | Available Drivers: "single", "daily", "slack", "syslog",
32 | | "errorlog", "monolog",
33 | | "custom", "stack"
34 | |
35 | */
36 |
37 | 'channels' => [
38 | 'stack' => [
39 | 'driver' => 'stack',
40 | 'channels' => ['single'],
41 | 'ignore_exceptions' => false,
42 | ],
43 |
44 | 'single' => [
45 | 'driver' => 'single',
46 | 'path' => storage_path('logs/laravel.log'),
47 | 'level' => 'debug',
48 | ],
49 |
50 | 'daily' => [
51 | 'driver' => 'daily',
52 | 'path' => storage_path('logs/laravel.log'),
53 | 'level' => 'debug',
54 | 'days' => 14,
55 | ],
56 |
57 | 'slack' => [
58 | 'driver' => 'slack',
59 | 'url' => env('LOG_SLACK_WEBHOOK_URL'),
60 | 'username' => 'Laravel Log',
61 | 'emoji' => ':boom:',
62 | 'level' => 'critical',
63 | ],
64 |
65 | 'papertrail' => [
66 | 'driver' => 'monolog',
67 | 'level' => 'debug',
68 | 'handler' => SyslogUdpHandler::class,
69 | 'handler_with' => [
70 | 'host' => env('PAPERTRAIL_URL'),
71 | 'port' => env('PAPERTRAIL_PORT'),
72 | ],
73 | ],
74 |
75 | 'stderr' => [
76 | 'driver' => 'monolog',
77 | 'handler' => StreamHandler::class,
78 | 'formatter' => env('LOG_STDERR_FORMATTER'),
79 | 'with' => [
80 | 'stream' => 'php://stderr',
81 | ],
82 | ],
83 |
84 | 'syslog' => [
85 | 'driver' => 'syslog',
86 | 'level' => 'debug',
87 | ],
88 |
89 | 'errorlog' => [
90 | 'driver' => 'errorlog',
91 | 'level' => 'debug',
92 | ],
93 |
94 | 'null' => [
95 | 'driver' => 'monolog',
96 | 'handler' => NullHandler::class,
97 | ],
98 |
99 | 'emergency' => [
100 | 'path' => storage_path('logs/laravel.log'),
101 | ],
102 | ],
103 |
104 | ];
105 |
--------------------------------------------------------------------------------
/config/auth.php:
--------------------------------------------------------------------------------
1 | [
17 | 'guard' => 'web',
18 | 'passwords' => 'users',
19 | ],
20 |
21 | /*
22 | |--------------------------------------------------------------------------
23 | | Authentication Guards
24 | |--------------------------------------------------------------------------
25 | |
26 | | Next, you may define every authentication guard for your application.
27 | | Of course, a great default configuration has been defined for you
28 | | here which uses session storage and the Eloquent user provider.
29 | |
30 | | All authentication drivers have a user provider. This defines how the
31 | | users are actually retrieved out of your database or other storage
32 | | mechanisms used by this application to persist your user's data.
33 | |
34 | | Supported: "session", "token"
35 | |
36 | */
37 |
38 | 'guards' => [
39 | 'web' => [
40 | 'driver' => 'session',
41 | 'provider' => 'users',
42 | ],
43 |
44 | 'api' => [
45 | 'driver' => 'token',
46 | 'provider' => 'users',
47 | ],
48 | ],
49 |
50 | /*
51 | |--------------------------------------------------------------------------
52 | | User Providers
53 | |--------------------------------------------------------------------------
54 | |
55 | | All authentication drivers have a user provider. This defines how the
56 | | users are actually retrieved out of your database or other storage
57 | | mechanisms used by this application to persist your user's data.
58 | |
59 | | If you have multiple user tables or models you may configure multiple
60 | | sources which represent each model / table. These sources may then
61 | | be assigned to any extra authentication guards you have defined.
62 | |
63 | | Supported: "database", "eloquent"
64 | |
65 | */
66 |
67 | 'providers' => [
68 | 'users' => [
69 | 'driver' => 'eloquent',
70 | 'model' => App\User::class,
71 | ],
72 |
73 | // 'users' => [
74 | // 'driver' => 'database',
75 | // 'table' => 'users',
76 | // ],
77 | ],
78 |
79 | /*
80 | |--------------------------------------------------------------------------
81 | | Resetting Passwords
82 | |--------------------------------------------------------------------------
83 | |
84 | | Here you may set the options for resetting passwords including the view
85 | | that is your password reset e-mail. You may also set the name of the
86 | | table that maintains all of the reset tokens for your application.
87 | |
88 | | You may specify multiple password reset configurations if you have more
89 | | than one user table or model in the application and you want to have
90 | | separate password reset settings based on the specific user types.
91 | |
92 | | The expire time is the number of minutes that the reset token should be
93 | | considered valid. This security feature keeps tokens short-lived so
94 | | they have less time to be guessed. You may change this as needed.
95 | |
96 | */
97 |
98 | 'passwords' => [
99 | 'users' => [
100 | 'provider' => 'users',
101 | 'email' => 'auth.emails.password',
102 | 'table' => 'password_resets',
103 | 'expire' => 60,
104 | ],
105 | ],
106 |
107 | ];
108 |
--------------------------------------------------------------------------------
/app/Services/BgpParser.php:
--------------------------------------------------------------------------------
1 | true, // AT&T
10 | 174 => true, // CogentCo
11 | 209 => true, // CenturyLink (Qwest)
12 | 3320 => true, // Deutsche Telekom
13 | 3257 => true, // GTT (Tinet)
14 | 3356 => true, // Level3
15 | 3549 => true, // Level3
16 | 1 => true, // Level3
17 | 2914 => true, // NTT (Verio)
18 | 5511 => true, // Orange
19 | 6453 => true, // Tata
20 | 6762 => true, //Sparkle
21 | 12956 => true, // Telefonica
22 | 1299 => true, // TeliaSonera
23 | 701 => true, // Verizon
24 | 702 => true, // Verizon
25 | 703 => true, // Verizon
26 | 2828 => true, // XO
27 | 6461 => true, //Zayo (AboveNet)
28 | 6963 => true, // HE
29 | 3491 => true, // PCCW
30 | 1273 => true, // Vodafone (UK)
31 | 1239 => true, // Sprint
32 | 2497 => true, // Internet Initiative Japan
33 | ];
34 |
35 |
36 | public function parse($input)
37 | {
38 | $input = trim(preg_replace('/\s*{[^)]*}/', '', $input));
39 | $bgpParts = explode('|', $input);
40 |
41 | // Remove AS-SETS
42 | $bgpParts[6] = preg_replace('/s*{[^)]*}/', '', $bgpParts[6]);
43 | // Remove any non numeric chars
44 | $bgpParts[6] = trim(preg_replace('/[^0-9 ]/', '', $bgpParts[6]));
45 | $pathArr = explode(' ', $bgpParts[6]);
46 |
47 | $peers = $this->getPeers($pathArr);
48 | $path = $this->getPath($pathArr);
49 |
50 | $prefixParts = explode('/', $bgpParts[5], 2);
51 |
52 | $bgpPrefixData = new \stdClass();
53 | $bgpPrefixData->prefix = $bgpParts[5];
54 | $bgpPrefixData->ip = filter_var($prefixParts[0], FILTER_VALIDATE_IP) ? $prefixParts[0] : null;
55 | $bgpPrefixData->cidr = $prefixParts[1];
56 | $bgpPrefixData->source = $bgpParts[8];
57 | $bgpPrefixData->asn = end($pathArr);
58 | $bgpPrefixData->upstream_asn = isset($path[1]) ? $path[1] : null; // Second BGP (Ignoring self)
59 | $bgpPrefixData->path_string = implode(' ', $path);
60 | $bgpPrefixData->path = $path;
61 | $bgpPrefixData->peersSet = $peers;
62 |
63 | return $bgpPrefixData;
64 | }
65 |
66 | private function getPath($pathArr)
67 | {
68 | $pathArr = array_unique($pathArr);
69 |
70 | foreach ($pathArr as $key => $asnHop) {
71 | // Since we are dealing with ONLY publicly seen prefixes
72 | // This means that we will need to make sure there is at least
73 | // a single teir one carrier in the prefix
74 | // else... we will disregard the BGP entry completely
75 | if (isset($this->topTeirAsnSet[$asnHop]) === true) {
76 | break;
77 | }
78 |
79 | unset($pathArr[$key]);
80 | }
81 |
82 | return array_reverse($pathArr);
83 | }
84 |
85 | private function getPeers($pathArr)
86 | {
87 | $peers = [];
88 |
89 | if (count($pathArr) < 2) {
90 | return [];
91 | }
92 |
93 | foreach ($pathArr as $key => $asnHop) {
94 | // Lets check if next ASN actually exists
95 | if (isset($pathArr[$key + 1]) === true) {
96 | $peerSet = [$asnHop, $pathArr[$key + 1]];
97 | sort($peerSet);
98 | $peers[] = $peerSet;
99 | }
100 | }
101 |
102 | // Remove any dupe peers
103 | foreach ($peers as $key => $peerSet) {
104 | if ($peerSet[0] === $peerSet[1] || empty($peerSet[0]) || empty($peerSet[1])) {
105 | unset($peers[$key]);
106 | }
107 | }
108 |
109 | return array_values($peers);
110 | }
111 | }
112 |
113 |
--------------------------------------------------------------------------------
/app/Console/Commands/ReindexRIRWhois.php:
--------------------------------------------------------------------------------
1 | bench = new Ubench;
38 | $this->esClient = ClientBuilder::create()->setHosts(config('elasticsearch.hosts'))->build();
39 | $this->versionedIndex = $this->indexName . '_' . time();
40 | $this->ipUtils = new IpUtils();
41 |
42 | }
43 |
44 | public function hotSwapIndices($versionedIndex, $entityIndexName)
45 | {
46 |
47 | $indexExists = $this->esClient->indices()->exists(['index' => $entityIndexName]);
48 | $previousIndexName = null;
49 | $indices = $this->esClient->indices()->getAliases();
50 | foreach ($indices as $indexName => $indexData) {
51 | if (array_key_exists('aliases', $indexData) && isset($indexData['aliases'][$entityIndexName])) {
52 | $previousIndexName = $indexName;
53 | break;
54 | }
55 | }
56 | if ($indexExists === true && $previousIndexName === null) {
57 | $this->esClient->indices()->delete([
58 | 'index' => $entityIndexName,
59 | ]);
60 | $this->esClient->indices()->putAlias([
61 | 'name' => $entityIndexName,
62 | 'index' => $versionedIndex,
63 | ]);
64 | } else {
65 | if ($previousIndexName !== null) {
66 | $this->esClient->indices()->deleteAlias([
67 | 'name' => $entityIndexName,
68 | 'index' => $previousIndexName,
69 | ]);
70 | }
71 | $this->esClient->indices()->putAlias([
72 | 'name' => $entityIndexName,
73 | 'index' => $versionedIndex,
74 | ]);
75 | if ($previousIndexName !== null) {
76 | $this->esClient->indices()->delete([
77 | 'index' => $previousIndexName,
78 | ]);
79 | }
80 | }
81 | }
82 |
83 | public function getContents($url)
84 | {
85 | $ch = curl_init();
86 | curl_setopt($ch, CURLOPT_URL, $url);
87 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
88 | curl_setopt($ch, CURLOPT_NOPROGRESS, false);
89 | curl_setopt($ch, CURLOPT_HEADER, false);
90 | curl_setopt($ch, CURLOPT_TIMEOUT, false);
91 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
92 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
93 | curl_setopt($ch, CURLOPT_ENCODING , "gzip");
94 | $data = curl_exec($ch);
95 | curl_close($ch);
96 | return $data;
97 | }
98 |
99 | public function extractValues($rawData, $key, $first = true)
100 | {
101 | $values = [];
102 | $rawLines = explode("\n", $rawData);
103 | $key = strtolower(trim($key));
104 | foreach ($rawLines as $line) {
105 | $lineParts = explode(":", $line, 2);
106 | if (strtolower(trim($lineParts[0])) === $key) {
107 | $testVal = trim($lineParts[1]);
108 | if (empty($testVal) !== true || $testVal === "0") {
109 | $values[] = trim($lineParts[1]);
110 | }
111 | }
112 | }
113 | if (count($values) > 0) {
114 | return $values[0];
115 | }
116 | return null;
117 | }
118 | }
119 |
--------------------------------------------------------------------------------
/app/Jobs/EnterPrefixes.php:
--------------------------------------------------------------------------------
1 | ipVersion = $ipVersion;
29 | $this->ipPrefix = $ipPrefix;
30 | $this->ipAllocation = $ipAllocation;
31 | $this->ipUtils = new IpUtils();
32 | }
33 |
34 | /**
35 | * Execute the job.
36 | *
37 | * @return void
38 | */
39 | public function handle()
40 | {
41 | $ipPrefix = $this->ipPrefix;
42 | $ipVersion = $this->ipVersion;
43 | $ipAllocation = $this->ipAllocation;
44 |
45 | $ipWhois = new Whois($ipPrefix->ip, $ipPrefix->cidr);
46 | $parsedWhois = $ipWhois->parse();
47 |
48 | $className = 'App\Models\IPv' . $ipVersion . 'PrefixWhois';
49 | $newPrefixWhois = new $className;
50 |
51 | // Skip null results
52 | if (is_null($parsedWhois) === true) {
53 |
54 | // Add them as null record
55 | $newPrefixWhois->ip = $ipPrefix->ip;
56 | $newPrefixWhois->cidr = $ipPrefix->cidr;
57 | $newPrefixWhois->raw_whois = $ipWhois->raw();
58 | $newPrefixWhois->save();
59 |
60 | return;
61 | }
62 |
63 | $newPrefixWhois->rir_id = $ipAllocation->rir_id;
64 | $newPrefixWhois->ip = $ipPrefix->ip;
65 | $newPrefixWhois->cidr = $ipPrefix->cidr;
66 |
67 | $newPrefixWhois->ip_dec_start = $this->ipUtils->ip2dec($newPrefixWhois->ip);
68 | if ($this->ipUtils->getInputType($newPrefixWhois->ip) === 4) {
69 | $ipv4Cidrs = $this->ipUtils->IPv4cidrIpCount();
70 | $ipCount = $ipv4Cidrs[$newPrefixWhois->cidr];
71 | } else {
72 | $ipv6Cidrs = $this->ipUtils->IPv6cidrIpCount();
73 | $ipCount = $ipv6Cidrs[$newPrefixWhois->cidr];
74 | }
75 | $newPrefixWhois->ip_dec_end = bcsub(bcadd($ipCount, $newPrefixWhois->ip_dec_start), 1);
76 |
77 | $newPrefixWhois->parent_ip = $ipAllocation->ip;
78 | $newPrefixWhois->parent_cidr = $ipAllocation->cidr;
79 | $newPrefixWhois->name = $parsedWhois->name;
80 | $newPrefixWhois->description_full = json_encode($parsedWhois->description);
81 | $newPrefixWhois->counrty_code = $parsedWhois->counrty_code;
82 | $newPrefixWhois->owner_address = json_encode($parsedWhois->address);
83 | $newPrefixWhois->raw_whois = $ipWhois->raw();
84 |
85 | $newPrefixWhois->save();
86 |
87 | // Save Prefix Emails
88 | foreach ($parsedWhois->emails as $email) {
89 | $className = 'App\Models\IPv' . $ipVersion . 'PrefixWhoisEmail';
90 | $prefixEmail = new $className;
91 | $prefixEmail->prefix_whois_id = $newPrefixWhois->id;
92 | $prefixEmail->email_address = $email;
93 |
94 | // Check if its an abuse email
95 | if (in_array($email, $parsedWhois->abuse_emails)) {
96 | $prefixEmail->abuse_email = true;
97 | }
98 |
99 | $prefixEmail->save();
100 | }
101 |
102 | dump([
103 | 'prefix' => $newPrefixWhois->ip . '/' . $newPrefixWhois->cidr,
104 | 'name' => $newPrefixWhois->name,
105 | 'description' => $newPrefixWhois->description,
106 | 'description_full' => $newPrefixWhois->description_full,
107 | 'counrty_code' => $newPrefixWhois->counrty_code,
108 | 'owner_address' => $newPrefixWhois->owner_address,
109 | ]);
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/scripts/update_bgp_ribs.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # Needs AXEL and unix system
4 |
5 | rm -f ./storage/bgp_lines.txt;
6 | touch ./storage/bgp_lines.txt;
7 | rm -f ./storage/temp_rib_*;
8 |
9 | function process_rib {
10 | response=$(curl --write-out %{http_code} --silent --output /dev/null -I $1)
11 | echo "Curl Response: $response"
12 | if [ "200" == $response ]; then
13 | random_name=$RANDOM
14 | filename=$1
15 | extension="${filename##*.}"
16 | $2 ./storage/temp_rib_$random_name.$extension $1;
17 | ./scripts/bgpdump -m ./storage/temp_rib_${random_name}.${extension} >> ./storage/${random_name}_bgp_out.txt
18 | rm -f ./storage/temp_rib_$random_name.$extension;
19 | fi
20 | }
21 |
22 | ###############################################################################################
23 |
24 | # IPv4 RouteViews
25 | BASE_URL="archive.routeviews.org/bgpdata";
26 | RIB_FOLDER=`curl ftp://$BASE_URL/ | tail -1 | awk '{print $(NF)}'`
27 | RIB_FILE=`curl ftp://$BASE_URL/$RIB_FOLDER/RIBS/ | tail -1 | awk '{print $(NF)}'`
28 | if [ -z "$RIB_FILE" ]
29 | then
30 | RIB_FOLDER=`curl ftp://$BASE_URL/ | tail -2 | head -1 | awk '{print $(NF)}'`
31 | RIB_FILE=`curl ftp://$BASE_URL/$RIB_FOLDER/RIBS/ | tail -1 | awk '{print $(NF)}'`
32 | fi
33 | process_rib $BASE_URL/$RIB_FOLDER/RIBS/$RIB_FILE "wget -6 -O" &
34 |
35 | # IPv6 RouteViews
36 | BASE_URL="archive.routeviews.org/route-views6/bgpdata";
37 | RIB_FOLDER=`curl ftp://$BASE_URL/ | tail -1 | awk '{print $(NF)}'`
38 | RIB_FILE=`curl ftp://$BASE_URL/$RIB_FOLDER/RIBS/ | tail -1 | awk '{print $(NF)}'`
39 | if [ -z "$RIB_FILE" ]
40 | then
41 | RIB_FOLDER=`curl ftp://$BASE_URL/ | tail -2 | head -1 | awk '{print $(NF)}'`
42 | RIB_FILE=`curl ftp://$BASE_URL/$RIB_FOLDER/RIBS/ | tail -1 | awk '{print $(NF)}'`
43 | fi
44 | process_rib $BASE_URL/$RIB_FOLDER/RIBS/$RIB_FILE "wget -6 -O" &
45 |
46 |
47 |
48 | ###############################################################################################
49 |
50 | process_rib http://data.ris.ripe.net/rrc00/latest-bview.gz "axel -o" &
51 | process_rib http://data.ris.ripe.net/rrc01/latest-bview.gz "axel -o" &
52 | # process_rib http://data.ris.ripe.net/rrc02/latest-bview.gz # Outdated and not used anymore
53 | process_rib http://data.ris.ripe.net/rrc03/latest-bview.gz "axel -o" &
54 | process_rib http://data.ris.ripe.net/rrc04/latest-bview.gz "axel -o" &
55 | process_rib http://data.ris.ripe.net/rrc05/latest-bview.gz "axel -o" &
56 | process_rib http://data.ris.ripe.net/rrc06/latest-bview.gz "axel -o" &
57 | process_rib http://data.ris.ripe.net/rrc07/latest-bview.gz "axel -o" &
58 | # process_rib http://data.ris.ripe.net/rrc08/latest-bview.gz # Outdated and not used anymore
59 | # process_rib http://data.ris.ripe.net/rrc09/latest-bview.gz # Outdated and not used anymore
60 | process_rib http://data.ris.ripe.net/rrc10/latest-bview.gz "axel -o" &
61 | process_rib http://data.ris.ripe.net/rrc11/latest-bview.gz "axel -o" &
62 | process_rib http://data.ris.ripe.net/rrc12/latest-bview.gz "axel -o" &
63 | process_rib http://data.ris.ripe.net/rrc13/latest-bview.gz "axel -o" &
64 | process_rib http://data.ris.ripe.net/rrc14/latest-bview.gz "axel -o" &
65 | process_rib http://data.ris.ripe.net/rrc15/latest-bview.gz "axel -o" &
66 | process_rib http://data.ris.ripe.net/rrc16/latest-bview.gz "axel -o" &
67 | process_rib http://data.ris.ripe.net/rrc18/latest-bview.gz "axel -o" &
68 | process_rib http://data.ris.ripe.net/rrc19/latest-bview.gz "axel -o" &
69 | process_rib http://data.ris.ripe.net/rrc20/latest-bview.gz "axel -o" &
70 | process_rib http://data.ris.ripe.net/rrc21/latest-bview.gz "axel -o" &
71 | process_rib http://data.ris.ripe.net/rrc22/latest-bview.gz "axel -o" &
72 | process_rib http://data.ris.ripe.net/rrc23/latest-bview.gz "axel -o" &
73 | ###############################################################################################
74 |
75 | sleep 5
76 |
77 | while pgrep -x "wget|axel|bgpdump" > /dev/null;
78 | do
79 | sleep 3
80 | done
81 |
82 | # Combine all output RIB files into the single file
83 | echo "Combining all the output BGP files into one..."
84 | cat ./storage/*_bgp_out.txt > ./storage/bgp_lines.txt
85 | rm -f ./storage/*_bgp_out.txt
86 |
87 | ./scripts/go-bgpparse -bgp_file=/var/www/api.bgpview.io/storage/bgp_lines.txt -db_name=XXXXXXXX -db_user=XXXXXX -db_pass=XXXXXXXXX -bulk_insert=20000 -bulk_insert_es=20000
88 |
89 | exit 0
90 |
--------------------------------------------------------------------------------
/config/mail.php:
--------------------------------------------------------------------------------
1 | env('MAIL_DRIVER', 'smtp'),
19 |
20 | /*
21 | |--------------------------------------------------------------------------
22 | | SMTP Host Address
23 | |--------------------------------------------------------------------------
24 | |
25 | | Here you may provide the host address of the SMTP server used by your
26 | | applications. A default option is provided that is compatible with
27 | | the Mailgun mail service which will provide reliable deliveries.
28 | |
29 | */
30 |
31 | 'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
32 |
33 | /*
34 | |--------------------------------------------------------------------------
35 | | SMTP Host Port
36 | |--------------------------------------------------------------------------
37 | |
38 | | This is the SMTP port used by your application to deliver e-mails to
39 | | users of the application. Like the host we have set this value to
40 | | stay compatible with the Mailgun e-mail application by default.
41 | |
42 | */
43 |
44 | 'port' => env('MAIL_PORT', 587),
45 |
46 | /*
47 | |--------------------------------------------------------------------------
48 | | Global "From" Address
49 | |--------------------------------------------------------------------------
50 | |
51 | | You may wish for all e-mails sent by your application to be sent from
52 | | the same address. Here, you may specify a name and address that is
53 | | used globally for all e-mails that are sent by your application.
54 | |
55 | */
56 |
57 | 'from' => ['address' => env('MAIL_FROM_ADDRESS'), 'name' => env('MAIL_FROM_NAME')],
58 |
59 | /*
60 | |--------------------------------------------------------------------------
61 | | E-Mail Encryption Protocol
62 | |--------------------------------------------------------------------------
63 | |
64 | | Here you may specify the encryption protocol that should be used when
65 | | the application send e-mail messages. A sensible default using the
66 | | transport layer security protocol should provide great security.
67 | |
68 | */
69 |
70 | 'encryption' => env('MAIL_ENCRYPTION', 'tls'),
71 |
72 | /*
73 | |--------------------------------------------------------------------------
74 | | SMTP Server Username
75 | |--------------------------------------------------------------------------
76 | |
77 | | If your SMTP server requires a username for authentication, you should
78 | | set it here. This will get used to authenticate with your server on
79 | | connection. You may also set the "password" value below this one.
80 | |
81 | */
82 |
83 | 'username' => env('MAIL_USERNAME'),
84 |
85 | /*
86 | |--------------------------------------------------------------------------
87 | | SMTP Server Password
88 | |--------------------------------------------------------------------------
89 | |
90 | | Here you may set the password required by your SMTP server to send out
91 | | messages from your application. This will be given to the server on
92 | | connection so that the application will be able to send messages.
93 | |
94 | */
95 |
96 | 'password' => env('MAIL_PASSWORD'),
97 |
98 | /*
99 | |--------------------------------------------------------------------------
100 | | Sendmail System Path
101 | |--------------------------------------------------------------------------
102 | |
103 | | When using the "sendmail" driver to send e-mails, we will need to know
104 | | the path to where Sendmail lives on this server. A default path has
105 | | been provided here, which will work well on most of your systems.
106 | |
107 | */
108 |
109 | 'sendmail' => '/usr/sbin/sendmail -bs',
110 |
111 | ];
112 |
--------------------------------------------------------------------------------
/app/Jobs/ReindexES.php:
--------------------------------------------------------------------------------
1 | cli = new CLImate();
32 | }
33 |
34 | /**
35 | * Execute the job.
36 | *
37 | * @return void
38 | */
39 | public function handle()
40 | {
41 | $this->reindexClass('ix', IX::class, $withRelated = false);
42 | $this->reindexClass('asn', ASN::class);
43 | $this->reindexClass('ipv6', IPv6PrefixWhois::class);
44 | $this->reindexClass('ipv4', IPv4PrefixWhois::class);
45 |
46 | }
47 |
48 | private function reindexClass($name, $class, $withRelated = true)
49 | {
50 | // Setting a brand new index name
51 | $originalIndex = config('elasticquent.default_index');
52 | $entityIndexName = config('elasticquent.default_index'). '_' . $name;
53 | $versionedIndex = $entityIndexName . '_' . time();
54 | Config::set('elasticquent.default_index', $versionedIndex);
55 |
56 | $class::createIndex();
57 |
58 | $class::putMapping($ignoreConflicts = true);
59 |
60 | $this->cli->comment('=====================================');
61 | $this->cli->comment('Getting total count for ' . $class);
62 | $total = $class::count();
63 | $this->cli->comment('Total: ' . number_format($total));
64 | $batches = floor($total / $this->batchAmount);
65 | $this->cli->comment('Batch Count: ' . $batches);
66 |
67 | for ($i = 0; $i <= $batches; $i++) {
68 | $this->cli->comment('Indexing Batch number ' . $i . ' on ' . $class);
69 |
70 | if ($withRelated === true) {
71 | $class::with('emails')->with('rir')->offset($i * $this->batchAmount)->limit($this->batchAmount)->get()->addToIndex();
72 | } else {
73 | $class::offset($i * $this->batchAmount)->limit($this->batchAmount)->get()->addToIndex();
74 | }
75 | }
76 |
77 | $this->hotSwapIndices($versionedIndex, $entityIndexName);
78 |
79 | Config::set('elasticquent.default_index', $originalIndex);
80 |
81 | }
82 |
83 | private function hotSwapIndices($versionedIndex, $entityIndexName)
84 | {
85 | $client = ClientBuilder::create()->setHosts(config('elasticquent.config.hosts'))->build();
86 |
87 | $indexExists = $client->indices()->exists(['index' => $entityIndexName]);
88 | $previousIndexName = null;
89 | $indices = $client->indices()->getAliases();
90 |
91 | foreach ($indices as $indexName => $indexData) {
92 | if (array_key_exists('aliases', $indexData) && isset($indexData['aliases'][$entityIndexName])) {
93 | $previousIndexName = $indexName;
94 | break;
95 | }
96 | }
97 |
98 | if ($indexExists === true && $previousIndexName === null) {
99 | $client->indices()->delete([
100 | 'index' => $entityIndexName,
101 | ]);
102 |
103 | $client->indices()->putAlias([
104 | 'name' => $entityIndexName,
105 | 'index' => $versionedIndex,
106 | ]);
107 | } else {
108 | if ($previousIndexName !== null) {
109 | $client->indices()->deleteAlias([
110 | 'name' => $entityIndexName,
111 | 'index' => $previousIndexName,
112 | ]);
113 | }
114 | $client->indices()->putAlias([
115 | 'name' => $entityIndexName,
116 | 'index' => $versionedIndex,
117 | ]);
118 |
119 | if ($previousIndexName !== null) {
120 | $client->indices()->delete([
121 | 'index' => $previousIndexName,
122 | ]);
123 | }
124 | }
125 | }
126 | }
127 |
--------------------------------------------------------------------------------
/app/Http/Controllers/ApiBaseController.php:
--------------------------------------------------------------------------------
1 | dns = $dns;
26 | $this->ipUtils = $ipUtils;
27 | $this->_startTime = microtime(true) * 1000;
28 |
29 | $url = \Illuminate\Support\Facades\Request::fullUrl();
30 | if ($data = Cache::get($url)) {
31 | return $this->respond($data);
32 | }
33 | }
34 |
35 | //returns load time in MiliSeconds
36 | private function getLoadTime($string_fromat = true) {
37 | $time = microtime(true) * 1000;
38 | $load_time = round(($time - $this->_startTime), 2);
39 | return $string_fromat ? $load_time . " ms" : $load_time;
40 | }
41 |
42 | public function makeStatus($message = 'Query was successful', $status = true) {
43 | $data['status'] = $status ? 'ok' : 'error';
44 | $data['status_message'] = $message;
45 | return $data;
46 | }
47 |
48 | public function respond($data, $code = 200)
49 | {
50 | $data['@meta']['time_zone'] = Config::get('app.timezone');
51 | $data['@meta']['api_version'] = 1;
52 | $data['@meta']['execution_time'] = $this->getLoadTime();
53 |
54 | return $data;
55 | }
56 |
57 | public function sendData($data_array)
58 | {
59 | $data = $this->makeStatus();
60 | $data['data'] = $data_array;
61 |
62 | // Set the data to cache
63 | $url = \Illuminate\Support\Facades\Request::fullUrl();
64 | Cache::put($url, $data, 15 * 60);
65 |
66 | return $this->respond($data);
67 | }
68 |
69 | /**
70 | * generates a random timecoded uuid
71 | *
72 | * @return string
73 | */
74 | public function generate_uuid()
75 | {
76 | return sprintf('%04x%04x%04x%04x%04x%04x%04x%04x',
77 |
78 | // 32 bits for "time_low"
79 | mt_rand(0, 0xffff), mt_rand(0, 0xffff),
80 |
81 | // 16 bits for "time_mid"
82 | mt_rand(0, 0xffff),
83 |
84 | // 16 bits for "time_hi_and_version",
85 | // four most significant bits holds version number 4
86 | mt_rand(0, 0x0fff) | 0x4000,
87 |
88 | // 16 bits, 8 bits for "clk_seq_hi_res",
89 | // 8 bits for "clk_seq_low",
90 | // two most significant bits holds zero and one for variant DCE1.1
91 | mt_rand(0, 0x3fff) | 0x8000,
92 |
93 | // 48 bits for "node"
94 | mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
95 | );
96 | }
97 |
98 |
99 | public function registerApplication(Request $request)
100 | {
101 | if ($request->isMethod('post') === true) {
102 | $validator = Validator::make($request->all(), [
103 | 'name' => 'required|max:255',
104 | 'email' => 'required|email|unique:api_applications',
105 | 'usage' => 'required|min:5',
106 | ]);
107 |
108 | if ($validator->fails()) {
109 | return redirect('register-application')
110 | ->withErrors($validator)
111 | ->withInput();
112 | }
113 |
114 | $key = $this->generate_uuid();
115 | $application = new ApiApplication();
116 | $application->name = $request->input('name');
117 | $application->email = $request->input('email');
118 | $application->use = $request->input('usage');
119 | $application->key = $key;
120 | $application->save();
121 |
122 | Mail::send('api.email', ['key' => $application->key], function ($message) use ($application) {
123 | $message->from(config('mail.from.address'), config('mail.from.name'));
124 | $message->to($application->email);
125 | $message->subject('BGP API Key');
126 | });
127 |
128 | return view('api.register-application-done');
129 | }
130 |
131 |
132 | return view('api.register-application');
133 | }
134 | }
135 |
--------------------------------------------------------------------------------
/scripts/parse_as42.php:
--------------------------------------------------------------------------------
1 | $val) {
11 | $ch[$key] = curl_init();
12 | curl_setopt($ch[$key], CURLOPT_URL, $val);
13 | curl_setopt($ch[$key], CURLOPT_HEADER, 0);
14 | curl_setopt($ch[$key], CURLOPT_RETURNTRANSFER, 1);
15 | curl_setopt($ch[$key], CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/602.4.8 (KHTML, like Gecko) Version/10.0.3 Safari/602.4.8");
16 | curl_setopt($ch[$key], CURLOPT_CONNECTTIMEOUT, 60);
17 | curl_setopt($ch[$key], CURLOPT_TIMEOUT, 60);
18 | curl_setopt($ch[$key], CURLOPT_FOLLOWLOCATION, true);
19 | curl_multi_add_handle($mh, $ch[$key]);
20 | }
21 | $running = 1;
22 | do {
23 | curl_multi_exec($mh, $running);
24 | curl_multi_select($mh);
25 | } while ($running > 0);
26 | foreach ($ch as $key => $val) {
27 | $results[curl_getinfo($val, CURLINFO_EFFECTIVE_URL)] = curl_multi_getcontent($val);
28 | curl_multi_remove_handle($mh, $val);
29 | }
30 | curl_multi_close($mh);
31 | return $results;
32 | }
33 |
34 | function getLatestBaseUrl($ipVersion = 4)
35 | {
36 | $regexYear = "| (\d+)|Usi";
37 | $regexMonth = "| (\d+)|Usi";
38 | $baseYear = "https://www.pch.net/resources/Routing_Data/IPv" . $ipVersion . "_daily_snapshots/";
39 |
40 | $str = file_get_contents($baseYear);
41 | $matches = array();
42 | $i = preg_match_all($regexYear, $str, $matches);
43 | if (isset($matches[1])) {
44 | $year = $matches[1];
45 | rsort($year);
46 | $year = $year[0];
47 | $baseMonth = $baseYear . $year . "/";
48 | $str = file_get_contents($baseMonth);
49 | $matches = array();
50 | $i = preg_match_all($regexMonth, $str, $matches);
51 | if (isset($matches[1])) {
52 | $month = $matches[1];
53 | rsort($month);
54 | $month = $month[0];
55 | } else {
56 | die("unable to fetch month\n");
57 | }
58 | } else {
59 | die("unable to fetch year\n");
60 | }
61 | return $baseYear . $year . "/" . $month . "/";
62 | }
63 |
64 | $dumpUrls = [];
65 | $threadnum = 10;
66 | $reqexFolder = "| (?:[a-zA-Z0-9\-\.\/]+)|Usi";
67 | $reqexFile = "| ([a-zA-Z0-9\-\_\.\/]+)|Usi";
68 |
69 | foreach ([4, 6] as $ipVersions) {
70 | $baseUrl = getLatestBaseUrl($ipVersions);
71 |
72 | $str = file_get_contents($baseUrl);
73 |
74 | $matches = array();
75 | $i = preg_match_all($reqexFolder, $str, $matches);
76 | if ((isset($matches[1])) && (count($matches[1]) > 0)) {
77 | $i = 0;
78 | $j = 0;
79 | while ($i <= count($matches[1])) {
80 | $urls = array();
81 | for ($j = 0; $j < $threadnum; $j++) {
82 | if (isset($matches[1][$i])) {
83 | array_push($urls, $baseUrl . $matches[1][$i]);
84 | }
85 |
86 | $i++;
87 | }
88 | $pages = fetchMulti($urls);
89 | foreach ($pages as $url => $contents) {
90 | $fileUrls = preg_match_all($reqexFile, $contents, $files);
91 | if (isset($files[1])) {
92 | rsort($files[1]);
93 |
94 | $finalUrl = $url . $files[1][0];
95 | $finalUrlParts = explode(date('Y'), $finalUrl);
96 | $date = date('Y') . str_replace('.gz', '', end($finalUrlParts));
97 | $fileTime = strtotime(str_replace('.', '-', $date));
98 |
99 | // Only add the file if we are dealing with dates are in last 24 hours
100 | if ($fileTime > 0 && (time() - 86400) < $fileTime) {
101 | $dumpUrls[] = [
102 | 'url' => $finalUrl,
103 | 'date' => $date,
104 | 'name' => $files[1][0],
105 | ];
106 | }
107 |
108 | }
109 | }
110 | }
111 | }
112 | }
113 |
114 | foreach ($dumpUrls as $dumpUrl) {
115 | // read raw file
116 | $fileContent = gzdecode(file_get_contents($dumpUrl['url']));
117 |
118 | // Make temp file
119 | $tempFile = tempnam(sys_get_temp_dir(), 'pch_dump');
120 |
121 | file_put_contents($tempFile, $fileContent);
122 |
123 | exec('cat '.$tempFile .' | awk -fscripts/pch.awk', $outputLines);
124 |
125 | // Delete file
126 | unlink($tempFile);
127 |
128 | $outputLines = array_unique($outputLines);
129 | foreach ($outputLines as $outputLine) {
130 | echo $outputLine.PHP_EOL;
131 | }
132 | }
133 |
--------------------------------------------------------------------------------
/config/database.php:
--------------------------------------------------------------------------------
1 | PDO::FETCH_CLASS,
17 |
18 | /*
19 | |--------------------------------------------------------------------------
20 | | Default Database Connection Name
21 | |--------------------------------------------------------------------------
22 | |
23 | | Here you may specify which of the database connections below you wish
24 | | to use as your default connection for all database work. Of course
25 | | you may use many connections at once using the Database library.
26 | |
27 | */
28 |
29 | 'default' => env('DB_CONNECTION', 'mysql'),
30 |
31 | /*
32 | |--------------------------------------------------------------------------
33 | | Database Connections
34 | |--------------------------------------------------------------------------
35 | |
36 | | Here are each of the database connections setup for your application.
37 | | Of course, examples of configuring each database platform that is
38 | | supported by Laravel is shown below to make development simple.
39 | |
40 | |
41 | | All database work in Laravel is done through the PHP PDO facilities
42 | | so make sure you have the driver for your particular database of
43 | | choice installed on your machine before you begin development.
44 | |
45 | */
46 |
47 | 'connections' => [
48 |
49 | 'sqlite' => [
50 | 'driver' => 'sqlite',
51 | 'database' => database_path('database.sqlite'),
52 | 'prefix' => '',
53 | ],
54 |
55 | 'mysql' => [
56 | 'driver' => 'mysql',
57 | 'host' => env('DB_HOST', 'localhost'),
58 | 'database' => env('DB_DATABASE', 'forge'),
59 | 'username' => env('DB_USERNAME', 'forge'),
60 | 'password' => env('DB_PASSWORD', ''),
61 | 'charset' => 'utf8',
62 | 'collation' => 'utf8_unicode_ci',
63 | 'prefix' => '',
64 | 'strict' => false,
65 | ],
66 |
67 | 'pgsql' => [
68 | 'driver' => 'pgsql',
69 | 'host' => env('DB_HOST', 'localhost'),
70 | 'database' => env('DB_DATABASE', 'forge'),
71 | 'username' => env('DB_USERNAME', 'forge'),
72 | 'password' => env('DB_PASSWORD', ''),
73 | 'charset' => 'utf8',
74 | 'prefix' => '',
75 | 'schema' => 'public',
76 | ],
77 |
78 | 'sqlsrv' => [
79 | 'driver' => 'sqlsrv',
80 | 'host' => env('DB_HOST', 'localhost'),
81 | 'database' => env('DB_DATABASE', 'forge'),
82 | 'username' => env('DB_USERNAME', 'forge'),
83 | 'password' => env('DB_PASSWORD', ''),
84 | 'charset' => 'utf8',
85 | 'prefix' => '',
86 | ],
87 |
88 | 'mongodb' => [
89 | 'driver' => 'mongodb',
90 | 'host' => env('DB_HOST', 'localhost'),
91 | 'port' => env('DB_PORT', 27017),
92 | 'database' => env('MONGO_DATABASE'),
93 | 'username' => env('MONGO_USERNAME'),
94 | 'password' => env('MONGO_PASSWORD'),
95 | 'options' => [
96 | 'db' => 'admin' // sets the authentication database required by mongo 3
97 | ]
98 | ],
99 |
100 | ],
101 |
102 | /*
103 | |--------------------------------------------------------------------------
104 | | Migration Repository Table
105 | |--------------------------------------------------------------------------
106 | |
107 | | This table keeps track of all the migrations that have already run for
108 | | your application. Using this information, we can determine which of
109 | | the migrations on disk haven't actually been run in the database.
110 | |
111 | */
112 |
113 | 'migrations' => 'migrations',
114 |
115 | /*
116 | |--------------------------------------------------------------------------
117 | | Redis Databases
118 | |--------------------------------------------------------------------------
119 | |
120 | | Redis is an open source, fast, and advanced key-value store that also
121 | | provides a richer set of commands than a typical key-value systems
122 | | such as APC or Memcached. Laravel makes it easy to dig right in.
123 | |
124 | */
125 |
126 | 'redis' => [
127 |
128 | 'cluster' => false,
129 |
130 | 'default' => [
131 | 'host' => env('REDIS_HOST', 'localhost'),
132 | 'password' => env('REDIS_PASSWORD', null),
133 | 'port' => env('REDIS_PORT', 6379),
134 | 'database' => 0,
135 | ],
136 |
137 | ],
138 |
139 | ];
140 |
--------------------------------------------------------------------------------
/app/Console/Commands/UpdateASNWhoisInfo.php:
--------------------------------------------------------------------------------
1 | cli = $cli;
51 | $this->ipUtils = $ipUtils;
52 | $this->esClient = ClientBuilder::create()->setHosts(config('elasticsearch.hosts'))->build();
53 | }
54 |
55 | /**
56 | * Execute the console command.
57 | *
58 | * @return mixed
59 | */
60 | public function handle()
61 | {
62 | $this->loadPeeringDB();
63 | $this->updateASN();
64 | }
65 |
66 | private function loadPeeringDB()
67 | {
68 | $this->cli->br()->comment('Downloading the Peeringhub DB...')->br();
69 |
70 | $ch = curl_init();
71 | curl_setopt($ch, CURLOPT_URL, $this->peeringdb_url);
72 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
73 | curl_setopt($ch, CURLOPT_NOPROGRESS, false);
74 | curl_setopt($ch, CURLOPT_HEADER, false);
75 | curl_setopt($ch, CURLOPT_TIMEOUT, false);
76 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
77 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
78 | curl_setopt($ch, CURLOPT_ENCODING, "gzip");
79 |
80 | if (defined('CURLOPT_IPRESOLVE') && defined('CURL_IPRESOLVE_V4')) {
81 | curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
82 | }
83 |
84 | $peeringDB = curl_exec($ch);
85 | curl_close($ch);
86 |
87 | $this->peeringDBData = json_decode($peeringDB)->data;
88 | }
89 |
90 | private function getPeeringDbInfo($asn)
91 | {
92 | foreach ($this->peeringDBData as $data) {
93 | if ($data->asn === $asn) {
94 | foreach ($data as $key => $value) {
95 | if (empty($value) === true) {
96 | $data->$key = null;
97 | }
98 | }
99 | return $data;
100 | }
101 | }
102 | return null;
103 | }
104 |
105 | private function getAllAsns()
106 | {
107 |
108 | $allocatedAsns = $this->ipUtils->getAllocatedAsns();
109 | $bgpAsns = $this->ipUtils->getBgpAsns();
110 |
111 | $sourceAsns['allocated_asns'] = $allocatedAsns->shuffle();
112 | $sourceAsns['bgp_asns'] = $bgpAsns->shuffle();
113 | $sourceAsns['ix_asns'] = IXMember::all()->shuffle();
114 |
115 | return $sourceAsns;
116 | }
117 |
118 | private function updateASN()
119 | {
120 | $this->cli->br()->comment('===================================================');
121 | $this->cli->br()->comment('Adding newly allocated ASNs to queue')->br();
122 |
123 | $sourceAsns = $this->getAllAsns();
124 |
125 | $asns = [];
126 | foreach ($sourceAsns as $sourceAsn) {
127 | foreach ($sourceAsn as $asnObj) {
128 | if (isset($asns[$asnObj->asn]) === false) {
129 | $asns[$asnObj->asn] = isset($asnObj->rir_id) ? $asnObj->rir_id : null;
130 | }
131 | }
132 | }
133 |
134 | $seenAsns = DB::table('asns')->pluck('asn')->toArray();
135 | $seenAsns = array_flip($seenAsns);
136 |
137 | foreach ($asns as $as_number => $rir_id) {
138 | // Lets check if the ASN has already been looked at in the past
139 | if (isset($seenAsns[$as_number]) !== true) {
140 | // Dispatch a new job into queue
141 | $this->dispatch(new EnterASNs($as_number, $rir_id, $this->getPeeringDbInfo($as_number)));
142 | }
143 | }
144 |
145 | // Ok, now that we are done with new allocations, lets update the old records
146 | $oldAsns = ASN::where('updated_at', '<', Carbon::now()->subWeek())->orderBy('updated_at', 'ASC')->limit(8000)->get();
147 | $oldAsns->shuffle();
148 |
149 | foreach ($oldAsns as $oldAsn) {
150 | $this->dispatch(new UpdateASNs($oldAsn, $this->getPeeringDbInfo($oldAsn->asn)));
151 |
152 | }
153 |
154 | }
155 | }
156 |
--------------------------------------------------------------------------------
/app/Models/IPv6PrefixWhois.php:
--------------------------------------------------------------------------------
1 | [
19 | 'analyzer' => [
20 | 'string_lowercase' => [
21 | 'tokenizer' => 'keyword',
22 | 'filter' => [ 'asciifolding', 'lowercase', 'custom_replace' ],
23 | ],
24 | ],
25 | 'filter' => [
26 | 'custom_replace' => [
27 | 'type' => 'pattern_replace',
28 | 'pattern' => "[^a-z0-9 ]",
29 | 'replacement' => "",
30 | ],
31 | ],
32 | ],
33 | ];
34 |
35 | /**
36 | * The elasticsearch mappings.
37 | *
38 | * @var array
39 | */
40 | protected $mappingProperties = [
41 | 'ip' => [
42 | 'type' => 'keyword',
43 | 'index' => true,
44 | ],
45 | 'name' => [
46 | 'type' => 'text',
47 | 'analyzer' => 'string_lowercase',
48 | 'fielddata' => true,
49 | ],
50 | 'description' => [
51 | 'type' => 'text',
52 | 'analyzer' => 'string_lowercase',
53 | 'fielddata' => true,
54 | ],
55 | ];
56 |
57 | /**
58 | * The database table used by the model.
59 | *
60 | * @var string
61 | */
62 | protected $table = 'ipv6_prefix_whois';
63 |
64 | /**
65 | * The attributes excluded from the model's JSON form.
66 | *
67 | * @var array
68 | */
69 | protected $hidden = ['id', 'rir_id', 'bgp_prefix_id', 'raw_whois', 'created_at', 'updated_at', 'ip_dec_start', 'ip_dec_end'];
70 |
71 |
72 | public function getIndexName()
73 | {
74 | if (substr_count(config('elasticquent.default_index'), '_') > 1) {
75 | return config('elasticquent.default_index');
76 | }
77 |
78 | return config('elasticquent.default_index'). '_ipv6';
79 | }
80 |
81 | public function rir()
82 | {
83 | return $this->belongsTo('App\Models\Rir');
84 | }
85 |
86 | public function emails()
87 | {
88 | return $this->hasMany('App\Models\IPv6PrefixWhoisEmail', 'prefix_whois_id', 'id');
89 | }
90 |
91 | public function bgpPrefix()
92 | {
93 | return $this->belongsTo('App\Models\IPv6BgpPrefix', 'bgp_prefix_id', 'id');
94 | }
95 |
96 | public function getDescriptionAttribute()
97 | {
98 | $descriptionLines = $this->description_full;
99 | if (is_null($descriptionLines) !== true) {
100 | foreach ($descriptionLines as $descriptionLine) {
101 | if (preg_match("/[A-Za-z0-9]/i", $descriptionLine)) {
102 | return $descriptionLine;
103 | }
104 | }
105 | }
106 |
107 | return $this->name;
108 | }
109 |
110 | public function getDescriptionFullAttribute($value)
111 | {
112 | if (is_null($value) === true) {
113 | return [];
114 | }
115 |
116 | if (is_string($value) !== true) {
117 | return $value;
118 | }
119 |
120 | return json_decode($value);
121 | }
122 |
123 | public function getOwnerAddressAttribute($value)
124 | {
125 | if (empty($value) === true) {
126 | return null;
127 | }
128 |
129 | $data = json_decode($value);
130 |
131 | if (empty($data) === true) {
132 | return null;
133 | }
134 |
135 | $addressLines = [];
136 |
137 | foreach($data as $entry) {
138 | // Remove/Clean all double commas
139 | $entry = preg_replace('/,+/', ',', $entry);
140 | $addressArr = explode(',', $entry);
141 | $addressLines = array_merge($addressLines, $addressArr);
142 | }
143 |
144 | return array_values(array_filter(array_map('trim', $addressLines)));
145 | }
146 |
147 | public function getRawWhoisAttribute($value)
148 | {
149 | // Remove the "source" entry
150 | $parts = explode("\n", $value);
151 | unset($parts[0]);
152 | return implode($parts, "\n");
153 | }
154 |
155 | public function getEmailContactsAttribute()
156 | {
157 | $email_contacts = [];
158 | foreach ($this->emails as $email) {
159 | $email_contacts[] = isset($email->email_address) ? $email->email_address : $email['email_address'];
160 | }
161 | return $email_contacts;
162 | }
163 |
164 | public function getAbuseContactsAttribute()
165 | {
166 | $abuse_contacts = [];
167 | foreach ($this->emails as $email) {
168 | if ((isset($email->abuse_email) && $email->abuse_email) || (isset($email['abuse_email']) && $email['abuse_email'])) {
169 | $abuse_contacts[] = isset($email->email_address) ? $email->email_address : $email['email_address'];
170 | }
171 | }
172 | return $abuse_contacts;
173 | }
174 | }
175 |
--------------------------------------------------------------------------------
/app/Models/IPv4PrefixWhois.php:
--------------------------------------------------------------------------------
1 | [
20 | 'analyzer' => [
21 | 'string_lowercase' => [
22 | 'tokenizer' => 'keyword',
23 | 'filter' => [ 'asciifolding', 'lowercase', 'custom_replace' ],
24 | ],
25 | ],
26 | 'filter' => [
27 | 'custom_replace' => [
28 | 'type' => 'pattern_replace',
29 | 'pattern' => "[^a-z0-9 ]",
30 | 'replacement' => "",
31 | ],
32 | ],
33 | ],
34 | ];
35 |
36 | /**
37 | * The elasticsearch mappings.
38 | *
39 | * @var array
40 | */
41 | protected $mappingProperties = [
42 | 'ip' => [
43 | 'type' => 'keyword',
44 | 'index' => true,
45 | ],
46 | 'name' => [
47 | 'type' => 'text',
48 | 'analyzer' => 'string_lowercase',
49 | 'fielddata' => true,
50 | ],
51 | 'description' => [
52 | 'type' => 'text',
53 | 'analyzer' => 'string_lowercase',
54 | 'fielddata' => true,
55 | ],
56 | ];
57 |
58 | /**
59 | * The database table used by the model.
60 | *
61 | * @var string
62 | */
63 | protected $table = 'ipv4_prefix_whois';
64 |
65 | /**
66 | * The attributes excluded from the model's JSON form.
67 | *
68 | * @var array
69 | */
70 | protected $hidden = ['id', 'rir_id', 'bgp_prefix_id', 'raw_whois', 'created_at', 'updated_at', 'ip_dec_start', 'ip_dec_end'];
71 |
72 |
73 | public function getIndexName()
74 | {
75 | if (substr_count(config('elasticquent.default_index'), '_') > 1) {
76 | return config('elasticquent.default_index');
77 | }
78 |
79 | return config('elasticquent.default_index'). '_ipv4';
80 | }
81 |
82 | public function rir()
83 | {
84 | return $this->belongsTo('App\Models\Rir');
85 | }
86 |
87 | public function emails()
88 | {
89 | return $this->hasMany('App\Models\IPv4PrefixWhoisEmail', 'prefix_whois_id', 'id');
90 | }
91 |
92 | public function bgpPrefix()
93 | {
94 | return $this->belongsTo('App\Models\IPv4BgpPrefix', 'bgp_prefix_id', 'id');
95 | }
96 |
97 | public function getDescriptionAttribute()
98 | {
99 | $descriptionLines = $this->description_full;
100 | if (is_null($descriptionLines) !== true) {
101 | foreach ($descriptionLines as $descriptionLine) {
102 | if (preg_match("/[A-Za-z0-9]/i", $descriptionLine)) {
103 | return $descriptionLine;
104 | }
105 | }
106 | }
107 |
108 | return $this->name;
109 | }
110 |
111 | public function getDescriptionFullAttribute($value)
112 | {
113 | if (is_null($value) === true) {
114 | return [];
115 | }
116 |
117 | if (is_string($value) !== true) {
118 | return $value;
119 | }
120 |
121 | return json_decode($value);
122 | }
123 |
124 | public function getOwnerAddressAttribute($value)
125 | {
126 | if (is_null($value) === true) {
127 | return null;
128 | }
129 |
130 | $data = json_decode($value);
131 |
132 | if (empty($data) === true) {
133 | return null;
134 | }
135 |
136 | $addressLines = [];
137 |
138 | foreach($data as $entry) {
139 | // Remove/Clean all double commas
140 | $entry = preg_replace('/,+/', ',', $entry);
141 | $addressArr = explode(',', $entry);
142 | $addressLines = array_merge($addressLines, $addressArr);
143 | }
144 |
145 | return array_values(array_filter(array_map('trim', $addressLines)));
146 | }
147 |
148 | public function getRawWhoisAttribute($value)
149 | {
150 | // Remove the "source" entry
151 | $parts = explode("\n", $value);
152 | unset($parts[0]);
153 | return implode($parts, "\n");
154 | }
155 |
156 | public function getEmailContactsAttribute()
157 | {
158 | $email_contacts = [];
159 | foreach ($this->emails as $email) {
160 | $email_contacts[] = isset($email->email_address) ? $email->email_address : $email['email_address'];
161 | }
162 | return $email_contacts;
163 | }
164 |
165 | public function getAbuseContactsAttribute()
166 | {
167 | $abuse_contacts = [];
168 | foreach ($this->emails as $email) {
169 | if ((isset($email->abuse_email) && $email->abuse_email) || (isset($email['abuse_email']) && $email['abuse_email'])) {
170 | $abuse_contacts[] = isset($email->email_address) ? $email->email_address : $email['email_address'];
171 | }
172 | }
173 | return $abuse_contacts;
174 | }
175 | }
176 |
--------------------------------------------------------------------------------
/config/session.php:
--------------------------------------------------------------------------------
1 | env('SESSION_DRIVER', 'file'),
20 |
21 | /*
22 | |--------------------------------------------------------------------------
23 | | Session Lifetime
24 | |--------------------------------------------------------------------------
25 | |
26 | | Here you may specify the number of minutes that you wish the session
27 | | to be allowed to remain idle before it expires. If you want them
28 | | to immediately expire on the browser closing, set that option.
29 | |
30 | */
31 |
32 | 'lifetime' => 120,
33 |
34 | 'expire_on_close' => false,
35 |
36 | /*
37 | |--------------------------------------------------------------------------
38 | | Session Encryption
39 | |--------------------------------------------------------------------------
40 | |
41 | | This option allows you to easily specify that all of your session data
42 | | should be encrypted before it is stored. All encryption will be run
43 | | automatically by Laravel and you can use the Session like normal.
44 | |
45 | */
46 |
47 | 'encrypt' => false,
48 |
49 | /*
50 | |--------------------------------------------------------------------------
51 | | Session File Location
52 | |--------------------------------------------------------------------------
53 | |
54 | | When using the native session driver, we need a location where session
55 | | files may be stored. A default has been set for you but a different
56 | | location may be specified. This is only needed for file sessions.
57 | |
58 | */
59 |
60 | 'files' => storage_path('framework/sessions'),
61 |
62 | /*
63 | |--------------------------------------------------------------------------
64 | | Session Database Connection
65 | |--------------------------------------------------------------------------
66 | |
67 | | When using the "database" or "redis" session drivers, you may specify a
68 | | connection that should be used to manage these sessions. This should
69 | | correspond to a connection in your database configuration options.
70 | |
71 | */
72 |
73 | 'connection' => null,
74 |
75 | /*
76 | |--------------------------------------------------------------------------
77 | | Session Database Table
78 | |--------------------------------------------------------------------------
79 | |
80 | | When using the "database" session driver, you may specify the table we
81 | | should use to manage the sessions. Of course, a sensible default is
82 | | provided for you; however, you are free to change this as needed.
83 | |
84 | */
85 |
86 | 'table' => 'sessions',
87 |
88 | /*
89 | |--------------------------------------------------------------------------
90 | | Session Sweeping Lottery
91 | |--------------------------------------------------------------------------
92 | |
93 | | Some session drivers must manually sweep their storage location to get
94 | | rid of old sessions from storage. Here are the chances that it will
95 | | happen on a given request. By default, the odds are 2 out of 100.
96 | |
97 | */
98 |
99 | 'lottery' => [2, 100],
100 |
101 | /*
102 | |--------------------------------------------------------------------------
103 | | Session Cookie Name
104 | |--------------------------------------------------------------------------
105 | |
106 | | Here you may change the name of the cookie used to identify a session
107 | | instance by ID. The name specified here will get used every time a
108 | | new session cookie is created by the framework for every driver.
109 | |
110 | */
111 |
112 | 'cookie' => 'laravel_session',
113 |
114 | /*
115 | |--------------------------------------------------------------------------
116 | | Session Cookie Path
117 | |--------------------------------------------------------------------------
118 | |
119 | | The session cookie path determines the path for which the cookie will
120 | | be regarded as available. Typically, this will be the root path of
121 | | your application but you are free to change this when necessary.
122 | |
123 | */
124 |
125 | 'path' => '/',
126 |
127 | /*
128 | |--------------------------------------------------------------------------
129 | | Session Cookie Domain
130 | |--------------------------------------------------------------------------
131 | |
132 | | Here you may change the domain of the cookie used to identify a session
133 | | in your application. This will determine which domains the cookie is
134 | | available to in your application. A sensible default has been set.
135 | |
136 | */
137 |
138 | 'domain' => null,
139 |
140 | /*
141 | |--------------------------------------------------------------------------
142 | | HTTPS Only Cookies
143 | |--------------------------------------------------------------------------
144 | |
145 | | By setting this option to true, session cookies will only be sent back
146 | | to the server if the browser has a HTTPS connection. This will keep
147 | | the cookie from being sent to you if it can not be done securely.
148 | |
149 | */
150 |
151 | 'secure' => false,
152 |
153 | ];
154 |
--------------------------------------------------------------------------------
/resources/lang/en/validation.php:
--------------------------------------------------------------------------------
1 | 'The :attribute must be accepted.',
17 | 'active_url' => 'The :attribute is not a valid URL.',
18 | 'after' => 'The :attribute must be a date after :date.',
19 | 'alpha' => 'The :attribute may only contain letters.',
20 | 'alpha_dash' => 'The :attribute may only contain letters, numbers, and dashes.',
21 | 'alpha_num' => 'The :attribute may only contain letters and numbers.',
22 | 'array' => 'The :attribute must be an array.',
23 | 'before' => 'The :attribute must be a date before :date.',
24 | 'between' => [
25 | 'numeric' => 'The :attribute must be between :min and :max.',
26 | 'file' => 'The :attribute must be between :min and :max kilobytes.',
27 | 'string' => 'The :attribute must be between :min and :max characters.',
28 | 'array' => 'The :attribute must have between :min and :max items.',
29 | ],
30 | 'boolean' => 'The :attribute field must be true or false.',
31 | 'confirmed' => 'The :attribute confirmation does not match.',
32 | 'date' => 'The :attribute is not a valid date.',
33 | 'date_format' => 'The :attribute does not match the format :format.',
34 | 'different' => 'The :attribute and :other must be different.',
35 | 'digits' => 'The :attribute must be :digits digits.',
36 | 'digits_between' => 'The :attribute must be between :min and :max digits.',
37 | 'email' => 'The :attribute must be a valid email address.',
38 | 'exists' => 'The selected :attribute is invalid.',
39 | 'filled' => 'The :attribute field is required.',
40 | 'image' => 'The :attribute must be an image.',
41 | 'in' => 'The selected :attribute is invalid.',
42 | 'integer' => 'The :attribute must be an integer.',
43 | 'ip' => 'The :attribute must be a valid IP address.',
44 | 'json' => 'The :attribute must be a valid JSON string.',
45 | 'max' => [
46 | 'numeric' => 'The :attribute may not be greater than :max.',
47 | 'file' => 'The :attribute may not be greater than :max kilobytes.',
48 | 'string' => 'The :attribute may not be greater than :max characters.',
49 | 'array' => 'The :attribute may not have more than :max items.',
50 | ],
51 | 'mimes' => 'The :attribute must be a file of type: :values.',
52 | 'min' => [
53 | 'numeric' => 'The :attribute must be at least :min.',
54 | 'file' => 'The :attribute must be at least :min kilobytes.',
55 | 'string' => 'The :attribute must be at least :min characters.',
56 | 'array' => 'The :attribute must have at least :min items.',
57 | ],
58 | 'not_in' => 'The selected :attribute is invalid.',
59 | 'numeric' => 'The :attribute must be a number.',
60 | 'regex' => 'The :attribute format is invalid.',
61 | 'required' => 'The :attribute field is required.',
62 | 'required_if' => 'The :attribute field is required when :other is :value.',
63 | 'required_unless' => 'The :attribute field is required unless :other is in :values.',
64 | 'required_with' => 'The :attribute field is required when :values is present.',
65 | 'required_with_all' => 'The :attribute field is required when :values is present.',
66 | 'required_without' => 'The :attribute field is required when :values is not present.',
67 | 'required_without_all' => 'The :attribute field is required when none of :values are present.',
68 | 'same' => 'The :attribute and :other must match.',
69 | 'size' => [
70 | 'numeric' => 'The :attribute must be :size.',
71 | 'file' => 'The :attribute must be :size kilobytes.',
72 | 'string' => 'The :attribute must be :size characters.',
73 | 'array' => 'The :attribute must contain :size items.',
74 | ],
75 | 'string' => 'The :attribute must be a string.',
76 | 'timezone' => 'The :attribute must be a valid zone.',
77 | 'unique' => 'The :attribute has already been taken.',
78 | 'url' => 'The :attribute format is invalid.',
79 |
80 | /*
81 | |--------------------------------------------------------------------------
82 | | Custom Validation Language Lines
83 | |--------------------------------------------------------------------------
84 | |
85 | | Here you may specify custom validation messages for attributes using the
86 | | convention "attribute.rule" to name the lines. This makes it quick to
87 | | specify a specific custom language line for a given attribute rule.
88 | |
89 | */
90 |
91 | 'custom' => [
92 | 'attribute-name' => [
93 | 'rule-name' => 'custom-message',
94 | ],
95 | ],
96 |
97 | /*
98 | |--------------------------------------------------------------------------
99 | | Custom Validation Attributes
100 | |--------------------------------------------------------------------------
101 | |
102 | | The following language lines are used to swap attribute place-holders
103 | | with something more reader friendly such as E-Mail Address instead
104 | | of "email". This simply helps us make messages a little cleaner.
105 | |
106 | */
107 |
108 | 'attributes' => [],
109 |
110 | ];
111 |
--------------------------------------------------------------------------------