-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsetup.sh
232 lines (186 loc) · 7.71 KB
/
setup.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#!bin/bash
#run as root checker
[[ $(id -u) -eq 0 ]] || { echo >&2 "Please run as root"; exit 1; }
#Requirement checker
command -v docker >/dev/null 2>&1 || { echo >&2 "This service requires Docker, but your computer doesn't have it. Install Docker then try again. Aborting."; exit 1; }
command -v docker-compose >/dev/null 2>&1 || { echo >&2 "This service requires Docker-Compose, but your computer doesn't have it. Install Docker-Compose then try again. Aborting."; exit 1;}
command -v mosquitto >/dev/null 2>&1 || { echo >&2 "This service requires Mosquitto Broker, but your computer doesn't have it. Install Mosquitto Broker then try again. Aborting."; exit 1; }
command -v curl >/dev/null 2>&1 || { echo >&2 "This service requires curl, but your computer doesn't have it. Install curl then try again. Aborting."; exit 1; }
#Opening
printf '
__ __ _ _____ _ _____ _ _ _ _ ____ _ _ ____
| \/ | / \|_ _|/ \ | ____| | / \ | \ | |/ ___| | | / \ | __ )
| |\/| | / _ \ | | / _ \ | _| | | / _ \ | \| | | _ | | / _ \ | _ \
| | | |/ ___ \| |/ ___ \ | |___| |___ / ___ \| |\ | |_| | | |___ / ___ \| |_) |
|_| |_/_/ \_|_/_/ \_\ |_____|_____/_/ \_|_| \_|\____| |_____/_/ \_|____/'
echo -e "\n"
echo ----------------------------------------------------------
echo -e "\tBigData Platform for Network Research"
echo ----------------------------------------------------------
echo -e "\n"
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
#Note
echo -----------
printf "${YELLOW}Warning: ${NC}If Using Virtual Machine, Please use NAT Mode\n"
echo -e "-----------\n"
#All input
#===========================================================
printf "If You have Your own ${YELLOW}DATASET${NC}, please put Your dataset in a folder ${YELLOW}${PWD}/resource${NC}.\n"
printf "So you can access it via ${YELLOW}'/resource'${NC} folder on zeppelin-notebook\n"
read -p "Press any key to resume ..."
echo -e "\nAvailable Network Interface :\n"
netints=`ls -C /sys/class/net`
netints+=("Dummy-Interface")
PS3="Network Interface Card for Tapping"$'\n'"Your Choice(ex: 1): "
select option in ${netints[@]}
do
if [ -z "$option" ]
then
echo -e "Choose a valid choice.\nExited."
exit 1
else
NETINT=$option
break
fi
done
if [[ "$NETINT" == *"Dummy"* ]]; then
ip link add name mel-dummy type dummy
rm -rf /etc/systemd/network/mel-dummy.netdev /etc/systemd/network/mel-dummy.network
cp scripts/dummy-interface/mel-dummy.netdev /etc/systemd/network/mel-dummy.netdev
cp scripts/dummy-interface/mel-dummy.network /etc/systemd/network/mel-dummy.network
systemctl restart systemd-networkd
NETINT='mel-dummy'
fi
echo -e "\n\n-----------------------------------"
#Create Charts users
echo -e "Create Mongo Chart UserAdmin Account"
read -p "Username: " USERNAME
read -s -p "Password: " PASSWORD
echo
echo -e "\nInput Jupyter-Notebook Password"
read -s -p "Password: " NOTEBOOK_PASSWORD
echo -e "\n\nWhat kind Mode do you want to use?\n\t1. Standalone\n\t2. Local Cluster(Under Construction)"
read -p "Your choice : " MELMODE
RULE_CHOICE=1
#Choose commpose mode
if [[ ! $MELMODE -eq 1 && ! $MELMODE -eq 2 ]]; then
echo -e "Choose a valid choice.\nExited."
exit 1
fi
if [[ $MELMODE -eq 1 ]]; then
# echo "Using Standalone MataElangLab.."
compose_file="docker-compose.yml"
fi
if [[ $MELMODE -eq 2 ]]; then
echo -e "\nSorry, This Mode Still Under Construction. Aborting.";
exit 0;
# echo "Using Single-Cluster MataElangLab.."
# compose_file="docker-compose-cluster.yml"
fi
# while true; do
# echo # (optional) move to a new line
# read -p "Do You want to use Your own docker-registry[Y/n]? " yn
# case $yn in
# [Yy]* )
# echo -e "Ex: 192.168.100.1:5000\n"
# read -p "Docker Registry Address: " DOCREGADD;
# replacement="image:$DOCREGADD/"
# break;;
# [Nn]* ) break;;
# * ) echo -e "Please answer yes or no.\n";;
# esac
# done
#============================================================
#Export Folder Project Path
export MEL_PATH=$PWD
#Get NIC IP then override env file
ip4=$(/sbin/ip -o -4 addr list $NETINT | awk '{print $4}' | cut -d/ -f1)
subnet=$(/sbin/ip -o -f inet addr show $NETINT | awk '/scope global/ {print $4}')
##Netflowmeter
sed -i 's/^NETINT=.*/NETINT='$NETINT'/' envfile/netflowmeter.env
sed -i 's/^MQTT_HOST=.*/MQTT_HOST='$ip4'/' envfile/netflowmeter.env
##Snort
sed -i 's/^PROTECTED_SUBNET=.*/PROTECTED_SUBNET='$subnet'\/24/' envfile/snort.env
sed -i 's/^ALERT_MQTT_SERVER=.*/ALERT_MQTT_SERVER='$ip4'/' envfile/snort.env
sed -i 's/^NETINT=.*/NETINT='$NETINT'/' envfile/snort.env
##Notebook
sed -i 's/^JUPYTER_TOKEN=.*/JUPYTER_TOKEN='$NOTEBOOK_PASSWORD'/' envfile/notebook.env
#Running MQTT
systemctl start mosquitto
#Allow mqqt in firewall
echo -e "\nAdding rule for port-forwarding"
ufw allow 1883
ufw allow 7077
#Remove Exist Volume
rm -rf ./volume/mongochart
#Starting Big Data
echo -e "\nStarting Compose BigData..."
echo "-----------------------------------\ "
#Set Config for Mode
mkdir -p /etc/mataelanglab
cat > /etc/mataelanglab/mode <<EOL
${compose_file}
EOL
docker-compose --file $compose_file up -d
echo -----------------------------------/
chars="/-\|"
container_name="connect"
#Set MQTT IP in confluent-config file for connection between Kafka-MQTT
sed -i 's|tcp://.*|tcp://'$ip4':1883",|' connector-config/nfm-connector.json
sed -i 's|tcp://.*|tcp://'$ip4':1883",|' connector-config/snort-connector.json
while [ "$( docker container inspect -f '{{.State.Running}}' $container_name )" == "true" ];
do
for (( i=0; i<${#chars}; i++ )); do
sleep 0.1
echo -en "Configuring Kafka Connector...[${chars:$i:1}]" "\r"
done
if [ "$( docker container inspect -f '{{.State.Health.Status}}' $container_name )" == "healthy" ]
then
curl -s -X POST -H 'Content-Type: application/json' --data @connector-config/nfm-connector.json http://localhost:8083/connectors
curl -s -X POST -H 'Content-Type: application/json' --data @connector-config/snort-connector.json http://localhost:8083/connectors
curl -s -X POST -H 'Content-Type: application/json' --data @connector-config/nfm-mongo-sink.json http://localhost:8083/connectors
curl -s -X POST -H 'Content-Type: application/json' --data @connector-config/snort-mongo-sink.json http://localhost:8083/connectors
break;
elif [ "$( docker container inspect -f '{{.State.ExitCode}}' $container_name )" == 1 ]
then
docker restart connect
fi
done
#Configuring MongoCharts
chars="/-\|"
container_name="mongo-charts"
echo
while [ "$( docker container inspect -f '{{.State.Running}}' $container_name )" == "true" ];
do
for (( i=0; i<${#chars}; i++ )); do
sleep 0.1
echo -en "Configuring MongoDB-Charts...[${chars:$i:1}]" "\r"
done
charts_conn=$( docker exec -it $container_name charts-cli test-connection 'mongodb://172.17.0.1' )
if [[ $charts_conn == *"successfully"* ]];
then
sleep 5
docker exec -it mongo-charts bash -c \
"charts-cli add-user \
--first-name "$USERNAME" \
--last-name \"lab\" \
--email \"[email protected]\" \
--password "$PASSWORD" \
--role \"UserAdmin\""
break
elif [ "$( docker container inspect -f '{{.State.Health.Status}}' $container_name )" == "unhealthy" ]
then
docker restart mongo-charts
fi
done
#Display Available Link
echo -e "\n\n-----------------------------------"
echo -e "${YELLOW}Available WebApp${NC}"
echo -e "(For easier Please Bookmark or Copy link)"
echo -e "-----------------------------------"
cat scripts/web-info.txt
echo -e "For easier debugging process, You can install portainer"
echo -e "\n\n-----------------------------------"
echo -e "${YELLOW}Setup completed.${NC}"
echo -e "-----------------------------------"