aboutsummaryrefslogtreecommitdiff
path: root/nixops/modules/task/www/index.php
diff options
context:
space:
mode:
Diffstat (limited to 'nixops/modules/task/www/index.php')
-rw-r--r--nixops/modules/task/www/index.php135
1 files changed, 135 insertions, 0 deletions
diff --git a/nixops/modules/task/www/index.php b/nixops/modules/task/www/index.php
new file mode 100644
index 0000000..829cdd0
--- /dev/null
+++ b/nixops/modules/task/www/index.php
@@ -0,0 +1,135 @@
1<?php
2if (!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);
15ldap_set_option($connect, LDAP_OPT_PROTOCOL_VERSION, 3);
16if (!$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
25if (ldap_count_entries($connect, $search) != 1) {
26 die("Impossible to find user in LDAP");
27}
28
29$entries = [];
30foreach($info[0]["immaetaskid"] as $key => $value) {
31 if ($key !== "count") {
32 $entries[] = explode(":", $value);
33 }
34}
35
36if (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 $server_cert = file_get_contents($vardir . "/keys/server.cert");
44
45 $file = $_GET["file"];
46 switch($file) {
47 case "ca.cert.pem":
48 $content = $server_cert;
49 $name = "ca.cert.pem";
50 $type = "application/x-x509-ca-cert";
51 break;
52 case "cert.pem":
53 $content = $certificate;
54 $name = $ldap_user . ".cert.pem";
55 $type = "application/x-x509-ca-cert";
56 break;
57 case "key.pem":
58 $content = $cert_key;
59 $name = $ldap_user . ".key.pem";
60 $type = "application/x-x509-ca-cert";
61 break;
62 case "mirakel";
63 foreach ($entries as $entry) {
64 list($org, $user, $key) = $entry;
65 if ($key == $_GET["key"]) { break; }
66 }
67 $name = $user . ".mirakel";
68 $type = "text/plain";
69 $content = "username: $user
70org: $org
71user key: $key
72server: $host
73client.cert:
74$certificate
75Client.key:
76$cert_key
77ca.cert:
78$server_cert
79";
80 break;
81 default:
82 die("invalid file name");
83 break;
84 }
85
86 header("Content-Type: $type");
87 header('Content-Disposition: attachment; filename="' . $name . '"');
88 header('Content-Transfer-Encoding: binary');
89 header('Accept-Ranges: bytes');
90 header('Cache-Control: private');
91 header('Pragma: private');
92 echo $content;
93 exit;
94}
95?>
96<html>
97<header>
98 <title>Taskwarrior configuration</title>
99</header>
100<body>
101<ul>
102 <li><a href="?file=ca.cert.pem">ca.cert.pem</a></li>
103 <li><a href="?file=cert.pem"><?php echo $ldap_user; ?>.cert.pem</a></li>
104 <li><a href="?file=key.pem"><?php echo $ldap_user; ?>.key.pem</a></li>
105</ul>
106For command line interface, download the files, put them near your Taskwarrior
107configuration files, and add that to your Taskwarrior configuration:
108<pre>
109taskd.certificate=/path/to/<?php echo $ldap_user; ?>.cert.pem
110taskd.key=/path/to/<?php echo $ldap_user; ?>.key.pem
111taskd.server=<?php echo $host ."\n"; ?>
112<?php if (count($entries) > 1) {
113 echo "# Chose one of them\n";
114 foreach($entries as $entry) {
115 list($org, $user, $key) = $entry;
116 echo "# taskd.credentials=$org/$user/$key\n";
117 }
118} else { ?>
119taskd.credentials=<?php echo $entries[0][0]; ?>/<?php echo $entries[0][1]; ?>/<?php echo $entries[0][2]; ?>
120<?php } ?>
121taskd.ca=/path/to/ca.cert.pem
122</pre>
123For Mirakel, download and import the file:
124<ul>
125<?php
126foreach ($entries as $entry) {
127 list($org, $user, $key) = $entry;
128 echo '<li><a href="?file=mirakel&key='.$key.'">' . $user . '.mirakel</a></li>';
129}
130?>
131</ul>
132For Android Taskwarrior app, see instructions <a href="https://bitbucket.org/kvorobyev/taskwarriorandroid/wiki/Configuration">here</a>.
133</body>
134</html>
135