Пример #1
0
def main():
    if not (udp_bridge_conf and udp_bridge_conf.enabled()):
        sys.exit(13)
    with utils.lower_privileges(self._logger):

        def removePut(line):
            if line.startswith('put '):
                return line[4:]
            else:
                return line

        try:
            if (udp_bridge_conf and udp_bridge_conf.usetcp()):
                sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            else:
                sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
            sock.bind((HOST, PORT))
        except socket.error, msg:
            utils.err('could not open socket: %s' % msg)
            sys.exit(1)

        try:
            flush_delay = udp_bridge_conf.flush_delay()
        except AttributeError:
            flush_delay = 60

        flush_timeout = int(time.time())
        try:
            try:
                while 1:
                    data, address = sock.recvfrom(SIZE)
                    if data:
                        lines = data.splitlines()
                        data = '\n'.join(map(removePut, lines))
                    if not data:
                        utils.err("invalid data")
                        break
                    print data
                    now = int(time.time())
                    if now > flush_timeout:
                        sys.stdout.flush()
                        flush_timeout = now + flush_delay

            except KeyboardInterrupt:
                utils.err("keyboard interrupt, exiting")
        finally:
            sock.close()
Пример #2
0
def main():
    if not (udp_bridge_conf and udp_bridge_conf.enabled()):
      sys.exit(13)
    utils.drop_privileges()

    def removePut(line):
        if line.startswith('put '):
            return line[4:]
        else:
            return line

    try:
        if (udp_bridge_conf and udp_bridge_conf.usetcp()):
          sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        else:
          sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        sock.bind((HOST, PORT))
    except socket.error as msg:
        utils.err('could not open socket: %s' % msg)
        sys.exit(1)

    try:
        flush_delay = udp_bridge_conf.flush_delay()
    except AttributeError:
        flush_delay = 60

    flush_timeout = int(time.time())
    try:
        try:
            while 1:
                data, address = sock.recvfrom(SIZE)
                if data:
                    lines = data.splitlines()
                    data = '\n'.join(map(removePut, lines))
                if not data:
                    utils.err("invalid data")
                    break
                print(data)
                now = int(time.time())
                if now > flush_timeout:
                    sys.stdout.flush()
                    flush_timeout = now + flush_delay

        except KeyboardInterrupt:
            utils.err("keyboard interrupt, exiting")
    finally:
        sock.close()
Пример #3
0
def main():
    if not (udp_bridge_conf and udp_bridge_conf.enabled()):
      sys.exit(13)
    utils.drop_privileges()

    def removePut(line):
        if line.startswith('put '):
            return line[4:]
        else:
            return line

    try:
        if (udp_bridge_conf and udp_bridge_conf.usetcp()):
          sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        else:
          sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        sock.bind((HOST, PORT))
    except socket.error, msg:
        utils.err('could not open socket: %s' % msg)
        sys.exit(1)
Пример #4
0
def main():
    if not (udp_bridge_conf and udp_bridge_conf.enabled()):
        sys.exit(13)
    utils.drop_privileges()

    def removePut(line):
        if line.startswith('put '):
            return line[4:]
        else:
            return line

    try:
        if (udp_bridge_conf and udp_bridge_conf.usetcp()):
            sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        else:
            sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        sock.bind((HOST, PORT))
    except socket.error, msg:
        utils.err('could not open socket: %s' % msg)
        sys.exit(1)