1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-05 18:52:44 +01:00

Forward support messages to contact@invoiceninja.com with system-level info (#2993)

* Sending support messages via API

* Sending log files only if self-hosted

* Remove legacy code
This commit is contained in:
Benjamin Beganović 2019-10-16 22:12:38 +02:00 committed by David Bomba
parent 6a0afaacb7
commit b35bff3cde
7 changed files with 164 additions and 22 deletions

View File

@ -0,0 +1,26 @@
<?php
namespace App\Http\Controllers\Support\Messages;
use App\Http\Controllers\Controller;
use App\Mail\SupportMessageSent;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail;
class SendingController extends Controller
{
public function __invoke(Request $request)
{
$request->validate([
'message' => ['required'],
]);
Mail::to(config('ninja.contact.ninja_official_contact'))
->send(new SupportMessageSent($request->message));
return response()->json([
'success' => true
]);
}
}

View File

@ -0,0 +1,59 @@
<?php
namespace App\Mail;
use App\Utils\Ninja;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class SupportMessageSent extends Mailable
{
use Queueable, SerializesModels;
public $message;
public function __construct($message)
{
$this->message = $message;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
$system_info = null;
$log_lines = [];
/**
* With self-hosted version of Ninja,
* we are going to bundle system-level info
* and last 10 lines of laravel.log file.
*/
if(Ninja::isSelfHost()) {
$system_info = Ninja::getDebugInfo();
$log_file = new \SplFileObject(sprintf('%s/laravel.log', base_path('storage/logs')));
$log_file->seek(PHP_INT_MAX);
$last_line = $log_file->key();
$lines = new \LimitIterator($log_file, $last_line - 10, $last_line);
$log_lines = iterator_to_array($lines);
}
return $this->from(config('mail.from.address'))
->subject(ctrans('texts.new_support_message'))
->markdown('email.support.message', [
'message' => $this->message,
'system_info' => $system_info,
'laravel_log' => $log_lines
]);
}
}

View File

@ -11,18 +11,33 @@
namespace App\Utils;
use Illuminate\Support\Facades\DB;
/**
* Class Ninja.
*/
class Ninja
{
public static function isSelfHost()
{
return config('ninja.environment') === 'selfhost';
}
public static function isSelfHost()
{
return config('ninja.environment') === 'selfhost';
}
public static function isHosted()
{
return config('ninja.environment') === 'hosted';
}
public static function isHosted()
{
return config('ninja.environment') === 'hosted';
}
public static function getDebugInfo()
{
$mysql_version = DB::select(DB::raw("select version() as version"))[0]->version;
$info = "App Version: v" . config('ninja.app_version') . "\\n" .
"White Label: " . "\\n" . // TODO: Implement white label with hasFeature.
"Server OS: " . php_uname('s') . ' ' . php_uname('r') . "\\n" .
"PHP Version: " . phpversion() . "\\n" .
"MySQL Version: " . $mysql_version;
return $info;
}
}

View File

@ -64,6 +64,7 @@ return [
'contact' => [
'email' => env('MAIL_FROM_ADDRESS'),
'from_name' => env('MAIL_FROM_NAME'),
'ninja_official_contact' => env('NINJA_OFFICIAL_CONTACT', 'contact@invoiceninja.com'),
],
'cached_tables' => [
'banks' => 'App\Models\Bank',

View File

@ -0,0 +1,39 @@
@component('mail::layout')
{{-- Header --}}
@slot('header')
@component('mail::header', ['url' => config('app.url')])
Header Title
@endcomponent
@endslot
{{-- Body --}}
{{ $message }}
{!! str_replace('\n', '<br>', $system_info) !!}
<details>
<summary>{{ ctrans('texts.display_log') }}</summary>
@foreach($laravel_log as $log_line)
<small>{{ $log_line }}</small> <br>
@endforeach
</details>
{{-- Subcopy --}}
@isset($subcopy)
@slot('subcopy')
@component('mail::subcopy')
{{ $subcopy }}
@endcomponent
@endslot
@endisset
{{-- Footer --}}
@slot('footer')
@component('mail::footer')
© {{ date('Y') }} {{ config('ninja.app_name') }}.
@endcomponent
@endslot
@endcomponent

View File

@ -22,20 +22,20 @@ Route::group(['middleware' => ['api_secret_check']], function () {
Route::post('api/v1/signup', 'AccountController@store')->name('signup.submit');
Route::post('api/v1/oauth_login', 'Auth\LoginController@oauthApiLogin');
});
Route::group(['api_secret_check','domain_db'], function () {
Route::post('api/v1/login', 'Auth\LoginController@apiLogin')->name('login.submit');
Route::post('api/v1/reset_password', 'Auth\ForgotPasswordController@sendResetLinkEmail')->name('password.reset');
});
Route::group(['middleware' => ['api_db','api_secret_check','token_auth'], 'prefix' =>'api/v1', 'as' => 'api.'], function () {
Route::resource('activities', 'ActivityController'); // name = (clients. index / create / show / update / destroy / edit
Route::resource('clients', 'ClientController'); // name = (clients. index / create / show / update / destroy / edit
Route::post('clients/bulk', 'ClientController@bulk')->name('clients.bulk');
@ -65,7 +65,7 @@ Route::group(['middleware' => ['api_db','api_secret_check','token_auth'], 'prefi
Route::resource('client_statement', 'ClientStatementController@statement'); // name = (client_statement. index / create / show / update / destroy / edit
Route::resource('payments', 'PaymentController'); // name = (payments. index / create / show / update / destroy / edit
Route::post('payments/bulk', 'PaymentController@bulk')->name('payments.bulk');
Route::resource('users', 'UserController'); // name = (users. index / create / show / update / destroy / edit
@ -81,22 +81,23 @@ Route::group(['middleware' => ['api_db','api_secret_check','token_auth'], 'prefi
Route::post('refresh', 'Auth\LoginController@refresh');
/*
Route::resource('tasks', 'TaskController'); // name = (tasks. index / create / show / update / destroy / edit
Route::post('tasks/bulk', 'TaskController@bulk')->name('tasks.bulk');
Route::resource('credits', 'CreditController'); // name = (credits. index / create / show / update / destroy / edit
Route::post('credits/bulk', 'CreditController@bulk')->name('credits.bulk');
Route::resource('expenses', 'ExpenseController'); // name = (expenses. index / create / show / update / destroy / edit
Route::post('expenses/bulk', 'ExpenseController@bulk')->name('expenses.bulk');
Route::get('settings', 'SettingsController@index')->name('user.settings');
*/
Route::post('support/messages/send', 'Support\Messages\SendingController');
});
Route::fallback('BaseController@notFound');
Route::fallback('BaseController@notFound');

View File

@ -180,6 +180,7 @@ class ClientPortalTest extends DuskTestCase
$this->browse(function ($browser) {
$browser->visit('/client/login')
->assertPathIs('/client/login')
->type('email', 'user@example.com')
->type('password', config('ninja.testvars.password'))
->press('Login')
@ -319,4 +320,4 @@ class ClientPortalTest extends DuskTestCase
});
}
}
}