Beispiel #1
0
def scriptproc(cmds):
	status=0
	ifproc=0
	"""Core Login Script Processing Function"""
	ifprocess=0
	count=1
	for temp in cmds:
		#print temp
		temp=temp.lower()
		if "write" in temp:
			try:
				temp1=temp.split("\"")
				temp1=temp1[1]
				temp1=sub(temp1)
				print temp1
			except:
				errorlog("Write Command Invalid",count)
			
		if "set" in temp or "dos set" in temp:
			print "\n"
			try:
				pts=temp.split(" ")
				params=pts[-1].split("=")
			except:
				# print "ERROR in line "+count
				errorlog("set failed",count)
				print "\n"
	
			print "STATUS: Setting Env Variable "+params[0]+" to "+params[1]
			try:
				os.system("setx "+params[0]+" "+params[1])
			except:
				errorlog("Client does not have setx.exe installed",count)
			print "\n"
			continue
	
		if "exit" == temp:
			print "STATUS: Login Script Finished"
			return
		
		for line in excluded_commands:
			if line in temp:
				print "\n"
				print "STATUS: Command Dropped "+temp+" In Line "+str(count)
				print "\n"
				continue
		
		if "if \"%" in temp.lower():
			ifmarker=1
			try:
				temp1=temp.split(" ")
				#print temp1
				vals=temp1[1].split("=")
				vals[1]=vals[1].replace("\"","")
				vals[0]=vals[0].replace("\"","")
				vals[0]=vals[0].replace("%","")
			
				envvar=vals[0]
			except:
				#print "ERROR: Command error in line "+count
				errorlog("Command error in if command",count)
				continue
			try:
				val1=os.environ.get(envvar)
				#print val1
			except:
				errorlog("Env Variable Not Found",count)
				status=1
				continue
			ifprocess=1
			if val1==vals[1]:
				status=0
				print "STATUS: Start IF Process. Env Variable Check Passed"
				
			
	
		if "if member of".lower() in temp.lower():
			#print "if member of found"h
			ifmarker=1
			try:
				temp1=temp.split("\"")
				name=groupname(temp1[1])
			except:
				errorlog("IF Failed",count)
				continue
			print "\n"
			print "STATUS Group found is "+name
			
			if "." in name:
				ldapgroup=ldappath(temp1[1])
				name=checkad(ldapgroup)
				print "Matched AD Group is "+name	
		
				usermember=aduser.get_attribute("memberOf")
				status=adgrp(usermember,name)
				ifprocess=1
				if status==0:
					print "STATUS: START IF statenent. User is member of group so drives mapped.."
					print
			else:
				print "STATUS: Group Not Found in AD"
				status=1
				ifprocess=1
				print "\n"
				
		if ifprocess==1 and status<>0 and "map" in temp.lower():
			print "STATUS: Failed if check command not executed line "+str(count)
			continue		
		
		if ifprocess==1 and status==0 and "map" in temp.lower():
			temp=temp.lower().replace("map root","map")
			try:
				mapbits=temp.lower().split(" ")
				print mapbits[1]
				drive,path=checkpath(mapbits[1])
				print drive,path
				if path.lower()=="%home_directory":
					path=homedir[0]
				status=drvmap(drive,path)
			except:
				errorlog("Drive Map Failed Inside IF",count)
				continue
			
		if ifprocess==0 and "map" in temp.lower():
			
			temp=temp.lower().replace("map root","map")
			try:
				mapbits=temp.lower().split(" ")
			
				drive,path=checkpath(mapbits[1])
				print drive,path
				#if path.lower()=="%home_directory":
					#path=homedir[0]
				path=sub(path)
				status=drvmap(drive,path)
				#sys.exit()
			except:
				errorlog("Drive Map Failed Outside IF",count)
		
		if "end".lower() in temp.lower():
			ifprocess=0
			status=0
			print "STATUS: ENDIF Statement"
			print "\n"
	
		if "include" in temp.lower():
			ndap=temp.split(" ")[1]
			ldapobj=ldappath(ndap)
			ldapobj=ldapobj.replace("cn=,","")
			print "\n"
			print "STATUS: Running Include from " +ldapobj
			status=inc("ldaps://"+edir[0],"include "+ldapobj,edir[1],edir[2])
			print "\n"
		if "#" == temp[0:1]:
			print "STATUS: Running external script"
			cmdline=temp[1:].replace("\n","")
			stat=os.system(cmdline)
			if stat<>0:
				errorlog("Script Returned an Error State",count)
				#print "ERROR: Script returned an Error State"
		count=count+1
			

	print "\n"
	print "Script Processing Finished"
	print "\n"

	return
Beispiel #2
0
os.system("cls")
ver="0.5"
print "LOGON SCRIPT PROCESSOR\t"+ver
print "\n"
print "LDAP Server is \t\t"+edir[0]+":636"
print "User Proxy is \t\t"+edir[1]
print "AD DNS Suffix \t\t"+suffix
print "EDIR CONF \t\t"+conf
print "AD User is \t\t"+os.getenv("USERNAME")
print "Log File location \t"+logloc

errors=open(logloc,"w")
grp=xmlparse(nurm)

print "\n"
homedir=aduser.get_attribute("homeDirectory")
homedrive=aduser.get_attribute("homeDrive")

lscript=findous("ldaps://"+edir[0],dn,edir[1],edir[2])
l=len(lscript)
if l==0:
	errorlog("No Login Script Found in EDIR",0)
	sys.exit()
ifprocess=0
print "STATUS: Processing Novell Login Script"
print
for temp in lscript:
	scr=temp[1]["loginScript"][0]

lscriptrans(scr)