/usr/lib/kannel/test/dlr-receiver.py is in kannel-extras 1.4.4-4.
This file is owned by root:root, with mode 0o644.
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 | #
# Copyright (c) 2004 MNC S.A.
#
# This program is open-source and released under
# the Kannel Software License, Version 1.0. Please see
# LICENSE from the main Kannel distribution sources.
#
import sys
import re
from socket import *
port = 6666
# you may optionally specify on commandline the port to use
if len( sys.argv ) == 2:
port = int( sys.argv[1] )
# create the socket which will represent the server endpoint
sock = socket( AF_INET, SOCK_STREAM, 0 )
# allow socket to reuse a port address not fully closed; necessary
# when relaunching the server program quickly several times; see
# http://hea-www.harvard.edu/~fine/Tech/addrinuse.html
sock.setsockopt( SOL_SOCKET, SO_REUSEADDR, 1 )
# assign the local address to the socket (127.0.0.1 specifies to only
# accept connections from the local machine, not from the network
sock.bind( ( '127.0.0.1', port ) )
# tell that we're willing to accept new connections */
sock.listen( 1 )
print 'Listening for connections on port %d...' % port
while 1:
# accept the incoming connection, obtaining the file-descriptor
# representing the connection
fd, addr = sock.accept()
# read data sent by the client
buf = ''
while 1:
data = fd.recv( 10000 )
# print received data on console while it's received
sys.stdout.write( data )
buf += data
match = re.search( r'\r\n\r\n', buf )
if match:
break
print '-=-=--'
response = "HTTP/1.1 200 OK\r\n"
response += "Connection: close\r\n"
response += "\r\n"
response += "<html><body>Ok.</body></html>"
fd.send( response )
# we're done
fd.close()
|