flavors diff proxy/rootfs/usr/bin/tazctl @ rev 158

Add Proxy (squid + sqduidclamav + SquidGuard + sarg)
author Eric Joseph-Alexandre <erjo@slitaz.org>
date Thu Mar 15 00:56:34 2012 +0100 (2012-03-15)
parents
children b15932f93d49
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/proxy/rootfs/usr/bin/tazctl	Thu Mar 15 00:56:34 2012 +0100
     1.3 @@ -0,0 +1,227 @@
     1.4 +#!/bin/sh
     1.5 +# Tazadmin - SliTaz System Configuration
     1.6 +#
     1.7 +#
     1.8 +# Author : Eric Joseph-Alexandre (Erjo) <erjo@slitaz.org>
     1.9 +#           
    1.10 +
    1.11 +#export DIALOGRC=$PWD/rc/slackware.rc
    1.12 +
    1.13 +VERSION=1.0
    1.14 +
    1.15 +: ${DIALOG=dialog}
    1.16 +
    1.17 +BACKTITLE="SliTaz Configuration Tools v.${VERSION}"
    1.18 +COMMAND=$1
    1.19 +LOG=/tmp/$(basename $0).log
    1.20 +OUT=/tmp/_retval_
    1.21 +DATADIR=/usr/share/slitaz-tools/tazadmin/
    1.22 +#DATADIR=./
    1.23 +
    1.24 +BS="15 50"
    1.25 +
    1.26 +# Messages language setting
    1.27 +# Switch to default English if $LANG.msg doesn't exist.
    1.28 +set_locale()
    1.29 +{
    1.30 +	if [ -f ${LANG%%_*}.msg ]; then
    1.31 +		. ${DATADIR}${LANG%%_*}.msg
    1.32 +	fi
    1.33 +}
    1.34 +
    1.35 +# use  --msgbox.
    1.36 +# syntax: msg ["Title"] "Message text"
    1.37 +msg()
    1.38 +{
    1.39 +	if [ $# -gt 1 ]; then
    1.40 +		TITLE=$1
    1.41 +		shift
    1.42 +		MSG="$@"
    1.43 +	else
    1.44 +		MSG="$@"
    1.45 +	fi
    1.46 +	$DIALOG --title " ${TITLE:-Message} " \
    1.47 +		--colors --backtitle "$BACKLIST" \
    1.48 +		--clear --msgbox "\n$MSG" 0 0
    1.49 +}
    1.50 +
    1.51 +# Exit install if user is not root.
    1.52 +check_root()
    1.53 +{
    1.54 +	if test $(id -u) != 0 ; then
    1.55 +		error_message "$ERR_CHK_ROOT"
    1.56 +		exit 0
    1.57 +	fi
    1.58 +}
    1.59 +
    1.60 +# functions
    1.61 +#
    1.62 +trim(){
    1.63 +	read LINE
    1.64 +	echo $LINE
    1.65 +}
    1.66 +
    1.67 +get_argc()
    1.68 +{
    1.69 +	echo $#
    1.70 +}
    1.71 +
    1.72 +
    1.73 +
    1.74 +
    1.75 +get_hostname()
    1.76 +{
    1.77 +	# Set hostname
    1.78 +	HOSTNAME=$(cat /etc/hostname)
    1.79 +	exec 3>&1
    1.80 +	HOSTNAME=`$DIALOG --backtitle "$BACKTITLE"  --title "Hostname" --clear  \
    1.81 +        --inputbox "Enter your computer hostname" $BS "${HOSTNAME}" 2>&1 1>&3`
    1.82 +	ret=$?
    1.83 +	exec 3>&-
    1.84 +	# if $HOSTNAME is set we update /etc/hostname
    1.85 +	# and change current hostname.
    1.86 +	if [ ! -z ${HOSTNAME} ]; then
    1.87 +		echo ${HOSTNAME} > /etc/hostname
    1.88 +		hostname $(cat /etc/hostname)
    1.89 +	fi
    1.90 +}	
    1.91 +
    1.92 +set_ip_adress()
    1.93 +{
    1.94 +	# Set static configuration for Network.
    1.95 +	. /etc/network.conf	
    1.96 +	exec 3>&1
    1.97 +	IPCONFIG=`$DIALOG --ok-label "Submit" \
    1.98 +     	 --backtitle "$backtitle" --extra-button --extra-label "${BTN_DHCP:-Use DHCP server}"\
    1.99 +      	--form "Here is a possible piece of a configuration program." \
   1.100 +		15 55 0 \
   1.101 +    	"IP Adress:" 1 1 "$IP" 1 20 20 0 \
   1.102 +    	"Network mask:"      2 1 "$NETMASK"  2 20  20 0 \
   1.103 +    	"Default gateway:"      3 1 "$GATEWAY"  3 20  20 0 \
   1.104 +    	"DNS server(s):"     4 1 "$DNS_SERVER" 4 20 20 0 \
   1.105 +    	2>&1 1>&3`
   1.106 +		ret=$?
   1.107 +		exec 3>&-
   1.108 +		
   1.109 +	case "$ret" in
   1.110 +		0)
   1.111 +			if  [[ "`get_argc $IPCONFIG`" -gt "1" ]]; then
   1.112 +				set_static_ip $IPCONFIG
   1.113 +			else
   1.114 +				msg "${ERR_BED_IP:-Invalid values.}"
   1.115 +			fi
   1.116 +			;;
   1.117 +		3)
   1.118 +			get_dhcp_lease ;;
   1.119 +	esac	
   1.120 +}
   1.121 +
   1.122 +get_dhcp_lease()
   1.123 +{
   1.124 +	sed -i 's/DHCP=.*/DHCP="yes"/' /etc/network.conf
   1.125 +	sed -i 's/STATIC=.*/STATIC="no"/' /etc/network.conf
   1.126 +	/sbin/udhcpc -b -i $INTERFACE -p /var/run/udhcpc.$INTERFACE.pid &
   1.127 +}
   1.128 +
   1.129 +set_static_ip()
   1.130 +{
   1.131 +	sed -i 's/DHCP=.*/DHCP="no"/' /etc/network.conf
   1.132 +	sed -i 's/STATIC=.*/STATIC="yes"/' /etc/network.conf
   1.133 +	sed -i -e "s/IP=".*"/IP=\"$1\"/" /etc/network.conf
   1.134 +	sed -i -e "s/NETMASK=".*"/NETMASK=\"$2\"/" /etc/network.conf
   1.135 +	sed -i -e "s/GATEWAY=".*"/GATEWAY=\"$3\"/" /etc/network.conf
   1.136 +	sed -i -e "s/DNS_SERVER=".*"/DNS_SERVER=\"$4\"/" /etc/network.conf
   1.137 +}
   1.138 +	
   1.139 +network_menu()
   1.140 +{
   1.141 +	ret=0
   1.142 + 	until [ $ret -eq 1 ];do
   1.143 +    	$DIALOG --title "$MENU_TITLE" \
   1.144 +        	--backtitle "$BACKTITLE" --clear \
   1.145 +        	--cancel-label "Quitter" \
   1.146 +        	--colors \
   1.147 +        	--menu "$TAZ_CMD_MSG" 15 50 40\
   1.148 +        	"adress"  	"  Network settings" \
   1.149 +        	"hostname"  	"  Set your hostname" \
   1.150 +        	2> $OUT
   1.151 +    	ret=$?
   1.152 +    	case `cat $OUT` in
   1.153 +       	hostname)
   1.154 +			get_hostname ;;
   1.155 +       	adress)
   1.156 +       		set_ip_adress ;;
   1.157 +    	esac
   1.158 +	done
   1.159 +}
   1.160 +
   1.161 +set_password()
   1.162 +{
   1.163 +	SEP='
   1.164 +'
   1.165 +	exec 3>&1
   1.166 +	PASSWORD=`$DIALOG --backtitle "$BACKTITLE" --title "Set password" --clear \
   1.167 + 		--separate-widget "$SEP" \
   1.168 + 		--insecure --passwordbox "Enter new password for user below: \n\n" 10 50 \
   1.169 +		--title "Confirme password" \
   1.170 +        --insecure --passwordbox "Confirme new password for user below: \n\n"	10 50 2>&1 1>&3`
   1.171 +	ret=$?
   1.172 +	exec 3>&-
   1.173 +	if [ -z "${PASSWORD}" ]; then
   1.174 +		msg "Password not set"
   1.175 +	else
   1.176 +		PASS1="$(echo $PASSWORD | cut -d ' ' -f1)"
   1.177 +		PASS2="$(echo $PASSWORD | cut -d ' ' -f2)"
   1.178 +		if [ "$PASS1" != "$PASS2" ]; then
   1.179 +			msg "Passwords don't match.\nNothing change."
   1.180 +		else
   1.181 +			echo  "root:$PASS1" | chpasswd
   1.182 +		fi
   1.183 +	fi
   1.184 +}
   1.185 +
   1.186 +##
   1.187 +# Program sequence
   1.188 +#
   1.189 +set_locale
   1.190 +check_root
   1.191 +
   1.192 +until [ $retval -eq 1 ];do
   1.193 +	$DIALOG --title "$MENU_TITLE" \
   1.194 +		--backtitle "$BACKTITLE" --clear \
   1.195 +		--cancel-label "Quitter" \
   1.196 +		--colors \
   1.197 +		--menu "$TAZ_CMD_MSG" 15 50 40\
   1.198 +		"keymap"  		"  Keyboard mapping" \
   1.199 +		"locale"      	"  Language setting" \
   1.200 +		"network"   	"  Netwok configuration" \
   1.201 +		"password" 		"  Change root password" \
   1.202 +		2> $OUT
   1.203 +	
   1.204 +	retval=$?
   1.205 +	
   1.206 +	# Execute commands
   1.207 +	#
   1.208 +	case `cat $OUT` in
   1.209 +		keymap)
   1.210 +			if [ -x /sbin/tazkeymap ]; then
   1.211 +				tazkeymap
   1.212 +			else
   1.213 +				msg "Unable to find tazkeymap !"
   1.214 +			fi
   1.215 +			;;
   1.216 +		locale)
   1.217 +			if [ -x /sbin/tazlocale ]; then
   1.218 +				tazlocale
   1.219 +			else
   1.220 +				msg "Unable to find tazlocale !"
   1.221 +			fi
   1.222 +			;;
   1.223 +		network)
   1.224 +			network_menu;;
   1.225 +		password)
   1.226 +			set_password ;;
   1.227 +	esac
   1.228 +done
   1.229 +
   1.230 +exit 0