OLD | NEW |
1 #!/usr/bin/python2.4 | 1 #!/usr/bin/python2.4 |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """This is a simple HTTP server used for testing Chrome. | 6 """This is a simple HTTP server used for testing Chrome. |
7 | 7 |
8 It supports several test URLs, as specified by the handlers in TestPageHandler. | 8 It supports several test URLs, as specified by the handlers in TestPageHandler. |
9 By default, it listens on an ephemeral port and sends the port number back to | 9 By default, it listens on an ephemeral port and sends the port number back to |
10 the originating process over a pipe. The originating process can specify an | 10 the originating process over a pipe. The originating process can specify an |
(...skipping 1471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1482 # let's make sure the cert file exists. | 1482 # let's make sure the cert file exists. |
1483 if not os.path.isfile(options.cert): | 1483 if not os.path.isfile(options.cert): |
1484 print 'specified server cert file not found: ' + options.cert + \ | 1484 print 'specified server cert file not found: ' + options.cert + \ |
1485 ' exiting...' | 1485 ' exiting...' |
1486 return | 1486 return |
1487 for ca_cert in options.ssl_client_ca: | 1487 for ca_cert in options.ssl_client_ca: |
1488 if not os.path.isfile(ca_cert): | 1488 if not os.path.isfile(ca_cert): |
1489 print 'specified trusted client CA file not found: ' + ca_cert + \ | 1489 print 'specified trusted client CA file not found: ' + ca_cert + \ |
1490 ' exiting...' | 1490 ' exiting...' |
1491 return | 1491 return |
1492 server = HTTPSServer(('127.0.0.1', port), TestPageHandler, options.cert, | 1492 server = HTTPSServer(('0.0.0.0', port), TestPageHandler, options.cert, |
1493 options.ssl_client_auth, options.ssl_client_ca, | 1493 options.ssl_client_auth, options.ssl_client_ca, |
1494 options.ssl_bulk_cipher) | 1494 options.ssl_bulk_cipher) |
1495 print 'HTTPS server started on port %d...' % server.server_port | 1495 print 'HTTPS server started on port %d...' % server.server_port |
1496 else: | 1496 else: |
1497 server = StoppableHTTPServer(('127.0.0.1', port), TestPageHandler) | 1497 server = StoppableHTTPServer(('0.0.0.0', port), TestPageHandler) |
1498 print 'HTTP server started on port %d...' % server.server_port | 1498 print 'HTTP server started on port %d...' % server.server_port |
1499 | 1499 |
1500 server.data_dir = MakeDataDir() | 1500 server.data_dir = MakeDataDir() |
1501 server.file_root_url = options.file_root_url | 1501 server.file_root_url = options.file_root_url |
1502 server_data['port'] = server.server_port | 1502 server_data['port'] = server.server_port |
1503 server._device_management_handler = None | 1503 server._device_management_handler = None |
1504 server.policy_keys = options.policy_keys | 1504 server.policy_keys = options.policy_keys |
1505 server.policy_user = options.policy_user | 1505 server.policy_user = options.policy_user |
1506 elif options.server_type == SERVER_SYNC: | 1506 elif options.server_type == SERVER_SYNC: |
1507 server = SyncHTTPServer(('127.0.0.1', port), SyncPageHandler) | 1507 server = SyncHTTPServer(('0.0.0.0', port), SyncPageHandler) |
1508 print 'Sync HTTP server started on port %d...' % server.server_port | 1508 print 'Sync HTTP server started on port %d...' % server.server_port |
1509 print 'Sync XMPP server started on port %d...' % server.xmpp_port | 1509 print 'Sync XMPP server started on port %d...' % server.xmpp_port |
1510 server_data['port'] = server.server_port | 1510 server_data['port'] = server.server_port |
1511 server_data['xmpp_port'] = server.xmpp_port | 1511 server_data['xmpp_port'] = server.xmpp_port |
1512 # means FTP Server | 1512 # means FTP Server |
1513 else: | 1513 else: |
1514 my_data_dir = MakeDataDir() | 1514 my_data_dir = MakeDataDir() |
1515 | 1515 |
1516 # Instantiate a dummy authorizer for managing 'virtual' users | 1516 # Instantiate a dummy authorizer for managing 'virtual' users |
1517 authorizer = pyftpdlib.ftpserver.DummyAuthorizer() | 1517 authorizer = pyftpdlib.ftpserver.DummyAuthorizer() |
1518 | 1518 |
1519 # Define a new user having full r/w permissions and a read-only | 1519 # Define a new user having full r/w permissions and a read-only |
1520 # anonymous user | 1520 # anonymous user |
1521 authorizer.add_user('chrome', 'chrome', my_data_dir, perm='elradfmw') | 1521 authorizer.add_user('chrome', 'chrome', my_data_dir, perm='elradfmw') |
1522 | 1522 |
1523 authorizer.add_anonymous(my_data_dir) | 1523 authorizer.add_anonymous(my_data_dir) |
1524 | 1524 |
1525 # Instantiate FTP handler class | 1525 # Instantiate FTP handler class |
1526 ftp_handler = pyftpdlib.ftpserver.FTPHandler | 1526 ftp_handler = pyftpdlib.ftpserver.FTPHandler |
1527 ftp_handler.authorizer = authorizer | 1527 ftp_handler.authorizer = authorizer |
1528 | 1528 |
1529 # Define a customized banner (string returned when client connects) | 1529 # Define a customized banner (string returned when client connects) |
1530 ftp_handler.banner = ("pyftpdlib %s based ftpd ready." % | 1530 ftp_handler.banner = ("pyftpdlib %s based ftpd ready." % |
1531 pyftpdlib.ftpserver.__ver__) | 1531 pyftpdlib.ftpserver.__ver__) |
1532 | 1532 |
1533 # Instantiate FTP server class and listen to 127.0.0.1:port | 1533 # Instantiate FTP server class and listen to 0.0.0.0:port |
1534 address = ('127.0.0.1', port) | 1534 address = ('0.0.0.0', port) |
1535 server = pyftpdlib.ftpserver.FTPServer(address, ftp_handler) | 1535 server = pyftpdlib.ftpserver.FTPServer(address, ftp_handler) |
1536 server_data['port'] = server.socket.getsockname()[1] | 1536 server_data['port'] = server.socket.getsockname()[1] |
1537 print 'FTP server started on port %d...' % server_data['port'] | 1537 print 'FTP server started on port %d...' % server_data['port'] |
1538 | 1538 |
1539 # Notify the parent that we've started. (BaseServer subclasses | 1539 # Notify the parent that we've started. (BaseServer subclasses |
1540 # bind their sockets on construction.) | 1540 # bind their sockets on construction.) |
1541 if options.startup_pipe is not None: | 1541 if options.startup_pipe is not None: |
1542 server_data_json = simplejson.dumps(server_data) | 1542 server_data_json = simplejson.dumps(server_data) |
1543 server_data_len = len(server_data_json) | 1543 server_data_len = len(server_data_json) |
1544 print 'sending server_data: %s (%d bytes)' % ( | 1544 print 'sending server_data: %s (%d bytes)' % ( |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1617 'random key if none is specified on the command ' | 1617 'random key if none is specified on the command ' |
1618 'line.') | 1618 'line.') |
1619 option_parser.add_option('', '--policy-user', default='user@example.com', | 1619 option_parser.add_option('', '--policy-user', default='user@example.com', |
1620 dest='policy_user', | 1620 dest='policy_user', |
1621 help='Specify the user name the server should ' | 1621 help='Specify the user name the server should ' |
1622 'report back to the client as the user owning the ' | 1622 'report back to the client as the user owning the ' |
1623 'token used for making the policy request.') | 1623 'token used for making the policy request.') |
1624 options, args = option_parser.parse_args() | 1624 options, args = option_parser.parse_args() |
1625 | 1625 |
1626 sys.exit(main(options, args)) | 1626 sys.exit(main(options, args)) |
OLD | NEW |