X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=plugins%2Fadmin%2Ffai%2Fclass_faiTemplateEntry.inc;h=160047b5dd2efd42b8c1cfaa3f947e1cadae0c1a;hb=e30063fbf3326ed504e4a78919fb86e82b720712;hp=4476c548505e5bede0641538d35952fff0dae1f3;hpb=38028cb0e829bf0dfbb4ff32dc0640eb480125ea;p=gosa.git diff --git a/plugins/admin/fai/class_faiTemplateEntry.inc b/plugins/admin/fai/class_faiTemplateEntry.inc index 4476c5485..160047b5d 100644 --- a/plugins/admin/fai/class_faiTemplateEntry.inc +++ b/plugins/admin/fai/class_faiTemplateEntry.inc @@ -9,17 +9,22 @@ class faiTemplateEntry extends plugin /* attribute list for save action */ var $ignore_account= TRUE; - var $attributes = array("Object_cn","Object_description","Object_FAItemplateFile","Object_FAItemplatePath"); + var $attributes = array("cn","description","FAItemplateFile","FAItemplatePath","FAImode","user","group","binary","FAIowner"); var $objectclasses= array(); var $orig_cn = ""; - var $Object_dn = ""; - var $Object_cn = ""; - var $Object_FAItemplateFile = ""; - var $Object_FAItemplatePath = ""; - var $Object_description = ""; - var $Object_status = "new"; + var $dn = ""; + var $cn = ""; + var $FAItemplateFile = ""; + var $FAItemplatePath = ""; + var $description = ""; + var $status = "new"; + var $FAImode = "0640"; + var $FAIowner = "root.root"; + var $user = "root"; + var $group = "root"; + var $binary = false; function faiTemplateEntry ($config, $dn= NULL,$object=false) { @@ -28,29 +33,76 @@ class faiTemplateEntry extends plugin $this->orig_cn= $object['cn']; $this->dn=$object['dn']; foreach($object as $name=>$value){ - $oname = "Object_".$name; + $oname = $name; $this->$oname=$value; } }else{ - $this->Object_status = "new"; + $this->status = "new"; $this->orig_cn = false; } + $this->user = explode( '.', $this->FAIowner ); + $this->group = $this->user[1]; + $this->user = $this->user[0]; + $_SESSION['binary'] = $this->FAItemplateFile; + $_SESSION['binarytype'] = 'octet-stream'; + $_SESSION['binaryfile'] = basename( $this->FAItemplatePath ); + + $this->FAImode= sprintf("%0.4s", $this->FAImode)." "; } function execute() { /* Fill templating stuff */ $smarty = get_smarty(); + $smarty->assign("rand", rand(0, 10000)); $display = ""; + if(isset($_POST['TmpFileUpload'])){ + if($str=file_get_contents($_FILES['FAItemplateFile']['tmp_name'])){ + $this->FAItemplateFile = $str; + + /* If we don't have a filename set it from upload filename. */ + if( 0 == strlen( $this->FAItemplatePath ) ) + $this->FAItemplatePath = $_FILES['FAItemplateFile']['name']; + } + + } + + $status= _("no file uploaded yet"); + if(strlen($this->FAItemplateFile)){ + $status= sprintf(_("exists in database (size: %s bytes)"),strlen($this->FAItemplateFile)); + } + $smarty->assign("status",$status); + + /* Magic quotes GPC, escapes every ' " \, to solve some security risks + * If we post the escaped strings they will be escaped again + */ foreach($this->attributes as $attrs){ - $smarty->assign($attrs,stripslashes($this->$attrs)); + if(get_magic_quotes_gpc()){ + $smarty->assign($attrs,stripslashes($this->$attrs)); + }else{ + $smarty->assign($attrs,($this->$attrs)); + } } - for($i =1 ; $i <= 100 ; $i++){ - $Object_FAIprioritys[$i]=$i; + /* Assign file modes */ + $tmode= "$this->FAImode "; + foreach (array("s", "u", "g", "o") as $type){ + $current= substr($tmode, 0, 1); + $tmode= preg_replace("/^./", "", $tmode); + $nr= 1; + while ($nr < 5){ + if ($current & $nr){ + $smarty->assign($type.$nr, "checked"); + } else { + $smarty->assign($type.$nr, ""); + } + $nr+= $nr; + } } - $smarty->assign("Object_FAIprioritys",$Object_FAIprioritys); + + $smarty->assign("FAItemplateFile",""); + $display.= $smarty->fetch(get_template_path('faiTemplateEntry.tpl', TRUE)); return($display); } @@ -58,8 +110,17 @@ class faiTemplateEntry extends plugin /* Save data to object */ function save_object() { + if (!isset($_POST['FAItemplatePath'])){ + return; + } if(isset($_POST['SubObjectFormSubmitted'])){ foreach($this->attributes as $attrs){ + if($attrs == "FAItemplateFile") + continue; + if($attrs == "FAIowner") { + $this->$attrs = $_POST["user"] . '.' . $_POST["group"]; + continue; + } if(isset($_POST[$attrs])){ $this->$attrs = $_POST[$attrs]; }else{ @@ -67,33 +128,53 @@ class faiTemplateEntry extends plugin } } } + + /* Save mode */ + $tmode= ""; + foreach (array("s", "u", "g", "o") as $type){ + $nr= 1; + $dest= 0; + while ($nr < 5){ + if (isset($_POST["$type$nr"])){ + $dest+= $nr; + } + $nr+= $nr; + } + $tmode= $tmode.$dest; + } + $this->FAImode= $tmode; } /* Check supplied data */ function check() { $message= array(); - if(empty($this->Object_FAItemplateFile)){ + if(empty($this->FAItemplateFile)){ $message[]=_("Please specify a value for attribute 'file'."); } - if(empty($this->Object_FAItemplatePath)){ + if(empty($this->FAItemplatePath)){ $message[]=_("Please specify a value for attribute 'path'."); } - $str = utf8_encode("üöä"); - - if(preg_match("/[^a-z0-9".$str."\.,;:\-_\? ]/i",$this->Object_description)){ - $message[] = _("Invalid character in description. Please enter a valid description."); + if(empty($this->cn)){ + $message[] = _("Please enter a name."); } - if(empty($this->Object_cn)){ - $message[] = _("Please enter a name."); + if(empty($this->user)){ + $message[] = _("Please enter a user."); + } + elseif(preg_match("/[^0-9a-z]/i",$this->user)){ + $message[] = _("Please enter a valid user. Only a-Z 0-9 are allowed."); } - if(preg_match("/[^0-9a-z]/i",$this->Object_cn)){ - $message[] = _("Please enter a valid name. Only a-Z 0-9 are allowed."); + if(empty($this->group)){ + $message[] = _("Please enter a group."); } + elseif(preg_match("/[^0-9a-z]/i",$this->group)){ + $message[] = _("Please enter a valid group. Only a-Z 0-9 are allowed."); + } + return ($message); } @@ -101,8 +182,7 @@ class faiTemplateEntry extends plugin { $tmp=array(); foreach($this->attributes as $attrs){ - $attr = preg_replace("/^Object_/","",$attrs); - $tmp[$attr] = $this->$attrs; + $tmp[$attrs] = $this->$attrs; } if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){ @@ -111,7 +191,7 @@ class faiTemplateEntry extends plugin } $tmp['dn'] = $this->dn; - $tmp['status'] = $this->Object_status; + $tmp['status'] = $this->status; return($tmp); }