Deprecated-Unsupported/Shell Projects/Lazy-Share/lazyShare-v3.01/resources/bkup/run.sh

208 lines
8.1 KiB
Bash
Raw Normal View History

2021-02-18 23:45:52 +00:00
#!/bin/bash
main() {
dir=$(pwd)
altSrvrName="nanoweb"
srvrName="Nanoweb"
ansr=$(zenity --text "Please chose an option." --radiolist --list \
--column "Options" --column "Descriptions" \
TRUE "Scan Dirs?" \
FALSE "Edit main settings" \
FALSE "Start or Stop ${srvrName}")
case "$ansr" in
"Scan Dirs?" ) dirScan;;
"Edit main settings" ) passwdReq;;
"Start or Stop ${srvrName}" ) webSrvrStrt;;
esac
}
dirScan() {
find . -type d > /tmp/lzyDirList.txt
filename="/tmp/lzyDirList.txt"
while read -r line ; do
pre=\""${line}"
name=`echo ${pre} | sed "s|\".|"${dir}"|g" | sed "s|*|*\"|g"`
if [[ "${name}" == *"resources"* ]] || \
[[ "${name}" == *"Uploads"* ]]; then
echo "This is a resources dir..."
else
if [ -f "${name}"/index.php ]; then
echo "Index.php for "${name}" already present..."
else
work
fi
fi
done < "${filename}"
}
work() {
mv lazyShareScan.sh "${name}/"
cd "${name}/"
bash ./lazyShareScan.sh
mv lazyShareScan.sh "${dir}"
cd "${dir}"
}
################## SETTINGS SECTION ##################
passwdReq()
{
PASSWD="$(zenity --password --title=Authentication)\n"
srvrEdit;
}
srvrEdit() {
auto="Turn psudo auto scan ON or Off"
theme="Change Theme"
portng="Set Port"
polcing="Set User And Group"
logng="Set Logging Status"
docdir="Set DocumentRoot"
nanoSrvr="Open The ServerConf In Nano"
main="START MENU"
exit="Exit Script"
selec=$(zenity --list \
--text "What would you like to edit in the ServerConf file?" \
--radiolist --column "Select" --column "Options" \
TRUE "Change Theme" \
FALSE "Set Port" \
FALSE "Set User And Group" \
FALSE "Set Logging Status" \
FALSE "Set DocumentRoot" \
FALSE "Open The ServerConf In Nano" \
FALSE "START MENU" FALSE "Exit Script" \
--height 300);
case "$selec" in
"${theme}" ) theme;;
"${portng}" ) port;;
"${polcing}" ) policy;;
"${logng}" ) logs;;
"${docdir}" ) docRoot;;
"${nanoSrvr}" ) nanoSrvrConf;;
"${main}" ) main;;
"${exit}" ) exit;;
esac
}
autoOnNOff() {
x=$(zenity --entry --text "Turn On/Off psudo auto scanning?
Default is : off .
" --entry-text "off");
sed -i 1s/"auto=*.*;"/"auto=${x};"/g $HOME/.config/lazyShareSettings/config.txt
srvrEdit;
}
theme() {
theme=$(zenity --list \
--text "What would you like to edit in the ServerConf file?" \
--radiolist --column "Select" --column "Options" \
TRUE "List On The Left" \
FALSE "List Centered" \
FALSE "Horizontal List" \
FALSE "Grid List" \
--height 175);
case "${theme}" in
"List On The Left" ) echo "" > ./resources/settings-notes/css.css
cat ./resources/themes/"List On The Left.css" > ./resources/settings-notes/css.css;;
"List Centered" ) echo "" > ./resources/settings-notes/css.css
cat ./resources/themes/"List Centered.css" > ./resources/settings-notes/css.css;;
"Horizontal List" ) echo "" > ./resources/settings-notes/css.css
cat ./resources/themes/"Horizontal List.css" > ./resources/settings-notes/css.css;;
"Grid List" ) echo "" > ./resources/settings-notes/css.css
cat ./resources/themes/"Grid List.css" > ./resources/settings-notes/css.css;;
esac
srvrEdit
}
port() {
x=$(zenity --entry --text "What will be the port that the server runs on?
Anything bellow 1024 means the server must run as root.
Default is port: 80 .
" --entry-text "80");
echo -e $PASSWD | sudo -S sed -i 13s/"ListenPort = *.*"/"ListenPort = ${x}"/g /etc/nanoweb/nanoweb.conf
srvrEdit;
}
policy() {
User=$(zenity --entry --text "What will be the User for the server?
(::-WARNING-::) Please leave as default unless you know EXACTLY
what you are doing! Changing user and group policies can
affect security of the system!
The default is : www-data ." --entry-text "www-data");
echo -e $PASSWD | sudo -S sed -i 187s/"User = *.*"/"User = ${User}"/g /etc/nanoweb/nanoweb.conf
Group=$(zenity --entry --text "What will be the Group for the server?
(::-WARNING-::) Please leave as default unless you know EXACTLY
what you are doing! Changing user and group policies can
affect security of the system!
The default is : www-data." --entry-text "www-data");
echo -e $PASSWD | sudo -S sed -i 188s/"Group = *.*"/"Group = ${Group}"/g /etc/nanoweb/nanoweb.conf
srvrEdit;
}
logs() {
logs=$(zenity --list --text "Do you wish to have AccessLog and ErrorLog enabled?
If this server isn't running 24/7 nor a production server then it can be OK to keep
logging off. It may also lessen the system resource load and speed up the server.
If this server runs 24/7 or is a production server then we advise keeping logging on
as added security. Respectively, it may add more resource demands and slow down the server.
Frankly, the effects are negligible in both instances so it's up to you.
The default is : Enabled .
" --radiolist --column "Select" --column "Options" TRUE Enable FALSE Disable --height 280);
yes="Enable"
no="Disable"
if [[ "${logs}" == "${yes}" ]]; then
echo -e $PASSWD | sudo -S sed -i 194s/"#LoggerProcess = *.*"/"LoggerProcess = 2"/g /etc/nanoweb/nanoweb.conf
echo -e $PASSWD | sudo -S sed -i 197s/"#LoggerUser"/"LoggerUser"/g /etc/nanoweb/nanoweb.conf
echo -e $PASSWD | sudo -S sed -i 198s/"#LoggerGroup"/"LoggerGroup"/g /etc/nanoweb/nanoweb.conf
echo -e $PASSWD | sudo -S sed -i 201s/"#LogDir"/"LogDir"/g /etc/nanoweb/nanoweb.conf
echo -e $PASSWD | sudo -S sed -i 207s/"#Log"/"Log"/g /etc/nanoweb/nanoweb.conf
elif [[ "${logs}" == "${no}" ]]; then
echo -e $PASSWD | sudo -S sed -i 194s/"LoggerProcess = *.*"/"#LoggerProcess = 0"/g /etc/nanoweb/nanoweb.conf
echo -e $PASSWD | sudo -S sed -i 197s/"LoggerUser"/"#LoggerUser"/g /etc/nanoweb/nanoweb.conf
echo -e $PASSWD | sudo -S sed -i 198s/"LoggerGroup"/"#LoggerGroup"/g /etc/nanoweb/nanoweb.conf
echo -e $PASSWD | sudo -S sed -i 201s/"LogDir"/"#LogDir"/g /etc/nanoweb/nanoweb.conf
echo -e $PASSWD | sudo -S sed -i 207s/"Log"/"#Log"/g /etc/nanoweb/nanoweb.conf
fi
srvrEdit;
}
nanoSrvrConf() {
echo -e $PASSWD | sudo -S xterm -e nano /etc/nanoweb/nanoweb.conf
srvrEdit;
}
docRoot() {
docDir=$(zenity --entry \
--text "What do you wish to set as DocumentRoot?
Document root is what the server defines as the directory in which files will
be served from. Group permissions must allow for the directory to be used so
please be aware of that.
The default is : /var/www/nanoweb ." --entry-text "/var/www/nanoweb");
echo -e $PASSWD | sudo -S sed -i 204s,"DocumentRoot = *.*","DocumentRoot = ${docDir}",g /etc/nanoweb/nanoweb.conf
srvrEdit;
}
webSrvrStrt() {
noRtStrt="Start $srvrName No Root?" ; noRtStp="Stop $srvrName No Root?" ;
rtStrt="Start $srvrName Root?" ; rtStp="Stop $srvrName Root?";
main="START MENU" ; exit="Exit Script" ;
ansr=$(zenity --list --text "Please select an option bellow to apply!!
" --radiolist --column "Select" --column "Options
" TRUE "Start $srvrName No Root?" FALSE "Stop $srvrName No Root?
" FALSE "Start $srvrName Root?" FALSE "Stop $srvrName Root?
" FALSE "START MENU" FALSE "Exit Script" --height 330);
case "${ansr}" in
"${noRtStrt}" ) $altSrvrName & main;;
"${noRtStp}" ) pkill $altSrvrName & main;;
"${rtStrt}" ) PASSWD="$(zenity --password --title=Authentication)\n"
echo -e $PASSWD | sudo -S $altSrvrName & main;;
"${rtStp}" ) PASSWD="$(zenity --password --title=Authentication)\n"
echo -e $PASSWD | sudo -S pkill $altSrvrName & main;;
"${main}" ) main;;
"${exit}" ) exit;;
esac
}
main