##
# zyc
#
# Write various settings to a ZyXEL P2000W and optionally register
# a FreeWorldDialup account for it.
#
# Based on ideas and code from Matt Westervelt
#
# --Rob Flickenger, 7/2004
#
# This code is freeware. Do something free with it.
#
# A wise man once said
# That life has no guarantees.
# Likewise, this software.
#
#
# Requirements: curl, bash, and typical unix tools
#
VERSION=0.999
##
# You shouldn't have to edit anything. =)
#
BLACK="[0;30m"
RED="[0;31m"
GREEN="[0;32m"
YELLOW="[0;33m"
BLUE="[0;34m"
MAGENTA="[0;35m"
CYAN="[0;36m"
WHITE="[0;37m"
RESET="[0m"
if [ ! -d "$HOME/.zyc/" ]; then
echo "First run: Creating ~/.zyc/ for profile storage..."
mkdir $HOME/.zyc
chmod 0700 $HOME/.zyc
if [ ! -w "$HOME/.zyc/" ]; then
echo "Can't write to $HOME/.zyc/. Fix that and try again."
exit 1
fi
fi
if [ "$1" == "-r" -o "$1" == "--reset" ]; then
echo "Resetting configuration."
rm -f "$HOME/.zyc/.config"
shift
fi
if [ ! -r "$HOME/.zyc/.config" ]; then
echo "Configuration file not found."
while [ -z "$ZYC_PHONEIP" ]; do
read -ep "What is your phone's IP address? " ZYC_PHONEIP
done
read -ep "What is the admin username? [zyxeladmin] " ZYC_PHONEUSER
[ -z "$ZYC_PHONEUSER" ] && ZYC_PHONEUSER="zyxeladmin"
read -ep "Password? [1234] " ZYC_PHONEPASS
[ -z "$ZYC_PHONEPASS" ] && ZYC_PHONEPASS="1234"
echo -n "ANSI ${RED}c${CYAN}o${YELLOW}l${MAGENTA}o${GREEN}r${RESET} support? [Y/n] "
read -e ZYC_COLOR
[ -z "$ZYC_COLOR" ] && ZYC_COLOR="y"
echo "Saving configuration file..."
set |grep ^ZYC > "$HOME/.zyc/.config"
chmod 0600 "$HOME/.zyc/.config"
else
. "$HOME/.zyc/.config"
if [ -z "$ZYC_PHONEIP" ]; then
echo "There seems to be a problem with $HOME/.zyc/.config."
echo "Please delete it and try again."
exit
fi
fi
##
# Color support hack
#
if [ "$ZYC_COLOR" == "n" -o "$ZYC_COLOR" == "N" ]; then
unset BLACK RED GREEN YELLOW BLUE MAGENTA CYAN WHITE RESET
fi
##
# Help requested?
#
if [ "$1" == "-h" -o "$1" == "--help" ]; then
me=`basename $0`
cat <<EOF
${CYAN}$me${RESET} : Configure a ${WHITE}ZyXEL Prestige 2000W Wi-Fi Phone${RESET}
Usage: ${CYAN}$me${RESET} [${YELLOW}profile${RESET}]
Run ${CYAN}$me${RESET} without parameters to configure the phone manually. Then save
your settings to a profile for quick loading later.
To change your phone's settings (IP address, password, etc.) just run
${GREEN}$me -r${RESET} (or ${GREEN}$me --reset${RESET}) to reset.
This is ${CYAN}$me${RESET} v${MAGENTA}$VERSION${RESET}.
EOF
exit
fi
##
# Some variables. Yes, they should be here and not at the top.
#
# Note that any environment variable starting with ZYC gets
# saved to the profiles.
#
ZYC_USERID=""
ZYC_PROXY="fwd.pulver.com"
ZYC_PORT="5060"
ZYC_OUTPROXY="fwdnat.pulver.com"
ZYC_OUTPORT="5082"
FIRST="John"
LAST="Doe"
ZYC_PASSWORD=""
EMAIL="jdoe@mailinator.com"
ADDRESS="1234 Main Street"
#
# This should really be actual demographic data. Hmm.
#
COUNTRY="57"
STATE="200"
CITY="2000"
ZIP="12223"
ZYC_DISPLAYNAME=$ZYC_USERID
ZYC_PROXYID=$ZYC_USERID
if [ $# -lt 1 ]; then
echo
echo "${WHITE}No profile specified.${RESET}"
echo -n "Proceed with manual configuration for ${CYAN}${ZYC_PHONEIP}${RESET}? [Y/n] "
read -e LINE
if [ "$LINE" == "n" -o "$LINE" == "N" ]; then
echo
echo "${WHITE}Exiting (nothing to do... Try ${GREEN}$0 -h${WHITE} for help.)${RESET}"
exit
fi
echo
if [ -z "$ZYC_USERID" ]; then
echo -n "Register a ${GREEN}FreeWorldDialup${RESET} account? [y/N] "
read -e LINE
if [ "$LINE" == "y" ]; then
echo
echo -n "First Name [${YELLOW}$FIRST${RESET}]: "
read -e X
[ -n "$X" ] && FIRST=$X
echo -n "Last Name [${YELLOW}$LAST${RESET}]: "
read -e X
[ -n "$X" ] && LAST=$X
echo -n "Email address [${YELLOW}$EMAIL${RESET}]: "
read -e X
[ -n "$X" ] && EMAIL=$X
echo -n "Mailing address [${YELLOW}$ADDRESS${RESET}]: "
read -e X
[ -n "$X" ] && ADDRESS=$X
echo -n "Zip code [${YELLOW}$ZIP${RESET}]: "
read -e X
[ -n "$X" ] && ZIP=$X
echo -n "Password [${YELLOW}$ZYC_PASSWORD${RESET}]: "
read -e X
[ -n "$X" ] && ZYC_PASSWORD=$X
echo
echo "Contacting ${CYAN}account.freeworlddialup.com${RESET}..."
results=`curl -s 'http://account.freeworlddialup.com/index_new.php?section_id=94&FormName=login' -F lastcontrol="" -F username="$EMAIL" -F password="$ZYC_PASSWORD" -F confirm="$ZYC_PASSWORD" -F SB_login="Finalize Registration" -F firstname="$FIRST" -F lastname="$LAST" -F email="$EMAIL" -F countryid="$COUNTRY" -F address="$ADDRESS" -F stateid="$STATE" -F cityid="$CITY" -F postal="$ZIP"`
x=${results/*Number: /}
fwdnum=${x/<*/}
if [ -n "$fwdnum" ]; then
echo "${GREEN}FWD${RESET} number registered: ${RED}$fwdnum${RESET}"
echo
ZYC_USERID=$fwdnum
ZYC_PROXYID=$fwdnum
ZYC_DISPLAYNAME=$fwdnum
else
echo "${RED}There was a problem registering with FWD.${RESET}"
read -ep "Continue with manual configuration? [y/N] : " LINE
[ "$LINE" != "y" ] && exit
fi
fi # End FWD registration
fi
echo
while [ -z "$ZYC_USERID" ]; do
read -ep "Username: " ZYC_USERID
done
export ZYC_PROXYID=$ZYC_USERID
export ZYC_DISPLAYNAME=$ZYC_USERID
while [ -z "$ZYC_PASSWORD" ]; do
read -ep "Password: " ZYC_PASSWORD
done
echo -n "SIP Proxy [${YELLOW}$ZYC_PROXY${RESET}]: "
read -e LINE
[ -n "$LINE" ] && ZYC_PROXY=$LINE
echo -n "Proxy Port [${YELLOW}$ZYC_PORT${RESET}]: "
read -e LINE
[ -n "$LINE" ] && ZYC_PORT=$LINE
echo -n "Outbound Proxy [${YELLOW}$ZYC_OUTPROXY${RESET}]: "
read -e LINE
[ -n "$LINE" ] && ZYC_OUTPROXY=$LINE
echo -n "Outbound Proxy Port [${YELLOW}$ZYC_OUTPORT${RESET}]: "
read -e LINE
[ -n "$LINE" ] && ZYC_OUTPORT=$LINE
echo
unset PROFILE
while [ -z "$PROFILE" ]; do
read -ep "Enter a name for this profile (no spaces): " PROFILE
done
echo "# auto-generated by $0" > $HOME/.zyc/$PROFILE
chmod 0600 $HOME/.zyc/$PROFILE
set |grep ^ZYC >> $HOME/.zyc/$PROFILE
read -ep "Save to phone ${CYAN}$ZYC_PHONEIP${RESET}? [Y/n] : " LINE
if [ "$LINE" == "n" -o "$LINE" == "N" ]; then
echo "Exiting."
exit
fi
else
if [ ! -r "$HOME/.zyc/$1" ]; then
echo "Can't find profile ${RED}$1${RESET}."
FILES=`ls $HOME/.zyc/`
if [ -z "$FILES" ]; then
echo "${WHITE}No profiles found.${RESET}"
echo "Run without parameters to configure one manually."
else
echo
echo "Saved profiles: "
echo ${GREEN}$FILES${RESET}
fi
exit 1
else
echo "${WHITE}Loading profile ${GREEN}$1${RESET}"
. $HOME/.zyc/$1
fi
fi
echo
echo "${WHITE}Saving settings to ${CYAN}$ZYC_PHONEIP${WHITE}...${RESET}"
RESULT=`curl -f -s --user $ZYC_PHONEUSER:$ZYC_PHONEPASS http://$ZYC_PHONEIP/set_outbound_proxy -d "proxy_ip_addr_str=$ZYC_OUTPROXY&proxy_port_str=$ZYC_OUTPORT"`
if [ -z "$RESULT" ]; then
echo "${RED}Server failure${RESET}."
echo "Perhaps you have the wrong username / password? (Try ${GREEN}$0 -r${RESET})."
exit
fi
curl -s --user $ZYC_PHONEUSER:$ZYC_PHONEPASS http://$ZYC_PHONEIP/set_registrar \
-d "registrar_phone_str=$ZYC_USERID&tcid=%13®istrar_ip_addr_str=$ZYC_PROXY®istrar_port_str=$ZYC_PORT®istrar_expire_str=300&keep_alive_timer_str=0&proxy_username_str=$ZYC_PROXYID&tcid=0&proxy_password_str=$ZYC_PASSWORD&tcid=0&cid_name_str=$ZYC_DISPLAYNAME&tcid=0" \
> /dev/null
curl -s --user $ZYC_PHONEUSER:$ZYC_PHONEPASS http://$ZYC_PHONEIP/save_config > /dev/null
sleep 1
echo "${WHITE}Resetting phone...${RESET}"
curl -s --user $ZYC_PHONEUSER:$ZYC_PHONEPASS http://$ZYC_PHONEIP/reset_system > /dev/null
sleep 1
##
# Ende
#