mirror of
https://github.com/billz/raspap-webgui.git
synced 2025-03-01 10:31:47 +00:00
Merge pull request #1717 from RaspAP/feat/plugin-manager
Plugin Manager UI
This commit is contained in:
@@ -51,6 +51,7 @@ function _install_raspap() {
|
||||
_download_latest_files
|
||||
_change_file_ownership
|
||||
_create_hostapd_scripts
|
||||
_create_plugin_scripts
|
||||
_create_lighttpd_scripts
|
||||
_install_lighttpd_configs
|
||||
_default_configuration
|
||||
@@ -313,6 +314,19 @@ function _create_hostapd_scripts() {
|
||||
_install_status 0
|
||||
}
|
||||
|
||||
# Generate plugin helper scripts
|
||||
function _create_plugin_scripts() {
|
||||
_install_log "Creating plugin helper scripts"
|
||||
sudo mkdir $raspap_dir/plugins || _install_status 1 "Unable to create directory '$raspap_dir/plugins'"
|
||||
|
||||
# Copy plugin helper script
|
||||
sudo cp "$webroot_dir/installers/"plugin_helper.sh "$raspap_dir/plugins" || _install_status 1 "Unable to move plugin script"
|
||||
# Change ownership and permissions of plugin script
|
||||
sudo chown -c root:root "$raspap_dir/plugins/"*.sh || _install_status 1 "Unable change owner and/or group"
|
||||
sudo chmod 750 "$raspap_dir/plugins/"*.sh || _install_status 1 "Unable to change file permissions"
|
||||
_install_status 0
|
||||
}
|
||||
|
||||
# Generate lighttpd service control scripts
|
||||
function _create_lighttpd_scripts() {
|
||||
_install_log "Creating lighttpd control scripts"
|
||||
@@ -584,14 +598,14 @@ function _download_latest_files() {
|
||||
if [ "$repo" == "RaspAP/raspap-insiders" ]; then
|
||||
if [ -n "$username" ] && [ -n "$acctoken" ]; then
|
||||
insiders_source_url="https://${username}:${acctoken}@github.com/$repo"
|
||||
git clone --branch $branch --depth 1 -c advice.detachedHead=false $insiders_source_url $source_dir || clone=false
|
||||
git clone --branch $branch --depth 1 --recurse-submodules -c advice.detachedHead=false $insiders_source_url $source_dir || clone=false
|
||||
else
|
||||
_install_status 3
|
||||
echo "Insiders please read this: https://docs.raspap.com/insiders/#authentication"
|
||||
fi
|
||||
fi
|
||||
if [ -z "$insiders_source_url" ]; then
|
||||
git clone --branch $branch --depth 1 -c advice.detachedHead=false $git_source_url $source_dir || clone=false
|
||||
git clone --branch $branch --depth 1 --recurse-submodules -c advice.detachedHead=false $git_source_url $source_dir || clone=false
|
||||
fi
|
||||
if [ "$clone" = false ]; then
|
||||
_install_status 1 "Unable to download files from GitHub"
|
||||
|
113
installers/plugin_helper.sh
Executable file
113
installers/plugin_helper.sh
Executable file
@@ -0,0 +1,113 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# PluginInstaller helper for RaspAP
|
||||
# @author billz
|
||||
# license: GNU General Public License v3.0
|
||||
|
||||
# Exit on error
|
||||
set -o errexit
|
||||
|
||||
readonly raspap_user="www-data"
|
||||
|
||||
[ $# -lt 1 ] && { echo "Usage: $0 <action> [parameters...]"; exit 1; }
|
||||
|
||||
action="$1" # action to perform
|
||||
shift 1
|
||||
|
||||
case "$action" in
|
||||
|
||||
"sudoers")
|
||||
[ $# -ne 1 ] && { echo "Usage: $0 sudoers <file>"; exit 1; }
|
||||
file="$1"
|
||||
plugin_name=$(basename "$file")
|
||||
dest="/etc/sudoers.d/${plugin_name}"
|
||||
|
||||
mv "$file" "$dest" || { echo "Error: Failed to move $file to $dest."; exit 1; }
|
||||
|
||||
chown root:root "$dest" || { echo "Error: Failed to set ownership for $dest."; exit 1; }
|
||||
chmod 0440 "$dest" || { echo "Error: Failed to set permissions for $dest."; exit 1; }
|
||||
|
||||
echo "OK"
|
||||
;;
|
||||
|
||||
"packages")
|
||||
[ $# -lt 1 ] && { echo "Usage: $0 packages <apt_packages...>"; exit 1; }
|
||||
|
||||
echo "Installing APT packages..."
|
||||
for package in "$@"; do
|
||||
echo "Installing package: $package"
|
||||
apt-get install -y "$package" || { echo "Error: Failed to install $package."; exit 1; }
|
||||
done
|
||||
echo "OK"
|
||||
;;
|
||||
|
||||
"user")
|
||||
[ $# -lt 2 ] && { echo "Usage: $0 user <username> <password>."; exit 1; }
|
||||
|
||||
username=$1
|
||||
password=$2
|
||||
|
||||
if id "$username" &>/dev/null; then # user already exists
|
||||
echo "OK"
|
||||
exit 0
|
||||
fi
|
||||
# create the user without shell access
|
||||
useradd -r -s /bin/false "$username"
|
||||
|
||||
# set password non-interactively
|
||||
echo "$username:$password" | chpasswd
|
||||
|
||||
echo "OK"
|
||||
;;
|
||||
|
||||
"config")
|
||||
[ $# -lt 2 ] && { echo "Usage: $0 config <source> <destination>"; exit 1; }
|
||||
|
||||
source=$1
|
||||
destination=$2
|
||||
|
||||
if [ ! -f "$source" ]; then
|
||||
echo "Source file $source does not exist."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p "$(dirname "$destination")"
|
||||
cp "$source" "$destination"
|
||||
|
||||
echo "OK"
|
||||
;;
|
||||
|
||||
"plugin")
|
||||
[ $# -lt 2 ] && { echo "Usage: $0 plugin <source> <destination>"; exit 1; }
|
||||
|
||||
source=$1
|
||||
destination=$2
|
||||
|
||||
if [ ! -d "$source" ]; then
|
||||
echo "Source directory $source does not exist."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
plugin_dir=$(dirname "$destination")
|
||||
if [ ! -d "$lugin_dir" ]; then
|
||||
mkdir -p "$plugin_dir"
|
||||
fi
|
||||
|
||||
cp -R "$source" "$destination"
|
||||
chown -R $raspap_user:$raspap_user "$plugin_dir"
|
||||
|
||||
echo "OK"
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Invalid action: $action"
|
||||
echo "Usage: $0 <action> [parameters...]"
|
||||
echo "Actions:"
|
||||
echo " sudoers <file> Install a sudoers file"
|
||||
echo " packages <packages> Install aptitude package(s)"
|
||||
echo " user <name> <password> Add user non-interactively"
|
||||
echo " config <source <destination> Applies a config file"
|
||||
echo " plugin <source <destination> Copies a plugin directory"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
@@ -78,3 +78,5 @@ www-data ALL=(ALL) NOPASSWD:/bin/rm /etc/wireguard/wg-*.key
|
||||
www-data ALL=(ALL) NOPASSWD:/usr/sbin/netplan
|
||||
www-data ALL=(ALL) NOPASSWD:/bin/truncate -s 0 /tmp/*.log,/bin/truncate -s 0 /var/log/dnsmasq.log
|
||||
www-data ALL=(ALL) NOPASSWD:/usr/bin/vnstat *
|
||||
www-data ALL=(ALL) NOPASSWD:/usr/sbin/visudo -cf *
|
||||
www-data ALL=(ALL) NOPASSWD:/etc/raspap/plugins/plugin_helper.sh
|
||||
|
Reference in New Issue
Block a user