X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=plugins%2Fpersonal%2Fgeneric%2Fclass_user.inc;h=46ecbc77d434db966131cb7fe6910dbc588d2228;hb=7697f34f9e7b22c3c38d429278e667f46a087f2b;hp=9f216a9575fa82dec047d274cdf18a5de813796d;hpb=99dd9b32f5d3d2eaebf909053834eae7c1a56cc8;p=gosa.git
diff --git a/plugins/personal/generic/class_user.inc b/plugins/personal/generic/class_user.inc
index 9f216a957..46ecbc77d 100644
--- a/plugins/personal/generic/class_user.inc
+++ b/plugins/personal/generic/class_user.inc
@@ -42,9 +42,10 @@ class user extends plugin
var $l= "";
var $st= "";
var $postalAddress= "";
- var $dob= "0";
+ var $dateOfBirth;
var $use_dob= "0";
- var $gender= "0";
+ var $gender="0";
+ var $preferredLanguage="0";
var $jpegPhoto= "*removed*";
var $photoData= "";
@@ -75,6 +76,8 @@ class user extends plugin
var $role= "";
var $publicVisible= "";
+ var $dialog;
+
/* variables to trigger password changes */
var $pw_storage= "crypt";
var $last_pw_storage= "unset";
@@ -82,8 +85,8 @@ class user extends plugin
/* attribute list for save action */
var $attributes= array("sn", "givenName", "uid", "personalTitle", "academicTitle",
- "homePostalAddress", "homePhone", "labeledURI", "o", "ou", "dob", "gender",
- "departmentNumber", "employeeNumber", "employeeType", "l", "st",
+ "homePostalAddress", "homePhone", "labeledURI", "o", "ou", "dateOfBirth", "gender","preferredLanguage",
+ "departmentNumber", "employeeNumber", "employeeType", "l", "st","jpegPhoto",
"roomNumber", "telephoneNumber", "mobile", "pager", "cn", "userPKCS12",
"postalAddress", "facsimileTelephoneNumber", "userSMIMECertificate");
@@ -102,27 +105,30 @@ class user extends plugin
'dn' from LDAP */
function user ($config, $dn= NULL)
{
- /* Configuration is fine, allways */
$this->config= $config;
+ /* Configuration is fine, allways */
+ if ($this->config->current['GOVERNMENTMODE']){
+ $this->attributes=array_merge($this->attributes,$this->govattrs);
+ }
/* Load base attributes */
plugin::plugin ($config, $dn);
- /* Load government mode attributes */
if ($this->config->current['GOVERNMENTMODE']){
+ /* Fix public visible attribute if unset */
+ if (!isset($this->attrs['publicVisible'])){
+ $this->publicVisible == "nein";
+ }
+ }
+ /* Load government mode attributes */
+ if ($this->config->current['GOVERNMENTMODE']){
/* Copy all attributs */
foreach ($this->govattrs as $val){
if (isset($this->attrs["$val"][0])){
$this->$val= $this->attrs["$val"][0];
}
}
-
- /* Fix public visible attribute if unset */
- if (!isset($this->attrs['publicVisible'])){
- $this->publicVisible == "nein";
- }
-
}
/* Create me for new accounts */
@@ -181,12 +187,12 @@ class user extends plugin
$this->last_pw_storage= $this->pw_storage;
}
- /* Generate dob entry */
+ /* Generate dateOfBirth entry */
if (isset ($this->attrs['dateOfBirth'])){
/* This entry is ISO 8601 conform */
list($year, $month, $day)= split("-", $this->attrs['dateOfBirth'][0], 3);
- $this->dob=array( 'mon'=> $month,"mday"=> $day,"year"=> $year);
+ $this->dateOfBirth=array( 'mon'=> $month,"mday"=> $day,"year"=> $year);
$this->use_dob= "1";
} else {
$this->use_dob= "0";
@@ -195,23 +201,26 @@ class user extends plugin
/* Put gender attribute to upper case */
if (isset ($this->attrs['gender'])){
$this->gender= strtoupper($this->attrs['gender'][0]);
- }
+ }
}
/* execute generates the html output for this node */
function execute()
{
+ /* Call parent execute */
+ plugin::execute();
+
$smarty= get_smarty();
/* Fill calendar */
- if ($this->dob == "0"){
+ if ($this->dateOfBirth == "0"){
$date= getdate();
} else {
- if(is_array($this->dob)){
- $date = $this->dob;
+ if(is_array($this->dateOfBirth)){
+ $date = $this->dateOfBirth;
}else{
- $date = getdate($this->dob);
+ $date = getdate($this->dateOfBirth);
}
}
@@ -247,6 +256,12 @@ class user extends plugin
$sex= array(0 => " ", "F" => _("female"), "M" => _("male"));
$smarty->assign("gender_list", $sex);
+ /* Assign prefered langage */
+ $language= array(0 => " ", "fr_FR" => ("fr_FR"), "en_EN" => ("en_EN"),
+ "de_DE" => ("de_DE"), "it_IT" => ("it_IT"),
+ "nl_NL" => ("nl_NL"), "ru_RU" => ("ru_RU"));
+ $smarty->assign("preferredLanguage_list", $language);
+
/* Get random number for pictures */
srand((double)microtime()*1000000);
$smarty->assign("rand", rand(0, 10000));
@@ -258,6 +273,31 @@ class user extends plugin
return;
}
+ /* Base select dialog */
+ $once = true;
+ foreach($_POST as $name => $value){
+ if(preg_match("/^chooseBase/",$name) && $once){
+ $once = false;
+ $this->dialog = new baseSelectDialog($this->config,$this->allowedBasesToMoveTo());
+ $this->dialog->setCurrentBase($this->base);
+ }
+ }
+
+ /* Dialog handling */
+ if(is_object($this->dialog)){
+ /* Must be called before save_object */
+ $this->dialog->save_object();
+
+ if($this->dialog->isClosed()){
+ $this->dialog = false;
+ }elseif($this->dialog->isSelected()){
+ $this->base = $this->dialog->isSelected();
+ $this->dialog= false;
+ }else{
+ return($this->dialog->execute());
+ }
+ }
+
/* Want picture edit dialog? */
if (isset($_POST['edit_picture'])){
/* Save values for later recovery, in case some presses
@@ -270,8 +310,8 @@ class user extends plugin
/* Remove picture? */
if (isset($_POST['picture_remove'])){
+ $this->set_picture ();
$this->jpegPhoto= "*removed*";
- $this->set_picture ("./images/default.jpg");
$this->is_modified= TRUE;
return($smarty->fetch (get_template_path('generic_picture.tpl', TRUE, dirname(__FILE__))));
@@ -304,12 +344,13 @@ class user extends plugin
$this->photoData= $this->old_photoData;
/* Update picture */
- $_SESSION['picture']= $this->photoData;
+ $_SESSION['binary']= $this->photoData;
+ $_SESSION['binarytype']= "image/jpeg";
$this->picture_dialog= FALSE;
$this->dialog= FALSE;
}
- /* Toggle dob information */
+ /* Toggle dateOfBirth information */
if (isset($_POST['set_dob'])){
$this->use_dob= ($this->use_dob == "0")?"1":"0";
}
@@ -414,8 +455,25 @@ class user extends plugin
/* Read out data*/
$timeto = $certificate->getvalidto_date();
$timefrom = $certificate->getvalidfrom_date();
- $str = "
CN | ".preg_replace("/ /", " ", $certificate->getname())." |
".
- sprintf(_("Certificate is valid from %s to %s and is currently %s."), date('d M Y',$timefrom),date('d M Y',$timeto), $certificate->isvalid()?""._("valid")."":""._("invalid")."");
+
+ /* Additional info if start end time is '0' */
+ $add_str_info = "";
+ if($timeto == 0 && $timefrom == 0){
+ $add_str_info = "
"._("(Some types of certificates are currently not supported and may be displayed as 'invalid'.)")."";
+ }
+
+ $str = "
+
+ CN |
+ ".preg_replace("/ /", " ", $certificate->getname())." |
+
+
".
+
+ sprintf(_("Certificate is valid from %s to %s and is currently %s."),
+ "".date('d M Y',$timefrom)."",
+ "".date('d M Y',$timeto)."",
+ $certificate->isvalid()?""._("valid")."":
+ ""._("invalid")."").$add_str_info;
$smarty->assign($cert."info",$str);
$smarty->assign($cert."_state","true");
} else {
@@ -428,18 +486,19 @@ class user extends plugin
}
/* Show us the edit screen */
- $smarty->assign("bases", $this->config->idepartments);
- $smarty->assign("base_select", $this->base);
- $smarty->assign("selectmode", chkacl($this->acl, "create"));
- $smarty->assign("certificatesACL", chkacl($this->acl, "certificates"));
- $smarty->assign("jpegPhotoACL", chkacl($this->acl, "jpegPhoto"));
+ @$smarty->assign("bases", $this->allowedBasesToMoveTo());
+# $smarty->assign("bases", $this->config->idepartments);
+ $smarty->assign("base_select", $this->base);
+ $smarty->assign("selectmode", chkacl($this->acl, "create"));
+ $smarty->assign("certificatesACL", chkacl($this->acl, "certificates"));
+ $smarty->assign("jpegPhotoACL", chkacl($this->acl, "jpegPhoto"));
/* Prepare password hashes */
if ($this->pw_storage == ""){
$this->pw_storage= $this->config->current['HASH'];
}
- $temp = passwordMethod::get_available_methods();
+ $temp = @passwordMethod::get_available_methods();
$hashes = $temp['name'];
$smarty->assign("pwmode", $hashes);
@@ -490,9 +549,8 @@ class user extends plugin
$smarty->assign("has_phoneaccount", "false");
}
} else {
- $smarty->assign("has_phoneaccount", "false");
+ $smarty->assign("has_phoneaccount", "false");
}
-
return($smarty->fetch (get_template_path('generic.tpl', TRUE, dirname(__FILE__))));
}
@@ -502,6 +560,7 @@ class user extends plugin
{
$ldap= $this->config->get_ldap_link();
$ldap->rmdir ($this->dn);
+ show_ldap_error($ldap->get_error(), _("Removing generic user account failed"));
/* Delete references to groups */
$ldap->cd ($this->config->current['BASE']);
@@ -521,8 +580,43 @@ class user extends plugin
$og->save ();
}
+ /* Kerberos server defined? */
+ if (isset($this->config->data['SERVERS']['KERBEROS'])){
+ $cfg= $this->config->data['SERVERS']['KERBEROS'];
+ }
+ if (isset($cfg['SERVER']) && function_exists('kadm5_init_with_password')){
+
+ /* Connect to the admin interface */
+ $handle = kadm5_init_with_password($cfg['SERVER'], $cfg['REALM'],
+ $cfg['ADMIN'], $cfg['PASSWORD']);
+
+ /* Errors? */
+ if ($handle === FALSE){
+ print_red (_("Kerberos database communication failed"));
+ return (2);
+ }
+
+ /* Build user principal, get list of existsing principals */
+ $principal= $this->uid."@".$cfg['REALM'];
+ $principals = kadm5_get_principals($handle);
+
+ /* User exists in database? */
+ if (in_array($principal, $principals)){
+
+ /* Ok. User exists. Remove him/her */
+ $ret= kadm5_delete_principal ( $handle, $principal);
+ if ($ret === FALSE){
+ print_red (_("Can't remove user from kerberos database."));
+ }
+ }
+
+ /* Free kerberos admin handle */
+ kadm5_destroy($handle);
+ }
+
+
/* Optionally execute a command after we're done */
- $this->handle_post_events("remove");
+ $this->handle_post_events("remove",array("uid" => $this->uid));
}
@@ -556,11 +650,13 @@ class user extends plugin
/* Save base and pw_storage, since these are no LDAP attributes */
if (isset($_POST['base'])){
foreach(array("base", "pw_storage") as $val){
- $data= validate($_POST[$val]);
- if ($data != $this->$val){
- $this->is_modified= TRUE;
+ if(isset($_POST[$val])){
+ $data= validate($_POST[$val]);
+ if ($data != $this->$val){
+ $this->is_modified= TRUE;
+ }
+ $this->$val= $data;
}
- $this->$val= $data;
}
}
}
@@ -583,14 +679,27 @@ class user extends plugin
/* Save data to LDAP, depending on is_account we save or delete */
function save()
{
+ /* Only force save of changes ....
+ If this attributes aren't changed, avoid saving.
+ */
+ if($this->gender=="0") $this->gender ="";
+ if($this->preferredLanguage=="0") $this->preferredLanguage ="";
+
+
/* First use parents methods to do some basic fillup in $this->attrs */
plugin::save ();
+ if ($this->use_dob == "1"){
+ /* If it is an array, the generic page has never been loaded - so there's no difference. Using an array would cause an error btw. */
+ if(!is_array($this->attrs['dateOfBirth'])) {
+ $this->attrs['dateOfBirth']= date("Y-m-d", $this->attrs['dateOfBirth']);
+ }
+ }
/* Remove additional objectClasses */
$tmp= array();
foreach ($this->attrs['objectClass'] as $key => $set){
$found= false;
- foreach (array("ivbbEntry", "gosaUserTemplate") as $val){
+ foreach (array("ivbbentry", "gosaUserTemplate") as $val){
if (preg_match ("/^$set$/i", $val)){
$found= true;
break;
@@ -612,7 +721,7 @@ class user extends plugin
/* Hard coded government mode? */
if ($this->config->current['GOVERNMENTMODE'] != 'false'){
- $this->attrs['objectClass'][]= "ivbbEntry";
+ $this->attrs['objectClass'][]= "ivbbentry";
/* Copy standard attributes */
foreach ($this->govattrs as $val){
@@ -644,23 +753,28 @@ class user extends plugin
$remove_userCertificate= true;
}
- /* Special handling for dob value */
- if ($this->use_dob == "1"){
- $this->attrs["dob"]= date("Y-m-d", $this->dob);
- } else {
+ /* Special handling for dateOfBirth value */
+ if ($this->use_dob != "1"){
if ($this->new) {
- unset($this->attrs["dob"]);
+ unset($this->attrs["dateOfBirth"]);
} else {
- $this->attrs["dob"]= array();
+ $this->attrs["dateOfBirth"]= array();
}
}
- if ($this->gender == "0"){
+ if (!$this->gender){
if ($this->new) {
unset($this->attrs["gender"]);
} else {
$this->attrs["gender"]= array();
}
}
+ if (!$this->preferredLanguage){
+ if ($this->new) {
+ unset($this->attrs["preferredLanguage"]);
+ } else {
+ $this->attrs["preferredLanguage"]= array();
+ }
+ }
/* Special handling for attribute jpegPhote needed, scale image via
image magick to 147x200 pixels and inject resulting data. */
@@ -726,7 +840,7 @@ class user extends plugin
$this->attrs["jpegPhoto"] = $output;
}
- } elseif(!$this->new) {
+ } else{
$this->attrs["jpegPhoto"] = array();
}
@@ -752,7 +866,7 @@ class user extends plugin
/* Save data. Using 'modify' implies that the entry is already present, use 'add' for
new entries. So do a check first... */
- $ldap->cat ($this->dn);
+ $ldap->cat ($this->dn, array('dn'));
if ($ldap->fetch()){
$mode= "modify";
} else {
@@ -770,9 +884,10 @@ class user extends plugin
$this->attributes, "Save via $mode");
/* Finally write data with selected 'mode' */
+ $this->cleanup();
$ldap->cd ($this->dn);
$ldap->$mode ($this->attrs);
- if (show_ldap_error($ldap->get_error())){
+ if (show_ldap_error($ldap->get_error(), _("Saving generic user account failed"))){
return (1);
}
@@ -832,7 +947,7 @@ class user extends plugin
/* Ok. User exists. Remove him/her when pw_storage has
changed to be NOT kerberos. */
- if ($this->pw_storage != "kerberos"){
+ if ($this->pw_storage != $this->config->current['KRBSASL']){
$ret= kadm5_delete_principal ( $handle, $principal);
if ($ret === FALSE){
@@ -842,8 +957,8 @@ class user extends plugin
} else {
- /* User doesn't exists, create it when pw_storage is kerberos. */
- if ($this->pw_storage == "kerberos"){
+ /* User doesn't exists, create it when pw_storage is kerberos or SASL. */
+ if ($this->pw_storage == "kerberos" || $this->pw_storage == "sasl" ){
$ret= kadm5_create_principal ( $handle, $principal);
if ($ret === FALSE){
@@ -859,11 +974,14 @@ class user extends plugin
/* Optionally execute a command after we're done */
if ($mode == "add"){
- $this->handle_post_events("add");
+ $this->handle_post_events("add",array("uid" => $this->uid));
} elseif ($this->is_modified){
- $this->handle_post_events("modify");
+ $this->handle_post_events("modify",array("uid" => $this->uid));
}
+ /* Fix tagging if needed */
+ $this->handle_object_tagging();
+
return (0);
}
@@ -871,10 +989,16 @@ class user extends plugin
/* Check formular input */
function check()
{
- $message= array();
+ /* Call common method to give check the hook */
+ $message= plugin::check();
/* Assemble cn */
- $this->cn= $this->givenName." ".$this->sn;
+ if ($this->personalTitle == ""){
+ $pt= "";
+ } else {
+ $pt= $this->personalTitle." ";
+ }
+ $this->cn= $pt.$this->givenName." ".$this->sn;
/* Permissions for that base? */
if (isset($this->config->current['DNMODE']) && $this->config->current['DNMODE'] == "uid"){
@@ -943,9 +1067,6 @@ class user extends plugin
}
/* Check phone numbers */
- if (!is_phone_nr($this->homePhone)){
- $message[]= _("The field 'Phone' contains an invalid phone number.");
- }
if (!is_phone_nr($this->telephoneNumber)){
$message[]= _("The field 'Phone' contains an invalid phone number.");
}
@@ -960,12 +1081,12 @@ class user extends plugin
}
/* Check for reserved characers */
- if (preg_match ('/[,+"?\'()-=<>;]/', $this->givenName)){
+ if (preg_match ('/[,+"?\'()=<>;]/', $this->givenName)){
$message[]= _("The field 'Given name' contains invalid characters.");
- }
- if (preg_match ('/[,+"?\'()-=<>;]/', $this->sn)){
- $message[]= _("The field 'Name' contains invalid characters.");
- }
+ }
+ if (preg_match ('/[,+"?\'()=<>;]/', $this->sn)){
+ $message[]= _("The field 'Name' contains invalid characters.");
+ }
return $message;
}
@@ -1008,7 +1129,8 @@ class user extends plugin
if ($ei) {
if ($info = ldap_get_values_len($ds, $ei, "jpegPhoto")){
$this->photoData= $info[0];
- $_SESSION['picture']= $this->photoData;
+ $_SESSION['binary']= $this->photoData;
+ $_SESSION['binarytype']= "image/jpeg";
$this->jpegPhoto= "";
}
}
@@ -1056,16 +1178,17 @@ class user extends plugin
/* Load picture from file to object */
- function set_picture($filename)
+ function set_picture($filename ="")
{
- if (!is_file($filename)){
+ if (!is_file($filename) || $filename == ""){
$filename= "./images/default.jpg";
$this->jpegPhoto= "*removed*";
}
$fd = fopen ($filename, "rb");
$this->photoData= fread ($fd, filesize ($filename));
- $_SESSION['picture']= $this->photoData;
+ $_SESSION['binary']= $this->photoData;
+ $_SESSION['binarytype']= "image/jpeg";
$this->jpegPhoto= "";
fclose ($fd);
@@ -1123,6 +1246,121 @@ class user extends plugin
}
}
+
+ /* This avoids that users move themselves out of their rights.
+ */
+ function allowedBasesToMoveTo()
+ {
+ $allowed = array();
+ $ret_all = false;
+ if($this->uid == $_SESSION['ui']->username){
+ $ldap= $this->config->get_ldap_link();
+ $ldap->cd($this->config->current['BASE']);
+ $ldap->search("(&(objectClass=posixGroup)(memberUid=".$_SESSION['ui']->username."))",array("gosaSubtreeACL"));
+
+ while($attrs = $ldap->fetch()){
+
+ if(isset($attrs['gosaSubtreeACL'])){
+
+ foreach($attrs['gosaSubtreeACL'] as $attr){
+ if((preg_match("/:user#/",$attr))||(preg_match("/:all/",$attr))){
+ $s = preg_replace("/^.*".get_groups_ou().",/","",$attrs['dn']);
+
+ foreach($this->config->idepartments as $key => $dep) {
+ if(preg_match("/".$s."/i",$key)){
+ $allowed[$key] = $dep;
+ }
+ }
+ }
+ }
+ }
+ }
+ if(count($allowed) == 0){
+ foreach($this->config->idepartments as $key => $dep) {
+ if($this->base==$key){
+ $allowed[$key] = $dep;
+ }
+ }
+ }
+
+ return($allowed);
+
+ }else{
+ return($this->config->idepartments);
+ }
+ }
+
+
+ function getCopyDialog()
+ {
+ $str = "";
+
+ $_SESSION['binary'] = $this->photoData;
+ $_SESSION['binarytype']= "image/jpeg";
+
+ /* Get random number for pictures */
+ srand((double)microtime()*1000000);
+ $rand = rand(0, 10000);
+
+ $smarty = get_smarty();
+
+ $smarty->assign("passwordTodo","clear");
+
+ if(isset($_POST['passwordTodo'])){
+ $smarty->assign("passwordTodo",$_POST['passwordTodo']);
+ }
+
+ $smarty->assign("sn", $this->sn);
+ $smarty->assign("givenName",$this->givenName);
+ $smarty->assign("uid", $this->uid);
+ $smarty->assign("rand", $rand);
+ $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
+
+
+ $ret = array();
+ $ret['string'] = $str;
+ $ret['status'] = "";
+ return($ret);
+ }
+
+ function saveCopyDialog()
+ {
+
+ if((isset($_FILES['picture_file']['tmp_name'])) && ($_FILES['picture_file']['size'] > 0)){
+ $this->set_picture($_FILES['picture_file']['tmp_name']);
+ }
+
+ /* Remove picture? */
+ if (isset($_POST['picture_remove'])){
+ $this->jpegPhoto= "*removed*";
+ $this->set_picture ("./images/default.jpg");
+ $this->is_modified= TRUE;
+ }
+
+ $attrs = array("uid","givenName","sn");
+ foreach($attrs as $attr){
+ if(isset($_POST[$attr])){
+ $this->$attr = $_POST[$attr];
+ }
+ }
+ }
+
+
+ function PrepareForCopyPaste($source)
+ {
+ plugin::PrepareForCopyPaste($source);
+
+ /* Reset certificate information addepted from source user
+ to avoid setting the same user certificate for the destination user. */
+ $this->userPKCS12= "";
+ $this->userSMIMECertificate= "";
+ $this->userCertificate= "";
+ $this->certificateSerialNumber= "";
+ $this->old_certificateSerialNumber= "";
+ $this->old_userPKCS12= "";
+ $this->old_userSMIMECertificate= "";
+ $this->old_userCertificate= "";
+ }
}
// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: