import gi gi.require_version('Gtk', '3.0') from gi.repository import GLib, Gtk, GObject import json import re import spur import threading import time 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 get_check_domain_command(domain): # return "sudo openssl x509 -text -in /etc/letsencrypt/live/" + domain + "/fullchain.pem" # # def join_commands(commands): # return " && ".join(commands) class EntryWindow(Gtk.Window): def __init__(self): Gtk.Window.__init__(self, title="Entry Demo") self.set_size_request(200, 100) self.timeout_id = None vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6) self.add(vbox) self.progressbar = Gtk.ProgressBar(show_text=True) # self.progressbar.set_fraction(0.0) vbox.pack_start(self.progressbar, True, True, 0) hbox = Gtk.Box(spacing=6) vbox.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 update_progess(self, domain): self.progressbar.pulse() self.progressbar.set_text('Done: ' + domain) return False def example_target(self): for d in self.domains: GLib.idle_add(self.get_https_subdomains_for_domain, d) time.sleep(0.3) def on_button_clicked(self, widget): decoded = ssh_command("ls /etc/letsencrypt/live", True) domains = decoded.split("\n") domains.pop() self.domains = domains self.num_domains = len(domains) self.num_done = 0 thread = threading.Thread(target=self.example_target) thread.daemon = True thread.start() # subdomains = [self.get_https_subdomains_for_domain(d) for d in domains] # subdomains_dict = dict(zip(domains, subdomains)) # print(subdomains_dict) def get_https_subdomains_for_domain(self, 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) self.num_done += 1 percent_done = self.num_done * 1.0 / self.num_domains # print(percent_done) self.progressbar.set_fraction(percent_done) # self.progressbar.set_text('Done: ' + domain) # print(cert_data) # return p.findall (cert_data) return False def app_main(): win = EntryWindow() win.connect("delete-event", Gtk.main_quit) win.show_all() if __name__ == '__main__': import signal signal.signal(signal.SIGINT, signal.SIG_DFL) # Calling GObject.threads_init() is not needed for PyGObject 3.10.2+ GObject.threads_init() app_main() Gtk.main()