<commit_before>#!/usr/bin/python

#test with below
#	curl --data "{\"token\":\"<KEY> <KEY>\",\"kpTrigger\":3}" http://aurora.cs.uaf.edu/push_notification

import base64
import BaseHTTPServer
import datetime
import json
import SimpleHTTPServer
import ssl

def validate_kp(kp):
	try:
		kp=int(kp)
	except:
		raise Exception("Not an integer.")
	if kp<0 or kp>9:
		raise Exception("Invalid KP value.")
	return int(kp)

class aurora_handler(BaseHTTPServer.BaseHTTPRequestHandler):
	def do_POST(self):
		return_code=200
		try:
			self.log()
			data_size=int(self.headers.getheader("content-length",0))
			data=self.rfile.read(data_size)
			print("    Data:       "+data)
			json_obj=json.loads(data)
			token=base64.b64encode(json_obj["token"])
			kp_trigger=validate_kp(json_obj["kpTrigger"])
			salt=base64.b64encode(self.headers.getheader("user-agent"))
			print("    token:      "+token)
			print("    kpTrigger:  "+str(kp_trigger))
			print("    salt:       "+salt)
		except Exception as error:
			print("    Error:      "+str(error))
			return_code=400
		try:
			print("    Sending:    "+str(return_code))
			self.end_headers()
			self.send_response(return_code)
		except Exception as error:<commit_msg>Server now accepts a service type \(gcm or apns\).<commit_after>#!/usr/bin/python

#test with below
#	curl --data "{\"token\":\"<KEY>:<KEY>\",\"kpTrigger\":3}" http://aurora.cs.uaf.edu/push_notification

import base64
import BaseHTTPServer
import datetime
import json
import SimpleHTTPServer
import ssl

def validate_service(service):
	if service=="gcm" or service=="apns":
		return service
	else:
		raise Exception("Invalid service\""+service+"\".")

def validate_kp(kp):
	error=False
	kp_int=-1

	try:
		kp_int=int(kp)
	except:
		error=True

	if not error and (kp_int<0 or kp_int>9):
		error=True

	if error:
		raise Exception("Invalid KP value \""+str(kp)+"\".")

	return kp_int

class aurora_handler(BaseHTTPServer.BaseHTTPRequestHandler):
	def do_POST(self):
		return_code=200
		try:
			self.log()
			data_size=int(self.headers.getheader("content-length",0))
			data=self.rfile.read(data_size)
			print("    Data:       "+data)
			json_obj=json.loads(data)
			service=validate_service(json_obj["service"])
			token=base64.b64encode(json_obj["token"])
			kp_trigger=validate_kp(json_obj["kpTrigger"])
			salt=base64.b64encode(self.headers.getheader("user-agent"))
			print("    service:    "+service)
			print("    token:      "+token)
			print("    kpTrigger:  "+str(kp_trigger))
			print("    salt:       "+salt)
		except Exception as error:
			print("    Error:      "+str(error))
			return_code=400
		try:
			print("    Sending:    "+str(return_code))
			self.end_headers()
			self.send_response(return_code)
		except Exception as error:
{'fraction_non_alphanumeric': 0.1477438136826783, 'fraction_numerical': 0.014919941775836972, 'mean_word_length': 4.147940074906367, 'pattern_counts': {'":': 5, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7196306', 'n_tokens_mistral': 1103, 'n_tokens_neox': 967, 'n_words': 194}