Skip to content

Commit b63fc02

Browse files
committed
Add settings to panel
1 parent 591cc86 commit b63fc02

File tree

12 files changed

+317
-14
lines changed

12 files changed

+317
-14
lines changed

app/Http/Controllers/Admin/AccountsController.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
namespace Pterodactyl\Http\Controllers\Admin;
2626

2727
use Alert;
28+
use Settings;
2829
use Mail;
2930
use Log;
3031
use Pterodactyl\Models\User;
@@ -124,8 +125,9 @@ public function postUpdate(Request $request)
124125
}
125126

126127
if($request->input('email_user')) {
127-
Mail::send('emails.new_password', ['user' => User::findOrFail($request->input('user')), 'password' => $request->input('password')], function($message) use ($request) {
128-
$message->to($request->input('email'))->subject('Pterodactyl - Admin Reset Password');
128+
Mail::queue('emails.new_password', ['user' => User::findOrFail($request->input('user')), 'password' => $request->input('password')], function($message) use ($request) {
129+
$message->to($request->input('email'))->subject(Settings::get('company') . ' - Admin Reset Password');
130+
$message->from(Settings::get('email_from', env('MAIL_FROM')), Settings::get('email_sender_name', env('MAIL_FROM_NAME', 'Pterodactyl Panel')));
129131
});
130132
}
131133

app/Http/Controllers/Admin/BaseController.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
*/
2424
namespace Pterodactyl\Http\Controllers\Admin;
2525

26-
use Debugbar;
26+
use Alert;
27+
use Settings;
28+
use Validator;
2729

2830
use Pterodactyl\Http\Controllers\Controller;
2931
use Illuminate\Http\Request;
@@ -44,4 +46,32 @@ public function getIndex(Request $request)
4446
return view('admin.index');
4547
}
4648

49+
public function getSettings(Request $request)
50+
{
51+
return view('admin.settings');
52+
}
53+
54+
public function postSettings(Request $request)
55+
{
56+
$validator = Validator::make($request->all(), [
57+
'company' => 'required|between:1,256',
58+
'default_language' => 'required|alpha_dash|min:2|max:5',
59+
'email_from' => 'required|email',
60+
'email_sender_name' => 'required|between:1,256'
61+
]);
62+
63+
if ($validator->fails()) {
64+
return redirect()->route('admin.settings')->withErrors($validator->errors())->withInput();
65+
}
66+
67+
Settings::set('company', $request->input('company'));
68+
Settings::set('default_language', $request->input('default_language'));
69+
Settings::set('email_from', $request->input('email_from'));
70+
Settings::set('email_sender_name', $request->input('email_sender_name'));
71+
72+
Alert::success('Settings have been successfully updated.')->flash();
73+
return redirect()->route('admin.settings');
74+
75+
}
76+
4777
}

app/Http/Routes/AdminRoutes.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,23 @@ public function map(Router $router) {
4141
'uses' => 'Admin\BaseController@getIndex'
4242
]);
4343

44+
$router->group([
45+
'prefix' => 'admin/settings',
46+
'middleware' => [
47+
'auth',
48+
'admin',
49+
'csrf'
50+
]
51+
], function () use ($router) {
52+
$router->get('/', [
53+
'as' => 'admin.settings',
54+
'uses' => 'Admin\BaseController@getSettings'
55+
]);
56+
$router->post('/', [
57+
'uses' => 'Admin\BaseController@postSettings'
58+
]);
59+
});
60+
4461
$router->group([
4562
'prefix' => 'admin/accounts',
4663
'middleware' => [

app/Repositories/SubuserRepository.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
namespace Pterodactyl\Repositories;
2525

2626
use DB;
27+
use Settings;
2728
use Validator;
2829
use Mail;
2930

@@ -179,7 +180,8 @@ public function create($sid, array $data)
179180
'url' => route('server.index', $server->uuidShort),
180181
], function ($message) use ($email) {
181182
$message->to($email);
182-
$message->subject('Pterodactyl - Added to Server');
183+
$message->from(Settings::get('email_from', env('MAIL_FROM')), Settings::get('email_sender_name', env('MAIL_FROM_NAME', 'Pterodactyl Panel')));
184+
$message->subject(Settings::get('company') . ' - Added to Server');
183185
});
184186
DB::commit();
185187
return $subuser->id;

app/Repositories/UserRepository.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
namespace Pterodactyl\Repositories;
2626

2727
use DB;
28+
use Settings;
2829
use Hash;
2930
use Validator;
3031
use Mail;
@@ -87,7 +88,8 @@ public function create($email, $password, $admin = false)
8788
'login' => route('auth.login')
8889
], function ($message) use ($email) {
8990
$message->to($email);
90-
$message->subject('Pterodactyl - New Account');
91+
$message->from(Settings::get('email_from', env('MAIL_FROM')), Settings::get('email_sender_name', env('MAIL_FROM_NAME', 'Pterodactyl Panel')));
92+
$message->subject(Settings::get('company') . ' - New Account');
9193
});
9294
DB::commit();
9395
return $user->id;

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"pragmarx/google2fa": "^0.7.1",
2626
"webpatser/laravel-uuid": "^2.0",
2727
"prologue/alerts": "^0.4.0",
28-
"s1lentium/iptools": "^1.0"
28+
"s1lentium/iptools": "^1.0",
29+
"edvinaskrucas/settings": "^2.0"
2930
},
3031
"require-dev": {
3132
"fzaninotto/faker": "~1.4",

config/app.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@
153153
Barryvdh\Debugbar\ServiceProvider::class,
154154
PragmaRX\Google2FA\Vendor\Laravel\ServiceProvider::class,
155155
Prologue\Alerts\AlertsServiceProvider::class,
156+
Krucas\Settings\Providers\SettingsServiceProvider::class
156157

157158
],
158159

@@ -202,6 +203,7 @@
202203
'Response' => Illuminate\Support\Facades\Response::class,
203204
'Route' => Illuminate\Support\Facades\Route::class,
204205
'Schema' => Illuminate\Support\Facades\Schema::class,
206+
'Settings' => Krucas\Settings\Facades\Settings::class,
205207
'Session' => Illuminate\Support\Facades\Session::class,
206208
'Storage' => Illuminate\Support\Facades\Storage::class,
207209
'URL' => Illuminate\Support\Facades\URL::class,

config/settings.php

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
<?php
2+
3+
return [
4+
5+
/*
6+
|--------------------------------------------------------------------------
7+
| Default Settings Driver
8+
|--------------------------------------------------------------------------
9+
|
10+
| Settings driver used to store persistent settings.
11+
|
12+
| Supported: "database"
13+
|
14+
*/
15+
16+
'default' => env('SETTINGS_DRIVER', 'database'),
17+
18+
/*
19+
|--------------------------------------------------------------------------
20+
| Enable / Disable caching
21+
|--------------------------------------------------------------------------
22+
|
23+
| If it is enabled all values gets cached after accessing it.
24+
|
25+
*/
26+
'cache' => true,
27+
28+
/*
29+
|--------------------------------------------------------------------------
30+
| Enable / Disable value encryption
31+
|--------------------------------------------------------------------------
32+
|
33+
| If it is enabled all values gets encrypted and decrypted.
34+
|
35+
*/
36+
'encryption' => env('SETTINGS_ENCRYPTION', false),
37+
38+
/*
39+
|--------------------------------------------------------------------------
40+
| Enable / Disable events
41+
|--------------------------------------------------------------------------
42+
|
43+
| If it is enabled various settings related events will be fired.
44+
|
45+
*/
46+
'events' => true,
47+
48+
/*
49+
|--------------------------------------------------------------------------
50+
| Repositories Configuration
51+
|--------------------------------------------------------------------------
52+
|
53+
| Here you may configure the driver information for each repository that
54+
| is used by your application. A default configuration has been added
55+
| for each back-end shipped with this package. You are free to add more.
56+
|
57+
*/
58+
59+
'repositories' => [
60+
61+
'database' => [
62+
'driver' => 'database',
63+
'connection' => env('DB_CONNECTION', 'mysql'),
64+
'table' => 'settings',
65+
],
66+
67+
],
68+
69+
/*
70+
|--------------------------------------------------------------------------
71+
| Key generator class
72+
|--------------------------------------------------------------------------
73+
|
74+
| Key generator is used to generate keys based on setting key and context.
75+
|
76+
*/
77+
'key_generator' => \Krucas\Settings\KeyGenerators\KeyGenerator::class,
78+
79+
/*
80+
|--------------------------------------------------------------------------
81+
| Context serializer class
82+
|--------------------------------------------------------------------------
83+
|
84+
| Context serializer serializes context.
85+
| It is used with "Krucas\Settings\KeyGenerators\KeyGenerator" class.
86+
|
87+
*/
88+
'context_serializer' => \Krucas\Settings\ContextSerializers\ContextSerializer::class,
89+
90+
/*
91+
|--------------------------------------------------------------------------
92+
| Value serializer class
93+
|--------------------------------------------------------------------------
94+
|
95+
| Value serializer serializes / unserializes given value.
96+
|
97+
*/
98+
'value_serializer' => \Krucas\Settings\ValueSerializers\ValueSerializer::class,
99+
100+
/*
101+
|--------------------------------------------------------------------------
102+
| Override application config values
103+
|--------------------------------------------------------------------------
104+
|
105+
| If defined, settings package will override these config values from persistent
106+
| settings repository.
107+
|
108+
| Sample:
109+
| "app.fallback_locale",
110+
| "app.locale" => "settings.locale",
111+
|
112+
*/
113+
114+
'override' => [
115+
116+
],
117+
118+
];
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
use Illuminate\Database\Schema\Blueprint;
4+
use Illuminate\Database\Migrations\Migration;
5+
6+
class CreateSettingsTable extends Migration
7+
{
8+
/**
9+
* Run the migrations.
10+
*
11+
* @return void
12+
*/
13+
public function up()
14+
{
15+
Schema::create('settings', function (Blueprint $table) {
16+
$table->string('key')->unique();
17+
$table->text('value');
18+
});
19+
}
20+
21+
/**
22+
* Reverse the migrations.
23+
*
24+
* @return void
25+
*/
26+
public function down()
27+
{
28+
Schema::drop('settings');
29+
}
30+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
{{--
2+
Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a copy
5+
of this software and associated documentation files (the "Software"), to deal
6+
in the Software without restriction, including without limitation the rights
7+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the Software is
9+
furnished to do so, subject to the following conditions:
10+
11+
The above copyright notice and this permission notice shall be included in all
12+
copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
SOFTWARE.
21+
--}}
22+
@extends('layouts.admin')
23+
24+
@section('title')
25+
Administration
26+
@endsection
27+
28+
@section('content')
29+
<div class="col-md-12">
30+
<ul class="breadcrumb">
31+
<li><a href="/admin">Admin Control</a></li>
32+
<li class="active">Settings</li>
33+
</ul>
34+
<h3 class="nopad">Panel Settings</h3><hr />
35+
<form action="{{ route('admin.settings') }}" method="POST">
36+
<div class="row">
37+
<div class="form-group col-md-6">
38+
<label class="control-label">Company Name:</label>
39+
<div>
40+
<input type="text" class="form-control" name="company" value="{{ old('company', Settings::get('company')) }}" />
41+
<p class="text-muted"><small>This is the name that is used throughout the panel and in emails sent to clients.</small></p>
42+
</div>
43+
</div>
44+
<div class="form-group col-md-6">
45+
<label class="control-label">Default Language:</label>
46+
<div>
47+
<select name="default_language" class="form-control">
48+
<option value="de" @if(Settings::get('default_language') === 'de')selected @endif>Deutsch</option>
49+
<option value="en" @if(Settings::get('default_language') === 'en')selected @endif>English</option>
50+
<option value="es" @if(Settings::get('default_language') === 'es')selected @endif>Espa&ntilde;ol</option>
51+
<option value="fr" @if(Settings::get('default_language') === 'fr')selected @endif>Fran&ccedil;ais</option>
52+
<option value="it" @if(Settings::get('default_language') === 'it')selected @endif>Italiano</option>
53+
<option value="pl" @if(Settings::get('default_language') === 'pl')selected @endif>Polski</option>
54+
<option value="pt" @if(Settings::get('default_language') === 'pt')selected @endif>Portugu&ecirc;s</option>
55+
<option value="ru" @if(Settings::get('default_language') === 'ru')selected @endif>&#1088;&#1091;&#1089;&#1089;&#1082;&#1080;&#1081;</option>
56+
<option value="se" @if(Settings::get('default_language') === 'se')selected @endif>Svenska</option>
57+
<option value="zh" @if(Settings::get('default_language') === 'zh')selected @endif>&#20013;&#22269;&#30340;的</option>
58+
</select>
59+
<p class="text-muted"><small>This is the default language that all clients will use unless they manually change it.</small></p>
60+
</div>
61+
</div>
62+
</div>
63+
<div class="row">
64+
<div class="col-md-12">
65+
<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>
66+
</div>
67+
</div>
68+
<div class="row">
69+
<div class="form-group col-md-6">
70+
<label class="control-label">Send Emails From:</label>
71+
<div>
72+
<input type="text" class="form-control" name="email_from" value="{{ old('email_from', Settings::get('email_from', env('MAIL_FROM', 'you@example.com'))) }}" />
73+
<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>
74+
</div>
75+
</div>
76+
<div class="form-group col-md-6">
77+
<label class="control-label">Email Sender Name:</label>
78+
<div>
79+
<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'))) }}" />
80+
<p class="text-muted"><small>The name that emails will appear to come from.</small></p>
81+
</div>
82+
</div>
83+
</div>
84+
<div class="well well-sm">
85+
<div class="row">
86+
<div class="col-md-12">
87+
{!! csrf_field() !!}
88+
<input type="submit" class="btn btn-sm btn-primary" value="Modify Settings">
89+
</div>
90+
</div>
91+
</div>
92+
</form>
93+
</div>
94+
<script>
95+
$(document).ready(function () {
96+
$('#sidebar_links').find("a[href='/admin/settings']").addClass('active');
97+
});
98+
</script>
99+
@endsection

0 commit comments

Comments
 (0)