BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mangoh-drivers
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
mangoh-drivers
Commits
786b0ac4
Commit
786b0ac4
authored
Mar 14, 2018
by
David Clark
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed user input validation
parent
da967340
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
16 deletions
+34
-16
cfg_gateway.sh
scripts/cfg_gateway.sh
+34
-16
No files found.
scripts/cfg_gateway.sh
View file @
786b0ac4
...
@@ -71,7 +71,7 @@ valid_net_mask()
...
@@ -71,7 +71,7 @@ valid_net_mask()
zero
=
1
zero
=
1
fi
fi
else
else
if
eval
[
$zero
-ne
0
]
;
then
if
[
$zero
-ne
0
]
;
then
echo
"Error net mask out of range (
$net_mask
)"
echo
"Error net mask out of range (
$net_mask
)"
return
1
return
1
fi
fi
...
@@ -88,19 +88,21 @@ valid_net_mask()
...
@@ -88,19 +88,21 @@ valid_net_mask()
echo
"MangOH gateway configuration"
echo
"MangOH gateway configuration"
read
-p
"Enter WAN (cellular) interface (default: rmnet_data0): "
ITF_WAN
read
-p
"Enter WAN (cellular) interface (default: rmnet_data0): "
ITF_WAN
if
[
-
n
$ITF_WAN
]
;
then
if
[
-
z
"
$ITF_WAN
"
]
;
then
ITF_WAN
=
"rmnet_data0"
ITF_WAN
=
"rmnet_data0"
fi
fi
echo
"WAN interface
$ITF_WAN
"
read
-p
"Enter LAN interface (default: eth0): "
ITF_LAN
read
-p
"Enter LAN interface (default: eth0): "
ITF_LAN
if
[
-
n
$ITF_LAN
]
;
then
if
[
-
z
"
$ITF_LAN
"
]
;
then
ITF_LAN
=
"eth0"
ITF_LAN
=
"eth0"
fi
fi
echo
"LAN interface
$ITF_LAN
"
while
true
while
true
do
do
read
-p
"Enter LAN IP (default: 192.168.20.1): "
LAN_IP
read
-p
"Enter LAN IP (default: 192.168.20.1): "
LAN_IP
if
[
-
n
$LAN_IP
]
;
then
if
[
-
z
"
$LAN_IP
"
]
;
then
LAN_IP
=
"192.168.20.1"
LAN_IP
=
"192.168.20.1"
fi
fi
...
@@ -112,8 +114,8 @@ done
...
@@ -112,8 +114,8 @@ done
while
true
while
true
do
do
read
-p
"Enter LAN
IP
Mask (default: 255.255.255.0): "
NET_MASK
read
-p
"Enter LAN
Net
Mask (default: 255.255.255.0): "
NET_MASK
if
[
-
n
$NET_MASK
]
;
then
if
[
-
z
"
$NET_MASK
"
]
;
then
NET_MASK
=
"255.255.255.0"
NET_MASK
=
"255.255.255.0"
fi
fi
...
@@ -153,7 +155,7 @@ case "$ITF_WAN" in
...
@@ -153,7 +155,7 @@ case "$ITF_WAN" in
sleep
1
sleep
1
read
-p
"Enter APN (default: internet.sierrawireless.com): "
APN
read
-p
"Enter APN (default: internet.sierrawireless.com): "
APN
if
[
-
n
$APN
]
;
then
if
[
-
z
"
$APN
"
]
;
then
APN
=
"internet.sierrawireless.com"
APN
=
"internet.sierrawireless.com"
fi
fi
...
@@ -167,7 +169,7 @@ case "$ITF_WAN" in
...
@@ -167,7 +169,7 @@ case "$ITF_WAN" in
esac
esac
RETRY
=
0
RETRY
=
0
while
[
${
RETRY
}
-lt
6
0
]
;
do
while
[
${
RETRY
}
-lt
3
0
]
;
do
ITF_WAN_ADDR
=
$(
/sbin/ifconfig
"
$ITF_WAN
"
|
grep
"inet addr"
|
cut
-d
':'
-f
2 |
cut
-d
' '
-f
1
)
ITF_WAN_ADDR
=
$(
/sbin/ifconfig
"
$ITF_WAN
"
|
grep
"inet addr"
|
cut
-d
':'
-f
2 |
cut
-d
' '
-f
1
)
if
[
"
${
ITF_WAN_ADDR
}
"
==
""
]
;
then
if
[
"
${
ITF_WAN_ADDR
}
"
==
""
]
;
then
sleep
1
sleep
1
...
@@ -205,6 +207,10 @@ fi
...
@@ -205,6 +207,10 @@ fi
echo
"Enabling IP forwarding..."
echo
"Enabling IP forwarding..."
sysctl
-w
net.ipv4.ip_forward
=
1
sysctl
-w
net.ipv4.ip_forward
=
1
if
[
"
$?
"
-ne
0
]
;
then
echo
"Enabling IP forwarding failed"
exit
1
fi
echo
"Configuring the NAT..."
echo
"Configuring the NAT..."
iptables
-P
INPUT ACCEPT
iptables
-P
INPUT ACCEPT
...
@@ -224,22 +230,22 @@ if [ "$?" -ne 0 ]; then
...
@@ -224,22 +230,22 @@ if [ "$?" -ne 0 ]; then
fi
fi
iptables
--table
nat
-A
POSTROUTING
-o
$ITF_WAN
-j
MASQUERADE
iptables
--table
nat
-A
POSTROUTING
-o
$ITF_WAN
-j
MASQUERADE
if
[
"
$?
"
-ne
0
]
;
then
if
[
"
$?
"
-ne
0
]
;
then
echo
"iptables postrouting failed"
echo
"iptables postrouting
$ITF_WAN
failed"
exit
1
exit
1
fi
fi
iptables
-A
FORWARD
-i
$ITF_WAN
-o
$ITF_LAN
-m
state
--state
RELATED,ESTABLISHED
-j
ACCEPT
iptables
-A
FORWARD
-i
$ITF_WAN
-o
$ITF_LAN
-m
state
--state
RELATED,ESTABLISHED
-j
ACCEPT
if
[
"
$?
"
-ne
0
]
;
then
if
[
"
$?
"
-ne
0
]
;
then
echo
"iptables forward failed"
echo
"iptables forward
$ITF_WAN
->
$ITF_LAN
failed"
exit
1
exit
1
fi
fi
iptables
-A
FORWARD
-i
$ITF_LAN
-o
$ITF_WAN
-m
state
--state
NEW
-j
ACCEPT
iptables
-A
FORWARD
-i
$ITF_LAN
-o
$ITF_WAN
-m
state
--state
NEW
-j
ACCEPT
if
[
"
$?
"
-ne
0
]
;
then
if
[
"
$?
"
-ne
0
]
;
then
echo
"iptables forward failed"
echo
"iptables forward
$ITF_LAN
->
$ITF_WAN
failed"
exit
1
exit
1
fi
fi
iptables
-A
INPUT
-m
udp
-p
udp
--sport
67:68
--dport
67:68
-j
ACCEPT
iptables
-A
INPUT
-m
udp
-p
udp
--sport
67:68
--dport
67:68
-j
ACCEPT
if
[
"
$?
"
-ne
0
]
;
then
if
[
"
$?
"
-ne
0
]
;
then
echo
"iptables accept
input
failed"
echo
"iptables accept
UDP input on source/destination ports 67,68
failed"
exit
1
exit
1
fi
fi
...
@@ -255,7 +261,7 @@ if [ "${rsp}" = 'Y' ]; then
...
@@ -255,7 +261,7 @@ if [ "${rsp}" = 'Y' ]; then
while
true
while
true
do
do
read
-p
"Enter start IP (default: 192.168.20.10): "
DHCP_IP_START
read
-p
"Enter start IP (default: 192.168.20.10): "
DHCP_IP_START
if
[
-
n
$DHCP_IP_START
]
;
then
if
[
-
z
$DHCP_IP_START
]
;
then
DHCP_IP_START
=
"192.168.20.10"
DHCP_IP_START
=
"192.168.20.10"
fi
fi
...
@@ -268,7 +274,7 @@ if [ "${rsp}" = 'Y' ]; then
...
@@ -268,7 +274,7 @@ if [ "${rsp}" = 'Y' ]; then
while
true
while
true
do
do
read
-p
"Enter end IP (default: 192.168.20.100): "
DHCP_IP_END
read
-p
"Enter end IP (default: 192.168.20.100): "
DHCP_IP_END
if
[
-
n
$DHCP_IP_END
]
;
then
if
[
-
z
$DHCP_IP_END
]
;
then
DHCP_IP_END
=
"192.168.20.100"
DHCP_IP_END
=
"192.168.20.100"
fi
fi
...
@@ -279,7 +285,11 @@ if [ "${rsp}" = 'Y' ]; then
...
@@ -279,7 +285,11 @@ if [ "${rsp}" = 'Y' ]; then
done
done
echo
"Reconfiguring the DHCP server..."
echo
"Reconfiguring the DHCP server..."
/etc/init.d/dnsmasq stop
||
echo
"UNABLE TO STOP THE DHCP server"
/etc/init.d/dnsmasq stop
if
[
"
$?
"
-ne
0
]
;
then
echo
"UNABLE TO STOP THE DHCP server"
exit
1
fi
### Configure the IP addresses range for DHCP (dnsmasq)
### Configure the IP addresses range for DHCP (dnsmasq)
DHCP_CFG_FILE
=
"
$DHCP_CFG_FILE_PREFIX
.
$ITF_LAN
.
$DHCP_CFG_FILE_SUFFIX
"
DHCP_CFG_FILE
=
"
$DHCP_CFG_FILE_PREFIX
.
$ITF_LAN
.
$DHCP_CFG_FILE_SUFFIX
"
...
@@ -295,10 +305,18 @@ if [ "${rsp}" = 'Y' ]; then
...
@@ -295,10 +305,18 @@ if [ "${rsp}" = 'Y' ]; then
"dhcp-range=
$DHCP_IP_START
,
$DHCP_IP_END
,24h
\n
"
\
"dhcp-range=
$DHCP_IP_START
,
$DHCP_IP_END
,24h
\n
"
\
"server=8.8.8.8
\n
"
>>
"/tmp/
$DHCP_CFG_FILE
"
"server=8.8.8.8
\n
"
>>
"/tmp/
$DHCP_CFG_FILE
"
ln
-s
"/tmp/
$DHCP_CFG_FILE
"
"/etc/dnsmasq.d/
$DHCP_CFG_FILE
"
ln
-s
"/tmp/
$DHCP_CFG_FILE
"
"/etc/dnsmasq.d/
$DHCP_CFG_FILE
"
if
[
"
$?
"
-ne
0
]
;
then
echo
"Create softlink for DHCP server configuration file failed"
exit
1
fi
### Start the DHCP server
### Start the DHCP server
echo
"Restarting the DHCP server..."
echo
"Restarting the DHCP server..."
/etc/init.d/dnsmasq start
||
echo
"UNABLE TO START THE DHCP server"
/etc/init.d/dnsmasq start
if
[
"
$?
"
-ne
0
]
;
then
echo
"UNABLE TO START THE DHCP server"
exit
1
fi
fi
fi
echo
"MangOH gateway configuration completed"
echo
"MangOH gateway configuration completed"
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment