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