home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / share / system-config-printer / firewall.py < prev    next >
Encoding:
Python Source  |  2010-09-28  |  2.5 KB  |  76 lines

  1. #!/usr/bin/env python
  2.  
  3. ## system-config-printer
  4.  
  5. ## Copyright (C) 2006, 2007, 2008, 2009, 2010 Red Hat, Inc.
  6. ## Authors:
  7. ##  Tim Waugh <twaugh@redhat.com>
  8.  
  9. ## This program is free software; you can redistribute it and/or modify
  10. ## it under the terms of the GNU General Public License as published by
  11. ## the Free Software Foundation; either version 2 of the License, or
  12. ## (at your option) any later version.
  13.  
  14. ## This program is distributed in the hope that it will be useful,
  15. ## but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. ## GNU General Public License for more details.
  18.  
  19. ## You should have received a copy of the GNU General Public License
  20. ## along with this program; if not, write to the Free Software
  21. ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22.  
  23. # config is generated from config.py.in by configure
  24. import config
  25.  
  26. import dbus
  27. import pickle
  28.  
  29. class Firewall:
  30.     ALLOW_IPP_CLIENT = "--service=ipp-client"
  31.     ALLOW_IPP_SERVER = "--service=ipp"
  32.     ALLOW_SAMBA_CLIENT = "--service=samba-client"
  33.     ALLOW_MDNS = "--service=mdns"
  34.     ALLOW_SNMP = "--port=161:udp"
  35.  
  36.     def _get_fw_data (self):
  37.         try:
  38.             bus = dbus.SystemBus ()
  39.             obj = bus.get_object ("org.fedoraproject.Config.Firewall",
  40.                                   "/org/fedoraproject/Config/Firewall")
  41.             iface = dbus.Interface (obj, "org.fedoraproject.Config.Firewall")
  42.             self._firewall = iface
  43.             p = self._firewall.read ()
  44.             self._fw_data = pickle.loads (p.encode ('utf-8'))
  45.         except dbus.DBusException:
  46.             raise RuntimeError
  47.  
  48.         return self._fw_data
  49.  
  50.     def write (self):
  51.         pass
  52.  
  53.     def _check_any_allowed (self, search):
  54.         return True
  55.  
  56.     def add_rule (self, rule):
  57.         pass
  58.  
  59.     def check_ipp_client_allowed (self):
  60.         return self._check_any_allowed (set(["--port=631:udp",
  61.                                              self.ALLOW_IPP_CLIENT]))
  62.  
  63.     def check_ipp_server_allowed (self):
  64.         return self._check_any_allowed (set(["--port=631:tcp",
  65.                                              self.ALLOW_IPP_SERVER]))
  66.  
  67.     def check_samba_client_allowed (self):
  68.         return self._check_any_allowed (set([self.ALLOW_SAMBA_CLIENT]))
  69.  
  70.     def check_mdns_allowed (self):
  71.         return self._check_any_allowed (set(["--port=5353:udp",
  72.                                              self.ALLOW_MDNS]))
  73.  
  74.     def check_snmp_allowed (self):
  75.         return self._check_any_allowed (set([self.ALLOW_SNMP]))
  76.