Commit 65f721fb authored by Sukru Senli's avatar Sukru Senli

remove juci.* ubus objects; each module brings its own object or info available via usp object

parent 3af0b1d8
#!/bin/sh
# Cgroup documentation found at at
# https://github.com/torvalds/linux/blob/master/Documentation/cgroup-v1
. /usr/share/libubox/jshn.sh
non_setter_vars="
memory.usage_in_bytes
memory.memsw.usage_in_bytes
memory.failcnt
memory.memsw.failcnt
memory.max_usage_in_bytes
memory.memsw.max_usage_in_bytes
memory.stat
memory.numa_stat
memory.kmem.usage_in_bytes
memory.kmem.failcnt
memory.kmem.max_usage_in_bytes
memory.kmem.tcp.usage_in_bytes
memory.kmem.tcp.failcnt
memory.kmem.tcp.max_usage_in_bytes
tasks
cgroup.procs
cgroup.event_control
"
is_setter_var="0"
check_if_setter_var () {
is_setter_var=1
for v in $non_setter_vars; do
if [ "$v" == "$1" ]; then
is_setter_var="0"
fi
done
}
case "$1" in
list)
echo '{ "knobs": {"cgroup":"str"}, "procs": {} }'
;;
call)
case "$2" in
knobs)
read input;
json_load "$input"
json_get_var cgroup cgroup
json_init
json_add_array knobs
for var in $(ls /sys/fs/cgroup/$cgroup -p | grep -v /); do
check_if_setter_var "$var"
if [ "$is_setter_var" == "1" ]; then
json_add_string "" "$var"
fi
done
json_dump
;;
procs)
json_init
json_add_array procs
for i in $(cat /proc/*/stat 2>/dev/null | grep -o "(.*)" | tr -d '()'); do
json_add_string "" "$i"
done
json_dump
;;
esac
;;
esac
#!/bin/sh
. /usr/share/libubox/jshn.sh
PROVIDERS_FILE="/etc/ddns/services"
PROVIDERS6_FILE="/etc/ddns/services_ipv6"
case "$1" in
list)
echo '{ "providers" : {}, "providers_ipv6" : {}, "status": { "service": "Str" } }'
;;
call)
case "$2" in
providers)
json_init
json_add_array "providers"
for service in $(cat $PROVIDERS_FILE | awk '{print$1}' | grep -v "#" | tr -d '"'); do
json_add_string "" "$service"
done
json_dump
;;
providers_ipv6)
json_init
json_add_array "providers"
for service in $(cat $PROVIDERS6_FILE | awk '{print$1}' | grep -v "#" | tr -d '"'); do
json_add_string "" "$service"
done
json_dump
;;
status)
input=""
service=""
read input
json_load "$input"
json_get_var service service
[ "$service" ] || exit 5
file="/var/log/ddns/${service}.log"
pid_line=$(ps -w | grep dynami[c] | grep -w "$service")
[ $? -eq 0 ] && running=1 || running=0
pid=$(echo $pid_line | awk '{ print $1}')
[ -z "$pid" ] && pid=$(cat $file | awk -F "'" '/WARN : PID.*exit WITH ERROR/ {print $2}' | tail -1)
json_init
json_add_boolean "running" $running
content=$(cat $file | awk "/PID '$pid' /{y=1;next}y")
IFS=$'\n'
if [ "$content" ]; then
reload_time=$(echo "$content" | awk '/Waiting [0-9]* seconds/ {i=$4} END {print i}')
last_reload=$(echo "$content" | awk -F 'at ' '/info : [RS]/ {i=$2} END {print i}')
if [ "$reload_time" -a "$last_reload" ]; then
last_reload=$(date -d "$last_reload" +%s)
cur_time="$(date +%s)"
if [ "$last_reload" -a "$cur_time" ]; then
diff=$((cur_time - last_reload))
time_left=$((reload_time - diff))
[ $time_left -lt 0 ] && time_left=0
fi
fi
time_left=${time_left-0}
json_add_int "next_update" $time_left
ERRORS=$(echo "$content" | awk -F ':' '/ERROR/ {print $2}' | sort -u)
WARNINGS=$(echo "$content" | awk -F ':' '/WARN/ {print $2}' | sort -u)
[ "$ERRORS" ] && {
json_add_array "errors"
for er in $ERRORS; do
json_add_string "" "${er##[ ]}"
done
json_select ..
}
[ "$WARNINGS" ] && {
json_add_array "warnings"
for er in $WARNINGS; do
json_add_string "" "${er##[ ]}"
done
json_select ..
}
fi
json_dump
esac
;;
esac
#!/bin/sh
. /usr/share/libubox/jshn.sh
. /lib/functions.sh
is_num() {
[ "$1" == "" ] && return 1
[ "$(echo $1 | sed 's/[0-9]//g')" == "" ] && return 0 || return 1
}
validate_ping_traceroute() {
host="$1"
seq="$2"
count="$3"
timeout="$4"
[ "$host" == "" ] && return 1
is_num $seq || return 1
is_num $count || return 1
is_num $timeout || return 1
return 0
}
validate_arguments_tptest() {
host="$1"
testmode="$2"
packetsize_up="$3"
packetsize_down="$4"
port="$5"
auto="$6"
is_num $port || return 1
[ "$host" == "" ] && return 1
case $testmode in
up|down|up_down);;
*) return 1 ;;
esac
if [ "$auto" == "0" ]; then
case $testmode in
*up*)
is_num $packetsize_up || return 1
;;
esac
case $testmode in
*down*)
is_num $packetsize_down || return 1
;;
esac
elif [ "$auto" == "1" ]; then
return 0;
else
return 1
fi
}
run_cmd() {
CMND=$1
input=$2
read input;
json_load "$input"
json_get_var host host
json_init
json_add_string stdout "$($CMND $host)"
json_dump
}
ifaces="ethernet vdsl adsl"
get_packet_sizes () {
option="$1"
packetsizes=$(uci -q get speedtest.@packetsize[0].$option)
if [ "$packetsizes" ]; then
packetsize_down=${packetsizes%/*}
packetsize_up=${packetsizes#*/}
else
case "$option" in
ethernet)
packetsize_up=10
packetsize_down=100
;;
vdsl)
packetsize_up=5
packetsize_down=50
;;
adsl)
packetsize_up=1
packetsize_down=10
;;
*)
packetsize_up=1
packetsize_down=10
esac
fi
}
get_iface () {
iface=$(ip route | awk '/default via/{print $5}')
case "$iface" in
eth*)
iface="ethernet"
;;
atm*)
iface="adsl"
;;
ptm*)
iface="vdsl"
;;
wwan*)
iface="vdsl"
;;
br-*)
iface="ethernet"
;;
*)
iface="ethernet"
esac
}
input=""
case "$1" in
list)
echo '{ "ping" : {"host":"str", "seq":32, "count":32, "timeout":32},
"ping6" : {"host":"str", "seq":32, "count":32, "timeout":32},
"traceroute" : {"host":"str", "seq":32, "querycount":32, "timeout":32},
"traceroute6" : {"host":"str", "seq":32, "querycount":32, "timeout":32},
"tptest_start" : {"seq":32, "auto": true, "testmode":"str","packetsize_up":32,"packetsize_down":32,"host":"str","port":32},
"tptest_stop" : {},
"tptest_packet_size" : {},
"tptest_running": {} }'
;;
call)
case "$2" in
ping|ping6)
cmd=$2
host=""
seq=""
count=""
timeout=""
read input
json_load "$input"
json_get_var host host
json_get_var seq seq 0
json_get_var count count 1
json_get_var timeout timeout 1
validate_ping_traceroute $host $seq $count $timeout && {
diagnostics -U -s $seq -C $cmd -h $host -c $count -W $timeout >/dev/null 2>&1 &
json_init
json_add_string "state" "running"
json_add_string "message" "success"
json_dump
} || {
json_init
json_add_string "state" "error"
json_add_string "message" "invalid arguments"
json_dump
}
;;
traceroute|traceroute6)
cmd=$2
host=""
seq=""
count=""
timeout=""
read input
json_load "$input"
json_get_var host host
json_get_var seq seq 0
json_get_var count count 1
json_get_var timeout timeout 1
validate_ping_traceroute $host $seq $count $timeout && {
diagnostics -U -s $seq -C $cmd -h $host -q $count -w $timeout >/dev/null 2>&1 &
json_init
json_add_string "state" "running"
json_add_string "message" "success"
json_dump
} || {
json_init
json_add_string "state" "error"
json_add_string "message" "invalid arguments"
json_dump
}
;;
tptest_start)
host=""
seq=""
testmode=""
packetsize_up=""
packetsize_down=""
port=""
auto=""
read input
json_load "$input"
json_get_var host host ""
json_get_var seq seq 1
json_get_var testmode testmode "up_down"
json_get_var packetsize_up packetsize_up 50000
json_get_var packetsize_down packetsize_down 50000
json_get_var port port 0
json_get_var auto auto 1
validate_arguments_tptest "$host" "$testmode" "$packetsize_up" "$packetsize_down" "$port" "$auto" && {
if [ $auto -eq 1 ]; then
diagnostics -U -s $seq -C tptest -a -t $testmode -h $host -p $port >/dev/null 2>&1 &
else
diagnostics -U -s $seq -C tptest -u $packetsize_up -d $packetsize_down -t $testmode -h $host -p $port >/dev/null 2>&1 &
fi
json_init
json_add_string "state" "running"
json_add_string "message" "success"
json_dump
} || {
json_init
json_add_string "state" "error"
json_add_string "message" "invalid arguments"
json_dump
}
;;
tptest_stop)
killall -9 diagnostics >/dev/null 2>&1
killall -9 tptest >/dev/null 2>&1
json_init
json_add_string "state" "aborted"
json_add_string "message" "success"
json_dump
;;
tptest_running)
json_init
seqs="$(ps -w | awk '/diagnostic[s].*-C tptest/ { print $10 }' | sort -u)"
if [ "$seqs" == "" ]; then
json_add_string "message" "Not running"
json_add_boolean "running" 0
json_dump
exit
else
json_add_string "message" "Running"
json_add_boolean "running" 1
fi
json_add_array "sequence numbers"
for s in $seqs; do
json_add_int "" $s
done
json_close_array
json_dump
;;
tptest_packet_size)
get_iface
for i in $ifaces; do
if [ $iface == "$i" ]; then
get_packet_sizes $iface
json_init
json_add_string "packetsize_up" "$packetsize_up"
json_add_string "packetsize_down" "$packetsize_down"
json_dump
return
fi
done
;;
*) return 1 ;;
esac
;;
esac
#!/bin/sh
. /usr/share/libubox/jshn.sh
. /lib/functions.sh
case "$1" in
list)
echo '{ "excluded_ports" : {} }'
;;
call)
case "$2" in
excluded_ports)
json_init
json_add_string result "$(cat /tmp/fw_used_ports 2>/dev/null)"
json_dump
;;
esac
;;
esac
#!/bin/sh
. /usr/share/libubox/jshn.sh
case "$1" in
list)
echo '{ "status": {} }'
;;
call)
case "$2" in
status)
json_init
output=`netstat -lpan | grep ice`
xmpp_client=":5223"
cloudAuth=`grep -c "cloudfriends_authenticated=false" /etc/iopsys/server.ini`
if [ `echo $output | grep $xmpp_client | grep -c ESTABLISHED` -gt 0 -a $cloudAuth -eq 0 ]; then
json_add_string status "Registered"
elif [ `echo $output | grep -c $xmpp_client` -gt 0 -a $cloudAuth -gt 0 ]; then
json_add_string status "Unregistered"
elif [ `echo $output | grep -c $xmpp_client` -eq 0 ]; then
json_add_string status "Offline"
else
json_add_string status "Undefined"
fi
json_dump
;;
esac
;;
esac
#!/bin/sh
. /usr/share/libubox/jshn.sh
case "$1" in
list)
echo '{ "backup" : {"filename":"str"} }'
;;
call)
case "$2" in
backup)
read input
json_load "$input"
json_get_var filename filename
if [ -n "$filename" ]; then
filename="/tmp/juci/$filename"
else
filename="/tmp/juci/iup-backup.tmp"
fi
json_init
json_add_string stdout "$(sysupgrade -u $filename)"
json_dump
;;
esac
;;
esac
#!/bin/sh
. /lib/functions.sh
. /usr/share/libubox/jshn.sh
case "$1" in
list)
echo '{ "press" : {"name":"str", "long":true}}'
;;
call)
case "$2" in
press)
read input
json_load "$input"
json_get_var name name ""
json_get_var long long "false"
isbutton=0
pressed=0
[ -n "$name" -a "$(uci -q get buttons.$name)" == "button" ] && isbutton=1
if [ $isbutton -eq 1 ]; then
config_load buttons
[ "$long" == "true" ] && hotplug="hotplug_long" || hotplug="hotplug"
config_get interface $name $hotplug
if [ -n "$interface" ]; then
ACTION=add INTERFACE=$interface /sbin/hotplug-call button >/dev/null 2>&1 &
pressed=1
fi
fi
json_init
json_add_boolean "pressed" $pressed
json_dump
;;
esac
;;
esac
#!/bin/sh
. /usr/share/libubox/jshn.sh
service_list() {
ubus call service list
}
handle_service() {
local action=$1
local service=$2
json_init
if [ -f /etc/init.d/$service ]; then
/etc/init.d/$service $action >/dev/null 2>&1 &
json_add_string success "$name $action"
else
json_add_string error "Invalid service!"
fi
json_dump
}
service_status() {
ubus call service list
}
case "$1" in
list)
echo '{ "list" : {}, "start" : {"name":"str"}, "stop" : {"name":"str"}, "enable" : {"name":"str"}, "disable" : {"name":"str"}, "reload" : {"name":"str"}, "restart" : {"name":"str"}, "status" : {"name":"str"} }'
;;
call)
case "$2" in
list)
enabled=0
running=0
start=0
json_init
json_add_array "services"
for serv in $(ls /etc/init.d/); do
ubus -q 1 call service list "{'name':'$serv'}" | grep -q '"running": true,' >/dev/null
[ $? -eq 0 ] && running=1 || running=0
output=$(ls /etc/rc.d/S*$serv 2>/dev/null)
[ $? -eq 0 ] && enabled=1 || enabled=0
start=${output##/etc/rc.d/S}
start=${start%%$serv}
json_add_object ""
json_add_string name $serv
json_add_boolean enabled $enabled
json_add_boolean running $running
json_add_int start $start
json_select ..
done
json_dump
;;
start|stop|enable|disable|reload|restart)
read input
json_load "$input"
json_get_var name name
[ -n "$name" ] && handle_service $2 $name
;;
status)
running=0
read input
json_load "$input"
json_get_var name name
running=$(ubus -t 1 call service list "{'name':'$name'}" | grep running | grep -q true && echo 1 || echo 0)
json_init
json_add_boolean running $running
json_dump
;;
esac
;;
esac
This diff is collapsed.
#!/bin/sh
. /usr/share/libubox/jshn.sh
. /lib/functions.sh
is_num() {
[ "$1" == "" ] && return 1
[ "$(echo $1 | sed 's/[0-9]//g')" == "" ] && return 0 || return 1
}
validate_arguments_ndttest() {
testmode="$1"
geoserver="$2"
[ "$geoserver" == "" ] && return 1
case $testmode in
up|down|up_down);;
*) return 1 ;;
esac
return 0;
}
input=""
case "$1" in
list)
echo '{ "ndttest_start" : {"seq":32, "testmode":"str","geoserver":"str"},
"ndttest_stop" : {},
"ndttest_running": {} }'
;;
call)
case "$2" in
ndttest_start)
host=""
seq=""
testmode=""
geoserver=""
auto=""
read input
json_load "$input"
json_get_var host host ""
json_get_var seq seq 1
json_get_var testmode testmode "up_down"
json_get_var geoserver geoserver "auto"
validate_arguments_ndttest "$testmode" "$geoserver" && {
diagnostics -U -s $seq -C ndttest -t $testmode -g $geoserver >/dev/null 2>&1 &
json_init
json_add_string "state" "running"
json_add_string "message" "success"
json_dump
} || {
json_init
json_add_string "state" "error"
json_add_string "message" "invalid arguments"
json_dump
}
;;
ndttest_stop)
killall -9 diagnostics >/dev/null 2>&1
killall -9 web100clt >/dev/null 2>&1
json_init
json_add_string "state" "aborted"
json_add_string "message" "success"
json_dump
;;
ndttest_running)
json_init
seqs="$(ps -w | awk '/diagnostic[s].*-C ndttest/ { print $10 }' | sort -u)"
if [ "$seqs" == "" ]; then
json_add_string "message" "Not running"
json_add_boolean "running" 0
json_dump
exit
else
json_add_string "message" "Running"
json_add_boolean "running" 1
fi
json_add_array "sequence numbers"
for s in $seqs; do
json_add_int "" $s
done
json_close_array
json_dump
;;
*) return 1 ;;
esac
;;
esac
#!/bin/sh
. /usr/share/libubox/jshn.sh
OVPN="/etc/openvpn/openvpn.ovpn"
case "$1" in
list)
echo '{ "get_config" : {