Example #1
0
def srvcmd_lan(server_cmd,client_words,client_args):
	# examples
	# "send", "Wohnz", "An"
	# "send", "Wohnz", "Aus"
	# "send", "Wohnz", "status"
	# "send", "Wohnz"

	if verbose_level > 2:  print "++++ srvcmd_lan()"	
	if verbose_level > 3:
		print "lan client_words : ", client_words
		print "lan client_args  : ", client_args
	
	if (client_args < 2):
		server_reply = "not enougth arguments for command " + client_cmd
		print server_reply
		return (server_reply)
			
	# get name of light provided as second argument
	LanName    = client_words[1]
	LanCmd = client_words[2]
	LanCmd = LanCmd.lower()
	
	if verbose_level > 2:
		print "Host:", LanName
		print "L.Cmd:", LanCmd
	# retrieve ID form dictionary
	LanID = lan_dict.get(LanName)
	if (None == LanID):
		print "Computer unknown : " , LanName
		server_reply = "Computer unknwon"
		return (server_reply)			
			
	if verbose_level > 2:
		print "Der Computer " + LanName + " mit id " + str(LanID) + " wird angesprochen"
		
	if LanCmd == LanCmdOn:
		server_reply = lan_wakeup(LanName)
	elif LanCmd == LanCmdOff:
		server_reply = lan_shutdown(LanName)
	elif LanCmd == LanCmdStatus:
		server_reply = lan_status(LanName)
	else:
		server_reply = "unknown command: " +  LanCmd
		sys.stderr.write(server_reply)
    								
	return(server_reply)
Example #2
0
def lan_shutdown(host_name):
	try:
		host_ip = socket.gethostbyname(host_name)
	except:
		return("ip address unkown -> please maintain /etc/hosts")
		
	host_data = lan_dict.get(host_name)
	if verbose_level > 3: print host_data
	host_os   = host_data[0]
	host_user = host_data[1]
	host_pw   = host_data[2]
	
	os_cmd_string = "net rpc SHUTDOWN -C 'NetIO shutdown' -f -I " + host_ip + " -U " +host_user +"%" +host_pw
	unix_reply = unix_cmd(os_cmd_string)
	
	if unix_reply[0] ==0:
		server_reply = "host shutdown succesfull / 1"
	else:
		server_reply = "ERROR shutdown failed " + unix_reply[1]
		sys.stderr.write(server_reply)	
	
	return(server_reply)