#!/bin/bash
# Script to secure access to webacula application
# by Adrian Moya

echo "This script will secure access to /webacula con this server"
echo 
while [[ $PASSWD = "" ]]; do
  stty -echo 
  read -p "Password for admin: " PASSWD; echo 
  stty echo  
  if [[ $PASSWD = "" ]]; then 
    echo "This password can't be blank"
  fi  
done
echo 
echo "Please set allowed network access to webacula"
echo "You can use Apache Allow Directive values here"
echo "Examples: if your network ip range is 192.168.1.x"
echo "Allow access from your current network (recommended): 192.168.1.0/24"
echo "More info at http://httpd.apache.org/docs/2.0/mod/mod_access.html#allow"
echo 
while [[ $ALLOWFROM = "" ]]; do
  read -p "Which ip's or domains can access webacula: " ALLOWFROM
  if [[ $ALLOWFROM = "" ]]; then 
    echo "This field can't be blank"
  fi
done
echo
htpasswd -b /etc/apache2/webacula.users admin $PASSWD
echo "Updating Allow directive for /webacula"
sed -r -i "s|Allow from .*|Allow from $ALLOWFROM|" /etc/apache2/conf.d/webacula.conf
service apache2 reload
