Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev/beta #3

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,17 @@ class Kernel extends HttpKernel
\Illuminate\Auth\Middleware\Authorize::class,
\App\Http\Middleware\AuthenticateAdmin::class,
];

/**
* Handle an incoming HTTP request.
*
* @param \Illuminate\Http\Request $request HTTP Request object
*
* @return \Illuminate\Http\Response
*/
public function handle($request)
{
// Overwrite the http request object
return parent::handle(Request::createFrom($request));
}
}
7 changes: 6 additions & 1 deletion src/app/Http/Middleware/TrustProxies.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ class TrustProxies extends Middleware
*
* @var array|string
*/
protected $proxies = '*';
protected $proxies = [
'10.0.0.0/8',
'127.0.0.1/8',
'172.16.0.0/12',
'192.168.0.0/16'
];

/**
* The headers that should be used to detect proxies.
Expand Down
22 changes: 22 additions & 0 deletions src/app/Http/Request.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace App\Http;

use Illuminate\Http\Request as LaravelRequest;

class Request extends LaravelRequest
{
/**
* Get the client IP address.
*
* @return string|null
*/
public function ip()
{
if (($client_ip = $this->headers->get('X-Client-IP')) && $this->isFromTrustedProxy()) {
return $client_ip;
}

return parent::ip();
}
}
9 changes: 9 additions & 0 deletions src/app/Observers/SignupCodeObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ public function creating(SignupCode $code): void
}
}

$code->headers = collect(request()->headers->all())
->filter(function ($value, $key) {
// remove some headers we don't care about
return !in_array($key, ['cookie', 'referer', 'x-test-payment-provider', 'origin']);
})
->map(function ($value) {
return is_array($value) && count($value) == 1 ? $value[0] : $value;
});

$code->expires_at = Carbon::now()->addHours($exp_hours);
$code->ip_address = request()->ip();

Expand Down
2 changes: 2 additions & 0 deletions src/app/SignupCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class SignupCode extends Model
'voucher'
];

protected $casts = ['headers' => 'array'];

/**
* The attributes that should be mutated to dates.
*
Expand Down
1 change: 1 addition & 0 deletions src/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"require": {
"php": "^7.1.3",
"barryvdh/laravel-dompdf": "^0.8.6",
"doctrine/dbal": "^2.13",
"dyrynda/laravel-nullable-fields": "*",
"fideloper/proxy": "^4.0",
"kolab/net_ldap3": "dev-master",
Expand Down
40 changes: 40 additions & 0 deletions src/database/migrations/2021_04_08_150000_signup_code_headers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

// phpcs:ignore
class SignupCodeHeaders extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table(
'signup_codes',
function (Blueprint $table) {
$table->text('headers')->nullable();
}
);
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table(
'signup_codes',
function (Blueprint $table) {
$table->dropColumn('headers');
}
);
}
}