whoami7 - Manager
:
/
opt
/
dedrads
/
Upload File:
files >> //opt/dedrads/check_prov.py
#!/opt/imh-python/bin/python3 # Check some things to make sure the vps provisioning went well # 6/19/2017 Nathan <nathans@inmotionhosting.com> import sys import os import socket import dns.resolver # pylint: disable=no-name-in-module from netifaces import interfaces, ifaddresses, AF_INET from rads import send_email logfile = '/root/prov_log' def ip4_addresses(): """List ipv4 addresses setup on this system""" ip_list = [] for interface in interfaces(): if AF_INET in ifaddresses(interface): for link in ifaddresses(interface)[AF_INET]: ip_list.append(link['addr']) return ip_list def get_mainip(): """This should only be run on brand new vps. so there will be 2 IP's. the main IP and a local address""" with open('/etc/wwwacct.conf') as f: for line in f.readlines(): if not line.strip(): continue if line.split()[0] == 'ADDR': main_ip = line.split()[1] return main_ip def check_dns(): """Check that forward and reverse DNS is setup properly""" sys.tracebacklimit = 0 vps_hostname = socket.getfqdn() vps_ips = ip4_addresses() # Forward DNS try: hostname_ip = socket.gethostbyname(vps_hostname) print(vps_hostname + " resolves to " + hostname_ip) except Exception as e: print("A record for hostname not found") print(e) return False # Get the main IP of the server for ip in vps_ips: if ip == hostname_ip: main_ip = ip else: pass if main_ip == hostname_ip: print(main_ip + " resolves to " + vps_hostname) return True print("Reverse DNS either doesn't match or is not present") return False def check_mailip(): """Ripped this straight from google. it does the trick""" myIP = get_mainip() # Spamhaus zen bls = [ "zen.spamhaus.org", "spam.abuse.ch", "cbl.abuseat.org", "virbl.dnsbl.bit.nl", "dnsbl.inps.de", "ix.dnsbl.manitu.net", "dnsbl.sorbs.net", "bl.spamcop.net", "xbl.spamhaus.org", "pbl.spamhaus.org", "db.wpbl.info", ] listings = [] for bl in bls: try: my_resolver = dns.resolver.Resolver() query = '.'.join(reversed(str(myIP).split("."))) + "." + bl answers = my_resolver.resolve(query, "A") answer_txt = my_resolver.resolve(query, "TXT") listings.append( 'IP: %s IS listed in %s (%s: %s)' % (myIP, bl, answers[0], answer_txt[0]) ) except dns.resolver.NXDOMAIN: # print 'IP: %s is NOT listed in %s' %(myIP, bl) pass if len(listings) > 0: return False return True def check_user_setup(): """Check if the reseller user was setup during provisioning""" user_list = [] for _, _, files in os.walk("/var/cpanel/users"): for file in files: user_list.append(file) try: user_list.remove('system') except Exception: pass if len(user_list) < 1: print("Reseller user not setup properly") return False print(user_list[0] + " setup as reseller user") return True def create_task(to_addr, subject, body): send_email(to_addr, subject, body) print("T2S notified") message_bodies = [ "One or more of the DNS setup checks failed. Please check that both forward and reverse DNS is setup properly for this VPS container", "The container was setup with a blacklisted or otherwise bad mail IP. Please review the mail ip of the server and rotate/delist as needed", "The reseller user was not found on this server after provisioning. Please check why, and setup user if needed", ] def main(): email_target = 'sadmin@imhadmin.net' subject = socket.getfqdn() + " provisioning check failure" if not check_dns(): print("DNS checks failed") create_task(email_target, subject, message_bodies[0]) else: print("DNS checks passed") if not check_mailip(): print("Mail IP checks failed") create_task(email_target, subject, message_bodies[1]) else: print("Mail IP checks passed") if not check_user_setup(): print('User setup checks failed') create_task(email_target, subject, message_bodies[2]) else: print('User setup checks passsed') if __name__ == "__main__": main()
Copyright ©2021 || Defacer Indonesia