diff options
Diffstat (limited to 'modules/private/tasks')
-rw-r--r-- | modules/private/tasks/default.nix | 355 | ||||
-rw-r--r-- | modules/private/tasks/www/index.php | 168 |
2 files changed, 0 insertions, 523 deletions
diff --git a/modules/private/tasks/default.nix b/modules/private/tasks/default.nix deleted file mode 100644 index 6480255..0000000 --- a/modules/private/tasks/default.nix +++ /dev/null | |||
@@ -1,355 +0,0 @@ | |||
1 | { lib, pkgs, config, ... }: | ||
2 | let | ||
3 | cfg = config.myServices.tasks; | ||
4 | server_vardir = config.services.taskserver.dataDir; | ||
5 | fqdn = "task.immae.eu"; | ||
6 | user = config.services.taskserver.user; | ||
7 | env = config.myEnv.tools.task; | ||
8 | group = config.services.taskserver.group; | ||
9 | taskserver-user-certs = pkgs.runCommand "taskserver-user-certs" {} '' | ||
10 | mkdir -p $out/bin | ||
11 | cat > $out/bin/taskserver-user-certs <<"EOF" | ||
12 | #!/usr/bin/env bash | ||
13 | |||
14 | user=$1 | ||
15 | |||
16 | silent_certtool() { | ||
17 | if ! output="$("${pkgs.gnutls.bin}/bin/certtool" "$@" 2>&1)"; then | ||
18 | echo "GNUTLS certtool invocation failed with output:" >&2 | ||
19 | echo "$output" >&2 | ||
20 | fi | ||
21 | } | ||
22 | |||
23 | silent_certtool -p \ | ||
24 | --bits 4096 \ | ||
25 | --outfile "${server_vardir}/userkeys/$user.key.pem" | ||
26 | ${pkgs.gnused}/bin/sed -i -n -e '/^-----BEGIN RSA PRIVATE KEY-----$/,$p' "${server_vardir}/userkeys/$user.key.pem" | ||
27 | |||
28 | silent_certtool -c \ | ||
29 | --template "${pkgs.writeText "taskserver-ca.template" '' | ||
30 | tls_www_client | ||
31 | encryption_key | ||
32 | signing_key | ||
33 | expiration_days = 3650 | ||
34 | ''}" \ | ||
35 | --load-ca-certificate "${server_vardir}/keys/ca.cert" \ | ||
36 | --load-ca-privkey "${server_vardir}/keys/ca.key" \ | ||
37 | --load-privkey "${server_vardir}/userkeys/$user.key.pem" \ | ||
38 | --outfile "${server_vardir}/userkeys/$user.cert.pem" | ||
39 | EOF | ||
40 | chmod a+x $out/bin/taskserver-user-certs | ||
41 | patchShebangs $out/bin/taskserver-user-certs | ||
42 | ''; | ||
43 | taskwarrior-web = pkgs.webapps.taskwarrior-web; | ||
44 | socketsDir = "/run/taskwarrior-web"; | ||
45 | varDir = "/var/lib/taskwarrior-web"; | ||
46 | taskwebPages = let | ||
47 | uidPages = lib.attrsets.zipAttrs ( | ||
48 | lib.lists.flatten | ||
49 | (lib.attrsets.mapAttrsToList (k: c: map (v: { "${v}" = k; }) c.uid) env.taskwarrior-web) | ||
50 | ); | ||
51 | pages = lib.attrsets.mapAttrs (uid: items: | ||
52 | if lib.lists.length items == 1 then | ||
53 | '' | ||
54 | <html> | ||
55 | <head> | ||
56 | <meta http-equiv="refresh" content="0; url=/taskweb/${lib.lists.head items}/" /> | ||
57 | </head> | ||
58 | <body></body> | ||
59 | </html> | ||
60 | '' | ||
61 | else | ||
62 | '' | ||
63 | <html> | ||
64 | <head> | ||
65 | <title>To-do list disponibles</title> | ||
66 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | ||
67 | <meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
68 | </head> | ||
69 | <body> | ||
70 | <ul> | ||
71 | ${builtins.concatStringsSep "\n" (map (item: "<li><a href='/taskweb/${item}'>${item}</a></li>") items)} | ||
72 | </ul> | ||
73 | </body> | ||
74 | </html> | ||
75 | '' | ||
76 | ) uidPages; | ||
77 | in | ||
78 | pkgs.runCommand "taskwerver-pages" {} '' | ||
79 | mkdir -p $out/ | ||
80 | ${builtins.concatStringsSep "\n" (lib.attrsets.mapAttrsToList (k: v: "cp ${pkgs.writeText k v} $out/${k}.html") pages)} | ||
81 | echo "Please login" > $out/index.html | ||
82 | ''; | ||
83 | in { | ||
84 | options.myServices.tasks = { | ||
85 | enable = lib.mkEnableOption "my tasks service"; | ||
86 | }; | ||
87 | |||
88 | config = lib.mkIf cfg.enable { | ||
89 | secrets.keys = { | ||
90 | "webapps/tools-taskwarrior-web" = { | ||
91 | user = "wwwrun"; | ||
92 | group = "wwwrun"; | ||
93 | permissions = "0400"; | ||
94 | text = '' | ||
95 | SetEnv TASKD_HOST "${fqdn}:${toString config.services.taskserver.listenPort}" | ||
96 | SetEnv TASKD_VARDIR "${server_vardir}" | ||
97 | SetEnv TASKD_LDAP_HOST "ldaps://${env.ldap.host}" | ||
98 | SetEnv TASKD_LDAP_DN "${env.ldap.dn}" | ||
99 | SetEnv TASKD_LDAP_PASSWORD "${env.ldap.password}" | ||
100 | SetEnv TASKD_LDAP_BASE "${env.ldap.base}" | ||
101 | SetEnv TASKD_LDAP_FILTER "${env.ldap.filter}" | ||
102 | ''; | ||
103 | }; | ||
104 | } // (lib.mapAttrs' (name: userConfig: lib.nameValuePair "webapps/tools-taskwarrior/${name}-taskrc" { | ||
105 | inherit user group; | ||
106 | permissions = "0400"; | ||
107 | text = let | ||
108 | credentials = "${userConfig.org}/${name}/${userConfig.key}"; | ||
109 | dateFormat = userConfig.date; | ||
110 | in '' | ||
111 | data.location=${varDir}/${name} | ||
112 | taskd.certificate=${server_vardir}/userkeys/taskwarrior-web.cert.pem | ||
113 | taskd.key=${server_vardir}/userkeys/taskwarrior-web.key.pem | ||
114 | # IdenTrust DST Root CA X3 | ||
115 | # obtained here: https://letsencrypt.org/fr/certificates/ | ||
116 | taskd.ca=${pkgs.writeText "ca.cert" '' | ||
117 | -----BEGIN CERTIFICATE----- | ||
118 | MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw | ||
119 | TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh | ||
120 | cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4 | ||
121 | WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJu | ||
122 | ZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBY | ||
123 | MTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK3oJHP0FDfzm54rVygc | ||
124 | h77ct984kIxuPOZXoHj3dcKi/vVqbvYATyjb3miGbESTtrFj/RQSa78f0uoxmyF+ | ||
125 | 0TM8ukj13Xnfs7j/EvEhmkvBioZxaUpmZmyPfjxwv60pIgbz5MDmgK7iS4+3mX6U | ||
126 | A5/TR5d8mUgjU+g4rk8Kb4Mu0UlXjIB0ttov0DiNewNwIRt18jA8+o+u3dpjq+sW | ||
127 | T8KOEUt+zwvo/7V3LvSye0rgTBIlDHCNAymg4VMk7BPZ7hm/ELNKjD+Jo2FR3qyH | ||
128 | B5T0Y3HsLuJvW5iB4YlcNHlsdu87kGJ55tukmi8mxdAQ4Q7e2RCOFvu396j3x+UC | ||
129 | B5iPNgiV5+I3lg02dZ77DnKxHZu8A/lJBdiB3QW0KtZB6awBdpUKD9jf1b0SHzUv | ||
130 | KBds0pjBqAlkd25HN7rOrFleaJ1/ctaJxQZBKT5ZPt0m9STJEadao0xAH0ahmbWn | ||
131 | OlFuhjuefXKnEgV4We0+UXgVCwOPjdAvBbI+e0ocS3MFEvzG6uBQE3xDk3SzynTn | ||
132 | jh8BCNAw1FtxNrQHusEwMFxIt4I7mKZ9YIqioymCzLq9gwQbooMDQaHWBfEbwrbw | ||
133 | qHyGO0aoSCqI3Haadr8faqU9GY/rOPNk3sgrDQoo//fb4hVC1CLQJ13hef4Y53CI | ||
134 | rU7m2Ys6xt0nUW7/vGT1M0NPAgMBAAGjQjBAMA4GA1UdDwEB/wQEAwIBBjAPBgNV | ||
135 | HRMBAf8EBTADAQH/MB0GA1UdDgQWBBR5tFnme7bl5AFzgAiIyBpY9umbbjANBgkq | ||
136 | hkiG9w0BAQsFAAOCAgEAVR9YqbyyqFDQDLHYGmkgJykIrGF1XIpu+ILlaS/V9lZL | ||
137 | ubhzEFnTIZd+50xx+7LSYK05qAvqFyFWhfFQDlnrzuBZ6brJFe+GnY+EgPbk6ZGQ | ||
138 | 3BebYhtF8GaV0nxvwuo77x/Py9auJ/GpsMiu/X1+mvoiBOv/2X/qkSsisRcOj/KK | ||
139 | NFtY2PwByVS5uCbMiogziUwthDyC3+6WVwW6LLv3xLfHTjuCvjHIInNzktHCgKQ5 | ||
140 | ORAzI4JMPJ+GslWYHb4phowim57iaztXOoJwTdwJx4nLCgdNbOhdjsnvzqvHu7Ur | ||
141 | TkXWStAmzOVyyghqpZXjFaH3pO3JLF+l+/+sKAIuvtd7u+Nxe5AW0wdeRlN8NwdC | ||
142 | jNPElpzVmbUq4JUagEiuTDkHzsxHpFKVK7q4+63SM1N95R1NbdWhscdCb+ZAJzVc | ||
143 | oyi3B43njTOQ5yOf+1CceWxG1bQVs5ZufpsMljq4Ui0/1lvh+wjChP4kqKOJ2qxq | ||
144 | 4RgqsahDYVvTH9w7jXbyLeiNdd8XM2w9U/t7y0Ff/9yi0GE44Za4rF2LN9d11TPA | ||
145 | mRGunUHBcnWEvgJBQl9nJEiU0Zsnvgc/ubhPgXRR4Xq37Z0j4r7g1SgEEzwxA57d | ||
146 | emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc= | ||
147 | -----END CERTIFICATE-----''} | ||
148 | taskd.server=${fqdn}:${toString config.services.taskserver.listenPort} | ||
149 | taskd.credentials=${credentials} | ||
150 | dateformat=${dateFormat} | ||
151 | ''; | ||
152 | }) env.taskwarrior-web); | ||
153 | services.websites.env.tools.watchPaths = [ config.secrets.fullPaths."webapps/tools-taskwarrior-web" ]; | ||
154 | services.websites.env.tools.modules = [ "proxy_fcgi" "sed" ]; | ||
155 | services.websites.env.tools.vhostConfs.task = { | ||
156 | certName = "eldiron"; | ||
157 | addToCerts = true; | ||
158 | hosts = [ "task.immae.eu" ]; | ||
159 | root = ./www; | ||
160 | extraConfig = [ '' | ||
161 | <Directory ${./www}> | ||
162 | DirectoryIndex index.php | ||
163 | Use LDAPConnect | ||
164 | Require ldap-group cn=users,cn=taskwarrior,ou=services,dc=immae,dc=eu | ||
165 | <FilesMatch "\.php$"> | ||
166 | SetHandler "proxy:unix:${config.services.phpfpm.pools.tasks.socket}|fcgi://localhost" | ||
167 | </FilesMatch> | ||
168 | Include ${config.secrets.fullPaths."webapps/tools-taskwarrior-web"} | ||
169 | </Directory> | ||
170 | '' | ||
171 | '' | ||
172 | <Macro Taskwarrior %{folderName}> | ||
173 | ProxyPass "unix://${socketsDir}/%{folderName}.sock|http://localhost-%{folderName}/" | ||
174 | ProxyPassReverse "unix://${socketsDir}/%{folderName}.sock|http://localhost-%{folderName}/" | ||
175 | ProxyPassReverse http://${fqdn}/ | ||
176 | |||
177 | SetOutputFilter Sed | ||
178 | OutputSed "s|/ajax|/taskweb/%{folderName}/ajax|g" | ||
179 | OutputSed "s|\([^x]\)/tasks|\1/taskweb/%{folderName}/tasks|g" | ||
180 | OutputSed "s|\([^x]\)/projects|\1/taskweb/%{folderName}/projects|g" | ||
181 | OutputSed "s|http://${fqdn}/|/taskweb/%{folderName}/|g" | ||
182 | OutputSed "s|/img/relax.jpg|/taskweb/%{folderName}/img/relax.jpg|g" | ||
183 | </Macro> | ||
184 | '' | ||
185 | '' | ||
186 | Alias /taskweb ${taskwebPages} | ||
187 | <Directory "${taskwebPages}"> | ||
188 | DirectoryIndex index.html | ||
189 | Require all granted | ||
190 | </Directory> | ||
191 | |||
192 | RewriteEngine on | ||
193 | RewriteRule ^/taskweb$ /taskweb/ [R=301,L] | ||
194 | RedirectMatch permanent ^/taskweb/([^/]+)$ /taskweb/$1/ | ||
195 | |||
196 | RewriteCond %{LA-U:REMOTE_USER} !="" | ||
197 | RewriteCond ${taskwebPages}/%{LA-U:REMOTE_USER}.html -f | ||
198 | RewriteRule ^/taskweb/?$ ${taskwebPages}/%{LA-U:REMOTE_USER}.html [L] | ||
199 | |||
200 | <Location /taskweb/> | ||
201 | Use LDAPConnect | ||
202 | Require ldap-group cn=users,cn=taskwarrior,ou=services,dc=immae,dc=eu | ||
203 | </Location> | ||
204 | '' | ||
205 | ] ++ (lib.attrsets.mapAttrsToList (k: v: '' | ||
206 | <Location /taskweb/${k}/> | ||
207 | ${builtins.concatStringsSep "\n" (map (uid: "Require ldap-attribute uid=${uid}") v.uid)} | ||
208 | |||
209 | Use Taskwarrior ${k} | ||
210 | </Location> | ||
211 | '') env.taskwarrior-web); | ||
212 | }; | ||
213 | services.phpfpm.pools = { | ||
214 | tasks = { | ||
215 | user = user; | ||
216 | group = group; | ||
217 | settings = { | ||
218 | "listen.owner" = "wwwrun"; | ||
219 | "listen.group" = "wwwrun"; | ||
220 | "pm" = "dynamic"; | ||
221 | "pm.max_children" = "60"; | ||
222 | "pm.start_servers" = "2"; | ||
223 | "pm.min_spare_servers" = "1"; | ||
224 | "pm.max_spare_servers" = "10"; | ||
225 | |||
226 | # Needed to avoid clashes in browser cookies (same domain) | ||
227 | "php_value[session.name]" = "TaskPHPSESSID"; | ||
228 | "php_admin_value[open_basedir]" = "${./www}:/tmp:${server_vardir}:/etc/profiles/per-user/${user}/bin/"; | ||
229 | }; | ||
230 | phpEnv = { | ||
231 | PATH = "/etc/profiles/per-user/${user}/bin"; | ||
232 | }; | ||
233 | phpPackage = pkgs.php72; | ||
234 | }; | ||
235 | }; | ||
236 | |||
237 | security.acme.certs."task" = config.myServices.certificates.certConfig // { | ||
238 | inherit user group; | ||
239 | domain = fqdn; | ||
240 | postRun = '' | ||
241 | systemctl restart taskserver.service | ||
242 | ''; | ||
243 | }; | ||
244 | |||
245 | users.users.${user} = { | ||
246 | extraGroups = [ "keys" ]; | ||
247 | packages = [ taskserver-user-certs ]; | ||
248 | }; | ||
249 | |||
250 | system.activationScripts.taskserver = { | ||
251 | deps = [ "users" ]; | ||
252 | text = '' | ||
253 | install -m 0750 -o ${user} -g ${group} -d ${server_vardir} | ||
254 | install -m 0750 -o ${user} -g ${group} -d ${server_vardir}/userkeys | ||
255 | install -m 0750 -o ${user} -g ${group} -d ${server_vardir}/keys | ||
256 | |||
257 | if [ ! -e "${server_vardir}/keys/ca.key" ]; then | ||
258 | silent_certtool() { | ||
259 | if ! output="$("${pkgs.gnutls.bin}/bin/certtool" "$@" 2>&1)"; then | ||
260 | echo "GNUTLS certtool invocation failed with output:" >&2 | ||
261 | echo "$output" >&2 | ||
262 | fi | ||
263 | } | ||
264 | |||
265 | silent_certtool -p \ | ||
266 | --bits 4096 \ | ||
267 | --outfile "${server_vardir}/keys/ca.key" | ||
268 | |||
269 | silent_certtool -s \ | ||
270 | --template "${pkgs.writeText "taskserver-ca.template" '' | ||
271 | cn = ${fqdn} | ||
272 | expiration_days = -1 | ||
273 | cert_signing_key | ||
274 | ca | ||
275 | ''}" \ | ||
276 | --load-privkey "${server_vardir}/keys/ca.key" \ | ||
277 | --outfile "${server_vardir}/keys/ca.cert" | ||
278 | |||
279 | chown :${group} "${server_vardir}/keys/ca.key" | ||
280 | chmod g+r "${server_vardir}/keys/ca.key" | ||
281 | fi | ||
282 | ''; | ||
283 | }; | ||
284 | |||
285 | services.taskserver = { | ||
286 | enable = true; | ||
287 | allowedClientIDs = [ "^task [2-9]" "^Mirakel [1-9]" ]; | ||
288 | inherit fqdn; | ||
289 | listenHost = "::"; | ||
290 | pki.manual.ca.cert = "${server_vardir}/keys/ca.cert"; | ||
291 | pki.manual.server.cert = "${config.security.acme.certs.task.directory}/fullchain.pem"; | ||
292 | pki.manual.server.crl = "${config.security.acme.certs.task.directory}/invalid.crl"; | ||
293 | pki.manual.server.key = "${config.security.acme.certs.task.directory}/key.pem"; | ||
294 | requestLimit = 104857600; | ||
295 | }; | ||
296 | |||
297 | system.activationScripts.taskwarrior-web = { | ||
298 | deps = [ "users" ]; | ||
299 | text = '' | ||
300 | if [ ! -f ${server_vardir}/userkeys/taskwarrior-web.cert.pem ]; then | ||
301 | ${taskserver-user-certs}/bin/taskserver-user-certs taskwarrior-web | ||
302 | chown taskd:taskd ${server_vardir}/userkeys/taskwarrior-web.cert.pem ${server_vardir}/userkeys/taskwarrior-web.key.pem | ||
303 | fi | ||
304 | ''; | ||
305 | }; | ||
306 | |||
307 | systemd.slices.taskwarrior = { | ||
308 | description = "Taskwarrior slice"; | ||
309 | }; | ||
310 | |||
311 | systemd.services = (lib.attrsets.mapAttrs' (name: userConfig: | ||
312 | lib.attrsets.nameValuePair "taskwarrior-web-${name}" { | ||
313 | description = "Taskwarrior webapp for ${name}"; | ||
314 | wantedBy = [ "multi-user.target" ]; | ||
315 | after = [ "network.target" ]; | ||
316 | path = [ pkgs.taskwarrior ]; | ||
317 | |||
318 | environment.TASKRC = config.secrets.fullPaths."webapps/tools-taskwarrior/${name}-taskrc"; | ||
319 | environment.BUNDLE_PATH = "${taskwarrior-web.gems}/${taskwarrior-web.gems.ruby.gemPath}"; | ||
320 | environment.BUNDLE_GEMFILE = "${taskwarrior-web.gems.confFiles}/Gemfile"; | ||
321 | environment.LC_ALL = "fr_FR.UTF-8"; | ||
322 | |||
323 | script = '' | ||
324 | exec ${taskwarrior-web.gems}/${taskwarrior-web.gems.ruby.gemPath}/bin/bundle exec thin start -R config.ru -S ${socketsDir}/${name}.sock | ||
325 | ''; | ||
326 | |||
327 | serviceConfig = { | ||
328 | Slice = "taskwarrior.slice"; | ||
329 | User = user; | ||
330 | PrivateTmp = true; | ||
331 | Restart = "always"; | ||
332 | TimeoutSec = 60; | ||
333 | Type = "simple"; | ||
334 | WorkingDirectory = taskwarrior-web; | ||
335 | StateDirectoryMode = 0750; | ||
336 | StateDirectory = assert lib.strings.hasPrefix "/var/lib/" varDir; | ||
337 | (lib.strings.removePrefix "/var/lib/" varDir + "/${name}"); | ||
338 | RuntimeDirectoryPreserve = "yes"; | ||
339 | RuntimeDirectory = assert lib.strings.hasPrefix "/run/" socketsDir; | ||
340 | lib.strings.removePrefix "/run/" socketsDir; | ||
341 | }; | ||
342 | |||
343 | unitConfig.RequiresMountsFor = varDir; | ||
344 | }) env.taskwarrior-web) // { | ||
345 | taskserver-ca.postStart = '' | ||
346 | chown :${group} "${server_vardir}/keys/ca.key" | ||
347 | chmod g+r "${server_vardir}/keys/ca.key" | ||
348 | ''; | ||
349 | taskserver-ca.serviceConfig.Slice = "taskwarrior.slice"; | ||
350 | taskserver-init.serviceConfig.Slice = "taskwarrior.slice"; | ||
351 | taskserver.serviceConfig.Slice = "taskwarrior.slice"; | ||
352 | }; | ||
353 | |||
354 | }; | ||
355 | } | ||
diff --git a/modules/private/tasks/www/index.php b/modules/private/tasks/www/index.php deleted file mode 100644 index 49ccd24..0000000 --- a/modules/private/tasks/www/index.php +++ /dev/null | |||
@@ -1,168 +0,0 @@ | |||
1 | <?php | ||
2 | if (!isset($_SERVER["REMOTE_USER"])) { | ||
3 | die("please login"); | ||
4 | } | ||
5 | $ldap_user = $_SERVER["REMOTE_USER"]; | ||
6 | $ldap_host = getenv("TASKD_LDAP_HOST"); | ||
7 | $ldap_dn = getenv('TASKD_LDAP_DN'); | ||
8 | $ldap_password = getenv('TASKD_LDAP_PASSWORD'); | ||
9 | $ldap_base = getenv('TASKD_LDAP_BASE'); | ||
10 | $ldap_filter = getenv('TASKD_LDAP_FILTER'); | ||
11 | $host = getenv('TASKD_HOST'); | ||
12 | $vardir = getenv('TASKD_VARDIR'); | ||
13 | |||
14 | $connect = ldap_connect($ldap_host); | ||
15 | ldap_set_option($connect, LDAP_OPT_PROTOCOL_VERSION, 3); | ||
16 | if (!$connect || !ldap_bind($connect, $ldap_dn, $ldap_password)) { | ||
17 | die("impossible to connect to LDAP"); | ||
18 | } | ||
19 | |||
20 | $search_query = str_replace('%login%', ldap_escape($ldap_user), $ldap_filter); | ||
21 | |||
22 | $search = ldap_search($connect, $ldap_base, $search_query); | ||
23 | $info = ldap_get_entries($connect, $search); | ||
24 | |||
25 | if (ldap_count_entries($connect, $search) != 1) { | ||
26 | die("Impossible to find user in LDAP"); | ||
27 | } | ||
28 | |||
29 | $entries = []; | ||
30 | foreach($info[0]["immaetaskid"] as $key => $value) { | ||
31 | if ($key !== "count") { | ||
32 | $entries[] = explode(":", $value); | ||
33 | } | ||
34 | } | ||
35 | |||
36 | if (isset($_GET["file"])) { | ||
37 | $basecert = $vardir . "/userkeys/" . $ldap_user; | ||
38 | if (!file_exists($basecert . ".cert.pem")) { | ||
39 | exec("taskserver-user-certs $ldap_user"); | ||
40 | } | ||
41 | $certificate = file_get_contents($basecert . ".cert.pem"); | ||
42 | $cert_key = file_get_contents($basecert . ".key.pem"); | ||
43 | |||
44 | // IdenTrust DST Root CA X3 | ||
45 | // obtained here: https://letsencrypt.org/fr/certificates/ | ||
46 | $server_cert = "-----BEGIN CERTIFICATE----- | ||
47 | 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 | ||
76 | -----END CERTIFICATE-----"; | ||
77 | |||
78 | $file = $_GET["file"]; | ||
79 | switch($file) { | ||
80 | case "ca.cert.pem": | ||
81 | $content = $server_cert; | ||
82 | $name = "ca.cert.pem"; | ||
83 | $type = "application/x-x509-ca-cert"; | ||
84 | break; | ||
85 | case "cert.pem": | ||
86 | $content = $certificate; | ||
87 | $name = $ldap_user . ".cert.pem"; | ||
88 | $type = "application/x-x509-ca-cert"; | ||
89 | break; | ||
90 | case "key.pem": | ||
91 | $content = $cert_key; | ||
92 | $name = $ldap_user . ".key.pem"; | ||
93 | $type = "application/x-x509-ca-cert"; | ||
94 | break; | ||
95 | case "mirakel"; | ||
96 | foreach ($entries as $entry) { | ||
97 | list($org, $user, $key) = $entry; | ||
98 | if ($key == $_GET["key"]) { break; } | ||
99 | } | ||
100 | $name = $user . ".mirakel"; | ||
101 | $type = "text/plain"; | ||
102 | $content = "username: $user | ||
103 | org: $org | ||
104 | user key: $key | ||
105 | server: $host | ||
106 | client.cert: | ||
107 | $certificate | ||
108 | Client.key: | ||
109 | $cert_key | ||
110 | ca.cert: | ||
111 | $server_cert | ||
112 | "; | ||
113 | break; | ||
114 | default: | ||
115 | die("invalid file name"); | ||
116 | break; | ||
117 | } | ||
118 | |||
119 | header("Content-Type: $type"); | ||
120 | header('Content-Disposition: attachment; filename="' . $name . '"'); | ||
121 | header('Content-Transfer-Encoding: binary'); | ||
122 | header('Accept-Ranges: bytes'); | ||
123 | header('Cache-Control: private'); | ||
124 | header('Pragma: private'); | ||
125 | echo $content; | ||
126 | exit; | ||
127 | } | ||
128 | ?> | ||
129 | <html> | ||
130 | <header> | ||
131 | <title>Taskwarrior configuration</title> | ||
132 | </header> | ||
133 | <body> | ||
134 | <ul> | ||
135 | <li><a href="?file=ca.cert.pem">ca.cert.pem</a></li> | ||
136 | <li><a href="?file=cert.pem"><?php echo $ldap_user; ?>.cert.pem</a></li> | ||
137 | <li><a href="?file=key.pem"><?php echo $ldap_user; ?>.key.pem</a></li> | ||
138 | </ul> | ||
139 | For command line interface, download the files, put them near your Taskwarrior | ||
140 | configuration files, and add that to your Taskwarrior configuration: | ||
141 | <pre> | ||
142 | taskd.certificate=/path/to/<?php echo $ldap_user; ?>.cert.pem | ||
143 | taskd.key=/path/to/<?php echo $ldap_user; ?>.key.pem | ||
144 | taskd.server=<?php echo $host ."\n"; ?> | ||
145 | <?php if (count($entries) > 1) { | ||
146 | echo "# Chose one of them\n"; | ||
147 | foreach($entries as $entry) { | ||
148 | list($org, $user, $key) = $entry; | ||
149 | echo "# taskd.credentials=$org/$user/$key\n"; | ||
150 | } | ||
151 | } else { ?> | ||
152 | taskd.credentials=<?php echo $entries[0][0]; ?>/<?php echo $entries[0][1]; ?>/<?php echo $entries[0][2]; ?> | ||
153 | <?php } ?> | ||
154 | taskd.ca=/path/to/ca.cert.pem | ||
155 | </pre> | ||
156 | For Mirakel, download and import the file: | ||
157 | <ul> | ||
158 | <?php | ||
159 | foreach ($entries as $entry) { | ||
160 | list($org, $user, $key) = $entry; | ||
161 | echo '<li><a href="?file=mirakel&key='.$key.'">' . $user . '.mirakel</a></li>'; | ||
162 | } | ||
163 | ?> | ||
164 | </ul> | ||
165 | For Android Taskwarrior app, see instructions <a href="https://bitbucket.org/kvorobyev/taskwarriorandroid/wiki/Configuration">here</a>. | ||
166 | </body> | ||
167 | </html> | ||
168 | |||