Solved

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

Posted on 2014-01-03
3
767 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
Comment Utility
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
Comment Utility
guess i answered my own question
0
 

Author Closing Comment

by:Tbalz
Comment Utility
No one could figure it out
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

A set of related code is known to be a Module, it helps us to organize our code logically which is much easier for us to understand and use it. Module is an object with arbitrarily named attributes which can be used in binding and referencing. …
The purpose of this article is to demonstrate how we can use conditional statements using Python.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

744 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

19 Experts available now in Live!

Get 1:1 Help Now