1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Cortex\Console\Http\Controllers\Adminarea; |
6
|
|
|
|
7
|
|
|
use Exception; |
8
|
|
|
use Illuminate\Http\Request; |
9
|
|
|
use Cortex\Console\Services\Terminal; |
10
|
|
|
use Cortex\Foundation\Http\Controllers\AuthorizedController; |
11
|
|
|
|
12
|
|
|
class TerminalController extends AuthorizedController |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* {@inheritdoc} |
16
|
|
|
*/ |
17
|
|
|
protected $resource = 'terminal'; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* {@inheritdoc} |
21
|
|
|
*/ |
22
|
|
|
protected $resourceAbilityMap = [ |
23
|
|
|
'index' => 'run', |
24
|
|
|
'execute' => 'run', |
25
|
|
|
]; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Show the form for create/update of the given resource. |
29
|
|
|
* |
30
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
31
|
|
|
*/ |
32
|
|
|
public function index(Terminal $terminal, Request $request) |
33
|
|
|
{ |
34
|
|
|
$token = null; |
35
|
|
|
|
36
|
|
|
if ($request->hasSession() === true) { |
37
|
|
|
$token = $request->session()->token(); |
|
|
|
|
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
$terminal->call('list --ansi'); |
41
|
|
|
$options = json_encode([ |
42
|
|
|
'username' => 'LARAVEL', |
43
|
|
|
'hostname' => php_uname('n'), |
44
|
|
|
'os' => PHP_OS, |
45
|
|
|
'csrfToken' => $token, |
46
|
|
|
'helpInfo' => $terminal->output(), |
47
|
|
|
'basePath' => app()->basePath(), |
48
|
|
|
'environment' => app()->environment(), |
49
|
|
|
'version' => app()->version(), |
50
|
|
|
'endpoint' => route('adminarea.console.terminal.execute'), |
51
|
|
|
'interpreters' => [ |
52
|
|
|
'mysql' => 'mysql', |
53
|
|
|
'artisan tinker' => 'tinker', |
54
|
|
|
'tinker' => 'tinker', |
55
|
|
|
], |
56
|
|
|
'confirmToProceed' => [ |
57
|
|
|
'artisan' => [ |
58
|
|
|
'migrate', |
59
|
|
|
'migrate:install', |
60
|
|
|
'migrate:refresh', |
61
|
|
|
'migrate:reset', |
62
|
|
|
'migrate:rollback', |
63
|
|
|
'db:seed', |
64
|
|
|
], |
65
|
|
|
], |
66
|
|
|
]); |
67
|
|
|
|
68
|
|
|
return view('cortex/console::adminarea.forms.terminal', compact('options')); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Process the form for store/update of the given resource. |
73
|
|
|
* |
74
|
|
|
* @param \Illuminate\Http\Request $request |
75
|
|
|
* |
76
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
77
|
|
|
*/ |
78
|
|
|
public function execute(Terminal $terminal, Request $request) |
79
|
|
|
{ |
80
|
|
|
$error = $terminal->call($request->get('command')); |
81
|
|
|
|
82
|
|
|
return response()->json([ |
83
|
|
|
'jsonrpc' => $request->get('jsonrpc'), |
84
|
|
|
'id' => $request->get('id'), |
85
|
|
|
'result' => $terminal->output(), |
86
|
|
|
'error' => $error, |
87
|
|
|
]); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Render exception. |
92
|
|
|
* |
93
|
|
|
* @param \Exception $exception |
94
|
|
|
* |
95
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
96
|
|
|
*/ |
97
|
|
|
protected function renderException(Exception $exception) |
98
|
|
|
{ |
99
|
|
|
return view('cortex/console::adminarea.forms.error', ['message' => $exception->getMessage()]); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.