Skip to content

Commit a5998e2

Browse files
committed
feat: add phpinfo
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
1 parent d9d169b commit a5998e2

File tree

6 files changed

+82
-11
lines changed

6 files changed

+82
-11
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,7 @@ php occ serverinfo:update-storage-statistics -v --output=json_pretty
127127
"num_storages_other": 33
128128
}
129129
```
130+
131+
Show phpinfo
132+
133+
``php occ config:app:set --value=yes serverinfo phpinfo``

appinfo/routes.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
return [
3535
'routes' => [
3636
['name' => 'page#update', 'url' => '/update', 'verb' => 'GET'],
37+
['name' => 'page#phpinfo', 'url' => '/phpinfo', 'verb' => 'GET'],
3738
],
3839
'ocs' => [
3940
['name' => 'api#info', 'url' => '/api/v1/info', 'verb' => 'GET'],

lib/Controller/PageController.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,22 @@
2424

2525
namespace OCA\ServerInfo\Controller;
2626

27+
use OCA\ServerInfo\PhpInfoResponse;
2728
use OCP\AppFramework\Http\JSONResponse;
29+
use OCP\AppFramework\Http\NotFoundResponse;
30+
use OCP\AppFramework\Http\Response;
31+
use OCP\IConfig;
2832
use OCP\IRequest;
2933
use OCP\AppFramework\Controller;
3034
use OCA\ServerInfo\SystemStatistics;
3135

3236
class PageController extends Controller {
33-
private SystemStatistics $systemStatistics;
34-
35-
/**
36-
* ApiController constructor.
37-
*/
3837
public function __construct(string $appName,
3938
IRequest $request,
40-
SystemStatistics $systemStatistics
39+
private SystemStatistics $systemStatistics,
40+
private IConfig $config,
4141
) {
4242
parent::__construct($appName, $request);
43-
44-
$this->systemStatistics = $systemStatistics;
4543
}
4644

4745
/**
@@ -54,4 +52,14 @@ public function update(): JSONResponse {
5452

5553
return new JSONResponse($data);
5654
}
55+
56+
/**
57+
* @NoCSRFRequired
58+
*/
59+
public function phpinfo(): Response {
60+
if ($this->config->getAppValue($this->appName, 'phpinfo', 'no') === 'yes') {
61+
return new PhpInfoResponse();
62+
}
63+
return new NotFoundResponse();
64+
}
5765
}

lib/PhpInfoResponse.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright Copyright (c) 2023 Daniel Kesselberg <mail@danielkesselberg.de>
7+
*
8+
* @author Daniel Kesselberg <mail@danielkesselberg.de>
9+
*
10+
* @license AGPL-3.0-or-later
11+
*
12+
* This code is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU Affero General Public License, version 3,
14+
* as published by the Free Software Foundation.
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU Affero General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU Affero General Public License, version 3,
22+
* along with this program. If not, see <http://www.gnu.org/licenses/>
23+
*
24+
*/
25+
26+
namespace OCA\ServerInfo;
27+
28+
use OCP\AppFramework\Http\ContentSecurityPolicy;
29+
use OCP\AppFramework\Http\FeaturePolicy;
30+
use OCP\AppFramework\Http\Response;
31+
32+
class PhpInfoResponse extends Response {
33+
public function __construct() {
34+
parent::__construct();
35+
36+
$this->setContentSecurityPolicy(new ContentSecurityPolicy());
37+
$this->setFeaturePolicy(new FeaturePolicy());
38+
}
39+
40+
public function render() {
41+
ob_start();
42+
phpinfo(INFO_ALL & ~INFO_ENVIRONMENT & ~INFO_VARIABLES);
43+
return ob_get_clean();
44+
}
45+
}

lib/Settings/AdminSettings.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
use OCA\ServerInfo\StorageStatistics;
3434
use OCA\ServerInfo\SystemStatistics;
3535
use OCP\AppFramework\Http\TemplateResponse;
36+
use OCP\IConfig;
3637
use OCP\IL10N;
3738
use OCP\IURLGenerator;
3839
use OCP\Settings\ISettings;
@@ -56,7 +57,8 @@ public function __construct(Os $os,
5657
DatabaseStatistics $databaseStatistics,
5758
ShareStatistics $shareStatistics,
5859
SessionStatistics $sessionStatistics,
59-
SystemStatistics $systemStatistics
60+
SystemStatistics $systemStatistics,
61+
private IConfig $config
6062
) {
6163
$this->os = $os;
6264
$this->l = $l;
@@ -86,7 +88,9 @@ public function getForm(): TemplateResponse {
8688
'database' => $this->databaseStatistics->getDatabaseStatistics(),
8789
'activeUsers' => $this->sessionStatistics->getSessionStatistics(),
8890
'system' => $this->systemStatistics->getSystemStatistics(),
89-
'thermalzones' => $this->os->getThermalZones()
91+
'thermalzones' => $this->os->getThermalZones(),
92+
'phpinfo' => $this->config->getAppValue('serverinfo', 'phpinfo', 'no') === 'yes',
93+
'phpinfoUrl' => $this->urlGenerator->linkToRoute('serverinfo.page.phpinfo')
9094
];
9195

9296
return new TemplateResponse('serverinfo', 'settings-admin', $params);

templates/settings-admin.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,16 @@ function FormatMegabytes(int $byte): string {
4343
return number_format($byte, 2, '.', '.') . ' ' . $unim[$count];
4444
}
4545

46+
/** @var array $_ */
47+
4648
/** @var Memory $memory */
4749
$memory = $_['memory'];
4850
/** @var Disk[] $disks */
4951
$disks = $_['diskinfo'];
5052
/** @var NetInterface[] $interfaces */
5153
$interfaces = $_['networkinterfaces'];
54+
/** @var bool $phpinfo */
55+
$phpinfo = $_['phpinfo'];
5256

5357
?>
5458

@@ -356,7 +360,7 @@ function FormatMegabytes(int $byte): string {
356360
<p>
357361
<?php p($l->t('Upload max size:')); ?>
358362
<em id="phpUploadMaxSize"><?php p($_['php']['upload_max_filesize']); ?></em>
359-
</p>
363+
</p>
360364
<p>
361365
<?php p($l->t('OPcache Revalidate Frequency:')); ?>
362366
<em id="phpOpcacheRevalidateFreq"><?php p($_['php']['opcache_revalidate_freq']); ?></em>
@@ -365,6 +369,11 @@ function FormatMegabytes(int $byte): string {
365369
<?php p($l->t('Extensions:')); ?>
366370
<em id="phpExtensions"><?php p($_['php']['extensions'] !== null ? implode(', ', $_['php']['extensions']) : $l->t('Unable to list extensions')); ?></em>
367371
</p>
372+
<?php if ($phpinfo): ?>
373+
<p>
374+
<a target="_blank" href="<?= $_['phpinfoUrl'] ?>"><?php p($l->t('Show phpinfo')) ?></a>
375+
</p>
376+
<?php endif; ?>
368377
</div>
369378
</div>
370379
</div>

0 commit comments

Comments
 (0)