Changeset View
Changeset View
Standalone View
Standalone View
bin/kolab_smtp_access_policy.py
Show First 20 Lines • Show All 1,213 Lines • ▼ Show 20 Lines | def cache_init(): | ||||
else: | else: | ||||
return False | return False | ||||
if conf.debuglevel > 8: | if conf.debuglevel > 8: | ||||
engine = create_engine(cache_uri, echo=True) | engine = create_engine(cache_uri, echo=True) | ||||
else: | else: | ||||
engine = create_engine(cache_uri, echo=False) | engine = create_engine(cache_uri, echo=False) | ||||
if conf.drop_tables: | |||||
log.info(_("Dropping caching tables from database")) | |||||
policy_result_table.drop(engine, checkfirst=True) | |||||
statistic_table.drop(engine, checkfirst=True) | |||||
return False | |||||
try: | try: | ||||
metadata.create_all(engine) | metadata.create_all(engine) | ||||
except sqlalchemy.exc.OperationalError, e: | except sqlalchemy.exc.OperationalError, e: | ||||
log.error(_("Operational Error in caching: %s" % (e))) | log.error(_("Operational Error in caching: %s" % (e))) | ||||
return False | return False | ||||
Session = sessionmaker(bind=engine) | Session = sessionmaker(bind=engine) | ||||
session = Session() | session = Session() | ||||
▲ Show 20 Lines • Show All 359 Lines • ▼ Show 20 Lines | def verify_domain(domain): | ||||
return domain_verified | return domain_verified | ||||
if __name__ == "__main__": | if __name__ == "__main__": | ||||
access_policy_group = conf.add_cli_parser_option_group( | access_policy_group = conf.add_cli_parser_option_group( | ||||
_("Access Policy Options") | _("Access Policy Options") | ||||
) | ) | ||||
access_policy_group.add_option( "--drop-tables", | |||||
dest = "drop_tables", | |||||
action = "store_true", | |||||
default = False, | |||||
help = _("Drop the caching tables from the " + \ | |||||
"database and exit.")) | |||||
access_policy_group.add_option( "--timeout", | access_policy_group.add_option( "--timeout", | ||||
dest = "timeout", | dest = "timeout", | ||||
action = "store", | action = "store", | ||||
default = 10, | default = 10, | ||||
help = _("SMTP Policy request timeout.")) | help = _("SMTP Policy request timeout.")) | ||||
access_policy_group.add_option( "--verify-recipient", | access_policy_group.add_option( "--verify-recipient", | ||||
dest = "verify_recipient", | dest = "verify_recipient", | ||||
Show All 16 Lines | if __name__ == "__main__": | ||||
conf.finalize_conf() | conf.finalize_conf() | ||||
auth = Auth() | auth = Auth() | ||||
cache = cache_init() | cache = cache_init() | ||||
policy_requests = {} | policy_requests = {} | ||||
if conf.drop_tables: | |||||
sys.exit(0) | |||||
# Start the work | # Start the work | ||||
while True: | while True: | ||||
policy_request = read_request_input() | policy_request = read_request_input() | ||||
instance = policy_request['instance'] | instance = policy_request['instance'] | ||||
log.debug(_("Got request instance %s") % (instance)) | log.debug(_("Got request instance %s") % (instance)) | ||||
if policy_requests.has_key(instance): | if policy_requests.has_key(instance): | ||||
policy_requests[instance].add_request(policy_request) | policy_requests[instance].add_request(policy_request) | ||||
else: | else: | ||||
▲ Show 20 Lines • Show All 46 Lines • Show Last 20 Lines |