Check for minimum PHP version in setup

This commit is contained in:
snipe 2018-08-02 21:36:18 -07:00
parent 84f20b6287
commit 1a660911e7
4 changed files with 50 additions and 18 deletions

View file

@ -1,6 +1,7 @@
<?php
namespace App\Http\Controllers;
use App\Notifications\MailTest;
use Input;
use Lang;
use Illuminate\Http\Request;
@ -43,7 +44,11 @@ class SettingsController extends Controller
*/
public function getSetupIndex()
{
$start_settings['php_version_min'] = false;
if (version_compare(PHP_VERSION, config('app.min_php'), '<')) {
return response('<center><h1>This software requires PHP version '.config('app.min_php').' or greater. This server is running '.PHP_VERSION.'. </h1><h2>Please upgrade PHP on this server and try again. </h2></center>', 500);
}
try {
$conn = DB::select('select 2 + 2');
@ -69,6 +74,7 @@ class SettingsController extends Controller
$start_settings['url_config'] = url('/');
$start_settings['real_url'] = $pageURL;
$start_settings['php_version_min'] = true;
// Curl the .env file to make sure it's not accessible via a browser
$ch = curl_init($protocol . $host.'/.env');
@ -80,7 +86,7 @@ class SettingsController extends Controller
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpcode == 404 || $httpcode == 403) {
if ($httpcode == 404 || $httpcode == 403 || $httpcode == 0) {
$start_settings['env_exposed'] = false;
} else {
$start_settings['env_exposed'] = true;
@ -195,11 +201,6 @@ class SettingsController extends Controller
$data['password'] = $request->input('password');
$user->notify(new FirstAdminNotification($data));
/*Mail::send(['text' => 'emails.firstadmin'], $data, function ($m) use ($data) {
$m->to($data['email'], $data['first_name']);
$m->replyTo(config('mail.reply_to.address'), config('mail.reply_to.name'));
$m->subject(trans('mail.your_credentials'));
});*/
}
@ -1092,11 +1093,14 @@ class SettingsController extends Controller
public function ajaxTestEmail()
{
try {
Mail::send('emails.test', [], function ($m) {
$m->to(config('mail.from.address'), config('mail.from.name'));
$m->replyTo(config('mail.reply_to.address'), config('mail.reply_to.name'));
$m->subject(trans('mail.test_email'));
});
(new User)->forceFill([
'name' => config('mail.from.name'),
'email' => config('mail.from.address')
])->notify(new MailTest());
return response()->json(Helper::formatStandardApiResponse('success', null, 'Maiol sent!'));
} catch (Exception $e) {
return response()->json(Helper::formatStandardApiResponse('success', null, $e->getMessage()));

View file

@ -195,6 +195,18 @@ return [
'lock_passwords' => env('APP_LOCKED', false),
/*
|--------------------------------------------------------------------------
| Minimum PHP version
|--------------------------------------------------------------------------
|
| Do not change this variable.
|
*/
'min_php' => '7.1.3',
/*
|--------------------------------------------------------------------------
| Autoloaded Service Providers

View file

@ -2,10 +2,6 @@
{{ trans('mail.test_mail_text') }}
Thanks,<br>
@if ($snipeSettings->show_url_in_emails=='1')
<p><a href="{{ url('/') }}">{{ $snipeSettings->site_name }}</a></p>
@else
<p>{{ $snipeSettings->site_name }}</p>
@endif
Thanks,
Snipe-IT
@endcomponent

View file

@ -20,6 +20,26 @@ Create a User ::
</tr>
</thead>
<tbody>
<tr {!! ($start_settings['php_version_min']) ? ' class="success"' : ' class="danger"' !!}>
<td>PHP</td>
<td>
@if ($start_settings['php_version_min'])
<i class="fa fa-check preflight-success"></i>
@else
<i class="fa fa-times preflight-error"></i>
@endif
</td>
<td>
@if ($start_settings['php_version_min'])
Yay!
@else
Oh no!
@endif
You're running PHP version {{ PHP_VERSION }}. ({{ config('app.min_php') }} or greater is required.)
</td>
</tr>
<tr {!! ($start_settings['url_valid']) ? ' class="success"' : ' class="danger"' !!}>
<td>URL</td>
<td>
@ -70,7 +90,7 @@ Create a User ::
@if (!$start_settings['env_exposed'])
Sweet. It doesn't look like your <code>.env</code> file is exposed to the outside world. (You should double check this in a browser though. You don't ever want anyone able to see that file. Ever. Ever ever.) <a href="../../.env">Click here to check now</a> (This should return a file not found or forbidden error.)
@else
Please make sure your <code>.env</code> is not readable by the outside world via web browser. You don't ever want anyone able to see that file. Ever. Ever ever. An exposed <code>.env</code> file can disclose sensitive data about your system and database. <a href="../../.env">Click here to check now</a> (This should return a file not found or forbidden error.)
We cannot determine if your config file is exposed to the outside world, so you will have to manually verify this. You don't ever want anyone able to see that file. Ever. Ever ever. An exposed <code>.env</code> file can disclose sensitive data about your system and database.
@endif
</td>
</tr>