steffen: server/kolab/kolab/admin/user create_user.php, 1.14, 1.15 forward.php, 1.8, 1.9 head.php, 1.8, 1.9 index.php, 1.15, 1.16 vacation.php, 1.9, 1.10
cvs at intevation.de
cvs at intevation.de
Fri Apr 16 12:17:31 CEST 2004
- Previous message: steffen: server/kolab/kolab/admin/statistics index.php, 1.5, 1.6 kolab.php, 1.4, 1.5 load.php, 1.4, 1.5 mta.php, 1.4, 1.5
- Next message: steffen: server/perl-kolab/Kolab-Conf Conf.pm,1.2,1.3
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Author: steffen
Update of /kolabrepository/server/kolab/kolab/admin/user
In directory doto:/tmp/cvs-serv22487/admin/user
Modified Files:
create_user.php forward.php head.php index.php vacation.php
Log Message:
Started restructuring the webinterface. New classes:
KolabLdap: Class for accessing the ldap server, API not fully evolved yet
KolabAuth: Class for authenticating a user using the LDAP class
KolabForm: HTML form handling class. This is supposed to replace the many
long input forms in the webinterface. Currently it is only used in
user/ and some error-handling is missing
Index: create_user.php
===================================================================
RCS file: /kolabrepository/server/kolab/kolab/admin/user/create_user.php,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- create_user.php 4 Apr 2004 16:26:37 -0000 1.14
+++ create_user.php 16 Apr 2004 10:17:28 -0000 1.15
@@ -1,19 +1,19 @@
-<?
+<?php
/*
(c) 2003 Tassilo Erlewein <tassilo.erlewein at erfrakon.de>
(c) 2003 Martin Konold <martin.konold at erfrakon.de>
This program is Free Software under the GNU General Public License (>=v2).
Read the file COPYING that comes with this packages for details.
*/
- include("head.php");
- This("user/create_user.php?action=create");
- Head();
- include("../include/checks.php");
-?>
+require_once('../include/authenticate.php');
+require_once('../include/form.class.php');
+include("head.php");
+This("user/create_user.php?action=create");
+Head();
+include("../include/checks.php");
-<?
function debug ($a) {
- #print "debug: $a<br>\n";
+ //print "debug: $a<br>\n";
}
debug("debug is on");
@@ -21,32 +21,26 @@
$errors = array();
$valid_actions = array('save','firstsave','modify','create','delete','kill');
-if (!empty($HTTP_GET_VARS['action']) &&
- in_array($HTTP_GET_VARS['action'],$valid_actions)) $action = trim(urldecode($HTTP_GET_VARS['action']));
- else array_push($errors, "Error: need valid action to proceed");
+if (!empty($_REQUEST['action']) &&
+ in_array($_REQUEST['action'],$valid_actions)) $action = trim(urldecode($_REQUEST['action']));
+else array_push($errors, "Error: need valid action to proceed");
$dn="";
-if (!empty($HTTP_GET_VARS['dn'])) $dn = trim(urldecode($HTTP_GET_VARS['dn']));
+if (!empty($_REQUEST['dn'])) $dn = trim(urldecode($_REQUEST['dn']));
-if (!($uid = $_SERVER['PHP_AUTH_USER']) ||
- !($bind_dn = uid2dn($uid)) ||
- !($group = uid2group($uid)))
- array_push($errors, "Internal Error: could not get Authentication Information");
+$uid = $auth->uid();
+$group = $auth->group();
+$bind_dn = $auth->dn();
+$link = $ldap->connection;
if (!$errors && $group != "maintainer" && $group != "admin" &&
- !($group == "user" && $dn == $bind_dn))
+ !($group == "user" && $dn == $auth->dn() ))
array_push($errors, "Error: You don't have the required Permissions");
debug("givenuid=$uid, bind_dn=$bind_dn, dn='$dn', group=$group");
$myself = $_SERVER['PHP_SELF'];
-if (!empty($_SESSION['ldap_server'])) $ldap_server = $_SESSION['ldap_server'];
- else $ldap_server = '127.0.0.1';
-
-if (!empty($_SESSION['ldap_port'])) $ldap_port = $_SESSION['ldap_port'];
- else $ldap_port = 389;
-
$attributes = array( 'title', 'cn', 'sn', 'uid', 'mail', 'alias', 'o',
'ou', 'roomNumber', 'street', 'postOfficeBox',
'postalCode', 'l', 'c', 'telephoneNumber',
@@ -55,361 +49,59 @@
$utf8 = array ( 'cn', 'title', 'o', 'ou', 'roomNumber', 'street', 'sn',
'postOfficeBox', 'postalCode', 'l', 'c', 'telephoneNumber',
'facsimileTelephoneNumber' );
-function to_utf8 ($a)
-{
- global $utf8;
- global $attributes;
- $utf8_ecnoded = true;
- foreach ($attributes as $attr) {
- if (!in_array($attr,$utf8) || empty($a[$attr])) continue;
- if (is_array($a[$attr])) {
- $index = 0;
- while (!empty($a[$attr][$index])) {
- $a[$attr][$index] = utf8_encode($a[$attr][$index]);
- $index++;
- }
- } elseif (!empty($a[$attr])) $a[$attr] = utf8_encode($a[$attr]);
- }
- return $a;
-}
-function from_utf8 ($a)
-{
- global $utf8;
- global $attributes;
- foreach ($attributes as $attr) {
- if (!in_array($attr,$utf8) || empty($a[$attr])) continue;
- if (is_array($a[$attr])) {
- $index = 0;
- while (!empty($a[$attr][$index])) {
- $a[$attr][$index] = utf8_decode($a[$attr][$index]);
- $index++;
- }
- } elseif (!empty($a[$attr])) $a[$attr] = utf8_decode($a[$attr]);
- }
- return $a;
-}
-
-function fill_up($a)
-{
- global $attributes;
- global $action;
- foreach ($attributes as $attr) {
- if ($attr == 'uid' || $attr == 'mail') continue;
- if ($attr == 'userPassword' && $action != "firstsave" ) continue;
- if (empty($a[$attr])) $a[$attr] = array();
- }
- return $a;
-}
-function fill_up2 ($a)
-{
- global $attributes;
- foreach ($attributes as $attr) {
- if ($attr == 'uid' || $attr == 'mail') continue;
- if (empty($a[$attr])) $a[$attr] = array(0 => "", 'count' => 1);
- }
- return $a;
-}
-
-
-$beautify = array (
- 'c' => 'Country', 'l' => 'City', 'street' => 'Street Address', 'telephoneNumber' => 'Telephone Number',
- 'postOfficeBox' => 'Postbox', 'postalCode' => 'Postal Code', 'ou' => 'Organizational Unit',
- 'o' => 'Organization', 'roomNumber' => 'Room Number', 'title' => 'Title', 'cn' => 'Name',
- 'sn' => 'Surname', 'facsimileTelephoneNumber' => 'Fax Number', 'mail' => 'Primary E-Mail Address',
- 'alias' => 'E-Mail Alias',
- #'uid' => 'Unique UserID',
- 'userquota' => 'Mailbox Size Limit',
- 'userPassword' => 'Password', 'firstname' => 'First Name', 'lastname' => 'Last Name');
-
-function dobeautify ($a)
-{
- global $beautify;
- if (array_key_exists($a, $beautify)) return $beautify[$a];
- return $a;
-}
-
-if ($action == "create") {
- $comment_mail_0 = 'Required, non volatile' ;
- $comment_password = 'Required';
-} else {
- $comment_mail_0 = 'non volatile' ;
- $comment_password = 'Leave blank to keep password unchanged';
-}
-
-$comment = array(
- 'firstname' => 'Required', 'sn_0' => 'Required',
- 'password_0' => $comment_password, 'password_1' => $comment_password,
- 'mail_0' => $comment_mail_0,
- 'visible' => 'check here to make this users address <br> visible in the address book');
-
-function comment ($a)
-{
- global $comment;
- if (array_key_exists($a, $comment)) return $comment[$a];
- return '';
-}
-
-$blacklist = array('cn', 'sn', 'uid', 'mail', 'userPassword');
-
-function black ($a)
-{
- global $blacklist;
- return in_array($a,$blacklist);
-}
-
-$noshow = array('objectClass','cn','sn', 'mail', 'userPassword', 'uid');
-
-
-function noshow ($a)
-{
- global $noshow;
- return in_array($a, $noshow);
+function comment( $s ) {
+ return $s;
}
-
-$firstname = "";
-$lastname = "";
-$password_0 = "";
-$password_1 = "";
-$mail_0 = "";
-$domain = "";
-$domain_dn = "";
-$visible = true;
-if (strstr($dn, "cn=internal")) $visible = false;
-
-$missing_input = 0;
-
-function missing_input ()
-{
- global $missing_input;
- global $errors;
-
- if (!$missing_input) {
- $missing_input++;
- array_push($errors, "Error: Input required");
- }
+function is_unique ($a, $b) {
+ global $ldap;
+ if (($result = $ldap->search( $_SESSION['base_dn'],"(".$a."=".$b.")")) &&
+ (ldap_count_entries($ldap->connection,$result) <= 0))
+ return true;
+ return false;
}
-function is_unique ($a, $b)
+function domain_dn()
{
- global $link;
- if (($result = ldap_search($link,$_SESSION['base_dn'],"(".$a."=".$b.")")) &&
- (ldap_count_entries($link,$result) <= 0))
- return TRUE;
- return FALSE;
+ /*
+ global $ldap;
+ global $errors;
+ if ($dattrs = $ldap->read( 'k=kolab,'.$_SESSION['base_dn'])) {
+ $domain = $dattrs['postfix-mydomain'][0];
+ $dcs = array_reverse(explode('.', $domain));
+ $domain_dn = $_SESSION['base_dn'];
+ foreach ($dcs as $dc) $domain_dn = "dc=$dc,".$domain_dn;
+
+ } else {
+ array_push($errors, "LDAP Error: could not determin domain");
+ $domain_dn = $_SESSION['base_dn'];
+ }
+ return $domain_dn;
+ */
+ return $_SESSION['base_dn'];
}
-
-$ldap_object = array('objectClass' => "inetOrgPerson");
-
-if (!$errors && (!($link = ldap_connect($ldap_server,$ldap_port)) ||
- !ldap_bind($link, $bind_dn, $_SERVER["PHP_AUTH_PW"])))
- array_push($errors, "Communication Error: could bind to ldap://$ldap_server:$ldap_port ".ldap_error($link));
-if (!$errors) {
- // ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION, 3);
- if (($result = ldap_read($link, $_SESSION['base_dn'], "(objectclass=*)")) &&
- ($entry = ldap_first_entry($link,$result)) &&
- ($dattrs = ldap_get_attributes($link,$entry))) {
-
- $domain = $dattrs['postfix-mydomain'][0];
- $dcs = array_reverse(explode('.', $domain));
- $domain_dn = $_SESSION['base_dn'];
- foreach ($dcs as $dc) $domain_dn = "dc=$dc,".$domain_dn;
-
- } else array_push($errors, "LDAP Error: could not determin domain");
- $domain_dn = $_SESSION['base_dn'];
-
- if ($action == "kill") {
-
- if (!$dn) array_push($errors, "Error: need dn for delete operation");
- elseif ($group != "maintainer" && $group != "admin")
- array_push($errors, "Error: you need administrative permissions to delete users");
-
- if (!$errors) {
- print("<div class=\"maintitle\"> Delete User </div>\n");
- $delete_template['deleteflag'] = 'TRUE';
- if (!(ldap_modify($link,$dn,$delete_template))) {
- array_push($errors, "LDAP Error: could not mark ".utf8_decode($dn)." for deletion ".ldap_error($link));
- } else {
-// system("sudo -u kolab /kolab/etc/kolab/kolab_buildconfig &");
- print("<div class=\"message\"> The object ".utf8_decode($dn)." has been deleted </div>\n");
- }
- }
-
- } else {
-
- switch ($action) {
-
- case "firstsave":
- if (empty($HTTP_GET_VARS['mail_0'])) {
- $comment['mail_0'] = "<span class=\"warning\"> Fill in valid email address</span>";
- missing_input();
- }
- if ( empty($HTTP_GET_VARS['password_0'])) {
- $comment['password_0'] = "<span class=\"warning\"> Fill in password </span>";
- missing_input();
- }
- if (empty($HTTP_GET_VARS['password_1'])) {
- $comment['password_1'] = "<span class=\"warning\"> Fill in password </span>";
- missing_input();
- }
-
- case "save":
- if ($action == "save" && !$dn) array_push($errors, "Internal Error: need dn to save");
- if ($group == "admin" || $group == "maintainer") {
- if (!empty($HTTP_GET_VARS['firstname'])) {
- $firstname = trim(urldecode($HTTP_GET_VARS['firstname']));
- } else {
- $comment['firstname'] = "<span class=\"warning\"> Fill in firstname </span>";
- missing_input();
- }
- if (!empty($HTTP_GET_VARS['lastname'])) {
- $ldap_object['sn'] = trim(urldecode($HTTP_GET_VARS['lastname']));
- if ($firstname) $ldap_object['cn'] = $firstname." ".$ldap_object['sn'];
- } else {
- $comment['lastname'] = "<span class=\"warning\"> Fill in lastname </span>";
- missing_input();
- }
- }
- if (!empty($HTTP_GET_VARS['password_0'])) $password_0 = urldecode($HTTP_GET_VARS['password_0']);
- if (!empty($HTTP_GET_VARS['password_1'])) $password_1 = urldecode($HTTP_GET_VARS['password_1']);
- if ($password_0 && $password_1 ) {
- if ($password_0 == $password_1) {
- $ldap_object['userPassword'] = '{sha}'.base64_encode(pack("H*", sha1($password_0)));
- } else {
- $comment['password_1'] = "<span class=\"warning\"> Passwords do not match </span>";
- missing_input();
- }
- }
-
- if (!empty($HTTP_GET_VARS['mail_0']) && !is_unique($HTTP_GET_VARS['mail_0'])) {
- $ldap_object['mail'] = trim(strtolower(urldecode($HTTP_GET_VARS['mail_0'])));
- if ($action == "firstsave") $ldap_object['uid'] = $ldap_object['mail'];
- } else {
- $comment['mail_0'] = "<span class=\"warning\">email address is already taken by another user</span>";
- missing_input();
- }
-
- foreach ($attributes as $attr) {
- if (black($attr)) continue;
- $count = 0;
- $key = $attr."_0";
- $args = array();
- while (!empty($HTTP_GET_VARS[$key])) {
- $args[$count] = trim(urldecode($HTTP_GET_VARS[$key]));
- $count++;
- $key = $attr."_".$count;
- }
- if ($count > 0) $ldap_object[$attr] = $args;
- elseif (!empty($HTTP_GET_VARS[$key])) $ldap_object[$attr] = $HTTP_GET_VARS[$key];
- }
- if ($group == "maintainer" || $group == "admin") {
- if (!empty($HTTP_GET_VARS['visible']) && $HTTP_GET_VARS['visible'] == "true")
- $visible = true;
- else $visible = false;
- }
- if (!$visible) $dn_add = ",cn=internal";
- else $dn_add = "";
- if (!empty($ldap_object['alias']) && !is_unique('alias',$ldap_object['alias'])) {
- $comment['alias_0'] = "<span class=\"warning\"> Error: the alias you gave is <br>".
- "already taken by another user</span>";
- missing_input();
- }
- $ldap_object = to_utf8($ldap_object);
- if ($action == "save") {
- if (!$errors) {
- if (!empty($ldap_object['cn'])) $newdn = "cn=".$ldap_object['cn'].",".$domain_dn;
- else $newdn = $dn;
- if (!$visible && !strstr($newdn,$dn_add)) {
- list($cn,$rest) = split(',', $newdn, 2);
- $newdn = $cn.$dn_add.",".$rest;
- }
- if (strcmp($dn,$newdn) != 0) {
- if (($result=ldap_read($link,$dn,"(objectclass=*)")) &&
- ($entry=ldap_first_entry($link,$result)) &&
- ($oldattrs=ldap_get_attributes($link,$entry))) {
- $ldap_object['uid'] = $oldattrs['uid'][0];
- $ldap_object['mail'] = $oldattrs['mail'][0];
- if (!ldap_add($link,$newdn, $ldap_object) || !ldap_delete($link,$dn))
- array_push($errors, "LDAP Error: could not rename $dn to $newdn ".ldap_error($link));
- $dn = $newdn;
- } else array_push($errors,"LDAP Error: could not read $dn ".ldap_error($link));
- } else {
- $ldap_object = fill_up($ldap_object);
- if ($group == "user") {
- unset($ldap_object['sn']);
- unset($ldap_object['cn']);
- }
- if (!ldap_modify($link, $dn, $ldap_object))
- array_push($errors, "LDAP Error: could not modify object $dn ".ldap_error($link));
- }
- }
- } else {
- if (!$errors) {
- $dn = "cn=".$ldap_object['cn'].$dn_add.",".$domain_dn;
- if ($dn && !ldap_add($link, $dn, $ldap_object))
- array_push($errors, "LDAP Error: could not add object $dn ".ldap_error($link));
-// else system("sudo -u kolab /kolab/etc/kolab/kolab_buildconfig &");
- }
- if ($errors) {
- print("<div class=\"maintitle\"> Create New User </div>\n");
- $blacklist = array('mail');
- $action = "create";
- $ldap_object = from_utf8($ldap_object);
- break;
- }
- }
- $action = "modify";
- print("<div class=\"maintitle\"> Modify Existing User </div>\n");
- break;
-
- case "create":
- print("<div class=\"maintitle\"> Create New User </div>\n");
- $blacklist = array('mail');
- break;
-
- case "modify":
- print("<div class=\"maintitle\"> Modify Existing User </div>\n");
- break;
-
- case "delete":
- print("<div class=\"maintitle\"> Confirm Delete User </div>\n");
- }
-
- if ($dn) {
- $ldap_object = array();
- if (($result = ldap_read($link, $dn, "(objectclass=*)")) &&
- ($entry = ldap_first_entry($link,$result)) &&
- ($ldap_object = ldap_get_attributes($link,$entry))) {
- $ldap_object = from_utf8($ldap_object);
- $ldap_object = fill_up2($ldap_object);
- ldap_free_result($result);
- } else array_push($errors, "LDAP Error: could not read $dn ".ldap_error($link));
+function checkpw( $form, $key, $value ) {
+ global $action;
+ if( $action == "firstsave" ) {
+ if( $key == 'password_0' ) {
+ if( $value == '' ) return 'Password is empty';
+ } else if( $key == 'password_1' ) {
+ if( $value != $_POST['password_0'] ) {
+ return 'Passwords dont match';
}
- }
- ldap_close($link);
-}
-
-$width = 50;
-
-//print "ldap_object gelesen: "; print_r($ldap_object); print "<br>";
-
-if (in_array($action, $valid_actions) && $action != "kill") {
- print "<div class=\"contenttable\"><form action=\"$myself\" method=\"GET\">\n";
- switch ($action) {
- case "create":
- print("<input type=\"hidden\" name=\"action\" value=\"firstsave\">\n");
- break;
- case "delete":
- print("<input type=\"hidden\" name=\"action\" value=\"kill\">\n");
- break;
- default:
- print("<input type=\"hidden\" name=\"action\" value=\"save\">\n");
+ }
+ } else {
+ if( $value != $_POST['password_0'] ) {
+ return 'Passwords dont match';
+ }
}
- if ($dn) print "<input type=\"hidden\" name=\"dn\" value=\"$dn\">\n";
- print "<table class=\"contentform\">\n";
+ return '';
+}
+
+function fill_form_for_modify( &$form, &$ldap_object ) {
if (is_array($ldap_object['sn'])) $lastname = $ldap_object['sn'][0];
else $lastname = $ldap_object['sn'];
if (is_array($ldap_object['cn'])) $cn = $ldap_object['cn'][0];
@@ -421,91 +113,228 @@
$firstname = substr($cn, 0, $b - $a);
}
}
- if ($action == "delete") print("<tr><th> Attribute </th><th> Value </th></tr>\n");
- else print("<tr><th> Attribute </th><th> Value </th><th> Comment </th></tr>\n");
- print "<tr><td> First Name </td><td>\n";
- if ($action == "delete") print("$firstname </td></tr>\n");
- else {
- if ($group == "admin" || $group == "maintainer") {
- print "<input type=\"text\" name=\"firstname\" size=$width maxlength=80 value=\"$firstname\">\n";
- print "</td><td>".(comment('firstname'))."</td></tr>\n";
- }
- else print("$firstname </td><td> </td></tr>\n");
+ if (is_array($ldap_object['mail'])) $mail_0 = $ldap_object['mail'][0];
+ else $mail_0 = $ldap_object['mail'];
+ $form->entries['firstname']['value'] = $firstname;
+ $form->entries['lastname']['value'] = $lastname;
+ $form->entries['password_0']['value'] = '';
+ $form->entries['password_1']['value'] = '';
+ $form->entries['mail_0']['value'] = $mail_0;
+ $form->entries['mail_0']['attrs'] = 'readonly';
+
+ foreach( array( 'title', 'alias', 'o', 'ou', 'street', 'postOfficeBox',
+ 'postalCode', 'l', 'c', 'telephoneNumber',
+ 'facsimileTelephoneNumber' ) as $attr ) {
+ if (is_array($ldap_object[$attr])) $v = $ldap_object[$attr][0];
+ else $v = $ldap_object[$attr];
+ $form->entries[$attr.'_0']['value'] = $v;
+ }
}
-print "<tr><td> Last Name </td><td>\n";
-if ($action == "delete") print("$lastname </td></tr>\n");
-else {
- if ($group == "admin" || $group == "maintainer") {
- print "<input type=\"text\" name=\"lastname\" size=$width maxlength=80 value=\"$lastname\">\n";
- print "</td><td>".(comment('sn_0'))."</td></tr>\n";
- } else print("$lastname </td><td> </td></tr>\n");
+if ($action == "create") {
+ $comment_mail_0 = 'Required, non volatile' ;
+ $comment_password = 'Required';
+} else {
+ $comment_mail_0 = 'non volatile' ;
+ $comment_password = 'Leave blank to keep password unchanged';
}
-if ($action != "delete") {
- /*if (is_array($ldap_object['userPassword'])) $password_0 = $password_1 = $ldap_object['userPassword'][0];
- else $password_0 = $password_1 = $ldap_object['userPassword'];
- */
- $password_0 = $password_1 = '';
- print "<tr><td> Password </td><td>\n";
- print "<input type=\"password\" name=\"password_0\" size=$width maxlength=80 value=\"$password_0\">\n";
- print "</td><td>".(comment('password_0'))."</td></tr>\n";
- print "<tr><td> Verfiy Password </td><td>\n";
- print "<input type=\"password\" name=\"password_1\" size=$width maxlength=80 value=\"$password_1\">\n";
- print "</td><td>".(comment('password_1'))."</td></tr>\n";
- print "<tr><td> Primary Email Address</td><td>\n";
- if (is_array($ldap_object['mail'])) $mail_0 = $ldap_object['mail'][0];
- else $mail_0 = $ldap_object['mail'];
- print "<input type=\"text\" ";
- if ($action != "create") {
- print " readonly ";
- }
- print "name=\"mail_0\" size=$width maxlength=80 value=\"$mail_0\">\n";
- print "<td>".(comment('mail_0'))."</td></tr>\n";
+
+$entries = array( 'firstname' => array( 'name' => 'First Name',
+ 'validation' => 'notempty',
+ 'comment' => 'Required' ),
+ 'lastname' => array( 'name' => 'Last Name',
+ 'validation' => 'notempty',
+ 'comment' => 'Required' ),
+ 'password_0' => array( 'name' => 'Password',
+ 'type' => 'password',
+ 'validation' => 'checkpw',
+ 'comment' => $comment_password ),
+ 'password_1' => array( 'name' => 'Verify Password',
+ 'type' => 'password',
+ 'validation' => 'checkpw',
+ 'comment' => $comment_password ),
+ 'mail_0' => array( 'name' => 'Primary Email Address',
+ 'validation' => 'notempty',
+ 'comment' => $comment_mail_0 ),
+ 'title_0' => array( 'name' => 'Title' ) );
+$entries['alias_0'] = array( 'name' => 'Email Alias' );
+// Add more alias entries here...
+
+$entries['o_0'] = array( 'name' => 'Organisation' );
+$entries['ou_0'] = array( 'name' => 'Organisational Unit' );
+$entries['roomNumber_0'] = array( 'name' => 'Room Number' );
+$entries['street_0'] = array( 'name' => 'Street Address' );
+$entries['postOfficeBox_0'] = array( 'name' => 'Postbox' );
+$entries['postalCode_0'] = array( 'name' => 'Postal Code' );
+$entries['l_0'] = array( 'name' => 'City' );
+$entries['c_0'] = array( 'name' => 'Country' );
+$entries['telephoneNumber_0'] = array( 'name' => 'Telephone Number' );
+$entries['facsimileTelephoneNumber_0'] = array( 'name' => 'Fax Number' );
+$entries['visible'] = array( 'name' => 'Addressbook',
+ 'type' => 'checkbox',
+ 'value' => true,
+ 'comment' => 'check here to make this users address <br> visible in the address book');
+$entries['action'] = array( 'name' => 'action',
+ 'type' => 'hidden' );
+
+if( $dn ) {
+ $ldap_object = $ldap->read( $dn );
+ if( $ldap_object ) {
+ //$ldap_object = from_utf8($ldap_object);
+ //$ldap_object = fill_up2($ldap_object);
+ //ldap_free_result($result);
+ } else {
+ print 'No such entry '.$dn.'!';
+ }
}
-foreach ($attributes as $attr) {
- if (noshow($attr)) continue;
- if (!empty($ldap_object[$attr])) {
- if (is_array($ldap_object[$attr])) $value = $ldap_object[$attr];
- else $value = array(0 => $ldap_object[$attr], 'count' => 1);
- } else $value = array( 0 => "", 'count' => 1);
- for ($count=0; $count<$value['count']; $count++) {
- $battr = dobeautify($attr);
- print "<tr><td> $battr </td><td>\n";
- if ($action != "delete") {
- if (!black($attr)) {
- print "<input type=\"text\" name=\"".$attr."_".$count."\" size=$width maxlength=80 value=\"".$value[$count]."\">\n";
- } else {
- if ($value[$count]) print "$value[$count]";
- else print "(not set)";
- }
- print "</td><td>".(comment($attr."_".$count))."</td></tr>\n";
- } else print($value[$count]." </td></tr>\n");
- $count++;
+$form =& new KolabForm( "user", $entries );
+debug("Action is $action");
+
+/***************** Main action swicth **********************/
+switch( $action ) {
+ case 'firstsave':
+ case 'save':
+ if( $form->isSubmitted() ) {
+ if( !$form->validate() ) {
+ $form->setValues();
+ $form->outputForm();
+ } else {
+ debug("Process...");
+ $ldap_object = array();
+ $ldap_object['objectClass'] = 'inetOrgPerson';
+ $ldap_object['sn'] = trim($_POST['lastname']);
+ $ldap_object['cn'] = trim($_POST['firstname']).' '.$ldap_object['sn'];
+ if( !empty( $_POST['password_0'] ) ) {
+ $ldap_object['userPassword'] = '{sha}'.base64_encode( pack('H*',
+ sha1( $_POST['password_0'])));
+ }
+ $ldap_object['mail'] = trim( strtolower( $_POST['mail_0'] ) );
+ if( $action == 'firstsave' ) $ldap_object['uid'] = $ldap_object['mail'];
+ foreach( array( 'title', 'alias', 'o', 'ou', 'roomNumber', 'street', 'postOfficeBox',
+ 'postalCode', 'l', 'c', 'telephoneNumber',
+ 'facsimileTelephoneNumber' ) as $attr ) {
+ $count = 0;
+ $key = $attr."_0";
+ $args = array();
+ while (!empty($_POST[$key])) {
+ $args[$count] = trim($_POST[$key]);
+ $count++;
+ $key = $attr."_".$count;
+ }
+ if ($count > 0) $ldap_object[$attr] = $args;
+ elseif (!empty($_POST[$key])) $ldap_object[$attr] = $_POST[$key];
+ }
+ if ($group == "maintainer" || $group == "admin") {
+ if (!empty($_POST['visible']) && $_POST['visible'] == "on")
+ $visible = true;
+ else $visible = false;
+ }
+ if (!$visible) $dn_add = ",cn=internal";
+ else $dn_add = "";
+ $domain_dn = domain_dn();
+
+ if ($action == "save") {
+ if (!$errors) {
+ if (!empty($ldap_object['cn'])) $newdn = "cn=".$ldap_object['cn'].",".$domain_dn;
+ else $newdn = $dn;
+ if (!$visible && !strstr($newdn,$dn_add)) {
+ list($cn,$rest) = split(',', $newdn, 2);
+ $newdn = $cn.$dn_add.",".$rest;
+ }
+ if (strcmp($dn,$newdn) != 0) {
+ if (($result=ldap_read($link,$dn,"(objectclass=*)")) &&
+ ($entry=ldap_first_entry($link,$result)) &&
+ ($oldattrs=ldap_get_attributes($link,$entry))) {
+ $ldap_object['uid'] = $oldattrs['uid'][0];
+ $ldap_object['mail'] = $oldattrs['mail'][0];
+ if (!ldap_add($link,$newdn, $ldap_object) )
+ array_push($errors, "LDAP Error: could not rename $dn to $newdn ".ldap_error($link));
+ if( !$errors ) {
+ if( !ldap_delete($link,$dn)) {
+ array_push($errors, "LDAP Error: could not remove old entry $dn: ".ldap_error($link));
+ }
+ }
+ $dn = $newdn;
+ } else array_push($errors,"LDAP Error: could not read $dn ".ldap_error($link));
+ } else {
+ //$ldap_object = fill_up($ldap_object);
+ if ($group == "user") {
+ unset($ldap_object['sn']);
+ unset($ldap_object['cn']);
+ }
+ if (!ldap_modify($link, $dn, $ldap_object)) {
+ array_push($errors, "LDAP Error: could not modify object $dn ".ldap_error($link));
+ }
+ }
+ }
+ print("<div class=\"maintitle\"> Modify User </div>\n");
+ $form->setValues();
+ $form->entries['action']['value'] = 'save';
+ $form->outputForm();
+ } else {
+ // firstsave
+ if (!$errors) {
+ $dn = "cn=".$ldap_object['cn'].$dn_add.",".$domain_dn;
+ debug("Calling ldap_add with dn=$dn");
+ var_dump( $ldap_object );
+ if ($dn && !ldap_add($link, $dn, $ldap_object))
+ array_push($errors, "LDAP Error: could not add object $dn ".ldap_error($link));
+ } else {
+ print("<div class=\"maintitle\"> Create New User </div>\n");
+ $blacklist = array('mail');
+ $action = "create";
+ $form->outputForm();
+ break;
+ }
+ }
+ }
+ break;
}
-}
-if ($action != "delete") {
- if ($group == "admin" || $group == "maintainer") {
- print("<tr><td>Addressbook</td><td><input type=\"checkbox\" name=\"visible\" value=\"true\" ");
- if ($visible) print("checked");
- print("></td>\n");
- print "<td>".(comment('visible'))."</td></tr>\n";
+ case 'create':
+ print '<div class="maintitle">Create new user</div>';
+ if( !$dn ) {
+ $form->entries['action']['value'] = 'firstsave';
+ } else {
+ $form->entries['action']['value'] = 'save';
}
+ $form->outputForm();
+ break;
+ case 'modify':
+ print '<div class="maintitle">Modify user</div>';
+ fill_form_for_modify( $form, $ldap_object );
+ $form->entries['action']['value'] = 'save';
+ $form->outputForm();
+ break;
+ case 'delete':
+ print '<div class="maintitle">Delete user</div>';
+ foreach( $form->entries as $k => $v ) {
+ if( $v['type'] != 'hidden' ) {
+ $form->entries[$k]['attrs'] = 'readonly';
+ }
+ }
+ fill_form_for_modify( $form, $ldap_object );
+ $form->entries['action']['value'] = 'kill';
+ $form->submittext = 'Delete';
+ $form->outputForm();
+ break;
+ case 'kill':
+ if (!$dn) array_push($errors, "Error: need dn for delete operation");
+ elseif ($group != "maintainer" && $group != "admin")
+ array_push($errors, "Error: you need administrative permissions to delete users");
+
+ if (!$errors) {
+ print("<div class=\"maintitle\"> Delete User </div>\n");
+ $delete_template['deleteflag'] = 'TRUE';
+ if (!(ldap_modify($link,$dn,$delete_template))) {
+ array_push($errors, "LDAP Error: could not mark ".$dn." for deletion ".ldap_error($link));
+ } else {
+ print("<div class=\"message\"> The object ".$dn." has been deleted </div>\n");
+ }
+ }
+ break;
}
-print "</table>\n";
-
-print "<table class=\"button\">\n";
-print "<tr><td><input type=\"image\" src=\"../pics/button_ok.png\" name=\"apply\" value=\"Apply\"></td>\n";
-if ($group == "user") {
- print "<td><a href=\"..\"> <img src=\"../pics/button_cancel.png\" alt=\"cancel\"></a></td></tr>\n";
-} else {
- print "<td><a href=\"index.php\"> <img src=\"../pics/button_cancel.png\" alt=\"cancel\"></a></td></tr>\n";
-}
-print "</td></tr>\n";
-
-} // if $action != delete
-print("</table></div>\n");
if ($errors) {
print("<TABLE style=\"errors\">\n");
Index: forward.php
===================================================================
RCS file: /kolabrepository/server/kolab/kolab/admin/user/forward.php,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- forward.php 3 Jul 2003 10:07:57 -0000 1.8
+++ forward.php 16 Apr 2004 10:17:28 -0000 1.9
@@ -5,13 +5,12 @@
This program is Free Software under the GNU General Public License (>=v2).
Read the file COPYING that comes with this packages for details.
*/
- include("head.php");
- This("user/forward");
- Head();
+require_once('../include/authenticate.php');
+include("head.php");
+This("user/forward");
+Head();
?>
-
<div class="maintitle">My Forward Settings</div>
-
<?
include("../include/sieve-php.lib");
@@ -20,14 +19,12 @@
$errors = array();
-// check user authentication
-if (!($uid = $_SERVER["PHP_AUTH_USER"]) ||
- !($bind_dn = uid2dn($uid)) ||
- !($group = uid2group($uid)))
- array_push($errors, "Internal Error: could not get UID Authentication Information");
-
-if (!($passwd = $_SERVER["PHP_AUTH_PW"]))
- array_push($errors, "Internal Error: could not get Password Authentication Information");
+// user authentication
+$uid = $auth->uid();
+$passwd = $auth->password();
+$bind_dn = $auth->dn();
+$group = $auth->group();
+$link = $ldap->connection;
if (!$errors && $group != "user" )
array_push($errors, "Error: You don't have Permissions to access this Menue");
Index: head.php
===================================================================
RCS file: /kolabrepository/server/kolab/kolab/admin/user/head.php,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- head.php 14 Jun 2003 17:06:31 -0000 1.8
+++ head.php 16 Apr 2004 10:17:28 -0000 1.9
@@ -5,12 +5,12 @@
This program is Free Software under the GNU General Public License (>=v2).
Read the file COPYING that comes with this packages for details.
*/
- include("../include/myfunctions.php");
- include("../include/headfoot.php");
-
- $uid=$_SERVER['PHP_AUTH_USER'];
- $group_id = uid2group($uid);
- $_pid = 1;
+require_once("../include/myfunctions.php");
+require_once("../include/headfoot.php");
+
+$uid=$auth->uid();
+$group_id = $auth->group();
+$_pid = 1;
Function idxExtend() {
global $group_id;
Index: index.php
===================================================================
RCS file: /kolabrepository/server/kolab/kolab/admin/user/index.php,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- index.php 18 Jun 2003 19:02:35 -0000 1.15
+++ index.php 16 Apr 2004 10:17:28 -0000 1.16
@@ -5,21 +5,24 @@
This program is Free Software under the GNU General Public License (>=v2).
Read the file COPYING that comes with this packages for details.
*/
- include("head.php");
- This("user/");
- Head();
-
-$utf8 = array ( 'cn', 'sn' );
+require_once('../include/authenticate.php');
+include("head.php");
+This("user/");
+Head();
$errors = array();
-// check user authentication
-if (!($uid = $_SERVER["PHP_AUTH_USER"]) ||
- !($bind_dn = uid2dn($uid)) ||
- !($group = uid2group($uid)))
- array_push($errors, "Internal Error: could not get Authentication Information");
+function debug( $str ) {
+ print "DEBUG: $str";
+}
-if (!$errors && $group != "maintainer" && $group != "admin")
+// user authentication
+$uid = $auth->uid();
+$bind_dn = $auth->dn();
+$group = $auth->group();
+$link = $ldap->connection;
+
+if ( $group != 'maintainer' && $group != 'admin')
array_push($errors, "Error: You don't have Permissions to access this Menue");
// read selector for register display
@@ -33,14 +36,6 @@
$myself = $_SERVER['PHP_SELF'];
-if (isset($_SESSION['ldap_server'])) $ldap_server = $_SESSION['ldap_server'];
- else $ldap_server = '127.0.0.1';
-
-if (isset($_SESSION['ldap_port'])) $ldap_port = $_SESSION['ldap_port'];
- else $ldap_port = 389;
-
-if (!$errors && !($link = ldap_connect($ldap_server,$ldap_port)) || !ldap_bind($link,$bind_dn,$_SERVER["PHP_AUTH_PW"]))
- array_push($errors, "Communication Error: could not query ldap://$ldap_server:$ldap_port ".ldap_error($link));
// get all entries & dynamically split the letters with growing entries
$filter = "(&(cn=*)(objectclass=inetOrgPerson)(uid=*)(mail=*)(sn=*))";
@@ -63,15 +58,12 @@
case "[".chr($i)."]":
$filter = "(&(cn=*)(objectclass=inetOrgPerson)(uid=*)(mail=*)(|(sn=".chr($i)." *)(sn=".chr($i+32)."*)";
if ($i == 65) {
- if (in_array('sn', $utf8)) $filter = $filter."(sn=".utf8_encode("Ä")."
-*)(sn=".utf8_encode("ä")."*)"; }
+ $filter = $filter."(sn=".utf8_encode("Ä")."*)(sn=".utf8_encode("ä")."*)"; }
if ($i == 79) {
- if (in_array('sn', $utf8)) $filter = $filter."(sn=".utf8_encode("Ö")."
-*)(sn=".utf8_encode("ö")."*)";
+ $filter = $filter."(sn=".utf8_encode("Ö")."*)(sn=".utf8_encode("ö")."*)";
}
if ($i == 85) {
- if (in_array('sn', $utf8)) $filter = $filter."(sn=".utf8_encode("Ü")."
-*)(sn=".utf8_encode("ü")."*)";
+ $filter = $filter."(sn=".utf8_encode("Ü")."*)(sn=".utf8_encode("ü")."*)";
}
$filter = $filter."))";
break;
@@ -99,7 +91,7 @@
case "[A-F]":
$filter = "(&(cn=*)(objectclass=inetOrgPerson)(uid=*)(mail=*)(|(sn=F*)(sn=E*)(sn=D*)(sn=C*)(sn=B*)(sn=A*)";
$filter = $filter."(sn=f*)(sn=e*)(sn=d*)(sn=c*)(sn=b*)(sn=a*)";
- if (in_array('sn', $utf8)) $filter = $filter."(sn=".utf8_encode("Ä")."*)(sn=".utf8_encode("ä")."*)";
+ $filter = $filter."(sn=".utf8_encode("Ä")."*)(sn=".utf8_encode("ä")."*)";
$filter = $filter."))";
break;
case "[G-L]":
@@ -109,7 +101,7 @@
case "[M-S]":
$filter = "(&(cn=*)(objectclass=inetOrgPerson)(uid=*)(mail=*)(|(sn=M*)(sn=N*)(sn=O*)(sn=P*)(sn=Q*)(sn=R*)(sn=S*)";
$filter = $filter."(sn=m*)(sn=n*)(sn=o*)(sn=p*)(sn=q*)(sn=r*)(sn=s*)";
- if (in_array('sn', $utf8)) $filter = $filter."(sn=".utf8_encode("Ö")."*)(sn=".utf8_encode("ö")."*)"."(sn=".utf8_encode("Ü")."*)(sn=".utf8_encode("ü")."*)";
+ $filter = $filter."(sn=".utf8_encode("Ö")."*)(sn=".utf8_encode("ö")."*)"."(sn=".utf8_encode("Ü")."*)(sn=".utf8_encode("ü")."*)";
$filter = $filter."))";
break;
case "[T-Z]":
@@ -170,13 +162,11 @@
$userid = $attrs['uid'][0];
$mail = $attrs['mail'][0];
$sn = $attrs['sn'][0];
- if (in_array('sn', $utf8)) $sn = utf8_decode($sn);
$cn = $attrs['cn'][0];
- if (in_array('cn', $utf8)) $cn = utf8_decode($cn);
$a = strlen($sn);
$b = strlen($cn);
$fn = substr($cn, 0, $b - $a);
- $gid = uid2group($userid);
+ $gid = $ldap->groupForUid($userid);
if ($gid == "user") {
$userid = urlencode($userid);
$dn = urlencode($dn);
Index: vacation.php
===================================================================
RCS file: /kolabrepository/server/kolab/kolab/admin/user/vacation.php,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- vacation.php 14 Jun 2003 17:06:31 -0000 1.9
+++ vacation.php 16 Apr 2004 10:17:28 -0000 1.10
@@ -5,13 +5,12 @@
This program is Free Software under the GNU General Public License (>=v2).
Read the file COPYING that comes with this packages for details.
*/
- include("head.php");
- This("user/vacation");
- Head();
+require_once('../include/authenticate.php');
+include("head.php");
+This("user/vacation");
+Head();
?>
-
-+<div class="maintitle">User Vacation Settings</div>
-
+<div class="maintitle">User Vacation Settings</div>
<?
include("../include/sieve-php.lib");
@@ -19,15 +18,13 @@
$errors = array();
-// check user authentication
-if (!($uid = $_SERVER["PHP_AUTH_USER"]) ||
- !($bind_dn = uid2dn($uid)) ||
- !($group = uid2group($uid)))
- array_push($errors, "Internal Error: could not get UID Authentication Information");
+// user authentication
+$uid = $auth->uid();
+$passwd = $auth->password();
+$bind_dn = $auth->dn();
+$group = $auth->group();
+$link = $ldap->connection;
-if (!($passwd = $_SERVER["PHP_AUTH_PW"]))
- array_push($errors, "Internal Error: could not get Password Authentication Information");
-
if (!$errors && $group != "user" )
array_push($errors, "Error: You don't have Permissions to access this Menue");
@@ -37,30 +34,30 @@
// read selector for register display
if (isset($HTTP_GET_VARS['action'])) $action = $HTTP_GET_VARS['action'];
- else $action = "start";
+else $action = "start";
if (isset($HTTP_GET_VARS['day'])) $day = $HTTP_GET_VARS['day'];
- else $day = 1;
+else $day = 1;
if (isset($HTTP_GET_VARS['month'])) $month = $HTTP_GET_VARS['month'];
- else $month = 1;
+else $month = 1;
if (isset($HTTP_GET_VARS['year'])) $year = $HTTP_GET_VARS['year'];
- else $year = 2002;
+else $year = 2002;
if (isset($HTTP_GET_VARS['vacnotify'])) $vacnotify = $HTTP_GET_VARS['vacnotify'];
- else $vacnotify = 7;
+else $vacnotify = 7;
if (isset($HTTP_GET_VARS['vacmsg'])) $vacmsg = $HTTP_GET_VARS['vacmsg'];
- else $vacmsg = "";
+else $vacmsg = "";
$myself = $_SERVER['PHP_SELF'];
if (isset($_SESSION['sieve_server'])) $sieve_server = $_SESSION['sieve_server'];
- else $sieve_server = '127.0.0.1';
+else $sieve_server = '127.0.0.1';
if (isset($_SESSION['sieve_port'])) $sieve_port = $_SESSION['sieve_port'];
- else $sieve_port = 2000;
+else $sieve_port = 2000;
$sieve=new sieve($sieve_server, $sieve_port, $uid, $passwd, $uid);
@@ -143,8 +140,8 @@
case "delete":
if ($sieveactive == TRUE) {
delete_script ($scriptname);
- print "<div class=\"message\">Vacation notification or email forwarding setting successfully deleteted</div>\n";
- else {
+ print "<div class=\"message\">Vacation notification or email forwarding setting successfully deleteted</div>\n";
+ } else {
print "<div class=\"message\">No vacation or forward directive on server found to be deleted!</div>\n";
}
print "<table class=\"contentform\"><form action=\"$myself\" method=\"GET\">\n";
- Previous message: steffen: server/kolab/kolab/admin/statistics index.php, 1.5, 1.6 kolab.php, 1.4, 1.5 load.php, 1.4, 1.5 mta.php, 1.4, 1.5
- Next message: steffen: server/perl-kolab/Kolab-Conf Conf.pm,1.2,1.3
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the commits
mailing list