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