00001 """ 00002 RPKI engine daemon. This is still very much a work in progress. 00003 00004 Usage: python rpkid.py [ { -c | --config } configfile ] 00005 [ { -h | --help } ] 00006 [ { -p | --profile } outputfile ] 00007 00008 Default configuration file is rpkid.conf, override with --config option. 00009 00010 $Id: rpkid.py 2913 2009-12-28 20:55:38Z sra $ 00011 00012 Copyright (C) 2009 Internet Systems Consortium ("ISC") 00013 00014 Permission to use, copy, modify, and distribute this software for any 00015 purpose with or without fee is hereby granted, provided that the above 00016 copyright notice and this permission notice appear in all copies. 00017 00018 THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 00019 REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 00020 AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 00021 INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 00022 LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 00023 OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 00024 PERFORMANCE OF THIS SOFTWARE. 00025 00026 Portions copyright (C) 2007--2008 American Registry for Internet Numbers ("ARIN") 00027 00028 Permission to use, copy, modify, and distribute this software for any 00029 purpose with or without fee is hereby granted, provided that the above 00030 copyright notice and this permission notice appear in all copies. 00031 00032 THE SOFTWARE IS PROVIDED "AS IS" AND ARIN DISCLAIMS ALL WARRANTIES WITH 00033 REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 00034 AND FITNESS. IN NO EVENT SHALL ARIN BE LIABLE FOR ANY SPECIAL, DIRECT, 00035 INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 00036 LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 00037 OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 00038 PERFORMANCE OF THIS SOFTWARE. 00039 """ 00040 00041 import os, time, getopt, sys 00042 import rpki.resource_set, rpki.up_down, rpki.left_right, rpki.x509, rpki.sql 00043 import rpki.https, rpki.config, rpki.exceptions, rpki.relaxng, rpki.log 00044 import rpki.rpki_engine 00045 00046 os.environ["TZ"] = "UTC" 00047 time.tzset() 00048 00049 cfg_file = "rpkid.conf" 00050 profile = None 00051 00052 opts, argv = getopt.getopt(sys.argv[1:], "c:dhp:?", ["config=", "debug", "help", "profile="]) 00053 for o, a in opts: 00054 if o in ("-h", "--help", "-?"): 00055 print __doc__ 00056 sys.exit(0) 00057 elif o in ("-d", "--debug"): 00058 rpki.log.use_syslog = False 00059 elif o in ("-c", "--config"): 00060 cfg_file = a 00061 elif o in ("-p", "--profile"): 00062 profile = a 00063 if argv: 00064 raise RuntimeError, "Unexpected arguments %s" % argv 00065 00066 rpki.log.init("rpkid") 00067 00068 def main(): 00069 00070 cfg = rpki.config.parser(cfg_file, "rpkid") 00071 00072 startup_msg = cfg.get("startup-message", "") 00073 if startup_msg: 00074 rpki.log.info(startup_msg) 00075 00076 if profile: 00077 rpki.log.info("Running in profile mode with output to %s" % profile) 00078 00079 cfg.set_global_flags() 00080 00081 gctx = rpki.rpki_engine.rpkid_context(cfg) 00082 00083 gctx.start_cron() 00084 00085 rpki.https.server(host = gctx.https_server_host, 00086 port = gctx.https_server_port, 00087 server_key = gctx.rpkid_key, 00088 server_cert = gctx.rpkid_cert, 00089 dynamic_https_trust_anchor = gctx.build_https_ta_cache, 00090 handlers = (("/left-right", gctx.left_right_handler), 00091 ("/up-down/", gctx.up_down_handler), 00092 ("/cronjob", gctx.cronjob_handler))) 00093 00094 if profile: 00095 import cProfile 00096 cProfile.run("main()", profile) 00097 else: 00098 main()