diff --git a/bin/vhost-get.sh b/bin/vhost-get.sh index 9140975..b293a93 100755 --- a/bin/vhost-get.sh +++ b/bin/vhost-get.sh @@ -12,10 +12,11 @@ help() thisfilename=$(basename -- "$0") echo "Get VirtualHost info." echo "" - echo "usage: $thisfilename [-d ] [-o ] [-c] [-h]" + echo "usage: $thisfilename [-d ] [-u ] [-o ] [-c] [-h]" echo "" echo " -h Print this help." - echo " -d Domain name to get info for. By defual all domains are returned" + echo " -d Domain name to get info for. By default all domains are returned." + echo " -u Only return domains owned by specified username." echo " -o Type of query. 'virtualhosts' (default), 'redirects', 'aliases'." echo " -c CVS - Output in cvs format, instead of tabbed table." } @@ -43,11 +44,11 @@ if [[ $option = 'virtualhosts' ]]; then vhost::set-virtualhostArray fi - output="Virtualhost Username Config Status" + output="virtualhost username config status" for v in "${virtualhostArray[@]}" do - username=$(stat -c '%U' /srv/www/$v) + owner=$(stat -c '%U' /srv/www/$v) if [[ -f /etc/apache2/sites-available/$v.conf ]]; then macro="Custom" if head -n 1 /etc/apache2/sites-available/$v.conf |grep --quiet ^Use; then @@ -61,12 +62,20 @@ if [[ $option = 'virtualhosts' ]]; then else status="Disabled" fi - output="$output${NL}$v $username $macro $status" + if [[ -n $username ]]; then + if [[ $username = $owner ]]; then + output="$output${NL}$v $owner $macro $status" + fi + else + output="$output${NL}$v $owner $macro $status" + fi done - if [[ $cvs ]]; then - echo "$output" | tr " " "," - else - echo "$output" | column -t + if [[ $output != "virtualhost username config status" ]]; then + if [[ $cvs ]]; then + echo "$output" | tr " " "," + else + echo "$output" | column -t + fi fi elif [[ $option = 'redirects' ]]; then @@ -89,7 +98,7 @@ elif [[ $option = 'redirects' ]]; then vhostConfigs=(`ls -1`) fi - output="Virtualhost Config Redirect Status" + output="virtualhost config redirect status" for c in "${vhostConfigs[@]}" do @@ -133,21 +142,21 @@ elif [[ $option = 'aliases' ]]; then vhostConfigs=(`ls -1`) fi - output="Virtualhost Username Macro Alias Status" + output="virtualhost username macro alias status" for c in "${vhostConfigs[@]}" do if head -n 1 /etc/apache2/sites-available/$c |grep --quiet '^Use VHostAlias'; then macro=$(head -n 1 /etc/apache2/sites-available/$c |grep '^Use VHostAlias'|cut -d ' ' -f 2) alias=$(head -n 1 /etc/apache2/sites-available/$c |grep '^Use VHostAlias'|cut -d ' ' -f 3) - username=$(head -n 1 /etc/apache2/sites-available/$c |grep '^Use VHostAlias'|cut -d ' ' -f 4) + owner=$(head -n 1 /etc/apache2/sites-available/$c |grep '^Use VHostAlias'|cut -d ' ' -f 4) virtualhost=$(head -n 1 /etc/apache2/sites-available/$c |grep '^Use VHostAlias'|cut -d ' ' -f 5) if [[ -f /etc/apache2/sites-enabled/$c ]]; then status="Enabled" else status="Disabled" fi - output="$output${NL}$alias $username $macro $virtualhost $status" + output="$output${NL}$alias $owner $macro $virtualhost $status" fi done