diff --git a/installers/plugin_helper.sh b/installers/plugin_helper.sh index 501534be..c980040b 100755 --- a/installers/plugin_helper.sh +++ b/installers/plugin_helper.sh @@ -78,6 +78,25 @@ case "$action" in echo "OK" ;; + "permissions") + [ $# -lt 4 ] && { echo "Usage: $0 permissions "; 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 "; exit 1; } diff --git a/src/RaspAP/Plugins/PluginInstaller.php b/src/RaspAP/Plugins/PluginInstaller.php index 3845dfa2..753b1b2f 100644 --- a/src/RaspAP/Plugins/PluginInstaller.php +++ b/src/RaspAP/Plugins/PluginInstaller.php @@ -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") .''; } - + $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. ''; - $version = htmlspecialchars($manifestData['version'] ?? 'N/A'); $description = htmlspecialchars($manifestData['description'] ?? 'No description available'); diff --git a/templates/system.php b/templates/system.php index fd4485f5..c54c778d 100755 --- a/templates/system.php +++ b/templates/system.php @@ -149,7 +149,6 @@ - @@ -164,7 +163,7 @@ - +