Skip to content

Commit

Permalink
device-observatory: add new package
Browse files Browse the repository at this point in the history
Shows network/wireless activity on a local website
to increase awareness for privacy and security matters.

Signed-off-by: Moritz Warning <[email protected]>
  • Loading branch information
mwarning authored and karlp committed Aug 15, 2018
1 parent 8b37cf3 commit 0d2948b
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 0 deletions.
36 changes: 36 additions & 0 deletions utils/device-observatory/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
include $(TOPDIR)/rules.mk

PKG_NAME:=device-observatory
PKG_VERSION:=1.2.0
PKG_RELEASE:=1

PKG_LICENSE:=GPL-3.0+

PKG_SOURCE_URL:=https://codeload.github.com/mwarning/device-observatory/tar.gz/v$(PKG_VERSION)?
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_HASH:=83b3f362f154a427abbd3af31b3c2dda9983cdc15f6b833d804727ef0fbdc72e

include $(INCLUDE_DIR)/package.mk

define Package/device-observatory
SECTION:=utils
CATEGORY:=Utilities
TITLE:=device-observatory
MAINTAINER:=Moritz Warning <[email protected]>
URL:=https://github.com/mwarning/device-observatory/
DEPENDS:=+iw +libpcap +libmicrohttpd-no-ssl
endef

define Package/device-observatory/description
Show information about connected devices and connections to increase security awareness.
endef

define Package/device-observatory/install
$(CP) files/* $(1)
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/device-observatory $(1)/usr/bin/
$(INSTALL_DIR) $(1)/usr/share/device-observatory
$(INSTALL_DATA) $(PKG_BUILD_DIR)/misc/macdb.txt $(1)/usr/share/device-observatory/macdb.txt
endef

$(eval $(call BuildPackage,device-observatory))
26 changes: 26 additions & 0 deletions utils/device-observatory/files/etc/config/device-observatory
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

config setup
list dev 'wlan0'
list mdev 'mon0'

option mac_db '/usr/share/device-observatory/macdb.txt'
option port_db '/etc/services'

# Optional JSON output into file
# option json_output '/tmp/device-observatory.json'

# Time after which a device is removed from the record
option device_timeout 3600

# Create monitoring interface mon0 based on physical interface wifi phy0.
# See 'iw dev' output for a list of interfaces.
list create_monitor 'mon0'

# Track router itself as device
option track_localhost 0

# Set to 0 to disable webserver
option webserver_port 8080

# Not needed, all necessary files are included
# option webserver_path '/www'
66 changes: 66 additions & 0 deletions utils/device-observatory/files/etc/init.d/device-observatory
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/bin/sh /etc/rc.common

START=90
USE_PROCD=1
PROG=/usr/bin/device-observatory
OPTS=""


boot() {
local dev="$(uci get -q device-observatory.@setup[0].dev | cut -d ' ' -f 1)"

# Wait for interface to be up
ubus -t 15 wait_for network.interface network.${dev:-localhost} 2>/dev/null
rc_procd start_service
}

xappend() {
local name="$2" value="$1"
OPTS="$OPTS --${name//_/-} ${value//'/\\'}"
}

append_opts() {
local name value cfg="$1"; shift
for name in $*; do
config_get value "$cfg" "$name"
[ -n "$value" ] && xappend "$value" "$name"
done
}

append_opts_list() {
local name cfg="$1"; shift
for name in $*; do
config_list_foreach "$cfg" "$name" xappend "$name"
done
}

create_monitor_interface() {
local ifce="$1" n=$(echo -n "$1" | tail -c 1)

if [ ! -d "/sys/class/net/$ifce/" ]; then
iw phy "phy$n" interface add "$ifce" type monitor
ip link set dev "$ifce" up
fi
}

start_instance() {
local cfg="$1"

OPTS=""

config_list_foreach "$cfg" "create_monitor" create_monitor_interface "create_monitor"

append_opts_list "$cfg" dev mdev
append_opts "$cfg" mac_db port_db json_output device_timeout webserver_port webserver_path track_localhost

procd_open_instance
procd_set_param command $PROG $OPTS
procd_set_param stderr 1
procd_set_param stdout 0
procd_close_instance
}

start_service() {
config_load 'device-observatory'
config_foreach start_instance 'setup'
}

0 comments on commit 0d2948b

Please sign in to comment.