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_help_requested
() {
239 for argument
in $@
; do
240 if [ "${argument}" = "help" -o "${argument}" = "-h" -o "${argument}" = "--help" ]; then
248 function cli_usage
() {
253 echo "${0}: [command] <options ...>"
257 echo " restart - ..."
267 echo "${0}: ${what#root-} [KEY=VAL, ...]"
269 echo " This command allows setting of global configuration parameters."
271 echo " If no additional arguments are passed it will list the current configuration."
273 echo " You can overwrite the settings like the following:"
275 echo " ${0} ${what#root-} DEBUG=1 ..."
278 root-start|root-stop|root-restart
)
279 echo "${0}: ${what#root-} [--local-only|--remote-only|--all|<zone>...]"
281 echo " This commands ${what#root-}s all zones by default."
282 echo " One can pass several parameters to only process a subset of all"
283 echo " available zones:"
285 echo -e " ${BOLD}--local-only${NORMAL}"
286 echo " Process all local zones which includes every zone without red."
288 echo -e " ${BOLD}--remote-only${NORMAL}"
289 echo " Process all remote zones which means only the red ones."
291 echo -e " ${BOLD}--all${NORMAL}"
292 echo " Process all zones. This is the default parameter."
294 echo " Additionally, you can pass one or more zone names which will"
295 echo " be processed."
299 echo "${0}: ${what#root-} <create|remove> <zone> [<type> <options...>]"
301 echo " Create or remove a zone."
303 echo -e " ${BOLD}create <zone> <type> <options>${NORMAL}"
304 echo " Create a new zone of type <type> where <zone> is an allowed"
307 echo -e " ${BOLD}remove <zone>${NORMAL}"
308 echo " Remove the zone <zone>."
310 echo " You may also edit the configuration of the zones."
312 echo -e " ${BOLD}<zone> ...${NORMAL}"
313 echo " Edit the zone <zone>."
318 echo " Run '${0} help' to get information how to use this tool."
322 error
"No help available for this command '${what}'."
327 echo "Network configuration tool. Report all bugs to <http://bugs.ipfire.org>."