Esempio n. 1
0
 def post(self, request):
     form = tasks_forms.AddTaskForm(user=request.user, data=request.POST)
     user = TikedgeUser.objects.get(user=request.user)
     if form.is_valid():
         name_of_task = form.cleaned_data['to_do_item']
         start_time = form.cleaned_data['start_time']
         end_time = form.cleaned_data['end_time']
         new_project = form.cleaned_data['new_project']
         existing_project = request.POST.get('existing_project')
         tasks = Tasks(name_of_tasks=name_of_task, user=user)
         tasks.save()
         if start_time:
             if is_time_conflict(request.user, start_time, end_time):
                 msg = "Hey, one tasks at a time"
                 form.add_error('start_time', msg)
                 return render(
                     request, 'tasks/add_tasks.html', {
                         'form': form,
                         'existing_project': get_user_projects(request.user)
                     })
             tasks.start = start_time
             tasks.save()
             if end_time:
                 tasks.end = start_time + timedelta(minutes=int(end_time))
             else:
                 tasks.end = start_time + timedelta(minutes=60)
             tasks.is_active = True
             tasks.save()
             new_calender_event = CalendarEvent(title=name_of_task,
                                                start=start_time,
                                                end=tasks.end,
                                                css_class='event-info')
             new_calender_event.save()
             action.send(user,
                         verb='Created A to do list item: ',
                         target=tasks)
         if new_project:
             if not user.userproject_set.all().filter(
                     name_of_project=new_project):
                 project = UserProject(name_of_project=new_project,
                                       user=user)
                 project.save()
                 tasks.project = project
                 tasks.save()
         if existing_project:
             project = user.userproject_set.all().get(
                 name_of_project=existing_project)
             project.save()
             tasks.project = project
             tasks.save()
         return HttpResponseRedirect(reverse('tasks:home'))
     return render(request, 'tasks/add_tasks.html', {
         'form': form,
         'existing_project': get_user_projects(request.user)
     })
Esempio n. 2
0
def setup(request):
	if request.method == 'POST':
		if request.POST.get('action') == 'cleardb':
			job = tasks.cleardb.delay()
			try:
				task = Tasks.objects.get(Task='cleardb')
			except:
				task = Tasks()
				task.Task = 'cleardb'
			task.Task_Id = job.id
			task.Count = 0
			task.save()
			LogKrakenEvent(request.user, 'Database Cleared', 'info')
			return HttpResponse()
		elif request.POST.get('action') == 'removescreenshots':
			job = tasks.removescreenshots.delay()
			try:
				task = Tasks.objects.get(Task='removescreenshots')
			except:
				task = Tasks()
				task.Task = 'removescreenshots'
			task.Task_Id = job.id
			task.Count = 0
			task.save()
			LogKrakenEvent(request.user, 'Screenshots Deleted', 'info')
			return HttpResponse()
		elif request.POST.get('action') == 'parse':
			form = ParseForm(request.POST, request.FILES)
			if form.is_valid:
				with open('/opt/Kraken/tmp/nmap.xml', 'wb+') as destination:
					for chunk in request.FILES["parsefile"].chunks():
						destination.write(chunk)
				job = tasks.nmap_parse.delay('/opt/Kraken/tmp/nmap.xml')
				try:
					task = Tasks.objects.get(Task='parse')
				except:
					task = Tasks()
					task.Task = 'parse'
				task.Task_Id = job.id
				task.Count = 0
				task.save()
				form = ParseForm()
				addresses = Addresses.objects.all()
				return render(request, 'Web_Scout/setup.html', {'addresses':addresses, 'form':form, 'uploaded':False, 'failedupload':False})

			else:
				return render(request, 'Web_Scout/setup.html', {'form':form, 'uploaded':False, 'failedupload':True})
		elif request.POST.get('action') == 'screenshot':
			overwrite = request.POST.get('overwrite')
			ipPattern = re.compile("^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$")
			hostnamePattern = re.compile("^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)+([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$")
			proxy = ""
			proxyHost = request.POST.get("proxyhost", "")
			proxyPort = request.POST.get("proxyport", "")
			if proxyHost != "" and (ipPattern.match(proxyHost) or hostnamePattern.match(proxyHost)) and int(proxyPort) > 0 and int(proxyPort) < 65536:
				proxy = request.POST.get('proxyhost') + ":" + request.POST.get('proxyport')
			elif proxyHost:
				return HttpResponse(status=500)
			if overwrite == 'True':
				job = tasks.startscreenshot.delay(True, proxy)
			else:
				job = tasks.startscreenshot.delay(False, proxy)
			try:
				task = Tasks.objects.get(Task='screenshot')
			except:
				task = Tasks()
				task.Task = 'screenshot'
			task.Task_Id = job.id
			task.Count = 0
			task.save()
			LogKrakenEvent(request.user, 'Screenshot taking task initiated', 'info')
			return HttpResponse()
		elif request.POST.get('action') == 'addurl':
			raw_list = request.POST.get('address-textarea')
			address_data = AddUrl(raw_list)
			json_data = json.dumps(address_data)
			return HttpResponse(json_data, content_type='application/json')
		elif request.POST.get('action') == 'runmodules':
			job = tasks.runmodules.delay()
			try:
				task = Tasks.objects.get(Task='runmodules')
			except:
				task = Tasks()
				task.Task = 'runmodules'
			task.Task_Id = job.id
			task.Count = 0
			task.save()
			LogKrakenEvent(request.user, 'Running default credential checks.', 'info')
			return HttpResponse()
		elif request.POST.get('action') == 'scan':
			address_list = []
			error_message = []

			for key,value in request.POST.items():
				if str(value) == "on":
					try:
						address_object = Addresses.objects.get(AddressID=key)
						if address_object.Hostname:
							address_list.append(address_object.Hostname)
						else:
							address_list.append(address_object.Address + '/' + address_object.Cidr)
					except:
						error_message.append(key + ' not found in database.')
						continue

			job = tasks.scan.delay(address_list)

			try:
				task = Tasks.objects.get(Task='scan')
			except:
				task = Tasks()
				task.Task = 'scan'
			task.Task_Id = job.id
			task.Count = 0
			task.save()

			json_data = json.dumps(error_message)
			return HttpResponse(json_data, content_type='application/json')
		elif request.POST.get('action') == 'addaddress':
			raw_list = request.POST.get('address-textarea')
			print raw_list
			address_data = AddAddress(raw_list)
			json_data = json.dumps(address_data)
			return HttpResponse(json_data, content_type='application/json')
		elif request.POST.get('action') == 'addhostname':
			raw_list = request.POST.get('address-textarea')
			address_data = AddHostname(raw_list)
			json_data = json.dumps(address_data)
			return HttpResponse(json_data, content_type='application/json')
		elif request.POST.get('action') == 'delete':
			address_list = []
			for key,value in request.POST.items():
				if str(value) == "on":
					address_list.append(key)
			deleted_addresses = DeleteAddress(address_list)
			json_data = json.dumps(deleted_addresses)
			return HttpResponse(json_data, content_type='application/json')
		else:
			return HttpResponse("Failure.")
	else:
		form = ParseForm()
		addresses = Addresses.objects.all()
		return render(request, 'Web_Scout/setup.html', {'addresses':addresses, 'form':form, 'uploaded':False, 'failedupload':False})