diff --git a/plugins/admin/fai/class_faiTemplateEntry.inc b/plugins/admin/fai/class_faiTemplateEntry.inc
index 0399e5d8d5407ff9e1d9234ca3328594594ab4e1..7a3c48ddf370042b058dca626bc8da9956fded21 100644 (file)
/* attribute list for save action */
var $ignore_account= TRUE;
- var $attributes = array("Object_cn","Object_description","Object_FAItemplateFile","Object_FAItemplatePath","Object_FAImode","Object_user","Object_group","Object_binary","Object_FAIowner");
+ 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 $Object_FAImode = "0640";
- var $Object_FAIowner = "root.root";
- var $Object_user = "root";
- var $Object_group = "root";
- var $Object_binary = false;
+ 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;
+
+ var $FAIstate = "";
function faiTemplateEntry ($config, $dn= NULL,$object=false)
{
plugin::plugin ($config, $dn);
- if($dn != "new"){
+
+ if((isset($object['cn'])) && (!empty($object['cn']))){
$this->orig_cn= $object['cn'];
$this->dn=$object['dn'];
foreach($object as $name=>$value){
- $oname = "Object_".$name;
+ $oname = $name;
$this->$oname=$value;
}
+
+ if(isset($this->attrs['FAIstate'][0])){
+ $this->FAIstate = $this->attrs['FAIstate'][0];
+ }
+
}else{
- $this->Object_status = "new";
- $this->orig_cn = false;
+ $this->status = "new";
+ $this->orig_cn= false;
}
- $this->Object_user = explode( '.', $this->Object_FAIowner );
- $this->Object_group = $this->Object_user[1];
- $this->Object_user = $this->Object_user[0];
- $_SESSION['binary'] = $this->Object_FAItemplateFile;
+
+ $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->Object_FAItemplatePath );
+ $_SESSION['binaryfile'] = basename( $this->FAItemplatePath );
+
+ if(!empty($this->dn) && $this->dn != "new"){
+ $ldap = $this->config->get_ldap_link();
+ $_SESSION['binary'] =$ldap->get_attribute($this->dn,"FAItemplateFile");
+ $this->FAItemplateFile = $_SESSION['binary'];
+ }
+
+ $this->FAImode= sprintf("%0.4s", $this->FAImode)." ";
}
+
function execute()
{
+ /* Call parent execute */
+ plugin::execute();
+
/* Fill templating stuff */
$smarty = get_smarty();
$smarty->assign("rand", rand(0, 10000));
$display = "";
- if(isset($_POST['TmpFileUpload'])){
+ if(isset($_POST['TmpFileUpload']) && $this->acl_is_writeable("FAItemplateFile")){
if($str=file_get_contents($_FILES['FAItemplateFile']['tmp_name'])){
- $this->Object_FAItemplateFile = $str;
+ $this->FAItemplateFile = $str;
/* If we don't have a filename set it from upload filename. */
- if( 0 == strlen( $this->Object_FAItemplatePath ) )
- $this->Object_FAItemplatePath = $_FILES['FAItemplateFile']['name'];
+ if( 0 == strlen( $this->FAItemplatePath )){
+ $this->FAItemplatePath = $_FILES['FAItemplateFile']['name'];
+ }
+
+ $_SESSION['binary'] = $this->FAItemplateFile;
+ $_SESSION['binarytype'] = 'octet-stream';
+ $_SESSION['binaryfile'] = basename( $this->FAItemplatePath );
}
-
}
$status= _("no file uploaded yet");
- if(strlen($this->Object_FAItemplateFile)){
- $status= sprintf(_("exists in database (size: %s bytes)"),strlen($this->Object_FAItemplateFile));
+
+ $bStatus = false; // Hide download icon on default
+
+ if(strlen($this->FAItemplateFile)){
+
+ $status= sprintf(_("exists in database (size: %s bytes)"),strlen($this->FAItemplateFile));
+ $bStatus = true; // Display download icon
}
$smarty->assign("status",$status);
+ $smarty->assign("bStatus",$bStatus);
/* Magic quotes GPC, escapes every ' " \, to solve some security risks
* If we post the escaped strings they will be escaped again
}
/* Assign file modes */
- $tmode= "$this->Object_FAImode ";
+ $tmode= "$this->FAImode ";
foreach (array("s", "u", "g", "o") as $type){
$current= substr($tmode, 0, 1);
$tmode= preg_replace("/^./", "", $tmode);
}
}
- $smarty->assign("Object_FAItemplateFile","");
+ $smarty->assign("FAItemplateFile","");
+
+ foreach($this->attributes as $attr){
+ $smarty->assign($attr."ACL",$this->getacl($attr,preg_match("/freeze/",$this->FAIstate)));
+ }
- $display.= $smarty->fetch(get_template_path('faiTemplateEntry.tpl', TRUE));
+ $display.= $smarty->fetch(get_template_path('faiTemplateEntry.tpl', TRUE));
return($display);
}
/* Save data to object */
function save_object()
{
- if (!isset($_POST['Object_FAItemplatePath'])){
- return;
- }
- if(isset($_POST['SubObjectFormSubmitted'])){
- foreach($this->attributes as $attrs){
- if($attrs == "Object_FAItemplateFile")
- continue;
- if($attrs == "Object_FAIowner") {
- $this->$attrs = $_POST["Object_user"] . '.' . $_POST["Object_group"];
- continue;
- }
- if(isset($_POST[$attrs])){
- $this->$attrs = $_POST[$attrs];
- }else{
- $this->$attrs = "";
- }
+ /* Check if form is posted and we are not freezed */
+ if((isset($_POST['SubObjectFormSubmitted'])) && ($this->FAIstate != "freeze")){
+
+ plugin::save_object();
+
+ /* Set user.group (FAIowner) attribute */
+ if(isset($_POST['group']) && isset($_POST["user"]) && $this->acl_is_writeable("FAIowner")){
+ $this->FAIowner = $_POST["user"].'.'.$_POST["group"];
+ $this->user = $_POST['user'];
+ $this->group= $_POST['group'];
}
- }
- /* 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;
+ /* Check if permissions have changed */
+ if($this->acl_is_writeable("FAImode")){
+
+ /* 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;
}
- $nr+= $nr;
+ $this->FAImode= $tmode;
}
- $tmode= $tmode.$dest;
}
- $this->Object_FAImode= $tmode;
}
+
/* Check supplied data */
function check()
{
- $message= array();
- if(empty($this->Object_FAItemplateFile)){
+ /* Call common method to give check the hook */
+ $message= plugin::check();
+
+ 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'.");
}
- if(empty($this->Object_cn)){
+ if(empty($this->cn)){
$message[] = _("Please enter a name.");
}
- elseif(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->Object_user)){
+ if(empty($this->user)){
$message[] = _("Please enter a user.");
}
- elseif(preg_match("/[^0-9a-z]/i",$this->Object_user)){
- $message[] = _("Please enter a valid user. Only a-Z 0-9 are allowed.");
+ elseif(preg_match("/[^0-9a-z]/i",$this->user)){
+ $message[] = _("Please enter a valid user. Only a-z/0-9 are allowed.");
}
- if(empty($this->Object_group)){
+ if(empty($this->group)){
$message[] = _("Please enter a group.");
}
- elseif(preg_match("/[^0-9a-z]/i",$this->Object_group)){
- $message[] = _("Please enter a valid group. Only a-Z 0-9 are allowed.");
+ elseif(preg_match("/[^0-9a-z]/i",$this->group)){
+ $message[] = _("Please enter a valid group. Only a-z/0-9 are allowed.");
}
return ($message);
{
$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)){
}
$tmp['dn'] = $this->dn;
- $tmp['status'] = $this->Object_status;
+ $tmp['status'] = $this->status;
return($tmp);
}
+
+
+ /* Return plugin informations for acl handling */
+ function plInfo()
+ {
+ return (array(
+ "plShortName" => _("Template entry"),
+ "plDescription" => _("FAI template entry"),
+ "plSelfModify" => FALSE,
+ "plDepends" => array(),
+ "plPriority" => 25,
+ "plSection" => array("administration"),
+ "plCategory" => array("fai"),
+ "plProvidedAcls" => array(
+ "cn" => _("Name"),
+ "description" => _("Description"),
+ "FAItemplateFile" => _("Template file"),
+ "FAItemplatePath" => _("Template path"),
+ "FAIowner" => _("File owner"),
+ "FAImode" => _("File permissions"))
+ ));
+ }
+
}
// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
?>