Solved

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

Posted on 2014-01-03
3
842 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 16

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Flask is a microframework for Python based on Werkzeug and Jinja 2. This requires you to have a good understanding of Python 2.7. Lets install Flask! To install Flask you can use a python repository for libraries tool called pip. Download this f…
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
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…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

690 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