]>
Commit | Line | Data |
---|---|---|
1 | { lib, pkgs, config, myconfig, ... }: | |
2 | let | |
3 | package = pkgs.pure-ftpd.override { ldapFtpId = "immaeFtp"; }; | |
4 | in | |
5 | { | |
6 | options = { | |
7 | services.pure-ftpd.enable = lib.mkOption { | |
8 | type = lib.types.bool; | |
9 | default = false; | |
10 | description = '' | |
11 | Whether to enable pure-ftpd. | |
12 | ''; | |
13 | }; | |
14 | }; | |
15 | ||
16 | config = lib.mkIf config.services.pure-ftpd.enable { | |
17 | security.acme.certs."ftp" = config.services.myCertificates.certConfig // { | |
18 | domain = "eldiron.immae.eu"; | |
19 | postRun = '' | |
20 | systemctl restart pure-ftpd.service | |
21 | ''; | |
22 | extraDomains = { "ftp.immae.eu" = null; }; | |
23 | }; | |
24 | ||
25 | networking = { | |
26 | firewall = { | |
27 | allowedTCPPorts = [ 21 ]; | |
28 | allowedTCPPortRanges = [ { from = 40000; to = 50000; } ]; | |
29 | }; | |
30 | }; | |
31 | ||
32 | users.users = [ | |
33 | { | |
34 | name = "ftp"; | |
35 | uid = config.ids.uids.ftp; # 8 | |
36 | group = "ftp"; | |
37 | description = "Anonymous FTP user"; | |
38 | home = "/homeless-shelter"; | |
39 | extraGroups = [ "keys" ]; | |
40 | } | |
41 | ]; | |
42 | ||
43 | users.groups.ftp.gid = config.ids.gids.ftp; | |
44 | ||
45 | system.activationScripts.pure-ftpd = '' | |
46 | install -m 0755 -o ftp -g ftp -d /var/lib/ftp | |
47 | ''; | |
48 | ||
49 | secrets.keys = [{ | |
50 | dest = "pure-ftpd-ldap"; | |
51 | permissions = "0400"; | |
52 | user = "ftp"; | |
53 | group = "ftp"; | |
54 | text = '' | |
55 | LDAPServer ${myconfig.env.ftp.ldap.host} | |
56 | LDAPPort 389 | |
57 | LDAPUseTLS True | |
58 | LDAPBaseDN ${myconfig.env.ftp.ldap.base} | |
59 | LDAPBindDN ${myconfig.env.ftp.ldap.dn} | |
60 | LDAPBindPW ${myconfig.env.ftp.ldap.password} | |
61 | LDAPDefaultUID 500 | |
62 | LDAPForceDefaultUID False | |
63 | LDAPDefaultGID 100 | |
64 | LDAPForceDefaultGID False | |
65 | LDAPFilter ${myconfig.env.ftp.ldap.filter} | |
66 | ||
67 | LDAPAuthMethod BIND | |
68 | ||
69 | # Pas de possibilite de donner l'Uid/Gid ! | |
70 | # Compile dans pure-ftpd directement avec immaeFtpUid / immaeFtpGid | |
71 | LDAPHomeDir immaeFtpDirectory | |
72 | ''; | |
73 | }]; | |
74 | ||
75 | systemd.services.pure-ftpd = let | |
76 | configFile = pkgs.writeText "pure-ftpd.conf" '' | |
77 | PassivePortRange 40000 50000 | |
78 | ChrootEveryone yes | |
79 | CreateHomeDir yes | |
80 | BrokenClientsCompatibility yes | |
81 | MaxClientsNumber 50 | |
82 | Daemonize yes | |
83 | MaxClientsPerIP 8 | |
84 | VerboseLog no | |
85 | DisplayDotFiles yes | |
86 | AnonymousOnly no | |
87 | NoAnonymous no | |
88 | SyslogFacility ftp | |
89 | DontResolve yes | |
90 | MaxIdleTime 15 | |
91 | LDAPConfigFile /var/secrets/pure-ftpd-ldap | |
92 | LimitRecursion 10000 8 | |
93 | AnonymousCanCreateDirs no | |
94 | MaxLoad 4 | |
95 | AntiWarez yes | |
96 | Umask 133:022 | |
97 | # ftp | |
98 | MinUID 8 | |
99 | AllowUserFXP no | |
100 | AllowAnonymousFXP no | |
101 | ProhibitDotFilesWrite no | |
102 | ProhibitDotFilesRead no | |
103 | AutoRename no | |
104 | AnonymousCantUpload no | |
105 | MaxDiskUsage 99 | |
106 | CustomerProof yes | |
107 | TLS 1 | |
108 | CertFile ${config.security.acme.directory}/ftp/full.pem | |
109 | ''; | |
110 | in { | |
111 | description = "Pure-FTPd server"; | |
112 | wantedBy = [ "multi-user.target" ]; | |
113 | after = [ "network.target" ]; | |
114 | ||
115 | serviceConfig.ExecStart = "${package}/bin/pure-ftpd ${configFile}"; | |
116 | serviceConfig.Type = "forking"; | |
117 | serviceConfig.PIDFile = "/run/pure-ftpd.pid"; | |
118 | }; | |
119 | }; | |
120 | ||
121 | } |