]> git.ipfire.org Git - network.git/commitdiff
network: Add reset option.
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 16 Jul 2010 16:15:24 +0000 (18:15 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 16 Jul 2010 16:15:24 +0000 (18:15 +0200)
functions.cli
functions.ports
network

index 56db94c054b145a4c31ae545f1292fcad26d8a10..14b764d96af348bbb41b4bb81e936c45dfda756a 100644 (file)
@@ -310,6 +310,49 @@ function cli_status() {
        done
 }
 
+function cli_reset() {
+       if cli_help_requested $@; then
+               cli_usage root-reset
+               exit ${EXIT_OK}
+       fi
+
+       warning_log "Will reset the whole network configuration!!!"
+
+       # Force mode is disabled by default
+       local force=0
+
+       while [ $# -gt 0 ]; do
+               case "${1}" in
+                       --force|-f)
+                               force=1
+                               ;;
+               esac
+               shift
+       done 
+
+       # If we are not running in force mode, we ask the user if he does know
+       # what he is doing.
+       if ! enabled force; then
+               if ! cli_yesno "Do you really want to reset the whole network configuration?"; then
+                       exit ${EXIT_ERROR}
+               fi
+       fi
+
+       local zone
+       for zone in $(zones_get --all); do
+               zone_remove ${zone}
+       done
+
+       local port
+       for port in $(ports_get --all); do
+               port_remove ${port}
+       done
+
+       # XXX recreate ethernet ports
+
+       exit ${EXIT_OK}
+}
+
 function cli_help_requested() {
        local argument
        for argument in ${1}; do
@@ -351,6 +394,16 @@ function cli_usage() {
                        echo    "    ${0} ${what#root-} DEBUG=1 ..."
                        echo
                        ;;
+               root-reset)
+                       echo    "${0}: ${what#root-} [--force | -f]"
+                       echo
+                       echo    "  This command resets the network configuration."
+                       echo
+                       echo    "  Will delete all zones and ports."
+                       echo
+                       echo -e "  ${COLOUR_RED}USE WITH CAUTION!${COLOUR_NORMAL}"
+                       echo
+                       ;;
                root-start|root-stop|root-restart)
                        echo    "${0}: ${what#root-} [--local-only|--remote-only|--all|<zone>...]"
                        echo
@@ -436,3 +489,18 @@ function cli_headline() {
        echo
        echo -e "${COLOUR_BOLD}$@${COLOUR_NORMAL}"
 }
+
+function cli_yesno() {
+       local message="$@ [y/N] "
+       local yesno
+
+       echo
+       echo -ne "${message}"
+       read yesno
+
+       if listmatch ${yesno} y Y j J yes YES Yes; then
+               return ${EXIT_OK}
+       fi
+
+       return ${EXIT_ERROR}
+}
index 25ce046c3104e821cee8c08170e25de9106f9ade..d0d7dee62398c0ad7d6717351adb3c22966b24fc 100644 (file)
@@ -93,6 +93,10 @@ function port_destroy() {
        rm -f $(port_file ${port})
 }
 
+function port_remove() {
+       port_destroy $@
+}
+
 function port_edit() {
        port_cmd edit $@
 }
@@ -128,3 +132,13 @@ function port_cmd() {
 
        hook_exec port ${hook} ${cmd} ${port} $@
 }
+
+function ports_get() {
+       local port
+       for port in $(port_dir)/*; do
+               port=$(basename ${port})
+               if port_exists ${port}; then
+                       echo "${port}"
+               fi
+       done
+}
diff --git a/network b/network
index e315b19ada70208e9a026fa16953ef6c15208051..d4a75b83bcf0fc4dafacdf23fcc3abd5f764a337 100755 (executable)
--- a/network
+++ b/network
@@ -38,7 +38,7 @@ done
 
 # Process the given action
 case "${action}" in
-       config|port|device|zone|start|stop|restart|status)
+       config|port|device|zone|start|stop|restart|status|reset)
                cli_${action} $@
                ;;