uci rpc
uci rpc
参考 https://zhuanlan.zhihu.com/p/648654423
参考 https://github.com/openwrt/luci/wiki/JsonRpcHowTo
参考 https://openwrt.org/docs/techref/ubus
参考 https://openwrt.org/docs/techref/luci
参考 https://openwrt.github.io/luci/api/modules/luci.model.uci.html
参考 https://openwrt.github.io/luci/api/modules/luci.sys.html
root@glinet:~# ubus -v list 'block' @5d04550d "hotplug":{"uuid":"String","label":"String","enabled":"Integer","target":"String","device":"String","options":"String","autofs":"Integer","anon":"Integer","remove":"Integer"} "mount":{"uuid":"String","label":"String","enabled":"Integer","target":"String","device":"String","options":"String","autofs":"Integer","anon":"Integer","remove":"Integer"} "umount":{"uuid":"String","label":"String","enabled":"Integer","target":"String","device":"String","options":"String","autofs":"Integer","anon":"Integer","remove":"Integer"} "info":{"device":"String"} 'container' @86ff39e3 "set":{"name":"String","script":"String","instances":"Table","triggers":"Array","validate":"Array","autostart":"Boolean","data":"Table"} "add":{"name":"String","script":"String","instances":"Table","triggers":"Array","validate":"Array","autostart":"Boolean","data":"Table"} "list":{"name":"String","verbose":"Boolean"} "delete":{"name":"String","instance":"String"} "state":{"spawn":"Boolean","name":"String"} "get_features":{} "console_set":{"name":"String","instance":"String"} "console_attach":{"name":"String","instance":"String"} 'dhcp' @142534ef "ipv4leases":{} "ipv6leases":{} "add_lease":{"ip":"String","mac":"String","duid":"String","hostid":"String","leasetime":"String","name":"String"} 'dnsmasq' @350819a1 "metrics":{} 'dnsmasq.dns' @f6dc14bd 'file' @22fb5cf8 "read":{"path":"String","base64":"Boolean","ubus_rpc_session":"String"} "write":{"path":"String","data":"String","append":"Boolean","mode":"Integer","base64":"Boolean","ubus_rpc_session":"String"} "list":{"path":"String","ubus_rpc_session":"String"} "stat":{"path":"String","ubus_rpc_session":"String"} "md5":{"path":"String","ubus_rpc_session":"String"} "remove":{"path":"String","ubus_rpc_session":"String"} "exec":{"command":"String","params":"Array","env":"Table","ubus_rpc_session":"String"} 'hostapd' @942baf16 "reload":{"phy":"String"} "apsta_state":{"phy":"String","up":"Boolean","frequency":"Integer","sec_chan_offset":"Integer","csa":"Boolean","csa_count":"Integer"} "config_get_macaddr_list":{"phy":"String"} "config_set":{"phy":"String","config":"String","prev_config":"String"} "config_add":{"iface":"String","config":"String"} "config_remove":{"iface":"String"} 'hostapd.phy0-ap0' @46e8d32a "reload":{} "get_clients":{} "get_status":{} "del_client":{"addr":"String","reason":"Integer","deauth":"Boolean","ban_time":"Integer"} "update_airtime":{"sta":"String","weight":"Integer"} "list_bans":{} "update_beacon":{} "get_features":{} "switch_chan":{"freq":"Integer","bcn_count":"Integer","center_freq1":"Integer","center_freq2":"Integer","bandwidth":"Integer","sec_channel_offset":"Integer","ht":"Boolean","vht":"Boolean","he":"Boolean","block_tx":"Boolean","force":"Boolean"} "set_vendor_elements":{"vendor_elements":"String"} "notify_response":{"notify_response":"Integer"} "bss_mgmt_enable":{"neighbor_report":"Boolean","beacon_report":"Boolean","link_measurement":"Boolean"} "rrm_nr_get_own":{} "rrm_nr_list":{} "rrm_nr_set":{"list":"Array"} "rrm_beacon_req":{"addr":"String","mode":"Integer","op_class":"Integer","channel":"Integer","duration":"Integer","bssid":"String","ssid":"String"} "link_measurement_req":{"addr":"String","tx-power-used":"Integer","tx-power-max":"Integer"} 'hotplug.block' @b75c306a "call":{"env":"Array"} 'hotplug.dhcp' @cec91b30 "call":{"env":"Array"} 'hotplug.firmware' @95fac0bf "call":{"env":"Array"} 'hotplug.ieee80211' @5a7f413b "call":{"env":"Array"} 'hotplug.iface' @6e324687 "call":{"env":"Array"} 'hotplug.neigh' @3eb3b06e "call":{"env":"Array"} 'hotplug.net' @bfd0060f "call":{"env":"Array"} 'hotplug.ntp' @26387b9b "call":{"env":"Array"} 'hotplug.tftp' @22eb64b7 "call":{"env":"Array"} 'hotplug.tty' @dd1a46d7 "call":{"env":"Array"} 'hotplug.usb' @a3e16406 "call":{"env":"Array"} 'hotplug.usbmisc' @c3e385de "call":{"env":"Array"} 'iwinfo' @8830431e "devices":{} "info":{"device":"String"} "scan":{"device":"String"} "assoclist":{"device":"String","mac":"String"} "freqlist":{"device":"String"} "txpowerlist":{"device":"String"} "countrylist":{"device":"String"} "survey":{"device":"String"} "phyname":{"section":"String"} 'log' @3a01d4c1 "read":{"lines":"Integer","stream":"Boolean","oneshot":"Boolean"} "write":{"event":"String"} 'luci' @8bd5a86d "getVersion":{} "getInitList":{"name":"String"} "setInitAction":{"name":"String","action":"String"} "getLocaltime":{} "setLocaltime":{"localtime":"Integer"} "getTimezones":{} "getLEDs":{} "getUSBDevices":{} "getConntrackHelpers":{} "getFeatures":{} "getSwconfigFeatures":{"switch":"String"} "getSwconfigPortState":{"switch":"String"} "setPassword":{"username":"String","password":"String"} "getBlockDevices":{} "setBlockDetect":{} "getMountPoints":{} "getRealtimeStats":{"mode":"String","device":"String"} "getConntrackList":{} "getProcessList":{} "getBuiltinEthernetPorts":{} 'luci-rpc' @d2bad56f "getNetworkDevices":{} "getWirelessDevices":{} "getHostHints":{} "getDUIDHints":{} "getBoardJSON":{} "getDHCPLeases":{"family":"Integer"} 'luci.upnp' @149053d8 "get_status":{} "delete_rule":{"token":"String"} 'mwan3' @92b73f1f "status":{"section":"String","interface":"String","policies":"String"} 'network' @0ace52b6 "restart":{} "reload":{} "add_host_route":{"target":"String","v6":"Boolean","interface":"String","exclude":"Boolean"} "get_proto_handlers":{} "add_dynamic":{"name":"String"} "netns_updown":{"jail":"String","start":"Boolean"} 'network.device' @f9a96b40 "status":{"name":"String"} "set_alias":{"alias":"Array","device":"String"} "set_state":{"name":"String","defer":"Boolean","auth_status":"Boolean","auth_vlans":"Array"} "stp_init":{} 'network.interface' @48276119 "up":{} "down":{} "renew":{} "status":{} "prepare":{} "dump":{} "add_device":{"name":"String","link-ext":"Boolean","vlan":"Array"} "remove_device":{"name":"String","link-ext":"Boolean","vlan":"Array"} "notify_proto":{} "remove":{} "set_data":{} 'network.interface.lan' @bdf9cc8b "up":{} "down":{} "renew":{} "status":{} "prepare":{} "dump":{} "add_device":{"name":"String","link-ext":"Boolean","vlan":"Array"} "remove_device":{"name":"String","link-ext":"Boolean","vlan":"Array"} "notify_proto":{} "remove":{} "set_data":{} 'network.interface.loopback' @de54d618 "up":{} "down":{} "renew":{} "status":{} "prepare":{} "dump":{} "add_device":{"name":"String","link-ext":"Boolean","vlan":"Array"} "remove_device":{"name":"String","link-ext":"Boolean","vlan":"Array"} "notify_proto":{} "remove":{} "set_data":{} 'network.interface.lte1' @0a94a945 "up":{} "down":{} "renew":{} "status":{} "prepare":{} "dump":{} "add_device":{"name":"String","link-ext":"Boolean","vlan":"Array"} "remove_device":{"name":"String","link-ext":"Boolean","vlan":"Array"} "notify_proto":{} "remove":{} "set_data":{} 'network.interface.lte2' @6e289636 "up":{} "down":{} "renew":{} "status":{} "prepare":{} "dump":{} "add_device":{"name":"String","link-ext":"Boolean","vlan":"Array"} "remove_device":{"name":"String","link-ext":"Boolean","vlan":"Array"} "notify_proto":{} "remove":{} "set_data":{} 'network.interface.wan' @2d2f99e4 "up":{} "down":{} "renew":{} "status":{} "prepare":{} "dump":{} "add_device":{"name":"String","link-ext":"Boolean","vlan":"Array"} "remove_device":{"name":"String","link-ext":"Boolean","vlan":"Array"} "notify_proto":{} "remove":{} "set_data":{} 'network.rrdns' @b049a1a3 "lookup":{"addrs":"Array","timeout":"Integer","server":"String","port":"(unknown)","limit":"Integer"} 'network.wireless' @58945e45 "up":{} "down":{} "reconf":{} "status":{} "notify":{} "get_validate":{} 'rc' @2a648463 "list":{"name":"String","skip_running_check":"Boolean"} "init":{"name":"String","action":"String"} 'service' @4f63f3f3 "set":{"name":"String","script":"String","instances":"Table","triggers":"Array","validate":"Array","autostart":"Boolean","data":"Table"} "add":{"name":"String","script":"String","instances":"Table","triggers":"Array","validate":"Array","autostart":"Boolean","data":"Table"} "list":{"name":"String","verbose":"Boolean"} "delete":{"name":"String","instance":"String"} "signal":{"name":"String","instance":"String","signal":"Integer"} "update_start":{"name":"String"} "update_complete":{"name":"String"} "event":{"type":"String","data":"Table"} "validate":{"package":"String","type":"String","service":"String"} "get_data":{"name":"String","instance":"String","type":"String"} "state":{"spawn":"Boolean","name":"String"} "watchdog":{"mode":"Integer","timeout":"Integer","name":"String","instance":"String"} 'session' @60d1d48e "create":{"timeout":"Integer"} "list":{"ubus_rpc_session":"String"} "grant":{"ubus_rpc_session":"String","scope":"String","objects":"Array"} "revoke":{"ubus_rpc_session":"String","scope":"String","objects":"Array"} "access":{"ubus_rpc_session":"String","scope":"String","object":"String","function":"String"} "set":{"ubus_rpc_session":"String","values":"Table"} "get":{"ubus_rpc_session":"String","keys":"Array"} "unset":{"ubus_rpc_session":"String","keys":"Array"} "destroy":{"ubus_rpc_session":"String"} "login":{"username":"String","password":"String","timeout":"Integer"} 'system' @dd444f7b "board":{} "info":{} "reboot":{} "watchdog":{"frequency":"Integer","timeout":"Integer","magicclose":"Boolean","stop":"Boolean"} "signal":{"pid":"Integer","signum":"Integer"} "validate_firmware_image":{"path":"String"} "sysupgrade":{"path":"String","force":"Boolean","backup":"String","prefix":"String","command":"String","options":"Table"} 'uci' @cb2fdd77 "configs":{} "get":{"config":"String","section":"String","option":"String","type":"String","match":"Table","ubus_rpc_session":"String"} "state":{"config":"String","section":"String","option":"String","type":"String","match":"Table","ubus_rpc_session":"String"} "add":{"config":"String","type":"String","name":"String","values":"Table","ubus_rpc_session":"String"} "set":{"config":"String","section":"String","type":"String","match":"Table","values":"Table","ubus_rpc_session":"String"} "delete":{"config":"String","section":"String","type":"String","match":"Table","option":"String","options":"Array","ubus_rpc_session":"String"} "rename":{"config":"String","section":"String","option":"String","name":"String","ubus_rpc_session":"String"} "order":{"config":"String","sections":"Array","ubus_rpc_session":"String"} "changes":{"config":"String","ubus_rpc_session":"String"} "revert":{"config":"String","ubus_rpc_session":"String"} "commit":{"config":"String","ubus_rpc_session":"String"} "apply":{"rollback":"Boolean","timeout":"Integer","ubus_rpc_session":"String"} "confirm":{"ubus_rpc_session":"String"} "rollback":{"ubus_rpc_session":"String"} "reload_config":{} 'wpa_supplicant' @43183e3d "phy_set_state":{"phy":"String","stop":"Boolean"} "phy_set_macaddr_list":{"phy":"String","macaddr":"Array"} "phy_status":{"phy":"String"} "config_set":{"phy":"String","config":"Array","defer":"Boolean"} "config_add":{"driver":"String","iface":"String","bridge":"String","hostapd_ctrl":"String","ctrl":"String","config":"String"} "config_remove":{"iface":"String"} root@glinet:~#
root@glinet:~# curl -i -X POST http://192.168.11.1/ubus -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","id":1,"method":"call","params":["00000000000000000000000000000000","session","login",{"username":"root","password":"admin"}]}' HTTP/1.1 200 OK Connection: Keep-Alive Transfer-Encoding: chunked Keep-Alive: timeout=20 Content-Type: application/json { "jsonrpc": "2.0", "id": 1, "result": [0, { "ubus_rpc_session": "7981ddb18003d772ee37385bf1633db8", "timeout": 300, "expires": 299, "acls": { "access-group": { "allow-full-uci-access": ["read", "write"], "luci-app-checknet": ["read", "write"], "luci-app-commands": ["read", "write"], "luci-app-ddns": ["read", "write"], "luci-app-firewall": ["read", "write"], "luci-app-hd-idle": ["read", "write"], "luci-app-mgmtlanip": ["read", "write"], "luci-app-mwan3": ["read", "write"], "luci-app-nft-qos": ["read", "write"], "luci-app-opkg": ["read", "write"], "luci-app-udpxy": ["read", "write"], "luci-app-ugps": ["read", "write"], "luci-app-uhttpd": ["read", "write"], "luci-app-wol": ["read", "write"], "luci-base": ["read", "write"], "luci-base-network-status": ["read"], "luci-mod-network-config": ["read", "write"], "luci-mod-network-dhcp": ["read", "write"], "luci-mod-network-diagnostics": ["read"], "luci-mod-status-channel_analysis": ["read"], "luci-mod-status-firewall": ["read", "write"], "luci-mod-status-index": ["read", "write"], "luci-mod-status-index-dhcp": ["read"], "luci-mod-status-index-dsl": ["read"], "luci-mod-status-index-ports": ["read"], "luci-mod-status-index-storage": ["read"], "luci-mod-status-index-wifi": ["read", "write"], "luci-mod-status-logs": ["read"], "luci-mod-status-processes": ["read", "write"], "luci-mod-status-realtime": ["read"], "luci-mod-status-routes": ["read"], "luci-mod-system-config": ["read", "write"], "luci-mod-system-cron": ["read", "write"], "luci-mod-system-flash": ["read", "write"], "luci-mod-system-init": ["read", "write"], "luci-mod-system-mounts": ["read", "write"], "luci-mod-system-reboot": ["write"], "luci-mod-system-ssh": ["read", "write"], "luci-mod-system-uhttpd": ["read", "write"], "unauthenticated": ["read"] }, "cgi-io": { "backup": ["read"], "download": ["read"], "exec": ["read", "write"], "upload": ["write"] }, "file": { "/": ["list"], "/*": ["list"], "/bin/dmesg -r": ["exec"], "/bin/kill": ["exec"], "/bin/ping": ["exec"], "/bin/ping6": ["exec", "list"], "/bin/tar -tzf /tmp/backup.tar.gz": ["exec"], "/bin/traceroute": ["exec"], "/bin/traceroute6": ["exec", "list"], "/bin/umount": ["exec"], "/dev/mtdblock[0-9]*": ["read"], "/etc/board.json": ["read"], "/etc/crontabs/root": ["read", "write"], "/etc/dropbear/authorized_keys": ["read", "write"], "/etc/filesystems": ["read"], "/etc/firewall.user": ["read", "write"], "/etc/init.d/cron reload": ["exec"], "/etc/init.d/firewall restart": ["exec"], "/etc/iproute2/rt_tables": ["read"], "/etc/luci-uploads/*": ["write"], "/etc/mwan3.user": ["read", "write"], "/etc/opkg.conf": ["read", "write"], "/etc/opkg/*.conf": ["read", "write"], "/etc/rc.local": ["read", "write"], "/etc/sysupgrade.conf": ["read", "write"], "/lib/upgrade/platform.sh": ["list"], "/proc/filesystems": ["read"], "/proc/mounts": ["read"], "/proc/mtd": ["read"], "/proc/partitions": ["read"], "/proc/sys/kernel/hostname": ["read"], "/proc/sys/net/ipv[46]/conf/*": ["read"], "/proc/sys/net/ipv6/conf/*/mtu": ["read"], "/proc/sys/net/ipv6/conf/*/hop_limit": ["read"], "/proc/sys/net/netfilter/nf_conntrack_count": ["read"], "/proc/sys/net/netfilter/nf_conntrack_max": ["read"], "/sbin/block": ["exec"], "/sbin/firstboot -r -y": ["exec"], "/sbin/ifdown": ["exec"], "/sbin/ifup": ["exec"], "/sbin/ip -[46] neigh show": ["exec"], "/sbin/ip -[46] route show table all": ["exec"], "/sbin/ip -[46] rule show": ["exec"], "/sbin/logread": ["stat"], "/sbin/logread -e ^": ["exec"], "/sbin/reboot": ["exec"], "/sbin/sysupgrade --force -k /tmp/firmware.bin": ["exec"], "/sbin/sysupgrade --force -u -k /tmp/firmware.bin": ["exec"], "/sbin/sysupgrade --force -u /tmp/firmware.bin": ["exec"], "/sbin/sysupgrade --force /tmp/firmware.bin": ["exec"], "/sbin/sysupgrade --list-backup": ["exec"], "/sbin/sysupgrade --restore-backup /tmp/backup.tar.gz": ["exec"], "/sbin/sysupgrade --test /tmp/firmware.bin": ["exec"], "/sbin/sysupgrade -k /tmp/firmware.bin": ["exec"], "/sbin/sysupgrade -n --force /tmp/firmware.bin": ["exec"], "/sbin/sysupgrade -n /tmp/firmware.bin": ["exec"], "/sbin/sysupgrade -u -k /tmp/firmware.bin": ["exec"], "/sbin/sysupgrade -u /tmp/firmware.bin": ["exec"], "/sbin/sysupgrade /tmp/firmware.bin": ["exec"], "/sbin/wifi": ["exec"], "/sys/class/net/*/brport/*": ["read"], "/tmp/backup.tar.gz": ["write"], "/tmp/firmware.bin": ["write"], "/tmp/upload.ipk": ["write"], "/usr/bin/arp-scan": ["exec", "list"], "/usr/bin/arping": ["list"], "/usr/bin/btrfsck": ["list"], "/usr/bin/etherwake": ["exec"], "/usr/bin/httping": ["list"], "/usr/bin/lsblk -n -J -do NAME,TRAN,ROTA,RM,VENDOR,MODEL": ["exec"], "/usr/bin/nping": ["list"], "/usr/bin/nslookup": ["exec"], "/usr/bin/ntfsfix": ["list"], "/usr/bin/ping": ["exec"], "/usr/bin/ping6": ["exec", "list"], "/usr/bin/traceroute": ["exec"], "/usr/bin/traceroute6": ["exec", "list"], "/usr/bin/wol": ["exec"], "/usr/lib/opkg/info/netifd.control": ["read"], "/usr/libexec/luci-mwan3 diag * *": ["exec"], "/usr/libexec/luci-mwan3 ipset *": ["exec"], "/usr/libexec/luci-peeraddr": ["exec"], "/usr/libexec/opkg-call install *": ["exec"], "/usr/libexec/opkg-call list-available": ["exec"], "/usr/libexec/opkg-call list-installed": ["exec"], "/usr/libexec/opkg-call remove *": ["exec"], "/usr/libexec/opkg-call update *": ["exec"], "/usr/libexec/opkg-list available": ["exec"], "/usr/libexec/opkg-list installed": ["exec"], "/usr/sbin/e2fsck": ["list"], "/usr/sbin/fsck.f2fs": ["list"], "/usr/sbin/fsck.fat": ["list"], "/usr/sbin/ip6tables": ["list"], "/usr/sbin/ip6tables --line-numbers -w -nvxL -t *": ["exec"], "/usr/sbin/ip6tables -Z": ["exec"], "/usr/sbin/ip6tables-save": ["exec"], "/usr/sbin/iptables --line-numbers -w -nvxL -t *": ["exec"], "/usr/sbin/iptables -Z": ["exec"], "/usr/sbin/iptables-save": ["exec"], "/usr/sbin/logread": ["stat"], "/usr/sbin/logread -e ^": ["exec"], "/usr/sbin/mwan3 ifdown *": ["exec"], "/usr/sbin/mwan3 ifup *": ["exec"], "/usr/sbin/mwan3 internal ipv4": ["exec"], "/usr/sbin/mwan3 internal ipv6": ["exec"], "/usr/sbin/mwan3 status": ["exec"], "/usr/sbin/nft --terse --json list ruleset": ["exec"], "/www/luci-static/resources/view/status/include": ["list"] }, "ubus": { "dsl": ["metrics"], "file": ["read", "write", "list", "remove", "exec", "stat"], "hostapd.*": ["del_client", "wps_start", "wps_cancel", "wps_status"], "iwinfo": ["assoclist", "countrylist", "freqlist", "txpowerlist", "scan", "info"], "luci": ["getConntrackHelpers", "getMountPoints", "setInitAction", "getFeatures", "getSwconfigFeatures", "getSwconfigPortState", "getVersion", "getBuiltinEthernetPorts", "getConntrackList", "getRealtimeStats", "getProcessList", "getInitList", "getLEDs", "getTimezones", "getUSBDevices", "setLocaltime", "setPassword", "getBlockDevices", "setBlockDetect"], "luci-rpc": ["getHostHints", "getBoardJSON", "getNetworkDevices", "getWirelessDevices", "getDHCPLeases", "getDUIDHints"], "luci.upnp": ["get_status", "delete_rule"], "mwan3": ["status"], "network": ["get_proto_handlers"], "network.interface": ["dump"], "network.rrdns": ["lookup"], "session": ["access", "login"], "system": ["board", "info", "validate_firmware_image", "reboot"], "uci": ["changes", "get", "add", "apply", "confirm", "delete", "order", "rename", "set"] }, "uci": { "*": ["read", "write"], "checknet": ["read", "write"], "dhcp": ["read", "write"], "dropbear": ["read", "write"], "etherwake": ["read"], "firewall": ["read", "write"], "fstab": ["read", "write"], "gps": ["read", "write"], "hd-idle": ["read", "write"], "luci": ["read", "write"], "mgmtlanip": ["read", "write"], "mwan3": ["read", "write"], "network": ["read", "write"], "nft-qos": ["read", "write"], "system": ["read", "write"], "udpxy": ["read", "write"], "uhttpd": ["read", "write"], "upnpd": ["read", "write"], "wireless": ["read", "write"] } }, "data": { "username": "root" } }] } root@glinet:~#
# 获取token curl -i -X POST http://192.168.11.1/cgi-bin/luci/rpc/auth --data '{"id":1,"method":"login","params":["root","admin"]}' 回复: HTTP/1.1 200 OK Connection: Keep-Alive Transfer-Encoding: chunked Keep-Alive: timeout=20 content-type: application/json set-cookie: sysauth=8d1b38561b3735ba631328d302c49bdd; path=/cgi-bin/luci cache-control: no-cache expires: 0 x-frame-options: SAMEORIGIN x-xss-protection: 1; mode=block x-content-type-options: nosniff {"id":1,"result":"8d1b38561b3735ba631328d302c49bdd","error":null} # 获取防火墙最后一个重定向(DNAT)规则 curl -s -X POST http://192.168.11.1/cgi-bin/luci/rpc/uci?auth=8d1b38561b3735ba631328d302c49bdd --data '{"id":1,"method":"get_all","params":["firewall","@redirect[-1]"]}' 回复: { "id": 1, "result": { ".name": "cfg143837", ".anonymous": true, "src_dport": "2000", "dest_ip": "192.168.111.202", "dest_port": "2000", "src": "wan", "name": "Forward2000", "dest": "lan", ".type": "redirect", "proto": "tcp", "target": "DNAT" }, "error": null } # 删除防火墙最后一个重定向(DNAT)规则 curl -s -X POST http://192.168.11.1/cgi-bin/luci/rpc/uci?auth=8d1b38561b3735ba631328d302c49bdd --data '{"id":1,"method":"delete","params":["firewall","@redirect[-1]"]}' 回复: { "id": 1, "result": true, "error": null } # 查看防火墙变更但未提交的项 curl -s -X POST http://192.168.11.1/cgi-bin/luci/rpc/uci?auth=8d1b38561b3735ba631328d302c49bdd --data '{"id":1,"method":"changes","params":["firewall"]}' 回复: { "id": 1, "result": [ ["remove", "cfg143837"] ], "error": null } # 丢弃防火墙丢弃未提交的项 curl -s -X POST http://192.168.11.1/cgi-bin/luci/rpc/uci?auth=8d1b38561b3735ba631328d302c49bdd --data '{"id":1,"method":"revert","params":["firewall"]}' 回复: { "id": 1, "result": true, "error": null } # 增加一个防火墙重定向(DNAT)有名规则 openamip-4001 curl -s -X POST http://192.168.11.1/cgi-bin/luci/rpc/uci?auth=8d1b38561b3735ba631328d302c49bdd --data '{"id":1,"method":"section","params":["firewall","redirect","openamip4001",{"name":"Forward4001","target":"DNAT","src":"wan","dest":"lan","proto":"tcp","src_dport":"4001","dest_ip":"192.168.111.202","dest_port":"4001"}]}' 回复: { "id": 1, "result": true, "error": null } # 提交防火墙变更项 curl -s -X POST http://192.168.11.1/cgi-bin/luci/rpc/uci?auth=8d1b38561b3735ba631328d302c49bdd --data '{"id":1,"method":"commit","params":["firewall"]}' 回复: { "id": 1, "result": true, "error": null } # 增加一个防火墙重定向(DNAT)匿名规则 @redirect[-1] root@glinet:~# curl -s -X POST http://192.168.11.1/cgi-bin/luci/rpc/uci?auth=8d1b38561b3735ba631328d302c49bdd --data '{"id":1,"method":"add","params":["firewall","redirect"]}' {"id":1,"result":"cfg163837","error":null} root@glinet:~# root@glinet:~# curl -s -X POST http://192.168.11.1/cgi-bin/luci/rpc/uci?auth=8d1b38561b3735ba631328d302c49bdd --data '{"id":1,"method":"set","params":["firewall","@redirect[-1]","name","Forward8080"]}' {"id":1,"result":true,"error":null} root@glinet:~# root@glinet:~# curl -s -X POST http://192.168.11.1/cgi-bin/luci/rpc/uci?auth=8d1b38561b3735ba631328d302c49bdd --data '{"id":1,"method":"set","params":["firewall","@redirect[-1]","target","DNAT"]}' {"id":1,"result":true,"error":null} root@glinet:~# root@glinet:~# curl -s -X POST http://192.168.11.1/cgi-bin/luci/rpc/uci?auth=8d1b38561b3735ba631328d302c49bdd --data '{"id":1,"method":"set","params":["firewall","@redirect[-1]","src","wan"]}' {"id":1,"result":true,"error":null} root@glinet:~# root@glinet:~# curl -s -X POST http://192.168.11.1/cgi-bin/luci/rpc/uci?auth=8d1b38561b3735ba631328d302c49bdd --data '{"id":1,"method":"set","params":["firewall","@redirect[-1]","dest","lan"]}' {"id":1,"result":true,"error":null} root@glinet:~# root@glinet:~# curl -s -X POST http://192.168.11.1/cgi-bin/luci/rpc/uci?auth=8d1b38561b3735ba631328d302c49bdd --data '{"id":1,"method":"set","params":["firewall","@redirect[-1]","proto","tcp"]}' {"id":1,"result":true,"error":null} root@glinet:~# root@glinet:~# curl -s -X POST http://192.168.11.1/cgi-bin/luci/rpc/uci?auth=8d1b38561b3735ba631328d302c49bdd --data '{"id":1,"method":"set","params":["firewall","@redirect[-1]","src_dport","8080"]}' {"id":1,"result":true,"error":null} root@glinet:~# root@glinet:~# curl -s -X POST http://192.168.11.1/cgi-bin/luci/rpc/uci?auth=8d1b38561b3735ba631328d302c49bdd --data '{"id":1,"method":"set","params":["firewall","@redirect[-1]","dest_ip","192.168.111.202"]}' {"id":1,"result":true,"error":null} root@glinet:~# root@glinet:~# curl -s -X POST http://192.168.11.1/cgi-bin/luci/rpc/uci?auth=8d1b38561b3735ba631328d302c49bdd --data '{"id":1,"method":"set","params":["firewall","@redirect[-1]","dest_port","80"]}' {"id":1,"result":true,"error":null} root@glinet:~# root@glinet:~# curl -s -X POST http://192.168.11.1/cgi-bin/luci/rpc/uci?auth=8d1b38561b3735ba631328d302c49bdd --data '{"id":1,"method":"changes","params":["firewall"]}' {"id":1,"result":[["add","cfg163837","redirect"],["set","cfg163837","name","Forward8080"],["set","cfg163837","target","DNAT"],["set","cfg163837","src","wan"],["set","cfg163837","dest","lan"],["set","cfg163837","proto","tcp"],["set","cfg163837","src_dport","8080"],["set","cfg163837","dest_ip","192.168.111.202"],["set","cfg163837","dest_port","80"]],"error":null} root@glinet:~# root@glinet:~# curl -s -X POST http://192.168.11.1/cgi-bin/luci/rpc/uci?auth=8d1b38561b3735ba631328d302c49bdd --data '{"id":1,"method":"commit","params":["firewall"]}' {"id":1,"result":true,"error":null} root@glinet:~# # 执行命令luci-reload curl -s -X POST http://192.168.11.1/cgi-bin/luci/rpc/sys?auth=8d1b38561b3735ba631328d302c49bdd --data '{"id":1,"method":"exec","params":["luci-reload"]}' 回复: { "id": 1, "result": "", "error": null } # 执行命令 /etc/init.d/network restart curl -s -X POST http://192.168.11.1/cgi-bin/luci/rpc/sys?auth=8d1b38561b3735ba631328d302c49bdd --data '{"id":1,"method":"exec","params":["/etc/init.d/network restart"]}' 回复: { "id": 1, "result": "", "error": null } # 执行命令 nft list chain inet fw4 dstnat_wan curl -s -X POST http://192.168.11.1/cgi-bin/luci/rpc/sys?auth=8d1b38561b3735ba631328d302c49bdd --data '{"id":1,"method":"exec","params":["nft list chain inet fw4 dstnat_wan"]}' 回复: { "id": 1, "result": "table inet fw4 {\u000a\u0009chain dstnat_wan {\u000a\u0009\u0009meta nfproto ipv4 tcp dport 2000 counter packets 0 bytes 0 dnat ip to 192.168.111.202:2000 comment \u0022!fw4: Forward2000\u0022\u000a\u0009\u0009meta nfproto ipv4 tcp dport 4001 counter packets 0 bytes 0 dnat ip to 192.168.111.202:4001 comment \u0022!fw4: Forward4001\u0022\u000a\u0009\u0009meta nfproto ipv4 tcp dport 8080 counter packets 0 bytes 0 dnat ip to 192.168.111.202:80 comment \u0022!fw4: Forward8080\u0022\u000a\u0009\u0009meta nfproto ipv4 fullcone comment \u0022!fw4: Handle wan IPv4 fullcone NAT dstnat traffic\u0022\u000a\u0009}\u000a}\u000a", "error": null } # 执行命令getmwan并获取输出 curl -s -X POST http://192.168.11.1/cgi-bin/luci/rpc/sys?auth=8d1b38561b3735ba631328d302c49bdd --data '{"id":1,"method":"exec","params":["getmwan"]}' 回复: { "id": 1, "result": "[ { \u0022zone\u0022: \u0022wan\u0022, \u0022is_online\u0022: 0, \u0022is_active\u0022: 0, \u0022rssi_lev\u0022: 0 }, { \u0022zone\u0022: \u0022lte1\u0022, \u0022is_online\u0022: 0, \u0022is_active\u0022: 0, \u0022rssi_lev\u0022: -113 }, { \u0022zone\u0022: \u0022lte2\u0022, \u0022is_online\u0022: 0, \u0022is_active\u0022: 0, \u0022rssi_lev\u0022: -113 } ]\u000a", "error": null }
============== End