1
|
#!/bin/sh
|
2
|
#
|
3
|
# rc.initial
|
4
|
#
|
5
|
# part of pfSense (https://www.pfsense.org)
|
6
|
# Copyright (c) 2004-2016 Electric Sheep Fencing, LLC
|
7
|
# All rights reserved.
|
8
|
#
|
9
|
# originally based on m0n0wall (http://neon1.net/m0n0wall)
|
10
|
# Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
11
|
# All rights reserved.
|
12
|
#
|
13
|
# Redistribution and use in source and binary forms, with or without
|
14
|
# modification, are permitted provided that the following conditions are met:
|
15
|
#
|
16
|
# 1. Redistributions of source code must retain the above copyright notice,
|
17
|
# this list of conditions and the following disclaimer.
|
18
|
#
|
19
|
# 2. Redistributions in binary form must reproduce the above copyright
|
20
|
# notice, this list of conditions and the following disclaimer in
|
21
|
# the documentation and/or other materials provided with the
|
22
|
# distribution.
|
23
|
#
|
24
|
# 3. All advertising materials mentioning features or use of this software
|
25
|
# must display the following acknowledgment:
|
26
|
# "This product includes software developed by the pfSense Project
|
27
|
# for use in the pfSense® software distribution. (http://www.pfsense.org/).
|
28
|
#
|
29
|
# 4. The names "pfSense" and "pfSense Project" must not be used to
|
30
|
# endorse or promote products derived from this software without
|
31
|
# prior written permission. For written permission, please contact
|
32
|
# coreteam@pfsense.org.
|
33
|
#
|
34
|
# 5. Products derived from this software may not be called "pfSense"
|
35
|
# nor may "pfSense" appear in their names without prior written
|
36
|
# permission of the Electric Sheep Fencing, LLC.
|
37
|
#
|
38
|
# 6. Redistributions of any form whatsoever must retain the following
|
39
|
# acknowledgment:
|
40
|
#
|
41
|
# "This product includes software developed by the pfSense Project
|
42
|
# for use in the pfSense software distribution (http://www.pfsense.org/).
|
43
|
#
|
44
|
# THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
|
45
|
# EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
46
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
47
|
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
|
48
|
# ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
49
|
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
50
|
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
51
|
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
52
|
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
53
|
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
54
|
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
55
|
# OF THE POSSIBILITY OF SUCH DAMAGE.
|
56
|
|
57
|
# make sure the user can't kill us by pressing Ctrl-C,
|
58
|
# ctrl-z, etc.
|
59
|
#trap : 2
|
60
|
#trap : 3
|
61
|
#trap : 4
|
62
|
|
63
|
if [ -f /etc/rc.local ]; then
|
64
|
RCLOCALPWD=`ps awux | grep rc.local | grep -v grep | awk '{ print $2 }'`
|
65
|
if [ "$RCLOCALPWD" = "" ]; then
|
66
|
echo ">>> Launching rc.local in background..."
|
67
|
sh /etc/rc.local &
|
68
|
sleep 1
|
69
|
sh /etc/rc.local.running &
|
70
|
else
|
71
|
if [ -f /etc/rc.local.running ]; then
|
72
|
echo ">>> Launching rc.local.running in background..."
|
73
|
sh /etc/rc.local.running &
|
74
|
fi
|
75
|
fi
|
76
|
fi
|
77
|
|
78
|
# Parse command line parameters
|
79
|
while [ $# -gt 0 ]; do
|
80
|
case $1 in
|
81
|
-c ) shift
|
82
|
/bin/sh -c $1
|
83
|
exit
|
84
|
;;
|
85
|
* )
|
86
|
esac
|
87
|
shift
|
88
|
done
|
89
|
|
90
|
CONFIG="/cf/conf/config.xml"
|
91
|
WORD="https"
|
92
|
|
93
|
# Set our operating platform
|
94
|
PLATFORM=`cat /etc/platform`
|
95
|
|
96
|
# endless loop
|
97
|
while : ; do
|
98
|
|
99
|
if [ -f /tmp/ttybug ]; then
|
100
|
rm /tmp/ttybug
|
101
|
exit && exit && logout
|
102
|
fi
|
103
|
|
104
|
/etc/rc.banner
|
105
|
|
106
|
# Read product_name from $g, defaults to pfSense
|
107
|
product=$(/usr/local/sbin/read_global_var product_name pfSense)
|
108
|
|
109
|
# Check to see if SSH is running.
|
110
|
if pgrep -q -a -F /var/run/sshd.pid sshd >/dev/null 2>&1; then
|
111
|
sshd_option="14) Disable Secure Shell (sshd)";
|
112
|
else
|
113
|
sshd_option="14) Enable Secure Shell (sshd)";
|
114
|
fi
|
115
|
|
116
|
for i in /var/db/pfi/capable_*; do
|
117
|
if [ -f $i -a ! -L /cf/conf ]; then
|
118
|
option98="98) Move configuration file to removable device"
|
119
|
break
|
120
|
fi
|
121
|
done
|
122
|
|
123
|
if [ "$PLATFORM" = "cdrom" ]; then
|
124
|
option99="99) Install ${product} to a hard drive, etc."
|
125
|
fi
|
126
|
|
127
|
# display a cheap menu
|
128
|
echo ""
|
129
|
echo " 0) Logout (SSH only) 9) pfTop"
|
130
|
echo " 1) Assign Interfaces 10) Filter Logs"
|
131
|
echo " 2) Set interface(s) IP address 11) Restart webConfigurator"
|
132
|
echo " 3) Reset webConfigurator password 12) PHP shell + ${product} tools"
|
133
|
echo " 4) Reset to factory defaults 13) Update from console"
|
134
|
echo " 5) Reboot system ${sshd_option}"
|
135
|
echo " 6) Halt system 15) Restore recent configuration"
|
136
|
echo " 7) Ping host 16) Restart PHP-FPM"
|
137
|
echo " 8) Shell"
|
138
|
echo " ${option98} "
|
139
|
|
140
|
if [ "${option99}" != "" ]; then
|
141
|
/bin/echo "${option99}"
|
142
|
fi
|
143
|
|
144
|
echo
|
145
|
read -p "Enter an option: " opmode
|
146
|
echo
|
147
|
|
148
|
# see what the user has chosen
|
149
|
case ${opmode} in
|
150
|
0)
|
151
|
exit && exit && logout
|
152
|
;;
|
153
|
1)
|
154
|
/etc/rc.initial.setports
|
155
|
;;
|
156
|
2)
|
157
|
/etc/rc.initial.setlanip
|
158
|
;;
|
159
|
3)
|
160
|
/etc/rc.initial.password
|
161
|
;;
|
162
|
4)
|
163
|
/etc/rc.initial.defaults
|
164
|
;;
|
165
|
5)
|
166
|
/etc/rc.initial.reboot
|
167
|
;;
|
168
|
6)
|
169
|
/etc/rc.initial.halt
|
170
|
;;
|
171
|
7)
|
172
|
/etc/rc.initial.ping
|
173
|
;;
|
174
|
8)
|
175
|
/bin/tcsh
|
176
|
;;
|
177
|
9)
|
178
|
/usr/local/sbin/pftop
|
179
|
;;
|
180
|
10)
|
181
|
/usr/local/sbin/clog -f /var/log/filter.log
|
182
|
;;
|
183
|
11 | 111)
|
184
|
/etc/rc.restart_webgui
|
185
|
;;
|
186
|
12)
|
187
|
/usr/local/sbin/pfSsh.php
|
188
|
;;
|
189
|
13)
|
190
|
/bin/sh /usr/local/sbin/${product}-upgrade
|
191
|
;;
|
192
|
14)
|
193
|
php -f /etc/rc.initial.toggle_sshd
|
194
|
;;
|
195
|
15)
|
196
|
/etc/rc.restore_config_backup
|
197
|
;;
|
198
|
16)
|
199
|
/etc/rc.php-fpm_restart
|
200
|
;;
|
201
|
98)
|
202
|
if [ ! -f /tmp/config_moved ]; then
|
203
|
/etc/rc.initial.store_config_to_removable_device
|
204
|
fi
|
205
|
;;
|
206
|
99)
|
207
|
if [ -e /dev/ukbd0 ]; then
|
208
|
env TERM=cons25 /scripts/lua_installer
|
209
|
else
|
210
|
/scripts/lua_installer
|
211
|
fi
|
212
|
;;
|
213
|
100)
|
214
|
if grep "$WORD" "$CONFIG"; then
|
215
|
links "https://localhost"
|
216
|
else
|
217
|
links "http://localhost"
|
218
|
fi
|
219
|
;;
|
220
|
"")
|
221
|
ps -o command='' -c -p $PPID | grep -E '^sshd$' > /dev/null
|
222
|
if [ $? -eq 0 ]; then
|
223
|
exit
|
224
|
else
|
225
|
kill $PPID ; exit
|
226
|
fi
|
227
|
;;
|
228
|
esac
|
229
|
|
230
|
done
|
231
|
|