本文整理汇总了Python中pykolab.auth.Auth.list_domains方法的典型用法代码示例。如果您正苦于以下问题:Python Auth.list_domains方法的具体用法?Python Auth.list_domains怎么用?Python Auth.list_domains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pykolab.auth.Auth
的用法示例。
在下文中一共展示了Auth.list_domains方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execute
# 需要导入模块: from pykolab.auth import Auth [as 别名]
# 或者: from pykolab.auth.Auth import list_domains [as 别名]
def execute(*args, **kw):
"""
List deleted mailboxes
"""
try:
domain = conf.cli_args.pop(0)
except:
domain = utils.ask_question(_("Domain"))
imap = IMAP()
imap.connect()
auth = Auth()
auth.connect()
domains = auth.list_domains()
folders = []
for primary,secondaries in domains:
if not domain == primary and not domain in secondaries:
continue
folders.extend(imap.lm("user/%%@%s" % (primary)))
for secondary in secondaries:
folders.extend(imap.lm("user/%%@%s" % (secondary)))
print "Deleted folders:"
for folder in folders:
if not conf.raw:
print imap_utf7.decode(folder)
else:
print folder
示例2: execute
# 需要导入模块: from pykolab.auth import Auth [as 别名]
# 或者: from pykolab.auth.Auth import list_domains [as 别名]
def execute(*args, **kw):
"""
List deleted mailboxes
"""
imap = IMAP()
imap.connect()
auth = Auth()
auth.connect()
domains = auth.list_domains()
folders = []
for domain in list(set(domains.keys())):
folders.extend(imap.lm("DELETED/*@%s" % (domain)))
folders.extend(imap.lm("DELETED/*"))
print "Deleted folders:"
for folder in folders:
mbox_parts = imap.parse_mailfolder(folder)
if not conf.raw:
print "%s (Deleted at %s)" % (imap_utf7.decode(folder).encode('utf-8'), datetime.datetime.fromtimestamp(int(mbox_parts['hex_timestamp'], 16)))
else:
print "%s (Deleted at %s)" % (folder, datetime.datetime.fromtimestamp(int(mbox_parts['hex_timestamp'], 16)))
示例3: execute
# 需要导入模块: from pykolab.auth import Auth [as 别名]
# 或者: from pykolab.auth.Auth import list_domains [as 别名]
def execute(*args, **kw):
auth = Auth()
log.debug(_("Listing domains..."), level=5)
start_time = time.time()
domains = auth.list_domains()
end_time = time.time()
log.debug(
_("Found %d domains in %d seconds") % (
len(domains),
(end_time-start_time)
),
level=8
)
all_folders = []
for primary_domain,secondary_domains in domains:
log.debug(_("Running for domain %s") % (primary_domain), level=8)
auth.connect(primary_domain)
start_time = time.time()
auth.synchronize()
end_time = time.time()
log.info(_("Synchronizing users for %s took %d seconds")
% (primary_domain, (end_time-start_time))
)
示例4: execute
# 需要导入模块: from pykolab.auth import Auth [as 别名]
# 或者: from pykolab.auth.Auth import list_domains [as 别名]
def execute(*args, **kw):
global imap, pool
auth = Auth()
log.debug(_("Listing domains..."), level=5)
start_time = time.time()
domains = auth.list_domains()
end_time = time.time()
log.debug(
_("Found %d domains in %d seconds") % (
len(domains),
(end_time-start_time)
),
level=8
)
if version.StrictVersion(sys.version[:3]) >= version.StrictVersion("2.7"):
pool = multiprocessing.Pool(conf.threads, worker_process, (), 1)
else:
pool = multiprocessing.Pool(conf.threads, worker_process, ())
for primary_domain in list(set(domains.values())):
log.debug(_("Running for domain %s") % (primary_domain), level=8)
auth = Auth(primary_domain)
auth.connect(primary_domain)
start_time = time.time()
auth.synchronize(mode='_paged_search', callback=queue_add)
end_time = time.time()
log.info(_("Synchronizing users for %s took %d seconds")
% (primary_domain, (end_time-start_time))
)
while not pool._taskqueue.empty():
time.sleep(1)
示例5: do_sync
# 需要导入模块: from pykolab.auth import Auth [as 别名]
# 或者: from pykolab.auth.Auth import list_domains [as 别名]
def do_sync(self):
domain_auth = {}
pid = os.getpid()
primary_domain = conf.get('kolab', 'primary_domain')
while 1:
primary_auth = Auth(primary_domain)
log.debug(_("Listing domains..."), level=5)
start = time.time()
try:
domains = primary_auth.list_domains()
except:
time.sleep(60)
continue
# domains now is a list of tuples, we want the primary_domains
primary_domains = []
for primary_domain, secondary_domains in domains:
primary_domains.append(primary_domain)
# Now we can check if any changes happened.
added_domains = []
removed_domains = []
all_domains = set(primary_domains + domain_auth.keys())
for domain in all_domains:
if domain in domain_auth.keys() and domain in primary_domains:
if not domain_auth[domain].is_alive():
domain_auth[domain].terminate()
added_domains.append(domain)
else:
continue
elif domain in domain_auth.keys():
removed_domains.append(domain)
else:
added_domains.append(domain)
if len(removed_domains) == 0 and len(added_domains) == 0:
time.sleep(600)
log.debug(
_("added domains: %r, removed domains: %r") % (
added_domains,
removed_domains
),
level=8
)
for domain in added_domains:
domain_auth[domain] = Process(domain)
domain_auth[domain].start()
示例6: execute
# 需要导入模块: from pykolab.auth import Auth [as 别名]
# 或者: from pykolab.auth.Auth import list_domains [as 别名]
def execute(*args, **kw):
"""
Synchronize or display changes
"""
imap = IMAP()
if not conf.connect_server == None:
imap.connect(server=conf.connect_server)
else:
imap.connect()
auth = Auth()
auth.connect()
domains = auth.list_domains()
folders = imap.lm()
imap_domains_not_domains = []
for folder in folders:
if len(folder.split('@')) > 1 and not folder.startswith('DELETED'):
_folder_domain = folder.split('@')[-1]
if not _folder_domain in list(set(domains.keys() + domains.values())):
imap_domains_not_domains.append(folder.split('@')[-1])
imap_domains_not_domains = list(set(imap_domains_not_domains))
log.debug(_("Domains in IMAP not in LDAP: %r") % (imap_domains_not_domains), level=8)
if len(imap_domains_not_domains) > 0:
for domain in imap_domains_not_domains:
folders = []
folders.extend(imap.lm('shared/%%@%s' % (domain)))
folders.extend(imap.lm('user/%%@%s' % (domain)))
for folder in folders:
if conf.delete:
if conf.dry_run:
if not folder.split('/')[0] == 'shared':
log.warning(_("No recipients for '%s' (would have deleted the mailbox if not for --dry-run)!") % ('/'.join(folder.split('/')[1:])))
else:
continue
else:
if not '/'.join(folder.split('/')[0]) == 'shared':
log.info(_("Deleting mailbox '%s' because it has no recipients") % (folder))
try:
imap.dm(folder)
except Exception, errmsg:
log.error(_("An error occurred removing mailbox %r: %r") % (folder, errmsg))
else:
log.info(_("Not automatically deleting shared folder '%s'") % (folder))
else:
log.warning(_("No recipients for '%s' (use --delete to delete)!") % ('/'.join(folder.split('/')[1:])))
示例7: expand_mydomains
# 需要导入模块: from pykolab.auth import Auth [as 别名]
# 或者: from pykolab.auth.Auth import list_domains [as 别名]
def expand_mydomains():
"""
Return a list of my domains.
"""
auth = Auth()
auth.connect()
mydomains = []
_mydomains = auth.list_domains()
for primary, secondaries in _mydomains:
mydomains.append(primary)
for secondary in secondaries:
mydomains.append(secondary)
return mydomains
示例8: execute
# 需要导入模块: from pykolab.auth import Auth [as 别名]
# 或者: from pykolab.auth.Auth import list_domains [as 别名]
def execute(*args, **kw):
"""
List deleted mailboxes
"""
imap = IMAP()
imap.connect()
auth = Auth()
auth.connect()
domains = auth.list_domains()
folders = []
for domain in domains.keys():
print "%s: %d" % (domain,len(imap.lm("user/%%@%s" % (domain))))
null_realm = len(imap.lm("user/%%"))
if null_realm > 0:
print "null: %d" % (null_realm)
示例9: verify_domain
# 需要导入模块: from pykolab.auth import Auth [as 别名]
# 或者: from pykolab.auth.Auth import list_domains [as 别名]
def verify_domain(domain):
"""
Verify whether the domain is internal (mine) or external.
"""
auth = Auth()
auth.connect()
domain_verified = False
_mydomains = auth.list_domains()
for primary, secondaries in _mydomains:
if primary == domain:
domain_verified = True
elif domain in secondaries:
domain_verified = True
if domain_verified == None:
domain_verified = False
return domain_verified
示例10: resource_record_from_email_address
# 需要导入模块: from pykolab.auth import Auth [as 别名]
# 或者: from pykolab.auth.Auth import list_domains [as 别名]
def resource_record_from_email_address(email_address):
"""
Resolves the given email address to a resource entity
"""
global auth
if not auth:
auth = Auth()
auth.connect()
resource_records = []
local_domains = auth.list_domains()
if not local_domains == None:
local_domains = list(set(local_domains.keys()))
if not email_address.split('@')[1] in local_domains:
return []
log.debug(
_("Checking if email address %r belongs to a resource (collection)") % (email_address),
level=8
)
resource_records = auth.find_resource(email_address)
if isinstance(resource_records, list):
if len(resource_records) > 0:
log.debug(_("Resource record(s): %r") % (resource_records), level=8)
else:
log.debug(_("No resource (collection) records found for %r") % (email_address), level=9)
elif isinstance(resource_records, basestring):
resource_records = [ resource_records ]
log.debug(_("Resource record: %r") % (resource_records), level=8)
return resource_records
示例11: user_dn_from_email_address
# 需要导入模块: from pykolab.auth import Auth [as 别名]
# 或者: from pykolab.auth.Auth import list_domains [as 别名]
def user_dn_from_email_address(email_address):
"""
Resolves the given email address to a Kolab user entity
"""
global auth
if not auth:
auth = Auth()
auth.connect()
# return cached value
if user_dn_from_email_address.cache.has_key(email_address):
return user_dn_from_email_address.cache[email_address]
local_domains = auth.list_domains()
if not local_domains == None:
local_domains = list(set(local_domains.keys()))
if not email_address.split('@')[1] in local_domains:
user_dn_from_email_address.cache[email_address] = None
return None
log.debug(_("Checking if email address %r belongs to a local user") % (email_address), level=8)
user_dn = auth.find_user_dn(email_address, True)
if isinstance(user_dn, basestring):
log.debug(_("User DN: %r") % (user_dn), level=8)
else:
log.debug(_("No user record(s) found for %r") % (email_address), level=9)
# remember this lookup
user_dn_from_email_address.cache[email_address] = user_dn
return user_dn
示例12: do_sync
# 需要导入模块: from pykolab.auth import Auth [as 别名]
# 或者: from pykolab.auth.Auth import list_domains [as 别名]
def do_sync(self):
domain_auth = {}
pid = os.getpid()
primary_domain = conf.get('kolab', 'primary_domain')
while 1:
primary_auth = Auth(primary_domain)
connected = False
while not connected:
try:
primary_auth.connect()
connected = True
except Exception, errmsg:
connected = False
log.error(_("Could not connect to LDAP, is it running?"))
time.sleep(5)
log.debug(_("Listing domains..."), level=5)
start = time.time()
try:
domains = primary_auth.list_domains()
except:
time.sleep(60)
continue
if isinstance(domains, list) and len(domains) < 1:
log.error(_("No domains. Not syncing"))
time.sleep(5)
continue
# domains now is a list of tuples, we want the primary_domains
primary_domains = []
for primary_domain in list(set(domains.values())):
primary_domains.append(primary_domain)
# Now we can check if any changes happened.
added_domains = []
removed_domains = []
all_domains = set(primary_domains + domain_auth.keys())
for domain in all_domains:
if domain in domain_auth.keys() and domain in primary_domains:
if not domain_auth[domain].is_alive():
domain_auth[domain].terminate()
added_domains.append(domain)
else:
continue
elif domain in domain_auth.keys():
removed_domains.append(domain)
else:
added_domains.append(domain)
if len(removed_domains) == 0 and len(added_domains) == 0:
try:
sleep_between_domain_operations_in_seconds = (float)(conf.get('kolab', 'domain_sync_interval'))
time.sleep(sleep_between_domain_operations_in_seconds)
except ValueError:
time.sleep(600)
log.debug(
_("added domains: %r, removed domains: %r") % (
added_domains,
removed_domains
),
level=8
)
for domain in added_domains:
domain_auth[domain] = Process(domain)
domain_auth[domain].start()
# Pause or hammer your LDAP server to death
if len(added_domains) >= 5:
time.sleep(10)
for domain in removed_domains:
domain_auth[domain].terminate()
del domain_auth[domain]
示例13: execute
# 需要导入模块: from pykolab.auth import Auth [as 别名]
# 或者: from pykolab.auth.Auth import list_domains [as 别名]
def execute(*args, **kw):
try:
primary_rcpt_address = conf.cli_args.pop(0)
try:
secondary_rcpt_address = conf.cli_args.pop(0)
except:
print >> sys.stderr, _("Specify the (new) alias address")
sys.exit(1)
except:
print >> sys.stderr, _("Specify the existing recipient address")
sys.exit(1)
if len(primary_rcpt_address.split('@')) > 1:
primary_rcpt_domain = primary_rcpt_address.split('@')[-1]
else:
primary_rcpt_domain = conf.get('kolab', 'primary_domain')
auth = Auth(domain=primary_rcpt_domain)
domains = auth.list_domains()
#print domains
if len(secondary_rcpt_address.split('@')) > 1:
secondary_rcpt_domain = secondary_rcpt_address.split('@')[-1]
else:
secondary_rcpt_domain = conf.get('kolab', 'primary_domain')
# Check if either is in fact a domain
if not primary_rcpt_domain.lower() in domains.keys():
print >> sys.stderr, _("Domain %r is not a local domain") % (primary_rcpt_domain)
sys.exit(1)
if not secondary_rcpt_domain.lower() in domains.keys():
print >> sys.stderr, _("Domain %r is not a local domain") % (secondary_rcpt_domain)
sys.exit(1)
if not primary_rcpt_domain == secondary_rcpt_domain:
if not domains[primary_rcpt_domain] == domains[secondary_rcpt_domain]:
print >> sys.stderr, _("Primary and secondary domain do not have the same parent domain")
sys.exit(1)
primary_recipient_dn = auth.find_recipient(primary_rcpt_address)
if primary_recipient_dn == [] or len(primary_recipient_dn) == 0:
print >> sys.stderr, _("No such recipient %r") % (primary_rcpt_address)
sys.exit(1)
secondary_recipient_dn = auth.find_recipient(secondary_rcpt_address)
if not secondary_recipient_dn == [] and not len(secondary_recipient_dn) == 0:
print >> sys.stderr, _("Recipient for alias %r already exists") % (secondary_rcpt_address)
sys.exit(1)
rcpt_attrs = conf.get_list('ldap', 'mail_attributes')
primary_rcpt_attr = rcpt_attrs[0]
if len(rcpt_attrs) >= 2:
secondary_rcpt_attr = rcpt_attrs[1]
else:
print >> sys.stderr, _("Environment is not configured for " + \
"users to hold secondary mail attributes")
sys.exit(1)
primary_recipient = auth.get_entry_attributes(primary_rcpt_domain, primary_recipient_dn, rcpt_attrs)
if not primary_recipient.has_key(primary_rcpt_attr):
print >> sys.stderr, _("Recipient %r is not the primary recipient for address %r") % (primary_recipient, primary_rcpt_address)
sys.exit(1)
if not primary_recipient.has_key(secondary_rcpt_attr):
auth.set_entry_attributes(primary_rcpt_domain, primary_recipient_dn, {secondary_rcpt_attr: [ secondary_rcpt_address ] })
else:
if isinstance(primary_recipient[secondary_rcpt_attr], basestring):
new_secondary_rcpt_attrs = [
primary_recipient[secondary_rcpt_attr],
secondary_rcpt_address
]
else:
new_secondary_rcpt_attrs = \
primary_recipient[secondary_rcpt_attr] + \
[ secondary_rcpt_address ]
auth.set_entry_attributes(
primary_rcpt_domain,
primary_recipient_dn,
{
secondary_rcpt_attr: new_secondary_rcpt_attrs
}
)