-
-
Notifications
You must be signed in to change notification settings - Fork 264
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Haproxy PROXY protocol v1 and v2
Signed-off-by: Frank Villaro-Dixon <[email protected]>
- Loading branch information
1 parent
5793ee5
commit 0dff56d
Showing
6 changed files
with
626 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/usr/bin/env python | ||
|
||
# Copyright (C) 2007 Giampaolo Rodola' <[email protected]>. | ||
# Use of this source code is governed by MIT license that can be | ||
# found in the LICENSE file. | ||
|
||
"""A basic FTP server which uses a DummyAuthorizer for managing 'virtual | ||
users', setting a limit for incoming connections and a range of passive | ||
ports. Accepts connections from proxies implementing the PROXY protocol. | ||
""" | ||
|
||
import os | ||
|
||
from pyftpdlib.authorizers import DummyAuthorizer | ||
from pyftpdlib.handlers import FTPHandler | ||
from pyftpdlib.servers import FTPServer | ||
|
||
|
||
def main(): | ||
# Instantiate a dummy authorizer for managing 'virtual' users | ||
authorizer = DummyAuthorizer() | ||
|
||
# Define a new user having full r/w permissions and a read-only | ||
# anonymous user | ||
authorizer.add_user('user', '12345', os.getcwd(), perm='elradfmwMT') | ||
authorizer.add_anonymous(os.getcwd()) | ||
|
||
# Instantiate FTP handler class | ||
handler = FTPHandler | ||
handler.authorizer = authorizer | ||
|
||
# Define a customized banner (string returned when client connects) | ||
handler.banner = "pyftpdlib based ftpd ready." | ||
|
||
# Specify a masquerade address and the range of ports to use for | ||
# passive connections. Decomment in case you're behind a NAT. | ||
# handler.masquerade_address = '151.25.42.11' | ||
handler.passive_ports = range(20000, 22535) | ||
|
||
|
||
# Instantiate FTP server class and listen on 0.0.0.0:2121 | ||
address = ('', 2121) | ||
FTPServer.proxy_proto_enabled = True | ||
FTPServer.proxy_proto_allow_untrusted = True | ||
server = FTPServer(address, handler) | ||
|
||
# set a limit for connections | ||
server.max_cons = 256 | ||
server.max_cons_per_ip = 5 | ||
|
||
# start ftp server | ||
server.serve_forever() | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.