Change custom request & response commands by two kapow subcommands
This commit is contained in:
@@ -595,5 +595,38 @@ def route_list(route_id, url):
|
|||||||
print(json.dumps(response.json(), indent=2))
|
print(json.dumps(response.json(), indent=2))
|
||||||
|
|
||||||
|
|
||||||
|
@kapow.command("set")
|
||||||
|
@click.option("--url", envvar='KAPOW_URL')
|
||||||
|
@click.option("--handler-id", envvar='KAPOW_HANDLER_ID')
|
||||||
|
@click.argument("path", nargs=1)
|
||||||
|
@click.argument("value", required=False)
|
||||||
|
def kapow_set(url, handler_id, path, value):
|
||||||
|
if value is None:
|
||||||
|
data = sys.stdin.buffer
|
||||||
|
else:
|
||||||
|
data = value.encode('utf-8')
|
||||||
|
|
||||||
|
try:
|
||||||
|
response = requests.put(f"{url}/handlers/{handler_id}{path}",
|
||||||
|
data=data)
|
||||||
|
except requests.exceptions.ConnectionError:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
response.raise_for_status()
|
||||||
|
|
||||||
|
|
||||||
|
@kapow.command("get")
|
||||||
|
@click.option("--url", envvar='KAPOW_URL')
|
||||||
|
@click.option("--handler-id", envvar='KAPOW_HANDLER_ID')
|
||||||
|
@click.argument("path", nargs=1)
|
||||||
|
def kapow_get(url, handler_id, path):
|
||||||
|
try:
|
||||||
|
response = requests.get(f"{url}/handlers/{handler_id}{path}")
|
||||||
|
response.raise_for_status()
|
||||||
|
except requests.exceptions.ConnectionError:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
print(response.text)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
kapow()
|
kapow()
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
#
|
|
||||||
# Copyright 2019 Banco Bilbao Vizcaya Argentaria, S.A.
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
# you may not use this file except in compliance with the License.
|
|
||||||
# You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
# See the License for the specific language governing permissions and
|
|
||||||
# limitations under the License.
|
|
||||||
#
|
|
||||||
|
|
||||||
curl -sf "${KAPOW_URL}/handlers/${KAPOW_HANDLER_ID}/request$1"
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
|
|
||||||
#
|
|
||||||
# Copyright 2019 Banco Bilbao Vizcaya Argentaria, S.A.
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
# you may not use this file except in compliance with the License.
|
|
||||||
# You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
# See the License for the specific language governing permissions and
|
|
||||||
# limitations under the License.
|
|
||||||
#
|
|
||||||
|
|
||||||
import sys
|
|
||||||
|
|
||||||
import click
|
|
||||||
import requests
|
|
||||||
|
|
||||||
|
|
||||||
@click.command()
|
|
||||||
@click.option("--url", envvar='KAPOW_URL')
|
|
||||||
@click.option("--handler-id", envvar='KAPOW_HANDLER_ID')
|
|
||||||
@click.argument("path", nargs=1)
|
|
||||||
@click.argument("value", required=False)
|
|
||||||
def response(url, handler_id, path, value):
|
|
||||||
if value is None:
|
|
||||||
data = sys.stdin.buffer
|
|
||||||
else:
|
|
||||||
data = value.encode('utf-8')
|
|
||||||
|
|
||||||
try:
|
|
||||||
response = requests.put(f"{url}/handlers/{handler_id}/response{path}",
|
|
||||||
data=data)
|
|
||||||
except requests.exceptions.ConnectionError:
|
|
||||||
return False
|
|
||||||
else:
|
|
||||||
response.raise_for_status()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
response()
|
|
||||||
@@ -16,4 +16,4 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
|
|
||||||
kapow route add -X POST '/eval' -c '$($(request /body) | response /stream)'
|
kapow route add -X POST '/eval' -c '$($(kapow get /request/body) | kapow set /response/stream)'
|
||||||
|
|||||||
@@ -16,4 +16,4 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
|
|
||||||
kapow route add -X GET '/list/{ip}' -c 'nmap -sL $(request /matches/ip) | response /body'
|
kapow route add -X GET '/list/{ip}' -c 'nmap -sL $(kapow get /request/matches/ip) | kapow set /response/body'
|
||||||
|
|||||||
+11
-11
@@ -16,26 +16,26 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
|
|
||||||
kapow route add /list/files -c 'ls -la $(request /params/path) | response /body'
|
kapow route add /list/files -c 'ls -la $(kapow get /request/params/path) | kapow set /response/body'
|
||||||
|
|
||||||
kapow route add /list/processes -c 'ps -aux | response /body'
|
kapow route add /list/processes -c 'ps -aux | kapow set /response/body'
|
||||||
|
|
||||||
kapow route add /show/cpuinfo -c 'response /body < /proc/cpuinfo'
|
kapow route add /show/cpuinfo -c 'kapow set /response/body < /proc/cpuinfo'
|
||||||
|
|
||||||
kapow route add /show/memory -c 'free -m | response /body'
|
kapow route add /show/memory -c 'free -m | kapow set /response/body'
|
||||||
|
|
||||||
kapow route add /show/disk -c 'df -h | response /body'
|
kapow route add /show/disk -c 'df -h | kapow set /response/body'
|
||||||
|
|
||||||
kapow route add /show/connections -c 'ss -pluton | response /body'
|
kapow route add /show/connections -c 'ss -pluton | kapow set /response/body'
|
||||||
|
|
||||||
kapow route add /show/mounts -c 'mount | response /body'
|
kapow route add /show/mounts -c 'mount | kapow set /response/body'
|
||||||
|
|
||||||
kapow route add /tail/dmesg - <<-'EOF'
|
kapow route add /tail/dmesg - <<-'EOF'
|
||||||
response /headers/Content-Type text/plain
|
kapow set /response/headers/Content-Type text/plain
|
||||||
dmesg -w | response /stream
|
dmesg -w | kapow set /response/stream
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
kapow route add /tail/journal - <<-'EOF'
|
kapow route add /tail/journal - <<-'EOF'
|
||||||
response /headers/Content-Type text/plain
|
kapow set /response/headers/Content-Type text/plain
|
||||||
journalctl -f | response /stream
|
journalctl -f | kapow set /response/stream
|
||||||
EOF
|
EOF
|
||||||
|
|||||||
@@ -17,10 +17,10 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
kapow route add -X POST --entrypoint '/bin/zsh -c' '/convert/{from}/{to}' - <<-'EOF'
|
kapow route add -X POST --entrypoint '/bin/zsh -c' '/convert/{from}/{to}' - <<-'EOF'
|
||||||
pandoc --from=$(request /matches/from) \
|
pandoc --from=$(kapow get /request/matches/from) \
|
||||||
--to=$(request /matches/to) \
|
--to=$(kapow get /request/matches/to) \
|
||||||
--output=>(response /body) \
|
--output=>(kapow set /response/body) \
|
||||||
=(request /body)
|
=(kapow get /request/body)
|
||||||
EOF
|
EOF
|
||||||
kapow route add -X GET '/formats/input' -c 'pandoc --list-input-formats | response /body'
|
kapow route add -X GET '/formats/input' -c 'pandoc --list-input-formats | kapow set /response/body'
|
||||||
kapow route add -X GET '/formats/output' -c 'pandoc --list-output-formats | grep -v pdf | response /body'
|
kapow route add -X GET '/formats/output' -c 'pandoc --list-output-formats | grep -v pdf | kapow set /response/body'
|
||||||
|
|||||||
@@ -17,4 +17,4 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
kapow route add -X POST --entrypoint ./topdf '/editor/pdf'
|
kapow route add -X POST --entrypoint ./topdf '/editor/pdf'
|
||||||
kapow route add / -c 'response /headers/Content-Type text/html && response /body < pdfeditor.html'
|
kapow route add / -c 'kapow set /response/headers/Content-Type text/html && kapow set /response/body < pdfeditor.html'
|
||||||
|
|||||||
@@ -17,12 +17,12 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
tmpfile=$(mktemp --suffix=.pdf)
|
tmpfile=$(mktemp --suffix=.pdf)
|
||||||
pandoc --from=$(request /form/from) --to=pdf --output=${tmpfile} -t latex =(request /form/content)
|
pandoc --from=$(kapow get /request/form/from) --to=pdf --output=${tmpfile} -t latex =(kapow get /request/form/content)
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
response /headers/Content-Type application/pdf
|
kapow set /response/headers/Content-Type application/pdf
|
||||||
response /body < ${tmpfile}
|
kapow set /response/body < ${tmpfile}
|
||||||
response /status 200
|
kapow set /response/status 200
|
||||||
else
|
else
|
||||||
response /status 500
|
kapow set /response/status 500
|
||||||
fi
|
fi
|
||||||
rm -f ${tmpfile}
|
rm -f ${tmpfile}
|
||||||
|
|||||||
@@ -17,8 +17,8 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
kapow route add / - <<-'EOF'
|
kapow route add / - <<-'EOF'
|
||||||
response /headers/Content-Type text/html
|
kapow set /response/headers/Content-Type text/html
|
||||||
response /body <<-HTML
|
kapow set /response/body <<-HTML
|
||||||
<html>
|
<html>
|
||||||
<body>
|
<body>
|
||||||
<a href='javascript: Array.from(document.querySelectorAll("a")).filter(x => x.href.indexOf("magnet") != -1 ).map(x => x.href = "http://localhost:8080/save/magnet?link="+encodeURI(x.href))'>Add me to your bookmarks!</a>
|
<a href='javascript: Array.from(document.querySelectorAll("a")).filter(x => x.href.indexOf("magnet") != -1 ).map(x => x.href = "http://localhost:8080/save/magnet?link="+encodeURI(x.href))'>Add me to your bookmarks!</a>
|
||||||
@@ -28,16 +28,16 @@ kapow route add / - <<-'EOF'
|
|||||||
EOF
|
EOF
|
||||||
|
|
||||||
kapow route add /save/magnet -e '/bin/bash -c' - <<-'EOF'
|
kapow route add /save/magnet -e '/bin/bash -c' - <<-'EOF'
|
||||||
link=$(request /params/link)
|
link=$(kapow get /request/params/link)
|
||||||
[ -z $link ] && response /status 400 && exit 0
|
[ -z $link ] && kapow set /response/status 400 && exit 0
|
||||||
|
|
||||||
watch_folder=/tmp
|
watch_folder=/tmp
|
||||||
cd $watch_folder
|
cd $watch_folder
|
||||||
[[ "$link" =~ xt=urn:btih:([^&/]+) ]] || exit;
|
[[ "$link" =~ xt=urn:btih:([^&/]+) ]] || exit;
|
||||||
echo "d10:magnet-uri${#link}:${link}e" > "meta-${BASH_REMATCH[1]}.torrent"
|
echo "d10:magnet-uri${#link}:${link}e" > "meta-${BASH_REMATCH[1]}.torrent"
|
||||||
|
|
||||||
response /status 302
|
kapow set /response/status 302
|
||||||
response /headers/Location /torrent/list
|
kapow set /response/headers/Location /torrent/list
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
kapow route add /torrent/list -c 'response /body "Not Implemented Yet"'
|
kapow route add /torrent/list -c 'kapow set /response/body "Not Implemented Yet"'
|
||||||
|
|||||||
Reference in New Issue
Block a user