index 373a8147a39159d0bd1fe05a3f0ca3f938a99319..e9b59675fe583568bf80df95c71d288fcec7b878 100644 (file)
class faiProfile extends plugin
{
- /* CLI vars */
- var $cli_summary = "Manage server basic objects";
- var $cli_description = "Some longer text\nfor help";
- var $cli_parameters = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
-
/* attribute list for save action */
var $ignore_account = TRUE;
var $FAIclasses = array(); // Contains classname seperated in an array
var $FAIAllclasses = array(); // Contains all possible Classnames
- var $FAIstate = "";
+ var $FAIstate = "";
+ var $base = "";
+ var $release = "";
+ var $copy_paste_mode= false;
+ var $cut_paste_mode = false;
+
+ var $CopyPasteVars = array("FAIclass","FAIclasses","FAIAllclasses");
function faiProfile($config, $dn= NULL)
{
}
}
- $categories = array("FAIscript","FAItemplate","FAIhook","FAIvariable","FAIpartitionTable","FAIpackageList");
-
- /* Build filter */
- $filter= "";
- foreach ($categories as $cat){
- $filter.= "(objectClass=$cat)";
+ /* Search only in fai tree */
+ $ObjectTypes = array(
+ "FAIpartitionTable" => array("OU"=>"ou=disk," ),
+ "FAIpackageList" => array("OU"=>"ou=packages," ),
+ "FAIscript" => array("OU"=>"ou=scripts," ),
+ "FAIvariable" => array("OU"=>"ou=variables," ),
+ "FAIhook" => array("OU"=>"ou=hooks," ),
+# "FAIprofile" => array("OU"=>"ou=profiles," ),
+ "FAItemplate" => array("OU"=>"ou=templates," ));
+
+ $base= "ou=fai,ou=configs,ou=systems,".$_SESSION['CurrentMainBase'];
+ if($_SESSION['faifilter']['branch']!="main"){
+ $base = $_SESSION['faifilter']['branch'];
}
-
- /* Get ldap connection */
- $base = $_SESSION['faifilter']['base'];
+
+ /* Get ldap connection */
+ $ldap= $this->config->get_ldap_link();
$ldap->cd($base);
$sort = array();
-
- /* search all FAI classes */
- $ldap->search("(|$filter)",array("*"));
- while($attrs = $ldap->fetch()){
-
- /* Sort by categorie */
- foreach($categories as $cat){
- if(in_array($cat,$attrs['objectClass'])){
-
- /* Append entry */
- $this->FAIAllclasses[$attrs['cn'][0]][$cat]=$attrs;
-
- /* Create sort array, because the array above is a multidimensional array, and can't be sorted by php sorting functions*/
- $sort[strtolower($attrs['cn'][0])] = $attrs['cn'][0];
- }
+ /* Capture objects from given base */
+ $result = array();
+ foreach($ObjectTypes as $oc => $data){
+ $ou = $data['OU'].$base;
+
+ $ldap->ls("(objectClass=".$oc.")",$ou,array("cn","objectClass","dn"));
+ while($attrs = $ldap->fetch()){
+ $this->FAIAllclasses[$attrs['cn'][0]][$oc]=$attrs;
+ $sort[strtolower($attrs['cn'][0])] = $attrs['cn'][0];
}
- }
-
+ }
+
/* Sort the sort array */
//ksort($sort);
$ldap = $this->config->get_ldap_link();
$ldap->cd ($this->dn);
$ldap->rmdir_recursive($this->dn);
+ show_ldap_error($ldap->get_error(), _("Removing FAI profile failed"));
$this->handle_post_events("remove");
}
/* Call common method to give check the hook */
$message= plugin::check();
- if(count($this->FAIclasses) == 0){
- $message[]=_("Please assign at least one class to this profile.");
- }
+ if($this->copy_paste_mode){
- if(empty($this->cn)){
- $message[]=_("Please enter a valid name.");
- }
+ /* If this is a new script, check if a script with this name already exists */
+ if(!empty($this->release) && ($this->copy_paste_mode || $this->cut_paste_mode) ){
- $ldap = $this->config->get_ldap_link();
- $ldap->cd($_SESSION['faifilter']['base']);
- $ldap->search("(&(objectClass=FAIprofile)(cn=".$this->cn.")(!cn=".$this->old_cn."))",array("*"));
+ /* Check if current name is already used for fai scripts in selected release */
+ $dn = 'cn='.$this->cn.",ou=profiles,".$this->release;
+ $ldap = $this->config->get_ldap_link();
+ $ldap->cat($dn);
+ if($ldap->count()){
- if($ldap->count()){
- $message[]=_("There is already a profile with this class name defined.");
- }
+ $r =convert_department_dn($this->release);;
+ $message[] = sprintf(_("Can't insert a script named '%s' in '%s' there is already a script with the given name."),$this->cn,$r);
+ }
+ }
+ }else{
+ if(count($this->FAIclasses) == 0){
+ $message[]=_("Please assign at least one class to this profile.");
+ }
+ if(empty($this->cn)){
+ $message[]=_("Please enter a valid name.");
+ }
+
+ $ldap = $this->config->get_ldap_link();
+ $release = "ou=profiles,ou=fai,ou=configs,ou=systems,".$_SESSION['CurrentMainBase'];
+ if($_SESSION['faifilter']['branch']!="main"){
+ $release = "ou=profiles,".$_SESSION['faifilter']['branch'];
+ }
+ $ldap->cd($release);
+ if ($this->old_cn == ""){
+ $ldap->search("(&(objectClass=FAIprofile)(cn=".$this->cn."))",array("*"));
+ } else {
+ $ldap->search("(&(objectClass=FAIprofile)(cn=".$this->cn.")(!cn=".$this->old_cn."))",array("*"));
+ }
+ if($ldap->count()){
+ $message[]=_("There is already a profile with this class name defined.");
+ }
+ }
return ($message);
}
$this->attrs['FAIclass']=trim($this->FAIclass);
- $ldap->cat($this->dn);
+ /* Copy & Paste : Ensure that FAIstate is copied too */
+ if($this->copy_paste_mode && preg_match("/freeze/",$this->FAIstate)){
+ $this->attrs['FAIstate'] = $this->FAIstate;
+ }
+
+ $ldap->cat($this->dn,array("objectClass"));
if($ldap->count()!=0){
/* Write FAIscript to ldap*/
$ldap->cd($this->dn);
$this->cleanup();
-$ldap->modify ($this->attrs);
-
+ $ldap->modify ($this->attrs);
}else{
/* Write FAIscript to ldap*/
$ldap->cd($this->config->current['BASE']);
$ldap->cd($this->dn);
$ldap->add($this->attrs);
}
+ show_ldap_error($ldap->get_error(), _("Saving FAI profile failed"));
+
+ /* Do object tagging */
+ $this->handle_object_tagging();
show_ldap_error($ldap->get_error());
}
+
+
+ /* return copy & paste dialog
+ */
+ function getCopyDialog()
+ {
+ /* Ask for cn */
+ $smarty = get_smarty();
+ $smarty->assign("cn" ,$this->cn);
+ $str = $smarty->fetch(get_template_path("paste_fai_object.tpl",TRUE));
+ $ret = array();
+ $ret['string'] = $str;
+ $ret['status'] = "";
+ return($ret);
+ }
+
+ /* Get posted cn */
+ function saveCopyDialog()
+ {
+ if(isset($_POST['cn'])){
+ $this->cn = $_POST['cn'];
+ }
+ }
}
// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: