Ejemplo n.º 1
0
 def post(self, plugin_id=None):
     data = request.get_json(force=True)
     self.create_config(plugin_id)
     if self.config is None:
         return exception(
             "Cannot found plugin {} ini file.".format(plugin_id), code=400)
     for key, value in data.items():
         if str(key).startswith("set_"):
             for item in value:
                 for sub_key, sub_value in item.items():
                     if not sub_key in self.config.get_all_childname(key):
                         return exception(
                             "Cannot found that attribute {} on {}!".format(
                                 sub_key, key),
                             code=400,
                         )
                     self.config.set(key, sub_key, sub_value)
         else:
             if not key in self.config.get_all_childname(self.key_name):
                 return exception(
                     "Cannot found that attribute {} on {}!".format(
                         key, self.key_name),
                     code=400,
                 )
             self.config.set(self.key_name, key, value)
     return jsonify(data)
Ejemplo n.º 2
0
 def post(self):
     data = request.get_json(force=True)
     for key, value in data.items():
         if not key in self.config.get_all_childname(self.key_name):
             return exception(
                 "Cannot found that attribute {} on {}!".format(
                     key, self.key_name),
                 code=400,
             )
         self.config.set(self.key_name, key, value)
     return jsonify(data)
Ejemplo n.º 3
0
 def post(self, command=None):
     data = request.get_json(force=True)
     if not "commands" in data:
         return exception(
             "Cannot found that key commands  on data",
             code=400,
         )
     output = []
     with Capturing(output) as output:
         self.root.onecmd(data.get("commands"))
     return jsonify(output)
Ejemplo n.º 4
0
 def get(self, plugin_name=None):
     if plugin_name:
         if not plugin_name in self.config.get_all_childname(self.key_name):
             return exception(
                 "Cannot found that attribute {} on {}!".format(
                     plugin_name, self.key_name),
                 code=400,
             )
     proxy_plugins = self.root.mitm_controller.getInfo(excluded=("Config"))
     for item in proxy_plugins:
         proxy_plugins[item]["Activate"] = self.config.get(
             self.key_name, proxy_plugins[item]["ID"], format=bool)
     return jsonify(proxy_plugins.get(plugin_name))
Ejemplo n.º 5
0
 def get(self, attribute=None):
     if attribute:
         if not attribute in self.config.get_all_childname(self.key_name):
             return exception(
                 "Cannot found that attribute {} on {}!".format(
                     key, self.key_name),
                 code=400,
             )
         return jsonify(
             {attribute: self.config.get(self.key_name, attribute)})
     data = {}
     for key in self.config.get_all_childname(self.key_name):
         data[key] = self.config.get(self.key_name, key)
     return jsonify(data)
Ejemplo n.º 6
0
    def get(self, filename=None):
        if not os.path.isfile("{}/{}.log".format(C.LOG_BASE, filename)):
            return exception("Cannot found that file log {}".format(filename),
                             code=400)
        for args in request.args:
            if not args in self.args:
                return exception(
                    "Cannot found parameters {} on request ".format(args),
                    code=400)

        table = []
        page = int(request.args.get("page"))
        with open("{}/{}.log".format(C.LOG_BASE, filename), "r") as f:
            for line in f:
                table.append(json.loads(line))
        data_splited = list(self.chunk(table, self.limit_view))

        if page <= (len(data_splited) - 1):
            return jsonify({
                "data": {
                    "items": data_splited[page],
                    "limit_view": self.limit_view,
                    "total_pages": (len(table) // self.limit_view) + 1,
                    "current_page": page,
                    "total_count": len(table),
                }
            })
        return jsonify({
            "data": {
                "items": [],
                "limt_view": self.limit_view,
                "total_pages": (len(table) // self.limit_view) + 1,
                "current_page": page,
                "total_count": len(table),
            }
        })
Ejemplo n.º 7
0
    def get(self, plugin_id=None):
        self.create_config(plugin_id)

        if self.config is None:
            return exception(
                "Cannot found plugin {} ini file.".format(plugin_id), code=400)
        data = {}

        for key in self.config.get_all_childname(self.key_name):
            data[key] = self.config.get(self.key_name, key)
            for sub_key in self.config.get_all_childname("set_{}".format(key)):
                if "set_{}".format(key) in list(data.keys()):
                    data["set_{}".format(key)].append({
                        sub_key:
                        self.config.get("set_{}".format(key), sub_key)
                    })
                else:
                    data["set_{}".format(key)] = []
                    data["set_{}".format(key)].append({
                        sub_key:
                        self.config.get("set_{}".format(key), sub_key)
                    })

        return jsonify(data)