Solved

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

Posted on 2014-01-03
3
828 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

Independent Software Vendors: 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

Suggested Solutions

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
This article offers some helpful and general tips for safe browsing and online shopping. It offers simple and manageable procedures that help to ensure the safety of one's personal information and the security of any devices.
The viewer will learn how to dynamically set the form action using jQuery.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

734 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