Passed
Push — master ( e69c39...874aa5 )
by Stefano
01:23
created

SystemInfoController::index()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 6
rs 10
1
<?php
2
/**
3
 * BEdita, API-first content management framework
4
 * Copyright 2023 Atlas Srl, Chialab Srl
5
 *
6
 * This file is part of BEdita: you can redistribute it and/or modify
7
 * it under the terms of the GNU Lesser General Public License as published
8
 * by the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * See LICENSE.LGPL or <http://gnu.org/licenses/lgpl-3.0.html> for more details.
12
 */
13
namespace App\Controller\Admin;
14
15
use BEdita\SDK\BEditaClientException;
16
use Cake\Core\Configure;
17
use Cake\Http\Response;
18
use Cake\Utility\Hash;
19
use Twig\Environment;
20
21
/**
22
 * System info Controller
23
 */
24
class SystemInfoController extends AdministrationBaseController
25
{
26
    /**
27
     * @inheritDoc
28
     */
29
    public function index(): ?Response
30
    {
31
        $this->set('system_info', $this->getSystemInfo());
32
        $this->set('api_info', $this->getApiInfo());
33
34
        return null;
35
    }
36
37
    /**
38
     * Get system info.
39
     *
40
     * @return array
41
     */
42
    public function getSystemInfo(): array
43
    {
44
        return [
45
            'Version' => Configure::read('Manager.version'),
46
            'CakePHP' => Configure::version(),
47
            'PHP' => phpversion(),
48
            'Twig' => Environment::VERSION,
49
            'Vuejs' => '',
50
            'Operating System' => php_uname(),
51
            'PHP Server API' => php_sapi_name(),
52
            'Extensions' => get_loaded_extensions(),
53
            'Extensions info' => get_loaded_extensions(true),
54
            'Memory limit' => ini_get('memory_limit'),
55
            'Post max size' => sprintf('%dM', intVal(substr(ini_get('post_max_size'), 0, -1))),
56
            'Upload max size' => sprintf('%dM', intVal(substr(ini_get('upload_max_filesize'), 0, -1))),
57
        ];
58
    }
59
60
    /**
61
     * Get api info from API server.
62
     *
63
     * @return array
64
     */
65
    public function getApiInfo(): array
66
    {
67
        $info = [
68
            'Url' => Configure::read('API.apiBaseUrl'),
69
            'Version' => Hash::get((array)$this->viewBuilder()->getVar('project'), 'version'),
70
        ];
71
        try {
72
            $info = (array)Hash::get(
73
                $this->apiClient->get('/admin/sysinfo'),
74
                'meta.info'
75
            );
76
        } catch (BEditaClientException $e) {
77
            $this->log($e->getMessage(), 'error');
78
        }
79
80
        return $info;
81
    }
82
}
83