From a868b2522ef865f117c892a07ae3507686783ff3 Mon Sep 17 00:00:00 2001 From: jim-p Date: Wed, 4 Mar 2015 15:35:54 -0500 Subject: Add a basic FTP Client Proxy using ftp-proxy(8) from FreeBSD --- config/ftpproxy/ftpproxy.inc | 137 +++++++++++++++++++++++++++++++++++++++++++ config/ftpproxy/ftpproxy.xml | 111 +++++++++++++++++++++++++++++++++++ 2 files changed, 248 insertions(+) create mode 100644 config/ftpproxy/ftpproxy.inc create mode 100644 config/ftpproxy/ftpproxy.xml (limited to 'config/ftpproxy') diff --git a/config/ftpproxy/ftpproxy.inc b/config/ftpproxy/ftpproxy.inc new file mode 100644 index 00000000..7f65e646 --- /dev/null +++ b/config/ftpproxy/ftpproxy.inc @@ -0,0 +1,137 @@ += 1) && ($cf["maxessions"] <= 500)) { + $start .= " -m " . escapeshellarg($cf["maxessions"]); + } + if (!empty($cf["tsq"])) { + $start .= " -q " . escapeshellarg($cf["tsq"]); + } + if ($cf["src20"] == "on") { + $start .= " -r "; + } + if (is_numeric($cf["idletimeout"]) && ($cf["idletimeout"] > 0) && ($cf["idletimeout"] <= 86400)) { + $start .= " -t " . escapeshellarg($cf["idletimeout"]); + } + if ($cf["log"] == "on") { + $start .= " -v "; + } + $start .= "\n"; + + write_rcfile(array( + "file" => "ftp-proxy.sh", + "start" => $start, + "stop" => "/usr/bin/killall -9 ftp-proxy" + ) + ); + restart_service("ftp-proxy"); + conf_mount_ro(); + config_unlock(); + filter_configure(); +} + +function validate_form_ftpproxy($post, &$input_errors) { + if (empty($post["localints"])) { + $input_errors[] = 'One or more Local Interfaces must be selected'; + } + if (!empty($post["sourceaddr"]) && !is_ipaddr($post["sourceaddr"])) { + $input_errors[] = 'You must specify a valid ip address in the \'Source Address\' field'; + } + if (!empty($post["bindport"]) && !is_port($post["bindport"])) { + $input_errors[] = 'You must specify a valid port number in the \'Bind Port\' field'; + } + if (!empty($post["maxessions"]) && (!is_numeric($post["maxessions"]) || ($post["maxessions"] < 1) || ($post["maxessions"] > 500))) { + $input_errors[] = 'You must specify a valid number in the \'Max Sessions\' field (Between 1 and 500)'; + } + if (!empty($post["idletimeout"]) && (is_numeric($post["idletimeout"]) || ($post["idletimeout"] <= 0) || ($post["idletimeout"] > 86400))) { + $input_errors[] = 'You must specify a valid number in the \'Idle Timeout\' field (Between 1 and 86400)'; + } +} + +function ftpproxy_get_port() { + global $config; + $cf = $config['installedpackages']['ftpclientproxy']['config'][0]; + if (!empty($cf["bindport"]) && is_port($cf["bindport"])) { + return $cf["bindport"]; + } else { + return 8021; + } +} + +function ftpproxy_generate_rules($type) { + global $config; + $cf = $config['installedpackages']['ftpclientproxy']['config'][0]; + $interface_list = explode(",", $cf['localints']); + + /* Proxy is not enabled, therefore, no rules/anchors. */ + if ($cf["proxy_enable"] != "on") { + return; + } + + /* Bail if there is nothing to do */ + if (empty($interface_list)) { + log_error("FTP Proxy cannot sync: No interfaces selected."); + return; + } + + $rules = ""; + switch ($type) { + case "nat": + $rules .= "nat-anchor \"ftp-proxy/*\"\n"; + $rules .= "rdr-anchor \"ftp-proxy/*\"\n"; + + foreach ($interface_list as $interface_friendly) { + if (empty($interface_friendly)) { + continue; + } + $interface = get_real_interface($interface_friendly); + if (empty($interface)) { + continue; + } + $rules .= "rdr pass on {$interface} inet proto tcp from any to any port 21 -> 127.0.0.1 port " . ftpproxy_get_port() . "\n"; + if ($cf["ipv6_enable"] == "on") { + $rules .= "rdr pass on {$interface} inet6 proto tcp from any to any port 21 -> ::1 port " . ftpproxy_get_port() . "\n"; + } + } + break; + case "filter": + $rules .= "anchor \"ftp-proxy/*\"\n"; + // $rules = "pass out proto tcp from any to any port 21\n"; + break; + + } + return $rules; +} +?> \ No newline at end of file diff --git a/config/ftpproxy/ftpproxy.xml b/config/ftpproxy/ftpproxy.xml new file mode 100644 index 00000000..ca83f911 --- /dev/null +++ b/config/ftpproxy/ftpproxy.xml @@ -0,0 +1,111 @@ + + FTP Client Proxy + 0.1 + FTP Client Proxy + pkg_edit.php?xml=ftpproxy.xml + /usr/local/pkg/ftpproxy.inc + + /usr/local/pkg/ + 077 + https://packages.pfsense.org/packages/config/ftpproxy/ftpproxy.inc + + + FTP Client Proxy + Modify FTP Client Proxy settings. +
Services
+ ftpproxy.xml + /pkg_edit.php?xml=ftpproxy.xml +
+ + ftp-proxy + ftp-proxy.sh + ftp-proxy + Client FTP Proxy Daemon + + + + General Settings + listtopic + + + Proxy Enabled + proxy_enable + Enable the FTP Proxy. + checkbox + off + + + Local Interface + localints + interfaces_selection + Select the local (LAN type) interfaces which contain FTP clients. + + + + + IPv6 Support + ipv6_enable + Support IPv6 FTP connections, otherwise only IPv4 connections are allowed. + checkbox + off + + + Anonymous Only + anononly + Only permit anonymous FTP connections using the "ftp" or "anonymous" users. + checkbox + off + + + Source Address + sourceaddr + Enter a VIP to be the source of outgoing control traffic. + input + + + Bind Port (Default: 8021) + bindport + Port where the proxy will listen for redirected connections. + input + + + Maximum Sessions (Default: 100) + maxessions + Maximum number of concurrent FTP sessions. When the proxy reaches this limit, new connections are denied. Must be between 1 and 500. + input + + + Traffic Shaping Queue + tsq + Create rules with queue appended, so that data connections can be queued. + input + + + Rewrite Source to Port 20 + src20 + Rewrite source port to 20 in active mode to suit ancient clients that insist on this behavior. + checkbox + off + + + Idle Timeout (Default: 86400) + idletimeout + (Seconds) Number of seconds that the control connection can be idle, before the proxy will disconnect. The maximum is 86400 seconds. Do not set this too low, because the control connection is usually idle when large data transfers are taking place. + input + + + Log Connections + log + Set the 'log' flag on pf rules committed by ftp-proxy. + checkbox + off + + + + + sync_package_ftpproxy(); + + + validate_form_ftpproxy($_POST, $input_errors); + +
-- cgit v1.2.3