Add settings to panel

This commit is contained in:
Dane Everitt 2016-01-20 22:08:09 -05:00
parent 591cc8648d
commit b63fc02cef
12 changed files with 317 additions and 14 deletions

View file

@ -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')));
});
}

View file

@ -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');
}
}

View file

@ -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' => [

View file

@ -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;

View file

@ -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;

View file

@ -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",

View file

@ -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,

118
config/settings.php Normal file
View file

@ -0,0 +1,118 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Default Settings Driver
|--------------------------------------------------------------------------
|
| Settings driver used to store persistent settings.
|
| Supported: "database"
|
*/
'default' => 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' => [
],
];

View file

@ -0,0 +1,30 @@
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateSettingsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('settings', function (Blueprint $table) {
$table->string('key')->unique();
$table->text('value');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('settings');
}
}

View file

@ -0,0 +1,99 @@
{{--
Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>
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')
<div class="col-md-12">
<ul class="breadcrumb">
<li><a href="/admin">Admin Control</a></li>
<li class="active">Settings</li>
</ul>
<h3 class="nopad">Panel Settings</h3><hr />
<form action="{{ route('admin.settings') }}" method="POST">
<div class="row">
<div class="form-group col-md-6">
<label class="control-label">Company Name:</label>
<div>
<input type="text" class="form-control" name="company" value="{{ old('company', Settings::get('company')) }}" />
<p class="text-muted"><small>This is the name that is used throughout the panel and in emails sent to clients.</small></p>
</div>
</div>
<div class="form-group col-md-6">
<label class="control-label">Default Language:</label>
<div>
<select name="default_language" class="form-control">
<option value="de" @if(Settings::get('default_language') === 'de')selected @endif>Deutsch</option>
<option value="en" @if(Settings::get('default_language') === 'en')selected @endif>English</option>
<option value="es" @if(Settings::get('default_language') === 'es')selected @endif>Espa&ntilde;ol</option>
<option value="fr" @if(Settings::get('default_language') === 'fr')selected @endif>Fran&ccedil;ais</option>
<option value="it" @if(Settings::get('default_language') === 'it')selected @endif>Italiano</option>
<option value="pl" @if(Settings::get('default_language') === 'pl')selected @endif>Polski</option>
<option value="pt" @if(Settings::get('default_language') === 'pt')selected @endif>Portugu&ecirc;s</option>
<option value="ru" @if(Settings::get('default_language') === 'ru')selected @endif>&#1088;&#1091;&#1089;&#1089;&#1082;&#1080;&#1081;</option>
<option value="se" @if(Settings::get('default_language') === 'se')selected @endif>Svenska</option>
<option value="zh" @if(Settings::get('default_language') === 'zh')selected @endif>&#20013;&#22269;&#30340;的</option>
</select>
<p class="text-muted"><small>This is the default language that all clients will use unless they manually change it.</small></p>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="alert alert-info">In order to modify your SMTP settings for sending mail you will need to edit the <code>.env</code> file in this project's root folder.</div>
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label class="control-label">Send Emails From:</label>
<div>
<input type="text" class="form-control" name="email_from" value="{{ old('email_from', Settings::get('email_from', env('MAIL_FROM', 'you@example.com'))) }}" />
<p class="text-muted"><small>The email address that panel emails will be sent from. Note that some SMTP services require this to match for a given API key.</small></p>
</div>
</div>
<div class="form-group col-md-6">
<label class="control-label">Email Sender Name:</label>
<div>
<input type="text" class="form-control" name="email_sender_name" value="{{ old('email_sender_name', Settings::get('email_sender_name', env('MAIL_FROM_NAME', 'Pterodactyl Panel'))) }}" />
<p class="text-muted"><small>The name that emails will appear to come from.</small></p>
</div>
</div>
</div>
<div class="well well-sm">
<div class="row">
<div class="col-md-12">
{!! csrf_field() !!}
<input type="submit" class="btn btn-sm btn-primary" value="Modify Settings">
</div>
</div>
</div>
</form>
</div>
<script>
$(document).ready(function () {
$('#sidebar_links').find("a[href='/admin/settings']").addClass('active');
});
</script>
@endsection

View file

@ -38,7 +38,7 @@
<script src="//cdnjs.cloudflare.com/ajax/libs/fuelux/3.13.0/js/fuelux.min.js"></script>
<script src="{{ asset('js/admin.min.js') }}"></script>
@show
<title>Pterodactyl - @yield('title')</title>
<title>{{ Settings::get('company') }} - @yield('title')</title>
</head>
<body>
<div class="container">
@ -49,7 +49,7 @@
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">Pterodactyl - Laravel</a>
<a class="navbar-brand" href="/">{{ Settings::get('company') }}</a>
</div>
<div class="navbar-collapse collapse navbar-responsive-collapse">
@section('right-nav')
@ -141,8 +141,8 @@
<div class="footer">
<div class="row">
<div class="col-md-12">
Copyright &copy; 2012 - {{ date('Y') }} <a href="https://github.com/Pterodactyl-IO/Panel" target="_blank">Pterodactyl Software &amp; Design</a>.<br />
Pterodactyl is licensed under a <a href="http://www.gnu.org/licenses/gpl-3.0.en.html" target="_blank">GPLv3</a> license. <!-- Please do not remove this license notice. -->
Copyright &copy; 2015 - {{ date('Y') }} <a href="https://github.com/Pterodactyl/Panel" target="_blank">Pterodactyl Software &amp; Design</a>.<br />
Pterodactyl is licensed under a <a href="https://opensource.org/licenses/MIT" target="_blank">MIT</a> license. <!-- Please do not remove this license notice. We can't stop you though... :) -->
</div>
</div>
</div>

View file

@ -154,7 +154,7 @@
@endif
@show
@show
<title>Pterodactyl - @yield('title')</title>
<title>{{ Settings::get('company') }} - @yield('title')</title>
</head>
<body>
<div class="container">
@ -165,7 +165,7 @@
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">Pterodactyl</a>
<a class="navbar-brand" href="/">{{ Settings::get('company') }}</a>
</div>
<div class="navbar-collapse collapse navbar-responsive-collapse">
@section('server-name')
@ -256,8 +256,8 @@
<div class="footer">
<div class="row">
<div class="col-md-12">
Copyright &copy; 2012 - {{ date('Y') }} <a href="https://github.com/Pterodactyl-IO/Panel" target="_blank">Pterodactyl Software &amp; Design</a>.<br />
Pterodactyl is licensed under a <a href="http://www.gnu.org/licenses/gpl-3.0.en.html" target="_blank">GPLv3</a> license. <!-- Please do not remove this license notice. -->
Copyright &copy; 2015 - {{ date('Y') }} <a href="https://github.com/Pterodactyl/Panel" target="_blank">Pterodactyl Software &amp; Design</a>.<br />
Pterodactyl is licensed under a <a href="https://opensource.org/licenses/MIT" target="_blank">MIT</a> license. <!-- Please do not remove this license notice. We can't stop you though... :) -->
</div>
</div>
</div>