~ubuntu-core-dev/update-manager/main

« back to all changes in this revision

Viewing changes to UpdateManager/Core/utils.py

  • Committer: Michael Vogt
  • Date: 2010-11-30 11:38:50 UTC
  • Revision ID: michael.vogt@ubuntu.com-20101130113850-76f5e0f9tcthaeoo
* DistUpgrade/DistUpgradeController.py:
  - when starting a additional sshd detect if there is a firewall
    running and if so print information that the additional sshd
    may need to be added to the firewall rules
* UpdateManager/Core/utils.py:
  - add iptables_active() helper

Show diffs side-by-side

added added

removed removed

Lines of Context:
367
367
def get_arch():
368
368
    return apt_pkg.Config.find("APT::Architecture")
369
369
 
 
370
 
 
371
def iptables_active():
 
372
    """ Return True if iptables is active """
 
373
    # FIXME: is there a better way?
 
374
    iptables_empty="""Chain INPUT (policy ACCEPT)
 
375
target     prot opt source               destination         
 
376
 
 
377
Chain FORWARD (policy ACCEPT)
 
378
target     prot opt source               destination         
 
379
 
 
380
Chain OUTPUT (policy ACCEPT)
 
381
target     prot opt source               destination         
 
382
"""
 
383
    if os.getuid() != 0:
 
384
        raise OSError, "Need root to check the iptables state"
 
385
    out = subprocess.Popen(["iptables", "-L"], 
 
386
                           stdout=subprocess.PIPE).communicate()[0]
 
387
    if out == iptables_empty:
 
388
        return False
 
389
    return True
 
390
 
 
391
 
370
392
if __name__ == "__main__":
371
393
  #print mirror_from_sources_list()
372
394
  #print on_battery()
373
 
  print inside_chroot()
 
395
  #print inside_chroot()
 
396
  print iptables_active()