diff --git a/app/Http/Controllers/Admin/AccountsController.php b/app/Http/Controllers/Admin/AccountsController.php index ca6de204b..a38350fa0 100644 --- a/app/Http/Controllers/Admin/AccountsController.php +++ b/app/Http/Controllers/Admin/AccountsController.php @@ -25,6 +25,7 @@ namespace Pterodactyl\Http\Controllers\Admin; use Alert; +use Settings; use Mail; use Log; use Pterodactyl\Models\User; @@ -124,8 +125,9 @@ class AccountsController extends Controller } if($request->input('email_user')) { - Mail::send('emails.new_password', ['user' => User::findOrFail($request->input('user')), 'password' => $request->input('password')], function($message) use ($request) { - $message->to($request->input('email'))->subject('Pterodactyl - Admin Reset Password'); + Mail::queue('emails.new_password', ['user' => User::findOrFail($request->input('user')), 'password' => $request->input('password')], function($message) use ($request) { + $message->to($request->input('email'))->subject(Settings::get('company') . ' - Admin Reset Password'); + $message->from(Settings::get('email_from', env('MAIL_FROM')), Settings::get('email_sender_name', env('MAIL_FROM_NAME', 'Pterodactyl Panel'))); }); } diff --git a/app/Http/Controllers/Admin/BaseController.php b/app/Http/Controllers/Admin/BaseController.php index 9d5f78d8a..f44ac06f4 100644 --- a/app/Http/Controllers/Admin/BaseController.php +++ b/app/Http/Controllers/Admin/BaseController.php @@ -23,7 +23,9 @@ */ namespace Pterodactyl\Http\Controllers\Admin; -use Debugbar; +use Alert; +use Settings; +use Validator; use Pterodactyl\Http\Controllers\Controller; use Illuminate\Http\Request; @@ -44,4 +46,32 @@ class BaseController extends Controller return view('admin.index'); } + public function getSettings(Request $request) + { + return view('admin.settings'); + } + + public function postSettings(Request $request) + { + $validator = Validator::make($request->all(), [ + 'company' => 'required|between:1,256', + 'default_language' => 'required|alpha_dash|min:2|max:5', + 'email_from' => 'required|email', + 'email_sender_name' => 'required|between:1,256' + ]); + + if ($validator->fails()) { + return redirect()->route('admin.settings')->withErrors($validator->errors())->withInput(); + } + + Settings::set('company', $request->input('company')); + Settings::set('default_language', $request->input('default_language')); + Settings::set('email_from', $request->input('email_from')); + Settings::set('email_sender_name', $request->input('email_sender_name')); + + Alert::success('Settings have been successfully updated.')->flash(); + return redirect()->route('admin.settings'); + + } + } diff --git a/app/Http/Routes/AdminRoutes.php b/app/Http/Routes/AdminRoutes.php index d950edd1e..296a1b1bc 100644 --- a/app/Http/Routes/AdminRoutes.php +++ b/app/Http/Routes/AdminRoutes.php @@ -41,6 +41,23 @@ class AdminRoutes { 'uses' => 'Admin\BaseController@getIndex' ]); + $router->group([ + 'prefix' => 'admin/settings', + 'middleware' => [ + 'auth', + 'admin', + 'csrf' + ] + ], function () use ($router) { + $router->get('/', [ + 'as' => 'admin.settings', + 'uses' => 'Admin\BaseController@getSettings' + ]); + $router->post('/', [ + 'uses' => 'Admin\BaseController@postSettings' + ]); + }); + $router->group([ 'prefix' => 'admin/accounts', 'middleware' => [ diff --git a/app/Repositories/SubuserRepository.php b/app/Repositories/SubuserRepository.php index c18e70fce..1f237ae56 100644 --- a/app/Repositories/SubuserRepository.php +++ b/app/Repositories/SubuserRepository.php @@ -24,6 +24,7 @@ namespace Pterodactyl\Repositories; use DB; +use Settings; use Validator; use Mail; @@ -179,7 +180,8 @@ class SubuserRepository 'url' => route('server.index', $server->uuidShort), ], function ($message) use ($email) { $message->to($email); - $message->subject('Pterodactyl - Added to Server'); + $message->from(Settings::get('email_from', env('MAIL_FROM')), Settings::get('email_sender_name', env('MAIL_FROM_NAME', 'Pterodactyl Panel'))); + $message->subject(Settings::get('company') . ' - Added to Server'); }); DB::commit(); return $subuser->id; diff --git a/app/Repositories/UserRepository.php b/app/Repositories/UserRepository.php index 71d50c0ac..746fd19c2 100644 --- a/app/Repositories/UserRepository.php +++ b/app/Repositories/UserRepository.php @@ -25,6 +25,7 @@ namespace Pterodactyl\Repositories; use DB; +use Settings; use Hash; use Validator; use Mail; @@ -87,7 +88,8 @@ class UserRepository 'login' => route('auth.login') ], function ($message) use ($email) { $message->to($email); - $message->subject('Pterodactyl - New Account'); + $message->from(Settings::get('email_from', env('MAIL_FROM')), Settings::get('email_sender_name', env('MAIL_FROM_NAME', 'Pterodactyl Panel'))); + $message->subject(Settings::get('company') . ' - New Account'); }); DB::commit(); return $user->id; diff --git a/composer.json b/composer.json index 24aa808eb..f23fea2c8 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,8 @@ "pragmarx/google2fa": "^0.7.1", "webpatser/laravel-uuid": "^2.0", "prologue/alerts": "^0.4.0", - "s1lentium/iptools": "^1.0" + "s1lentium/iptools": "^1.0", + "edvinaskrucas/settings": "^2.0" }, "require-dev": { "fzaninotto/faker": "~1.4", diff --git a/config/app.php b/config/app.php index c054c592d..7c4030d45 100644 --- a/config/app.php +++ b/config/app.php @@ -153,6 +153,7 @@ return [ Barryvdh\Debugbar\ServiceProvider::class, PragmaRX\Google2FA\Vendor\Laravel\ServiceProvider::class, Prologue\Alerts\AlertsServiceProvider::class, + Krucas\Settings\Providers\SettingsServiceProvider::class ], @@ -202,6 +203,7 @@ return [ 'Response' => Illuminate\Support\Facades\Response::class, 'Route' => Illuminate\Support\Facades\Route::class, 'Schema' => Illuminate\Support\Facades\Schema::class, + 'Settings' => Krucas\Settings\Facades\Settings::class, 'Session' => Illuminate\Support\Facades\Session::class, 'Storage' => Illuminate\Support\Facades\Storage::class, 'URL' => Illuminate\Support\Facades\URL::class, diff --git a/config/settings.php b/config/settings.php new file mode 100644 index 000000000..e5c82eea0 --- /dev/null +++ b/config/settings.php @@ -0,0 +1,118 @@ + env('SETTINGS_DRIVER', 'database'), + + /* + |-------------------------------------------------------------------------- + | Enable / Disable caching + |-------------------------------------------------------------------------- + | + | If it is enabled all values gets cached after accessing it. + | + */ + 'cache' => true, + + /* + |-------------------------------------------------------------------------- + | Enable / Disable value encryption + |-------------------------------------------------------------------------- + | + | If it is enabled all values gets encrypted and decrypted. + | + */ + 'encryption' => env('SETTINGS_ENCRYPTION', false), + + /* + |-------------------------------------------------------------------------- + | Enable / Disable events + |-------------------------------------------------------------------------- + | + | If it is enabled various settings related events will be fired. + | + */ + 'events' => true, + + /* + |-------------------------------------------------------------------------- + | Repositories Configuration + |-------------------------------------------------------------------------- + | + | Here you may configure the driver information for each repository that + | is used by your application. A default configuration has been added + | for each back-end shipped with this package. You are free to add more. + | + */ + + 'repositories' => [ + + 'database' => [ + 'driver' => 'database', + 'connection' => env('DB_CONNECTION', 'mysql'), + 'table' => 'settings', + ], + + ], + + /* + |-------------------------------------------------------------------------- + | Key generator class + |-------------------------------------------------------------------------- + | + | Key generator is used to generate keys based on setting key and context. + | + */ + 'key_generator' => \Krucas\Settings\KeyGenerators\KeyGenerator::class, + + /* + |-------------------------------------------------------------------------- + | Context serializer class + |-------------------------------------------------------------------------- + | + | Context serializer serializes context. + | It is used with "Krucas\Settings\KeyGenerators\KeyGenerator" class. + | + */ + 'context_serializer' => \Krucas\Settings\ContextSerializers\ContextSerializer::class, + + /* + |-------------------------------------------------------------------------- + | Value serializer class + |-------------------------------------------------------------------------- + | + | Value serializer serializes / unserializes given value. + | + */ + 'value_serializer' => \Krucas\Settings\ValueSerializers\ValueSerializer::class, + + /* + |-------------------------------------------------------------------------- + | Override application config values + |-------------------------------------------------------------------------- + | + | If defined, settings package will override these config values from persistent + | settings repository. + | + | Sample: + | "app.fallback_locale", + | "app.locale" => "settings.locale", + | + */ + + 'override' => [ + + ], + +]; diff --git a/database/migrations/2016_01_21_015230_create_settings_table.php b/database/migrations/2016_01_21_015230_create_settings_table.php new file mode 100644 index 000000000..657f1ba1b --- /dev/null +++ b/database/migrations/2016_01_21_015230_create_settings_table.php @@ -0,0 +1,30 @@ +string('key')->unique(); + $table->text('value'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('settings'); + } +} diff --git a/resources/views/admin/settings.blade.php b/resources/views/admin/settings.blade.php new file mode 100644 index 000000000..289649899 --- /dev/null +++ b/resources/views/admin/settings.blade.php @@ -0,0 +1,99 @@ +{{-- + Copyright (c) 2015 - 2016 Dane Everitt + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +--}} +@extends('layouts.admin') + +@section('title') + Administration +@endsection + +@section('content') +
+ +

Panel Settings


+
+
+
+ +
+ +

This is the name that is used throughout the panel and in emails sent to clients.

+
+
+
+ +
+ +

This is the default language that all clients will use unless they manually change it.

+
+
+
+
+
+
In order to modify your SMTP settings for sending mail you will need to edit the .env file in this project's root folder.
+
+
+
+
+ +
+ +

The email address that panel emails will be sent from. Note that some SMTP services require this to match for a given API key.

+
+
+
+ +
+ +

The name that emails will appear to come from.

+
+
+
+
+
+
+ {!! csrf_field() !!} + +
+
+
+
+
+ +@endsection diff --git a/resources/views/layouts/admin.blade.php b/resources/views/layouts/admin.blade.php index ae0a8e926..d0fd5702f 100644 --- a/resources/views/layouts/admin.blade.php +++ b/resources/views/layouts/admin.blade.php @@ -38,7 +38,7 @@ @show - Pterodactyl - @yield('title') + {{ Settings::get('company') }} - @yield('title')
@@ -49,7 +49,7 @@ - Pterodactyl - Laravel + {{ Settings::get('company') }}