diff --git a/gns3server/main.py b/gns3server/main.py index 0ef24789..ac6c6b19 100644 --- a/gns3server/main.py +++ b/gns3server/main.py @@ -86,6 +86,7 @@ def parse_arguments(argv, config): "ssl": config.getboolean("ssl", False), "certfile": config.get("certfile", ""), "certkey": config.get("certkey", ""), + "record": config.get("record", ""), "local": config.getboolean("local", False), "allow": config.getboolean("allow_remote_console", False), "quiet": config.getboolean("quiet", False), @@ -101,6 +102,7 @@ def parse_arguments(argv, config): parser.add_argument("--ssl", action="store_true", help="run in SSL mode") parser.add_argument("--certfile", help="SSL cert file") parser.add_argument("--certkey", help="SSL key file") + parser.add_argument("--record", help="save curl requests into a file") parser.add_argument("-L", "--local", action="store_true", help="local mode (allows some insecure operations)") parser.add_argument("-A", "--allow", action="store_true", help="allow remote connections to local console ports") parser.add_argument("-q", "--quiet", action="store_true", help="do not show logs on stdout") @@ -122,6 +124,7 @@ def set_config(args): server_config["ssl"] = str(args.ssl) server_config["certfile"] = args.certfile server_config["certkey"] = args.certkey + server_config["record"] = args.record server_config["debug"] = str(args.debug) server_config["live"] = str(args.live) server_config["shell"] = str(args.shell) diff --git a/gns3server/web/route.py b/gns3server/web/route.py index f6f9407f..84b06da4 100644 --- a/gns3server/web/route.py +++ b/gns3server/web/route.py @@ -28,6 +28,7 @@ log = logging.getLogger(__name__) from ..modules.vm_error import VMError from .response import Response from ..crash_report import CrashReport +from ..config import Config @asyncio.coroutine @@ -125,6 +126,15 @@ class Route(object): # API call try: request = yield from parse_request(request, input_schema) + server_config = Config.instance().get_section_config("Server") + record_file = server_config.get("record") + if record_file: + try: + with open(record_file, "a") as f: + f.write("curl -X {} 'http://{}{}' -d '{}'".format(request.method, request.host, request.path_qs, json.dumps(request.json))) + f.write("\n") + except OSError as e: + log.warn("Could not write to the record file {}: {}".format(record_file, e)) response = Response(route=route, output_schema=output_schema) yield from func(request, response) except aiohttp.web.HTTPException as e: