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 1880 2008-06-12 21:54:53Z sra $ 00011 00012 Copyright (C) 2007--2008 American Registry for Internet Numbers ("ARIN") 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 ARIN DISCLAIMS ALL WARRANTIES WITH 00019 REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 00020 AND FITNESS. IN NO EVENT SHALL ARIN 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 00027 import traceback, os, time, getopt, sys, MySQLdb, lxml.etree 00028 import rpki.resource_set, rpki.up_down, rpki.left_right, rpki.x509, rpki.sql 00029 import rpki.https, rpki.config, rpki.exceptions, rpki.relaxng, rpki.log 00030 import rpki.rpki_engine 00031 00032 os.environ["TZ"] = "UTC" 00033 time.tzset() 00034 00035 rpki.log.init("rpkid") 00036 00037 cfg_file = "rpkid.conf" 00038 profile = None 00039 00040 opts,argv = getopt.getopt(sys.argv[1:], "c:hp:?", ["config=", "help", "profile="]) 00041 for o,a in opts: 00042 if o in ("-h", "--help", "-?"): 00043 print __doc__ 00044 sys.exit(0) 00045 elif o in ("-c", "--config"): 00046 cfg_file = a 00047 elif o in ("-p", "--profile"): 00048 profile = a 00049 if argv: 00050 raise RuntimeError, "Unexpected arguments %s" % argv 00051 00052 def main(): 00053 00054 cfg = rpki.config.parser(cfg_file, "rpkid") 00055 00056 startup_msg = cfg.get("startup-message", "") 00057 if startup_msg: 00058 rpki.log.info(startup_msg) 00059 00060 if profile: 00061 rpki.log.info("Running in profile mode with output to %s" % profile) 00062 00063 gctx = rpki.rpki_engine.rpkid_context(cfg) 00064 00065 rpki.https.server(host = gctx.https_server_host, 00066 port = gctx.https_server_port, 00067 server_key = gctx.rpkid_key, 00068 server_cert = gctx.rpkid_cert, 00069 dynamic_https_trust_anchor = gctx.build_https_ta_cache, 00070 handlers = (("/left-right", gctx.left_right_handler), 00071 ("/up-down/", gctx.up_down_handler), 00072 ("/cronjob", gctx.cronjob_handler))) 00073 00074 if profile: 00075 import cProfile 00076 cProfile.run("main()", profile) 00077 else: 00078 main()