2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2010 Michael Tremer & Christian Schmidt #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
22 function cli_config
() {
23 if cli_help_requested $@
; then
28 if [ -n "${1}" ]; then
35 function cli_device
() {
42 if [ -z "${devices}" ]; then
43 devices
=$
(devices_get_all
)
48 echo "# XXX need to implement --raw here"
49 for device
in ${devices}; do
50 cli_device_discover
${device} $@
55 for device
in ${devices}; do
56 cli_device_print
${device}
65 function cli_device_print
() {
68 if ! device_exists
${device}; then
69 error
"Device '${device}' does not exist."
74 echo " Type: $(device_get_type ${device})"
75 echo " Addr: $(device_get_address ${device})"
79 function cli_device_discover
() {
83 local device_type
=$
(device_get_type
${device})
84 if [ "${device_type}" != "real" ]; then
90 while [ $# -gt 0 ]; do
100 device_is_up
${device} && up
=1
101 device_set_up
${device}
103 enabled raw ||
echo "${device}"
108 for hook
in $
(hooks_get_all
); do
109 out
=$
(hook_exec
${hook} discover
${device})
112 [ ${ret} -eq ${DISCOVER_NOT_SUPPORTED} ] && continue
120 echo "${hook}: ${line}"
125 echo "${hook}: FAILED"
131 echo " ${hook} was successful."
139 echo " ${hook} failed."
147 [ "${up}" = "1" ] || device_set_down
${device}
150 function cli_zone
() {
154 if zone_name_is_valid
${1}; then
160 config|down|edit|port|show|status|up
)
161 zone_
${action} ${zone} $@
173 error
"Unrecognized argument: '${action}'"
179 function cli_start
() {
180 if cli_help_requested $@
; then
185 local zones
=$
(zones_get $@
)
188 for zone
in ${zones}; do
193 function cli_stop
() {
194 if cli_help_requested $@
; then
199 local zones
=$
(zones_get $@
)
202 for zone
in ${zones}; do
207 function cli_restart
() {
208 if cli_help_requested $@
; then
209 cli_usage root-restart
215 # Give the system some time to calm down
216 sleep ${TIMEOUT_RESTART}
221 function cli_help_requested
() {
223 for argument
in $@
; do
224 if [ "${argument}" = "help" -o "${argument}" = "-h" -o "${argument}" = "--help" ]; then
232 function cli_usage
() {
237 echo "${0}: [command] <options ...>"
241 echo " restart - ..."
251 echo "${0}: ${what#root-} [KEY=VAL, ...]"
253 echo " This command allows setting of global configuration parameters."
255 echo " If no additional arguments are passed it will list the current configuration."
257 echo " You can overwrite the settings like the following:"
259 echo " ${0} ${what#root-} DEBUG=1 ..."
262 root-start|root-stop|root-restart
)
263 echo "${0}: ${what#root-} [--local-only|--remote-only|--all|<zone>...]"
265 echo " This commands ${what#root-}s all zones by default."
266 echo " One can pass several parameters to only process a subset of all"
267 echo " available zones:"
269 echo -e " ${BOLD}--local-only${NORMAL}"
270 echo " Process all local zones which includes every zone without red."
272 echo -e " ${BOLD}--remote-only${NORMAL}"
273 echo " Process all remote zones which means only the red ones."
275 echo -e " ${BOLD}--all${NORMAL}"
276 echo " Process all zones. This is the default parameter."
278 echo " Additionally, you can pass one or more zone names which will"
279 echo " be processed."
284 echo " Run '${0} help' to get information how to use this tool."
288 error
"No help available for this command '${what}'."
293 echo "Network configuration tool. Report all bugs to <http://bugs.ipfire.org>."