def _save_config(config, req, log): """Try to save the config, and display either a success notice or a failure warning (code copied verbatim from Trac core). """ try: config.save() add_notice(req, _("Your changes have been saved.")) except Exception, e: log.error('Error writing to trac.ini: %s', exception_to_unicode(e)) add_warning(req, _("""Error writing to trac.ini, make sure it is writable by the web server. Your changes have not been saved."""))
def __init__(self): try: from gnupg import GPG except ImportError: raise TracError(_("""Unable to load the python-gnupg module. Please check and correct your installation.""")) try: # Initialize the GnuPG instance. path = os.path.join(os.path.abspath(self.env.path), self.gpg_home) self.env.log.debug('Using GnuPG home dir: ' + str(path)) self.gpg = GPG(gpgbinary=self.gpg_binary, gnupghome=path) except ValueError: raise TracError(_("""Missing the crypto binary. Please check and set full path with option 'gpg_binary'."""))
def _save_config(config, req, log): """Try to save the config, and display either a success notice or a failure warning (code copied verbatim from Trac core). """ try: config.save() add_notice(req, _("Your changes have been saved.")) except Exception, e: log.error('Error writing to trac.ini: %s', exception_to_unicode(e)) add_warning( req, _("""Error writing to trac.ini, make sure it is writable by the web server. Your changes have not been saved."""))
def __init__(self): try: from gnupg import GPG except ImportError: raise TracError( _("""Unable to load the python-gnupg module. Please check and correct your installation.""")) try: # Initialize the GnuPG instance. path = os.path.join(os.path.abspath(self.env.path), self.gpg_home) self.env.log.debug('Using GnuPG home dir: ' + str(path)) self.gpg = GPG(gpgbinary=self.gpg_binary, gnupghome=path) except ValueError: raise TracError( _("""Missing the crypto binary. Please check and set full path with option 'gpg_binary'."""))
def render_preference_panel(self, req, panel): if req.method == 'POST': new_content = req.args.get('replace_with_real_argname') if new_content: #req.session['replace_with_real_argname'] = new_content add_notice(req, _('Your content has been saved.')) req.redirect(req.href.prefs(panel or None)) data = { '_dgettext': dgettext # content = req.session.get('replace_with_real_argname', # 'your text') } return 'prefs_crypto.html', data
def render_admin_panel(self, req, cat, page, path_info): if req.method == 'POST': defaults = self.config.defaults().get('crypto') ## Read admin form values. # GnuPG settings gpg_binary = req.args.get('gpg_binary') gpg_home = req.args.get('gpg_home') priv_key = req.args.get('priv_key') # Key generation presets expire_date = req.args.get('expire_date') key_length = req.args.get('key_length') key_type = req.args.get('key_type') subkey_length = req.args.get('subkey_length') subkey_type = req.args.get('subkey_type') # Checkbox return value requires special parsing. allow_usermod = bool(req.args.get('allow_usermod')) # Overwrite deleted values with defaults. if not gpg_binary and defaults: gpg_binary = defaults['gpg_binary'] self.config.set('crypto', 'gpg_binary', gpg_binary) if not gpg_home and defaults: gpg_home = defaults['gpg_home'] self.config.set('crypto', 'gpg_home', gpg_home) if not priv_key and defaults: priv_key = defaults['private_key'] self.config.set('crypto', 'gpg_private_key', priv_key) self.config.set('crypto', 'gpg_keygen_allow_usermod', allow_usermod) if not expire_date and defaults: expire_date = defaults['gpg_keygen_expire_date'] self.config.set('crypto', 'gpg_keygen_expire_date', expire_date) if not key_length and defaults: key_length = defaults['gpg_keygen_key_length'] self.config.set('crypto', 'gpg_keygen_key_length', key_length) if not key_type and defaults: key_type = defaults['gpg_keygen_key_type'] self.config.set('crypto', 'gpg_keygen_key_type', key_type) if not subkey_length and defaults: subkey_length = defaults['gpg_keygen_subkey_length'] self.config.set('crypto', 'gpg_keygen_subkey_length', subkey_length) if not subkey_type and defaults: subkey_type = defaults['gpg_keygen_subkey_type'] self.config.set('crypto', 'gpg_keygen_subkey_type', subkey_type) # Save effective new configuration. _save_config(self.config, req, self.log) req.redirect(req.href.admin(cat, page)) # Get current configuration. gpg = { 'binary': self.config.get('crypto', 'gpg_binary'), 'home': self.config.get('crypto', 'gpg_home') } keygen = { 'allow_usermod': self.config.getbool('crypto', 'gpg_keygen_allow_usermod'), 'expire_date': self.config.get('crypto', 'gpg_keygen_expire_date'), 'key_length': self.config.getint('crypto', 'gpg_keygen_key_length'), 'key_type': self.config.get('crypto', 'gpg_keygen_key_type'), 'subkey_length': self.config.getint('crypto', 'gpg_keygen_subkey_length'), 'subkey_type': self.config.get('crypto', 'gpg_keygen_subkey_type') } now_ts = to_timestamp(datetime.now(utc)) priv_key = self.config.get('crypto', 'gpg_private_key') priv_keys = [dict(id='', label=_("(Select private key)"))] + [ dict(id=key['keyid'], label=' - '.join([key['keyid'], key.get('uids')[1]]), disabled=key.get('expires') and \ int(key.get('expires')) < now_ts, selected=key['keyid'] == priv_key) for key in CryptoBase(self.env).keys(private=True) ] data = { '_dgettext': dgettext, 'env_dir': os.path.abspath(self.env.path), 'gpg': gpg, 'keygen': keygen, 'priv_keys': priv_keys } add_stylesheet(req, 'crypto/crypto.css') return 'admin_crypto.html', data
def get_admin_panels(self, req): if req.perm.has_permission('CRYPTO_ADMIN'): yield ('crypto', _('Cryptography'), 'config', _('Configuration'))
def get_preference_panels(self, req): yield ('crypto', _('Cryptography'))