Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

The guy who wrote ufw is too smart for me. Is there any documentation for any of the python code?

Some things I'm trying to do are:

  • Allow/close ports by number
  • Get the currently set rules
  • Remove rules

Edit:

My question wasn't specific enough. Everyone here is assuming that I somehow want to reinvent my own interface to iptables, or make some kind of firewall application, when really, I'm just creating a simple ui for ufw that fits into my current application. However, the current state of the ufw python code base makes this a lot harder than it needs to be.

share|improve this question

closed as off-topic by Alvin Row, Eric Carvalho, Stephen Myall, Alvar, AgentCool Aug 17 '13 at 14:44

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This is not about Ubuntu. Questions about other Linux distributions can be asked on Unix & Linux, those about Windows on Super User, those about Apple products on Ask Different and generic programming questions on Stack Overflow." – Alvin Row, Eric Carvalho, Stephen Myall, Alvar, AgentCool
If this question can be reworded to fit the rules in the help center, please edit the question.

6  
This question would be much more useful if you asked what specifically you're trying to do with ufw! –  Jorge Castro Aug 15 '13 at 15:02
    
I added the things I'm trying to do with ufw, but really, I just want some documentation on the python api. –  notbad.jpeg Aug 15 '13 at 16:53
    
I just had a quick scan through UFW's source code. It looks quite standard level of a Python applictation. The docstrings give you a basic idea of what a method does and I find it quite easy to understand from just reading the source code. Please be more specific on what you're looking for or what you don't understand. Note that UFW is meant to be a end-user application, using the iptables backend. It is not intended to be integrated in your own application - it does not offer a really well-documented API (it's not a library in this sense). –  gertvdijk Aug 16 '13 at 8:17
    
I guess there's not really much use in it being open source then –  notbad.jpeg Aug 18 '13 at 22:43
1  
@notbad.jpeg There is no API to document. Again, UFW is a end-user application, not a library. And it seems to me you're missing the point about open source versus closed source application. That remark is completely misplaced here. If you need to implement your own firewall, look at how UFW handles it using iptables. That's your point to start if you're developing your software. –  gertvdijk Aug 19 '13 at 17:41

2 Answers 2

up vote 5 down vote accepted

This illustrated tutorial has the answers to the three bulleted points in your question, but it doesn't answer the part of your question about about documentation for any of the Python code. Below is a screenshot of the gufw application from the Ubuntu Software Center that shows how easy it is to get the currently set rules in gufw. Gufw is a graphical front-end to ufw which is itself a front-end to iptables.

enter image description here

If you really want to get down to the code level with ufw, then you're ready to consider using iptables in order to get exactly what firewall rules you want by running commands in the terminal. A quick search for iptables at the Unix & Linux Stack Exchange Q&A website yielded 15 pages of search results. This should give you an idea of how popular iptables is with Unix & Linux users.

share|improve this answer

Here is a pretty comprehensive guide on iptables -- the backend of UFW:

http://www.frozentux.net/documents/iptables-tutorial/

Also, a short tutorial on UFW:

https://help.ubuntu.com/community/UFW

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.