コード例 #1
0
ファイル: qomui_service.py プロジェクト: precla/qomui
    def __init__(self):
        self.sys_bus = dbus.SystemBus()
        self.bus_name = dbus.service.BusName(BUS_NAME, bus=self.sys_bus)
        dbus.service.Object.__init__(self, self.bus_name, OPATH)
        self.logger = logging.getLogger()
        self.gui_handler = GuiLogHandler(self.send_log)
        self.gui_handler.setFormatter(
            logging.Formatter('%(asctime)s - %(levelname)s - %(message)s'))
        self.logger.addHandler(self.gui_handler)
        self.filehandler = logging.handlers.RotatingFileHandler(
            "{}/qomui.log".format(ROOTDIR),
            maxBytes=2 * 1024 * 1024,
            backupCount=1)
        self.logger.addHandler(self.filehandler)
        self.filehandler.setFormatter(
            logging.Formatter('%(asctime)s - %(levelname)s - %(message)s'))
        self.logger.setLevel(logging.DEBUG)
        self.logger.info("Dbus-service successfully initialized")

        #Clean slate after (re-)starting
        try:
            check_call(["killall", "openvpn"])
            self.logger.debug("Killed all running instances of OpenVPN")
        except CalledProcessError:
            pass

        self.check_version()
        firewall.save_iptables()
        self.load_firewall(0)
    def load_firewall(self, stage):
        try:
            with open('{}/config.json'.format(ROOTDIR), 'r') as c:
                self.config = json.load(c)

        except (FileNotFoundError, json.decoder.JSONDecodeError) as e:
            self.logger.error(
                '{}: Could not open config.json - loading default configuration'
                .format(e))
            with open('{}/default_config.json'.format(ROOTDIR), 'r') as c:
                self.config = json.load(c)

        try:
            self.logger.setLevel(self.config["log_level"].upper())
            self.disable_ipv6(self.config["ipv6_disable"])
            fw = self.config["firewall"]
            gui_only = self.config["fw_gui_only"]
            block_lan = self.config["block_lan"]
            preserve = self.config["preserve_rules"]

            if fw == 1 and gui_only == 0:
                opt = 1
            elif gui_only == 1 and stage == 1:
                firewall.save_iptables()
                opt = fw
            elif gui_only == 1 and stage == 2:
                firewall.restore_iptables()
                opt = 2
            elif fw == 0 and stage == 1:
                opt = 0
                firewall.restore_iptables()
            else:
                opt = 2

            if opt < 2:
                firewall.apply_rules(opt,
                                     block_lan=block_lan,
                                     preserve=preserve)
        except KeyError:
            self.logger.warning('Malformed config file')

        #default dns is always set to the alternative servers
        self.dns = self.config["alt_dns1"]
        self.dns_2 = self.config["alt_dns2"]
        self.dns_bypass = self.config["alt_dns1"]
        self.dns_2_bypass = self.config["alt_dns2"]
コード例 #3
0
ファイル: qomui_service.py プロジェクト: rohitereddy/qomui
 def __init__(self):
     self.sys_bus = dbus.SystemBus()
     self.bus_name = dbus.service.BusName(BUS_NAME, bus=self.sys_bus)
     dbus.service.Object.__init__(self, self.bus_name, OPATH)
     self.logger = logging.getLogger()
     self.gui_handler = GuiLogHandler(self.send_log)
     self.gui_handler.setFormatter(
         logging.Formatter('%(asctime)s - %(levelname)s - %(message)s'))
     self.logger.addHandler(self.gui_handler)
     self.filehandler = logging.handlers.RotatingFileHandler(
         "{}/qomui.log".format(ROOTDIR),
         maxBytes=2 * 1024 * 1024,
         backupCount=1)
     self.logger.addHandler(self.filehandler)
     self.filehandler.setFormatter(
         logging.Formatter('%(asctime)s - %(levelname)s - %(message)s'))
     self.logger.setLevel(logging.DEBUG)
     self.logger.info("Dbus-service successfully initialized")
     self.check_version()
     firewall.save_iptables()
     self.load_firewall(0)
コード例 #4
0
    def load_firewall(self, stage):
        config.load_config()

        try:
            self.logger.setLevel(config.settings["log_level"].upper())
            self.disable_ipv6(config.settings["ipv6_disable"])
            fw = config.settings["firewall"]
            gui_only = config.settings["fw_gui_only"]
            block_lan=config.settings["block_lan"]
            preserve=config.settings["preserve_rules"]

            if fw == 1 and gui_only == 0:
                opt = 1
            elif gui_only == 1 and stage == 1:
                firewall.save_iptables()
                opt = fw
            elif gui_only == 1 and stage == 2:
                firewall.restore_iptables()
                opt = 2
            elif fw == 0 and stage == 1:
                opt = 0
                firewall.restore_iptables()
            else:
                opt = 2

            if opt < 2:
                firewall.apply_rules(
                                    opt,
                                    block_lan=block_lan,
                                    preserve=preserve
                                    )
        except KeyError:
            self.logger.warning('Malformed config file')

        #default dns is always set to the alternative servers
        self.dns = config.settings["alt_dns1"]
        self.dns_2 = config.settings["alt_dns2"]
        self.dns_bypass = config.settings["alt_dns1"]
        self.dns_2_bypass = config.settings["alt_dns2"]
コード例 #5
0
ファイル: qomui_service.py プロジェクト: precla/qomui
    def load_firewall(self, activate):
        try:
            with open('{}/config.json'.format(ROOTDIR), 'r') as c:
                self.config = json.load(c)

        except (FileNotFoundError, json.decoder.JSONDecodeError) as e:
            self.logger.error(
                '{}: Could not open config.json - loading default configuration'
                .format(e))
            with open('{}/default_config.json'.format(ROOTDIR), 'r') as c:
                self.config = json.load(c)

        try:
            self.logger.setLevel(self.config["log_level"].upper())

        except KeyError:
            pass

        try:
            if self.config["fw_gui_only"] == 0:
                activate = 1

        except KeyError:
            activate = 1

        try:
            if self.config["preserve_rules"] == 1:
                preserve = 1
            else:
                preserve = 0

        except KeyError:
            preserve = 0

        try:
            if self.config["block_lan"] == 1:
                block_lan = 1
            else:
                block_lan = 0

        except KeyError:
            block_lan = 0

        try:
            if activate == 1:
                firewall.save_iptables()
                firewall.apply_rules(self.config["firewall"],
                                     block_lan=block_lan,
                                     preserve=preserve)

            elif activate == 2:
                if self.config["fw_gui_only"] == 1:
                    firewall.restore_iptables()
                    firewall.apply_rules(0, block_lan=0, preserve=preserve)

                    try:
                        bypass.delete_cgroup(self.default_interface_4,
                                             self.default_interface_6)

                    except AttributeError:
                        pass

            self.disable_ipv6(self.config["ipv6_disable"])

        except KeyError:
            self.logger.warning('Could not read all values from config file')

        #default dns is always set to the alternative servers
        self.dns = self.config["alt_dns1"]
        self.dns_2 = self.config["alt_dns2"]
        self.dns_bypass = self.config["alt_dns1"]
        self.dns_2_bypass = self.config["alt_dns2"]