Move pnac config back to main script
This commit is contained in:
parent
80b83a2e28
commit
975ec2d4d5
127
econnman-bin.in
127
econnman-bin.in
|
@ -8,6 +8,7 @@
|
|||
# gateway is not updated.
|
||||
|
||||
|
||||
import sys
|
||||
import dbus
|
||||
import dbus.service
|
||||
import logging
|
||||
|
@ -53,8 +54,6 @@ except:
|
|||
ELM_WIN_DIALOG_BASIC, ELM_POLICY_QUIT, ELM_SCROLLER_POLICY_OFF, \
|
||||
ELM_SCROLLER_POLICY_AUTO, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED
|
||||
|
||||
from pnac import PNACConfig
|
||||
|
||||
dbus_ml = DBusEcoreMainLoop()
|
||||
bus = dbus.SystemBus(mainloop=dbus_ml)
|
||||
log = logging.getLogger("econnman")
|
||||
|
@ -73,6 +72,125 @@ EXPAND_HORIZ = (evas.EVAS_HINT_EXPAND, 0.0)
|
|||
FILL_BOTH = (evas.EVAS_HINT_FILL, evas.EVAS_HINT_FILL)
|
||||
|
||||
|
||||
# python2 backwards compatibility
|
||||
try:
|
||||
from configparser import SafeConfigParser
|
||||
except ImportError:
|
||||
from ConfigParser import SafeConfigParser
|
||||
|
||||
|
||||
class PNACConfig(SafeConfigParser):
|
||||
|
||||
"""A custom config parser for IEEE802.1x (PNAC)
|
||||
|
||||
Section names are prefixed with service_
|
||||
|
||||
"""
|
||||
|
||||
CONF_FILE = "/var/lib/connman/econnman.config"
|
||||
|
||||
def __init__(self):
|
||||
SafeConfigParser.__init__(self)
|
||||
self.optionxform = str
|
||||
|
||||
def read(self):
|
||||
args = self.CONF_FILE, 'r'
|
||||
kwargs = {}
|
||||
if sys.hexversion >= 0x03000000:
|
||||
kwargs["encoding"] = 'utf8'
|
||||
try:
|
||||
with open(*args, **kwargs) as fd:
|
||||
self.readfp(fd)
|
||||
except IOError:
|
||||
log.error(
|
||||
"Econnman cannot read the configuration file \"%s\" used by "
|
||||
"connman to configure your ieee802.1x networks. Make sure the "
|
||||
"user running econnman is able to read/write it.",
|
||||
self.CONF_FILE
|
||||
)
|
||||
#raise
|
||||
|
||||
# defaults()
|
||||
# sections()
|
||||
|
||||
def add_section(self, service_name):
|
||||
secname = 'service_' + service_name
|
||||
SafeConfigParser.add_section(self, secname)
|
||||
self.set(service_name, 'Type', 'wifi')
|
||||
self.set(service_name, 'Name', service_name)
|
||||
#self.write()
|
||||
|
||||
def has_section(self, service_name): # config_exists
|
||||
return bool(self.section_get(service_name))
|
||||
|
||||
# options()
|
||||
|
||||
def has_option(self, service_name, key):
|
||||
secname = self.section_get(service_name)
|
||||
return SafeConfigParser.has_option(secname, key)
|
||||
|
||||
# read()
|
||||
# readfp()
|
||||
|
||||
def get(self, service_name, key): # config_option_get
|
||||
secname = self.section_get(service_name)
|
||||
if self.has_option(service_name, key):
|
||||
return SafeConfigParser.get(self, secname, key)
|
||||
return None
|
||||
|
||||
# getint()
|
||||
# getfloat()
|
||||
# getboolean()
|
||||
# items()
|
||||
|
||||
def set(self, service_name, key, value): # config_set
|
||||
secname = self.section_get(service_name)
|
||||
if not self.has_section(service_name):
|
||||
self.add_section(service_name)
|
||||
if value is not None:
|
||||
SafeConfigParser.set(self, secname, key, value)
|
||||
elif self.has_option(secname, key):
|
||||
self.remove_option(secname, key)
|
||||
#self.write()
|
||||
|
||||
def write(self):
|
||||
# TODO: Copy owner and mask from existing config file, write to a temp
|
||||
# file and request overwriting with sudo or polkit, then set the
|
||||
# owner and mask like it was before. This is to avoid the
|
||||
# requirement of running the entire econnman instance with root
|
||||
# rights.
|
||||
try:
|
||||
with open(self.CONF_FILE, 'w', encoding='utf8') as configfile:
|
||||
SafeConfigParser.write(self, configfile)
|
||||
except IOError:
|
||||
log.error(
|
||||
"Econnman cannot write to the configuration file \"%s\" used "
|
||||
"by connman to configure your ieee802.1x networks. Make sure "
|
||||
"the user running econnman is able to read/write it.",
|
||||
self.CONF_FILE
|
||||
)
|
||||
|
||||
def remove_option(self, service_name, key):
|
||||
secname = self.section_get(service_name)
|
||||
SafeConfigParser.remove_option(self, secname, key)
|
||||
#self.write()
|
||||
|
||||
def remove_section(self, service_name): # config_del
|
||||
secname = self.section_get(service_name)
|
||||
ret = SafeConfigParser.remove_section(self, secname)
|
||||
#self.write()
|
||||
return ret
|
||||
|
||||
def section_get(self, service_name): # config_get
|
||||
#secname = 'service_' + service_name
|
||||
for sec in self.sections():
|
||||
if self.has_option(sec, 'Name') and \
|
||||
self.get(sec, 'Name') == service_name:
|
||||
return sec
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
########################################################################
|
||||
# Debug helpers:
|
||||
def dbus_variant_to_str(v):
|
||||
|
@ -942,6 +1060,7 @@ class ServiceView(ObjectView):
|
|||
|
||||
# section: Two Phase Authentication
|
||||
if (self.type == "wifi") and ("ieee8021x" in self.security_mode):
|
||||
pnac_conf.read()
|
||||
fr, bx = self.add_frame_and_box(self.box, "ieee8021x")
|
||||
self.ieee8021x_frame = fr
|
||||
#cfg_sec = pnac_conf.section_get(self.name)
|
||||
|
@ -1352,6 +1471,7 @@ class ServiceView(ObjectView):
|
|||
eap_val = None
|
||||
|
||||
pnac_conf.set(self.name, "EAP", eap_val)
|
||||
pnac_conf.write()
|
||||
return
|
||||
|
||||
def _on_phase2(self, obj, item):
|
||||
|
@ -1364,6 +1484,7 @@ class ServiceView(ObjectView):
|
|||
phase2_val = None
|
||||
|
||||
pnac_conf.set(self.name, 'Phase2', phase2_val)
|
||||
pnac_conf.write()
|
||||
return
|
||||
|
||||
|
||||
|
@ -1686,4 +1807,6 @@ if __name__ == "__main__":
|
|||
log.info("Registered agent at %s", agent.path)
|
||||
|
||||
elm.run()
|
||||
#pnac_conf.write()
|
||||
logging.shutdown()
|
||||
elm.shutdown()
|
||||
|
|
114
pnac.py
114
pnac.py
|
@ -1,114 +0,0 @@
|
|||
import sys
|
||||
import logging
|
||||
log = logging.getLogger("econnman.pnac")
|
||||
|
||||
CONF_FILE = "/var/lib/connman/econnman.config"
|
||||
|
||||
# python2 backwards compatibility
|
||||
try:
|
||||
from configparser import SafeConfigParser
|
||||
except ImportError:
|
||||
from ConfigParser import SafeConfigParser
|
||||
|
||||
|
||||
class PNACConfig(SafeConfigParser):
|
||||
|
||||
"""A custom config parser for IEEE802.1x (PNAC)
|
||||
|
||||
Section names are prefixed with service_
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
SafeConfigParser.__init__(self)
|
||||
self.optionxform = str
|
||||
|
||||
def read(self):
|
||||
args = CONF_FILE, 'r'
|
||||
kwargs = {}
|
||||
if sys.hexversion >= 0x03000000:
|
||||
kwargs["encoding"] = 'utf8'
|
||||
try:
|
||||
with open(*args, **kwargs) as fd:
|
||||
self.readfp(fd)
|
||||
except IOError:
|
||||
log.error(
|
||||
"Econnman cannot read the configuration file \"%s\" used by "
|
||||
"connman to configure your ieee802.1x networks. Make sure the "
|
||||
"user running econnman is able to read/write it.",
|
||||
CONF_FILE
|
||||
)
|
||||
#raise
|
||||
|
||||
# defaults()
|
||||
# sections()
|
||||
|
||||
def add_section(self, service_name):
|
||||
secname = 'service_' + service_name
|
||||
SafeConfigParser.add_section(self, secname)
|
||||
self.set(service_name, 'Type', 'wifi')
|
||||
self.set(service_name, 'Name', service_name)
|
||||
|
||||
def has_section(self, service_name): # config_exists
|
||||
return bool(self.section_get(service_name))
|
||||
|
||||
# options()
|
||||
|
||||
def has_option(self, service_name, key):
|
||||
secname = self.section_get(service_name)
|
||||
return SafeConfigParser.has_option(secname, key)
|
||||
|
||||
# read()
|
||||
# readfp()
|
||||
|
||||
def get(self, service_name, key): # config_option_get
|
||||
secname = self.section_get(service_name)
|
||||
if self.has_option(service_name, key):
|
||||
return SafeConfigParser.get(self, secname, key)
|
||||
return None
|
||||
|
||||
# getint()
|
||||
# getfloat()
|
||||
# getboolean()
|
||||
# items()
|
||||
|
||||
def set(self, service_name, key, value): # config_set
|
||||
secname = self.section_get(service_name)
|
||||
if not self.has_section(service_name):
|
||||
self.add_section(service_name)
|
||||
if value is not None:
|
||||
SafeConfigParser.set(self, secname, key, value)
|
||||
elif self.has_option(secname, key):
|
||||
self.remove_option(secname, key)
|
||||
#self.write()
|
||||
|
||||
def write(self):
|
||||
try:
|
||||
with open(CONF_FILE, 'w', encoding='utf8') as configfile:
|
||||
SafeConfigParser.write(self, configfile)
|
||||
except IOError:
|
||||
log.error(
|
||||
"Econnman cannot write to the configuration file \"%s\" used "
|
||||
"by connman to configure your ieee802.1x networks. Make sure "
|
||||
"the user running econnman is able to read/write it.",
|
||||
CONF_FILE
|
||||
)
|
||||
|
||||
def remove_option(self, service_name, key):
|
||||
secname = self.section_get(service_name)
|
||||
SafeConfigParser.remove_option(self, secname, key)
|
||||
|
||||
def remove_section(self, service_name): # config_del
|
||||
secname = self.section_get(service_name)
|
||||
ret = SafeConfigParser.remove_section(self, secname)
|
||||
#self.write()
|
||||
return ret
|
||||
|
||||
def section_get(self, service_name): # config_get
|
||||
#secname = 'service_' + service_name
|
||||
for sec in self.sections():
|
||||
if self.has_option(sec, 'Name') and \
|
||||
self.get(sec, 'Name') == service_name:
|
||||
return sec
|
||||
else:
|
||||
return None
|
Loading…
Reference in New Issue