Created
April 13, 2018 07:42
-
-
Save icasimpan/91c6915b2ee7a656478eba0a9250030e to your computer and use it in GitHub Desktop.
Given a text file 'client_domains.txt' check which one are not yet forced to do https
This file contains 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/bin/env python3 | |
import subprocess, re | |
## client_domains.txt format: | |
## <client_id>:<http_user>:<http_password>:<domain> | |
## | |
client_domains='client_domains.txt' | |
with open(client_domains) as fp: | |
for _, each_line in enumerate(fp): | |
if each_line.startswith('#'): ## skip config lines that are commented-out. | |
continue | |
line2list = each_line.split(':') ## convert to list for easy processing. | |
client_id = line2list[0].strip() | |
client_httpuser = line2list[1].strip() | |
client_httppass = line2list[2].strip() | |
client_domain = line2list[3].strip() | |
print("Checking:", client_domain) | |
http_authopts = '' | |
if client_httpuser != 'x': ## add http authentication if it's specified... | |
http_authopts = '-u' + client_httpuser + ':' + client_httppass | |
whole_command = '/usr/bin/curl -s -IL ' + http_authopts + ' ' + client_domain + '| egrep "HTTP|Location|Link"' | |
#print('[DEBUG] whole_command ->| ' + whole_command + '|<-') | |
out = subprocess.getoutput(whole_command) | |
out_list=out.split() | |
## within shortened http headers, check for presence of 'https' | |
## ..informing us if there is a need to work on the site. | |
for each_item in out_list: | |
pattern = re.compile('https') | |
found = pattern.match(each_item) | |
if found: | |
break | |
if not found: | |
print('>>> NEED FORCED HTTPS WORK!') | |
print('-' * 5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment