-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Disks filtering by mount points from a configurable parameter #572
base: master
Are you sure you want to change the base?
Changes from all commits
715f615
bf89390
1d8c635
87b33fa
bfa19fd
8dbf2bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -32,10 +32,12 @@ | |||||
|
||||||
class Os implements IOperatingSystem { | ||||||
private IOperatingSystem $backend; | ||||||
private IConfig $config; | ||||||
|
||||||
public function __construct(IConfig $config) { | ||||||
$restrictedMode = $config->getAppValue('serverinfo', 'restricted_mode', 'no') === 'yes'; | ||||||
$this->backend = $this->getBackend($restrictedMode ? 'Dummy' : PHP_OS); | ||||||
$this->config = $config; | ||||||
} | ||||||
|
||||||
public function supported(): bool { | ||||||
|
@@ -70,7 +72,47 @@ public function getUptime(): int { | |||||
} | ||||||
|
||||||
public function getDiskInfo(): array { | ||||||
return $this->backend->getDiskInfo(); | ||||||
$disks = $this->backend->getDiskInfo(); | ||||||
$filters = $this->config->getSystemValue('serverinfo_disk_filter_paths', null); | ||||||
if ($filters === null) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
If you follow my suggestion from above, don't forget to replace null with empty string. |
||||||
return $disks; | ||||||
} | ||||||
// apply defined filters to restrict the list of disks according to their mount point | ||||||
$filtered_disks = []; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
CamelCase please ;) |
||||||
foreach (explode(':', $filters) as $filter) { | ||||||
// convert special filters to their corresponding paths | ||||||
switch ($filter) { | ||||||
case 'DOCROOT': $path = ''; | ||||||
if (isset($_SERVER['SCRIPT_FILENAME'])) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't like the docroot special filter because it might be empty. A good alternative might be \OC::$SERVERROOT which always point to the nextcloud installation dir. |
||||||
$path = dirname($_SERVER['SCRIPT_FILENAME']); | ||||||
} | ||||||
elseif (isset($_SERVER['DOCUMENT_ROOT'])) { | ||||||
$path = $_SERVER['DOCUMENT_ROOT']; | ||||||
} | ||||||
break; | ||||||
case 'DATADIR': $path = $this->config->getSystemValue('datadirectory', ''); | ||||||
break; | ||||||
case 'TEMPDIR': $path = $this->config->getSystemValue('tempdirectory', ''); | ||||||
break; | ||||||
case 'LOGSDIR': $path = dirname($this->config->getSystemValue('logfile', '')); | ||||||
break; | ||||||
default: $path = $filter; | ||||||
} | ||||||
// find the disk whose mount point contains the filtering path | ||||||
$find_index = null; | ||||||
$find_mount = ''; | ||||||
foreach ($disks as $index => $disk) { | ||||||
$mount = $disk->getMount(); | ||||||
if ((strncmp($path, $mount, strlen($mount)) === 0) && (strlen($mount) >= strlen($find_mount))) { | ||||||
$find_mount = $mount; | ||||||
$find_index = $index; | ||||||
} | ||||||
} | ||||||
if ($find_index !== null) { | ||||||
$filtered_disks[ $find_index ] = $disks[ $find_index ]; | ||||||
} | ||||||
} | ||||||
return $filtered_disks; | ||||||
} | ||||||
|
||||||
/** | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have two configuration systems in Nextcloud: SystemConfig and AppConfig
I'm using AppConfig here in serverinfo nowadays.
You can also use occ to configure it.
For example like https://github.com/nextcloud/serverinfo?tab=readme-ov-file#restricted-mode--nextcloud-28