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
() {
151 if cli_help_requested $@
; then
159 if zone_name_is_valid
${1}; then
165 config|down|edit|port|show|status|up
)
166 zone_
${action} ${zone} $@
169 error
"Unrecognized argument: ${action}"
170 cli_usage root-zone-subcommands
183 if [ -n "${action}" ]; then
184 error
"Unrecognized argument: '${action}'"
195 function cli_start
() {
196 if cli_help_requested $@
; then
201 local zones
=$
(zones_get $@
)
204 for zone
in ${zones}; do
209 function cli_stop
() {
210 if cli_help_requested $@
; then
215 local zones
=$
(zones_get $@
)
218 for zone
in ${zones}; do
223 function cli_restart
() {
224 if cli_help_requested $@
; then
225 cli_usage root-restart
231 # Give the system some time to calm down
232 sleep ${TIMEOUT_RESTART}
237 function cli_status
() {
238 if cli_help_requested $@
; then
239 cli_usage root-status
243 local zones
=$
(zones_get $@
)
246 for zone
in ${zones}; do
251 function cli_help_requested
() {
253 for argument
in $@
; do
254 if [ "${argument}" = "help" -o "${argument}" = "-h" -o "${argument}" = "--help" ]; then
262 function cli_usage
() {
267 echo "${0}: [command] <options ...>"
271 echo " restart - ..."
281 echo "${0}: ${what#root-} [KEY=VAL, ...]"
283 echo " This command allows setting of global configuration parameters."
285 echo " If no additional arguments are passed it will list the current configuration."
287 echo " You can overwrite the settings like the following:"
289 echo " ${0} ${what#root-} DEBUG=1 ..."
292 root-start|root-stop|root-restart
)
293 echo "${0}: ${what#root-} [--local-only|--remote-only|--all|<zone>...]"
295 echo " This commands ${what#root-}s all zones by default."
296 echo " One can pass several parameters to only process a subset of all"
297 echo " available zones:"
299 echo -e " ${BOLD}--local-only${NORMAL}"
300 echo " Process all local zones which includes every zone without red."
302 echo -e " ${BOLD}--remote-only${NORMAL}"
303 echo " Process all remote zones which means only the red ones."
305 echo -e " ${BOLD}--all${NORMAL}"
306 echo " Process all zones. This is the default parameter."
308 echo " Additionally, you can pass one or more zone names which will"
309 echo " be processed."
313 echo "${0}: ${what#root-} [--local-only|--remote-only|--all|<zone>...]"
315 echo " This commands shows status information of all zones by default."
316 echo " One can pass several parameters to only process a subset of all"
317 echo " available zones:"
319 echo -e " ${BOLD}--local-only${NORMAL}"
320 echo " Process all local zones which includes every zone without red."
322 echo -e " ${BOLD}--remote-only${NORMAL}"
323 echo " Process all remote zones which means only the red ones."
325 echo -e " ${BOLD}--all${NORMAL}"
326 echo " Process all zones. This is the default parameter."
328 echo " Additionally, you can pass one or more zone names which will"
329 echo " be processed."
333 echo "${0}: ${what#root-} <create|remove> <zone> [<type> <options...>]"
335 echo " Create or remove a zone."
337 echo -e " ${BOLD}create <zone> <type> <options>${NORMAL}"
338 echo " Create a new zone of type <type> where <zone> is an allowed"
341 echo -e " ${BOLD}remove <zone>${NORMAL}"
342 echo " Remove the zone <zone>."
344 echo " You may also edit the configuration of the zones."
346 echo -e " ${BOLD}<zone> ...${NORMAL}"
347 echo " Edit the zone <zone>."
352 echo " Run '${0} help' to get information how to use this tool."
356 error
"No help available for this command '${what}'."
361 echo "Network configuration tool. Report all bugs to <http://bugs.ipfire.org>."
364 function cli_status_headline
() {
367 local state
="${COLOUR_DOWN}DOWN${COLOUR_NORMAL}"
368 zone_is_up
${zone} && state="${COLOUR_UP}UP${COLOUR_NORMAL}"
370 echo -e "${zone} - ${state} - $(zone_get_hook ${zone})"
373 function cli_headline() {
375 echo -e "${COLOUR_BOLD}$@
${COLOUR_NORMAL}"