gtk3-listdomains.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import gi
  2. gi.require_version('Gtk', '3.0')
  3. from gi.repository import Gtk, GObject
  4. import spur
  5. import json
  6. import re
  7. fp = open('creds.json', 'r')
  8. creds = json.load(fp)
  9. def ssh_command(command, sudo=False):
  10. shell = spur.SshShell(
  11. hostname=creds['host'],
  12. username=creds['user'],
  13. private_key_file=creds['ssh_key_path'])
  14. with shell:
  15. command_bits = command.split(" ")
  16. if sudo:
  17. command_bits.insert(0, "sudo")
  18. process = shell.spawn(command_bits)
  19. if sudo:
  20. process.stdin_write(creds['password'])
  21. result = process.wait_for_result()
  22. return result.output.decode()
  23. def check_domain(domain):
  24. print(domain)
  25. p = re.compile('DNS:([0-9a-z-.]+)')
  26. cert_data = ssh_command("sudo openssl x509 -text -in /etc/letsencrypt/live/" + domain + "/fullchain.pem", True)
  27. print(cert_data)
  28. print(p.findall (cert_data))
  29. class EntryWindow(Gtk.Window):
  30. def __init__(self):
  31. Gtk.Window.__init__(self, title="Entry Demo")
  32. self.set_size_request(200, 100)
  33. self.timeout_id = None
  34. hbox = Gtk.Box(spacing=6)
  35. self.add(hbox)
  36. self.entry_passphrase = Gtk.Entry()
  37. # https://developer.gnome.org/gtk3/stable/GtkEntry.html#gtk-entry-set-invisible-char
  38. self.entry_passphrase.set_visibility(False)
  39. # self.entry_passphrase.set_text("Enter SSH key passphrase")
  40. hbox.pack_start(self.entry_passphrase, True, True, 0)
  41. self.entry_password = Gtk.Entry()
  42. self.entry_password.set_visibility(False)
  43. # self.entry_password.set_text("Enter sudo user password")
  44. hbox.pack_start(self.entry_password, True, True, 0)
  45. self.button = Gtk.Button(label="Click Here")
  46. self.button.connect("clicked", self.on_button_clicked)
  47. hbox.pack_start(self.button, True, True, 0)
  48. def on_button_clicked(self, widget):
  49. decoded = ssh_command("ls /etc/letsencrypt/live", True)
  50. domains = decoded.split("\n")
  51. domains.pop()
  52. for d in domains:
  53. if d == "benoithubert.net":
  54. check_domain(d)
  55. def app_main():
  56. win = EntryWindow()
  57. win.connect("delete-event", Gtk.main_quit)
  58. win.show_all()
  59. Gtk.main()
  60. if __name__ == '__main__':
  61. import signal
  62. signal.signal(signal.SIGINT, signal.SIG_DFL)
  63. app_main()