Skip to content

Commit e18f452

Browse files
authored
Update to Laravel 5.7 (PHP 7.3 support) (librenms#9800)
* Move assets to 5.7 location * Add 5.7 SVGs * add cache data dir * update QUEUE_DRIVER -> QUEUE_CONNECTION * Update trusted proxy config * update composer.json * 5.5 command loading * @php and @endphp can't be inline * Laravel 5.6 logging, Nice! * Update blade directives * improved redirects * remove unneeded service providers * Improved debugbar loading * no need to emulate renderable exceptions anymore * merge updated 5.7 files (WIP) * Enable CSRF * database_path() call causes issue in init.php * fix old testcase name * generic phpunit 7 fixes * add missed file_get_contents Keep migrations table content * fix duplicate key * Drop old php versions from travis-ci * remove hhvm * fix code climate message * remove use of deprecated function assertInternalType * Disable CSRF, we'll enable it separately. All forms need to be updated to work. * Update document references
1 parent 25954cc commit e18f452

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+3072
-1346
lines changed

.editorconfig

+8-12
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
1-
# EditorConfig is awesome: http://EditorConfig.org
2-
3-
# top-most EditorConfig file
41
root = true
52

6-
# Unix-style newlines with a newline ending every file
73
[*]
8-
end_of_line = lf
94
charset = utf-8
10-
trim_trailing_whitespace = true
5+
end_of_line = lf
116
insert_final_newline = true
12-
13-
[**.css]
14-
indent_style = space
15-
indent_size = 2
16-
17-
[**.php]
187
indent_style = space
198
indent_size = 4
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false
13+
14+
[*.yml]
15+
indent_size = 2

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ patches
2929
!/lib/yaml
3030
/vendor
3131
/node_modules
32+
npm-debug.log
33+
yarn-error.log
3234
composer.phar
3335
_ide_helper.php
3436

.travis.yml

+3-10
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,12 @@ services:
55
matrix:
66
fast_finish: true
77
include:
8-
- php: 7.2
8+
- php: 7.3
99
env: SKIP_STYLE_CHECK=1
10-
- php: 7.1
10+
- php: 7.2
1111
env: SKIP_UNIT_CHECK=1
12-
- php: 7.0
13-
env: SKIP_STYLE_CHECK=1 SKIP_UNIT_CHECK=1
14-
- php: 5.6
12+
- php: 7.1
1513
env: SKIP_STYLE_CHECK=1 EXECUTE_BUILD_DOCS=true
16-
# - php: hhvm
17-
# env: SKIP_STYLE_CHECK=1
18-
19-
allow_failures:
20-
- php: hhvm
2114

2215
cache:
2316
directories:

LibreNMS/Util/Laravel.php

+3-36
Original file line numberDiff line numberDiff line change
@@ -83,48 +83,15 @@ public static function disableQueryDebug()
8383

8484
public static function enableCliDebugOutput()
8585
{
86-
if (class_exists('\Log')) {
87-
$logger = Log::getMonolog();
88-
89-
// only install if not existing
90-
$install = true;
91-
$logfile = Config::get('log_file', base_path('logs/librenms.log'));
92-
foreach ($logger->getHandlers() as $handler) {
93-
if ($handler instanceof \Monolog\Handler\StreamHandler) {
94-
if ($handler->getUrl() == 'php://stdout') {
95-
$install = false;
96-
} elseif ($handler->getUrl() == $logfile) {
97-
// send to librenms log file if not a cli app
98-
if (!App::runningInConsole()) {
99-
set_error_handler(function ($errno, $errstr, $errfile, $errline) {
100-
Log::error("$errno $errfile:$errline $errstr");
101-
});
102-
$handler->setLevel(\Monolog\Logger::DEBUG);
103-
}
104-
}
105-
}
106-
}
107-
108-
if ($install) {
109-
$handler = new \Monolog\Handler\StreamHandler(
110-
'php://stdout',
111-
\Monolog\Logger::DEBUG
112-
);
113-
114-
$handler->setFormatter(new CliColorFormatter());
115-
116-
$logger->pushHandler($handler);
117-
}
86+
if (class_exists('\Log') && App::runningInConsole()) {
87+
Log::setDefaultDriver('console');
11888
}
11989
}
12090

12191
public static function disableCliDebugOutput()
12292
{
12393
if (class_exists('Log')) {
124-
$handlers = Log::getMonolog()->getHandlers();
125-
if (isset($handlers[0]) && $handlers[0]->getUrl() == 'php://stdout') {
126-
Log::getMonolog()->popHandler();
127-
}
94+
Log::setDefaultDriver('logfile');
12895
}
12996
}
13097
}

LibreNMS/Util/ModuleTestHelper.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function __construct($modules, $os, $variant = '')
9595

9696
if (is_null(self::$module_tables)) {
9797
// only load the yaml once, then keep it in memory
98-
self::$module_tables = Yaml::parse($install_dir . '/tests/module_tables.yaml');
98+
self::$module_tables = Yaml::parse(file_get_contents($install_dir . '/tests/module_tables.yaml'));
9999
}
100100
}
101101

app/Console/Kernel.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Kernel extends ConsoleKernel
1414
* @var array
1515
*/
1616
protected $commands = [
17-
\App\Console\Commands\BashCompletionCommand::class,
17+
//
1818
];
1919

2020
/**
@@ -30,12 +30,14 @@ protected function schedule(Schedule $schedule)
3030
}
3131

3232
/**
33-
* Register the Closure based commands for the application.
33+
* Register the commands for the application.
3434
*
3535
* @return void
3636
*/
3737
protected function commands()
3838
{
39+
$this->load(__DIR__.'/Commands');
40+
3941
require base_path('routes/console.php');
4042

4143
if ($this->app->environment() !== 'production') {

app/Exceptions/Handler.php

-5
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ class Handler extends ExceptionHandler
2727

2828
public function render($request, Exception $exception)
2929
{
30-
// emulate Laravel 5.5 renderable exceptions
31-
if (method_exists($exception, 'render')) {
32-
return $exception->render($request);
33-
}
34-
3530
return parent::render($request, $exception);
3631
}
3732

app/Http/Controllers/Auth/RegisterController.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use App\User;
66
use App\Http\Controllers\Controller;
7+
use Illuminate\Support\Facades\Hash;
78
use Illuminate\Support\Facades\Validator;
89
use Illuminate\Foundation\Auth\RegistersUsers;
910

@@ -48,9 +49,9 @@ public function __construct()
4849
protected function validator(array $data)
4950
{
5051
return Validator::make($data, [
51-
'name' => 'required|string|max:255',
52-
'email' => 'required|string|email|max:255|unique:users',
53-
'password' => 'required|string|min:6|confirmed',
52+
'name' => ['required', 'string', 'max:255'],
53+
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
54+
'password' => ['required', 'string', 'min:6', 'confirmed'],
5455
]);
5556
}
5657

@@ -65,7 +66,7 @@ protected function create(array $data)
6566
return User::create([
6667
'name' => $data['name'],
6768
'email' => $data['email'],
68-
'password' => bcrypt($data['password']),
69+
'password' => Hash::make($data['password']),
6970
]);
7071
}
7172
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Auth;
4+
5+
use App\Http\Controllers\Controller;
6+
use Illuminate\Foundation\Auth\VerifiesEmails;
7+
8+
class VerificationController extends Controller
9+
{
10+
/*
11+
|--------------------------------------------------------------------------
12+
| Email Verification Controller
13+
|--------------------------------------------------------------------------
14+
|
15+
| This controller is responsible for handling email verification for any
16+
| user that recently registered with the application. Emails may also
17+
| be re-sent if the user didn't receive the original email message.
18+
|
19+
*/
20+
21+
use VerifiesEmails;
22+
23+
/**
24+
* Where to redirect users after verification.
25+
*
26+
* @var string
27+
*/
28+
protected $redirectTo = '/home';
29+
30+
/**
31+
* Create a new controller instance.
32+
*
33+
* @return void
34+
*/
35+
public function __construct()
36+
{
37+
$this->middleware('auth');
38+
$this->middleware('signed')->only('verify');
39+
$this->middleware('throttle:6,1')->only('verify', 'resend');
40+
}
41+
}

app/Http/Kernel.php

+19-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Kernel extends HttpKernel
3333
\App\Http\Middleware\EncryptCookies::class,
3434
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
3535
\Illuminate\Session\Middleware\StartSession::class,
36-
// \Illuminate\Session\Middleware\AuthenticateSession::class, // Works in Laravel 5.5
36+
// \Illuminate\Session\Middleware\AuthenticateSession::class,
3737
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
3838
\App\Http\Middleware\VerifyCsrfToken::class,
3939
\App\Http\Middleware\LegacyExternalAuth::class,
@@ -64,11 +64,29 @@ class Kernel extends HttpKernel
6464
'2fa' => \App\Http\Middleware\VerifyTwoFactor::class,
6565
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
6666
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
67+
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
6768
'can' => \Illuminate\Auth\Middleware\Authorize::class,
6869
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
70+
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
6971
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
72+
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
7073
];
7174

75+
/**
76+
* The priority-sorted list of middleware.
77+
*
78+
* This forces non-global middleware to always be in the given order.
79+
*
80+
* @var array
81+
*/
82+
protected $middlewarePriority = [
83+
\Illuminate\Session\Middleware\StartSession::class,
84+
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
85+
\Illuminate\Auth\Middleware\Authenticate::class,
86+
\Illuminate\Session\Middleware\AuthenticateSession::class,
87+
\Illuminate\Routing\Middleware\SubstituteBindings::class,
88+
\Illuminate\Auth\Middleware\Authorize::class,
89+
];
7290

7391
public function bootstrap()
7492
{

app/Http/Middleware/EncryptCookies.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace App\Http\Middleware;
44

5-
use Illuminate\Cookie\Middleware\EncryptCookies as BaseEncrypter;
5+
use Illuminate\Cookie\Middleware\EncryptCookies as Middleware;
66

7-
class EncryptCookies extends BaseEncrypter
7+
class EncryptCookies extends Middleware
88
{
99
/**
1010
* The names of the cookies that should not be encrypted.

app/Http/Middleware/TrimStrings.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace App\Http\Middleware;
44

5-
use Illuminate\Foundation\Http\Middleware\TrimStrings as BaseTrimmer;
5+
use Illuminate\Foundation\Http\Middleware\TrimStrings as Middleware;
66

7-
class TrimStrings extends BaseTrimmer
7+
class TrimStrings extends Middleware
88
{
99
/**
1010
* The names of the attributes that should not be trimmed.

app/Http/Middleware/VerifyCsrfToken.php

+9-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,17 @@
22

33
namespace App\Http\Middleware;
44

5-
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as BaseVerifier;
5+
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
66

7-
class VerifyCsrfToken extends BaseVerifier
7+
class VerifyCsrfToken extends Middleware
88
{
9+
/**
10+
* Indicates whether the XSRF-TOKEN cookie should be set on the response.
11+
*
12+
* @var bool
13+
*/
14+
protected $addHttpCookie = true;
15+
916
/**
1017
* The URIs that should be excluded from CSRF verification.
1118
*

app/Providers/AppServiceProvider.php

+14-35
Original file line numberDiff line numberDiff line change
@@ -31,43 +31,9 @@ public function boot()
3131
// load config
3232
Config::load();
3333

34-
// replace early boot logging redirect log to config location, unless APP_LOG is set
35-
Log::getMonolog()->popHandler(); // remove existing errorlog logger
36-
Log::useFiles(config('app.log') ?: Config::get('log_file', base_path('logs/librenms.log')), 'error');
37-
38-
// Blade directives (Yucky because of < L5.5)
39-
Blade::directive('config', function ($key) {
40-
return "<?php if (\LibreNMS\Config::get(($key))): ?>";
41-
});
42-
Blade::directive('notconfig', function ($key) {
43-
return "<?php if (!\LibreNMS\Config::get(($key))): ?>";
44-
});
45-
Blade::directive('endconfig', function () {
46-
return "<?php endif; ?>";
47-
});
48-
Blade::directive('admin', function () {
49-
return "<?php if (auth()->check() && auth()->user()->isAdmin()): ?>";
50-
});
51-
Blade::directive('endadmin', function () {
52-
return "<?php endif; ?>";
53-
});
54-
34+
$this->bootCustomBladeDirectives();
5535
$this->bootCustomValidators();
5636
$this->configureMorphAliases();
57-
58-
// Development service providers
59-
if ($this->app->environment() !== 'production') {
60-
if (class_exists(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class)) {
61-
$this->app->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class);
62-
}
63-
64-
if (config('app.debug') && class_exists(\Barryvdh\Debugbar\ServiceProvider::class)) {
65-
// disable debugbar for api routes
66-
if (!Request::is('api/*')) {
67-
$this->app->register(\Barryvdh\Debugbar\ServiceProvider::class);
68-
}
69-
}
70-
}
7137
}
7238

7339
/**
@@ -80,6 +46,19 @@ public function register()
8046
$this->registerGeocoder();
8147
}
8248

49+
private function bootCustomBladeDirectives()
50+
{
51+
Blade::if('config', function ($key) {
52+
return \LibreNMS\Config::get($key);
53+
});
54+
Blade::if('notconfig', function ($key) {
55+
return !\LibreNMS\Config::get($key);
56+
});
57+
Blade::if('admin', function () {
58+
return auth()->check() && auth()->user()->isAdmin();
59+
});
60+
}
61+
8362
private function configureMorphAliases()
8463
{
8564
Relation::morphMap([

app/Providers/EventServiceProvider.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ class EventServiceProvider extends ServiceProvider
1212
* @var array
1313
*/
1414
protected $listen = [
15-
'Illuminate\Auth\Events\Login' => ['App\Listeners\AuthEventListener@login'],
16-
'Illuminate\Auth\Events\Logout' => ['App\Listeners\AuthEventListener@logout'],
15+
\Illuminate\Auth\Events\Login::class => ['App\Listeners\AuthEventListener@login'],
16+
\Illuminate\Auth\Events\Logout::class => ['App\Listeners\AuthEventListener@logout'],
1717
];
1818

1919
/**

artisan

100644100755
File mode changed.

0 commit comments

Comments
 (0)