-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtranslate_profiles.sh
executable file
·75 lines (62 loc) · 1.79 KB
/
translate_profiles.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
# Translate all profiles in the devices folder into their corresponding
# pair of NFTables firewall script and NFQueue C source code.
###### VARIABLES ######
# Retrieve this script's path
# (from https://stackoverflow.com/questions/4774054/reliable-way-for-a-bash-script-to-get-the-full-path-to-itself)
SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
DEVICES_DIR="$SCRIPTPATH/devices" # Devices directory
# NFQueue IDs
NFQ_ID_START=0 # NFQueue start index
LOG_GROUP=2 # NFLog group ID
###### FUNCTIONS ######
# Print usage information
usage() {
echo "Usage: $0 [-t] [-l log_type]" 1>&2
exit 1
}
###### MAIN ######
# Parse command line arguments
TEST=""
LOG_TYPE=""
while getopts "tl:" opt;
do
case "${opt}" in
t)
# Enable test mode
TEST="-t"
echo "Test mode enabled: use VM instead of router"
;;
l)
# Enable packet logging
LOG_TYPE="${OPTARG}"
echo "Packet logging enabled with type $LOG_TYPE"
;;
*)
usage
;;
esac
done
shift $((OPTIND-1))
# Iterate on all devices
for DEVICE in amazon-echo dlink-cam philips-hue smartthings-hub tplink-plug xiaomi-cam
do
DEVICE_PATH="$DEVICES_DIR/$DEVICE"
if [[ -d "$DEVICE_PATH" ]]
then
LOGGING=""
if [[ $LOG_TYPE == "CSV" ]]
then
LOGGING="-l $LOG_TYPE"
elif [[ $LOG_TYPE == "PCAP" ]]
then
LOGGING="-l $LOG_TYPE -g $LOG_GROUP"
fi
python3 "$SCRIPTPATH/src/translator/translator.py" "$DEVICE_PATH/profile.yaml" $NFQ_ID_START $TEST $LOGGING
NFQ_ID_START=$((NFQ_ID_START+1000))
if [[ $LOG_TYPE == "PCAP" ]]
then
LOG_GROUP=$((LOG_GROUP+1))
fi
fi
done