]> git.datanom.net - webcal.git/blob - utils/ldap.php
Initial upload
[webcal.git] / utils / ldap.php
1 <?php
2 /* $Id$ */
3 require_once 'config.inc.php';
4 require_once 'user_validate.php';
5 require_once 'helper.php';
6
7 valid_user();
8
9 if (! defined($_SESSION['__ROOT__']) && empty($_SESSION['__ROOT__'])) {
10 if (session_id())
11 session_destroy();
12 header('Location: ' . WEB_ROOT . 'error.html');
13 exit;
14 }
15
16 require_once 'persistens.php';
17
18 $user = $_SESSION['user_settings'];
19
20 if ($user->getRole() !== 0) {
21 if (session_id())
22 session_destroy();
23 header('Location: ' . WEB_ROOT . 'error.html');
24 exit;
25 }
26
27 $db = Persistens::getInstance(DBDRIVER);
28
29 if (count($_POST) > 0) {
30 $config = array(
31 (isset($_POST['enable']) && $_POST['enable'] == 'on') ? 1 : 0,
32 $_POST['dns'],
33 (isset($_POST['tls']) && $_POST['tls'] == 'on') ? 1 : 0,
34 $_POST['base_dn'],
35 $_POST['user_attr']
36 );
37 if (($res = $db->setLdapConfig($config)) === true)
38 $pageView = "<p style=\"text-align: center\">
39 LDAP configuration was successfully updated</p>";
40 else
41 $pageView = "<p style=\"text-align: center\">$res</p>";
42 }
43 else {
44 $config = $db->getLdapConfig();
45 if (! is_array($config) && $config) {
46 if (session_id())
47 session_destroy();
48 header('Location: ' . WEB_ROOT . 'error.html');
49 exit;
50 }
51
52 $enable = ($config['enable']) ? ' checked="checked"' : '';
53 $tls = ($config['tls']) ? ' checked="checked"' : '';
54 $dns = $config['dns'];
55 $base_dn = $config['base_dn'];
56 $user_attr = $config['user_attr'];
57 $pageView = <<< __EOF
58 <form action="{$_SERVER['PHP_SELF']}" method="post">
59 <table class="config">
60 <tr>
61 <th>Setting</th><th>Current</th>
62 </tr>
63 <tr>
64 <td class="config">LDAP enabled</td>
65 <td class="config">
66 <input name="enable" type="checkbox"$enable/>
67 </td>
68 </tr>
69 <tr>
70 <td class="config">URL</td>
71 <td class="config">
72 <input size="30" name="dns" type="text" value="$dns"/>
73 </td>
74 </tr>
75 <tr>
76 <td class="config">Use TLS</td>
77 <td class="config">
78 <input name="tls" type="checkbox"$tls/>
79 </td>
80 </tr>
81 <tr>
82 <td class="config">Base DN</td>
83 <td class="config">
84 <input size="30" name="base_dn" type="text" value="$base_dn"/>
85 </td>
86 </tr>
87 <tr>
88 <td class="config">User ATTR</td>
89 <td class="config">
90 <input name="user_attr" type="text" value="$user_attr"/>
91 </td>
92 </tr>
93 <tr>
94 <td class="config" colspan="2" style="text-align: center">
95 <input type="submit" name="setting" value="Submit changes"/>
96 </td>
97 </tr>
98 </table>
99 </form>
100 <p>
101 After enabling LDAP users will be authenticated by LDAP and when
102 a user logs on for the first time an account will automatically
103 be created using the username provided by LDAP. If the user
104 account is removed from LDAP the account will be deactivated but
105 remain in webcal until deleted by the admin user.<br/>
106 <br/>
107 If your LDAP server is located here: <span class="bold">ldap.foo.tld
108 </span> on either port
109 389 or 636 then URL is:<br/>
110 Without SSL (389): <span class="bold">ldap://</span>ldap.foo.tld<br/>
111 With SSL (636): <span class="bold">ldaps://</span>ldap.foo.tld<br/>
112 With TLS (389): <span class="bold">ldap://</span>ldap.foo.tld and
113 <span class="bold">check "Use TLS"</span><br/>
114 If your LDAP server is listen on 8389 then this port number must
115 be added to the URL like ldap://ldap.foo.tld<span class="bold">:8389</span><br/>
116 <br/>
117 If your Bind DN is the following: uid=username,ou=people,dc=foo,
118 dc=tld then "Base DN" and "User ATTR" has to look like this:<br/>
119 Base DN: <span class="bold">ou=people,dc=foo,dc=tld</span><br/>
120 User ATTR: <span class="bold">uid</span><br/>
121 If your Bind DN is the following: cn=username,dc=foo,dc=tld then
122 "Base DN" and "User ATTR" has to look like this:<br/>
123 Base DN: <span class="bold">dc=foo,dc=tld</span><br/>
124 User ATTR: <span class="bold">cn</span>
125 </p>
126 __EOF;
127 }
128
129 include TOP_FOLDER.'/include/header.inc.php';
130 include TOP_FOLDER.'/include/menu.inc.php';
131
132 print "<div id=\"ui\">$pageView</div>";
133
134 include TOP_FOLDER.'/include/footer.inc.php';
135 ?>
This page took 0.07861 seconds and 6 git commands to generate.