jethrocarr / namedmanager

AGPL web-based DNS management interface in PHP
349 stars 125 forks source link

Where can find namedmanager's SOAP API exapmle,thks #65

Open leonzhao2020 opened 7 years ago

leonzhao2020 commented 7 years ago

Hi,all

I want write record to namedmanager by python program, Where can find namedmanger's SOAP API example, thks.

SOAP API这部分有没有使用样例? 我想通过程序往namedmananger里面自动增删改记录

X-Mars commented 7 years ago

楼上的,点开我的头像,给我发邮件,我给你说说我是怎么程序添加记录的

X-Mars commented 3 years ago

最近好多人看到这条issues后,发邮件问我如何实现的api,我在此解答一下。 当时我实现了api,但是遇到了一点问题,时间太久我记不清具体问题了。 后来我就通过 python selenium 实现了域名的添加和修改。 如果有需要的朋友,可以朝这个方向尝试。

X-Mars commented 3 years ago

最近好多人看到这条issues后,发邮件问我如何实现的api,我在此解答一下。 当时我实现了api,但是遇到了一点问题,时间太久我记不清具体问题了。 后来我就通过 python selenium 实现了域名的添加和修改。 如果有需要的朋友,可以朝这个方向尝试。

X-Mars commented 3 years ago
from selenium import webdriver
import dns.resolver as nslookup
import datetime
import commands

import json

import time

class Namedmanager(object):

    def __init__(self, hostname, ip):
        #self.driver = webdriver.PhantomJS("/usr/local/phantomjs-2.1.1-macosx/bin/phantomjs", service_args=['--ignore-ssl-errors=true', '--ssl-protocol=any'])
        self.driver = webdriver.PhantomJS("/usr/local/phantomjs-2.1.1-linux-x86_64/bin/phantomjs", service_args=['--ignore-ssl-errors=true', '--ssl-protocol=any'])
        #self.driver = webdriver.Chrome()
        self.username = "setup"
        self.password = "c"
        self.hostname = hostname
        self.ip = ip

    def creat_domain(self):
        driver = self.driver
        driver.maximize_window()
        driver.set_window_size(1120, 900)
        driver.set_page_load_timeout(30)
        driver.get("https://xxxx.xxxx.com//namedmanager/")
        #print driver.page_source
        time.sleep(2)
        try:
            username = driver.find_element_by_id("username_namedmanager")
            password = driver.find_element_by_id("password_namedmanager")
            actions = webdriver.ActionChains(driver)
            actions.move_to_element(username)
            actions.click()
            actions.send_keys(self.username)

            actions.move_to_element(password)
            actions.click()
            actions.send_keys(self.password)
            actions.perform()

            driver.find_element_by_name("submit").click()

            actions.reset_actions()
            time.sleep(2)
            driver.set_page_load_timeout(30)
            #actions = webdriver.ActionChains(driver)
            domains = driver.find_element_by_link_text("Domains/Zones")
            actions.move_to_element(domains)
            actions.click()
            actions.perform()

            time.sleep(1)

            actions.reset_actions()
            driver.set_page_load_timeout(30)
            time.sleep(2)
            domain_records = driver.find_element_by_link_text("domain records")
            actions.move_to_element(domain_records)
            actions.click()
            actions.perform()

            actions.reset_actions()
            time.sleep(4)
            #hostname = driver.find_element_by_id("record_custom_26_name")
            hostname = driver.find_element_by_xpath("//input[@value='Record name, eg www']")
            actions.move_to_element(hostname)
            actions.click()
            actions.send_keys(self.hostname)

            #ip = driver.find_element_by_id("record_custom_26_content")
            ip = driver.find_element_by_xpath("//input[@value='Target IP, eg 192.168.0.1']")
            actions.move_to_element(ip)
            actions.click()
            actions.send_keys(self.ip)
            actions.perform()

            time.sleep(2)
            driver.find_element_by_name("submit").click()
        except Exception, e:
            print Exception, ":", e

# 检查当前需要添加域名是否已经存在
def nslookup_hostanme(hostname):
    try:
        a = nslookup.query(hostname + ".xxxx.com", 'A')
        ip = a.response.answer[0].items[0].address
    except:
        ip = None
    return ip

new_host_dict = [{
    'hostname': 1.1.1.1
}]
for hostname in new_host_dict:
    ip = new_host_dict[hostname]
    exist_ip = nslookup_hostanme(hostname)
    if exist_ip is None:
        N = Namedmanager(hostname, ip)
        N.creat_domain()
        #add_host_to_ansible(hostname)
    else:
        print exist_ip

节选代码供参考。

如果帮到了你,请到我的github 主页,任意项目 点 star