-
Notifications
You must be signed in to change notification settings - Fork 2
API
mauricelambert edited this page Dec 29, 2021
·
5 revisions
-
/api/(HTTP GET METHOD): JSON response with scripts details/informations -
/api/scripts/<script name>(HTTP POST METHOD): JSON response with script stdout (outputs), stderr (errors) and exitcode. A csrf token is added if you use the WEB interface. -
/api/script/get/<key>(HTTP GET METHOD): JSON response
{
"<script name>": {
"content_type": "text/<plain or html>",
"documentation_content_type": "text/<html or plain>",
"description": "<short description>",
"category": "<category>",
"name": "<script name>",
"args": [
{
"default_value": "<default value>",
"html_type": "<input type>",
"description": "<short description>",
"example": "<example>",
"input": false,
"predefined_values": ["<value1>", "<value2>"],
"list": false,
"name": "<argument name>"
}
]
}
}{
"stdout": "<script outputs>",
"stderr": "<script errors>",
"code": 0,
"Content-Type": "text/<plain or html>",
"csrf": "<token>",
"error": "<server timeout error>",
"key": "<key>"
}- stdout: the output of the script. Required, type string.
- stderr: script errors. Required, type string.
- code: the exit code of the script. Required, type integer or null.
-
Content-Type: script output content-type. Required, type string, value:
text/plainortext/html. -
Stderr-Content-Type: script errors content-type. Required, type string, value:
text/plain(recommended for security reason) ortext/html. - error: WebScripts error (reason to kill the child process). Required, type string.
- key: for real time output only, while key is defined the process is not terminated.
- csrf: for web browser only, in the response of the POST request only.
A POST HTTP method is required. The content should be a JSON object with an arguments object as attribute (and a csrf_token string as attribute for webbrowser).
For web browser:
{
"csrf_token": "<token>",
"arguments": {
"<argument name>": {
"value": "<value or list of values>",
"input": false
}
}
}For client API:
{
"arguments": {
"<argument name>": {
"value": "<value or list of values>",
"input": false
}
}
}Some HTTP Headers are required to use scripts with WebScripts API:
-
Content-Typeshould beapplication/json(orapplication/json; charset=utf-8). -
Originshould be<scheme>://<host>(examples:http://webscript.local,http://webscript.local:8000,https://webscript.local,https://webscript.local:4430). -
Referershould be the last visited page, required for webbrowser only.
Recommandation:
-
Api-Tokenshould be the session cookie (example:SessionID=2:0123456789abcdef). Session cookie is sent by the server on the response of/auth/script (the/auth/script should accept--usernameand--passwordarguments OR--api-keyargument). You can useApi-Tokenas much as you want but Basic Auth andApi-Keywill be blacklisted if you exceed the anti bruteforce configuration.
To use the WebScripts API you can use HTTP BasicAuth or an API key in a Api-Key header.
You should never use these authentication methods with a Web Browser because CSRF protection is not enabled.