| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- 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()
|