From 17ac686f98cf8c85ca26ab00904310169844ec3b Mon Sep 17 00:00:00 2001 From: hickert Date: Tue, 6 Sep 2005 11:19:19 +0000 Subject: [PATCH] First FAI commit git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@1311 594d385d-05f5-0310-b6e9-bd551577e9d8 --- plugins/admin/FAI/askClassName.tpl | 49 ++ plugins/admin/FAI/class_askClassName.inc | 144 ++++++ plugins/admin/FAI/class_faiManagement.inc | 451 ++++++++++++++++++ plugins/admin/FAI/class_faiPartitionTable.inc | 236 +++++++++ .../FAI/class_faiPartitionTableEntry.inc | 322 +++++++++++++ plugins/admin/FAI/faiPartitionTable.tpl | 36 ++ plugins/admin/FAI/faiPartitionTableEntry.tpl | 33 ++ plugins/admin/FAI/headpage.tpl | 61 +++ plugins/admin/FAI/main.inc | 55 +++ plugins/admin/FAI/tabsPartition.inc | 45 ++ 10 files changed, 1432 insertions(+) create mode 100644 plugins/admin/FAI/askClassName.tpl create mode 100644 plugins/admin/FAI/class_askClassName.inc create mode 100644 plugins/admin/FAI/class_faiManagement.inc create mode 100644 plugins/admin/FAI/class_faiPartitionTable.inc create mode 100644 plugins/admin/FAI/class_faiPartitionTableEntry.inc create mode 100644 plugins/admin/FAI/faiPartitionTable.tpl create mode 100644 plugins/admin/FAI/faiPartitionTableEntry.tpl create mode 100644 plugins/admin/FAI/headpage.tpl create mode 100644 plugins/admin/FAI/main.inc create mode 100644 plugins/admin/FAI/tabsPartition.inc diff --git a/plugins/admin/FAI/askClassName.tpl b/plugins/admin/FAI/askClassName.tpl new file mode 100644 index 000000000..38317185b --- /dev/null +++ b/plugins/admin/FAI/askClassName.tpl @@ -0,0 +1,49 @@ +
+ {$headline} +

+
+ {t}Please select a class name for this object. The class name specifies a set of configurations.{/t} +
+ {t}Every Class name must be unique. But it can be used for diffrent objects at the same time.\n + If you use this class name in a profile, all object with this class name will be included to this profile.{/t} +
+
+ {t}The list box below shows all available class names you can use, for this object, to avoid duplicates.{/t} +
+
+ + + + + + + + + + + + + + + + + + +
+ {t}You can select one the following class names for this object.{/t} +
{t}Available class names.{/t} + + + +

+
+ {t}Please enter your class name here, if want to create a new class.{/t} +
{t}A new class name.{/t} + + + +
+

 

+ diff --git a/plugins/admin/FAI/class_askClassName.inc b/plugins/admin/FAI/class_askClassName.inc new file mode 100644 index 000000000..46f83eca8 --- /dev/null +++ b/plugins/admin/FAI/class_askClassName.inc @@ -0,0 +1,144 @@ + "Eins ist toll", "zwei" => "Zwei ist noch besser"); + + /* attribute list for save action */ + var $ignore_account = TRUE; + var $attributes = array(); + var $objectclasses = array("whatever"); + + var $objectClass = false; + var $forbidden =array(); + var $ClassName = ""; + var $ClassAlreadyExists = false; + + function askClassName ($config, $dn= NULL,$ui = false, $objectClass) + { + $this->ui = $ui; + $this->objectClass = $objectClass; + plugin::plugin ($config, $dn); + } + + function execute() + { + /* Fill templating stuff */ + $smarty= get_smarty(); + $display= ""; + + /* The faifilter contais + The base for all fai objects + */ + $faifilter = $_SESSION['faifilter']; + + /* First search for every ou, in given fai base + * With a second search detect all object that belong to the different ous. + */ + $ldap = $this->config->get_ldap_link(); + $res= get_list($this->ui->subtreeACL, "(objectClass=organizationalUnit)",FALSE, $faifilter['base'], array("cn","description","objectClass"),TRUE); + $used=array(); + + $delete = array(); + foreach($res as $objecttypes){ + $res2 = get_list2($this->ui->subtreeACL, "(objectClass=*)", + FALSE, $objecttypes['dn'], array("cn","description","objectClass","FAIclass"),TRUE); + foreach($res2 as $object){ + + /* skip class names with this type of object */ + if(in_array($this->objectClass,$object['objectClass'])){ + $delete[] = $object['cn'][0]; + } + + /* Skip profiles */ + if(!in_array("FAIprofile",$object['objectClass'])){ + $used[$object['cn'][0]]= $object['cn'][0]; + } + } + } + + /* Create headline + * Depending on the object type we want to create, a different headline will be shown + */ + switch($this->objectClass) { + case "FAIpartitionTable": $str =_("Create new FAI object - partition table.");break; + case "FAIpackageList" : $str =_("Create new FAI object - package list.");break; + case "FAIscript" : $str =_("Create new FAI object - set of scripts.");break; + case "FAIvariable" : $str =_("Create new FAI object - set of variables.");break; + case "FAIhook" : $str =_("Create new FAI object - set of hooks.");break; + case "FAIprofile" : $str =_("Create new FAI object - profile.");break; + case "FAItemplate" : $str =_("Create new FAI object - template.");break; + default : $str =_("Create nre FAI object");break; + } + $smarty->assign("headline",$str); + + /* Save forbidden class names + */ + $this->forbidden = $delete; + + /* Delete all class names which already have this type of object + */ + foreach($delete as $del){ + unset($used[$del]); + } + + /* if there is no class name which is missing the type + * of objectClass wew want to create now, disable selectBox + */ + if(count ($used)==0){ + $smarty->assign("ClassNamesAvailable", " disabled "); + }else{ + $smarty->assign("ClassNamesAvailable", ""); + } + $smarty->assign("ClassNames", $used); + $smarty->assign("ClassNameKeys", $used); + $display.= $smarty->fetch(get_template_path('askClassName.tpl', TRUE)); + return($display); + } + + /* Get posts and set class name + */ + function save_object() + { + if(isset($_POST['UseNewClass'])){ + $this->ClassName = $_POST['UseTextInputName']; + $this->ClassAlreadyExists = true; + } + + if(isset($_POST['UseSelectedClass'])){ + $this->ClassAlreadyExists = false; + $this->ClassName = $_POST['SelectedClass']; + } + } + + + /* Check given class name + * A class name For each object type, + */ + function check() + { + $message= array(); + if(empty($this->ClassName)){ + $message[]=_("The given class name is empty."); + } + + if(in_array($this->ClassName,$this->forbidden)){ + $message[]=_("The specified class name is already in use for this object type."); + } + return ($message); + } + + + /* Return the class name */ + function save() + { + return($this->ClassName); + } + +} + +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/plugins/admin/FAI/class_faiManagement.inc b/plugins/admin/FAI/class_faiManagement.inc new file mode 100644 index 000000000..901b44baf --- /dev/null +++ b/plugins/admin/FAI/class_faiManagement.inc @@ -0,0 +1,451 @@ + "Eins ist toll", "zwei" => "Zwei ist noch besser"); + + /* Headpage attributes */ + var $departments= array(); + var $deptabs= NULL; + + /* attribute list for save action */ + var $attributes = array(); // Attributes Managed by this plugin, none, + // because this is only an overview over all objects already defined in FAI. + var $objectclasses = array(); // ObjectClasses which the attributes are related to + var $dialog = array(); // This object contains every dialog we have currently opened + + var $objects = array(); // This array contains all available objects shown in divlist + var $is_dialog = false; + + /* construction/reconstruction + * The Filter ($faifilter stored in $_SESSION['faifilter']) defines the last + * selected department and filter options + * If it is not defined already we create a new fresh faifilter. + */ + function faiManagement ($config, $ui) + { + /* #WT ??? Whats That */ + $this->ui = $ui; + + /* Set current dn to "", wherefore ? */ + $this->dn = ""; + + /* Assign config */ + $this->config = $config; + + /* Get global filter config */ + if (!is_global("faifilter")){ + $base = get_base_from_people($ui->dn); + $faifilter= array("base" => "ou=fai,ou=configs,ou=systems,".$base, + "regex" => "*"); + $faifilter['ShowProfiles'] = true; + $faifilter['ShowTemplates'] = true; + $faifilter['ShowScripts'] = true; + $faifilter['ShowHooks'] = true; + $faifilter['ShowVariables'] = true; + $faifilter['ShowPackages'] = true; + $faifilter['ShowPartitions']=true; + register_global("faifilter", $faifilter); + } + } + + function execute() + { + $display = ""; + $smarty = get_smarty(); + $s_action = ""; + $s_entry = ""; + /* filter management + * Filter will be changed if POST['regex'] or $_GET['search'] isset + * New Filter will be stored in session and is used to generate list contents + */ + $faifilter = $_SESSION['faifilter']; + + /* Filter is posted by apply button + * Check every single chkbox + */ + if(isset($_POST['regex'])){ + $faifilter['regex'] = $_POST['regex']."*"; + foreach(array("ShowPartitions","ShowProfiles","ShowTemplates","ShowScripts","ShowHooks","ShowVariables","ShowPackages") as $attrs){ + if(isset($_POST[$attrs])){ + $faifilter[$attrs] = true; + }else{ + $faifilter[$attrs] = false; + } + } + } + + /* Check ImageButton posts + * Create new tab ich new_xx is posted + */ + foreach($_POST as $key => $val){ + if(preg_match("/create_partition/i",$key)){ + $s_action = "new_partition"; + }elseif(preg_match("/UseNewClass/",$key)){ + $s_action = "select_class_name_finished"; + }elseif(preg_match("/UseSelectedClass/",$key)){ + $s_action = "select_class_name_finished"; + }elseif(preg_match("/^entry_edit_.*/",$key)){ + $s_entry = preg_replace("/^entry_edit_/","",$key); + $s_entry = preg_replace("/_.*$/","",$s_entry); + + $s_action = "edit"; + } + + } + + if($s_action == "edit"){ + $entry = $this->objects[$s_entry]; + switch($entry['type']){ + case "FAIpartitionTable" : + $this->dn = $entry['dn']; + $this->dialog= new tabsPartition($this->config, + $this->config->data['TABS']['PARTITIONTABS'],$this->dn); + $this->is_dialog = true; + ;break; + default :;break; + } + + } + + + /* Dialog handling */ + if($s_action == "new_partition"){ + $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIpartitionTable"); + } + + if($s_action == "select_class_name_finished"){ + $this->dialog->save_object(); + if(count($this->dialog->check())!=0){ + foreach($this->dialog->check() as $msg){ + print_red($msg); + } + }else{ + $this->dn = "new" ; + $name = $this->dialog->save(); + $this->dialog = new tabsPartition($this->config, + $this->config->data['TABS']['PARTITIONTABS'],$this->dn); + $this->dialog->by_object['faiPartitionTable']->cn = $name; + $this->is_dialog = true; + } + } + + + /* Search is set */ + if(isset($_GET['search'])){ + $faifilter['regex']=$_GET['search']."*"; + } + + /* remove double asterisks and save new filter */ + $faifilter['regex'] = preg_replace("/\*\*/","*",$faifilter['regex']); + $_SESSION['faifilter']= $faifilter; + + $this->reload(); + + /* Edit dialog was canceled + * Remove dialog an show management dialog + */ + if(isset($_POST['edit_cancel'])){ + unset($this->dialog); + $this->dialog=NULL; + $this->is_dialog = false; + } + + + /* This check if the given tab could be saved + * If it was possible to save it, remove dialog object. + * If it wasn't possible, show errors and keep dialog. + */ + if(isset($_POST['edit_finish'])){ + $this->dialog->save_object(); + if(count($this->dialog->check())!=0){ + foreach($this->dialog->check() as $msg){ + print_red($msg); + } + }else{ + $this->dialog->save(); + unset($this->dialog); + $this->dialog=NULL; + $this->is_dialog=false; + } + } + + + /* If dialog is set, but $this->is_dialog==false, then + * only the "abort" button is shown, this are dialogs that must not be saved. + * If is_dialog == true, we are currently editing tab objects. + * Here we need both, save and cancel + */ + + if($this->dialog != NULL){ + $display .= $this->dialog->execute(); + /* Don't show buttons if tab dialog requests this */ + if (((isset($this->dialog->current))&&($this->dialog->by_object[$this->dialog->current]->is_dialog))){ + + }elseif(((isset($this->dialog->current))&&(!$this->dialog->by_object[$this->dialog->current]->is_dialog))){ + $display.= "

\n"; + $display.= "\n"; + $display.= " \n"; + $display.= "\n"; + $display.= "

"; + }elseif(!isset($this->dialog->current)){ + $display.= "

\n"; + $display.= "\n"; + $display.= "

"; + } + return($display); + } + + /* Show Management template + * The following code will only be reached if no dialog (tabs or dialogs) + * are currently opened. + * Assign all reguired vars to template engine + */ + + /* Create listhead, it will be shown on top of the divlist. + * It provides general navigation and object creation + */ + $faihead = + "
". + "  ". + "  ". + + "  ". + + "  ". + + "
"; + + + /* Create list with objects */ + $divlist = new divlist("faiManagement"); + $divlist->SetEntriesPerPage(20); + $divlist->SetSummary(_("This table displays all systems, in the selected tree.")); + + $divlist->SetHeader(array( + array("string" => " "), + array("string" => _("FAI objects / ObjectClasses")), + array("string" => _("Object type")), + array("string" => _("Obtions"), "attach" => "style='border:none'" ))); + + + $action = ""; + + /* Attach objects */ + foreach($this->objects as $key => $value){ + $info= ""; + $img = ""; + $type = $value['type']; + $abort=false; + + switch($type) { + case "FAIpartitionTable" : + if(!$faifilter['ShowPartitions']){ + $abort = true; + } + $img="PT"; + $info = _("Partition table"); + break; + case "FAIpackageList" : + if(!$faifilter['ShowPackages']){ + $abort = true; + } + $img="PL"; + $info = _("Package list"); + break; + case "FAIscript" : + if(!$faifilter['ShowScripts']){ + $abort = true; + } + $img="S"; + $info = _("Script set"); + break; + case "FAIvariable" : + if(!$faifilter['ShowVariables']){ + $abort = true; + } + $img="V"; + $info = _("Varialbe set"); + break; + case "FAIhook" : + if(!$faifilter['ShowHooks']){ + $abort = true; + } + $img="H"; + $info = _("Hook set"); + break; + case "FAIprofile" : + if(!$faifilter['ShowProfiles']){ + $abort = true; + } + $img="P"; + $info = _("Profile")." (".$value['FAIclass']." )"; + break; + case "FAItemplate" : + if(!$faifilter['ShowTemplates']){ + $abort = true; + } + $img="T"; + $info = _("Template"); + break; + default : + $img="";$info = "";break; + + } + if(!$abort) { + if((isset($value['description']))&&(!empty($value['description']))){ + $desc= " [".$value['description']."]"; + }else{ + $desc= ""; + } + + $field1 = array("string" => $img , "attach" => "style='height:26px;width=20px;'"); + $field2 = array("string" => $value['cn'].$desc , "attach" => ""); + $field3 = array("string" => $info, "attach" => ""); + $field4 = array("string" => sprintf($action,$key) , "attach" => "style='border-right:none;'"); + $divlist->AddEntry(array($field1,$field2,$field3,$field4)); + + } + } + + foreach($faifilter as $attrs => $value){ + if($value){ + $smarty->assign($attrs."CHK", " checked "); + }else{ + $smarty->assign($attrs."CHK", " "); + } + } + + /* Assign all reguired vars to template engine */ + $smarty->assign("faihead" , $faihead); + $smarty->assign("failist" , $divlist->DrawList()); + $smarty->assign("regex" , $faifilter['regex']); + $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()); + $smarty->assign("search_image" , get_template_path('images/search.png')); + + $display = $smarty->fetch(get_template_path('headpage.tpl', TRUE, dirname(__FILE__))); + return ($display); + } + + + function reload() + { + /* Create a new list of FAI object + * Object list depends on faifilter['regex'] + * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ... + */ + $faifilter= get_global('faifilter'); + // Added for dirlist function... + + /* Set base for all searches */ + $base= $faifilter['base']; + $regex = $faifilter['regex']; + + /* Array to save objects */ + $objects = array(); + + $res= get_list($this->ui->subtreeACL, "(objectClass=organizationalUnit)", + FALSE, $base, array("cn","description","objectClass"),TRUE); + + foreach($res as $objecttypes){ + $res2 = get_list($this->ui->subtreeACL, "(&(objectClass=*)(cn=".$regex."))", + FALSE, $objecttypes['dn'], array("cn","description","objectClass","FAIclass"),TRUE); + foreach($res2 as $object){ + $type= ""; + unset($object['objectClass']['count']); + if(!isset($object['description'][0])){ + $object['description'][0]=""; + } + + /* Clean up object informations */ + $obj['cn'] = $object['cn'][0]; + $obj['dn'] = $object['dn']; + $obj['description'] = $object['description'][0]; + $obj['objectClass'] = $object['objectClass']; + + if(in_array("FAIpartitionTable",$obj['objectClass'])){ + $type = "FAIpartitionTable"; + }elseif(in_array("FAIpackageList",$obj['objectClass'])){ + $type = "FAIpackageList"; + }elseif(in_array("FAIscript",$obj['objectClass'])){ + $type = "FAIscript"; + }elseif(in_array("FAIvariable",$obj['objectClass'])){ + $type = "FAIvariable"; + }elseif(in_array("FAIhook",$obj['objectClass'])){ + $type = "FAIhook"; + }elseif(in_array("FAIprofile",$obj['objectClass'])){ + $obj['FAIclass'] = $object['FAIclass'][0]; + $type = "FAIprofile"; + }elseif(in_array("FAItemplate",$obj['objectClass'])){ + $type = "FAItemplate"; + } + $this->objects[$obj['cn'].$type] = $obj; + $this->objects[$obj['cn'].$type]['type']=$type; + + } + } + reset ($this->objects); + } + + function remove_from_parent() + { + $ldap= $this->config->get_ldap_link(); + $ldap->cd ($this->dn); + $ldap->recursive_remove(); + + /* Optionally execute a command after we're done */ + $this->postremove(); + + /* Delete references to object groups */ + $ldap->cd ($this->config->current['BASE']); + $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn")); + while ($ldap->fetch()){ + $og= new ogroup($this->config, $ldap->getDN()); + unset($og->member[$this->dn]); + $og->save (); + } + + } + + function remove_lock() + { + if (isset($this->dn)){ + del_lock ($this->dn); + } + } + +} + +?> diff --git a/plugins/admin/FAI/class_faiPartitionTable.inc b/plugins/admin/FAI/class_faiPartitionTable.inc new file mode 100644 index 000000000..6a45e892b --- /dev/null +++ b/plugins/admin/FAI/class_faiPartitionTable.inc @@ -0,0 +1,236 @@ + "Eins ist toll", "zwei" => "Zwei ist noch besser"); + + /* attribute list for save action */ + var $ignore_account= TRUE; + var $attributes = array("cn","description"); + var $objectclasses= array("top","FAIclass","FAIpartitionTable"); + + var $cn = ""; + var $description = ""; + var $disks = array(); + var $is_dialog = false; + var $dialog = NULL; + function faiPartitionTable ($config, $dn= NULL) + { + plugin::plugin ($config, $dn); + + $this->partitions = array(); + + /* If "dn==new" we try to create a new entry + * Else we must read all objects from ldap taht belong to this entry + * First read disks from ldap ... and then the partition definitions for the disks + */ + if($dn != "new"){ + $this->dn =$dn; + + /* Read all disks from ldap taht are defined fot this partition table + */ + $ldap = $this->config->get_ldap_link(); + $ldap->cd ($this->dn); + $ldap->search("(&(objectClass=FAIclass)(objectClass=FAIpartitionDisk))",array("*")); + while($object = $ldap->fetch()){ + $this->disks[$object['cn'][0]]['dn'] = $object['dn']; + $this->disks[$object['cn'][0]]['cn'] = $object['cn'][0]; + if(isset($object['description'][0])){ + $this->disks[$object['cn'][0]]['description'] = $object['description'][0]; + }else{ + $this->disks[$object['cn'][0]]['description'] = ""; + } + $this->disks[$object['cn'][0]]['partitions'] = array(); + } + + /* read all partitions for each disk + */ + foreach($this->disks as $name => $disk){ + $ldap->cd ($disk['dn']); + $ldap->search("(&(objectClass=FAIclass)(objectClass=FAIpartitionEntry))",array("*")); + while($partition = $ldap->fetch()){ + + /* remove count ... from ldap result + */ + foreach($partition as $key=>$val){ + if((is_numeric($key))||($key=="count")||($key=="dn")){ + unset($partition[$key]); + }else{ + $partition[$key] = $val[0]; + } + } + + $this->disks[$name]['partitions'][$partition['FAIpartitionNr']] = $partition; + } + } + } + } + + function execute() + { + /* Fill templating stuff */ + $smarty= get_smarty(); + $display= ""; + + /* Add Disk to this Partitionset + * This code adds a new HDD to the disks + * A new Dialog will be opened + */ + if(isset($_POST['AddDisk'])){ + $this->dialog = new faiPartitionTableEntry($this->config,$this->dn); + $this->is_dialog = true; + } + + if((isset($_POST['EditDisk']))&&(isset($_POST['disks']))){ + $this->dialog = new faiPartitionTableEntry($this->config,$this->dn,$this->disks[$_POST['disks']]); + $this->is_dialog = true; + } + + if(isset($_POST['CancelDisk'])){ + unset($this->dialog); + $this->dialog = NULL; + $this->is_dialog=false; + } + + if(isset($_POST['SaveDisk'])){ + $this->dialog->save_object(); + if(count($this->dialog->check())){ + foreach($this->dialog->check() as $msg){ + print_red($msg); + } + }else{ + $disk = $this->dialog->save(); + $this->disks[$disk['cn']]=$disk; + unset($this->dialog); + $this->dialog = NULL; + $this->is_dialog=false; + } + } + + if(isset($this->dialog)){ + $this->dialog->save_object(); + return($this->dialog->execute()); + } + + foreach($this->attributes as $attrs){ + $smarty->assign($attrs,$this->$attrs); + if($this->$attrs){ + $smarty->assign($attrs."CHK"," "); + }else{ + $smarty->assign($attrs."CHK"," disabled "); + } + } + + $disks = array(); + foreach($this->partitions as $part){ + $disks[$part['cn']] = $part['cn']." [".$part['description']."]"; + } + + + $disks = $this->getDisks(); + $smarty->assign("disks" ,$disks); + $smarty->assign("diskKeys",array_flip($disks)); + $display.= $smarty->fetch(get_template_path('faiPartitionTable.tpl', TRUE)); + return($display); + } + + function getDisks(){ + $a_return = array(); + foreach($this->disks as $key => $disk){ + $cnt = count( $disk['partitions']); + if(!empty($disk['description'])){ + $a_return[$key]= $disk['cn']." [".$disk['description']."] - "._("Number of Partitions")." :".$cnt; + }else{ + $a_return[$key]= $disk['cn']." - "._("Number of Partitions")." :".$cnt; + } + } + return($a_return); + } + + function remove_from_parent() + { + /* This cannot be removed... */ + } + + + /* 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(); + + return ($message); + } + + + /* Save to LDAP */ + function save() + { + plugin::save(); + + $ldap = $this->config->get_ldap_link(); + $ldap->cat($this->dn); + if($ldap->count()){ + $ldap->cd ($this->dn); + $ldap->rmdir_recursive($this->dn); + show_ldap_error($ldap->get_error()); + } + $ldap->cd($this->dn); + $ldap->create_missing_trees($this->dn); + $ldap->cd($this->dn); + $ldap->add($this->attrs); + show_ldap_error($ldap->get_error()); + + foreach($this->disks as $cn=>$disk){ + $disk_cn = "cn=".$cn.",".$this->dn; + $disk_attrs['cn'] = $disk['cn']; + $disk_attrs['description'] = $disk['description']; + $disk_attrs['objectClass']=array("top","FAIclass","FAIpartitionDisk"); + + $ldap->cd($disk_cn); + $ldap->create_missing_trees($disk_cn); + $ldap->cd($disk_cn); + $ldap->add($disk_attrs); + show_ldap_error($ldap->get_error()); + + foreach($disk['partitions'] as $key => $partition){ + $partition_attrs = array(); + foreach($partition as $key => $value){ + if(!empty($value)){ + $partition_attrs[$key]=$value; + }else{ + unset($partition_attrs[$key]); + } + } + + $partition_dn = "cn=".$partition_attrs['cn'].",".$disk_cn; + $partition_attrs['objectClass'] = array("top","FAIclass","FAIpartitionEntry"); + + $ldap->cd($partition_dn); + $ldap->create_missing_trees($partition_dn); + $ldap->cd($partition_dn); + $ldap->add($partition_attrs); + show_ldap_error($ldap->get_error()); + } + } + $this->handle_post_events("add"); + } + +} + +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/plugins/admin/FAI/class_faiPartitionTableEntry.inc b/plugins/admin/FAI/class_faiPartitionTableEntry.inc new file mode 100644 index 000000000..c652ee965 --- /dev/null +++ b/plugins/admin/FAI/class_faiPartitionTableEntry.inc @@ -0,0 +1,322 @@ + "Eins ist toll", "zwei" => "Zwei ist noch besser"); + + /* attribute list for save action */ + var $ignore_account= TRUE; + var $attributes = array("DISK_cn","DISK_description"); + var $objectclasses= array(); + + var $DISK_cn = ""; + var $DISK_description = ""; + + var $partitions = array(); + var $UsedAttrs = array(); + var $AvailableDiskNames = array(); + var $is_edit = false; + var $old_cn = ""; + + function faiPartitionTableEntry ($config, $dn= NULL,$disk=false) + { + plugin::plugin ($config, $dn); + $this->UsedAttrs = array("cn","description","FAIpartitionType","FAIpartitionNr","FAIfsType","FAImountPoint","FAIpartitionSize", + "FAImountOptions","FAIfsOptions","FAIpartitionFlags"); + + $this->AvailableDiskNames = array(); + foreach(array("a","b","c","d","e","f","g","h") as $ts){ + $this->AvailableDiskNames["hd".$ts]= "hd".$ts; + } + + if($disk){ + foreach($disk['partitions'] as $name => $values){ + foreach($this->UsedAttrs as $attr){ + if(!isset($values[$attr])){ + $disk['partitions'][$name][$attr]=""; + } + } + } + + + $this->DISK_cn = $disk['cn']; + $this->DISK_description = $disk['description']; + $this->partitions = $disk['partitions']; + $this->is_edit = true; + $this->old_cn = $disk['cn']; + } + } + + function execute() + { + /* Fill templating stuff */ + $smarty = get_smarty(); + $s_action = ""; + $s_entry = ""; + $display = ""; + + /* Assign values + * And Checkbox selection + */ + foreach($this->attributes as $attrs){ + $smarty->assign($attrs,$this->$attrs); + if($this->$attrs){ + $smarty->assign($attrs."CHK"," "); + }else{ + $smarty->assign($attrs."CHK"," disabled "); + } + } + + /* Check all Posts if there is something usefull for us, + * For example : Delete is posted as Delete_1 + * The number specifies the index we want to delete + */ + foreach($_POST as $name => $value){ + if(preg_match("/Delete_.*/",$name)){ + $tmp = split("_",$name); + $s_action = "remove"; + $s_entry = $tmp[1]; + } + } + + /* To remove a partition we unset the index posted. + * We must sort the index again, else we possibly got problems + * with partitions order. + */ + if($s_action == "remove"){ + unset($this->partitions[$s_entry]); + $tmp= array(); + foreach($this->partitions as $part){ + $tmp[count($tmp)+1]=$part; + } + $this->partitions = $tmp; + + } + + /* To add a partitions we only append an empty + * array to the already defined partitions. + */ + if(isset($_POST['AddPartition'])){ + foreach($this->UsedAttrs as $attr){ + $tmp[$attr] = ""; + } + $this->partitions[count($this->partitions)+1]=$tmp; + } + + /* Tell smarty which Disknames are available. + */ + $smarty->assign("cns", $this->AvailableDiskNames); + + /* $setup contains a table with the partitions. + */ + $smarty->assign("setup", $this->generateParts()); + foreach($this->attributes as $attr){ + $smarty->assign($attr,$this->$attr); + } + + /* The user can't change a diskname + * if we are currently in edit mode for the specified disk + */ + if($this->is_edit){ + $smarty->assign("DISK_cnACL"," disabled "); + }else{ + $smarty->assign("DISK_cnACL",""); + } + + /* Fetch template and show the result + */ + $display.= $smarty->fetch(get_template_path('faiPartitionTableEntry.tpl', TRUE)); + return($display); + } + + function generateParts() + { + /* Define Arrays with allowed syntax */ + $PartitionTypes = array("primary","logical"); + $FAIfsTypes = array("ext2","ext3","xfs","swap","reiserfs","dos fat 16","win fat 32"); + + /* Display Header */ + $str = ""; + $str .= ""; + $str .= ""; + $str .= ""; + $str .= ""; + $str .= ""; + $str .= ""; + $str .= ""; + $str .= ""; + $str .= ""; + $str .= ""; + $str .= ""; + $str .= ""; + $str .= ""; + + /* Walk through all defined partitions. + * Create a new row for each partition and append it to + * the header defined above. + * To be able to check the posts later, we append a key to each single postfield. like cn_1 ... cn_2 + */ + foreach($this->partitions as $key => $part){ + + /* Generate Partition select box + */ + $PartitionType = ""; + + + /* Generate fsType select box + */ + $FAIfsType= ""; + + $str .= ""; + $str .= ""; + $str .= ""; + $str .= ""; + $str .= ""; + $str .= ""; + $str .= ""; + $str .= ""; + $str .= ""; + $str .= ""; + if($part['FAIpartitionFlags']!=false){ + $str .= ""; + }else{ + $str .= ""; + } + $str .= ""; + $str .= ""; + } + $str.="
"._("Nr").""._("Name").""._("Description").""._("Type").""._("FS type").""._("Mount point").""._("Size in MB").""._("Mount options").""._("FS option").""._("Preserve")."
".($key)."".$PartitionType."".$FAIfsType."
"; + return($str); + + } + + /* Save data to object */ + function save_object() + { + if(isset($_POST['TableEntryFrameSubmitted'])){ + plugin::save_object(); + + /* Check base attributes */ + foreach($this->attributes as $attrs){ + if(isset($_POST[$attrs])){ + $this->$attrs = $_POST[$attrs]; + } + } + + foreach($this->partitions as $key => $part){ + foreach($this->UsedAttrs as $attrs){ + if(isset($_POST[$attrs."_".$key])){ + $this->partitions[$key][$attrs] = $_POST[$attrs."_".$key]; + }else{ + $this->partitions[$key][$attrs] = false; + } + } + } + } + } + + + /* Check supplied data */ + function check() + { + $message= array(); + + /* Check descriptions + */ + if(empty($this->DISK_description)){ + $message[] = _("Please enter a description for your disk."); + } + if(preg_match("/[^0-9a-z]/",$this->DISK_description)){ + $message[] = _("Please enter a valid description for your disk. Only a-Z 0-9 are allowed."); + } + + /* check every partition. + * if there is an invalid value defined, append an errorstr to message + */ + foreach($this->partitions as $key => $part){ + if((empty($part['cn']))||(preg_match("/[^0-9a-z]/",$part['cn']))){ + $message[]=sprintf(_("Please enter a valid name for partition %s." ),($key)); + } + + if(empty($part['description'])){ + $message[]=sprintf(_("Please enter a valid description for partition %s." ),($key)); + } + + if((empty($part['FAImountPoint']))||(!((preg_match("/^\/.*/",$part['FAImountPoint']))||(preg_match("/^swap$/",$part['FAImountPoint']))))){ + $message[]=sprintf(_("Please enter a valid mount point for partition %s." ),($key)); + } + + $tmp = split("-",$part['FAIpartitionSize']); + if(count($tmp)!=2){ + $message[]=sprintf(_("Please enter a range for partition size, 'from-to', for partition %s."),($key)); + }elseif((!is_numeric($tmp[0]))||(!is_numeric($tmp[1]))){ + $message[]=sprintf(_("Please enter a valid range for partition %s."),($key)); + }elseif($tmp[0]>=$tmp[1]){ + $message[]=sprintf(_("Please enter a valid range for partition %s."),($key)); + } + } + + + /* Only show 5 errors */ + $cnt = 0; + if(count($message)>5){ + foreach($message as $msg){ + if($cnt < 5){ + $tmp2[]=$msg; + } + $cnt ++; + } + $tmp2[] = "..."; + $message = $tmp2; + } + + return ($message); + } + + + function save() + { + /* This function returns the new or edited disk with its partitions. + * If the disk was edited and not a new one, we reset the name of the disk + * to keep the correct index. + */ + + if($this->is_edit){ + $tmp['cn'] = $this->old_cn; + }else{ + $tmp['cn'] = $this->DISK_cn; + } + + foreach($this->partitions as $key=>$val) { + $this->partitions[$key]['FAIpartitionNr']=$key; + } + + $tmp['description'] = $this->DISK_description; + $tmp['partitions'] = $this->partitions; + + return($tmp); + } + +} + +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/plugins/admin/FAI/faiPartitionTable.tpl b/plugins/admin/FAI/faiPartitionTable.tpl new file mode 100644 index 000000000..e1d511c9b --- /dev/null +++ b/plugins/admin/FAI/faiPartitionTable.tpl @@ -0,0 +1,36 @@ +

{t}FAI partition table{/t} +

+ + + + + + + + + +
+ {t}Name{/t} + + +
+ {t}Description{/t} + + +
+
+
+

{t}Already defined disk{/t}

+ + + + +
+
+ + + +
+ diff --git a/plugins/admin/FAI/faiPartitionTableEntry.tpl b/plugins/admin/FAI/faiPartitionTableEntry.tpl new file mode 100644 index 000000000..e06668263 --- /dev/null +++ b/plugins/admin/FAI/faiPartitionTableEntry.tpl @@ -0,0 +1,33 @@ +

{t}FAI partition table entry{/t} + +

+ + + + + + + + + +
{t}Name{/t} + +
+
{t}Description{/t} + +
+
+

 

+
+{$setup} +
+ +
+
+

 

+
+ + +
diff --git a/plugins/admin/FAI/headpage.tpl b/plugins/admin/FAI/headpage.tpl new file mode 100644 index 000000000..473cae381 --- /dev/null +++ b/plugins/admin/FAI/headpage.tpl @@ -0,0 +1,61 @@ + + + + + +
+
+

+ {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 profiles{/t}
{t}Show templates{/t}
{t}Show scripts{/t}
{t}Show hooks{/t}
{t}Show variables{/t}
{t}Show packages{/t}
{t}Show partitions{/t}
+ + + + + +
+ + + +
+ {$apply} +
+
+ + diff --git a/plugins/admin/FAI/main.inc b/plugins/admin/FAI/main.inc new file mode 100644 index 000000000..bdb04615c --- /dev/null +++ b/plugins/admin/FAI/main.inc @@ -0,0 +1,55 @@ +remove_lock(); + del_lock ($ui->dn); + sess_del ('FAI'); + } +} else { + /* Create usermanagement object on demand */ + if (!isset($_SESSION['FAI']) || (isset($_GET['reset']) && $_GET['reset'] == 1)){ + $_SESSION['FAI']= new faiManagement($config, $ui); + } + $FAI= $_SESSION['FAI']; + $output= $FAI->execute(); + + /* Page header*/ + if (isset($_SESSION['objectinfo'])){ + $display= print_header(get_template_path('images/department.png'), _("FAI management"), "\"\" ".$_SESSION['objectinfo']); + } else { + $display= print_header(get_template_path('images/department.png'), _("FAI management")); + } + + /* Reset requested? */ + if (isset($_GET['reset']) && $_GET['reset'] == 1){ + del_lock ($ui->dn); + sess_del ('FAI'); + } + + /* Show and save dialog */ + $FAI->save_object(); + $display.= $output; + $_SESSION['FAI']= $FAI; +} + +?> diff --git a/plugins/admin/FAI/tabsPartition.inc b/plugins/admin/FAI/tabsPartition.inc new file mode 100644 index 000000000..d61396d67 --- /dev/null +++ b/plugins/admin/FAI/tabsPartition.inc @@ -0,0 +1,45 @@ +by_object['faiPartitionTable']; + + // cn=FAIBASE,ou=disk,ou=fai,ou=configs,ou=systems,dc=gonicus,dc=de + $new_dn= 'cn='.$baseobject->cn.",ou=disk,ou=fai,ou=configs,ou=systems,".$_SESSION['config']->current['BASE']; + + // Old .. $new_dn= 'ou='.$baseobject->ou.','.$baseobject->base; + + if ($this->dn != $new_dn && $this->dn != "new"){ + + /* if( new_dn is subtree of this->dn ) */ + $cnt1 = count(split(",",$this->dn)); + $cnt2 = count(split(",",$new_dn)); + if((strstr($new_dn,$this->dn))&&($cnt1<$cnt2)){ + print_red(_("Try to move tree failed. Destination tree is subtree of source tree.")); + }else{ + $baseobject->recursive_move($this->dn, $new_dn); + } + } + $this->dn= $new_dn; + + tabs::save(TRUE); + } + +} + +?> -- 2.30.2