Created
March 17, 2017 20:53
-
-
Save jhyland87/74e5a80376e40786eac42a38f3a9822f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/local/bin/awk -f | |
@include "/Users/jhyland/Documents/scripts/awk/utils.awk" | |
function resetVhost() { | |
vhost["server_name"] = "" | |
vhost["document_root"] = "" | |
vhost["error_log"] = "" | |
vhost["access_log"] = "" | |
vhost["cfg_file"] = "" | |
vhost["ip"] = "" | |
vhost["port"] = "" | |
vhost["cfg_line_begin"] = "" | |
vhost["cfg_line_end"] = "" | |
} | |
function showHost() { | |
format = "%-20s: %s\n" | |
printf format, "Server Name", vhost["server_name"] | |
printf "%-20s: %s (Lines %s-%s)\n", "Config File", vhost["cfg_file"], vhost["cfg_line_begin"], vhost["cfg_line_end"] | |
if ( vhost["ip"] ) | |
printf format, "IP Address", vhost["ip"] | |
if ( vhost["port"] ) | |
printf format, "Port", vhost["port"] | |
} | |
BEGIN { | |
#vhost["server_name"] = "" | |
#vhost["document_root"] = "" | |
#vhost["error_log"] = "" | |
#vhost["access_log"] = "" | |
#vhost["cfg_file"] = "" | |
} | |
BEGINFILE { | |
resetVhost() | |
vhost["cfg_file"] = FILENAME | |
} | |
{ | |
if ( $1 == "<VirtualHost" ){ | |
#printf "[%s] Line is a VirtualHost OPEN tag\t%s\n", NR, $1 | |
match( $2, "(\*|[0-9]{2,3}\.[0-9]{2,3}\.[0-9]{2,3}\.[0-9]{2,3}):([0-9]{2,4})", ip_port ) | |
if ( ip_port[1] ) vhost["ip"] = ip_port[1] | |
if ( ip_port[2] ) vhost["port"] = ip_port[2] | |
vhost["cfg_line_begin"] = NR | |
} | |
if ( $1 == "</VirtualHost>" ){ | |
#printf "[%s] Line is a VirtualHost CLOSE tag\t%s\n", NR, $1 | |
vhost["cfg_line_end"] = NR | |
showHost() | |
} | |
} | |
ENDFILE { | |
} | |
END { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment