|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the core-bundle package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) 2022 WEBEWEB |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace WBW\Bundle\CoreBundle\Controller; |
|
13
|
|
|
|
|
14
|
|
|
use Doctrine\DBAL\Connection; |
|
15
|
|
|
use Doctrine\Persistence\ManagerRegistry; |
|
16
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
|
17
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
18
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
19
|
|
|
use WBW\Library\System\System; |
|
20
|
|
|
use WBW\Library\Types\Helper\ArrayHelper; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Host controller. |
|
24
|
|
|
* |
|
25
|
|
|
* @author webeweb <https://github.com/webeweb> |
|
26
|
|
|
* @package WBW\Bundle\CoreBundle\Controller |
|
27
|
|
|
*/ |
|
28
|
|
|
class HostController extends AbstractController { |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Service name. |
|
32
|
|
|
* |
|
33
|
|
|
* @var string |
|
34
|
|
|
*/ |
|
35
|
|
|
const SERVICE_NAME = "wbw.core.controller.host"; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* CPU. |
|
39
|
|
|
* |
|
40
|
|
|
* @return Response Returns the response. |
|
41
|
|
|
*/ |
|
42
|
|
|
public function cpuAction(): Response { |
|
43
|
|
|
|
|
44
|
|
|
$info = System::getCpu(); |
|
45
|
|
|
$data = $this->newDefaultJsonResponseData(true, $info->jsonSerialize()); |
|
46
|
|
|
|
|
47
|
|
|
return new JsonResponse($data); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Hard disks. |
|
52
|
|
|
* |
|
53
|
|
|
* @return Response Returns the response. |
|
54
|
|
|
*/ |
|
55
|
|
|
public function hardDisksAction(): Response { |
|
56
|
|
|
|
|
57
|
|
|
$info = System::getHardDisks(); |
|
58
|
|
|
$data = $this->newDefaultJsonResponseData(true, $info); |
|
59
|
|
|
|
|
60
|
|
|
return new JsonResponse($data); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Memory. |
|
65
|
|
|
* |
|
66
|
|
|
* @return Response Returns the response. |
|
67
|
|
|
*/ |
|
68
|
|
|
public function memoryAction(): Response { |
|
69
|
|
|
|
|
70
|
|
|
$info = System::getMemory(); |
|
71
|
|
|
$data = $this->newDefaultJsonResponseData(true, $info->jsonSerialize()); |
|
72
|
|
|
|
|
73
|
|
|
return new JsonResponse($data); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Retrieve the information "database". |
|
78
|
|
|
* |
|
79
|
|
|
* @return array Returns the information "database". |
|
80
|
|
|
*/ |
|
81
|
|
|
public function retrieveInformationDatabase(): array { |
|
82
|
|
|
|
|
83
|
|
|
/** @var ManagerRegistry $doctrine */ |
|
84
|
|
|
$doctrine = $this->container->get("doctrine"); |
|
85
|
|
|
|
|
86
|
|
|
/** @var Connection $connection */ |
|
87
|
|
|
$connection = $doctrine->getConnection(); |
|
88
|
|
|
$parameters = $connection->getParams(); |
|
89
|
|
|
|
|
90
|
|
|
return [ |
|
91
|
|
|
"driver" => $parameters["driver"], |
|
92
|
|
|
"dbname" => ArrayHelper::get($parameters, "dbname"), |
|
93
|
|
|
"host" => $parameters["host"], |
|
94
|
|
|
"port" => $parameters["port"], |
|
95
|
|
|
"user" => $parameters["user"], |
|
96
|
|
|
"serverVersion" => ArrayHelper::get($parameters, "serverVersion"), |
|
97
|
|
|
]; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Retrieve the information "server". |
|
102
|
|
|
* |
|
103
|
|
|
* @param Request $request The request. |
|
104
|
|
|
* @return array Returns the information "server". |
|
105
|
|
|
*/ |
|
106
|
|
|
public function retrieveInformationServer(Request $request): array { |
|
107
|
|
|
|
|
108
|
|
|
return [ |
|
109
|
|
|
"maxExecutionTime" => ini_get("max_execution_time"), |
|
110
|
|
|
"memoryLimit" => ini_get("memory_limit"), |
|
111
|
|
|
"phpUname" => implode(" ", [ |
|
112
|
|
|
php_uname('s'), |
|
113
|
|
|
php_uname('v'), |
|
114
|
|
|
php_uname('m'), |
|
115
|
|
|
]), |
|
116
|
|
|
"phpVersion" => phpversion(), |
|
117
|
|
|
"serverSoftware" => $request->server->get("SERVER_SOFTWARE"), |
|
118
|
|
|
]; |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
|