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 = 'run-terminal'; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Show terminal index. |
21
|
|
|
* |
22
|
|
|
* @param \Illuminate\Http\Request $request |
23
|
|
|
* @param \Cortex\Console\Services\Terminal $terminal |
24
|
|
|
* |
25
|
|
|
* @throws \Exception |
26
|
|
|
* |
27
|
|
|
* @return \Illuminate\View\View |
28
|
|
|
*/ |
29
|
|
|
public function index(Request $request, Terminal $terminal) |
30
|
|
|
{ |
31
|
|
|
$token = null; |
32
|
|
|
|
33
|
|
|
if ($request->hasSession() === true) { |
34
|
|
|
$token = $request->session()->token(); |
|
|
|
|
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
$terminal->call('list --ansi'); |
38
|
|
|
$options = json_encode([ |
39
|
|
|
'username' => 'LARAVEL', |
40
|
|
|
'hostname' => php_uname('n'), |
41
|
|
|
'os' => PHP_OS, |
42
|
|
|
'csrfToken' => $token, |
43
|
|
|
'helpInfo' => $terminal->output(), |
44
|
|
|
'basePath' => app()->basePath(), |
45
|
|
|
'environment' => app()->environment(), |
46
|
|
|
'version' => app()->version(), |
47
|
|
|
'endpoint' => route('adminarea.console.terminal.execute'), |
48
|
|
|
'interpreters' => [ |
49
|
|
|
'mysql' => 'mysql', |
50
|
|
|
'artisan tinker' => 'tinker', |
51
|
|
|
'tinker' => 'tinker', |
52
|
|
|
], |
53
|
|
|
'confirmToProceed' => [ |
54
|
|
|
'artisan' => [ |
55
|
|
|
'migrate', |
56
|
|
|
'migrate:install', |
57
|
|
|
'migrate:refresh', |
58
|
|
|
'migrate:reset', |
59
|
|
|
'migrate:rollback', |
60
|
|
|
'db:seed', |
61
|
|
|
], |
62
|
|
|
], |
63
|
|
|
]); |
64
|
|
|
|
65
|
|
|
return view('cortex/console::adminarea.pages.terminal', compact('options')); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Process the form for store/update of the given resource. |
70
|
|
|
* |
71
|
|
|
* @param \Illuminate\Http\Request $request |
72
|
|
|
* |
73
|
|
|
* @throws \Exception |
74
|
|
|
* |
75
|
|
|
* @return \Illuminate\Http\JsonResponse |
76
|
|
|
*/ |
77
|
|
|
public function execute(Terminal $terminal, Request $request) |
78
|
|
|
{ |
79
|
|
|
$error = $terminal->call($request->get('command')); |
80
|
|
|
|
81
|
|
|
return response()->json([ |
|
|
|
|
82
|
|
|
'jsonrpc' => $request->get('jsonrpc'), |
83
|
|
|
'id' => $request->get('id'), |
84
|
|
|
'result' => $terminal->output(), |
85
|
|
|
'error' => $error, |
86
|
|
|
]); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Render exception. |
91
|
|
|
* |
92
|
|
|
* @param \Exception $exception |
93
|
|
|
* |
94
|
|
|
* @return \Illuminate\View\View |
95
|
|
|
*/ |
96
|
|
|
protected function renderException(Exception $exception) |
97
|
|
|
{ |
98
|
|
|
return view('cortex/console::adminarea.pages.error', ['message' => $exception->getMessage()]); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.