Infoblox’s global team of threat hunters uncovers a DNS operation with the ability to bypass traditional security measures and control the Great Firewall of China. Read about “Muddling Meerkat” and the many other threat actors discovered by Infoblox Threat Intel here.

API Examples

Reply

Problem with csv export using wapi

New Member
Posts: 4
2098     0

Hi,

 

Am trying to export dns zone dumps using wapi.

 

First dns zone dump gets exported properly however subsequent zone dump export is failing with below error.

 

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>401 Authorization Required</title>
</head><body>
<h1>Authorization Required</h1>
<p>This server could not verify that you
are authorized to access the document
requested. Either you supplied the wrong
credentials (e.g., bad password), or your
browser doesn't understand how to supply
the credentials required.</p>
</body></html>

 

This is particulary with recent version of NIOS.Older NIOs versions are working perfectly fine.

 

Any help is appreciated.

 

Thanks

 

Regards,

AJ

Re: Problem with csv export using wapi

Superuser
Posts: 38
2098     0

Hi Anand,

 

It looks like an auth issue, but you say the first export is working. I'd still suggest to check the credentials once again. Also, if you could share the different wapi calls that you are using maybe that will give a better picture.

 

Shukran

Re: Problem with csv export using wapi

New Member
Posts: 4
2098     0

Hello Shukran,

 

Thankyou for the response.

 

Yes, You are right it is seems to be an auth issue.

 

My requirement is basically to export DNS Zone records of multiple auth zones from a particular Grid Manager.

 

Am running a for loop passing zone names to csv export wapi calls to the same Grid Manager thus credentials remain the same irrespective of zone passed.

 

Procedure - 

 

1.Generating token for a particular zone using below wapi call

curl -k -u xxxx:xxxx -H 'content-type: application/json' -X POST "https://x.x.x.x/wapi/v2.9/fileop?_function=csv_export" -d '{"_object": "allrecords","view": "default","zone": "zone_name"}'

 

2.Downloading CSV file

curl -k -u xxxx:xxxx -H 'content-type: application/force-download' "https://x.x.x.x/http_direct_file_io/req_id-DOWNLOAD-0220145046916620/Zonechilds.csv" -o "Zonechilds.csv"

 

3.Removing Stored Token

curl -k -u xxxx:xxxx -H 'content-type: application/json' -X POST "https://x.x.x.x/wapi/v2.9/fileop?_function=downloadcomplete" -d '{"token" :"token generated in step 1\n"}'

 

CSV Export is working fine for 1st zone, however, failing with 401 status for subsequent zones. Also issue is with recent NIOS releases.

 

Thanks,

 

Regards,

AJ

Re: Problem with csv export using wapi

Moderator
Moderator
Posts: 293
2098     0

I can assure you it works, I have a script I use on a regular basis that does exactly this.

Maybe check if there's an authentication policy defined, for simultaneous logins, or if there's a web proxy getting in the way, or something like that.

What language are you working in?  There should be a method to store and re-use the authentication cookie.  That would minimze the number of authentications you're performing, which will help slightly with performance and maybe with this issue too.

Re: Problem with csv export using wapi

New Member
Posts: 4
2099     0
Hi,

Thankyou for the response.

Am using shell scripting.

Could not find anything in the authentication policy as such but I do suspect there is something related to configuration.Will explore further.

There is no web proxy in between.

In my understanding, there is a separate token & url for file download for each zone hence not sure if authentication cookie came be re-used.


Thanks

Regards,
AJ

Re: Problem with csv export using wapi

Moderator
Moderator
Posts: 293
2099     0

Try this.  It's printing lots of extra info, all those extra echo commands can be removed.

#!/bin/sh

GM="gm.example.net"
GM_USER="admin"
GM_PASS="infoblox"
GM_WAPI="v2.11"
ZONES=("example.net", "10.in-addr.arpa")


for ZONE ("$ZONES[@]")
do
	echo "Exporting $ZONE"
	CMD="curl -k -u $GM_USER:$GM_PASS -H \"content-type: application/json\" -X POST \"https://$GM/wapi/$GM_WAPI/fileop?_function=csv_export\" -d '{\"_object\":\"allrecords\",\"view\":\"Internal DNS\",\"zone\":\"$ZONE\"}'"
	echo $CMD


	RESULT=$(eval $CMD)
	echo $RESULT

	URL=$(jq '.url' <<< $RESULT)
	TOKEN=$(jq '.token' <<< $RESULT)

	echo "==============="
	echo "URL:"
	echo $URL
	echo "==============="
	echo "TOKEN:"
	echo $TOKEN
	echo "==============="

	CMD="curl -k -u $GM_USER:$GM_PASS -H \"content-type: application/force-download\" $URL -o \"$ZONE.csv\""
	echo $CMD

	# Downloading CSV file
	RESULT=$(eval $CMD)
	echo $RESULT
 
	echo "==============="

	# use token to clear downloaded file
	CMD="curl -k -u $GM_USER:$GM_PASS -H \"content-type: application/json\" -X POST \"https://$GM/wapi/$GM_WAPI/fileop?_function=downloadcomplete\" -d '{\"token\" :$TOKEN}'"
	RESULT=$(eval $CMD)
	echo $RESULT
done

Re: Problem with csv export using wapi

New Member
Posts: 4
2099     0

Dear All,

 

Working with cookie re-use.

 

Problem stands resolved.

 

Thanks to all for their valuable inputs.

 

Regards,

AJ

Showing results for 
Search instead for 
Did you mean: 

Recommended for You