Browse Source

Adding command line flags for operations

jigen 5 years ago
parent
commit
02f9f2d3f7
1 changed files with 40 additions and 28 deletions
  1. 40 28
      OTcerts.py

+ 40 - 28
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))
+    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:
+            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)
+    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()
+        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()