Advertisement
Guest User

Untitled

a guest
May 5th, 2017
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 8.98 KB | None | 0 0
  1. #!/bin/bash
  2. # Web Server Configuration Script.
  3.  
  4. # Variables:
  5. WWWROOT="/home/premise/core"
  6.  
  7. APACHEROOT="/etc/httpd"
  8.  
  9. APACHECONFD="/etc/httpd/conf.d"
  10.  
  11. APACHECONF="/etc/httpd/conf"
  12.  
  13. PHPADMIN="/usr/share/phpMyAdmin"
  14.  
  15. MYSQLDATABASES="/var/lib/mysql"
  16.  
  17. SSLCONFIGS="/etc/pki/tls"
  18.  
  19. SSLDEFAULTKEYS="/etc/pki/tls/misc"
  20.  
  21. BACKUPDIR="/home/premise/core/backup"
  22.  
  23. FILELIMIT="2M"
  24.  
  25. #Resources
  26. DESCRIPTIONS=""
  27.  
  28. # Default command:
  29. TEXT="gedit"
  30. EDITTEXT="gedit"
  31. DIR="nautilus --browser"
  32.  
  33.  
  34. function mainmenu {
  35. clear
  36. echo -e "\E[34;3m:::Web Server Administration - Main Menu :::" #BOLD BLUE
  37. echo             "============================================"
  38. echo ""
  39. echo -e "\E[31;3mType a number and press enter to view a section:" #RED
  40. echo -e "\E[36;2m" #Light Green
  41. echo -e "1.) Help"
  42. echo -e "2.) Directories"
  43. echo -e "3.) Configuration Menu"
  44. echo -e "4.) Backup Menu"
  45. echo -e "5.) Settings"
  46. echo -e "6.) Exit"
  47.   read opt
  48.   if [ "$opt" = "1" ]; then
  49.     helpmenu
  50.   elif [ "$opt" = "2" ]; then
  51.     directorymenu
  52.   elif [ "$opt" = "3" ]; then
  53.     confmenu
  54.   elif [ "$opt" = "4" ]; then
  55.     backupmenu
  56.   elif [ "$opt" = "5" ]; then
  57.     settingsmenu
  58.   elif [ "$opt" = "6" ]; then
  59.     exit
  60.   else
  61.     mainmenu
  62.   fi
  63. }
  64.  
  65. ############################################################
  66.  
  67. function directorymenu {
  68. clear
  69. echo -e "\E[34;3m:::Web Server Administration - Directory Menu :::" #BOLD BLUE
  70. echo             "============================================"
  71. echo ""
  72. echo -e "\E[31;3mDirectory Menu:" #RED
  73. echo -e "\E[36;2m" #Light Green
  74. echo -e "1.) Directory Descriptions"
  75. echo -e -n "2.) WWW Root "
  76. echo -e $WWWROOT
  77. echo -e -n "3.) APACHE Root "
  78. echo -e $APACHEROOT
  79. echo -e -n "4.) APACHE conf.d "
  80. echo -e $APACHECONF
  81. echo -e -n "5.) APACHE conf "
  82. echo -e $APACHECONFD
  83. echo -e -n "6.) MYSQL Databases "
  84. echo -e $MYSQLDATABASES
  85. echo -e -n "7.) SSL Configuration "
  86. echo -e $SSLCONFIGS
  87. echo -e -n "8.) SSL Default Keys "
  88. echo -e $SSLDEFAULTKEYS
  89. echo -e -n "9.) PHPMyAdmin "
  90. echo -e $PHPADMIN
  91. echo -e "10.) <- Return"
  92. echo ""
  93.   read opt
  94.   if [ "$opt" = "1" ]; then
  95.     $TEXT $DESCRIPTIONS
  96.   elif [ "$opt" = "2" ]; then
  97.     $DIR $WWWROOT
  98.   elif [ "$opt" = "3" ]; then
  99.     $DIR $APACHEROOT
  100.   elif [ "$opt" = "4" ]; then
  101.     $DIR $APACHECONF
  102.   elif [ "$opt" = "5" ]; then
  103.     $DIR $APACHECONFD
  104.   elif [ "$opt" = "6" ]; then
  105.     $DIR $MYSQLDATABASES
  106.   elif [ "$opt" = "7" ]; then
  107.     $DIR $SSLCONFIGS
  108.   elif [ "$opt" = "8" ]; then
  109.     $DIR $SSLDEFAULTKEYS
  110.   elif [ "$opt" = "9" ]; then
  111.     $DIR $PHPADMIN
  112.   elif [ "$opt" = "10" ]; then
  113.     mainmenu
  114.   fi
  115. echo ""
  116. echo -e "\E[34;3m [enter] ";
  117. read blank
  118. directorymenu
  119. }
  120.  
  121. ############################################################
  122.  
  123. function confmenu {
  124. clear
  125. echo -e "\E[34;3m:::Web Server Administration - Configurations :::" #BOLD BLUE
  126. echo             "================================================"
  127. echo ""
  128. echo -e "\E[31;3mConfiguration Menu:" #RED
  129. echo -e "\E[36;2m" #Light Green
  130. echo -e "1.) Edit Apache Configuration (httpd.conf)"
  131. echo -e "2.) Edit Php Configuration (php.ini)"/home/premise/core/
  132. echo -e "3.) Edit SSL Apache Configuration (ssl.conf)"
  133. echo -e "4.) Edit PhpMyAdmin Apache Configuration (phpMyAdmin.conf)"
  134. echo -e "5.) Edit PhpMyAdmin Setup Configuration (config.inc.php)"
  135. echo -e "6.) Edit Private Interface Configuration (eth0:0)"
  136. echo -e "7.) Edit Public Interface Configuration (eth0:1)"
  137. echo -e "8.) Restart Web Services (required after any changes)"
  138. echo -e "9.) Restart Network Services"
  139. echo -e "10.) Reset Mysql and Apache Runlevel (Run on Startup)"
  140. echo -e "11.) Reset Security and Ownership on databases and wwwroot"
  141. echo -e "12.) <- Return"
  142. echo ""
  143.   read opt
  144.   if [ "$opt" = "1" ]; then
  145.     $EDITTEXT "/etc/httpd/conf/httpd.conf"
  146.   elif [ "$opt" = "2" ]; then
  147.     $EDITTEXT "/etc/php.ini"
  148.   elif [ "$opt" = "3" ]; then
  149.     $EDITTEXT "/etc/httpd/conf.d/ssl.conf"
  150.   elif [ "$opt" = "4" ]; then
  151.     $EDITTEXT "/etc/httpd/conf.d/phpMyAdmin.conf"
  152.   elif [ "$opt" = "5" ]; then
  153.     $EDITTEXT "usr/share/phpMyAdmin/config.inc.php"
  154.   elif [ "$opt" = "6" ]; then
  155.     $EDITTEXT "/etc/sysconfig/network-scripts/ifcfg-eth0"
  156.   elif [ "$opt" = "7" ]; then
  157.     $EDITTEXT "/etc/sysconfig/network-scripts/ifcfg-eth0:1"
  158.   elif [ "$opt" = "8" ]; then
  159.     echo "Restarting Services ..."
  160.     service httpd stop
  161.     service mysqld stop
  162.     service mysqld start
  163.     service httpd start
  164.     echo ""
  165.     echo "Services restarted..."
  166.         echo ""
  167.         echo -e "\E[34;3m [enter] "
  168.         echo ""
  169.         read blank
  170.         confmenu
  171.   elif [ "$opt" = "9" ]; then
  172.     service network restart
  173.   elif [ "$opt" = "10" ]; then
  174.     chkconfig --levels 235 mysqld on
  175.     chkconfig --levels 235 httpd on
  176.     chkconfig --list httpd
  177.     chkconfig --list mysqld
  178.     echo ""
  179.     echo -e "\E[34;3m Levels Reset..."
  180.   elif [ "$opt" = "11" ]; then
  181.     echo "Resetting Permissions on WWW root in $WWWROOT"
  182.     chown premise -R $WWWROOT
  183.     chgrp premise -R $WWWROOT
  184.     chmod 771 -R $WWWROOT
  185.     echo "Resetting Permissions on Databases in $MYSQLDATABASES"
  186.     chown premise -R $MYSQLDATABASES
  187.     chgrp premise -R $MYSQLDATABASES
  188.     chmod 771 -R $MYSQLDATABASES
  189.     echo ""
  190.     echo "Permissions Reset"
  191.   elif [ "$opt" = "12" ]; then
  192.     mainmenu
  193.   fi
  194. echo ""
  195. echo -e "\E[34;3m [enter] "
  196. echo ""
  197. read blank
  198. confmenu
  199. }
  200. ############################################################
  201.  
  202. function backupmenu {
  203. clear
  204. echo -e "\E[34;3m:::Web Server Administration - Backup Menu :::" #BOLD BLUE
  205. echo             "============================================"
  206. echo ""
  207. echo -e "\E[31;3mBackup Options:" #RED
  208. echo -e "\E[36;2m" #Light Green
  209. echo "Perform Full backup of WWW Directory and Databases ... (Press Enter)"
  210. read blank
  211. echo -e "\E[31;3mBacking up to Root's Desktop ..."
  212. echo -e "\E[31;3mStarting SQL Structure Backup ..."
  213. echo -e "\E[36;2m"
  214. timestamp=`date +%s`
  215. BACKUPSOURCE=$BACKUPDIR
  216. BACKUPDIR="${BACKUPDIR}/backup_${timestamp}"
  217. mkdir $BACKUPDIR
  218. mysqldump --all-databases -f --skip-comments --password=r*fed*core08 --host=localhost --user=root --no-data > $BACKUPDIR/databases_structure_$timestamp.sql
  219. echo -e "\E[31;3mStructure Done!"
  220. echo ""
  221. echo -e "\E[31;3mStarting SQL Data backup ..."
  222. echo -e "\E[36;2m"
  223. mysqldump --all-databases -f --skip-comments --password=r*fed*core08 --host=localhost --user=root > $BACKUPDIR/databases_$timestamp.sql
  224. echo -e "\E[31;3mData Done!"
  225. echo ""
  226. echo "Performing MysqlHotCopy of all Databases!"
  227. echo ""
  228. echo ""
  229. echo "getting database list ..."
  230. echo ""
  231. echo -e "\E[36;2m"
  232. cd $MYSQLDATABASES
  233. ARRAY=`find * -type d -prune`
  234. cd $BACKUPDIR
  235. mkdir -p databases_hotcopy_$timestamp
  236. echo "starting backup ..."
  237. echo ""
  238. for DATABASE in `echo $ARRAY`
  239. do
  240. echo "backing up ${DATABASE}"
  241. mkdir databases_hotcopy_$timestamp/$DATABASE
  242. mysqlhotcopy --quiet --user=root --password=r*fed*core08 $DATABASE $BACKUPDIR/databases_hotcopy_$timestamp/$DATABASE
  243. done
  244. echo "mysqlhotcopy completed!"
  245. echo ""
  246. echo ""
  247.  
  248. echo "Backing up Core Directories ..."
  249. currentdir=`pwd`
  250. cd $WWWROOT
  251. cd ..
  252. echo "Source Directory is: ${WWWROOT}"
  253. echo "Backup DEST Dir is: ${BACKUPDIR}"
  254. echo ""
  255. echo ""
  256. echo "Excluding Files larger than ${FILELIMIT} - Searching ..."
  257. rm -f $BACKUPROOT/exclude.txt
  258. find $WWWROOT -size +$FILELIMIT -fprintf $BACKUPROOT/exclude.txt '%p\n'
  259. echo -e "\E[32;3mDone ... Excluding these files:"
  260. echo ""
  261. cat $BACKUPROOT/exclude.txt
  262. echo ""
  263. echo "Starting Archive Creating ..."
  264. tar --create --recursion --verbose --exclude-from $BACKUPROOT/exclude.txt --exclude "${WWWROOT}/backup" --file=coreroot_master_$timestamp.tar $WWWROOT >> coreroot_master_$timestamp.tar.log
  265. echo "Moving Backup ..."
  266. mv -f -t $BACKUPDIR coreroot_master_$timestamp.tar coreroot_master_$timestamp.tar.log
  267. cd $currentdir
  268. FILE="coreroot_master_${timestamp}.tar"
  269. FILEINFO=`ls -l ${BACKUPDIR}/${FILE}`
  270. echo -e "\E[32;3mBackup ${FILE} Created:"
  271. echo -e "\E[34;3m$FILEINFO"
  272. echo ""
  273. echo "Done ..."
  274. echo ""
  275. echo "All operations completed... "
  276. echo -e "\E[34;3mDEST: ${BACKUPDIR} SRC: ${WWWROOT}"
  277. echo ""
  278. echo "[Enter]"
  279. read blank
  280. mainmenu
  281. }
  282.  
  283. function settingsmenu {
  284. clear
  285. echo -e "\E[34;3m:::Web Server Administration - Settings Menu :::" #BOLD BLUE
  286. echo             "================================================"
  287. echo ""
  288. echo -e "\E[31;3mDirectory Menu:" #RED
  289. echo -e "\E[36;2m" #Light Green
  290. echo -e "1.) GUI Mode (xserver is active)"
  291. echo -e "2.) Text Mode (command line only)"
  292. echo -e "3.) <- Return"
  293.   read opt
  294.   if [ "$opt" = "1" ]; then
  295.     guimode
  296.   elif [ "$opt" = "2" ]; then
  297.     textmode
  298.   elif [ "$opt" = "3" ]; then
  299.     mainmenu
  300.   fi
  301. }
  302.  
  303. ############################################################
  304.  
  305. function guimode {
  306.   TEXT="gedit"
  307.   EDITTEXT="gedit"
  308.   DIR="nautilus --browser"
  309.   echo "Graphical Mode Set ..."
  310.   echo ""
  311.   echo -e "\E[34;3m [enter] "
  312.   read blank
  313.   echo ""
  314.   settingsmenu
  315. }
  316.  
  317. function textmode {
  318.   TEXT="cat"
  319.   EDITTEXT="vi"
  320.   DIR="echo"
  321.   echo "Text Mode Set ..."
  322.   echo ""
  323.   echo -e "\E[34;3m [enter] "
  324.   read blank
  325.   echo ""
  326.   settingsmenu
  327. }
  328.  
  329. mainmenu
  330. su
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement