diff options
author | noah <noah@656d521f-e311-0410-88e0-e7920216d269> | 2004-03-02 09:33:36 +0000 |
---|---|---|
committer | noah <noah@656d521f-e311-0410-88e0-e7920216d269> | 2004-03-02 09:33:36 +0000 |
commit | a2bda099219267b1c2b91a99c084084f531254f3 (patch) | |
tree | bbf7a3b66592e01e613ff04bdf1ea0a0137aa4a8 | |
parent | 825916a7141b7ee1ab93f3ac3737d494f924d57b (diff) | |
download | pexpect-a2bda099219267b1c2b91a99c084084f531254f3.tar.gz |
This is evil!
git-svn-id: http://pexpect.svn.sourceforge.net/svnroot/pexpect/trunk@216 656d521f-e311-0410-88e0-e7920216d269
-rwxr-xr-x | pexpect/examples/bd_client_web.py | 75 | ||||
-rwxr-xr-x | pexpect/examples/bd_serv.py | 14 |
2 files changed, 67 insertions, 22 deletions
diff --git a/pexpect/examples/bd_client_web.py b/pexpect/examples/bd_client_web.py index 80edf11..5b5e9c6 100755 --- a/pexpect/examples/bd_client_web.py +++ b/pexpect/examples/bd_client_web.py @@ -12,39 +12,74 @@ import socket ROOTPATH="/tmp" -def page (url, result = ''): +def page (result = ''): """Return the main form""" return """<html> <head> <title>Og.</title> - <body> +<script language="JavaScript"> +function firstFocus() +{ + if (document.forms.length > 0) + { + var TForm = document.forms[0]; + for (i=0;i<TForm.length;i++) + { + if ((TForm.elements[i].type=="text")|| + (TForm.elements[i].type=="textarea")|| + (TForm.elements[i].type.toString().charAt(0)=="s")) + { + document.forms[0].elements[i].focus(); + break; + } + } + } +} +</script> +</head> +<body onLoad="firstFocus()"> +<hr noshade="1"> <pre> %s </pre> - <hr> - <form action="%s" method="POST"> - <input name="command" type="text" size="80"> - <input name="submit" type="submit"> - </form> - - </body> - </html> - """ % (result, url) +<hr noshade="1"> +<form action="http://www.chocho.org/cgi-bin/bd_client_web.py" method="POST"> +<input name="command" type="text" size="80"> +<input name="submit" type="submit" value="Enter"> +</form> +</body> +</html> + """ % (result) def bd_client (command, host='localhost', port = 1666): + HOST = 'localhost' # The remote host + PORT = 1666 # The same port as used by the server + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.connect((HOST, PORT)) + s.send(command) + data = s.recv(1024) + s.close() + return data + + #fout = file ('/tmp/log2','w') + #fout.write (command) + #fout.write ('\n') s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((host, port)) s.send(command) data = s.recv(1024) + #fout.write (data) + #fout.write ('\n') s.close() + #fout.close() return data -def link (matchobject): - """Used in re.sub calls to replace a matched object with an HTML link.""" - path = matchobject.group(0) - l = "<a href=\"http://63.199.26.227/cgi-bin/ls.py?root=%s&path=%s\">%s</a>" % \ - (ROOTPATH+"/"+path, ROOTPATH+"/"+path, path) - return l +#def link (matchobject): +# """Used in re.sub calls to replace a matched object with an HTML link.""" +# path = matchobject.group(0) +# l = "<a href=\"http://63.199.26.227/cgi-bin/ls.py?root=%s&path=%s\">%s</a>" % \ +# (ROOTPATH+"/"+path, ROOTPATH+"/"+path, path) +# return l def escape_shell_meta_chars(s): """Escape shell meta characters. This is done for security.""" @@ -61,7 +96,7 @@ def escape_shell_meta_chars(s): s = string.replace(s, ">", "\\>",) return s -sys.path.insert (0,"/var/www/cgi-bin") +sys.path.insert (0,"/usr/local/apache/cgi-bin") sys.stderr = sys.stdout print "Content-type: text/html" @@ -72,9 +107,9 @@ try: if form.has_key("command"): command = form["command"].value result = bd_client (command) - print page('bd_client_web.py', result) + print page(result) else: - print page('bd_client_web.py') + print page() except: print "\n\n<pre>" diff --git a/pexpect/examples/bd_serv.py b/pexpect/examples/bd_serv.py index 64477e7..260a5d6 100755 --- a/pexpect/examples/bd_serv.py +++ b/pexpect/examples/bd_serv.py @@ -1,8 +1,11 @@ #!/usr/bin/env python import socket, pexpect +import time p = pexpect.spawn ('bash') -p.expect ('# ') +time.sleep (0.1) +p.expect ('\$') +time.sleep (0.1) HOST = '' # Symbolic name meaning the local host PORT = 1666 # Arbitrary non-privileged port @@ -15,11 +18,18 @@ while 1: conn, addr = s.accept() print 'Connected by', addr data = conn.recv(1024) + print 'RECEIVED:' + print data # if not data: # break + time.sleep (0.1) p.sendline (data) - p.expect ('# ') + time.sleep (0.1) + p.expect ('\$') + time.sleep (0.1) response = p.before + p.after + print 'RESPONSE:' + print response conn.send(response) conn.close() |