/usr/sbin/jetpipe is in ltsp-client-core 5.3.7-0ubuntu2.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | #!/usr/bin/python
#
# Minimal Printserver, forwards a printer device to a tcp port (usually 9100)
#
# TODO:
# * add read for bidirectional comm ?
# * add writeonly opts
#
# Copyright 2006, Canonical Ltd.
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, you can find it on the World Wide
# Web at http://www.gnu.org/copyleft/gpl.html, or write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
#Serial redirection code adapted from work by:
#(C)2002-2003 Chris Liechti <cliechti@gmx.net>
#redirect data from a TCP/IP connection to a serial port and vice versa
#requires Python 2.2 'cause socket.sendall is used
#
"""
usage: jetpipe [options] <device> <port>
Note: no security measures are implemeted. Anyone can remotely connect
to this service over the network.
Only one connection at once is supported. If the connection is terminaed
it waits for the next connect.
"""
import os
import sys
import socket
import serial
import threading
import getopt
import daemon
class Redirector:
def __init__(self, devicename, socket):
self.socket = socket
if devicename[:8] == '/dev/tty': # This should catch regular serial and USB serial
self.device = serial.Serial(devicename)
self.device.baudrate = 9600
self.device.bytesize = 8
self.device.parity = 'N'
self.device.stopbits = 1
self.device.timeout = 1 #required so that the reader thread can exit
self.device.rtscts = False
self.device.xonxoff = False
self.devicetype = 'S'
else:
self.device = open(devicename, 'wb')
self.devicetype = 'P'
def shortcut(self):
"""connect the serial port to the tcp port by copying everything
from one side to the other"""
self.writer()
def writer(self):
"""loop forever and copy socket->serial"""
print 'in writer loop'
self.alive = True
while self.alive:
try:
data = self.socket.recv(1024)
if not data:
break
except socket.error, msg:
print "error receiving from socket: ", msg
self.device.write(data)
try:
if self.devicetype == 'P':
self.device.flush() # parallel device
except:
pass
self.device.close()
self.alive = False
def run_server(devicename, port):
srv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
srv.bind( ('', int(port)) )
srv.listen(1)
while 1:
try:
print "Waiting for connection...."
connection, addr = srv.accept()
print 'Connected by', addr
#enter console->serial loop
redir = Redirector(devicename, connection)
if redir.devicetype == 'S':
if locals().has_key('baudrate'):
redir.device.baudrate = baudrate
if locals().has_key('bytesize'):
redir.device.bytesize = bytesize
if locals().has_key('parity'):
redir.device.parity = parity
if locals().has_key('stopbits'):
redir.device.stopbits = stopbits
if locals().has_key('rtscts'):
redir.device.rtscts = rtscts
if locals().has_key('xonxoff'):
redir.device.xonxoff = xonxoff
try:
redir.device.open()
except serial.SerialException, e:
print "Could not open serial port %s: %s" % (devicename.port, e)
sys.exit(1)
redir.shortcut()
print 'Disconnected'
connection.close()
except socket.error, msg:
print msg
if __name__ == '__main__':
#parse command line options
try:
opts, args = getopt.getopt(sys.argv[1:],
"dhb:p:rs:xy:",
[ "debug", "help", "baud=", "rtscts", "xonxoff" ])
except getopt.GetoptError:
# print help information and exit:
print >>sys.stderr, __doc__
sys.exit(2)
debug = False
for o, a in opts:
if o in ("-h", "--help"): # help text
usage()
sys.exit()
elif o in ("-b", "--baud"): # specified baudrate
try:
baudrate = int(a)
except ValueError:
raise ValueError, "Baudrate must be a integer number"
elif o in ("-y", "--bytesize"): # specified bytesize
bytesize = int(a)
elif o in ("-p", "--parity"): # specified parity
parity = a
elif o in ("-s", "--stopbits"): # specified stopbits
stopbits = int(a)
elif o in ("-r", "--rtscts"):
rtscts = True
elif o in ("-x", "--xonxoff"):
xonxoff = True
elif o in ("-d", "--debug"):
debug = True
devicename = args[0]
port = args[1]
if debug == False:
with daemon.DaemonContext():
run_server(devicename, port)
else:
run_server(devicename, port)
|