1
|
#!/bin/sh
|
2
|
#
|
3
|
# rc.initial
|
4
|
#
|
5
|
# part of pfSense (https://www.pfsense.org)
|
6
|
# Copyright (c) 2004-2013 BSD Perimeter
|
7
|
# Copyright (c) 2013-2016 Electric Sheep Fencing
|
8
|
# Copyright (c) 2014-2021 Rubicon Communications, LLC (Netgate)
|
9
|
# All rights reserved.
|
10
|
#
|
11
|
# originally based on m0n0wall (http://neon1.net/m0n0wall)
|
12
|
# Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
13
|
# All rights reserved.
|
14
|
#
|
15
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
16
|
# you may not use this file except in compliance with the License.
|
17
|
# You may obtain a copy of the License at
|
18
|
#
|
19
|
# http://www.apache.org/licenses/LICENSE-2.0
|
20
|
#
|
21
|
# Unless required by applicable law or agreed to in writing, software
|
22
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
23
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
24
|
# See the License for the specific language governing permissions and
|
25
|
# limitations under the License.
|
26
|
|
27
|
# make sure the user can't kill us by pressing Ctrl-C,
|
28
|
# ctrl-z, etc.
|
29
|
trap : 2
|
30
|
trap : 3
|
31
|
trap : 4
|
32
|
|
33
|
unset do_sleep
|
34
|
if [ -f /etc/rc.local ]; then
|
35
|
if ! ps auxwww | egrep -q '[r]c.local$'; then
|
36
|
echo ">>> Launching rc.local in background..."
|
37
|
sh /etc/rc.local &
|
38
|
do_sleep=1
|
39
|
fi
|
40
|
if [ -f /etc/rc.local.running ] && \
|
41
|
! ps auxwww | egrep -q '[r]c.local.running$'; then
|
42
|
[ -n "${do_sleep}" ] && sleep 1
|
43
|
echo ">>> Launching rc.local.running in background..."
|
44
|
sh /etc/rc.local.running &
|
45
|
fi
|
46
|
fi
|
47
|
|
48
|
# Parse command line parameters
|
49
|
while [ $# -gt 0 ]; do
|
50
|
case $1 in
|
51
|
-c ) shift
|
52
|
/bin/sh -c "$@"
|
53
|
exit
|
54
|
;;
|
55
|
* )
|
56
|
esac
|
57
|
shift
|
58
|
done
|
59
|
|
60
|
CONFIG="/cf/conf/config.xml"
|
61
|
WORD="https"
|
62
|
|
63
|
# endless loop
|
64
|
while : ; do
|
65
|
|
66
|
if [ -f /tmp/ttybug ]; then
|
67
|
rm /tmp/ttybug
|
68
|
exit && exit && logout
|
69
|
fi
|
70
|
|
71
|
/etc/rc.banner
|
72
|
|
73
|
# Read product_name from $g, defaults to pfSense
|
74
|
product_name=$(/usr/local/sbin/read_global_var product_name pfSense)
|
75
|
product_label=$(/usr/local/sbin/read_global_var product_label pfSense)
|
76
|
|
77
|
# Check to see if SSH is running.
|
78
|
if pgrep -q -a -F /var/run/sshd.pid sshd >/dev/null 2>&1; then
|
79
|
sshd_option="14) Disable Secure Shell (sshd)";
|
80
|
else
|
81
|
sshd_option="14) Enable Secure Shell (sshd)";
|
82
|
fi
|
83
|
|
84
|
# display a cheap menu
|
85
|
echo ""
|
86
|
echo " 0) Logout (SSH only) 9) pfTop"
|
87
|
echo " 1) Assign Interfaces 10) Filter Logs"
|
88
|
echo " 2) Set interface(s) IP address 11) Restart webConfigurator"
|
89
|
echo " 3) Reset webConfigurator password 12) PHP shell + ${product_label} tools"
|
90
|
echo " 4) Reset to factory defaults 13) Update from console"
|
91
|
echo " 5) Reboot system ${sshd_option}"
|
92
|
echo " 6) Halt system 15) Restore recent configuration"
|
93
|
echo " 7) Ping host 16) Restart PHP-FPM"
|
94
|
echo " 8) Shell"
|
95
|
|
96
|
echo
|
97
|
read -p "Enter an option: " opmode
|
98
|
echo
|
99
|
|
100
|
# see what the user has chosen
|
101
|
case ${opmode} in
|
102
|
0)
|
103
|
exit && exit && logout
|
104
|
;;
|
105
|
1)
|
106
|
/etc/rc.initial.setports
|
107
|
;;
|
108
|
2)
|
109
|
/etc/rc.initial.setlanip
|
110
|
;;
|
111
|
3)
|
112
|
/etc/rc.initial.password
|
113
|
;;
|
114
|
4)
|
115
|
/etc/rc.initial.defaults
|
116
|
;;
|
117
|
5)
|
118
|
/etc/rc.initial.reboot
|
119
|
;;
|
120
|
6)
|
121
|
/etc/rc.initial.halt
|
122
|
;;
|
123
|
7)
|
124
|
/etc/rc.initial.ping
|
125
|
;;
|
126
|
8)
|
127
|
/bin/tcsh
|
128
|
;;
|
129
|
9)
|
130
|
/usr/local/sbin/pftop
|
131
|
;;
|
132
|
10)
|
133
|
/usr/bin/tail -F /var/log/filter.log
|
134
|
;;
|
135
|
11 | 111)
|
136
|
/etc/rc.restart_webgui
|
137
|
;;
|
138
|
12)
|
139
|
/usr/local/sbin/pfSsh.php
|
140
|
;;
|
141
|
13)
|
142
|
/bin/sh /usr/local/sbin/${product_name}-upgrade
|
143
|
;;
|
144
|
14)
|
145
|
php -f /etc/rc.initial.toggle_sshd
|
146
|
;;
|
147
|
15)
|
148
|
/etc/rc.restore_config_backup
|
149
|
;;
|
150
|
16)
|
151
|
/etc/rc.php-fpm_restart
|
152
|
;;
|
153
|
100)
|
154
|
if grep "$WORD" "$CONFIG"; then
|
155
|
links "https://localhost"
|
156
|
else
|
157
|
links "http://localhost"
|
158
|
fi
|
159
|
;;
|
160
|
"")
|
161
|
ps -o command='' -c -p $PPID | grep -E '^sshd$' > /dev/null
|
162
|
if [ $? -eq 0 ]; then
|
163
|
exit
|
164
|
else
|
165
|
kill $PPID ; exit
|
166
|
fi
|
167
|
;;
|
168
|
esac
|
169
|
|
170
|
done
|