diff --git a/CHANGELOG b/CHANGELOG
new file mode 100644
index 0000000..484594e
--- /dev/null
+++ b/CHANGELOG
@@ -0,0 +1,6 @@
+======================
+= Extension Bastille =
+======================
+Version Description
+
+1.0.0......First Public Release.
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..85f2386
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,28 @@
+---------------------------------------------------------
+ Copyright (c) 2019, José Rivera
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ 3. Neither the name of the developer nor the names of contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE DEVELOPER ``AS IS'' AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE DEVELOPER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+ ---------------------------------------------------------
diff --git a/bastille-init b/bastille-init
index 88d0f26..db9a554 100755
--- a/bastille-init
+++ b/bastille-init
@@ -1,33 +1,40 @@
#!/bin/sh
# bastille-init
# Bastille Extension for XigmaNAS x64 11.x and later.
-# Bastille Homepage: http://bastillebsd.org/
+# Bastille Extension Forum: https://www.xigmanas.com/forums/viewtopic.php?f=71&t=14848
+# Bastille Extension GitHub: https://github.com/JRGTH/xigmanas-bastille-extension
+# Bastille Homepage: http://bastillebsd.org/
+# Bastille GitHub: https://github.com/BastilleBSD/bastille
#
-# ***(For Preview/Testing)***
# Debug script
#set -x
-# Copyright (c) 2019 José Rivera (JoseMR)
+# Copyright (c) 2019, José Rivera (joserprg@gmail.com).
# All rights reserved.
-#
+
# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that following conditions are met:
+# modification, are permitted provided that the following conditions
+# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
-#
-# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS 'AS IS' AND ANY
-# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-# DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY
-# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
-# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+# 3. Neither the name of the developer nor the names of contributors
+# may be used to endorse or promote products derived from this software
+# without specific prior written permission.
+
+# THIS SOFTWARE IS PROVIDED BY THE DEVELOPER ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE DEVELOPER OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
# Set environment.
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
@@ -45,8 +52,7 @@ CONFIG="/cf/conf/config.xml"
PRDNAME="Bastille"
APPNAME="bastille"
EXTLOGFILE="${CWDIR}/log/bastille_ext.log"
-FULLAPPNAME="${APPNAME}-addon"
-PKGCONF="/etc/pkg/FreeBSD.conf"
+FULLAPPNAME="${APPNAME}-main"
WWWPATH="/usr/local/www"
PKGCACHE="/var/cache/pkg"
USRLOCAL="/usr/local"
@@ -56,11 +62,12 @@ EXTCONFLINK="/var/etc/${APPNAME}_conf"
BASTILLERCD="/usr/local/etc/rc.d/${APPNAME}"
BASTILLEPATH="${USRLOCAL}/bin"
BASTILLECONF="${USRLOCAL}/etc/${APPNAME}/${APPNAME}.conf"
-BASTILLECONFLINK="/var/etc/bastilleconf"
+BASTILLECONFLINK="/var/etc/bastille_conf"
+BASTILLECONF_EXT="${CWDIR}/conf/bastille.conf.ext"
INSTALLPATH="${CWDIR}/${FULLAPPNAME}"
BRANCH="master"
-#BATSILLE_URL="https://github.com/BastilleBSD/${APPNAME}/archive/${BRANCH}.zip" # Official Bastille repository(Pending some updates/fixes)
-BATSILLE_URL="https://github.com/JRGTH/${APPNAME}/archive/${BRANCH}.zip" # Alternate Bastille repository(Updated, supports 11.3-RELEASE base)
+BATSILLE_URL="https://github.com/BastilleBSD/${APPNAME}/archive/${BRANCH}.zip" # Official Bastille Repository)
+#BATSILLE_URL="https://github.com/JRGTH/${APPNAME}/archive/${BRANCH}.zip" # Alternate Bastille Repository)
BASTILE_VERSION="https://raw.githubusercontent.com/BastilleBSD/${APPNAME}/${BRANCH}/usr/local/bin/${APPNAME}"
GITURL="https://github.com/JRGTH/xigmanas-${APPNAME}-extension/archive/${BRANCH}.zip"
VERFILE="https://raw.githubusercontent.com/JRGTH/xigmanas-${APPNAME}-extension/${BRANCH}/version"
@@ -81,6 +88,9 @@ runtime_config()
sysrc -f ${INSTALLPATH}/${BASTILLECONF} bastille_prefix="${CWDIR}" >/dev/null 2>&1
fi
fi
+ if [ ! -d ${CWDIR}/backups ]; then
+ mkdir -p ${CWDIR}/backups
+ fi
if [ ! -d ${CWDIR}/conf ]; then
mkdir -p ${CWDIR}/conf
fi
@@ -110,9 +120,10 @@ bastille_pkg_extract()
if [ -f ${CWDIR}/${BRANCH}.zip ]; then
if [ ! -f ${CWDIR}/${FULLAPPNAME}${BASTILLEPATH}/${APPNAME} ]; then
echo "Extracting ${APPNAME}..."
- tar -xf ${CWDIR}/${BRANCH}.zip --exclude='.git*' --strip-components 1 -C ${CWDIR}/${FULLAPPNAME} || \
+ tar -xf ${CWDIR}/${BRANCH}.zip --exclude='.git*' --exclude='docs' --exclude='bastille.conf' --strip-components 1 -C ${CWDIR}/${FULLAPPNAME} || \
error_notify "Error: A problem has occurred while extractig ${APPNAME} files."
chmod 555 ${CWDIR}/${FULLAPPNAME}${BASTILLEPATH}/${APPNAME}
+ chmod 555 ${CWDIR}/${FULLAPPNAME}${BASTILLERCD}
rm -f ${CWDIR}/${BRANCH}.zip
echo "Done!"
fi
@@ -123,7 +134,7 @@ bastille_upgrade()
{
# Perform an online bastille upgrade.
DATE=$(date +"%a %b %d %T %Y")
- echo "Looking for new ${APPNAME} package!"
+ echo "Looking for new ${PRDNAME} package!"
mkdir -p ${CWDIR}/update
fetch -ao ${CWDIR}/update --no-verify-peer --timeout=30 ${BASTILE_VERSION} || \
error_notify "Error: A problem has occurred while fetching version file."
@@ -136,10 +147,11 @@ bastille_upgrade()
echo "New ${APPNAME} package found, performing upgrade..."
fetch -ao ${CWDIR}/update --no-verify-peer --timeout=30 ${BATSILLE_URL} || \
error_notify "Error: A problem has occurred while fetching ${APPNAME} package."
- tar -xf ${CWDIR}/update/${BRANCH}.zip --exclude='.git*' --strip-components 1 -C ${CWDIR}/update
+ tar -xf ${CWDIR}/update/${BRANCH}.zip --exclude='.git*' --exclude='docs' --exclude='bastille.conf' --strip-components 1 -C ${CWDIR}/update
rm -f ${CWDIR}/update/${BRANCH}.zip
rm -f ${CWDIR}/update/${APPNAME}
chmod 555 ${CWDIR}/update/${BASTILLEPATH}/${APPNAME}
+ chmod 555 ${CWDIR}/${FULLAPPNAME}${BASTILLERCD}
cp -Rf ${CWDIR}/update/* ${CWDIR}/${FULLAPPNAME}/
rm -R ${CWDIR}/update
@@ -209,10 +221,13 @@ extension_upgrade()
create_addon_env()
{
- # Set bastile dir proper permissions.
+ # Set bastille dir required permissions.
chmod 0750 ${CWDIR}
# Create required directories.
+ if [ ! -d "${CWDIR}/backups" ]; then
+ mkdir -p ${CWDIR}/backups
+ fi
if [ ! -d "${CWDIR}/log" ]; then
mkdir -p ${CWDIR}/log
fi
@@ -252,7 +267,7 @@ bin_symlinks()
cd ${INSTALLPATH}/${BASTILLEPATH}
for file in *
do
- ln -Ffhs ${INSTALLPATH}/${BASTILLEPATH}/${file} ${USRLOCAL}/bin/${file}
+ ln -fhs ${INSTALLPATH}/${BASTILLEPATH}/${file} ${USRLOCAL}/bin/${file}
done
fi
}
@@ -262,26 +277,26 @@ sys_symlinkdir()
# Check and create/relink required symlinks/dirs for bastille.
# This environment will be checked each time the script is started for consistency.
+ # Link required binaries.
+ bin_symlinks
+
# Required directories for bastille.
if [ ! -d "${USRLOCAL}/share/licenses" ]; then
mkdir -p ${USRLOCAL}/share/licenses
fi
- # Link required binaries.
- bin_symlinks
-
# Required symlinks for bastille.
if [ -d "${INSTALLPATH}/${USRLOCAL}/share/licenses" ]; then
cd ${INSTALLPATH}/${USRLOCAL}/share/licenses
for file in *
do
- ln -Ffhs ${INSTALLPATH}/${USRLOCAL}/share/licenses/${file} ${USRLOCAL}/share/licenses/${file}
+ ln -fhs ${INSTALLPATH}/${USRLOCAL}/share/licenses/${file} ${USRLOCAL}/share/licenses/${file}
done
fi
# Link bastile config file directory.
if [ -d "${INSTALLPATH}/${USRLOCAL}/etc/${APPNAME}" ]; then
- ln -Ffhs ${INSTALLPATH}/${USRLOCAL}/etc/${APPNAME} ${USRLOCAL}/etc/${APPNAME}
+ ln -fhs ${INSTALLPATH}/${USRLOCAL}/etc/${APPNAME} ${USRLOCAL}/etc/${APPNAME}
fi
# Link bastile config file.
@@ -290,11 +305,15 @@ sys_symlinkdir()
if [ ! -f "${APPNAME}.conf" ]; then
cp ${APPNAME}.conf.sample ${APPNAME}.conf
fi
+ else
+ if [ -f "${BASTILLECONF_EXT}" ]; then
+ cp ${BASTILLECONF_EXT} ${INSTALLPATH}/${USRLOCAL}/etc/${APPNAME}/${APPNAME}.conf
+ fi
fi
# Copy bastille shared.
if [ -d "${INSTALLPATH}/${USRLOCAL}/share/${APPNAME}" ]; then
- ln -Ffhs ${INSTALLPATH}/${USRLOCAL}/share/${APPNAME} ${USRLOCAL}/share/${APPNAME}
+ ln -fhs ${INSTALLPATH}/${USRLOCAL}/share/${APPNAME} ${USRLOCAL}/share/${APPNAME}
fi
# Copy bastille rc.
@@ -309,8 +328,8 @@ postinit_cmd()
if ! grep -qw ${CWDIR}/${SCRIPTNAME} ${CONFIG}; then
touch ${CWDIR}/postinit || error_notify "Error: A problem has occurred while creating the postinit file."
chmod +x ${CWDIR}/postinit
- if [ ! "${PRDVERSION}" -ge "110" ]; then
- # Generate php script for NAS4Free 10.3 versions.
+ if [ ! "${PRDVERSION}" -ge "112" ]; then
+ # Generate php script for previous product versions.
cat << EOF > ${CWDIR}/postinit
EOF
else
- # Generate php script for NAS4Free/XigmaNAS 11.x versions.
+ # Generate php script for later product versions.
cat << EOF > ${CWDIR}/postinit
EOF
fi
@@ -359,7 +402,7 @@ EOF
echo "Done!"
fi
- # Set extension to disable by default.
+ # Set extension to enable by default.
sysrc -f ${CWDIR}${EXTCONF} GUI_ENABLE=YES INSTALL_DIR=${CWDIR} >/dev/null 2>&1
fi
}
@@ -382,21 +425,31 @@ gui_start()
sysrc -f ${CWDIR}${EXTCONF} INSTALL_DIR=${CWDIR} >/dev/null 2>&1
fi
mkdir -p ${BASTILLECONFLINK}
- ln -Ffhs ${CWDIR}/conf ${BASTILLECONFLINK}/conf
- # Copy the gui files.
- cp -R ${CWDIR}/gui/* ${WWWPATH}/ || error_notify "Error: A problem has occurred while copying extension gui files."
+ ln -fhs ${CWDIR}/conf ${BASTILLECONFLINK}/conf
+ # Link the gui files.
+ if [ ! -d "${WWWPATH}/ext" ]; then
+ mkdir -p ${WWWPATH}/ext
+ fi
+ ln -fhs ${CWDIR}/gui/ext/bastille ${WWWPATH}/ext/ || error_notify "Error: A problem has occurred while copying extension gui files."
+ ln -fhs ${CWDIR}/gui/images ${WWWPATH}/ext/bastille/ || error_notify "Error: A problem has occurred while copying extension gui files."
+ ln -fhs ${CWDIR}/gui/bastille_manager_*.php ${WWWPATH}/ || error_notify "Error: A problem has occurred while linking extension gui files."
fi
fi
}
gui_enable()
{
- # Relink conf and copy the gui files.
+ # Relink conf and gui files.
if [ -d "${CWDIR}/gui" ]; then
mkdir -p ${BASTILLECONFLINK}
- ln -Ffhs ${CWDIR}/conf ${BASTILLECONFLINK}/conf
+ ln -fhs ${CWDIR}/conf ${BASTILLECONFLINK}/conf
sysrc -f ${CWDIR}${EXTCONF} GUI_ENABLE=YES >/dev/null 2>&1
- cp -R ${CWDIR}/gui/* ${WWWPATH}/ || error_notify "Error: A problem has occurred while copying extension gui files."
+ if [ ! -d "${WWWPATH}/ext" ]; then
+ mkdir -p ${WWWPATH}/ext
+ fi
+ ln -fhs ${CWDIR}/gui/ext/bastille ${WWWPATH}/ext/ || error_notify "Error: A problem has occurred while copying extension gui files."
+ ln -fhs ${CWDIR}/gui/images ${WWWPATH}/ext/bastille/ || error_notify "Error: A problem has occurred while copying extension gui files."
+ ln -fhs ${CWDIR}/gui/bastille_manager_*.php ${WWWPATH}/ || error_notify "Error: A problem has occurred while copying extension gui files."
exit 0
else
error_notify "Error: Extension gui files not found."
@@ -407,10 +460,11 @@ gui_disable()
{
# Disable gui if -t option specified.
if [ -d "${CWDIR}/gui" ]; then
- rm -f ${WWWPATH}bastille-gui.php
- rm -Rf ${WWWPATH}/ext/bastille-gui
+ rm -f ${WWWPATH}bastille_manager_*.php
+ rm -rf ${WWWPATH}/ext/bastille
+ rm -rf ${WWWPATH}/ext/bastille/images
rm -f ${LOCALSHAREPATH}/locale-bastille
- rm -Rf ${BASTILLECONFLINK}
+ rm -rf ${BASTILLECONFLINK}
sysrc -f ${CWDIR}${EXTCONF} GUI_ENABLE=NO >/dev/null 2>&1 || error_notify "Error: A problem while removing extension gui files."
exit 0
else
@@ -420,7 +474,7 @@ gui_disable()
# Remove empty ext folder to prevent empty "Extensions" tab.
if [ -d "${WWWPATH}/ext" ]; then
if [ ! "$(ls -A ${WWWPATH}/ext)" ]; then
- rm -R ${WWWPATH}/ext
+ rm -r ${WWWPATH}/ext
fi
fi
}
@@ -442,8 +496,8 @@ reset_install()
{
# Reset the extension environment.
echo "Removing extension files..."
- if [ -d ${CWDIR}/conf ]; then
- rm -rf ${CWDIR}/conf
+ if [ -f ${CWDIR}/conf/bastille_config ]; then
+ rm -rf ${CWDIR}/conf/bastille_config
fi
if [ -d ${CWDIR}/${FULLAPPNAME} ]; then
rm -rf ${CWDIR}/${FULLAPPNAME}
@@ -470,11 +524,11 @@ remove_addon()
echo "Proceeding..."
# Check for working platform and remove symlinks.
- if [ "${PRDPLATFORM}" = "x64-embedded" ]; then
+ if [ "${PRDPLATFORM}" = "x64-embedded" ] || [ "${PRDPLATFORM}" = "x64-full" ]; then
if [ -d "${USRLOCAL}/share/licenses/${APPNAME}-*" ]; then
rm -rf ${USRLOCAL}/share/licenses/${APPNAME}-*
fi
- if [ -d ${USRLOCAL}/share/locale-bastille ]; then
+ if [ -d $"{USRLOCAL}/share/locale-bastille" ]; then
rm -rf ${USRLOCAL}/share/locale-bastille
fi
if [ -f "${USRLOCAL}/etc/rc.d/${APPNAME}" ]; then
@@ -489,21 +543,19 @@ remove_addon()
if [ -d "${VARLOG}/${APPNAME}" ]; then
rm -rf ${VARLOG}/${APPNAME}
fi
- elif [ "${PRDPLATFORM}" = "x64-full" ]; then
- pkg delete -y ${APPNAME}
fi
# Remove extension and GUI components.
- if [ -f "${WWWPATH}/${APPNAME}-gui.php" ]; then
- rm -f ${WWWPATH}/${APPNAME}-gui.php
+ if [ -f "${WWWPATH}/bastille_manager_gui.php" ]; then
+ rm -f ${WWWPATH}/bastille_manager_*.php
fi
- if [ -d "${WWWPATH}/ext/bastille-gui" ]; then
- rm -rf ${WWWPATH}/ext/bastille-gui
+ if [ -d "${WWWPATH}/ext/bastille" ]; then
+ rm -rf ${WWWPATH}/ext/bastille
fi
- if [ -f ${USRLOCAL}/bin/${APPNAME} ]; then
+ if [ -f "${USRLOCAL}/bin/${APPNAME}" ]; then
rm -rf ${USRLOCAL}/bin/${APPNAME}
fi
- if [ -d ${VARLOG}/${APPNAME} ]; then
+ if [ -d "${VARLOG}/${APPNAME}" ]; then
rm -rf ${VARLOG}/${APPNAME}
fi
@@ -515,11 +567,12 @@ remove_addon()
fi
# Remove addon related files and folders only-
- # to protect any user-created custom files.
- FILES="conf download gui locale-bastille log bastille-addon README.md postinit release_notes version bastille-init"
- for file in ${FILES}; do
- if [ -f ${CWDIR}/${file} ] || [ -d ${CWDIR}/${file} ]; then
- rm -rf ${CWDIR}/${file}
+ # to protect any user-created custom files-
+ # as well as for the containers dirs/files.
+ FILES="conf download gui locale-bastille log bastille-main LICENSE README.md postinit release_notes version bastille-init"
+ for FILE in ${FILES}; do
+ if [ -f "${CWDIR}/${file}" ] || [ -d "${CWDIR}/${file}" ]; then
+ rm -rf ${CWDIR}/${FILE}
fi
done
@@ -530,7 +583,7 @@ remove_addon()
get_versions()
{
- # Get bastille-addon extension version.
+ # Get product versions.
if [ -f "${CWDIR}/version" ]; then
APPVERSION=$(cat ${CWDIR}/version)
else
@@ -540,7 +593,6 @@ get_versions()
# Display product versions.
BASTILLEVER=$(${USRLOCAL}/bin/bastille --version)
echo "Bastille version: ${BASTILLEVER}"
-
echo "Extension version: ${APPVERSION}"
exit 0
}
@@ -548,15 +600,15 @@ get_versions()
ext_start()
{
# Start bastille jails.
- if [ "${PRDPLATFORM}" = "x64-embedded" ]; then
- if [ -d "${CWDIR}/jails" ]; then
- if [ "$(ls -A ${CWDIR}/jails)" ]; then
- JAIL_AUTO_START=$(sysrc -qn bastille_enable)
- if [ "${JAIL_AUTO_START}" = "YES" ]; then
- service bastille start
+ if [ -d "${CWDIR}/jails" ]; then
+ JAIL_LIST=$(bastille list jail)
+ for jail in ${JAIL_LIST}; do
+ if sysrc -f ${CWDIR}${EXTCONF} -qn ${jail}_AUTO_START | grep -w "YES" >/dev/null; then
+ if ! jls | sed "1 d" | awk '{print $3}' | grep -qw ${jail}; then
+ bastille start ${jail}
fi
fi
- fi
+ done
fi
if [ $? -eq 0 ]; then
@@ -572,27 +624,70 @@ ext_start()
rc_params()
{
- # Bastille rc parameters.
+ # Bastille required parameters.
+
+ # Set bastille prefix.
if ! sysrc -f ${BASTILLECONF} -qn bastille_prefix | grep -q "${CWDIR}"; then
sysrc -f ${BASTILLECONF} bastille_prefix="${CWDIR}" >/dev/null 2>&1
fi
- # Default network interface.
- ACTIVE_NETIF=$(ifconfig | grep "UP,BROADCAST" | awk -F":" '{print $1}')
- if ! sysrc -f ${BASTILLECONF} -qn bastille_jail_external >/dev/null 2>&1; then
- echo "" >> ${BASTILLECONF} && echo "## default network interface" >> ${BASTILLECONF}
+ # Set bastille.conf location.
+ if ! sysrc -f ${CWDIR}${EXTCONF} -n BASTILLE_CONFIG 2>/dev/null | grep -q "${CWDIR}/${FULLAPPNAME}${BASTILLECONF}"; then
+ sysrc -f ${CWDIR}${EXTCONF} BASTILLE_CONFIG="${CWDIR}/${FULLAPPNAME}${BASTILLECONF}" >/dev/null 2>&1
+ fi
+
+ # Default first network interface.
+ ACTIVE_NETIF=$(ifconfig | grep "UP,BROADCAST" | awk -F":" '{print $1}' | sed 1q)
+ if ! sysrc -f ${BASTILLECONF} -qn bastille_jail_external | grep -q "${ACTIVE_NETIF}" >/dev/null 2>&1; then
+ #echo "" >> ${BASTILLECONF} && echo "## default network interface" >> ${BASTILLECONF}
sysrc -f ${BASTILLECONF} bastille_jail_external="${ACTIVE_NETIF}" >/dev/null 2>&1
else
- BLANK_NETIF=$(sysrc -f ${BASTILLECONF} -qn bastille_jail_external)
- if [ -z "${BLANK_NETIF}" ]; then
- echo "" >> ${BASTILLECONF} && echo "## default network interface" >> ${BASTILLECONF}
+ EXT_NETIF=$(sysrc -f ${BASTILLECONF} -qn bastille_jail_external)
+ if [ -z "${EXT_NETIF}" ]; then
+ #echo "" >> ${BASTILLECONF} && echo "## default network interface" >> ${BASTILLECONF}
sysrc -f ${BASTILLECONF} bastille_jail_external="${ACTIVE_NETIF}" >/dev/null 2>&1
fi
fi
- # Start all jails by default.
+ # Do't start containers by default.
if ! sysrc -qn bastille_enable >/dev/null 2>&1; then
- sysrc bastille_enable="YES" >/dev/null 2>&1
+ sysrc bastille_enable="NO" >/dev/null 2>&1
+ fi
+}
+
+bastille_start()
+{
+ # Start all bastille containers.
+ echo "${PRDNAME} Extension: Starting all containers..."
+ bastille start ALL
+ if [ $? -eq 0 ]; then
+ exit 0
+ else
+ exit 1
+ fi
+}
+
+bastille_stop()
+{
+ # Stop all bastille containers.
+ echo "${PRDNAME} Extension: Stopping all containers..."
+ bastille stop ALL
+ if [ $? -eq 0 ]; then
+ exit 0
+ else
+ exit 1
+ fi
+}
+
+bastille_restart()
+{
+ # Restart all bastille containers.
+ echo "${PRDNAME} Extension: Restarting all containers..."
+ bastille restart ALL
+ if [ $? -eq 0 ]; then
+ exit 0
+ else
+ exit 1
fi
}
@@ -603,7 +698,7 @@ bastille_init()
echo "Unsupported platform!"; exit 1
fi
# Check for product compatibility.
- if [ ! "${PRDVERSION}" -ge "110" ]; then
+ if [ ! "${PRDVERSION}" -ge "112" ]; then
echo "Unsupported version!"; exit 1
fi
@@ -621,18 +716,24 @@ bastille_init()
# Run-time configuration.
runtime_config
-while getopts ":ouxRvgth" option; do
+while getopts ":ospruxRvgth" option; do
case ${option} in
[h]) echo "Usage: ${SCRIPTNAME} -[option]";
echo "Options:"
+ echo " -s Start All ${PRDNAME} Containers."
+ echo " -p Stop All ${PRDNAME} Containers."
+ echo " -r Restart All ${PRDNAME} Containers."
echo " -u Upgrade ${PRDNAME}/Extension packages."
echo " -v Display product versions."
echo " -g Enables the addon GUI."
echo " -t Disable the addon GUI."
echo " -x Reset ${PRDNAME}/Extension config."
- echo " -R Remove ${PRDNAME}."
+ echo " -R Remove ${PRDNAME} (Extension files only)."
echo " -h Display this help message."; exit 0;;
[o]) OBI_INSTALL="ON";; # To prevent nested PHP-CGI call for installation with OBI.
+ [s]) bastille_start;;
+ [p]) bastille_stop;;
+ [r]) bastille_restart;;
[u]) pkg_upgrade;;
[x]) reset_install;;
[R]) remove_addon;;
diff --git a/conf/bastille.conf.ext b/conf/bastille.conf.ext
new file mode 100644
index 0000000..88c4805
--- /dev/null
+++ b/conf/bastille.conf.ext
@@ -0,0 +1,20 @@
+bastille_prefix="/usr/local/bastille"
+bastille_cachedir="${bastille_prefix}/cache"
+bastille_jailsdir="${bastille_prefix}/jails"
+bastille_logsdir="${bastille_prefix}/logs"
+bastille_releasesdir="${bastille_prefix}/releases"
+bastille_templatesdir="${bastille_prefix}/templates"
+bastille_sharedir="/usr/local/share/bastille"
+bastille_bootstrap_archives="base"
+bastille_tzdata="etc/UTC"
+bastille_resolv_conf="/etc/resolv.conf"
+bastille_zfs_enable=""
+bastille_zfs_zpool=""
+bastille_zfs_prefix="bastille"
+bastille_zfs_mountpoint="${bastille_prefix}"
+bastille_zfs_options="-o compress=lz4 -o atime=off"
+bastille_jail_loopback=""
+bastille_jail_interface=""
+bastille_jail_external=""
+bastille_jail_addr=""
+bastille_jail_gateway=""
diff --git a/conf/bastille.conf.sample b/conf/bastille.conf.sample
new file mode 100644
index 0000000..2bef663
--- /dev/null
+++ b/conf/bastille.conf.sample
@@ -0,0 +1,37 @@
+#####################
+## [ BastilleBSD ] ##
+#####################
+
+## default paths
+bastille_prefix="/usr/local/bastille" ## default: "/usr/local/bastille"
+bastille_cachedir="${bastille_prefix}/cache" ## default: ${bastille_prefix}/cache
+bastille_jailsdir="${bastille_prefix}/jails" ## default: ${bastille_prefix}/jails
+bastille_logsdir="${bastille_prefix}/logs" ## default: ${bastille_prefix}/logs
+bastille_releasesdir="${bastille_prefix}/releases" ## default: ${bastille_prefix}/releases
+bastille_templatesdir="${bastille_prefix}/templates" ## default: ${bastille_prefix}/templates
+
+## bastille scripts directory (assumed by bastille pkg)
+bastille_sharedir="/usr/local/share/bastille" ## default: "/usr/local/share/bastille"
+
+## bootstrap archives (base, lib32, ports, src, test)
+bastille_bootstrap_archives="base" ## default: "base"
+
+## default timezone
+bastille_tzdata="etc/UTC" ## default: "etc/UTC"
+
+## default jail resolv.conf
+bastille_resolv_conf="/etc/resolv.conf" ## default: "/etc/resolv.conf"
+
+## ZFS options
+bastille_zfs_enable="" ## default: ""
+bastille_zfs_zpool="" ## default: ""
+bastille_zfs_prefix="bastille" ## default: "${bastille_zfs_zpool}/bastille"
+bastille_zfs_mountpoint=${bastille_prefix} ## default: "${bastille_prefix}"
+bastille_zfs_options="-o compress=lz4 -o atime=off" ## default: "-o compress=lz4 -o atime=off"
+
+## Networking
+bastille_jail_loopback="lo1" ## default: "lo1"
+bastille_jail_interface="bastille0" ## default: "bastille0"
+bastille_jail_external="" ## default: ""
+bastille_jail_addr="10.17.89.10" ## default: "10.17.89.10"
+bastille_jail_gateway="" ## default: ""
diff --git a/gui/bastille_manager-lib.inc b/gui/bastille_manager-lib.inc
new file mode 100755
index 0000000..37c0aeb
--- /dev/null
+++ b/gui/bastille_manager-lib.inc
@@ -0,0 +1,187 @@
+/dev/null)");
+if ($avail_releases == ''):
+ $empty_releases = "YES";
+ $avail_releases = "No base releases detected!";
+endif;
+
+// Ensure the root directory is configured.
+if ($rootfolder == "")
+ $input_errors[] = gtext("Extension installed with fault");
+else {
+// Initialize locales.
+ $textdomain = "/usr/local/share/locale";
+ $textdomain_bastille = "/usr/local/share/locale-bastille";
+ if (!is_link($textdomain_bastille)) { mwexec("ln -s {$rootfolder}/locale-bastille {$textdomain_bastille}", true); }
+ bindtextdomain("xigmanas", $textdomain_bastille);
+}
+if (is_file("{$rootfolder}/postinit")) unlink("{$rootfolder}/postinit");
+
+// Get all base releases list.
+function get_all_release_list() {
+ global $rootfolder;
+ global $g;
+ exec("/bin/echo; /bin/ls {$rootfolder}/releases 2>/dev/null | /usr/bin/tr -s ' ' '\n'",$relinfo);
+ array_shift($relinfo);
+ $rellist = [];
+ foreach($relinfo as $rel):
+ $arel = preg_split("/\s+/",ltrim($rel));
+ $relname = chop($arel[0]);
+ if(substr($relname,-1) === '*'):
+ $relname = substr($relname,0,strlen($relname) - 1);
+ endif;
+ $rellist[$relname] = [];
+ endforeach;
+ return $rellist;
+}
+
+// Get all interface list.
+function get_all_interface_list() {
+ global $g;
+ exec("/bin/echo; /sbin/ifconfig -l | /usr/bin/tr -s ' ' '\n'; /bin/echo 'NONE'",$linkinfo);
+ array_shift($linkinfo);
+ $iflist = [];
+ foreach($linkinfo as $link):
+ $alink = preg_split("/\s+/",ltrim($link));
+ $ifname = chop($alink[0]);
+ if(substr($ifname,-1) === '*'):
+ $ifname = substr($ifname,0,strlen($ifname) - 1);
+ endif;
+ $iflist[$ifname] = [];
+ endforeach;
+ return $iflist;
+}
+
+// Get jail infos.
+function get_jail_infos() {
+ global $img_path;
+ global $image_dir;
+ global $configfile;
+ global $jail_dir;
+ $result = [];
+ if(is_dir($jail_dir)):
+ $cmd = '/usr/local/bin/bastille list jail 2>&1';
+ else:
+ $cmd = ":";
+ endif;
+ mwexec2($cmd,$rawdata);
+ foreach($rawdata as $line):
+ $a = preg_split('/\t/',$line);
+ $r = [];
+ $name = $a[0];
+ if(preg_match('/(.*)/', $name, $m)):
+ $r['name'] = $m[1];
+ else:
+ $r['name'] = '-';
+ endif;
+ $r['jailname'] = $r['name'];
+
+ // Set the JID on the running jails.
+ $item = $r['jailname'];
+ $r['id'] = exec("/usr/sbin/jls | /usr/bin/grep {$item} | /usr/bin/awk '{print $1}'");
+ if (!$r['id']):
+ $r['id'] = "-";
+ endif;
+ // Set the IPv4 on the running jails.
+ //$r['ip'] = exec("/usr/sbin/jls | /usr/bin/grep {$item} | /usr/bin/awk '{print $2}'");
+ $r['ip'] = exec("/usr/bin/grep -w 'ip4.addr' {$jail_dir}/{$item}/jail.conf | /usr/bin/awk '{print $3}' | /usr/bin/tr -d ';'");
+ if (!$r['ip']):
+ $r['ip'] = "-";
+ endif;
+ // Display interfaces.
+ $r['nic'] = exec("/usr/bin/grep -w 'interface' {$jail_dir}/{$item}/jail.conf | /usr/bin/awk '{print $3}' | /usr/bin/tr -d ';'");
+ if (!$r['nic']):
+ $r['nic'] = "-";
+ endif;
+ // Display path.
+ $r['path'] = exec("/usr/bin/grep -w 'path' {$jail_dir}/{$item}/jail.conf | /usr/bin/awk '{print $3}' | /usr/bin/tr -d ';'");
+ if (!$r['path']):
+ $r['path'] = "-";
+ endif;
+ // Display auto-start settings.
+ $jail_autostart = exec("/usr/sbin/sysrc -qn -f {$configfile} {$item}_AUTO_START");
+ if ($jail_autostart == 'YES') {
+ $r['boot'] = $img_path['ena'];
+ } elseif ($jail_autostart == 'NO') {
+ $r['boot'] = $img_path['dis'];
+ } else {
+ $r['boot'] = $img_path['dis'];
+ }
+ // Display running status icons.
+ $jail_running = exec("/usr/sbin/jls | /usr/bin/grep -w {$item}");
+ if ($jail_running):
+ $r['stat'] = $img_path['ena'];
+ else:
+ $r['stat'] = $img_path['dis'];
+ endif;
+ // Display custom template icons if available.
+ $item = $item;
+ $template_icon = "{$image_dir}/{$item}_icon.png";
+ if(file_exists($template_icon)):
+ $r['logo'] = "{$image_dir}/{$item}_icon.png";
+ else:
+ // Display standard FreeBSD icon.
+ $r['logo'] = "{$image_dir}/bsd_icon.png";
+ endif;
+
+ $result[] = $r;
+ endforeach;
+ return $result;
+}
+
+?>
diff --git a/gui/bastille_manager_add.php b/gui/bastille_manager_add.php
new file mode 100644
index 0000000..1990b57
--- /dev/null
+++ b/gui/bastille_manager_add.php
@@ -0,0 +1,188 @@
+.
+ XigmaNAS® is a registered trademark of Michael Zoon (zoon01@xigmanas.com).
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ 3. Neither the name of the developer nor the names of contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE DEVELOPER ``AS IS'' AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE DEVELOPER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+*/
+
+require_once 'auth.inc';
+require_once 'guiconfig.inc';
+require_once("bastille_manager-lib.inc");
+
+$pgtitle = array(gtext("Extensions"), "Bastille", "Create");
+
+if(!$pconfig['jailname']):
+ $pconfig['jailname'] = 'jail1';
+endif;
+if(!$pconfig['ipaddress']):
+ $pconfig['ipaddress'] = '';
+endif;
+
+// list of configured interfaces
+$a_interface = get_all_interface_list();
+$l_interfaces = [];
+foreach($a_interface as $k_interface => $ifinfo):
+ $l_interfaces[$k_interface] = $k_interface;
+endforeach;
+
+// list base releases
+$a_release = get_all_release_list();
+$l_release = [];
+foreach($a_release as $k_release => $release):
+ $l_release[$k_release] = $k_release;
+endforeach;
+
+if(!is_dir($jail_dir)):
+ $errormsg = gtext('No base releases extracted yet.')
+ . ' '
+ . ''
+ . gtext('Please download a base release first.')
+ . '';
+ $prerequisites_ok = false;
+endif;
+
+if($_POST):
+ global $empty_releases;
+ global $configfile;
+ unset($input_errors);
+ $pconfig = $_POST;
+ if(isset($_POST['Cancel']) && $_POST['Cancel']):
+ header('Location: bastille_manager_gui.php');
+ exit;
+ endif;
+ if(isset($_POST['Create']) && $_POST['Create']):
+ $jname = $pconfig['jailname'];
+ $ipaddr = $pconfig['ipaddress'];
+ $release = $pconfig['release'];
+ if ($_POST['interface'] == 'NONE'):
+ $interface = "";
+ else:
+ $interface = $pconfig['interface'];
+ endif;
+
+ if($empty_releases !== "YES"):
+ if ($_POST['nowstart']):
+ $cmd = ("/usr/local/bin/bastille create {$jname} {$release} {$ipaddr} {$interface} && /usr/local/bin/bastille start {$jname}");
+ else:
+ $cmd = ("/usr/local/bin/bastille create {$jname} {$release} {$ipaddr} {$interface}");
+ endif;
+ else:
+ $cmd = "";
+ endif;
+ if ($_POST['Create']):
+ if ($_POST['autostart']):
+ exec("/usr/sbin/sysrc -f {$configfile} {$jname}_AUTO_START=\"YES\"");
+ endif;
+ unset($output,$retval);mwexec2($cmd,$output,$retval);
+ if($retval == 0):
+ //$savemsg .= gtext("Boot Environment created and activated successfully.");
+ header('Location: bastille_manager_gui.php');
+ exit;
+ else:
+ $errormsg .= gtext("Failed to create container.");
+ endif;
+ endif;
+ endif;
+endif;
+
+include 'fbegin.inc';
+?>
+
+
+ add_area_tabnav()->
+ push()->
+ add_tabnav_upper()->
+ ins_tabnav_record('bastille_manager_gui.php',gettext('Containers'),gettext('Reload page'),true)->
+ ins_tabnav_record('bastille_manager_info.php',gettext('Information'),gettext('Reload page'),true)->
+ ins_tabnav_record('bastille_manager_maintenance.php',gettext('Maintenance'),gettext('Reload page'),true);
+$document->render();
+?>
+
+
diff --git a/gui/bastille_manager_config.php b/gui/bastille_manager_config.php
new file mode 100644
index 0000000..7a34e4c
--- /dev/null
+++ b/gui/bastille_manager_config.php
@@ -0,0 +1,177 @@
+";
+ return $result;
+}
+
+function htmlButton($name, $text, $value="", $title="", $confirm="", $buttonImage="") {
+ $onClick = ($confirm == "") ? "" : "onclick='return confirm(\"{$confirm}\")'";
+ switch ($buttonImage) {
+ case "save": $buttonImage = ""; break;
+ default: $buttonImage = "";
+ }
+ $result = "";
+ return $result;
+}
+
+function parseConfigFile($configFile) {
+ $fileArray = file($configFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); // load config file content to array
+ $configArray = array();
+ foreach($fileArray as $line) { // create array from config
+ $line = trim($line); // remove leading/trailing space
+ if ($line[0] == "#") continue; // skip if comment line
+ if ($line[0] == "[") { // add as section
+ $configArray[$line] = [];
+ $section = $line; // remember section name for params
+ } else { // process params
+ $parameter = explode("=", $line, 2); // seperate key and value, (Split at the first occurrence only)
+ $key = trim($parameter[0]); // set key
+ $val = explode("#", trim($parameter[1])); // get value, remove trailing comments
+ $value = $val[0]; // set value
+ $configArray[$section][$key] = $value; // add param to section
+ }
+ }
+ return $configArray;
+}
+
+function saveConfigFile($configFile, $configArray, $hashTag="", $prettyPrint=true) {
+ //$printTab = ($prettyPrint) ? "\t" : ""; // Print leading tab.
+ //$printSpace = ($prettyPrint) ? " " : ""; // Print spaces.
+ $printTab = ($prettyPrint) ? "" : ""; // Do not print leading tab.
+ $printSpace = ($prettyPrint) ? "" : ""; // Do not print spaces.
+
+ $cFile = fopen($configFile, "w");
+ foreach($configArray as $key => $line) { // traverse array, key = section
+ if (is_array($line)) {
+ if ($key != '') fwrite($cFile, $key.PHP_EOL); // write section if not "['']" => NO section
+ foreach($line as $pName => $pValue) fwrite($cFile, $printTab.$pName.$printSpace."=".$printSpace.$pValue.PHP_EOL); // "\t".$pName = add TAB for output formatting
+ fwrite($cFile, PHP_EOL);
+ } else fwrite($cFile, $key.$printSpace."=".$printSpace.$line.PHP_EOL);
+ } // end foreach
+ fclose($cFile);
+ if (!empty($hashTag)) header("Location:#{$hashTag}");
+}
+
+// load addon config - use selected config from Bastille tab or alternative if exist
+$configAddonArray = parseConfigFile($configAddon); // read addon config file
+if (empty($configAddonArray['']['ALTERNATIVE_CONFIG'])) $configFile = str_replace('"', "", $configAddonArray['']['BASTILLE_CONFIG']); // get Bastille config file path and name
+else $configFile = str_replace('"', "", $configAddonArray['']['ALTERNATIVE_CONFIG']); // get Bastille config file path and name
+
+// load Bastille config
+if (!is_file($configFile)) $input_errors[] = sprintf(gtext("%s not found!"), gettext("Configuration File")." {$configFile}");
+else {
+ $configArray = parseConfigFile($configFile); // parse Bastille config file
+ //$savemsg = gtext("Loaded config file").": ".basename($configFile)."";
+}
+
+if ($_POST) {
+ unset($input_errors);
+
+ if (isset($_POST['saveParam']) && $_POST['saveParam']) { // saveParam s/n/v: [[outputs.influxdb]]#urls outputsinfluxdburls ["http://192.168.1.XYZ:8086"]
+ $buttonTag = explode("#", $_POST['saveParam']); // buttonTag[0] = section, buttonTag[1] = paramName
+ $hashTag = str_replace(["[", "]", ".", "#"], "", $buttonTag[0]); // create destination to jump to after post
+ $nameTag = str_replace(["[", "]", ".", "#"], "", $_POST['saveParam']); // nameTag =
+ $configArray[$buttonTag[0]][$buttonTag[1]] = $_POST[$nameTag]; // save param to section
+ # $savemsg .= "saveParam s/n/v: ".$_POST['saveParam']." ".$nameTag." ".$_POST[$nameTag];
+ }
+
+ if (empty($input_errors) && !isset($_POST['loadConfig'])) saveConfigFile($configFile, $configArray, $hashTag);
+}
+
+bindtextdomain("xigmanas", $textdomain);
+include("fbegin.inc");
+bindtextdomain("xigmanas", $textdomain_bastille);
+?>
+
+
diff --git a/gui/bastille_manager_editor.php b/gui/bastille_manager_editor.php
new file mode 100644
index 0000000..5ac2316
--- /dev/null
+++ b/gui/bastille_manager_editor.php
@@ -0,0 +1,162 @@
+.
+ XigmaNAS® is a registered trademark of Michael Zoon (zoon01@xigmanas.com).
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ 3. Neither the name of the developer nor the names of contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE DEVELOPER ``AS IS'' AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE DEVELOPER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+*/
+
+require_once 'auth.inc';
+require_once 'guiconfig.inc';
+require_once("bastille_manager-lib.inc");
+
+$savetopath = "{$rootfolder}/jails/";
+if (isset($_POST['savetopath'])) {
+ $savetopath = htmlspecialchars($_POST['savetopath']);
+}
+if(isset($_POST['submit'])) {
+ switch($_POST['submit']) {
+ case 'edit':
+ if(preg_match('/\S/', $savetopath)) {
+ if(file_exists($savetopath) && is_file($savetopath)) {
+ $content = file_get_contents($savetopath);
+ $edit_area = "";
+ if (stristr($savetopath, ".php") == true) $language = "php";
+ else if (stristr($savetopath, ".inc") == true) $language = "php";
+ else if (stristr($savetopath, ".sh") == true) $language = "core";
+ else if (stristr($savetopath, ".xml") == true) $language = "xml";
+ else if (stristr($savetopath, ".js") == true) $language = "js";
+ else if (stristr($savetopath, ".css") == true) $language = "css";
+ } else {
+ $savemsg = sprintf('%s %s', gtext('File not found'), $savetopath);
+ $content = '';
+ $savetopath = '';
+ }
+ }
+ break;
+ case 'save':
+ if(preg_match('/\S/', $savetopath)) {
+ conf_mount_rw();
+ $content = preg_replace("/\r/","",$_POST['code']) ;
+ file_put_contents($savetopath, $content);
+ $edit_area = "";
+ $savemsg = sprintf('%s %s', gtext('Saved file to'), $savetopath);
+ if ($savetopath === "{$g['cf_conf_path']}/config.xml") {
+ unlink_if_exists("{$g['tmp_path']}/config.cache");
+ }
+ conf_mount_ro();
+ }
+ break;
+ case 'bastille':
+ // Return to Bastille index.
+ header('Location: bastille_manager_gui.php');
+ break;
+ }
+}
+
+if(isset($_POST['rows']) && !empty($_POST['rows'])) {
+ $rows = $_POST['rows'];
+} else {
+ $rows = 30;
+}
+if(isset($_POST['cols']) && !empty($_POST['cols'])) {
+ $cols = $_POST['cols'];
+} else {
+ $cols = 66;
+}
+$pgtitle = [gtext('Bastille'), gtext('File Editor')];
+include 'fbegin.inc';
+?>
+
+
+
+.
+ XigmaNAS® is a registered trademark of Michael Zoon (zoon01@xigmanas.com).
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ 3. Neither the name of the developer nor the names of contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE DEVELOPER ``AS IS'' AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE DEVELOPER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+*/
+
+require_once 'auth.inc';
+require_once 'guiconfig.inc';
+require_once 'bastille_manager-lib.inc';
+
+$sphere_scriptname = basename(__FILE__);
+$sphere_scriptname_child = 'bastille_manager_util.php';
+$sphere_header = 'Location: '.$sphere_scriptname;
+$sphere_header_parent = $sphere_header;
+$sphere_array = [];
+$sphere_record = [];
+$checkbox_member_name = 'checkbox_member_array';
+$checkbox_member_array = [];
+$checkbox_member_record = [];
+$gt_record_add = gtext('Create new jail');
+$gt_record_mod = gtext('Utilities');
+$gt_selection_start = gtext('Start Selected');
+$gt_selection_stop = gtext('Stop Selected');
+$gt_selection_restart = gtext('Restart Selected');
+$gt_record_inf = gtext('Information');
+$gt_selection_start_confirm = gtext('Do you really want to start selected jail(s)?');
+$gt_selection_stop_confirm = gtext('Do you want to stop the selected jail(s)?');
+$gt_selection_restart_confirm = gtext('Do you want to restart the selected jail(s)?');
+$img_path = [
+ 'add' => 'images/add.png',
+ 'mod' => 'images/edit.png',
+ 'del' => 'images/delete.png',
+ 'loc' => 'images/locked.png',
+ 'unl' => 'images/unlocked.png',
+ 'mai' => 'images/maintain.png',
+ 'inf' => 'images/info.png',
+ 'ena' => 'images/status_enabled.png',
+ 'dis' => 'images/status_disabled.png',
+ 'mup' => 'images/up.png',
+ 'mdn' => 'images/down.png'
+];
+
+$jls_list = get_jail_infos();
+$sphere_array = $jls_list;
+
+if($_POST):
+ if(isset($_POST['apply']) && $_POST['apply']):
+ $ret = array('output' => [], 'retval' => 0);
+ if(!file_exists($d_sysrebootreqd_path)):
+ // Process notifications
+ endif;
+ $savemsg = get_std_save_message($ret['retval']);
+ if($ret['retval'] == 0):
+ updatenotify_delete($sphere_notifier);
+ header($sphere_header);
+ exit;
+ endif;
+ updatenotify_delete($sphere_notifier);
+ $errormsg = implode("\n", $ret['output']);
+ endif;
+
+ if(isset($_POST['start_selected_jail']) && $_POST['start_selected_jail']):
+ $checkbox_member_array = isset($_POST[$checkbox_member_name]) ? $_POST[$checkbox_member_name] : [];
+ foreach($checkbox_member_array as $checkbox_member_record):
+ if(false !== ($index = array_search_ex($checkbox_member_record, $sphere_array, 'jailname'))):
+ if(!isset($sphere_array[$index]['protected'])):
+ $cmd = ("/usr/local/bin/bastille start {$checkbox_member_record}");
+ $return_val = mwexec($cmd);
+ if($return_val == 0):
+ //$savemsg .= gtext("Jail(s) started successfully.");
+ header($sphere_header);
+ else:
+ $errormsg .= gtext("Failed to start jail(s).");
+ endif;
+ endif;
+ endif;
+ endforeach;
+ endif;
+
+ if(isset($_POST['stop_selected_jail']) && $_POST['stop_selected_jail']):
+ $checkbox_member_array = isset($_POST[$checkbox_member_name]) ? $_POST[$checkbox_member_name] : [];
+ foreach($checkbox_member_array as $checkbox_member_record):
+ if(false !== ($index = array_search_ex($checkbox_member_record, $sphere_array, 'jailname'))):
+ if(!isset($sphere_array[$index]['protected'])):
+ $cmd = ("/usr/local/bin/bastille stop {$checkbox_member_record}");
+ $return_val = mwexec($cmd);
+ if($return_val == 0):
+ //$savemsg .= gtext("Jail(s) stopped successfully.");
+ header($sphere_header);
+ else:
+ $errormsg .= gtext("Failed to stop jail(s).");
+ endif;
+ endif;
+ endif;
+ endforeach;
+ endif;
+
+ if(isset($_POST['restart_selected_jail']) && $_POST['restart_selected_jail']):
+ $checkbox_member_array = isset($_POST[$checkbox_member_name]) ? $_POST[$checkbox_member_name] : [];
+ foreach($checkbox_member_array as $checkbox_member_record):
+ if(false !== ($index = array_search_ex($checkbox_member_record, $sphere_array, 'jailname'))):
+ if(!isset($sphere_array[$index]['protected'])):
+ $cmd = ("/usr/local/bin/bastille restart {$checkbox_member_record}");
+ $return_val = mwexec($cmd);
+ if($return_val == 0):
+ //$savemsg .= gtext("Jail(s) restarted successfully.");
+ header($sphere_header);
+ else:
+ $errormsg .= gtext("Failed to restart jail(s).");
+ endif;
+ endif;
+ endif;
+ endforeach;
+ endif;
+endif;
+
+$pgtitle = [gtext("Extensions"), gtext('Bastille')];
+include 'fbegin.inc';
+?>
+
+
+ add_area_tabnav()->
+ push()->
+ add_tabnav_upper()->
+ ins_tabnav_record('bastille_manager_gui.php',gettext('Containers'))->
+ ins_tabnav_record('bastille_manager_info.php',gettext('Information'))->
+ ins_tabnav_record('bastille_manager_maintenance.php',gettext('Maintenance'));
+$document->render();
+?>
+
+.
+ XigmaNAS® is a registered trademark of Michael Zoon (zoon01@xigmanas.com).
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ 3. Neither the name of the developer nor the names of contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE DEVELOPER ``AS IS'' AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE DEVELOPER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+*/
+
+require_once 'auth.inc';
+require_once 'guiconfig.inc';
+require_once("bastille_manager-lib.inc");
+
+function jls_get_jail_list(string $entity_name = NULL) {
+ if(isset($entity_name)):
+ $cmd = "/usr/sbin/jls -v -j $entity_name 2>&1";
+ else:
+ $cmd = '/usr/sbin/jls -v 2>&1';
+ endif;
+ unset($output);
+ mwexec2($cmd,$output);
+ return implode(PHP_EOL,$output);
+}
+
+function jls_get_all(string $entity_name = NULL) {
+ if(isset($entity_name)):
+ $cmd = "/usr/sbin/jls -qn -j $entity_name | tr -s \" \" \"\n\" 2>&1";
+ else:
+ $cmd = ':';
+ endif;
+ unset($a_names);
+ mwexec2($cmd,$a_names);
+ if(is_array($a_names) && count($a_names) > 0):
+ $names = implode(' ',array_map('escapeshellarg',$a_names));
+ unset($output);
+ mwexec2($cmd,$output);
+ else:
+ $output = [gtext('Parameters information available for individual selection only.')];
+ endif;
+ return implode(PHP_EOL,$output);
+}
+
+$entity_name = NULL;
+if(isset($_GET['uuid']) && is_string($_GET['uuid'])):
+ $entity_name = sprintf('%s',$_GET['uuid']);
+endif;
+$pgtitle = [gtext("Extensions"), gtext('Bastille'),gtext('Information')];
+include 'fbegin.inc';
+$document = new co_DOMDocument();
+$document->
+ add_area_tabnav()->
+ push()->
+ add_tabnav_upper()->
+ ins_tabnav_record('bastille_manager_gui.php',gettext('Containers'),gettext('Reload page'),true)->
+ ins_tabnav_record('bastille_manager_info.php',gettext('Information'),gettext('Reload page'),true)->
+ ins_tabnav_record('bastille_manager_maintenance.php',gettext('Maintenance'),gettext('Reload page'),true);
+$document->render();
+?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
=gtext('Summary');?>
+
+
=jls_get_jail_list($entity_name);?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
=gtext('Parameters');?>
+
+
=jls_get_all($entity_name);?>
+
+
+
+
+
+
+
diff --git a/gui/bastille-gui.php b/gui/bastille_manager_maintenance.php
similarity index 60%
rename from gui/bastille-gui.php
rename to gui/bastille_manager_maintenance.php
index a07688e..810cfe5 100644
--- a/gui/bastille-gui.php
+++ b/gui/bastille_manager_maintenance.php
@@ -1,48 +1,50 @@
.
All rights reserved.
Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ 3. Neither the name of the developer nor the names of contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
- 1. Redistributions of source code must retain the above copyright notice, this
- list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
- The views and conclusions contained in the software and documentation are those
- of the authors and should not be interpreted as representing official policies,
- either expressed or implied, of the NAS4Free Project.
+ THIS SOFTWARE IS PROVIDED BY THE DEVELOPER ``AS IS'' AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE DEVELOPER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
*/
+
require("auth.inc");
require("guiconfig.inc");
+require_once("bastille_manager-lib.inc");
$application = "Bastille";
-$pgtitle = array(gtext("Extensions"), "Bastille");
+$pgtitle = array(gtext("Extensions"), "Bastille", "Maintenance");
-// For NAS4Free 10.x versions.
+// For legacy product versions.
$return_val = mwexec("/bin/cat /etc/prd.version | cut -d'.' -f1 | /usr/bin/grep '10'", true);
if ($return_val == 0) {
if (is_array($config['rc']['postinit'] ) && is_array( $config['rc']['postinit']['cmd'] ) ) {
@@ -50,29 +52,15 @@ if ($return_val == 0) {
}
}
-// Initialize some variables.
-//$rootfolder = dirname($config['rc']['postinit']['cmd'][$i]);
-$confdir = "/var/etc/bastilleconf";
-$cwdir = exec("/usr/bin/grep 'INSTALL_DIR=' {$confdir}/conf/bastille_config | cut -d'\"' -f2");
-$rootfolder = $cwdir;
-$configfile = "{$rootfolder}/conf/bastille_config";
-$versionfile = "{$rootfolder}/version";
-$date = strftime('%c');
-$logfile = "{$rootfolder}/log/bastille_ext.log";
-$logevent = "{$rootfolder}/log/bastille_last_event.log";
+// Set default backup directory.
+if (1 == mwexec("/bin/cat {$configfile} | /usr/bin/grep 'BACKUP_DIR='")) {
+ if (is_file("{$configfile}")) exec("/usr/sbin/sysrc -f {$configfile} BACKUP_DIR={$rootfolder}/backups");
+}
+$backup_path = exec("/bin/cat {$configfile} | /usr/bin/grep 'BACKUP_DIR=' | cut -d'\"' -f2");
+
$prdname = "bastille";
$tarballversion = "/usr/local/bin/bastille";
-if ($rootfolder == "") $input_errors[] = gtext("Extension installed with fault");
-else {
-// Initialize locales.
- $textdomain = "/usr/local/share/locale";
- $textdomain_bastille = "/usr/local/share/locale-bastille";
- if (!is_link($textdomain_bastille)) { mwexec("ln -s {$rootfolder}/locale-bastille {$textdomain_bastille}", true); }
- bindtextdomain("xigmanas", $textdomain_bastille);
-}
-if (is_file("{$rootfolder}/postinit")) unlink("{$rootfolder}/postinit");
-
if ($_POST) {
if(isset($_POST['upgrade']) && $_POST['upgrade']):
$cmd = sprintf('%1$s/bastille-init -u > %2$s',$rootfolder,$logevent);
@@ -105,7 +93,7 @@ if ($_POST) {
if (is_link("/var/cache/pkg")) mwexec("rm /var/cache/pkg", true);
if (is_link("/var/db/pkg")) mwexec("rm /var/db/pkg && mkdir /var/db/pkg", true);
- // Remove postinit cmd in NAS4Free 10.x versions.
+ // Remove postinit cmd in legacy product versions.
$return_val = mwexec("/bin/cat /etc/prd.version | cut -d'.' -f1 | /usr/bin/grep '10'", true);
if ($return_val == 0) {
if (is_array($config['rc']['postinit']) && is_array($config['rc']['postinit']['cmd'])) {
@@ -117,7 +105,7 @@ if ($_POST) {
write_config();
}
- // Remove postinit cmd in NAS4Free later versions.
+ // Remove postinit cmd in later product versions.
if (is_array($config['rc']) && is_array($config['rc']['param'])) {
$postinit_cmd = "{$rootfolder}/bastille-init";
$value = $postinit_cmd;
@@ -135,6 +123,29 @@ if ($_POST) {
header("Location:index.php");
}
+ if (isset($_POST['save']) && $_POST['save']) {
+ // Ensure to have NO whitespace & trailing slash.
+ $backup_path = rtrim(trim($_POST['backup_path']),'/');
+ if ("{$backup_path}" == "") {
+ $backup_path = "{$rootfolder}/backups";
+ }
+ if (!is_file($backup_path)) {
+ $cmd = "/usr/sbin/sysrc -f {$configfile} BACKUP_DIR={$backup_path}";
+ unset($retval);mwexec($cmd,$retval);
+ if ($retval == 0) {
+ $savemsg .= gtext("Extension settings saved successfully.");
+ exec("echo '{$date}: {$application} Extension settings saved successfully' >> {$logfile}");
+ }
+ else {
+ $input_errors[] = gtext("Failed to save extension settings.");
+ exec("echo '{$date}: {$application} Failed to save extension settings' >> {$logfile}");
+ }
+ }
+ else {
+ $input_errors[] = gtext("Failed to save extension settings.");
+ exec("echo '{$date}: {$application} Failed to save extension settings' >> {$logfile}");
+ }
+ }
}
function get_version_bastille() {
@@ -185,11 +196,33 @@ $(document).ready(function(){
}
//-->
-
+
diff --git a/gui/bastille_manager_util.php b/gui/bastille_manager_util.php
new file mode 100644
index 0000000..165b78f
--- /dev/null
+++ b/gui/bastille_manager_util.php
@@ -0,0 +1,376 @@
+.
+ XigmaNAS® is a registered trademark of Michael Zoon (zoon01@xigmanas.com).
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ 3. Neither the name of the developer nor the names of contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE DEVELOPER ``AS IS'' AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE DEVELOPER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+*/
+
+require_once 'auth.inc';
+require_once 'guiconfig.inc';
+require_once("bastille_manager-lib.inc");
+
+if(isset($_GET['uuid'])):
+ $uuid = $_GET['uuid'];
+endif;
+if(isset($_POST['uuid'])):
+ $uuid = $_POST['uuid'];
+endif;
+
+$pgtitle = [gtext("Extensions"), gtext('Bastille'),gtext('Utilities')];
+
+if(isset($_GET['jailname'])):
+ $container = $_GET['jailname'];
+endif;
+if(isset($_POST['jailname'])):
+ $container = $_POST['jailname'];
+endif;
+
+$cnid = FALSE;
+if(isset($container) && !empty($container)):
+ $pconfig['uuid'] = uuid();
+ $pconfig['jailname'] = $container;
+ if(preg_match('/^([^\/\@]+)(\/([^\@]+))?\@(.*)$/', $pconfig['jailname'], $m)):
+ $pconfig['name'] = $m[''];
+ else:
+ $pconfig['name'] = 'unknown';
+ endif;
+ $pconfig['newname'] = '';
+ $pconfig['recursive'] = false;
+ $pconfig['action'] = 'activate';
+else:
+ // not supported
+ $pconfig = [];
+endif;
+
+if($_POST):
+ global $configfile;
+ global $backup_path;
+ global $rootfolder;
+ unset($input_errors);
+ $pconfig = $_POST;
+ if(isset($_POST['Cancel']) && $_POST['Cancel']):
+ header('Location: bastille_manager_gui.php');
+ exit;
+ endif;
+ if(isset($_POST['action'])):
+ $action = $_POST['action'];
+ endif;
+ if(empty($action)):
+ $input_errors[] = sprintf(gtext("The attribute '%s' is required."), gtext("Action"));
+ else:
+ switch($action):
+ case 'advanced':
+ // Input validation not required
+ if(empty($input_errors)):
+ $container = [];
+ $container['uuid'] = $_POST['uuid'];
+ $container['jailname'] = $_POST['jailname'];
+ $confirm_name = $pconfig['confirmname'];
+ $item = $container['jailname'];
+ if ($_POST['advanced']):
+ header('Location: bastille_manager_editor.php');
+ exit;
+ else:
+ $errormsg .= gtext("Failed to open editor, confirmation is required.");
+ endif;
+ endif;
+ break;
+
+ case 'backup':
+ // Input validation not required
+ if(empty($input_errors)):
+ $container = [];
+ $container['uuid'] = $_POST['uuid'];
+ $container['jailname'] = $_POST['jailname'];
+ $confirm_name = $pconfig['confirmname'];
+ $item = $container['jailname'];
+ $date = (strftime('%Y-%m-%d-%H%M%S'));
+ $cmd = ("cd {$rootfolder}/jails && /usr/bin/tar -cf {$item}-{$date}.tar --exclude=.bastille --exclude=.template {$item} && /bin/mv {$item}-{$date}.tar {$backup_path}");
+ unset($output,$retval);mwexec2($cmd,$output,$retval);
+ if($retval == 0):
+ $savemsg .= gtext("Container backup process completed successfully.");
+ //header('Location: bastille_manager_gui.php');
+ //exit;
+ else:
+ $errormsg .= gtext("Failed to backup container.");
+ endif;
+ endif;
+ break;
+
+ case 'autoboot':
+ // Input validation not required
+ if(empty($input_errors)):
+ $container = [];
+ $container['uuid'] = $_POST['uuid'];
+ $container['jailname'] = $_POST['jailname'];
+ $confirm_name = $pconfig['confirmname'];
+ $item = $container['jailname'];
+ $cmd = ("/usr/sbin/sysrc -f {$configfile} {$item}_AUTO_START=\"YES\"");
+ unset($output,$retval);mwexec2($cmd,$output,$retval);
+ if($retval == 0):
+ header('Location: bastille_manager_gui.php');
+ exit;
+ else:
+ $errormsg .= gtext("Failed to set auto-boot.");
+ endif;
+ endif;
+ break;
+
+ case 'noauto':
+ // Input validation not required
+ if(empty($input_errors)):
+ $container = [];
+ $container['uuid'] = $_POST['uuid'];
+ $container['jailname'] = $_POST['jailname'];
+ $confirm_name = $pconfig['confirmname'];
+ $item = $container['jailname'];
+ $cmd = ("/usr/sbin/sysrc -f {$configfile} {$item}_AUTO_START=\"NO\"");
+ unset($output,$retval);mwexec2($cmd,$output,$retval);
+ if($retval == 0):
+ header('Location: bastille_manager_gui.php');
+ exit;
+ else:
+ $errormsg .= gtext("Failed to set no-auto.");
+ endif;
+ endif;
+ break;
+
+ case 'fstab':
+ // Input validation not required
+ if(empty($input_errors)):
+ $container = [];
+ $container['uuid'] = $_POST['uuid'];
+ $container['jailname'] = $_POST['jailname'];
+ $confirm_name = $pconfig['confirmname'];
+ $item = $container['jailname'];
+ $sourcedir = $pconfig['source_path'];
+ $targetdir = $pconfig['target_path'];
+
+ if ($_POST['readonly']):
+ $dir_mode = "ro";
+ else:
+ $dir_mode = "rw";
+ endif;
+
+ $cmd = ("/bin/echo \"{$sourcedir} {$targetdir} nullfs {$dir_mode} 0 0\" >> {$rootfolder}/jails/{$item}/fstab");
+ unset($output,$retval);mwexec2($cmd,$output,$retval);
+ if($retval == 0):
+ if ($_POST['createdir']):
+ mkdir("$targetdir");
+ endif;
+
+ $savemsg .= gtext("Container backup process completed successfully.");
+ //header('Location: bastille_manager_gui.php');
+ //exit;
+ else:
+ $errormsg .= gtext("Failed to backup container.");
+ endif;
+ endif;
+ break;
+
+ case 'delete':
+ // Delete a contained
+ if(empty($input_errors)):
+ $container = [];
+ $container['uuid'] = $_POST['uuid'];
+ $container['jailname'] = $_POST['jailname'];
+ $confirm_name = $pconfig['confirmname'];
+ $item = $container['jailname'];
+
+ if(strcmp($confirm_name, $item) !== 0):
+ $errormsg .= gtext("Failed to destroy container, name confirmation is required.");
+ break;
+ else:
+ if ($_POST['nowstop']):
+ $cmd = ("/usr/local/bin/bastille stop {$item} && /usr/local/bin/bastille destroy {$item}");
+ else:
+ $cmd = ("/usr/local/bin/bastille destroy {$item}");
+ endif;
+ unset($output,$retval);mwexec2($cmd,$output,$retval);
+ if($retval == 0):
+ exec("/usr/sbin/sysrc -f {$configfile} -qx {$item}_AUTO_START");
+ header('Location: bastille_manager_gui.php');
+ exit;
+ else:
+ $errormsg .= gtext("Failed to destroy container, make sure this container is stopped.");
+ endif;
+ endif;
+ endif;
+ break;
+ default:
+ $input_errors[] = sprintf(gtext("The attribute '%s' is invalid."), 'action');
+ break;
+ endswitch;
+ endif;
+endif;
+include 'fbegin.inc';
+?>
+
+
+ add_area_tabnav()->
+ push()->
+ add_tabnav_upper()->
+ ins_tabnav_record('bastille_manager_gui.php',gettext('Containers'),gettext('Reload page'),true)->
+ ins_tabnav_record('bastille_manager_info.php',gettext('Information'),gettext('Reload page'),true)->
+ ins_tabnav_record('bastille_manager_maintenance.php',gettext('Maintenance'),gettext('Reload page'),true);
+$document->render();
+?>
+
+
+
diff --git a/gui/ext/bastille-gui/menu.inc b/gui/ext/bastille-gui/menu.inc
deleted file mode 100644
index f98b809..0000000
--- a/gui/ext/bastille-gui/menu.inc
+++ /dev/null
@@ -1 +0,0 @@
-Bastille
\ No newline at end of file
diff --git a/gui/ext/bastille/menu.inc b/gui/ext/bastille/menu.inc
new file mode 100644
index 0000000..9db5777
--- /dev/null
+++ b/gui/ext/bastille/menu.inc
@@ -0,0 +1 @@
+Bastille
\ No newline at end of file
diff --git a/gui/images/bsd_icon.png b/gui/images/bsd_icon.png
new file mode 100644
index 0000000..6b5e20d
Binary files /dev/null and b/gui/images/bsd_icon.png differ
diff --git a/gui/images/icon.png b/gui/images/icon.png
new file mode 100644
index 0000000..6784de3
Binary files /dev/null and b/gui/images/icon.png differ
diff --git a/gui/images/icon_small.png b/gui/images/icon_small.png
new file mode 100644
index 0000000..9f35796
Binary files /dev/null and b/gui/images/icon_small.png differ
diff --git a/release_notes b/release_notes
deleted file mode 100644
index 44c9969..0000000
--- a/release_notes
+++ /dev/null
@@ -1,11 +0,0 @@
-======================
-= Extension Bastille =
-======================
-Version Description
-
-0.0.6......Switch to alternate repository supporting 11.3-RELEASE base.
-0.0.5......Start all jails once.
-0.0.4......Start jails if directory not empty.
-0.0.3......Minor code adjustment.
-0.0.2......Added addon preview page.
-0.0.1......First Release.
diff --git a/version b/version
index 1750564..3eefcb9 100644
--- a/version
+++ b/version
@@ -1 +1 @@
-0.0.6
+1.0.0