Beispiel #1
0
def create_server_cert(cert, key, cert_path, args, port):
    cert_cmd.check_server_certificate(cert,key,cert_path,args,port,auto=True)
Beispiel #2
0
def main(*args, **keywords):
    if os.path.basename(sys.argv[0]) != 'cl-core':
        parser = cert_cmd.parse(full=False)
        args, unknown_args = parser.parse_known_args()
        args.method = '_temp_'
    else:
        parser = cert_cmd.parse(full=True)
        args, unknown_args = parser.parse_known_args()
        if args.method:
            parser = cert_cmd.parse(full=False)
            args, unknown_args = parser.parse_known_args()

    if not args.method:
        if unknown_args:
            args = parser.parse_args()

    if args.help and not args.method:
        parser.print_help()
        return 0

    from calculate.core.datavars import DataVarsCore
    ob = DataVarsCore()
    ob.importCore()

    # set var env
    if not ob.flIniFile():
        sys.exit(1)
#    cl_wsdl = ob.Get('cl_wsdl')
    cl_wsdl = ob.Get('cl_wsdl_available')
    data_path = ob.Get('cl_core_data')
    local_data_path = ob.Get('cl_core_local_data')
    certbase = ob.Get('cl_core_database')
    serv_certbase = ob.Get('cl_core_serv_database')
    rights = ob.Get('cl_core_rights')
    group_rights = ob.Get('cl_core_group_rights')
    sids = ob.Get('cl_core_sids_path')
    pids = ob.Get('cl_core_pids_path')
    sids_pids = ob.Get('cl_core_sids_pids')
    sids_file = ob.Get('cl_core_sids_file')
    pids_file = ob.Get('cl_core_pids_file')
    max_sid = ob.Get('cl_core_max_sid')
    max_pid = ob.Get('cl_core_max_pid')
    cert_path = ob.Get('cl_core_cert_path')
    cert = ob.Get('cl_core_cert')
    key = ob.Get('cl_core_key')
    cl_ver = ob.Get('cl_ver')
    log_path_var = ob.Get('cl_log_path')

    if args.version:
        print cl_ver
        return 0

    if os.getuid():
        if any("sbin" in x for x in sys.argv[0].split('/')):
            print _("User must be root")
            sys.exit(1)
    elif ob.Get('cl_ebuild_phase') == '':
        import logging
        import logging.handlers

        log_path = args.log_path if args.log_path else log_path_var

        if not os.path.exists(log_path):
            os.makedirs(log_path)
        LOG_FILENAME = os.path.join(log_path, 'logging_cl_core.out')
        file_logger = logging.getLogger('MyLogger')
        file_logger.setLevel(logging.DEBUG)

        # Add the log message handler to the logger
        handler = logging.handlers.RotatingFileHandler(
                    LOG_FILENAME, maxBytes=10000000, backupCount=3)

        file_logger.addHandler(handler)

        # debug
        if args.debug:
            logging.basicConfig(level=logging.DEBUG)
            logger = logging.getLogger('soaplib.wsgi')
            logger.setLevel(logging.DEBUG)

        from urllib2 import URLError

    from traceback import print_exc
    if not args.method:
        try:
            port = args.port
            if args.check:
                import bootstrap
                bootstrap.check(cert, key, cert_path, data_path, certbase, args)
                return 0
            if args.bootstrap_user_name:
                import bootstrap
                bootstrap.init(cert, key, cert_path, data_path, certbase, args, \
                               port, args.bootstrap_user_name)
                return 0
            if args.revoke_cert_id:
                cert_cmd.revoke_signed_cert(args.revoke_cert_id, data_path,
                                            cert_path)
                return 0
            if args.host or args.gen_root_cert or args.root_host or \
                                                               args.use_root_cert:
                cert_cmd.check_server_certificate(cert, key, cert_path, args, port)
                return 0
            if args.id_client_req:
                cert_cmd.sing_req_by_server(args.id_client_req,cert_path,data_path)
                return 0
            if args.Id:
                cert_cmd.view_cert(args, certbase, data_path, rights, group_rights)
                return 0
            if args.cert_id:
                cert_cmd.view_signed_cert(args, serv_certbase, data_path)
                return 0
            if args.req_id:
                cert_cmd.view_client_request(args, certbase, data_path)
                return 0
            # Sign request by root certificate
            if args.id_server_req:
                cert_cmd.sing_req_by_root(args, cert_path, data_path)
                return 0
            if args.id_del_req or args.id_del_client_req:
                cert_cmd.del_request(args.id_del_req, args.id_del_client_req,
                                     serv_certbase, certbase, data_path)
                return 0
        except URLError, e:
            fd = open(LOG_FILENAME,'a')
            file_logger.debug(print_exc(file=fd))
            fd.close()
            print e