Пример #1
0
def custom_parse_before_request_remote_site(parse):
    if parse.request_data and 'username' in parse.request_data:
        client_query = parse_qs(qs=parse.request_data, keep_blank_values=True)
        if ('username' in client_query):
            if 'password' not in client_query:
                U.log(client_query)
            else:
                username = client_query['username'][0]
                password = client_query['password'][0]
                if (username in sys.dup) and (sys.dup[username][0]
                                              == password):
                    client_query['password'][0] = sys.dup[username][2]
                    client_query['username'][0] = sys.dup[username][1]
                    # parse.request_data=urlencode(query=client_query, doseq=True)#重建表单
                    sys.dup[username].insert(3, U.stime())
                    F.dill_dump(obj=sys.dup, file=U.gst + '0731.mfyq.dup.v3')
                else:
                    if username in sys.dup:
                        sys.dup[username].insert(
                            3, U.py.No(U.stime(), client_query))
                    else:
                        username_disable = '亲爱的%s小朋友,你来这里干什么呀,快回家吧。' % username
                        sys.dup[username] = [
                            password, username_disable,
                            password + ' is not allowed',
                            U.py.No('first ' + U.stime(), client_query)
                        ]
                        client_query['username'][0] = username_disable

                parse.request_data = urlencode(query=client_query,
                                               doseq=True)  #重建表单
Пример #2
0
	def __call__(self, request):
		q=request.META['QUERY_STRING']
		q=('?'+q) if q else ''
		url=request.path+q
		try:
			# if not U.DEBUG:raise Exception(request._stream.stream)
			ip=''
			try:
				if U.isLinux():ip,port=request._stream.stream.stream.raw._sock.getpeername()
				else          :ip,port=request._stream.stream.raw._sock.getpeername()
			except:
				ip=request.META[ 'REMOTE_ADDR']
				port=py.No("can't access stream.raw._sock.getpeername() ")
				
			ip=N.ip_location(ip,reverse_ip=True)
			
			log_obj={
				'url': url,
				'ua': request.environ['HTTP_USER_AGENT'],
				'data':request.body,
				'ip':ip,
				'port':port,
			}
			self.s=log_obj
			F.write('log/8000/'+U.stime(),U.pformat(log_obj))
		except Exception as e:
			self.e=e
			F.write('log/8000/e'+U.stime(),U.pformat(e))
			
		if url.startswith('/#rpc\n'):
			self.g['self']=self #test?
			
			request.url=url
			self.g['q']=request
			
			response = HttpResponse()
			response['content-type'] = 'text/plain; charset=utf-8'
			response['X-XSS-Protection']='0'
			response['Access-Control-Allow-Origin'] = '*'
			self.g['p']=response
			
			r=U.execStrResult(url[1:],globals=self.g)
			if not response.content:
				response.content=r
			return response

		# Code to be executed for each request before
		# the view (and later middleware) are called.
		response = self.get_response(request)
		# Code to be executed for each request/response after
		# the view is called.
		return response
		
# from django import template
# register = template.Library()

# @register.tag(name='eval')
# def do_eval(parser, token):
	# "Usage: {% eval %}1 + 1{% endeval %}"

	# nodelist = parser.parse(('endeval',))

	# class EvalNode(template.Node):
		# def render(self, context):
			# return eval(nodelist.render(context))

	# parser.delete_first_token()
	# return EvalNode()