Skip to content

Commit

Permalink
treewide: make fmt
Browse files Browse the repository at this point in the history
Signed-off-by: Packet Please <[email protected]>
  • Loading branch information
pktpls committed Apr 6, 2024
1 parent 57c0aff commit d60a115
Show file tree
Hide file tree
Showing 36 changed files with 455 additions and 467 deletions.
7 changes: 5 additions & 2 deletions luci/luci-app-falter-owm/files/owm-defaults
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#!/bin/sh
test -f /etc/crontabs/root || touch /etc/crontabs/root
OWM="/usr/sbin/owm.sh"
SEED="$( dd if=/dev/urandom bs=2 count=1 2>&- | hexdump | if read -r line; then echo "0x${line#* }"; fi )"
SEED="$(dd if=/dev/urandom bs=2 count=1 2>&- | hexdump | if read -r line; then echo "0x${line#* }"; fi)"
MIN1="$((SEED % 29))"
MIN2="$((MIN1 + 30))"
(crontab -l | grep -v "$OWM"; echo "$MIN1,$MIN2 * * * * test -e $OWM && $OWM") | crontab -
(
crontab -l | grep -v "$OWM"
echo "$MIN1,$MIN2 * * * * test -e $OWM && $OWM"
) | crontab -
197 changes: 94 additions & 103 deletions luci/luci-app-falter-owm/files/owm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
# Copyright (C) 2021 Patrick Grimm
# Copyright (C) 2021 Martin Hübner


# Omit warning for missing local statement. busybox-ash has them included
# shellcheck shell=dash

Expand All @@ -32,7 +31,7 @@
OWM_API_VER="1.0"

printhelp() {
printf "owm.sh - Tool for registering routers at openwifimap.net\n
printf "owm.sh - Tool for registering routers at openwifimap.net\n
Options:
\t--help|-h:\tprint this text
Expand All @@ -52,12 +51,11 @@ To override the server used by this script, set freifunk.community.owm_api.
# save positional argument, as it would get overwritten otherwise.
CMD_1="$1"
if [ -n "$CMD_1" ] && [ "$CMD_1" != "--dry-run" ]; then
[ "$CMD_1" != "-h" ] && [ "$CMD_1" != "--help" ] && printf "Unrecognized argument %s.\n\n" "$CMD_1"
printhelp
exit 1
[ "$CMD_1" != "-h" ] && [ "$CMD_1" != "--help" ] && printf "Unrecognized argument %s.\n\n" "$CMD_1"
printhelp
exit 1
fi


# calback function: This function aggregates all items of the 'contact'
# option list from /etc/config/freifunk into one single string for better
# transport
Expand All @@ -69,25 +67,24 @@ handle_contact() {
fi
}


######################
# #
# Collect OWM-Data #
# #
######################

olsr4_links() {
json_select "$2"
json_get_var localIP localIP
json_get_var remoteIP remoteIP
remotehost="$(nslookup "$remoteIP" | grep name | sed -e 's/.*name = \(.*\)/\1/' | sed 's/^mid\d*\.//' )"
json_get_var linkQuality linkQuality
json_get_var olsrInterface olsrInterface
json_get_var ifName ifName
json_select ..
if ! echo "$olsrInterface" | grep -q -E '.*(wg|ts)_.*'; then
olsr4links="$olsr4links$localIP $remoteIP $remotehost $linkQuality $ifName;"
fi
json_select "$2"
json_get_var localIP localIP
json_get_var remoteIP remoteIP
remotehost="$(nslookup "$remoteIP" | grep name | sed -e 's/.*name = \(.*\)/\1/' | sed 's/^mid\d*\.//')"
json_get_var linkQuality linkQuality
json_get_var olsrInterface olsrInterface
json_get_var ifName ifName
json_select ..
if ! echo "$olsrInterface" | grep -q -E '.*(wg|ts)_.*'; then
olsr4links="$olsr4links$localIP $remoteIP $remotehost $linkQuality $ifName;"
fi
}

# This section is relevant for hopglass statistics feature (isUplink/isHotspot)
Expand All @@ -102,21 +99,19 @@ latitude="$(uci_get system @system[-1] latitude)"
# Stop execution if lat/lon is not set.
#
if [ -z "$latitude" ] || [ -z "$longitude" ]; then
printf "latitude/longitude is not set.\nStopping now...\n"
exit 2
printf "latitude/longitude is not set.\nStopping now...\n"
exit 2
fi


# collect data on OLSR-links
json_load "$( printf "/links" | nc 127.0.0.1 9090 2>/dev/null)" 2>/dev/null
json_load "$(printf "/links" | nc 127.0.0.1 9090 2>/dev/null)" 2>/dev/null
#json_get_var timeSinceStartup timeSinceStartup
olsr4links=""
if json_is_a links array;then
json_for_each_item olsr4_links links
if json_is_a links array; then
json_for_each_item olsr4_links links
fi
json_cleanup


# collect board info
json_load "$(ubus call system board)"
json_get_var model model
Expand All @@ -133,10 +128,10 @@ json_get_values loads load

# if file freifunk_release is available, override version and revision
if [ -f /etc/freifunk_release ]; then
. /etc/freifunk_release
distribution="$FREIFUNK_DISTRIB_ID"
version="$FREIFUNK_RELEASE"
revision="$FREIFUNK_REVISION"
. /etc/freifunk_release
distribution="$FREIFUNK_DISTRIB_ID"
version="$FREIFUNK_RELEASE"
revision="$FREIFUNK_REVISION"
fi

# Get Sysload
Expand Down Expand Up @@ -165,7 +160,6 @@ config_list_foreach contact contact handle_contact
# omit the first pipe-symbol.
contacts=$(echo "$CONTACT_AGGREGATOR" | sed 's/|//')


# community info
ssid="$(uci_get freifunk community ssid)"
mesh_network="$(uci_get freifunk community mesh_network)"
Expand All @@ -178,8 +172,6 @@ com_ssid_scheme=$(uci_get freifunk community ssid_scheme)
com_splash_network=$(uci_get freifunk community splash_network)
com_splash_prefix=$(uci_get freifunk community splash_prefix)



###########################
# #
# Construct JSON-string #
Expand All @@ -189,36 +181,36 @@ com_splash_prefix=$(uci_get freifunk community splash_prefix)
json_init
json_add_object freifunk
{
json_add_object contact
{
if [ -n "$name" ]; then json_add_string name "$name"; fi
# contact list superseeds the use of mail option
if [ -n "$contacts" ]; then
json_add_string mail "$contacts"
else
if [ -n "$mail" ]; then json_add_string mail "$mail"; fi
fi
if [ -n "$nick" ]; then json_add_string nickname "$nick"; fi
if [ -n "$phone" ]; then json_add_string phone "$phone"; fi
if [ -n "$homepage" ]; then json_add_string homepage "$homepage"; fi # was array of homepages
if [ -n "$note" ]; then json_add_string note "$note"; fi
}
json_close_object

json_add_object community
{
json_add_string ssid "$ssid"
json_add_string mesh_network "$mesh_network"
json_add_string owm_api "$uci_owm_api"
json_add_string name "$com_name"
json_add_string homepage "$com_homepage"
json_add_string longitude "$com_longitude"
json_add_string latitude "$com_latitude"
json_add_string ssid_scheme "$com_ssid_scheme"
json_add_string splash_network "$com_splash_network"
json_add_int splash_prefix $com_splash_prefix
}
json_close_object
json_add_object contact
{
if [ -n "$name" ]; then json_add_string name "$name"; fi
# contact list superseeds the use of mail option
if [ -n "$contacts" ]; then
json_add_string mail "$contacts"
else
if [ -n "$mail" ]; then json_add_string mail "$mail"; fi
fi
if [ -n "$nick" ]; then json_add_string nickname "$nick"; fi
if [ -n "$phone" ]; then json_add_string phone "$phone"; fi
if [ -n "$homepage" ]; then json_add_string homepage "$homepage"; fi # was array of homepages
if [ -n "$note" ]; then json_add_string note "$note"; fi
}
json_close_object

json_add_object community
{
json_add_string ssid "$ssid"
json_add_string mesh_network "$mesh_network"
json_add_string owm_api "$uci_owm_api"
json_add_string name "$com_name"
json_add_string homepage "$com_homepage"
json_add_string longitude "$com_longitude"
json_add_string latitude "$com_latitude"
json_add_string ssid_scheme "$com_ssid_scheme"
json_add_string splash_network "$com_splash_network"
json_add_int splash_prefix $com_splash_prefix
}
json_close_object
}
json_close_object

Expand All @@ -229,51 +221,51 @@ json_add_double api_rev $OWM_API_VER

json_add_object system
{
json_add_array sysinfo
{
json_add_string "" "system is deprecated"
json_add_string "" "$model"
}
json_close_array
json_add_array uptime
{
json_add_int "" $uptime
}
json_close_array
json_add_array loadavg
{
json_add_double "" $load5
}
json_close_array
json_add_array sysinfo
{
json_add_string "" "system is deprecated"
json_add_string "" "$model"
}
json_close_array
json_add_array uptime
{
json_add_int "" $uptime
}
json_close_array
json_add_array loadavg
{
json_add_double "" $load5
}
json_close_array
}
json_close_object

# OLSR-Config
# That string gets substituted by the olsrd-config-string afterwards
json_add_object olsr
{
json_add_string ipv4Config '$OLSRCONFIG'
json_add_string ipv4Config '$OLSRCONFIG'
}
json_close_object

json_add_array links
{
IFSORIG="$IFS"
IFS=';'
for i in ${olsr4links} ; do
IFS="$IFSORIG"
set -- $i
json_add_object
{
json_add_string sourceAddr4 "$1"
json_add_string destAddr4 "$2"
json_add_string id "$3"
json_add_double quality "$4"
}
json_close_object
IFS=';'
done
IFS="$IFSORIG"
IFSORIG="$IFS"
IFS=';'
for i in ${olsr4links}; do
IFS="$IFSORIG"
set -- $i
json_add_object
{
json_add_string sourceAddr4 "$1"
json_add_string destAddr4 "$2"
json_add_string id "$3"
json_add_double quality "$4"
}
json_close_object
IFS=';'
done
IFS="$IFSORIG"
}
json_close_array

Expand All @@ -287,26 +279,25 @@ json_add_int updateInterval 3600
json_add_string hardware "$system"
json_add_object firmware
{
json_add_string name "$distribution $version"
json_add_string revision "$revision"
json_add_string kernelVersion "$kernelVersion"
json_add_string kernelBuildDate "$buildDate"
json_add_string name "$distribution $version"
json_add_string revision "$revision"
json_add_string kernelVersion "$kernelVersion"
json_add_string kernelBuildDate "$buildDate"
}
json_close_object

json_close_object

JSON_STRING=$(json_dump)
# insert json-string from OLSR and repair wrong syntax at string-borders (shell-quotes...)
JSON_STRING=$(echo "$JSON_STRING" | sed -e 's|$OLSRCONFIG|'"$OLSRCONFIG"'|; s|"{|{|; s|}"|}|' )
JSON_STRING=$(echo "$JSON_STRING" | sed -e 's|$OLSRCONFIG|'"$OLSRCONFIG"'|; s|"{|{|; s|}"|}|')

# just print data to stdout, if we have test-run.
if [ "$CMD_1" = "--dry-run" ]; then
printf "%s\n" "$JSON_STRING"
exit 0
printf "%s\n" "$JSON_STRING"
exit 0
fi


################################
# #
# Send data to openwifimap #
Expand Down
24 changes: 12 additions & 12 deletions luci/luci-app-ffwizard-falter/root/usr/libexec/rpcd/ffwizard-berlin
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
. /usr/share/libubox/jshn.sh

case "$1" in
list)
echo '{ "has_root-pass": {} }'
;;
call)
case "$2" in
has_root-pass)
USER=root
# taken from http://serverfault.com/a/240961
grep ${USER} /etc/shadow | awk -F":" '{ if ($2 == "!" || $2 == "") \
list)
echo '{ "has_root-pass": {} }'
;;
call)
case "$2" in
has_root-pass)
USER=root
# taken from http://serverfault.com/a/240961
grep ${USER} /etc/shadow | awk -F":" '{ if ($2 == "!" || $2 == "") \
printf "{ \"password_is_set\" : \"no\" }";\
else \
printf "{ \"password_is_set\" : \"yes\" }"\
}'
;;
esac
;;
;;
esac
;;
esac
2 changes: 1 addition & 1 deletion packages/falter-berlin-admin-keys/files/register_keys.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ KEY_FILES=$(find "$SCRIPTPATH" -name "*.pub")
for KEY_FILE in $KEY_FILES; do
KEY=$(cat "$KEY_FILE")
if ! grep -q "$KEY" /etc/dropbear/authorized_keys; then
echo "$KEY" >> /etc/dropbear/authorized_keys
echo "$KEY" >>/etc/dropbear/authorized_keys
fi
done
Loading

0 comments on commit d60a115

Please sign in to comment.