#!/usr/bin/expect
#
# ICECMD
# copyleft 2002 by jaromil <http://korova.dyne.org>
#
# ICECMD lets you execute commands on a remote icecast server
# from operator status without logging into the system
# (dedicated to evey lazy icecast admin out there)
# please check out the configuration below to fit your needs
# and take care to not expose publicly your secret passwords
#
# this script needs expect and TCL installed on your machine
#
# "$Id$"

################
## CONFIGURATION
################
set timeout 5
set server "localhost"
set port "8000"
set admin_pass "hackme"
set oper_pass "hackme"
################

stty -echo
log_user 0

spawn -noecho telnet $server $port


expect	{
	Connected { send "ADMIN $admin_pass\n\n" }
	refused { send_user "\[!\] Icecast server is not running\n"; exit }
}
expect	{
	OK { send "oper $oper_pass\n" }
	"Bad Request" { send_user "\[!\] Can't log into the icecast console\n"; exit }
}
expect {
	operator { log_user 1; send "[lrange $argv 0 $argc]\n" }
        invalid { send_user "\[!\] Invalid Password\n"; exit }
}

send "quit\n"
expect bye { close; exit }
