Exemplo n.º 1
0
 def log_message(self, format, *args):
     message = str(
         "%s - - [%s] %s" % (self.address_string(),
                             self.log_date_time_string(), format % args))
     serverTemplate.writeServerLog(message, serverLogFile)
     if verbose == True:
         print(message)
Exemplo n.º 2
0
    def do_POST(s):
        if len(s.path) >= 7 and s.path[:7] == '/dexter':
            s.send_response(200)
            s.send_header("Content-Location", "dexter.html")
            s.send_header("Vary", "negotiate,Accept-Encoding")
            s.send_header("TCN", "choice")
            s.send_header("Pragma", "no-cache")
            s.send_header("Connection", "close")
            s.send_header("Content-type", "text/plain")
            s.end_headers()
            postData = json.loads(
                str(s.rfile.read(int(s.headers.get_all('Content-Length')[0])),
                    'utf-8'))

            # Validate if the POST was from a Dexter client
            if postData and s.headers.get_all('User-Agent')[0] == 'Dexter 1.0':
                #message = 'Successful connection'
                message = 'Successful connection from ' + s.client_address[
                    0] + ': ' + postData['DEXTERID']
                if verbose == True:
                    print(message)
                serverTemplate.writeServerLog(message, serverLogFile)
                s.wfile.write(bytes("Received", 'ascii'))
            else:
                s.wfile.write(bytes("Website under construction", 'ascii'))

        else:
            s.send_response(404)
        pass
Exemplo n.º 3
0

if __name__ == '__main__':
    # Parse arguments
    parser = argparse.ArgumentParser()
    parser.add_argument('host', help='host interface to run server on')
    parser.add_argument('port', type=int, help='port number to run server on')
    parser.add_argument('log', help='path to server log file')
    parser.add_argument(
        '-v',
        action='store_true',
        default=False,
        help='verbose mode. print incoming connections to the terminal')
    args = parser.parse_args()

    # Start server
    template = dexterHttpServer(args.host, args.port, args.log, args.v)
    httpd = template.server((args.host, args.port), MyHandler)
    print(time.asctime(), "Server Started - %s:%s" % (args.host, args.port))
    serverTemplate.writeServerLog(
        "Server Started - %s:%s" % (args.host, args.port), serverLogFile)
    try:
        httpd.serve_forever()
    except KeyboardInterrupt:
        pass
    httpd.server_close()
    print(time.asctime(), "Server Stopped - %s:%s" % (args.host, args.port))
    serverTemplate.writeServerLog(
        "Server Stopped - %s:%s" % (args.host, args.port), serverLogFile)
    pass
Exemplo n.º 4
0
    # Parse arguments
    parser = argparse.ArgumentParser()
    parser.add_argument('configFile',
                        help='JSON-formatted file with server config info')
    parser.add_argument(
        '-v',
        action='store_true',
        default=False,
        help='verbose mode. print incoming connections to the terminal')
    args = parser.parse_args()

    # Start server
    template = dexterHttpTemplate(args.configFile, verbose=args.v)
    httpd = template.server((template.host, template.port), MyHandler)
    print(time.asctime(),
          "Server Started - %s:%s" % (template.host, template.port))
    serverTemplate.writeServerLog(
        "Server Started - %s:%s" % (template.host, template.port),
        template.server.logfile)
    try:
        httpd.serve_forever()
    except KeyboardInterrupt:
        pass
    httpd.server_close()
    print(time.asctime(),
          "Server Stopped - %s:%s" % (template.host, template.port))
    serverTemplate.writeServerLog(
        "Server Stopped - %s:%s" % (template.host, template.port),
        template.server.logfile)
    pass