diff options
| author | Patrick Grimm <patrick@lunatiki.de> | 2023-01-15 10:43:07 +0100 |
|---|---|---|
| committer | Moritz Warning <moritzwarning@web.de> | 2023-01-23 14:25:30 +0100 |
| commit | d27be8dad93d17b80a057389207ffd1d75c5c683 (patch) | |
| tree | 9d978a4be94eec3670b41872bb7c6051789475ac /luci-app-olsrd2/root | |
| parent | c8ba43a99b67b5a56fe2a1a29bc33e9aa2c3a773 (diff) | |
luci-app-olsrd2: New Package for OLSR2 configuration and status visualisation'
Compile tested: mips_24kc, arm_cortex-a9_vfpv3-d16, i386_pentium4, x86_64, i386_pentium-mmx, mipsel_24kc
Signed-off-by: Patrick Grimm <patrick@lunatiki.de>
Diffstat (limited to 'luci-app-olsrd2/root')
6 files changed, 366 insertions, 0 deletions
diff --git a/luci-app-olsrd2/root/etc/config/luci_olsrd2 b/luci-app-olsrd2/root/etc/config/luci_olsrd2 new file mode 100644 index 0000000..9935410 --- /dev/null +++ b/luci-app-olsrd2/root/etc/config/luci_olsrd2 @@ -0,0 +1,3 @@ +config 'olsrd2' 'general' + option 'resolve' '1' + option 'domain' 'olsr' diff --git a/luci-app-olsrd2/root/etc/uci-defaults/41_luci-olsrd2 b/luci-app-olsrd2/root/etc/uci-defaults/41_luci-olsrd2 new file mode 100755 index 0000000..094970a --- /dev/null +++ b/luci-app-olsrd2/root/etc/uci-defaults/41_luci-olsrd2 @@ -0,0 +1,13 @@ +#!/bin/sh + +uci -q batch <<-EOF >/dev/null + delete ucitrack.@olsrd2[-1] + add ucitrack olsrd2 + set ucitrack.@olsrd2[-1].init=olsrd2 + commit ucitrack +EOF + +rm -f /tmp/luci-indexcache +rm -f /tmp/luci-modulecache/* + +exit 0 diff --git a/luci-app-olsrd2/root/lib/functions/olsrd2.sh b/luci-app-olsrd2/root/lib/functions/olsrd2.sh new file mode 100644 index 0000000..b998073 --- /dev/null +++ b/luci-app-olsrd2/root/lib/functions/olsrd2.sh @@ -0,0 +1,61 @@ +# 1: destination variable +# 2: interface +# 3: path +# 4: separator +# 5: limit +__network_ifstatus() { + local __tmp + + [ -z "$__NETWORK_CACHE" ] && { + __tmp="$(ubus call network.interface dump 2>&1)" + case "$?" in + 4) : ;; + 0) export __NETWORK_CACHE="$__tmp" ;; + *) echo "$__tmp" >&2 ;; + esac + } + + __tmp="$(jsonfilter ${4:+-F "$4"} ${5:+-l "$5"} -s "${__NETWORK_CACHE:-{}}" -e "$1=@.interface${2:+[@.interface='$2']}$3")" + + [ -z "$__tmp" ] && \ + unset "$1" && \ + return 1 + + eval "$__tmp" +} + +# 1: addr +# 2: export var neighbour dev lladdr +network_get_neighbour_by_ip() +{ + local __tmp + neighbour='' + dev='' + lladdr='' + local ipaddr="$1" + hostname=$(nslookup "$ipaddr" "$ipaddr" | grep name | cut -d " " -f 3 | cut -d '.' -f -1) + [ -z "$__NEIGH_CACHE" ] && { + __tmp="$(ip -6 neigh)" + export __NEIGH_CACHE="$__tmp" + } + [ -z "$__ROUTE_CACHE" ] && { + __tmp="$(ip -6 route)" + export __ROUTE_CACHE="$__tmp" + } + local gwaddr=$(echo "$__ROUTE_CACHE" | grep "^$ipaddr" | cut -d ' ' -f 3) + [ -z "$gwaddr" ] && return + local neigh=$(echo "$__NEIGH_CACHE" | grep "$gwaddr") + [ -z "$neigh" ] && return + set -- $neigh + eval "neighbour=$1;dev=$3;lladdr=$5" +} + +# 1: destination variable +# 2: addr +network_get_name_by_device() +{ + __network_ifstatus "$1" "" \ + "[@.device='$2' && !@.table].interface" "" 1 && \ + return 0 +} + diff --git a/luci-app-olsrd2/root/usr/libexec/rpcd/status.olsrd2 b/luci-app-olsrd2/root/usr/libexec/rpcd/status.olsrd2 new file mode 100644 index 0000000..fa4d668 --- /dev/null +++ b/luci-app-olsrd2/root/usr/libexec/rpcd/status.olsrd2 @@ -0,0 +1,91 @@ +#!/bin/sh +# Copyright (C) 2016 OpenWrt.org + +. /lib/functions.sh +. /usr/share/libubox/jshn.sh +. /lib/functions/olsrd2.sh + +case "$1" in + list) + json_init + + json_add_object "getVersion" + json_close_object + json_add_object "getLan" + json_close_object + json_add_object "getNode" + json_close_object + json_add_object "getNeighbors" + json_close_object + json_add_object "getAttached_network" + json_close_object + json_add_object "getRoute" + json_close_object + json_add_object "getGraph" + json_close_object + json_add_object "getDomain" + json_close_object + + json_dump + ;; + call) + case "$2" in + getVersion) + echo '/systeminfo json version /quit' | nc ::1 2009 2>/dev/null + ;; + getLan) + echo '/olsrv2info json lan /quit' | nc ::1 2009 2>/dev/null + ;; + getNode) + echo '/olsrv2info json node /quit' | nc ::1 2009 2>/dev/null + ;; + getNeighbors) + domain="$(uci_get luci_olsr2 general domain)" + [ -z "$domain" ] || domain=".$domain" + json_init + json_add_array "neighbors" + OLDIFS="$IFS" + IFS=$'\n' + neighbor_status="$(echo '/nhdpinfo neighbor /quit' | nc ::1 2009 | cut -f 1,9,10,11,12)" + for neighbor in $neighbor_status; do + json_add_object 0 + IFS="$OLDIFS" + i=1 + for value in $neighbor ; do + case $i in + 1) json_add_string "originator" "${value}" + network_get_neighbour_by_ip "${value}" + json_add_string "lladdr" "${lladdr}" + json_add_string "hostname" "${hostname}${domain}" + network_get_name_by_device interface $dev + json_add_string "interface" "${interface}" + ;; + 2) json_add_string "metric_in" "${value}";; + 3) json_add_string "metric_in_raw" "${value}";; + 4) json_add_string "metric_out" "${value}";; + 5) json_add_string "metric_out_raw" "${value}";; + esac + i=$(( i + 1 )) + done + IFS=$'\n' + json_close_object + done + IFS="$OLDIFS" + json_close_array + json_dump + ;; + getAttached_network) + echo '/olsrv2info json attached_network /quit' | nc ::1 2009 2>/dev/null + ;; + getRoute) + echo '/netjsoninfo filter route ipv6_0' | nc ::1 2009 2>/dev/null + ;; + getGraph) + echo '/netjsoninfo filter graph ipv6_0' | nc ::1 2009 2>/dev/null + ;; + getDomain) + echo '/netjsoninfo domain' | nc ::1 2009 2>/dev/null + ;; + esac + ;; +esac diff --git a/luci-app-olsrd2/root/usr/share/luci/menu.d/luci-app-olsrd2.json b/luci-app-olsrd2/root/usr/share/luci/menu.d/luci-app-olsrd2.json new file mode 100644 index 0000000..ab45e72 --- /dev/null +++ b/luci-app-olsrd2/root/usr/share/luci/menu.d/luci-app-olsrd2.json @@ -0,0 +1,171 @@ +{ + "admin/services/olsrd2": { + "title": "OLSRD2", + "action": { + "type": "firstchild" + }, + "depends": { + "acl": [ "luci-app-olsrd2" ] + } + }, + "admin/services/olsrd2/global": { + "title": "Global", + "order": 1, + "action": { + "type": "view", + "path": "olsrd2/global" + } + }, + "admin/services/olsrd2/log": { + "title": "Logging", + "order": 2, + "action": { + "type": "view", + "path": "olsrd2/log" + } + }, + "admin/services/olsrd2/olsrv2": { + "title": "Daemon", + "order": 3, + "action": { + "type": "view", + "path": "olsrd2/olsrv2" + } + }, + "admin/services/olsrd2/olsrv2_lan": { + "title": "Prefix", + "order": 4, + "action": { + "type": "view", + "path": "olsrd2/olsrv2_lan" + } + }, + "admin/services/olsrd2/domain": { + "title": "Domain", + "order": 5, + "action": { + "type": "view", + "path": "olsrd2/domain" + } + }, + "admin/services/olsrd2/mesh": { + "title": "Mesh", + "order": 6, + "action": { + "type": "view", + "path": "olsrd2/mesh" + } + }, + "admin/services/olsrd2/lan_import": { + "title": "LAN Import", + "order": 7, + "action": { + "type": "view", + "path": "olsrd2/lan_import" + } + }, + "admin/services/olsrd2/interface": { + "title": "Interface", + "order": 8, + "action": { + "type": "view", + "path": "olsrd2/interface" + } + }, + "admin/services/olsrd2/luci": { + "title": "LUCI", + "order": 8, + "action": { + "type": "view", + "path": "olsrd2/luci" + } + }, + "admin/status/olsrd2": { + "title": "OLSRD2", + "action": { + "type": "firstchild" + } + }, + "admin/status/olsrd2/overview": { + "title": "Overview", + "order": 1, + "action": { + "type": "view", + "path": "olsrd2/overview" + } + }, + "admin/status/olsrd2/node": { + "title": "Nodes", + "order": 2, + "action": { + "type": "view", + "path": "olsrd2/node" + } + }, + "admin/status/olsrd2/attachednetwork": { + "title": "Attachednetwork", + "order": 3, + "action": { + "type": "view", + "path": "olsrd2/attachednetwork" + } + }, + "admin/status/olsrd2/neighbors": { + "title": "Neighbors", + "order": 4, + "action": { + "type": "view", + "path": "olsrd2/neighbors" + } + }, + "public/status": { + "title": "Status", + "order": 10, + "action": { + "type": "firstchild", + "recurse": true + }, + "auth": {} + }, + "public/status/olsrd2": { + "title": "OLSRD2", + "order": 20, + "action": { + "type": "firstchild", + "recurse": true + }, + "auth": {} + }, + "public/status/olsrd2/overview": { + "title": "Overview", + "order": 4, + "action": { + "type": "view", + "path": "olsrd2/overview" + } + }, + "public/status/olsrd2/node": { + "title": "Nodes", + "order": 2, + "action": { + "type": "view", + "path": "olsrd2/node" + } + }, + "public/status/olsrd2/attachednetwork": { + "title": "Attachednetwork", + "order": 3, + "action": { + "type": "view", + "path": "olsrd2/attachednetwork" + } + }, + "public/status/olsrd2/neighbors": { + "title": "Neighbors", + "order": 1, + "action": { + "type": "view", + "path": "olsrd2/neighbors" + } + } +} diff --git a/luci-app-olsrd2/root/usr/share/rpcd/acl.d/luci-app-olsrd2.json b/luci-app-olsrd2/root/usr/share/rpcd/acl.d/luci-app-olsrd2.json new file mode 100644 index 0000000..61e8691 --- /dev/null +++ b/luci-app-olsrd2/root/usr/share/rpcd/acl.d/luci-app-olsrd2.json @@ -0,0 +1,27 @@ +{ + "unauthenticated": { + "description": "Allow system feature probing", + "read": { + "file": { + "/www/luci-static/resources/view/olsrd2": [ "list" ] + }, + "ubus": { + "status.olsrd2": [ "getVersion", "getLan", "getNode", "getNeighbors", "getAttached_network" ], + "file": [ "list" ] + + } + } + }, + "luci-app-olsrd2": { + "description": "Grant UCI access for luci-app-olsrd2", + "read": { + "uci": [ "olsrd2" ], + "ubus": { + "status.olsrd2": [ "getVersion", "getLan", "getNode", "getNeighbors", "getAttached_network" ] + } + }, + "write": { + "uci": [ "olsrd2" ] + } + } +} |
