本文整理汇总了Python中Mailman.Utils.sha_new方法的典型用法代码示例。如果您正苦于以下问题:Python Utils.sha_new方法的具体用法?Python Utils.sha_new怎么用?Python Utils.sha_new使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mailman.Utils
的用法示例。
在下文中一共展示了Utils.sha_new方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create
# 需要导入模块: from Mailman import Utils [as 别名]
# 或者: from Mailman.Utils import sha_new [as 别名]
def create(self, email):
if self.exists:
raise ListAlreadyExists
langs = [mm_cfg.DEFAULT_SERVER_LANGUAGE]
pw = Utils.MakeRandomPassword()
pw_hashed = Utils.sha_new(pw).hexdigest()
urlhost = mm_cfg.DEFAULT_URL_HOST
host_name = mm_cfg.DEFAULT_EMAIL_HOST
web_page_url = mm_cfg.DEFAULT_URL_PATTERN % urlhost
# TODO: Add some atomicity. We should roll back changes using
# a try/else if something (like MTA alias update) fails
# before the function terminates.
try:
oldmask = os.umask(002)
self.mlist.Create(self.name, email, pw_hashed, langs=langs,
emailhost=host_name, urlhost=urlhost)
self.mlist.preferred_language = langs[0]
# Reply-To set to list address
self.mlist.reply_goes_to_list = 2
self.mlist.reply_to_address = "%[email protected]%s" % (self.list, self.domain)
# Allow messages from [email protected]
self.mlist.acceptable_aliases = "%[email protected]%s\n" % (self.list, self.domain)
self.mlist.subject_prefix = "[%s] " % (self.list)
self.mlist.msg_footer = ""
self.mlist.subscribe_policy = 2 # Confirm and approve
self.mlist.max_message_size = 20480 # 20M
self.mlist.Save()
finally:
os.umask(oldmask)
self.mlist.Unlock()
if mm_cfg.MTA:
modname = 'Mailman.MTA.' + mm_cfg.MTA
__import__(modname)
sys.modules[modname].create(self.mlist)
siteowner = Utils.get_site_email(self.mlist.host_name, 'owner')
text = Utils.maketext(
'newlist.txt',
{'listname' : self.name,
'password' : pw,
'admin_url' : self.mlist.GetScriptURL('admin', absolute=1),
'listinfo_url': self.mlist.GetScriptURL('listinfo', absolute=1),
'requestaddr' : self.mlist.GetRequestEmail(),
'siteowner' : siteowner,
}, mlist=self.mlist)
msg = Message.UserNotification(email, siteowner, 'Your new mailing list: %s' % self.name,
text, self.mlist.preferred_language)
msg.send(self.mlist)
示例2: create_list
# 需要导入模块: from Mailman import Utils [as 别名]
# 或者: from Mailman.Utils import sha_new [as 别名]
def create_list(listname):
"""Create an email list.
**Method**: PUT
**URI**: /v3/<listname>
**Parameters**:
* `admin`: email of list admin
* `password`: list admin password
* `subscribe_policy`: 1) Confirm; 2) Approval; 3)Confirm and approval.
Default is Confirm (1)
* `archive_private`: 0) Public; 1) Private. Default is Public (0) """
admin = request.forms.get('admin')
password = request.forms.get('password')
subscribe_policy = request.forms.get('subscribe_policy', 1)
archive_private = request.forms.get('archive_private', 0)
try:
subscribe_policy = int(subscribe_policy)
archive_private = int(archive_private)
except ValueError:
return jsonify(ERRORS_CODE['InvalidParams'])
if subscribe_policy < 1 or subscribe_policy > 3:
subscribe_policy = 1
if archive_private < 0 or archive_private > 1:
archive_private = 0
result = jsonify(ERRORS_CODE['Ok'])
if password == '':
return jsonify(ERRORS_CODE['InvalidPassword'])
else:
password = Utils.sha_new(password).hexdigest()
mail_list = MailList.MailList()
try:
mail_list.Create(listname, admin, password)
mail_list.archive_private = archive_private
mail_list.subscribe_policy = subscribe_policy
mail_list.Save()
except (Errors.BadListNameError, AssertionError,
Errors.MMBadEmailError, Errors.MMListAlreadyExistsError), e:
result = jsonify(ERRORS_CODE[e.__class__.__name__])
示例3: process_form
# 需要导入模块: from Mailman import Utils [as 别名]
# 或者: from Mailman.Utils import sha_new [as 别名]
def process_form(mlist, doc, cgidata, lang):
listowner = mlist.GetOwnerEmail()
realname = mlist.real_name
results = []
# The email address being subscribed, required
email = cgidata.getvalue('email', '').strip()
if not email:
results.append(_('You must supply a valid email address.'))
fullname = cgidata.getvalue('fullname', '')
# Canonicalize the full name
fullname = Utils.canonstr(fullname, lang)
# Who was doing the subscribing?
remote = os.environ.get('HTTP_FORWARDED_FOR',
os.environ.get('HTTP_X_FORWARDED_FOR',
os.environ.get('REMOTE_ADDR',
'unidentified origin')))
# Are we checking the hidden data?
if mm_cfg.SUBSCRIBE_FORM_SECRET:
now = int(time.time())
# Try to accept a range in case of load balancers, etc. (LP: #1447445)
if remote.find('.') >= 0:
# ipv4 - drop last octet
remote1 = remote.rsplit('.', 1)[0]
else:
# ipv6 - drop last 16 (could end with :: in which case we just
# drop one : resulting in an invalid format, but it's only
# for our hash so it doesn't matter.
remote1 = remote.rsplit(':', 1)[0]
try:
ftime, fhash = cgidata.getvalue('sub_form_token', '').split(':')
then = int(ftime)
except ValueError:
ftime = fhash = ''
then = 0
token = Utils.sha_new(mm_cfg.SUBSCRIBE_FORM_SECRET +
ftime +
mlist.internal_name() +
remote1).hexdigest()
if ftime and now - then > mm_cfg.FORM_LIFETIME:
results.append(_('The form is too old. Please GET it again.'))
if ftime and now - then < mm_cfg.SUBSCRIBE_FORM_MIN_TIME:
results.append(
_('Please take a few seconds to fill out the form before submitting it.'))
if ftime and token != fhash:
results.append(
_("The hidden token didn't match. Did your IP change?"))
if not ftime:
results.append(
_('There was no hidden token in your submission or it was corrupted.'))
results.append(_('You must GET the form before submitting it.'))
# Was an attempt made to subscribe the list to itself?
if email == mlist.GetListEmail():
syslog('mischief', 'Attempt to self subscribe %s: %s', email, remote)
results.append(_('You may not subscribe a list to itself!'))
# If the user did not supply a password, generate one for him
password = cgidata.getvalue('pw', '').strip()
confirmed = cgidata.getvalue('pw-conf', '').strip()
if not password and not confirmed:
password = Utils.MakeRandomPassword()
elif not password or not confirmed:
results.append(_('If you supply a password, you must confirm it.'))
elif password <> confirmed:
results.append(_('Your passwords did not match.'))
# Get the digest option for the subscription.
digestflag = cgidata.getvalue('digest')
if digestflag:
try:
digest = int(digestflag)
except (TypeError, ValueError):
digest = 0
else:
digest = mlist.digest_is_default
# Sanity check based on list configuration. BAW: It's actually bogus that
# the page allows you to set the digest flag if you don't really get the
# choice. :/
if not mlist.digestable:
digest = 0
elif not mlist.nondigestable:
digest = 1
if results:
print_results(mlist, ERRORSEP.join(results), doc, lang)
return
# If this list has private rosters, we have to be careful about the
# message that gets printed, otherwise the subscription process can be
# used to mine for list members. It may be inefficient, but it's still
# possible, and that kind of defeats the purpose of private rosters.
# We'll use this string for all successful or unsuccessful subscription
# results.
if mlist.private_roster == 0:
# Public rosters
privacy_results = ''
else:
privacy_results = _("""\
#.........这里部分代码省略.........
示例4: ssha_password
# 需要导入模块: from Mailman import Utils [as 别名]
# 或者: from Mailman.Utils import sha_new [as 别名]
def ssha_password(password):
salt = os.urandom(SALT_LENGTH)
h = Utils.sha_new(password)
h.update(salt)
return '{SSHA}' + base64.b64encode(h.digest() + salt)
示例5: sha_password
# 需要导入模块: from Mailman import Utils [as 别名]
# 或者: from Mailman.Utils import sha_new [as 别名]
def sha_password(password):
h = Utils.sha_new(password)
return '{SHA}' + base64.b64encode(h.digest())
示例6: list_listinfo
# 需要导入模块: from Mailman import Utils [as 别名]
# 或者: from Mailman.Utils import sha_new [as 别名]
def list_listinfo(mlist, lang):
# Generate list specific listinfo
doc = HeadlessDocument()
doc.set_language(lang)
replacements = mlist.GetStandardReplacements(lang)
if not mlist.digestable or not mlist.nondigestable:
replacements['<mm-digest-radio-button>'] = ""
replacements['<mm-undigest-radio-button>'] = ""
replacements['<mm-digest-question-start>'] = '<!-- '
replacements['<mm-digest-question-end>'] = ' -->'
else:
replacements['<mm-digest-radio-button>'] = mlist.FormatDigestButton()
replacements['<mm-undigest-radio-button>'] = \
mlist.FormatUndigestButton()
replacements['<mm-digest-question-start>'] = ''
replacements['<mm-digest-question-end>'] = ''
replacements['<mm-plain-digests-button>'] = \
mlist.FormatPlainDigestsButton()
replacements['<mm-mime-digests-button>'] = mlist.FormatMimeDigestsButton()
replacements['<mm-subscribe-box>'] = mlist.FormatBox('email', size=30)
replacements['<mm-subscribe-button>'] = mlist.FormatButton(
'email-button', text=_('Subscribe'))
replacements['<mm-new-password-box>'] = mlist.FormatSecureBox('pw')
replacements['<mm-confirm-password>'] = mlist.FormatSecureBox('pw-conf')
replacements['<mm-subscribe-form-start>'] = mlist.FormatFormStart(
'subscribe')
if mm_cfg.SUBSCRIBE_FORM_SECRET:
now = str(int(time.time()))
remote = os.environ.get('REMOTE_HOST',
os.environ.get('REMOTE_ADDR',
'w.x.y.z'))
# Try to accept a range in case of load balancers, etc. (LP: #1447445)
if remote.find('.') >= 0:
# ipv4 - drop last octet
remote = remote.rsplit('.', 1)[0]
else:
# ipv6 - drop last 16 (could end with :: in which case we just
# drop one : resulting in an invalid format, but it's only
# for our hash so it doesn't matter.
remote = remote.rsplit(':', 1)[0]
replacements['<mm-subscribe-form-start>'] += (
'<input type="hidden" name="sub_form_token" value="%s:%s">\n'
% (now, Utils.sha_new(mm_cfg.SUBSCRIBE_FORM_SECRET +
now +
mlist.internal_name() +
remote
).hexdigest()
)
)
# Roster form substitutions
replacements['<mm-roster-form-start>'] = mlist.FormatFormStart('roster')
replacements['<mm-roster-option>'] = mlist.FormatRosterOptionForUser(lang)
# Options form substitutions
replacements['<mm-options-form-start>'] = mlist.FormatFormStart('options')
replacements['<mm-editing-options>'] = mlist.FormatEditingOption(lang)
replacements['<mm-info-button>'] = SubmitButton('UserOptions',
_('Edit Options')).Format()
# If only one language is enabled for this mailing list, omit the choice
# buttons.
if len(mlist.GetAvailableLanguages()) == 1:
displang = ''
else:
displang = mlist.FormatButton('displang-button',
text = _("View this page in"))
replacements['<mm-displang-box>'] = displang
replacements['<mm-lang-form-start>'] = mlist.FormatFormStart('listinfo')
replacements['<mm-fullname-box>'] = mlist.FormatBox('fullname', size=30)
# Do the expansion.
doc.AddItem(mlist.ParseTags('listinfo.html', replacements, lang))
print doc.Format()