Skip to content

Commit

Permalink
Hide server IP in listing page. Only visible when editing with edit p…
Browse files Browse the repository at this point in the history
…ermissions
  • Loading branch information
Xinecraft committed Nov 24, 2024
1 parent e9b9fd3 commit 59d293b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
17 changes: 9 additions & 8 deletions app/Http/Controllers/Admin/ServerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,12 @@ public function index()
->allowedSorts(['id', 'name', 'hostname', 'ip_address', 'join_port', 'query_port', 'webquery_port', 'type', 'minecraft_version', 'order', 'country_id', 'last_scanned_at', 'created_at'])
->defaultSort('-order')
->paginate($perPage)
->through(fn($server) => $server->append('masked_ip_address')->makeHidden('ip_address'))
->withQueryString();

return Inertia::render('Admin/Server/IndexServer', [
'servers' => $servers,
'canCreateBungeeServer' => ! $canCreateBungeeServer,
'canCreateBungeeServer' => !$canCreateBungeeServer,
'filters' => request()->all(['perPage', 'sort', 'filter']),
]);
}
Expand Down Expand Up @@ -177,7 +178,7 @@ public function storeBungee(Request $request, GeolocationService $geolocationSer
'order' => $request->order,
]);

if (! $request->webquery_port) {
if (!$request->webquery_port) {
return redirect()->route('admin.server.index')
->with(['toast' => ['type' => 'success', 'title' => __('Created Successfully'), 'body' => __('Proxy server added successfully')]]);
}
Expand Down Expand Up @@ -306,9 +307,9 @@ public function updateBungee(Request $request, Server $server, GeolocationServic
$server->save();

// We forget the cached result so that new data will be shown instantly and not redundant data.
Cache::forget('server:ping:'.$server->id);
Cache::forget('server:query:'.$server->id);
Cache::forget('server:webquery:'.$server->id);
Cache::forget('server:ping:' . $server->id);
Cache::forget('server:query:' . $server->id);
Cache::forget('server:webquery:' . $server->id);

return redirect()->route('admin.server.index')
->with(['toast' => ['type' => 'success', 'title' => __('Updated Successfully'), 'body' => __('Server updated successfully')]]);
Expand Down Expand Up @@ -338,9 +339,9 @@ public function update(UpdateServerRequest $request, Server $server, Geolocation
$server->save();

// We forget the cached result so that new data will be shown instantly and not redundant data.
Cache::forget('server:ping:'.$server->id);
Cache::forget('server:query:'.$server->id);
Cache::forget('server:webquery:'.$server->id);
Cache::forget('server:ping:' . $server->id);
Cache::forget('server:query:' . $server->id);
Cache::forget('server:webquery:' . $server->id);

return redirect()->route('admin.server.index')
->with(['toast' => ['type' => 'success', 'title' => __('Updated Successfully'), 'body' => __('Server updated successfully')]]);
Expand Down
5 changes: 5 additions & 0 deletions app/Models/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,9 @@ public function getSettingsKey($key, $default = null)
{
return Arr::dot($this->settings)[$key] ?? $default;
}

public function getMaskedIpAddressAttribute()
{
return preg_replace('/(\d{1,3})\.\d{1,3}\.\d{1,3}\.\d{1,3}/', '$1.xx.xx.xx', $this->ip_address);
}
}
2 changes: 1 addition & 1 deletion resources/default/js/Pages/Admin/Server/IndexServer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ function getServerWebQueryStatus(serverId) {
<DtRowItem>
<div class="group">
<div class="text-sm filter blur-sm text-gray-900 dark:text-gray-300 group-hover:blur-none duration-300 cursor-text">
{{ item.ip_address }} : {{ item.join_port }}
{{ item.masked_ip_address }} : {{ item.join_port }}
</div>
<div class="text-sm text-gray-500 dark:text-gray-400 filter blur-sm group-hover:blur-none duration-300 cursor-text">
{{
Expand Down

0 comments on commit 59d293b

Please sign in to comment.