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
() {
36 if device_config_exists
${1}; then
43 device_
${action} ${device} $@
56 echo "# XXX need to implement --raw here"
58 for device
in ${devices}; do
59 cli_device_discover
${device} $@
65 for device
in $
(device_get $@
); do
66 device_print
${device}
76 function cli_device_discover
() {
80 local device_type
=$
(device_get_type
${device})
81 if [ "${device_type}" != "real" ]; then
87 while [ $# -gt 0 ]; do
97 device_is_up
${device} && up
=1
98 device_set_up
${device}
100 enabled raw ||
echo "${device}"
105 for hook
in $
(hook_zone_get_all
); do
106 out
=$
(hook_zone_exec
${hook} discover
${device})
109 [ ${ret} -eq ${DISCOVER_NOT_SUPPORTED} ] && continue
117 echo "${hook}: ${line}"
122 echo "${hook}: FAILED"
128 echo " ${hook} was successful."
136 echo " ${hook} failed."
144 [ "${up}" = "1" ] || device_set_down
${device}
147 function cli_port
() {
148 if cli_help_requested $@
; then
156 if port_exists
${1}; then
176 port_
${action} ${port} $@
179 error
"Unrecognized argument: ${action}"
192 error
"Unrecognized argument: ${action}"
199 function cli_zone
() {
200 if cli_help_requested $@
; then
208 if zone_name_is_valid
${1}; then
227 config|down|edit|port|status|up
)
228 zone_
${action} ${zone} $@
231 error
"Unrecognized argument: ${action}"
232 cli_usage root-zone-subcommands
245 if [ -n "${action}" ]; then
246 error
"Unrecognized argument: '${action}'"
257 function cli_start
() {
258 if cli_help_requested $@
; then
263 local zones
=$
(zones_get $@
)
266 for zone
in ${zones}; do
271 function cli_stop
() {
272 if cli_help_requested $@
; then
277 local zones
=$
(zones_get $@
)
280 for zone
in ${zones}; do
285 function cli_restart
() {
286 if cli_help_requested $@
; then
287 cli_usage root-restart
293 # Give the system some time to calm down
294 sleep ${TIMEOUT_RESTART}
299 function cli_status
() {
300 if cli_help_requested $@
; then
301 cli_usage root-status
305 local zones
=$
(zones_get $@
)
308 for zone
in ${zones}; do
313 function cli_reset
() {
314 if cli_help_requested $@
; then
319 warning_log
"Will reset the whole network configuration!!!"
321 # Force mode is disabled by default
324 while [ $# -gt 0 ]; do
333 # If we are not running in force mode, we ask the user if he does know
335 if ! enabled force
; then
336 if ! cli_yesno
"Do you really want to reset the whole network configuration?"; then
342 for zone
in $
(zones_get
--all); do
347 for port
in $
(ports_get
--all); do
351 # XXX recreate ethernet ports
356 function cli_help_requested
() {
357 local argument
="${1}"
359 if [ -n "${argument}" ]; then
360 if listmatch
${argument} help -h --help; then
368 function cli_usage
() {
373 echo "${0}: [command] <options ...>"
377 echo " restart - ..."
387 echo "${0}: ${what#root-} [KEY=VAL, ...]"
389 echo " This command allows setting of global configuration parameters."
391 echo " If no additional arguments are passed it will list the current configuration."
393 echo " You can overwrite the settings like the following:"
395 echo " ${0} ${what#root-} DEBUG=1 ..."
399 echo "${0}: ${what#root-} [--force | -f]"
401 echo " This command resets the network configuration."
403 echo " Will delete all zones and ports."
405 echo -e " ${COLOUR_RED}USE WITH CAUTION!${COLOUR_NORMAL}"
408 root-start|root-stop|root-restart
)
409 echo "${0}: ${what#root-} [--local-only|--remote-only|--all|<zone>...]"
411 echo " This commands ${what#root-}s all zones by default."
412 echo " One can pass several parameters to only process a subset of all"
413 echo " available zones:"
415 echo -e " ${COLOUR_BOLD}--local-only${COLOUR_NORMAL}"
416 echo " Process all local zones which includes every zone without red."
418 echo -e " ${COLOUR_BOLD}--remote-only${COLOUR_NORMAL}"
419 echo " Process all remote zones which means only the red ones."
421 echo -e " ${COLOUR_BOLD}--all${COLOUR_NORMAL}"
422 echo " Process all zones. This is the default parameter."
424 echo " Additionally, you can pass one or more zone names which will"
425 echo " be processed."
429 echo "${0}: ${what#root-} [--local-only|--remote-only|--all|<zone>...]"
431 echo " This commands shows status information of all zones by default."
432 echo " One can pass several parameters to only process a subset of all"
433 echo " available zones:"
435 echo -e " ${COLOUR_BOLD}--local-only${COLOUR_NORMAL}"
436 echo " Process all local zones which includes every zone without red."
438 echo -e " ${COLOUR_BOLD}--remote-only${COLOUR_NORMAL}"
439 echo " Process all remote zones which means only the red ones."
441 echo -e " ${COLOUR_BOLD}--all${COLOUR_NORMAL}"
442 echo " Process all zones. This is the default parameter."
444 echo " Additionally, you can pass one or more zone names which will"
445 echo " be processed."
449 echo "${0}: ${what#root-} <create|remove> <zone> [<type> <options...>]"
451 echo " Create or remove a zone."
453 echo -e " ${COLOUR_BOLD}create <zone> <type> <options>${COLOUR_NORMAL}"
454 echo " Create a new zone of type <type> where <zone> is an allowed"
457 echo -e " ${COLOUR_BOLD}remove <zone>${COLOUR_NORMAL}"
458 echo " Remove the zone <zone>."
460 echo " You may also edit the configuration of the zones."
462 echo -e " ${COLOUR_BOLD}<zone> ...${COLOUR_NORMAL}"
463 echo " Edit the zone <zone>."
468 echo " Run '${0} help' to get information how to use this tool."
472 error
"No help available for this command '${what}'."
477 echo "Network configuration tool. Report all bugs to <http://bugs.ipfire.org>."
480 function cli_status_headline
() {
483 local state
="${COLOUR_DOWN}DOWN${COLOUR_NORMAL}"
484 zone_is_up
${zone} && state="${COLOUR_UP}UP${COLOUR_NORMAL}"
486 echo -e "${zone} - ${state} - $(zone_get_hook ${zone})"
489 function cli_headline() {
491 echo -e "${COLOUR_BOLD}$@
${COLOUR_NORMAL}"
494 function cli_yesno() {
495 local message="$@
[y
/N
] "
499 echo -ne "${message}"
502 if listmatch ${yesno} y Y j J yes YES Yes; then