50 lines
1.4 KiB
Python
50 lines
1.4 KiB
Python
import socket
|
|
|
|
HOST = ''
|
|
PORT = 8000
|
|
|
|
content = b'''HTTP/1.x 200 OK
|
|
Content-Type: text/html
|
|
|
|
<head>
|
|
<meta http-equiv="refresh" content="1; url=http://chat.localhost.observer/fax/">
|
|
<title>WOW</title>
|
|
</head>
|
|
<html>
|
|
<p>Wow, Python Server</p>
|
|
</html>
|
|
'''
|
|
|
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
s.bind((HOST, PORT))
|
|
|
|
while True:
|
|
s.listen(3)
|
|
conn, addr = s.accept()
|
|
request = conn.recv(4096)
|
|
method = request.decode().split(' ')[0]
|
|
ctype = request.decode().split('Content-Type: ')[1].split('\r\n')[0]
|
|
# src = request.decode().split(' ')[1]
|
|
body = request.decode('utf-8').split('\r\n\r\n', 1)[1]
|
|
single = str(body.encode('utf-8')).split('&',1)
|
|
sender = single[0].split('=',1)
|
|
|
|
print (request)
|
|
|
|
if method == 'POST' and ctype == 'application/x-www-form-urlencoded':
|
|
message = single[1].split('=',1)
|
|
with open('/dev/usb/lp0', 'w') as printer:
|
|
printer.write('\n'+str(addr)+'\n')
|
|
printer.write(str(request.decode('utf-8'))+'\n')
|
|
# printer.write('\n'*2+str(body)+'\n')
|
|
# printer.write(single[0]+'\n')
|
|
# printer.write(single[1]+'\n')
|
|
# printer.write(sender[0]+'\n')
|
|
printer.write(sender[1]+'\n')
|
|
printer.write(message[1][:-1]+'\n')
|
|
print (sender)
|
|
print (message)
|
|
print (ctype)
|
|
conn.sendall(content)
|
|
|
|
conn.close() |