Example #1
0
            self.writebuf = b"ERROR Time out of sync"
            return
        if action not in (b"grant", b"revoke"):
            self.writebuf = b"ERROR Invalid action"
            return
        LOGGER.info("Valid request to {0!r} {1!s}".format(action, mac))
        if action == b"grant":
            print("grant", str(mac))
        elif action == b"revoke":
            print("revoke", str(mac))
        sys.stdout.flush()
        resp = sys.stdin.readline().strip()
        if resp == "OK":
            self.writebuf = netstring.encode_netstring(b"OK")
        else:
            self.writebuf = netstring.encode_netstring(b"ERROR " + resp.encode("ascii"))


if __name__ == "__main__":
    addrinfos = socket.getaddrinfo(None, PORT, 0, socket.SOCK_STREAM, socket.SOL_TCP, socket.AI_PASSIVE)
    listeners = []
    for (family, socktype, proto, _, sockaddr) in addrinfos:
        sock = socket.socket(family, socktype, proto)
        if family == socket.AF_INET6:
            sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 1)
        sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        sock.bind(sockaddr)
        sock.listen(255)
        listeners.append(sock)
    asyncserver.main(listeners, AccessServer)
Example #2
0
            '%a, %d %b %Y %H:%M:%S GMT').encode('ascii') + b'\r\n'
        self.writebuf += b'Location: ' + url + b'\r\n'
        self.writebuf += b'Content-Length: ' + str(
            len(content)).encode('ascii') + b'\r\n'
        self.writebuf += b'Content-Type: text/html; charset=us-ascii\r\n'
        self.writebuf += b'\r\n'
        self.writebuf += content


def drop_privs():
    pwdent = pwd.getpwnam(RUNAS)
    os.setgid(pwdent.pw_gid)
    os.setuid(pwdent.pw_uid)


if __name__ == "__main__":
    addrinfos = socket.getaddrinfo(None, PORT, 0, socket.SOCK_STREAM,
                                   socket.SOL_TCP, socket.AI_PASSIVE)
    listeners = []
    for (family, socktype, proto, _, sockaddr) in addrinfos:
        sock = socket.socket(family, socktype, proto)
        if family == socket.AF_INET6:
            sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 1)
        sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        sock.setsockopt(socket.SOL_IP, IP_TRANSPARENT, 1)
        sock.bind(sockaddr)
        sock.listen(255)
        listeners.append(sock)
    drop_privs()
    asyncserver.main(listeners, RedirectorServer)
Example #3
0
        if action not in (b'grant', b'revoke'):
            self.writebuf = b'ERROR Invalid action'
            return
        LOGGER.info('Valid request to {0!r} {1!s}'.format(action, mac))
        if action == b'grant':
            print('grant', str(mac))
        elif action == b'revoke':
            print('revoke', str(mac))
        sys.stdout.flush()
        resp = sys.stdin.readline().strip()
        if resp == 'OK':
            self.writebuf = netstring.encode_netstring(b'OK')
        else:
            self.writebuf = netstring.encode_netstring(b'ERROR ' +
                                                       resp.encode('ascii'))


if __name__ == "__main__":
    addrinfos = socket.getaddrinfo(None, PORT, 0, socket.SOCK_STREAM,
                                   socket.SOL_TCP, socket.AI_PASSIVE)
    listeners = []
    for (family, socktype, proto, _, sockaddr) in addrinfos:
        sock = socket.socket(family, socktype, proto)
        if family == socket.AF_INET6:
            sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 1)
        sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        sock.bind(sockaddr)
        sock.listen(255)
        listeners.append(sock)
    asyncserver.main(listeners, AccessServer)
Example #4
0
''')

        self.writebuf += b'HTTP/1.1 302 Found\r\n'
        self.writebuf += b'Date: ' + datetime.datetime.utcnow().strftime('%a, %d %b %Y %H:%M:%S GMT').encode('ascii') + b'\r\n'
        self.writebuf += b'Location: ' + url + b'\r\n' 
        self.writebuf += b'Content-Length: ' + str(len(content)).encode('ascii') + b'\r\n'
        self.writebuf += b'Content-Type: text/html; charset=us-ascii\r\n'
        self.writebuf += b'\r\n'
        self.writebuf += content

def drop_privs():
    pwdent = pwd.getpwnam(RUNAS)
    os.setgid(pwdent.pw_gid)
    os.setuid(pwdent.pw_uid)

if __name__ == "__main__":
    addrinfos = socket.getaddrinfo(None, PORT, 0, socket.SOCK_STREAM,
                                   socket.SOL_TCP, socket.AI_PASSIVE)
    listeners = []
    for (family, socktype, proto, _, sockaddr) in addrinfos:
        sock = socket.socket(family, socktype, proto)
        if family == socket.AF_INET6:
            sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 1)
        sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        sock.setsockopt(socket.SOL_IP, IP_TRANSPARENT, 1)
        sock.bind(sockaddr)
        sock.listen(255)
        listeners.append(sock)
    drop_privs()
    asyncserver.main(listeners, RedirectorServer)