Benoît Hubert 7 gadi atpakaļ
revīzija
3116cde1b2
1 mainītis faili ar 78 papildinājumiem un 0 dzēšanām
  1. 78 0
      gtk3-listdomains.py

+ 78 - 0
gtk3-listdomains.py

@@ -0,0 +1,78 @@
+import gi
+gi.require_version('Gtk', '3.0')
+from gi.repository import Gtk, GObject
+import spur
+import json
+import re
+
+fp = open('creds.json', 'r')
+creds = json.load(fp)
+
+def ssh_command(command, sudo=False):
+    shell = spur.SshShell(
+        hostname=creds['host'],
+        username=creds['user'],
+        private_key_file=creds['ssh_key_path'])
+    with shell:
+        command_bits = command.split(" ")
+        if sudo:
+            command_bits.insert(0, "sudo")
+        process = shell.spawn(command_bits)
+        if sudo:
+            process.stdin_write(creds['password'])
+        result = process.wait_for_result()
+    return result.output.decode()
+
+def check_domain(domain):
+    print(domain)
+    p = re.compile('DNS:([0-9a-z-.]+)')
+    cert_data = ssh_command("sudo openssl x509 -text -in /etc/letsencrypt/live/" + domain + "/fullchain.pem", True)
+    print(cert_data)
+    print(p.findall (cert_data))
+
+class EntryWindow(Gtk.Window):
+
+    def __init__(self):
+        Gtk.Window.__init__(self, title="Entry Demo")
+        self.set_size_request(200, 100)
+
+        self.timeout_id = None
+
+        hbox = Gtk.Box(spacing=6)
+        self.add(hbox)
+
+        self.entry_passphrase = Gtk.Entry()
+        # https://developer.gnome.org/gtk3/stable/GtkEntry.html#gtk-entry-set-invisible-char
+        self.entry_passphrase.set_visibility(False)
+        # self.entry_passphrase.set_text("Enter SSH key passphrase")
+        hbox.pack_start(self.entry_passphrase, True, True, 0)
+
+        self.entry_password = Gtk.Entry()
+        self.entry_password.set_visibility(False)
+        # self.entry_password.set_text("Enter sudo user password")
+        hbox.pack_start(self.entry_password, True, True, 0)
+
+        self.button = Gtk.Button(label="Click Here")
+        self.button.connect("clicked", self.on_button_clicked)
+        hbox.pack_start(self.button, True, True, 0)
+
+    def on_button_clicked(self, widget):
+        decoded = ssh_command("ls /etc/letsencrypt/live", True)
+        domains = decoded.split("\n")
+        domains.pop()
+
+        for d in domains:
+            if d == "benoithubert.net":
+                check_domain(d)
+
+
+def app_main():
+    win = EntryWindow()
+    win.connect("delete-event", Gtk.main_quit)
+    win.show_all()
+    Gtk.main()
+
+if __name__ == '__main__':
+    import signal
+    signal.signal(signal.SIGINT, signal.SIG_DFL)
+    app_main()