Skip to content

Commit b996316

Browse files
committed
Fixes some permissions stuff
1 parent 71e6d2e commit b996316

File tree

4 files changed

+71
-39
lines changed

4 files changed

+71
-39
lines changed

app/Policies/ServerPolicy.php

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace Pterodactyl\Policies;
44

5-
use Log;
6-
use Debugbar;
75
use Pterodactyl\Models\User;
86
use Pterodactyl\Models\Server;
97

@@ -191,4 +189,36 @@ public function setConnection(User $user, Server $server)
191189
return $user->permissions()->server($server)->permission('set-connection')->exists();
192190
}
193191

192+
/**
193+
* Check if user has permission to view subusers for the server.
194+
*
195+
* @param Pterodactyl\Models\User $user
196+
* @param Pterodactyl\Models\Server $server
197+
* @return boolean
198+
*/
199+
public function viewSubusers(User $user, Server $server)
200+
{
201+
if ($this->isOwner($user, $server)) {
202+
return true;
203+
}
204+
205+
return $user->permissions()->server($server)->permission('view-subusers')->exists();
206+
}
207+
208+
/**
209+
* Check if user has permission to view the server management page.
210+
*
211+
* @param Pterodactyl\Models\User $user
212+
* @param Pterodactyl\Models\Server $server
213+
* @return boolean
214+
*/
215+
public function viewManage(User $user, Server $server)
216+
{
217+
if ($this->isOwner($user, $server)) {
218+
return true;
219+
}
220+
221+
return $user->permissions()->server($server)->permission('view-manage')->exists();
222+
}
223+
194224
}

app/Providers/AuthServiceProvider.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
namespace Pterodactyl\Providers;
44

5-
use Pterodactyl\Models\Server;
6-
use Pterodactyl\Policies\ServerPolicy;
7-
85
use Illuminate\Contracts\Auth\Access\Gate as GateContract;
96
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
107

@@ -16,8 +13,7 @@ class AuthServiceProvider extends ServiceProvider
1613
* @var array
1714
*/
1815
protected $policies = [
19-
'Pterodactyl\Model' => 'Pterodactyl\Policies\ModelPolicy',
20-
Server::class => ServerPolicy::class,
16+
'Pterodactyl\Models\Server' => 'Pterodactyl\Policies\ServerPolicy'
2117
];
2218

2319
/**

resources/views/layouts/master.blade.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,9 @@
193193
<div class="list-group">
194194
<a href="#" class="list-group-item list-group-item-heading"><strong>{{ trans('pagination.sidebar.server_controls') }}</strong></a>
195195
<a href="/server/{{ $server->uuidShort }}/" class="list-group-item server-index">{{ trans('pagination.sidebar.overview') }}</a>
196-
<a href="/server/{{ $server->uuidShort }}/files" class="list-group-item server-files">{{ trans('pagination.sidebar.files') }}</a>
197-
<a href="/server/{{ $server->uuidShort }}/users" class="list-group-item server-users">{{ trans('pagination.sidebar.subusers') }}</a>
198-
<a href="/server/{{ $server->uuidShort }}/settings" class="list-group-item server-settings">{{ trans('pagination.sidebar.manage') }}</a>
196+
@can('list-files', Auth::user())<a href="/server/{{ $server->uuidShort }}/files" class="list-group-item server-files">{{ trans('pagination.sidebar.files') }}</a>@endcan
197+
@can('view-subusers', Auth::user())<a href="/server/{{ $server->uuidShort }}/users" class="list-group-item server-users">{{ trans('pagination.sidebar.subusers') }}</a>@endcan
198+
@can('view-manage', Auth::user())<a href="/server/{{ $server->uuidShort }}/settings" class="list-group-item server-settings">{{ trans('pagination.sidebar.manage') }}</a>@endcan
199199
</div>
200200
@endif
201201
@show

resources/views/server/index.blade.php

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<ul class="nav nav-tabs tabs_with_panel" id="config_tabs">
1515
<li id="triggerConsoleView" class="active"><a href="#console" data-toggle="tab">{{ trans('server.index.control') }}</a></li>
1616
<li><a href="#stats" data-toggle="tab">{{ trans('server.index.usage') }}</a></li>
17-
<li><a href="#allocation" data-toggle="tab">{{ trans('server.index.allocation') }}</a></li>
17+
@can('allocation', $server)<li><a href="#allocation" data-toggle="tab">{{ trans('server.index.allocation') }}</a></li>@endcan
1818
</ul>
1919
<div class="tab-content">
2020
<div class="tab-pane active" id="console">
@@ -27,26 +27,30 @@
2727
</div>
2828
<div class="col-md-6">
2929
<hr />
30-
<form action="#" method="post" id="console_command" style="display:none;">
31-
<fieldset>
32-
<div class="input-group">
33-
<input type="text" class="form-control" name="command" id="ccmd" placeholder="{{ trans('server.index.command') }}" />
34-
<span class="input-group-btn">
35-
<button id="sending_command" class="btn btn-primary btn-sm">&rarr;</button>
36-
</span>
37-
</div>
38-
</fieldset>
39-
</form>
40-
<div class="alert alert-danger" id="sc_resp" style="display:none;margin-top: 15px;"></div>
30+
@can('command', $server)
31+
<form action="#" method="post" id="console_command" style="display:none;">
32+
<fieldset>
33+
<div class="input-group">
34+
<input type="text" class="form-control" name="command" id="ccmd" placeholder="{{ trans('server.index.command') }}" />
35+
<span class="input-group-btn">
36+
<button id="sending_command" class="btn btn-primary btn-sm">&rarr;</button>
37+
</span>
38+
</div>
39+
</fieldset>
40+
</form>
41+
<div class="alert alert-danger" id="sc_resp" style="display:none;margin-top: 15px;"></div>
42+
@endcan
4143
</div>
4244
<div class="col-md-6" style="text-align:center;">
4345
<hr />
44-
<button class="btn btn-success btn-sm disabled" data-attr="power" data-action="start">Start</button>
45-
<button class="btn btn-primary btn-sm disabled" data-attr="power" data-action="restart">Restart</button>
46-
<button class="btn btn-danger btn-sm disabled" data-attr="power" data-action="stop">Stop</button>
47-
<button class="btn btn-danger btn-sm disabled" data-attr="power" data-action="kill"><i class="fa fa-ban" data-toggle="tooltip" data-placement="top" title="Kill Running Process"></i></button>
48-
<button class="btn btn-primary btn-sm" data-toggle="modal" data-target="#pauseConsole" id="pause_console"><small><i class="fa fa-pause fa-fw"></i></small></button>
49-
<div id="pw_resp" style="display:none;margin-top: 15px;"></div>
46+
@can('power', $server)
47+
<button class="btn btn-success btn-sm disabled" data-attr="power" data-action="start">Start</button>
48+
<button class="btn btn-primary btn-sm disabled" data-attr="power" data-action="restart">Restart</button>
49+
<button class="btn btn-danger btn-sm disabled" data-attr="power" data-action="stop">Stop</button>
50+
<button class="btn btn-danger btn-sm disabled" data-attr="power" data-action="kill"><i class="fa fa-ban" data-toggle="tooltip" data-placement="top" title="Kill Running Process"></i></button>
51+
<button class="btn btn-primary btn-sm" data-toggle="modal" data-target="#pauseConsole" id="pause_console"><small><i class="fa fa-pause fa-fw"></i></small></button>
52+
<div id="pw_resp" style="display:none;margin-top: 15px;"></div>
53+
@endcan
5054
</div>
5155
</div>
5256
<div class="row">
@@ -74,19 +78,21 @@
7478
</div>
7579
</div>
7680
</div>
77-
<div class="tab-pane" id="allocation">
78-
<div class="panel panel-default">
79-
<div class="panel-heading"></div>
80-
<div class="panel-body">
81-
<div class="alert alert-info">Below is a listing of all avaliable IPs and Ports for your service. To change the default connection address for your server, simply click on the one you would like to make default below.</div>
82-
<ul class="nav nav-pills nav-stacked" id="conn_options">
83-
@foreach ($allocations as $allocation)
84-
<li role="presentation" @if($allocation->ip === $server->ip && $allocation->port === $server->port) class="active" @endif><a href="#/set-connnection/{{ $allocation->ip }}:{{ $allocation->port }}" data-action="set-connection" data-connection="{{ $allocation->ip }}:{{ $allocation->port }}">{{ $allocation->ip }} <span class="badge">{{ $allocation->port }}</span></a></li>
85-
@endforeach
86-
</ul>
81+
@can('allocation', $server)
82+
<div class="tab-pane" id="allocation">
83+
<div class="panel panel-default">
84+
<div class="panel-heading"></div>
85+
<div class="panel-body">
86+
<div class="alert alert-info">Below is a listing of all avaliable IPs and Ports for your service. To change the default connection address for your server, simply click on the one you would like to make default below.</div>
87+
<ul class="nav nav-pills nav-stacked" id="conn_options">
88+
@foreach ($allocations as $allocation)
89+
<li role="presentation" @if($allocation->ip === $server->ip && $allocation->port === $server->port) class="active" @endif><a href="#/set-connnection/{{ $allocation->ip }}:{{ $allocation->port }}" data-action="set-connection" data-connection="{{ $allocation->ip }}:{{ $allocation->port }}">{{ $allocation->ip }} <span class="badge">{{ $allocation->port }}</span></a></li>
90+
@endforeach
91+
</ul>
92+
</div>
8793
</div>
8894
</div>
89-
</div>
95+
@endcan
9096
</div>
9197
<div class="row">
9298
<div class="col-xs-11" id="col11_setter"></div>

0 commit comments

Comments
 (0)