示例#1
0
 def method(*args, **kws):
     request = args[0]
     haoyaoshi_uid = request.COOKIES.get("COOKIE_ADMIN_USER_ID", None)
     haoyaoshi_verify = request.COOKIES.get("COOKIE_ADMIN_VERIFY", None)
     # TODO log the IP of failed attempt
     #print haoyaoshi_uid, haoyaoshi_verify
     client_ip = get_ip(request)
     auth_result = haoyaoshi_auth.check(haoyaoshi_uid, haoyaoshi_verify)
     if (haoyaoshi_uid is not None) and (haoyaoshi_verify is not None) \
                 and auth_result == "SUCC":
         # log which user do what
         logging.getLogger("Dashboard").info(
             "Haoyaoshi Auth Succ: ip=%s, path=%s, uid=%s" %
             (client_ip, request.path, haoyaoshi_uid))
         request.session["user_name"] = settings.HAOYAOSHI_DASHBOARD_USER
         return callable(*args, **kws)
     else:
         if auth_result == "FAIL":
             logging.getLogger("Dashboard").info(
                 "Haoyaoshi Auth Failed: ip=%s, path=%s, uid=%s, verify=%s"
                 %
                 (client_ip, request.path, haoyaoshi_uid, haoyaoshi_verify))
             return HttpResponseForbidden("未登录")
         else:
             return HttpResponseForbidden("后台集成接口错误")
示例#2
0
 def get(self, request, *args, **kwargs):
     article = self.get_object()
     # 统计文章的访问访问次数
     ip = get_ip(request)
     # 获取15*60s时间内访问过这篇文章的所有ip
     visited_ips = cache.get(article.id, [])
     # 如果ip不存在就把文章的浏览次数+1
     if ip not in visited_ips:
         article.view_times += 1
         article.save()
         # 更新缓存
         visited_ips.append(ip)
         cache.set(article.id, visited_ips, 15 * 60)
     return super(ArticleDetailView, self).get(request, *args, **kwargs)
示例#3
0
文件: peerBase.py 项目: APWHY/carlsb
    def __init__(self, broadcastHandler, streamHandler):
        # we get our own ip
        self.IP = utils.get_ip()
        # set up our streaming server
        self.streamServer = socketserver.TCPServer((self.IP, 0), streamHandler)
        # now we can get the port our streaming server is bound to
        self.SSERVPORT = self.streamServer.socket.getsockname()[1]

        # finally, we set up the broadcast server
        # allow multiple processes to listen on the same port since we want this to be the case
        # for broadcasts
        socketserver.UDPServer.allow_reuse_address = True
        self.broadcastServer = socketserver.UDPServer(
            (self.IP, self.BSERVPORT), broadcastHandler)
        tempSocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        tempSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        tempSocket.bind(('0.0.0.0', self.BSERVPORT))
        # We manually remake the socket so that it can handle broadcasts instead of normal udp packets
        self.broadcastServer.socket = tempSocket
示例#4
0
文件: views.py 项目: sunliwen/poco
 def method(*args,**kws):
     request = args[0]
     haoyaoshi_uid = request.COOKIES.get("COOKIE_ADMIN_USER_ID", None)
     haoyaoshi_verify = request.COOKIES.get("COOKIE_ADMIN_VERIFY", None)
     # TODO log the IP of failed attempt
     #print haoyaoshi_uid, haoyaoshi_verify
     client_ip = get_ip(request)
     auth_result = haoyaoshi_auth.check(haoyaoshi_uid, haoyaoshi_verify)
     if (haoyaoshi_uid is not None) and (haoyaoshi_verify is not None) \
                 and auth_result == "SUCC":
         # log which user do what
         logging.getLogger("Dashboard").info("Haoyaoshi Auth Succ: ip=%s, path=%s, uid=%s" % (client_ip, request.path, haoyaoshi_uid))
         request.session["user_name"] = settings.HAOYAOSHI_DASHBOARD_USER
         return callable(*args, **kws)
     else:
         if auth_result == "FAIL":
             logging.getLogger("Dashboard").info("Haoyaoshi Auth Failed: ip=%s, path=%s, uid=%s, verify=%s" % (client_ip, request.path, haoyaoshi_uid, haoyaoshi_verify))
             return HttpResponseForbidden("未登录")
         else:
             return HttpResponseForbidden("后台集成接口错误")
示例#5
0
def login(request):
    if request.method == "GET":
        return render(request, "login.html")
    data = json.loads(request.body)
    username = data.get("username")
    password = data.get("password")
    ip = get_ip(request)
    # 验证账号
    status, message = verify_account(username, ip)
    if not status:
        return render_json({}, message, code=100001)
    user_obj = auth.authenticate(username=username, password=password)
    if user_obj:
        auth.login(request, user_obj)
        result = dict(id=user_obj.id,
                      username=user_obj.username,
                      token=get_token(user_obj.username, 60))
        return render_json(result, "登录成功!")
    else:
        update_failnumber(username, ip)
        return render_json({}, "登录失败!", code=100002)
示例#6
0
文件: benchMsgs.py 项目: APWHY/carlsb
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)  #do standard CH stuff
     self.httpIP = utils.get_ip()
     self.lock = _thread.allocate_lock(
     )  # to stop sendMsg from clashing with itself
     print("benchMsgs serving")
示例#7
0
文件: demoOEMCM.py 项目: APWHY/carlsb
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)  #do standard CH stuff
     self.httpIP = utils.get_ip()
     self.fileServer = socketserver.TCPServer(
         (self.httpIP, consts.HTTP_PORT), simpleServer.SimpleFileHandler)
     print("demoOEM serving")
示例#8
0
文件: demoCarCM.py 项目: APWHY/carlsb
            "---------------------------------------------------------------------"
        )
        self.msgIP = ip
        self.msgPort = port
        self.msgSig = signature
        self.msgPubKey = pubKey
        super().verifyTransaction(self.retrieve, pubKey, signature)

    def retrieve(self, result):
        if result:
            addr = "http://" + self.msgIP + ":" + str(self.msgPort)
            msgf = urllib.request.urlopen(addr)
            msg = msgf.read()
            print(msg)
            if cryptostuff.verifyMsg(self.msgPubKey, msg, self.msgSig):
                print("message is verified properly!")
                return True
            else:
                print("something went wrong with checking the message....n")
                return False
        else:
            print("signature not verified on chain")
            return False


if __name__ == "__main__":
    print("IP is: " + utils.get_ip())
    test = Car(CM.UDPHandler, CM.TCPHandler)
    test.addDownloadFunc(test.checkChain)
    time.sleep(300)
示例#9
0

# This class sets up a simple HTTP server that is set up to serve the 'example' file in the 'download' folder
# The file will be returned on any get request.
class SimpleFileHandler(http.server.BaseHTTPRequestHandler):
    serving = os.path.join(os.path.curdir, 'simplehttp', 'download',
                           'example')  # default, can be overridden

    def do_GET(self):
        f = open(self.serving, 'rb')
        self.send_response(200)
        self.send_header("Content-type", 'text/plain')
        fs = os.fstat(f.fileno())
        self.send_header("Content-Length", str(fs[6]))
        self.send_header("Last-Modified", self.date_time_string(fs.st_mtime))
        self.end_headers()
        shutil.copyfileobj(f, self.wfile)
        f.close()


# simple test code
if __name__ == "__main__":  # must run this from root dir or it won't work

    handler = SimpleFileHandler
    ip = utils.get_ip()

    with socketserver.TCPServer((ip, consts.HTTP_PORT), handler) as httpd:
        print("serving at port", consts.HTTP_PORT)
        print("serving at address", ip)
        httpd.serve_forever()