Skip to content

Instantly share code, notes, and snippets.

@oxr463
Last active May 9, 2023 08:07
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save oxr463/ba3af20541647ee613e47f0787168084 to your computer and use it in GitHub Desktop.
Save oxr463/ba3af20541647ee613e47f0787168084 to your computer and use it in GitHub Desktop.
OpenWrt JSON-RPC

OpenWrt JSON-RPC

Dependencies

Authentication

# Update OPENWRT_HOSTNAME and OPENWRT_USERNAME in environment.sh before proceeding
sh ./environment.sh
export OPENWRT_PASSWORD="{{password}}" # set the password here
export OPENWRT_TOKEN="$(sh ./auth.sh | jq .result)"

Examples

# Be sure to set the OPENWRT_TOKEN before making any requests
sh ./sys_net_conntrack.sh
sh ./sys_net_devices.sh
sh ./sys_uptime.sh
sh ./uci_get_all_network.sh

License

SPDX: GPL-3.0-or-later

See Also

#!/bin/sh
set -e
. ./request.sh
URL="https://${OPENWRT_HOSTNAME}/cgi-bin/luci/rpc/auth"
request "{ \"id\": 1, \"method\": \"login\", \"params\": [ \"${OPENWRT_USERNAME}\", \"${OPENWRT_PASSWORD}\" ] }"
#!/bin/sh
set -e
export OPENWRT_HOSTNAME=""
export OPENWRT_USERNAME=""
unset OPENWRT_PASSWORD
unset OPENWRT_TOKEN
#!/bin/sh
set -e
request() {
curl "${URL}" --data "${1}"
}
#!/bin/sh
set -e
. ./request.sh
URL="https://${OPENWRT_HOSTNAME}/cgi-bin/luci/rpc/sys?auth=${OPENWRT_TOKEN}"
request "{ \"method\": \"net.conntrack\" }"
#!/bin/sh
set -e
. ./request.sh
URL="https://${OPENWRT_HOSTNAME}/cgi-bin/luci/rpc/sys?auth=${OPENWRT_TOKEN}"
request "{ \"method\": \"net.devices\" }"
#!/bin/sh
set -e
. ./request.sh
URL="https://${OPENWRT_HOSTNAME}/cgi-bin/luci/rpc/sys?auth=${OPENWRT_TOKEN}"
request "{ \"method\": \"uptime\" }"
#!/bin/sh
set -e
. ./request.sh
URL="https://${OPENWRT_HOSTNAME}/cgi-bin/luci/rpc/uci?auth=${OPENWRT_TOKEN}"
request "{ \"method\": \"get_all\", \"params\": [ \"network\" ] }"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment