diff --git a/.env b/.env index 32b2ac6..e889de0 120000 --- a/.env +++ b/.env @@ -1 +1 @@ -dash.conf \ No newline at end of file +listen.conf \ No newline at end of file diff --git a/dash.conf_example b/dash.conf_example deleted file mode 100644 index e236f4a..0000000 --- a/dash.conf_example +++ /dev/null @@ -1,5 +0,0 @@ -DASH_INTERFACE= - -DASH_MQTT_SERVER=127.0.0.1 -DASH_MQTT_PORT=1883 -DASH_MQTT_TOPIC="dashlisten" diff --git a/docker-compose.yml b/docker-compose.yml index 6aeea2c..bb997e1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,10 +6,10 @@ mem_limit: 128m restart: always environment: - - DASH_INTERFACE=${DASH_INTERFACE} - - DASH_MQTT_SERVER=${DASH_MQTT_SERVER:-127.0.0.1} - - DASH_MQTT_PORT=${DASH_MQTT_PORT:-1883} - - DASH_MQTT_TOPIC=${DASH_MQTT_TOPIC:-dashbutton} + - LISTEN_INTERFACE=${LISTEN_INTERFACE} + - MQTT_SERVER=${MQTT_SERVER:-127.0.0.1} + - MQTT_PORT=${MQTT_PORT:-1883} + - MQTT_TOPIC=${MQTT_TOPIC:-dashbutton} tmpfs: - /tmp network_mode: host diff --git a/docker/Dockerfile b/docker/Dockerfile index 4630d0b..5e367a6 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,24 +1,19 @@ FROM alpine -MAINTAINER Osbert Feng - # since 2019-09-05 MAINTAINER Pascal Gollor # environment variables -ENV DASH_HOME /srv/dash +ENV LISTEN_HOME /srv/listen RUN apk update RUN apk add scapy tcpdump py2-paho-mqtt RUN rm -rf /var/cache/apk/* # working directory -WORKDIR $DASH_HOME +WORKDIR $LISTEN_HOME # copy files -ADD dash-listen.py ./dash-listen.py -#COPY docker-entrypoint.sh / -#RUN chmod +x /docker-entrypoint.sh +ADD listen.py ./listen.py -#ENTRYPOINT ["/docker-entrypoint.sh"] -CMD python ./dash-listen.py +CMD python ./listen.py diff --git a/docker/dash-listen.py b/docker/dash-listen.py deleted file mode 100644 index a621bf1..0000000 --- a/docker/dash-listen.py +++ /dev/null @@ -1,36 +0,0 @@ -# sudo apt-get install python-scapy tcpdump tcpreplay wireshark - -# Note that wireshark prompts during installation if non-root users -# should be allowed to perform packed capture. - -from scapy.all import * -import paho.mqtt.client as mqtt -import os - - -DASH_INTERFACE=os.environ.get('DASH_INTERFACE') - -DASH_MQTT_SERVER = os.environ.get('DASH_MQTT_SERVER') -DASH_MQTT_PORT = os.environ.get('DASH_MQTT_PORT') -DASH_MQTT_TOPIC = os.environ.get('DASH_MQTT_TOPIC') - - - -def arp_display(pkt): - if (pkt.haslayer(DHCP)): - print "DHCP from " + pkt[Ether].src - client.publish(DASH_MQTT_TOPIC + "/mac", str(pkt[Ether])) - # end if -# end apr_display - -client = mqtt.Client() -client.connect(DASH_MQTT_SERVER, DASH_MQTT_PORT, keepalive=60, bind_address="") - -try: - print sniff(prn=arp_display, iface=DASH_INTERFACE, filter="ip", store=0, count=0) -except KeyboardInterrupt: - if (GLOBAL_DEBUG): - print("exit") - # end if -# end try - diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh deleted file mode 100644 index 453529e..0000000 --- a/docker/docker-entrypoint.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/sh -set -e - -# check for exisitng user and create it if necessary -if ! id -u dash >/dev/null 2>&1; then - echo "create dash user" - adduser -u 1000 -D -g '' -h ${DASH_HOME} dash -fi - -# update user rights -chown -R dash:dash ${DASH_HOME} - -exec "$@" - diff --git a/docker/listen.py b/docker/listen.py new file mode 100644 index 0000000..a4c5aa5 --- /dev/null +++ b/docker/listen.py @@ -0,0 +1,33 @@ +from scapy.all import * +import paho.mqtt.client as mqtt +import os + + +LISTEN_INTERFACE=os.environ.get('LISTEN_INTERFACE') + +MQTT_SERVER = os.environ.get('MQTT_SERVER') +MQTT_PORT = os.environ.get('MQTT_PORT') +MQTT_TOPIC = os.environ.get('MQTT_TOPIC') + + + +def onPackage(pkt): + if (pkt.haslayer(DHCP)): + print "DHCP from " + pkt[Ether].src + client.publish(MQTT_TOPIC + "/mac", str(pkt[Ether].src)) + # end if +# end apr_display + +client = mqtt.Client() +client.connect(MQTT_SERVER, MQTT_PORT, keepalive=60, bind_address="") + +try: + if (LISTEN_INTERFACE): + print sniff(prn=onPackage, iface=LISTEN_INTERFACE, filter="ip", store=0, count=0) + else: + print sniff(prn=onPackage, filter="ip", store=0, count=0) + # end if +except KeyboardInterrupt: + pass +# end try + diff --git a/listen.conf-example b/listen.conf-example new file mode 100644 index 0000000..05bd3c2 --- /dev/null +++ b/listen.conf-example @@ -0,0 +1,5 @@ +LISTEN_INTERFACE=wlan0 + +MQTT_SERVER=127.0.0.1 +MQTT_PORT=1883 +MQTT_TOPIC="dashbutton"