def get_gale_sys_env(): pygaledir = gale_env.get('PYGALE_DIR', os.path.join(userinfo.home_dir, '.gale')) fname = os.path.join(pygaledir, PYGALE_CONF) if os.path.exists(fname): gale_env.load_file(fname) result = 'Reading PyGale settings from ' + fname else: # Assume some reasonable defaults try: gale_env.set('GALE_SYS_DIR', os.path.join(string.strip( os.popen('gale-config --prefix', 'r').read()), 'etc', 'gale')) except: # Can't find gale-config; Gale probably isn't installed if sys.platform == 'win32': gale_env.set('GALE_SYS_DIR', get_start_dir()) else: gale_env.set('GALE_SYS_DIR', '/usr/local/etc/gale') conffile = os.path.join(gale_env.get('GALE_SYS_DIR'), 'conf') if os.path.exists(conffile): confvars = gale_env.parse_sys_conf(conffile) result = 'Reading Gale settings from ' + conffile else: confvars = {} result = 'No existing Gale configuration found' if confvars.has_key('GALE_DOMAIN'): gale_env.set('GALE_DOMAIN', confvars['GALE_DOMAIN']) return result
def get_gale_sys_env(): pygaledir = gale_env.get('PYGALE_DIR', os.path.join(userinfo.home_dir, '.gale')) fname = os.path.join(pygaledir, PYGALE_CONF) if os.path.exists(fname): gale_env.load_file(fname) result = 'Reading PyGale settings from ' + fname else: # Assume some reasonable defaults try: gale_env.set( 'GALE_SYS_DIR', os.path.join( string.strip(os.popen('gale-config --prefix', 'r').read()), 'etc', 'gale')) except: # Can't find gale-config; Gale probably isn't installed if sys.platform == 'win32': gale_env.set('GALE_SYS_DIR', get_start_dir()) else: gale_env.set('GALE_SYS_DIR', '/usr/local/etc/gale') conffile = os.path.join(gale_env.get('GALE_SYS_DIR'), 'conf') if os.path.exists(conffile): confvars = gale_env.parse_sys_conf(conffile) result = 'Reading Gale settings from ' + conffile else: confvars = {} result = 'No existing Gale configuration found' if confvars.has_key('GALE_DOMAIN'): gale_env.set('GALE_DOMAIN', confvars['GALE_DOMAIN']) return result
def check(): pygaledir = gale_env.get('PYGALE_DIR', os.path.join(userinfo.home_dir, '.gale')) conf_file = os.path.join(pygaledir, PYGALE_CONF) if os.path.exists(conf_file): gale_env.load_file(conf_file) if gale_env.get('PYGALE_VERSION', '1.0') >= version.VERSION: return run_gui_setup()
def __init__(self, master, wizard, vars): Tkinter.Frame.__init__(self, master) self.wizard = wizard self.vars = vars self.title = 'PyGale configuration' self.galedir = gale_env.get('PYGALE_DIR', os.path.join(userinfo.home_dir, '.gale')) if not os.path.exists(self.galedir): create_str = "\n\nThis directory does not exist. I'll " +\ 'create it for you.\n' else: create_str = '\n\nGood! This directory already exists.\n' conffile = os.path.join(self.galedir, PYGALE_CONF) if os.path.exists(conffile): create_str = create_str + "I'll read the settings from " +\ 'your existing conf file.\n' gale_env.load_file(conffile) self.label = Tkinter.Label(self, wraplength=310, anchor='nw', justify='left', text= 'PyGale configuration, version %s\n\n' % version.VERSION + 'By default, this configuration will be stored in the ' + '.gale directory in your home directory. Optionally, you ' + 'can set the environment variable PYGALE_DIR to a directory ' + 'where the configuration file will be stored.\n\n' + 'Your Gale directory is: ' + self.galedir + create_str )
def next(self): sig_name = self.gale_user.get() gale_env.set('GALE_ID', sig_name) gale_dir = gale_env.get('GALE_DIR', os.path.join(userinfo.home_dir, '.gale')) privkey = os.path.join(gale_dir, 'auth', 'private', sig_name) privkey_gpri = os.path.join(gale_dir, 'auth', 'private', sig_name + '.gpri') self.vars['sig_name'] = sig_name if os.path.exists(privkey_gpri): file_exists = 1 sigfile = privkey_gpri elif os.path.exists(privkey): file_exists = 1 sigfile = privkey else: file_exists = 0 sigfile = None next_is_sigscreen = self.wizard.next_screen_is(self, FindSignature) if not file_exists and not next_is_sigscreen: self.wizard.add_screen_after(self, FindSignature) elif not file_exists and next_is_sigscreen: pass elif file_exists and not next_is_sigscreen: pass elif file_exists and next_is_sigscreen: self.wizard.del_screen_after(self) if file_exists: self.vars['sig_file_name'] = sigfile
def run_gui_setup(): print get_gale_sys_env() root = Tkinter.Tk() if sys.platform == 'win32': wizard = WizardDialog( root, [GetPygaleDir, GetGaleDomain, GetGaleUser, EnterUser]) else: wizard = WizardDialog(root, [ GetPygaleDir, GetGaleSysDir, GetGaleDomain, GetGaleUser, EnterUser ]) wizard.wait_window(wizard) if not wizard.finished: sys.exit(0) write_settings() # Copy private key file user, domain = string.split(os.path.basename(wizard.vars['sig_name']), '@', 1) gale_dir = gale_env.get('GALE_DIR', os.path.join(userinfo.home_dir, '.gale')) private_dir = os.path.join(gale_dir, 'auth', 'private') target_file = os.path.join(private_dir, os.path.basename(wizard.vars['sig_file_name'])) if not os.path.exists(target_file): shutil.copy(wizard.vars['sig_file_name'], target_file) else: print 'Not overwriting existing private key:', target_file # Quit root.destroy()
def run_gui_setup(): print get_gale_sys_env() root = Tkinter.Tk() if sys.platform == 'win32': wizard = WizardDialog(root, [GetPygaleDir, GetGaleDomain, GetGaleUser, EnterUser]) else: wizard = WizardDialog(root, [GetPygaleDir, GetGaleSysDir, GetGaleDomain, GetGaleUser, EnterUser]) wizard.wait_window(wizard) if not wizard.finished: sys.exit(0) write_settings() # Copy private key file user, domain = string.split(os.path.basename( wizard.vars['sig_name']),'@', 1) gale_dir = gale_env.get('GALE_DIR', os.path.join(userinfo.home_dir, '.gale')) private_dir = os.path.join(gale_dir, 'auth', 'private') target_file = os.path.join(private_dir, os.path.basename(wizard.vars['sig_file_name'])) if not os.path.exists(target_file): shutil.copy(wizard.vars['sig_file_name'], target_file) else: print 'Not overwriting existing private key:', target_file # Quit root.destroy()
def __init__(self, master, wizard, vars): Tkinter.Frame.__init__(self, master) self.vars = vars self.title = 'Find Signature' self.sig_file_name = Tkinter.StringVar() sig_name = self.vars['sig_name'] gale_dir = gale_env.get('GALE_DIR', os.path.join(userinfo.home_dir, '.gale')) sig_file = os.path.join(gale_dir, 'auth', 'private', sig_name) sig_file_gpri = sig_file + '.gpri' if os.path.exists(sig_file_gpri): self.sig_file_name.set(sig_file_gpri) elif os.path.exists(sig_file): self.sig_file_name.set(sig_file) self.grid_propagate(0) self.grid_rowconfigure(0, weight=1) self.grid_rowconfigure(1, weight=1) self.grid_columnconfigure(0, weight=1) self.grid_columnconfigure(1, weight=0) self.label = Tkinter.Label( self, wraplength=310, anchor='nw', justify='left', text= "The Gale id you have specified requires a private key file. I was unable to find it at either '%s' or '%s'. Enter the location of your private key file." % (sig_file_gpri, sig_file)) self.browse_button = Tkinter.Button(self, command=self.browse, text='Browse', width=10) self.entry = Tkinter.Entry(self, textvariable=self.sig_file_name)
def __init__(self, master, wizard, vars): Tkinter.Frame.__init__(self, master) self.wizard = wizard self.vars = vars self.title = 'PyGale configuration' self.galedir = gale_env.get('PYGALE_DIR', os.path.join(userinfo.home_dir, '.gale')) if not os.path.exists(self.galedir): create_str = "\n\nThis directory does not exist. I'll " +\ 'create it for you.\n' else: create_str = '\n\nGood! This directory already exists.\n' conffile = os.path.join(self.galedir, PYGALE_CONF) if os.path.exists(conffile): create_str = create_str + "I'll read the settings from " +\ 'your existing conf file.\n' gale_env.load_file(conffile) self.label = Tkinter.Label( self, wraplength=310, anchor='nw', justify='left', text='PyGale configuration, version %s\n\n' % version.VERSION + 'By default, this configuration will be stored in the ' + '.gale directory in your home directory. Optionally, you ' + 'can set the environment variable PYGALE_DIR to a directory ' + 'where the configuration file will be stored.\n\n' + 'Your Gale directory is: ' + self.galedir + create_str)
def __init__(self, master, wizard, vars): Tkinter.Frame.__init__(self, master) self.wizard = wizard self.vars = vars self.gale_sys_dir = Tkinter.StringVar() self.title = 'PyGale configuration' self.gale_sys_dir.set(gale_env.get('GALE_SYS_DIR', '/usr/local/etc/gale')) self.label = Tkinter.Label(self, wraplength = 310, anchor = 'nw', justify = 'left', text = "Gale system directory\n\nThis directory contains the public key cache and other Gale-specific data. It can and should be shared between Gale users on the same machine or network. If you have an existing Gale installation, enter its path here. Otherwise, I will create this directory for you.") self.entry = Tkinter.Entry(self, textvariable = self.gale_sys_dir)
def __init__(self, master, wizard, vars): Tkinter.Frame.__init__(self, master) self.title = 'Select User Name' self.vars = vars self.user_name = Tkinter.StringVar() # Use (in order) GALE_NAME or our username fullname = gale_env.get('GALE_NAME', userinfo.user_name) self.user_name.set(fullname) self.grid_propagate(0) self.grid_rowconfigure(0, weight = 1) self.grid_rowconfigure(1, weight = 1) self.grid_columnconfigure(0, weight = 1) self.user_label = Tkinter.Label(self, wraplength = 310, anchor = 'nw', justify = 'left', text = "Enter your user name. This is a free form string that accompanies every puff. People generally use their full name (e.g. Joe Smith).") self.user_entry = Tkinter.Entry(self, textvariable = self.user_name)
def __init__(self, master, wizard, vars): Tkinter.Frame.__init__(self, master) self.wizard = wizard self.vars = vars self.title = 'Enter Gale Domain' self.gale_domain = Tkinter.StringVar() domain = gale_env.get('GALE_DOMAIN', None) if domain is None: domain = socket.gethostbyaddr(socket.gethostname())[0] self.gale_domain.set(domain) self.grid_propagate(0) self.grid_rowconfigure(0, weight = 1) self.grid_rowconfigure(1, weight = 1) self.grid_columnconfigure(0, weight = 1) self.label = Tkinter.Label(self, wraplength = 310, anchor = 'nw', justify = 'left', text = "Gale domain\n\nEnter your Gale domain here (for example, gale.org). If you don't know what this is, contact your local Gale administrator. This domain will be appended to all non-qualified locations, and it determines which Gale server you will connect to.") self.entry = Tkinter.Entry(self, textvariable = self.gale_domain)
def __init__(self, master, wizard, vars): Tkinter.Frame.__init__(self, master) self.wizard = wizard self.vars = vars self.gale_sys_dir = Tkinter.StringVar() self.title = 'PyGale configuration' self.gale_sys_dir.set( gale_env.get('GALE_SYS_DIR', '/usr/local/etc/gale')) self.label = Tkinter.Label( self, wraplength=310, anchor='nw', justify='left', text= "Gale system directory\n\nThis directory contains the public key cache and other Gale-specific data. It can and should be shared between Gale users on the same machine or network. If you have an existing Gale installation, enter its path here. Otherwise, I will create this directory for you." ) self.entry = Tkinter.Entry(self, textvariable=self.gale_sys_dir)
def main(): global RETURN_RECEIPT, DONT_SEND opts, args = getopt.getopt(sys.argv[1:], 'pPd:vn') for (opt, val) in opts: if opt == '-P': RETURN_RECEIPT = 0 elif opt == '-p': RETURN_RECEIPT = 1 elif opt == '-n': DONT_SEND = 1 elif opt == '-d': pygale.DEBUG = int(val) elif opt == '-v': usage(sys.argv[0]) sys.exit(0) else: usage(sys.argv[0]) print 'Unknown option:', opt sys.exit(0) # Initialize PyGale before processing locations pygale.init() sys.exitfunc = pygale.shutdown pygale.set_error_handler(print_msg) pygale.set_update_handler(print_msg) if not gale_env.get('GALE_DOMAIN', None): print 'Please run pygale-config to set up your PyGale environment.' sys.exit(0) # Extract locations and keywords from cmdline args locs = filter(lambda x: x[0] != '/', args) # default domain and alias expansion locs = map(pygale.expand_aliases, locs) keywords = map(lambda x: x[1:], filter(lambda x: x[0] == '/', args)) if not locs: usage(sys.argv[0]) sys.exit() # Send it try: sendpuff(locs, keywords) except KeyboardInterrupt: sys.exit(0)
def __init__(self, master, wizard, vars): Tkinter.Frame.__init__(self, master) self.title = 'Select User Name' self.vars = vars self.user_name = Tkinter.StringVar() # Use (in order) GALE_NAME or our username fullname = gale_env.get('GALE_NAME', userinfo.user_name) self.user_name.set(fullname) self.grid_propagate(0) self.grid_rowconfigure(0, weight=1) self.grid_rowconfigure(1, weight=1) self.grid_columnconfigure(0, weight=1) self.user_label = Tkinter.Label( self, wraplength=310, anchor='nw', justify='left', text= "Enter your user name. This is a free form string that accompanies every puff. People generally use their full name (e.g. Joe Smith)." ) self.user_entry = Tkinter.Entry(self, textvariable=self.user_name)
def __init__(self, master, wizard, vars): Tkinter.Frame.__init__(self, master) self.wizard = wizard self.vars = vars self.title = 'Enter Gale Domain' self.gale_domain = Tkinter.StringVar() domain = gale_env.get('GALE_DOMAIN', None) if domain is None: domain = socket.gethostbyaddr(socket.gethostname())[0] self.gale_domain.set(domain) self.grid_propagate(0) self.grid_rowconfigure(0, weight=1) self.grid_rowconfigure(1, weight=1) self.grid_columnconfigure(0, weight=1) self.label = Tkinter.Label( self, wraplength=310, anchor='nw', justify='left', text= "Gale domain\n\nEnter your Gale domain here (for example, gale.org). If you don't know what this is, contact your local Gale administrator. This domain will be appended to all non-qualified locations, and it determines which Gale server you will connect to." ) self.entry = Tkinter.Entry(self, textvariable=self.gale_domain)
def on_connect(host, conn, sub, quiet): print_msg('Connected to %s' % host) if not quiet: sender = gale_env.get('GALE_FROM', 'Unknown sender') pygale.notify_in('in.present', conn, fullname=sender) pygale.notify_out('out.disconnected', conn, fullname=sender) # Subscribe to a list of locations # Add in our location if not there myid = pygale.gale_user() if myid not in sub: sub.append(myid) bad, good = conn.sub_to(sub) if bad: for b in bad: print_msg('Unable to find location %s' % b) if not good: print_msg('No locations found') sys.exit(-1) else: for g in good: print_msg('Subscribed to %s' % g)
def __init__(self, master, wizard, vars): Tkinter.Frame.__init__(self, master) self.vars = vars self.title = 'Find Signature' self.sig_file_name = Tkinter.StringVar() sig_name = self.vars['sig_name'] gale_dir = gale_env.get('GALE_DIR', os.path.join(userinfo.home_dir, '.gale')) sig_file = os.path.join(gale_dir, 'auth', 'private', sig_name) sig_file_gpri = sig_file + '.gpri' if os.path.exists(sig_file_gpri): self.sig_file_name.set(sig_file_gpri) elif os.path.exists(sig_file): self.sig_file_name.set(sig_file) self.grid_propagate(0) self.grid_rowconfigure(0, weight = 1) self.grid_rowconfigure(1, weight = 1) self.grid_columnconfigure(0, weight = 1) self.grid_columnconfigure(1, weight = 0) self.label = Tkinter.Label(self, wraplength = 310, anchor = 'nw', justify = 'left', text = "The Gale id you have specified requires a private key file. I was unable to find it at either '%s' or '%s'. Enter the location of your private key file." % (sig_file_gpri, sig_file)) self.browse_button = Tkinter.Button(self, command = self.browse, text= 'Browse', width = 10) self.entry = Tkinter.Entry(self, textvariable = self.sig_file_name)
def write_settings(): GALE_SYS_DIR = gale_env.get('GALE_SYS_DIR') conditional_mkdir(GALE_SYS_DIR, 0755) conditional_mkdir(os.path.join(GALE_SYS_DIR, 'auth'), 0755) conditional_mkdir(os.path.join(GALE_SYS_DIR, 'auth', 'cache'), 0777) conditional_mkdir(os.path.join(GALE_SYS_DIR, 'auth', 'local'), 01777) conditional_mkdir(os.path.join(GALE_SYS_DIR, 'auth', 'private'), 0755) conditional_mkdir(os.path.join(GALE_SYS_DIR, 'auth', 'trusted'), 0755) root_key_path = os.path.join(GALE_SYS_DIR, 'auth', 'trusted', 'ROOT') if not os.path.exists(root_key_path): try: f = open(root_key_path, 'wb') f.write(ROOT.rootkey) f.close() os.chmod(root_key_path, 0644) except: print '#' * 50 print 'Trouble installing the ROOT key in its proper location.' print 'WARNING! Puffs will not be verified!' print '#' * 50 galedir = gale_env.get('GALE_DIR', os.path.join(userinfo.home_dir, '.gale')) conditional_mkdir(galedir) conditional_mkdir(os.path.join(galedir, 'auth')) conditional_mkdir(os.path.join(galedir, 'auth', 'local')) conditional_mkdir(os.path.join(galedir, 'auth', 'private')) conditional_mkdir(os.path.join(galedir, 'auth', 'trusted')) pygaledir = gale_env.get('PYGALE_DIR', os.path.join(userinfo.home_dir, '.gale')) fname = os.path.join(pygaledir, PYGALE_CONF) f = open(fname, 'w') f.write('PYGALE_VERSION %s\n' % version.VERSION) f.write('GALE_SYS_DIR %s\n' % gale_env.get('GALE_SYS_DIR')) f.write('GALE_ID %s\n' % gale_env.get('GALE_ID')) f.write('GALE_DOMAIN %s\n' % gale_env.get('GALE_DOMAIN')) f.write('GALE_NAME %s\n' % gale_env.get('GALE_NAME')) f.close() print 'Run pygale-config to modify this configuration at any point.'
def sendpuff(locs, keywords): # Look up locations ret = pygale.lookup_all_locations(locs) send_locs = [] bad_locs = [] encr_recipients = [] for (loc, recps) in ret: if recps is None: bad_locs.append(loc) else: send_locs.append(loc) encr_recipients = encr_recipients + recps if bad_locs: print 'Error: no valid recipients' sys.exit(-1) if '' in encr_recipients: # null key encr_recipients = [] # Print the header bolded_locs = map(prettypuff.bold_location, send_locs) header = 'To: %s' % string.join(bolded_locs, ' ') if keywords: bolded_keywords = map(prettypuff.bold_keyword, keywords) bolded_keywords = map(lambda x: '/' + x, bolded_keywords) header = header + ' ' + string.join(bolded_keywords, ' ') print header print '(End your message with EOF or a solitary dot.)' # Get the puff text pufftext = enter_puff() # Construct puff signer = pygale.gale_user() puff = pygale.Puff() gfrom = gale_env.get('GALE_NAME', gale_env.get('GALE_FROM', 'PyGale user')) puff.set_loc(string.join(locs, ' ')) puff.set_text('message/sender', gfrom) puff.set_time('id/time', int(time.time())) puff.set_text('id/class', 'gsend.py/%s' % version.VERSION) puff.set_text('id/instance', pygale.getinstance()) if RETURN_RECEIPT: puff.set_text('question.receipt', signer) if keywords: for keyw in keywords: puff.set_text('message.keyword', keyw) puff.set_text('message/body', pufftext) # Sign ret = puff.sign_message(signer) if ret is None: # unable to sign signed_puff = puff else: signed_puff = ret # Encrypt if encr_recipients: ret = signed_puff.encrypt_message(encr_recipients) if ret is None: # unable to encrypt encrypted_puff = signed_puff else: encrypted_puff = ret else: encrypted_puff = signed_puff # Create gale connection c = pygale.GaleClient() if not DONT_SEND: c.connect() c.transmit_puff(encrypted_puff) print 'Message sent.' else: print `c.swizzle_puff(encrypted_puff)` print 'Message NOT sent.'