Skip to content

Commit 8d1f371

Browse files
committed
Update module
1 parent 1bb3c3b commit 8d1f371

14 files changed

+175
-63
lines changed
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace GameapModules\Ftp\Exceptions;
4+
5+
use Illuminate\Http\Request;
6+
use Symfony\Component\HttpFoundation\Response;
7+
8+
class FTPCommandNotFoundException extends FtpModuleException
9+
{
10+
public function render(Request $request): Response
11+
{
12+
return redirect()->route('admin.ftp.accounts')
13+
->with('error', __('ftp::ftp_accounts.command_not_found_error'));
14+
}
15+
}

Http/Controllers/FtpAccountsController.php

+18-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace GameapModules\Ftp\Http\Controllers;
44

55
use Gameap\Exceptions\GameapException;
6+
use Gameap\Models\Server;
67
use GameapModules\Ftp\Exceptions\ExecuteCommandException;
78
use GameapModules\Ftp\Http\Requests\FtpAccountUpdateRequest;
89
use GameapModules\Ftp\Repositories\FtpAccountRepository;
@@ -64,10 +65,18 @@ public function create()
6465
* @return RedirectResponse
6566
* @throws GameapException
6667
*/
67-
public function store(FtpAccountCreateRequest $request)
68+
public function store(FtpAccountCreateRequest $request): RedirectResponse
6869
{
70+
$attributes = $request->all();
71+
72+
if (!empty($attributes['game_server_id'])) {
73+
/** @var Server $server */
74+
$server = Server::findOrFail($attributes['game_server_id']);
75+
$attributes['user'] = $server->su_user;
76+
}
77+
6978
try {
70-
$this->repository->store($request->all());
79+
$this->repository->store($attributes);
7180
} catch (ExecuteCommandException $exception) {
7281
return redirect()->route('admin.ftp')
7382
->with('error', __('ftp::ftp_accounts.create_fail_msg'));
@@ -77,6 +86,13 @@ public function store(FtpAccountCreateRequest $request)
7786
->with('success', __('ftp::ftp_accounts.create_success_msg'));
7887
}
7988

89+
public function show(FtpAccount $ftpAccount)
90+
{
91+
return view('ftp::ftp_accounts.view', [
92+
'ftpAccount' => $ftpAccount
93+
]);
94+
}
95+
8096
/**
8197
* Show the form for editing the specified resource.
8298
*

Http/Requests/FtpAccountCreateRequest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ public function rules()
1515
'port' => 'integer',
1616
'username' => 'required',
1717
'password' => 'required',
18+
'game_server_id' => 'exists:servers,id',
1819
'dir' => 'required'
1920
];
2021
}
21-
}
22+
}

Models/FtpAccount.php

+14-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Gameap\Models\DedicatedServer;
77
use Gameap\Models\User;
88
use Gameap\Traits\Encryptable;
9+
use Illuminate\Database\Eloquent\Relations\BelongsTo;
910

1011
/**
1112
* Class FtpAccount
@@ -20,6 +21,8 @@
2021
* @property string $username
2122
* @property string $password
2223
* @property string $dir
24+
*
25+
* @property string $link
2326
*/
2427
class FtpAccount extends Model
2528
{
@@ -36,13 +39,22 @@ class FtpAccount extends Model
3639
'password',
3740
];
3841

39-
public function dedicatedServer()
42+
public function dedicatedServer(): BelongsTo
4043
{
4144
return $this->belongsTo(DedicatedServer::class, 'ds_id');
4245
}
4346

44-
public function user()
47+
public function user(): BelongsTo
4548
{
4649
return $this->belongsTo(User::class);
4750
}
51+
52+
public function getLinkAttribute(): string
53+
{
54+
$portString = $this->port === 21
55+
? ''
56+
: ":{$this->port}";
57+
58+
return "ftp://{$this->username}:{$this->password}@{$this->host}{$portString}";
59+
}
4860
}

Repositories/FtpAccountRepository.php

+10-8
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
use GameapModules\Ftp\Exceptions\ExecuteCommandException;
88
use GameapModules\Ftp\Models\FtpAccount;
99
use GameapModules\Ftp\Services\CommandsService;
10-
use Cache;
10+
use Illuminate\Support\Facades\Cache;
1111

1212
class FtpAccountRepository
1313
{
14-
const EXEC_SUCCESS_CODE = 0;
14+
public const EXEC_SUCCESS_CODE = 0;
1515

16-
const CACHE_TTL_SECONDS = 300;
17-
const CACHE_LAST_ERROR_KEY = 'ftp:last_error';
16+
public const CACHE_TTL_SECONDS = 300;
17+
public const CACHE_LAST_ERROR_KEY = 'ftp:last_error';
1818

1919
/**
2020
* @var CommandsService
@@ -43,6 +43,7 @@ public function store(array $attributes)
4343
$attributes['username'],
4444
$attributes['password'],
4545
$attributes['dir'],
46+
$attributes['user'] ?? '',
4647
$exitCode
4748
);
4849

@@ -60,7 +61,7 @@ public function store(array $attributes)
6061
* @throws ExecuteCommandException
6162
* @throws GameapException
6263
*/
63-
function update(int $id, array $attributes)
64+
public function update(int $id, array $attributes)
6465
{
6566
$ftpAccount = FtpAccount::findOrFail($id);
6667

@@ -69,6 +70,7 @@ function update(int $id, array $attributes)
6970
$attributes['username'] ?? $ftpAccount->username,
7071
$attributes['password'],
7172
$attributes['dir'],
73+
$attributes['user'] ?? '',
7274
$exitCode
7375
);
7476

@@ -86,7 +88,7 @@ function update(int $id, array $attributes)
8688
* @throws GameapException
8789
* @throws Exception
8890
*/
89-
function destroy(FtpAccount $ftpAccount)
91+
public function destroy(FtpAccount $ftpAccount)
9092
{
9193
$result = $this->commandsService->deleteAccount(
9294
$ftpAccount->ds_id,
@@ -105,8 +107,8 @@ function destroy(FtpAccount $ftpAccount)
105107
/**
106108
* @return mixed
107109
*/
108-
function lastError()
110+
public function lastError()
109111
{
110112
return Cache::get(self::CACHE_LAST_ERROR_KEY);
111113
}
112-
}
114+
}

Resources/lang/en/ftp_accounts.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
return [
44
'title_create' => 'Create FTP Account',
55
'title_edit' => 'Edit FTP Account',
6+
'title_view' => 'View FTP Account',
67

78
'username' => 'FTP Username',
89
'password' => 'FTP Password',
10+
'link' => 'Link to connect',
911

1012
'create_success_msg' => 'FTP Account created successfully',
1113
'update_success_msg' => 'FTP Account updated successfully',
@@ -15,6 +17,10 @@
1517
'update_fail_msg' => 'Error updating FTP account. See latest errors for details',
1618
'delete_fail_msg' => 'Error deleting FTP account. See latest errors for details',
1719

20+
'command_not_found_error' => 'Failed to get the command. Perhaps a dedicated server is not configured, or the command is missing.',
21+
22+
'select_dedicated_server' => 'Select a dedicated server first to select a game server',
23+
1824
'last_error' => 'Last Error',
1925
'no_last_errors' => 'No errors',
20-
];
26+
];

Resources/lang/ru/ftp_accounts.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
return [
44
'title_create' => 'Создание FTP аккаунта',
55
'title_edit' => 'Редактирование FTP аккаунта',
6+
'title_view' => 'Просмотр FTP аккаунта',
67

78
'username' => 'Имя пользователя FTP',
89
'password' => 'Пароль FTP',
10+
'link' => 'Ссылка для подключения',
911

1012
'create_success_msg' => 'FTP аккаунт успешно создан',
1113
'update_success_msg' => 'FTP аккаунт успешно обновлён',
@@ -15,6 +17,10 @@
1517
'update_fail_msg' => 'Ошибка обновления FTP аккаунта. Подробности можете посмотреть в последних ошибках.',
1618
'delete_fail_msg' => 'Ошибка удаления FTP аккаунта. Подробности можете посмотреть в последних ошибках.',
1719

20+
'command_not_found_error' => 'Не удалось получить команду. Возможно выделенный сервер не настроен, либо не указана команда.',
21+
22+
'select_dedicated_server' => 'Для выбора игрового сервера необходимо сначала выбрать выделенный сервер.',
23+
1824
'last_error'=> 'Последняя ошибка',
1925
'no_last_errors' => 'Ошибок нет',
20-
];
26+
];

Resources/views/ftp_accounts/create.blade.php

+28-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@
3636
</div>
3737
</div>
3838
</div>
39+
</div>
40+
</div>
41+
</div>
42+
<div class="col-6">
43+
<div class="card">
44+
<div class="card-body">
45+
<server-selector></server-selector>
3946

4047
{{ Form::bsText('dir') }}
4148
</div>
@@ -52,5 +59,25 @@
5259
@endsection
5360

5461
@section('footer-scripts')
62+
<script>
63+
const dirPathChanger = {
64+
computed: {
65+
selectedServerId: function () { return window.gameapStore.state.servers.serverId }
66+
},
67+
watch: {
68+
selectedServerId() {
69+
const server = window.gameapStore.getters['servers/selectedServer'];
70+
if (server !== null) {
71+
$('input[name=dir]').val(server.full_path);
72+
}
73+
}
74+
}
75+
};
76+
77+
new (window.Vue.extend({
78+
mixins: [dirPathChanger]
79+
}));
80+
81+
</script>
5582
<script src="{{ URL::asset('/js/formHelpers.js') }}"></script>
56-
@endsection
83+
@endsection

Resources/views/ftp_accounts/list.blade.php

-35
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
@php
2+
/**
3+
* @var $ftpAccount \GameapModules\Ftp\Models\FtpAccount
4+
**/
5+
@endphp
6+
7+
@php($title = __('ftp::ftp_accounts.title_view'))
8+
9+
@extends('layouts.main')
10+
11+
@section('breadclumbs')
12+
<ol class="breadcrumb">
13+
<li class="breadcrumb-item"><a href="/">GameAP</a></li>
14+
<li class="breadcrumb-item"><a href="{{ route('admin.ftp') }}">FTP</a></li>
15+
<li class="breadcrumb-item active">{{ __('ftp::ftp_accounts.title_view') }}</li>
16+
</ol>
17+
@endsection
18+
19+
@section('content')
20+
<div class="row">
21+
<div class="col-md-12">
22+
<table class="table table-striped table-bordered detail-view">
23+
<tbody>
24+
<tr>
25+
<th>{{ __('labels.host') }} : {{ __('labels.port') }}</th>
26+
<td>{{ $ftpAccount->host }}:{{ $ftpAccount->port }}</td>
27+
</tr>
28+
<tr>
29+
<th>{{ __('ftp::ftp_accounts.username') }}</th>
30+
<td>{{ $ftpAccount->username }}</td>
31+
</tr>
32+
<tr>
33+
<th>{{ __('labels.password') }}</th>
34+
<td>{{ $ftpAccount->password }}</td>
35+
</tr>
36+
<tr>
37+
<th>{{ __('ftp::ftp_accounts.link') }}</th>
38+
<td><a href="{{ $ftpAccount->link }}">{{ $ftpAccount->link }}</a></td>
39+
</tr>
40+
41+
</tbody>
42+
</table>
43+
</div>
44+
</div>
45+
@endsection

Resources/views/index.blade.php

+8-4
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,20 @@
2626

2727
@include('components.grid', [
2828
'modelsList' => $ftpAccounts,
29-
'labels' => [ __('ftp::ftp_accounts.username'), __('labels.host'), __('servers.dedicated_server'), __('users.user')],
29+
'labels' => [
30+
__('ftp::ftp_accounts.username'),
31+
__('labels.host') . ':' . __('labels.port'),
32+
__('servers.dedicated_server')
33+
],
3034
'attributes' => [
3135
'username',
32-
'host',
36+
['twoSeparatedValues', ['host', ':', 'port']],
3337
'dedicatedServer.name',
34-
'user.login',
3538
],
39+
'viewRoute' => 'admin.ftp.accounts.show',
3640
'editRoute' => 'admin.ftp.accounts.edit',
3741
'destroyRoute' => 'admin.ftp.accounts.destroy',
3842
])
3943

4044
{!! $ftpAccounts->links() !!}
41-
@endsection
45+
@endsection

Routes/web.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
Route::name('admin.ftp')->resource('ftp/accounts', 'FtpAccountsController', [
1818
'as' => 'admin',
1919
'parameters' => ['accounts' => 'ftp_account'],
20-
'except' => ['show']
2120
]);
2221

2322
Route::name('admin.ftp.accounts.last_error')
@@ -28,4 +27,4 @@
2827

2928
Route::name('admin.ftp.commands.autosetup')
3029
->post('ftp/autosetup', 'FtpCommandsController@autosetup');
31-
});
30+
});

0 commit comments

Comments
 (0)