def do_Echo(self, args): command = docopt(str(self.doc), args) e = ExecHelper() e.reset("Echo") cmd = "echo -n " + ' '.join(command['ARGS']) e.Log(cmd) e.RetOutput(cmd) print e.r.output
def do_Gdm(self, args): command = docopt(str(self.doc), args) e = ExecHelper() e.reset("Gdm") cmd = "pidof X" pid = e.RetOutput(cmd).strip() cmd = "sh -c 'xargs -0 < /proc/" + pid + "/cmdline'" e.Log(cmd) xcmdline = e.RetOutput(cmd).split() count = len(xcmdline) i = 0 while i < count: if xcmdline[i] == "-auth": xauthority = xcmdline[i + 1] i += 1 os.environ['XAUTHORITY'] = xauthority if command['login']: for word in command['PHRASE']: word = word.strip() if word == "{Tab}": cmd = 'echo %s|sudo -S xdotool key Tab' % ( command['<sudopassword>']) elif word == "{Return}": cmd = 'echo %s|sudo -S xdotool key Return' % ( command['<sudopassword>']) elif word == "{Clear}": cmd = 'echo %s|sudo -S xdotool key ctrl+a Delete' % ( command['<sudopassword>']) elif word == "{Space}": cmd = 'echo %s|sudo -S xdotool key space' % ( command['<sudopassword>']) else: cmd = 'echo %s|sudo -S xdotool type %s' % ( command['<sudopassword>'], word) e.Log(cmd) e.Execute(cmd) time.sleep(2) e.Log(e.r.output) else: cmd = "xdotool key ctrl+alt+Delete" e.Execute(cmd) time.sleep(2) e.Execute("sleep 30 && xdotool key Return &") e.setExecCodes("Reboot", "Going out in 1/2 minute", "Reboot") e.Log(e.r.output)
def do_Xenapp(self, args): command = docopt(str(self.doc), args) e = ExecHelper() e.reset("Xenapp") if command["application"] or command["desktop"]: citrixuser = command['<username>'] citrixpass = command['<password>'] citrixurl = command['<url>'] citrixapp = " ".join(command['APPNAME']) citrixappmod = citrixapp.replace(" ", "_0020") #driver = webdriver.Firefox() profpath = os.path.join(os.getenv('HOME'), ".mozilla", "firefox", "wyse_default") if os.path.exists(profpath): e.Log("using existing profile") profile = FirefoxProfile(profpath) else: e.Log("using a temporary profile") profile = FirefoxProfile() driver = webdriver.Firefox(profile) driver.implicitly_wait(60) driver.get(citrixurl) #driver.find_element_by_id("skipWizardLink").click() driver.find_element_by_id("user").clear() driver.find_element_by_id("user").send_keys(citrixuser) driver.find_element_by_id("password").clear() driver.find_element_by_id("password").send_keys(citrixpass) driver.find_element_by_css_selector("span.rightDoor").click() if command["desktop"]: e.Log("finding ") driver.find_element_by_css_selector( "#Desktops_Text > span").click() try: appid = "a[id*='%s']" % citrixappmod element = driver.find_element_by_css_selector(appid) element.click() #e.setExecCodes(args, "Check app launch using Process alive wfica.orig","Pass") except Exception as e: print str(e) e.Log(str(e)) print "Oops app not found!!", citrixapp e.setExecCodes(args, "Could not locate app", "Fail") #The app takes its own sweet time coming up. Should sleep time be a parameter? print "Waiting for 90 secs before checking for window creation" time.sleep(90) chkcmd = "./agent/cli/bin/windowinfo.sh '%s'" % citrixapp e.RetOutput(chkcmd) e.Log(e.r.getOutput())
def do_HTTPCounter(self, args): command = docopt(str(self.doc), args) e = ExecHelper() e.reset("HTTPCounter") sudopassword = command['<sudopassword>'] if command["initialize"]: e.Log("HTTPCounter initalizing") self.initialize(sudopassword) e.setExecCodes(args, "Warning: Does not verify execution", "Pass") elif command["resetCounter"]: cmd = "echo %s|sudo -S iptables -Z AF" % (sudopassword) e.Log("HTTPCounter resetCounter") e.Execute(cmd) e.setExecCodes(args, "Warning: Does not verify execution", "Pass") elif command["getCount"]: cmd = "sh -c 'echo %s|sudo -S iptables -vL AF'" % (sudopassword) lines = e.RetOutput(cmd).split(os.linesep) output = " GET " + lines[2].split()[0] output += " POST " + lines[3].split()[0] output += " PUT " + lines[4].split()[0] e.r.setOutput(output) print output
def do_Process(self, args): command = docopt(str(self.doc), args) e = ExecHelper() e.reset("Process") if command["monitor"]: psopts = "/bin/ps -C %s o pcpu,pmem --cumulative --no-heading" % ( command["<name>"]) e.Log("Executing monitor " + psopts) counter = 0 cpu = float(0) mem = float(0) while (counter < int(command["<duration>"])): pcpu, pmem = self.parse(e.RetOutput(psopts)) cpu = cpu + pcpu mem = mem + pmem time.sleep(1) counter = counter + 1 output = "%s consumed %s%% cpu and %s %% memory" % ( command["<name>"], cpu / counter, mem / counter) e.Log(output) print output if cpu > 0 or mem > 0: e.setExecCodes("Process monitor", output, "Pass") else: e.setExecCodes("Process monitor", output, "Fail") elif command["kill"]: killopts = "/usr/bin/killall %s" % (command["<name>"]) e.Log(killopts) e.EvalRetVal(killopts) elif command["spawn"]: spawnopts = ' '.join(command["PATH"]) e.Log(spawnopts) e.Spawn(spawnopts) elif command["exec"]: execopts = ' '.join(command["PATH"]) e.Log(execopts) execopts = "/bin/sh -c '%s' " % (execopts) e.EvalRetVal(execopts) elif command["forfeit"]: execopts = ' '.join(command["PATH"]) e.Log(execopts) execopts = "/bin/sh -c '%s' " % (execopts) e.EvalRetVal(execopts) e.r.setRetVal("Fail") elif command["thrive"]: execopts = ' '.join(command["PATH"]) e.Log(execopts) execopts = "/bin/sh -c '%s' " % (execopts) e.EvalRetVal(execopts) e.r.setRetVal("Pass") elif command["alive"]: killopts = "/usr/bin/killall -s 0 %s" % (command["<name>"]) e.Log(killopts) e.EvalRetVal(killopts) elif command["dead"]: killopts = "pidof %s" % (command["<name>"]) e.Log(killopts) e.EvalRetVal(killopts, 1) elif command["pid"]: execopts = "pidof %s" % (command["<name>"]) e.Log(execopts) e.EvalRetVal(execopts) elif command["output"]: # Process output contains 1360x78 xdpyinfo | grep dimensions execopts = ' '.join(command["PATH"]) e.Log(execopts) execopts = "/bin/sh -c '%s' " % (execopts) output = e.RetOutput(execopts) if command['<expectation>'] in output: e.setExecCodes(execopts, output, "Pass") else: e.setExecCodes(execopts, output, "Fail") e.Log(e.r.getOutput()) print e.r.getRetVal()