-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathnet_server_dhcp_tftp
executable file
·116 lines (82 loc) · 1.87 KB
/
net_server_dhcp_tftp
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
#!/bin/sh
## hyphop ##
#= tftp dhcp server + traffic forward
#set -e
[ "$CONF" ] || CONF="$1"
[ "$CONF" ] || CONF=conf/dhcp.conf
[ "$1" ] && {
shift
}
[ -f "$CONF" ] || {
echo "[e] not found config file: $CONF">&2
exit 1
}
echo "[i] config $CONF">&2
RP=$(realpath $0); DP=$(dirname $RP); . $DP/$CONF
## need a root privs
for runas in $DP/bin/runas runas sudo; do
which $runas 1>/dev/null && {
echo "[i] runas = $runas">&2
break
}
done
$runas $(which pkill) -f $PID_FILE
case "$1" in
stop|off)
exit 0
;;
esac
IPT_RULE="INPUT -p udp -m multiport --dports 67,69 -i $DEV -j ACCEPT"
iptables="$runas $(which iptables)"
$iptables -D $IPT_RULE >/dev/null 2>/dev/null
$iptables -I $IPT_RULE
[ "$IP" ] || IP=192.168.100.1
[ "$ROUTER" ] || ROUTER=$IP
[ "$DNS" ] || DNS=8.8.8.8
[ "$DNS" ] || DNS=1.1.1.1
[ "$MASK" ] || MASK=255.255.255.0
TEST=1
[ "$TEST" = "1" ] && debug=-d
[ "$1" = "test" ] && debug=-d
[ "$IP0" ] || {
IP0="${IP%.*}.100"
}
[ "$IP1" ] || {
IP1="${IP%.*}.200"
}
ifconfig="$runas $(which ifconfig)"
$ifconfig $DEV $IP netmask $MASK
$ifconfig $DEV up
dnsmasq="$runas $(which dnsmasq)"
RUNIT(){
echo "[#] $@">&2
"$@"
}
RUNAS=--user=root
RUNAS=
SHARE="$DP/../share"
SHARE2="/tmp/krescue.share"
## secure tricks
for a in $SHARE2; do
[ -e $a ] || ln -s "$SHARE" $a
done
SHARE=$SHARE2
# --tftp-secure \
#$runas $(which net_forward) start
$runas $DP/net_forward start
#echo "$IP" > /tmp/dhcp_host.ip
echo "[i] uboot cmd usage example">&2
echo "[i] dhcp; tftp 0 boot.scr; autoscr 0">&2
echo "[i] dhcp; tftp 1000000 boot.scr; source 1000000">&2
RUNIT $dnsmasq $debug -p0 $RUNAS \
-z -i $DEV \
--enable-tftp=$DEV \
--tftp-root="$SHARE" \
--tftp-no-fail \
-Z \
--dhcp-option=1,$MASK \
--dhcp-option=3,$ROUTER \
--dhcp-option=6,$DNS \
--dhcp-range=$IP0,$IP1,240h \
--dhcp-leasefile=$LEASE_FILE \
-x $PID_FILE "$@"