mirror of
https://github.com/billz/raspap-webgui.git
synced 2025-03-01 10:31:47 +00:00
Merge pull request #1519 from NL-TCH/REST-API
RestAPI installer integrated
This commit is contained in:
@@ -57,6 +57,7 @@ function _install_raspap() {
|
||||
_configure_networking
|
||||
_prompt_install_adblock
|
||||
_prompt_install_openvpn
|
||||
_prompt_install_restapi
|
||||
_install_extra_features
|
||||
_prompt_install_wireguard
|
||||
_prompt_install_vpn_providers
|
||||
@@ -502,6 +503,24 @@ function _prompt_install_openvpn() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Prompt to install restapi
|
||||
function _prompt_install_restapi() {
|
||||
_install_log "Configure RestAPI"
|
||||
echo -n "Install and enable RestAPI? [Y/n]: "
|
||||
if [ "$assume_yes" == 0 ]; then
|
||||
read answer < /dev/tty
|
||||
if [ "$answer" != "${answer#[Nn]}" ]; then
|
||||
_install_status 0 "(Skipped)"
|
||||
else
|
||||
_install_restapi
|
||||
fi
|
||||
elif [ "$restapi_option" == 1 ]; then
|
||||
_install_restapi
|
||||
else
|
||||
echo "(Skipped)"
|
||||
fi
|
||||
}
|
||||
|
||||
# Prompt to install WireGuard
|
||||
function _prompt_install_wireguard() {
|
||||
_install_log "Configure WireGuard support"
|
||||
@@ -562,6 +581,33 @@ function _create_openvpn_scripts() {
|
||||
_install_status 0
|
||||
}
|
||||
|
||||
# Install and enable RestAPI configuration option
|
||||
function _install_restapi() {
|
||||
_install_log "Installing and enabling RestAPI"
|
||||
sudo mv "$webroot_dir/api" "$raspap_dir/api" || _install_status 1 "Unable to move api folder"
|
||||
|
||||
if ! command -v python3 &> /dev/null; then
|
||||
echo "Python is not installed. Installing Python..."
|
||||
sudo apt update
|
||||
sudo apt install -y python3 python3-pip
|
||||
echo "Python installed successfully."
|
||||
else
|
||||
echo "Python is already installed."
|
||||
sudo apt install python3-pip -y
|
||||
|
||||
fi
|
||||
python3 -m pip install -r "$raspap_dir/api/requirements.txt" --break-system-packages || _install_status 1 " Unable to install pip modules"
|
||||
|
||||
echo "Moving restapi systemd unit control file to /lib/systemd/system/"
|
||||
sudo mv $webroot_dir/installers/restapi.service /lib/systemd/system/ || _install_status 1 "Unable to move restapi.service file"
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable restapi.service || _install_status 1 "Failed to enable restapi.service"
|
||||
echo "Enabling RestAPI management option"
|
||||
sudo sed -i "s/\('RASPI_RESTAPI_ENABLED', \)false/\1true/g" "$webroot_dir/includes/config.php" || _install_status 1 "Unable to modify config.php"
|
||||
|
||||
_install_status 0
|
||||
}
|
||||
|
||||
# Fetches latest files from github to webroot
|
||||
function _download_latest_files() {
|
||||
_install_log "Cloning latest files from GitHub"
|
||||
|
||||
@@ -26,6 +26,11 @@ www-data ALL=(ALL) NOPASSWD:/bin/systemctl start openvpn-client@client
|
||||
www-data ALL=(ALL) NOPASSWD:/bin/systemctl enable openvpn-client@client
|
||||
www-data ALL=(ALL) NOPASSWD:/bin/systemctl stop openvpn-client@client
|
||||
www-data ALL=(ALL) NOPASSWD:/bin/systemctl disable openvpn-client@client
|
||||
www-data ALL=(ALL) NOPASSWD:/bin/systemctl start restapi.service
|
||||
www-data ALL=(ALL) NOPASSWD:/bin/systemctl stop restapi.service
|
||||
www-data ALL=(ALL) NOPASSWD:/bin/systemctl status restapi.service
|
||||
www-data ALL=(ALL) NOPASSWD:/bin/touch /etc/raspap/api/.env
|
||||
www-data ALL=(ALL) NOPASSWD:/bin/mv /tmp/.env /etc/raspap/api/.env
|
||||
www-data ALL=(ALL) NOPASSWD:/bin/mv /tmp/ovpn/* /etc/openvpn/client/*.conf
|
||||
www-data ALL=(ALL) NOPASSWD:/usr/bin/ln -s /etc/openvpn/client/*.conf /etc/openvpn/client/*.conf
|
||||
www-data ALL=(ALL) NOPASSWD:/bin/rm /etc/openvpn/client/*.conf
|
||||
|
||||
@@ -40,6 +40,7 @@ OPTIONS:
|
||||
-y, --yes, --assume-yes Assumes "yes" as an answer to all prompts
|
||||
-c, --cert, --certificate Installs an SSL certificate for lighttpd
|
||||
-o, --openvpn <flag> Used with -y, --yes, sets OpenVPN install option (0=no install)
|
||||
-s, --rest, --restapi <flag> Used with -y, --yes, sets RestAPI install option (0=no install)
|
||||
-a, --adblock <flag> Used with -y, --yes, sets Adblock install option (0=no install)
|
||||
-w, --wireguard <flag> Used with -y, --yes, sets WireGuard install option (0=no install)
|
||||
-e, --provider <value> Used with -y, --yes, sets the VPN provider install option
|
||||
@@ -94,6 +95,7 @@ function _parse_params() {
|
||||
upgrade=0
|
||||
update=0
|
||||
ovpn_option=1
|
||||
restapi_option=1
|
||||
adblock_option=1
|
||||
wg_option=1
|
||||
insiders=0
|
||||
@@ -111,6 +113,10 @@ function _parse_params() {
|
||||
ovpn_option="$2"
|
||||
shift
|
||||
;;
|
||||
-s|--rest|--restapi)
|
||||
restapi_option="$2"
|
||||
shift
|
||||
;;
|
||||
-a|--adblock)
|
||||
adblock_option="$2"
|
||||
shift
|
||||
|
||||
16
installers/restapi.service
Normal file
16
installers/restapi.service
Normal file
@@ -0,0 +1,16 @@
|
||||
[Unit]
|
||||
Description=raspap-restapi
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
User=pi
|
||||
WorkingDirectory=/etc/raspap/api
|
||||
LimitNOFILE=4096
|
||||
ExecStart=/usr/bin/python3 -m uvicorn main:app --host 0.0.0.0 --port 8081
|
||||
ExecStop=/bin/kill -HUP ${MAINPID}
|
||||
Restart=on-failure
|
||||
RestartSec=5s
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
||||
Reference in New Issue
Block a user