f4Nm1Z9k2P

letsencrypt-imscp.py

Mar 12th, 2016
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.16 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3.  
  4. # Dieses Skript kann Zertifikate nur updaten. Ist noch kein Zertifikat vorhanden, wird es aber von
  5. # letsencrypt-auto erstellt und muss dann einmalig manuell in i-MSCP zu der jeweiligen Domain
  6. # hinzugefügt werden.
  7.  
  8. # Autoren: seppel (i-mscp.net user)
  9. # f4Nm1Z9k2P (i-mscp.net user)
  10. #
  11. # Letzte Änderung: 2016-07-01
  12.  
  13. import subprocess
  14. import os
  15. import MySQLdb
  16. username="root"
  17. pw=""
  18. pfadLetsencryptauto="/root/certbot/certbot-auto"
  19. db = MySQLdb.connect( host="localhost",
  20.  user=username,
  21.  passwd=pw,
  22.  db="imscp")
  23. cur = db.cursor()
  24. cur.execute("SELECT domain_name FROM domain WHERE domain_name IN ('example.com', 'example.invalid');");
  25. for domainTmp in cur.fetchall():
  26.  domain = domainTmp[0]
  27.  print domain
  28.  domainListe = []
  29.  cmd = pfadLetsencryptauto+" certonly --apache --keep -d "+domain+" -d www."+domain
  30.  cur.execute("select subdomain_name,subdomain_mount from subdomain where domain_id=(select domain_id from domain where domain_name='"+domain+"');");
  31.  for subdomain in cur.fetchall():
  32.   domainListe.append(subdomain[0]+"."+domain);
  33.   cmd = cmd +" -d "+(subdomain[0]+"."+domain)
  34.  print domainListe
  35.  print cmd
  36.  os.system(cmd)
  37.  pkey = open("/etc/letsencrypt/live/"+domain+"/privkey.pem",'r').read() #default-pfad
  38.  chain = open("/etc/letsencrypt/live/"+domain+"/chain.pem",'r').read() #default-pfad
  39.  cert = open("/etc/letsencrypt/live/"+domain+"/cert.pem",'r').read() #default-pfad
  40.  cur.execute("""update ssl_certs set
  41. ca_bundle=%s,
  42. private_key=%s,
  43. certificate=%s,
  44. status=%s
  45. where
  46. domain_type='dmn'
  47. AND domain_id=(select domain_id from domain where domain_name=%s)
  48. """
  49.  ,(chain,pkey,cert,'tochange',domain));
  50.  foo = cur.execute("""update ssl_certs set
  51. ca_bundle=%s,
  52. private_key=%s,
  53. certificate=%s,
  54. status=%s
  55. where domain_type='sub'
  56. AND domain_id IN (select subdomain_id
  57. from subdomain
  58. where domain_id= (select domain_id from domain where domain_name=%s)
  59. );
  60. """,(chain,pkey,cert,'tochange',domain));
  61.  cur.execute("update domain set domain_status='tochange'");
  62.  cur.execute("update subdomain set subdomain_status='tochange'");
  63.  db.commit();
  64. os.system("/var/www/imscp/engine/imscp-rqst-mngr")
Add Comment
Please, Sign In to add comment