From: rtrimana Date: Wed, 5 Apr 2017 16:04:43 +0000 (-0700) Subject: Adding a simple script to register a new device (MAC, IP, key, and device name) X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=676386fdf11afbadac7c7281f59436f59d3a4ded;p=iot2.git Adding a simple script to register a new device (MAC, IP, key, and device name) --- diff --git a/benchmarks/other/OpenWrt/README b/benchmarks/other/OpenWrt/README new file mode 100644 index 0000000..129e2f3 --- /dev/null +++ b/benchmarks/other/OpenWrt/README @@ -0,0 +1,19 @@ +Device registration utility for Sentinel system +This is a simple script that register a new device +into /etc/config/dhcp and /etc/hostapd-psk +Copyright (c) 2015-2017, Rahmadi Trimananda PLRG@UCIrvine + +Usage: + ./register_device.sh [-h] + ./register_device.sh [-a ] + ./register_device.sh [-l] + +Options: + -h show this usage + -a adding device by putting MAC address, desired IP address, key, and device name (optional) + -l show list of devices registered + + +Notes: +- This simple script now only adds device information (no delete feature) +- Meant to ease the setup process (mimicking production environment) diff --git a/benchmarks/other/OpenWrt/devices.dat b/benchmarks/other/OpenWrt/devices.dat new file mode 100644 index 0000000..ffea2e2 --- /dev/null +++ b/benchmarks/other/OpenWrt/devices.dat @@ -0,0 +1,2 @@ +12:32:34:45:56:67 192.168.2.123 mydevice +12:32:34:45:56:67 192.168.2.123 mydevice diff --git a/benchmarks/other/OpenWrt/register_device.sh b/benchmarks/other/OpenWrt/register_device.sh new file mode 100755 index 0000000..193381b --- /dev/null +++ b/benchmarks/other/OpenWrt/register_device.sh @@ -0,0 +1,62 @@ +#!/bin/sh + +# Print usage +if [ "$#" -eq 0 ] || [ "$1" == "-h" ]; then + echo "Device registration utility for Sentinel system" + echo "This is a simple script that register a new device" + echo "into /etc/config/dhcp and /etc/hostapd-psk" + echo "Copyright (c) 2015-2017, Rahmadi Trimananda PLRG@UCIrvine" + echo "" + echo "Usage:" + echo " ./register_device.sh [-h]" + echo " ./register_device.sh [-a ]" + echo " ./register_device.sh [-l]" + echo "" + echo "Options:" + echo " -h show this usage" + echo " -a adding device by putting MAC address, desired IP address, key, and device name (optional)" + echo " -l show list of devices registered" + echo "" + +elif [ "$1" == "-a" ]; then + + if [ "$2" == "" ] || [ "$3" == "" ] || [ "$4" == "" ]; then + echo "Empty or incomplete parameters! Please run ./register_device.sh -h for usage." + else + # Add a new device + MAC=$2 + IP=$3 + KEY=$4 + + # Keep a local log + echo "$MAC $IP $KEY $5" >> devices.dat + + # Insert into /etc/hostapd-psk + echo "$MAC $KEY" >> /etc/hostapd-psk + + # Insert into /etc/config/dhcp + echo "" >> /etc/config/dhcp + if [ "$5" != "" ]; then # If device-name is not empty + echo "# $5" >> /etc/config/dhcp + fi + echo "config host" >> /etc/config/dhcp + echo " option ip '$IP'" >> /etc/config/dhcp + echo " option mac '$MAC'" >> /etc/config/dhcp + + if [ "$5" != "" ]; then # If device-name is not empty + echo " option name '$5'" >> /etc/config/dhcp + fi + echo "Device added!" + fi + +elif [ "$1" == "-l" ]; then + # Print list of devices + echo "List of devices" + cat devices.dat + echo "" + echo "/etc/hostapd-psk" + cat /etc/hostapd-psk +else + echo "Unknown option. Please run ./register_device.sh -h for usage." +fi +