Esempio n. 1
0
    def create_config(self, cfg, resinfo):
        # XXX: watchdog
        # - process status
        # - could also: use monit to run the process
        # - check process health (cpu usage, memory usage, etc.)

        self.debug_on = helpers.get_debug(cfg)

        params = {}
        params['webui_pid'] = constants.WEBUI_PIDFILE
        params['openl2tp_pid'] = constants.OPENL2TP_PIDFILE
        params['l2tpd_pid'] = constants.L2TPD_PIDFILE
        params['ippool_pid'] = constants.IPPOOL_PIDFILE
        params['pluto_pid'] = constants.PLUTO_PIDFILE
        params['ezipupdate_pid'] = constants.EZIPUPDATE_PIDFILE
        params['dhclient_pid'] = constants.DHCLIENT_PIDFILE
        # XXX: reboot script?
        #        params['fail_action'] = '/usr/bin/l2tpgw-reboot'
        params['fail_action'] = '/bin/true'
        params['stop_action'] = '/bin/true'

        dhcp_conf = ''
        if helpers.get_public_dhcp_interface(
                cfg) is not None or helpers.get_private_dhcp_interface(
                    cfg) is not None:
            dhcp_conf = textwrap.dedent("""\

            # dhclient3
            check process dhclient3
                with pidfile \"%(dhclient_pid)s\"
                start program = \"%(fail_action)s\"
                stop program = \"%(stop_action)s\"
            """) % params

        # Note: not using monit httpd server:
        # set
        # set httpd port 2812 and use address localhost
        #     allow localhost
        #     allow admin:monit
        # Note: process health check, pluto cpu usage: if cpu > 90%, etc

        ezipupdate_conf = ''
        if helpers.get_dyndns_config(cfg) is not None:
            ezipupdate_conf = textwrap.dedent("""\

            # ez-ipupdate
            check process ez-ipupdate
                with pidfile \"%(ezipupdate_pid)s\"
                start program = \"%(fail_action)s\"
                stop program = \"%(stop_action)s\"
            """) % params

        conf = textwrap.dedent("""\
        set daemon 60
        set logfile syslog facility log_daemon

        check process twistd
            with pidfile \"%(webui_pid)s\"
            start program = \"%(fail_action)s\"
            stop program = \"%(stop_action)s\"

        check process openl2tp
            with pidfile \"%(openl2tp_pid)s\"
            start program = \"%(fail_action)s\"
            stop program = \"%(stop_action)s\"

        check process ippoold
            with pidfile \"%(ippool_pid)s\"
            start program = \"%(fail_action)s\"
            stop program = \"%(stop_action)s\"

        check process pluto
            with pidfile \"%(pluto_pid)s\"
            start program = \"%(fail_action)s\"
            stop program = \"%(stop_action)s\"
        """) % params

        self.configs = [{
            'file': constants.MONIT_CONF,
            'cont': conf + dhcp_conf + ezipupdate_conf,
            'mode': 0700
        }]
Esempio n. 2
0
    def create_config(self, cfg, resinfo):
        """Create configuration file for ez-ipupdate.

        See http://www.shakabuku.org/writing/dyndns.html.
        """

        global_st = helpers.get_global_status()
        pub_iface, pub_iface_name = helpers.get_public_iface(cfg)
        pub_dyndns_cfg = helpers.get_dyndns_config(cfg)

        conf = textwrap.dedent("""\
        # intentionally empty
        """)

        self.do_start = False
        if pub_dyndns_cfg is not None:
            self.debug_on = helpers.get_debug(cfg)
            if self.debug_on:
                debug = 'debug'
            else:
                debug = ''

            self._log.debug('Dynamic DNS configured')
            provider = pub_dyndns_cfg.getS(ns.provider, rdf.String)
            username = pub_dyndns_cfg.getS(ns.username, rdf.String)
            password = pub_dyndns_cfg.getS(ns.password, rdf.String)
            hostname = pub_dyndns_cfg.getS(ns.hostname, rdf.String)

            # address selection is complicated due to many options
            address = None
            if pub_dyndns_cfg.hasS(ns.dynDnsAddress):
                addr = pub_dyndns_cfg.getS(ns.dynDnsAddress)
                if addr.hasType(ns.DynDnsInterfaceAddress):
                    address = None
                elif addr.hasType(ns.DynDnsStaticAddress):
                    address = addr.getS(ns.ipAddress, rdf.IPv4Address).toString()
                elif addr.hasType(ns.DynDnsManagementConnectionAddress):
                    if global_st.hasS(ns.managementConnectionOurNattedAddress):
                        address = global_st.getS(ns.managementConnectionOurNattedAddress, rdf.IPv4Address).toString()
                    else:
                        address = None
                else:
                    raise Exception('invalid dynDnsAddress type')
            if address == '':
                address = None
            address_str = ''
            if address is not None:
                address_str = 'address=%s' % address
                
            interface_str = 'interface=%s' % pub_iface_name
                
            self._log.debug('Dynamic DNS parameters: provider=%s, username=%s, password=%s, hostname=%s, address=%s, interface=%s' % (provider, username, password, hostname, address, pub_iface_name))

            # NB: persistent cache is required for proper dyndns operation
            
            conf = textwrap.dedent("""\
            #!/usr/local/bin/ez-ipupdate -c

            service-type=%(provider)s
            user=%(username)s:%(password)s
            host=%(hostname)s
            %(address)s
            %(interface)s
            max-interval=2073600
            %(debug)s
            cache-file=%(cache_file_stem)s.%(pubif)s
            daemon
            """) % {'provider':provider,
                    'username':username,
                    'password':password,
                    'hostname':hostname,
                    'address':address_str,
                    'interface':interface_str,
                    'cache_file_stem':constants.EZIPUPDATE_CACHE,
                    'pubif':pub_iface_name,
                    'debug':debug}

            self.do_start = True
        else:
            self._log.debug('No dynamic DNS configured')

        self.configs = [{'file': constants.EZIPUPDATE_CONF,
                         'cont': conf,
                         'mode': 0755}]
Esempio n. 3
0
    def create_config(self, cfg, resinfo):
        # XXX: watchdog
        # - process status
        # - could also: use monit to run the process
        # - check process health (cpu usage, memory usage, etc.)

        self.debug_on = helpers.get_debug(cfg)

        params = {}
        params['webui_pid'] = constants.WEBUI_PIDFILE
        params['openl2tp_pid'] = constants.OPENL2TP_PIDFILE
        params['l2tpd_pid'] = constants.L2TPD_PIDFILE
        params['ippool_pid'] = constants.IPPOOL_PIDFILE
        params['pluto_pid'] = constants.PLUTO_PIDFILE
        params['ezipupdate_pid'] = constants.EZIPUPDATE_PIDFILE
        params['dhclient_pid'] = constants.DHCLIENT_PIDFILE
# XXX: reboot script?
#        params['fail_action'] = '/usr/bin/l2tpgw-reboot'
        params['fail_action'] = '/bin/true'
        params['stop_action'] = '/bin/true'

        dhcp_conf = ''
        if helpers.get_public_dhcp_interface(cfg) is not None or helpers.get_private_dhcp_interface(cfg) is not None:
            dhcp_conf = textwrap.dedent("""\

            # dhclient3
            check process dhclient3
                with pidfile \"%(dhclient_pid)s\"
                start program = \"%(fail_action)s\"
                stop program = \"%(stop_action)s\"
            """) % params


        # Note: not using monit httpd server:
        # set
        # set httpd port 2812 and use address localhost
        #     allow localhost
        #     allow admin:monit
        # Note: process health check, pluto cpu usage: if cpu > 90%, etc

        ezipupdate_conf = ''
        if helpers.get_dyndns_config(cfg) is not None:
            ezipupdate_conf = textwrap.dedent("""\

            # ez-ipupdate
            check process ez-ipupdate
                with pidfile \"%(ezipupdate_pid)s\"
                start program = \"%(fail_action)s\"
                stop program = \"%(stop_action)s\"
            """) % params

        conf = textwrap.dedent("""\
        set daemon 60
        set logfile syslog facility log_daemon

        check process twistd
            with pidfile \"%(webui_pid)s\"
            start program = \"%(fail_action)s\"
            stop program = \"%(stop_action)s\"

        check process openl2tp
            with pidfile \"%(openl2tp_pid)s\"
            start program = \"%(fail_action)s\"
            stop program = \"%(stop_action)s\"

        check process ippoold
            with pidfile \"%(ippool_pid)s\"
            start program = \"%(fail_action)s\"
            stop program = \"%(stop_action)s\"

        check process pluto
            with pidfile \"%(pluto_pid)s\"
            start program = \"%(fail_action)s\"
            stop program = \"%(stop_action)s\"
        """) % params
        
        self.configs = [{'file': constants.MONIT_CONF,
                         'cont': conf + dhcp_conf + ezipupdate_conf,
                         'mode': 0700}]