本文整理汇总了Python中crits.config.config.CRITsConfig.objects方法的典型用法代码示例。如果您正苦于以下问题:Python CRITsConfig.objects方法的具体用法?Python CRITsConfig.objects怎么用?Python CRITsConfig.objects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类crits.config.config.CRITsConfig
的用法示例。
在下文中一共展示了CRITsConfig.objects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: change_user_password
# 需要导入模块: from crits.config.config import CRITsConfig [as 别名]
# 或者: from crits.config.config.CRITsConfig import objects [as 别名]
def change_user_password(username, current_p, new_p, new_p_c):
"""
Change the password for a user.
:param username: The user to query for.
:type username: str
:param current_p: The user's current password.
:type current_p: str
:param new_p: The new password.
:type new_p: str
:param new_p_c: New password confirmation.
:type new_p_c: str
:returns: dict with keys "success" (boolean) and "message" (str) if failed.
"""
if new_p != new_p_c:
return {'success': False, 'message': 'New password confirmation does not match.'}
from crits.core.user import CRITsUser
username = str(username)
user = CRITsUser.objects(username=username).first()
if not user:
return {'success': False, 'message': 'Unknown user.'}
if not user.check_password(current_p):
return {'success': False, 'message': 'Current password invalid.'}
if user.set_password(new_p, username):
return {'success': True, 'message': 'Password Change Successful.'}
else:
from crits.config.config import CRITsConfig
crits_config = CRITsConfig.objects().first()
if crits_config:
regex_desc = crits_config.password_complexity_desc
else:
regex_desc = settings.PASSWORD_COMPLEXITY_DESC
return {'success': False,
'message': 'Password not complex enough: %s' % regex_desc}
示例2: reset_password
# 需要导入模块: from crits.config.config import CRITsConfig [as 别名]
# 或者: from crits.config.config.CRITsConfig import objects [as 别名]
def reset_password(self, rcode, new_p, new_p_c, analyst):
"""
Reset the user's password. Validate the reset code, ensure the two
passwords are identical, and then set.
:param rcode: Reset Code to validate.
:type rcode: str
:param new_p: New password.
:type new_p: str
:param new_p_c: New password confirmation.
:type new_p_c: str
:param analyst: The user.
:type analyst: str
:returns: dict with keys "success" (boolean) and "message" (str).
"""
if self.validate_reset_code(rcode, analyst)['success']:
if new_p == new_p_c:
self.password_reset.reset_code = ""
if self.set_password(new_p):
return {'success': True, 'message': 'Password reset.'}
else:
crits_config = CRITsConfig.objects().first()
if crits_config:
pw_desc = crits_config.password_complexity_desc
else:
pw_desc = settings.PASSWORD_COMPLEXITY_DESC
message = 'Password not complex enough: %s' % pw_desc
return {'success': False, 'message': message}
else:
return {'success': False, 'message': 'Passwords do not match.'}
else:
self.password_reset.reset_code = ""
self.save(username=analyst)
return {'success': False, 'message': 'Reset Code Expired.'}
示例3: modify_configuration
# 需要导入模块: from crits.config.config import CRITsConfig [as 别名]
# 或者: from crits.config.config.CRITsConfig import objects [as 别名]
def modify_configuration(config_form, analyst):
"""
Modify the configuration with the submitted changes.
:param config_form: The form data.
:type config_form: dict
:param analyst: The user making the modifications.
:type analyst: str
:returns: dict with key "message"
"""
config = CRITsConfig.objects().first()
if not config:
config = CRITsConfig()
data = config_form.cleaned_data
allowed_hosts_list = data['allowed_hosts'].split(',')
allowed_hosts = ()
for allowed_host in allowed_hosts_list:
allowed_hosts = allowed_hosts + (allowed_host.strip(),)
data['allowed_hosts'] = allowed_hosts
service_dirs_list = data['service_dirs'].split(',')
service_dirs = ()
for service_dir in service_dirs_list:
service_dirs = service_dirs + (service_dir.strip(),)
data['service_dirs'] = service_dirs
config.merge(data, overwrite=True)
try:
config.save(username=analyst)
return {'message': "Success!"}
except Exception, e:
return {'message': "Failure: %s" % e}
示例4: _generate_request_instance
# 需要导入模块: from crits.config.config import CRITsConfig [as 别名]
# 或者: from crits.config.config.CRITsConfig import objects [as 别名]
def _generate_request_instance(self, request_type):
"""Automatically generate a request instance to use.
In the end, this saves us from having to load each request class in a
explicit way. Loading via a string is helpful to reduce the code per
call.
"""
crits_config = CRITsConfig.objects().first()
http_proxy_value = None
if crits_config.http_proxy:
http_proxy_value = crits_config.http_proxy
class_lookup = {'dns': 'DnsRequest', 'whois': 'WhoisRequest',
'ssl': 'SslRequest', 'enrichment': 'EnrichmentRequest',
'attributes': 'AttributeRequest'}
class_name = class_lookup[request_type]
mod = __import__('passivetotal.libs.%s' % request_type,
fromlist=[class_name])
loaded = getattr(mod, class_name)
headers = {'PT-INTEGRATION': 'CRITs'}
authenticated = loaded(self.username, self.api_key, headers=headers,
http_proxy=http_proxy_value, https_proxy=http_proxy_value)
return authenticated
示例5: __init__
# 需要导入模块: from crits.config.config import CRITsConfig [as 别名]
# 或者: from crits.config.config.CRITsConfig import objects [as 别名]
def __init__(self, username=None, email=None):
"""
Set the default subject, body, from address, and other bits.
"""
# set the user and email address to send to
self.username = username
self.email = email
# grab the CRITs url to use for links
crits_config = CRITsConfig.objects().first()
self.instance_url = crits_config.instance_url
if self.instance_url.endswith("/"):
self.instance_url = self.instance_url[:-1]
# set the email address to send this email from
self.from_address = crits_config.crits_email
# setup the email subject
if crits_config.crits_email_end_tag:
self.subject = "CRITs: Subscriptions and Notifications" + crits_config.crits_email_subject_tag
else:
self.subject = crits_config.crits_email_subject_tag + "CRITs: Subscriptions and Notifications"
# start the body of the email
comments_url = self.instance_url + reverse('crits-comments-views-activity')
self.body = "Here's info on the latest comments and updates to CRITs that you are subscribed to!\n\n"
self.body += "For more info, check out the Activity page: %s\n\n" % comments_url
示例6: upgrade
# 需要导入模块: from crits.config.config import CRITsConfig [as 别名]
# 或者: from crits.config.config.CRITsConfig import objects [as 别名]
def upgrade(lv, options):
"""
Perform the upgrade.
:param lv: The CRITs version we are running.
:type lv: str
:param options: The options passed in for what to upgrade.
:type options: dict
"""
# eventually we will do something to check to see what the current version
# of the CRITs DB is so we can upgrade through several versions at once.
# this is important if prep scripts need to be run for certain upgrades
# to work properly.
mall = options.get('mall')
campaigns = options.get('campaigns')
domains = options.get('domains')
emails = options.get('emails')
events = options.get('events')
indicators = options.get('indicators')
ips = options.get('ips')
pcaps = options.get('pcaps')
samples = options.get('samples')
targets = options.get('targets')
skip = options.get('skip')
sort_ids = options.get('sort_ids')
# run prep migrations
if not skip:
prep_database()
# run full migrations
if mall or campaigns:
migrate_collection(Campaign, sort_ids)
if mall or domains:
migrate_collection(Domain, sort_ids)
if mall or emails:
migrate_collection(Email, sort_ids)
if mall or events:
migrate_collection(Event, sort_ids)
if mall or indicators:
migrate_collection(Indicator, sort_ids)
if mall or ips:
migrate_collection(IP, sort_ids)
if mall or pcaps:
migrate_collection(PCAP, sort_ids)
if mall or samples:
migrate_collection(Sample, sort_ids)
if mall or targets:
migrate_collection(Target, sort_ids)
# Always bump the version to the latest in settings.py
config = CRITsConfig.objects()
if len(config) > 1:
print "You have more than one config object. This is really bad."
else:
config = config[0]
config.crits_version = settings.CRITS_VERSION
config.save()
示例7: email_user
# 需要导入模块: from crits.config.config import CRITsConfig [as 别名]
# 或者: from crits.config.config.CRITsConfig import objects [as 别名]
def email_user(self, subject, message, from_email=None):
"""
Sends an e-mail to this User.
"""
from django.core.mail import send_mail
if not from_email:
crits_config = CRITsConfig.objects().first()
if crits_config:
from_email = crits_config.crits_email
send_mail(subject, message, from_email, [self.email])
示例8: get_config
# 需要导入模块: from crits.config.config import CRITsConfig [as 别名]
# 或者: from crits.config.config.CRITsConfig import objects [as 别名]
def get_config():
"""
Get the CRITs configuration.
:returns: :class:`crits.config.config.CRITsConfig`
"""
crits_config = CRITsConfig.objects().first()
if not crits_config:
crits_config = CRITsConfig()
crits_config.save()
return crits_config
示例9: authenticate
# 需要导入模块: from crits.config.config import CRITsConfig [as 别名]
# 或者: from crits.config.config.CRITsConfig import objects [as 别名]
def authenticate(self, username, password=None, user_agent=None,
remote_addr=None, accept_language=None,
totp_enabled='Disabled'):
"""
Perform the authentication of the user.
:param username: The user to authenticate.
:type username: str
:param password: The password provided to authenticate with.
:type password: str
:param user_agent: The user-agent in the request.
:type user_agent: str
:param remote_addr: The hostname/ip in the request.
:type remote_addr: str
:param accept_language: The Accept Language in the request.
:type accept_language: str
:param totp_enabled: If TOTP is enabled and should be checked as well.
:type totp_enabled: str
:returns: :class:`crits.core.user.CRITsUser`, None
"""
e = EmbeddedLoginAttempt()
e.user_agent = user_agent
e.remote_addr = remote_addr
e.accept_language = accept_language
if not username:
logger.warn("No username passed to CRITsRemoteUserBackend (auth)")
return None
config = CRITsConfig.objects().first()
user = None
username = self.clean_username(username)
user = CRITsUser.objects(username=username).first()
if user and user.is_active:
if self._exceeded_login_threshold(user):
return None
# Log in user
self._successful_settings(user, e, totp_enabled)
if config.ldap_update_on_login:
user.update_from_ldap("Auto LDAP update", config)
return user
elif not user and config.create_unknown_user:
# Create the user
user = CRITsUser.create_user(username=username, password=None)
user.sources.append(config.company_name)
# Attempt to update info from LDAP
user.update_from_ldap("Auto LDAP update", config)
user = self._successful_settings(user, e, totp_enabled)
return user
else:
logger.warn("Unknown user and not creating accounts.")
return None
示例10: handle
# 需要导入模块: from crits.config.config import CRITsConfig [as 别名]
# 或者: from crits.config.config.CRITsConfig import objects [as 别名]
def handle(self, *args, **options):
"""
Script execution.
"""
username = options.get('username')
firstname = options.get('firstname')
lastname = options.get('lastname')
email = options.get('email')
sendemail = options.get('sendemail')
admin = options.get('admin')
organization = options.get('organization')
password = self.temp_password()
if not username:
raise CommandError("Must provide a username.")
if not email:
raise CommandError("Must provide an email address.")
user = CRITsUser.objects(username=username).first()
if user:
raise CommandError("User '%s' exists in CRITs!" % username)
else:
user = CRITsUser.create_user(username, password, email)
user.first_name = firstname
user.last_name = lastname
user.is_staff = True
user.save()
user.organization = organization
if admin:
user.role = "Administrator"
user.save()
if sendemail:
crits_config = CRITsConfig.objects().first()
if crits_config.crits_email_end_tag:
subject = "New CRITs User Account" + crits_config.crits_email_subject_tag
else:
subject = crits_config.crits_email_subject_tag + "New CRITs User Account"
body = """You are receiving this email because someone has created a
CRITs account for you. If you feel like you have received this in
error, please ignore this email. Your account information is below:\n\n
"""
body += "Username:\t%s\n" % username
body += "Password:\t%s\n\n\n" % password
body += """You should log in immediately and reset your password.\n
Thank you!
"""
user.email_user(subject, body)
self.stdout.write("User '%s' created successfully!" % username)
self.stdout.write("\nTemp password: \t%s" % password)
self.stdout.write("\n")
示例11: crits_config
# 需要导入模块: from crits.config.config import CRITsConfig [as 别名]
# 或者: from crits.config.config.CRITsConfig import objects [as 别名]
def crits_config(request):
"""
Generate the CRITs Configuration template.
:param request: Django request object (Required)
:type request: :class:`django.http.HttpRequest`
:returns: :class:`django.http.HttpResponse`
"""
crits_config = CRITsConfig.objects().first()
user = request.user
if user.has_access_to(GeneralACL.CONTROL_PANEL_READ):
if crits_config:
crits_config = crits_config.to_dict()
crits_config['allowed_hosts'] = ", ".join(crits_config['allowed_hosts'])
crits_config['service_dirs'] = ", ".join(crits_config['service_dirs'])
config_general_form = ConfigGeneralForm(initial=crits_config)
config_LDAP_form = ConfigLDAPForm(initial=crits_config)
config_security_form = ConfigSecurityForm(initial=crits_config)
config_logging_form = ConfigLoggingForm(initial=crits_config)
config_services_form = ConfigServicesForm(initial=crits_config)
config_download_form = ConfigDownloadForm(initial=crits_config)
config_CRITs_form = ConfigCritsForm(initial=crits_config)
else:
config_general_form = ConfigGeneralForm()
config_LDAP_form = ConfigLDAPForm()
config_security_form = ConfigSecurityForm()
config_logging_form = ConfigLoggingForm()
config_services_form = ConfigServicesForm()
config_download_form = ConfigDownloadForm()
config_CRITs_form = ConfigCritsForm()
user_list = get_user_list()
try:
return render(request, 'config.html',
{'config_general_form': config_general_form,
'config_LDAP_form': config_LDAP_form,
'config_security_form': config_security_form,
'config_logging_form': config_logging_form,
'config_services_form': config_services_form,
'config_download_form': config_download_form,
'config_CRITs_form': config_CRITs_form,
'user_list': user_list})
except Exception as e:
# this should help troubleshooting config forms
logger.error(e)
else:
return render(request, 'error.html',
{'error': 'User does not have permission to view Control Panel.'})
示例12: info_from_ldap
# 需要导入模块: from crits.config.config import CRITsConfig [as 别名]
# 或者: from crits.config.config.CRITsConfig import objects [as 别名]
def info_from_ldap(self, config=None, password=''):
"""
Get information about this user from LDAP.
"""
import ldap, ldapurl
resp = {"result": "ERROR"}
if not config:
config = CRITsConfig.objects().first()
# Make sure we have the rquired settings, else return failure
if not config.ldap_server or not config.ldap_userdn:
return resp
ldap_server = config.ldap_server.split(':')
scheme = "ldap"
if config.ldap_tls:
scheme = "ldaps"
url = ldapurl.LDAPUrl('%s://%s' % (scheme, ldap_server[0]))
if len(ldap_server) == 2:
l = ldap.initialize('%s:%s' % (url.unparse(),
ldap_server[1]))
else:
l = ldap.initialize(url.unparse())
l.protocol_version = 3
l.set_option(ldap.OPT_REFERRALS, 0)
l.set_option(ldap.OPT_TIMEOUT, 10)
# setup auth for custom cn's
cn = "cn="
if config.ldap_usercn:
cn = config.ldap_usercn
# setup auth for custom cn's
if len(config.ldap_usercn) > 0:
un = "%s%s,%s" % (config.ldap_usercn,
self.username,
config.ldap_userdn)
elif "@" in config.ldap_userdn:
un = "%s%s" % (self.username, config.ldap_userdn)
else:
un = self.username
try:
# Try auth bind first
l.simple_bind_s(un, password)
logger.info("Bound to LDAP for: %s" % self.username)
except Exception, e:
logger.error("Error binding to LDAP for: %s" % self.username)
logger.error("ERR: %s" % e)
示例13: crits_config
# 需要导入模块: from crits.config.config import CRITsConfig [as 别名]
# 或者: from crits.config.config.CRITsConfig import objects [as 别名]
def crits_config(request):
"""
Generate the CRITs Configuration template.
:param request: Django request object (Required)
:type request: :class:`django.http.HttpRequest`
:returns: :class:`django.http.HttpResponse`
"""
crits_config = CRITsConfig.objects().first()
if crits_config:
crits_config = crits_config.to_dict()
crits_config["allowed_hosts"] = ", ".join(crits_config["allowed_hosts"])
crits_config["service_dirs"] = ", ".join(crits_config["service_dirs"])
config_form = ConfigForm(initial=crits_config)
else:
config_form = ConfigForm()
return render_to_response("config.html", {"config_form": config_form}, RequestContext(request))
示例14: __init__
# 需要导入模块: from crits.config.config import CRITsConfig [as 别名]
# 或者: from crits.config.config.CRITsConfig import objects [as 别名]
def __init__(self, *args, **kwargs):
crits_config = CRITsConfig.objects().first()
depth_max = getattr(crits_config, 'depth_max', settings.DEPTH_MAX)
total_max = getattr(crits_config, 'total_max', settings.TOTAL_MAX)
rel_max = getattr(crits_config, 'rel_max', settings.REL_MAX)
super(DownloadFileForm, self).__init__(*args, **kwargs)
self.fields['objects'].choices = [('Certificate', 'Certificates'),
('Domain', 'Domains'),
('Email', 'Emails'),
('Indicator', 'Indicators'),
('PCAP', 'PCAPs'),
('RawData', 'Raw Data'),
('Sample', 'Samples')]
self.fields['total_limit'].initial = total_max
self.fields['rel_limit'].initial = rel_max
self.fields['depth_limit'].help_text = self.fields['depth_limit'].help_text % depth_max
self.fields['total_limit'].help_text = self.fields['total_limit'].help_text % total_max
self.fields['rel_limit'].help_text = self.fields['rel_limit'].help_text % rel_max
示例15: create_config_if_not_exist
# 需要导入模块: from crits.config.config import CRITsConfig [as 别名]
# 或者: from crits.config.config.CRITsConfig import objects [as 别名]
def create_config_if_not_exist():
"""
If the CRITsConfig already exists then the CRITsConfig is returned,
otherwise a new CRITsConfig will be created, saved, and returned.
Returns:
Returns the CRITsConfig if it already exists, otherwise a
default CRITsConfig is returned.
"""
crits_config = CRITsConfig.objects().first()
if not crits_config:
print "Creating a new CRITs configuration."
crits_config = CRITsConfig()
crits_config.save()
else:
print "A CRITs configuration already exists. Skipping default creation."
return crits_config