From a93d9df563dcfe538baea9908282183609563faa Mon Sep 17 00:00:00 2001 From: hickert Date: Thu, 8 Sep 2005 11:44:18 +0000 Subject: [PATCH] Added Profile management git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@1328 594d385d-05f5-0310-b6e9-bd551577e9d8 --- plugins/admin/FAI/class_faiManagement.inc | 4 + plugins/admin/FAI/class_faiProfile.inc | 231 ++++++++++++++++++++ plugins/admin/FAI/class_faiProfileEntry.inc | 201 +++++++++++++++++ plugins/admin/FAI/faiProfile.tpl | 46 ++++ plugins/admin/FAI/faiProfileEntry.tpl | 63 ++++++ 5 files changed, 545 insertions(+) create mode 100644 plugins/admin/FAI/class_faiProfile.inc create mode 100644 plugins/admin/FAI/class_faiProfileEntry.inc create mode 100644 plugins/admin/FAI/faiProfile.tpl create mode 100644 plugins/admin/FAI/faiProfileEntry.tpl diff --git a/plugins/admin/FAI/class_faiManagement.inc b/plugins/admin/FAI/class_faiManagement.inc index 76bf88bf2..463deda53 100644 --- a/plugins/admin/FAI/class_faiManagement.inc +++ b/plugins/admin/FAI/class_faiManagement.inc @@ -22,6 +22,7 @@ require "tabsVariable.inc"; require "tabsHook.inc"; require "tabsTemplate.inc"; require "tabsScript.inc"; +require "tabsProfile.inc"; class faiManagement extends plugin { @@ -557,6 +558,9 @@ class faiManagement extends plugin if(in_array("FAIvariable",$array['objectClass'])){ return(array("tabsVariable","faiVariable","FAIVARIABLETABS")); } + if(in_array("FAIprofile",$array['objectClass'])){ + return(array("tabsProfile","faiProfile","FAIPROFILETABS")); + } } } diff --git a/plugins/admin/FAI/class_faiProfile.inc b/plugins/admin/FAI/class_faiProfile.inc new file mode 100644 index 000000000..d760d9e41 --- /dev/null +++ b/plugins/admin/FAI/class_faiProfile.inc @@ -0,0 +1,231 @@ + "Eins ist toll", "zwei" => "Zwei ist noch besser"); + + /* attribute list for save action */ + var $ignore_account = TRUE; + + /* Attributes for this Object */ + var $attributes = array("cn","description","FAIclass"); + + /* ObjectClasses for this Object*/ + var $objectclasses = array("top","FAIclass","FAIprofile"); + + /* Class name of the Ldap ObjectClass for the Sub Object */ + var $subClass = "FAIscriptEntry"; + var $subClasses = array("top","FAIclass","FAIscriptEntry"); + + /* Specific attributes */ + var $cn = ""; // The class name for this object + var $description = ""; // The description for this set of partitions + var $is_dialog = false; // specifies which buttons will be shown to save or abort + var $dialog = NULL; // a dialog, e.g. new disk dialog + var $FAIclass = ""; // Classnames used for this profile + var $FAIclasses = array(); // Contains classname seperated in an array + var $FAIAllclasses = array(); // Contains all possible Classnames + + function faiProfile($config, $dn= NULL) + { + /* Load Attributes */ + plugin::plugin ($config, $dn); + $ldap=$this->config->get_ldap_link(); + + $tmp = split(" ",$this->FAIclass); + + foreach($tmp as $class){ + $this->FAIclasses[trim($class)] = trim($class); + } + + $categories = array("FAIscript","FAItemplate","FAIhook","FAIvariable","FAIpartitionTAble","FAIpackage"); + + $base = $_SESSION['faifilter']['base']; + $ldap->cd($base); + $ldap->search("(objectClass=*)",array("*")); + while($attrs = $ldap->fetch()){ + foreach($categories as $cat){ + if(in_array($cat,$attrs['objectClass'])){ + $this->FAIAllclasses[$attrs['cn'][0]][$cat]=$attrs; + } + } + } + + if($dn != "new"){ + $this->dn =$dn; + } + } + + function execute() + { + /* Fill templating stuff */ + $smarty= get_smarty(); + $display= ""; + + $s_entry = ""; + $s_action = ""; + + /* Remove class name From list */ + foreach($_POST as $name => $post){ + if(preg_match("/DEL_/i",$name)){ + $s_action = "delete"; + $s_entry = preg_replace("/DEL_/","",$name); + $s_entry = preg_replace("/_.*$/","",$s_entry); + }elseif(preg_match("/Add_class/i",$name)){ + $s_action = "add"; + } + } + + if($s_action == "delete"){ + unset($this->FAIclasses[$s_entry]); + } + + if($s_action == "add"){ + $this->dialog = new faiProfileEntry($this->config,$this->dn,$this->FAIclasses); + $this->is_dialog =true; + } + + /* Save Dialog */ + if(isset($_POST['SaveSubObject'])){ + $this->dialog->save_object(); + $msgs= $this->dialog->check(); + if(count($msgs)){ + print_red($msgs); + }else{ + $ret = $this->dialog->save(); + foreach($ret as $class){ + $this->FAIclasses[$class] =$class; + } + $this->is_dialog=false; + unset($this->dialog); + $this->dialog=NULL; + } + } + + /* Cancel Dialog */ + if(isset($_POST['CancelSubObject'])){ + $this->is_dialog=false; + unset($this->dialog); + $this->dialog=NULL; + } + + if(isset($this->dialog)){ + $this->dialog->save_object(); + return($this->dialog->execute()); + } + + $divlist =new divlist("Profile"); + $divlist->SetSummary(_("This list displays all assigned class names for this profile.")); + $divlist->SetEntriesPerPage(10); + + $divlist->SetHeader(array(array("string"=>"Class name"), + array("string"=>"Objects"), + array("string"=>"Options"))); + $listhead = + "
". + " ". + "
"; + + $objTypes['FAIhook'] = ""; + $objTypes['FAItemplate'] = ""; + $objTypes['FAIscript'] = ""; + $objTypes['FAIvariable'] = ""; + $objTypes['FAIpackages'] = ""; + $objTypes['FAIpartitionTable'] = ""; + + $actions = ""; + + foreach($this->FAIclasses as $usedClass){ + $str = ""; + if(isset($this->FAIAllclasses[$usedClass])){ + foreach($this->FAIAllclasses[$usedClass] as $class => $obj){ + $str.= $objTypes[$class]; + } + } + + $field1 = array("string"=> $usedClass,"attach"=>""); + $field2 = array("string"=> $str,"attach"=>""); + $field3 = array("string"=> preg_replace("/%KEY%/",$usedClass,$actions),"attach"=>"style='border-right:none;'"); + $divlist->AddEntry(array($field1,$field2,$field3)); + } + + $smarty->assign("divlisthead" ,$listhead); + $smarty->assign("divlist" ,$divlist->DrawList()); + + /* Assign variables */ + foreach($this->attributes as $attrs){ + $smarty->assign($attrs,$this->$attrs); + } + + $display.= $smarty->fetch(get_template_path('faiProfile.tpl', TRUE)); + return($display); + } + + function remove_from_parent() + { + $ldap = $this->config->get_ldap_link(); + $ldap->cd ($this->dn); + $ldap->rmdir_recursive($this->dn); + $this->handle_post_events("remove"); + } + + /* Save data to object + */ + function save_object() + { + plugin::save_object(); + foreach($this->attributes as $attrs){ + if(isset($_POST[$attrs])){ + $this->$attrs = $_POST[$attrs]; + } + } + } + + + /* Check supplied data */ + function check() + { + $message= array(); + $str = utf8_encode("üöä"); + if((empty($this->description))||(preg_match("/[^a-z0-9".$str."\.,;:-_\? ]/i",$this->description))){ + $message[]=_("Please enter a valid description."); + } + return ($message); + } + + + /* Save to LDAP */ + function save() + { + plugin::save(); + + $ldap = $this->config->get_ldap_link(); + + $this->FAIclass = ""; + foreach($this->FAIclasses as $class){ + $this->FAIclass=$class." "; + } + + $this->attrs['FAIclass']=trim($this->FAIclass); + + $ldap->cat($this->dn); + if($ldap->count()!=0){ + /* Write FAIscript to ldap*/ + $ldap->cd($this->dn); + $ldap->modify($this->attrs); + }else{ + /* Write FAIscript to ldap*/ + $ldap->cd($this->dn); + $ldap->create_missing_trees($this->dn); + $ldap->cd($this->dn); + $ldap->add($this->attrs); + } + show_ldap_error($ldap->get_error()); + } +} + +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/plugins/admin/FAI/class_faiProfileEntry.inc b/plugins/admin/FAI/class_faiProfileEntry.inc new file mode 100644 index 000000000..5e0566434 --- /dev/null +++ b/plugins/admin/FAI/class_faiProfileEntry.inc @@ -0,0 +1,201 @@ + "Eins ist toll", "zwei" => "Zwei ist noch besser"); + + /* attribute list for save action */ + var $ignore_account= TRUE; + var $attributes = array(); + var $objectclasses= array(); + + var $FAIAllclasses = array(); + + function faiProfileEntry ($config, $dn= NULL,$used=array(),$objects=false) + { + plugin::plugin ($config, $dn); + + $base = $_SESSION['faifilter']['base']; + + $categories = array("FAIscript","FAItemplate","FAIhook","FAIvariable","FAIpartitionTAble","FAIpackage"); + + $base = $_SESSION['faifilter']['base']; + $ldap= $this->config->get_ldap_link(); + $ldap->cd($base); + $ldap->search("(objectClass=*)",array("*")); + while($attrs = $ldap->fetch()){ + if((isset($attrs['cn'][0]))&&(!in_array($attrs['cn'][0],$used))){ + foreach($categories as $cat){ + if(in_array($cat,$attrs['objectClass'])){ + $this->FAIAllclasses[$attrs['cn'][0]]['objects'][$cat]=$cat; + $this->FAIAllclasses[$attrs['cn'][0]]['status']=false; + } + } + } + } + + if (1==1||!is_global("SUBfaifilter")){ + $SUBfaifilter= array("base" => "ou=fai,ou=configs,ou=systems,".$base, "Sregex" => "*"); + $SUBfaifilter['SShowTemplates'] = false; + $SUBfaifilter['SShowScripts'] = false; + $SUBfaifilter['SShowHooks'] = false; + $SUBfaifilter['SShowVariables'] = false; + $SUBfaifilter['SShowPackages'] = false; + $SUBfaifilter['SShowPartitions']= false; + register_global("SUBfaifilter", $SUBfaifilter); + } + } + + function execute() + { + /* Fill templating stuff */ + $smarty = get_smarty(); + $display = ""; + + $SUBfaifilter = $_SESSION['SUBfaifilter']; + + if(isset($_POST['apply'])){ + foreach($SUBfaifilter as $key => $val){ + if(!isset($_POST[$key])){ + $SUBfaifilter[$key] = false; + }else{ + $SUBfaifilter[$key] =$_POST[$key]; + } + } + } + + $_SESSION['SUBfaifilter']= $SUBfaifilter; + + foreach($_POST as $name => $value){ + foreach($this->FAIAllclasses as $class => $obj){ + if(isset($_POST["ON_PAGE_".$class])){ + if(isset($_POST['USE_'.$class])){ + $this->FAIAllclasses[$class]['status']=true; + }else{ + $this->FAIAllclasses[$class]['status']=false; + } + } + } + } + + $objTypes['FAIhook'] = ""; + $objTypes['FAItemplate'] = ""; + $objTypes['FAIscript'] = ""; + $objTypes['FAIvariable'] = ""; + $objTypes['FAIpackages'] = ""; + $objTypes['FAIpartitionTable'] = ""; + + foreach($this->attributes as $attrs){ + $smarty->assign($attrs,stripslashes($this->$attrs)); + } + + foreach($SUBfaifilter as $key => $val){ + if(($key != "base")&&($key != "Sregex")){ + if($val){ + $smarty->assign($key."CHK", " checked "); + }else{ + $smarty->assign($key."CHK", ""); + } + }else{ + $smarty->assign($key,$val); + } + } + $divlist = new divlist("ProfileEntry"); + $divlist->SetSummary(_("This list displays all assigned class names for this profile.")); + $divlist->SetEntriesPerPage(20); + $divlist->SetHeader(array(array("string"=>"Class name"), + array("string"=>"Objects"))); + + $action = " + "; + + foreach($this->FAIAllclasses as $usedClass => $classes){ + + $abort = false; + + if(($SUBfaifilter['SShowScripts'])&&(!in_array('FAIscript',$classes['objects']))){ + $abort = "true"; + } + if(($SUBfaifilter['SShowTemplates'])&&(!in_array('FAItemplate',$classes['objects']))){ + $abort = "true"; + } + if(($SUBfaifilter['SShowHooks'])&&(!in_array('FAIhook',$classes['objects']))){ + $abort = "true"; + } + if(($SUBfaifilter['SShowVariables'])&&(!in_array('FAIvariable',$classes['objects']))){ + $abort = "true"; + } + if(($SUBfaifilter['SShowPartitions'])&&(!in_array('FAIpartitionTable',$classes['objects']))){ + $abort = "true"; + } + if(($SUBfaifilter['SShowPackages'])&&(!in_array('FAIpackages',$classes['objects']))){ + $abort = "true"; + } + + if(!$abort){ + $str = ""; + foreach($classes['objects'] as $class => $obj){ + $str.= $objTypes[$obj]; + } + + if($classes['status']==true){ + $action_check = preg_replace("/%CHECK%/"," checked ",$action); + }else{ + $action_check = preg_replace("/%CHECK%/","",$action); + } + + $field1 = array("string"=> preg_replace("/%KEY%/",$usedClass,$action_check).$usedClass,"attach"=>""); + $field2 = array("string"=> $str,"attach"=>""); + $divlist->AddEntry(array($field1,$field2)); + } + } + + $smarty->assign("faihead" , ""); + $smarty->assign("failist" , $divlist->DrawList()); + $smarty->assign("infoimage" , get_template_path('images/info.png')); + $smarty->assign("launchimage" , get_template_path('images/launch.png')); + $smarty->assign("alphabet" , generate_alphabet()); + $smarty->assign("apply" , apply_filter(TRUE)); + $smarty->assign("search_image" , get_template_path('images/search.png')); + + $display.= $smarty->fetch(get_template_path('faiProfileEntry.tpl', TRUE)); + return($display); + } + + /* Save data to object */ + function save_object() + { + if(isset($_POST['SubObjectFormSubmitted'])){ + foreach($this->attributes as $attrs){ + if(isset($_POST[$attrs])){ + $this->$attrs = $_POST[$attrs]; + }else{ + $this->$attrs = ""; + } + } + } + } + + /* Check supplied data */ + function check() + { + $message= array(); + return ($message); + } + + function save() + { + $tmp = array(); + foreach($this->FAIAllclasses as $class => $obj){ + if($obj['status']==true){ + $tmp[$class]=$class; + } + } + return($tmp); + } +} +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/plugins/admin/FAI/faiProfile.tpl b/plugins/admin/FAI/faiProfile.tpl new file mode 100644 index 000000000..90bbb8824 --- /dev/null +++ b/plugins/admin/FAI/faiProfile.tpl @@ -0,0 +1,46 @@ +

 {t}Generic{/t}


+ + + + + + + + + +
+ + + +
+ + + +
+
+ + + + + +
+
+

+ +

+
+
+ + {$divlisthead} +
+
+
+
+ {$divlist} + +
+
diff --git a/plugins/admin/FAI/faiProfileEntry.tpl b/plugins/admin/FAI/faiProfileEntry.tpl new file mode 100644 index 000000000..b04a7ee33 --- /dev/null +++ b/plugins/admin/FAI/faiProfileEntry.tpl @@ -0,0 +1,63 @@ + + + + + +
+
+

+ {t}List of FAI objects (Fully Automatic Installation){/t} +

+
+
+ {$faihead} +
+
+
+ {$failist} + +
+
+
+

[i]{t}Information{/t}

+
+
+

+ {t}This menu allows you to create, delete and edit selected FAI obejcts. Having a large size of objects, you might prefer the range selectors on top of this list.{/t} +

+
+
+
+

[F]{t}Filters{/t}

+
+
+ + {$alphabet} +
+ + + + + + + +
{t}Show only classes with templates{/t}
{t}Show only classes with scripts{/t}
{t}Show only classes with hooks{/t}
{t}Show only classes with variables{/t}
{t}Show only classes with packages{/t}
{t}Show only classes with partitions{/t}
+ + + + + +
+ + + +
+ {$apply} +
+
+
+ + +
+ -- 2.30.2