This repository has been archived by the owner on Dec 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure.sh
executable file
·162 lines (145 loc) · 4.31 KB
/
configure.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
#!/bin/bash
function help {
echo " ./configure.sh"
echo " -s configure as server"
echo " -c configure as client"
echo " -ap connect/configure Access Point"
echo " --help this help menu"
echo ""
exit 1
}
#-----------------------------------------------------------------------------#
function menu_from_array()
{
select choice; do
# Check the selected menu item number
if [ 1 -le "$REPLY" ] && [ "$REPLY" -le $# ];
then
break;
else
echo "Wrong selection: Select any number from 1-$#"
fi
done
}
function create_wpa_supplicant_conf {
cat <<EOF > tools/wpa_tools/wpa_supplicant_client_AP.conf
network={
ssid="$1"
psk="$2"
}
EOF
}
function create_ap_conf {
cat <<EOF > tools/wpa_tools/access-point.conf
network={
ssid="$1"
mode=2
key_mgmt=WPA-PSK
psk="$2"
frequency=2437
}
EOF
}
#-----------------------------------------------------------------------------#
function ap_connect {
echo '> Connecting to Access Point...'
read -p "- SSID: " ssid
read -p "- Password: " password
create_wpa_supplicant_conf $ssid $password
echo '> Please choose from the list of available interfaces...'
interfaces_arr=($(ip link | awk -F: '$0 !~ "lo|vir|doc|eth|bat|^[^0-9]"{print $2}'))
menu_from_array "${interfaces_arr[@]}"
sudo wpa_supplicant -B -i $choice -c tools/wpa_tools/wpa_supplicant_client_AP.conf
sudo dhclient -v $choice
}
function ap_create {
echo '> Creating a Mesh Access Point...'
echo '> Please choose from the list of available interfaces...'
interfaces_arr=($(ip link | awk -F: '$0 !~ "lo|vir|doc|eth|bat|^[^0-9]"{print $2}'))
menu_from_array "${interfaces_arr[@]}"
read -p "- SSID: " ssid
read -p "- Password: " password
echo "Password must be eight (8) characters lenght"
create_ap_conf $ssid $password
cd tools/wpa_tools
chmod +x access_point_wpa_supplicant.sh
sudo bash access_point_wpa_supplicant.sh $choice
cd ../..
}
function access_point {
echo '> Do you wish to...'
ap_arr=('Connect to an Access Point?' 'Create an Access Point?')
menu_from_array "${ap_arr[@]}"
if [ $REPLY == "1" ]; then
ap_connect
elif [[ $REPLY == "2" ]]; then
ap_create
fi
}
function server {
echo '> Configuring the server...'
# Create a certificate
make certificate
# Make the server
make server
# Advertise the server using avahi (zeroconf)
avahi-publish-service mesh_server _http._tcp 5000 &
sudo python3 src/server-mesh.py -c src/ecc_key.der
}
function client {
echo '> Configuring the client...'
# Make the server
make client
# Connect to the same AP as the server
read -p "> We need to be connect to the same network as the server... Connect to an Access Point? (Y/N): " confirm
if [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]]; then
ap_connect
fi
echo -n '> Server discovery...'
# get server IPv4 and hostname
while ! [ "$server_details" ] ; do
server_details=$(timeout 7 avahi-browse -rptfl _http._tcp | awk -F';' '$1 == "=" && $3 == "IPv4" && $4 == "mesh_server" {print $8 " " $7}')
done
# split ip/host into separate vars
server_details=($(sed -r 's/\b.local\b//g' <<< $server_details))
server_ip=${server_details[0]}
server_host=${server_details[1]}
echo "> We will use src/ecc_key.der if it already exists, or we can try and fetch it..."
read -p "> Do you want to fetch the certificate from the server $server_host@$server_ip? (Y/N): " confirm
if [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]]; then
echo '> Fetching certificate from server...'
read -p "- Server Username: " server_user
# pull the key from the server
scp $server_user@$server_ip:/home/$server_user/sc-mesh-secure-deployment/src/ecc_key.der src/ecc_key.der
fi
echo '> Configuring the client and connecting to server...'
sudo python3 src/client/client-mesh.py -c src/ecc_key.der -s http://$server_ip:5000
}
#-----------------------------------------------------------------------------#
echo '=== sc-mesh-secure-deployment-configure ==='
PARAMS=""
while (( "$#" )); do
case "$1" in
-s)
server
shift
;;
-c)
client
NOAP=1
shift
;;
-ap)
access_point
shift
;;
--help)
help
shift 2
;;
*) # preserve positional arguments
PARAMS="$PARAMS $1"
shift
;;
esac
done