All pastes #544247 Raw Edit

Something

public shellscript v1 · immutable
·published 2007-06-06 11:09 UTC
rendered paste body
#!/bin/bash## Variables#TEMP=/tmp/dnse/dnse.$$## Remove temporary files and exit script#clean_up(){#  rm -f /tmp/dnse.*#  rm -f /tmp/dnse_input.*#  rm -f /tmp/dnse_input2.*  rm -rf /tmp/dnse  exit}## Edit the DNS settings#edit_dns(){  dialog --nocancel \         --backtitle "DNS Editor v1.0" \         --title "Edit DNS settings" \	 --menu "Use [UP] [DOWN] to move, [ENTER] to select and [ESC] to exit. \	         Doing this will over write your current /etc/resolv.conf. Only do these steps if you're sure you wish to do so" 20 40 4 \	 Stored "Use stored settings" \	 New "Change to new settings" \	 Main "Go back to the main menu" \	 Exit "Exit the script" 2>$TEMP  OPT=$?  SELECT=`cat $TEMP`  case $OPT in    0)       case $SELECT in         Stored)                 if [ $(id -u) != "0" ]; then		   dialog --backtitle "DNS Editor v1.0" \		          --title "Alert : Root Required!" \			  --yesno "You are currently not running as root! This feature is unavailable. Please exit and rerun this script to enable this feature. \			           Would you like to exit?" 6 80		    SEL=$?		    case $SEL in		      0)		        clean_up;;		      1)		        edit_dns;;		    esac		 else		   if [ -e $HOME/.dnseditor ] ; then		     cp ~/.dnseditor /etc/resolv.conf		     dialog --backtitle "DNS Editor v1.0" \		 	    --title "Copying settings" \			    --infobox "Copying stored DNS settings to /etc/resolv.conf" 5 40	           else		     dialog --backtitle "DNS Editor v1.0" \		            --title "Error" \		            --infobox "Could not find ~/.dnseditor. Please go to create new settings and select the save option!" 8 40 		   fi		 fi		 sleep 1s		 edit_dns;;	 New)                  if [ $(id -u) != "0" ]; then		   dialog --backtitle "DNS Editor v1.0" \		          --title "Alert : Root Required!" \			  --yesno "You are currently not running as root! This feature is unavailable. Please exit and rerun this script as root to enable this feature. \			           Would you like to exit?" 6 80		   SEL=$?		   case $SEL in		     0)		       clean_up;;		     1)		       edit_dns;;		   esac		 else		   dialog --nocancel \		          --backtitle "DNS Editor v1.0" \                          --title "DNS Server #1" \		          --inputbox "Enter 1st DNS setting" 8 40 2>/tmp/dnse/input.$$                   SEL=$?		   NA=`cat /tmp/dnse/input.$$`		   case $SEL in		     0)		       dialog --extra-button \		              --extra-label "Save" \		              --nocancel \		              --backtitle "DNS Editor v1.0" \			      --title "DNS server #2" \			      --inputbox "Enter 2nd DNS setting" 8 40 2>/tmp/dnse/input2.$$		       SEL=$?		       NA1=`cat /tmp/dnse/input2.$$`		       case $SEL in		         0)		           `echo "nameserver $NA" > /etc/resolv.conf`		           `echo "nameserver $NA1" >> /etc/resolv.conf`			   dialog --backtitle "DNS Editor v1.0" \		                  --title "Copying DNS settings" \			          --infobox "Copying new settings to /etc/resolv.conf. Please wait.\n$NA\n$NA1" 8 40		           sleep 1s;;		         3)		           `echo "nameserver $NA" > $HOME/.dnseditor`			   `echo "nameserver $NA1" >> $HOME/.dnseditor`			   cp $HOME/.dnseditor /etc/resolv.conf			   dialog --backtitle "DNS Editor v1.0" \			          --title "Saving" \			  	  --infobox "Saving and setting your current settings of \n$NA\n$NA1" 8 40			   sleep 1s;;		       esac		   esac		   edit_dns	       fi	       sleep 1s	       edit_dns;;	 Main)	         main_menu;;	 Exit)	         clean_up;;       esac;;    255)       clean_up;;  esac}## View the current DNS settings#view_dns(){  CURRENT=`cat /etc/resolv.conf`  dialog --backtitle "DNS Editor v1.0" \	 --title "Current DNS settings" \	 --infobox "Your current DNS settings are:\n$CURRENT" 6 35  sleep 2s  main_menu}## The main menu of the script#main_menu(){  dialog --nocancel \         --backtitle "DNS Editor v1.0" \         --title "Main Menu" \         --menu "Use [UP] [DOWN] to move, [ENTER] to select and [ESC] to exit" 20 40 3 \	 View "View the current DNS settings" \	 Edit "Edit the DNS settings" \	 Exit "Exit the script" 2>$TEMP  OPT=$?  SELECT=`cat $TEMP`  case $OPT in    0)       case $SELECT in         View) view_dns;;	 Edit) edit_dns;;	 Exit) clean_up;;       esac;;    255)       clean_up;;  esac}## Check if the user is running the script as root#mkdir /tmp/dnseif [ $(id -u) != "0" ]; then  dialog --backtitle "DNS Editor v1.0" \  	 --title "Alert : Root Required" \  	 --yesno "\nYou are currently not running as root! Some features in this script will not be usable. Would you like to continue anyway?" 8 60  SEL=$?  case $SEL in    0)        main_menu;;    1)        clean_up;;    255)        clean_up;;  esacelse  main_menufi