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()
zero
=
1
fi
else
if
eval
[
$zero
-ne
0
]
;
then
if
[
$zero
-ne
0
]
;
then
echo
"Error net mask out of range (
$net_mask
)"
return
1
fi
...
...
@@ -88,19 +88,21 @@ valid_net_mask()
echo
"MangOH gateway configuration"
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"
fi
echo
"WAN interface
$ITF_WAN
"
read
-p
"Enter LAN interface (default: eth0): "
ITF_LAN
if
[
-
n
$ITF_LAN
]
;
then
if
[
-
z
"
$ITF_LAN
"
]
;
then
ITF_LAN
=
"eth0"
fi
echo
"LAN interface
$ITF_LAN
"
while
true
do
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"
fi
...
...
@@ -112,8 +114,8 @@ done
while
true
do
read
-p
"Enter LAN
IP
Mask (default: 255.255.255.0): "
NET_MASK
if
[
-
n
$NET_MASK
]
;
then
read
-p
"Enter LAN
Net
Mask (default: 255.255.255.0): "
NET_MASK
if
[
-
z
"
$NET_MASK
"
]
;
then
NET_MASK
=
"255.255.255.0"
fi
...
...
@@ -153,7 +155,7 @@ case "$ITF_WAN" in
sleep
1
read
-p
"Enter APN (default: internet.sierrawireless.com): "
APN
if
[
-
n
$APN
]
;
then
if
[
-
z
"
$APN
"
]
;
then
APN
=
"internet.sierrawireless.com"
fi
...
...
@@ -167,7 +169,7 @@ case "$ITF_WAN" in
esac
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
)
if
[
"
${
ITF_WAN_ADDR
}
"
==
""
]
;
then
sleep
1
...
...
@@ -205,6 +207,10 @@ fi
echo
"Enabling IP forwarding..."
sysctl
-w
net.ipv4.ip_forward
=
1
if
[
"
$?
"
-ne
0
]
;
then
echo
"Enabling IP forwarding failed"
exit
1
fi
echo
"Configuring the NAT..."
iptables
-P
INPUT ACCEPT
...
...
@@ -224,22 +230,22 @@ if [ "$?" -ne 0 ]; then
fi
iptables
--table
nat
-A
POSTROUTING
-o
$ITF_WAN
-j
MASQUERADE
if
[
"
$?
"
-ne
0
]
;
then
echo
"iptables postrouting failed"
echo
"iptables postrouting
$ITF_WAN
failed"
exit
1
fi
iptables
-A
FORWARD
-i
$ITF_WAN
-o
$ITF_LAN
-m
state
--state
RELATED,ESTABLISHED
-j
ACCEPT
if
[
"
$?
"
-ne
0
]
;
then
echo
"iptables forward failed"
echo
"iptables forward
$ITF_WAN
->
$ITF_LAN
failed"
exit
1
fi
iptables
-A
FORWARD
-i
$ITF_LAN
-o
$ITF_WAN
-m
state
--state
NEW
-j
ACCEPT
if
[
"
$?
"
-ne
0
]
;
then
echo
"iptables forward failed"
echo
"iptables forward
$ITF_LAN
->
$ITF_WAN
failed"
exit
1
fi
iptables
-A
INPUT
-m
udp
-p
udp
--sport
67:68
--dport
67:68
-j
ACCEPT
if
[
"
$?
"
-ne
0
]
;
then
echo
"iptables accept
input
failed"
echo
"iptables accept
UDP input on source/destination ports 67,68
failed"
exit
1
fi
...
...
@@ -255,7 +261,7 @@ if [ "${rsp}" = 'Y' ]; then
while
true
do
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"
fi
...
...
@@ -268,7 +274,7 @@ if [ "${rsp}" = 'Y' ]; then
while
true
do
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"
fi
...
...
@@ -279,7 +285,11 @@ if [ "${rsp}" = 'Y' ]; then
done
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)
DHCP_CFG_FILE
=
"
$DHCP_CFG_FILE_PREFIX
.
$ITF_LAN
.
$DHCP_CFG_FILE_SUFFIX
"
...
...
@@ -295,10 +305,18 @@ if [ "${rsp}" = 'Y' ]; then
"dhcp-range=
$DHCP_IP_START
,
$DHCP_IP_END
,24h
\n
"
\
"server=8.8.8.8
\n
"
>>
"/tmp/
$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
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
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