{"id":77,"date":"2017-04-20T17:50:12","date_gmt":"2017-04-20T17:50:12","guid":{"rendered":"http:\/\/news.innerfire.net\/?p=77"},"modified":"2018-07-25T15:32:38","modified_gmt":"2018-07-25T15:32:38","slug":"apache-config-validater","status":"publish","type":"post","link":"https:\/\/news.innerfire.net\/?p=77","title":{"rendered":"Apache config validater."},"content":{"rendered":"<p>This is an Apache config sanitizer, it checks to make sure there are no orphaned files in the Debian style sites-available\/sites-enabled type setup and checks to make sure each virtual host has a valid DNS.<\/p>\n<pre class=\"brush: bash; tab-size: 8; title: ; notranslate\" title=\"\">\r\n#!\/bin\/bash\r\n# Apache config sanitizer.. Checks to make sure all sites are correctly configured \r\n# for DNS and checks for orphaned config files.\r\n#\r\n# By Gerhard Mack &lt;gmack@innerfire.net&gt;\r\n\r\nfunction getipaddress {\r\n        if &#x5B;&#x5B; &quot;${1}&quot; == 4 ]]\r\n        then\r\n                getent ahostsv4 &quot;${2}&quot; | grep STREAM | head -n 1 | cut -d ' ' -f 1\r\n                return\r\n        fi\r\n\r\n        if &#x5B;&#x5B; &quot;${1}&quot; == 6 ]]\r\n        then\r\n                getent ahostsv6 &quot;${2}&quot; | grep STREAM | head -n 1 | cut -d ' ' -f 1\r\n                return\r\n        fi\r\n}\r\n\r\nwhile read line\r\ndo\r\n        name=&quot;$(basename $line)&quot;\r\n\r\n        #Ignore common standard files\r\n        if &#x5B;&#x5B; &quot;${name}&quot; == &quot;000-default-le-ssl.conf&quot; ]]\r\n        then\r\n                continue\r\n        fi\r\n\r\n        if &#x5B;&#x5B; &quot;${name}&quot; == &quot;default-ssl.conf&quot; ]]\r\n        then\r\n                continue\r\n        fi\r\n\r\n        if &#x5B;&#x5B; &quot;${name}&quot; == &quot;000-default.conf&quot; ]]\r\n        then\r\n                continue\r\n        fi\r\n\r\n        if &#x5B;&#x5B; ! -e &quot;\/etc\/apache2\/sites-enabled\/${name}&quot; ]]\r\n        then\r\n                echo orphaned file: ${line}\r\n        fi\r\ndone &lt;&lt;&lt; &quot;$(find \/etc\/apache2\/sites-available\/ -name '*.conf')&quot;\r\n\r\nwhile read line\r\ndo\r\n        array=( $line )\r\n\r\n        if &#x5B;&#x5B; &quot;${line:0:1}&quot; == &#x5B;0-9] ]]\r\n        then\r\n                VIP=$(echo ${array&#x5B;0]} | cut -d: -f1 )\r\n                IPV=4\r\n                continue\r\n        fi\r\n\r\n        if &#x5B;&#x5B; &quot;${line:0:1}&quot; == &quot;&#x5B;&quot; ]]\r\n        then\r\n                 VIP=$(echo ${array&#x5B;0]} | cut -d\\] -f1 | cut -d \\&#x5B; -f2)\r\n                 IPV=6\r\n                 continue\r\n        fi\r\n\r\n        if &#x5B;&#x5B; &quot;${line:0:1}&quot; == &quot;*&quot; ]] \r\n        then\r\n                 continue\r\n        fi\r\n\r\n        if &#x5B;&#x5B; &quot;${array&#x5B;0]}&quot; == &quot;port&quot; ]]\r\n        then\r\n                 VHOST=&quot;${array&#x5B;3]}&quot;\r\n\r\n                 IP=$(getipaddress ${IPV} ${VHOST})\r\n\r\n                 if &#x5B;&#x5B; -z &quot;${IP}&quot; ]]\r\n                 then\r\n                         echo ${VHOST} does not resolve. \\(should be \\&quot;${VIP}\\&quot;\\)\r\n                         continue\r\n                 fi\r\n\r\n                 if &#x5B;&#x5B; &quot;${IP}&quot; == &quot;::ffff:&quot;* ]]\r\n                 then\r\n                          echo ${VHOST} does not have an IPv6 address. \\(should be \\&quot;${VIP}\\&quot;\\)\r\n                          continue\r\n                 fi\r\n\r\n                 if &#x5B;&#x5B; &quot;$IP&quot; != &quot;$VIP&quot; ]]\r\n                 then\r\n                          echo vhost ${VHOST} points to \\&quot;${IP}\\&quot; \\(should be \\&quot;${VIP}\\&quot;\\)\r\n                 fi\r\n                 \r\n                 continue\r\n         fi\r\n\r\n         if &#x5B;&#x5B; &quot;$array&#x5B;0]&quot; == &quot;alias&#x5B;0]&quot; ]]\r\n         then\r\n                 VALIAS=&quot;${array&#x5B;1]}&quot;\r\n                 IP=$(getipaddress ${IPV} ${VALIAS})\r\n\r\n         if &#x5B;&#x5B; -z $IP ]] ; then\r\n                 echo ${VHOST} alias ${VALIAS} does not resolve. \\(should be \\&quot;${VIP}\\&quot;\\)\r\n                 continue\r\n         fi\r\n\r\n         if &#x5B;&#x5B; ${IP} == &quot;::ffff:&quot;* ]]\r\n         then\r\n                 echo ${VHOST} alias ${VALIAS} does not have an IPv6 address. \\(should be \\&quot;${VIP}\\&quot;\\)\r\n                 continue\r\n         fi\r\n\r\n         if &#x5B;&#x5B; &quot;$IP&quot; != &quot;$VIP&quot; ]] ; then\r\n                echo vhost ${VHOST} alias $VALIAS points to \\&quot;${IP}\\&quot; \\(should be \\&quot;${VIP}\\&quot;\\)\r\n         fi\r\n\r\n         continue\r\n         fi\r\ndone &lt;&lt;&lt; &quot;$(apachectl -S)&quot;\r\n<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is an Apache config sanitizer, it checks to make sure there are no orphaned files in the Debian style sites-available\/sites-enabled type setup and checks to make sure each virtual host has a valid DNS. #!\/bin\/bash # Apache config sanitizer.. Checks to make sure all sites are correctly configured # for DNS and checks for [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-77","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/news.innerfire.net\/index.php?rest_route=\/wp\/v2\/posts\/77","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/news.innerfire.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/news.innerfire.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/news.innerfire.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/news.innerfire.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=77"}],"version-history":[{"count":17,"href":"https:\/\/news.innerfire.net\/index.php?rest_route=\/wp\/v2\/posts\/77\/revisions"}],"predecessor-version":[{"id":106,"href":"https:\/\/news.innerfire.net\/index.php?rest_route=\/wp\/v2\/posts\/77\/revisions\/106"}],"wp:attachment":[{"href":"https:\/\/news.innerfire.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=77"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/news.innerfire.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=77"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/news.innerfire.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=77"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}