From 02f9f2d3f71be4a2757214612a9d6545d02fdaab Mon Sep 17 00:00:00 2001 From: jigen Date: Sun, 10 Jun 2018 23:15:57 +0200 Subject: [PATCH] Adding command line flags for operations --- OTcerts.py | 70 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 29 deletions(-) diff --git a/OTcerts.py b/OTcerts.py index edfa850..c04e89e 100644 --- a/OTcerts.py +++ b/OTcerts.py @@ -41,6 +41,14 @@ def init_prog(argv): required=False, default=default_conf_file, help="Specifity config file (default: {})".format(default_conf_file)) + parser.add_argument("--liste", default=False, action='store_true', required=False, + help="Richiedi i certificati per liste.indivia.net") + parser.add_argument("--hosting", default=False, action='store_true', required=False, + help="Richiedi i certificati per i siti in hosting") + parser.add_argument("--webmail", default=False, action='store_true', required=False, + help="Richiedi i certificati per le webmail") + parser.add_argument("--renew", default=False, action='store_true', required=False, + help="Invoca solamente il renew per i certificati gia' presenti") args = parser.parse_args() try: config = configparser.ConfigParser() @@ -185,33 +193,37 @@ if __name__ == '__main__': dns_conn=connect_db(dict(config['dns_db'])) # Caso speciale per le webmail - vhost_name = config['webmail']['vhost'].strip() - webmails_list = ["webmail.{}".format(d.strip()) for d in config['webmail']['domains'].split(',')] - if acme_request(config, vhost_name, acme_test='HTTP-01', dryrun=dryrun, domains_list=webmails_list): - link_cert(config, vhost_name, vhost_name, dryrun=dryrun) - else: - logger.error('Error asking certificate for {}'.format(vhost_name)) - - # Subdomains da escludere - ex_subdomains = tuple([s.strip() for s in config['main']['special_subdomains'].split(',') if len(s.strip())>0]) - domains_dict = get_domain_list(config, ot_conn, dns_conn) - - for domain_name, domain_feat in domains_dict.items(): - domain_feat['subdomains']=get_subdomain_list(config, domain_name, ot_conn, ex_subdomains=ex_subdomains) - # Controlla se i nameserver sono gestiti da noi - if domain_feat['managed_ns']: - # Nel caso il nameserver sia gestito, chiedi certificati per il dominio e la wildcard - if acme_request(config, domain_name, acme_test='DNS-01', dryrun=dryrun): - link_cert(config, domain_name, domain_name, dryrun=dryrun) - # Crea il link per ogni subdomain - for subdomain in domain_feat['subdomains']: - link_cert(config, domain_name, subdomain, dryrun=dryrun) + if args.webmail: + logging.info('Asking certificates for webmail') + vhost_name = config['webmail']['vhost'].strip() + webmails_list = ["webmail.{}".format(d.strip()) for d in config['webmail']['domains'].split(',')] + if acme_request(config, vhost_name, acme_test='HTTP-01', dryrun=dryrun, domains_list=webmails_list): + link_cert(config, vhost_name, vhost_name, dryrun=dryrun) else: - # Nel caso i nameserver NON siano gestiti, allora chiedi un certificato per ogni sottodominio - # Crea il link per ogni subdomain - for subdomain in domain_feat['subdomains']: - if acme_request(config, subdomain, acme_test='HTTP-01', dryrun=dryrun): - link_cert(config, subdomain, subdomain, dryrun=dryrun) - - ot_conn.close() - dns_conn.close() + logger.error('Error asking certificate for {}'.format(vhost_name)) + + if args.hosting: + logging.info('Asking certificates for hosted web domains') + # Subdomains da escludere + ex_subdomains = tuple([s.strip() for s in config['main']['special_subdomains'].split(',') if len(s.strip())>0]) + domains_dict = get_domain_list(config, ot_conn, dns_conn) + + for domain_name, domain_feat in domains_dict.items(): + domain_feat['subdomains']=get_subdomain_list(config, domain_name, ot_conn, ex_subdomains=ex_subdomains) + # Controlla se i nameserver sono gestiti da noi + if domain_feat['managed_ns']: + # Nel caso il nameserver sia gestito, chiedi certificati per il dominio e la wildcard + if acme_request(config, domain_name, acme_test='DNS-01', dryrun=dryrun): + link_cert(config, domain_name, domain_name, dryrun=dryrun) + # Crea il link per ogni subdomain + for subdomain in domain_feat['subdomains']: + link_cert(config, domain_name, subdomain, dryrun=dryrun) + else: + # Nel caso i nameserver NON siano gestiti, allora chiedi un certificato per ogni sottodominio + # Crea il link per ogni subdomain + for subdomain in domain_feat['subdomains']: + if acme_request(config, subdomain, acme_test='HTTP-01', dryrun=dryrun): + link_cert(config, subdomain, subdomain, dryrun=dryrun) + + ot_conn.close() + dns_conn.close()