Ejemplo n.º 1
0
 def run(self, arguments):
     if len(arguments) != 3:
         Console.print_help(arguments)
         sys.exit()
     else:
         conf = WhatTheFileConfiguration()
         conf.parse_file(arguments[1])
         output = OutputFactory.get_output_by_conf(conf)
         core = Core(conf, output)
         core.run(arguments[2])
Ejemplo n.º 2
0
def importRoutes(rootpath, app, config_object: Config):
    """Add user routes to app."""

    conf = WhatTheFileConfiguration()
    conf.parse_file(config_object.WHATTHEFILECONFIGFILE)
    output = ListOutput()
    core = Core(conf, output)

    @app.route(rootpath, methods=['GET', 'POST'])
    def index_or_upload_file():
        if request.method == 'GET':
            return send_file("pages/index.html", mimetype='text/html')
        else:
            if 'fileToUpload' not in request.files:
                abort(404)
            else:
                file = request.files['fileToUpload']
                binary = file.read()
                if len(binary) != 0:
                    path = _write_file(config_object, binary,
                                       os.path.basename(file.filename))
                    output.get_list().clear()
                    core.run(path)
                    _remove_file(path)
                    core.clean_safe_output_path()
                    result = output.get_list()
                    remove_internal_info(result)
                    return Response(json.dumps(result, default=str),
                                    200,
                                    mimetype='application/json')
                else:
                    return Response(json.dumps({"error": "invalid file"},
                                               default=str),
                                    400,
                                    mimetype='application/json')

    @app.route(rootpath + "favicon.ico", methods=['GET'])
    def get_favicon():
        return send_file("images/favicon.png", mimetype='image/png')
 def test_load_conf_file(self):
     conf = WhatTheFileConfiguration()
     conf.parse_file('./tests/examples/whatthefile.ini')
     self.assertEqual(len(conf.get_modules_names()), 10)
     self.assertTrue(conf.get_property_boolean("module.hashes", "active"))
     self.assertTrue("active" in conf.get_section("module.hashes"))