mirror of
https://github.com/billz/raspap-webgui.git
synced 2025-07-07 16:47:41 +02:00
Merge pull request #1851 from RaspAP/feat/plugin-installer-ex
Extends PluginInstaller w/ setFilePermissions()
This commit is contained in:
commit
98e753ffa1
@ -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; }
|
||||
|
||||
|
@ -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
|
||||
*
|
||||
@ -503,7 +539,7 @@ class PluginInstaller
|
||||
name="install-plugin" data-bs-toggle="modal" data-bs-target="#install-user-plugin"
|
||||
data-plugin-manifest="' .$manifest. '" data-repo-public="' .$this->repoPublic. '">' . _("Details") .'</button>';
|
||||
}
|
||||
|
||||
|
||||
$icon = htmlspecialchars($manifestData['icon'] ?? '');
|
||||
$pluginDocs = htmlspecialchars($manifestData['plugin_docs'] ?? '');
|
||||
$nameText = htmlspecialchars($manifestData['name'] ?? 'Unknown Plugin');
|
||||
@ -511,7 +547,6 @@ class PluginInstaller
|
||||
.$pluginDocs
|
||||
.'" target="_blank">'
|
||||
.$nameText. '</a>';
|
||||
|
||||
$version = htmlspecialchars($manifestData['version'] ?? 'N/A');
|
||||
$description = htmlspecialchars($manifestData['description'] ?? 'No description available');
|
||||
|
||||
|
@ -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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user