#!/bin/bash -i
#
# ZigzagProxy (ZPROXY)
# 
# This program is free software: you can redistribute it and/or modify it 
# under the terms of the GNU General Public License as published 
# by the Free Software Foundation; either version 3 of the License, 
# or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, 
# but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License 
# along with this program. If not, see http://www.gnu.org/licenses/. 
# 
# Copyright (C) 2012
# Free Software Foundation, Inc.
# 
# For information or to collaborate on the project:
# https://savannah.nongnu.org/projects/zproxy
# 
# Gianluca Zoni
# http://inventati.org/zoninoz
# zoninoz@inventati.org
#


#### CONFIG
# NB: se si usa "source" oppure "." prima dello script, ovviamente "$prog" è "/bin/bash", quindi è meglio scegliere un nome al posto di basename:
#prog=`basename $0`

prog="zproxy"
path_chrome="/usr/bin"
unset http_proxy

#### layout

function init_colors {
	# Reset
    Color_Off='\e[0m'       # Text Reset
    
	# Regular Colors
    Black='\e[0;30m'        # Nero
    Red='\e[0;31m'          # Rosso
    Green='\e[0;32m'        # Verde
    Yellow='\e[0;33m'       # Giallo
    Blue='\e[0;34m'         # Blu
    Purple='\e[0;35m'       # Viola
    Cyan='\e[0;36m'         # Ciano
    White='\e[0;37m'        # Bianco
    
	# Bold
    BBlack='\e[1;30m'       # Nero
    BRed='\e[1;31m'         # Rosso
    BGreen='\e[1;32m'       # Verde
    BYellow='\e[1;33m'      # Giallo
    BBlue='\e[1;34m'        # Blu
    BPurple='\e[1;35m'      # Viola
    BCyan='\e[1;36m'        # Ciano
    BWhite='\e[1;37m'       # Bianco
    
	# Underline
    UBlack='\e[4;30m'       # Nero
    URed='\e[4;31m'         # Rosso
    UGreen='\e[4;32m'       # Verde
    UYellow='\e[4;33m'      # Giallo
    UBlue='\e[4;34m'        # Blu
    UPurple='\e[4;35m'      # Viola
    UCyan='\e[4;36m'        # Ciano
    UWhite='\e[4;37m'       # Bianco
    
	# Background
    On_Black='\e[40m'       # Nero
    On_Red='\e[41m'         # Rosso
    On_Green='\e[42m'       # Verde
    On_Yellow='\e[43m'      # Giallo
    On_Blue='\e[44m'        # Blu
    On_Purple='\e[45m'      # Purple
    On_Cyan='\e[46m'        # Ciano
    On_White='\e[47m'       # Bianco
    
	# High Intensty
    IBlack='\e[0;90m'       # Nero
    IRed='\e[0;91m'         # Rosso
    IGreen='\e[0;92m'       # Verde
    IYellow='\e[0;93m'      # Giallo
    IBlue='\e[0;94m'        # Blu
    IPurple='\e[0;95m'      # Viola
    ICyan='\e[0;96m'        # Ciano
    IWhite='\e[0;97m'       # Bianco
    
	# Bold High Intensty
    BIBlack='\e[1;90m'      # Nero
    BIRed='\e[1;91m'        # Rosso
    BIGreen='\e[1;92m'      # Verde
    BIYellow='\e[1;93m'     # Giallo
    BIBlue='\e[1;94m'       # Blu
    BIPurple='\e[1;95m'     # Viola
    BICyan='\e[1;96m'       # Ciano
    BIWhite='\e[1;97m'      # Bianco
    
	# High Intensty backgrounds
    On_IBlack='\e[0;100m'   # Nero
    On_IRed='\e[0;101m'     # Rosso
    On_IGreen='\e[0;102m'   # Verde
    On_IYellow='\e[0;103m'  # Giallo
    On_IBlue='\e[0;104m'    # Blu
    On_IPurple='\e[10;95m'  # Viola
    On_ICyan='\e[0;106m'    # Ciano
    On_IWhite='\e[0;107m'   # Bianco
}


function print_c {
    case "$1" in
	1)
	    echo -n -e '\e[1;32m' #verde
	    ;;
	2)
	    echo -n -e '\e[1;33m' #giallo
	    ;;	
	3)
	    echo -n -e '\e[1;31m' #rosso
	    ;;	
	4)
	    echo -n -e "$BBlue"
    esac
    echo -n -e "$2\n"
    echo -n -e "${Color_Off}"
}

function separator {
	#COLUMNS=$( tput cols ) 2>/dev/null
    if [ -z "$COLUMNS" ]; then 
	COLUMNS=50
    fi
    echo -n -e "${BBlue}"
    for column in `seq 1 $COLUMNS`; do echo -n -e "$1" ; done #\e[1;34m
    echo -n -e "${Color_Off}"
}


function separator- {
    separator "─"
}

function fclear {
	#echo -n -e "\e[0;37m\e[40m\ec"
	#echo -n -e "\ec\e[37m\e[40m\e[J"
    echo -n -e "\ec${White}${On_Black}\e[J"
}

function cursor {
    stato=$1
    case $stato in
	off)
	    echo -e -n "\033[?30;30;30c" ;;
	on)
	    echo -e -n "\033[?0;0;0c" ;;
    esac
}

function header { # $1=label ; $2=colors ; $3=header pattern
	# echo -n -e "\e[1;34m $1 ${Color_Off}\n"
    text="$1"
    length_text=$(( ${#text}+2 ))

    hpattern="$3"
    [ -z "$hpattern" ] && hpattern=" "
    echo -n -e "${2}"
    for column in `seq 1 $COLUMNS`; do
	echo -n -e "$hpattern" 
    done 
    if [ ! -z "$length_text" ] && [ ! -z "$COLUMNS" ] && (( $length_text<=$COLUMNS )); then
	echo -n -e "\r$text${Color_Off}\n"
    elif [ ! -z "$length_text" ] && [ ! -z "$COLUMNS" ]; then
	echo -n -e "\r${text:0:$COLUMNS}${Color_Off}${text:$COLUMNS}\n"
    fi
}


function header_z {
    fclear
    zclock
    header " ZigzagProxy ($prog) $zclock" "$On_Blue" " "
}

function header_box {
    header " $1 " "$Black${On_White}" "─" #"-" 
}

function header_dl {
    header " $1 " "$White${On_Blue}" " "
}

function pause {
    echo
    header ">>>>>>>> Digita un tasto per continuare " "$On_Blue$BWhite" "<"
    cursor off
    read -n 1
    cursor on
}

function xterm_stop {
    echo
    header ">>>>>>>> Digita < Enter > per chiudere Xterm " "$On_Blue$BWhite" "<"
    cursor off
    read -n 1
    cursor on
}
function zclock {
    week=( "dom" "lun" "mar" "mer" "gio" "ven" "sab" )
    zclock="\033[1;$((COLUMNS-22))f$(date +%R) │ ${week[$( date +%w )]} $(date +%d·%m·%Y)"
}



## INIT
declare -A list_proxy_url

function init {
    PROG=`echo $prog | tr a-z A-Z`
    path_prog="$HOME/$prog"
    mkdir -p "$path_prog"
	#proxy_types=( Transparent )
    credentials="$HOME/${prog}/.credenziali_router.txt"
    max_waiting=40
    
    url_update="http://inventati.org/zoninoz/html/upload/files/zproxy"

    proxy_server="ip_adress"
    list_proxy_url["ip_adress"]="http://zoninoz.hostoi.com" #www.ip-adress.com/proxy_list/"
    list_proxy_url["proxy_list"]="http://proxy-list.org/en/index.php"

    ck_proxy_url="http://inventati.org/zoninoz/html/index.php"
	#ck_proxy_url="https://savannah.nongnu.org"
    
    unset h r u d dff t a e ff ffox rff c dc chromium ip
    init_colors
}

## procedure

function my_ip {
    myip=`wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//'`
    echo "Indirizzo IP: $myip"
    echo
}

function new_ip_router {
    if [ -f $credentials ]; then
	USER=`cat "$credentials" |awk '{ print($1) }'`
	PASSWD=`cat "$credentials" |awk '{ print($2) }'`

	print_c 1 "Cambio indirizzo IP..."
	wget --http-passwd=$PASSWD --http-user=$USER 192.168.0.1/stanet.stm  -O - &>/dev/null
		#my_ip
	wget --http-passwd=$PASSWD --http-user=$USER --post-data="disconnect=1" 192.168.0.1/cgi-bin/statusprocess.exe -O - &>/dev/null
		#my_ip
	echo
    else
	print_c 3 "Funzione di cambio indirizzo IP (riconnessione del router) disattivata: non esiste il file di configurazione $credentials"
    fi

}

function new_ip_proxy {
    [ ! -f "$path_prog/proxy_${proxy_types[0]}.txt" ] && update_proxy
    num=`wc -l "$path_prog/proxy_${proxy_types[0]}.txt" | awk '{ print($1) }'`
    newproxy=`cat "$path_prog/proxy_${proxy_types[0]}.txt" | sed -n "${num}p"`
    no_proxy
    export http_proxy="$newproxy"
    print_c 1 "Proxy ${proxy_type} attivato: $http_proxy"
}

function no_proxy {
    unset http_proxy
    export http_proxy
}

function _firefox_noproxy {
    firefox_pref="user_pref(\"network.proxy.type\", 1);"
    sed -i "s/${firefox_pref}//g" $HOME/.mozilla/firefox/*.default/prefs.js
}

function save_ffprefs {
    if [ ! -d "$path_prog/ripristino" ]; then
	mkdir -p "$path_prog/ripristino"
	
	ls  $HOME/.mozilla/firefox/*.default/prefs.js | while read file1; do
	    file=${file1//default\/prefs.js/default_prefs.js}
	    file=${file##*\/}
	    cp $file1 "$path_prog/ripristino/$file"
	    echo "cp $file1 $path_prog/ripristino/$file"
	done
	echo
	print_c 1 "Le preferenze di Firefox sono state salvate in $path_prog/ripristino/ per consentirne un eventuale ripristino con il seguente comando: $prog -rff"
	echo
    fi
}

function restore_ffprefs {
    if [ -d "$path_prog/ripristino" ]; then
	ls  $path_prog/ripristino/ | while read file1; do
	    file=${file1#${path_prog}\/ripristino\/}
	    file="$HOME/.mozilla/firefox/${file}"
	    file=${file//default_prefs.js/default\/prefs.js}
	    cp $path_prog/ripristino/$file1 $file
	    echo "cp $path_prog/ripristino/$file1 $file"
	done
	echo
	print_c 1 "Le preferenze di Firefox sono state ripristinate da $path_prog/ripristino/"
	echo
	rm -r "$path_prog/ripristino"
    else
	print_c 3 "Impossibile il ripristino delle preferenze di Firefox: la directory $path_prog/ripristino/ è inesistente"
    fi
}

function _proxy {
    
    if [ -f "$path_prog/proxy_${proxy_types[0]}.txt" ]; then
	num=`wc -l "$path_prog/proxy_${proxy_types[0]}.txt" | awk '{ print($1) }'`
	newproxy=`cat $path_prog/proxy_${proxy_types[0]}.txt | sed -n "${num}p"`
    else
	update_proxy
    fi
}


function _firefox {
    save_ffprefs
    
    update_proxy
    
    ip=${newproxy%:*}
    port=${newproxy#*:}
    _proxy_http="user_pref(\"network.proxy.http\", \"$ip\");"
    _proxy_http_port="user_pref(\"network.proxy.http_port\", $port);"
    _proxy_type="user_pref(\"network.proxy.type\", 1);"
    

    ls $HOME/.mozilla/firefox/*.default/prefs.js | while read file; do
	for key in 'proxy.http\"' 'network.proxy.http_port' 'network.proxy.type' ; do
	    
	    firefox_pref=`cat $file |grep $key`
			#echo $key
	    case $key in
		'proxy.http\"')
		    new_pref="$_proxy_http"
					#echo new_pref="$_proxy_http"
		    
		    ;;
		'network.proxy.http_port')
		    new_pref="$_proxy_http_port"
					#echo new_pref="$_proxy_http_port"
		    
		    ;;
		'network.proxy.type')
		    new_pref="$_proxy_type"
					#echo new_pref="$_proxy_type"
		    if [ "$firefox_pref" != "user_pref(\"network.proxy.type\", 1);" ] && [ -z $ff_prefs ]; then 
			touch $path_prog/.ff_noproxy
		    fi
		    ;;
	    esac
			#echo firefox_pref=$firefox_pref
	    if [ -z "${firefox_pref}" ]; then
		echo ${new_pref} >> $file
	    else
		sed -i "s/${firefox_pref}/${new_pref}/g" $file
		
				#text=`cat $file`
				#echo "${text//${firefox_pref}/${new_pref}}" > $file
	    fi
	done
    done
}

function noproxy {
    unset http_proxy
    export http_proxy
}


## servizi che offrono liste di proxy
function ip_adress {
    ## ip-adress.com
    
    for proxy_type in ${proxy_types[*]}; do
	cat "$path_prog/proxy.tmp"|grep "Proxy_Details" |grep "${proxy_type}" >> "$path_prog/proxy2.tmp"
    done

    max=`wc -l "$path_prog/proxy2.tmp" | awk '{ print($1) }'`
    
    string_line=`cat "$path_prog/proxy2.tmp" |sed -n "${line}p"`
    
    proxy="${string_line#*Proxy_Details\/}"
    [ "$proxy" != "${proxy%:Anonymous*}" ] && proxy_type="Anonymous"
    [ "$proxy" != "${proxy%:Transparent*}" ] && proxy_type="Transparent"
    [ "$proxy" != "${proxy%:Elite*}" ] && proxy_type="Elite"
    proxy="${proxy%:${proxy_type}*}"
}

function proxy_list {
    ## proxy-list.org
    for proxy_type in ${proxy_types[*]}; do
	html=$(cat  "$path_prog/proxy.tmp" | grep -B 4 "${proxy_type}" |grep class)
    done
    n=$(( $(wc -l <<< "$html")/4 ))
    proxy_type=$(sed -n $(( ${line}*4 ))p <<< "$html")
    proxy_type="${proxy_type%%'</'*}"
    proxy_type="${proxy_type##*>}"

    proxy=$(sed -n $(( ${line}*4-3 ))p <<< "$html")
    proxy="${proxy#*proxy\">}"
    proxy="${proxy%<*}"
}

function update_proxy {
    maxspeed=0
    minspeed=25
    unset close unreached speed ptypes
    rm -f "$path_prog/proxy.tmp"
    #proxy_types=( "Transparent" "Anonymous" "Elite" )
    while true; do
	unset proxy
	#### tipi di proxy: Anonymous Transparent Elite
	if [ -z "${proxy_types[*]}" ]; then
	    proxy_types=( "Transparent" )
	fi
	ptypes="${proxy_types[*]}"
	print_c 1 "Aggiorna proxy (${ptypes// /, }):"
	old=$http_proxy
	
	noproxy
	line=1
	while [ -z "$proxy" ] ; do		
	    if [ ! -f "$path_prog/proxy.tmp" ]; then
		wget -q -t 1 -T 20 --post-data="cmd=pr0xylist" --user-agent="Anonimo" ${list_proxy_url[$proxy_server]} -O "$path_prog/proxy.tmp" &>/dev/null
		print_c 4 "Ricerca lista proxy $proxy_server: ${list_proxy_url[$proxy_server]}"
	    fi
	    rm -f "$path_prog/proxy2.tmp"
	    [ -f "$path_prog/proxy.tmp" ] && $proxy_server
	    
	    z=$(( ${#proxy_done[*]}-1 ))
	    if (( $z<0 )) || [ "$z" == "" ]; then z=0 ; fi
	    
	    for p in `seq 0 $z`; do
		if [ "${proxy_done[$p]}" == "$proxy" ]; then
		    proxy=""
		fi
	    done
	    
	    if [ "$string_line" == "" ]; then
		#echo -n -e "|"
		sleep 3
		(( search_proxy++ ))
		[ $search_proxy == 100 ] && print_c 3 "Finora nessun proxy disponibile: tentativo con proxy disattivato" && noproxy && close=true && break
	    fi
	    if [ "$line" == "$max" ] || [ "$string_line" == "" ]; then
		rm -f "$path_prog/proxy.tmp"
		line=0
	    fi
	    (( line++ ))
	    [ "$proxy" != "" ] && [ "${proxy_done[*]}" == "${proxy_done[*]//$proxy}" ] && proxy_done[${#proxy_done[*]}]="$proxy"
	done
	unset search_proxy
	[ ! -z $close ] && break
	http_proxy=$proxy
	export http_proxy
	echo -n "Proxy: $http_proxy ($proxy_type)"
	echo
	unset myip
		#my_ip
		#echo "Nuovo IP: $myip"
	print_c 2 "Test velocità di download:"
	i=0
	while (( $i<3 )); do
	    i=${#speed[*]}
	    speed[$i]=`wget -t 1 -T $max_waiting -O /dev/null "$ck_proxy_url" 2>&1 | grep '\([0-9.]\+ [KM]B/s\)'`
	    if [ ! -z "${speed[$i]}" ]; then
		speed[$i]="${speed[$i]#*'('}"
		speed[$i]="${speed[$i]%%)*}"
		
		type_speed[$i]="${speed[$i]//[0-9. ]}"
		num_speed[$i]="${speed[$i]//${type_speed[$i]}}"
		num_speed[$i]="${num_speed[$i]//[ ]*}"
		num_speed[$i]="${num_speed[$i]//[.,]*}"
		
		if [ "${type_speed[$i]}" == 'B/s' ]; then
		    num_speed[$i]="0"
		elif [ "${type_speed[$i]}" == 'MB/s' ]; then
		    num_speed[$i]=$(( ${num_speed[$i]}*1024 ))
		fi
	    else
		speed[$i]="0 KB/s"
		num_speed[$i]="0"
		type_speed[$i]='KB/s'
	    fi
	    
	    echo "${speed[$i]}"
	done 2>/dev/null
	
	if [ -z $unreached ]; then
	    for k in ${num_speed[*]}; do  
		if (( $maxspeed<$k )); then 
		    maxspeed=$k 
		fi 
	    done
	    
	    if (( $maxspeed<$minspeed )); then
		print_c 3 "La massima velocità di download raggiunta usando il proxy è inferiore a quella minima richiesta ($minspeed KB/s)"
				#unset $proxy
		
	    else
		print_c 1 "Massima velocità di download raggiunta usando il proxy $http_proxy: $maxspeed KB/s"
		echo "$http_proxy" >> "$path_prog/proxy_${proxy_type}.txt"
		newproxy="$http_proxy"
		break
	    fi 2>/dev/null
	fi
	unset unreached speed
    done
    unset maxspeed
    echo
    rm -f "$path_prog/proxy.tmp"
    old_proxy="$proxy"
}

function update_prog {
    print_c 1 "Aggiornamento di $PROG ..."
    wget -T $max_waiting "$url_update" -O /tmp/$prog 
    print_c 1 "Installazione di $PROG in /usr/local/bin/"
    ( mv /tmp/$prog /usr/local/bin/$prog ; chmod +x /usr/local/bin/$prog ; print_c 1 "Aggiornamento completato." ) || ( sudo mv /tmp/$prog /usr/local/bin/$prog ; sudo chmod +x /usr/local/bin/$prog ; print_c 1 "Aggiornamento completato." ) || ( echo -n "(Root)" ; su -c "mv /tmp/$prog /usr/local/bin/$prog ; chmod +x /usr/local/bin/$prog" ; print_c 1 "Aggiornamento completato." ) || ( print_c 3 "Aggiornamento automatico non riuscito" )
    echo
}

function usage {
    echo -e -n '\e[0m\e[J'
    echo -e -n "\e[0m\e[J
\e[1mUso (l'ordine degli argomenti non è importante): \e[0m"
	echo -e "$prog [OPZIONI]

\e[1mOpzioni:\e[0m
-h,	--help		      Manuale di ZigzagProxy

-ip                           Indirizzo IP attuale

-up     --update-proxy        Aggiorna proxy
	
-u      --update              Aggiorna ZigzagProxy
	
-d      --disable             Disabilita il proxy
	
-t      --transparent
-a      --anonymous
-e      --elite               Seleziona il tipo di proxy: Transparent, Anonymous, Elite
	
-r      --reconnect           Forza la riconnessione del modem (funziona solo per pochi modelli)
	
-ff     --enable-firefox      Abilita un proxy per Firefox
-dff    --disable-firefox     Disabilita un proxy per Firefox
-rff    --restore-firefox     Ripristina la configurazione iniziale per Firefox
firefox                       Avvia Firefox/Iceweasel utilizzando un proxy
iceweasel
	
-c      --enable-chrome       Abilita un proxy per Chrome/Chromium
        --enable-chromium
-dc     --disable-chrome      Disabilita un proxy per Chrome/Chromium
        --disable-chromium
chromium                      Avvia Chromium/Chrome utilizzando un proxy
chrome
" #|less --RAW-CONTROL-CHARS	
}


init

header_z

#separator z

if (( $#>0 )); then

    args=( $@ )
    i=0
    while (( i<$# )) ; do
	case "${args[$i]}" in
	    -u | --update) 
		u=1
		;;
	    -up | --update-proxy) 
		up=1
		;;

	    -h | --help)
		h=1
		;;
	    -d | --disable)
		d=1
		;;
	    -dff | --disable-firefox)
		dff=1
		;;

	    -t | --transparent)
		t=1 ; proxy_types[${#proxy_types[*]}]=Transparent
		;;
	    -a | --anonymous)
		a=1 ; proxy_types[${#proxy_types[*]}]=Anonymous
		;;
	    -e | --elite)
		e=1 ; proxy_types[${#proxy_types[*]}]=Elite
		;;
	    -r | --reconnect)
		r=1
		;;
	    -ff | --enable-firefox)
		ff=1
		;;
	    -rff | --restore-firefox)
		rff=1
		;;
	    -dc | --disable-chrome | --disable-chromium)
		dc=1
		;;
	    -c | --enable-chrome | --enable-chromium)
		c=1
		;;
	    firefox | iceweasel)
		ffox=1
		;;
	    chromium | chrome)
		chromium=1
		;;
	    -ip | --my-ip)
		ip=1
		;;
	    *)
		usage
	# 			if [ ! -z `which ${args[$i]}` ]; then 
	# 				"${args[$i]}"
	# 			else
	# 				usage
	# 			fi
		;;
	esac
	(( i++ ))
	
    done
    
	####
    if [ -z "${proxy_types[*]}" ]; then
	proxy_types=( "Transparent" )
    fi
	####
    
    [ ! -z $h ] && usage	
    
    if [ ! -z $u ]; then 
	update_prog
    fi

    if [ ! -z $r ]; then 
	new_ip_router
    fi

    if [ ! -z $up ]; then 
	update_proxy
    fi
    

    [ ! -z $d ] && no_proxy

    if [ ! -z $dff ]; then 
	_firefox_noproxy
    fi

    if [ ! -z $t ] || [ ! -z $a ] || [ ! -z $e ]; then
	echo 
		#my_ip
	new_ip_proxy
		#my_ip
    fi

    if [ ! -z $rff ]; then
	restore_ffprefs
    fi


    if [ ! -z $ffox ]; then
	_firefox
	firefox &>/dev/null &
	
	if [ -f "$path_prog/.ff_noproxy" ]; then
	    sleep 30
	    rm "$path_prog/.ff_noproxy"
	    _firefox_noproxy
	fi
    fi
    

    if [ ! -z $ff ]; then
	ff_prefs=1
	_firefox
    fi
    
    if [ ! -z $dc ]; then
	rm -f $HOME/bin/chrome $HOME/bin/chromium
    fi
    
    if [ ! -z $c ]; then
	mkdir -p $HOME/bin
#		if [ -f $HOME/bin/chrome ] || [ -f $HOME/bin/chromium ]; then
	cp -n $HOME/bin/chrome $HOME/bin/chrome.old &>/dev/null &
	cp -n $HOME/bin/chromium $HOME/bin/chromium.old &>/dev/null &
#		fi
	[ ! -z $t ] && opts="-t $opts"
	[ ! -z $a ] && opts="-a $opts"
	[ ! -z $e ] && opts="-e $opts"
	[ ! -z $u ] && opts="-u $opts"

	echo -e "#!/bin/bash
zproxy $opts chromium" > $HOME/bin/chromium
	echo -e "#!/bin/bash
zproxy $opts chrome" > $HOME/bin/chrome
	chmod +x $HOME/bin/chrome $HOME/bin/chromium
    fi
    
    if [ ! -z $chromium ]; then
		#_proxy
	update_proxy
	( ${path_chrome}/chromium --proxy-server=$newproxy || ${path_chrome}/chrome --proxy-server=$newproxy ) &>/dev/null &
    fi
    
    [ ! -z $ip ] && my_ip
    
    unset h r u d dff t a e ff ffox rff c dc chromium ip

else
    usage
fi
