-
Notifications
You must be signed in to change notification settings - Fork 0
/
osmobridge.sh
199 lines (166 loc) · 4.39 KB
/
osmobridge.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
#!/bin/bash
# source configuration from config file
if [ -r /root/osmobridge.inc ];
then
. /root/osmobridge.inc
fi
if [ "$1" == "init" ];
then
# read in values that aren't present
if [ "x$OSMOSSID" == "x" ];
then
echo "Enter Osmo network name (SSID)"
read OSMOSSID
fi
if [ "x$OSMOPASS" == "x" ];
then
echo "Enter Osmo network password"
read OSMOPASS
fi
if [ "x$BRIDGESSID" == "x" ];
then
echo "Enter bridge network name (SSID)"
read BRIDGESSID
fi
if [ "x$BRIDGEPASS" == "x" ];
then
echo "Enter bridge network password"
read BRIDGEPASS
fi
cat <<EOF > /root/osmobridge.inc
OSMOSSID="$OSMOSSID"
OSMOPASS="$OSMOPASS"
BRIDGESSID="$BRIDGESSID"
BRIDGEPASS="$BRIDGEPASS"
EOF
# get the OS up to date and necessities installed
apt-get update
apt-get -y upgrade
apt-get -y install hostapd dnsmasq wpasupplicant iptables
# populate wpa_supplicant.conf
cat <<EOF > /etc/wpa_supplicant/wpa_supplicant.conf
country=US
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid="${OSMOSSID}"
psk="${OSMOPASS}"
}
EOF
# populate hostapd.conf
cat <<EOF > /etc/hostapd/hostapd.conf
interface=wlan1
driver=nl80211
ssid=${BRIDGESSID}
hw_mode=g
channel=6
ieee80211n=1
wmm_enabled=1
ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40]
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_key_mgmt=WPA-PSK
wpa_passphrase=${BRIDGEPASS}
rsn_pairwise=CCMP
EOF
# Apparently there is no default config file
echo "DAEMON_CONF=/etc/hostapd/hostapd.conf" >> /etc/default/hostapd
# populate dnsmasq.conf
cat <<EOF > /etc/dnsmasq.conf
interface=wlan1
listen-address=192.168.2.1
bind-interfaces
server=8.8.8.8
domain-needed
bogus-priv
dhcp-range=192.168.2.50,192.168.2.150,12h
EOF
# initialize an (essentially) blank /etc/network/interfaces
cat <<EOF > /etc/network/interfaces
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
EOF
# populate /etc/network/interfaces.d/eth0
cat <<EOF > /etc/network/interfaces.d/eth0
allow-hotplug eth0
iface eth0 inet manual
EOF
# populate /etc/network/interfaces.d/eth1 (for things like USB MiFi)
cat <<EOF > /etc/network/interfaces.d/eth1
allow-hotplug eth1
iface eth1 inet manual
EOF
# populate /etc/network/interfaces.d/wlan0
# we use 192.168.1.25 because it seems to be in the range the Osmo will
# give out via DHCP. IPs lower than .20 get denied streaming/control by
# the osmo.
cat <<EOF > /etc/network/interfaces.d/wlan0
allow-hotplug wlan0
iface wlan0 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
EOF
# populate /etc/network/interfaces.d/wlan1
cat <<EOF > /etc/network/interfaces.d/wlan1
iface wlan1 inet static
address 192.168.2.1
network 255.255.255.0
EOF
# run out of rc.local
cat <<EOF > /etc/rc.local
#!/bin/sh -e
/root/osmobridge.sh
exit 0
EOF
# add directives to dhcpcd.conf
cat <<EOF >> /etc/dhcpcd.conf
denyinterfaces wlan1
EOF
chmod +x /root/osmobridge.sh
chmod +x /etc/rc.local
# enable/disable applicable services
systemctl disable dnsmasq
systemctl disable hostapd
systemctl enable dhcpcd
systemctl enable wpa_supplicant
# disable unnecessary crap
systemctl disable avahi-daemon
systemctl disable bluetooth
else
# make it go!
ifup wlan1
echo 1 > /proc/sys/net/ipv4/ip_forward
# ACCEPT in the beginning
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEPT
# flush relevant tables
iptables -F INPUT
iptables -F OUTPUT
iptables -F FORWARD
iptables -F POSTROUTING -t nat
# populate rules
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -i wlan1 -j ACCEPT
iptables -A INPUT -p icmp -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -p icmp -j ACCEPT
iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i wlan1 -s 192.168.2.1/24 -j ACCEPT
iptables -t nat -A POSTROUTING -o wlan0 -s 192.168.2.1/24 -d 192.168.1.0/24 -j MASQUERADE
iptables -t nat -A POSTROUTING -o eth0 -s 192.168.2.0/24 -j MASQUERADE
iptables -t nat -A POSTROUTING -o eth1 -s 192.168.2.0/24 -j MASQUERADE
# make security great again
iptables -P INPUT DROP
iptables -P FORWARD DROP
service hostapd start
service dnsmasq start
# start the DHCP interfaces later after all the other stuff is running
ifup wlan0 > /dev/null 2>&1 &
ifup eth0 > /dev/null 2>&1 &
# start connection monitor notifier thing
wpa_cli -a /root/wpa_action.sh &
fi