Example #1
0
def add_reverse_record():
    ip_address_to_be_added = sys.argv[1]
    host_name_to_be_added = sys.argv[2]
    record_valid = 1
    ip_valid = 0
    os.chdir("/root")
    network_address_file = open("user_network_address", 'r')
    network_address = network_address_file.read()
    network_address_file.close()
    ip = IPNetwork(network_address)
    prefix_length = int(ip.prefixlen)
    ip_address = IPAddress(ip_address_to_be_added)

    if ip_address_to_be_added in IPNetwork(network_address):
        ip_valid = 1
        reverse_zone_file_name, reverse_zone_name = reverseZone_name()
        os.chdir(zone_files_path)
        readFiles = open(reverse_zone_file_name, 'r')
        forward_zone_file_content = readFiles.read()
        readFiles.close()
        if host_name_to_be_added in forward_zone_file_content:
            record_valid = 0
            print "\nHostname is already entered in the database.\nSorry! Cannot enter duplicate records.\nPlease enter a different record\n"

        if record_valid == 1:
            octate = str(ip_address).split(".")
            if prefix_length < 16:
                reverse_record = octate[3] + "." + octate[2] + "." + octate[1]
            elif prefix_length >= 16 and prefix_length < 24:
                reverse_record = octate[3] + "." + octate[2]
            else:
                reverse_record = octate[3]

            if reverse_record in forward_zone_file_content:
                record_valid = 0
                print "\nIP address is already entered in the database.\nSorry! Cannot enter duplicate records.\nPlease enter a different record\n"

    else:
        print(
            "\nSorry, cannot accept this record! \nPlease enter an IP address within your entered zone! \nYour entered zone is: %s\n"
            % (IPNetwork(network_address)))

    if ip_valid == 1:
        if record_valid == 1:
            reverse_zone_file_name, reverse_zone_name = reverseZone_name()
            os.chdir(zone_files_path)
            reverse_zone_file_path = reverse_zone_file_name
            reverse_zone_content = open(reverse_zone_file_path, 'a')
            reverse_zone_content.write("\n%s \t IN \t PTR \t %s" %
                                       (reverse_record, host_name_to_be_added))
            reverse_zone_content.close()
            print "\nThe reverse record that you entered has been added!\n"
            subprocess.call("service bind9 reload", shell=True)
def add_reverse_record():
	ip_address_to_be_added= sys.argv[1]
	host_name_to_be_added= sys.argv[2]
	record_valid=1
	ip_valid=0
	os.chdir("/root")
	network_address_file= open("user_network_address", 'r')
	network_address=network_address_file.read()       
	network_address_file.close()
	ip = IPNetwork(network_address)
	prefix_length=int(ip.prefixlen)
	ip_address=IPAddress(ip_address_to_be_added)

	if ip_address_to_be_added in IPNetwork(network_address):
		ip_valid=1
		reverse_zone_file_name,reverse_zone_name=reverseZone_name()
		os.chdir(zone_files_path)
		readFiles = open(reverse_zone_file_name, 'r')
		forward_zone_file_content = readFiles.read()
		readFiles.close()
		if host_name_to_be_added in forward_zone_file_content:
			record_valid=0
			print "\nHostname is already entered in the database.\nSorry! Cannot enter duplicate records.\nPlease enter a different record\n"
			
		if record_valid==1:
			octate = str(ip_address).split(".")
			if prefix_length<16:
				reverse_record=octate[3]+"."+octate[2]+"."+octate[1]
			elif prefix_length>=16 and prefix_length<24:
				reverse_record=octate[3]+"."+octate[2]
			else:
				reverse_record=octate[3]
		
			if reverse_record in forward_zone_file_content:
				record_valid=0
				print "\nIP address is already entered in the database.\nSorry! Cannot enter duplicate records.\nPlease enter a different record\n"

	else:
		print ("\nSorry, cannot accept this record! \nPlease enter an IP address within your entered zone! \nYour entered zone is: %s\n" % (IPNetwork(network_address))) 

	if ip_valid==1:
		if record_valid==1:
			reverse_zone_file_name,reverse_zone_name=reverseZone_name()
			os.chdir(zone_files_path)
			reverse_zone_file_path=reverse_zone_file_name
			reverse_zone_content = open(reverse_zone_file_path, 'a')
			reverse_zone_content.write("\n%s \t IN \t PTR \t %s" % (reverse_record,host_name_to_be_added))       
			reverse_zone_content.close()
			print "\nThe reverse record that you entered has been added!\n"
			subprocess.call("service bind9 reload",shell=True)
def creating_reverse_zone(domain_name):
    old_file = "/etc/bind/db.127"

    old_file_content = open(old_file, 'r')
    text_in_oldFile = old_file_content.read()
    old_file_content.close()
    text_updated = text_in_oldFile.replace("localhost.", domain_name + ".")
    text_modified = text_updated.replace("root.localhost.",
                                         "admin." + domain_name + ".")

    reverse_zone_file_name, reverse_zone_name = reverseZone_name()
    os.chdir(zone_files_path)
    new_zone_file_content = open(reverse_zone_file_name, 'w')
    new_zone_file_content.write(text_modified)
    new_zone_file_content.close()

    # delete last 2 lines

    readFiles = open(reverse_zone_file_name, 'r')
    lines = readFiles.readlines()
    readFiles.close()

    file_content = open(reverse_zone_file_name, 'w')
    file_content.writelines([item for item in lines[:-2]])
    file_content.close()

    # Add few lines

    zoneFile_content = open(reverse_zone_file_name, 'a')
    zoneFile_content.write("\n \t IN \t NS \t %s   \n" %
                           ("ns." + domain_name + "."))
    zoneFile_content.close()
    print "\nThe reverse zone is created and is now ready to accept your records!\nYou can add reverse records any time!\n"
def creating_reverse_zone():
	domain_name= sys.argv[1]
	old_file="/etc/bind/db.127"
	
	old_file_content=open(old_file,'r')
	text_in_oldFile=old_file_content.read()
	old_file_content.close()
	text_updated=text_in_oldFile.replace("localhost.",domain_name+".")
	text_modified=text_updated.replace("root.localhost.","admin."+domain_name+".")

	reverse_zone_file_name,reverse_zone_name=reverseZone_name()
	os.chdir(zone_files_path)
	new_zone_file_content=open(reverse_zone_file_name,'w')
	new_zone_file_content.write(text_modified)
	new_zone_file_content.close()

	# delete last 2 lines

	readFiles = open(reverse_zone_file_name,'r')
	lines = readFiles.readlines()
	readFiles.close()

	file_content = open(reverse_zone_file_name,'w')
	file_content.writelines([item for item in lines[:-2]])
	file_content.close()

	# Add few lines

	zoneFile_content = open(reverse_zone_file_name, 'a')
	zoneFile_content.write("\n \t IN \t NS \t %s   \n"% ("ns."+domain_name+"."))        
	zoneFile_content.close()
	print "\nThe reverse zone is created and is now ready to accept your records!\nYou can add reverse records any time!\n"
Example #5
0
def local_file_configure(domain_name):
    reverse_zone_file_name, reverse_zone_name = reverseZone_name()
    local_file_path = "/etc/bind/named.conf.local"
    local_file_path_content = open(local_file_path, 'w')
    local_file_path_content.write(
        "zone \"%s\" %s \n\ttype master;  \n        file \"/etc/bind/zones/%s\";  \t  # zone file path \n        allow-transfer %s none; %s;\t   \n%s;\n \nzone \"%s\" %s \n\ttype master;  \n        file \"/etc/bind/zones/%s\";  \n        allow-transfer %s none; %s ;\t   \n%s;\n"
        % (domain_name, curlybrace1, "db." + domain_name, curlybrace1,
           curlybrace2, curlybrace2, reverse_zone_name, curlybrace1,
           reverse_zone_file_name, curlybrace1, curlybrace2, curlybrace2))
    local_file_path_content.close()
def remove_reverse_record():
    host_name_to_be_removed = sys.argv[1]

    reverse_zone_file_name, reverse_zone_name = reverseZone_name()
    os.chdir(zone_files_path)
    readFiles = open(reverse_zone_file_name, 'r')
    reverse_zone_file_content = readFiles.read()
    readFiles.close()

    readFiles = open(reverse_zone_file_name, 'r')
    lines = readFiles.readlines()
    readFiles.close()

    if host_name_to_be_removed in reverse_zone_file_content:
        file_content = open(reverse_zone_file_name, 'w')
        for line in lines:
            if not host_name_to_be_removed in line:
                file_content.write(line)
        file_content.close()
        print "\nThe reverse record that you entered has been removed!\n"
    else:
        print "\nThe record you wanted to remove is already absent in the database!\n"
def remove_reverse_record():
	host_name_to_be_removed= sys.argv[1]

	reverse_zone_file_name,reverse_zone_name=reverseZone_name()
	os.chdir(zone_files_path)
	readFiles = open(reverse_zone_file_name,'r')
	reverse_zone_file_content = readFiles.read()
	readFiles.close()

	readFiles = open(reverse_zone_file_name,'r')
	lines = readFiles.readlines()
	readFiles.close()
	
	if host_name_to_be_removed in reverse_zone_file_content:
		file_content = open(reverse_zone_file_name,'w')
		for line in lines:
			if not host_name_to_be_removed in line:
				file_content.write(line)		
		file_content.close()
		print "\nThe reverse record that you entered has been removed!\n"
	else:
		print "\nThe record you wanted to remove is already absent in the database!\n"