acudovs / powergslb

PowerGSLB - PowerDNS Remote GSLB Backend
MIT License
104 stars 33 forks source link

Have any api to manage? #15

Closed chenglonglinux closed 4 years ago

chenglonglinux commented 5 years ago

may i know have any api to manage? Only have ui?

thank!

acudovs commented 5 years ago

There is no documented API. But the admin interface uses http-backend to update the database entries from which the dns-backend reads configuration. So you can send the same HTTP requests or directly update the database. Both are logged at the debugging level, so you can see the exact requests in the log.

chenglonglinux commented 5 years ago

thanks Aleksey, I tried to use HTTP requests, but got below error:

data = {
    "recid": "0",
    "cmd": "save-record",
    "data": "records",
    "record": {
        "domain": "example.com",
        "monitor": "No check",
        "name": "example.com",
        "content": "ns1.example.com",
        "ttl": "300",
        "name_type": "SOA",
        "view": "Public"
    }
}

result = requests.post('https://xxx.xxx.xxx.xxx/admin/w2ui', auth=('xxxx', 'xxxxx'), data=data, verify=False)

Result: Thread-178: W2UIContentHandler: query: {'recid': '0', 'cmd': 'save-record', 'data': 'records', 'record': ['domain', 'monitor', 'name', 'content', 'ttl', 'name_type', 'view']} save_records() argument after ** must be a mapping, not list

Not sure why my record becomes a list, but I do pass a map.

When I try to pass json, the query is empty: result = requests.post('https://xxx.xxx.xxx.xxx/admin/w2ui', auth=('xxxx', 'xxxxx'), data=data, verify=False)

Thread-173: W2UIContentHandler: query: {}

Is there any way to solve? Thanks very much

acudovs commented 5 years ago

I recomend to update database directly. But if you want to use http requests, you should scan traffic to see the exact requests sent by w2ui library.

conman2305 commented 3 years ago

For anyone who found there way here from Google, w2ui uses literal bracket characters in the key to encode the form data. The request from OP should be encoded like this:

data = {
    "recid": "0",
    "cmd": "save-record",
    "data": "records",
    "record[domain]": "example.com",
    "record[monitor]": "No check",
    "record[name]": "example.com",
    "record[content]": "ns1.example.com",
    "record[ttl]": "300",
    "record[name_type]": "SOA",
    "record[view]": "Public"
}

result = requests.post('https://xxx.xxx.xxx.xxx/admin/w2ui', auth=('xxxx', 'xxxxx'), data=data, verify=False)