mirror of
https://github.com/billz/raspap-webgui.git
synced 2025-12-26 23:26:47 +01:00
Extends PluginInstaller w/ setFilePermissions()
This commit is contained in:
@@ -78,6 +78,25 @@ case "$action" in
|
|||||||
echo "OK"
|
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")
|
"javascript")
|
||||||
[ $# -lt 2 ] && { echo "Usage: $0 javascript <source> <destination>"; exit 1; }
|
[ $# -lt 2 ] && { echo "Usage: $0 javascript <source> <destination>"; exit 1; }
|
||||||
|
|
||||||
|
|||||||
@@ -205,6 +205,10 @@ class PluginInstaller
|
|||||||
$this->copyConfigFiles($manifest['configuration'], $pluginDir);
|
$this->copyConfigFiles($manifest['configuration'], $pluginDir);
|
||||||
$rollbackStack[] = 'removeConfigFiles';
|
$rollbackStack[] = 'removeConfigFiles';
|
||||||
}
|
}
|
||||||
|
if (!empty($manifest['permissions'])) {
|
||||||
|
$this->setFilePermissions($manifest['permissions']);
|
||||||
|
$rollbackStack[] = 'revertFilePermissions';
|
||||||
|
}
|
||||||
if (!empty($manifest['javascript'])) {
|
if (!empty($manifest['javascript'])) {
|
||||||
$this->copyJavaScriptFiles($manifest['javascript'], $pluginDir);
|
$this->copyJavaScriptFiles($manifest['javascript'], $pluginDir);
|
||||||
$rollbackStack[] = 'removeJavaScript';
|
$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
|
* 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"
|
name="install-plugin" data-bs-toggle="modal" data-bs-target="#install-user-plugin"
|
||||||
data-plugin-manifest="' .$manifest. '" data-repo-public="' .$this->repoPublic. '">' . _("Details") .'</button>';
|
data-plugin-manifest="' .$manifest. '" data-repo-public="' .$this->repoPublic. '">' . _("Details") .'</button>';
|
||||||
}
|
}
|
||||||
|
|
||||||
$icon = htmlspecialchars($manifestData['icon'] ?? '');
|
$icon = htmlspecialchars($manifestData['icon'] ?? '');
|
||||||
$pluginDocs = htmlspecialchars($manifestData['plugin_docs'] ?? '');
|
$pluginDocs = htmlspecialchars($manifestData['plugin_docs'] ?? '');
|
||||||
$nameText = htmlspecialchars($manifestData['name'] ?? 'Unknown Plugin');
|
$nameText = htmlspecialchars($manifestData['name'] ?? 'Unknown Plugin');
|
||||||
@@ -511,7 +547,6 @@ class PluginInstaller
|
|||||||
.$pluginDocs
|
.$pluginDocs
|
||||||
.'" target="_blank">'
|
.'" target="_blank">'
|
||||||
.$nameText. '</a>';
|
.$nameText. '</a>';
|
||||||
|
|
||||||
$version = htmlspecialchars($manifestData['version'] ?? 'N/A');
|
$version = htmlspecialchars($manifestData['version'] ?? 'N/A');
|
||||||
$description = htmlspecialchars($manifestData['description'] ?? 'No description available');
|
$description = htmlspecialchars($manifestData['description'] ?? 'No description available');
|
||||||
|
|
||||||
|
|||||||
@@ -149,7 +149,6 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th><?php echo _("Configuration files"); ?></th>
|
<th><?php echo _("Configuration files"); ?></th>
|
||||||
<td><small><code><span id="plugin-configuration" class="mb-0"></span></code></small></td>
|
<td><small><code><span id="plugin-configuration" class="mb-0"></span></code></small></td>
|
||||||
</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th><?php echo _("Signed Packages"); ?></th>
|
<th><?php echo _("Signed Packages"); ?></th>
|
||||||
@@ -164,7 +163,7 @@
|
|||||||
<td><small><code><span id="plugin-javascript" class="mb-0"></span></code></small></td>
|
<td><small><code><span id="plugin-javascript" class="mb-0"></span></code></small></td>
|
||||||
</tr>
|
</tr>
|
||||||
<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>
|
<td><small><code><span id="plugin-sudoers" class="mb-0"></span></code></small></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
|||||||
Reference in New Issue
Block a user