Solved

How to create a Python Rest API call to Firewall for url filtering

Posted on 2014-01-03
3
784 Views
Last Modified: 2014-02-11
Hi Guys,

I'm new to Python but i really want to figure out how to implement this solution in a desktop or preferably Python web GUI. I need to create a simple Python GUI application that will tap into my Firewall's API which I already have. The GUI will have a simple line to enter a url that needs to be blocked. Once the user enters it they press enter and the api below is executed: for a site named www.badsite.com

http(s)://hostname/api/?type=config&action=set&xpath=/config/devices/entry/vsys/entry[@name='vsys1']/pro files/url-filtering/entry[@name='xml test']/block-list&element=<member>www.badsite.com</member>

How would I get this into a GUI and how can I call the API?

I'm familiar with bash and with it I can get user input like

What is the site to be blocked?
get input
block = badsite2.bad.com

Then I can append block as a variable into the API call as seen below:

http(s)://hostname/api/?type=config&action=set&xpath=/config/devices/entry/vsys/entry[@name='vsys1']/pro files/url-filtering/entry[@name='xml test']/block-list&element=<member>$Block</member>

I want the http post to be executed when the user presses the "enter button" Here is what I'm thinking.

import urllib2
import urlparse

Block_url = raw_input("Enter URL to be blocked: ")

url = "http(s)://hostname/api/?type=config&action=set&xpath=/config/devices/entry/vsys/entry[@name='vsys1']/pro files/url-filtering/entry[@name='xml test']/block-list&element=<member> + Block_url </member>"
try:
  result = urllib2.urlopen(url)
except urllib2.URLError, e:
  handleError(e)

Open in new window

0
Comment
Question by:Tbalz
  • 2
3 Comments
 
LVL 15

Expert Comment

by:Walter Ritzel
ID: 39788840
That is pretty much what you need. So, you can probably close this question with no points distributed.

Tks,
Walter.
0
 

Accepted Solution

by:
Tbalz earned 0 total points
ID: 39841052
guess i answered my own question
0
 

Author Closing Comment

by:Tbalz
ID: 39849697
No one could figure it out
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here I am using Python IDLE(GUI) to write a simple program and save it, so that we can just execute it in future. Because when we write any program and exit from Python then program that we have written will be lost. So for not losing our program we…
I found an issue or “bug” in the SonicOS platform (the firmware controlling SonicWALL security appliances) that has to do with renaming Default Service Objects, which then causes a portion of the system to become uncontrollable and unstable. BACK…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now