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 [ -n "${1}" ]; then
30 function cli_device
() {
37 if [ -z "${devices}" ]; then
38 devices
=$
(devices_get_all
)
43 echo "# XXX need to implement --raw here"
44 for device
in ${devices}; do
45 cli_device_discover
${device} $@
50 for device
in ${devices}; do
51 cli_device_print
${device}
60 function cli_device_print
() {
63 if ! device_exists
${device}; then
64 error
"Device '${device}' does not exist."
69 echo " Type: $(device_get_type ${device})"
70 echo " Addr: $(device_get_address ${device})"
74 function cli_device_discover
() {
78 local device_type
=$
(device_get_type
${device})
79 if [ "${device_type}" != "real" ]; then
85 while [ $# -gt 0 ]; do
95 device_is_up
${device} && up
=1
96 device_set_up
${device}
98 enabled raw ||
echo "${device}"
103 for hook
in $
(hooks_get_all
); do
104 out
=$
(hook_exec
${hook} discover
${device})
107 [ ${ret} -eq ${DISCOVER_NOT_SUPPORTED} ] && continue
115 echo "${hook}: ${line}"
120 echo "${hook}: FAILED"
126 echo " ${hook} was successful."
134 echo " ${hook} failed."
142 [ "${up}" = "1" ] || device_set_down
${device}
145 function cli_zone
() {
149 if zone_name_is_valid
${1}; then
155 config|down|edit|port|show|status|up
)
156 zone_
${action} ${zone} $@
168 error
"Unrecognized argument: '${action}'"
174 function cli_start
() {
175 if cli_help_requested $@
; then
180 local zones
=$
(zones_get $@
)
183 for zone
in ${zones}; do
188 function cli_stop
() {
189 if cli_help_requested $@
; then
194 local zones
=$
(zones_get $@
)
197 for zone
in ${zones}; do
202 function cli_help_requested
() {
204 for argument
in $@
; do
205 if [ "${argument}" = "help" -o "${argument}" = "-h" -o "${argument}" = "--help" ]; then
213 function cli_usage
() {
218 echo "${0}: [command] <options ...>"
230 root-start|root-stop
)
231 echo "${0}: ${what#root-} [--local-only|--remote-only|--all|<zone>...]"
233 echo " This commands ${what#root-}s all zones by default."
234 echo " One can pass several parameters to only process a subset of all"
235 echo " available zones:"
237 echo -e " ${BOLD}--local-only${NORMAL}"
238 echo " Process all local zones which includes every zone without red."
240 echo -e " ${BOLD}--remote-only${NORMAL}"
241 echo " Process all remote zones which means only the red ones."
243 echo -e " ${BOLD}--all${NORMAL}"
244 echo " Process all zones. This is the default parameter."
246 echo " Additionally, you can pass one or more zone names which will"
247 echo " be processed."
252 echo " Run '${0} help' to get information how to use this tool."
256 error
"No help available for this command '${what}'."
261 echo "Network configuration tool. Report all bugs to <http://bugs.ipfire.org>."