/usr/sbin/jetpipe is in ltsp-client-core 5.5.1-1ubuntu2.
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 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | #!/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 getopt
class Redirector:
def __init__(self, devicename, socket):
self.socket = socket
# This should catch regular serial and USB serial
if devicename[:8] == '/dev/tty':
self.device = serial.Serial(devicename)
self.device.baudrate = 9600
self.device.bytesize = 8
self.device.parity = 'N'
self.device.stopbits = 1
# Required so that the reader thread can exit
self.device.timeout = 1
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':
# parallel device
self.device.flush()
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 'baudrate' in locals():
redir.device.baudrate = baudrate
if 'bytesize' in locals():
redir.device.bytesize = bytesize
if 'parity' in locals():
redir.device.parity = parity
if 'stopbits' in locals():
redir.device.stopbits = stopbits
if 'rtscts' in locals():
redir.device.rtscts = rtscts
if 'xonxoff' in locals():
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
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 not debug:
# Fork in background
pid = os.fork()
if pid:
sys.exit(0)
# Replace stdin
sys.stdin.close()
sys.stdin = open("/dev/null", "r")
# Replace stdout
sys.stdout.close()
sys.stdout = open("/dev/null", "w")
# Replace stderr
sys.stderr.close()
sys.stderr = open("/dev/null", "w")
run_server(devicename, port)
|