예제 #1
0
    def do_GET(self):
        print('{} GET received '.format(self.path))
        split_path = os.path.splitext(self.path)
        request_extension = split_path[1]

        handler = None
        if request_extension == ".png" and self.path.startswith(
                '/anomaly/image'):
            handler = ImageHandler()
            handler.find({'path': self.path})
        elif request_extension is ".py":
            handler = BadRequestHandler()
        elif self.path.startswith('/analysis/run'):
            self.experiment.run_experiment()
            handler = OkHandler()
        elif self.path.startswith('/analysis/response'):
            if self.path == '/analysis/response' or self.path == '/analysis/response/':
                payload = self.__pop_payload()
            else:
                payload = self.__pop_payload_for_channel(
                    self.path.split('/', 3)[3])
            action = payload.action if payload else ''
            handler = OkHandler(data=action)
        else:
            handler = StaticHandler()
            handler.find(self.path)

        if handler:
            self.respond({'handler': handler})
예제 #2
0
    def do_GET(self):
        split_path = os.path.splitext(self.path)
        request_extension = split_path[1]

        if request_extension is "" or request_extension is ".html":
            route_handler = RouteHandler(router.getRoutes())

            if route_handler.find(self.path):
                route_result = route_handler.get_result()
                if "template" in route_result:
                    handler = TemplateHandler()
                    handler.find(route_result["template"],
                                 route_result["data"])
                elif "json" in route_result:
                    handler = JsonHandler()
                    handler.format(route_result["data"])
                else:
                    handler = BadRequestHandler()
            else:
                handler = BadRequestHandler()

        elif request_extension is ".py":
            handler = BadRequestHandler()

        else:
            handler = StaticHandler()
            handler.find(self.path)

        self.respond({
            'status': handler.getStatus(),
            'type': handler.getType(),
            'handler': handler
        })
예제 #3
0
    def do_GET(self):
        request_tokens = self.path.split('?')
        self.path = request_tokens[0]

        #here we are checking the file type of the requested object. This is how we know how to handle the request
        split_path = os.path.splitext(self.path)
        request_extension = split_path[1]

        #if it's an html then we probably got a comparison submission
        if (request_extension == "") or (request_extension == ".html"):
            #if we did in fact get a comparison
            if len(request_tokens) > 1:
                values, submit = request_tokens[1].split("&")
                values = values.split('=')[1].split('%26')
                print('values <{}>'.format(values))
                print('submit <{}>'.format(submit))

                #process the data according to user submission. We put the answer on the FinishedEntry queue (this is used in human_backend to keep track of comparisons for the human phase)
                if submit == "submit=A":
                    try:
                        closer = values[1]
                        further = values[2]
                        finished_comp.put(
                            FinishedEntry(main_pic_name=values[0],
                                          closer_pic_name=closer,
                                          further_pic_name=further))
                    except:
                        # On bad html requests, just ignore it and move on
                        pass
                elif submit == "submit=B":
                    try:
                        closer = values[2]
                        further = values[1]
                        finished_comp.put(
                            FinishedEntry(main_pic_name=values[0],
                                          closer_pic_name=closer,
                                          further_pic_name=further))
                    except:
                        # On bad html requests, just ignore it and move on
                        pass
            #routes is a folder that houses our html page. We made it a folder for later project expansion.
            if self.path in routes:
                handler = TemplateHandler()
                handler.find(routes[self.path])
            else:
                handler = BadRequestHandler()
        elif request_extension is ".py":
            #if someone is trying to hack us
            handler = BadRequestHandler()
        else:
            #StaticHandler is sorta our catch all for images
            handler = StaticHandler()
            handler.find(self.path)

        self.respond({'handler': handler})
예제 #4
0
    def do_GET(self):
        global org_roam_db

        requested_file = os.path.basename(urlparse(self.path)[2])
        requested_extension = os.path.splitext(requested_file)[1]
        requested_filename = os.path.splitext(requested_file)[0]
        to_be_exported_file = os.path.join(
            org_roam_directory, requested_filename + ".org")

        if "network-vis-options" in self.path:
            handler = NetworkVisHandler()

        elif "default-filters" in self.path:
            handler = DefaultFiltersHandler()

        elif "server-css" in self.path:
            handler = ServerCSSHandler()

        elif "roam-data" in self.path:
            self.roam_force = get_query_field(self.path, "force")
            handler = RoamDataHandler(self.roam_force, org_roam_db)

        elif "current-buffer-data" in self.path:
            handler = CurrentBufferHandler()

        elif "org-roam-buffer" in self.path:
            file_path = get_query_field(self.path, "path")
            file_label = get_query_field(self.path, "label")
            handler = RoamBufferHandler(org_roam_db, file_path, file_label)

        elif (requested_file
              and requested_extension == ".html"
              and os.path.isfile(to_be_exported_file)):
            handler = FilePreviewHandler(to_be_exported_file, org_roam_db)

        elif (requested_file
              and requested_extension == ".html"
              and os.path.isfile(get_fullpath(to_be_exported_file))):
            handler = FilePreviewHandler(
                get_fullpath(to_be_exported_file), org_roam_db)

        elif requested_extension == "" or requested_extension == ".html":
            if self.path in routes:
                handler = TemplateHandler()
                handler.find(routes[self.path])
            else:
                handler = BadRequestHandler()

        elif requested_extension == ".py":
            handler = BadRequestHandler()
        else:
            handler = StaticHandler()
            handler.find(self.path)

        self.respond({"handler": handler})
예제 #5
0
    def do_GET(self):
        split_path = os.path.splitext(self.path)
        request_extension = split_path[1]

        if (request_extension is "" or request_extension is ".html"):
            if (self.path in routes):
                handler = TemplateHandler()
                handler.find(routes[self.path])
            else:
                handler = BadRequestHandler()
        elif request_extension is ".py":
            handler = BadRequestHandler()
        else:
            handler = StaticHandler()
            handler.find(self.path)

        self.respond({'handler': handler})
예제 #6
0
    def do_GET(self):
        split_path = os.path.splitext(self.path)
        request_extension = split_path[1]

        if request_extension is "" or request_extension is ".json":
            if self.path in routes:
                handler = JsonHandler()
                handler.find(routes[self.path])
            else:
                handler = BadRequestHandler()
        elif request_extension is ".py":
            handler = BadRequestHandler()
        else:
            handler = StaticHandler()
            handler.find(self.path)

        self.respond({'handler': handler})
예제 #7
0
    def do_GET(self):
        # logging.basicConfig(level=logging.DEBUG,
        #                     format= '%(asctime)s %(levelname)-8s %(message)s',
        #                     datefmt='%Y-%m-%d %H:%M:%S',
        #                     filename=config.log_web_filepath,
        #                     filemode='w')
        # logger_web_sv = logging.getLogger("server")
        # logger_web_sv.info("hello")
        self.log_web = logging.getLogger("server")
        self.file_log_web = logging.FileHandler("log_web.txt")
        self.format_log_web = logging.Formatter(
            '%(asctime)s %(levelname)-8s %(message)s',
            datefmt='%Y-%m-%d %H:%M:%S')
        self.file_log_web.setFormatter(self.format_log_web)
        self.log_web.setLevel(logging.DEBUG)
        self.log_web.addHandler(self.file_log_web)
        # log_web.info("hello log web")
        # print(self.address_string())
        split_path = os.path.splitext(self.path)
        request_extension = split_path[1]
        # print(request_extension)
        # print(self.client_address)
        # print(self.log_request())
        if request_extension == "":
            #print(self.path)
            #print(self.path[1:-5])
            #print(routes)
            if self.path in routes:
                #print("if")
                handler = TemplateHandler()
                #print(routes[self.path[:-5]])
                handler.find(routes[self.path])
            else:
                #print("else")
                handler = BadRequestHandler()
        elif request_extension == ".py":
            handler = BadRequestHandler()
        else:
            handler = StaticHandler()
            handler.find(self.path)

        self.respond({'handler': handler})
예제 #8
0
    def do_GET(self):

        handler = StaticHandler()
        alt = routes['static']['path'] + self.path

        if self.path in routes:

            file_found = handler.find(routes[self.path])
            if file_found == 0:
                handler = BadRequestHandler()
        elif os.path.isfile(alt):
            temp_route = {'path': alt}
            file_found = handler.find(temp_route)
            if file_found == 0:
                handler = BadRequestHandler()
        else:
            handler = BadRequestHandler()
        self.respond({'handler': handler})
예제 #9
0
        def do_GET(self):
            split_path = os.path.splitext(self.path)
            request_extension = split_path[1]

            if request_extension is "" or request_extension is ".html":
                hashingslash = self.path[-1:]
                if hashingslash is not '/':
                    self.path += '/'

                # print (self.path)
                if self.path in routes:
                    handler = TemplateHandler()
                    handler.find(routes[self.path])
                else:
                    handler = BadRequestHandler()
            elif request_extension is ".py":
                handler = BadRequestHandler()
            else:
                handler = StaticHandler()
                handler.find(self.path)

            self.respond({'handler': handler})
예제 #10
0
    def do_GET(self):
        # print('{} GET received '.format(self.path))
        split_path = os.path.splitext(self.path)
        request_extension = split_path[1]

        handler = None
        if request_extension == ".png" and self.path.startswith(
                '/anomaly/image'):
            handler = ImageHandler()
            handler.find({'path': self.path})
        elif request_extension is ".py":
            handler = BadRequestHandler()
        elif self.path.startswith('/analysis/run'):
            self.experiment.run_experiment()
            handler = OkHandler()
        elif self.path.startswith('/slack/command'):
            print('{} slack command received'.format(self.path))
            handler = SlackHandler(self.experiment)
        else:
            handler = StaticHandler()
            handler.find(self.path)

        if handler:
            self.respond({'handler': handler})