1
0
mirror of https://github.com/billz/raspap-webgui.git synced 2025-07-07 20:57:41 +02:00

Merge pull request #1851 from RaspAP/feat/plugin-installer-ex

Extends PluginInstaller w/ setFilePermissions()
This commit is contained in:
Bill Zimmerman 2025-05-12 06:50:19 +02:00 committed by GitHub
commit 98e753ffa1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 57 additions and 4 deletions

View File

@ -78,6 +78,25 @@ case "$action" in
echo "OK"
;;
"permissions")
[ $# -lt 4 ] && { echo "Usage: $0 permissions <filepath> <user> <group> <mode>"; exit 1; }
filepath="$1"
user="$2"
group="$3"
mode="$4"
if [ ! -e "$filepath" ]; then
echo "File not found: $filepath" >&2
exit 1
fi
chown "$user:$group" "$filepath" || exit 1
chmod "$mode" "$filepath" || exit 1
echo "OK"
;;
"javascript")
[ $# -lt 2 ] && { echo "Usage: $0 javascript <source> <destination>"; exit 1; }

View File

@ -205,6 +205,10 @@ class PluginInstaller
$this->copyConfigFiles($manifest['configuration'], $pluginDir);
$rollbackStack[] = 'removeConfigFiles';
}
if (!empty($manifest['permissions'])) {
$this->setFilePermissions($manifest['permissions']);
$rollbackStack[] = 'revertFilePermissions';
}
if (!empty($manifest['javascript'])) {
$this->copyJavaScriptFiles($manifest['javascript'], $pluginDir);
$rollbackStack[] = 'removeJavaScript';
@ -319,6 +323,38 @@ class PluginInstaller
}
}
/**
* Sets permissions on a specified file, including owner/group and mode
*
* @param array $permissions): void
*/
private function setFilePermissions(array $permissions): void
{
foreach ($permissions as $entry) {
$file = $entry['file'] ?? null;
$owner = $entry['owner'] ?? null;
$group = $entry['group'] ?? null;
$mode = $entry['mode'] ?? null;
if (!$file || !$owner || !$group || !$mode) {
error_log("Incomplete permission entry for file: " . json_encode($entry));
continue;
}
$cmd = escapeshellcmd('sudo '.RASPI_CONFIG.'/plugins/plugin_helper.sh') .
' permissions ' .
escapeshellarg($file) .' '.
escapeshellarg($owner) .' '.
escapeshellarg($group) .' '.
escapeshellarg($mode);
exec($cmd . ' 2>&1', $output, $return);
if ($return !== 0) {
throw new \Exception("Failed to set permissions on $file: " . implode("\n", $output));
}
}
}
/**
* Copies plugin JavaScript files to their destination
*
@ -511,7 +547,6 @@ class PluginInstaller
.$pluginDocs
.'" target="_blank">'
.$nameText. '</a>';
$version = htmlspecialchars($manifestData['version'] ?? 'N/A');
$description = htmlspecialchars($manifestData['description'] ?? 'No description available');

View File

@ -149,7 +149,6 @@
<tr>
<th><?php echo _("Configuration files"); ?></th>
<td><small><code><span id="plugin-configuration" class="mb-0"></span></code></small></td>
</td>
</tr>
<tr>
<th><?php echo _("Signed Packages"); ?></th>
@ -164,7 +163,7 @@
<td><small><code><span id="plugin-javascript" class="mb-0"></span></code></small></td>
</tr>
<tr>
<th><?php echo _("Permissions"); ?></th>
<th><?php echo _("Sudoers"); ?></th>
<td><small><code><span id="plugin-sudoers" class="mb-0"></span></code></small></td>
</tr>
<tr>