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 # Parse the command line
23 while [ $# -gt 0 ]; do
33 [ -n "${action}" ] && break
36 .
/usr
/lib
/network
/functions
38 function cli_config
() {
39 if cli_help_requested $@
; then
40 cli_show_man network-config
44 if [ -n "${1}" ]; then
52 function cli_device
() {
57 assert device_exists
${device}
59 if zone_exists
${device} || port_exists
${device}; then
60 error
"The device '${device}' has already been configured."
61 error
"You cannot do a device action."
67 echo "# XXX need to implement --raw here"
68 cli_device_discover
${device} $@
72 # XXX device_show needs to be implemented
76 cli_show_man network-device
81 function cli_device_discover
() {
85 local device_type
=$
(device_get_type
${device})
86 if [ "${device_type}" != "real" ]; then
92 while [ $# -gt 0 ]; do
102 device_is_up
${device} && up
=1
103 device_set_up
${device}
105 enabled raw ||
echo "${device}"
110 for hook
in $
(hook_zone_get_all
); do
111 out
=$
(hook_zone_exec
${hook} discover
${device})
114 [ ${ret} -eq ${DISCOVER_NOT_SUPPORTED} ] && continue
122 echo "${hook}: ${line}"
127 echo "${hook}: FAILED"
133 echo " ${hook} was successful."
141 echo " ${hook} failed."
149 [ "${up}" = "1" ] || device_set_down
${device}
152 function cli_hostname
() {
153 if cli_help_requested $@
; then
160 if [ -n "${hostname}" ]; then
161 config_hostname
${hostname}
162 log INFO
"Hostname was set to '${hostname}'."
163 log INFO
"Changes do only take affect after reboot."
167 echo "$(config_hostname)"
171 function cli_port
() {
172 if cli_help_requested $@
; then
173 cli_show_man network-port
180 if port_exists
${1}; then
200 port_
${action} ${port} $@
203 error
"Unrecognized argument: ${action}"
216 error
"Unrecognized argument: ${action}"
223 function cli_zone
() {
224 if cli_help_requested $@
; then
225 cli_show_man network-zone
232 if zone_name_is_valid
${1}; then
251 config|down|edit|port|status|up
)
252 zone_
${action} ${zone} $@
255 error
"Unrecognized argument: ${action}"
256 cli_show_man network-zone
272 cli_list_hooks zone $@
275 if [ -n "${action}" ]; then
276 error
"Unrecognized argument: '${action}'"
280 cli_show_man network-zone
287 # Removes a zone either immediately, if it is currently down,
288 # or adds a tag that the removal will be done when the zone
289 # is brought down the next time.
290 function cli_zone_remove
() {
291 if cli_help_requested $@
; then
292 cli_show_man network-zone
297 assert zone_exists
${zone}
299 if zone_is_up
${zone}; then
300 echo "Zone '${zone}' is up and will be removed when it goes down the next time."
303 echo "Removing zone '${zone}' now..."
304 zone_remove_now
${zone}
310 function cli_list_hooks
() {
314 if cli_help_requested $@
; then
315 cli_show_man network-zone
319 local hook_dir
=$
(hook_dir
${type})
322 for hook
in ${hook_dir}/*; do
323 hook
=$
(basename ${hook})
324 if hook_exists
${type} ${hook}; then
330 function cli_start
() {
331 if cli_help_requested $@
; then
336 local zones
=$
(zones_get $@
)
339 for zone
in ${zones}; do
343 wait # until everything is settled
346 function cli_stop
() {
347 if cli_help_requested $@
; then
352 local zones
=$
(zones_get $@
)
355 for zone
in ${zones}; do
359 wait # until everything is settled
362 function cli_restart
() {
363 if cli_help_requested $@
; then
370 # Give the system some time to calm down
371 sleep ${TIMEOUT_RESTART}
376 function cli_status
() {
377 if cli_help_requested $@
; then
382 # When dumping status information, the debug
383 # mode clutters the console which is not what we want.
384 # Logging on the console is disabled for a short time.
385 local log_disable_stdout
=${LOG_DISABLE_STDOUT}
386 LOG_DISABLE_STDOUT
="true"
388 local zones
=$
(zones_get $@
)
391 for zone
in ${zones}; do
396 LOG_DISABLE_STDOUT
=${log_disable_stdout}
399 function cli_reset
() {
400 if cli_help_requested $@
; then
405 warning_log
"Will reset the whole network configuration!!!"
407 # Force mode is disabled by default
410 while [ $# -gt 0 ]; do
419 # If we are not running in force mode, we ask the user if he does know
421 if ! enabled force
; then
422 if ! cli_yesno
"Do you really want to reset the whole network configuration?"; then
428 for zone
in $
(zones_get
--all); do
433 for port
in $
(ports_get
--all); do
437 # Re-run the initialization functions
443 # Process the given action
449 config|hostname|port|device|zone|start|stop|restart|status|
reset)
459 error
"Invalid command given: ${action}"
460 cli_usage
"network help"
461 exit ${EXIT_CONF_ERROR}