예제 #1
0
파일: views.py 프로젝트: r4is3/heimdall
def app_config(request):
    '''
	Application configurations view. Can save user configuration such as language and theme.
	Accessible by /admin/app-config
	'''
    args = utils.give_arguments(request.user, 'Users admin')

    if PendingThread.objects.filter(process='userhost-list-refresh').exists():
        thread = PendingThread.objects.get(process='userhost-list-refresh')
        messages.success(
            request, 'Server user host currently refreshing ' +
            str(thread.pending_request))

    admin_configs = [
        'theme', 'mail_server_hostname', 'mail_system_user_account',
        'user_notification', 'admin_notification', 'forbidden_users'
    ]

    for field in admin_configs:
        args.update({field: utils.getConfiguration(request.user, field)})

    args.update({'default_theme': utils.getConfigurationAdmin('theme')})
    if request.user.is_authenticated():
        return render_to_response('admin/app_config.html',
                                  args,
                                  context_instance=RequestContext(request))
    else:
        messages.success(request, 'You have not the rights to do this action')
    return HttpResponseRedirect(reverse('index'))
예제 #2
0
def app_config(request):
	'''
	Application configurations view. Can save user configuration such as language and theme.
	Accessible by /admin/app-config
	'''
	args = utils.give_arguments(request.user, 'Users admin')

	if PendingThread.objects.filter(process='userhost-list-refresh').exists():
		thread = PendingThread.objects.get(process='userhost-list-refresh')
		messages.success(request, 'Server user host currently refreshing ' + str(thread.pending_request))

	admin_configs = ['theme', 'mail_server_hostname', 'mail_system_user_account', 'user_notification', 'admin_notification', 'forbidden_users']

	for field in admin_configs:
		args.update({field: utils.getConfiguration(request.user, field)})

	args.update({'default_theme': utils.getConfigurationAdmin('theme')})
	if request.user.is_authenticated():
		return render_to_response('admin/app_config.html', args, context_instance=RequestContext(request))
	else:
		messages.success(request, 'You have not the rights to do this action')
	return HttpResponseRedirect(reverse('index'))
예제 #3
0
	def alertToAdmin(self, message, server, userEmail):
		'''Alert by email the admins and the user if configured'''
		# Create an html message
		msg = MIMEText(message, 'html')
		s = smtplib.SMTP(utils.getConfigurationAdmin('mail_server_hostname'))

		sender = utils.getConfigurationAdmin('mail_system_user_account')
		recipients = [utils.getConfigurationAdmin('mail_system_user_account')]
		msg['Subject'] = 'Heimdall permissions changed on %s' % server
		msg['From'] = sender

		if utils.getConfigurationAdmin('user_notification') == 'true':
			msg['To'] = userEmail
			recipients = [utils.getConfigurationAdmin('mail_system_user_account'), userEmail]
		else:
			msg['To'] = ", ".join(recipients)

		if utils.getConfigurationAdmin('admin_notification') == 'true' and not utils.getConfigurationAdmin('user_notification') == 'false':
			msg['Cc'] = ", ".join(recipients)

		s.sendmail(sender, recipients, msg.as_string())
		s.quit()