diff --git a/scripts/client-api-request-crafter.py b/scripts/client-api-request-crafter.py new file mode 100644 index 00000000..73f55b33 --- /dev/null +++ b/scripts/client-api-request-crafter.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 + +"""Craft and send requests to the local client API""" + + +import sys +import os +if not os.path.exists('onionr.sh'): + os.chdir('../') +sys.path.append("src/") +from onionrutils.localcommand import local_command +from onionrutils.localcommand import get_hostname + +try: + print('API file found, probably running on ' + get_hostname()) +except TypeError: + print('Onionr not running') + sys.exit(1) +print('1. get request') +print('2. post request') +choice = input(">").lower().strip() +post = False +post_data = {} +json = False +endpoint = input("URL Endpoint: ") +data = input("Data url param: ") +if choice in ("2", "post", "post request"): + post = True + print("Enter post data") + post_data = input() + if post_data: + print("Is this JSON?") + json = input("y/n").lower().strip() + if json == "y": + json = True + +ret = local_command(endpoint, data=data, post=post, post_data=post_data, is_json=json) +print("Response: \n", ret) diff --git a/src/onionrutils/localcommand.py b/src/onionrutils/localcommand.py index 1dbb31b0..5c38fe22 100644 --- a/src/onionrutils/localcommand.py +++ b/src/onionrutils/localcommand.py @@ -67,7 +67,7 @@ def local_command(command, data='', silent=True, post=False, if not hostname: return False - if data != '': + if data: data = '&data=' + urllib.parse.quote_plus(data) payload = 'http://%s/%s%s' % (hostname, command, data) if not config.get('client.webpassword'):