Esempio n. 1
0
 def donttest_update_noip(self):
     logging.basicConfig()
     config = {}
     config['hostname'] = "dyndnsc.no-ip.biz"
     config['userid'] = "example"
     config['password'] = "******"
     config['protocol'] = "noip"
     config['method'] = "random"
     config['sleeptime'] = 60
     dyndnsclient = dyndnsc.getDynDnsClientForConfig(config)
     self.assertTrue(dyndnsclient.needsCheck())
Esempio n. 2
0
def main():
    import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument("-d", "--daemon", dest="daemon", help="go into daemon mode (implies --loop)", action="store_true", default=False)
    parser.add_argument("--hostname", dest="hostname", help="hostname to update", default=None)
    parser.add_argument("--key", dest="key", help="your authentication key", default=None)
    parser.add_argument("--userid", dest="userid", help="your userid", default=None)
    parser.add_argument("--password", dest="password", help="your password", default=None)
    parser.add_argument("--protocol", dest="protocol", help="protocol/service to use for updating your IP (default dyndns)", default='dyndns')
    parser.add_argument("--method", dest="method", help="method for detecting your IP (default webcheck)", default='webcheck')
    parser.add_argument("--loop", dest="loop", help="loop forever (default is to update once)", action="store_true", default=False)
    parser.add_argument("--sleeptime", dest="sleeptime", help="how long to sleep between checks in seconds", default=300)
    parser.add_argument("--version", dest="version", help="show version and exit", action="store_true", default=False)
    args = parser.parse_args()

    if args.version:
        print("dyndnsc %s" % pkg_resources.get_distribution("dyndnsc").version)  # pylint: disable=E1103
        return 0

    logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)s %(message)s')
    requests_log = logging.getLogger("requests")
    requests_log.setLevel(logging.WARNING)

    if args.hostname is None:
        parser.error("Please specify a hostname using --hostname")

    config = {}
    config['hostname'] = args.hostname
    config['key'] = args.key
    config['userid'] = args.userid
    config['password'] = args.password
    config['protocol'] = args.protocol
    config['method'] = args.method
    config['sleeptime'] = int(args.sleeptime)

    # done with command line options, bring on the dancing girls
    dyndnsclient = getDynDnsClientForConfig(config)
    if dyndnsclient is None:
        return 1
    # do an initial synchronization, before going into endless loop:
    dyndnsclient.sync()

    if args.daemon:
        daemonize()  # fork into background
        args.loop = True

    if args.loop:
        dyndnsclient.loop()
    else:
        dyndnsclient.check()

    return 0
Esempio n. 3
0
 def test_dummy(self):
     config = {}
     config['hostname'] = "dyndnsc.no-ip.biz"
     config['userid'] = "example"
     config['password'] = "******"
     config['protocol'] = "dummy"
     config['method'] = "random"
     config['sleeptime'] = 60
     dyndnsclient = dyndnsc.getDynDnsClientForConfig(config)
     self.assertTrue(dyndnsclient.needsCheck())
     dyndnsclient.needsForcedCheck()
     dyndnsclient.check()
     dyndnsclient.sync()
     dyndnsclient.stateHasChanged()
Esempio n. 4
0
 def test_dummy(self):
     config = {}
     config['hostname'] = "dyndnsc.no-ip.biz"
     config['userid'] = "example"
     config['password'] = "******"
     config['protocol'] = "dummy"
     config['method'] = "random"
     config['sleeptime'] = 60
     dyndnsclient = dyndnsc.getDynDnsClientForConfig(config)
     self.assertTrue(dyndnsclient.needs_check())
     dyndnsclient.needs_forced_check()
     dyndnsclient.check()
     dyndnsclient.sync()
     dyndnsclient.has_state_changed()
def getCallLaterDynDnsClientForAngelConfig(angelConfig, callLaterMethod,
                                           logger):
    """
    factory method to instantiate and initialize a complete and working dyndns client for 
    use in the reactor loop.
    
    @param config: a dictionary with configuration pairs
    @return: None or a valid object for use with reactor.callLater()  
    """

    # no need to expose this class globally
    class CallLaterDynDnsClient(object):
        "Minimal class to handle all of the dyndns logic using callbacks started from the reactor loop"

        def __init__(self, dyndnsclient, callLaterMethod, sleeptime):
            """
            @param dyndnsclient: a dyndnsclient object
            @param callLaterMethod: the twisted reactors callLater method
            @param sleeptime: how long to wait until callLater (secs)
            """
            self.sleeptime = sleeptime
            self.client = dyndnsclient
            self.callLaterMethod = callLaterMethod
            # do an initial synchronization:
            self.client.sync()

        def check(self):
            "this will make the dyndns client check its state and also insert an additional callLater timer"
            self.client.check()
            self.callLaterMethod(self.sleeptime, self.check)

    # actual method
    try:
        dyndnsc.logger = logger
        config = getDynDnsConfiguration(angelConfig)
        if config is None:
            return None
        client = dyndnsc.getDynDnsClientForConfig(config)
        if not client is None:
            return CallLaterDynDnsClient(client, callLaterMethod,
                                         config['sleeptime'])
        else:
            return None
    except Exception, e:
        getLogger().error("Initializing dyndns client crashed", exc_info=e)
        return None
Esempio n. 6
0
def getCallLaterDynDnsClientForAngelConfig(angelConfig, callLaterMethod, logger):
    """
    factory method to instantiate and initialize a complete and working dyndns client for 
    use in the reactor loop.
    
    @param config: a dictionary with configuration pairs
    @return: None or a valid object for use with reactor.callLater()  
    """
    # no need to expose this class globally 
    class CallLaterDynDnsClient(object):
        "Minimal class to handle all of the dyndns logic using callbacks started from the reactor loop"
        def __init__(self, dyndnsclient, callLaterMethod, sleeptime):
            """
            @param dyndnsclient: a dyndnsclient object
            @param callLaterMethod: the twisted reactors callLater method
            @param sleeptime: how long to wait until callLater (secs)
            """
            self.sleeptime = sleeptime
            self.client = dyndnsclient 
            self.callLaterMethod = callLaterMethod
            # do an initial synchronization:
            self.client.sync()
    
        def check(self):
            "this will make the dyndns client check its state and also insert an additional callLater timer"
            self.client.check()
            self.callLaterMethod(self.sleeptime, self.check)

    # actual method
    try:
        dyndnsc.logger = logger
        config = getDynDnsConfiguration(angelConfig)
        if config is None:
            return None
        client = dyndnsc.getDynDnsClientForConfig(config)
        if not client is None:
            return CallLaterDynDnsClient(client, callLaterMethod, config['sleeptime'])
        else:
            return None
    except Exception, e:
        getLogger().error("Initializing dyndns client crashed", exc_info = e)
        return None 
Esempio n. 7
0
    def test_dyndnsclient_factory(self):
        # the type of these exceptions is not formally required,
        # but we want to have some basic form of argument validity checking
        # Note: we prefer ValueError for semantically wrong options
        self.assertRaises(TypeError, dyndnsc.getDynDnsClientForConfig, None)
        self.assertRaises(ValueError, dyndnsc.getDynDnsClientForConfig, {})
        self.assertRaises(ValueError, dyndnsc.getDynDnsClientForConfig,
                          {'updater': ()})

        # create a dummy config:
        config = {}
        config['interval'] = 10
        config['detector'] = (("random", {}),)
        config['updater'] = (("dummy", {'hostname': "example.com"}),)
        dyndnsclient = dyndnsc.getDynDnsClientForConfig(config)
        self.assertEqual(dyndnsclient.detector.af(), dyndnsclient.dns.af())
        self.assertTrue(dyndnsclient.needs_check())
        dyndnsclient.needs_sync()
        dyndnsclient.check()
        dyndnsclient.sync()
        dyndnsclient.has_state_changed()
Esempio n. 8
0
    def test_dyndnsclient_factory(self):
        # the type of these exceptions is not formally required,
        # but we want to have some basic form of argument validity checking
        # Note: we prefer ValueError for semantically wrong options
        self.assertRaises(TypeError, dyndnsc.getDynDnsClientForConfig, None)
        self.assertRaises(ValueError, dyndnsc.getDynDnsClientForConfig, {})
        self.assertRaises(ValueError, dyndnsc.getDynDnsClientForConfig,
                          {'updater': ()})

        # create a dummy config:
        config = {}
        config['interval'] = 10
        config['detector'] = (("random", {}), )
        config['updater'] = (("dummy", {'hostname': "example.com"}), )
        dyndnsclient = dyndnsc.getDynDnsClientForConfig(config)
        self.assertEqual(dyndnsclient.detector.af(), dyndnsclient.dns.af())
        self.assertTrue(dyndnsclient.needs_check())
        dyndnsclient.needs_sync()
        dyndnsclient.check()
        dyndnsclient.sync()
        dyndnsclient.has_state_changed()
Esempio n. 9
0
def main():
    from dyndnsc.plugins.manager import DefaultPluginManager
    plugins = DefaultPluginManager()
    plugins.load_plugins()
    from os import environ

    import argparse
    parser = argparse.ArgumentParser()

    plugins.options(parser, environ)

    parser.add_argument("-d",
                        "--daemon",
                        dest="daemon",
                        help="go into daemon mode (implies --loop)",
                        action="store_true",
                        default=False)
    parser.add_argument("--debug",
                        dest="debug",
                        help="increase logging level to DEBUG",
                        action="store_true",
                        default=False)
    parser.add_argument("--hostname",
                        dest="hostname",
                        help="hostname to update",
                        default=None)
    parser.add_argument("--key",
                        dest="key",
                        help="your authentication key",
                        default=None)
    parser.add_argument("--userid",
                        dest="userid",
                        help="your userid",
                        default=None)
    parser.add_argument("--password",
                        dest="password",
                        help="your password",
                        default=None)
    parser.add_argument(
        "--protocol",
        dest="protocol",
        help="protocol to use for updating IP (default dyndns)",
        default='dyndns')
    parser.add_argument("--method",
                        dest="method",
                        help="method for detecting your IP (default webcheck)",
                        default='webcheck')
    parser.add_argument("--loop",
                        dest="loop",
                        help="loop forever (default is to update once)",
                        action="store_true",
                        default=False)
    parser.add_argument("--sleeptime",
                        dest="sleeptime",
                        help="how long to sleep between checks in seconds",
                        default=300)
    parser.add_argument("--version",
                        dest="version",
                        help="show version and exit",
                        action="store_true",
                        default=False)
    args = parser.parse_args()

    if args.version:
        print("dyndnsc %s" % __version__)
        return 0

    if args.debug:
        level = logging.DEBUG
    else:
        level = logging.INFO

    logging.basicConfig(level=level,
                        format='%(asctime)s %(levelname)s %(message)s')
    # silence 'requests' logging
    requests_log = logging.getLogger("requests")
    requests_log.setLevel(logging.WARNING)

    if args.hostname is None:
        parser.error("Please specify a hostname using --hostname")

    config = {}
    config['hostname'] = args.hostname
    config['key'] = args.key
    config['userid'] = args.userid
    config['password'] = args.password
    config['protocol'] = args.protocol
    config['method'] = args.method
    config['sleeptime'] = int(args.sleeptime)

    plugins.configure(args)
    plugins.initialize()

    # done with command line options, bring on the dancing girls
    dyndnsclient = getDynDnsClientForConfig(config, plugins=plugins)
    if dyndnsclient is None:
        return 1
    # do an initial synchronization, before going into endless loop:
    dyndnsclient.sync()

    if args.daemon:
        daemonize()  # fork into background
        args.loop = True

    if args.loop:
        dyndnsclient.loop()
    else:
        dyndnsclient.check()

    return 0
Esempio n. 10
0
def main():
    from dyndnsc.plugins.manager import DefaultPluginManager
    plugins = DefaultPluginManager()
    plugins.load_plugins()
    from os import environ

    import argparse
    parser = argparse.ArgumentParser()

    plugins.options(parser, environ)

    parser.add_argument("-d", "--daemon", dest="daemon",
                        help="go into daemon mode (implies --loop)",
                        action="store_true", default=False)
    parser.add_argument("--debug", dest="debug",
                        help="increase logging level to DEBUG",
                        action="store_true", default=False)
    parser.add_argument("--hostname", dest="hostname",
                        help="hostname to update", default=None)
    parser.add_argument("--key", dest="key",
                        help="your authentication key", default=None)
    parser.add_argument("--userid", dest="userid",
                        help="your userid", default=None)
    parser.add_argument("--password", dest="password",
                        help="your password", default=None)
    parser.add_argument("--protocol", dest="protocol",
                        help="protocol to use for updating IP (default dyndns)",
                        default='dyndns')
    parser.add_argument("--method", dest="method",
                        help="method for detecting your IP (default webcheck)",
                        default='webcheck')
    parser.add_argument("--loop", dest="loop",
                        help="loop forever (default is to update once)",
                        action="store_true", default=False)
    parser.add_argument("--sleeptime", dest="sleeptime",
                        help="how long to sleep between checks in seconds",
                        default=300)
    parser.add_argument("--version", dest="version",
                        help="show version and exit",
                        action="store_true", default=False)
    args = parser.parse_args()

    if args.version:
        print("dyndnsc %s" % __version__)
        return 0

    if args.debug:
        level = logging.DEBUG
    else:
        level = logging.INFO

    logging.basicConfig(level=level,
                        format='%(asctime)s %(levelname)s %(message)s')
    # silence 'requests' logging
    requests_log = logging.getLogger("requests")
    requests_log.setLevel(logging.WARNING)

    if args.hostname is None:
        parser.error("Please specify a hostname using --hostname")

    config = {}
    config['hostname'] = args.hostname
    config['key'] = args.key
    config['userid'] = args.userid
    config['password'] = args.password
    config['protocol'] = args.protocol
    config['method'] = args.method
    config['sleeptime'] = int(args.sleeptime)

    plugins.configure(args)
    plugins.initialize()

    # done with command line options, bring on the dancing girls
    dyndnsclient = getDynDnsClientForConfig(config, plugins=plugins)
    if dyndnsclient is None:
        return 1
    # do an initial synchronization, before going into endless loop:
    dyndnsclient.sync()

    if args.daemon:
        daemonize()  # fork into background
        args.loop = True

    if args.loop:
        dyndnsclient.loop()
    else:
        dyndnsclient.check()

    return 0