From: cajus Date: Thu, 17 Jan 2008 13:44:18 +0000 (+0000) Subject: Moved fai X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=9169b2843e25912293f2c2ef8f96278b52b9fbae;p=gosa.git Moved fai git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8455 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-core/plugins/admin/fai/askClassName.tpl b/gosa-core/plugins/admin/fai/askClassName.tpl deleted file mode 100644 index 7975e1052..000000000 --- a/gosa-core/plugins/admin/fai/askClassName.tpl +++ /dev/null @@ -1,89 +0,0 @@ -
- {$headline} -
-
-

-{t}Adding a new class to the FAI management, requires a class name. You have to specify a unique class name for unique types of FAI classes, while you can use the same class name for different types of FAI classes. In the laste case, FAI will automatically enclose all these different class types to one unique class name.{/t} -
-
-

-

-
-{t}Please use one of the following methods to choose the name for the new FAI class.{/t} -
-
-

-
- - - - - - -
- - - - - - - - - -
- - -

{t}Enter FAI class name manually{/t}

-
  - {t}Class name{/t}  -
-
-
-
- - - - - - - - - - -
- - -

{t}Choose FAI class name from a list of existing classes{/t}

-
  - {t}Class name{/t}  -
-
-
-
- - -

 

- - - diff --git a/gosa-core/plugins/admin/fai/branch_selector.tpl b/gosa-core/plugins/admin/fai/branch_selector.tpl deleted file mode 100644 index addb5a7a2..000000000 --- a/gosa-core/plugins/admin/fai/branch_selector.tpl +++ /dev/null @@ -1,42 +0,0 @@ -
-
-

[F]{t}Branches{/t}

-
-
- - - - -
- {t}Current release{/t}  - -
- - - - -
- {if $allow_create} - - {t}Create new branch{/t} -
- - {t}Create new locked branch{/t} - {else} - {t}Branch{/t} - {t}Create new branch{/t} -
- {t}Freeze{/t} - {t}Create new locked branch{/t} - {/if} - - {if $selectedBranch != "main" && $allow_remove} -
- - {t}Delete current release{/t} - {/if} -
-
- diff --git a/gosa-core/plugins/admin/fai/class_FAI.inc b/gosa-core/plugins/admin/fai/class_FAI.inc deleted file mode 100644 index 0365d50e9..000000000 --- a/gosa-core/plugins/admin/fai/class_FAI.inc +++ /dev/null @@ -1,920 +0,0 @@ -get_ldap_link(); - $ldap->cd($config->current['BASE']); - $res = array(); - $tmp = array(); - - if(!FAI::is_release_department($Current_DN)) { - return($res); - } - - /* Collect some basic informations and initialize some variables */ - $base_release = FAI::get_release_dn($Current_DN); - $previous_releases = array_reverse(FAI:: get_previous_releases_of_this_release($base_release,true)); - - /* We must also include the given release dn */ - $previous_releases[] = $base_release; - - /* Walk through all releases */ - foreach($previous_releases as $release){ - - /* Get fai departments */ - $deps_to_search = FAI::get_FAI_departments($release); - - /* For every single department (ou=hoos,ou ..) */ - foreach($deps_to_search as $fai_base){ - - /* Ldap search for fai classes specified in this release */ - $attributes = array("dn","objectClass","FAIstate","cn"); - $res_tmp = get_list($filter,"fai",$fai_base,$attributes,GL_SUBSEARCH | GL_SIZELIMIT); - - /* check the returned objects, and add/replace them in our return variable */ - foreach($res_tmp as $attr){ - - $buffer = array(); - $name = preg_replace("/".normalizePreg($release)."/i","",$attr['dn']); - - if(isset($attr['FAIstate'][0])){ - if(preg_match("/removed$/",$attr['FAIstate'][0])){ - if(isset($res[$name])){ - unset($res[$name]); - } - continue; - } - } - - /* In detailed mode are some additonal informations visible */ - if($detailed){ - - /* Create list of parents */ - if(isset($res[$name])){ - $buffer = $res[$name]; - $buffer['parents'][] = $res[$name]['dn']; - }else{ - $buffer['parents'] = array(); - } - - /* Append objectClass to resulsts */ - foreach($attributes as $val){ - if(isset($attr[$val])){ - $buffer[$val] = $attr[$val]; - } - } - unset($buffer['objectClass']['count']); - } - - /* Add this object to our list */ - $buffer['dn'] = $attr['dn']; - $res[$name] = $buffer; - } - } - } - return($res); - } - - - /* Return all relevant FAI departments */ - static function get_FAI_departments($suffix = "") - { - $arr = array("hooks","scripts","disk","packages","profiles","templates","variables"); - $tmp = array(); - if(preg_match("/^,/",$suffix)){ - $suffix = preg_replace("/^,/","",$suffix); - } - foreach($arr as $name){ - if(empty($suffix)){ - $tmp[$name] = "ou=".$name; - }else{ - $tmp[$name] = "ou=".$name.",".$suffix; - } - } - return($tmp); - } - - - /* Return all releases within the given base */ - static function get_all_releases_from_base($dn,$appendedName=false) - { - global $config; - - if(!preg_match("/".normalizePreg(get_ou('faiou'))."/",$dn)){ - $base = get_ou('faiou').$dn; - }else{ - $base = $dn; - } - $res = array(); - - $ldap = $config->get_ldap_link(); - $ldap->cd($base); - $ldap->search("(objectClass=FAIbranch)",array("ou","dn")); - while($attrs = $ldap->fetch()){ - if($appendedName){ - $res[$attrs['dn']] = convert_department_dn(preg_replace("/,".normalizePreg(get_ou('faiou')).".*$/","",$attrs['dn'])); - }else{ - $res[$attrs['dn']] = $attrs['ou'][0]; - } - } - return($res); - } - - - /* Add this object to list of objects, that must be checked for release saving */ - static function prepare_to_save_FAI_object($Current_DN,$objectAttrs,$removed = false) - { - /* Get ldap object */ - global $config; - $addObj['Current_DN'] = $Current_DN; - $addObj['objectAttrs']= $objectAttrs; - $addObj['removed'] = $removed; - $addObj['diff'] = TRUE; - - if(!$removed){ - $ldap = $config->get_ldap_link(); - $ldap->cd($config->current['BASE']); - - /* Get some basic informations */ - $parent_obj = FAI::get_parent_release_object($Current_DN); - if(!empty($parent_obj)){ - $ldap->cat($parent_obj,array("*")); - $attrs = FAI:: prepare_ldap_fetch_to_be_saved($ldap->fetch()); - - if(!FAI::array_diff_FAI( $attrs,$objectAttrs)){ - $addObj['diff'] = FALSE; - } - } - } - $FAI_objects_to_save = session::get('FAI_objects_to_save') ; - $FAI_objects_to_save[$Current_DN] = $addObj; - session::set('FAI_objects_to_save',$FAI_objects_to_save); - } - - - /* Detect differences in attribute arrays */ - static function array_diff_FAI($ar1,$ar2) - { - - if((!isset($ar1['description'])) || (isset($ar1['description']) && (count($ar1['description']) == 0))){ - $ar1['description'] = ""; - } - if((!isset($ar2['description'])) || (isset($ar2['description']) && (count($ar2['description']) == 0))){ - $ar2['description'] = ""; - } - - if(count($ar1) != count($ar2)) { - return (true); - } - - foreach($ar1 as $key1 => $val1){ - - if((is_array($val1)) && (count($val1)==1)){ - $ar1[$key1] = $val1[0]; - } - - if((is_array($ar2[$key1])) && (count($ar2[$key1])==1)){ - $val1 = $val1[0]; - $ar2[$key1] = $ar2[$key1][0]; - } - } - ksort($ar1); - ksort($ar2); - if(count( array_diff($ar1,$ar2)) || FAI::arr_diff($ar1,$ar2)){ - return(true); - }else{ - return(false); - } - } - - - static function arr_diff($ar1,$ar2) - { - foreach($ar1 as $ak1 => $av1){ - if(!isset($ar2[$ak1]) || (!($av1 === $ar2[$ak1]))){ - return(true); - }elseif(is_array($av1)){ - return(FAI::arr_diff($av1,$ar2[$ak1])); - } - } - return(FALSE); - } - - - - - /* check which objects must be saved, and save them */ - static function save_release_changes_now() - { - /* Variable init*/ - $to_save = array(); - - /* check which objects must be saved */ - $FAI_objects_to_save = session::get('FAI_objects_to_save'); - foreach($FAI_objects_to_save as $Current_DN => $object){ - if($object['diff']){ - $sub_name = $Current_DN; - while(isset($FAI_objects_to_save[$sub_name])){ - $to_save[strlen($sub_name)][$sub_name] = $FAI_objects_to_save[$sub_name]; - unset($FAI_objects_to_save[$sub_name]); - $sub_name = preg_replace('/^[^,]+,/', '', $sub_name); - } - } - } - session::set('FAI_objects_to_save',$FAI_objects_to_save); - - /* Sort list of objects that must be saved, and ensure that - container objects are safed, before their childs are saved */ - ksort($to_save); - $tmp = array(); - foreach($to_save as $SubObjects){ - foreach($SubObjects as $object){ - $tmp[] = $object; - } - } - $to_save = $tmp; - - /* Save objects and manage the correct release behavior*/ - foreach($to_save as $save){ - - $Current_DN = $save['Current_DN']; - $removed = $save['removed']; - $objectAttrs= $save['objectAttrs']; - - /* Get ldap object */ - global $config; - $ldap = $config->get_ldap_link(); - $ldap->cd($config->current['BASE']); - - /* Get some basic informations */ - $base_release = FAI::get_release_dn($Current_DN); - $sub_releases = FAI:: get_sub_releases_of_this_release($base_release,true); - $parent_obj = FAI::get_parent_release_object($Current_DN); - $following_releases = FAI:: get_sub_releases_of_this_release($base_release,true); - - /* Check if given dn exists or if is a new entry */ - $ldap->cat($Current_DN); - if(!$ldap->count()){ - $is_new = true; - }else{ - $is_new = false; - } - - /* if parameter removed is true, we have to add FAIstate to the current attrs - FAIstate should end with ...|removed after this operation */ - if($removed ){ - $ldap->cat($Current_DN); - - /* Get current object, because we must add the FAIstate ...|removed */ - if((!$ldap->count()) && !empty($parent_obj)){ - $ldap->cat($parent_obj); - } - - /* Check if we have found a suiteable object */ - if(!$ldap->count()){ - echo "Error can't remove this object ".$Current_DN; - return; - }else{ - - /* Set FAIstate to current objectAttrs */ - $objectAttrs = FAI:: prepare_ldap_fetch_to_be_saved($ldap->fetch()); - if(isset($objectAttrs['FAIstate'][0])){ - if(!preg_match("/removed$/",$objectAttrs['FAIstate'][0])){ - $objectAttrs['FAIstate'][0] .= "|removed"; - } - }else{ - $objectAttrs['FAIstate'][0] = "|removed"; - } - } - } - - /* Check if this a leaf release or not */ - if(count($following_releases) == 0 ){ - - /* This is a leaf object. It isn't inherited by any other object */ - if(DEBUG_FAI_FUNC) { - echo "Saving directly, is a leaf object
".$Current_DN; - print_a($objectAttrs); - } - FAI::save_FAI_object($Current_DN,$objectAttrs); - }else{ - - /* This object is inherited by some sub releases */ - - /* Get all releases, that inherit this object */ - $r = get_following_releases_that_inherit_this_object($Current_DN); - - /* Get parent object */ - $ldap->cat($parent_obj); - $parent_attrs = FAI:: prepare_ldap_fetch_to_be_saved($ldap->fetch()); - - /* New objects require special handling */ - if($is_new){ - - /* check if there is already an entry named like this, - in one of our parent releases */ - if(!empty($parent_obj)){ - if(DEBUG_FAI_FUNC) { - echo "There is already an entry named like this.
"; - - echo "Saving main object".$Current_DN; - print_a($objectAttrs); - } - FAI::save_FAI_object($Current_DN,$objectAttrs); - - foreach($r as $key){ - if(DEBUG_FAI_FUNC) { - echo "Saving parent to following release ".$key; - print_a($parent_attrs); - } - FAI::save_FAI_object($key,$parent_attrs); - } - }else{ - - if(DEBUG_FAI_FUNC) { - echo "Saving main object".$Current_DN; - print_a($objectAttrs); - } - FAI::save_FAI_object($Current_DN,$objectAttrs); - - if(isset($objectAttrs['FAIstate'])){ - $objectAttrs['FAIstate'] .= "|removed"; - }else{ - $objectAttrs['FAIstate'] = "|removed"; - } - - foreach($r as $key ){ - if(DEBUG_FAI_FUNC) { - echo "Create an empty placeholder in follwing release ".$key; - print_a($objectAttrs); - } - FAI::save_FAI_object($key,$objectAttrs); - } - } - }else{ - - /* check if we must patch the follwing release */ - if(!empty($r)){ - foreach($r as $key ){ - if(DEBUG_FAI_FUNC) { - echo "Copy current objects original attributes to next release ".$key; - print_a($parent_attrs); - } - FAI::save_FAI_object($key,$parent_attrs); - } - } - - if(DEBUG_FAI_FUNC) { - echo "Saving current object".$parent_obj; - print_a($objectAttrs); - } - FAI::save_FAI_object($parent_obj,$objectAttrs); - - if(($parent_obj != $Current_DN)){ - msg_dialog::display(_("Error"), sprintf(_("Error, following objects should be equal '%s' and '%s'"),$parent_obj,$Current_DN), ERROR_DIALOG); - } - } - } - } - session::set('FAI_objects_to_save',array()); - } - - - /* this function will remove all unused (deleted) objects, - that have no parent object */ - static function clean_up_releases($Current_DN) - { - global $config; - $ldap = $config->get_ldap_link(); - $ldap->cd($config->current['BASE']); - - /* Collect some basic informations and initialize some variables */ - $base_release = FAI::get_release_dn($Current_DN); - $previous_releases = array_reverse(FAI:: get_previous_releases_of_this_release($base_release,true)); - $Kill = array(); - $Skip = array(); - - /* We must also include the given release dn */ - $previous_releases[] = $base_release; - - /* Walk through all releases */ - foreach($previous_releases as $release){ - - /* Get fai departments */ - $deps_to_search = FAI::get_FAI_departments($release); - - /* For every single department (ou=hoos,ou ..) */ - foreach($deps_to_search as $fai_base){ - - /* Ldap search for fai classes specified in this release */ - $ldap->cd($fai_base); - $ldap->search("(objectClass=FAIclass)",array("dn","objectClass","FAIstate")); - - /* check the returned objects, and add/replace them in our return variable */ - while($attr = $ldap->fetch()){ - - $buffer = array(); -# $name = str_ireplace($release,"",$attr['dn']); - $name = preg_replace("/".normalizePreg($release)."/i","",$attr['dn']); - - if(isset($attr['FAIstate'][0])&&(preg_match("/removed$/",$attr['FAIstate'][0]))){ - - /* Check if this object is required somehow */ - if(!isset($Skip[$name])){ - $Kill[$attr['dn']] = $attr['dn']; - } - }else{ - - /* This object is required (not removed), so do not - delete any following sub releases of this object */ - $Skip[$name] = $attr['dn']; - } - } - } - } - return($Kill); - } - - - /* Remove numeric index and 'count' from ldap->fetch result */ - static function prepare_ldap_fetch_to_be_saved($attrs) - { - foreach($attrs as $key => $value){ - if(is_numeric($key) || ($key == "count") || ($key == "dn")){ - unset($attrs[$key]); - } - if(is_array($value) && isset($value['count'])){ - unset($attrs[$key]['count']); - } - } - return($attrs); - } - - - /* Save given attrs to specified dn*/ - static function save_FAI_object($dn,$attrs) - { - global $config; - $ldap = $config->get_ldap_link(); - $ldap->cd($config->current['BASE']); - $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $dn)); - $ldap->cd($dn); - - $ldap->cat($dn,array("dn")); - if($ldap->count()){ - - /* Remove FAIstate*/ - if(!isset($attrs['FAIstate'])){ - $attrs['FAIstate'] = array(); - } - - $ldap->modify($attrs); - }else{ - - /* Unset description if empty */ - if(empty($attrs['description'])){ - unset($attrs['description']); - } - - $ldap->add($attrs); - } - show_ldap_error($ldap->get_error(),sprintf(_("Release management failed, can't save '%s'"),$dn)); - } - - - /* Return FAIstate freeze branch or "" for specified release department */ - static function get_release_tag($dn) - { - global $config; - $ldap = $config->get_ldap_link(); - $ldap->cd($dn); - $ldap->cat($dn,array("FAIstate")); - - if($ldap->count()){ - - $attr = $ldap->fetch(); - if(isset($attr['FAIstate'][0])){ - if(preg_match("/freeze/",$attr['FAIstate'][0])){ - return("freeze"); - }elseif(preg_match("/branch/",$attr['FAIstate'][0])){ - return("branch"); - } - } - } - return(""); - } - - - static function get_following_releases_that_inherit_this_object($dn) - { - global $config; - $ldap = $config->get_ldap_link(); - $ldap->cd($config->current['BASE']); - - $ret = array(); - - /* Get base release */ - $base_release = FAI::get_release_dn($dn); - - /* Get previous release dns */ - $sub_releases = FAI:: get_sub_releases_of_this_release($base_release); - - /* Get dn suffix. Example "FAIvairableEntry=keksdose,FAIvariable=Keksregal," */ -# $dn_suffix = str_ireplace($base_release,"",$dn); - $dn_suffix = preg_replace("/".normalizePreg($base_release)."/i","",$dn); - - /* Check if given object also exists whitin one of these releases */ - foreach($sub_releases as $p_release => $name){ - - $check_dn = $dn_suffix.$p_release; - - $ldap->cat($check_dn,array("dn","objectClass")); - - if($ldap->count()){ - //return($ret); - }else{ - $ret[$check_dn]=$check_dn; - } - } - return($ret); - } - - - /* Get previous version of the object dn */ - static function get_parent_release_object($dn,$include_myself=true) - { - global $config; - $ldap = $config->get_ldap_link(); - $ldap->cd($config->current['BASE']); - $previous_releases= array(); - - /* Get base release */ - $base_release = FAI::get_release_dn($dn); - if($include_myself){ - $previous_releases[] = $base_release; - } - - /* Get previous release dns */ - $tmp = FAI:: get_previous_releases_of_this_release($base_release,true); - foreach($tmp as $release){ - $previous_releases[] = $release; - } - - /* Get dn suffix. Example "FAIvairableEntry=keksdose,FAIvariable=Keksregal," */ -# $dn_suffix = str_ireplace($base_release,"",$dn); - $dn_suffix = preg_replace("/".normalizePreg($base_release)."/i","",$dn); - - /* Check if given object also exists whitin one of these releases */ - foreach($previous_releases as $p_release){ - $check_dn = $dn_suffix.$p_release; - $ldap->cat($check_dn,array("dn","objectClass")); - - if($ldap->count()){ - return($check_dn); - } - } - return(""); - } - - - /* return release names of all parent releases */ - static function get_previous_releases_of_this_release($dn,$flat) - { - global $config; - $ldap = $config->get_ldap_link(); - $ldap->cd($config->current['BASE']); - $ret = array(); - - /* Explode dns into pieces, to be able to build parent dns */ - $dns_to_check = gosa_ldap_explode_dn(preg_replace("/".normalizePreg(",".$config->current['BASE'])."/i","",$dn)); - - if(!is_array($dns_to_check)){ - return; - } - - /* Unset first entry which represents the given dn */ - unset($dns_to_check['count']); - unset($dns_to_check[key($dns_to_check)]); - - /* Create dns addresses and check if this dn is a release dn */ - $id = 0; - while(count($dns_to_check)){ - - /* build parent dn */ - $new_dn = ""; - foreach($dns_to_check as $part){ - $new_dn .= $part.","; - } - $new_dn .= $config->current['BASE']; - - /* check if this dn is a release */ - if(FAI::is_release_department($new_dn)){ - if($flat){ - $ret[$id] = $new_dn; - }else{ - $ret = array($new_dn=>$ret); - } - $id ++; - }else{ - return($ret); - } - reset($dns_to_check); - unset($dns_to_check[key($dns_to_check)]); - } - return($ret); - } - - - /* This function returns all sub release names, recursivly */ - static function get_sub_releases_of_this_release($dn,$flat = false) - { - global $config; - $res = array(); - $ldap = $config->get_ldap_link(); - $ldap->cd($config->current['BASE']); - $ldap->ls("(objectClass=FAIbranch)",$dn,array("objectClass","dn","ou")); - while($attr = $ldap->fetch()){ - - /* Append department name */ - if($flat){ - $res[$attr['dn']] = $attr['ou'][0]; - }else{ - $res[$attr['dn']] = array(); - } - - /* Get sub release departments of this department */ - if(in_array("FAIbranch",$attr['objectClass'])) { - if($flat){ - $tmp = FAI:: get_sub_releases_of_this_release($attr['dn'],$flat); - foreach($tmp as $dn => $value){ - $res[$dn]=$value; - } - }else{ - $res[$attr['dn']] = FAI:: get_sub_releases_of_this_release($attr['dn']); - } - } - } - return($res); - } - - - /* Check if the given department is a release department */ - static function is_release_department($dn) - { - global $config; - $ldap = $config->get_ldap_link(); - $ldap->cd($config->current['BASE']); - $ldap->cat($dn,array("objectClass","ou")); - - /* Check objectClasses and name to check if this is a release department */ - if($ldap->count()){ - $attrs = $ldap->fetch(); - - $ou = ""; - if(isset($attrs['ou'][0])){ - $ou = $attrs['ou'][0]; - } - - if((in_array("FAIbranch",$attrs['objectClass'])) || ($ou == "fai")){ - return($attrs['dn']); - } - } - return(false); - } - - - /*! \brief Create a new FAI branch. - * @param $sourcedn String The source release dn - * @param $destinationdn String The destination dn - * @param $destinationName String The name of the new release - * @param $type String The release type (freeze/branch) - * @param $is_first Boolean Use to identify the first func. call when recursivly called. - * @param $depth Integer Current depth of recursion. - */ - function copy_FAI_resource_recursive($sourcedn,$destinationdn,$destinationName,$type="branch",$is_first = true,$depth=0) - { - global $config; - error_reporting(E_ALL | E_STRICT); - $ldap = $config->get_ldap_link(); - $basedn = $config->current['BASE']; - $delarray = array(); - - /* The following code will output a status string - * for each handled object, in a seperate iframe. - */ - - - /* Display current action information. - */ - if($is_first){ - echo "

".sprintf(_("Creating copy of %s"),"".LDAP::fix($sourcedn)."")."

"; - }else{ - if(preg_match("/^ou=/",$sourcedn)){ - echo "

"._("Processing")." ".LDAP::fix($destinationdn)."

"; - }else{ - $tmp = split(",",$sourcedn); - echo " "._("Object").": "; - $deststr = LDAP::fix($destinationdn); - if(strlen($deststr) > 96){ - $deststr = substr($deststr,0,96)."..."; - } - echo $deststr."
"; - } - } - /* .. immediately display infos */ - flush(); - - /* Check if destination entry already exists - */ - $ldap->cat($destinationdn); - if($ldap->count()){ - echo _("Could not create new release, the destination dn is already in use."); - return; - }else{ - - $ldap->clearResult(); - - /* Get source entry - * if it does not exist, abort here. - */ - $ldap->cd($basedn); - $ldap->cat($sourcedn); - $attr = $ldap->fetch(); - if((!$attr) || (count($attr)) ==0) { - echo _("Error while fetching source dn - aborted!"); - return; - } - - /* The current object we want to create is an department. - * Create the department and add the FAIbranch tag. - */ - if(in_array("organizationalUnit",$attr['objectClass'])){ - $attr['dn'] = LDAP::convert($destinationdn); - $ldap->cd($basedn); - $ldap->create_missing_trees($destinationdn); - $ldap->cd($destinationdn); - - /* If is first entry, append FAIbranch to department entry */ - if($is_first){ - $ldap->cat($destinationdn); - $attr= $ldap->fetch(); - /* Filter unneeded informations */ - foreach($attr as $key => $value){ - if(is_numeric($key)) unset($attr[$key]); - if(isset($attr[$key]['count'])){ - if(is_array($attr[$key])){ - unset($attr[$key]['count']); - } - } - } - - unset($attr['count']); - unset($attr['dn']); - - /* Add marking attribute */ - $attr['objectClass'][] = "FAIbranch"; - - /* Add this entry */ - $ldap->modify($attr); - } - }else{ - - /* Replicate all relevant FAI objects here. - * FAI objects, Apps and Mimetypes. - * Get all attributes as binary value, to ensure that Icon, File template aso - * are created correctly. - */ - foreach($attr as $key => $value){ - - if(in_array($key ,array("gotoLogonScript", "gosaApplicationIcon","gotoMimeIcon"))){ - $sr= ldap_read($ldap->cid, LDAP::fix($sourcedn), "$key=*", array($key)); - $ei= ldap_first_entry($ldap->cid, $sr); - if ($tmp= @ldap_get_values_len($ldap->cid, $ei,$key)){ - $attr[$key] = $tmp; - } - } - - if(is_numeric($key)) unset($attr[$key]); - if(isset($attr[$key]['count'])){ - if(is_array($attr[$key])){ - unset($attr[$key]['count']); - } - } - } - unset($attr['count']); - unset($attr['dn']); - - /* Add entry - */ - $ldap->cd($destinationdn); - $ldap->cat($destinationdn); - - $a = $ldap->fetch(); - if(!count($a)){ - $ldap->add($attr); - } - - if($ldap->error != "Success"){ - - /* Some error occurred */ - print "---------------------------------------------"; - print $ldap->get_error()."
"; - print $sourcedn."
"; - print $destinationdn."
"; - print_a( $attr); - exit(); - } - } - } - - echo "" ; - - /* Prepare for recursive copy. - * Get all object within the source dn and - * call the recursive copy for each. - */ - $ldap->ls ("(objectClass=*)",$sourcedn); - while ($ldap->fetch()){ - $deldn= $ldap->getDN(); - $delarray[$deldn]= strlen($deldn); - } - asort ($delarray); - reset ($delarray); - $depth ++; - foreach($delarray as $dn => $bla){ - if($dn != $destinationdn){ - $ldap->cd($basedn); - $item = $ldap->fetch($ldap->cat($dn)); - if(!in_array("FAIbranch",$item['objectClass'])){ - FAI::copy_FAI_resource_recursive($dn,str_replace($sourcedn,$destinationdn,$dn),$destinationName,$type,false,$depth); - } - } - } - if($is_first){ - echo "

 

"; - } - } - - - - /* This function returns the dn of the object release */ - static function get_release_dn($Current_DN) - { - global $config; - $ldap = $config->get_ldap_link(); - $ldap->cd($config->current['BASE']); - - /* Split dn into pices */ - $dns_to_check = gosa_ldap_explode_dn(preg_replace("/".normalizePreg(",".$config->current['BASE'])."/i","",$Current_DN)); - - if(!is_array($dns_to_check)){ - return; - } - - /* Use dn pieces, to create sub dns like - ou=test,ou=1,ou=0... - ou=1,ou=0... - ou=0... - To check which dn is our release container. - */ - unset($dns_to_check['count']); - while(count($dns_to_check)){ - - /* Create dn */ - $new_dn = ""; - foreach($dns_to_check as $part){ - $new_dn .= $part.","; - } - $new_dn .= $config->current['BASE']; - - /* Check if this dn is a release dn */ - if(FAI::is_release_department($new_dn)){ - return($new_dn); - } - - /* Remove first element of dn pieces */ - reset($dns_to_check); - unset($dns_to_check[key($dns_to_check)]); - } - return(""); - } -} - - - - -// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: -?> diff --git a/gosa-core/plugins/admin/fai/class_askClassName.inc b/gosa-core/plugins/admin/fai/class_askClassName.inc deleted file mode 100644 index c7e38adb5..000000000 --- a/gosa-core/plugins/admin/fai/class_askClassName.inc +++ /dev/null @@ -1,172 +0,0 @@ - "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,$ui,$objectClass) - { - $this->ui = $ui; - $this->objectClass = $objectClass; - plugin::plugin ($config, $dn); - if(!session::is_set('CurrentMainBase')){ - session::set('CurrentMainBase',$this->config->current['BASE']); - } - } - - function execute() - { - /* Call parent execute */ - plugin::execute(); - - /* Fill templating stuff */ - $smarty = get_smarty(); - $display= ""; - - /* The faifilter contais - * The base for all fai objects - */ - $faifilter = session::get('faifilter'); - - /* First search for every ou, in given fai base - * With a second search detect all object that belong to the different ous. - */ - - $base = get_ou('faiou').session::get('CurrentMainBase'); - if($faifilter['branch'] != "main"){ - $base = $faifilter['branch']; - } - $ldap = $this->config->get_ldap_link(); - - $res= get_list("(&(objectClass=organizationalUnit)(!(objectClass=FAIbranch)))", "fai", $base, - array("cn","description","objectClass"), GL_SIZELIMIT ); - - $delete = array(); - $used = array(); - foreach($res as $objecttypes){ - $res2= get_list("(objectClass=*)", "fai", $objecttypes['dn'], - array("cn","description","objectClass","FAIclass","FAIstate"), GL_SIZELIMIT | GL_CONVERT ); - foreach($res2 as $object){ - - /* skip class names with this name */ - if(in_array($this->objectClass,$object['objectClass']) || in_array("FAIprofile",$object['objectClass'])){ - if(isset($object['FAIstate'][0]) && preg_match("/removed$/",$object['FAIstate'][0])){ - continue; - } - $delete[] = $object['cn'][0]; - } - - /* Skip profiles */ - if(!in_array("FAIprofile",$object['objectClass'])){ - if(isset($object['cn'])){ - $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 bundle.");break; - case "FAIscript" : $str =_("Create new FAI object - script bundle.");break; - case "FAIvariable" : $str =_("Create new FAI object - variable bundle.");break; - case "FAIhook" : $str =_("Create new FAI object - hook bundle.");break; - case "FAIprofile" : $str =_("Create new FAI object - profile.");break; - case "FAItemplate" : $str =_("Create new FAI object - template.");break; - default : $str =_("Create new 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 for this type - * of objectClass, we only can create a new one, disable selectBox - */ - if(count ($used)==0){ - $smarty->assign("ClassNamesAvailable", " disabled "); - $smarty->assign("grey", 'style="color:#C0C0C0"'); - }else{ - $smarty->assign("ClassNamesAvailable", ""); - $smarty->assign("grey", ""); - } - ksort($used); - $smarty->assign("ClassNames", $used); - $smarty->assign("ClassName", $this->ClassName); - $display.= $smarty->fetch(get_template_path('askClassName.tpl', TRUE)); - return($display); - } - - /* Get posts and set class name - */ - function save_object() - { - if(isset($_POST['classSelector']) && $_POST['classSelector'] == 1 - && isset($_POST['edit_continue'])){ - $this->ClassName = $_POST['UseTextInputName']; - $this->ClassAlreadyExists = true; - } - - if(isset($_POST['classSelector']) && $_POST['classSelector'] == 2 - && isset($_POST['edit_continue'])){ - $this->ClassAlreadyExists = false; - $this->ClassName = $_POST['SelectedClass']; - } - } - - /* Check given class name - */ - function check() - { - /* Call common method to give check the hook */ - $message= plugin::check(); - - if($this->ClassName != preg_replace("/ /","",trim($this->ClassName))){ - $message[] = _("Spaces are not allowed within class names."); - } - - 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/gosa-core/plugins/admin/fai/class_debconfTemplate.inc b/gosa-core/plugins/admin/fai/class_debconfTemplate.inc deleted file mode 100644 index d781321ec..000000000 --- a/gosa-core/plugins/admin/fai/class_debconfTemplate.inc +++ /dev/null @@ -1,428 +0,0 @@ -set_language($language); - $this->set_package($package); - } - - - function set_package($package) - { - $this->package= $package; - } - - - function set_template_directory($directory) - { - if (is_dir($directory) && is_readable($directory)){ - $this->template_directory = $directory; - return TRUE; - } - - $this->template_directory= ""; - return FALSE; - } - - - function set_language($language) - { - $this->language= $language; - } - - - function load() - { - if( TRUE === $this->has_template() ) { - - /* Try to load package based template file */ - $this->template= array(); - - /* Read template array */ - $post_name = 0; - $langcode = $this->language.".UTF-8"; - $in_description = FALSE; - $got_local_description = FALSE; - - /* get filename */ - $filename= preg_replace("/\/+/", "/", $this->template_directory."/".$this->package.".templates"); - - /* Check if file is readable */ - if (!is_file($filename) || !is_readable($filename)){ - return(FALSE); - } - - /* Open file and read content line by line */ - $fh= fopen($filename, 'r'); - - /* While the file handle is valid && there is still data to read -> parse configuration file */ - while ($fh && !feof($fh)){ - $line= fgets($fh, 1024); - - /* Reset description flag */ - if ($in_description && !preg_match("/^ /", $line)){ - $in_description= FALSE; - } - - /* Template header */ - if (preg_match("/^Template: /", $line)){ - $post_name ++; - $name= trim(preg_replace("/^Template: (.*)$/", "\\1", $line)); - $this->template[$post_name]['Name'] = $name; - $this->template[$post_name]['Default'] =""; - - $got_local_description= FALSE; - continue; - } - - /* Get type */ - if (preg_match("/^Type: /", $line)){ - $type= trim(preg_replace("/^Type: (.*)$/", "\\1", $line)); - $this->template[$post_name]['Type']= $type; - continue; - } - - /* Get default */ - if (preg_match("/^Default: /", $line)){ - $this->template[$post_name]['Default']= ""; - $default= trim(preg_replace("/^Default: (.*)$/", "\\1", $line)); - $this->template[$post_name]['Default']= $default; - continue; - } - - /* Get description */ - if (!$got_local_description && preg_match("/^Description: /", $line)){ - $this->template[$post_name]['Description']= ""; - $description= trim(preg_replace("/^Description: (.*)$/", "\\1", $line)); - $this->template[$post_name]['Topic']= $description; - $this->template[$post_name]['Description']= ""; - $in_description= TRUE; - continue; - } - - /* Fill description */ - if (!$got_local_description && $in_description){ - $description= preg_replace("/^ (.*)$/", "\\1", $line); - $this->template[$post_name]['Description'].= $description; - continue; - } - - /* Get local description */ - if (preg_match("/^Description-$langcode: /", $line)){ - $description= trim(preg_replace("/^Description-$langcode: (.*)$/", "\\1", $line)); - $this->template[$post_name]['Topic']= $description; - $in_description= TRUE; - $got_local_description= TRUE; - $this->template[$post_name]['Description']= ""; - continue; - } - - /* Fill local description */ - if ($got_local_description && $in_description){ - $description= preg_replace("/^ (.*)$/", "\\1", $line); - $this->template[$post_name]['Description'].= $description; - continue; - } - - /* Get native choices */ - if (preg_match("/^Choices: /", $line)){ - $type= trim(preg_replace("/^Choices: (.*)$/", "\\1", $line)); - $this->template[$post_name]['Choices']= $type; - } - - /* Get local choices */ - if (preg_match("/^Choices-$langcode: /", $line)){ - $type= trim(preg_replace("/^Choices-$langcode: (.*)$/", "\\1", $line)); - $this->template[$post_name]['Choices-local']= $type; - } - - } - - fclose($fh); - $this->loaded_template= TRUE; - - $tmp= array(); - foreach($this->template as $post_name => $template){ - $template['post_name'] = "post_".$post_name; - $tmp[] = $template; - } - $this->template = $tmp; - - return (TRUE); - } - - $this->loaded_template= FALSE; - return (FALSE); - } - - - function has_template() - { - /* Reject requests, if parameters are not set */ - if ($this->package == "" || $this->template_directory == ""){ - return (FALSE); - } - $filename= preg_replace("/\/+/", "/", $this->template_directory."/".$this->package.".templates"); - return (is_file($filename) && is_readable($filename)); - } - - - /* Check if some fields are posted */ - function PostCheck() - { - /* Walk through all template variables */ - foreach($this->template as $post_name => $entry){ - - /* Check if this var is set*/ - if(isset($_POST[$entry['post_name']])){ - - /* special handling for arrays */ - if(is_array($_POST[$entry['post_name']])){ - $str = ""; - foreach($_POST[$entry['post_name']] as $val){ - $str.= $val.", "; - } - $str = preg_replace("/\,\ $/","",$str); - $this->template[$post_name]['Default'] = $str; - }else{ - $this->template[$post_name]['Default'] = $_POST[$entry['post_name']]; - } - } - } - - foreach($this->template as $post_name => $entry){ - if(isset($_POST["multi-".$entry['post_name']])){ - $this->template[$post_name]['Default']= ""; - foreach($_POST as $name => $value){ - if(preg_match("/".$entry['post_name']."-multi-/",$name)){ - $this->template[$post_name]['Default'] .= $value.", "; - } - } - $this->template[$post_name]['Default'] = preg_replace("/, $/","",$this->template[$post_name]['Default']); - } - } - - - } - - - /* This funtion sets the defualt value */ - function SetDefault($var,$val) - { - if ($this->loaded_template) { - foreach($this->template as $key => $tmp){ - if($tmp['Name'] == $var ){ - $this->template[$key]['Default'] = $val; - } - } - } - } - - - /* Display all possible options in html*/ - function get_dialog() - { - if ($this->loaded_template) { - $result= ""; - - foreach ($this->template as $post_name => $entry){ - - $types= array("boolean" => "", "multiselect" => "", "note" => "", - "password" => "", "select" => "", "string" => "", "text" => "", "title" => ""); - - /* Check if type is available */ - if ((isset($entry['Type']))&&(isset($types[$entry['Type']]))){ - - /* Produce type specific output */ - $fn= "render_".$entry['Type']; - $str = $this->$fn($entry); - if(!empty($str)){ - $result.=$str.""; - } - } else { - //php_error(E_WARNING, "An unknown type has been specified in the debconf template. Please fix."); - } - } - - - $result .= "

 

"; - return ($result); - } else { - return _("This package has no debconf options."); - } - } - - - function render_boolean($data) - { - - $post_name= $data['post_name']; - $result=" - - -

".$data['Topic']."

".$data['Description']." - - "; - - foreach(array("true","false") as $value){ - if($data['Default'] == $value){ - $result.=""._($value); - }else{ - $result.=""._($value); - } - $result.="
"; - } - - $result.= " - - - "; - - return ($result); - } - - - function render_multiselect($data) - { - $post_name= $data['post_name']; - if (preg_match('/\$\{/', $data['Choices'])){ - $result= $this->render_string($data); - } else { - $choices= ""; - foreach (split(", ", $data['Choices']) as $choice){ - $choices[]= $choice; - } - - - $result=" - - -

".$data['Topic']."

".$data['Description']." - - - - "; - - $defs = split(", ",$data['Default']); - foreach($choices as $value){ - if(in_array($value,$defs)){ - $result.="\n".$value."
"; - }else{ - $result.="\n".$value."
"; - } - } - - $result .= " - - "; - } - - return ($result); - } - - - function render_note($data) - { - /* Ignore notes, they do not makes sense, since we don't get any - chance to test entered values... */ - return (""); - } - - - function render_password($data) - { - $result= ""; - $result.= ""; - $result.= "

".$data['Topic']."

".$data['Description']." 

"; - $result.= $data['Description']; - $result.= ""; - - return ($result); - } - - - function render_select($data) - { - $post_name= $data['post_name']; - - if (preg_match('/\$\{/', $data['Choices'])){ - $choices= array("Need to use some text..."); - } else { - $choices= ""; - foreach (split(", ", $data['Choices']) as $choice){ - $choices[]= $choice; - } - } - - - $result=" - - - -

".$data['Topic']."

".$data['Description']." - - - "; - - foreach($choices as $value){ - if($data['Default'] == $value){ - $result.="\n".htmlentities($value)."
"; - }else{ - $result.="\n".htmlentities($value)."
"; - } - } - - $result.= " - - - - "; - - return ($result); - } - - - function render_string($data) - { - $result= " - - -

".$data['Topic']."

".$data['Description']." - - - - - - "; - - return ($result); - } - - - function render_text($data) - { - /* Ignore text messages, they are normally used for status hints. */ - return (""); - } - - - function render_title($data) - { - /* Ignore text messages, they are normally used for status hints. */ - return (""); - } - -} - - -// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: -?> diff --git a/gosa-core/plugins/admin/fai/class_divListFai.inc b/gosa-core/plugins/admin/fai/class_divListFai.inc deleted file mode 100644 index f8977130e..000000000 --- a/gosa-core/plugins/admin/fai/class_divListFai.inc +++ /dev/null @@ -1,421 +0,0 @@ -parent = $parent; - $this->ui = get_userinfo(); - - /* Set default base */ - if(!session::is_set('CurrentMainBase')){ - session::set('CurrentMainBase',$this->config->current['BASE']); - } - $this->selectedBase = session::get('CurrentMainBase'); - - /* Set list strings */ - $this->SetTitle(_("List of FAI classes")); - $this->SetSummary(_("This table displays all FAI classes in the selected tree.")); - - /* Result page will look like a headpage */ - $this->SetHeadpageMode(); - $this->SetInformation(_("This menu allows you to create, delete and edit FAI classes.")); - - $this->EnableAplhabet (true); - - /* Disable buttonsm */ - $this->EnableCloseButton(false); - $this->EnableSaveButton (false); - - /* Dynamic action col, depending on snapshot icons */ - $action_col_size = 80; -# if($this->parent->snapshotEnabled()){ -# $action_col_size += 32; -# } - - /* Toggle all selected / deselected */ - $chk = ""; - - /* set Page header */ - $this->AddHeader(array("string"=> $chk, "attach"=>"style='width:20px;'")); - $this->AddHeader(array("string" => " ", "attach" => "style='text-align:center;width:20px;'")); - $this->AddHeader(array("string" => _("Name of FAI class"), "attach" => "style=''")); - $this->AddHeader(array("string" => _("Class type"), "attach" => "style='width:200px;'")); - $this->AddHeader(array("string" => _("Actions"), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'")); - - $this->AddCheckBox("ShowProfiles" , _("Display FAI profile objects") ,_("Show profiles") ,true); - $this->AddCheckBox("ShowTemplates" , _("Display FAI template objects") ,_("Show templates") ,true); - $this->AddCheckBox("ShowScripts" , _("Display FAI scripts") ,_("Show scripts") ,true); - $this->AddCheckBox("ShowHooks" , _("Display FAI hooks") ,_("Show hooks") ,true); - $this->AddCheckBox("ShowVariables" , _("Display FAI variables") ,_("Show variables") ,true); - $this->AddCheckBox("ShowPackages" , _("Display FAI packages") ,_("Show packages") ,true); - $this->AddCheckBox("ShowPartitions" , _("Display FAI partitions") ,_("Show partitions") ,true); - - /* Add SubSearch checkbox */ - //$this->AddCheckBox(SEPERATOR); - //$this->AddCheckBox("SubSearch", _("Select to search within subtrees"), _("Search in subtrees"), false); - - /* Name ,Text ,Default , Connect with alphabet */ - $this->AddRegex ("Regex", _("Display users matching"),"*" , true); - } - - function AddUserBoxToFilter($position) - { - $str = ""; - if($position == 2){ - - /* Check if there are post commands available for fai management. - * If not, grey out freeze/branch and release remove buttons. - */ - $r = $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs')); - $c = $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs')); - - $smarty = get_smarty(); - $smarty->assign("allow_create", $c); - $smarty->assign("allow_remove", $r); - $smarty->assign("selectedBranch",$this->selectedBranch); - $smarty->assign("branchimage","images/branch.png"); - $smarty->assign("branches",$this->AvailableBranches); - $plug_id = 0; - if(isset($_GET['plug'])){ - $plug_id = $_GET['plug']; - } - $smarty->assign("plug_id",$plug_id); - $str = $smarty->fetch(get_template_path('branch_selector.tpl', TRUE)); - } - return($str); - } - - function GenHeader() - { - /* Prepare departments, - which are shown in the listbox on top of the listbox - */ - $options= ""; - - /* Get all departments within this subtree */ - $ui= get_userinfo(); - $first = ""; - $found = FALSE; - $base = $this->config->current['BASE']; - - /* Add base */ - $tmp = array(); - $tmp[] = array("dn"=>$this->config->current['BASE']); - $tmp= array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base, - array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH)); - - $deps = array(); - foreach($tmp as $tm){ - $deps[$tm['dn']] = $tm['dn']; - } - - /* Load possible departments */ - $ui= get_userinfo(); - $tdeps= $ui->get_module_departments("fai"); - $ids = $this->config->idepartments; - $first = ""; - $found = FALSE; - foreach($ids as $dep => $name){ - if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){ - - /* Keep first base dn in mind, we could need this - * info if no valid base was found - */ - if(empty($first)) { - $first = $dep['dn']; - } - - $value = $ids[$dep]; - if ($this->selectedBase == $dep){ - $found = TRUE; - $options.= ""; - } else { - $options.= ""; - } - } - } - - /* The currently used base is not visible with your acl setup. - * Set base to first useable base. - */ - if(!$found){ - $this->selectedBase = $first; - } - - /* Add seperator */ - $add_sep = false; - - /* Get complete fai acls, to be able to check if we must show or hide the snapshot abilities */ - $acl_all = $ui->has_complete_category_acls($this->selectedBase,$this->module); - - /* Add default header */ - $listhead = MultiSelectWindow::get_default_header(); - - /* Add additional seperator */ - if($add_sep){ - $listhead .="  "; - } - - $listhead .= _("Base")." ". - "  "; - - - $s = ".|"._("Actions")."|\n"; - $s .= "..|". - " "._("Create")."|\n"; - - $acl = $ui->get_permissions($this->selectedBase,"fai/faiProfile"); - if(preg_match("/c/",$acl)){ - $s.= "...|". - " "._("Profile")."|Create_profile|\n"; - } - - /* Append create icons for each fai component */ - $arr = array( - array("images/fai_new_partitionTable.png" , _("Partition table") ,"Create_partition" , _("PT") , "faiPartitionTable"), - array("images/fai_new_script.png" , _("Scripts") ,"Create_script" , _("S") , "faiScript"), - array("images/fai_new_hook.png" , _("Hooks") ,"Create_hook" , _("H") , "faiHook"), - array("images/fai_new_variable.png" , _("Variables") ,"Create_variable" , _("V") , "faiVariable"), - array("images/fai_new_template.png" , _("Templates ") ,"Create_template" , _("I") , "faiTemplate"), - array("images/fai_new_packages.png" , _("Package list") ,"Create_package" , _("PK") , "faiPackage")); - - foreach($arr as $ar){ - $acl = $ui->get_permissions($this->selectedBase,"fai/".$ar[4]); - if(preg_match("/c/",$acl)){ - $s.= "...|". - " ".$ar[1]."|".$ar[2]."|\n"; - } - } - - /* Multiple options */ - $s.= "..|". - " "._("Remove")."|"."remove_multiple|\n"; - - /* Add multiple copy & cut icons */ - if(is_object($this->parent->CopyPasteHandler)){ - $s.= "..|---|\n"; - $s.= "..|". - " "._("Copy")."|"."multiple_copy_systems|\n"; - $s.= "..|". - " "._("Cut")."|"."multiple_cut_systems|\n"; - } - - /* Add copy & paste icons, currently disabled, this ability is not implemeneted yet */ - if(preg_match("/(c.*w|w.*c)/",$acl_all) && isset($this->parent->CopyPasteHandler) && $this->parent->CopyPasteHandler){ - $s .= "..|---|\n"; - if($this->parent->CopyPasteHandler->entries_queued()){ - $img = ""; - $s.="..|".$img." "._("Paste")."|editPaste|\n"; - }else{ - $img = ""; - $s.="..|".$img." "._("Paste")."\n"; - } - } - -# /* Add snapshot icons, if we are allowed to write and create the complete fai module ($ui->has_complete_category_acls) */ -# if(preg_match("/(c.*w|w.*c)/",$acl_all)){ -# if($this->parent->snapshotEnabled()){ -# $s .= "..|---|\n"; -# $s .= $this->get_snapshot_header(TRUE); -# } -# } - - $this->SetDropDownHeaderMenu($s); - $this->SetListHeader($listhead); - } - - /* so some basic settings */ - function execute() - { - $this->ClearElementsList(); - $this->GenHeader(); - $this->AvailableBranches = $this->parent->getBranches(); - } - - function setEntries($list) - { - /******************** - Variable init - ********************/ - - $objects = array( - "FAIpartitionTable" => array("IMG"=> "images/fai_partitionTable.png", "NAME"=>_("Partition table"),"KZL"=> "PT", "VAR"=>"ShowPartitions"), - "FAIpackageList" => array("IMG"=> "images/fai_packages.png", "NAME"=>_("Package list") , "KZL"=> "PL", "VAR"=>"ShowPackages"), - "FAIscript" => array("IMG"=> "images/fai_script.png", "NAME"=>_("Scripts") , "KZL"=> "S", "VAR"=>"ShowScripts"), - "FAIvariable" => array("IMG"=> "images/fai_variable.png", "NAME"=>_("Variables") , "KZL"=> "V", "VAR"=>"ShowVariables"), - "FAIhook" => array("IMG"=> "images/fai_hook.png", "NAME"=>_("Hooks"), "KZL"=> "H", "VAR"=>"ShowHooks"), - "FAIprofile" => array("IMG"=> "images/fai_profile.png", "NAME"=>_("Profile") , "KZL"=> "P", "VAR"=>"ShowProfiles"), - "FAItemplate" => array("IMG"=> "images/fai_template.png", "NAME"=>_("Templates") , "KZL"=> "T", "VAR"=>"ShowTemplates")); - - $editlink ="%NAME%"; - - /* Dynamic action col, depending on snapshot icons */ - $action_col_size = 80; -# if($this->parent->snapshotEnabled()){ -# $action_col_size += 32; -# } - - /******************** - Attach objects - ********************/ - - $cnts = array(); - foreach($objects as $key => $data){ - $cnts[$key] = 0; - } - - foreach($list as $key => $value){ - $info = ""; - $img = ""; - $type = $value['type']; - $abort =false; - - $cnts[$type] ++; - - if(isset($objects[$type])){ - $img = "".$objects[$type]["; - $info = $objects[$type]['NAME']; - $var = $objects[$type]['VAR']; - }else{ - $img = ""; - $info = ""; - $var = ""; - } - - if((isset($value['description']))&&(!empty($value['description']))){ - $desc= " [".$value['description']."]"; - }else{ - $desc= ""; - } - - /* Add copy & cut icons */ - $ui = get_userinfo(); - $action =""; - $acl_all = $ui->has_complete_category_acls($this->selectedBase,$this->module); - if(preg_match("/(c.*w|w.*c)/",$acl_all) && $this->parent->CopyPasteHandler){ - $action .= " "; - $action.= " "; - } - - if($value['FAIstate'] == "freeze"){ - $action.= "F"; - $action.= ""; - }else{ - $action.= ""; - -# if(preg_match("/(c)/",$value['acl']) && preg_match("/(w)/",$value['acl'])){ -# $action.= $this->GetSnapShotActions($value['dn']);; -# } - - if(preg_match("/d/",$value['acl'])){ - $action.= ""; - } - } - - /* Cutted objects should be displayed in light grey */ - $display = $value['cn'].$desc; - if($this->parent->CopyPasteHandler){ - foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){ - if($queue_data['dn'] == $value['dn']) { - $display = "".$display.""; - break; - } - } - } - $edi = $editlink; - $acti = $action; - - /* Create each field */ - $field0 = array("string" => "" , - "attach" => "style='width:20px;'"); - $field1 = array("string" => $img , "attach" => "style='text-align:center;width:20px;'"); - $field2 = array("string" => preg_replace(array("/%KEY%/","/%NAME%/","/%TITLE%/"),array($key,$display,preg_replace('/ /', ' ', @LDAP::fix($value['dn']))),$edi) , "attach" => "style=''"); - $field3 = array("string" => $info, "attach" => "style='width:200px;'"); - $field4 = array("string" => preg_replace("/%KEY%/",$key,$acti) , "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'"); - $this->AddElement(array($field0,$field1,$field2,$field3,$field4)); - } - - /* Create summary string for list footer */ - $num_deps=0; - if(!$this->SubSearch){ - $num_deps = count($this->Added_Departments); - } - - $profile_str = _("Number of listed profiles"); - $partition_str = _("Number of listed partitions"); - $script_str = _("Number of listed scripts"); - $hook_str = _("Number of listed hooks"); - $variable_str = _("Number of listed variables"); - $template_str = _("Number of listed templates"); - $package_str = _("Number of listed packages"); - $dep_str = _("Number of listed departments"); - - $str = "".$profile_str." ".$cnts['FAIprofile']."    "; - $str.= "".$partition_str." ".$cnts['FAIpartitionTable']."    "; - $str.= "".$script_str." ".$cnts['FAIscript']."    "; - $str.= "".$hook_str." ".$cnts['FAIhook']."    "; - $str.= "".$variable_str." ".$cnts['FAIvariable']."    "; - $str.= "".$template_str." ".$cnts['FAItemplate']."    "; - $str.= "".$package_str." ".$cnts['FAIpackageList']."    "; - $str.= "".$dep_str." ".$num_deps."    "; - $this->set_List_Bottom_Info($str); - } - - function Save() - { - MultiSelectWindow::Save(); - } - - function save_object() - { - /* Save automatic created POSTs like regex, checkboxes */ - MultiSelectWindow::save_object(); - $faifilter = session::get('faifilter'); - $faifilter['branch'] = $this->selectedBranch; - session::set('faifilter',$faifilter); - } -} -// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: -?> diff --git a/gosa-core/plugins/admin/fai/class_faiHook.inc b/gosa-core/plugins/admin/fai/class_faiHook.inc deleted file mode 100644 index fb64e5d3c..000000000 --- a/gosa-core/plugins/admin/fai/class_faiHook.inc +++ /dev/null @@ -1,595 +0,0 @@ - "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"); - - /* ObjectClasses for this Object*/ - var $objectclasses = array("top","FAIclass","FAIhook"); - - /* Class name of the Ldap ObjectClass for the Sub Object */ - var $subClass = "FAIhookEntry"; - var $subClasses = array("top","FAIclass","FAIhookEntry"); - - /* Class name of the php class which allows us to edit a Sub Object */ - var $subClassName = "faiHookEntry"; - - /* Attributes to initialise for each subObject */ - var $subAttributes = array("cn","description","FAItask"); - var $sub_Load_Later = array("FAIscript"); - var $sub64coded = array(); - var $subBinary = array("FAIscript"); - - /* 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 $SubObjects = array(); // All leafobjects of this object - var $view_logged = FALSE; - var $FAIstate = ""; - var $ui; - - function faiHook (&$config, $dn= NULL) - { - /* Load Attributes */ - plugin::plugin ($config, $dn); - - /* If "dn==new" we try to create a new entry - * Else we must read all objects from ldap which belong to this entry. - */ - if($dn != "new"){ - $this->dn =$dn; - - /* Get FAIstate - */ - if(isset($this->attrs['FAIstate'][0])){ - $this->FAIstate = $this->attrs['FAIstate'][0]; - } - - /* Read all leaf objects of this object (For FAIscript this would be FAIscriptEntry) - */ - $ldap = $this->config->get_ldap_link(); - $ldap->cd ($this->dn); - $attrs_to_search = $this->subAttributes; - $attrs_to_search[] = "FAIstate"; - $ldap->search("(&(objectClass=FAIclass)(objectClass=".$this->subClass."))", $attrs_to_search); - - while($object = $ldap->fetch()){ - - /* Skip objects, that are tagged as removed */ - if(isset($object['FAIstate'][0])){ - if(preg_match("/removed$/",$object['FAIstate'][0])){ - continue; - } - } - - /* Set status for save management */ - $objects = array(); - $objects['status'] = "FreshLoaded"; - $objects['dn'] = $object['dn']; - $objects = $this->get_object_attributes($objects,$this->subAttributes); - $this->SubObjects[$objects['cn']] = $objects; - } - } - $this->ui = get_userinfo(); - } - - - /* Reload some attributes */ - function get_object_attributes($object,$attributes) - { - $ldap = $this->config->get_ldap_link(); - $ldap->cd($this->config->current['BASE']); - $ldap->cat($object['dn'],$attributes); - $tmp = $ldap->fetch(); - - foreach($attributes as $attrs){ - if(isset($tmp[$attrs][0])){ - $var = $tmp[$attrs][0]; - - /* Check if we must decode some attributes */ - if(in_array_ics($attrs,$this->sub64coded)){ - $var = base64_decode($var); - } - - /* check if this is a binary entry */ - if(in_array_ics($attrs,$this->subBinary)){ - $var = $ldap->get_attribute($object['dn'], $attrs,$r_array=0); - } - - /* Fix slashes */ - $var = addslashes($var); - $object[$attrs] = $var; - } - } - return($object); - } - - - function acl_base_for_current_object($dn) - { - if($dn == "new"){ - if($this->dn == "new"){ - $dn = session::get('CurrentMainBase'); - }else{ - $dn = $this->dn; - } - } - return($dn); - } - - - function getUsedFAItask($cn) - { - $ret = array(); - foreach($this->SubObjects as $name => $class){ - if($class['cn'] == $cn){ - continue; - } - if($class['status'] != "delete"){ - $ret[$class['FAItask']] = $class['FAItask']; - } - } - return($ret); - } - - function execute() - { - /* Call parent execute */ - plugin::execute(); - - if($this->is_account && !$this->view_logged){ - $this->view_logged = TRUE; - new log("view","fai/".get_class($this),$this->dn); - } - - /* Fill templating stuff */ - $smarty= get_smarty(); - $display= ""; - - /* New Listhandling - */ - $once = true; - foreach($_POST as $name => $value){ - if(preg_match("/^editscript_/",$name)&&($once)){ - $once = false; - $entry = preg_replace("/^editscript_/","",$name); - $entry = base64_decode(preg_replace("/_.*/","",$entry)); - - $obj = $this->SubObjects[$entry]; - if($obj['status'] == "FreshLoaded"){ - $obj = $this->get_object_attributes($obj,$this->sub_Load_Later); - } - - $this->dialog= new $this->subClassName($this->config,$this->dn,$obj); - $this->dialog->set_acl_base($this->acl_base_for_current_object($obj['dn'])); - $this->dialog->set_acl_category("fai"); - - session::set('objectinfo',$obj['dn']); - $this->dialog->parent = &$this; - $this->is_dialog=true; - } - if(preg_match("/^deletescript_/",$name)&&($once)){ - $entry = preg_replace("/^deletescript_/","",$name); - $entry = base64_decode(preg_replace("/_.*/","",$entry)); - - $dn = $this->acl_base_for_current_object($this->SubObjects[$entry]['dn']); - $acl = $this->ui -> get_permissions($dn,"fai/faiScriptEntry") ; - - if(preg_match("/d/",$acl)){ - $once = false; - - $status = $this->SubObjects[$entry]['status']; - if($status == "edited" || $status == "FreshLoaded"){ - $this->SubObjects[$entry]['status']= "delete"; - }else{ - unset($this->SubObjects[$entry]); - } - } - } - } - - /* Edit entries via GET */ - if(isset($_GET['act']) && isset($_GET['id'])){ - if($_GET['act'] == "edit" && isset($this->SubObjects[$_GET['id']])){ - $obj = $this->SubObjects[$_GET['id']]; - if($obj['status'] == "FreshLoaded"){ - $obj = $this->get_object_attributes($obj,$this->sub_Load_Later); - } - $this->dialog= new $this->subClassName($this->config,$this->dn,$obj); - $this->dialog->acl = $this->acl; - session::set('objectinfo',$obj['dn']); - $this->dialog->parent = &$this; - $this->is_dialog=true; - } - } - - ///// Ende new list handling - - /* Add new sub object */ - if(isset($_POST['AddSubObject'])){ - - $c_dn = $this->acl_base_for_current_object($this->dn); - $this->dialog= new $this->subClassName($this->config,"new"); - $this->dialog->set_acl_base($c_dn); - $this->dialog->set_acl_category("fai"); - $this->dialog->parent = &$this; - $this->is_dialog=true; - } - - - /* Save Dialog */ - if(isset($_POST['SaveSubObject'])){ - - /* Perform post check*/ - $this->dialog->save_object(); - - /* Get messages */ - $msgs = $this->dialog->check(); - - /* print errors */ - if(count($msgs)>0){ - foreach($msgs as $msg){ - print_red($msg); - } - }else{ - - /* Get return object */ - $obj = $this->dialog->save(); - if(isset($obj['remove'])){ - - $old_stat = $this->SubObjects[$obj['remove']['from']]['status']; - - /* Depending on status, set new status */ - if($old_stat == "edited" || $old_stat == "FreshLoaded"){ - $this->SubObjects[$obj['remove']['from']]['status'] = "delete"; - }elseif($this->SubObjects[$obj['remove']['from']]['status']=="new"){ - unset($this->SubObjects[$obj['remove']['from']]); - } - $obj['status'] = "new"; - $this->SubObjects[$obj['remove']['to']] = $obj; - unset($this->SubObjects[$obj['remove']['to']]['remove']); - }else{ - if($obj['status'] == "FreshLoaded"){ - $obj['status'] = "edited"; - } - $this->SubObjects[$obj['cn']]=$obj; - } - $this->is_dialog=false; - unset($this->dialog); - $this->dialog=FALSE; - } - } - - /* Sort entries */ - $tmp = $keys = array(); - foreach($this->SubObjects as $key => $entry){ - $keys[$key]=$key; - } - natcasesort($keys); - foreach($keys as $key){ - $tmp[$key]=$this->SubObjects[$key]; - } - $this->SubObjects = $tmp; - - /* Cancel Dialog */ - if(isset($_POST['CancelSubObject'])){ - $this->is_dialog=false; - unset($this->dialog); - $this->dialog=FALSE; - } - - /* Print dialog if $this->dialog is set */ - if(is_object($this->dialog)){ - $this->dialog->save_object(); - $display = $this->dialog->execute(); - return($display); - } - - - - /* Divlist added 28.02.2006 - Containing FAIscripts - */ - - $divlist = new divSelectBox("FAIhooks"); - $divlist->setHeight(400); - - foreach($this->getList(true) as $key => $name){ - - $dn= $this->acl_base_for_current_object($name['dn']); - $acl = $this->ui->get_permissions($dn,"fai/faiHookEntry") ; - $act = ""; - - /* Check if this object is freezed, in this case hide the delete icon */ - if($this->FAIstate == "freeze"){ - $act .= ""; - }else{ - $act .= ""; - if(preg_match("/d/",$acl)){ - $act .=""; - } - } - - /* Check if we are allowed to use the export button for this object */ - $s_acl = $this->ui->get_permissions($dn,"fai/faiHookEntry","FAIscript") ; - if(($this->SubObjects[$key]['status'] == "new") || ($this->SubObjects[$key]['dn'] == "new") || !preg_match("/r/",$s_acl)){ - $down = ""; - }else{ - $down = " - "._("Download")." - "; - } - - /* Check if we are allowed to view the object */ - $s_acl = $this->ui->get_permissions($dn,"fai/faiHookEntry","cn") ; - if(preg_match("/r/",$s_acl)){ - - $edit_link = "".$name['name'].""; - $divlist->AddEntry(array( array("string"=>$edit_link), - array("string"=>$down , "attach" => "style='width:20px;'"), - array("string"=>str_replace("%s",base64_encode($key),$act), - "attach"=>"style='border-right: 0px;width:50px;text-align:right;'"))); - } - } - $smarty->assign("Entry_divlist",$divlist->DrawList()); - /* Divlist creation complete - */ - - $smarty->assign("SubObjects",$this->getList()); - - /* 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){ - if(get_magic_quotes_gpc()){ - $smarty->assign($attrs,stripslashes($this->$attrs)); - }else{ - $smarty->assign($attrs,($this->$attrs)); - } - } - - $tmp = $this->plInfo(); - - $c_dn = $this->acl_base_for_current_object($this->dn); - $smarty->assign("sub_object_is_addable", preg_match("/c/",$this->ui->get_permissions($c_dn,"fai/faiHookEntry")) && $this->FAIstate!="freeze"); - foreach($tmp['plProvidedAcls'] as $name => $translation){ - $smarty->assign($name."ACL",$this->getacl($name)); - } - - $display.= $smarty->fetch(get_template_path('faiHook.tpl', TRUE)); - return($display); - } - - /* Generate listbox friendly SubObject list - */ - function getList($use_dns=false){ - $a_return=array(); - foreach($this->SubObjects as $obj){ - if($obj['status'] != "delete"){ - if($use_dns){ - if((isset($obj['description']))&&(!empty($obj['description']))){ - $a_return[$obj['cn']]['name']= $obj['cn']." [".stripslashes($obj['description'])."]"; - }else{ - $a_return[$obj['cn']]['name']= $obj['cn']; - } - $a_return[$obj['cn']]['dn']= $obj['dn']; - }else{ - if((isset($obj['description']))&&(!empty($obj['description']))){ - $a_return[$obj['cn']]= $obj['cn']." [".stripslashes($obj['description'])."]"; - }else{ - $a_return[$obj['cn']]= $obj['cn']; - } - } - } - } - return($a_return); - } - - - /* Delete me, and all my subtrees - */ - function remove_from_parent() - { - $ldap = $this->config->get_ldap_link(); - $ldap->cd ($this->dn); - - $faifilter = session::get('faifilter'); - $use_dn = preg_replace("/".normalizePreg(FAI::get_release_dn($this->dn))."/i", $faifilter['branch'], $this->dn); - if($faifilter['branch'] == "main"){ - $use_dn = $this->dn; - } - - FAI::prepare_to_save_FAI_object($use_dn,array(),true); - - new log("remove","fai/".get_class($this),$use_dn,$this->attributes); - - foreach($this->SubObjects as $name => $obj){ - $use_dn = preg_replace("/".normalizePreg(FAI::get_release_dn($this->dn))."/i", $faifilter['branch'], $obj['dn']); - if($faifilter['branch'] == "main"){ - $use_dn = $obj['dn']; - } - FAI::prepare_to_save_FAI_object($use_dn,array(),true); - } - $this->handle_post_events("remove"); - } - - - /* Save data to object - */ - function save_object() - { - if((isset($_POST['FAIhook_posted'])) && ($this->FAIstate != "freeze")){ - plugin::save_object(); - foreach($this->attributes as $attrs){ - if(isset($_POST[$attrs])){ - $this->$attrs = $_POST[$attrs]; - } - } - } - } - - - /* Check supplied data */ - function check() - { - /* Call common method to give check the hook */ - $message= plugin::check(); - - return ($message); - } - - - /* Save to LDAP */ - function save() - { - plugin::save(); - - $ldap = $this->config->get_ldap_link(); - - FAI::prepare_to_save_FAI_object($this->dn,$this->attrs); - show_ldap_error($ldap->get_error(), sprintf(_("Saving of FAI/hook with dn '%s' failed."),$this->dn)); - - if($this->initially_was_account){ - new log("modify","fai/".get_class($this),$this->dn,$this->attributes); - }else{ - new log("create","fai/".get_class($this),$this->dn,$this->attributes); - } - - $ldap->cd($this->dn); - - /* Prepare FAIscriptEntry to write it to ldap - * First sort array. - * Because we must delete old entries first. - * After deletion, we perform add and modify - */ - $Objects = array(); - - /* We do not need to save untouched objects */ - foreach($this->SubObjects as $name => $obj){ - if($obj['status'] == "FreshLoaded"){ - unset($this->SubObjects[$name]); - } - } - - foreach($this->SubObjects as $name => $obj){ - if($obj['status'] == "delete"){ - $Objects[$name] = $obj; - } - } - foreach($this->SubObjects as $name => $obj){ - if($obj['status'] != "delete"){ - $Objects[$name] = $obj; - } - } - - foreach($Objects as $name => $obj){ - - foreach($this->sub64coded as $codeIt){ - $obj[$codeIt]=base64_encode(stripslashes($obj[$codeIt])); - } - - $tmp = array(); - $attributes = array_merge($this->sub_Load_Later,$this->subAttributes); - foreach($attributes as $attrs){ - if(empty($obj[$attrs])){ - $obj[$attrs] = array(); - } - if(!is_array($obj[$attrs])){ - $tmp[$attrs] = stripslashes($obj[$attrs]); - }else{ - $tmp[$attrs] = $obj[$attrs]; - } - } - - $tmp['objectClass'] = $this->subClasses; - - $sub_dn = "cn=".$obj['cn'].",".$this->dn; - - if($obj['status']=="new"){ - $ldap->cat($sub_dn,array("objectClass")); - if($ldap->count()){ - $obj['status']="edited"; - } - } - - /* Tag object */ - $this->tag_attrs(&$tmp, $sub_dn, $this->gosaUnitTag); - - if($obj['status'] == "delete"){ - FAI::prepare_to_save_FAI_object($sub_dn,array(),true); - $this->handle_post_events("remove"); - }elseif($obj['status'] == "edited"){ - FAI::prepare_to_save_FAI_object($sub_dn,$tmp); - $this->handle_post_events("modify"); - }elseif($obj['status']=="new"){ - FAI::prepare_to_save_FAI_object($sub_dn,$tmp); - $this->handle_post_events("add"); - } - } - } - - - function PrepareForCopyPaste($source) - { - plugin::PrepareForCopyPaste($source); - - /* Read all leaf objects of this object (For FAIscript this would be FAIscriptEntry) - */ - $ldap = $this->config->get_ldap_link(); - $ldap->cd ($source['dn']); - - $attrs_to_search = $this->subAttributes; - $attrs_to_search[] = "FAIstate"; - $ldap->search("(&(objectClass=FAIclass)(objectClass=".$this->subClass."))",$attrs_to_search); - - while($object = $ldap->fetch()){ - - /* Skip objects, that are tagged as removed */ - if(isset($object['FAIstate'][0])){ - if(preg_match("/removed$/",$object['FAIstate'][0])){ - continue; - } - } - - /* Set status for save management */ - $objects = array(); - $objects['status'] = "edited"; - $objects['dn'] = $object['dn']; - $objects = $this->get_object_attributes($objects,$this->subAttributes); - $objects = $this->get_object_attributes($objects,$this->sub_Load_Later); - - $this->SubObjects[$objects['cn']] = $objects; - } - } - - - /* Return plugin informations for acl handling */ - static function plInfo() - { - return (array( - "plShortName" => _("Hook"), - "plDescription" => _("FAI hook"), - "plSelfModify" => FALSE, - "plDepends" => array(), - "plPriority" => 20, - "plSection" => array("administration"), - "plCategory" => array("fai"), - "plProvidedAcls" => array( - "cn" => _("Name")." ("._("Read only").")", - "description" => _("Description")) - )); - } -} - -// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: -?> diff --git a/gosa-core/plugins/admin/fai/class_faiHookEntry.inc b/gosa-core/plugins/admin/fai/class_faiHookEntry.inc deleted file mode 100644 index cab96dbf2..000000000 --- a/gosa-core/plugins/admin/fai/class_faiHookEntry.inc +++ /dev/null @@ -1,206 +0,0 @@ - "Eins ist toll", "zwei" => "Zwei ist noch besser"); - - /* attribute list for save action */ - var $ignore_account= TRUE; - var $attributes = array("cn","description","FAIscript","FAItask"); - var $objectclasses= array(); - - var $orig_cn = ""; - var $tasks = array("chboot", "configure", "debconf", "extrbase", "faiend", "finish", - "install", "instsoft", "mirror", "mountdisks", "partition", "prepareapt", - "savelog", "softupdate", "sysinfo","updatebase", "error"); - var $dn = ""; - var $cn = ""; - var $FAItask = "chboot"; - var $FAIscript = ""; - var $description = ""; - var $status = "new"; - var $parent = NULL; - var $FAIstate = ""; - - function faiHookEntry (&$config, $dn= NULL,$object=false) - { - plugin::plugin ($config, $dn); - if($dn != "new"){ - $this->orig_cn= $object['cn']; - $this->dn=$object['dn']; - foreach($object as $name=>$value){ - $oname = $name; - $this->$oname=$value; - } - - if(isset($this->attrs['FAIstate'][0])){ - $this->FAIstate = $this->attrs['FAIstate'][0]; - } - - }elseif(is_array($object)){ - if(count($object)){ - $this->orig_cn= $object['cn']; - $this->dn=$object['dn']; - foreach($object as $name=>$value){ - $oname = $name; - $this->$oname=$value; - } - }else{ - - $this->status = "new"; - $this->orig_cn = false; - } - } - } - - - function execute() - { - /* Call parent execute */ - plugin::execute(); - - /* Fill templating stuff */ - $smarty = get_smarty(); - $display = ""; - - if(isset($_POST['ImportUpload'])){ - if(($_FILES['ImportFile']['error']!=0)){ - print_red(_("Please select a valid file.")); - }else - if(($_FILES['ImportFile']['size']==0)){ - print_red(_("Selected file is empty.")); - }else{ - $str = utf8_encode(file_get_contents($_FILES['ImportFile']['tmp_name'])); - $this->FAIscript = $str; - } - } - - /* Create download button*/ - if($this->dn != "new" && $this->acl_is_readable("FAIscript")){ - $smarty->assign("DownMe"," - "._("Download")." - "); - }else{ - $smarty->assign("DownMe",""); - } - - $used_tasks = $this->parent->getUsedFAItask($this->cn); - $tasks = $this->tasks; - foreach($this->tasks as $id => $task){ - if(in_array($task,$used_tasks)){ - unset($tasks[$id]); - } - } - $smarty->assign("tasks", $tasks); - - /* 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){ - if(get_magic_quotes_gpc()){ - $smarty->assign($attrs,(stripslashes($this->$attrs))); - }else{ - $smarty->assign($attrs,($this->$attrs)); - } - } - - $tmp = $this->plInfo(); - foreach($tmp['plProvidedAcls'] as $name => $translated){ - $acl = $this->getacl($name); - if($this->FAIstate == "freezed"){ - $acl = preg_replace("/w/","",$acl); - } - $smarty->assign($name."ACL",$acl); - } - - if(get_magic_quotes_gpc()){ - $smarty->assign("FAIscript" , htmlentities(stripslashes($this->FAIscript))); - }else{ - $smarty->assign("FAIscript" , htmlentities($this->FAIscript)); - } - $display.= $smarty->fetch(get_template_path('faiHookEntry.tpl', TRUE)); - return($display); - } - - /* Save data to object */ - function save_object() - { - if((isset($_POST['SubObjectFormSubmitted'])) && ($this->FAIstate != "freeze")){ - foreach($this->attributes as $attrs){ - if($this->acl_is_writeable($attrs)){ - if(isset($_POST[$attrs])){ - $this->$attrs = $_POST[$attrs]; - }else{ - $this->$attrs = ""; - } - } - } - } - } - - /* Check supplied data */ - function check() - { - /* Call common method to give check the hook */ - $message= plugin::check(); - - if(isset($this->parent->SubObjects[$this->cn]) && $this->cn != $this->orig_cn){ - $message[] =_("There is already a hook with the given name."); - } - - if(empty($this->FAIscript)) { - $message[]=_("Please enter a value for script."); - } - - if(empty($this->cn)){ - $message[] = _("Please enter a name."); - } - - return ($message); - } - - function save() - { - $tmp=array(); - foreach($this->attributes as $attrs){ - $tmp[$attrs] = $this->$attrs; - } - - /* Strip out dos newlines */ - $tmp['FAIscript']= strtr($this->FAIscript, array("\x0D" => "")); - - if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){ - $tmp['remove']['from'] = $this->orig_cn; - $tmp['remove']['to'] = $tmp['cn']; - } - - $tmp['dn'] = $this->dn; - $tmp['status'] = $this->status; - return($tmp); - } - - /* Return plugin informations for acl handling */ - static function plInfo() - { - return (array( - "plShortName" => _("Hook entry"), - "plDescription" => _("FAI hook entry"), - "plSelfModify" => FALSE, - "plDepends" => array(), - "plPriority" => 21, - "plSection" => array("administration"), - "plCategory" => array("fai"), - "plProvidedAcls" => array( - "cn" => _("Name"), - "description" => _("Description"), - "FAItask" => _("Task"), - "FAIscript" => _("FAI script")) - )); - } - -} -// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: -?> diff --git a/gosa-core/plugins/admin/fai/class_faiManagement.inc b/gosa-core/plugins/admin/fai/class_faiManagement.inc deleted file mode 100644 index 2bf246655..000000000 --- a/gosa-core/plugins/admin/fai/class_faiManagement.inc +++ /dev/null @@ -1,1162 +0,0 @@ - "Eins ist toll", "zwei" => "Zwei ist noch besser"); - - /* Headpage attributes */ - var $lock_type = ""; // should be branch/freeze - var $lock_name = ""; - var $lock_dn = ""; - - /* attribute list for save action */ - var $attributes = array("lock_type","lock_name","lock_dn"); // Attributes Managed by this plugin - 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; - - var $dispNewBranch= false; - var $dispNewFreeze= false; - - var $DivListFai; - var $start_pasting_copied_objects = FALSE; - var $CopyPasteHandler = FALSE; - var $base = ""; - - /* construction/reconstruction - */ - function faiManagement (&$config, $ui) - { - /* Set defaults */ - $this->dn = ""; - $this->config = $config; - $this->ui = $ui; - - /* Creat dialog object */ - $this->DivListFai = new divListFai($this->config,$this); - - /* Copy & Paste handler */ - if ($this->config->boolValueIsTrue("main", "enableCopyPaste")){ - $this->CopyPasteHandler= new CopyPasteHandler($this->config); - } - } - - function execute() - { - /* Call parent execute */ - plugin::execute(); - - /* Initialise vars and smarty */ - $smarty = get_smarty(); - $smarty->assign("BranchName",""); - - $display = ""; - $s_action = ""; - $s_entry = ""; - - /* If an entry was locked, these vars will be stored in a session to allow direct edit */ - session::set('LOCK_VARS_TO_USE',array("/^edit_entry$/","/^id$/","/^entry_edit_/","/^entry_delete_/","/^item_selected/","/^remove_multiple_fai_objects/")); - - - /**************** - Handle posts - ****************/ - - /* Check ImageButton posts - * Create new tab ich new_xx is posted - */ - $posts = array( "/remove_branch/"=>"remove_branch", "/branch_branch/"=>"branch_branch", - "/freeze_branch/"=>"freeze_branch", "/create_partition/i"=>"new_partition", - "/create_script/i"=>"new_script", "/create_hook/i"=>"new_hook", - "/create_variable/i"=>"new_variable", "/create_template/i"=>"new_template", - "/create_package/i"=>"new_package", "/create_profile/i"=>"new_profile", - "/edit_continue/"=>"select_class_name_finished", - "/^multiple_copy_fai/" => "copy_multiple", - "/^multiple_cut_fai/" => "cut_multiple", - "/^copy/" => "copy", - "/^cut/" => "cut", - "/^remove_multiple_fai_objects/" => "del_multiple"); - - foreach($_POST as $name => $value){ - foreach($posts as $reg => $act ){ - if(preg_match($reg,$name)){ - $s_action = $act; - $s_entry = ltrim(preg_replace($reg,"",$name),"_"); - $s_entry = preg_replace("/_.*$/","",$s_entry); - } - } - if(preg_match("/^entry_edit_.*/",$name)){ - $s_entry = preg_replace("/^entry_edit_/","",$name); - $s_entry = preg_replace("/_.*$/","",$s_entry); - $s_action = "edit"; - }elseif(preg_match("/^entry_delete_.*/",$name)){ - $s_entry = preg_replace("/^entry_delete_/","",$name); - $s_entry = preg_replace("/_.*$/","",$s_entry); - $s_action = "delete"; - } - } - - if(isset($_GET['edit_entry'])){ - $s_entry = $_GET['edit_entry']; - $s_action = "edit"; - } - - if(isset($_GET['act']) && $_GET['act'] == "freeze_branch"){ - $s_action = "freeze_branch"; - } - if(isset($_GET['act']) && $_GET['act'] == "branch_branch"){ - $s_action = "branch_branch"; - } - if(isset($_GET['act']) && $_GET['act'] == "remove_branch"){ - $s_action = "remove_branch"; - } - - if((isset($_POST['CancelBranchName'])) || (isset($_POST['CloseIFrame']))){ - $this->dispNewBranch = false; - $this->dispNewFreeze = false; - } - - - $type_acl_mapping = array( - "FAIpartitionTable" => "faiPartitionTable", - "FAIpackageList" => "faiPackage", - "FAIscript" => "faiScript", - "FAIvariable" => "faiVariable", - "FAIhook" => "faiHook", - "FAIprofile" => "faiProfile", - "FAItemplate" => "faiTemplate"); - - - /* handle C&P from layers menu */ - if(isset($_POST['menu_action']) && preg_match("/^multiple_copy_systems/",$_POST['menu_action'])){ - $s_action = "copy_multiple"; - } - if(isset($_POST['menu_action']) && preg_match("/^multiple_cut_systems/",$_POST['menu_action'])){ - $s_action = "cut_multiple"; - } - if(isset($_POST['menu_action']) && preg_match("/^editPaste/",$_POST['menu_action'])){ - $s_action = "editPaste"; - } - - /* Create options */ - if(isset($_POST['menu_action']) && preg_match("/^Create_/",$_POST['menu_action'])){ - $s_action = "new_".preg_replace("/^Create_/","",$_POST['menu_action']);; - $s_entry = preg_replace("/^Create_/","",$_POST['menu_action']); - } - - /* handle remove from layers menu */ - if(isset($_POST['menu_action']) && preg_match("/^remove_multiple/",$_POST['menu_action'])){ - $s_action = "del_multiple"; - } - - /******************** - Copy & Paste - ********************/ - - /* Display the copy & paste dialog, if it is currently open */ - $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry); - if($ret){ - return($ret); - } - - - /**************** - Delete confirme dialog - ****************/ - - if ($s_action=="delete"){ - - /* Get 'dn' from posted termlinst */ - $this->dn= $this->objects[$s_entry]['dn']; - - /* Load permissions for selected 'dn' and check if - we're allowed to remove this 'dn' */ - $acl = $this->ui->get_permissions($this->dn,"fai/".$type_acl_mapping[$this->objects[$s_entry]['type']]); - if(preg_match("/d/",$acl)){ - - /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */ - if (($user= get_lock($this->dn)) != ""){ - return(gen_locked_message ($user, $this->dn)); - } - - /* Lock the current entry, so nobody will edit it during deletion */ - add_lock ($this->dn, $this->ui->dn); - $smarty->assign("warning", sprintf(_("You're about to delete all information about the FAI class at '%s'."), @LDAP::fix($this->dn))); - $smarty->assign("multiple", false); - return($smarty->fetch(get_template_path('remove.tpl', TRUE))); - } else { - - /* Obviously the user isn't allowed to delete. Show message and - clean session. */ - print_red (_("You are not allowed to delete this component!")); - } - } - - - /******************** - Delete MULTIPLE entries requested, display confirm dialog - ********************/ - - if ($s_action=="del_multiple"){ - $this->dns = array(); - $ids = $this->list_get_selected_items(); - - if(count($ids)){ - - foreach($ids as $id){ - $dn = $this->objects[$id]['dn']; - if (($user= get_lock($dn)) != ""){ - return(gen_locked_message ($user, $dn)); - } - $this->dns[$id] = $dn; - } - - $dns_names = "
";
-        foreach($this->dns as $dn){
-          add_lock ($dn, $this->ui->dn);
-          $dns_names .= $dn."\n";
-        }
-        $dns_names .="
"; - - /* Lock the current entry, so nobody will edit it during deletion */ - if (count($this->dns) == 1){ - $smarty->assign("warning", sprintf(_("You're about to delete the following entry %s"), @LDAP::fix($dns_names))); - } else { - $smarty->assign("warning", sprintf(_("You're about to delete the following entries %s"), @LDAP::fix($dns_names))); - } - $smarty->assign("multiple", true); - return($smarty->fetch(get_template_path('remove.tpl', TRUE))); - } - } - - - /******************** - Delete MULTIPLE entries confirmed - ********************/ - - /* Confirmation for deletion has been passed. Users should be deleted. */ - if (isset($_POST['delete_multiple_fai_object_confirm'])){ - - /* Find out more about the object type */ - $ldap = $this->config->get_ldap_link(); - - /* Remove user by user and check acls before removeing them */ - foreach($this->dns as $key => $dn){ - - $ldap->cat($dn, array('objectClass')); - $attrs = $ldap->fetch(); - $type = $this->get_type($attrs); - - $acl = $this->ui->get_permissions($dn,"fai/".$type[1]); - if(preg_match("/d/",$acl)){ - - $this->dialog = new $type[0]($this->config, $this->config->data['TABS'][$type[2]], $dn,"fai"); - $this->dialog->set_acl_base($dn); - $this->dialog->by_object[$type[1]]->remove_from_parent (); - unset ($this->dialog); - $this->dialog= FALSE; - $to_del = FAI::clean_up_releases($dn); - FAI::save_release_changes_now(); - - foreach($to_del as $dn){ - $ldap->rmdir_recursive($dn); - } - - } else { - - /* Normally this shouldn't be reached, send some extra - logs to notify the administrator */ - print_red (_("You are not allowed to delete this component!")); - new log("security","fai/".get_class($this),$dn,array(),"Tried to trick deletion."); - } - - /* Remove lock file after successfull deletion */ - del_lock ($dn); - unset($this->dns[$key]); - } - } - - - /******************** - Delete MULTIPLE entries Canceled - ********************/ - - /* Remove lock */ - if(isset($_POST['delete_multiple_fai_object_cancel'])){ - foreach($this->dns as $key => $dn){ - del_lock ($dn); - unset($this->dns[$key]); - } - } - - - /**************** - Delete aborted - ****************/ - - /* Delete canceled? */ - if (isset($_POST['delete_cancel'])){ - del_lock ($this->dn); - } - - - /**************** - Delete confirmed - ****************/ - - /* Deltetion was confirmed, so delete this entry - */ - if (isset($_POST['delete_terminal_confirm'])){ - - /* Some nice guy may send this as POST, so we've to check - for the permissions again. */ - - /* Find out more about the object type */ - $ldap = $this->config->get_ldap_link(); - $ldap->cat($this->dn, array('objectClass')); - if($ldap->count()){ - $attrs = $ldap->fetch(); - $type = $this->get_type($attrs); - - $acl = $this->ui->get_permissions($this->dn,"fai/".$type[1]); - if(preg_match("/d/",$acl)){ - - $this->dialog = new $type[0]($this->config, $this->config->data['TABS'][$type[2]], $this->dn,"fai"); - $this->dialog->set_acl_base($this->dn); - $this->dialog->by_object[$type[1]]->remove_from_parent (); - unset ($this->dialog); - $this->dialog= FALSE; - $to_del = FAI::clean_up_releases($this->dn); - FAI::save_release_changes_now(); - - foreach($to_del as $dn){ - $ldap->rmdir_recursive($dn); - } - - } else { - - /* Normally this shouldn't be reached, send some extra - logs to notify the administrator */ - print_red (_("You are not allowed to delete this component!")); - new log("security","fai/".get_class($this),$dn,array(),"Tried to trick deletion."); - } - - }else{ - print_red(sprintf(_("Object could not be deleted '%s', object does not exist."),$this->dn)); - } - /* Remove lock file after successfull deletion */ - del_lock ($this->dn); - } - - - /**************** - Edit entry - ****************/ - - if(($s_action == "edit") && (!isset($this->dialog->config))){ - $entry = $this->objects[$s_entry]; - $a_setup = $this->get_type($entry); - $this->dn = $entry['dn']; - - /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */ - if (($user= get_lock($this->dn)) != ""){ - return(gen_locked_message ($user, $this->dn)); - } - add_lock ($this->dn, $this->ui->dn); - - $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai"); - $this->dialog->set_acl_base($this->dn); - $this->is_dialog = true; - - if($entry['FAIstate'] == "freeze"){ - #$this->dialog->set_acl(array("*none*")) ; - } - session::set('objectinfo',$this->dn); - } - - - /* Branch handling - 09.01.2006 - */ - - /**************** - Remove branch - ****************/ - - /* Remove branch - */ - if($s_action == "remove_branch"){ - $base= $this->DivListFai->selectedBranch; - - /* Check if we have a post remove method configured - * else skip this operation. (Skip:Button in the ui should be disabled in this case too) - */ - if("" != $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'))){ - /* Load permissions for selected 'dn' and check if - we're allowed to remove this 'dn' */ - if($this->acl_is_removeable()){ - - $smarty->assign("info", sprintf(_("You're about to delete a fai branch / freeze '%s'."), $this->DivListFai->selectedBranch)); - return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE))); - } else { - print_red (_("You are not allowed to delete this release!")); - } - } - } - - - /**************** - Remove branch confirmed - ****************/ - - if(isset($_POST['delete_branch_confirm'])){ - - /* Check if we have a post remove method configured - * else skip this operation. (Skip:Button in the ui should be disabled in this case too) - */ - if("" != $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'))){ - - $bb = $this->DivListFai->selectedBranch; - if(!isset($ldap)){ - $ldap = $this->config->get_ldap_link(); - } - - $br = $this->getBranches(); - - if(isset($br[$bb]) && $this->acl_is_removeable()){ - $name = $br[$bb]; - $ldap->cd($bb); - $ldap->recursive_remove(); - $ldap->cd(preg_replace('/,'.normalizePreg(get_ou('faiou')).'/', ','.get_ou('applicationou'), $bb)); - $ldap->recursive_remove(); - $this->DivListFai->selectedBranch = "main"; - - /* Post remove */ - $this->lock_name = $name; - $this->lock_dn = $bb; - $this->postremove(); - - new log("remove","fai/".get_class($this),$br[$bb],array(),"Release removed"); - } - } - } - - - /**************** - Create a new branch "insert Name" - ****************/ - - if((isset($_POST['UseBranchName']))&&(($this->dispNewBranch)||($this->dispNewFreeze))){ - session::set('LASTPOST',$_POST); - - if($this->dispNewBranch){ - $type = "branch"; - }else{ - $type = "freeze"; - } - - /* Check branch name */ - $name = $_POST['BranchName']; - $is_ok = true; - $smarty->assign("BranchName",$name); - $base= get_ou('faiou').$this->DivListFai->selectedBase; - - /* Check used characters */ - if(preg_match("/[^0-9a-z \ö\ä\ü\.-_:,]/i",$name)){ - if($type == "branch"){ - print_red(_("Specified branch name is invalid.")); - }else{ - print_red(_("Specified freeze name is invalid.")); - } - $is_ok = false; - } - - /* Check if this name is already in use */ - if(!$this->CheckNewBranchName($_POST['BranchName'],$this->DivListFai->selectedBranch)){ - print_red(_("This name is already in use.")); - $is_ok = false; - } - - if($is_ok){ - - if(session::is_set('LASTPOST')){ - $LASTPOST = session::get('LASTPOST'); - }else{ - $LASTPOST = array(); - } - $LASTPOST['base'] = $base; - $LASTPOST['type'] = $type; - session::set('LASTPOST',$LASTPOST); - $smarty->assign("iframe", true); - $smarty->assign("plugID", $_GET['plug']); - $display = $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__))); - return($display); - } - } - - - /**************** - Create a new branch - ****************/ - - if(isset($_GET['PerformBranch'])){ - - if(!$this->acl_is_createable()){ - print_red(_("You are not allowed to create a new branch.")); - }else{ - - /* Create it know */ - $this->dispNewBranch = false; - $this->dispNewFreeze = false; - - $LASTPOST = session::get('LASTPOST'); - $base = $LASTPOST['base']; - $_POST = session::get('LASTPOST'); - $name = $_POST['BranchName']; - - $type = $LASTPOST['type']; - $ldap = $this->config->get_ldap_link(); - - $baseToUse = $base; - if($this->DivListFai->selectedBranch != "main" ){ - $baseToUse = $this->DivListFai->selectedBranch; - } - - /* Create new Release name to be able to set faidebianRelease for FAIpackageList */ - - $CurrentReleases = $this->getBranches(); - $NewReleaseName = $name; - if(isset($CurrentReleases[$this->DivListFai->selectedBranch])) { - if($this->DivListFai->selectedBranch != "main"){ - $NewReleaseName = $CurrentReleases[$this->DivListFai->selectedBranch]."/".$name; - $NewReleaseName = preg_replace("#\/#","/",$NewReleaseName); - }else{ - $NewReleaseName = $name; - } - } - - $appsrc = preg_replace("/".normalizePreg(get_ou('faiou'))."/",get_ou('applicationou'),$baseToUse); - $appdst = preg_replace("/".normalizePreg(get_ou('faiou'))."/",get_ou('applicationou'),"ou=".$name.",".$baseToUse) ; - - $mimesrc = preg_replace("/".normalizePreg(get_ou('faiou'))."/",get_ou('mimetypeou'),$baseToUse); - $mimedst = preg_replace("/".normalizePreg(get_ou('faiou'))."/",get_ou('mimetypeou'),"ou=".$name.",".$baseToUse) ; - - /* Check if source depeartments exist */ - foreach(array($baseToUse,$appsrc,$mimesrc) as $dep){ - $ldap->cd($this->config->current['BASE']); - $ldap->cat($dep); - if(!$ldap->count()){ - $ldap->create_missing_trees($dep); - } - } - - /* Print header to have styles included */ - echo ' - - - - - - - - '; - - new log("create","fai/".get_class($this),$NewReleaseName,array(),"New $type created"); - - /* Duplicate applications - */ - $ldap->cat($appsrc,array("dn")) ; - if($ldap->count()){ - $ldap->cd ($appdst); - $ldap->recursive_remove(); - FAI::copy_FAI_resource_recursive($appsrc,$appdst,$NewReleaseName,$type,true); - } - - /* Duplicate mime types - */ - $ldap->cat($mimesrc,array("dn")) ; - if($ldap->count()){ - $ldap->cd ($mimedst); - $ldap->recursive_remove(); - FAI::copy_FAI_resource_recursive($mimesrc,$mimedst,$NewReleaseName,$type,true); - } - - $attr = array(); - $attr['objectClass'] = array("organizationalUnit","FAIbranch"); - $attr['ou'] = $name; - $attr['FAIstate'] = $type; - $ldap->cd($this->config->current['BASE']); - $ldap->cd("ou=".$name.",".$baseToUse); - $ldap->cat("ou=".$name.",".$baseToUse); - if($ldap->count()){ - $ldap->modify($attr); - }else{ - $ldap->add($attr); - } - - /* Duplicate fai objects - */ - // $ldap->cd ("ou=".$name.",".$baseToUse); - // $ldap->recursive_remove(); - // FAI::copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,$NewReleaseName,$type,true); - - echo "
-
-
"; - - echo "" ; - - /* Print footer to have valid html */ - echo ""; - - $this->dispNewFreeze = false; - - /* Postcreate */ - - /* Assign possible attributes */ - $this->lock_type = $type; - $this->lock_name = $name; - $this->lock_dn = $baseToUse; - $this->postcreate(); - exit(); - } - } - - /**************** - Display dialog to enter new Branch name - ****************/ - - /* Check if we have a post create method configured - * else skip this operation. (Skip:Button in the ui should be disabled in this case too) - */ - if("" != $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs'))){ - if(($s_action == "branch_branch")||($this->dispNewBranch)){ - if(!$this->acl_is_createable()){ - print_red(_("You are not allowed to create a new branch.")); - }else{ - $this->dispNewBranch=true; - $smarty->assign("iframe",false); - $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__))); - return($display); - } - } - } - - - /**************** - Display dialog to enter new Freeze name - ****************/ - - /* Check if we have a post create method configured - * else skip this operation. (Skip:Button in the ui should be disabled in this case too) - */ - if("" != $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs'))){ - if(($s_action == "freeze_branch")||($this->dispNewFreeze)){ - if(!$this->acl_is_createable()){ - print_red(_("You are not allowed to create a new branch.")); - }else{ - $this->dispNewFreeze = true; - $smarty->assign("iframe",false); - $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__))); - return($display); - } - } - } - - - /**************** - Create a new object - ****************/ - - $types = array( "new_partition" => "FAIpartitionTable", - "new_script" => "FAIscript", - "new_hook" => "FAIhook", - "new_variable" => "FAIvariable", - "new_template" => "FAItemplate", - "new_package" => "FAIpackageList"); - - if(isset($types[$s_action])){ - $acl = $this->ui->get_permissions($this->DivListFai->selectedBase,"fai/".$type_acl_mapping[$types[$s_action]]); - if(preg_match("/c/",$acl)){ - $this->dialog = new askClassName($this->config,$this->dn,$this->ui,$types[$s_action]); - }else{ - print_red(sprintf(_("You are not allowed to create a new '%s' object."),$types[$s_action])); - } - } - - /* New Profile */ - if($s_action == "new_profile"){ - $this->dn = "new" ; - - $acl = $this->ui->get_permissions($this->DivListFai->selectedBase,"fai/faiProfile"); - if(preg_match("/c/",$acl)){ - $a_setup= $this->get_type(array("objectClass"=>array("FAIprofile"))); - $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai"); - $this->dialog->set_acl_base($this->base); - - $this->is_dialog = false; - }else{ - print_red(sprintf(_("You are not allowed to create a new '%s' object."),"FAIprofile")); - } - } - - - /**************** - Get from ask class name dialog - ****************/ - - 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); - } - }elseif(isset($this->dialog->objectClass)){ - $this->dn = "new" ; - $a_setup= $this->get_type(array("objectClass"=>array($this->dialog->objectClass))); - $name = $this->dialog->save(); - - if(class_exists($a_setup[0])){ - $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai"); - $this->dialog->set_acl_base($this->base); - $this->dialog->by_object[$a_setup[1]]->cn = $name; - $this->is_dialog = true; - } - } - } - - - /**************** - Cancel dialogs - ****************/ - - if(isset($_POST['edit_cancel'])){ - unset($this->dialog); - $this->dialog=FALSE; - $this->is_dialog = false; - session::un_set('objectinfo'); - del_lock ($this->dn); - } - - - /**************** - Save sub dialogs - ****************/ - - /* 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']) || isset($_POST['edit_apply'])) && (isset($this->dialog->config))){ - $this->dialog->save_object(); - $msgs= $this->dialog->check(); - if(count($msgs)!=0){ - foreach($msgs as $msg){ - print_red($msg); - } - }else{ - $this->dialog->save(); - FAI::save_release_changes_now(); - if (!isset($_POST['edit_apply'])){ - del_lock ($this->dn); - unset($this->dialog); - $this->dialog=FALSE; - $this->is_dialog=false; - session::un_set('objectinfo'); - } - } - } - - - /**************** - Display currently open dialog - ****************/ - - /* 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(is_object($this->dialog)){ - $display .= $this->dialog->execute(); - /* Don't show buttons if tab dialog requests this */ - - if(isset($this->dialog->current)){ - - $obj = $this->dialog->by_object[$this->dialog->current]; - - if((isset($obj->is_dialog) && (!$obj->is_dialog)) || (isset($obj->dialog) && (!$obj->dialog))){ - - $display.= "

\n"; - $display.= "\n"; - $display.= " \n"; - if ($this->dn != "new"){ - $display.= "\n"; - $display.= " \n"; - } - $display.= "\n"; - $display.= "

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

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

"; - } - }else{ - $display.= "

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

"; - - } - return($display); - } - - - /**************** - Dialog display - ****************/ - - /* Check if there is a snapshot dialog open */ - $base = $this->DivListFai->selectedBase; - if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){ - return($str); - } - - /* Display dialog with system list */ - $this->DivListFai->parent = $this; - $this->DivListFai->execute(); - $this->DivListFai->AddDepartments($this->DivListFai->selectedBase,4,1); - $this->reload(); - $this->DivListFai->setEntries($this->objects); - return($this->DivListFai->Draw()); - } - - - /* Return departments, that will be included within snapshot detection */ - function get_used_snapshot_bases() - { - $tmp = array(); - $types = array("faipartitionou","faiscriptou","faitemplateou","faihookou","faiprofileou","faivariableou","faipackageou"); - foreach($types as $type){ - if($this->DivListFai->selectedBranch == "main"){ - $tmp[] = get_ou($type).get_ou('faiou').$this->DivListFai->selectedBase; - }else{ - $tmp[] = get_ou($type).$this->DivListFai->selectedBranch; - } - } - return($tmp); - } - - - /* Get available branches for current base */ - function getBranches($base = false,$prefix = "") - { - $ret = array("/"=>"main"); - $ldap = $this->config->get_ldap_link(); - if(!$base){ - $base = session::get('CurrentMainBase'); - } - $tmp = FAI::get_all_releases_from_base($base,true); - foreach($tmp as $dn => $name){ - $ret[$name]=$dn; - } - ksort($ret); - $ret = array_flip($ret); - - return ($ret); - } - - - function list_get_selected_items() - { - $ids = array(); - foreach($_POST as $name => $value){ - if(preg_match("/^item_selected_[0-9]*$/",$name)){ - $id = preg_replace("/^item_selected_/","",$name); - $ids[$id] = $id; - } - } - return($ids); - } - - - /* reload list of objects */ - function reload() - { - /* Variable initialisation */ - $str = ""; - $Regex = $this->DivListFai->Regex; - $this->objects = array(); - - /* Get base */ - $base = get_ou('faiou').$this->DivListFai->selectedBase; - if($this->DivListFai->selectedBranch != "main"){ - $br = $this->getBranches(); - if(isset($br[$this->DivListFai->selectedBranch])){ - $base = $this->DivListFai->selectedBranch; - }else{ - $base = get_ou('faiou').$this->DivListFai->selectedBase; - } - } - $this->base = $base; - $this->set_acl_base($this->base); - - $this->lock_type = FAI::get_release_tag(FAI::get_release_dn($base)); - - /* Create a new list of FAI object - * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ... - */ - $ObjectTypes = array( - "FAIpartitionTable" => array("OU"=> get_ou('faipartitionou') , "CHKBOX"=>"ShowPartitions" ,"ACL" => "faiPartitionTable"), - "FAIpackageList" => array("OU"=> get_ou('faipackageou') , "CHKBOX"=>"ShowPackages" ,"ACL" => "faiPackage"), - "FAIscript" => array("OU"=> get_ou('faiscriptou') , "CHKBOX"=>"ShowScripts" ,"ACL" => "faiScript"), - "FAIvariable" => array("OU"=> get_ou('faivariableou') , "CHKBOX"=>"ShowVariables" ,"ACL" => "faiVariable"), - "FAIhook" => array("OU"=> get_ou('faihookou') , "CHKBOX"=>"ShowHooks" ,"ACL" => "faiHook"), - "FAIprofile" => array("OU"=> get_ou('faiprofileou') , "CHKBOX"=>"ShowProfiles" ,"ACL" => "faiProfile"), - "FAItemplate" => array("OU"=> get_ou('faitemplateou') , "CHKBOX"=>"ShowTemplates" ,"ACL" => "faiTemplate")); - - $filter = ""; - foreach($ObjectTypes as $key => $data){ - if($this->DivListFai->$data['CHKBOX']){ - $filter.= "(objectClass=".$key.")"; - } - } - $filter = "(&(|".$filter.")(cn=$Regex))"; - - /* Get resolved release dependencies */ - $tmp = FAI::get_all_objects_for_given_base($base,$filter); - - /* Ge listed ldap objects */ - $ldap = $this->config->get_ldap_link(); - $ldap->cd($this->config->current['BASE']); - foreach($tmp as $entry){ - - /* Get some more informations about the object */ - $ldap->cat($entry['dn'], array("cn","description","objectClass","FAIclass","FAIstate","objectClass")); - $object = $ldap->fetch(); - - /* Walk through possible types */ - foreach($ObjectTypes as $type => $rest){ - - $acl = $this->ui->get_permissions($object['dn'],"fai/".$rest ['ACL']); - - if(in_array($type,$object['objectClass']) && preg_match("/r/",$acl)){ - - /* Prepare object */ - unset($object['objectClass']['count']); - if(!isset($object['description'][0])){ - $object['description'][0]=""; - } - - /* Clean up object informations */ - $obj = array(); - $obj['cn'] = $object['cn'][0]; - $obj['dn'] = $object['dn']; - $obj['acl'] = $acl; - $obj['description'] = $object['description'][0]; - $obj['objectClass'] = $object['objectClass']; - - /* Append type to this string, to be able to check if the selected - * entry is of type 'freeze' or 'branch' - */ - if(!isset($object['FAIstate'])){ - $obj['FAIstate'] = $this->lock_type; - }else{ - $obj['FAIstate'] = $object['FAIstate'][0]; - } - - $this->objects[strtolower($obj['cn']).$obj['cn'].$type] = $obj; - $this->objects[strtolower($obj['cn']).$obj['cn'].$type]['type']=$type; - } - } - } - - ksort($this->objects); - reset ($this->objects); - - /* use numeric index, thats a bit more secure */ - $tmp0 = array(); - foreach($this->objects as $obj){ - $tmp0[]= $obj; - } - $this->objects = array(); - $this->objects = $tmp0; - } - - function remove_lock() - { - if (isset($this->dn)){ - del_lock ($this->dn); - } - } - - function get_type($array){ - if(in_array("FAIpartitionTable",$array['objectClass'])){ - return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS")); - } - if(in_array("FAIscript",$array['objectClass'])){ - return(array("tabsScript","faiScript","FAISCRIPTTABS")); - } - if(in_array("FAItemplate",$array['objectClass'])){ - return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS")); - } - if(in_array("FAIhook",$array['objectClass'])){ - return(array("tabsHook","faiHook","FAIHOOKTABS")); - } - if(in_array("FAIvariable",$array['objectClass'])){ - return(array("tabsVariable","faiVariable","FAIVARIABLETABS")); - } - if(in_array("FAIprofile",$array['objectClass'])){ - return(array("tabsProfile","faiProfile","FAIPROFILETABS")); - } - - if(in_array("FAIpackageList",$array['objectClass'])){ - return(array("tabsPackage","faiPackage","FAIPACKAGETABS")); - } - } - - function CheckNewBranchName($name,$base) - { - $f = $this->DivListFai->selectedBranch; - if($name == ""){ - return(false); - }elseif(in_array($name,$this->getBranches($f))) { - return(false); - }elseif(tests::is_department_name_reserved($name,$base)){ - return(false); - } - return(true); - } - - function save_object() - { - $this->DivListFai->save_object(); - } - - - function copyPasteHandling_from_queue($s_action,$s_entry) - { - /* Check if Copy & Paste is disabled */ - if(!is_object($this->CopyPasteHandler)){ - return(""); - } - - $base = $this->DivListFai->selectedBranch; - if($base == "main"){ - $base = $this->DivListFai->selectedBase; - } - - /* Add a single entry to queue */ - if($s_action == "cut" || $s_action == "copy"){ - - /* Cleanup object queue */ - $this->CopyPasteHandler->cleanup_queue(); - $entry = $this->objects[$s_entry]; - $a_setup = $this->get_type($entry); - $dn = $entry['dn']; - $this->CopyPasteHandler->add_to_queue($dn,$s_action,$a_setup[0],$a_setup[2],"fai");//$a_setup[1]); - } - - /* Add entries to queue */ - if($s_action == "copy_multiple" || $s_action == "cut_multiple"){ - - /* Cleanup object queue */ - $this->CopyPasteHandler->cleanup_queue(); - - /* Add new entries to CP queue */ - foreach($this->list_get_selected_items() as $id){ - - /* Cleanup object queue */ - $entry = $this->objects[$id]; - $a_setup = $this->get_type($entry); - $dn = $entry['dn']; - - - if($s_action == "copy_multiple"){ - $this->CopyPasteHandler->add_to_queue($dn,"copy",$a_setup[0],$a_setup[2],"fai");//$a_setup[1]); - } - if($s_action == "cut_multiple"){ - $this->CopyPasteHandler->add_to_queue($dn,"cut",$a_setup[0],$a_setup[2],"fai");//$a_setup[1]); - } - } - } - - /* Start pasting entries */ - if($s_action == "editPaste"){ - $this->start_pasting_copied_objects = TRUE; - } - - /* Return C&P dialog */ - if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){ - - /* Load entry from queue and set base */ - $this->CopyPasteHandler->load_entry_from_queue(); - $this->CopyPasteHandler->SetVar("base",$base); - - /* Get dialog */ - $data = $this->CopyPasteHandler->execute(); - - FAI::save_release_changes_now(); - - /* Return dialog data */ - if(!empty($data)){ - return($data); - } - } - - /* Automatically disable status for pasting */ - if(!$this->CopyPasteHandler->entries_queued()){ - $this->start_pasting_copied_objects = FALSE; - } - return(""); - } - - - /* Return plugin informations for acl handling */ - static function plInfo() - { - return (array( - "plShortName" => _("FAI releases"), - "plDescription" => _("FAI release management"), - "plSelfModify" => FALSE, - "plDepends" => array(), - "plPriority" => 0, - "plSection" => array("administration"), - "plCategory" => array("fai"=> array("description" => _("FAI"), - "objectClass" => "FAIclass")), - "plProvidedAcls"=> array())); - } -} -// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: -?> diff --git a/gosa-core/plugins/admin/fai/class_faiPackage.inc b/gosa-core/plugins/admin/fai/class_faiPackage.inc deleted file mode 100644 index 6d6826222..000000000 --- a/gosa-core/plugins/admin/fai/class_faiPackage.inc +++ /dev/null @@ -1,659 +0,0 @@ - "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","FAIpackage","FAIdebianRelease","FAIdebianSection", "FAIinstallMethod"); - - /* ObjectClasses for this Object*/ - var $objectclasses = array("top","FAIclass","FAIpackageList","FAIrepository"); - - /* Class name of the Ldap ObjectClass for the Sub Object */ - var $subClass = ""; - var $subClasses = array("top","FAIclass","FAIscriptEntry"); - - /* Class name of the php class which allows us to edit a Sub Object */ - var $subClassName = ""; - - /* Attributes to initialise for each subObject */ - var $subAttributes = array("cn","description"); - var $sub64coded = array(); - - var $ConfiguredPackages = array(); - - /* 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 $SubObjects = array(); // All leafobjects of this object - - var $FAIdebianRelease = ""; // The selected release - var $FAIdebianSection = array(); // selected section - var $FAIinstallMethod = "aptitude"; // hard coded - var $mirror = ""; // selected mirror - - var $servers = array(); // All available servers - var $releases = array(); // All possible releases - var $sections = array(); // All section types - - var $list = NULL; - - var $mirrors = array(); // The combination of server/release/section - var $confDir = ""; - var $usedPackages = array(); - var $buffer = NULL; - var $strID =""; - var $newDialogShown =false; - - var $FAIstate = ""; - var $view_logged = FALSE; - var $base; - - var $FAIinstallMethods = array( "install", "ninstall", "remove", - "dselect-upgrade", "taskinst", "taskrm", - "hold", "clean", "aptitude", "aptitude-r", - "pending", "dpkgc" ); - - - function faiPackage (&$config, $dn= NULL) - { - /* Load Attributes */ - plugin::plugin ($config, $dn); - - /* If "dn==new" we try to create a new entry - * Else we must read all objects from ldap which belong to this entry. - * First read SubObjects from ldap ... and then the partition definitions for the SubObjects. - */ - if($dn != "new"){ - $this->dn =$dn; - - /* Get FAIstate - */ - if(isset($this->attrs['FAIstate'][0])){ - $this->FAIstate = $this->attrs['FAIstate'][0]; - } - } - - if(isset($this->attrs['FAIpackage'])){ - unset($this->attrs['FAIpackage']['count']); - foreach($this->attrs['FAIpackage'] as $pkg){ - $this->usedPackages[$pkg] = $pkg; - } - ksort($this->usedPackages); - }else{ - $this->usedPackages = array(); - } - - if($dn != "new"){ - - /* Create one filter with all package names, - instead of calling $ldap->search for every single package - */ - $PackageFilter = ""; - foreach($this->usedPackages as $name){ - $PackageFilter .= "(FAIpackage=".$name.")"; - } - $PackageFilter = "(&(objectClass=FAIdebconfInfo)(|".$PackageFilter."))"; - - /* Search for configuration objects */ - $ldap = $this->config->get_ldap_link(); - $ldap->cd($this->dn); - $ldap->search($PackageFilter,array("FAIvariable","FAIvariableType","FAIvariableContent","FAIpackage","FAIdebianSection","FAIstate")); - - /* Walk through configurations and append them to our list of ConfiguredPackages */ - while($attr = $ldap->fetch()){ - - /* Skip objects, that are tagged as removed */ - if(isset($object['FAIstate'][0])){ - if(preg_match("/removed$/",$attr['FAIstate'][0])){ - continue; - } - } - - $tmp =array(); - $tmp['Name'] = $attr['FAIvariable'][0]; - $tmp['Type'] = $attr['FAIvariableType'][0]; - - if (isset($attr['FAIvariableContent'][0])){ - if(!in_array($attr['FAIvariableType'],array("multiselect"))){ - $tmp['Value'] = $attr['FAIvariableContent'][0]; - }else{ - $content = array(); - unset($attr['FAIvariableContent']['count']); - foreach($attr['FAIvariableContent'] as $attr){ - $tmp['Value'][] = $attr; - } - } - $this->ConfiguredPackages[$attr['FAIpackage'][0]][$attr['FAIvariable'][0]]=$tmp; - } - } - } - - if (isset($this->attrs['FAIdebianSection']['count'])){ - unset($this->attrs['FAIdebianSection']['count']); - } - if((isset($this->attrs['FAIdebianSection']))&&(is_array($this->attrs['FAIdebianSection']))){ - $this->FAIdebianSection = array(); - foreach($this->attrs['FAIdebianSection'] as $sec){ - $this->FAIdebianSection[$sec]=$sec; - } - } - - if((isset($this->attrs['FAIdebianSection']))&&(is_string($this->attrs['FAIdebianSection']))){ - $this->FAIdebianSection=array($this->attrs['FAIdebianSection']=>$this->attrs['FAIdebianSection']) ; - } - $this->confDir = CONFIG_DIR."/fai/"; - $this->FAIpackage = array(); - - - $methods = array(); - foreach($this->FAIinstallMethods as $method){ - $methods[$method] = $method; - } - $this->FAIinstallMethods = $methods; - /* Check if we exist already - no need to ask for revisions, etc. then */ - if ($this->dn != "new"){ - $this->newDialogShown= true; - } - - } - - function execute() - { - /* Call parent execute */ - plugin::execute(); - - if($this->is_account && !$this->view_logged){ - $this->view_logged = TRUE; - new log("view","fai/".get_class($this),$this->dn); - } - - /* Fill templating stuff */ - $smarty= get_smarty(); - $display= ""; - - $smarty->assign( "FAIinstallMethods", $this->FAIinstallMethods ); - - if(!$this->is_account){ - - /* Assemble release name */ - $faifilter = session::get('faifilter'); - $tmp= preg_replace('/,'.normalizePreg(get_ou('faiou')).'.*$/', '', $faifilter['branch']); - $tmp= preg_replace('/ou=/', '', $tmp); - $rev= array_reverse(split(',', $tmp)); - $this->FAIdebianRelease= ""; - foreach ($rev as $part){ - $this->FAIdebianRelease.= "/$part"; - } - $this->FAIdebianRelease= preg_replace('#^/#', '', $this->FAIdebianRelease); - - /* Assemble sections */ - $repos= $this->getServerInfos(); - if(isset($repos[$this->FAIdebianRelease])){ - $this->FAIdebianSection= $repos[$this->FAIdebianRelease]; - $this->FAIdebianSection= array_unique($this->FAIdebianSection); - } - - /* Assign Repository settings*/ - $this->is_account = true; - } - - /* Assign variables */ - foreach($this->attributes as $attrs){ - $smarty->assign($attrs,$this->$attrs); - } - - /* Generate package list */ - $this->list= $this->genPkgs(); - - /* + was pressed to open the package dialog */ - if(isset($_POST['Addpkg']) && $this->acl_is_writeable("FAIpackage")){ - $this->dialog = new faiPackageEntry($this->config, $this->dn,$this->list,$this->usedPackages); - $this->is_dialog =true; - } - - /* Delte selected package */ - if(isset($_POST['Delpkg']) && $this->acl_is_writeable("FAIpackage")){ - if($this->FAIstate != "freeze"){ - foreach($_POST['usedPackages'] as $del){ - if(isset($this->usedPackages[$del])){ - unset($this->usedPackages[$del]); - } - } - } - } - - /* Abort package selection dialog */ - if(isset($_POST['CancelSubObject'])){ - $this->dialog = false; - $this->is_dialog=false; - } - - /* attach new packages */ - if(isset($_POST['SaveSubObject'])) { - if($this->FAIstate != "freeze"){ - $this->dialog->save_object(); - if(count($this->dialog->check())){ - foreach($this->dialog->check() as $msgs){ - print_red($msgs); - } - }else{ - $use = $this->dialog->save(); - $this->usedPackages = $use; - $this->dialog = false; - $this->is_dialog=false; - ksort($this->usedPackages); - } - }else{ - $this->dialog = false; - $this->is_dialog=false; - } - } - - /* Configuration dialog open*/ - if((isset($_POST['Conpkg']))&&(isset($_POST['usedPackages']))&&(!empty($_POST['usedPackages'][0])) && $this->acl_is_writeable("FAIdebconfInfo")){ - $path = CONFIG_DIR."/fai/".$this->FAIdebianRelease."/debconf.d"; - $pkg_config = array(); - $pkg = $_POST['usedPackages'][0]; - - if(isset($this->ConfiguredPackages[$pkg])){ - $pkg_config = $this->ConfiguredPackages[$pkg]; - } - - $this->dialog = new faiPackageConfiguration($this->config, $this->dn,$pkg, $path, $pkg_config); - $this->is_dialog =true; - } - - /* Configuration dialog open*/ - if($this->FAIstate != "freeze" && $this->acl_is_writeable("FAIpackage")){ - if((isset($_POST['Markpkg']))&&(isset($_POST['usedPackages']))&&(!empty($_POST['usedPackages']))){ - foreach($_POST['usedPackages'] as $pkg){ - if (isset($this->usedPackages[$pkg])){ - unset($this->usedPackages[$pkg]); - if (preg_match('/^-/', $pkg)){ - $pkg= preg_replace('/^-/', '', $pkg); - } else { - $pkg= preg_replace('/^/', '-', $pkg); - } - $this->usedPackages[$pkg]= $pkg; - } - } - } - } - - /* Save Configuration */ - if(isset($_POST['SaveObjectConfig'])){ - if($this->FAIstate != "freeze"){ - $this->ConfiguredPackages= array_merge($this->ConfiguredPackages,$this->dialog->save()); - } - $this->dialog = false; - $this->is_dialog=false; - } - - /* cancel configuration */ - if(isset($_POST['CancelObjectConfig'])){ - $this->dialog = false; - $this->is_dialog=false; - } - - /* Display dialog */ - if($this->is_dialog){ - return $this->dialog->execute(); - } - - /* Assign section to smarty */ - $strsec = ""; - foreach($this->FAIdebianSection as $sec){ - $strsec .= $sec." "; - } - - $tmp = $this->plInfo(); - foreach($tmp['plProvidedAcls'] as $name => $translated){ - $smarty->assign($name."ACL",$this->getacl($name,preg_match("/freeze/",$this->FAIstate))); - } - - $smarty->assign("releases",$this->releases); - $smarty->assign("release" ,$this->FAIdebianRelease); - $smarty->assign("sections",$this->sections); - $smarty->assign("section" ,$strsec); - $smarty->assign("usedPackages",$this->printUsedPackages()); - $display.= $smarty->fetch(get_template_path('faiPackage.tpl', TRUE)); - return($display); - } - - /* Delete me, and all my subtrees - */ - function remove_from_parent() - { - $ldap = $this->config->get_ldap_link(); - $ldap->cd ($this->dn); - - $use_dn = preg_replace("/".normalizePreg(FAI::get_release_dn($this->dn))."/i", $faifilter['branch'], $this->dn); - if($faifilter['branch'] == "main"){ - $use_dn = $this->dn; - } - - FAI::prepare_to_save_FAI_object($use_dn,array(),true); - - new log("remove","fai/".get_class($this),$use_dn,$this->attributes); - - foreach($this->ConfiguredPackages as $pkgname => $attrs){ - foreach($attrs as $name => $attr){ - $pkgdn = "FAIvariable=".$name.",".$this->dn; - $use_dn = preg_replace("/".normalizePreg(FAI::get_release_dn($this->dn))."/i", $faifilter['branch'], $pkgdn); - if($faifilter['branch'] == "main"){ - $use_dn = $obj['dn']; - } - FAI::prepare_to_save_FAI_object($use_dn,array(),true); - } - } - $this->handle_post_events("remove"); - } - - - /* Save data to object - */ - function save_object() - { - if($this->FAIstate == "freeze") return; - plugin::save_object(); - } - - - /* Check supplied data */ - function check() - { - /* Call common method to give check the hook */ - $message= plugin::check(); - - if(count($this->usedPackages)==0){ - $message[]=_("Please select a least one Package."); - } - - if((empty($this->FAIdebianRelease))||(empty($this->FAIdebianSection))){ - $message[]=_("Please choose a valid combination for your repository setup."); - } - - return ($message); - } - - function printUsedPackages(){ - $a_ret=array(); - if(is_array($this->usedPackages)) { - foreach($this->usedPackages as $usedName){ - - $config = 0; - - foreach($this->ConfiguredPackages as $name => $value){ - if($name == $usedName){ - $config ++; - } - } - - $c_str =""; - if($config){ - $c_str = " - "._("package is configured"); - } - - /* Adapt used name if we're marked for removal */ - $dsc= ""; - if (preg_match('/^-/', $usedName)){ - $dsc= " - "._("Package marked for removal"); - // Generally a bad idea here, because the toggel triggers on -, not on ! - //$usedName= preg_replace('/^-/', '! ', $usedName); - }else{ - $usedName2= $usedName; - } - - if(isset($this->list[$usedName][1])){ - $a_ret[$usedName] = $usedName2." [".$this->list[$usedName][1]."]".$c_str.$dsc; - }else{ - $a_ret[$usedName] = $usedName2.$c_str.$dsc; - } - } - } - return($a_ret); - } - - function genPkgs() - { - /* Generate a list off available packages for this mirror, section and release - */ - /* Only read this file if it wasn't read before */ - if($this->buffer === NULL){ - $this->buffer=array(); - $a_ret = array(); - foreach($this->FAIdebianSection as $sec){ - $strID= CONFIG_DIR."/fai/".$this->FAIdebianRelease."/".$sec; - - if(!is_file($strID)){ - print_red(sprintf(_("Package file '%s' does not exist."),$strID)); - unset($this->buffer); - return(array()); - } - $fp = fopen($strID,"r"); - - /* Parse every line and create an array */ - while(!feof($fp)){ - $str= fgets($fp,512); - $stra= split("\|",$str); - if(count($stra)==4){ - $a_ret[$stra[0]] = $stra; - } - } - fclose($fp); - /* Save our Data, to avoid reading it again */ - } - $this->buffer = $a_ret; - ksort($a_ret); - return($a_ret); - }else{ - return $this->buffer; - } - } - - - /* Save to LDAP */ - function save() - { - - /* Assemble release name */ - if($this->FAIdebianRelease == "ClearFromCopyPaste"){ - $faifilter = session::get('faifilter'); - $tmp= preg_replace('/,'.normalizePreg(get_ou('faiou')).'.*$/', '', $faifilter['branch']); - $tmp= preg_replace('/ou=/', '', $tmp); - $rev= array_reverse(split(',', $tmp)); - $this->FAIdebianRelease= ""; - foreach ($rev as $part){ - $this->FAIdebianRelease.= "/$part"; - } - $this->FAIdebianRelease= preg_replace('#^/#', '', $this->FAIdebianRelease); - } - - plugin::save(); - - $ldap = $this->config->get_ldap_link(); - - $this->attrs['FAIpackage'] = array(); - foreach($this->usedPackages as $pkg => $obj){ - $this->attrs['FAIpackage'][] = $pkg; - } - - $this->attrs['FAIdebianSection'] = array(); - foreach($this->FAIdebianSection as $sec){ - $this->attrs['FAIdebianSection'][] = $sec; - } - - FAI::prepare_to_save_FAI_object($this->dn,$this->attrs); - show_ldap_error($ldap->get_error(), sprintf(_("Saving of FAI/package list with dn '%s' failed."),$this->dn)); - - if($this->initially_was_account){ - new log("modify","fai/".get_class($this),$this->dn,$this->attributes); - }else{ - new log("create","fai/".get_class($this),$this->dn,$this->attributes); - } - - $ldap->cd($this->dn); - - /* Save Package configurations */ - foreach($this->ConfiguredPackages as $pkgname => $attrs){ - foreach($attrs as $name => $attr){ - - $pkgattrs = array(); - - foreach($attr as $n=>$v){ - if(empty($v)) $v = array(); - } - - /* Set attributes */ - $pkgattrs['objectClass'][] = "FAIdebconfInfo"; - - $pkgattrs['FAIpackage'] = $pkgname; - $pkgattrs['FAIvariable'] = $name; - $pkgattrs['FAIvariableType'] = $attr['Type']; - $pkgattrs['FAIvariableContent'] = $attr['Value']; - $pkgdn = "FAIvariable=".$name.",".$this->dn; - - /* Tag object */ - $this->tag_attrs(&$pkgattrs, $pkgdn, $this->gosaUnitTag); - - if(in_array($pkgattrs['FAIvariableType'],array("boolean","multiselect","password","select","string","text"))){ - FAI::prepare_to_save_FAI_object($pkgdn,$pkgattrs); - } - } - } - } - - /* Return plugin informations for acl handling */ - static function plInfo() - { - return (array( - "plShortName" => _("Package"), - "plDescription" => _("FAI Package list"), - "plSelfModify" => FALSE, - "plDepends" => array(), - "plPriority" => 28, - "plSection" => array("administration"), - "plCategory" => array("fai"), - "plProvidedAcls" => array( - "cn" => _("Name"), - "description" => _("Description"), - "FAIpackage" => _("Packages"), - "FAIdebianSection" => _("Section")." ("._("Readonly").")", - "FAIinstallMethod" => _("Install Method"), - "FAIdebconfInfo" => _("Package configuration"), - "FAIdebianRelease" => _("Release")." ("._("Readonly").")") - )); - } - - - - - function PrepareForCopyPaste($source) - { - plugin::PrepareForCopyPaste($source); - - if(isset($source['FAIstate'][0])){ - $this->FAIstate = $source['FAIstate'][0]; - } - - $this->FAIdebianRelease = "ClearFromCopyPaste"; - - if(isset($source['FAIpackage'])){ - unset($source['FAIpackage']['count']); - foreach($source['FAIpackage'] as $pkg){ - $this->usedPackages[$pkg] = $pkg; - } - ksort($this->usedPackages); - }else{ - $this->usedPackages = array(); - } - - if((isset($source['FAIdebianSection']))&&(is_array($source['FAIdebianSection']))){ - $this->FAIdebianSection = array(); - for($i = 0 ; $i < $source['FAIdebianSection']['count'] ; $i ++){ - $this->FAIdebianSection[$source['FAIdebianSection'][$i]]=$source['FAIdebianSection'][$i]; - } - } - - /* Create one filter with all package names, - instead of calling $ldap->search for every single package - */ - $PackageFilter = ""; - foreach($this->usedPackages as $name){ - $PackageFilter .= "(FAIpackage=".$name.")"; - } - $PackageFilter = "(&(objectClass=FAIdebconfInfo)(|".$PackageFilter."))"; - - /* Search for configuration objects */ - $ldap = $this->config->get_ldap_link(); - $ldap->cd($source['dn']); - $ldap->search($PackageFilter,array("FAIvariable","FAIvariableType","FAIvariableContent","FAIpackage","FAIdebianSection","FAIstate")); - - /* Walk through configurations and append them to our list of ConfiguredPackages */ - while($attr = $ldap->fetch()){ - - /* Skip objects, that are tagged as removed */ - if(isset($object['FAIstate'][0])){ - if(preg_match("/removed$/",$attr['FAIstate'][0])){ - continue; - } - } - - $tmp =array(); - $tmp['Name'] = $attr['FAIvariable'][0]; - $tmp['Type'] = $attr['FAIvariableType'][0]; - - if (isset($attr['FAIvariableContent'][0])){ - if(!in_array($attr['FAIvariableType'],array("multiselect"))){ - $tmp['Value'] = $attr['FAIvariableContent'][0]; - }else{ - $content = array(); - unset($attr['FAIvariableContent']['count']); - foreach($attr['FAIvariableContent'] as $attr){ - $tmp['Value'][] = $attr; - } - } - $this->ConfiguredPackages[$attr['FAIpackage'][0]][$attr['FAIvariable'][0]]=$tmp; - } - } - } - - - function getServerInfos() - { - $ret = array(); - $ldap = $this->config->get_ldap_link(); - $ldap->cd($this->config->current['BASE']); - $ldap->search("(objectClass=FAIrepositoryServer)",array("*")); - while($attrs = $ldap->fetch()){ - if(isset($attrs['FAIrepository'])){ - for($i =0 ; $i < $attrs['FAIrepository']['count']; $i++){ - $obj = $attrs['FAIrepository'][$i]; - $tmp = split("\|",$obj); - if(count($tmp)==4){ - foreach(split(",",$tmp[3]) as $sec){ - if(!empty($sec)){ - $ret[$tmp[2]][] = $sec; - } - } - } - } - } - } - return($ret); - } - - -} - -// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: -?> diff --git a/gosa-core/plugins/admin/fai/class_faiPackageConfiguration.inc b/gosa-core/plugins/admin/fai/class_faiPackageConfiguration.inc deleted file mode 100644 index 18f3e2b6c..000000000 --- a/gosa-core/plugins/admin/fai/class_faiPackageConfiguration.inc +++ /dev/null @@ -1,84 +0,0 @@ - "Eins ist toll", "zwei" => "Zwei ist noch besser"); - - /* attribute list for save action */ - var $ignore_account = TRUE; - var $attributes = array(); - var $objectclasses = array(); - - var $Debconf_handle = NULL; - var $pkg_config ; - var $obj; - - function faiPackageConfiguration (&$config, $dn= NULL,$obj,$path,$pkg_config) - { - plugin::plugin ($config, $dn); - $this->obj = $obj; - $this->Debconf_handle = new debconf(); - $this->Debconf_handle->set_template_directory($path); - $this->Debconf_handle->set_package($this->obj); - $this->Debconf_handle->set_language(preg_replace('/_.*$/', '', get_browser_language())); - - if( $this->Debconf_handle->load() ) { - $this->pkg_config = $pkg_config; - - foreach($this->pkg_config as $var){ - $this->Debconf_handle->SetDefault($var['Name'],$var['Value']); - } - } - } - - function execute() - { - /* Call parent execute */ - plugin::execute(); - - /* Fill templating stuff */ - $smarty = get_smarty(); - $display = ""; - $smarty->assign("headline", sprintf(_("Debconf information for package '%s'"), $this->obj)); - - $this->Debconf_handle->PostCheck(); - - $smarty->assign("Config",$this->Debconf_handle->get_dialog()); - - $display.= $smarty->fetch(get_template_path('faiPackageConfiguration.tpl', TRUE)); - return($display); - } - - /* Save data to object */ - function save_object() - { - } - - /* Check supplied data */ - function check() - { - /* Call common method to give check the hook */ - $message= plugin::check(); - - return ($message); - } - - function save() - { - $this->Debconf_handle->PostCheck(); - $pkgs = $this->Debconf_handle->template; - - $tmp = array(); - foreach($pkgs as $pkg){ - $tmp[$this->obj][$pkg['Name']]['Value']= $pkg['Default']; - $tmp[$this->obj][$pkg['Name']]['Name'] = $pkg['Name']; - $tmp[$this->obj][$pkg['Name']]['Type'] = $pkg['Type']; - } - return($tmp); - } -} -// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: -?> diff --git a/gosa-core/plugins/admin/fai/class_faiPackageEntry.inc b/gosa-core/plugins/admin/fai/class_faiPackageEntry.inc deleted file mode 100644 index 3670a3af0..000000000 --- a/gosa-core/plugins/admin/fai/class_faiPackageEntry.inc +++ /dev/null @@ -1,200 +0,0 @@ - "Eins ist toll", "zwei" => "Zwei ist noch besser"); - - /* attribute list for save action */ - var $ignore_account= TRUE; - var $attributes = array(); - var $objectclasses= array(); - var $pkgs = array(); - - var $buffer = array(); - var $categories = array(); - var $searchStrPKG = ""; - var $selected = array(); - - /* Array with available class names */ - var $FAIAllclasses = array(); - - function faiPackageEntry (&$config, $dn= NULL,$pkgs,$selected=array()) - { - plugin::plugin ($config, $dn); - - $this->pkgs=$pkgs; - - if(session::is_set('searchStrPKG')){ - $this->searchStrPKG = session::get('searchStrPKG'); - } - $this->selected=$selected; - - $this->searchStrPKG= _("Please enter your search string here"); - } - - function execute() - { - /* Call parent execute */ - plugin::execute(); - - /* Fill templating stuff */ - $smarty = get_smarty(); - $display = ""; - - $divlist = new divlist("PackageEntry"); - $divlist->SetPluginMode(); - $divlist->SetSummary(_("This list displays all assigned package names for this repository settings.")); - $divlist->SetEntriesPerPage(0); - $divlist->SetHeight("650px;"); - $divlist->SetHeader(array(array("string" => " ", "attach" => "style='text-align:center;width:20px;'"), - array("string" => "Name", "attach" => "style='width:180px;'"), - array("string" => "Version", "attach" ), - array("string" => "Description", "attach" => "style='width:240px;border-right:0px;text-align:left;'"))); - - if(isset($_GET['search'])){ - $this->searchStrPKG= $_GET['search']."*"; - } - - $pkgs= $this->pkgs; - - unset($this->categories); - foreach($pkgs as $name => $entry){ - $cat = $entry[2]; - if(!empty($cat)){ - if(!isset($this->categories[$cat])){ - $this->categories[$cat] = true; - } - if(isset($_POST['chkchange'])){ - $this->searchStrPKG = $_POST['searchStrPKG']; - if(isset($_POST['CAT'.$cat])){ - $this->categories[$cat]=true; - }else{ - $this->categories[$cat]=false; - } - } - } - } - - $this->searchStrPKG = preg_replace("/^\+/","",$this->searchStrPKG); - if(empty($this->searchStrPKG)){ - $this->searchStrPKG = "*"; - } - - @ksort($this->categories); - -$CHKS = ""; - $i = 0; - if(is_array($this->categories)) - foreach($this->categories as $cat => $selected){ - if($i == 3){ - $CHKS .=""; - $i = 0; - } - $i ++ ; - if($selected){ - $CHKS .=""; - }else{ - $CHKS .=""; - } - } - $CHKS .= "
 ".$cat."  ".$cat." 
"; - - - foreach($_POST as $name => $value){ - if(preg_match("/^wasonpage_/i",$name)){ - $name = preg_replace("/^wasonpage_/","",$name); - $n =base64_decode($name); - - if(isset($_POST['use_'.$name])){ - $this->selected[$n] = $n; - }else{ - if(isset($this->selected[$n])){ - unset($this->selected[$n]); - } - } - - } - } - - /* Prepare search filter */ - $search_str = preg_replace("/\\\\\*/",".*",normalizePreg($this->searchStrPKG)); - - $cnt = 0; - foreach($pkgs as $pkg){ - if($cnt > 200) { - print_red(sprintf(_("Your specified search string '%s' returned too many results. Only the first 200 entries are shown, to keep the memory usage low."),$this->searchStrPKG)); - break; - } - if((preg_match("/^".$search_str."/i",$pkg[0]))|| - (preg_match("/^".$search_str."/i",$pkg[3]))){ - if($this->categories[$pkg[2]]){ - if(in_array($pkg[0],$this->selected)){ - $check = " checked "; - }else{ - $check = ""; - } - $cnt ++ ; - $chkbox = " - "; - $divlist->AddEntry(array(array("string"=>$chkbox, "attach" => "style='text-align:center;width:20px;'"), - array("string"=>$pkg[0], "attach" => "style='width:180px;'"), - array("string"=>htmlentities($pkg[1])), - array("string"=>htmlentities($pkg[3]), "attach" => "style='width:221px;border-right:0px;text-align:left;'"))); - } - } - } - - session::set('searchStrPKG',$this->searchStrPKG); - $smarty->assign("CHKS" , $CHKS); - $smarty->assign("searchStrPKG" , $this->searchStrPKG); - $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('faiPackageEntry.tpl', TRUE)); - return($display); - } - - /* Save data to object */ - function save_object() - { - foreach($_POST as $name => $value){ - if(preg_match("/^wasonpage_/i",$name)){ - $name = preg_replace("/^wasonpage_/","",$name); - $n =base64_decode($name); - if(isset($_POST['use_'.$name])){ - $this->selected[$n] = $n; - }else{ - if(isset($this->selected[$n])){ - unset($this->selected[$n]); - } - } - - } - } - - } - - /* Check supplied data */ - function check() - { - /* Call common method to give check the hook */ - $message= plugin::check(); - - return ($message); - } - - function save() - { - return($this->selected); - } -} -// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: -?> diff --git a/gosa-core/plugins/admin/fai/class_faiPartitionTable.inc b/gosa-core/plugins/admin/fai/class_faiPartitionTable.inc deleted file mode 100644 index 99417316e..000000000 --- a/gosa-core/plugins/admin/fai/class_faiPartitionTable.inc +++ /dev/null @@ -1,604 +0,0 @@ - "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"); - - /* Specific attributes */ - var $cn = ""; // The class name for this object - var $description = ""; // The description for this set of partitions - var $disks = array(); // All defined Disks - var $is_dialog = false; // specifies which buttons will be shown to save or abort - - var $FAIstate = ""; - var $ui; - - var $view_logged = FALSE; - - function faiPartitionTable (&$config, $dn= NULL) - { - /* Load Attributes */ - plugin::plugin ($config, $dn); - - $this->acl ="#all#"; - - $this->ui = get_userinfo(); - - /* If "dn==new" we try to create a new entry - * Else we must read all objects from ldap which belong to this entry. - * First read disks from ldap ... and then the partition definitions for the disks. - */ - if($dn != "new"){ - $this->dn =$dn; - - /* Get FAIstate - */ - if(isset($this->attrs['FAIstate'][0])){ - $this->FAIstate = $this->attrs['FAIstate'][0]; - } - - /* 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()){ - - /* Skip objects, that are tagged as removed */ - if(isset($object['FAIstate'][0])){ - if(preg_match("/removed$/",$object['FAIstate'][0])){ - continue; - } - } - - $this->disks[$object['cn'][0]]['status'] = "edited"; - $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()){ - - /* Skip objects, that are tagged as removed */ - if(isset($partition['FAIstate'][0])){ - if(preg_match("/removed$/",$partition['FAIstate'][0])){ - continue; - } - } - - /* 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]; - } - } - - /* Append fetched partitions - */ - $partition['status']="edited"; - $this->disks[$name]['partitions'][$partition['FAIpartitionNr']] = $partition; - } - } - } - ksort($this->disks); - } - - - function acl_base_for_current_object($dn) - { - if($dn == "new"){ - if($this->dn == "new"){ - $dn = session::get('CurrentMainBase'); - }else{ - $dn = $this->dn; - } - } - return($dn); - } - - - function execute() - { - /* Call parent execute */ - plugin::execute(); - - if($this->is_account && !$this->view_logged){ - $this->view_logged = TRUE; - new log("view","fai/".get_class($this),$this->dn); - } - - /* 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'])){ - $usedDiskNames =array(); - foreach($this->disks as $key=>$disk){ - $usedDiskNames[]= $key; - } - $this->dialog = new faiPartitionTableEntry($this->config,$this->dn,$usedDiskNames); - $this->dialog->set_acl_base($this->acl_base_for_current_object($this->dn)); - $this->dialog->set_acl_category("fai"); - $this->dialog->FAIstate = $this->FAIstate; - $this->is_dialog = true; - } - - /* Edit disk. - * Open dialog which allows us to edit the selected entry - */ - - if($this->dn != "new"){ - session::set('objectinfo',$this->dn); - } - - if((isset($_POST['EditDisk']))&&(isset($_POST['disks']))){ - $usedDiskNames =array(); - $Udisk = $_POST['disks'][0]; - if(isset($this->disks[$Udisk])){ - - foreach($this->disks as $key=>$disk){ - if($key != $Udisk){ - $usedDiskNames[]= $key; - } - } - - /* Set object info string, which will be displayed in plugin info line */ - if(isset($this->disks[$Udisk]['dn'])){ - session::set('objectinfo',$this->disks[$Udisk]['dn']); - $dn = $this->disks[$Udisk]['dn']; - }else{ - session::set('objectinfo',""); - $dn = "new"; - } - - $this->dialog = new faiPartitionTableEntry($this->config,$this->dn,$usedDiskNames,$this->disks[$Udisk]); - $this->dialog->set_acl_base($this->acl_base_for_current_object($dn)); - $this->dialog->set_acl_category("fai"); - $this->dialog->FAIstate = $this->FAIstate; - - $this->is_dialog = true; - } - } - - /* Edit aborted, close dialog, without saving anything - */ - if(isset($_POST['CancelDisk'])){ - unset($this->dialog); - $this->dialog = FALSE; - $this->is_dialog=false; - } - - /* Dialog saved - * Save given data from Dialog, if no error is occurred - */ - if(isset($_POST['SaveDisk'])){ - - if($this->FAIstate != "freeze"){ - $this->dialog->save_object(); - if(count($this->dialog->check())){ - foreach($this->dialog->check() as $msg){ - print_red($msg); - } - }else{ - $disk = $this->dialog->save(); - if(isset($disk['rename'])){ - if($this->disks[$disk['rename']['from']]['status']=="edited"){ - $this->disks[$disk['rename']['from']]['status']="delete"; - }else{ - unset($this->disks[$disk['rename']['from']]); - } - - foreach($disk['partitions'] as $key => $val){ - if($disk['partitions'][$key]['status']!="delete"){ - $disk['partitions'][$key]['status']= "new"; - } - } - - $disk['status']="new"; - $disk['cn']= $disk['rename']['to']; - } - - $this->disks[$disk['cn']]=$disk; - unset($this->dialog); - $this->dialog = FALSE; - $this->is_dialog=false; - ksort($this->disks); - } - }else{ - $this->dialog = FALSE; - $this->is_dialog=false; - } - } - - /* Delete selected disk drive from list - * Assign delete status for all its partitions - */ - if((isset($_POST['DelDisk']))&&(!empty($_POST['disks']))){ - if($this->FAIstate != "freeze"){ - foreach($_POST['disks'] as $disk) { - - if(isset($this->disks[$disk])){ - if($this->disks[$disk]['status']=="edited"){ - $this->disks[$disk."-delete"]=$this->disks[$disk]; - unset($this->disks[$disk]); - $disk = $disk."-delete"; - $this->disks[$disk]['status']="delete"; - foreach($this->disks[$disk]['partitions'] as $name => $value ){ - if($value['status']=="edited"){ - $this->disks[$disk]['partitions'][$name]['status']="delete"; - }else{ - unset($this->disks[$disk]['partitions'][$name]); - } - } - }else{ - unset($this->disks[$disk]); - } - } - } - } - } - - /* Display dialog if one is defined - */ - if(is_object($this->dialog)){ - $this->dialog->save_object(); - return($this->dialog->execute()); - } - - /* Assign all attributes to smarty engine - */ - foreach($this->attributes as $attrs){ - $smarty->assign($attrs,$this->$attrs); - if($this->$attrs){ - $smarty->assign($attrs."CHK"," "); - }else{ - $smarty->assign($attrs."CHK"," disabled "); - } - } - - $dn = $this->acl_base_for_current_object($this->dn); - $smarty->assign("sub_object_is_addable", - preg_match("/c/",$this->ui->get_permissions($dn,"fai/faiPartitionTableEntry")) && - !preg_match("/freeze/",$this->FAIstate)); - - $tmp = $this->plInfo(); - foreach($tmp['plProvidedAcls'] as $name => $translated){ - $smarty->assign($name."ACL",$this->getacl($name)); - } - $disks = $this->getDisks(); - $smarty->assign("disks" ,$disks); - $display.= $smarty->fetch(get_template_path('faiPartitionTable.tpl', TRUE)); - return($display); - } - - function getDisks(){ - /* Return all available disks for this partition table - * Return in listBox friendly array - */ - $a_return = array(); - foreach($this->disks as $key => $disk){ - - $dn = "new"; - if(isset($obj['dn'])){ - $dn = $obj['dn']; - } - $dn = $this->acl_base_for_current_object($dn); - $acl = $this->ui->get_permissions($dn,"fai/faiPartitionTableEntry"); - if(preg_match("/(r|w)/",$acl)) { - - if($disk['status'] != "delete"){ - $cnt=0; - foreach($disk['partitions'] as $val){ - if($val['status']!="delete"){ - $cnt ++; - } - } - if(!empty($disk['description'])){ - if($cnt == 1){ - $a_return[$key]= $disk['cn']." [".$disk['description']."], ".sprintf(_("%s partition"), $cnt); - }else{ - $a_return[$key]= $disk['cn']." [".$disk['description']."], ".sprintf(_("%s partition(s)"), $cnt); - } - }else{ - if($cnt == 1){ - $a_return[$key]= $disk['cn'].", ".sprintf(_("%s partition"), $cnt); - }else{ - $a_return[$key]= $disk['cn'].", ".sprintf(_("%s partition(s)"), $cnt); - } - } - } - } - } - return($a_return); - } - - - /* Delete me, and all my subtrees - */ - function remove_from_parent() - { - $ldap = $this->config->get_ldap_link(); - $ldap->cd ($this->dn); - - $faifilter = session::get('faifilter'); - $use_dn = preg_replace("/".normalizePreg(FAI::get_release_dn($this->dn))."/i", $faifilter['branch'], $this->dn); - if($faifilter['branch'] == "main"){ - $use_dn = $this->dn; - } - - FAI::prepare_to_save_FAI_object($use_dn,array(),true); - - new log("remove","fai/".get_class($this),$use_dn,$this->attributes); - - foreach($this->disks as $disk){ - - $disk_dn = "cn=".$disk['cn'].",".$this->dn; - $use_dn = preg_replace("/".normalizePreg(FAI::get_release_dn($this->dn))."/i", $faifilter['branch'], $disk_dn); - if($faifilter['branch'] == "main"){ - $use_dn = $disk_dn; - } - FAI::prepare_to_save_FAI_object($use_dn,array(),true); - - foreach($disk['partitions'] as $key => $partition){ - - $partition_dn= "FAIpartitionNr=".$partition['FAIpartitionNr'].",".$disk_dn; - $use_dn = preg_replace("/".normalizePreg(FAI::get_release_dn($this->dn))."/i", $faifilter['branch'], $partition_dn); - if($faifilter['branch'] == "main"){ - $use_dn = $disk_dn; - } - FAI::prepare_to_save_FAI_object($use_dn,array(),true); - } - } - } - - - /* Save data to object - */ - function save_object() - { - if($this->FAIstate == "freeze") return; - plugin::save_object(); - foreach($this->attributes as $attrs){ - if(isset($_POST[$attrs])){ - $this->$attrs = $_POST[$attrs]; - } - } - } - - - /* Check supplied data */ - function check() - { - /* Call common method to give check the hook */ - $message= plugin::check(); - - return ($message); - } - - - /* Save to LDAP */ - function save() - { - - plugin::save(); - /* Save current settings. - * 1 : We must save the partition table, with its description and cn - * 2 : Append Disk with cn and description. - * 3 : Save partitions for each disk - */ - - $ldap = $this->config->get_ldap_link(); - - FAI::prepare_to_save_FAI_object($this->dn,$this->attrs); - show_ldap_error($ldap->get_error(), sprintf(_("Saving of FAI/partition table with dn '%s' failed."),$this->dn)); - - if($this->initially_was_account){ - new log("modify","fai/".get_class($this),$this->dn,$this->attributes); - }else{ - new log("create","fai/".get_class($this),$this->dn,$this->attributes); - } - - /* Sort entries, because we must delete entries with status="delete" first */ - $order = array(); - foreach($this->disks as $key => $disk){ - if($disk['status'] == "delete"){ - $order[$key] = $disk; - } - } - foreach($this->disks as $key => $disk){ - if($disk['status'] != "delete"){ - $order[$key] = $disk; - } - } - - /* Append all disks to ldap */ - foreach($order as $cn=>$disk){ - $disk_dn = "cn=".$disk['cn'].",".$this->dn; - $disk_attrs['cn'] = $disk['cn']; - $disk_attrs['description'] = $disk['description']; - $disk_attrs['objectClass'] = array("top","FAIclass","FAIpartitionDisk"); - - if($disk['status']=="new"){ - $ldap->cat($disk_dn,array("objectClass")); - if($ldap->count()){ - $disk['status']="edited"; - } - } - - /* Tag object */ - $this->tag_attrs(&$disk_attrs, $disk_dn, $this->gosaUnitTag); - - if($disk['status'] == "delete"){ - FAI::prepare_to_save_FAI_object($disk_dn,array(),true); - $this->handle_post_events("remove"); - }elseif($disk['status'] == "edited"){ - FAI::prepare_to_save_FAI_object($disk_dn,$disk_attrs); - $this->handle_post_events("modify"); - }elseif($disk['status']=="new"){ - FAI::prepare_to_save_FAI_object($disk_dn,$disk_attrs); - $this->handle_post_events("add"); - } - - if($disk['status']!="delete") - /* Add all partitions */ - 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= "FAIpartitionNr=".$partition_attrs['FAIpartitionNr'].",".$disk_dn; - $partition_attrs['objectClass']= array("top","FAIclass","FAIpartitionEntry"); - $partition_attrs['cn']= $partition_attrs['FAIpartitionNr']; - - unset($partition_attrs['status']); - unset($partition_attrs['old_cn']); - - if($partition['status']=="new"){ - $ldap->cat($partition_dn,array("objectClass")); - if($ldap->count()){ - $partition['status']="edited"; - } - } - - if((!isset($partition['FAImountPoint']))||(empty($partition['FAImountPoint']))){ - $partition_attrs['FAImountPoint']="swap"; - } - - /* Tag object */ - $this->tag_attrs(&$partition_attrs, $partition_dn, $this->gosaUnitTag); - - if($partition['status'] == "delete"){ - FAI::prepare_to_save_FAI_object($partition_dn,array(),true); - $this->handle_post_events("remove"); - }elseif($partition['status'] == "edited"){ - FAI::prepare_to_save_FAI_object($partition_dn,$partition_attrs); - $this->handle_post_events("modify"); - }elseif($partition['status']=="new"){ - FAI::prepare_to_save_FAI_object($partition_dn,$partition_attrs); - $this->handle_post_events("add"); - } - } - } - $this->handle_post_events("add"); - } - - - function PrepareForCopyPaste($source) - { - plugin::PrepareForCopyPaste($source); - /* Get FAIstate - */ - if(isset($source['FAIstate'][0])){ - $this->FAIstate = $source['FAIstate'][0]; - } - - /* Read all disks from ldap taht are defined fot this partition table - */ - $ldap = $this->config->get_ldap_link(); - $ldap->cd ($source['dn']); - $ldap->search("(&(objectClass=FAIclass)(objectClass=FAIpartitionDisk))",array("*")); - while($object = $ldap->fetch()){ - - /* Skip objects, that are tagged as removed */ - if(isset($object['FAIstate'][0])){ - if(preg_match("/removed$/",$object['FAIstate'][0])){ - continue; - } - } - - $this->disks[$object['cn'][0]]['status'] = "edited"; - $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()){ - - /* Skip objects, that are tagged as removed */ - if(isset($partition['FAIstate'][0])){ - if(preg_match("/removed$/",$partition['FAIstate'][0])){ - continue; - } - } - - /* 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]; - } - } - - /* Append fetched partitions - */ - $partition['status']="edited"; - $this->disks[$name]['partitions'][$partition['FAIpartitionNr']] = $partition; - } - } - ksort($this->disks); - } - - - /* Return plugin informations for acl handling */ - static function plInfo() - { - return (array( - "plShortName" => _("Partition table"), - "plDescription" => _("FAI partition table"), - "plSelfModify" => FALSE, - "plDepends" => array(), - "plPriority" => 26, - "plSection" => array("administration"), - "plCategory" => array("fai"), - "plProvidedAcls" => array( - "cn" => _("Name")." ("._("Read only").")", - "description" => _("Description")) - )); - } -} - -// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: -?> diff --git a/gosa-core/plugins/admin/fai/class_faiPartitionTableEntry.inc b/gosa-core/plugins/admin/fai/class_faiPartitionTableEntry.inc deleted file mode 100644 index d72ec5149..000000000 --- a/gosa-core/plugins/admin/fai/class_faiPartitionTableEntry.inc +++ /dev/null @@ -1,521 +0,0 @@ - "Eins ist toll", "zwei" => "Zwei ist noch besser"); - - /* attribute list for save action */ - var $ignore_account= TRUE; - var $attributes = array("DISKcn","DISKdescription"); - var $objectclasses= array(); - - var $DISKcn = ""; - var $DISKdescription = ""; - - var $partitions = array(); - var $UsedAttrs = array(); - var $is_edit = false; - var $old_cn = ""; - var $status = "new"; - var $deletePartitions = array(); - - var $FAIstate = ""; - - function faiPartitionTableEntry (&$config, $dn= NULL,$usedDiskNames=array(),$disk=false) - { - plugin::plugin ($config, $dn); - $this->UsedAttrs = array("cn","description","FAIpartitionType","FAIpartitionNr","FAIfsType","FAImountPoint","FAIpartitionSize", - "FAImountOptions","FAIfsOptions","FAIpartitionFlags"); - - /* Default status is new */ - $this->status = "new"; - - /* We want to edit an entry */ - if($disk){ - - /* Set disk status */ - $this->status = $disk['status']; - - /* Walk through partitions */ - foreach($disk['partitions'] as $name => $values){ - - /* If a partition is already marked as delete, attach it to deletePartitions only. */ - if($values['status'] == "delete"){ - unset($disk['partitions'][$name]); - $this->deletePartitions[]=$values; - }else{ - - /* Set status, to know which partition must be deleted from ldap - new : Neu partition entry // save - edited : Update partition entry in ldap - deleted: Remove partition from ldap - */ - - /* If status is not new, set to edit mode. - * New means that this partition currently wasn't saved to ldap. - */ - if($disk['partitions'][$name]['status']!="new"){ - $disk['partitions'][$name]['status']="edited"; - } - - $disk['partitions'][$name]['old_cn']= $disk['partitions'][$name]['cn']; - - /* Assign empty attributes, if attribute is missing */ - foreach($this->UsedAttrs as $attr){ - if(!isset($values[$attr])){ - $disk['partitions'][$name][$attr]=""; - } - } - - if (preg_match('/^_/', $disk['partitions'][$name]['FAIfsType'])){ - $disk['partitions'][$name]['FAIfsType']= preg_replace('/^_/', '', $disk['partitions'][$name]['FAIfsType']); - $disk['partitions'][$name]['FAIencrypted']= true; - } else { - $disk['partitions'][$name]['FAIencrypted']= false; - } - } - } - - /* Set default attributes */ - $this->DISKcn = $disk['cn']; - $this->DISKdescription = $disk['description']; - $this->partitions = $disk['partitions']; - $this->is_edit = true; - $this->old_cn = $disk['cn']; - } - } - - - function execute() - { - /* Call parent execute */ - plugin::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)) && $this->acl_is_removeable()){ - $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" && $this->acl_is_removeable()){ - if($this->partitions[$s_entry]['status'] == "edited"){ - $this->deletePartitions[$s_entry]= $this->partitions[$s_entry]; - $this->deletePartitions[$s_entry]['FAIpartitionNr']=$s_entry; - unset($this->partitions[$s_entry]); - }else{ - 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']) && $this->acl_is_createable()){ - foreach($this->UsedAttrs as $attr){ - $tmp[$attr] = ""; - } - $tmp["old_cn"] = ""; - $tmp["FAIencrypted"] = FALSE; - $tmp['status']="new"; - $this->partitions[count($this->partitions)+1]=$tmp; - } - - /* $setup contains a table with the partitions. - */ - $smarty->assign("setup", $this->generateParts()); - foreach($this->attributes as $attr){ - $smarty->assign($attr,$this->$attr); - } - - $tmp = $this->plInfo(); - $sacl = ""; - foreach($tmp['plProvidedAcls'] as $name => $translated){ - - $acl = $this->getacl($name); - $sacl .= $acl; - if($this->FAIstate == "freezed"){ - $acl = preg_replace("/w/","",$acl); - } - $smarty->assign($name."ACL",$acl); - } - $smarty->assign("allowSave",$sacl); - - $smarty->assign("sub_object_is_createable",$this->acl_is_createable()); - - /* 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"=>_("primary"),"logical"=>_("logical")); - $FAIfsTypes = array("ext2","ext3","xfs","swap","reiser","dosfat16","winfat32"); - - /* Display Header */ - $str = ""; - if (count($this->partitions)){ - $str .= ""; - $str .= ""._("Type").""; - $str .= ""._("FS type").""; - $str .= ""._("Mount point").""; - $str .= ""._("Size in MB").""; - $str .= ""._("Mount options").""; - $str .= ""._("FS option").""; - $str .= ""._("Preserve").""; - $str .= ""._("Encrypted").""; - $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){ - - $dis = ""; - if($part['FAIpartitionFlags'] == "preserve"){ - $dis = " disabled "; - } - - $disableALL = ""; - if($this->FAIstate =="freeze"){ - $disableALL = " disabled "; - } - - if($part['status']!="delete"){ - - /* Generate Partition select box - */ - $PartitionType = ""; - if($this->acl_is_writeable("FAIpartitionType")){ - $PartitionType = ""; - }elseif($this->acl_is_readable("FAIpartitionType")){ - $PartitionType = $part['FAIpartitionType']; - } - - - /* Generate fsType select box - */ - $FAIfsType= ""; - if($this->acl_is_writeable("FAIfsType")){ - $FAIfsType= ""; - }elseif($this->acl_is_readable("FAIfsType")){ - $FAIfsType = $part['FAIfsType']; - } - - foreach(array("FAImountPoint","FAIpartitionSize","FAImountOptions","FAIfsOptions") as $attr){ - $$attr = ""; - if($this->acl_is_writeable($attr)){ - $$attr = ""; - - }elseif($this->acl_is_readable($attr)){ - $$attr = $part[$attr]; - } - } - - - $str .= "\n"; - $str .= "\n".$PartitionType.""; - $str .= "\n".$FAIfsType.""; - $str .= "\n".$FAImountPoint.""; - $str .= "\n".$FAIpartitionSize.""; - $str .= "\n".$FAImountOptions.""; - $str .= "\n".$FAIfsOptions.""; - - $changeState = "onClick=\"changeState('FAImountPoint_".$key."') ; ". - "changeState('FAIpartitionSize_".$key."') ; ". - "changeState('FAImountOptions_".$key."') ; ". - "changeState('FAIfsType_".$key."') ; ". - "changeState('FAIfsOptions_".$key."') ; \""; - - if($this->acl_is_writeable("FAIpartitionFlags")){ - if($part['FAIpartitionFlags']!=false){ - $str .= "\n"; - }else{ - $str .= "\n"; - } - if($part['FAIencrypted']!=false){ - $str .= "\n"; - }else{ - $str .= "\n"; - } - }else{ - if($part['FAIpartitionFlags']!=false){ - $str .= ""._("False").""; - }else{ - $str .= ""._("True").""; - } - if($part['FAIencrypted']!=false){ - $str .= ""._("False").""; - }else{ - $str .= ""._("True").""; - } - } - if($this->acl_is_removeable()){ - $str .= "\n"; - }else{ - $str .= "\n"; - } - $str .= "\n"; - } - } - - if(!empty($str)){ - $str = "".$str."
"; - } - return($str); - - } - - function save() - { - $tmp = array(); - $tmp['cn'] = $this->DISKcn; - - /* Attach partitions */ - foreach($this->partitions as $key=>$val) { - if (isset($this->partitions[$key]['FAIencrypted']) && $this->partitions[$key]['FAIencrypted']){ - unset ($this->partitions[$key]['FAIencrypted']); - $this->partitions[$key]['FAIfsType']= "_".$this->partitions[$key]['FAIfsType']; - } - $this->partitions[$key]['FAIpartitionNr']=$key; - } - - /* Attach deleted */ - foreach($this->deletePartitions as $key=>$val) { - $this->partitions[$key."-delete"]=$val; - $this->partitions[$key."-delete"]['status']="delete"; - } - - $tmp['description'] = $this->DISKdescription; - $tmp['partitions'] = $this->partitions; - $tmp['status'] = $this->status; - - /* If hdd name has changed, tell partitionTable to rename it */ - if(($this->is_edit)&&($this->old_cn != $this->DISKcn)){ - $tmp['rename']['from'] = $this->old_cn; - $tmp['rename']['to'] = $this->DISKcn; - } - return($tmp); - } - - - /* Save data to object */ - function save_object() - { - if((isset($_POST['TableEntryFrameSubmitted'])) && ($this->FAIstate != "freeze") ){ - plugin::save_object(); - - foreach($this->partitions as $key => $part){ - foreach($this->UsedAttrs as $attrs){ - - if($this->acl_is_writeable($attrs)){ - - if(isset($_POST[$attrs."_".$key])){ - $this->partitions[$key][$attrs] = $_POST[$attrs."_".$key]; - }else{ - $this->partitions[$key][$attrs] = false; - } - } - } - - if($this->acl_is_writeable("FAIencrypted")){ - - if(isset($_POST["FAIencrypted_".$key])){ - $this->partitions[$key]["FAIencrypted"] = $_POST["FAIencrypted_".$key]; - }else{ - $this->partitions[$key]["FAIencrypted"] = false; - } - } - - /* Adapt ext3 to have -j option */ - if ($this->partitions[$key]["FAIfsType"] == "ext3") { - $this->partitions[$key]["FAIfsOptions"]= preg_replace('/\s*-j\s*/', '', $this->partitions[$key]["FAIfsOptions"]); - $this->partitions[$key]["FAIfsOptions"]= "-j ".$this->partitions[$key]["FAIfsOptions"]; - } - } - - } - } - - - /* Check supplied data */ - function check() - { - /* Call common method to give check the hook */ - $message= plugin::check(); - - /* Check for an empty disk name */ - if(empty($this->DISKcn)){ - $message[] = _("Please specify a valid disc name."); - } - - /* check every partition. - * if there is an invalid value defined, append an errorstr to message - */ - - /* Array that contain every partitionname mountpoint etc already assigned */ - $alreadyUsed = array(); - foreach($this->UsedAttrs as $attrs){ - $alreadyUsed[$attrs] = array(); - } - - foreach($this->partitions as $key => $part){ - - /* Skip all checks, if preserve is set */ - if($part['FAIpartitionFlags'] == "preserve"){ - $this->partitions[$key]['FAIfsType'] = "preserve"; - $this->partitions[$key]['FAIpartitionSize'] = "preserve"; - continue; - } - - if((in_array($part['FAImountPoint'],$alreadyUsed['FAImountPoint']))&&($part['FAIfsType']!="swap")){ - $message[]=sprintf(_("please enter a unique mount point for partition %s"),($key)); - } - - if($part['FAIfsType']!="swap" && $part['FAImountPoint'] != "-"){ - 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)); - } - } - if($part['FAIfsType'] == "swap"){ - if(in_array($part['FAIfsType'],$alreadyUsed['FAIfsType'])){ - $message[]=sprintf(_("File system type 'swap' is already used, change file system type for partition %s."),$key); - } - } - if(($part['FAIfsType'] == "swap")&&(!empty($part['FAImountPoint']))&&($part['FAImountPoint']!="swap")){ - $message[]=_("Please use 'swap' as mount point, if 'swap' is used as fs-type."); - } - - $tmp = split("-",$part['FAIpartitionSize']); - switch (count($tmp)){ - case 0: - $message[]= sprintf(_("Please enter a valid partition size for partition %s."),($key)); - break; - case 1: - if (!tests::is_id(is_id($tmp[0])) &&(!empty($tmp[1]))){ - $message[]= sprintf(_("Please enter a valid partition size for partition %s."),($key)); - } - break; - - case 2: - if((!tests::is_id($tmp[0]))&&(!tests::is_id($tmp[1])) &&(!empty($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)); - } - break; - - default: - $message[]=sprintf(_("Please enter a range for partition size for partition %s."),($key)); - } - - foreach($this->UsedAttrs as $attrs){ - $alreadyUsed[$attrs][$key] = $part[$attrs]; - } - } - - $cnt = 0; - foreach($this->partitions as $key => $part){ - if($part['FAIpartitionType'] == "primary"){ - $cnt ++ ; - } - } - if($cnt > 3){ - $message[] = _("You have more than 3 primary partition table entries in your configuration, please check your configuration twice."); - } - - return ($message); - } - - - - /* Return plugin informations for acl handling */ - static function plInfo() - { - return (array( - "plShortName" => _("Partition table entry"), - "plDescription" => _("FAI partition table entry"), - "plSelfModify" => FALSE, - "plDepends" => array(), - "plPriority" => 27, - "plSection" => array("administration"), - "plCategory" => array("fai"), - "plProvidedAcls" => array( - "DISKcn" => _("Name"), - "DISKdescription" => _("Description"), - "FAIpartitionType" => _("Partition type"), - "FAIpartitionNr" => _("Partition no."), - "FAIfsType" => _("File system type"), - "FAImountPoint" => _("Mount point"), - "FAIpartitionSize" => _("Partition size"), - "FAImountOptions" => _("Mount options"), - "FAIfsOptions" => _("File system options"), - "FAIencrypted" => _("File system encryption"), - "FAIpartitionFlags" => _("Partition flags")) - )); - } - - -} - -// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: -?> diff --git a/gosa-core/plugins/admin/fai/class_faiProfile.inc b/gosa-core/plugins/admin/fai/class_faiProfile.inc deleted file mode 100644 index 3eaa08b5e..000000000 --- a/gosa-core/plugins/admin/fai/class_faiProfile.inc +++ /dev/null @@ -1,497 +0,0 @@ - "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"); - - /* Specific attributes */ - var $old_cn = ""; - 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 $FAIclass = ""; // Classnames used for this profile - var $FAIclasses = array(); // Contains classname seperated in an array - var $FAIAllclasses = array(); // Contains all possible Classnames - var $ui ; - var $FAIstate = ""; - var $view_logged = FALSE; - - function faiProfile(&$config, $dn= NULL) - { - /* Load Attributes */ - plugin::plugin ($config, $dn); - $ldap=$this->config->get_ldap_link(); - - $this->ui = get_userinfo(); - - /* Parse ldap attribute to get all assigned classes */ - $tmp = split(" ",$this->FAIclass); - $tmp2 = array(); - foreach($tmp as $class){ - if(!empty($class)){ - $tmp2[trim($class)] = trim($class); - } - } - - if(isset($this->attrs['FAIstate'][0])){ - $this->FAIstate = $this->attrs['FAIstate'][0]; - } - - /* Sort assigned classes */ - if(is_array($tmp2)){ - foreach($tmp2 as $class){ - $this->FAIclasses[$class]=$class; - } - } - - $categories = array("FAIscript","FAItemplate","FAIhook","FAIvariable","FAIpartitionTable","FAIpackageList"); - - /* Build filter */ - $filter= ""; - foreach ($categories as $cat){ - $filter.= "(objectClass=$cat)"; - } - - /* Get ldap connection */ - $base = session::get('CurrentMainBase'); - $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]; - } - } - } - - /* Sort the sort array */ - //ksort($sort); - - /* Reorder the FAIclasses array */ - foreach($sort as $name){ - $tmp[$name] =$this->FAIAllclasses[$name]; - } - - /* Assign sorted classes */ - $this->FAIAllclasses = array(); - $this->FAIAllclasses = $tmp; - - if($dn != "new"){ - $this->dn =$dn; - } - $this->old_cn = $this->cn; - } - - - /* Combine new array, used for up down buttons */ - function combineArrays($ar0,$ar1,$ar2) - { - $ret = array(); - if(is_array($ar0)) - foreach($ar0 as $ar => $a){ - $ret[$ar]=$a; - } - if(is_array($ar1)) - foreach($ar1 as $ar => $a){ - $ret[$ar]=$a; - } - if(is_array($ar2)) - foreach($ar2 as $ar => $a){ - $ret[$ar]=$a; - } - return($ret); - } - - - function acl_base_for_current_object($dn) - { - if($dn == "new"){ - if($this->dn == "new"){ - $dn = session::get('CurrentMainBase'); - }else{ - $dn = $this->dn; - } - } - return($dn); - } - - - /* returns position in array */ - function getpos($atr,$attrs) - { - $i = 0; - foreach($attrs as $attr => $name) { - $i++; - if($attr == $atr){ - return($i); - } - } - return(-1); - } - - /* Transports the given Arraykey one position up*/ - function ArrayUp($atr,$attrs) - { - $ret = $attrs; - $pos = $this->getpos($atr,$attrs) ; - $cn = count($attrs); - if(!(($pos == -1)||($pos == 1))){ - $before = array_slice($attrs,0,($pos-2)); - $mitte = array_reverse(array_slice($attrs,($pos-2),2)); - $unten = array_slice($attrs,$pos); - $ret = array(); - $ret = $this->combineArrays($before,$mitte,$unten); - } - return($ret); - } - - - /* Transports the given Arraykey one position down*/ - function ArrayDown($atr,$attrs) - { - $ret = $attrs; - $pos = $this->getpos($atr,$attrs) ; - $cn = count($attrs); - if(!(($pos == -1)||($pos == $cn))){ - $before = array_slice($attrs,0,($pos-1)); - $mitte = array_reverse(array_slice($attrs,($pos-1),2)); - $unten = array_slice($attrs,($pos+1)); - $ret = array(); - $ret = $this->combineArrays($before,$mitte,$unten); - } - return($ret); - } - - /* class one position up */ - function catUp($id) - { - /* Get all cats depinding on current dir */ - $cats = $this->FAIclasses; - $this->FAIclasses =$this->ArrayUp($id,$cats); - } - - /* Class one position down */ - function catDown($id) - { - /* Get all cats depinding on current dir */ - $cats = $this->FAIclasses; - $this->FAIclasses =$this->ArrayDown($id,$cats); - } - - function execute() - { - /* Call parent execute */ - plugin::execute(); - - if($this->is_account && !$this->view_logged){ - $this->view_logged = TRUE; - new log("view","fai/".get_class($this),$this->dn); - } - - /* Fill templating stuff */ - $smarty= get_smarty(); - $display= ""; - - $s_entry = ""; - $s_action = ""; - - /* Remove class name From list */ - $sort_once = false; - foreach($_POST as $name => $post){ - if(preg_match("/DEL_/i",$name) && $this->acl_is_writeable("FAIclass")){ - $s_action = "delete"; - $s_entry = preg_replace("/DEL_/","",$name); - $s_entry = base64_decode(preg_replace("/_.*$/","",$s_entry)); - }elseif(preg_match("/Add_class/i",$name)&& $this->acl_is_writeable("FAIclass")){ - $s_action = "add"; - }elseif(preg_match("/DelClass/i",$name) && $this->acl_is_writeable("FAIclass")){ - $s_action = "delete"; - $s_entry = $_POST['FAIclass']; - }elseif(preg_match("/AddClass/i",$name) && $this->acl_is_writeable("FAIclass")){ - $s_action = "add"; - } - - /* Check if a list element should be pushed one position up */ - if((preg_match("/sortup_/",$name))&&(!$sort_once) && $this->acl_is_writeable("FAIclass")){ - $sort_once = true; - $val = preg_replace("/sortup_/","",$name); - $val = preg_replace("/_.*$/","",$val); - $val = base64_decode($val); - $this->catUp($val); - } - - /* Check if a list element should be pushed one position down */ - if((preg_match("/sortdown_/",$name))&&(!$sort_once) && $this->acl_is_writeable("FAIclass")){ - $sort_once = true; - $val = preg_replace("/sortdown_/","",$name); - $val = preg_replace("/_.*$/","",$val); - $val = base64_decode($val); - $this->catDown($val); - } - - } - - if($s_action == "delete" && $this->acl_is_writeable("FAIclass")){ - unset($this->FAIclasses[$s_entry]); - } - - if($s_action == "add" && $this->acl_is_writeable("FAIclass")){ - $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=FALSE; - //ksort($this->FAIclasses); - } - } - - /* Cancel Dialog */ - if(isset($_POST['CancelSubObject'])){ - $this->is_dialog=false; - unset($this->dialog); - $this->dialog=FALSE; - } - - if(is_object($this->dialog)){ - $this->dialog->save_object(); - return($this->dialog->execute()); - } - - $divlist =new divSelectBox("Profile"); - $divlist->SetSummary(_("This list displays all assigned class names for this profile.")); - - /* item images */ - $objTypes['FAIhook'] = ""; - $objTypes['FAItemplate'] = ""; - $objTypes['FAIscript'] = ""; - $objTypes['FAIvariable'] = ""; - $objTypes['FAIpackageList'] = ""; - $objTypes['FAIpartitionTable'] = ""; - - /* Delete button */ - $actions = ""; - - /* Up down buttons */ - $linkupdown = " "; - $linkupdown.= ""; - - /* Append fai classes to divlist */ - if($this->acl_is_readable("FAIclass")){ - foreach($this->FAIclasses as $usedClass){ - $str = " "; - $act = ""; - - 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"=>""); - if(($this->FAIstate != "freeze") && $this->acl_is_writeable("FAIclass")){ - $field3 = array("string"=> preg_replace("/%KEY%/",base64_encode($usedClass),$actions). - preg_replace("/%s/",base64_encode($usedClass),$linkupdown), - "attach"=>"style='border-right:none;'"); - }else{ - $field3 = array("string"=>" ", "attach"=>"style='border-right:none;'"); - } - $divlist->AddEntry(array($field1,$field2,$field3)); - } - } - - $smarty->assign("FAIclasses" ,$this->FAIclasses); - $smarty->assign("divlist" ,$divlist->DrawList()); - - /* 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){ - if(get_magic_quotes_gpc()){ - $smarty->assign($attrs,stripslashes($this->$attrs)); - }else{ - $smarty->assign($attrs,($this->$attrs)); - } - } - - - $dn = $this->acl_base_for_current_object($this->dn); - $smarty->assign("sub_object_is_addable", - preg_match("/c/",$this->ui->get_permissions($dn,"fai/faiScriptEntry")) && - !preg_match("/freeze/",$this->FAIstate)); - - $tmp = $this->plInfo(); - foreach($tmp['plProvidedAcls'] as $name => $translated){ - $smarty->assign($name."ACL",$this->getacl($name)); - } - - $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); - - $faifilter = session::get('faifilter'); - $use_dn = preg_replace("/".normalizePreg(FAI::get_release_dn($this->dn))."/i", $faifilter['branch'], $this->dn); - if($faifilter['branch'] == "main"){ - $use_dn = $this->dn; - } - - new log("remove","fai/".get_class($this),$use_dn,$this->attributes); - FAI::prepare_to_save_FAI_object($use_dn,array(),true); - $this->handle_post_events("remove"); - } - - - /* Save data to object - */ - function save_object() - { - plugin::save_object(); - } - - - /* Check supplied data */ - function check() - { - /* 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(empty($this->cn)){ - $message[]=_("Please enter a valid name."); - } - - $ldap = $this->config->get_ldap_link(); - $faifilter = session::get('faifilter'); - $base = $faifilter['branch']; - if($base == "main"){ - $base = session::get('CurrentMainBase'); - } - $base = get_ou('faiprofileou').$base; - - $ldap->cd($base); - if ($this->old_cn == ""){ - $ldap->ls("(&(objectClass=FAIprofile)(cn=".$this->cn."))",$base,array("*")); - } else { - $ldap->ls("(&(objectClass=FAIprofile)(cn=".$this->cn.")(!cn=".$this->old_cn."))",$base,array("*")); - } - - if($ldap->count() || isset($this->FAIAllclasses[$this->cn])){ - $message[]=_("There is already a FAI object with this class name defined."); - } - - 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); - - FAI::prepare_to_save_FAI_object($this->dn,$this->attrs); - - if($this->initially_was_account){ - new log("modify","fai/".get_class($this),$this->dn,$this->attributes); - }else{ - new log("create","fai/".get_class($this),$this->dn,$this->attributes); - } - - show_ldap_error($ldap->get_error(), sprintf(_("Saving of FAI/profile with dn '%s' failed."),$this->dn)); - } - - - function PrepareForCopyPaste($source) - { - plugin::PrepareForCopyPaste($source); - - /* Parse ldap attribute to get all assigned classes */ - $tmp = split(" ",$this->FAIclass); - $tmp2 = array(); - foreach($tmp as $class){ - if(!empty($class)){ - $tmp2[trim($class)] = trim($class); - } - } - - /* Sort assigned classes */ - if(is_array($tmp2)){ - foreach($tmp2 as $class){ - $this->FAIclasses[$class]=$class; - } - } - } - - - /* Return plugin informations for acl handling */ - static function plInfo() - { - return (array( - "plShortName" => _("Profile"), - "plDescription" => _("FAI profile"), - "plSelfModify" => FALSE, - "plDepends" => array(), - "plPriority" => 30, - "plSection" => array("administration"), - "plCategory" => array("fai"), - "plProvidedAcls" => array( - "cn" => _("Name"), - "description" => _("Description"), - "FAIclass" => _("FAI classes")) - )); - } -} - -// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: -?> diff --git a/gosa-core/plugins/admin/fai/class_faiProfileEntry.inc b/gosa-core/plugins/admin/fai/class_faiProfileEntry.inc deleted file mode 100644 index 8963973e3..000000000 --- a/gosa-core/plugins/admin/fai/class_faiProfileEntry.inc +++ /dev/null @@ -1,278 +0,0 @@ - "Eins ist toll", "zwei" => "Zwei ist noch besser"); - - /* attribute list for save action */ - var $ignore_account= TRUE; - var $attributes = array(); - var $objectclasses= array(); - - /* Array with available class names */ - var $FAIAllclasses = array(); - var $ui; - - function faiProfileEntry (&$config, $dn= NULL,$used=array(),$objects=false) - { - plugin::plugin ($config, $dn); - - /* Search only in fai tree */ - $base = get_ou('faiou').session::get('CurrentMainBase'); - $faifilter = session::get('faifilter'); - if($faifilter['branch']!="main"){ - $base = $faifilter['branch']; - } - - $this->ui = get_userinfo(); - - $filter = "(|(objectClass=FAIscript)(objectClass=FAItemplate)(objectClass=FAIhook)". - "(objectClass=FAIvariable)(objectClass=FAIpartitionTable)(objectClass=FAIpackageList))"; - - $FAI_objects = FAI::get_all_objects_for_given_base($base,$filter,true); - - /* Create array with categories to be able to sort different types of objects */ - $categories = array("FAIscript" => "faiScript", - "FAItemplate" => "faiTemplate", - "FAIhook" => "faiHook", - "FAIvariable" => "faiVariable", - "FAIpartitionTable" => "faiPartitionTable", - "FAIpackageList" => "faiPackageList"); - - /* Read out all objects from fai tree */ - $ldap= $this->config->get_ldap_link(); - $ldap->cd($base); - $sort=array(); - foreach($FAI_objects as $obj){ - - $ldap->cat($obj['dn']); - $attrs = $ldap->fetch(); - - /* Only use objects which have cn set */ - if((isset($attrs['cn'][0]))&&(!in_array($attrs['cn'][0],$used))){ - foreach($categories as $cat => $acl){ - if(in_array($cat,$attrs['objectClass'])){ - - $acl = $this->ui->get_permissions($attrs['dn'],"fai/".$acl); - - /* Append different types of objects */ - $this->FAIAllclasses[$attrs['cn'][0]]['objects'][$cat]=$cat; - - if(!isset($this->FAIAllclasses[$attrs['cn'][0]]['acl'])){ - $this->FAIAllclasses[$attrs['cn'][0]]['acl']=""; - } - $this->FAIAllclasses[$attrs['cn'][0]]['acl'].=$acl; - - /* Set selected status to false */ - $this->FAIAllclasses[$attrs['cn'][0]]['status']=false; - - $sort[strtolower($attrs['cn'][0])] = $attrs['cn'][0]; - } - } - } - } - - - $tmp = array(); - ksort($sort); - foreach($sort as $name){ - $tmp[$name] =$this->FAIAllclasses[$name]; - } - $this->FAIAllclasses = array(); - $this->FAIAllclasses = $tmp; - - /* If no search filter is set, create one */ - if (!session::is_set("SUBfaifilter")){ - $SUBfaifilter= array("base" => get_ou('faiou').session::get('CurrentMainBase'), "Sregex" => "*"); - $SUBfaifilter['SShowTemplates'] = true; - $SUBfaifilter['SShowScripts'] = true; - $SUBfaifilter['SShowHooks'] = true; - $SUBfaifilter['SShowVariables'] = true; - $SUBfaifilter['SShowPackages'] = true; - $SUBfaifilter['SShowPartitions']= true; - session::set("SUBfaifilter", $SUBfaifilter); - } - } - - function execute() - { - /* Call parent execute */ - plugin::execute(); - - /* Fill templating stuff */ - $smarty = get_smarty(); - $display = ""; - - $SUBfaifilter = session::get('SUBfaifilter'); - - /* If someone used the apply button, update searchfilter */ - if(isset($_POST['Sregex'])){ - foreach($SUBfaifilter as $key => $val){ - if(!isset($_POST[$key])){ - $SUBfaifilter[$key] = false; - }else{ - $SUBfaifilter[$key] =$_POST[$key]; - } - } - $SUBfaifilter['Sregex']= $_POST['Sregex']; - if(!strstr($SUBfaifilter['Sregex'],"*")){ - $SUBfaifilter['Sregex'] = $SUBfaifilter['Sregex']."*"; - } - } - - /* Save current searchfilter in session*/ - session::set('SUBfaifilter',$SUBfaifilter); - - /* Check if we used a checkboxe from the list, to select dselect an entry */ - foreach($_POST as $name => $value){ - foreach($this->FAIAllclasses as $class => $obj){ - $bclass = base64_encode($class); - if(isset($_POST["ON_PAGE_".$bclass])){ - if(isset($_POST['USE_'.$bclass])){ - $this->FAIAllclasses[$class]['status']=true; - }else{ - $this->FAIAllclasses[$class]['status']=false; - } - } - } - } - - /* Create different picture for each object type */ - $objTypes['FAIhook'] = " "; - $objTypes['FAItemplate'] = " "; - $objTypes['FAIscript'] = " "; - $objTypes['FAIvariable'] = " "; - $objTypes['FAIpackageList'] = " "; - $objTypes['FAIpartitionTable'] = " "; - - /* 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){ - if(get_magic_quotes_gpc()){ - $smarty->assign($attrs,stripslashes($this->$attrs)); - }else{ - $smarty->assign($attrs,($this->$attrs)); - } - } - - /* Assign all filter attributes to smarty */ - 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); - } - } - - /* Create a divlist to display all available class names with the depending object types */ - $divlist = new divlist("ProfileEntry"); - $divlist->SetPluginMode(); - $divlist->SetSummary(_("This list displays all assigned class names for this profile.")); - $divlist->SetEntriesPerPage(0); - $divlist->SetHeader(array(array("string"=> _("Class name")), - array("string"=> _("Objects"),"attach"=>"style='border-right:0px;'"))); - - /* Action button allows us to delete an entry */ - $action = " - "; - - /* Check every single class name to match the current search filter */ - foreach($this->FAIAllclasses as $usedClass => $classes){ - - /* Skip those entries that we are not allowed to read. */ - if(!preg_match("/r/",$classes['acl'])){ - continue; - } - - $fi = str_replace("*",".*",$SUBfaifilter['Sregex']); - - $abort = true; - if(!preg_match("/".$fi."/",$usedClass)){ - $abort = false; - } - if((isset($classes['objects']['FAIscript']))&&($SUBfaifilter['SShowScripts'])){ - $abort = false; - } - if((isset($classes['objects']['FAItemplate']))&&($SUBfaifilter['SShowTemplates'])){ - $abort = false; - } - if((isset($classes['objects']['FAIhook']))&&($SUBfaifilter['SShowHooks'])){ - $abort = false; - } - if((isset($classes['objects']['FAIvariable']))&&($SUBfaifilter['SShowVariables'])){ - $abort = false; - } - if((isset($classes['objects']['FAIpartitionTable']))&&($SUBfaifilter['SShowPartitions'])){ - $abort = false; - } - if((isset($classes['objects']['FAIpackageList']))&&($SUBfaifilter['SShowPackages'])){ - $abort = false; - } - - if(!$abort){ - $str = ""; - foreach($classes['objects'] as $class => $obj){ - $str.= $objTypes[$obj]; - } - - /* Is this entry selected */ - if($classes['status']==true){ - $action_check = preg_replace("/%CHECK%/"," checked ",$action); - }else{ - $action_check = preg_replace("/%CHECK%/","",$action); - } - - /* Append to list */ - $field1 = array("string"=> str_replace("%KEY%",base64_encode($usedClass),$action_check).$usedClass,"attach"=>""); - $field2 = array("string"=> $str,"attach"=>"style='border-right:0px;'"); - $divlist->AddEntry(array($field1,$field2)); - } - } - - $smarty->assign("faihead" , ""); - $smarty->assign("failist" , $divlist->DrawList()); - $smarty->assign("infoimage" , get_template_path('images/info_small.png')); - $smarty->assign("launchimage" , get_template_path('images/small_filter.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() - { - } - - /* Check supplied data */ - function check() - { - /* Call common method to give check the hook */ - $message= plugin::check(); - - 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/gosa-core/plugins/admin/fai/class_faiScript.inc b/gosa-core/plugins/admin/fai/class_faiScript.inc deleted file mode 100644 index 2233b6ae6..000000000 --- a/gosa-core/plugins/admin/fai/class_faiScript.inc +++ /dev/null @@ -1,645 +0,0 @@ - "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"); - - /* ObjectClasses for this Object*/ - var $objectclasses = array("top","FAIclass","FAIscript"); - - /* Class name of the Ldap ObjectClass for the Sub Object */ - var $subClass = "FAIscriptEntry"; - var $subClasses = array("top","FAIclass","FAIscriptEntry"); - - /* Class name of the php class which allows us to edit a Sub Object */ - var $subClassName = "faiScriptEntry"; - - /* Attributes to initialise for each subObject */ - var $subAttributes = array("cn","description","FAIpriority"); - var $sub_Load_Later = array("FAIscript"); - var $sub64coded = array(); - var $subBinary = array("FAIscript"); - - /* 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 $SubObjects = array(); // All leafobjects of this object - - var $FAIstate = ""; - var $sort_by = "name"; - var $sort_order = "up"; - - var $view_logged = FALSE; - var $ui; - - function faiScript (&$config, $dn= NULL) - { - /* Load Attributes */ - plugin::plugin ($config, $dn); - - /* If "dn==new" we try to create a new entry - * Else we must read all objects from ldap which belong to this entry. - * First read SubObjects from ldap ... and then the partition definitions for the SubObjects. - */ - if($dn != "new"){ - - $this->dn =$dn; - - /* Get FAIstate - */ - if(isset($this->attrs['FAIstate'][0])){ - $this->FAIstate = $this->attrs['FAIstate'][0]; - } - - /* Read all leaf objects of this object (For FAIscript this would be FAIscriptEntry) - */ - $ldap = $this->config->get_ldap_link(); - $ldap->cd ($this->dn); - - $attrs_to_search = $this->subAttributes; - $attrs_to_search[] = "FAIstate"; - $ldap->search("(&(objectClass=FAIclass)(objectClass=".$this->subClass."))",$attrs_to_search); - - while($object = $ldap->fetch()){ - - /* Skip objects, that are tagged as removed */ - if(isset($object['FAIstate'][0])){ - if(preg_match("/removed$/",$object['FAIstate'][0])){ - continue; - } - } - - /* Set status for save management */ - $objects = array(); - $objects['status'] = "FreshLoaded"; - $objects['dn'] = $object['dn']; - $objects = $this->get_object_attributes($objects,$this->subAttributes); - $this->SubObjects[$objects['cn']] = $objects; - } - - } - $this->ui = get_userinfo(); - } - - - /* Reload some attributes */ - function get_object_attributes($object,$attributes) - { - $ldap = $this->config->get_ldap_link(); - $ldap->cd($this->config->current['BASE']); - $ldap->cat($object['dn'],$attributes); - $tmp = $ldap->fetch(); - - foreach($attributes as $attrs){ - if(isset($tmp[$attrs][0])){ - $var = $tmp[$attrs][0]; - - /* Check if we must decode some attributes */ - if(in_array_ics($attrs,$this->sub64coded)){ - $var = base64_decode($var); - } - - /* check if this is a binary entry */ - if(in_array_ics($attrs,$this->subBinary)){ - $var = $ldap->get_attribute($object['dn'], $attrs,$r_array=0); - } - - /* Fix slashes */ - $var = addslashes($var); - $object[$attrs] = $var; - } - } - return($object); - } - - - /* Return a valid dn to fetch acls. Because 'new' will not work. */ - function acl_base_for_current_object($dn) - { - if($dn == "new"){ - if($this->dn == "new"){ - $dn= "cn=dummy,".session::get('CurrentMainBase'); - }else{ - $dn = $this->dn; - } - } - return($dn); - } - - - function execute() - { - /* Call parent execute */ - plugin::execute(); - - if($this->is_account && !$this->view_logged){ - $this->view_logged = TRUE; - new log("view","fai/".get_class($this),$this->dn); - } - - /* Fill templating stuff */ - $smarty= get_smarty(); - $display= ""; - - /* Add new sub object */ - if(isset($_POST['AddSubObject'])){ - $this->dialog= new $this->subClassName($this->config,"new"); - $this->dialog->set_acl_base($this->acl_base); - $this->dialog->set_acl_category("fai"); - $this->dialog->parent = &$this; - $this->is_dialog=true; - } - - if($this->dn != "new"){ - session::set('objectinfo',$this->dn); - } - - /* Handle posts */ - $s_action = $s_entry = ""; - foreach($_POST as $name => $value){ - - /* Edit script posted */ - if(preg_match("/^editscript_/",$name)){ - $s_action = "edit"; - $s_entry = preg_replace("/^editscript_/","",$name); - $s_entry = base64_decode(preg_replace("/_.*/","",$s_entry)); - break; - } - - /* Delete script requested */ - if(preg_match("/^deletescript_/",$name)){ - $s_action = "remove"; - $s_entry = preg_replace("/^deletescript_/","",$name); - $s_entry = base64_decode(preg_replace("/_.*/","",$s_entry)); - break; - } - } - - if(isset($_GET['act']) && $_GET['act'] == "edit" && isset($_GET['id'])){ - $s_entry = $_GET['id']; - if(isset($this->SubObjects[$s_entry])){ - $s_action = "edit"; - } - } - - if($s_action =="edit" && isset($this->SubObjects[$s_entry])){ - - /* Get object, and load missing entry values */ - $obj = $this->SubObjects[$s_entry]; - if($obj['status'] == "FreshLoaded"){ - $obj = $this->get_object_attributes($obj,$this->sub_Load_Later); - } - - /* Create new dialog and set acl attributes */ - $this->dialog= new $this->subClassName($this->config,$this->dn,$obj); - $this->dialog->set_acl_base($this->acl_base_for_current_object($obj['dn'])); - $this->dialog->set_acl_category("fai"); - - /* Assign some additional dialog informations like headline and parent */ - session::set('objectinfo',$obj['dn']); - $this->dialog->parent = &$this; - $this->is_dialog=true; - } - - /* Check acls, are we allowed to delete an entry */ - if($s_action == "remove" && isset($this->SubObjects[$s_entry])){ - $entry = $this->SubObjects[$s_entry]; - $acl = $this->ui->get_permissions($this->acl_base_for_current_object($entry['dn']),"fai/faiScriptEntry") ; - if(preg_match("/d/",$acl)){ - $status = $entry['status']; - if($status == "edited" || $status == "FreshLoaded"){ - $this->SubObjects[$s_entry]['status']= "delete"; - }else{ - unset($this->SubObjects[$s_entry]); - } - } - } - - /* Save the edited entry */ - if(isset($_POST['SaveSubObject'])){ - - /* Check if there are still errors remaining that must be fixed before saving */ - $this->dialog->save_object(); - $msgs = $this->dialog->check(); - if(count($msgs)>0){ - foreach($msgs as $msg){ - print_red($msg); - } - }else{ - - /* Get return object */ - $obj = $this->dialog->save(); - - /* If we have renamed the script entry, we must remove the old entry */ - if(isset($obj['remove'])){ - - /* Get old entry values */ - $old_stat = $this->SubObjects[$obj['remove']['from']]['status']; - - /* Depending on status, set new status */ - if($old_stat == "edited" || $old_stat == "FreshLoaded"){ - $this->SubObjects[$obj['remove']['from']]['status'] = "delete"; - }elseif($this->SubObjects[$obj['remove']['from']]['status']=="new"){ - unset($this->SubObjects[$obj['remove']['from']]); - } - - /* Append the new entry */ - $obj['status'] = "new"; - $this->SubObjects[$obj['remove']['to']] = $obj; - unset($this->SubObjects[$obj['remove']['to']]['remove']); - }else{ - - /* Set new status and append the entry */ - if($obj['status'] == "FreshLoaded"){ - $obj['status'] = "edited"; - } - $this->SubObjects[$obj['cn']]=$obj; - } - $this->is_dialog=false; - unset($this->dialog); - $this->dialog=FALSE; - - } - } - - /* Sort entries */ - $tmp = $keys = array(); - - if($this->sort_by == "name"){ - foreach($this->SubObjects as $key => $entry){ - $keys[$key]=$entry['cn']; - } - }elseif($this->sort_by == "priority"){ - foreach($this->SubObjects as $key => $entry){ - $keys[$key]=$entry['FAIpriority']; - } - } - - natcasesort($keys); - - if($this->sort_order == "down"){ - $keys =array_reverse($keys); - } - - foreach($keys as $key => $order_var){ - $tmp[$key]=$this->SubObjects[$key]; - } - $this->SubObjects = $tmp; - - /* Cancel Dialog */ - if(isset($_POST['CancelSubObject'])){ - $this->is_dialog=false; - unset($this->dialog); - $this->dialog=FALSE; - } - - /* Print dialog if $this->dialog is set */ - if(is_object($this->dialog)){ - $this->dialog->save_object(); - $display = $this->dialog->execute(); - return($display); - } - - /* Divlist added 23.02.2006 - Containing FAIscripts - */ - $divlist = new divlist("FAIscripts"); - $divlist->SetEntriesPerPage(0); - $plug = $_GET['plug']; - - if($this->sort_order == "up"){ - $dir = "\/"; - }else{ - $dir = "/\"; - } - - if($this->sort_by == "name"){ - $sort_name = $dir; - $sort_prio = ""; - }else{ - $sort_name = ""; - $sort_prio = $dir; - } - - $divlist->SetHeader(array( array("string"=>""._("Name").$sort_name.""), - array("string"=>"".$sort_prio._("Priority")."", - "attach"=>"style='width:100px;'"), - array("string"=>_("Download"), - "attach"=>"style='width:100px;'"), - array("string"=>_("Action"), - "attach"=>"style='border-right: 0px;width:100px;text-align:right;'"))); - $divlist->SetHeight(300); - $divlist->SetWidth("100%"); - foreach($this->getList(true) as $key => $name){ - - $dn= $this->acl_base_for_current_object($name['dn']); - $acl = $this->ui->get_permissions($dn,"fai/faiScriptEntry") ; - $act = ""; - - /* Hide delete icon if this object is freezed */ - if($this->FAIstate == "freeze"){ - $act .= ""; - }else{ - $act .= ""; - if(preg_match("/d/",$acl)){ - $act .=""; - } - } - - /* Check acls for download icon */ - $s_acl = $this->ui->get_permissions($dn,"fai/faiScriptEntry","FAIscript") ; - if(($this->SubObjects[$key]['status'] == "new") || ($this->SubObjects[$key]['dn'] == "new") || !preg_match("/r/",$s_acl)){ - $down = ""; - }else{ - $down = " - "._("Download")." - "; - } - - /* Check if we are allowed to view this object */ - $s_acl = $this->ui->get_permissions($dn,"fai/faiScriptEntry","cn") ; - if(preg_match("/r/",$s_acl)){ - $divlist->AddEntry(array( array("string"=>"".$name['name'].""), - array("string"=>$name['FAIpriority'] , "attach" => "style='width:100px;'"), - array("string"=>$down , "attach" => "style='width:100px;'"), - array("string"=>str_replace("%s",base64_encode($key),$act), - "attach"=>"style='border-right: 0px;width:100px;text-align:right;'"))); - } - } - $smarty->assign("Entry_divlist",$divlist->DrawList()); - - - /* 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){ - if(get_magic_quotes_gpc()){ - $smarty->assign($attrs,stripslashes($this->$attrs)); - }else{ - $smarty->assign($attrs,($this->$attrs)); - } - } - - $dn = $this->acl_base_for_current_object($this->dn); - $smarty->assign("sub_object_is_addable", - preg_match("/c/",$this->ui->get_permissions($dn,"fai/faiScriptEntry")) && - !preg_match("/freeze/",$this->FAIstate)); - - $tmp = $this->plInfo(); - foreach($tmp['plProvidedAcls'] as $name => $translated){ - $smarty->assign($name."ACL",$this->getacl($name)); - } - - $display.= $smarty->fetch(get_template_path('faiScript.tpl', TRUE)); - return($display); - } - - /* Generate listbox friendly SubObject list - */ - function getList($use_dns=false){ - $a_return=array(); - foreach($this->SubObjects as $obj){ - if($obj['status'] != "delete"){ - if($use_dns){ - if((isset($obj['description']))&&(!empty($obj['description']))){ - $a_return[$obj['cn']]['name']= $obj['cn']." [".stripslashes($obj['description'])."]"; - }else{ - $a_return[$obj['cn']]['name']= $obj['cn']; - } - $a_return[$obj['cn']]['dn']= $obj['dn']; - $a_return[$obj['cn']]['FAIpriority']= $obj['FAIpriority']; - }else{ - if((isset($obj['description']))&&(!empty($obj['description']))){ - $a_return[$obj['cn']]= $obj['cn']." [".stripslashes($obj['description'])."]"; - }else{ - $a_return[$obj['cn']]= $obj['cn']; - } - } - } - } - return($a_return); - } - - /* Delete me, and all my subtrees - */ - function remove_from_parent() - { - if($this->acl_is_removeable()){ - $ldap = $this->config->get_ldap_link(); - $ldap->cd ($this->dn); - $faifilter = session::get('faifilter'); - $use_dn = preg_replace("/".normalizePreg(FAI::get_release_dn($this->dn))."/i", $faifilter['branch'], $this->dn); - if($faifilter['branch'] == "main"){ - $use_dn = $this->dn; - } - - new log("remove","fai/".get_class($this),$use_dn,$this->attributes); - - FAI::prepare_to_save_FAI_object($use_dn,array(),true); - - foreach($this->SubObjects as $name => $obj){ - $use_dn = preg_replace("/".normalizePreg(FAI::get_release_dn($this->dn))."/i", $faifilter['branch'], $obj['dn']); - if($faifilter['branch'] == "main"){ - $use_dn = $obj['dn']; - } - FAI::prepare_to_save_FAI_object($use_dn,array(),true); - } - $this->handle_post_events("remove"); - } - } - - - /* Save data to object - */ - function save_object() - { - if((isset($_POST['FAIscript_posted'])) && ($this->FAIstate != "freeze")){ - plugin::save_object(); - foreach($this->attributes as $attrs){ - if(isset($_POST[$attrs])){ - $this->$attrs = $_POST[$attrs]; - } - } - } - - /* Get sort order */ - if(isset($_GET['sort']) && in_array($_GET['sort'],array("name","priority"))){ - if($this->sort_by == $_GET['sort']){ - if($this->sort_order == "up"){ - $this->sort_order = "down"; - }elseif($this->sort_order == "down"){ - $this->sort_order = "up"; - } - } - $this->sort_by = $_GET['sort']; - } - } - - - /* Check supplied data */ - function check() - { - /* Call common method to give check the hook */ - $message= plugin::check(); - - return ($message); - } - - - /* Save to LDAP */ - function save() - { - plugin::save(); - - $ldap = $this->config->get_ldap_link(); - - FAI::prepare_to_save_FAI_object($this->dn,$this->attrs); - show_ldap_error($ldap->get_error(), sprintf(_("Creating of FAI/script with dn '%s' failed."),$this->dn)); - - if($this->initially_was_account){ - new log("modify","fai/".get_class($this),$this->dn,$this->attributes); - }else{ - new log("create","fai/".get_class($this),$this->dn,$this->attributes); - } - - /* Prepare FAIscriptEntry to write it to ldap - * First sort array. - * Because we must delete old entries first. - * After deletion, we perform add and modify - */ - $Objects = array(); - - /* We do not need to save untouched objects */ - foreach($this->SubObjects as $name => $obj){ - if($obj['status'] == "FreshLoaded"){ - unset($this->SubObjects[$name]); - } - } - - foreach($this->SubObjects as $name => $obj){ - if($obj['status'] == "delete"){ - $Objects[$name] = $obj; - } - } - foreach($this->SubObjects as $name => $obj){ - if($obj['status'] != "delete"){ - $Objects[$name] = $obj; - } - } - - foreach($Objects as $name => $obj){ - - foreach($this->sub64coded as $codeIt){ - $obj[$codeIt]=base64_encode(stripslashes($obj[$codeIt])); - } - - $tmp = array(); - $attributes = array_merge($this->sub_Load_Later,$this->subAttributes); - foreach($attributes as $attrs){ - - if(empty($obj[$attrs])){ - $obj[$attrs] = array(); - } - if(!is_array($obj[$attrs])){ - $tmp[$attrs] = stripslashes($obj[$attrs]); - }else{ - $tmp[$attrs] = $obj[$attrs]; - } - } - - $tmp['objectClass'] = $this->subClasses; - - $sub_dn = "cn=".$obj['cn'].",".$this->dn; - - if($obj['status']=="new"){ - $ldap->cat($sub_dn,array("objectClass")); - if($ldap->count()){ - $obj['status']="edited"; - } - } - - if(empty($tmp['FAIpriority'])){ - $tmp['FAIpriority'] ="0"; - } - - /* Tag object */ - $this->tag_attrs(&$tmp, $sub_dn, $this->gosaUnitTag); - - if($obj['status'] == "delete"){ - FAI::prepare_to_save_FAI_object($sub_dn,array(),true); - $this->handle_post_events("remove"); - }elseif($obj['status'] == "edited"){ - FAI::prepare_to_save_FAI_object($sub_dn,$tmp); - $this->handle_post_events("modify"); - }elseif($obj['status']=="new"){ - FAI::prepare_to_save_FAI_object($sub_dn,$tmp); - $this->handle_post_events("add"); - } - } - } - - - function PrepareForCopyPaste($source) - { - plugin::PrepareForCopyPaste($source); - - /* Read all leaf objects of this object (For FAIscript this would be FAIscriptEntry) - */ - $ldap = $this->config->get_ldap_link(); - $ldap->cd ($source['dn']); - - $attrs_to_search = $this->subAttributes; - $attrs_to_search[] = "FAIstate"; - $ldap->search("(&(objectClass=FAIclass)(objectClass=".$this->subClass."))",$attrs_to_search); - - while($object = $ldap->fetch()){ - - /* Skip objects, that are tagged as removed */ - if(isset($object['FAIstate'][0])){ - if(preg_match("/removed$/",$object['FAIstate'][0])){ - continue; - } - } - - /* Set status for save management */ - $objects = array(); - $objects['status'] = "edited"; - $objects['dn'] = $object['dn']; - $objects = $this->get_object_attributes($objects,$this->subAttributes); - $objects = $this->get_object_attributes($objects,$this->sub_Load_Later); - - $this->SubObjects[$objects['cn']] = $objects; - } - } - - - /* Return plugin informations for acl handling */ - static function plInfo() - { - return (array( - "plShortName" => _("Script"), - "plDescription" => _("FAI script"), - "plSelfModify" => FALSE, - "plDepends" => array(), - "plPriority" => 18, - "plSection" => array("administration"), - "plCategory" => array("fai"), - "plProvidedAcls" => array( - "cn" => _("Name")." ("._("Readonly").")", - "description" => _("Description")) - )); - } -} - -// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: -?> diff --git a/gosa-core/plugins/admin/fai/class_faiScriptEntry.inc b/gosa-core/plugins/admin/fai/class_faiScriptEntry.inc deleted file mode 100644 index 032132920..000000000 --- a/gosa-core/plugins/admin/fai/class_faiScriptEntry.inc +++ /dev/null @@ -1,198 +0,0 @@ - "Eins ist toll", "zwei" => "Zwei ist noch besser"); - - /* attribute list for save action */ - var $ignore_account= TRUE; - var $attributes = array("cn","description","FAIpriority","FAIscript"); - var $objectclasses= array(); - - var $orig_cn = ""; - - var $dn = ""; - var $cn = ""; - var $FAIpriority = "0"; - var $FAIscript = ""; - var $description = ""; - var $status = "new"; - var $parent = NULL; - var $FAIstate = ""; - - function faiScriptEntry (&$config, $dn= NULL,$object=false) - { - plugin::plugin ($config, $dn); - if($dn != "new"){ - $this->orig_cn= $object['cn']; - $this->dn=$object['dn']; - foreach($object as $name=>$value){ - $oname = $name; - $this->$oname=$value; - } - - if(isset($this->attrs['FAIstate'][0])){ - $this->FAIstate = $this->attrs['FAIstate'][0]; - } - - }else{ - if(is_array($object)&&count($object)){ - $this->orig_cn= $object['cn']; - $this->dn=$object['dn']; - foreach($object as $name=>$value){ - $oname = $name; - $this->$oname=$value; - } - }else{ - - $this->status = "new"; - $this->orig_cn = false; - } - } - } - - function execute() - { - /* Call parent execute */ - plugin::execute(); - - /* Fill templating stuff */ - $smarty = get_smarty(); - $display = ""; - - if(isset($_POST['ImportUpload']) && $this->acl_is_writeable("FAIscript")){ - if(($_FILES['ImportFile']['error']!=0)){ - print_red(_("Please select a valid file.")); - }else - if(($_FILES['ImportFile']['size']==0)){ - print_red(_("Selected file is empty.")); - }else{ - $str = utf8_encode(addslashes(file_get_contents($_FILES['ImportFile']['tmp_name']))); - $this->FAIscript = $str; - } - } - - foreach($this->attributes as $attrs){ - if(get_magic_quotes_gpc()){ - $smarty->assign($attrs,stripslashes($this->$attrs)); - }else{ - $smarty->assign($attrs,($this->$attrs)); - } - } - - /* Create download button*/ - if($this->dn != "new" && $this->acl_is_readable("FAIscript")){ - $smarty->assign("DownMe"," - - "); - }else{ - $smarty->assign("DownMe",""); - } - - for($i =0 ; $i < 100 ; $i++){ - $FAIprioritys[$i]=$i; - } - - $tmp = $this->plInfo(); - foreach($tmp['plProvidedAcls'] as $name => $translated){ - $acl = $this->getacl($name); - if($this->FAIstate == "freezed"){ - $acl = preg_replace("/w/","",$acl); - } - $smarty->assign($name."ACL",$acl); - } - - $smarty->assign("FAIprioritys",$FAIprioritys); - if(get_magic_quotes_gpc()){ - $smarty->assign("FAIscript" , htmlentities(stripslashes($this->FAIscript))); - }else{ - $smarty->assign("FAIscript" , htmlentities($this->FAIscript)); - } - $display.= $smarty->fetch(get_template_path('faiScriptEntry.tpl', TRUE)); - return($display); - } - - /* Save data to object */ - function save_object() - { - if((isset($_POST['SubObjectFormSubmitted'])) && ($this->FAIstate != "freeze")){ - foreach($this->attributes as $attrs){ - if($this->acl_is_writeable($attrs)){ - if(isset($_POST[$attrs])){ - $this->$attrs = $_POST[$attrs]; - }else{ - $this->$attrs = ""; - } - } - } - } - } - - /* Check supplied data */ - function check() - { - /* Call common method to give check the hook */ - $message= plugin::check(); - - if(isset($this->parent->SubObjects[$this->cn]) && $this->cn != $this->orig_cn){ - $message[] =_("There is already a script with the given name."); - } - - if(empty($this->cn)){ - $message[] = _("Please enter a name."); - } - - if(empty($this->FAIscript)){ - $message[]=_("Please enter a script."); - } - - return ($message); - } - - function save() - { - $tmp=array(); - foreach($this->attributes as $attrs){ - $tmp[$attrs] = $this->$attrs; - } - - /* Strip out dos newlines */ - $tmp['FAIscript']= strtr($this->FAIscript, array("\x0D" => "")); - - if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){ - $tmp['remove']['from'] = $this->orig_cn; - $tmp['remove']['to'] = $tmp['cn']; - } - - $tmp['dn'] = $this->dn; - $tmp['status'] = $this->status; - return($tmp); - } - - - /* Return plugin informations for acl handling */ - static function plInfo() - { - return (array( - "plShortName" => _("Script entry"), - "plDescription" => _("FAI script entry"), - "plSelfModify" => FALSE, - "plDepends" => array(), - "plPriority" => 19, - "plSection" => array("administration"), - "plCategory" => array("fai"), - "plProvidedAcls" => array( - "cn" => _("Name"), - "description" => _("Description"), - "FAIscript" => _("Script entry"), - "FAIpriority" => _("Script Priority")) - )); - } - - -} -// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: -?> diff --git a/gosa-core/plugins/admin/fai/class_faiSummaryTab.inc b/gosa-core/plugins/admin/fai/class_faiSummaryTab.inc deleted file mode 100644 index f2bdd51f1..000000000 --- a/gosa-core/plugins/admin/fai/class_faiSummaryTab.inc +++ /dev/null @@ -1,582 +0,0 @@ -ui = get_userinfo(); - - /* Base object configuration */ - $this->objs = array( - "FAIscript" => array( "Image" =>"images/fai_script.png", "Name"=>_("Scripts") ,"Tree" =>get_ou('faiscriptou')) , - "FAIhook" => array( "Image" =>"images/fai_hook.png" , "Name"=>_("Hooks") ,"Tree" =>get_ou('faihookou')), - "FAIvariable" => array( "Image" =>"images/fai_variable.png", "Name"=>_("Variables") ,"Tree" =>get_ou('faivariableou')) , - "FAItemplate" => array( "Image" =>"images/fai_template.png", "Name"=>_("Templates") ,"Tree" =>get_ou('faitemplateou')) , - "FAIpartitionTable" => array( "Image" =>"images/fai_partitionTable.png","Name"=>_("Partition table") ,"Tree" =>get_ou('faipartitionou')) , - "FAIpackageList" => array( "Image" =>"images/fai_packages.png", "Name"=>_("Package list") ,"Tree" =>get_ou('faipackageou')) , - "FAIprofile" => array( "Image" =>"images/fai_profile.png", "Name"=>_("Profiles") ,"Tree" =>get_ou('faiprofileou'))); - } - - - /* Init the fai tree with objects. - If this method is called, all assigned classes and the release name - will be read from parent object. */ - function init() - { - $this->InitCalled = true; - $this->Result = array(); - - /* Get classes & release name - There are 2 different tabs which use the summary tab - faiProfile / Workstations */ - - /* Check if given parent object is fai profile tabs */ - if(isset($this->parent->by_name['faiProfile'])){ - - /* Get Classes and release */ - $this->Classes = $this->parent->by_object['faiProfile']->FAIclasses; - $this->base = $this->parent->by_object['faiProfile']->base; - $str = preg_replace("/^.*".normalizePreg(get_ou('faiprofileou'))."/","",$this->dn); - - /* Check if parent tab is work tab */ - }elseif(isset($this->parent->by_name['workstartup'])){ - $this->Classes = $this->parent->by_object['workstartup']->FAIclass; - $this->Release = $this->parent->by_object['workstartup']->FAIrelease; - - /* Check if this is a workstation or an object group */ - if(isset($this->parent->by_object['workgeneric'])){ - $this->base = $this->parent->by_object['workgeneric']->base; - }elseif(isset($this->parent->by_object['ogroup'])){ - $this->base = $this->parent->by_object['ogroup']->base; - }elseif(isset($this->parent->by_object['servgeneric'])){ - $this->base = $this->parent->by_object['servgeneric']->base; - }else{ - print_red(_("Unknown type of FAI source information. This is not a profile, workstation nor a ogroup.")); - } - - /* Append workstation class && LAST */ - if(isset($this->parent->by_object['workgeneric']->cn)){ - $this->Classes[] = $this->parent->by_object['workgeneric']->cn; - } - } - - $tmp = array_flip($this->getBranches()); - - $this->Classes[] = "LAST"; - - /* You need full access to complete collection of fai acls to view this summary */ - $acl = $this->ui->has_complete_category_acls($this->base,"fai"); - if(!preg_match("/r/",$acl)){ - $this->Classes = array(); - } - - /* Set all available releases */ - $this->Releases = $tmp; - $this->usedClasses = array(); - - /* Check the configuration */ - if(count($this->Classes) && (!empty($this->Release))){ - foreach($this->Classes as $class){ - $this->resolveObject($class); - } - } - } - - - /* Capture posts, and call opnen close tag */ - function save_object() - { - $once = true; - - if(isset($_GET['expand']) && isset($_GET['id'])){ - if(isset($this->Result[$_GET['id']])){ - $this->Result[$_GET['id']]['Open'] =true ; - } - } - - if(isset($_GET['compress']) && isset($_GET['id'])){ - if(isset($this->Result[$_GET['id']])){ - unset($this->Result[$_GET['id']]['Open']); - } - } - - foreach($_POST as $name => $value ){ - - /* check for open tag request */ - if(preg_match("/^open_/",$name) && $once){ - $once = false; - $value = preg_replace("/^open_/","",$name); - $value = preg_replace("/_.*$/","",$value); - $this->Result[$value]['Open'] =true ; - } - /* Check for close tag request */ - if(preg_match("/^close_/",$name) && $once){ - $once = false; - $value = preg_replace("/^close_/","",$name); - $value = preg_replace("/_.*$/","",$value); - unset($this->Result[$value]['Open']); - } - if(preg_match("/^reloadList/",$name)){ - $this->InitCalled = false; - } - } - } - - - /* returns an array with all possibly release types */ - function getBranches($base = false,$prefix = "") - { - if(!$base){ - $base = $this->base; - } - return(FAI::get_all_releases_from_base($base,true)); - } - - - /* This function calls all nescessary functions to generate the fai class summary tree */ - function execute() - { - - /* Skip this if fai is deactivated */ - $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs')); - if(empty($tmp)){ - $str = "

"._("You can't use this plugin until FAI is activated.")."

"; - return $str; - } - - /* Check if we must (re)init the this tab */ - if(!$this->InitCalled){ - $this->init(); - } - - if(isset($_GET['show'])){ - $ldap = $this->config->get_ldap_link(); - $ldap->cat(base64_decode($_GET['id']), array('FAIscript', 'FAIhook', 'FAItemplateFile')); - $attrs = $ldap->fetch(); - if($_GET['type'] == "FAIscript"){ - $str = $attrs['FAIscript'][0]; - }elseif($_GET['type'] == "FAIhook"){ - $str = $attrs['FAIscript'][0]; - }elseif($_GET['type'] == "FAItemplate"){ - $str = $attrs['FAItemplateFile'][0]; - } - echo "
".$str."
"; - exit(); - } - - /* Get smarty class & assign created summary results */ - $smarty = get_smarty(); - $acl = $this->ui->has_complete_category_acls($this->base,"fai"); - $smarty->assign("readable", preg_match("/r/",$acl)); - - $this->ObjectList = $this->createSummary($this->Result); - $smarty->assign("objectList",$this->ObjectList); - return($smarty->fetch (get_template_path('faiSummary.tpl', TRUE, dirname(__FILE__)))); - } - - - /* Create output of from resolved fai objects */ - function createSummary($data) - { - /* Don't generate any output, if there is no result */ - $str =" "; - if(!count($this->Result)){ - $str.="
"; - $str.= (_("This object has no FAI classes assigned.")); - $str.= "
"; - return($str); - } - - /* walk through all classes */ - foreach($data as $key => $entry){ - - $image = "".$this->objs[$key]["; - if(!isset($entry['Open'])){ - $str .= " - - - "._("Open")." "; - $str .= $image." "; - $str .= " ".$this->objs[$key]['Name'].""; - }else{ - $str .= " - - "._("Close")." "; - $str .= $image." "; - $str .= "".$this->objs[$key]['Name'].""; - - /* Display FAItemplate FAIhook FAIscript entries */ - if(in_array($key,array("FAItemplate","FAIhook","FAIscript"))){ - - $nums = array(); - $tmp = array(); - if($key == "FAIscript"){ - if(is_array($entry['Entries'])){ - foreach($entry['Entries'] as $scripts){ - foreach($scripts as $script){ - - if(!isset($nums[$script['cn'][0]])){ - $nums[$script['cn'][0]]= 0; - } - $nums[$script['cn'][0]] ++; - - $tmp[$script['FAIpriority'][0].$script['cn'][0].$script['CLASS']] = $script; - } - } - } - krsort($tmp);; - - $entry['Entries'] = $tmp; - }else{ - $tmp = array(); - foreach($entry['Entries'] as $script){ - $tmp[$script['cn'][0].$script['CLASS']] = $script; - if(!isset($nums[$script['cn'][0]])){ - $nums[$script['cn'][0]]= 0; - } - $nums[$script['cn'][0]] ++; - } - ksort($tmp); - $entry['Entries'] = $tmp; - } - - foreach($entry['Entries'] as $cn => $data){ - - if(isset($nums[$data['cn'][0]]) && ($nums[$data['cn'][0]] > 1)){ - $str .=""; - }else{ - $str .=""; - } - - $str .= ""; - $str .= $image." "; - if(isset($data['FAIpriority'][0])){ - $str .= "(".$data['FAIpriority'][0].")"; - } - - $str .= " ".$data['cn'][0]; - if(isset($data['description'][0])){ - $str .= " [".$data['description'][0]."]"; - } - $str .= ""; - $str .= "".$data['CLASS'].""; - $str .= ""; - } - } - - /* Create variable entries */ - if(in_array($key,array("FAIvariable"))) { - foreach($entry['Entries'] as $cn => $data){ - $str .=""; - $str .= $image." ".$data['cn'][0]; - if(isset($data['description'][0])){ - $str .= " [".$data['description'][0]."] "; - } - /* Only display FAIvariableContent if description dosn't contain [*] */ - if(isset($data['description'][0]) && !preg_match("#\[\*\]#",$data['description'][0])){ - $str .=" = '".$data['FAIvariableContent'][0]."'"; - } - $str .= "".$data['CLASS'].""; - $str .=""; - } - } - - /* Create packagelist entries */ - if(in_array($key,array("FAIpackageList"))) { - ksort($entry['Entries']); - foreach($entry['Entries'] as $data){ - $str .=""; - $str .= $image." ".$data['cn'][0]; - $str .= "".$data['CLASS'].""; - $str .= "";; - } - } - - /* Create partition table entries */ - if(in_array($key,array("FAIpartitionTable"))) { - foreach($entry['Entries'] as $cn => $data){ - $str .= ""; - $str .= $image." ".$data['name']; - $str .= "".$data['CLASS'].""; - $str .= ""; - ksort($data['partitions']); - - $str .= ""; - $str .= " - - - - - - - - - "; - - $i = 0; - foreach($data['partitions'] as $key => $part){ - $i ++; - - if($i%2 == 1){ - $c = " class='rowxp1'"; - $d = " class='list1'"; - }else{ - $c = " class='rowxp0'"; - $d = " class='list0'"; - } - - $str.=" - - - - - - - - "; - } - $str .="
"._("No.").""._("Name").""._("FS options").""._("Mount options").""._("Size in MB").""._("Mount point").""._("Type")."
".$i."".$part['cn'][0]."".$part['FAIfsType'][0]."".$part['FAIfsOptions'][0]."".$part['FAIpartitionSize'][0]."".$part['FAImountPoint'][0]."".$part['FAIpartitionType'][0]."
"; - } - } - } - } - $str .=""; - return($str); - } - - - /* resolve specified object to append it to our object tree */ - function resolveObject($class) - { - $ldap = $this->config->get_ldap_link(); - $dn = $this->Releases [$this->Release]; - $resolvedClasses = FAI::get_all_objects_for_given_base($dn,"(&(objectClass=FAIclass)(cn=".$class."))"); - - /* Try to fetch all types of fai objects with the given cn */ - foreach($resolvedClasses as $obj){ - - $dn = $obj['dn']; - $ldap->cat($dn); - - while($attrs = $ldap->fetch()){ - - foreach($this-> objs as $key => $rest){ - if(in_array($key,$attrs['objectClass'])){ - - if(!isset($this->usedClasses[$key][$class])){ - $this->usedClasses[$key][$class] = true; - switch($key){ - case "FAIprofile": $this->prepare_FAIprofile($attrs);break; - case "FAIscript": $this->prepare_FAIscript($attrs);break; - case "FAIhook": $this->prepare_FAIhook($attrs);break; - case "FAIvariable": $this->prepare_FAIvariable($attrs);break; - case "FAItemplate": $this->prepare_FAItemplate($attrs);break; - case "FAIpackageList": $this->prepare_FAIpackageList($attrs);break; - case "FAIpartitionTable": $this->prepare_FAIpartitionTable($attrs);break; - } - } - - } - } - } - } - } - - /* Prepare fai script */ - function prepare_FAIscript($data) - { - if(isset($this->Result['FAIscript']['Entries'])){ - $current = $this->Result['FAIscript']['Entries']; - }else{ - $current = array(); - } - $ldap = $this->config->get_ldap_link(); - $ldap->cd($data['dn']); - $ldap->search("(objectClass=FAIscriptEntry)",array("cn","description","FAIpriority")); - while($attrs = $ldap->fetch()){ - $attrs['CLASS'] = $data['cn'][0]; - $current[$attrs['FAIpriority'][0]][] = $attrs; - } - $this->Result['FAIscript']['Entries'] = $current ; - } - - - /* Prepare fai script */ - function prepare_FAIpartitionTable($data) - { - if(isset($this->Result['FAIpartitionTable']['Entries'])){ - $current = $this->Result['FAIpartitionTable']['Entries']; - }else{ - $current = array(); - } - - /* get subentries */ - $ldap = $this->config->get_ldap_link(); - $ldap->cd($data['dn']); - $ldap->search("(objectClass=FAIpartitionDisk)",array("cn","description")); - $disks = array(); - - /* Create an array which is sortable by priority */ - while($attrs = $ldap->fetch()){ - $attrs['CLASS'] = $data['cn'][0]; - $disks[$attrs['cn'][0]]= $attrs; - if(isset($attrs['description'][0])){ - $disks[$attrs['cn'][0]]['name'] = $attrs['cn'][0]." [".$attrs['description'][0]."]"; - }else{ - $disks[$attrs['cn'][0]]['name'] = $attrs['cn'][0]; - } - $disks[$attrs['cn'][0]]['dn'] = $attrs['dn']; - $disks[$attrs['cn'][0]]['partitions'] = array(); - } - - /* Sort by priority */ - foreach($disks as $key => $disk){ - $ldap->cd($disk['dn']); - $ldap->search("(objectClass=FAIpartitionEntry)",array("*")); - while($attrs = $ldap->fetch()){ - if(!isset($attrs['FAIfsOptions'][0])){ - $attrs['FAIfsOptions'][0] = ""; - } - $attrs['CLASS'] = $data['cn'][0]; - $disks[$key]['partitions'][$attrs['cn'][0]] = $attrs; - } - } - $this->Result['FAIpartitionTable']['Entries'] = $disks; - } - - - /* Create template entry */ - function prepare_FAItemplate($data) - { - $current = array(); - if(isset($this->Result['FAItemplate']['Entries'])){ - $current = $this->Result['FAItemplate']['Entries']; - } - - $ldap = $this->config->get_ldap_link(); - $ldap->cd($data['dn']); - $ldap->search("(objectClass=FAItemplateEntry)",array("cn","description")); - while($attrs = $ldap->fetch()){ - $attrs['CLASS'] = $data['cn'][0]; - $current[] = $attrs; - } - $this->Result['FAItemplate']['Entries'] = $current ; - } - - - /* Create a package list */ - function prepare_FAIpackageList($data) - { - $current = array(); - if(isset($this->Result['FAIpackageList']['Entries'])){ - $current = $this->Result['FAIpackageList']['Entries']; - } - if(isset($data['FAIpackage'])){ - unset($data['FAIpackage']['count']); - foreach($data['FAIpackage'] as $pkg){ - $attrs['CLASS'] = $data['cn'][0]; - $attrs['cn'][0] = $pkg; - $current[$pkg] = $attrs; - } - } - $this->Result['FAIpackageList']['Entries'] = $current ; - } - - - /* Create a variable entry */ - function prepare_FAIvariable($data) - { - $current = array(); - if(isset($this->Result['FAIvariable']['Entries'])){ - $current = $this->Result['FAIvariable']['Entries']; - } - $ldap = $this->config->get_ldap_link(); - $ldap->cd($data['dn']); - $ldap->search("(objectClass=FAIvariableEntry)",array("cn","description","FAIvariableContent")); - while($attrs = $ldap->fetch()){ - $attrs['CLASS'] = $data['cn'][0]; - $current[] = $attrs; - } - $this->Result['FAIvariable']['Entries'] = $current ; - } - - /* Create a hook entry */ - function prepare_FAIhook($data) - { - $current = array(); - if(isset($this->Result['FAIhook']['Entries'])){ - $current = $this->Result['FAIhook']['Entries']; - } - $ldap = $this->config->get_ldap_link(); - $ldap->cd($data['dn']); - $ldap->search("(objectClass=FAIhookEntry)",array("cn","description")); - while($attrs = $ldap->fetch()){ - $attrs['CLASS'] = $data['cn'][0]; - $current[$attrs['cn'][0]] = $attrs; - } - $this->Result['FAIhook']['Entries'] = $current ; - } - - - /* Create a new Profile entry */ - function prepare_FAIprofile($data) - { - $classes = split("\ ",$data['FAIclass'][0]); - foreach($classes as $class){ - $class = trim($class); - $this->resolveObject($class); - } - } - - /* Return plugin informations for acl handling * / - static function plInfo() - { - return (array( - "plShortName" => _("Summary"), - "plDescription" => _("FAI summary"), - "plSelfModify" => FALSE, - "plDepends" => array(), - "plPriority" => 15, - "plSection" => array("administration"), - "plCategory" => array("workstation","server","fai","ogroups") , - "plProvidedAcls"=> array( - "readable" => _("Viewable")), - )); - } - */ -} -// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: -?> diff --git a/gosa-core/plugins/admin/fai/class_faiTemplate.inc b/gosa-core/plugins/admin/fai/class_faiTemplate.inc deleted file mode 100644 index 54bd83267..000000000 --- a/gosa-core/plugins/admin/fai/class_faiTemplate.inc +++ /dev/null @@ -1,565 +0,0 @@ - "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"); - - /* ObjectClasses for this Object*/ - var $objectclasses = array("top","FAIclass","FAItemplate"); - - /* Class name of the Ldap ObjectClass for the Sub Object */ - var $subClass = "FAItemplateEntry"; - var $subClasses = array("top","FAIclass","FAItemplateEntry"); - - /* Class name of the php class which allows us to edit a Sub Object */ - var $subClassName = "faiTemplateEntry"; - - /* Attributes to initialise for each subObject */ - var $subAttributes = array("cn","description","FAItemplatePath","FAIowner","FAImode"); - var $sub_Load_Later = array("FAItemplateFile"); - var $sub64coded = array(); - var $subBinary = array("FAItemplateFile"); - - /* 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 $SubObjects = array(); // All leafobjects of this object - - var $FAIstate = ""; - var $ui; - var $view_logged = FALSE; - - function faiTemplate (&$config, $dn= NULL) - { - /* Load Attributes */ - plugin::plugin ($config, $dn); - - /* If "dn==new" we try to create a new entry - * Else we must read all objects from ldap which belong to this entry. - * First read SubObjects from ldap ... and then the partition definitions for the SubObjects. - */ - if($dn != "new"){ - $this->dn =$dn; - - /* Get FAIstate - */ - if(isset($this->attrs['FAIstate'][0])){ - $this->FAIstate = $this->attrs['FAIstate'][0]; - } - - /* Read all leaf objects of this object (For FAIscript this would be FAIscriptEntry) - */ - $ldap = $this->config->get_ldap_link(); - $ldap->cd ($this->dn); - - $attrs_to_search = $this->subAttributes; - $attrs_to_search[] = "FAIstate"; - $ldap->search("(&(objectClass=FAIclass)(objectClass=".$this->subClass."))",$attrs_to_search); - - while($object = $ldap->fetch()){ - - /* Skip objects, that are tagged as removed */ - if(isset($object['FAIstate'][0])){ - if(preg_match("/removed$/",$object['FAIstate'][0])){ - continue; - } - } - - /* Set status for save management */ - $objects = array(); - $objects['status'] = "FreshLoaded"; - $objects['dn'] = $object['dn']; - $objects = $this->get_object_attributes($objects,$this->subAttributes); - $this->SubObjects[$objects['cn']] = $objects; - } - } - $this->ui = get_userinfo(); - } - - - /* Reload some attributes */ - function get_object_attributes($object,$attributes) - { - $ldap = $this->config->get_ldap_link(); - $ldap->cd($this->config->current['BASE']); - $ldap->cat($object['dn'],$attributes); - $tmp = $ldap->fetch(); - - foreach($attributes as $attrs){ - if(isset($tmp[$attrs][0])){ - $var = $tmp[$attrs][0]; - - /* Check if we must decode some attributes */ - if(in_array_ics($attrs,$this->sub64coded)){ - $var = base64_decode($var); - } - - /* check if this is a binary entry */ - if(in_array_ics($attrs,$this->subBinary)){ - $var = $ldap->get_attribute($object['dn'], $attrs,$r_array=0); - } - - $var = stripslashes($var); - - $object[$attrs] = $var; - } - } - return($object); - } - - - function execute() - { - /* Call parent execute */ - plugin::execute(); - - if($this->is_account && !$this->view_logged){ - $this->view_logged = TRUE; - new log("view","fai/".get_class($this),$this->dn); - } - - /* Fill templating stuff */ - $smarty= get_smarty(); - $display= ""; - - /* New Listhandling - */ - $once = true; - foreach($_POST as $name => $value){ - if(preg_match("/^editscript_/",$name)&&($once)){ - $once = false; - $entry = preg_replace("/^editscript_/","",$name); - $entry = base64_decode(preg_replace("/_.*/","",$entry)); - $obj = $this->SubObjects[$entry]; - - $acl_dn = $this->acl_base_for_current_object($obj['dn']); - $acl = $this->ui->get_permissions($acl_dn,"fai/faiTemplateEntry"); - if(preg_match("/r/",$acl)){ - if($obj['status'] == "FreshLoaded"){ - $obj = $this->get_object_attributes($obj,$this->sub_Load_Later); - } - $this->dialog= new $this->subClassName($this->config,$this->dn,$obj); - $this->dialog->set_acl_base($this->acl_base); - $this->dialog->set_acl_category("fai"); - - session::set('objectinfo',$obj['dn']); - $this->dialog->parent = &$this; - $this->is_dialog=true; - } - } - if(preg_match("/^deletescript_/",$name)&&($once)){ - $once = false; - $entry = preg_replace("/^deletescript_/","",$name); - $entry = base64_decode(preg_replace("/_.*/","",$entry)); - $obj = $this->SubObjects[$entry]; - - $acl_dn = $this->acl_base_for_current_object($obj['dn']); - $acl = $this->ui->get_permissions($acl_dn,"fai/faiTemplateEntry"); - if(preg_match("/d/",$acl)){ - $status = $this->SubObjects[$entry]['status']; - if($status == "edited" || $status == "FreshLoaded"){ - $this->SubObjects[$entry]['status']= "delete"; - }else{ - unset($this->SubObjects[$entry]); - } - } - } - } - - /* Edit entries via GET */ - if(isset($_GET['act']) && isset($_GET['id'])){ - if($_GET['act'] == "edit" && isset($this->SubObjects[$_GET['id']])){ - $obj = $this->SubObjects[$_GET['id']]; - if($obj['status'] == "FreshLoaded"){ - $obj = $this->get_object_attributes($obj,$this->sub_Load_Later); - } - $this->dialog= new $this->subClassName($this->config,$this->dn,$obj); - $this->dialog->acl = $this->acl; - session::set('objectinfo',$obj['dn']); - $this->dialog->parent = &$this; - $this->is_dialog=true; - } - } - - /* Add new sub object */ - if(isset($_POST['AddSubObject'])){ - $acl_dn = "cn=dummy,".$this->acl_base_for_current_object($this->dn); - $acl = $this->ui->get_permissions($acl_dn,"fai/faiTemplateEntry"); - - if(preg_match("/c/",$acl)){ - $this->dialog= new $this->subClassName($this->config,"new"); - $this->dialog->set_acl_base($this->acl_base); - $this->dialog->set_acl_category("fai"); - $this->dialog->parent = &$this; - $this->is_dialog=true; - } - } - - if($this->dn != "new"){ - session::set('objectinfo',$this->dn); - } - - /* Save Dialog */ - if(isset($_POST['SaveSubObject']) && is_object($this->dialog)){ - $this->dialog->save_object(); - $msgs = $this->dialog->check(); - if(count($msgs)>0){ - foreach($msgs as $msg){ - print_red($msg); - } - }else{ - /* Get return object */ - $obj = $this->dialog->save(); - if(isset($obj['remove'])){ - - $old_stat = $this->SubObjects[$obj['remove']['from']]['status']; - - /* Depending on status, set new status */ - if($old_stat == "edited" || $old_stat == "FreshLoaded"){ - $this->SubObjects[$obj['remove']['from']]['status'] = "delete"; - }elseif($this->SubObjects[$obj['remove']['from']]['status']=="new"){ - unset($this->SubObjects[$obj['remove']['from']]); - } - $obj['status'] = "new"; - $this->SubObjects[$obj['remove']['to']] = $obj; - unset($this->SubObjects[$obj['remove']['to']]['remove']); - }else{ - if($obj['status'] == "FreshLoaded"){ - $obj['status'] = "edited"; - } - $this->SubObjects[$obj['cn']]=$obj; - } - $this->is_dialog=false; - unset($this->dialog); - $this->dialog=FALSE; - } - } - - /* Sort entries */ - $tmp = $keys = array(); - foreach($this->SubObjects as $key => $entry){ - $keys[$key]=$key; - } - natcasesort($keys); - foreach($keys as $key){ - $tmp[$key]=$this->SubObjects[$key]; - } - $this->SubObjects = $tmp; - - /* Cancel Dialog */ - if(isset($_POST['CancelSubObject'])){ - $this->is_dialog=false; - unset($this->dialog); - $this->dialog=FALSE; - } - - /* Print dialog if $this->dialog is set */ - if(is_object($this->dialog)){ - $this->dialog->save_object(); - $display = $this->dialog->execute(); - return($display); - } - - /* Divlist Containing FAItemplates */ - $divlist = new divSelectBox("FAItemplates"); - $divlist->setHeight(400); - - $tmp = $this->getList(true); - - /* Create div list with all sub entries listed */ - foreach($this->SubObjects as $key => $name){ - - /* Skip removed entries */ - if($name['status'] == "delete") continue; - - /* Get permissions */ - $dn = $this->acl_base_for_current_object($name['dn']); - $acl = $this->ui->get_permissions($dn,"fai/faiTemplateEntry") ; - $act = ""; - - /* Hide delete icon if this object is freezed */ - if(preg_match("/freeze/",$this->FAIstate)){ - $act .= ""; - }else{ - $act .= ""; - if(preg_match("/d/",$acl)){ - $act .=""; - } - } - - /* Check acls for download icon */ - $s_acl = $this->ui->get_permissions($dn,"fai/faiTemplateEntry","FAItemplateFile") ; - if(($this->SubObjects[$key]['status'] == "new") || ($this->SubObjects[$key]['dn'] == "new") || !preg_match("/r/",$s_acl)){ - $down = ""; - }else{ - $down = " - "._("Download")." - "; - } - - /* Check if we are allowed to view this object */ - $s_acl = $this->ui->get_permissions($dn,"fai/faiTemplateEntry","cn") ; - if(preg_match("/r/",$s_acl)){ - - $edit_link = "".$tmp[$key].""; - $divlist->AddEntry(array( array("string"=> $edit_link), - array("string"=>$down , "attach" => "style='width:20px;'"), - array("string"=>str_replace("%s",base64_encode($key),$act), - "attach"=>"style='border-right: 0px;width:50px;text-align:right;'"))); - } - } - $smarty->assign("Entry_divlist",$divlist->DrawList()); - /* Divlist creation complete - */ - - /* 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){ - if(get_magic_quotes_gpc()){ - $smarty->assign($attrs,stripslashes($this->$attrs)); - }else{ - $smarty->assign($attrs,($this->$attrs)); - } - } - - $dn = $this->acl_base_for_current_object($this->dn); - $smarty->assign("sub_object_is_addable", - preg_match("/c/",$this->ui->get_permissions($dn,"fai/faiTemplateEntry")) && - !preg_match("/freeze/",$this->FAIstate)); - - foreach($this->attributes as $attr){ - $smarty->assign($attr."ACL",$this->getacl($attr)); - } - - $display.= $smarty->fetch(get_template_path('faiTemplate.tpl', TRUE)); - return($display); - } - - - function acl_base_for_current_object($dn) - { - if($dn == "new"){ - if($this->dn == "new"){ - $dn = session::get('CurrentMainBase'); - }else{ - $dn = $this->dn; - } - } - return($dn); - } - - - /* Generate listbox friendly SubObject list - */ - function getList(){ - $a_return=array(); - foreach($this->SubObjects as $obj){ - if($obj['status'] != "delete"){ - - if((isset($obj['description']))&&(!empty($obj['description']))){ - if(strlen($obj['description']) > 40){ - $obj['description'] = substr($obj['description'],0,40)."..."; - } - $a_return[$obj['cn']]= $obj['cn']." [".$obj['description']."]"; - }else{ - $a_return[$obj['cn']]= $obj['cn']; - } - } - } - return($a_return); - } - - /* Delete me, and all my subtrees - */ - function remove_from_parent() - { - $ldap = $this->config->get_ldap_link(); - $ldap->cd ($this->dn); - - $faifilter = session::get('faifilter'); - $use_dn = preg_replace("/".normalizePreg(FAI::get_release_dn($this->dn))."/i", $faifilter['branch'], $this->dn); - if($faifilter['branch'] == "main"){ - $use_dn = $this->dn; - } - - FAI::prepare_to_save_FAI_object($use_dn,array(),true); - new log("remove","fai/".get_class($this),$use_dn,$this->attributes); - - foreach($this->SubObjects as $name => $obj){ - $use_dn = preg_replace("/".normalizePreg(FAI::get_release_dn($this->dn))."/i", $faifilter['branch'], $obj['dn']); - if($faifilter['branch'] == "main"){ - $use_dn = $obj['dn']; - } - FAI::prepare_to_save_FAI_object($use_dn,array(),true); - } - $this->handle_post_events("remove"); - } - - - /* Save data to object - */ - function save_object() - { - if((isset($_POST['FAItemplate_posted'])) && (!preg_match("/freeze/",$this->FAIstate))){ - plugin::save_object(); - } - } - - - /* Check supplied data */ - function check() - { - /* Call common method to give check the hook */ - $message= plugin::check(); - - return ($message); - } - - - /* Save to LDAP */ - function save() - { - plugin::save(); - - $ldap = $this->config->get_ldap_link(); - - FAI::prepare_to_save_FAI_object($this->dn,$this->attrs); - show_ldap_error($ldap->get_error(), sprintf(_("Saving of FAI/template with dn '%s' failed."),$this->dn)); - - if($this->initially_was_account){ - new log("modify","fai/".get_class($this),$this->dn,$this->attributes); - }else{ - new log("create","fai/".get_class($this),$this->dn,$this->attributes); - } - - /* Prepare FAIscriptEntry to write it to ldap - * First sort array. - * Because we must delete old entries first. - * After deletion, we perform add and modify - */ - $Objects = array(); - foreach($this->SubObjects as $name => $obj){ - if($obj['status'] == "FreshLoaded"){ - unset($this->SubObjects[$name]); - } - } - - foreach($this->SubObjects as $name => $obj){ - if($obj['status'] == "delete"){ - $Objects[$name] = $obj; - } - } - foreach($this->SubObjects as $name => $obj){ - if($obj['status'] != "delete"){ - $Objects[$name] = $obj; - } - } - - foreach($Objects as $name => $obj){ - - foreach($this->sub64coded as $codeIt){ - $obj[$codeIt]=base64_encode($obj[$codeIt]); - } - $tmp = array(); - $attributes = array_merge($this->sub_Load_Later,$this->subAttributes); - foreach($attributes as $attrs){ - if(empty($obj[$attrs])){ - $obj[$attrs] = array(); - } - $tmp[$attrs] =($obj[$attrs]); - } - - $tmp['objectClass'] = $this->subClasses; - - $sub_dn = "cn=".$obj['cn'].",".$this->dn; - - if($obj['status']=="new"){ - $ldap->cat($sub_dn,array("objectClass")); - if($ldap->count()){ - $obj['status']="edited"; - } - } - - /* Tag object */ - $this->tag_attrs(&$tmp, $sub_dn, $this->gosaUnitTag); - - if($obj['status'] == "delete"){ - FAI::prepare_to_save_FAI_object($sub_dn,array(),true); - $this->handle_post_events("remove"); - }elseif($obj['status'] == "edited"){ - FAI::prepare_to_save_FAI_object($sub_dn,$tmp); - $this->handle_post_events("modify"); - }elseif($obj['status']=="new"){ - FAI::prepare_to_save_FAI_object($sub_dn,$tmp); - $this->handle_post_events("add"); - } - - } - } - - - function PrepareForCopyPaste($source) - { - plugin::PrepareForCopyPaste($source); - - /* Read all leaf objects of this object (For FAIscript this would be FAIscriptEntry) - */ - $ldap = $this->config->get_ldap_link(); - $ldap->cd ($source['dn']); - - $attrs_to_search = $this->subAttributes; - $attrs_to_search[] = "FAIstate"; - $ldap->search("(&(objectClass=FAIclass)(objectClass=".$this->subClass."))",$attrs_to_search); - - while($object = $ldap->fetch()){ - - /* Skip objects, that are tagged as removed */ - if(isset($object['FAIstate'][0])){ - if(preg_match("/removed$/",$object['FAIstate'][0])){ - continue; - } - } - - /* Set status for save management */ - $objects = array(); - $objects['status'] = "edited"; - $objects['dn'] = $object['dn']; - $objects = $this->get_object_attributes($objects,$this->subAttributes); - $objects = $this->get_object_attributes($objects,$this->sub_Load_Later); - - $this->SubObjects[$objects['cn']] = $objects; - } - } - - - /* Return plugin informations for acl handling */ - static function plInfo() - { - return (array( - "plShortName" => _("Template"), - "plDescription" => _("FAI template"), - "plSelfModify" => FALSE, - "plDepends" => array(), - "plPriority" => 24, - "plSection" => array("administration"), - "plCategory" => array("fai"), - "plProvidedAcls" => array( - "cn" => _("Name")." ("._("Readonly").")", - "description" => _("Description")) - )); - } -} - -// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: -?> diff --git a/gosa-core/plugins/admin/fai/class_faiTemplateEntry.inc b/gosa-core/plugins/admin/fai/class_faiTemplateEntry.inc deleted file mode 100644 index a0734aa6a..000000000 --- a/gosa-core/plugins/admin/fai/class_faiTemplateEntry.inc +++ /dev/null @@ -1,275 +0,0 @@ - "Eins ist toll", "zwei" => "Zwei ist noch besser"); - - /* attribute list for save action */ - var $ignore_account= TRUE; - var $attributes = array("cn","description","FAItemplateFile","FAItemplatePath","FAImode","user","group","binary","FAIowner"); - var $objectclasses= array(); - - var $orig_cn = ""; - - 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 $parent = NULL; - var $FAIstate = ""; - - function faiTemplateEntry (&$config, $dn= NULL,$object=false) - { - plugin::plugin ($config, $dn); - - if((isset($object['cn'])) && (!empty($object['cn']))){ - $this->orig_cn= $object['cn']; - $this->dn=$object['dn']; - foreach($object as $name=>$value){ - $oname = $name; - $this->$oname=$value; - } - - if(isset($this->attrs['FAIstate'][0])){ - $this->FAIstate = $this->attrs['FAIstate'][0]; - } - - }else{ - $this->status = "new"; - $this->orig_cn= false; - } - - $this->user = explode( '.', $this->FAIowner ); - $this->group = $this->user[1]; - $this->user = $this->user[0]; - - session::set('binary',$this->FAItemplateFile); - session::set('binarytype','octet-stream'); - session::set('binaryfile',basename($this->FAItemplatePath)); - - if(!empty($this->dn) && $this->dn != "new"){ - $ldap = $this->config->get_ldap_link(); - session::set('binary',$ldap->get_attribute($this->dn,"FAItemplateFile")); - $this->FAItemplateFile = session::get('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']) && $this->acl_is_writeable("FAItemplateFile")){ - 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']; - } - - session::set('binary',$this->FAItemplateFile); - session::set('binarytype','octet-stream'); - session::set('binaryfile',basename($this->FAItemplatePath)); - } - } - - $status= _("no file uploaded yet"); - - $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 - */ - foreach($this->attributes as $attrs){ - if(get_magic_quotes_gpc()){ - $smarty->assign($attrs,stripslashes($this->$attrs)); - }else{ - $smarty->assign($attrs,($this->$attrs)); - } - } - - /* 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("FAItemplateFile",""); - - foreach($this->attributes as $attr){ - $smarty->assign($attr."ACL",$this->getacl($attr,preg_match("/freeze/",$this->FAIstate))); - } - - /* We now split cn/FAItemplatePath to make things more clear... */ - $smarty->assign("cn", basename($this->FAItemplatePath)); - $smarty->assign("templatePath", dirname($this->FAItemplatePath)); - - $display.= $smarty->fetch(get_template_path('faiTemplateEntry.tpl', TRUE)); - return($display); - } - - /* Save data to object */ - function save_object() - { - /* 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']; - } - - /* 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; - } - $this->FAImode= $tmode; - - /* Assemble cn/FAItemplatePath */ - $this->cn= preg_replace('/\/+/', '/', $this->FAItemplatePath.'/'.$this->cn); - $this->FAItemplatePath= $this->cn; - } - } - } - - - /* Check supplied data */ - function check() - { - /* Call common method to give check the hook */ - $message= plugin::check(); - - if(isset($this->parent->SubObjects[$this->cn]) && $this->cn != $this->orig_cn){ - $message[] =_("There is already a template with the given name."); - } - - if(empty($this->FAItemplateFile)){ - $message[]=_("Please specify a value for attribute 'file'."); - } - - if(!preg_match('/^\//', $this->FAItemplatePath)){ - $message[]=_("Please specify a valid value for attribute 'Destination path'."); - } - - if(empty($this->cn)){ - $message[] = _("Please enter a file name."); - } - -# echo $this->cn; -# if(preg_match('/\//', $this->cn)){ -# $message[] = _("The file name should not contain / characters."); -# # } - - 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(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); - } - - function save() - { - $tmp=array(); - foreach($this->attributes as $attrs){ - $tmp[$attrs] = $this->$attrs; - } - - if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){ - $tmp['remove']['from'] = $this->orig_cn; - $tmp['remove']['to'] = $tmp['cn']; - } - - $tmp['dn'] = $this->dn; - $tmp['status'] = $this->status; - - return($tmp); - } - - - /* Return plugin informations for acl handling */ - static 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: -?> diff --git a/gosa-core/plugins/admin/fai/class_faiVariable.inc b/gosa-core/plugins/admin/fai/class_faiVariable.inc deleted file mode 100644 index 7229e3634..000000000 --- a/gosa-core/plugins/admin/fai/class_faiVariable.inc +++ /dev/null @@ -1,464 +0,0 @@ - "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"); - - /* ObjectClasses for this Object*/ - var $objectclasses = array("top","FAIclass","FAIvariable"); - - /* Class name of the Ldap ObjectClass for the Sub Object */ - var $subClass = "FAIvariableEntry"; - var $subClasses = array("top","FAIclass","FAIvariableEntry"); - - /* Class name of the php class which allows us to edit a Sub Object */ - var $subClassName = "faiVariableEntry"; - - /* Attributes to initialise for each subObject */ - var $subAttributes = array("cn","description","FAIvariableContent"); - var $sub64coded = array(); - - /* 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 $SubObjects = array(); // All leafobjects of this object - - var $FAIstate = ""; - var $ui ; - var $view_logged = FALSE; - - function faiVariable (&$config, $dn= NULL) - { - /* Load Attributes */ - plugin::plugin ($config, $dn); - - if($dn != "new"){ - $this->dn =$dn; - - /* Get FAIstate - */ - if(isset($this->attrs['FAIstate'][0])){ - $this->FAIstate = $this->attrs['FAIstate'][0]; - } - - /* Read all leaf objects of this object (For FAIscript this would be FAIscriptEntry) - */ - $ldap = $this->config->get_ldap_link(); - $ldap->cd ($this->dn); - - $attrs_to_search = $this->subAttributes; - $attrs_to_search[] = "FAIstate"; - $ldap->search("(&(objectClass=FAIclass)(objectClass=".$this->subClass."))",$attrs_to_search); - - while($object = $ldap->fetch()){ - - /* Skip objects, that are tagged as removed */ - if(isset($object['FAIstate'][0])){ - if(preg_match("/removed$/",$object['FAIstate'][0])){ - continue; - } - } - - /* Set status for save management */ - foreach($this->subAttributes as $attrs){ - if(!isset($object[$attrs][0])){ - $this->SubObjects[$object['cn'][0]][$attrs]=""; - }else{ - $this->SubObjects[$object['cn'][0]][$attrs]=$object[$attrs][0]; - } - } - - foreach($this->sub64coded as $codeIt){ - $this->SubObjects[$object['cn'][0]][$codeIt]=base64_decode($this->SubObjects[$object['cn'][0]][$codeIt]); - } - - $this->SubObjects[$object['cn'][0]]['status'] = "edited"; - $this->SubObjects[$object['cn'][0]]['dn'] = $object['dn']; - } - - } - $this->ui = get_userinfo(); - } - - - function acl_base_for_current_object($dn) - { - if($dn == "new"){ - if($this->dn == "new"){ - $dn = session::get('CurrentMainBase'); - }else{ - $dn = $this->dn; - } - } - return($dn); - } - - - function execute() - { - /* Call parent execute */ - plugin::execute(); - - if($this->is_account && !$this->view_logged){ - $this->view_logged = TRUE; - new log("view","fai/".get_class($this),$this->dn); - } - - /* Fill templating stuff */ - $smarty= get_smarty(); - $display= ""; - - /* Add new sub object */ - if(isset($_POST['AddSubObject'])){ - $this->dialog= new $this->subClassName($this->config,"new"); - $this->dialog->set_acl_base($this->acl_base_for_current_object($this->dn)); - $this->dialog->set_acl_category("fai"); - $this->dialog->parent = &$this; - $this->is_dialog=true; - } - - if($this->dn != "new"){ - session::set('objectinfo',$this->dn); - } - - - /* Edit selected Sub Object */ - if((isset($_POST['EditSubObject']))&&(isset($_POST['SubObject']))){ - - $var = $_POST['SubObject'][0]; - $c_dn = $this->acl_base_for_current_object($this->SubObjects[$var]['dn']); - $this->dialog= new $this->subClassName($this->config,$this->dn,$this->SubObjects[$var]); - $this->dialog->set_acl_category("fai"); - $this->dialog->set_acl_base($c_dn); - $this->dialog->parent = &$this; - session::set('objectinfo',$this->SubObjects[$var]['dn']); - $this->is_dialog=true; - } - - /* Remove Sub object */ - if((isset($_POST['DelSubObject']))&&(isset($_POST['SubObject']))){ - foreach($_POST['SubObject'] as $var){ - - $c_dn = $this->acl_base_for_current_object($this->SubObjects[$var]['dn']); - $acl = $this->ui->get_permissions($c_dn,"fai/faiVariable"); - if(preg_match("/d/",$acl)){ - if($this->SubObjects[$var]['status'] == "edited"){ - $this->SubObjects[$var]['status']= "delete"; - }else{ - unset($this->SubObjects[$var]); - } - } - } - } - - /* Save Dialog */ - if(isset($_POST['SaveSubObject'])){ - $this->dialog->save_object(); - $msgs = $this->dialog->check(); - if(count($msgs)>0){ - foreach($msgs as $msg){ - print_red($msg); - } - }else{ - $obj = $this->dialog->save(); - if(isset($obj['remove'])){ - if($this->SubObjects[$obj['remove']['from']]['status']=="edited"){ - $this->SubObjects[$obj['remove']['from']]['status'] = "delete"; - }elseif($this->SubObjects[$obj['remove']['from']]['status']=="new"){ - unset($this->SubObjects[$obj['remove']['from']]); - } - $obj['status'] = "new"; - $this->SubObjects[$obj['remove']['to']] = $obj; - unset($this->SubObjects[$obj['remove']['to']]['remove']); - }else{ - $this->SubObjects[$obj['cn']]=$obj; - } - $this->is_dialog=false; - unset($this->dialog); - $this->dialog=FALSE; - } - } - - /* Sort entries */ - $tmp = $keys = array(); - foreach($this->SubObjects as $key => $entry){ - $keys[$key]=$key; - } - natcasesort($keys); - foreach($keys as $key){ - $tmp[$key]=$this->SubObjects[$key]; - } - $this->SubObjects = $tmp; - - /* Cancel Dialog */ - if(isset($_POST['CancelSubObject'])){ - $this->is_dialog=false; - unset($this->dialog); - $this->dialog=FALSE; - } - - /* Print dialog if $this->dialog is set */ - if(is_object($this->dialog)){ - $this->dialog->save_object(); - $display = $this->dialog->execute(); - return($display); - } - - $ui = get_userinfo(); - $ret = $this->getList(); - $tmp = array(); - foreach($this->SubObjects as $key => $obj){ - $acl = $ui->get_permissions($obj['dn'],"fai/faiVariableEntry"); - if(preg_match("/r/",$acl) || $obj['dn'] == "new"){ - $tmp[$key] = $ret[$key]; - } - } - $smarty->assign("SubObjects",$tmp); - - - /* 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){ - if(get_magic_quotes_gpc()){ - $smarty->assign($attrs,htmlentities (stripslashes(utf8_decode($this->$attrs)))); - }else{ - $smarty->assign($attrs,htmlentities (utf8_decode($this->$attrs))); - } - } - - $c_dn = $this->acl_base_for_current_object($this->dn); - $smarty->assign("is_createable", preg_match("/c/",$this->ui->get_permissions($c_dn,"fai/faiVariableEntry")) && $this->FAIstate!="freeze"); - $smarty->assign("is_removeable", preg_match("/d/",$this->ui->get_permissions($c_dn,"fai/faiVariableEntry")) && $this->FAIstate!="freeze"); - - $tmp = $this->plInfo(); - foreach($tmp['plProvidedAcls'] as $name => $translation) { - $smarty->assign($name."ACL",$this->getacl($name)); - } - - - $display.= $smarty->fetch(get_template_path('faiVariable.tpl', TRUE)); - return($display); - } - - /* Generate listbox friendly SubObject list - */ - function getList(){ - $a_return=array(); - foreach($this->SubObjects as $obj){ - if($obj['status'] != "delete"){ - - if((isset($obj['description']))&&(!empty($obj['description']))&&(!preg_match("/\[\*\]/",$obj['description']))){ - if (preg_match("/\[\*\]/", $obj['description'])){ - $a_return[$obj['cn']]= $obj['cn']." [".preg_replace("/\s*\[\*\]\s*/", "", $obj['description'])."]"; - } else { - $a_return[$obj['cn']]= $obj['cn']."=".$obj['FAIvariableContent']." [".$obj['description']."]"; - } - }else{ - if (preg_match("/\[\*\]/", $obj['description'])){ - $a_return[$obj['cn']]= $obj['cn']; - } else { - $a_return[$obj['cn']]= $obj['cn']."=".$obj['FAIvariableContent']; - } - } - } - } - return($a_return); - } - - /* Delete me, and all my subtrees - */ - function remove_from_parent() - { - if($this->acl_is_removeable()){ - $ldap = $this->config->get_ldap_link(); - $ldap->cd ($this->dn); - - $faifilter = session::get('faifilter'); - $use_dn = preg_replace("/".normalizePreg(FAI::get_release_dn($this->dn))."/i", $faifilter['branch'], $this->dn); - if($faifilter['branch'] == "main"){ - $use_dn = $this->dn; - } - - FAI::prepare_to_save_FAI_object($use_dn,array(),true); - new log("remove","fai/".get_class($this),$use_dn,$this->attributes); - - foreach($this->SubObjects as $name => $obj){ - $use_dn = preg_replace("/".normalizePreg(FAI::get_release_dn($this->dn))."/i", $faifilter['branch'], $obj['dn']); - if($faifilter['branch'] == "main"){ - $use_dn = $obj['dn']; - } - FAI::prepare_to_save_FAI_object($use_dn,array(),true); - } - $this->handle_post_events("remove"); - } - } - - - /* Save data to object - */ - function save_object() - { - if((isset($_POST['FAIvariable_posted'])) && ($this->FAIstate != "freeze") ){ - plugin::save_object(); - foreach($this->attributes as $attrs){ - if(isset($_POST[$attrs])){ - $this->$attrs = $_POST[$attrs]; - } - } - } - } - - - /* Check supplied data */ - function check() - { - /* Call common method to give check the hook */ - $message= plugin::check(); - - return ($message); - } - - - /* Save to LDAP */ - function save() - { - plugin::save(); - - $ldap = $this->config->get_ldap_link(); - FAI::prepare_to_save_FAI_object($this->dn,$this->attrs); - show_ldap_error($ldap->get_error(), sprintf(_("Saving of FAI/variable with dn '%s' failed."),$this->dn)); - - if($this->initially_was_account){ - new log("modify","fai/".get_class($this),$this->dn,$this->attributes); - }else{ - new log("create","fai/".get_class($this),$this->dn,$this->attributes); - } - - /* Prepare FAIscriptEntry to write it to ldap - * First sort array. - * Because we must delete old entries first. - * After deletion, we perform add and modify - */ - $Objects = array(); - foreach($this->SubObjects as $name => $obj){ - if($obj['status'] == "delete"){ - $Objects[$name] = $obj; - } - } - foreach($this->SubObjects as $name => $obj){ - if($obj['status'] != "delete"){ - $Objects[$name] = $obj; - } - } - - foreach($Objects as $name => $obj){ - - foreach($this->sub64coded as $codeIt){ - $obj[$codeIt]=base64_encode($obj[$codeIt]); - } - - $tmp = array(); - foreach($this->subAttributes as $attrs){ - if(empty($obj[$attrs])){ - $obj[$attrs] = array(); - } - $tmp[$attrs] = $obj[$attrs]; - } - - $tmp['objectClass'] = $this->subClasses; - - $sub_dn = "cn=".$obj['cn'].",".$this->dn; - - if($obj['status']=="new"){ - $ldap->cat($sub_dn,array("objectClass")); - if($ldap->count()){ - $obj['status']="edited"; - } - } - - /* Tag object */ - $this->tag_attrs(&$tmp, $sub_dn, $this->gosaUnitTag); - - if($obj['status'] == "delete"){ - FAI::prepare_to_save_FAI_object($sub_dn,array(),true); - $this->handle_post_events("remove"); - }elseif($obj['status'] == "edited"){ - FAI::prepare_to_save_FAI_object($sub_dn,$tmp); - $this->handle_post_events("modify"); - }elseif($obj['status']=="new"){ - FAI::prepare_to_save_FAI_object($sub_dn,$tmp); - $this->handle_post_events("add"); - } - - } - } - - - function PrepareForCopyPaste($source) - { - plugin::PrepareForCopyPaste($source); - - /* Read all leaf objects of this object (For FAIscript this would be FAIscriptEntry) - */ - $ldap = $this->config->get_ldap_link(); - $ldap->cd ($source['dn']); - $attrs_to_search = $this->subAttributes; - $attrs_to_search[] = "FAIstate"; - $ldap->search("(&(objectClass=FAIclass)(objectClass=".$this->subClass."))",$attrs_to_search); - while($object = $ldap->fetch()){ - - /* Skip objects, that are tagged as removed */ - if(isset($object['FAIstate'][0])){ - if(preg_match("/removed$/",$object['FAIstate'][0])){ - continue; - } - } - - /* Set status for save management */ - foreach($this->subAttributes as $attrs){ - if(!isset($object[$attrs][0])){ - $this->SubObjects[$object['cn'][0]][$attrs]=""; - }else{ - $this->SubObjects[$object['cn'][0]][$attrs]=$object[$attrs][0]; - } - } - foreach($this->sub64coded as $codeIt){ - $this->SubObjects[$object['cn'][0]][$codeIt]=base64_decode($this->SubObjects[$object['cn'][0]][$codeIt]); - } - $this->SubObjects[$object['cn'][0]]['status'] = "edited"; - $this->SubObjects[$object['cn'][0]]['dn'] = $object['dn']; - } - } - - - /* Return plugin informations for acl handling */ - static function plInfo() - { - return (array( - "plShortName" => _("Variable"), - "plDescription" => _("FAI variable"), - "plSelfModify" => FALSE, - "plDepends" => array(), - "plPriority" => 22, - "plSection" => array("administration"), - "plCategory" => array("fai"), - "plProvidedAcls" => array( - "cn" => _("Name")." ("._("Read only").")", - "description" => _("Description")) - )); - } -} - -// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: -?> diff --git a/gosa-core/plugins/admin/fai/class_faiVariableEntry.inc b/gosa-core/plugins/admin/fai/class_faiVariableEntry.inc deleted file mode 100644 index 5fc6ef01e..000000000 --- a/gosa-core/plugins/admin/fai/class_faiVariableEntry.inc +++ /dev/null @@ -1,155 +0,0 @@ - "Eins ist toll", "zwei" => "Zwei ist noch besser"); - - /* attribute list for save action */ - var $ignore_account= TRUE; - var $attributes = array("cn","description","FAIvariableContent"); - var $objectclasses= array(); - - var $orig_cn = ""; - var $dn = ""; - var $cn = ""; - var $FAIvariableContent = ""; - var $description = ""; - var $status = "new"; - var $parent = NULL; - var $FAIstate = ""; - - function faiVariableEntry (&$config, $dn= NULL,$object=false) - { - plugin::plugin ($config, $dn); - if((isset($object['cn'])) && (!empty($object['cn']))){ - $this->orig_cn= $object['cn']; - $this->dn=$object['dn']; - foreach($object as $name=>$value){ - $oname = $name; - $this->$oname=addslashes($value); - } - - if(isset($this->attrs['FAIstate'][0])){ - $this->FAIstate = $this->attrs['FAIstate'][0]; - } - - }else{ - $this->status = "new"; - $this->orig_cn = false; - } - } - - function execute() - { - /* Call parent execute */ - plugin::execute(); - - /* Fill templating stuff */ - $smarty = get_smarty(); - $display = ""; - - /* 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){ - if(get_magic_quotes_gpc()){ - $smarty->assign($attrs,htmlentities (stripslashes(utf8_decode($this->$attrs)))); - }else{ - $smarty->assign($attrs,htmlentities (utf8_decode($this->$attrs))); - } - } - - $tmp = $this->plInfo(); - foreach($tmp['plProvidedAcls'] as $name => $translated){ - $acl = $this->getacl($name); - if($this->FAIstate == "freezed"){ - $acl = preg_replace("/w/","",$acl); - } - $smarty->assign($name."ACL",$acl); - } - - - - $display.= $smarty->fetch(get_template_path('faiVariableEntry.tpl', TRUE)); - return($display); - } - - /* Save data to object */ - function save_object() - { - if((isset($_POST['SubObjectFormSubmitted'])) && ($this->FAIstate != "freeze")){ - foreach($this->attributes as $attrs){ - if($this->acl_is_writeable($attrs)){ - if(isset($_POST[$attrs])){ - $this->$attrs = $_POST[$attrs]; - }else{ - $this->$attrs = ""; - } - } - } - } - } - - /* Check supplied data */ - function check() - { - /* Call common method to give check the hook */ - $message= plugin::check(); - - if(isset($this->parent->SubObjects[$this->cn]) && $this->cn != $this->orig_cn){ - $message[] =_("There is already a variable with the given name."); - } - - if(empty($this->FAIvariableContent)) { - $message[]=_("Please specify a value for the attribute 'content'."); - } - - if(empty($this->cn)){ - $message[] = _("Please enter a name."); - } - - return ($message); - } - - function save() - { - $tmp=array(); - foreach($this->attributes as $attrs){ - $tmp[$attrs] = stripslashes( $this->$attrs); - } - - if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){ - $tmp['remove']['from'] = $this->orig_cn; - $tmp['remove']['to'] = $tmp['cn']; - } - - $tmp['dn'] = $this->dn; - $tmp['status'] = $this->status; - return($tmp); - } - - /* Return plugin informations for acl handling */ - static function plInfo() - { - return (array( - "plShortName" => _("Variable entry"), - "plDescription" => _("FAI variable entry "), - "plSelfModify" => FALSE, - "plDepends" => array(), - "plPriority" => 23, - "plSection" => array("administration"), - "plCategory" => array("fai"), - "plProvidedAcls" => array( - "cn" => _("Name"), - "description" => _("Description"), - "FAIvariableContent"=> _("Variable content") ) - )); - } - - -} -// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: -?> diff --git a/gosa-core/plugins/admin/fai/faiHook.tpl b/gosa-core/plugins/admin/fai/faiHook.tpl deleted file mode 100644 index 6768ad92d..000000000 --- a/gosa-core/plugins/admin/fai/faiHook.tpl +++ /dev/null @@ -1,63 +0,0 @@ - - - - -
-

 {t}Generic{/t}

- - - - - - - - - -
- - -{render acl=$cnACL} - -{/render} -
- - -{render acl=$descriptionACL} - -{/render} -
-
-

 

- - - - -
-

  - {t}List of hook scripts{/t} -

- - - - -
- {$Entry_divlist} -{if $sub_object_is_addable} - -{else} - -{/if} -
-
- - - - diff --git a/gosa-core/plugins/admin/fai/faiHookEntry.tpl b/gosa-core/plugins/admin/fai/faiHookEntry.tpl deleted file mode 100644 index 882da267d..000000000 --- a/gosa-core/plugins/admin/fai/faiHookEntry.tpl +++ /dev/null @@ -1,94 +0,0 @@ - - - - - - - -
-

 {t}Generic{/t}

- - - - - - - - - -
- {t}Name{/t}{$must}  - -{render acl=$cnACL} - -{/render} -
- {t}Description{/t}  - -{render acl=$descriptionACL} - -{/render} -
-
-   - -

 {t}Hook attributes{/t}

- - - - -
- -{render acl=$FAItaskACL} - -{/render} -
-
- - -

 

-

  - -

- - - - -
-{render acl=$FAIscriptACL} - -{/render} -
-
-
-{render acl=$FAIscriptACL} -   -{/render} -{render acl=$FAIscriptACL} - -{/render} -{render acl=$FAIscriptACL} - {$DownMe} -{/render} -
- -

 

-
-
-   - -
- - - diff --git a/gosa-core/plugins/admin/fai/faiNewBranch.tpl b/gosa-core/plugins/admin/fai/faiNewBranch.tpl deleted file mode 100644 index 831e02898..000000000 --- a/gosa-core/plugins/admin/fai/faiNewBranch.tpl +++ /dev/null @@ -1,55 +0,0 @@ -{if $iframe == false} - -
-

-{t}You are now going to create a branch or locked branch. This action clones the existing release to another release name. Branches can be modified as usual. FAI classes of locked branches cannot be modified, just additional classes are possible. Branch names should be alphanumeric, excluding the reserved names 'scripts', 'hooks', 'partitions', 'variables', 'templates' and 'fai'.{/t} -
-{t}Branches are created as subreleases of the currently selected branch. Creating a new branch named 1.0.2 in SARGE for example, will result in a new release called SARGE/1.0.2.{/t} -
-
-

-

-
-{t}Please enter a name for the branch{/t}   - -
-
-

- -
-

- - -

-
- - - -{else} - -

{t}Processing the requested operation{/t}

-{t}As soon as the copy operation has finished, you can scroll down to end of the page and press the 'Continue' button to continue with the fai management dialog.{/t} -
-
-
- -
- -{/if} diff --git a/gosa-core/plugins/admin/fai/faiPackage.tpl b/gosa-core/plugins/admin/fai/faiPackage.tpl deleted file mode 100644 index 87c83d98e..000000000 --- a/gosa-core/plugins/admin/fai/faiPackage.tpl +++ /dev/null @@ -1,100 +0,0 @@ - - - - - -
-

 {t}Generic{/t}

- - - - - - - - - -
- - -{render acl=$cnACL} - -{/render} -
- - -{render acl=$descriptionACL} - -{/render} -
-
-

 {t}Repository{/t}

- - - - - - - - - - - - - -
- {t}Release{/t} : - - {$release} -
- {t}Section{/t} : - - {$section} -
- {t}Install method{/t} : - -{render acl=$FAIinstallMethodACL} - -{/render} -
-
-

 

- - - - -
-

 {t}Used packages{/t}

-
- -
-{render acl=$FAIpackageACL} - -{/render} -{render acl=$FAIpackageACL} - -{/render} -{render acl=$FAIdebconfInfoACL} - -{/render} -{render acl=$FAIpackageACL} - -{/render} -
- - - - diff --git a/gosa-core/plugins/admin/fai/faiPackageConfiguration.tpl b/gosa-core/plugins/admin/fai/faiPackageConfiguration.tpl deleted file mode 100644 index db047590f..000000000 --- a/gosa-core/plugins/admin/fai/faiPackageConfiguration.tpl +++ /dev/null @@ -1,9 +0,0 @@ -

 {$headline}

-{$Config} -

 

-
-
- - -
- diff --git a/gosa-core/plugins/admin/fai/faiPackageEntry.tpl b/gosa-core/plugins/admin/fai/faiPackageEntry.tpl deleted file mode 100644 index 79f47c6c4..000000000 --- a/gosa-core/plugins/admin/fai/faiPackageEntry.tpl +++ /dev/null @@ -1,66 +0,0 @@ - - - - - -
-
-

- {t}List of available packages{/t} -

-
-
- {$faihead} -
-
-
-
- {$failist} - -
-
-
-

- [i]{t}Information{/t} -

-
-
- {t}This menu allows you to select multiple packages to add them to the currently edited package list.{/t} -
-
-
-

- [F] - {t}Filters{/t} -

-
-
- {$CHKS} -
-
- - - - - -
- {t}Display objects matching{/t} - - -
- {$apply} -
-
-
- - -
- - - - diff --git a/gosa-core/plugins/admin/fai/faiPartitionTable.tpl b/gosa-core/plugins/admin/fai/faiPartitionTable.tpl deleted file mode 100644 index f330fe67b..000000000 --- a/gosa-core/plugins/admin/fai/faiPartitionTable.tpl +++ /dev/null @@ -1,68 +0,0 @@ - - - - - - -
-

 {t}Generic{/t}

- - - - - - - - - -
- - -{render acl=$cnACL} - -{/render} -
- - -{render acl=$descriptionACL} - -{/render} -
-
-   - -

  - -

- - - - -
-
-{if $sub_object_is_addable} - -{else} - -{/if} - - - -
-
- - - diff --git a/gosa-core/plugins/admin/fai/faiPartitionTableEntry.tpl b/gosa-core/plugins/admin/fai/faiPartitionTableEntry.tpl deleted file mode 100644 index 4379b663d..000000000 --- a/gosa-core/plugins/admin/fai/faiPartitionTableEntry.tpl +++ /dev/null @@ -1,48 +0,0 @@ - -

 {t}Device{/t}

- - - - - -
{$must}  -{render acl=$DISKcnACL} - -{/render} -   -{render acl=$DISKdescriptionACL} - -{/render} -
-
-

 

-
-

 {t}Partition entries{/t}

-{$setup} -
-{if $sub_object_is_createable} - -{else} - -{/if} -
-
-

 

-
-
-{render acl=$allowSave} - -{/render} - -
- - - diff --git a/gosa-core/plugins/admin/fai/faiProfile.tpl b/gosa-core/plugins/admin/fai/faiProfile.tpl deleted file mode 100644 index 090d968e7..000000000 --- a/gosa-core/plugins/admin/fai/faiProfile.tpl +++ /dev/null @@ -1,58 +0,0 @@ - - - - - -
-

 {t}Generic{/t}

- - - - - - - - - -
- - -{render acl=$cnACL} - -{/render} -
- - -{render acl=$descriptionACL} - -{/render} -
-
- - - - -
-

 {t}FAI classes{/t}

- - {$divlist} -
-{render acl=$FAIclassACL} - -{/render} - -
-
- - - diff --git a/gosa-core/plugins/admin/fai/faiProfileEntry.tpl b/gosa-core/plugins/admin/fai/faiProfileEntry.tpl deleted file mode 100644 index 72e865bea..000000000 --- a/gosa-core/plugins/admin/fai/faiProfileEntry.tpl +++ /dev/null @@ -1,73 +0,0 @@ - - - - - -
-
-

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

-
-
- {$faihead} -
-
-
- {$failist} - -
-
-
-

- [i]{t}Information{/t} -

-
-
-

- {t}This menu allows you to select FAI class names and to add them to the currently edited profile.{/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}
- - - - - -
- {t}Display objects matching{/t} - - -
- {$apply} -
-
- -
- - -
- diff --git a/gosa-core/plugins/admin/fai/faiScript.tpl b/gosa-core/plugins/admin/fai/faiScript.tpl deleted file mode 100644 index c0ff247b5..000000000 --- a/gosa-core/plugins/admin/fai/faiScript.tpl +++ /dev/null @@ -1,63 +0,0 @@ - - - - -
-

 {t}Generic{/t}

- - - - - - - - - -
- - -{render acl=$cnACL} - -{/render} -
- - -{render acl=$descriptionACL} - -{/render} -
-
-

 

- - - - -
-

  - {t}List of scripts{/t} -

- - - - -
- {$Entry_divlist} -{if $sub_object_is_addable} - -{else} - -{/if} -
-
- - - - diff --git a/gosa-core/plugins/admin/fai/faiScriptEntry.tpl b/gosa-core/plugins/admin/fai/faiScriptEntry.tpl deleted file mode 100644 index cddb2bbcd..000000000 --- a/gosa-core/plugins/admin/fai/faiScriptEntry.tpl +++ /dev/null @@ -1,92 +0,0 @@ - - - - - - - -
-

 {t}Generic{/t}

- - - - - - - - - -
- {t}Name{/t}{$must}  - -{render acl=$cnACL} - -{/render} -
- {t}Description{/t}  - -{render acl=$descriptionACL} - -{/render} -
-
-   - -

 {t}Script attributes{/t}

- - - - - -
- - -{render acl=$FAIpriorityACL} - -{/render} -
-
-

 

-

  - -

- - - - -
-{render acl=$FAIscriptACL} - -{/render} -
-
-
-{render acl=$FAIscriptACL} -   -{/render} -{render acl=$FAIscriptACL} - -{/render} -{render acl=$FAIscriptACL} - {$DownMe} -{/render} -
-
-
-   - -
- - - diff --git a/gosa-core/plugins/admin/fai/faiSummary.tpl b/gosa-core/plugins/admin/fai/faiSummary.tpl deleted file mode 100644 index 196f7cab8..000000000 --- a/gosa-core/plugins/admin/fai/faiSummary.tpl +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - -{if $readable} - - - - - - -{else} - - - -{/if} -
{t}FAI object tree{/t}
- - {t}Reload class and release configuration from parent object.{/t} -
- {$objectList} -
- {t}You are not allowed to view the fai summary.{/t} -
- diff --git a/gosa-core/plugins/admin/fai/faiTemplate.tpl b/gosa-core/plugins/admin/fai/faiTemplate.tpl deleted file mode 100644 index 627c5ddd5..000000000 --- a/gosa-core/plugins/admin/fai/faiTemplate.tpl +++ /dev/null @@ -1,52 +0,0 @@ - - - - - -
-

 {t}Generic{/t}

- - - - - - - - - -
- - -{render acl=$cnACL} - -{/render} -
- - -{render acl=$descriptionACL} - -{/render} -
-
-

  - {t}List of template files{/t} -

- {$Entry_divlist} -{if $sub_object_is_addable} - -{else} - -{/if} -
- - - - diff --git a/gosa-core/plugins/admin/fai/faiTemplateEntry.tpl b/gosa-core/plugins/admin/fai/faiTemplateEntry.tpl deleted file mode 100644 index b8ee41a61..000000000 --- a/gosa-core/plugins/admin/fai/faiTemplateEntry.tpl +++ /dev/null @@ -1,203 +0,0 @@ - - -

 {t}Generic{/t}

- - - - - -
- - - - - - - - - -
- {t}File name{/t}{$must}  - -{render acl=$cnACL} -    -{/render} -
- - -{render acl=$FAItemplatePathACL} - -{/render} -
-
- {t}Description{/t}  -{render acl=$descriptionACL} - -{/render} -
- -

 

- - - - - - - - - - - - -

 {t}Template attributes{/t}

- - - - - - - - -
- - - {$status} - {if $bStatus} - - {t}Save template{/t}... - - {/if} -
-
-{render acl=$FAItemplateFileACL} - -{/render} -{render acl=$FAItemplateFileACL} -   -{/render} -
-
-
- {t}Full path{/t}  - -{render acl=$FAItemplatePathACL} - {$FAItemplatePath} -{/render} -
-
- - - - - - - - - - -
- - -{render acl=$FAIownerACL} - -{/render} -
- - -{render acl=$FAIownerACL} - -{/render} -
-
-
{t}Access{/t}{$must}  - - - - - - - - - - - - - -{render acl=$FAImodeACL} - -{/render} -{render acl=$FAImodeACL} - -{/render} -{render acl=$FAImodeACL} - -{/render} - -{render acl=$FAImodeACL} - -{/render} - - - - -{render acl=$FAImodeACL} - -{/render} -{render acl=$FAImodeACL} - -{/render} -{render acl=$FAImodeACL} - -{/render} - -{render acl=$FAImodeACL} - -{/render} - - - - -{render acl=$FAImodeACL} - -{/render} -{render acl=$FAImodeACL} - -{/render} -{render acl=$FAImodeACL} - -{/render} - -{render acl=$FAImodeACL} - -{/render} - -
{t}Class{/t}{t}Read{/t}{t}Write{/t}{t}Execute{/t} {t}Special{/t} 
{t}User{/t} ({t}SUID{/t})
{t}Group{/t} ({t}SGID{/t})
{t}Others{/t} ({t}sticky{/t})
- -
-
-
-

 

-
-
-   - -
-
- - - - - - diff --git a/gosa-core/plugins/admin/fai/faiVariable.tpl b/gosa-core/plugins/admin/fai/faiVariable.tpl deleted file mode 100644 index cdbdab96b..000000000 --- a/gosa-core/plugins/admin/fai/faiVariable.tpl +++ /dev/null @@ -1,72 +0,0 @@ - - - - - - -
-

 {t}Generic{/t}

- - - - - - - - - -
- - -{render acl=$cnACL} - -{/render} -
- - -{render acl=$descriptionACL} - -{/render} -
-
-   - -

  - -

- - - - -
-
-{if $is_createable} - -{else} - -{/if} - -{if $is_removeable} - -{else} - -{/if} -
-
- - - - diff --git a/gosa-core/plugins/admin/fai/faiVariableEntry.tpl b/gosa-core/plugins/admin/fai/faiVariableEntry.tpl deleted file mode 100644 index 0fd8a4afa..000000000 --- a/gosa-core/plugins/admin/fai/faiVariableEntry.tpl +++ /dev/null @@ -1,64 +0,0 @@ - - - - - - - -
-

 {t}Generic{/t}

- - - - - - - - - -
- {t}Name{/t}{$must}  - -{render acl=$cnACL} - -{/render} -
- {t}Description{/t}  - -{render acl=$descriptionACL} - -{/render} -
-
-   - -

 {t}Variable attributes{/t}

- - - - - -
- - -{render acl=$FAIvariableContentACL} - -{/render} -
-
-

 

-
-
-   - -
- - - - diff --git a/gosa-core/plugins/admin/fai/main.inc b/gosa-core/plugins/admin/fai/main.inc deleted file mode 100644 index b482e3248..000000000 --- a/gosa-core/plugins/admin/fai/main.inc +++ /dev/null @@ -1,56 +0,0 @@ -remove_lock(); - del_lock ($ui->dn); - session::un_set ('FAI'); - } -} else { - /* Create usermanagement object on demand */ - if (!session::is_set('FAI') || (isset($_GET['reset']) && $_GET['reset'] == 1)){ - $FAI= new faiManagement($config, $ui); - $FAI->set_acl_category("fai"); - $FAI->set_acl_base(session::get('CurrentMainBase')); - session::set('FAI',$FAI); - } - $FAI = session::get('FAI'); - $FAI->save_object(); - $output= $FAI->execute(); - - /* Reset requested? */ - if (isset($_GET['reset']) && $_GET['reset'] == 1){ - del_lock ($ui->dn); - session::un_set ('FAI'); - } - /* Page header*/ - if (session::is_set('objectinfo')){ - $display= print_header(get_template_path('images/fai.png'), _("Fully Automatic Installation"), "\"\" ".@LDAP::fix(session::get('objectinfo'))); - } else { - $display= print_header(get_template_path('images/fai.png'), _("Fully Automatic Installation")); - } - $display.= $output; - - session::set('FAI',$FAI); -} - -?> diff --git a/gosa-core/plugins/admin/fai/remove.tpl b/gosa-core/plugins/admin/fai/remove.tpl deleted file mode 100644 index 10bf93dc5..000000000 --- a/gosa-core/plugins/admin/fai/remove.tpl +++ /dev/null @@ -1,24 +0,0 @@ -
- {t}Warning{/t} -
- -

- {$warning} - {t}This includes 'all' object information. Please double check if your really want to do this since there is no way for GOsa to get your data back.{/t} -

- -

- {t}Best thing to do before performing this action would be to save the current contents of your LDAP tree in a file. So - if you've done so - press 'Delete' to continue or 'Cancel' to abort.{/t} -

- -

-{if $multiple} - -   - -{else} - -   - -{/if} -

diff --git a/gosa-core/plugins/admin/fai/remove_branch.tpl b/gosa-core/plugins/admin/fai/remove_branch.tpl deleted file mode 100644 index 3ed7f2329..000000000 --- a/gosa-core/plugins/admin/fai/remove_branch.tpl +++ /dev/null @@ -1,18 +0,0 @@ -
-  {t}Warning{/t} -
-

- {$info} - {t}This includes all account data, system access, etc. for this branch. Please double check if your really want to do this since there is no way for GOsa to get your data back.{/t} -

- -

- {t}So - if you're sure - press 'Delete' to continue or 'Cancel' to abort.{/t} -

- -

- -   - -

- diff --git a/gosa-core/plugins/admin/fai/tabsHook.inc b/gosa-core/plugins/admin/fai/tabsHook.inc deleted file mode 100644 index ed61e1fc8..000000000 --- a/gosa-core/plugins/admin/fai/tabsHook.inc +++ /dev/null @@ -1,48 +0,0 @@ -addSpecialTabs(); - } - - function check($ignore_account= FALSE) - { - return (tabs::check(TRUE)); - } - - - function save($ignore_account= FALSE) - { - $baseobject= $this->by_object['faiHook']; - - $new_dn= 'cn='.$baseobject->cn.",".get_ou('faihookou').get_ou('faiou').session::get('CurrentMainBase'); - $faifilter = session::get('faifilter'); - if($faifilter['branch']!="main"){ - $new_dn ='cn='.$baseobject->cn.",".get_ou('faihookou').$faifilter['branch']; - } - - 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); - } - -} - -?> diff --git a/gosa-core/plugins/admin/fai/tabsPackage.inc b/gosa-core/plugins/admin/fai/tabsPackage.inc deleted file mode 100644 index e678a835e..000000000 --- a/gosa-core/plugins/admin/fai/tabsPackage.inc +++ /dev/null @@ -1,51 +0,0 @@ -addSpecialTabs(); - } - - function check($ignore_account= FALSE) - { - return (tabs::check(TRUE)); - } - - - function save($ignore_account= FALSE) - { - $baseobject= $this->by_object['faiPackage']; - - $new_dn= 'cn='.$baseobject->cn.",".get_ou('faipackageou').get_ou('faiou').session::get('CurrentMainBase'); - - $faifilter = session::get('faifilter'); - - if($faifilter['branch']!="main"){ - $new_dn ='cn='.$baseobject->cn.",".get_ou('faipackageou').$faifilter['branch']; - } - - 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); - } - -} - -?> diff --git a/gosa-core/plugins/admin/fai/tabsPartition.inc b/gosa-core/plugins/admin/fai/tabsPartition.inc deleted file mode 100644 index 308d50b8a..000000000 --- a/gosa-core/plugins/admin/fai/tabsPartition.inc +++ /dev/null @@ -1,50 +0,0 @@ -addSpecialTabs(); - } - - function check($ignore_account= FALSE) - { - return (tabs::check(TRUE)); - } - - - function save($ignore_account= FALSE) - { - $baseobject= $this->by_object['faiPartitionTable']; - - $new_dn= 'cn='.$baseobject->cn.",".get_ou('faipartitionou').get_ou('faiou').session::get('CurrentMainBase'); - - $faifilter = session::get('faifilter'); - if($faifilter['branch']!="main"){ - $new_dn ='cn='.$baseobject->cn.",".get_ou('faipartitionou').$faifilter['branch']; - } - - 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); - } - -} - -?> diff --git a/gosa-core/plugins/admin/fai/tabsProfile.inc b/gosa-core/plugins/admin/fai/tabsProfile.inc deleted file mode 100644 index ccac199c2..000000000 --- a/gosa-core/plugins/admin/fai/tabsProfile.inc +++ /dev/null @@ -1,50 +0,0 @@ -addSpecialTabs(); - } - - function check($ignore_account= FALSE) - { - return (tabs::check(TRUE)); - } - - - function save($ignore_account= FALSE) - { - $baseobject= $this->by_object['faiProfile']; - - $new_dn= 'cn='.$baseobject->cn.",".get_ou('faiprofileou').get_ou('faiou').session::get('CurrentMainBase'); - - $faifilter = session::get('faifilter'); - if($faifilter['branch']!="main"){ - $new_dn ='cn='.$baseobject->cn.",".get_ou('faiprofileou').$faifilter['branch']; - } - - 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); - } - -} - -?> diff --git a/gosa-core/plugins/admin/fai/tabsScript.inc b/gosa-core/plugins/admin/fai/tabsScript.inc deleted file mode 100644 index 094fbb405..000000000 --- a/gosa-core/plugins/admin/fai/tabsScript.inc +++ /dev/null @@ -1,51 +0,0 @@ -addSpecialTabs(); - } - - function check($ignore_account= FALSE) - { - return (tabs::check(TRUE)); - } - - - function save($ignore_account= FALSE) - { - $baseobject= $this->by_object['faiScript']; - - $new_dn= 'cn='.$baseobject->cn.",".get_ou('faiscriptou').get_ou('faiou').session::get('CurrentMainBase'); - - $faifilter = session::get('faifilter'); - - if($faifilter['branch']!="main"){ - $new_dn ='cn='.$baseobject->cn.",".get_ou('faiscriptou').$faifilter['branch']; - } - - 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); - } - -} - -?> diff --git a/gosa-core/plugins/admin/fai/tabsTemplate.inc b/gosa-core/plugins/admin/fai/tabsTemplate.inc deleted file mode 100644 index 5f7f8ab4c..000000000 --- a/gosa-core/plugins/admin/fai/tabsTemplate.inc +++ /dev/null @@ -1,50 +0,0 @@ -addSpecialTabs(); - } - - function check($ignore_account= FALSE) - { - return (tabs::check(TRUE)); - } - - - function save($ignore_account= FALSE) - { - $baseobject= $this->by_object['faiTemplate']; - - $new_dn= 'cn='.$baseobject->cn.",".get_ou('faitemplateou').get_ou('faiou').session::get('CurrentMainBase'); - - $faifilter = session::get('faifilter'); - if($faifilter['branch']!="main"){ - $new_dn ='cn='.$baseobject->cn.",".get_ou('faitemplateou').$faifilter['branch']; - } - - 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); - } - -} - -?> diff --git a/gosa-core/plugins/admin/fai/tabsVariable.inc b/gosa-core/plugins/admin/fai/tabsVariable.inc deleted file mode 100644 index 11694b1d1..000000000 --- a/gosa-core/plugins/admin/fai/tabsVariable.inc +++ /dev/null @@ -1,51 +0,0 @@ -addSpecialTabs(); - } - - function check($ignore_account= FALSE) - { - return (tabs::check(TRUE)); - } - - - function save($ignore_account= FALSE) - { - $baseobject= $this->by_object['faiVariable']; - - $new_dn= 'cn='.$baseobject->cn.",".get_ou('faivariableou').get_ou('faiou').session::get('CurrentMainBase'); - - $faifilter = session::get('faifilter'); - - if($faifilter['branch']!="main"){ - $new_dn ='cn='.$baseobject->cn.",".get_ou('faivariableou').$faifilter['branch']; - } - - 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); - } - -} - -?> diff --git a/gosa-plugins/fai/admin/fai/askClassName.tpl b/gosa-plugins/fai/admin/fai/askClassName.tpl new file mode 100644 index 000000000..7975e1052 --- /dev/null +++ b/gosa-plugins/fai/admin/fai/askClassName.tpl @@ -0,0 +1,89 @@ +
+ {$headline} +
+
+

+{t}Adding a new class to the FAI management, requires a class name. You have to specify a unique class name for unique types of FAI classes, while you can use the same class name for different types of FAI classes. In the laste case, FAI will automatically enclose all these different class types to one unique class name.{/t} +
+
+

+

+
+{t}Please use one of the following methods to choose the name for the new FAI class.{/t} +
+
+

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

{t}Enter FAI class name manually{/t}

+
  + {t}Class name{/t}  +
+
+
+
+ + + + + + + + + + +
+ + +

{t}Choose FAI class name from a list of existing classes{/t}

+
  + {t}Class name{/t}  +
+
+
+
+ + +

 

+ + + diff --git a/gosa-plugins/fai/admin/fai/branch_selector.tpl b/gosa-plugins/fai/admin/fai/branch_selector.tpl new file mode 100644 index 000000000..addb5a7a2 --- /dev/null +++ b/gosa-plugins/fai/admin/fai/branch_selector.tpl @@ -0,0 +1,42 @@ +
+
+

[F]{t}Branches{/t}

+
+
+ + + + +
+ {t}Current release{/t}  + +
+ + + + +
+ {if $allow_create} + + {t}Create new branch{/t} +
+ + {t}Create new locked branch{/t} + {else} + {t}Branch{/t} + {t}Create new branch{/t} +
+ {t}Freeze{/t} + {t}Create new locked branch{/t} + {/if} + + {if $selectedBranch != "main" && $allow_remove} +
+ + {t}Delete current release{/t} + {/if} +
+
+ diff --git a/gosa-plugins/fai/admin/fai/class_FAI.inc b/gosa-plugins/fai/admin/fai/class_FAI.inc new file mode 100644 index 000000000..0365d50e9 --- /dev/null +++ b/gosa-plugins/fai/admin/fai/class_FAI.inc @@ -0,0 +1,920 @@ +get_ldap_link(); + $ldap->cd($config->current['BASE']); + $res = array(); + $tmp = array(); + + if(!FAI::is_release_department($Current_DN)) { + return($res); + } + + /* Collect some basic informations and initialize some variables */ + $base_release = FAI::get_release_dn($Current_DN); + $previous_releases = array_reverse(FAI:: get_previous_releases_of_this_release($base_release,true)); + + /* We must also include the given release dn */ + $previous_releases[] = $base_release; + + /* Walk through all releases */ + foreach($previous_releases as $release){ + + /* Get fai departments */ + $deps_to_search = FAI::get_FAI_departments($release); + + /* For every single department (ou=hoos,ou ..) */ + foreach($deps_to_search as $fai_base){ + + /* Ldap search for fai classes specified in this release */ + $attributes = array("dn","objectClass","FAIstate","cn"); + $res_tmp = get_list($filter,"fai",$fai_base,$attributes,GL_SUBSEARCH | GL_SIZELIMIT); + + /* check the returned objects, and add/replace them in our return variable */ + foreach($res_tmp as $attr){ + + $buffer = array(); + $name = preg_replace("/".normalizePreg($release)."/i","",$attr['dn']); + + if(isset($attr['FAIstate'][0])){ + if(preg_match("/removed$/",$attr['FAIstate'][0])){ + if(isset($res[$name])){ + unset($res[$name]); + } + continue; + } + } + + /* In detailed mode are some additonal informations visible */ + if($detailed){ + + /* Create list of parents */ + if(isset($res[$name])){ + $buffer = $res[$name]; + $buffer['parents'][] = $res[$name]['dn']; + }else{ + $buffer['parents'] = array(); + } + + /* Append objectClass to resulsts */ + foreach($attributes as $val){ + if(isset($attr[$val])){ + $buffer[$val] = $attr[$val]; + } + } + unset($buffer['objectClass']['count']); + } + + /* Add this object to our list */ + $buffer['dn'] = $attr['dn']; + $res[$name] = $buffer; + } + } + } + return($res); + } + + + /* Return all relevant FAI departments */ + static function get_FAI_departments($suffix = "") + { + $arr = array("hooks","scripts","disk","packages","profiles","templates","variables"); + $tmp = array(); + if(preg_match("/^,/",$suffix)){ + $suffix = preg_replace("/^,/","",$suffix); + } + foreach($arr as $name){ + if(empty($suffix)){ + $tmp[$name] = "ou=".$name; + }else{ + $tmp[$name] = "ou=".$name.",".$suffix; + } + } + return($tmp); + } + + + /* Return all releases within the given base */ + static function get_all_releases_from_base($dn,$appendedName=false) + { + global $config; + + if(!preg_match("/".normalizePreg(get_ou('faiou'))."/",$dn)){ + $base = get_ou('faiou').$dn; + }else{ + $base = $dn; + } + $res = array(); + + $ldap = $config->get_ldap_link(); + $ldap->cd($base); + $ldap->search("(objectClass=FAIbranch)",array("ou","dn")); + while($attrs = $ldap->fetch()){ + if($appendedName){ + $res[$attrs['dn']] = convert_department_dn(preg_replace("/,".normalizePreg(get_ou('faiou')).".*$/","",$attrs['dn'])); + }else{ + $res[$attrs['dn']] = $attrs['ou'][0]; + } + } + return($res); + } + + + /* Add this object to list of objects, that must be checked for release saving */ + static function prepare_to_save_FAI_object($Current_DN,$objectAttrs,$removed = false) + { + /* Get ldap object */ + global $config; + $addObj['Current_DN'] = $Current_DN; + $addObj['objectAttrs']= $objectAttrs; + $addObj['removed'] = $removed; + $addObj['diff'] = TRUE; + + if(!$removed){ + $ldap = $config->get_ldap_link(); + $ldap->cd($config->current['BASE']); + + /* Get some basic informations */ + $parent_obj = FAI::get_parent_release_object($Current_DN); + if(!empty($parent_obj)){ + $ldap->cat($parent_obj,array("*")); + $attrs = FAI:: prepare_ldap_fetch_to_be_saved($ldap->fetch()); + + if(!FAI::array_diff_FAI( $attrs,$objectAttrs)){ + $addObj['diff'] = FALSE; + } + } + } + $FAI_objects_to_save = session::get('FAI_objects_to_save') ; + $FAI_objects_to_save[$Current_DN] = $addObj; + session::set('FAI_objects_to_save',$FAI_objects_to_save); + } + + + /* Detect differences in attribute arrays */ + static function array_diff_FAI($ar1,$ar2) + { + + if((!isset($ar1['description'])) || (isset($ar1['description']) && (count($ar1['description']) == 0))){ + $ar1['description'] = ""; + } + if((!isset($ar2['description'])) || (isset($ar2['description']) && (count($ar2['description']) == 0))){ + $ar2['description'] = ""; + } + + if(count($ar1) != count($ar2)) { + return (true); + } + + foreach($ar1 as $key1 => $val1){ + + if((is_array($val1)) && (count($val1)==1)){ + $ar1[$key1] = $val1[0]; + } + + if((is_array($ar2[$key1])) && (count($ar2[$key1])==1)){ + $val1 = $val1[0]; + $ar2[$key1] = $ar2[$key1][0]; + } + } + ksort($ar1); + ksort($ar2); + if(count( array_diff($ar1,$ar2)) || FAI::arr_diff($ar1,$ar2)){ + return(true); + }else{ + return(false); + } + } + + + static function arr_diff($ar1,$ar2) + { + foreach($ar1 as $ak1 => $av1){ + if(!isset($ar2[$ak1]) || (!($av1 === $ar2[$ak1]))){ + return(true); + }elseif(is_array($av1)){ + return(FAI::arr_diff($av1,$ar2[$ak1])); + } + } + return(FALSE); + } + + + + + /* check which objects must be saved, and save them */ + static function save_release_changes_now() + { + /* Variable init*/ + $to_save = array(); + + /* check which objects must be saved */ + $FAI_objects_to_save = session::get('FAI_objects_to_save'); + foreach($FAI_objects_to_save as $Current_DN => $object){ + if($object['diff']){ + $sub_name = $Current_DN; + while(isset($FAI_objects_to_save[$sub_name])){ + $to_save[strlen($sub_name)][$sub_name] = $FAI_objects_to_save[$sub_name]; + unset($FAI_objects_to_save[$sub_name]); + $sub_name = preg_replace('/^[^,]+,/', '', $sub_name); + } + } + } + session::set('FAI_objects_to_save',$FAI_objects_to_save); + + /* Sort list of objects that must be saved, and ensure that + container objects are safed, before their childs are saved */ + ksort($to_save); + $tmp = array(); + foreach($to_save as $SubObjects){ + foreach($SubObjects as $object){ + $tmp[] = $object; + } + } + $to_save = $tmp; + + /* Save objects and manage the correct release behavior*/ + foreach($to_save as $save){ + + $Current_DN = $save['Current_DN']; + $removed = $save['removed']; + $objectAttrs= $save['objectAttrs']; + + /* Get ldap object */ + global $config; + $ldap = $config->get_ldap_link(); + $ldap->cd($config->current['BASE']); + + /* Get some basic informations */ + $base_release = FAI::get_release_dn($Current_DN); + $sub_releases = FAI:: get_sub_releases_of_this_release($base_release,true); + $parent_obj = FAI::get_parent_release_object($Current_DN); + $following_releases = FAI:: get_sub_releases_of_this_release($base_release,true); + + /* Check if given dn exists or if is a new entry */ + $ldap->cat($Current_DN); + if(!$ldap->count()){ + $is_new = true; + }else{ + $is_new = false; + } + + /* if parameter removed is true, we have to add FAIstate to the current attrs + FAIstate should end with ...|removed after this operation */ + if($removed ){ + $ldap->cat($Current_DN); + + /* Get current object, because we must add the FAIstate ...|removed */ + if((!$ldap->count()) && !empty($parent_obj)){ + $ldap->cat($parent_obj); + } + + /* Check if we have found a suiteable object */ + if(!$ldap->count()){ + echo "Error can't remove this object ".$Current_DN; + return; + }else{ + + /* Set FAIstate to current objectAttrs */ + $objectAttrs = FAI:: prepare_ldap_fetch_to_be_saved($ldap->fetch()); + if(isset($objectAttrs['FAIstate'][0])){ + if(!preg_match("/removed$/",$objectAttrs['FAIstate'][0])){ + $objectAttrs['FAIstate'][0] .= "|removed"; + } + }else{ + $objectAttrs['FAIstate'][0] = "|removed"; + } + } + } + + /* Check if this a leaf release or not */ + if(count($following_releases) == 0 ){ + + /* This is a leaf object. It isn't inherited by any other object */ + if(DEBUG_FAI_FUNC) { + echo "Saving directly, is a leaf object
".$Current_DN; + print_a($objectAttrs); + } + FAI::save_FAI_object($Current_DN,$objectAttrs); + }else{ + + /* This object is inherited by some sub releases */ + + /* Get all releases, that inherit this object */ + $r = get_following_releases_that_inherit_this_object($Current_DN); + + /* Get parent object */ + $ldap->cat($parent_obj); + $parent_attrs = FAI:: prepare_ldap_fetch_to_be_saved($ldap->fetch()); + + /* New objects require special handling */ + if($is_new){ + + /* check if there is already an entry named like this, + in one of our parent releases */ + if(!empty($parent_obj)){ + if(DEBUG_FAI_FUNC) { + echo "There is already an entry named like this.
"; + + echo "Saving main object".$Current_DN; + print_a($objectAttrs); + } + FAI::save_FAI_object($Current_DN,$objectAttrs); + + foreach($r as $key){ + if(DEBUG_FAI_FUNC) { + echo "Saving parent to following release ".$key; + print_a($parent_attrs); + } + FAI::save_FAI_object($key,$parent_attrs); + } + }else{ + + if(DEBUG_FAI_FUNC) { + echo "Saving main object".$Current_DN; + print_a($objectAttrs); + } + FAI::save_FAI_object($Current_DN,$objectAttrs); + + if(isset($objectAttrs['FAIstate'])){ + $objectAttrs['FAIstate'] .= "|removed"; + }else{ + $objectAttrs['FAIstate'] = "|removed"; + } + + foreach($r as $key ){ + if(DEBUG_FAI_FUNC) { + echo "Create an empty placeholder in follwing release ".$key; + print_a($objectAttrs); + } + FAI::save_FAI_object($key,$objectAttrs); + } + } + }else{ + + /* check if we must patch the follwing release */ + if(!empty($r)){ + foreach($r as $key ){ + if(DEBUG_FAI_FUNC) { + echo "Copy current objects original attributes to next release ".$key; + print_a($parent_attrs); + } + FAI::save_FAI_object($key,$parent_attrs); + } + } + + if(DEBUG_FAI_FUNC) { + echo "Saving current object".$parent_obj; + print_a($objectAttrs); + } + FAI::save_FAI_object($parent_obj,$objectAttrs); + + if(($parent_obj != $Current_DN)){ + msg_dialog::display(_("Error"), sprintf(_("Error, following objects should be equal '%s' and '%s'"),$parent_obj,$Current_DN), ERROR_DIALOG); + } + } + } + } + session::set('FAI_objects_to_save',array()); + } + + + /* this function will remove all unused (deleted) objects, + that have no parent object */ + static function clean_up_releases($Current_DN) + { + global $config; + $ldap = $config->get_ldap_link(); + $ldap->cd($config->current['BASE']); + + /* Collect some basic informations and initialize some variables */ + $base_release = FAI::get_release_dn($Current_DN); + $previous_releases = array_reverse(FAI:: get_previous_releases_of_this_release($base_release,true)); + $Kill = array(); + $Skip = array(); + + /* We must also include the given release dn */ + $previous_releases[] = $base_release; + + /* Walk through all releases */ + foreach($previous_releases as $release){ + + /* Get fai departments */ + $deps_to_search = FAI::get_FAI_departments($release); + + /* For every single department (ou=hoos,ou ..) */ + foreach($deps_to_search as $fai_base){ + + /* Ldap search for fai classes specified in this release */ + $ldap->cd($fai_base); + $ldap->search("(objectClass=FAIclass)",array("dn","objectClass","FAIstate")); + + /* check the returned objects, and add/replace them in our return variable */ + while($attr = $ldap->fetch()){ + + $buffer = array(); +# $name = str_ireplace($release,"",$attr['dn']); + $name = preg_replace("/".normalizePreg($release)."/i","",$attr['dn']); + + if(isset($attr['FAIstate'][0])&&(preg_match("/removed$/",$attr['FAIstate'][0]))){ + + /* Check if this object is required somehow */ + if(!isset($Skip[$name])){ + $Kill[$attr['dn']] = $attr['dn']; + } + }else{ + + /* This object is required (not removed), so do not + delete any following sub releases of this object */ + $Skip[$name] = $attr['dn']; + } + } + } + } + return($Kill); + } + + + /* Remove numeric index and 'count' from ldap->fetch result */ + static function prepare_ldap_fetch_to_be_saved($attrs) + { + foreach($attrs as $key => $value){ + if(is_numeric($key) || ($key == "count") || ($key == "dn")){ + unset($attrs[$key]); + } + if(is_array($value) && isset($value['count'])){ + unset($attrs[$key]['count']); + } + } + return($attrs); + } + + + /* Save given attrs to specified dn*/ + static function save_FAI_object($dn,$attrs) + { + global $config; + $ldap = $config->get_ldap_link(); + $ldap->cd($config->current['BASE']); + $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $dn)); + $ldap->cd($dn); + + $ldap->cat($dn,array("dn")); + if($ldap->count()){ + + /* Remove FAIstate*/ + if(!isset($attrs['FAIstate'])){ + $attrs['FAIstate'] = array(); + } + + $ldap->modify($attrs); + }else{ + + /* Unset description if empty */ + if(empty($attrs['description'])){ + unset($attrs['description']); + } + + $ldap->add($attrs); + } + show_ldap_error($ldap->get_error(),sprintf(_("Release management failed, can't save '%s'"),$dn)); + } + + + /* Return FAIstate freeze branch or "" for specified release department */ + static function get_release_tag($dn) + { + global $config; + $ldap = $config->get_ldap_link(); + $ldap->cd($dn); + $ldap->cat($dn,array("FAIstate")); + + if($ldap->count()){ + + $attr = $ldap->fetch(); + if(isset($attr['FAIstate'][0])){ + if(preg_match("/freeze/",$attr['FAIstate'][0])){ + return("freeze"); + }elseif(preg_match("/branch/",$attr['FAIstate'][0])){ + return("branch"); + } + } + } + return(""); + } + + + static function get_following_releases_that_inherit_this_object($dn) + { + global $config; + $ldap = $config->get_ldap_link(); + $ldap->cd($config->current['BASE']); + + $ret = array(); + + /* Get base release */ + $base_release = FAI::get_release_dn($dn); + + /* Get previous release dns */ + $sub_releases = FAI:: get_sub_releases_of_this_release($base_release); + + /* Get dn suffix. Example "FAIvairableEntry=keksdose,FAIvariable=Keksregal," */ +# $dn_suffix = str_ireplace($base_release,"",$dn); + $dn_suffix = preg_replace("/".normalizePreg($base_release)."/i","",$dn); + + /* Check if given object also exists whitin one of these releases */ + foreach($sub_releases as $p_release => $name){ + + $check_dn = $dn_suffix.$p_release; + + $ldap->cat($check_dn,array("dn","objectClass")); + + if($ldap->count()){ + //return($ret); + }else{ + $ret[$check_dn]=$check_dn; + } + } + return($ret); + } + + + /* Get previous version of the object dn */ + static function get_parent_release_object($dn,$include_myself=true) + { + global $config; + $ldap = $config->get_ldap_link(); + $ldap->cd($config->current['BASE']); + $previous_releases= array(); + + /* Get base release */ + $base_release = FAI::get_release_dn($dn); + if($include_myself){ + $previous_releases[] = $base_release; + } + + /* Get previous release dns */ + $tmp = FAI:: get_previous_releases_of_this_release($base_release,true); + foreach($tmp as $release){ + $previous_releases[] = $release; + } + + /* Get dn suffix. Example "FAIvairableEntry=keksdose,FAIvariable=Keksregal," */ +# $dn_suffix = str_ireplace($base_release,"",$dn); + $dn_suffix = preg_replace("/".normalizePreg($base_release)."/i","",$dn); + + /* Check if given object also exists whitin one of these releases */ + foreach($previous_releases as $p_release){ + $check_dn = $dn_suffix.$p_release; + $ldap->cat($check_dn,array("dn","objectClass")); + + if($ldap->count()){ + return($check_dn); + } + } + return(""); + } + + + /* return release names of all parent releases */ + static function get_previous_releases_of_this_release($dn,$flat) + { + global $config; + $ldap = $config->get_ldap_link(); + $ldap->cd($config->current['BASE']); + $ret = array(); + + /* Explode dns into pieces, to be able to build parent dns */ + $dns_to_check = gosa_ldap_explode_dn(preg_replace("/".normalizePreg(",".$config->current['BASE'])."/i","",$dn)); + + if(!is_array($dns_to_check)){ + return; + } + + /* Unset first entry which represents the given dn */ + unset($dns_to_check['count']); + unset($dns_to_check[key($dns_to_check)]); + + /* Create dns addresses and check if this dn is a release dn */ + $id = 0; + while(count($dns_to_check)){ + + /* build parent dn */ + $new_dn = ""; + foreach($dns_to_check as $part){ + $new_dn .= $part.","; + } + $new_dn .= $config->current['BASE']; + + /* check if this dn is a release */ + if(FAI::is_release_department($new_dn)){ + if($flat){ + $ret[$id] = $new_dn; + }else{ + $ret = array($new_dn=>$ret); + } + $id ++; + }else{ + return($ret); + } + reset($dns_to_check); + unset($dns_to_check[key($dns_to_check)]); + } + return($ret); + } + + + /* This function returns all sub release names, recursivly */ + static function get_sub_releases_of_this_release($dn,$flat = false) + { + global $config; + $res = array(); + $ldap = $config->get_ldap_link(); + $ldap->cd($config->current['BASE']); + $ldap->ls("(objectClass=FAIbranch)",$dn,array("objectClass","dn","ou")); + while($attr = $ldap->fetch()){ + + /* Append department name */ + if($flat){ + $res[$attr['dn']] = $attr['ou'][0]; + }else{ + $res[$attr['dn']] = array(); + } + + /* Get sub release departments of this department */ + if(in_array("FAIbranch",$attr['objectClass'])) { + if($flat){ + $tmp = FAI:: get_sub_releases_of_this_release($attr['dn'],$flat); + foreach($tmp as $dn => $value){ + $res[$dn]=$value; + } + }else{ + $res[$attr['dn']] = FAI:: get_sub_releases_of_this_release($attr['dn']); + } + } + } + return($res); + } + + + /* Check if the given department is a release department */ + static function is_release_department($dn) + { + global $config; + $ldap = $config->get_ldap_link(); + $ldap->cd($config->current['BASE']); + $ldap->cat($dn,array("objectClass","ou")); + + /* Check objectClasses and name to check if this is a release department */ + if($ldap->count()){ + $attrs = $ldap->fetch(); + + $ou = ""; + if(isset($attrs['ou'][0])){ + $ou = $attrs['ou'][0]; + } + + if((in_array("FAIbranch",$attrs['objectClass'])) || ($ou == "fai")){ + return($attrs['dn']); + } + } + return(false); + } + + + /*! \brief Create a new FAI branch. + * @param $sourcedn String The source release dn + * @param $destinationdn String The destination dn + * @param $destinationName String The name of the new release + * @param $type String The release type (freeze/branch) + * @param $is_first Boolean Use to identify the first func. call when recursivly called. + * @param $depth Integer Current depth of recursion. + */ + function copy_FAI_resource_recursive($sourcedn,$destinationdn,$destinationName,$type="branch",$is_first = true,$depth=0) + { + global $config; + error_reporting(E_ALL | E_STRICT); + $ldap = $config->get_ldap_link(); + $basedn = $config->current['BASE']; + $delarray = array(); + + /* The following code will output a status string + * for each handled object, in a seperate iframe. + */ + + + /* Display current action information. + */ + if($is_first){ + echo "

".sprintf(_("Creating copy of %s"),"".LDAP::fix($sourcedn)."")."

"; + }else{ + if(preg_match("/^ou=/",$sourcedn)){ + echo "

"._("Processing")." ".LDAP::fix($destinationdn)."

"; + }else{ + $tmp = split(",",$sourcedn); + echo " "._("Object").": "; + $deststr = LDAP::fix($destinationdn); + if(strlen($deststr) > 96){ + $deststr = substr($deststr,0,96)."..."; + } + echo $deststr."
"; + } + } + /* .. immediately display infos */ + flush(); + + /* Check if destination entry already exists + */ + $ldap->cat($destinationdn); + if($ldap->count()){ + echo _("Could not create new release, the destination dn is already in use."); + return; + }else{ + + $ldap->clearResult(); + + /* Get source entry + * if it does not exist, abort here. + */ + $ldap->cd($basedn); + $ldap->cat($sourcedn); + $attr = $ldap->fetch(); + if((!$attr) || (count($attr)) ==0) { + echo _("Error while fetching source dn - aborted!"); + return; + } + + /* The current object we want to create is an department. + * Create the department and add the FAIbranch tag. + */ + if(in_array("organizationalUnit",$attr['objectClass'])){ + $attr['dn'] = LDAP::convert($destinationdn); + $ldap->cd($basedn); + $ldap->create_missing_trees($destinationdn); + $ldap->cd($destinationdn); + + /* If is first entry, append FAIbranch to department entry */ + if($is_first){ + $ldap->cat($destinationdn); + $attr= $ldap->fetch(); + /* Filter unneeded informations */ + foreach($attr as $key => $value){ + if(is_numeric($key)) unset($attr[$key]); + if(isset($attr[$key]['count'])){ + if(is_array($attr[$key])){ + unset($attr[$key]['count']); + } + } + } + + unset($attr['count']); + unset($attr['dn']); + + /* Add marking attribute */ + $attr['objectClass'][] = "FAIbranch"; + + /* Add this entry */ + $ldap->modify($attr); + } + }else{ + + /* Replicate all relevant FAI objects here. + * FAI objects, Apps and Mimetypes. + * Get all attributes as binary value, to ensure that Icon, File template aso + * are created correctly. + */ + foreach($attr as $key => $value){ + + if(in_array($key ,array("gotoLogonScript", "gosaApplicationIcon","gotoMimeIcon"))){ + $sr= ldap_read($ldap->cid, LDAP::fix($sourcedn), "$key=*", array($key)); + $ei= ldap_first_entry($ldap->cid, $sr); + if ($tmp= @ldap_get_values_len($ldap->cid, $ei,$key)){ + $attr[$key] = $tmp; + } + } + + if(is_numeric($key)) unset($attr[$key]); + if(isset($attr[$key]['count'])){ + if(is_array($attr[$key])){ + unset($attr[$key]['count']); + } + } + } + unset($attr['count']); + unset($attr['dn']); + + /* Add entry + */ + $ldap->cd($destinationdn); + $ldap->cat($destinationdn); + + $a = $ldap->fetch(); + if(!count($a)){ + $ldap->add($attr); + } + + if($ldap->error != "Success"){ + + /* Some error occurred */ + print "---------------------------------------------"; + print $ldap->get_error()."
"; + print $sourcedn."
"; + print $destinationdn."
"; + print_a( $attr); + exit(); + } + } + } + + echo "" ; + + /* Prepare for recursive copy. + * Get all object within the source dn and + * call the recursive copy for each. + */ + $ldap->ls ("(objectClass=*)",$sourcedn); + while ($ldap->fetch()){ + $deldn= $ldap->getDN(); + $delarray[$deldn]= strlen($deldn); + } + asort ($delarray); + reset ($delarray); + $depth ++; + foreach($delarray as $dn => $bla){ + if($dn != $destinationdn){ + $ldap->cd($basedn); + $item = $ldap->fetch($ldap->cat($dn)); + if(!in_array("FAIbranch",$item['objectClass'])){ + FAI::copy_FAI_resource_recursive($dn,str_replace($sourcedn,$destinationdn,$dn),$destinationName,$type,false,$depth); + } + } + } + if($is_first){ + echo "

 

"; + } + } + + + + /* This function returns the dn of the object release */ + static function get_release_dn($Current_DN) + { + global $config; + $ldap = $config->get_ldap_link(); + $ldap->cd($config->current['BASE']); + + /* Split dn into pices */ + $dns_to_check = gosa_ldap_explode_dn(preg_replace("/".normalizePreg(",".$config->current['BASE'])."/i","",$Current_DN)); + + if(!is_array($dns_to_check)){ + return; + } + + /* Use dn pieces, to create sub dns like + ou=test,ou=1,ou=0... + ou=1,ou=0... + ou=0... + To check which dn is our release container. + */ + unset($dns_to_check['count']); + while(count($dns_to_check)){ + + /* Create dn */ + $new_dn = ""; + foreach($dns_to_check as $part){ + $new_dn .= $part.","; + } + $new_dn .= $config->current['BASE']; + + /* Check if this dn is a release dn */ + if(FAI::is_release_department($new_dn)){ + return($new_dn); + } + + /* Remove first element of dn pieces */ + reset($dns_to_check); + unset($dns_to_check[key($dns_to_check)]); + } + return(""); + } +} + + + + +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/gosa-plugins/fai/admin/fai/class_askClassName.inc b/gosa-plugins/fai/admin/fai/class_askClassName.inc new file mode 100644 index 000000000..c7e38adb5 --- /dev/null +++ b/gosa-plugins/fai/admin/fai/class_askClassName.inc @@ -0,0 +1,172 @@ + "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,$ui,$objectClass) + { + $this->ui = $ui; + $this->objectClass = $objectClass; + plugin::plugin ($config, $dn); + if(!session::is_set('CurrentMainBase')){ + session::set('CurrentMainBase',$this->config->current['BASE']); + } + } + + function execute() + { + /* Call parent execute */ + plugin::execute(); + + /* Fill templating stuff */ + $smarty = get_smarty(); + $display= ""; + + /* The faifilter contais + * The base for all fai objects + */ + $faifilter = session::get('faifilter'); + + /* First search for every ou, in given fai base + * With a second search detect all object that belong to the different ous. + */ + + $base = get_ou('faiou').session::get('CurrentMainBase'); + if($faifilter['branch'] != "main"){ + $base = $faifilter['branch']; + } + $ldap = $this->config->get_ldap_link(); + + $res= get_list("(&(objectClass=organizationalUnit)(!(objectClass=FAIbranch)))", "fai", $base, + array("cn","description","objectClass"), GL_SIZELIMIT ); + + $delete = array(); + $used = array(); + foreach($res as $objecttypes){ + $res2= get_list("(objectClass=*)", "fai", $objecttypes['dn'], + array("cn","description","objectClass","FAIclass","FAIstate"), GL_SIZELIMIT | GL_CONVERT ); + foreach($res2 as $object){ + + /* skip class names with this name */ + if(in_array($this->objectClass,$object['objectClass']) || in_array("FAIprofile",$object['objectClass'])){ + if(isset($object['FAIstate'][0]) && preg_match("/removed$/",$object['FAIstate'][0])){ + continue; + } + $delete[] = $object['cn'][0]; + } + + /* Skip profiles */ + if(!in_array("FAIprofile",$object['objectClass'])){ + if(isset($object['cn'])){ + $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 bundle.");break; + case "FAIscript" : $str =_("Create new FAI object - script bundle.");break; + case "FAIvariable" : $str =_("Create new FAI object - variable bundle.");break; + case "FAIhook" : $str =_("Create new FAI object - hook bundle.");break; + case "FAIprofile" : $str =_("Create new FAI object - profile.");break; + case "FAItemplate" : $str =_("Create new FAI object - template.");break; + default : $str =_("Create new 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 for this type + * of objectClass, we only can create a new one, disable selectBox + */ + if(count ($used)==0){ + $smarty->assign("ClassNamesAvailable", " disabled "); + $smarty->assign("grey", 'style="color:#C0C0C0"'); + }else{ + $smarty->assign("ClassNamesAvailable", ""); + $smarty->assign("grey", ""); + } + ksort($used); + $smarty->assign("ClassNames", $used); + $smarty->assign("ClassName", $this->ClassName); + $display.= $smarty->fetch(get_template_path('askClassName.tpl', TRUE)); + return($display); + } + + /* Get posts and set class name + */ + function save_object() + { + if(isset($_POST['classSelector']) && $_POST['classSelector'] == 1 + && isset($_POST['edit_continue'])){ + $this->ClassName = $_POST['UseTextInputName']; + $this->ClassAlreadyExists = true; + } + + if(isset($_POST['classSelector']) && $_POST['classSelector'] == 2 + && isset($_POST['edit_continue'])){ + $this->ClassAlreadyExists = false; + $this->ClassName = $_POST['SelectedClass']; + } + } + + /* Check given class name + */ + function check() + { + /* Call common method to give check the hook */ + $message= plugin::check(); + + if($this->ClassName != preg_replace("/ /","",trim($this->ClassName))){ + $message[] = _("Spaces are not allowed within class names."); + } + + 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/gosa-plugins/fai/admin/fai/class_debconfTemplate.inc b/gosa-plugins/fai/admin/fai/class_debconfTemplate.inc new file mode 100644 index 000000000..d781321ec --- /dev/null +++ b/gosa-plugins/fai/admin/fai/class_debconfTemplate.inc @@ -0,0 +1,428 @@ +set_language($language); + $this->set_package($package); + } + + + function set_package($package) + { + $this->package= $package; + } + + + function set_template_directory($directory) + { + if (is_dir($directory) && is_readable($directory)){ + $this->template_directory = $directory; + return TRUE; + } + + $this->template_directory= ""; + return FALSE; + } + + + function set_language($language) + { + $this->language= $language; + } + + + function load() + { + if( TRUE === $this->has_template() ) { + + /* Try to load package based template file */ + $this->template= array(); + + /* Read template array */ + $post_name = 0; + $langcode = $this->language.".UTF-8"; + $in_description = FALSE; + $got_local_description = FALSE; + + /* get filename */ + $filename= preg_replace("/\/+/", "/", $this->template_directory."/".$this->package.".templates"); + + /* Check if file is readable */ + if (!is_file($filename) || !is_readable($filename)){ + return(FALSE); + } + + /* Open file and read content line by line */ + $fh= fopen($filename, 'r'); + + /* While the file handle is valid && there is still data to read -> parse configuration file */ + while ($fh && !feof($fh)){ + $line= fgets($fh, 1024); + + /* Reset description flag */ + if ($in_description && !preg_match("/^ /", $line)){ + $in_description= FALSE; + } + + /* Template header */ + if (preg_match("/^Template: /", $line)){ + $post_name ++; + $name= trim(preg_replace("/^Template: (.*)$/", "\\1", $line)); + $this->template[$post_name]['Name'] = $name; + $this->template[$post_name]['Default'] =""; + + $got_local_description= FALSE; + continue; + } + + /* Get type */ + if (preg_match("/^Type: /", $line)){ + $type= trim(preg_replace("/^Type: (.*)$/", "\\1", $line)); + $this->template[$post_name]['Type']= $type; + continue; + } + + /* Get default */ + if (preg_match("/^Default: /", $line)){ + $this->template[$post_name]['Default']= ""; + $default= trim(preg_replace("/^Default: (.*)$/", "\\1", $line)); + $this->template[$post_name]['Default']= $default; + continue; + } + + /* Get description */ + if (!$got_local_description && preg_match("/^Description: /", $line)){ + $this->template[$post_name]['Description']= ""; + $description= trim(preg_replace("/^Description: (.*)$/", "\\1", $line)); + $this->template[$post_name]['Topic']= $description; + $this->template[$post_name]['Description']= ""; + $in_description= TRUE; + continue; + } + + /* Fill description */ + if (!$got_local_description && $in_description){ + $description= preg_replace("/^ (.*)$/", "\\1", $line); + $this->template[$post_name]['Description'].= $description; + continue; + } + + /* Get local description */ + if (preg_match("/^Description-$langcode: /", $line)){ + $description= trim(preg_replace("/^Description-$langcode: (.*)$/", "\\1", $line)); + $this->template[$post_name]['Topic']= $description; + $in_description= TRUE; + $got_local_description= TRUE; + $this->template[$post_name]['Description']= ""; + continue; + } + + /* Fill local description */ + if ($got_local_description && $in_description){ + $description= preg_replace("/^ (.*)$/", "\\1", $line); + $this->template[$post_name]['Description'].= $description; + continue; + } + + /* Get native choices */ + if (preg_match("/^Choices: /", $line)){ + $type= trim(preg_replace("/^Choices: (.*)$/", "\\1", $line)); + $this->template[$post_name]['Choices']= $type; + } + + /* Get local choices */ + if (preg_match("/^Choices-$langcode: /", $line)){ + $type= trim(preg_replace("/^Choices-$langcode: (.*)$/", "\\1", $line)); + $this->template[$post_name]['Choices-local']= $type; + } + + } + + fclose($fh); + $this->loaded_template= TRUE; + + $tmp= array(); + foreach($this->template as $post_name => $template){ + $template['post_name'] = "post_".$post_name; + $tmp[] = $template; + } + $this->template = $tmp; + + return (TRUE); + } + + $this->loaded_template= FALSE; + return (FALSE); + } + + + function has_template() + { + /* Reject requests, if parameters are not set */ + if ($this->package == "" || $this->template_directory == ""){ + return (FALSE); + } + $filename= preg_replace("/\/+/", "/", $this->template_directory."/".$this->package.".templates"); + return (is_file($filename) && is_readable($filename)); + } + + + /* Check if some fields are posted */ + function PostCheck() + { + /* Walk through all template variables */ + foreach($this->template as $post_name => $entry){ + + /* Check if this var is set*/ + if(isset($_POST[$entry['post_name']])){ + + /* special handling for arrays */ + if(is_array($_POST[$entry['post_name']])){ + $str = ""; + foreach($_POST[$entry['post_name']] as $val){ + $str.= $val.", "; + } + $str = preg_replace("/\,\ $/","",$str); + $this->template[$post_name]['Default'] = $str; + }else{ + $this->template[$post_name]['Default'] = $_POST[$entry['post_name']]; + } + } + } + + foreach($this->template as $post_name => $entry){ + if(isset($_POST["multi-".$entry['post_name']])){ + $this->template[$post_name]['Default']= ""; + foreach($_POST as $name => $value){ + if(preg_match("/".$entry['post_name']."-multi-/",$name)){ + $this->template[$post_name]['Default'] .= $value.", "; + } + } + $this->template[$post_name]['Default'] = preg_replace("/, $/","",$this->template[$post_name]['Default']); + } + } + + + } + + + /* This funtion sets the defualt value */ + function SetDefault($var,$val) + { + if ($this->loaded_template) { + foreach($this->template as $key => $tmp){ + if($tmp['Name'] == $var ){ + $this->template[$key]['Default'] = $val; + } + } + } + } + + + /* Display all possible options in html*/ + function get_dialog() + { + if ($this->loaded_template) { + $result= ""; + + foreach ($this->template as $post_name => $entry){ + + $types= array("boolean" => "", "multiselect" => "", "note" => "", + "password" => "", "select" => "", "string" => "", "text" => "", "title" => ""); + + /* Check if type is available */ + if ((isset($entry['Type']))&&(isset($types[$entry['Type']]))){ + + /* Produce type specific output */ + $fn= "render_".$entry['Type']; + $str = $this->$fn($entry); + if(!empty($str)){ + $result.=$str.""; + } + } else { + //php_error(E_WARNING, "An unknown type has been specified in the debconf template. Please fix."); + } + } + + + $result .= "

 

"; + return ($result); + } else { + return _("This package has no debconf options."); + } + } + + + function render_boolean($data) + { + + $post_name= $data['post_name']; + $result=" + + +

".$data['Topic']."

".$data['Description']." + + "; + + foreach(array("true","false") as $value){ + if($data['Default'] == $value){ + $result.=""._($value); + }else{ + $result.=""._($value); + } + $result.="
"; + } + + $result.= " + + + "; + + return ($result); + } + + + function render_multiselect($data) + { + $post_name= $data['post_name']; + if (preg_match('/\$\{/', $data['Choices'])){ + $result= $this->render_string($data); + } else { + $choices= ""; + foreach (split(", ", $data['Choices']) as $choice){ + $choices[]= $choice; + } + + + $result=" + + +

".$data['Topic']."

".$data['Description']." + + + + "; + + $defs = split(", ",$data['Default']); + foreach($choices as $value){ + if(in_array($value,$defs)){ + $result.="\n".$value."
"; + }else{ + $result.="\n".$value."
"; + } + } + + $result .= " + + "; + } + + return ($result); + } + + + function render_note($data) + { + /* Ignore notes, they do not makes sense, since we don't get any + chance to test entered values... */ + return (""); + } + + + function render_password($data) + { + $result= ""; + $result.= ""; + $result.= "

".$data['Topic']."

".$data['Description']." 

"; + $result.= $data['Description']; + $result.= ""; + + return ($result); + } + + + function render_select($data) + { + $post_name= $data['post_name']; + + if (preg_match('/\$\{/', $data['Choices'])){ + $choices= array("Need to use some text..."); + } else { + $choices= ""; + foreach (split(", ", $data['Choices']) as $choice){ + $choices[]= $choice; + } + } + + + $result=" + + + +

".$data['Topic']."

".$data['Description']." + + + "; + + foreach($choices as $value){ + if($data['Default'] == $value){ + $result.="\n".htmlentities($value)."
"; + }else{ + $result.="\n".htmlentities($value)."
"; + } + } + + $result.= " + + + + "; + + return ($result); + } + + + function render_string($data) + { + $result= " + + +

".$data['Topic']."

".$data['Description']." + + + + + + "; + + return ($result); + } + + + function render_text($data) + { + /* Ignore text messages, they are normally used for status hints. */ + return (""); + } + + + function render_title($data) + { + /* Ignore text messages, they are normally used for status hints. */ + return (""); + } + +} + + +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/gosa-plugins/fai/admin/fai/class_divListFai.inc b/gosa-plugins/fai/admin/fai/class_divListFai.inc new file mode 100644 index 000000000..f8977130e --- /dev/null +++ b/gosa-plugins/fai/admin/fai/class_divListFai.inc @@ -0,0 +1,421 @@ +parent = $parent; + $this->ui = get_userinfo(); + + /* Set default base */ + if(!session::is_set('CurrentMainBase')){ + session::set('CurrentMainBase',$this->config->current['BASE']); + } + $this->selectedBase = session::get('CurrentMainBase'); + + /* Set list strings */ + $this->SetTitle(_("List of FAI classes")); + $this->SetSummary(_("This table displays all FAI classes in the selected tree.")); + + /* Result page will look like a headpage */ + $this->SetHeadpageMode(); + $this->SetInformation(_("This menu allows you to create, delete and edit FAI classes.")); + + $this->EnableAplhabet (true); + + /* Disable buttonsm */ + $this->EnableCloseButton(false); + $this->EnableSaveButton (false); + + /* Dynamic action col, depending on snapshot icons */ + $action_col_size = 80; +# if($this->parent->snapshotEnabled()){ +# $action_col_size += 32; +# } + + /* Toggle all selected / deselected */ + $chk = ""; + + /* set Page header */ + $this->AddHeader(array("string"=> $chk, "attach"=>"style='width:20px;'")); + $this->AddHeader(array("string" => " ", "attach" => "style='text-align:center;width:20px;'")); + $this->AddHeader(array("string" => _("Name of FAI class"), "attach" => "style=''")); + $this->AddHeader(array("string" => _("Class type"), "attach" => "style='width:200px;'")); + $this->AddHeader(array("string" => _("Actions"), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'")); + + $this->AddCheckBox("ShowProfiles" , _("Display FAI profile objects") ,_("Show profiles") ,true); + $this->AddCheckBox("ShowTemplates" , _("Display FAI template objects") ,_("Show templates") ,true); + $this->AddCheckBox("ShowScripts" , _("Display FAI scripts") ,_("Show scripts") ,true); + $this->AddCheckBox("ShowHooks" , _("Display FAI hooks") ,_("Show hooks") ,true); + $this->AddCheckBox("ShowVariables" , _("Display FAI variables") ,_("Show variables") ,true); + $this->AddCheckBox("ShowPackages" , _("Display FAI packages") ,_("Show packages") ,true); + $this->AddCheckBox("ShowPartitions" , _("Display FAI partitions") ,_("Show partitions") ,true); + + /* Add SubSearch checkbox */ + //$this->AddCheckBox(SEPERATOR); + //$this->AddCheckBox("SubSearch", _("Select to search within subtrees"), _("Search in subtrees"), false); + + /* Name ,Text ,Default , Connect with alphabet */ + $this->AddRegex ("Regex", _("Display users matching"),"*" , true); + } + + function AddUserBoxToFilter($position) + { + $str = ""; + if($position == 2){ + + /* Check if there are post commands available for fai management. + * If not, grey out freeze/branch and release remove buttons. + */ + $r = $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs')); + $c = $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs')); + + $smarty = get_smarty(); + $smarty->assign("allow_create", $c); + $smarty->assign("allow_remove", $r); + $smarty->assign("selectedBranch",$this->selectedBranch); + $smarty->assign("branchimage","images/branch.png"); + $smarty->assign("branches",$this->AvailableBranches); + $plug_id = 0; + if(isset($_GET['plug'])){ + $plug_id = $_GET['plug']; + } + $smarty->assign("plug_id",$plug_id); + $str = $smarty->fetch(get_template_path('branch_selector.tpl', TRUE)); + } + return($str); + } + + function GenHeader() + { + /* Prepare departments, + which are shown in the listbox on top of the listbox + */ + $options= ""; + + /* Get all departments within this subtree */ + $ui= get_userinfo(); + $first = ""; + $found = FALSE; + $base = $this->config->current['BASE']; + + /* Add base */ + $tmp = array(); + $tmp[] = array("dn"=>$this->config->current['BASE']); + $tmp= array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base, + array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH)); + + $deps = array(); + foreach($tmp as $tm){ + $deps[$tm['dn']] = $tm['dn']; + } + + /* Load possible departments */ + $ui= get_userinfo(); + $tdeps= $ui->get_module_departments("fai"); + $ids = $this->config->idepartments; + $first = ""; + $found = FALSE; + foreach($ids as $dep => $name){ + if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){ + + /* Keep first base dn in mind, we could need this + * info if no valid base was found + */ + if(empty($first)) { + $first = $dep['dn']; + } + + $value = $ids[$dep]; + if ($this->selectedBase == $dep){ + $found = TRUE; + $options.= ""; + } else { + $options.= ""; + } + } + } + + /* The currently used base is not visible with your acl setup. + * Set base to first useable base. + */ + if(!$found){ + $this->selectedBase = $first; + } + + /* Add seperator */ + $add_sep = false; + + /* Get complete fai acls, to be able to check if we must show or hide the snapshot abilities */ + $acl_all = $ui->has_complete_category_acls($this->selectedBase,$this->module); + + /* Add default header */ + $listhead = MultiSelectWindow::get_default_header(); + + /* Add additional seperator */ + if($add_sep){ + $listhead .="  "; + } + + $listhead .= _("Base")." ". + "  "; + + + $s = ".|"._("Actions")."|\n"; + $s .= "..|". + " "._("Create")."|\n"; + + $acl = $ui->get_permissions($this->selectedBase,"fai/faiProfile"); + if(preg_match("/c/",$acl)){ + $s.= "...|". + " "._("Profile")."|Create_profile|\n"; + } + + /* Append create icons for each fai component */ + $arr = array( + array("images/fai_new_partitionTable.png" , _("Partition table") ,"Create_partition" , _("PT") , "faiPartitionTable"), + array("images/fai_new_script.png" , _("Scripts") ,"Create_script" , _("S") , "faiScript"), + array("images/fai_new_hook.png" , _("Hooks") ,"Create_hook" , _("H") , "faiHook"), + array("images/fai_new_variable.png" , _("Variables") ,"Create_variable" , _("V") , "faiVariable"), + array("images/fai_new_template.png" , _("Templates ") ,"Create_template" , _("I") , "faiTemplate"), + array("images/fai_new_packages.png" , _("Package list") ,"Create_package" , _("PK") , "faiPackage")); + + foreach($arr as $ar){ + $acl = $ui->get_permissions($this->selectedBase,"fai/".$ar[4]); + if(preg_match("/c/",$acl)){ + $s.= "...|". + " ".$ar[1]."|".$ar[2]."|\n"; + } + } + + /* Multiple options */ + $s.= "..|". + " "._("Remove")."|"."remove_multiple|\n"; + + /* Add multiple copy & cut icons */ + if(is_object($this->parent->CopyPasteHandler)){ + $s.= "..|---|\n"; + $s.= "..|". + " "._("Copy")."|"."multiple_copy_systems|\n"; + $s.= "..|". + " "._("Cut")."|"."multiple_cut_systems|\n"; + } + + /* Add copy & paste icons, currently disabled, this ability is not implemeneted yet */ + if(preg_match("/(c.*w|w.*c)/",$acl_all) && isset($this->parent->CopyPasteHandler) && $this->parent->CopyPasteHandler){ + $s .= "..|---|\n"; + if($this->parent->CopyPasteHandler->entries_queued()){ + $img = ""; + $s.="..|".$img." "._("Paste")."|editPaste|\n"; + }else{ + $img = ""; + $s.="..|".$img." "._("Paste")."\n"; + } + } + +# /* Add snapshot icons, if we are allowed to write and create the complete fai module ($ui->has_complete_category_acls) */ +# if(preg_match("/(c.*w|w.*c)/",$acl_all)){ +# if($this->parent->snapshotEnabled()){ +# $s .= "..|---|\n"; +# $s .= $this->get_snapshot_header(TRUE); +# } +# } + + $this->SetDropDownHeaderMenu($s); + $this->SetListHeader($listhead); + } + + /* so some basic settings */ + function execute() + { + $this->ClearElementsList(); + $this->GenHeader(); + $this->AvailableBranches = $this->parent->getBranches(); + } + + function setEntries($list) + { + /******************** + Variable init + ********************/ + + $objects = array( + "FAIpartitionTable" => array("IMG"=> "images/fai_partitionTable.png", "NAME"=>_("Partition table"),"KZL"=> "PT", "VAR"=>"ShowPartitions"), + "FAIpackageList" => array("IMG"=> "images/fai_packages.png", "NAME"=>_("Package list") , "KZL"=> "PL", "VAR"=>"ShowPackages"), + "FAIscript" => array("IMG"=> "images/fai_script.png", "NAME"=>_("Scripts") , "KZL"=> "S", "VAR"=>"ShowScripts"), + "FAIvariable" => array("IMG"=> "images/fai_variable.png", "NAME"=>_("Variables") , "KZL"=> "V", "VAR"=>"ShowVariables"), + "FAIhook" => array("IMG"=> "images/fai_hook.png", "NAME"=>_("Hooks"), "KZL"=> "H", "VAR"=>"ShowHooks"), + "FAIprofile" => array("IMG"=> "images/fai_profile.png", "NAME"=>_("Profile") , "KZL"=> "P", "VAR"=>"ShowProfiles"), + "FAItemplate" => array("IMG"=> "images/fai_template.png", "NAME"=>_("Templates") , "KZL"=> "T", "VAR"=>"ShowTemplates")); + + $editlink ="%NAME%"; + + /* Dynamic action col, depending on snapshot icons */ + $action_col_size = 80; +# if($this->parent->snapshotEnabled()){ +# $action_col_size += 32; +# } + + /******************** + Attach objects + ********************/ + + $cnts = array(); + foreach($objects as $key => $data){ + $cnts[$key] = 0; + } + + foreach($list as $key => $value){ + $info = ""; + $img = ""; + $type = $value['type']; + $abort =false; + + $cnts[$type] ++; + + if(isset($objects[$type])){ + $img = "".$objects[$type]["; + $info = $objects[$type]['NAME']; + $var = $objects[$type]['VAR']; + }else{ + $img = ""; + $info = ""; + $var = ""; + } + + if((isset($value['description']))&&(!empty($value['description']))){ + $desc= " [".$value['description']."]"; + }else{ + $desc= ""; + } + + /* Add copy & cut icons */ + $ui = get_userinfo(); + $action =""; + $acl_all = $ui->has_complete_category_acls($this->selectedBase,$this->module); + if(preg_match("/(c.*w|w.*c)/",$acl_all) && $this->parent->CopyPasteHandler){ + $action .= " "; + $action.= " "; + } + + if($value['FAIstate'] == "freeze"){ + $action.= "F"; + $action.= ""; + }else{ + $action.= ""; + +# if(preg_match("/(c)/",$value['acl']) && preg_match("/(w)/",$value['acl'])){ +# $action.= $this->GetSnapShotActions($value['dn']);; +# } + + if(preg_match("/d/",$value['acl'])){ + $action.= ""; + } + } + + /* Cutted objects should be displayed in light grey */ + $display = $value['cn'].$desc; + if($this->parent->CopyPasteHandler){ + foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){ + if($queue_data['dn'] == $value['dn']) { + $display = "".$display.""; + break; + } + } + } + $edi = $editlink; + $acti = $action; + + /* Create each field */ + $field0 = array("string" => "" , + "attach" => "style='width:20px;'"); + $field1 = array("string" => $img , "attach" => "style='text-align:center;width:20px;'"); + $field2 = array("string" => preg_replace(array("/%KEY%/","/%NAME%/","/%TITLE%/"),array($key,$display,preg_replace('/ /', ' ', @LDAP::fix($value['dn']))),$edi) , "attach" => "style=''"); + $field3 = array("string" => $info, "attach" => "style='width:200px;'"); + $field4 = array("string" => preg_replace("/%KEY%/",$key,$acti) , "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'"); + $this->AddElement(array($field0,$field1,$field2,$field3,$field4)); + } + + /* Create summary string for list footer */ + $num_deps=0; + if(!$this->SubSearch){ + $num_deps = count($this->Added_Departments); + } + + $profile_str = _("Number of listed profiles"); + $partition_str = _("Number of listed partitions"); + $script_str = _("Number of listed scripts"); + $hook_str = _("Number of listed hooks"); + $variable_str = _("Number of listed variables"); + $template_str = _("Number of listed templates"); + $package_str = _("Number of listed packages"); + $dep_str = _("Number of listed departments"); + + $str = "".$profile_str." ".$cnts['FAIprofile']."    "; + $str.= "".$partition_str." ".$cnts['FAIpartitionTable']."    "; + $str.= "".$script_str." ".$cnts['FAIscript']."    "; + $str.= "".$hook_str." ".$cnts['FAIhook']."    "; + $str.= "".$variable_str." ".$cnts['FAIvariable']."    "; + $str.= "".$template_str." ".$cnts['FAItemplate']."    "; + $str.= "".$package_str." ".$cnts['FAIpackageList']."    "; + $str.= "".$dep_str." ".$num_deps."    "; + $this->set_List_Bottom_Info($str); + } + + function Save() + { + MultiSelectWindow::Save(); + } + + function save_object() + { + /* Save automatic created POSTs like regex, checkboxes */ + MultiSelectWindow::save_object(); + $faifilter = session::get('faifilter'); + $faifilter['branch'] = $this->selectedBranch; + session::set('faifilter',$faifilter); + } +} +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/gosa-plugins/fai/admin/fai/class_faiHook.inc b/gosa-plugins/fai/admin/fai/class_faiHook.inc new file mode 100644 index 000000000..fb64e5d3c --- /dev/null +++ b/gosa-plugins/fai/admin/fai/class_faiHook.inc @@ -0,0 +1,595 @@ + "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"); + + /* ObjectClasses for this Object*/ + var $objectclasses = array("top","FAIclass","FAIhook"); + + /* Class name of the Ldap ObjectClass for the Sub Object */ + var $subClass = "FAIhookEntry"; + var $subClasses = array("top","FAIclass","FAIhookEntry"); + + /* Class name of the php class which allows us to edit a Sub Object */ + var $subClassName = "faiHookEntry"; + + /* Attributes to initialise for each subObject */ + var $subAttributes = array("cn","description","FAItask"); + var $sub_Load_Later = array("FAIscript"); + var $sub64coded = array(); + var $subBinary = array("FAIscript"); + + /* 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 $SubObjects = array(); // All leafobjects of this object + var $view_logged = FALSE; + var $FAIstate = ""; + var $ui; + + function faiHook (&$config, $dn= NULL) + { + /* Load Attributes */ + plugin::plugin ($config, $dn); + + /* If "dn==new" we try to create a new entry + * Else we must read all objects from ldap which belong to this entry. + */ + if($dn != "new"){ + $this->dn =$dn; + + /* Get FAIstate + */ + if(isset($this->attrs['FAIstate'][0])){ + $this->FAIstate = $this->attrs['FAIstate'][0]; + } + + /* Read all leaf objects of this object (For FAIscript this would be FAIscriptEntry) + */ + $ldap = $this->config->get_ldap_link(); + $ldap->cd ($this->dn); + $attrs_to_search = $this->subAttributes; + $attrs_to_search[] = "FAIstate"; + $ldap->search("(&(objectClass=FAIclass)(objectClass=".$this->subClass."))", $attrs_to_search); + + while($object = $ldap->fetch()){ + + /* Skip objects, that are tagged as removed */ + if(isset($object['FAIstate'][0])){ + if(preg_match("/removed$/",$object['FAIstate'][0])){ + continue; + } + } + + /* Set status for save management */ + $objects = array(); + $objects['status'] = "FreshLoaded"; + $objects['dn'] = $object['dn']; + $objects = $this->get_object_attributes($objects,$this->subAttributes); + $this->SubObjects[$objects['cn']] = $objects; + } + } + $this->ui = get_userinfo(); + } + + + /* Reload some attributes */ + function get_object_attributes($object,$attributes) + { + $ldap = $this->config->get_ldap_link(); + $ldap->cd($this->config->current['BASE']); + $ldap->cat($object['dn'],$attributes); + $tmp = $ldap->fetch(); + + foreach($attributes as $attrs){ + if(isset($tmp[$attrs][0])){ + $var = $tmp[$attrs][0]; + + /* Check if we must decode some attributes */ + if(in_array_ics($attrs,$this->sub64coded)){ + $var = base64_decode($var); + } + + /* check if this is a binary entry */ + if(in_array_ics($attrs,$this->subBinary)){ + $var = $ldap->get_attribute($object['dn'], $attrs,$r_array=0); + } + + /* Fix slashes */ + $var = addslashes($var); + $object[$attrs] = $var; + } + } + return($object); + } + + + function acl_base_for_current_object($dn) + { + if($dn == "new"){ + if($this->dn == "new"){ + $dn = session::get('CurrentMainBase'); + }else{ + $dn = $this->dn; + } + } + return($dn); + } + + + function getUsedFAItask($cn) + { + $ret = array(); + foreach($this->SubObjects as $name => $class){ + if($class['cn'] == $cn){ + continue; + } + if($class['status'] != "delete"){ + $ret[$class['FAItask']] = $class['FAItask']; + } + } + return($ret); + } + + function execute() + { + /* Call parent execute */ + plugin::execute(); + + if($this->is_account && !$this->view_logged){ + $this->view_logged = TRUE; + new log("view","fai/".get_class($this),$this->dn); + } + + /* Fill templating stuff */ + $smarty= get_smarty(); + $display= ""; + + /* New Listhandling + */ + $once = true; + foreach($_POST as $name => $value){ + if(preg_match("/^editscript_/",$name)&&($once)){ + $once = false; + $entry = preg_replace("/^editscript_/","",$name); + $entry = base64_decode(preg_replace("/_.*/","",$entry)); + + $obj = $this->SubObjects[$entry]; + if($obj['status'] == "FreshLoaded"){ + $obj = $this->get_object_attributes($obj,$this->sub_Load_Later); + } + + $this->dialog= new $this->subClassName($this->config,$this->dn,$obj); + $this->dialog->set_acl_base($this->acl_base_for_current_object($obj['dn'])); + $this->dialog->set_acl_category("fai"); + + session::set('objectinfo',$obj['dn']); + $this->dialog->parent = &$this; + $this->is_dialog=true; + } + if(preg_match("/^deletescript_/",$name)&&($once)){ + $entry = preg_replace("/^deletescript_/","",$name); + $entry = base64_decode(preg_replace("/_.*/","",$entry)); + + $dn = $this->acl_base_for_current_object($this->SubObjects[$entry]['dn']); + $acl = $this->ui -> get_permissions($dn,"fai/faiScriptEntry") ; + + if(preg_match("/d/",$acl)){ + $once = false; + + $status = $this->SubObjects[$entry]['status']; + if($status == "edited" || $status == "FreshLoaded"){ + $this->SubObjects[$entry]['status']= "delete"; + }else{ + unset($this->SubObjects[$entry]); + } + } + } + } + + /* Edit entries via GET */ + if(isset($_GET['act']) && isset($_GET['id'])){ + if($_GET['act'] == "edit" && isset($this->SubObjects[$_GET['id']])){ + $obj = $this->SubObjects[$_GET['id']]; + if($obj['status'] == "FreshLoaded"){ + $obj = $this->get_object_attributes($obj,$this->sub_Load_Later); + } + $this->dialog= new $this->subClassName($this->config,$this->dn,$obj); + $this->dialog->acl = $this->acl; + session::set('objectinfo',$obj['dn']); + $this->dialog->parent = &$this; + $this->is_dialog=true; + } + } + + ///// Ende new list handling + + /* Add new sub object */ + if(isset($_POST['AddSubObject'])){ + + $c_dn = $this->acl_base_for_current_object($this->dn); + $this->dialog= new $this->subClassName($this->config,"new"); + $this->dialog->set_acl_base($c_dn); + $this->dialog->set_acl_category("fai"); + $this->dialog->parent = &$this; + $this->is_dialog=true; + } + + + /* Save Dialog */ + if(isset($_POST['SaveSubObject'])){ + + /* Perform post check*/ + $this->dialog->save_object(); + + /* Get messages */ + $msgs = $this->dialog->check(); + + /* print errors */ + if(count($msgs)>0){ + foreach($msgs as $msg){ + print_red($msg); + } + }else{ + + /* Get return object */ + $obj = $this->dialog->save(); + if(isset($obj['remove'])){ + + $old_stat = $this->SubObjects[$obj['remove']['from']]['status']; + + /* Depending on status, set new status */ + if($old_stat == "edited" || $old_stat == "FreshLoaded"){ + $this->SubObjects[$obj['remove']['from']]['status'] = "delete"; + }elseif($this->SubObjects[$obj['remove']['from']]['status']=="new"){ + unset($this->SubObjects[$obj['remove']['from']]); + } + $obj['status'] = "new"; + $this->SubObjects[$obj['remove']['to']] = $obj; + unset($this->SubObjects[$obj['remove']['to']]['remove']); + }else{ + if($obj['status'] == "FreshLoaded"){ + $obj['status'] = "edited"; + } + $this->SubObjects[$obj['cn']]=$obj; + } + $this->is_dialog=false; + unset($this->dialog); + $this->dialog=FALSE; + } + } + + /* Sort entries */ + $tmp = $keys = array(); + foreach($this->SubObjects as $key => $entry){ + $keys[$key]=$key; + } + natcasesort($keys); + foreach($keys as $key){ + $tmp[$key]=$this->SubObjects[$key]; + } + $this->SubObjects = $tmp; + + /* Cancel Dialog */ + if(isset($_POST['CancelSubObject'])){ + $this->is_dialog=false; + unset($this->dialog); + $this->dialog=FALSE; + } + + /* Print dialog if $this->dialog is set */ + if(is_object($this->dialog)){ + $this->dialog->save_object(); + $display = $this->dialog->execute(); + return($display); + } + + + + /* Divlist added 28.02.2006 + Containing FAIscripts + */ + + $divlist = new divSelectBox("FAIhooks"); + $divlist->setHeight(400); + + foreach($this->getList(true) as $key => $name){ + + $dn= $this->acl_base_for_current_object($name['dn']); + $acl = $this->ui->get_permissions($dn,"fai/faiHookEntry") ; + $act = ""; + + /* Check if this object is freezed, in this case hide the delete icon */ + if($this->FAIstate == "freeze"){ + $act .= ""; + }else{ + $act .= ""; + if(preg_match("/d/",$acl)){ + $act .=""; + } + } + + /* Check if we are allowed to use the export button for this object */ + $s_acl = $this->ui->get_permissions($dn,"fai/faiHookEntry","FAIscript") ; + if(($this->SubObjects[$key]['status'] == "new") || ($this->SubObjects[$key]['dn'] == "new") || !preg_match("/r/",$s_acl)){ + $down = ""; + }else{ + $down = " + "._("Download")." + "; + } + + /* Check if we are allowed to view the object */ + $s_acl = $this->ui->get_permissions($dn,"fai/faiHookEntry","cn") ; + if(preg_match("/r/",$s_acl)){ + + $edit_link = "".$name['name'].""; + $divlist->AddEntry(array( array("string"=>$edit_link), + array("string"=>$down , "attach" => "style='width:20px;'"), + array("string"=>str_replace("%s",base64_encode($key),$act), + "attach"=>"style='border-right: 0px;width:50px;text-align:right;'"))); + } + } + $smarty->assign("Entry_divlist",$divlist->DrawList()); + /* Divlist creation complete + */ + + $smarty->assign("SubObjects",$this->getList()); + + /* 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){ + if(get_magic_quotes_gpc()){ + $smarty->assign($attrs,stripslashes($this->$attrs)); + }else{ + $smarty->assign($attrs,($this->$attrs)); + } + } + + $tmp = $this->plInfo(); + + $c_dn = $this->acl_base_for_current_object($this->dn); + $smarty->assign("sub_object_is_addable", preg_match("/c/",$this->ui->get_permissions($c_dn,"fai/faiHookEntry")) && $this->FAIstate!="freeze"); + foreach($tmp['plProvidedAcls'] as $name => $translation){ + $smarty->assign($name."ACL",$this->getacl($name)); + } + + $display.= $smarty->fetch(get_template_path('faiHook.tpl', TRUE)); + return($display); + } + + /* Generate listbox friendly SubObject list + */ + function getList($use_dns=false){ + $a_return=array(); + foreach($this->SubObjects as $obj){ + if($obj['status'] != "delete"){ + if($use_dns){ + if((isset($obj['description']))&&(!empty($obj['description']))){ + $a_return[$obj['cn']]['name']= $obj['cn']." [".stripslashes($obj['description'])."]"; + }else{ + $a_return[$obj['cn']]['name']= $obj['cn']; + } + $a_return[$obj['cn']]['dn']= $obj['dn']; + }else{ + if((isset($obj['description']))&&(!empty($obj['description']))){ + $a_return[$obj['cn']]= $obj['cn']." [".stripslashes($obj['description'])."]"; + }else{ + $a_return[$obj['cn']]= $obj['cn']; + } + } + } + } + return($a_return); + } + + + /* Delete me, and all my subtrees + */ + function remove_from_parent() + { + $ldap = $this->config->get_ldap_link(); + $ldap->cd ($this->dn); + + $faifilter = session::get('faifilter'); + $use_dn = preg_replace("/".normalizePreg(FAI::get_release_dn($this->dn))."/i", $faifilter['branch'], $this->dn); + if($faifilter['branch'] == "main"){ + $use_dn = $this->dn; + } + + FAI::prepare_to_save_FAI_object($use_dn,array(),true); + + new log("remove","fai/".get_class($this),$use_dn,$this->attributes); + + foreach($this->SubObjects as $name => $obj){ + $use_dn = preg_replace("/".normalizePreg(FAI::get_release_dn($this->dn))."/i", $faifilter['branch'], $obj['dn']); + if($faifilter['branch'] == "main"){ + $use_dn = $obj['dn']; + } + FAI::prepare_to_save_FAI_object($use_dn,array(),true); + } + $this->handle_post_events("remove"); + } + + + /* Save data to object + */ + function save_object() + { + if((isset($_POST['FAIhook_posted'])) && ($this->FAIstate != "freeze")){ + plugin::save_object(); + foreach($this->attributes as $attrs){ + if(isset($_POST[$attrs])){ + $this->$attrs = $_POST[$attrs]; + } + } + } + } + + + /* Check supplied data */ + function check() + { + /* Call common method to give check the hook */ + $message= plugin::check(); + + return ($message); + } + + + /* Save to LDAP */ + function save() + { + plugin::save(); + + $ldap = $this->config->get_ldap_link(); + + FAI::prepare_to_save_FAI_object($this->dn,$this->attrs); + show_ldap_error($ldap->get_error(), sprintf(_("Saving of FAI/hook with dn '%s' failed."),$this->dn)); + + if($this->initially_was_account){ + new log("modify","fai/".get_class($this),$this->dn,$this->attributes); + }else{ + new log("create","fai/".get_class($this),$this->dn,$this->attributes); + } + + $ldap->cd($this->dn); + + /* Prepare FAIscriptEntry to write it to ldap + * First sort array. + * Because we must delete old entries first. + * After deletion, we perform add and modify + */ + $Objects = array(); + + /* We do not need to save untouched objects */ + foreach($this->SubObjects as $name => $obj){ + if($obj['status'] == "FreshLoaded"){ + unset($this->SubObjects[$name]); + } + } + + foreach($this->SubObjects as $name => $obj){ + if($obj['status'] == "delete"){ + $Objects[$name] = $obj; + } + } + foreach($this->SubObjects as $name => $obj){ + if($obj['status'] != "delete"){ + $Objects[$name] = $obj; + } + } + + foreach($Objects as $name => $obj){ + + foreach($this->sub64coded as $codeIt){ + $obj[$codeIt]=base64_encode(stripslashes($obj[$codeIt])); + } + + $tmp = array(); + $attributes = array_merge($this->sub_Load_Later,$this->subAttributes); + foreach($attributes as $attrs){ + if(empty($obj[$attrs])){ + $obj[$attrs] = array(); + } + if(!is_array($obj[$attrs])){ + $tmp[$attrs] = stripslashes($obj[$attrs]); + }else{ + $tmp[$attrs] = $obj[$attrs]; + } + } + + $tmp['objectClass'] = $this->subClasses; + + $sub_dn = "cn=".$obj['cn'].",".$this->dn; + + if($obj['status']=="new"){ + $ldap->cat($sub_dn,array("objectClass")); + if($ldap->count()){ + $obj['status']="edited"; + } + } + + /* Tag object */ + $this->tag_attrs(&$tmp, $sub_dn, $this->gosaUnitTag); + + if($obj['status'] == "delete"){ + FAI::prepare_to_save_FAI_object($sub_dn,array(),true); + $this->handle_post_events("remove"); + }elseif($obj['status'] == "edited"){ + FAI::prepare_to_save_FAI_object($sub_dn,$tmp); + $this->handle_post_events("modify"); + }elseif($obj['status']=="new"){ + FAI::prepare_to_save_FAI_object($sub_dn,$tmp); + $this->handle_post_events("add"); + } + } + } + + + function PrepareForCopyPaste($source) + { + plugin::PrepareForCopyPaste($source); + + /* Read all leaf objects of this object (For FAIscript this would be FAIscriptEntry) + */ + $ldap = $this->config->get_ldap_link(); + $ldap->cd ($source['dn']); + + $attrs_to_search = $this->subAttributes; + $attrs_to_search[] = "FAIstate"; + $ldap->search("(&(objectClass=FAIclass)(objectClass=".$this->subClass."))",$attrs_to_search); + + while($object = $ldap->fetch()){ + + /* Skip objects, that are tagged as removed */ + if(isset($object['FAIstate'][0])){ + if(preg_match("/removed$/",$object['FAIstate'][0])){ + continue; + } + } + + /* Set status for save management */ + $objects = array(); + $objects['status'] = "edited"; + $objects['dn'] = $object['dn']; + $objects = $this->get_object_attributes($objects,$this->subAttributes); + $objects = $this->get_object_attributes($objects,$this->sub_Load_Later); + + $this->SubObjects[$objects['cn']] = $objects; + } + } + + + /* Return plugin informations for acl handling */ + static function plInfo() + { + return (array( + "plShortName" => _("Hook"), + "plDescription" => _("FAI hook"), + "plSelfModify" => FALSE, + "plDepends" => array(), + "plPriority" => 20, + "plSection" => array("administration"), + "plCategory" => array("fai"), + "plProvidedAcls" => array( + "cn" => _("Name")." ("._("Read only").")", + "description" => _("Description")) + )); + } +} + +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/gosa-plugins/fai/admin/fai/class_faiHookEntry.inc b/gosa-plugins/fai/admin/fai/class_faiHookEntry.inc new file mode 100644 index 000000000..cab96dbf2 --- /dev/null +++ b/gosa-plugins/fai/admin/fai/class_faiHookEntry.inc @@ -0,0 +1,206 @@ + "Eins ist toll", "zwei" => "Zwei ist noch besser"); + + /* attribute list for save action */ + var $ignore_account= TRUE; + var $attributes = array("cn","description","FAIscript","FAItask"); + var $objectclasses= array(); + + var $orig_cn = ""; + var $tasks = array("chboot", "configure", "debconf", "extrbase", "faiend", "finish", + "install", "instsoft", "mirror", "mountdisks", "partition", "prepareapt", + "savelog", "softupdate", "sysinfo","updatebase", "error"); + var $dn = ""; + var $cn = ""; + var $FAItask = "chboot"; + var $FAIscript = ""; + var $description = ""; + var $status = "new"; + var $parent = NULL; + var $FAIstate = ""; + + function faiHookEntry (&$config, $dn= NULL,$object=false) + { + plugin::plugin ($config, $dn); + if($dn != "new"){ + $this->orig_cn= $object['cn']; + $this->dn=$object['dn']; + foreach($object as $name=>$value){ + $oname = $name; + $this->$oname=$value; + } + + if(isset($this->attrs['FAIstate'][0])){ + $this->FAIstate = $this->attrs['FAIstate'][0]; + } + + }elseif(is_array($object)){ + if(count($object)){ + $this->orig_cn= $object['cn']; + $this->dn=$object['dn']; + foreach($object as $name=>$value){ + $oname = $name; + $this->$oname=$value; + } + }else{ + + $this->status = "new"; + $this->orig_cn = false; + } + } + } + + + function execute() + { + /* Call parent execute */ + plugin::execute(); + + /* Fill templating stuff */ + $smarty = get_smarty(); + $display = ""; + + if(isset($_POST['ImportUpload'])){ + if(($_FILES['ImportFile']['error']!=0)){ + print_red(_("Please select a valid file.")); + }else + if(($_FILES['ImportFile']['size']==0)){ + print_red(_("Selected file is empty.")); + }else{ + $str = utf8_encode(file_get_contents($_FILES['ImportFile']['tmp_name'])); + $this->FAIscript = $str; + } + } + + /* Create download button*/ + if($this->dn != "new" && $this->acl_is_readable("FAIscript")){ + $smarty->assign("DownMe"," + "._("Download")." + "); + }else{ + $smarty->assign("DownMe",""); + } + + $used_tasks = $this->parent->getUsedFAItask($this->cn); + $tasks = $this->tasks; + foreach($this->tasks as $id => $task){ + if(in_array($task,$used_tasks)){ + unset($tasks[$id]); + } + } + $smarty->assign("tasks", $tasks); + + /* 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){ + if(get_magic_quotes_gpc()){ + $smarty->assign($attrs,(stripslashes($this->$attrs))); + }else{ + $smarty->assign($attrs,($this->$attrs)); + } + } + + $tmp = $this->plInfo(); + foreach($tmp['plProvidedAcls'] as $name => $translated){ + $acl = $this->getacl($name); + if($this->FAIstate == "freezed"){ + $acl = preg_replace("/w/","",$acl); + } + $smarty->assign($name."ACL",$acl); + } + + if(get_magic_quotes_gpc()){ + $smarty->assign("FAIscript" , htmlentities(stripslashes($this->FAIscript))); + }else{ + $smarty->assign("FAIscript" , htmlentities($this->FAIscript)); + } + $display.= $smarty->fetch(get_template_path('faiHookEntry.tpl', TRUE)); + return($display); + } + + /* Save data to object */ + function save_object() + { + if((isset($_POST['SubObjectFormSubmitted'])) && ($this->FAIstate != "freeze")){ + foreach($this->attributes as $attrs){ + if($this->acl_is_writeable($attrs)){ + if(isset($_POST[$attrs])){ + $this->$attrs = $_POST[$attrs]; + }else{ + $this->$attrs = ""; + } + } + } + } + } + + /* Check supplied data */ + function check() + { + /* Call common method to give check the hook */ + $message= plugin::check(); + + if(isset($this->parent->SubObjects[$this->cn]) && $this->cn != $this->orig_cn){ + $message[] =_("There is already a hook with the given name."); + } + + if(empty($this->FAIscript)) { + $message[]=_("Please enter a value for script."); + } + + if(empty($this->cn)){ + $message[] = _("Please enter a name."); + } + + return ($message); + } + + function save() + { + $tmp=array(); + foreach($this->attributes as $attrs){ + $tmp[$attrs] = $this->$attrs; + } + + /* Strip out dos newlines */ + $tmp['FAIscript']= strtr($this->FAIscript, array("\x0D" => "")); + + if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){ + $tmp['remove']['from'] = $this->orig_cn; + $tmp['remove']['to'] = $tmp['cn']; + } + + $tmp['dn'] = $this->dn; + $tmp['status'] = $this->status; + return($tmp); + } + + /* Return plugin informations for acl handling */ + static function plInfo() + { + return (array( + "plShortName" => _("Hook entry"), + "plDescription" => _("FAI hook entry"), + "plSelfModify" => FALSE, + "plDepends" => array(), + "plPriority" => 21, + "plSection" => array("administration"), + "plCategory" => array("fai"), + "plProvidedAcls" => array( + "cn" => _("Name"), + "description" => _("Description"), + "FAItask" => _("Task"), + "FAIscript" => _("FAI script")) + )); + } + +} +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/gosa-plugins/fai/admin/fai/class_faiManagement.inc b/gosa-plugins/fai/admin/fai/class_faiManagement.inc new file mode 100644 index 000000000..2bf246655 --- /dev/null +++ b/gosa-plugins/fai/admin/fai/class_faiManagement.inc @@ -0,0 +1,1162 @@ + "Eins ist toll", "zwei" => "Zwei ist noch besser"); + + /* Headpage attributes */ + var $lock_type = ""; // should be branch/freeze + var $lock_name = ""; + var $lock_dn = ""; + + /* attribute list for save action */ + var $attributes = array("lock_type","lock_name","lock_dn"); // Attributes Managed by this plugin + 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; + + var $dispNewBranch= false; + var $dispNewFreeze= false; + + var $DivListFai; + var $start_pasting_copied_objects = FALSE; + var $CopyPasteHandler = FALSE; + var $base = ""; + + /* construction/reconstruction + */ + function faiManagement (&$config, $ui) + { + /* Set defaults */ + $this->dn = ""; + $this->config = $config; + $this->ui = $ui; + + /* Creat dialog object */ + $this->DivListFai = new divListFai($this->config,$this); + + /* Copy & Paste handler */ + if ($this->config->boolValueIsTrue("main", "enableCopyPaste")){ + $this->CopyPasteHandler= new CopyPasteHandler($this->config); + } + } + + function execute() + { + /* Call parent execute */ + plugin::execute(); + + /* Initialise vars and smarty */ + $smarty = get_smarty(); + $smarty->assign("BranchName",""); + + $display = ""; + $s_action = ""; + $s_entry = ""; + + /* If an entry was locked, these vars will be stored in a session to allow direct edit */ + session::set('LOCK_VARS_TO_USE',array("/^edit_entry$/","/^id$/","/^entry_edit_/","/^entry_delete_/","/^item_selected/","/^remove_multiple_fai_objects/")); + + + /**************** + Handle posts + ****************/ + + /* Check ImageButton posts + * Create new tab ich new_xx is posted + */ + $posts = array( "/remove_branch/"=>"remove_branch", "/branch_branch/"=>"branch_branch", + "/freeze_branch/"=>"freeze_branch", "/create_partition/i"=>"new_partition", + "/create_script/i"=>"new_script", "/create_hook/i"=>"new_hook", + "/create_variable/i"=>"new_variable", "/create_template/i"=>"new_template", + "/create_package/i"=>"new_package", "/create_profile/i"=>"new_profile", + "/edit_continue/"=>"select_class_name_finished", + "/^multiple_copy_fai/" => "copy_multiple", + "/^multiple_cut_fai/" => "cut_multiple", + "/^copy/" => "copy", + "/^cut/" => "cut", + "/^remove_multiple_fai_objects/" => "del_multiple"); + + foreach($_POST as $name => $value){ + foreach($posts as $reg => $act ){ + if(preg_match($reg,$name)){ + $s_action = $act; + $s_entry = ltrim(preg_replace($reg,"",$name),"_"); + $s_entry = preg_replace("/_.*$/","",$s_entry); + } + } + if(preg_match("/^entry_edit_.*/",$name)){ + $s_entry = preg_replace("/^entry_edit_/","",$name); + $s_entry = preg_replace("/_.*$/","",$s_entry); + $s_action = "edit"; + }elseif(preg_match("/^entry_delete_.*/",$name)){ + $s_entry = preg_replace("/^entry_delete_/","",$name); + $s_entry = preg_replace("/_.*$/","",$s_entry); + $s_action = "delete"; + } + } + + if(isset($_GET['edit_entry'])){ + $s_entry = $_GET['edit_entry']; + $s_action = "edit"; + } + + if(isset($_GET['act']) && $_GET['act'] == "freeze_branch"){ + $s_action = "freeze_branch"; + } + if(isset($_GET['act']) && $_GET['act'] == "branch_branch"){ + $s_action = "branch_branch"; + } + if(isset($_GET['act']) && $_GET['act'] == "remove_branch"){ + $s_action = "remove_branch"; + } + + if((isset($_POST['CancelBranchName'])) || (isset($_POST['CloseIFrame']))){ + $this->dispNewBranch = false; + $this->dispNewFreeze = false; + } + + + $type_acl_mapping = array( + "FAIpartitionTable" => "faiPartitionTable", + "FAIpackageList" => "faiPackage", + "FAIscript" => "faiScript", + "FAIvariable" => "faiVariable", + "FAIhook" => "faiHook", + "FAIprofile" => "faiProfile", + "FAItemplate" => "faiTemplate"); + + + /* handle C&P from layers menu */ + if(isset($_POST['menu_action']) && preg_match("/^multiple_copy_systems/",$_POST['menu_action'])){ + $s_action = "copy_multiple"; + } + if(isset($_POST['menu_action']) && preg_match("/^multiple_cut_systems/",$_POST['menu_action'])){ + $s_action = "cut_multiple"; + } + if(isset($_POST['menu_action']) && preg_match("/^editPaste/",$_POST['menu_action'])){ + $s_action = "editPaste"; + } + + /* Create options */ + if(isset($_POST['menu_action']) && preg_match("/^Create_/",$_POST['menu_action'])){ + $s_action = "new_".preg_replace("/^Create_/","",$_POST['menu_action']);; + $s_entry = preg_replace("/^Create_/","",$_POST['menu_action']); + } + + /* handle remove from layers menu */ + if(isset($_POST['menu_action']) && preg_match("/^remove_multiple/",$_POST['menu_action'])){ + $s_action = "del_multiple"; + } + + /******************** + Copy & Paste + ********************/ + + /* Display the copy & paste dialog, if it is currently open */ + $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry); + if($ret){ + return($ret); + } + + + /**************** + Delete confirme dialog + ****************/ + + if ($s_action=="delete"){ + + /* Get 'dn' from posted termlinst */ + $this->dn= $this->objects[$s_entry]['dn']; + + /* Load permissions for selected 'dn' and check if + we're allowed to remove this 'dn' */ + $acl = $this->ui->get_permissions($this->dn,"fai/".$type_acl_mapping[$this->objects[$s_entry]['type']]); + if(preg_match("/d/",$acl)){ + + /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */ + if (($user= get_lock($this->dn)) != ""){ + return(gen_locked_message ($user, $this->dn)); + } + + /* Lock the current entry, so nobody will edit it during deletion */ + add_lock ($this->dn, $this->ui->dn); + $smarty->assign("warning", sprintf(_("You're about to delete all information about the FAI class at '%s'."), @LDAP::fix($this->dn))); + $smarty->assign("multiple", false); + return($smarty->fetch(get_template_path('remove.tpl', TRUE))); + } else { + + /* Obviously the user isn't allowed to delete. Show message and + clean session. */ + print_red (_("You are not allowed to delete this component!")); + } + } + + + /******************** + Delete MULTIPLE entries requested, display confirm dialog + ********************/ + + if ($s_action=="del_multiple"){ + $this->dns = array(); + $ids = $this->list_get_selected_items(); + + if(count($ids)){ + + foreach($ids as $id){ + $dn = $this->objects[$id]['dn']; + if (($user= get_lock($dn)) != ""){ + return(gen_locked_message ($user, $dn)); + } + $this->dns[$id] = $dn; + } + + $dns_names = "
";
+        foreach($this->dns as $dn){
+          add_lock ($dn, $this->ui->dn);
+          $dns_names .= $dn."\n";
+        }
+        $dns_names .="
"; + + /* Lock the current entry, so nobody will edit it during deletion */ + if (count($this->dns) == 1){ + $smarty->assign("warning", sprintf(_("You're about to delete the following entry %s"), @LDAP::fix($dns_names))); + } else { + $smarty->assign("warning", sprintf(_("You're about to delete the following entries %s"), @LDAP::fix($dns_names))); + } + $smarty->assign("multiple", true); + return($smarty->fetch(get_template_path('remove.tpl', TRUE))); + } + } + + + /******************** + Delete MULTIPLE entries confirmed + ********************/ + + /* Confirmation for deletion has been passed. Users should be deleted. */ + if (isset($_POST['delete_multiple_fai_object_confirm'])){ + + /* Find out more about the object type */ + $ldap = $this->config->get_ldap_link(); + + /* Remove user by user and check acls before removeing them */ + foreach($this->dns as $key => $dn){ + + $ldap->cat($dn, array('objectClass')); + $attrs = $ldap->fetch(); + $type = $this->get_type($attrs); + + $acl = $this->ui->get_permissions($dn,"fai/".$type[1]); + if(preg_match("/d/",$acl)){ + + $this->dialog = new $type[0]($this->config, $this->config->data['TABS'][$type[2]], $dn,"fai"); + $this->dialog->set_acl_base($dn); + $this->dialog->by_object[$type[1]]->remove_from_parent (); + unset ($this->dialog); + $this->dialog= FALSE; + $to_del = FAI::clean_up_releases($dn); + FAI::save_release_changes_now(); + + foreach($to_del as $dn){ + $ldap->rmdir_recursive($dn); + } + + } else { + + /* Normally this shouldn't be reached, send some extra + logs to notify the administrator */ + print_red (_("You are not allowed to delete this component!")); + new log("security","fai/".get_class($this),$dn,array(),"Tried to trick deletion."); + } + + /* Remove lock file after successfull deletion */ + del_lock ($dn); + unset($this->dns[$key]); + } + } + + + /******************** + Delete MULTIPLE entries Canceled + ********************/ + + /* Remove lock */ + if(isset($_POST['delete_multiple_fai_object_cancel'])){ + foreach($this->dns as $key => $dn){ + del_lock ($dn); + unset($this->dns[$key]); + } + } + + + /**************** + Delete aborted + ****************/ + + /* Delete canceled? */ + if (isset($_POST['delete_cancel'])){ + del_lock ($this->dn); + } + + + /**************** + Delete confirmed + ****************/ + + /* Deltetion was confirmed, so delete this entry + */ + if (isset($_POST['delete_terminal_confirm'])){ + + /* Some nice guy may send this as POST, so we've to check + for the permissions again. */ + + /* Find out more about the object type */ + $ldap = $this->config->get_ldap_link(); + $ldap->cat($this->dn, array('objectClass')); + if($ldap->count()){ + $attrs = $ldap->fetch(); + $type = $this->get_type($attrs); + + $acl = $this->ui->get_permissions($this->dn,"fai/".$type[1]); + if(preg_match("/d/",$acl)){ + + $this->dialog = new $type[0]($this->config, $this->config->data['TABS'][$type[2]], $this->dn,"fai"); + $this->dialog->set_acl_base($this->dn); + $this->dialog->by_object[$type[1]]->remove_from_parent (); + unset ($this->dialog); + $this->dialog= FALSE; + $to_del = FAI::clean_up_releases($this->dn); + FAI::save_release_changes_now(); + + foreach($to_del as $dn){ + $ldap->rmdir_recursive($dn); + } + + } else { + + /* Normally this shouldn't be reached, send some extra + logs to notify the administrator */ + print_red (_("You are not allowed to delete this component!")); + new log("security","fai/".get_class($this),$dn,array(),"Tried to trick deletion."); + } + + }else{ + print_red(sprintf(_("Object could not be deleted '%s', object does not exist."),$this->dn)); + } + /* Remove lock file after successfull deletion */ + del_lock ($this->dn); + } + + + /**************** + Edit entry + ****************/ + + if(($s_action == "edit") && (!isset($this->dialog->config))){ + $entry = $this->objects[$s_entry]; + $a_setup = $this->get_type($entry); + $this->dn = $entry['dn']; + + /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */ + if (($user= get_lock($this->dn)) != ""){ + return(gen_locked_message ($user, $this->dn)); + } + add_lock ($this->dn, $this->ui->dn); + + $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai"); + $this->dialog->set_acl_base($this->dn); + $this->is_dialog = true; + + if($entry['FAIstate'] == "freeze"){ + #$this->dialog->set_acl(array("*none*")) ; + } + session::set('objectinfo',$this->dn); + } + + + /* Branch handling + 09.01.2006 + */ + + /**************** + Remove branch + ****************/ + + /* Remove branch + */ + if($s_action == "remove_branch"){ + $base= $this->DivListFai->selectedBranch; + + /* Check if we have a post remove method configured + * else skip this operation. (Skip:Button in the ui should be disabled in this case too) + */ + if("" != $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'))){ + /* Load permissions for selected 'dn' and check if + we're allowed to remove this 'dn' */ + if($this->acl_is_removeable()){ + + $smarty->assign("info", sprintf(_("You're about to delete a fai branch / freeze '%s'."), $this->DivListFai->selectedBranch)); + return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE))); + } else { + print_red (_("You are not allowed to delete this release!")); + } + } + } + + + /**************** + Remove branch confirmed + ****************/ + + if(isset($_POST['delete_branch_confirm'])){ + + /* Check if we have a post remove method configured + * else skip this operation. (Skip:Button in the ui should be disabled in this case too) + */ + if("" != $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'))){ + + $bb = $this->DivListFai->selectedBranch; + if(!isset($ldap)){ + $ldap = $this->config->get_ldap_link(); + } + + $br = $this->getBranches(); + + if(isset($br[$bb]) && $this->acl_is_removeable()){ + $name = $br[$bb]; + $ldap->cd($bb); + $ldap->recursive_remove(); + $ldap->cd(preg_replace('/,'.normalizePreg(get_ou('faiou')).'/', ','.get_ou('applicationou'), $bb)); + $ldap->recursive_remove(); + $this->DivListFai->selectedBranch = "main"; + + /* Post remove */ + $this->lock_name = $name; + $this->lock_dn = $bb; + $this->postremove(); + + new log("remove","fai/".get_class($this),$br[$bb],array(),"Release removed"); + } + } + } + + + /**************** + Create a new branch "insert Name" + ****************/ + + if((isset($_POST['UseBranchName']))&&(($this->dispNewBranch)||($this->dispNewFreeze))){ + session::set('LASTPOST',$_POST); + + if($this->dispNewBranch){ + $type = "branch"; + }else{ + $type = "freeze"; + } + + /* Check branch name */ + $name = $_POST['BranchName']; + $is_ok = true; + $smarty->assign("BranchName",$name); + $base= get_ou('faiou').$this->DivListFai->selectedBase; + + /* Check used characters */ + if(preg_match("/[^0-9a-z \ö\ä\ü\.-_:,]/i",$name)){ + if($type == "branch"){ + print_red(_("Specified branch name is invalid.")); + }else{ + print_red(_("Specified freeze name is invalid.")); + } + $is_ok = false; + } + + /* Check if this name is already in use */ + if(!$this->CheckNewBranchName($_POST['BranchName'],$this->DivListFai->selectedBranch)){ + print_red(_("This name is already in use.")); + $is_ok = false; + } + + if($is_ok){ + + if(session::is_set('LASTPOST')){ + $LASTPOST = session::get('LASTPOST'); + }else{ + $LASTPOST = array(); + } + $LASTPOST['base'] = $base; + $LASTPOST['type'] = $type; + session::set('LASTPOST',$LASTPOST); + $smarty->assign("iframe", true); + $smarty->assign("plugID", $_GET['plug']); + $display = $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__))); + return($display); + } + } + + + /**************** + Create a new branch + ****************/ + + if(isset($_GET['PerformBranch'])){ + + if(!$this->acl_is_createable()){ + print_red(_("You are not allowed to create a new branch.")); + }else{ + + /* Create it know */ + $this->dispNewBranch = false; + $this->dispNewFreeze = false; + + $LASTPOST = session::get('LASTPOST'); + $base = $LASTPOST['base']; + $_POST = session::get('LASTPOST'); + $name = $_POST['BranchName']; + + $type = $LASTPOST['type']; + $ldap = $this->config->get_ldap_link(); + + $baseToUse = $base; + if($this->DivListFai->selectedBranch != "main" ){ + $baseToUse = $this->DivListFai->selectedBranch; + } + + /* Create new Release name to be able to set faidebianRelease for FAIpackageList */ + + $CurrentReleases = $this->getBranches(); + $NewReleaseName = $name; + if(isset($CurrentReleases[$this->DivListFai->selectedBranch])) { + if($this->DivListFai->selectedBranch != "main"){ + $NewReleaseName = $CurrentReleases[$this->DivListFai->selectedBranch]."/".$name; + $NewReleaseName = preg_replace("#\/#","/",$NewReleaseName); + }else{ + $NewReleaseName = $name; + } + } + + $appsrc = preg_replace("/".normalizePreg(get_ou('faiou'))."/",get_ou('applicationou'),$baseToUse); + $appdst = preg_replace("/".normalizePreg(get_ou('faiou'))."/",get_ou('applicationou'),"ou=".$name.",".$baseToUse) ; + + $mimesrc = preg_replace("/".normalizePreg(get_ou('faiou'))."/",get_ou('mimetypeou'),$baseToUse); + $mimedst = preg_replace("/".normalizePreg(get_ou('faiou'))."/",get_ou('mimetypeou'),"ou=".$name.",".$baseToUse) ; + + /* Check if source depeartments exist */ + foreach(array($baseToUse,$appsrc,$mimesrc) as $dep){ + $ldap->cd($this->config->current['BASE']); + $ldap->cat($dep); + if(!$ldap->count()){ + $ldap->create_missing_trees($dep); + } + } + + /* Print header to have styles included */ + echo ' + + + + + + + + '; + + new log("create","fai/".get_class($this),$NewReleaseName,array(),"New $type created"); + + /* Duplicate applications + */ + $ldap->cat($appsrc,array("dn")) ; + if($ldap->count()){ + $ldap->cd ($appdst); + $ldap->recursive_remove(); + FAI::copy_FAI_resource_recursive($appsrc,$appdst,$NewReleaseName,$type,true); + } + + /* Duplicate mime types + */ + $ldap->cat($mimesrc,array("dn")) ; + if($ldap->count()){ + $ldap->cd ($mimedst); + $ldap->recursive_remove(); + FAI::copy_FAI_resource_recursive($mimesrc,$mimedst,$NewReleaseName,$type,true); + } + + $attr = array(); + $attr['objectClass'] = array("organizationalUnit","FAIbranch"); + $attr['ou'] = $name; + $attr['FAIstate'] = $type; + $ldap->cd($this->config->current['BASE']); + $ldap->cd("ou=".$name.",".$baseToUse); + $ldap->cat("ou=".$name.",".$baseToUse); + if($ldap->count()){ + $ldap->modify($attr); + }else{ + $ldap->add($attr); + } + + /* Duplicate fai objects + */ + // $ldap->cd ("ou=".$name.",".$baseToUse); + // $ldap->recursive_remove(); + // FAI::copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,$NewReleaseName,$type,true); + + echo "
+
+
"; + + echo "" ; + + /* Print footer to have valid html */ + echo ""; + + $this->dispNewFreeze = false; + + /* Postcreate */ + + /* Assign possible attributes */ + $this->lock_type = $type; + $this->lock_name = $name; + $this->lock_dn = $baseToUse; + $this->postcreate(); + exit(); + } + } + + /**************** + Display dialog to enter new Branch name + ****************/ + + /* Check if we have a post create method configured + * else skip this operation. (Skip:Button in the ui should be disabled in this case too) + */ + if("" != $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs'))){ + if(($s_action == "branch_branch")||($this->dispNewBranch)){ + if(!$this->acl_is_createable()){ + print_red(_("You are not allowed to create a new branch.")); + }else{ + $this->dispNewBranch=true; + $smarty->assign("iframe",false); + $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__))); + return($display); + } + } + } + + + /**************** + Display dialog to enter new Freeze name + ****************/ + + /* Check if we have a post create method configured + * else skip this operation. (Skip:Button in the ui should be disabled in this case too) + */ + if("" != $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs'))){ + if(($s_action == "freeze_branch")||($this->dispNewFreeze)){ + if(!$this->acl_is_createable()){ + print_red(_("You are not allowed to create a new branch.")); + }else{ + $this->dispNewFreeze = true; + $smarty->assign("iframe",false); + $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__))); + return($display); + } + } + } + + + /**************** + Create a new object + ****************/ + + $types = array( "new_partition" => "FAIpartitionTable", + "new_script" => "FAIscript", + "new_hook" => "FAIhook", + "new_variable" => "FAIvariable", + "new_template" => "FAItemplate", + "new_package" => "FAIpackageList"); + + if(isset($types[$s_action])){ + $acl = $this->ui->get_permissions($this->DivListFai->selectedBase,"fai/".$type_acl_mapping[$types[$s_action]]); + if(preg_match("/c/",$acl)){ + $this->dialog = new askClassName($this->config,$this->dn,$this->ui,$types[$s_action]); + }else{ + print_red(sprintf(_("You are not allowed to create a new '%s' object."),$types[$s_action])); + } + } + + /* New Profile */ + if($s_action == "new_profile"){ + $this->dn = "new" ; + + $acl = $this->ui->get_permissions($this->DivListFai->selectedBase,"fai/faiProfile"); + if(preg_match("/c/",$acl)){ + $a_setup= $this->get_type(array("objectClass"=>array("FAIprofile"))); + $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai"); + $this->dialog->set_acl_base($this->base); + + $this->is_dialog = false; + }else{ + print_red(sprintf(_("You are not allowed to create a new '%s' object."),"FAIprofile")); + } + } + + + /**************** + Get from ask class name dialog + ****************/ + + 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); + } + }elseif(isset($this->dialog->objectClass)){ + $this->dn = "new" ; + $a_setup= $this->get_type(array("objectClass"=>array($this->dialog->objectClass))); + $name = $this->dialog->save(); + + if(class_exists($a_setup[0])){ + $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai"); + $this->dialog->set_acl_base($this->base); + $this->dialog->by_object[$a_setup[1]]->cn = $name; + $this->is_dialog = true; + } + } + } + + + /**************** + Cancel dialogs + ****************/ + + if(isset($_POST['edit_cancel'])){ + unset($this->dialog); + $this->dialog=FALSE; + $this->is_dialog = false; + session::un_set('objectinfo'); + del_lock ($this->dn); + } + + + /**************** + Save sub dialogs + ****************/ + + /* 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']) || isset($_POST['edit_apply'])) && (isset($this->dialog->config))){ + $this->dialog->save_object(); + $msgs= $this->dialog->check(); + if(count($msgs)!=0){ + foreach($msgs as $msg){ + print_red($msg); + } + }else{ + $this->dialog->save(); + FAI::save_release_changes_now(); + if (!isset($_POST['edit_apply'])){ + del_lock ($this->dn); + unset($this->dialog); + $this->dialog=FALSE; + $this->is_dialog=false; + session::un_set('objectinfo'); + } + } + } + + + /**************** + Display currently open dialog + ****************/ + + /* 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(is_object($this->dialog)){ + $display .= $this->dialog->execute(); + /* Don't show buttons if tab dialog requests this */ + + if(isset($this->dialog->current)){ + + $obj = $this->dialog->by_object[$this->dialog->current]; + + if((isset($obj->is_dialog) && (!$obj->is_dialog)) || (isset($obj->dialog) && (!$obj->dialog))){ + + $display.= "

\n"; + $display.= "\n"; + $display.= " \n"; + if ($this->dn != "new"){ + $display.= "\n"; + $display.= " \n"; + } + $display.= "\n"; + $display.= "

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

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

"; + } + }else{ + $display.= "

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

"; + + } + return($display); + } + + + /**************** + Dialog display + ****************/ + + /* Check if there is a snapshot dialog open */ + $base = $this->DivListFai->selectedBase; + if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){ + return($str); + } + + /* Display dialog with system list */ + $this->DivListFai->parent = $this; + $this->DivListFai->execute(); + $this->DivListFai->AddDepartments($this->DivListFai->selectedBase,4,1); + $this->reload(); + $this->DivListFai->setEntries($this->objects); + return($this->DivListFai->Draw()); + } + + + /* Return departments, that will be included within snapshot detection */ + function get_used_snapshot_bases() + { + $tmp = array(); + $types = array("faipartitionou","faiscriptou","faitemplateou","faihookou","faiprofileou","faivariableou","faipackageou"); + foreach($types as $type){ + if($this->DivListFai->selectedBranch == "main"){ + $tmp[] = get_ou($type).get_ou('faiou').$this->DivListFai->selectedBase; + }else{ + $tmp[] = get_ou($type).$this->DivListFai->selectedBranch; + } + } + return($tmp); + } + + + /* Get available branches for current base */ + function getBranches($base = false,$prefix = "") + { + $ret = array("/"=>"main"); + $ldap = $this->config->get_ldap_link(); + if(!$base){ + $base = session::get('CurrentMainBase'); + } + $tmp = FAI::get_all_releases_from_base($base,true); + foreach($tmp as $dn => $name){ + $ret[$name]=$dn; + } + ksort($ret); + $ret = array_flip($ret); + + return ($ret); + } + + + function list_get_selected_items() + { + $ids = array(); + foreach($_POST as $name => $value){ + if(preg_match("/^item_selected_[0-9]*$/",$name)){ + $id = preg_replace("/^item_selected_/","",$name); + $ids[$id] = $id; + } + } + return($ids); + } + + + /* reload list of objects */ + function reload() + { + /* Variable initialisation */ + $str = ""; + $Regex = $this->DivListFai->Regex; + $this->objects = array(); + + /* Get base */ + $base = get_ou('faiou').$this->DivListFai->selectedBase; + if($this->DivListFai->selectedBranch != "main"){ + $br = $this->getBranches(); + if(isset($br[$this->DivListFai->selectedBranch])){ + $base = $this->DivListFai->selectedBranch; + }else{ + $base = get_ou('faiou').$this->DivListFai->selectedBase; + } + } + $this->base = $base; + $this->set_acl_base($this->base); + + $this->lock_type = FAI::get_release_tag(FAI::get_release_dn($base)); + + /* Create a new list of FAI object + * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ... + */ + $ObjectTypes = array( + "FAIpartitionTable" => array("OU"=> get_ou('faipartitionou') , "CHKBOX"=>"ShowPartitions" ,"ACL" => "faiPartitionTable"), + "FAIpackageList" => array("OU"=> get_ou('faipackageou') , "CHKBOX"=>"ShowPackages" ,"ACL" => "faiPackage"), + "FAIscript" => array("OU"=> get_ou('faiscriptou') , "CHKBOX"=>"ShowScripts" ,"ACL" => "faiScript"), + "FAIvariable" => array("OU"=> get_ou('faivariableou') , "CHKBOX"=>"ShowVariables" ,"ACL" => "faiVariable"), + "FAIhook" => array("OU"=> get_ou('faihookou') , "CHKBOX"=>"ShowHooks" ,"ACL" => "faiHook"), + "FAIprofile" => array("OU"=> get_ou('faiprofileou') , "CHKBOX"=>"ShowProfiles" ,"ACL" => "faiProfile"), + "FAItemplate" => array("OU"=> get_ou('faitemplateou') , "CHKBOX"=>"ShowTemplates" ,"ACL" => "faiTemplate")); + + $filter = ""; + foreach($ObjectTypes as $key => $data){ + if($this->DivListFai->$data['CHKBOX']){ + $filter.= "(objectClass=".$key.")"; + } + } + $filter = "(&(|".$filter.")(cn=$Regex))"; + + /* Get resolved release dependencies */ + $tmp = FAI::get_all_objects_for_given_base($base,$filter); + + /* Ge listed ldap objects */ + $ldap = $this->config->get_ldap_link(); + $ldap->cd($this->config->current['BASE']); + foreach($tmp as $entry){ + + /* Get some more informations about the object */ + $ldap->cat($entry['dn'], array("cn","description","objectClass","FAIclass","FAIstate","objectClass")); + $object = $ldap->fetch(); + + /* Walk through possible types */ + foreach($ObjectTypes as $type => $rest){ + + $acl = $this->ui->get_permissions($object['dn'],"fai/".$rest ['ACL']); + + if(in_array($type,$object['objectClass']) && preg_match("/r/",$acl)){ + + /* Prepare object */ + unset($object['objectClass']['count']); + if(!isset($object['description'][0])){ + $object['description'][0]=""; + } + + /* Clean up object informations */ + $obj = array(); + $obj['cn'] = $object['cn'][0]; + $obj['dn'] = $object['dn']; + $obj['acl'] = $acl; + $obj['description'] = $object['description'][0]; + $obj['objectClass'] = $object['objectClass']; + + /* Append type to this string, to be able to check if the selected + * entry is of type 'freeze' or 'branch' + */ + if(!isset($object['FAIstate'])){ + $obj['FAIstate'] = $this->lock_type; + }else{ + $obj['FAIstate'] = $object['FAIstate'][0]; + } + + $this->objects[strtolower($obj['cn']).$obj['cn'].$type] = $obj; + $this->objects[strtolower($obj['cn']).$obj['cn'].$type]['type']=$type; + } + } + } + + ksort($this->objects); + reset ($this->objects); + + /* use numeric index, thats a bit more secure */ + $tmp0 = array(); + foreach($this->objects as $obj){ + $tmp0[]= $obj; + } + $this->objects = array(); + $this->objects = $tmp0; + } + + function remove_lock() + { + if (isset($this->dn)){ + del_lock ($this->dn); + } + } + + function get_type($array){ + if(in_array("FAIpartitionTable",$array['objectClass'])){ + return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS")); + } + if(in_array("FAIscript",$array['objectClass'])){ + return(array("tabsScript","faiScript","FAISCRIPTTABS")); + } + if(in_array("FAItemplate",$array['objectClass'])){ + return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS")); + } + if(in_array("FAIhook",$array['objectClass'])){ + return(array("tabsHook","faiHook","FAIHOOKTABS")); + } + if(in_array("FAIvariable",$array['objectClass'])){ + return(array("tabsVariable","faiVariable","FAIVARIABLETABS")); + } + if(in_array("FAIprofile",$array['objectClass'])){ + return(array("tabsProfile","faiProfile","FAIPROFILETABS")); + } + + if(in_array("FAIpackageList",$array['objectClass'])){ + return(array("tabsPackage","faiPackage","FAIPACKAGETABS")); + } + } + + function CheckNewBranchName($name,$base) + { + $f = $this->DivListFai->selectedBranch; + if($name == ""){ + return(false); + }elseif(in_array($name,$this->getBranches($f))) { + return(false); + }elseif(tests::is_department_name_reserved($name,$base)){ + return(false); + } + return(true); + } + + function save_object() + { + $this->DivListFai->save_object(); + } + + + function copyPasteHandling_from_queue($s_action,$s_entry) + { + /* Check if Copy & Paste is disabled */ + if(!is_object($this->CopyPasteHandler)){ + return(""); + } + + $base = $this->DivListFai->selectedBranch; + if($base == "main"){ + $base = $this->DivListFai->selectedBase; + } + + /* Add a single entry to queue */ + if($s_action == "cut" || $s_action == "copy"){ + + /* Cleanup object queue */ + $this->CopyPasteHandler->cleanup_queue(); + $entry = $this->objects[$s_entry]; + $a_setup = $this->get_type($entry); + $dn = $entry['dn']; + $this->CopyPasteHandler->add_to_queue($dn,$s_action,$a_setup[0],$a_setup[2],"fai");//$a_setup[1]); + } + + /* Add entries to queue */ + if($s_action == "copy_multiple" || $s_action == "cut_multiple"){ + + /* Cleanup object queue */ + $this->CopyPasteHandler->cleanup_queue(); + + /* Add new entries to CP queue */ + foreach($this->list_get_selected_items() as $id){ + + /* Cleanup object queue */ + $entry = $this->objects[$id]; + $a_setup = $this->get_type($entry); + $dn = $entry['dn']; + + + if($s_action == "copy_multiple"){ + $this->CopyPasteHandler->add_to_queue($dn,"copy",$a_setup[0],$a_setup[2],"fai");//$a_setup[1]); + } + if($s_action == "cut_multiple"){ + $this->CopyPasteHandler->add_to_queue($dn,"cut",$a_setup[0],$a_setup[2],"fai");//$a_setup[1]); + } + } + } + + /* Start pasting entries */ + if($s_action == "editPaste"){ + $this->start_pasting_copied_objects = TRUE; + } + + /* Return C&P dialog */ + if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){ + + /* Load entry from queue and set base */ + $this->CopyPasteHandler->load_entry_from_queue(); + $this->CopyPasteHandler->SetVar("base",$base); + + /* Get dialog */ + $data = $this->CopyPasteHandler->execute(); + + FAI::save_release_changes_now(); + + /* Return dialog data */ + if(!empty($data)){ + return($data); + } + } + + /* Automatically disable status for pasting */ + if(!$this->CopyPasteHandler->entries_queued()){ + $this->start_pasting_copied_objects = FALSE; + } + return(""); + } + + + /* Return plugin informations for acl handling */ + static function plInfo() + { + return (array( + "plShortName" => _("FAI releases"), + "plDescription" => _("FAI release management"), + "plSelfModify" => FALSE, + "plDepends" => array(), + "plPriority" => 0, + "plSection" => array("administration"), + "plCategory" => array("fai"=> array("description" => _("FAI"), + "objectClass" => "FAIclass")), + "plProvidedAcls"=> array())); + } +} +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/gosa-plugins/fai/admin/fai/class_faiPackage.inc b/gosa-plugins/fai/admin/fai/class_faiPackage.inc new file mode 100644 index 000000000..6d6826222 --- /dev/null +++ b/gosa-plugins/fai/admin/fai/class_faiPackage.inc @@ -0,0 +1,659 @@ + "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","FAIpackage","FAIdebianRelease","FAIdebianSection", "FAIinstallMethod"); + + /* ObjectClasses for this Object*/ + var $objectclasses = array("top","FAIclass","FAIpackageList","FAIrepository"); + + /* Class name of the Ldap ObjectClass for the Sub Object */ + var $subClass = ""; + var $subClasses = array("top","FAIclass","FAIscriptEntry"); + + /* Class name of the php class which allows us to edit a Sub Object */ + var $subClassName = ""; + + /* Attributes to initialise for each subObject */ + var $subAttributes = array("cn","description"); + var $sub64coded = array(); + + var $ConfiguredPackages = array(); + + /* 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 $SubObjects = array(); // All leafobjects of this object + + var $FAIdebianRelease = ""; // The selected release + var $FAIdebianSection = array(); // selected section + var $FAIinstallMethod = "aptitude"; // hard coded + var $mirror = ""; // selected mirror + + var $servers = array(); // All available servers + var $releases = array(); // All possible releases + var $sections = array(); // All section types + + var $list = NULL; + + var $mirrors = array(); // The combination of server/release/section + var $confDir = ""; + var $usedPackages = array(); + var $buffer = NULL; + var $strID =""; + var $newDialogShown =false; + + var $FAIstate = ""; + var $view_logged = FALSE; + var $base; + + var $FAIinstallMethods = array( "install", "ninstall", "remove", + "dselect-upgrade", "taskinst", "taskrm", + "hold", "clean", "aptitude", "aptitude-r", + "pending", "dpkgc" ); + + + function faiPackage (&$config, $dn= NULL) + { + /* Load Attributes */ + plugin::plugin ($config, $dn); + + /* If "dn==new" we try to create a new entry + * Else we must read all objects from ldap which belong to this entry. + * First read SubObjects from ldap ... and then the partition definitions for the SubObjects. + */ + if($dn != "new"){ + $this->dn =$dn; + + /* Get FAIstate + */ + if(isset($this->attrs['FAIstate'][0])){ + $this->FAIstate = $this->attrs['FAIstate'][0]; + } + } + + if(isset($this->attrs['FAIpackage'])){ + unset($this->attrs['FAIpackage']['count']); + foreach($this->attrs['FAIpackage'] as $pkg){ + $this->usedPackages[$pkg] = $pkg; + } + ksort($this->usedPackages); + }else{ + $this->usedPackages = array(); + } + + if($dn != "new"){ + + /* Create one filter with all package names, + instead of calling $ldap->search for every single package + */ + $PackageFilter = ""; + foreach($this->usedPackages as $name){ + $PackageFilter .= "(FAIpackage=".$name.")"; + } + $PackageFilter = "(&(objectClass=FAIdebconfInfo)(|".$PackageFilter."))"; + + /* Search for configuration objects */ + $ldap = $this->config->get_ldap_link(); + $ldap->cd($this->dn); + $ldap->search($PackageFilter,array("FAIvariable","FAIvariableType","FAIvariableContent","FAIpackage","FAIdebianSection","FAIstate")); + + /* Walk through configurations and append them to our list of ConfiguredPackages */ + while($attr = $ldap->fetch()){ + + /* Skip objects, that are tagged as removed */ + if(isset($object['FAIstate'][0])){ + if(preg_match("/removed$/",$attr['FAIstate'][0])){ + continue; + } + } + + $tmp =array(); + $tmp['Name'] = $attr['FAIvariable'][0]; + $tmp['Type'] = $attr['FAIvariableType'][0]; + + if (isset($attr['FAIvariableContent'][0])){ + if(!in_array($attr['FAIvariableType'],array("multiselect"))){ + $tmp['Value'] = $attr['FAIvariableContent'][0]; + }else{ + $content = array(); + unset($attr['FAIvariableContent']['count']); + foreach($attr['FAIvariableContent'] as $attr){ + $tmp['Value'][] = $attr; + } + } + $this->ConfiguredPackages[$attr['FAIpackage'][0]][$attr['FAIvariable'][0]]=$tmp; + } + } + } + + if (isset($this->attrs['FAIdebianSection']['count'])){ + unset($this->attrs['FAIdebianSection']['count']); + } + if((isset($this->attrs['FAIdebianSection']))&&(is_array($this->attrs['FAIdebianSection']))){ + $this->FAIdebianSection = array(); + foreach($this->attrs['FAIdebianSection'] as $sec){ + $this->FAIdebianSection[$sec]=$sec; + } + } + + if((isset($this->attrs['FAIdebianSection']))&&(is_string($this->attrs['FAIdebianSection']))){ + $this->FAIdebianSection=array($this->attrs['FAIdebianSection']=>$this->attrs['FAIdebianSection']) ; + } + $this->confDir = CONFIG_DIR."/fai/"; + $this->FAIpackage = array(); + + + $methods = array(); + foreach($this->FAIinstallMethods as $method){ + $methods[$method] = $method; + } + $this->FAIinstallMethods = $methods; + /* Check if we exist already - no need to ask for revisions, etc. then */ + if ($this->dn != "new"){ + $this->newDialogShown= true; + } + + } + + function execute() + { + /* Call parent execute */ + plugin::execute(); + + if($this->is_account && !$this->view_logged){ + $this->view_logged = TRUE; + new log("view","fai/".get_class($this),$this->dn); + } + + /* Fill templating stuff */ + $smarty= get_smarty(); + $display= ""; + + $smarty->assign( "FAIinstallMethods", $this->FAIinstallMethods ); + + if(!$this->is_account){ + + /* Assemble release name */ + $faifilter = session::get('faifilter'); + $tmp= preg_replace('/,'.normalizePreg(get_ou('faiou')).'.*$/', '', $faifilter['branch']); + $tmp= preg_replace('/ou=/', '', $tmp); + $rev= array_reverse(split(',', $tmp)); + $this->FAIdebianRelease= ""; + foreach ($rev as $part){ + $this->FAIdebianRelease.= "/$part"; + } + $this->FAIdebianRelease= preg_replace('#^/#', '', $this->FAIdebianRelease); + + /* Assemble sections */ + $repos= $this->getServerInfos(); + if(isset($repos[$this->FAIdebianRelease])){ + $this->FAIdebianSection= $repos[$this->FAIdebianRelease]; + $this->FAIdebianSection= array_unique($this->FAIdebianSection); + } + + /* Assign Repository settings*/ + $this->is_account = true; + } + + /* Assign variables */ + foreach($this->attributes as $attrs){ + $smarty->assign($attrs,$this->$attrs); + } + + /* Generate package list */ + $this->list= $this->genPkgs(); + + /* + was pressed to open the package dialog */ + if(isset($_POST['Addpkg']) && $this->acl_is_writeable("FAIpackage")){ + $this->dialog = new faiPackageEntry($this->config, $this->dn,$this->list,$this->usedPackages); + $this->is_dialog =true; + } + + /* Delte selected package */ + if(isset($_POST['Delpkg']) && $this->acl_is_writeable("FAIpackage")){ + if($this->FAIstate != "freeze"){ + foreach($_POST['usedPackages'] as $del){ + if(isset($this->usedPackages[$del])){ + unset($this->usedPackages[$del]); + } + } + } + } + + /* Abort package selection dialog */ + if(isset($_POST['CancelSubObject'])){ + $this->dialog = false; + $this->is_dialog=false; + } + + /* attach new packages */ + if(isset($_POST['SaveSubObject'])) { + if($this->FAIstate != "freeze"){ + $this->dialog->save_object(); + if(count($this->dialog->check())){ + foreach($this->dialog->check() as $msgs){ + print_red($msgs); + } + }else{ + $use = $this->dialog->save(); + $this->usedPackages = $use; + $this->dialog = false; + $this->is_dialog=false; + ksort($this->usedPackages); + } + }else{ + $this->dialog = false; + $this->is_dialog=false; + } + } + + /* Configuration dialog open*/ + if((isset($_POST['Conpkg']))&&(isset($_POST['usedPackages']))&&(!empty($_POST['usedPackages'][0])) && $this->acl_is_writeable("FAIdebconfInfo")){ + $path = CONFIG_DIR."/fai/".$this->FAIdebianRelease."/debconf.d"; + $pkg_config = array(); + $pkg = $_POST['usedPackages'][0]; + + if(isset($this->ConfiguredPackages[$pkg])){ + $pkg_config = $this->ConfiguredPackages[$pkg]; + } + + $this->dialog = new faiPackageConfiguration($this->config, $this->dn,$pkg, $path, $pkg_config); + $this->is_dialog =true; + } + + /* Configuration dialog open*/ + if($this->FAIstate != "freeze" && $this->acl_is_writeable("FAIpackage")){ + if((isset($_POST['Markpkg']))&&(isset($_POST['usedPackages']))&&(!empty($_POST['usedPackages']))){ + foreach($_POST['usedPackages'] as $pkg){ + if (isset($this->usedPackages[$pkg])){ + unset($this->usedPackages[$pkg]); + if (preg_match('/^-/', $pkg)){ + $pkg= preg_replace('/^-/', '', $pkg); + } else { + $pkg= preg_replace('/^/', '-', $pkg); + } + $this->usedPackages[$pkg]= $pkg; + } + } + } + } + + /* Save Configuration */ + if(isset($_POST['SaveObjectConfig'])){ + if($this->FAIstate != "freeze"){ + $this->ConfiguredPackages= array_merge($this->ConfiguredPackages,$this->dialog->save()); + } + $this->dialog = false; + $this->is_dialog=false; + } + + /* cancel configuration */ + if(isset($_POST['CancelObjectConfig'])){ + $this->dialog = false; + $this->is_dialog=false; + } + + /* Display dialog */ + if($this->is_dialog){ + return $this->dialog->execute(); + } + + /* Assign section to smarty */ + $strsec = ""; + foreach($this->FAIdebianSection as $sec){ + $strsec .= $sec." "; + } + + $tmp = $this->plInfo(); + foreach($tmp['plProvidedAcls'] as $name => $translated){ + $smarty->assign($name."ACL",$this->getacl($name,preg_match("/freeze/",$this->FAIstate))); + } + + $smarty->assign("releases",$this->releases); + $smarty->assign("release" ,$this->FAIdebianRelease); + $smarty->assign("sections",$this->sections); + $smarty->assign("section" ,$strsec); + $smarty->assign("usedPackages",$this->printUsedPackages()); + $display.= $smarty->fetch(get_template_path('faiPackage.tpl', TRUE)); + return($display); + } + + /* Delete me, and all my subtrees + */ + function remove_from_parent() + { + $ldap = $this->config->get_ldap_link(); + $ldap->cd ($this->dn); + + $use_dn = preg_replace("/".normalizePreg(FAI::get_release_dn($this->dn))."/i", $faifilter['branch'], $this->dn); + if($faifilter['branch'] == "main"){ + $use_dn = $this->dn; + } + + FAI::prepare_to_save_FAI_object($use_dn,array(),true); + + new log("remove","fai/".get_class($this),$use_dn,$this->attributes); + + foreach($this->ConfiguredPackages as $pkgname => $attrs){ + foreach($attrs as $name => $attr){ + $pkgdn = "FAIvariable=".$name.",".$this->dn; + $use_dn = preg_replace("/".normalizePreg(FAI::get_release_dn($this->dn))."/i", $faifilter['branch'], $pkgdn); + if($faifilter['branch'] == "main"){ + $use_dn = $obj['dn']; + } + FAI::prepare_to_save_FAI_object($use_dn,array(),true); + } + } + $this->handle_post_events("remove"); + } + + + /* Save data to object + */ + function save_object() + { + if($this->FAIstate == "freeze") return; + plugin::save_object(); + } + + + /* Check supplied data */ + function check() + { + /* Call common method to give check the hook */ + $message= plugin::check(); + + if(count($this->usedPackages)==0){ + $message[]=_("Please select a least one Package."); + } + + if((empty($this->FAIdebianRelease))||(empty($this->FAIdebianSection))){ + $message[]=_("Please choose a valid combination for your repository setup."); + } + + return ($message); + } + + function printUsedPackages(){ + $a_ret=array(); + if(is_array($this->usedPackages)) { + foreach($this->usedPackages as $usedName){ + + $config = 0; + + foreach($this->ConfiguredPackages as $name => $value){ + if($name == $usedName){ + $config ++; + } + } + + $c_str =""; + if($config){ + $c_str = " - "._("package is configured"); + } + + /* Adapt used name if we're marked for removal */ + $dsc= ""; + if (preg_match('/^-/', $usedName)){ + $dsc= " - "._("Package marked for removal"); + // Generally a bad idea here, because the toggel triggers on -, not on ! + //$usedName= preg_replace('/^-/', '! ', $usedName); + }else{ + $usedName2= $usedName; + } + + if(isset($this->list[$usedName][1])){ + $a_ret[$usedName] = $usedName2." [".$this->list[$usedName][1]."]".$c_str.$dsc; + }else{ + $a_ret[$usedName] = $usedName2.$c_str.$dsc; + } + } + } + return($a_ret); + } + + function genPkgs() + { + /* Generate a list off available packages for this mirror, section and release + */ + /* Only read this file if it wasn't read before */ + if($this->buffer === NULL){ + $this->buffer=array(); + $a_ret = array(); + foreach($this->FAIdebianSection as $sec){ + $strID= CONFIG_DIR."/fai/".$this->FAIdebianRelease."/".$sec; + + if(!is_file($strID)){ + print_red(sprintf(_("Package file '%s' does not exist."),$strID)); + unset($this->buffer); + return(array()); + } + $fp = fopen($strID,"r"); + + /* Parse every line and create an array */ + while(!feof($fp)){ + $str= fgets($fp,512); + $stra= split("\|",$str); + if(count($stra)==4){ + $a_ret[$stra[0]] = $stra; + } + } + fclose($fp); + /* Save our Data, to avoid reading it again */ + } + $this->buffer = $a_ret; + ksort($a_ret); + return($a_ret); + }else{ + return $this->buffer; + } + } + + + /* Save to LDAP */ + function save() + { + + /* Assemble release name */ + if($this->FAIdebianRelease == "ClearFromCopyPaste"){ + $faifilter = session::get('faifilter'); + $tmp= preg_replace('/,'.normalizePreg(get_ou('faiou')).'.*$/', '', $faifilter['branch']); + $tmp= preg_replace('/ou=/', '', $tmp); + $rev= array_reverse(split(',', $tmp)); + $this->FAIdebianRelease= ""; + foreach ($rev as $part){ + $this->FAIdebianRelease.= "/$part"; + } + $this->FAIdebianRelease= preg_replace('#^/#', '', $this->FAIdebianRelease); + } + + plugin::save(); + + $ldap = $this->config->get_ldap_link(); + + $this->attrs['FAIpackage'] = array(); + foreach($this->usedPackages as $pkg => $obj){ + $this->attrs['FAIpackage'][] = $pkg; + } + + $this->attrs['FAIdebianSection'] = array(); + foreach($this->FAIdebianSection as $sec){ + $this->attrs['FAIdebianSection'][] = $sec; + } + + FAI::prepare_to_save_FAI_object($this->dn,$this->attrs); + show_ldap_error($ldap->get_error(), sprintf(_("Saving of FAI/package list with dn '%s' failed."),$this->dn)); + + if($this->initially_was_account){ + new log("modify","fai/".get_class($this),$this->dn,$this->attributes); + }else{ + new log("create","fai/".get_class($this),$this->dn,$this->attributes); + } + + $ldap->cd($this->dn); + + /* Save Package configurations */ + foreach($this->ConfiguredPackages as $pkgname => $attrs){ + foreach($attrs as $name => $attr){ + + $pkgattrs = array(); + + foreach($attr as $n=>$v){ + if(empty($v)) $v = array(); + } + + /* Set attributes */ + $pkgattrs['objectClass'][] = "FAIdebconfInfo"; + + $pkgattrs['FAIpackage'] = $pkgname; + $pkgattrs['FAIvariable'] = $name; + $pkgattrs['FAIvariableType'] = $attr['Type']; + $pkgattrs['FAIvariableContent'] = $attr['Value']; + $pkgdn = "FAIvariable=".$name.",".$this->dn; + + /* Tag object */ + $this->tag_attrs(&$pkgattrs, $pkgdn, $this->gosaUnitTag); + + if(in_array($pkgattrs['FAIvariableType'],array("boolean","multiselect","password","select","string","text"))){ + FAI::prepare_to_save_FAI_object($pkgdn,$pkgattrs); + } + } + } + } + + /* Return plugin informations for acl handling */ + static function plInfo() + { + return (array( + "plShortName" => _("Package"), + "plDescription" => _("FAI Package list"), + "plSelfModify" => FALSE, + "plDepends" => array(), + "plPriority" => 28, + "plSection" => array("administration"), + "plCategory" => array("fai"), + "plProvidedAcls" => array( + "cn" => _("Name"), + "description" => _("Description"), + "FAIpackage" => _("Packages"), + "FAIdebianSection" => _("Section")." ("._("Readonly").")", + "FAIinstallMethod" => _("Install Method"), + "FAIdebconfInfo" => _("Package configuration"), + "FAIdebianRelease" => _("Release")." ("._("Readonly").")") + )); + } + + + + + function PrepareForCopyPaste($source) + { + plugin::PrepareForCopyPaste($source); + + if(isset($source['FAIstate'][0])){ + $this->FAIstate = $source['FAIstate'][0]; + } + + $this->FAIdebianRelease = "ClearFromCopyPaste"; + + if(isset($source['FAIpackage'])){ + unset($source['FAIpackage']['count']); + foreach($source['FAIpackage'] as $pkg){ + $this->usedPackages[$pkg] = $pkg; + } + ksort($this->usedPackages); + }else{ + $this->usedPackages = array(); + } + + if((isset($source['FAIdebianSection']))&&(is_array($source['FAIdebianSection']))){ + $this->FAIdebianSection = array(); + for($i = 0 ; $i < $source['FAIdebianSection']['count'] ; $i ++){ + $this->FAIdebianSection[$source['FAIdebianSection'][$i]]=$source['FAIdebianSection'][$i]; + } + } + + /* Create one filter with all package names, + instead of calling $ldap->search for every single package + */ + $PackageFilter = ""; + foreach($this->usedPackages as $name){ + $PackageFilter .= "(FAIpackage=".$name.")"; + } + $PackageFilter = "(&(objectClass=FAIdebconfInfo)(|".$PackageFilter."))"; + + /* Search for configuration objects */ + $ldap = $this->config->get_ldap_link(); + $ldap->cd($source['dn']); + $ldap->search($PackageFilter,array("FAIvariable","FAIvariableType","FAIvariableContent","FAIpackage","FAIdebianSection","FAIstate")); + + /* Walk through configurations and append them to our list of ConfiguredPackages */ + while($attr = $ldap->fetch()){ + + /* Skip objects, that are tagged as removed */ + if(isset($object['FAIstate'][0])){ + if(preg_match("/removed$/",$attr['FAIstate'][0])){ + continue; + } + } + + $tmp =array(); + $tmp['Name'] = $attr['FAIvariable'][0]; + $tmp['Type'] = $attr['FAIvariableType'][0]; + + if (isset($attr['FAIvariableContent'][0])){ + if(!in_array($attr['FAIvariableType'],array("multiselect"))){ + $tmp['Value'] = $attr['FAIvariableContent'][0]; + }else{ + $content = array(); + unset($attr['FAIvariableContent']['count']); + foreach($attr['FAIvariableContent'] as $attr){ + $tmp['Value'][] = $attr; + } + } + $this->ConfiguredPackages[$attr['FAIpackage'][0]][$attr['FAIvariable'][0]]=$tmp; + } + } + } + + + function getServerInfos() + { + $ret = array(); + $ldap = $this->config->get_ldap_link(); + $ldap->cd($this->config->current['BASE']); + $ldap->search("(objectClass=FAIrepositoryServer)",array("*")); + while($attrs = $ldap->fetch()){ + if(isset($attrs['FAIrepository'])){ + for($i =0 ; $i < $attrs['FAIrepository']['count']; $i++){ + $obj = $attrs['FAIrepository'][$i]; + $tmp = split("\|",$obj); + if(count($tmp)==4){ + foreach(split(",",$tmp[3]) as $sec){ + if(!empty($sec)){ + $ret[$tmp[2]][] = $sec; + } + } + } + } + } + } + return($ret); + } + + +} + +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/gosa-plugins/fai/admin/fai/class_faiPackageConfiguration.inc b/gosa-plugins/fai/admin/fai/class_faiPackageConfiguration.inc new file mode 100644 index 000000000..18f3e2b6c --- /dev/null +++ b/gosa-plugins/fai/admin/fai/class_faiPackageConfiguration.inc @@ -0,0 +1,84 @@ + "Eins ist toll", "zwei" => "Zwei ist noch besser"); + + /* attribute list for save action */ + var $ignore_account = TRUE; + var $attributes = array(); + var $objectclasses = array(); + + var $Debconf_handle = NULL; + var $pkg_config ; + var $obj; + + function faiPackageConfiguration (&$config, $dn= NULL,$obj,$path,$pkg_config) + { + plugin::plugin ($config, $dn); + $this->obj = $obj; + $this->Debconf_handle = new debconf(); + $this->Debconf_handle->set_template_directory($path); + $this->Debconf_handle->set_package($this->obj); + $this->Debconf_handle->set_language(preg_replace('/_.*$/', '', get_browser_language())); + + if( $this->Debconf_handle->load() ) { + $this->pkg_config = $pkg_config; + + foreach($this->pkg_config as $var){ + $this->Debconf_handle->SetDefault($var['Name'],$var['Value']); + } + } + } + + function execute() + { + /* Call parent execute */ + plugin::execute(); + + /* Fill templating stuff */ + $smarty = get_smarty(); + $display = ""; + $smarty->assign("headline", sprintf(_("Debconf information for package '%s'"), $this->obj)); + + $this->Debconf_handle->PostCheck(); + + $smarty->assign("Config",$this->Debconf_handle->get_dialog()); + + $display.= $smarty->fetch(get_template_path('faiPackageConfiguration.tpl', TRUE)); + return($display); + } + + /* Save data to object */ + function save_object() + { + } + + /* Check supplied data */ + function check() + { + /* Call common method to give check the hook */ + $message= plugin::check(); + + return ($message); + } + + function save() + { + $this->Debconf_handle->PostCheck(); + $pkgs = $this->Debconf_handle->template; + + $tmp = array(); + foreach($pkgs as $pkg){ + $tmp[$this->obj][$pkg['Name']]['Value']= $pkg['Default']; + $tmp[$this->obj][$pkg['Name']]['Name'] = $pkg['Name']; + $tmp[$this->obj][$pkg['Name']]['Type'] = $pkg['Type']; + } + return($tmp); + } +} +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/gosa-plugins/fai/admin/fai/class_faiPackageEntry.inc b/gosa-plugins/fai/admin/fai/class_faiPackageEntry.inc new file mode 100644 index 000000000..3670a3af0 --- /dev/null +++ b/gosa-plugins/fai/admin/fai/class_faiPackageEntry.inc @@ -0,0 +1,200 @@ + "Eins ist toll", "zwei" => "Zwei ist noch besser"); + + /* attribute list for save action */ + var $ignore_account= TRUE; + var $attributes = array(); + var $objectclasses= array(); + var $pkgs = array(); + + var $buffer = array(); + var $categories = array(); + var $searchStrPKG = ""; + var $selected = array(); + + /* Array with available class names */ + var $FAIAllclasses = array(); + + function faiPackageEntry (&$config, $dn= NULL,$pkgs,$selected=array()) + { + plugin::plugin ($config, $dn); + + $this->pkgs=$pkgs; + + if(session::is_set('searchStrPKG')){ + $this->searchStrPKG = session::get('searchStrPKG'); + } + $this->selected=$selected; + + $this->searchStrPKG= _("Please enter your search string here"); + } + + function execute() + { + /* Call parent execute */ + plugin::execute(); + + /* Fill templating stuff */ + $smarty = get_smarty(); + $display = ""; + + $divlist = new divlist("PackageEntry"); + $divlist->SetPluginMode(); + $divlist->SetSummary(_("This list displays all assigned package names for this repository settings.")); + $divlist->SetEntriesPerPage(0); + $divlist->SetHeight("650px;"); + $divlist->SetHeader(array(array("string" => " ", "attach" => "style='text-align:center;width:20px;'"), + array("string" => "Name", "attach" => "style='width:180px;'"), + array("string" => "Version", "attach" ), + array("string" => "Description", "attach" => "style='width:240px;border-right:0px;text-align:left;'"))); + + if(isset($_GET['search'])){ + $this->searchStrPKG= $_GET['search']."*"; + } + + $pkgs= $this->pkgs; + + unset($this->categories); + foreach($pkgs as $name => $entry){ + $cat = $entry[2]; + if(!empty($cat)){ + if(!isset($this->categories[$cat])){ + $this->categories[$cat] = true; + } + if(isset($_POST['chkchange'])){ + $this->searchStrPKG = $_POST['searchStrPKG']; + if(isset($_POST['CAT'.$cat])){ + $this->categories[$cat]=true; + }else{ + $this->categories[$cat]=false; + } + } + } + } + + $this->searchStrPKG = preg_replace("/^\+/","",$this->searchStrPKG); + if(empty($this->searchStrPKG)){ + $this->searchStrPKG = "*"; + } + + @ksort($this->categories); + +$CHKS = ""; + $i = 0; + if(is_array($this->categories)) + foreach($this->categories as $cat => $selected){ + if($i == 3){ + $CHKS .=""; + $i = 0; + } + $i ++ ; + if($selected){ + $CHKS .=""; + }else{ + $CHKS .=""; + } + } + $CHKS .= "
 ".$cat."  ".$cat." 
"; + + + foreach($_POST as $name => $value){ + if(preg_match("/^wasonpage_/i",$name)){ + $name = preg_replace("/^wasonpage_/","",$name); + $n =base64_decode($name); + + if(isset($_POST['use_'.$name])){ + $this->selected[$n] = $n; + }else{ + if(isset($this->selected[$n])){ + unset($this->selected[$n]); + } + } + + } + } + + /* Prepare search filter */ + $search_str = preg_replace("/\\\\\*/",".*",normalizePreg($this->searchStrPKG)); + + $cnt = 0; + foreach($pkgs as $pkg){ + if($cnt > 200) { + print_red(sprintf(_("Your specified search string '%s' returned too many results. Only the first 200 entries are shown, to keep the memory usage low."),$this->searchStrPKG)); + break; + } + if((preg_match("/^".$search_str."/i",$pkg[0]))|| + (preg_match("/^".$search_str."/i",$pkg[3]))){ + if($this->categories[$pkg[2]]){ + if(in_array($pkg[0],$this->selected)){ + $check = " checked "; + }else{ + $check = ""; + } + $cnt ++ ; + $chkbox = " + "; + $divlist->AddEntry(array(array("string"=>$chkbox, "attach" => "style='text-align:center;width:20px;'"), + array("string"=>$pkg[0], "attach" => "style='width:180px;'"), + array("string"=>htmlentities($pkg[1])), + array("string"=>htmlentities($pkg[3]), "attach" => "style='width:221px;border-right:0px;text-align:left;'"))); + } + } + } + + session::set('searchStrPKG',$this->searchStrPKG); + $smarty->assign("CHKS" , $CHKS); + $smarty->assign("searchStrPKG" , $this->searchStrPKG); + $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('faiPackageEntry.tpl', TRUE)); + return($display); + } + + /* Save data to object */ + function save_object() + { + foreach($_POST as $name => $value){ + if(preg_match("/^wasonpage_/i",$name)){ + $name = preg_replace("/^wasonpage_/","",$name); + $n =base64_decode($name); + if(isset($_POST['use_'.$name])){ + $this->selected[$n] = $n; + }else{ + if(isset($this->selected[$n])){ + unset($this->selected[$n]); + } + } + + } + } + + } + + /* Check supplied data */ + function check() + { + /* Call common method to give check the hook */ + $message= plugin::check(); + + return ($message); + } + + function save() + { + return($this->selected); + } +} +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/gosa-plugins/fai/admin/fai/class_faiPartitionTable.inc b/gosa-plugins/fai/admin/fai/class_faiPartitionTable.inc new file mode 100644 index 000000000..99417316e --- /dev/null +++ b/gosa-plugins/fai/admin/fai/class_faiPartitionTable.inc @@ -0,0 +1,604 @@ + "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"); + + /* Specific attributes */ + var $cn = ""; // The class name for this object + var $description = ""; // The description for this set of partitions + var $disks = array(); // All defined Disks + var $is_dialog = false; // specifies which buttons will be shown to save or abort + + var $FAIstate = ""; + var $ui; + + var $view_logged = FALSE; + + function faiPartitionTable (&$config, $dn= NULL) + { + /* Load Attributes */ + plugin::plugin ($config, $dn); + + $this->acl ="#all#"; + + $this->ui = get_userinfo(); + + /* If "dn==new" we try to create a new entry + * Else we must read all objects from ldap which belong to this entry. + * First read disks from ldap ... and then the partition definitions for the disks. + */ + if($dn != "new"){ + $this->dn =$dn; + + /* Get FAIstate + */ + if(isset($this->attrs['FAIstate'][0])){ + $this->FAIstate = $this->attrs['FAIstate'][0]; + } + + /* 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()){ + + /* Skip objects, that are tagged as removed */ + if(isset($object['FAIstate'][0])){ + if(preg_match("/removed$/",$object['FAIstate'][0])){ + continue; + } + } + + $this->disks[$object['cn'][0]]['status'] = "edited"; + $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()){ + + /* Skip objects, that are tagged as removed */ + if(isset($partition['FAIstate'][0])){ + if(preg_match("/removed$/",$partition['FAIstate'][0])){ + continue; + } + } + + /* 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]; + } + } + + /* Append fetched partitions + */ + $partition['status']="edited"; + $this->disks[$name]['partitions'][$partition['FAIpartitionNr']] = $partition; + } + } + } + ksort($this->disks); + } + + + function acl_base_for_current_object($dn) + { + if($dn == "new"){ + if($this->dn == "new"){ + $dn = session::get('CurrentMainBase'); + }else{ + $dn = $this->dn; + } + } + return($dn); + } + + + function execute() + { + /* Call parent execute */ + plugin::execute(); + + if($this->is_account && !$this->view_logged){ + $this->view_logged = TRUE; + new log("view","fai/".get_class($this),$this->dn); + } + + /* 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'])){ + $usedDiskNames =array(); + foreach($this->disks as $key=>$disk){ + $usedDiskNames[]= $key; + } + $this->dialog = new faiPartitionTableEntry($this->config,$this->dn,$usedDiskNames); + $this->dialog->set_acl_base($this->acl_base_for_current_object($this->dn)); + $this->dialog->set_acl_category("fai"); + $this->dialog->FAIstate = $this->FAIstate; + $this->is_dialog = true; + } + + /* Edit disk. + * Open dialog which allows us to edit the selected entry + */ + + if($this->dn != "new"){ + session::set('objectinfo',$this->dn); + } + + if((isset($_POST['EditDisk']))&&(isset($_POST['disks']))){ + $usedDiskNames =array(); + $Udisk = $_POST['disks'][0]; + if(isset($this->disks[$Udisk])){ + + foreach($this->disks as $key=>$disk){ + if($key != $Udisk){ + $usedDiskNames[]= $key; + } + } + + /* Set object info string, which will be displayed in plugin info line */ + if(isset($this->disks[$Udisk]['dn'])){ + session::set('objectinfo',$this->disks[$Udisk]['dn']); + $dn = $this->disks[$Udisk]['dn']; + }else{ + session::set('objectinfo',""); + $dn = "new"; + } + + $this->dialog = new faiPartitionTableEntry($this->config,$this->dn,$usedDiskNames,$this->disks[$Udisk]); + $this->dialog->set_acl_base($this->acl_base_for_current_object($dn)); + $this->dialog->set_acl_category("fai"); + $this->dialog->FAIstate = $this->FAIstate; + + $this->is_dialog = true; + } + } + + /* Edit aborted, close dialog, without saving anything + */ + if(isset($_POST['CancelDisk'])){ + unset($this->dialog); + $this->dialog = FALSE; + $this->is_dialog=false; + } + + /* Dialog saved + * Save given data from Dialog, if no error is occurred + */ + if(isset($_POST['SaveDisk'])){ + + if($this->FAIstate != "freeze"){ + $this->dialog->save_object(); + if(count($this->dialog->check())){ + foreach($this->dialog->check() as $msg){ + print_red($msg); + } + }else{ + $disk = $this->dialog->save(); + if(isset($disk['rename'])){ + if($this->disks[$disk['rename']['from']]['status']=="edited"){ + $this->disks[$disk['rename']['from']]['status']="delete"; + }else{ + unset($this->disks[$disk['rename']['from']]); + } + + foreach($disk['partitions'] as $key => $val){ + if($disk['partitions'][$key]['status']!="delete"){ + $disk['partitions'][$key]['status']= "new"; + } + } + + $disk['status']="new"; + $disk['cn']= $disk['rename']['to']; + } + + $this->disks[$disk['cn']]=$disk; + unset($this->dialog); + $this->dialog = FALSE; + $this->is_dialog=false; + ksort($this->disks); + } + }else{ + $this->dialog = FALSE; + $this->is_dialog=false; + } + } + + /* Delete selected disk drive from list + * Assign delete status for all its partitions + */ + if((isset($_POST['DelDisk']))&&(!empty($_POST['disks']))){ + if($this->FAIstate != "freeze"){ + foreach($_POST['disks'] as $disk) { + + if(isset($this->disks[$disk])){ + if($this->disks[$disk]['status']=="edited"){ + $this->disks[$disk."-delete"]=$this->disks[$disk]; + unset($this->disks[$disk]); + $disk = $disk."-delete"; + $this->disks[$disk]['status']="delete"; + foreach($this->disks[$disk]['partitions'] as $name => $value ){ + if($value['status']=="edited"){ + $this->disks[$disk]['partitions'][$name]['status']="delete"; + }else{ + unset($this->disks[$disk]['partitions'][$name]); + } + } + }else{ + unset($this->disks[$disk]); + } + } + } + } + } + + /* Display dialog if one is defined + */ + if(is_object($this->dialog)){ + $this->dialog->save_object(); + return($this->dialog->execute()); + } + + /* Assign all attributes to smarty engine + */ + foreach($this->attributes as $attrs){ + $smarty->assign($attrs,$this->$attrs); + if($this->$attrs){ + $smarty->assign($attrs."CHK"," "); + }else{ + $smarty->assign($attrs."CHK"," disabled "); + } + } + + $dn = $this->acl_base_for_current_object($this->dn); + $smarty->assign("sub_object_is_addable", + preg_match("/c/",$this->ui->get_permissions($dn,"fai/faiPartitionTableEntry")) && + !preg_match("/freeze/",$this->FAIstate)); + + $tmp = $this->plInfo(); + foreach($tmp['plProvidedAcls'] as $name => $translated){ + $smarty->assign($name."ACL",$this->getacl($name)); + } + $disks = $this->getDisks(); + $smarty->assign("disks" ,$disks); + $display.= $smarty->fetch(get_template_path('faiPartitionTable.tpl', TRUE)); + return($display); + } + + function getDisks(){ + /* Return all available disks for this partition table + * Return in listBox friendly array + */ + $a_return = array(); + foreach($this->disks as $key => $disk){ + + $dn = "new"; + if(isset($obj['dn'])){ + $dn = $obj['dn']; + } + $dn = $this->acl_base_for_current_object($dn); + $acl = $this->ui->get_permissions($dn,"fai/faiPartitionTableEntry"); + if(preg_match("/(r|w)/",$acl)) { + + if($disk['status'] != "delete"){ + $cnt=0; + foreach($disk['partitions'] as $val){ + if($val['status']!="delete"){ + $cnt ++; + } + } + if(!empty($disk['description'])){ + if($cnt == 1){ + $a_return[$key]= $disk['cn']." [".$disk['description']."], ".sprintf(_("%s partition"), $cnt); + }else{ + $a_return[$key]= $disk['cn']." [".$disk['description']."], ".sprintf(_("%s partition(s)"), $cnt); + } + }else{ + if($cnt == 1){ + $a_return[$key]= $disk['cn'].", ".sprintf(_("%s partition"), $cnt); + }else{ + $a_return[$key]= $disk['cn'].", ".sprintf(_("%s partition(s)"), $cnt); + } + } + } + } + } + return($a_return); + } + + + /* Delete me, and all my subtrees + */ + function remove_from_parent() + { + $ldap = $this->config->get_ldap_link(); + $ldap->cd ($this->dn); + + $faifilter = session::get('faifilter'); + $use_dn = preg_replace("/".normalizePreg(FAI::get_release_dn($this->dn))."/i", $faifilter['branch'], $this->dn); + if($faifilter['branch'] == "main"){ + $use_dn = $this->dn; + } + + FAI::prepare_to_save_FAI_object($use_dn,array(),true); + + new log("remove","fai/".get_class($this),$use_dn,$this->attributes); + + foreach($this->disks as $disk){ + + $disk_dn = "cn=".$disk['cn'].",".$this->dn; + $use_dn = preg_replace("/".normalizePreg(FAI::get_release_dn($this->dn))."/i", $faifilter['branch'], $disk_dn); + if($faifilter['branch'] == "main"){ + $use_dn = $disk_dn; + } + FAI::prepare_to_save_FAI_object($use_dn,array(),true); + + foreach($disk['partitions'] as $key => $partition){ + + $partition_dn= "FAIpartitionNr=".$partition['FAIpartitionNr'].",".$disk_dn; + $use_dn = preg_replace("/".normalizePreg(FAI::get_release_dn($this->dn))."/i", $faifilter['branch'], $partition_dn); + if($faifilter['branch'] == "main"){ + $use_dn = $disk_dn; + } + FAI::prepare_to_save_FAI_object($use_dn,array(),true); + } + } + } + + + /* Save data to object + */ + function save_object() + { + if($this->FAIstate == "freeze") return; + plugin::save_object(); + foreach($this->attributes as $attrs){ + if(isset($_POST[$attrs])){ + $this->$attrs = $_POST[$attrs]; + } + } + } + + + /* Check supplied data */ + function check() + { + /* Call common method to give check the hook */ + $message= plugin::check(); + + return ($message); + } + + + /* Save to LDAP */ + function save() + { + + plugin::save(); + /* Save current settings. + * 1 : We must save the partition table, with its description and cn + * 2 : Append Disk with cn and description. + * 3 : Save partitions for each disk + */ + + $ldap = $this->config->get_ldap_link(); + + FAI::prepare_to_save_FAI_object($this->dn,$this->attrs); + show_ldap_error($ldap->get_error(), sprintf(_("Saving of FAI/partition table with dn '%s' failed."),$this->dn)); + + if($this->initially_was_account){ + new log("modify","fai/".get_class($this),$this->dn,$this->attributes); + }else{ + new log("create","fai/".get_class($this),$this->dn,$this->attributes); + } + + /* Sort entries, because we must delete entries with status="delete" first */ + $order = array(); + foreach($this->disks as $key => $disk){ + if($disk['status'] == "delete"){ + $order[$key] = $disk; + } + } + foreach($this->disks as $key => $disk){ + if($disk['status'] != "delete"){ + $order[$key] = $disk; + } + } + + /* Append all disks to ldap */ + foreach($order as $cn=>$disk){ + $disk_dn = "cn=".$disk['cn'].",".$this->dn; + $disk_attrs['cn'] = $disk['cn']; + $disk_attrs['description'] = $disk['description']; + $disk_attrs['objectClass'] = array("top","FAIclass","FAIpartitionDisk"); + + if($disk['status']=="new"){ + $ldap->cat($disk_dn,array("objectClass")); + if($ldap->count()){ + $disk['status']="edited"; + } + } + + /* Tag object */ + $this->tag_attrs(&$disk_attrs, $disk_dn, $this->gosaUnitTag); + + if($disk['status'] == "delete"){ + FAI::prepare_to_save_FAI_object($disk_dn,array(),true); + $this->handle_post_events("remove"); + }elseif($disk['status'] == "edited"){ + FAI::prepare_to_save_FAI_object($disk_dn,$disk_attrs); + $this->handle_post_events("modify"); + }elseif($disk['status']=="new"){ + FAI::prepare_to_save_FAI_object($disk_dn,$disk_attrs); + $this->handle_post_events("add"); + } + + if($disk['status']!="delete") + /* Add all partitions */ + 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= "FAIpartitionNr=".$partition_attrs['FAIpartitionNr'].",".$disk_dn; + $partition_attrs['objectClass']= array("top","FAIclass","FAIpartitionEntry"); + $partition_attrs['cn']= $partition_attrs['FAIpartitionNr']; + + unset($partition_attrs['status']); + unset($partition_attrs['old_cn']); + + if($partition['status']=="new"){ + $ldap->cat($partition_dn,array("objectClass")); + if($ldap->count()){ + $partition['status']="edited"; + } + } + + if((!isset($partition['FAImountPoint']))||(empty($partition['FAImountPoint']))){ + $partition_attrs['FAImountPoint']="swap"; + } + + /* Tag object */ + $this->tag_attrs(&$partition_attrs, $partition_dn, $this->gosaUnitTag); + + if($partition['status'] == "delete"){ + FAI::prepare_to_save_FAI_object($partition_dn,array(),true); + $this->handle_post_events("remove"); + }elseif($partition['status'] == "edited"){ + FAI::prepare_to_save_FAI_object($partition_dn,$partition_attrs); + $this->handle_post_events("modify"); + }elseif($partition['status']=="new"){ + FAI::prepare_to_save_FAI_object($partition_dn,$partition_attrs); + $this->handle_post_events("add"); + } + } + } + $this->handle_post_events("add"); + } + + + function PrepareForCopyPaste($source) + { + plugin::PrepareForCopyPaste($source); + /* Get FAIstate + */ + if(isset($source['FAIstate'][0])){ + $this->FAIstate = $source['FAIstate'][0]; + } + + /* Read all disks from ldap taht are defined fot this partition table + */ + $ldap = $this->config->get_ldap_link(); + $ldap->cd ($source['dn']); + $ldap->search("(&(objectClass=FAIclass)(objectClass=FAIpartitionDisk))",array("*")); + while($object = $ldap->fetch()){ + + /* Skip objects, that are tagged as removed */ + if(isset($object['FAIstate'][0])){ + if(preg_match("/removed$/",$object['FAIstate'][0])){ + continue; + } + } + + $this->disks[$object['cn'][0]]['status'] = "edited"; + $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()){ + + /* Skip objects, that are tagged as removed */ + if(isset($partition['FAIstate'][0])){ + if(preg_match("/removed$/",$partition['FAIstate'][0])){ + continue; + } + } + + /* 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]; + } + } + + /* Append fetched partitions + */ + $partition['status']="edited"; + $this->disks[$name]['partitions'][$partition['FAIpartitionNr']] = $partition; + } + } + ksort($this->disks); + } + + + /* Return plugin informations for acl handling */ + static function plInfo() + { + return (array( + "plShortName" => _("Partition table"), + "plDescription" => _("FAI partition table"), + "plSelfModify" => FALSE, + "plDepends" => array(), + "plPriority" => 26, + "plSection" => array("administration"), + "plCategory" => array("fai"), + "plProvidedAcls" => array( + "cn" => _("Name")." ("._("Read only").")", + "description" => _("Description")) + )); + } +} + +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/gosa-plugins/fai/admin/fai/class_faiPartitionTableEntry.inc b/gosa-plugins/fai/admin/fai/class_faiPartitionTableEntry.inc new file mode 100644 index 000000000..d72ec5149 --- /dev/null +++ b/gosa-plugins/fai/admin/fai/class_faiPartitionTableEntry.inc @@ -0,0 +1,521 @@ + "Eins ist toll", "zwei" => "Zwei ist noch besser"); + + /* attribute list for save action */ + var $ignore_account= TRUE; + var $attributes = array("DISKcn","DISKdescription"); + var $objectclasses= array(); + + var $DISKcn = ""; + var $DISKdescription = ""; + + var $partitions = array(); + var $UsedAttrs = array(); + var $is_edit = false; + var $old_cn = ""; + var $status = "new"; + var $deletePartitions = array(); + + var $FAIstate = ""; + + function faiPartitionTableEntry (&$config, $dn= NULL,$usedDiskNames=array(),$disk=false) + { + plugin::plugin ($config, $dn); + $this->UsedAttrs = array("cn","description","FAIpartitionType","FAIpartitionNr","FAIfsType","FAImountPoint","FAIpartitionSize", + "FAImountOptions","FAIfsOptions","FAIpartitionFlags"); + + /* Default status is new */ + $this->status = "new"; + + /* We want to edit an entry */ + if($disk){ + + /* Set disk status */ + $this->status = $disk['status']; + + /* Walk through partitions */ + foreach($disk['partitions'] as $name => $values){ + + /* If a partition is already marked as delete, attach it to deletePartitions only. */ + if($values['status'] == "delete"){ + unset($disk['partitions'][$name]); + $this->deletePartitions[]=$values; + }else{ + + /* Set status, to know which partition must be deleted from ldap + new : Neu partition entry // save + edited : Update partition entry in ldap + deleted: Remove partition from ldap + */ + + /* If status is not new, set to edit mode. + * New means that this partition currently wasn't saved to ldap. + */ + if($disk['partitions'][$name]['status']!="new"){ + $disk['partitions'][$name]['status']="edited"; + } + + $disk['partitions'][$name]['old_cn']= $disk['partitions'][$name]['cn']; + + /* Assign empty attributes, if attribute is missing */ + foreach($this->UsedAttrs as $attr){ + if(!isset($values[$attr])){ + $disk['partitions'][$name][$attr]=""; + } + } + + if (preg_match('/^_/', $disk['partitions'][$name]['FAIfsType'])){ + $disk['partitions'][$name]['FAIfsType']= preg_replace('/^_/', '', $disk['partitions'][$name]['FAIfsType']); + $disk['partitions'][$name]['FAIencrypted']= true; + } else { + $disk['partitions'][$name]['FAIencrypted']= false; + } + } + } + + /* Set default attributes */ + $this->DISKcn = $disk['cn']; + $this->DISKdescription = $disk['description']; + $this->partitions = $disk['partitions']; + $this->is_edit = true; + $this->old_cn = $disk['cn']; + } + } + + + function execute() + { + /* Call parent execute */ + plugin::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)) && $this->acl_is_removeable()){ + $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" && $this->acl_is_removeable()){ + if($this->partitions[$s_entry]['status'] == "edited"){ + $this->deletePartitions[$s_entry]= $this->partitions[$s_entry]; + $this->deletePartitions[$s_entry]['FAIpartitionNr']=$s_entry; + unset($this->partitions[$s_entry]); + }else{ + 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']) && $this->acl_is_createable()){ + foreach($this->UsedAttrs as $attr){ + $tmp[$attr] = ""; + } + $tmp["old_cn"] = ""; + $tmp["FAIencrypted"] = FALSE; + $tmp['status']="new"; + $this->partitions[count($this->partitions)+1]=$tmp; + } + + /* $setup contains a table with the partitions. + */ + $smarty->assign("setup", $this->generateParts()); + foreach($this->attributes as $attr){ + $smarty->assign($attr,$this->$attr); + } + + $tmp = $this->plInfo(); + $sacl = ""; + foreach($tmp['plProvidedAcls'] as $name => $translated){ + + $acl = $this->getacl($name); + $sacl .= $acl; + if($this->FAIstate == "freezed"){ + $acl = preg_replace("/w/","",$acl); + } + $smarty->assign($name."ACL",$acl); + } + $smarty->assign("allowSave",$sacl); + + $smarty->assign("sub_object_is_createable",$this->acl_is_createable()); + + /* 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"=>_("primary"),"logical"=>_("logical")); + $FAIfsTypes = array("ext2","ext3","xfs","swap","reiser","dosfat16","winfat32"); + + /* Display Header */ + $str = ""; + if (count($this->partitions)){ + $str .= ""; + $str .= ""._("Type").""; + $str .= ""._("FS type").""; + $str .= ""._("Mount point").""; + $str .= ""._("Size in MB").""; + $str .= ""._("Mount options").""; + $str .= ""._("FS option").""; + $str .= ""._("Preserve").""; + $str .= ""._("Encrypted").""; + $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){ + + $dis = ""; + if($part['FAIpartitionFlags'] == "preserve"){ + $dis = " disabled "; + } + + $disableALL = ""; + if($this->FAIstate =="freeze"){ + $disableALL = " disabled "; + } + + if($part['status']!="delete"){ + + /* Generate Partition select box + */ + $PartitionType = ""; + if($this->acl_is_writeable("FAIpartitionType")){ + $PartitionType = ""; + }elseif($this->acl_is_readable("FAIpartitionType")){ + $PartitionType = $part['FAIpartitionType']; + } + + + /* Generate fsType select box + */ + $FAIfsType= ""; + if($this->acl_is_writeable("FAIfsType")){ + $FAIfsType= ""; + }elseif($this->acl_is_readable("FAIfsType")){ + $FAIfsType = $part['FAIfsType']; + } + + foreach(array("FAImountPoint","FAIpartitionSize","FAImountOptions","FAIfsOptions") as $attr){ + $$attr = ""; + if($this->acl_is_writeable($attr)){ + $$attr = ""; + + }elseif($this->acl_is_readable($attr)){ + $$attr = $part[$attr]; + } + } + + + $str .= "\n"; + $str .= "\n".$PartitionType.""; + $str .= "\n".$FAIfsType.""; + $str .= "\n".$FAImountPoint.""; + $str .= "\n".$FAIpartitionSize.""; + $str .= "\n".$FAImountOptions.""; + $str .= "\n".$FAIfsOptions.""; + + $changeState = "onClick=\"changeState('FAImountPoint_".$key."') ; ". + "changeState('FAIpartitionSize_".$key."') ; ". + "changeState('FAImountOptions_".$key."') ; ". + "changeState('FAIfsType_".$key."') ; ". + "changeState('FAIfsOptions_".$key."') ; \""; + + if($this->acl_is_writeable("FAIpartitionFlags")){ + if($part['FAIpartitionFlags']!=false){ + $str .= "\n"; + }else{ + $str .= "\n"; + } + if($part['FAIencrypted']!=false){ + $str .= "\n"; + }else{ + $str .= "\n"; + } + }else{ + if($part['FAIpartitionFlags']!=false){ + $str .= ""._("False").""; + }else{ + $str .= ""._("True").""; + } + if($part['FAIencrypted']!=false){ + $str .= ""._("False").""; + }else{ + $str .= ""._("True").""; + } + } + if($this->acl_is_removeable()){ + $str .= "\n"; + }else{ + $str .= "\n"; + } + $str .= "\n"; + } + } + + if(!empty($str)){ + $str = "".$str."
"; + } + return($str); + + } + + function save() + { + $tmp = array(); + $tmp['cn'] = $this->DISKcn; + + /* Attach partitions */ + foreach($this->partitions as $key=>$val) { + if (isset($this->partitions[$key]['FAIencrypted']) && $this->partitions[$key]['FAIencrypted']){ + unset ($this->partitions[$key]['FAIencrypted']); + $this->partitions[$key]['FAIfsType']= "_".$this->partitions[$key]['FAIfsType']; + } + $this->partitions[$key]['FAIpartitionNr']=$key; + } + + /* Attach deleted */ + foreach($this->deletePartitions as $key=>$val) { + $this->partitions[$key."-delete"]=$val; + $this->partitions[$key."-delete"]['status']="delete"; + } + + $tmp['description'] = $this->DISKdescription; + $tmp['partitions'] = $this->partitions; + $tmp['status'] = $this->status; + + /* If hdd name has changed, tell partitionTable to rename it */ + if(($this->is_edit)&&($this->old_cn != $this->DISKcn)){ + $tmp['rename']['from'] = $this->old_cn; + $tmp['rename']['to'] = $this->DISKcn; + } + return($tmp); + } + + + /* Save data to object */ + function save_object() + { + if((isset($_POST['TableEntryFrameSubmitted'])) && ($this->FAIstate != "freeze") ){ + plugin::save_object(); + + foreach($this->partitions as $key => $part){ + foreach($this->UsedAttrs as $attrs){ + + if($this->acl_is_writeable($attrs)){ + + if(isset($_POST[$attrs."_".$key])){ + $this->partitions[$key][$attrs] = $_POST[$attrs."_".$key]; + }else{ + $this->partitions[$key][$attrs] = false; + } + } + } + + if($this->acl_is_writeable("FAIencrypted")){ + + if(isset($_POST["FAIencrypted_".$key])){ + $this->partitions[$key]["FAIencrypted"] = $_POST["FAIencrypted_".$key]; + }else{ + $this->partitions[$key]["FAIencrypted"] = false; + } + } + + /* Adapt ext3 to have -j option */ + if ($this->partitions[$key]["FAIfsType"] == "ext3") { + $this->partitions[$key]["FAIfsOptions"]= preg_replace('/\s*-j\s*/', '', $this->partitions[$key]["FAIfsOptions"]); + $this->partitions[$key]["FAIfsOptions"]= "-j ".$this->partitions[$key]["FAIfsOptions"]; + } + } + + } + } + + + /* Check supplied data */ + function check() + { + /* Call common method to give check the hook */ + $message= plugin::check(); + + /* Check for an empty disk name */ + if(empty($this->DISKcn)){ + $message[] = _("Please specify a valid disc name."); + } + + /* check every partition. + * if there is an invalid value defined, append an errorstr to message + */ + + /* Array that contain every partitionname mountpoint etc already assigned */ + $alreadyUsed = array(); + foreach($this->UsedAttrs as $attrs){ + $alreadyUsed[$attrs] = array(); + } + + foreach($this->partitions as $key => $part){ + + /* Skip all checks, if preserve is set */ + if($part['FAIpartitionFlags'] == "preserve"){ + $this->partitions[$key]['FAIfsType'] = "preserve"; + $this->partitions[$key]['FAIpartitionSize'] = "preserve"; + continue; + } + + if((in_array($part['FAImountPoint'],$alreadyUsed['FAImountPoint']))&&($part['FAIfsType']!="swap")){ + $message[]=sprintf(_("please enter a unique mount point for partition %s"),($key)); + } + + if($part['FAIfsType']!="swap" && $part['FAImountPoint'] != "-"){ + 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)); + } + } + if($part['FAIfsType'] == "swap"){ + if(in_array($part['FAIfsType'],$alreadyUsed['FAIfsType'])){ + $message[]=sprintf(_("File system type 'swap' is already used, change file system type for partition %s."),$key); + } + } + if(($part['FAIfsType'] == "swap")&&(!empty($part['FAImountPoint']))&&($part['FAImountPoint']!="swap")){ + $message[]=_("Please use 'swap' as mount point, if 'swap' is used as fs-type."); + } + + $tmp = split("-",$part['FAIpartitionSize']); + switch (count($tmp)){ + case 0: + $message[]= sprintf(_("Please enter a valid partition size for partition %s."),($key)); + break; + case 1: + if (!tests::is_id(is_id($tmp[0])) &&(!empty($tmp[1]))){ + $message[]= sprintf(_("Please enter a valid partition size for partition %s."),($key)); + } + break; + + case 2: + if((!tests::is_id($tmp[0]))&&(!tests::is_id($tmp[1])) &&(!empty($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)); + } + break; + + default: + $message[]=sprintf(_("Please enter a range for partition size for partition %s."),($key)); + } + + foreach($this->UsedAttrs as $attrs){ + $alreadyUsed[$attrs][$key] = $part[$attrs]; + } + } + + $cnt = 0; + foreach($this->partitions as $key => $part){ + if($part['FAIpartitionType'] == "primary"){ + $cnt ++ ; + } + } + if($cnt > 3){ + $message[] = _("You have more than 3 primary partition table entries in your configuration, please check your configuration twice."); + } + + return ($message); + } + + + + /* Return plugin informations for acl handling */ + static function plInfo() + { + return (array( + "plShortName" => _("Partition table entry"), + "plDescription" => _("FAI partition table entry"), + "plSelfModify" => FALSE, + "plDepends" => array(), + "plPriority" => 27, + "plSection" => array("administration"), + "plCategory" => array("fai"), + "plProvidedAcls" => array( + "DISKcn" => _("Name"), + "DISKdescription" => _("Description"), + "FAIpartitionType" => _("Partition type"), + "FAIpartitionNr" => _("Partition no."), + "FAIfsType" => _("File system type"), + "FAImountPoint" => _("Mount point"), + "FAIpartitionSize" => _("Partition size"), + "FAImountOptions" => _("Mount options"), + "FAIfsOptions" => _("File system options"), + "FAIencrypted" => _("File system encryption"), + "FAIpartitionFlags" => _("Partition flags")) + )); + } + + +} + +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/gosa-plugins/fai/admin/fai/class_faiProfile.inc b/gosa-plugins/fai/admin/fai/class_faiProfile.inc new file mode 100644 index 000000000..3eaa08b5e --- /dev/null +++ b/gosa-plugins/fai/admin/fai/class_faiProfile.inc @@ -0,0 +1,497 @@ + "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"); + + /* Specific attributes */ + var $old_cn = ""; + 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 $FAIclass = ""; // Classnames used for this profile + var $FAIclasses = array(); // Contains classname seperated in an array + var $FAIAllclasses = array(); // Contains all possible Classnames + var $ui ; + var $FAIstate = ""; + var $view_logged = FALSE; + + function faiProfile(&$config, $dn= NULL) + { + /* Load Attributes */ + plugin::plugin ($config, $dn); + $ldap=$this->config->get_ldap_link(); + + $this->ui = get_userinfo(); + + /* Parse ldap attribute to get all assigned classes */ + $tmp = split(" ",$this->FAIclass); + $tmp2 = array(); + foreach($tmp as $class){ + if(!empty($class)){ + $tmp2[trim($class)] = trim($class); + } + } + + if(isset($this->attrs['FAIstate'][0])){ + $this->FAIstate = $this->attrs['FAIstate'][0]; + } + + /* Sort assigned classes */ + if(is_array($tmp2)){ + foreach($tmp2 as $class){ + $this->FAIclasses[$class]=$class; + } + } + + $categories = array("FAIscript","FAItemplate","FAIhook","FAIvariable","FAIpartitionTable","FAIpackageList"); + + /* Build filter */ + $filter= ""; + foreach ($categories as $cat){ + $filter.= "(objectClass=$cat)"; + } + + /* Get ldap connection */ + $base = session::get('CurrentMainBase'); + $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]; + } + } + } + + /* Sort the sort array */ + //ksort($sort); + + /* Reorder the FAIclasses array */ + foreach($sort as $name){ + $tmp[$name] =$this->FAIAllclasses[$name]; + } + + /* Assign sorted classes */ + $this->FAIAllclasses = array(); + $this->FAIAllclasses = $tmp; + + if($dn != "new"){ + $this->dn =$dn; + } + $this->old_cn = $this->cn; + } + + + /* Combine new array, used for up down buttons */ + function combineArrays($ar0,$ar1,$ar2) + { + $ret = array(); + if(is_array($ar0)) + foreach($ar0 as $ar => $a){ + $ret[$ar]=$a; + } + if(is_array($ar1)) + foreach($ar1 as $ar => $a){ + $ret[$ar]=$a; + } + if(is_array($ar2)) + foreach($ar2 as $ar => $a){ + $ret[$ar]=$a; + } + return($ret); + } + + + function acl_base_for_current_object($dn) + { + if($dn == "new"){ + if($this->dn == "new"){ + $dn = session::get('CurrentMainBase'); + }else{ + $dn = $this->dn; + } + } + return($dn); + } + + + /* returns position in array */ + function getpos($atr,$attrs) + { + $i = 0; + foreach($attrs as $attr => $name) { + $i++; + if($attr == $atr){ + return($i); + } + } + return(-1); + } + + /* Transports the given Arraykey one position up*/ + function ArrayUp($atr,$attrs) + { + $ret = $attrs; + $pos = $this->getpos($atr,$attrs) ; + $cn = count($attrs); + if(!(($pos == -1)||($pos == 1))){ + $before = array_slice($attrs,0,($pos-2)); + $mitte = array_reverse(array_slice($attrs,($pos-2),2)); + $unten = array_slice($attrs,$pos); + $ret = array(); + $ret = $this->combineArrays($before,$mitte,$unten); + } + return($ret); + } + + + /* Transports the given Arraykey one position down*/ + function ArrayDown($atr,$attrs) + { + $ret = $attrs; + $pos = $this->getpos($atr,$attrs) ; + $cn = count($attrs); + if(!(($pos == -1)||($pos == $cn))){ + $before = array_slice($attrs,0,($pos-1)); + $mitte = array_reverse(array_slice($attrs,($pos-1),2)); + $unten = array_slice($attrs,($pos+1)); + $ret = array(); + $ret = $this->combineArrays($before,$mitte,$unten); + } + return($ret); + } + + /* class one position up */ + function catUp($id) + { + /* Get all cats depinding on current dir */ + $cats = $this->FAIclasses; + $this->FAIclasses =$this->ArrayUp($id,$cats); + } + + /* Class one position down */ + function catDown($id) + { + /* Get all cats depinding on current dir */ + $cats = $this->FAIclasses; + $this->FAIclasses =$this->ArrayDown($id,$cats); + } + + function execute() + { + /* Call parent execute */ + plugin::execute(); + + if($this->is_account && !$this->view_logged){ + $this->view_logged = TRUE; + new log("view","fai/".get_class($this),$this->dn); + } + + /* Fill templating stuff */ + $smarty= get_smarty(); + $display= ""; + + $s_entry = ""; + $s_action = ""; + + /* Remove class name From list */ + $sort_once = false; + foreach($_POST as $name => $post){ + if(preg_match("/DEL_/i",$name) && $this->acl_is_writeable("FAIclass")){ + $s_action = "delete"; + $s_entry = preg_replace("/DEL_/","",$name); + $s_entry = base64_decode(preg_replace("/_.*$/","",$s_entry)); + }elseif(preg_match("/Add_class/i",$name)&& $this->acl_is_writeable("FAIclass")){ + $s_action = "add"; + }elseif(preg_match("/DelClass/i",$name) && $this->acl_is_writeable("FAIclass")){ + $s_action = "delete"; + $s_entry = $_POST['FAIclass']; + }elseif(preg_match("/AddClass/i",$name) && $this->acl_is_writeable("FAIclass")){ + $s_action = "add"; + } + + /* Check if a list element should be pushed one position up */ + if((preg_match("/sortup_/",$name))&&(!$sort_once) && $this->acl_is_writeable("FAIclass")){ + $sort_once = true; + $val = preg_replace("/sortup_/","",$name); + $val = preg_replace("/_.*$/","",$val); + $val = base64_decode($val); + $this->catUp($val); + } + + /* Check if a list element should be pushed one position down */ + if((preg_match("/sortdown_/",$name))&&(!$sort_once) && $this->acl_is_writeable("FAIclass")){ + $sort_once = true; + $val = preg_replace("/sortdown_/","",$name); + $val = preg_replace("/_.*$/","",$val); + $val = base64_decode($val); + $this->catDown($val); + } + + } + + if($s_action == "delete" && $this->acl_is_writeable("FAIclass")){ + unset($this->FAIclasses[$s_entry]); + } + + if($s_action == "add" && $this->acl_is_writeable("FAIclass")){ + $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=FALSE; + //ksort($this->FAIclasses); + } + } + + /* Cancel Dialog */ + if(isset($_POST['CancelSubObject'])){ + $this->is_dialog=false; + unset($this->dialog); + $this->dialog=FALSE; + } + + if(is_object($this->dialog)){ + $this->dialog->save_object(); + return($this->dialog->execute()); + } + + $divlist =new divSelectBox("Profile"); + $divlist->SetSummary(_("This list displays all assigned class names for this profile.")); + + /* item images */ + $objTypes['FAIhook'] = ""; + $objTypes['FAItemplate'] = ""; + $objTypes['FAIscript'] = ""; + $objTypes['FAIvariable'] = ""; + $objTypes['FAIpackageList'] = ""; + $objTypes['FAIpartitionTable'] = ""; + + /* Delete button */ + $actions = ""; + + /* Up down buttons */ + $linkupdown = " "; + $linkupdown.= ""; + + /* Append fai classes to divlist */ + if($this->acl_is_readable("FAIclass")){ + foreach($this->FAIclasses as $usedClass){ + $str = " "; + $act = ""; + + 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"=>""); + if(($this->FAIstate != "freeze") && $this->acl_is_writeable("FAIclass")){ + $field3 = array("string"=> preg_replace("/%KEY%/",base64_encode($usedClass),$actions). + preg_replace("/%s/",base64_encode($usedClass),$linkupdown), + "attach"=>"style='border-right:none;'"); + }else{ + $field3 = array("string"=>" ", "attach"=>"style='border-right:none;'"); + } + $divlist->AddEntry(array($field1,$field2,$field3)); + } + } + + $smarty->assign("FAIclasses" ,$this->FAIclasses); + $smarty->assign("divlist" ,$divlist->DrawList()); + + /* 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){ + if(get_magic_quotes_gpc()){ + $smarty->assign($attrs,stripslashes($this->$attrs)); + }else{ + $smarty->assign($attrs,($this->$attrs)); + } + } + + + $dn = $this->acl_base_for_current_object($this->dn); + $smarty->assign("sub_object_is_addable", + preg_match("/c/",$this->ui->get_permissions($dn,"fai/faiScriptEntry")) && + !preg_match("/freeze/",$this->FAIstate)); + + $tmp = $this->plInfo(); + foreach($tmp['plProvidedAcls'] as $name => $translated){ + $smarty->assign($name."ACL",$this->getacl($name)); + } + + $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); + + $faifilter = session::get('faifilter'); + $use_dn = preg_replace("/".normalizePreg(FAI::get_release_dn($this->dn))."/i", $faifilter['branch'], $this->dn); + if($faifilter['branch'] == "main"){ + $use_dn = $this->dn; + } + + new log("remove","fai/".get_class($this),$use_dn,$this->attributes); + FAI::prepare_to_save_FAI_object($use_dn,array(),true); + $this->handle_post_events("remove"); + } + + + /* Save data to object + */ + function save_object() + { + plugin::save_object(); + } + + + /* Check supplied data */ + function check() + { + /* 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(empty($this->cn)){ + $message[]=_("Please enter a valid name."); + } + + $ldap = $this->config->get_ldap_link(); + $faifilter = session::get('faifilter'); + $base = $faifilter['branch']; + if($base == "main"){ + $base = session::get('CurrentMainBase'); + } + $base = get_ou('faiprofileou').$base; + + $ldap->cd($base); + if ($this->old_cn == ""){ + $ldap->ls("(&(objectClass=FAIprofile)(cn=".$this->cn."))",$base,array("*")); + } else { + $ldap->ls("(&(objectClass=FAIprofile)(cn=".$this->cn.")(!cn=".$this->old_cn."))",$base,array("*")); + } + + if($ldap->count() || isset($this->FAIAllclasses[$this->cn])){ + $message[]=_("There is already a FAI object with this class name defined."); + } + + 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); + + FAI::prepare_to_save_FAI_object($this->dn,$this->attrs); + + if($this->initially_was_account){ + new log("modify","fai/".get_class($this),$this->dn,$this->attributes); + }else{ + new log("create","fai/".get_class($this),$this->dn,$this->attributes); + } + + show_ldap_error($ldap->get_error(), sprintf(_("Saving of FAI/profile with dn '%s' failed."),$this->dn)); + } + + + function PrepareForCopyPaste($source) + { + plugin::PrepareForCopyPaste($source); + + /* Parse ldap attribute to get all assigned classes */ + $tmp = split(" ",$this->FAIclass); + $tmp2 = array(); + foreach($tmp as $class){ + if(!empty($class)){ + $tmp2[trim($class)] = trim($class); + } + } + + /* Sort assigned classes */ + if(is_array($tmp2)){ + foreach($tmp2 as $class){ + $this->FAIclasses[$class]=$class; + } + } + } + + + /* Return plugin informations for acl handling */ + static function plInfo() + { + return (array( + "plShortName" => _("Profile"), + "plDescription" => _("FAI profile"), + "plSelfModify" => FALSE, + "plDepends" => array(), + "plPriority" => 30, + "plSection" => array("administration"), + "plCategory" => array("fai"), + "plProvidedAcls" => array( + "cn" => _("Name"), + "description" => _("Description"), + "FAIclass" => _("FAI classes")) + )); + } +} + +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/gosa-plugins/fai/admin/fai/class_faiProfileEntry.inc b/gosa-plugins/fai/admin/fai/class_faiProfileEntry.inc new file mode 100644 index 000000000..8963973e3 --- /dev/null +++ b/gosa-plugins/fai/admin/fai/class_faiProfileEntry.inc @@ -0,0 +1,278 @@ + "Eins ist toll", "zwei" => "Zwei ist noch besser"); + + /* attribute list for save action */ + var $ignore_account= TRUE; + var $attributes = array(); + var $objectclasses= array(); + + /* Array with available class names */ + var $FAIAllclasses = array(); + var $ui; + + function faiProfileEntry (&$config, $dn= NULL,$used=array(),$objects=false) + { + plugin::plugin ($config, $dn); + + /* Search only in fai tree */ + $base = get_ou('faiou').session::get('CurrentMainBase'); + $faifilter = session::get('faifilter'); + if($faifilter['branch']!="main"){ + $base = $faifilter['branch']; + } + + $this->ui = get_userinfo(); + + $filter = "(|(objectClass=FAIscript)(objectClass=FAItemplate)(objectClass=FAIhook)". + "(objectClass=FAIvariable)(objectClass=FAIpartitionTable)(objectClass=FAIpackageList))"; + + $FAI_objects = FAI::get_all_objects_for_given_base($base,$filter,true); + + /* Create array with categories to be able to sort different types of objects */ + $categories = array("FAIscript" => "faiScript", + "FAItemplate" => "faiTemplate", + "FAIhook" => "faiHook", + "FAIvariable" => "faiVariable", + "FAIpartitionTable" => "faiPartitionTable", + "FAIpackageList" => "faiPackageList"); + + /* Read out all objects from fai tree */ + $ldap= $this->config->get_ldap_link(); + $ldap->cd($base); + $sort=array(); + foreach($FAI_objects as $obj){ + + $ldap->cat($obj['dn']); + $attrs = $ldap->fetch(); + + /* Only use objects which have cn set */ + if((isset($attrs['cn'][0]))&&(!in_array($attrs['cn'][0],$used))){ + foreach($categories as $cat => $acl){ + if(in_array($cat,$attrs['objectClass'])){ + + $acl = $this->ui->get_permissions($attrs['dn'],"fai/".$acl); + + /* Append different types of objects */ + $this->FAIAllclasses[$attrs['cn'][0]]['objects'][$cat]=$cat; + + if(!isset($this->FAIAllclasses[$attrs['cn'][0]]['acl'])){ + $this->FAIAllclasses[$attrs['cn'][0]]['acl']=""; + } + $this->FAIAllclasses[$attrs['cn'][0]]['acl'].=$acl; + + /* Set selected status to false */ + $this->FAIAllclasses[$attrs['cn'][0]]['status']=false; + + $sort[strtolower($attrs['cn'][0])] = $attrs['cn'][0]; + } + } + } + } + + + $tmp = array(); + ksort($sort); + foreach($sort as $name){ + $tmp[$name] =$this->FAIAllclasses[$name]; + } + $this->FAIAllclasses = array(); + $this->FAIAllclasses = $tmp; + + /* If no search filter is set, create one */ + if (!session::is_set("SUBfaifilter")){ + $SUBfaifilter= array("base" => get_ou('faiou').session::get('CurrentMainBase'), "Sregex" => "*"); + $SUBfaifilter['SShowTemplates'] = true; + $SUBfaifilter['SShowScripts'] = true; + $SUBfaifilter['SShowHooks'] = true; + $SUBfaifilter['SShowVariables'] = true; + $SUBfaifilter['SShowPackages'] = true; + $SUBfaifilter['SShowPartitions']= true; + session::set("SUBfaifilter", $SUBfaifilter); + } + } + + function execute() + { + /* Call parent execute */ + plugin::execute(); + + /* Fill templating stuff */ + $smarty = get_smarty(); + $display = ""; + + $SUBfaifilter = session::get('SUBfaifilter'); + + /* If someone used the apply button, update searchfilter */ + if(isset($_POST['Sregex'])){ + foreach($SUBfaifilter as $key => $val){ + if(!isset($_POST[$key])){ + $SUBfaifilter[$key] = false; + }else{ + $SUBfaifilter[$key] =$_POST[$key]; + } + } + $SUBfaifilter['Sregex']= $_POST['Sregex']; + if(!strstr($SUBfaifilter['Sregex'],"*")){ + $SUBfaifilter['Sregex'] = $SUBfaifilter['Sregex']."*"; + } + } + + /* Save current searchfilter in session*/ + session::set('SUBfaifilter',$SUBfaifilter); + + /* Check if we used a checkboxe from the list, to select dselect an entry */ + foreach($_POST as $name => $value){ + foreach($this->FAIAllclasses as $class => $obj){ + $bclass = base64_encode($class); + if(isset($_POST["ON_PAGE_".$bclass])){ + if(isset($_POST['USE_'.$bclass])){ + $this->FAIAllclasses[$class]['status']=true; + }else{ + $this->FAIAllclasses[$class]['status']=false; + } + } + } + } + + /* Create different picture for each object type */ + $objTypes['FAIhook'] = " "; + $objTypes['FAItemplate'] = " "; + $objTypes['FAIscript'] = " "; + $objTypes['FAIvariable'] = " "; + $objTypes['FAIpackageList'] = " "; + $objTypes['FAIpartitionTable'] = " "; + + /* 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){ + if(get_magic_quotes_gpc()){ + $smarty->assign($attrs,stripslashes($this->$attrs)); + }else{ + $smarty->assign($attrs,($this->$attrs)); + } + } + + /* Assign all filter attributes to smarty */ + 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); + } + } + + /* Create a divlist to display all available class names with the depending object types */ + $divlist = new divlist("ProfileEntry"); + $divlist->SetPluginMode(); + $divlist->SetSummary(_("This list displays all assigned class names for this profile.")); + $divlist->SetEntriesPerPage(0); + $divlist->SetHeader(array(array("string"=> _("Class name")), + array("string"=> _("Objects"),"attach"=>"style='border-right:0px;'"))); + + /* Action button allows us to delete an entry */ + $action = " + "; + + /* Check every single class name to match the current search filter */ + foreach($this->FAIAllclasses as $usedClass => $classes){ + + /* Skip those entries that we are not allowed to read. */ + if(!preg_match("/r/",$classes['acl'])){ + continue; + } + + $fi = str_replace("*",".*",$SUBfaifilter['Sregex']); + + $abort = true; + if(!preg_match("/".$fi."/",$usedClass)){ + $abort = false; + } + if((isset($classes['objects']['FAIscript']))&&($SUBfaifilter['SShowScripts'])){ + $abort = false; + } + if((isset($classes['objects']['FAItemplate']))&&($SUBfaifilter['SShowTemplates'])){ + $abort = false; + } + if((isset($classes['objects']['FAIhook']))&&($SUBfaifilter['SShowHooks'])){ + $abort = false; + } + if((isset($classes['objects']['FAIvariable']))&&($SUBfaifilter['SShowVariables'])){ + $abort = false; + } + if((isset($classes['objects']['FAIpartitionTable']))&&($SUBfaifilter['SShowPartitions'])){ + $abort = false; + } + if((isset($classes['objects']['FAIpackageList']))&&($SUBfaifilter['SShowPackages'])){ + $abort = false; + } + + if(!$abort){ + $str = ""; + foreach($classes['objects'] as $class => $obj){ + $str.= $objTypes[$obj]; + } + + /* Is this entry selected */ + if($classes['status']==true){ + $action_check = preg_replace("/%CHECK%/"," checked ",$action); + }else{ + $action_check = preg_replace("/%CHECK%/","",$action); + } + + /* Append to list */ + $field1 = array("string"=> str_replace("%KEY%",base64_encode($usedClass),$action_check).$usedClass,"attach"=>""); + $field2 = array("string"=> $str,"attach"=>"style='border-right:0px;'"); + $divlist->AddEntry(array($field1,$field2)); + } + } + + $smarty->assign("faihead" , ""); + $smarty->assign("failist" , $divlist->DrawList()); + $smarty->assign("infoimage" , get_template_path('images/info_small.png')); + $smarty->assign("launchimage" , get_template_path('images/small_filter.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() + { + } + + /* Check supplied data */ + function check() + { + /* Call common method to give check the hook */ + $message= plugin::check(); + + 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/gosa-plugins/fai/admin/fai/class_faiScript.inc b/gosa-plugins/fai/admin/fai/class_faiScript.inc new file mode 100644 index 000000000..2233b6ae6 --- /dev/null +++ b/gosa-plugins/fai/admin/fai/class_faiScript.inc @@ -0,0 +1,645 @@ + "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"); + + /* ObjectClasses for this Object*/ + var $objectclasses = array("top","FAIclass","FAIscript"); + + /* Class name of the Ldap ObjectClass for the Sub Object */ + var $subClass = "FAIscriptEntry"; + var $subClasses = array("top","FAIclass","FAIscriptEntry"); + + /* Class name of the php class which allows us to edit a Sub Object */ + var $subClassName = "faiScriptEntry"; + + /* Attributes to initialise for each subObject */ + var $subAttributes = array("cn","description","FAIpriority"); + var $sub_Load_Later = array("FAIscript"); + var $sub64coded = array(); + var $subBinary = array("FAIscript"); + + /* 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 $SubObjects = array(); // All leafobjects of this object + + var $FAIstate = ""; + var $sort_by = "name"; + var $sort_order = "up"; + + var $view_logged = FALSE; + var $ui; + + function faiScript (&$config, $dn= NULL) + { + /* Load Attributes */ + plugin::plugin ($config, $dn); + + /* If "dn==new" we try to create a new entry + * Else we must read all objects from ldap which belong to this entry. + * First read SubObjects from ldap ... and then the partition definitions for the SubObjects. + */ + if($dn != "new"){ + + $this->dn =$dn; + + /* Get FAIstate + */ + if(isset($this->attrs['FAIstate'][0])){ + $this->FAIstate = $this->attrs['FAIstate'][0]; + } + + /* Read all leaf objects of this object (For FAIscript this would be FAIscriptEntry) + */ + $ldap = $this->config->get_ldap_link(); + $ldap->cd ($this->dn); + + $attrs_to_search = $this->subAttributes; + $attrs_to_search[] = "FAIstate"; + $ldap->search("(&(objectClass=FAIclass)(objectClass=".$this->subClass."))",$attrs_to_search); + + while($object = $ldap->fetch()){ + + /* Skip objects, that are tagged as removed */ + if(isset($object['FAIstate'][0])){ + if(preg_match("/removed$/",$object['FAIstate'][0])){ + continue; + } + } + + /* Set status for save management */ + $objects = array(); + $objects['status'] = "FreshLoaded"; + $objects['dn'] = $object['dn']; + $objects = $this->get_object_attributes($objects,$this->subAttributes); + $this->SubObjects[$objects['cn']] = $objects; + } + + } + $this->ui = get_userinfo(); + } + + + /* Reload some attributes */ + function get_object_attributes($object,$attributes) + { + $ldap = $this->config->get_ldap_link(); + $ldap->cd($this->config->current['BASE']); + $ldap->cat($object['dn'],$attributes); + $tmp = $ldap->fetch(); + + foreach($attributes as $attrs){ + if(isset($tmp[$attrs][0])){ + $var = $tmp[$attrs][0]; + + /* Check if we must decode some attributes */ + if(in_array_ics($attrs,$this->sub64coded)){ + $var = base64_decode($var); + } + + /* check if this is a binary entry */ + if(in_array_ics($attrs,$this->subBinary)){ + $var = $ldap->get_attribute($object['dn'], $attrs,$r_array=0); + } + + /* Fix slashes */ + $var = addslashes($var); + $object[$attrs] = $var; + } + } + return($object); + } + + + /* Return a valid dn to fetch acls. Because 'new' will not work. */ + function acl_base_for_current_object($dn) + { + if($dn == "new"){ + if($this->dn == "new"){ + $dn= "cn=dummy,".session::get('CurrentMainBase'); + }else{ + $dn = $this->dn; + } + } + return($dn); + } + + + function execute() + { + /* Call parent execute */ + plugin::execute(); + + if($this->is_account && !$this->view_logged){ + $this->view_logged = TRUE; + new log("view","fai/".get_class($this),$this->dn); + } + + /* Fill templating stuff */ + $smarty= get_smarty(); + $display= ""; + + /* Add new sub object */ + if(isset($_POST['AddSubObject'])){ + $this->dialog= new $this->subClassName($this->config,"new"); + $this->dialog->set_acl_base($this->acl_base); + $this->dialog->set_acl_category("fai"); + $this->dialog->parent = &$this; + $this->is_dialog=true; + } + + if($this->dn != "new"){ + session::set('objectinfo',$this->dn); + } + + /* Handle posts */ + $s_action = $s_entry = ""; + foreach($_POST as $name => $value){ + + /* Edit script posted */ + if(preg_match("/^editscript_/",$name)){ + $s_action = "edit"; + $s_entry = preg_replace("/^editscript_/","",$name); + $s_entry = base64_decode(preg_replace("/_.*/","",$s_entry)); + break; + } + + /* Delete script requested */ + if(preg_match("/^deletescript_/",$name)){ + $s_action = "remove"; + $s_entry = preg_replace("/^deletescript_/","",$name); + $s_entry = base64_decode(preg_replace("/_.*/","",$s_entry)); + break; + } + } + + if(isset($_GET['act']) && $_GET['act'] == "edit" && isset($_GET['id'])){ + $s_entry = $_GET['id']; + if(isset($this->SubObjects[$s_entry])){ + $s_action = "edit"; + } + } + + if($s_action =="edit" && isset($this->SubObjects[$s_entry])){ + + /* Get object, and load missing entry values */ + $obj = $this->SubObjects[$s_entry]; + if($obj['status'] == "FreshLoaded"){ + $obj = $this->get_object_attributes($obj,$this->sub_Load_Later); + } + + /* Create new dialog and set acl attributes */ + $this->dialog= new $this->subClassName($this->config,$this->dn,$obj); + $this->dialog->set_acl_base($this->acl_base_for_current_object($obj['dn'])); + $this->dialog->set_acl_category("fai"); + + /* Assign some additional dialog informations like headline and parent */ + session::set('objectinfo',$obj['dn']); + $this->dialog->parent = &$this; + $this->is_dialog=true; + } + + /* Check acls, are we allowed to delete an entry */ + if($s_action == "remove" && isset($this->SubObjects[$s_entry])){ + $entry = $this->SubObjects[$s_entry]; + $acl = $this->ui->get_permissions($this->acl_base_for_current_object($entry['dn']),"fai/faiScriptEntry") ; + if(preg_match("/d/",$acl)){ + $status = $entry['status']; + if($status == "edited" || $status == "FreshLoaded"){ + $this->SubObjects[$s_entry]['status']= "delete"; + }else{ + unset($this->SubObjects[$s_entry]); + } + } + } + + /* Save the edited entry */ + if(isset($_POST['SaveSubObject'])){ + + /* Check if there are still errors remaining that must be fixed before saving */ + $this->dialog->save_object(); + $msgs = $this->dialog->check(); + if(count($msgs)>0){ + foreach($msgs as $msg){ + print_red($msg); + } + }else{ + + /* Get return object */ + $obj = $this->dialog->save(); + + /* If we have renamed the script entry, we must remove the old entry */ + if(isset($obj['remove'])){ + + /* Get old entry values */ + $old_stat = $this->SubObjects[$obj['remove']['from']]['status']; + + /* Depending on status, set new status */ + if($old_stat == "edited" || $old_stat == "FreshLoaded"){ + $this->SubObjects[$obj['remove']['from']]['status'] = "delete"; + }elseif($this->SubObjects[$obj['remove']['from']]['status']=="new"){ + unset($this->SubObjects[$obj['remove']['from']]); + } + + /* Append the new entry */ + $obj['status'] = "new"; + $this->SubObjects[$obj['remove']['to']] = $obj; + unset($this->SubObjects[$obj['remove']['to']]['remove']); + }else{ + + /* Set new status and append the entry */ + if($obj['status'] == "FreshLoaded"){ + $obj['status'] = "edited"; + } + $this->SubObjects[$obj['cn']]=$obj; + } + $this->is_dialog=false; + unset($this->dialog); + $this->dialog=FALSE; + + } + } + + /* Sort entries */ + $tmp = $keys = array(); + + if($this->sort_by == "name"){ + foreach($this->SubObjects as $key => $entry){ + $keys[$key]=$entry['cn']; + } + }elseif($this->sort_by == "priority"){ + foreach($this->SubObjects as $key => $entry){ + $keys[$key]=$entry['FAIpriority']; + } + } + + natcasesort($keys); + + if($this->sort_order == "down"){ + $keys =array_reverse($keys); + } + + foreach($keys as $key => $order_var){ + $tmp[$key]=$this->SubObjects[$key]; + } + $this->SubObjects = $tmp; + + /* Cancel Dialog */ + if(isset($_POST['CancelSubObject'])){ + $this->is_dialog=false; + unset($this->dialog); + $this->dialog=FALSE; + } + + /* Print dialog if $this->dialog is set */ + if(is_object($this->dialog)){ + $this->dialog->save_object(); + $display = $this->dialog->execute(); + return($display); + } + + /* Divlist added 23.02.2006 + Containing FAIscripts + */ + $divlist = new divlist("FAIscripts"); + $divlist->SetEntriesPerPage(0); + $plug = $_GET['plug']; + + if($this->sort_order == "up"){ + $dir = "\/"; + }else{ + $dir = "/\"; + } + + if($this->sort_by == "name"){ + $sort_name = $dir; + $sort_prio = ""; + }else{ + $sort_name = ""; + $sort_prio = $dir; + } + + $divlist->SetHeader(array( array("string"=>""._("Name").$sort_name.""), + array("string"=>"".$sort_prio._("Priority")."", + "attach"=>"style='width:100px;'"), + array("string"=>_("Download"), + "attach"=>"style='width:100px;'"), + array("string"=>_("Action"), + "attach"=>"style='border-right: 0px;width:100px;text-align:right;'"))); + $divlist->SetHeight(300); + $divlist->SetWidth("100%"); + foreach($this->getList(true) as $key => $name){ + + $dn= $this->acl_base_for_current_object($name['dn']); + $acl = $this->ui->get_permissions($dn,"fai/faiScriptEntry") ; + $act = ""; + + /* Hide delete icon if this object is freezed */ + if($this->FAIstate == "freeze"){ + $act .= ""; + }else{ + $act .= ""; + if(preg_match("/d/",$acl)){ + $act .=""; + } + } + + /* Check acls for download icon */ + $s_acl = $this->ui->get_permissions($dn,"fai/faiScriptEntry","FAIscript") ; + if(($this->SubObjects[$key]['status'] == "new") || ($this->SubObjects[$key]['dn'] == "new") || !preg_match("/r/",$s_acl)){ + $down = ""; + }else{ + $down = " + "._("Download")." + "; + } + + /* Check if we are allowed to view this object */ + $s_acl = $this->ui->get_permissions($dn,"fai/faiScriptEntry","cn") ; + if(preg_match("/r/",$s_acl)){ + $divlist->AddEntry(array( array("string"=>"".$name['name'].""), + array("string"=>$name['FAIpriority'] , "attach" => "style='width:100px;'"), + array("string"=>$down , "attach" => "style='width:100px;'"), + array("string"=>str_replace("%s",base64_encode($key),$act), + "attach"=>"style='border-right: 0px;width:100px;text-align:right;'"))); + } + } + $smarty->assign("Entry_divlist",$divlist->DrawList()); + + + /* 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){ + if(get_magic_quotes_gpc()){ + $smarty->assign($attrs,stripslashes($this->$attrs)); + }else{ + $smarty->assign($attrs,($this->$attrs)); + } + } + + $dn = $this->acl_base_for_current_object($this->dn); + $smarty->assign("sub_object_is_addable", + preg_match("/c/",$this->ui->get_permissions($dn,"fai/faiScriptEntry")) && + !preg_match("/freeze/",$this->FAIstate)); + + $tmp = $this->plInfo(); + foreach($tmp['plProvidedAcls'] as $name => $translated){ + $smarty->assign($name."ACL",$this->getacl($name)); + } + + $display.= $smarty->fetch(get_template_path('faiScript.tpl', TRUE)); + return($display); + } + + /* Generate listbox friendly SubObject list + */ + function getList($use_dns=false){ + $a_return=array(); + foreach($this->SubObjects as $obj){ + if($obj['status'] != "delete"){ + if($use_dns){ + if((isset($obj['description']))&&(!empty($obj['description']))){ + $a_return[$obj['cn']]['name']= $obj['cn']." [".stripslashes($obj['description'])."]"; + }else{ + $a_return[$obj['cn']]['name']= $obj['cn']; + } + $a_return[$obj['cn']]['dn']= $obj['dn']; + $a_return[$obj['cn']]['FAIpriority']= $obj['FAIpriority']; + }else{ + if((isset($obj['description']))&&(!empty($obj['description']))){ + $a_return[$obj['cn']]= $obj['cn']." [".stripslashes($obj['description'])."]"; + }else{ + $a_return[$obj['cn']]= $obj['cn']; + } + } + } + } + return($a_return); + } + + /* Delete me, and all my subtrees + */ + function remove_from_parent() + { + if($this->acl_is_removeable()){ + $ldap = $this->config->get_ldap_link(); + $ldap->cd ($this->dn); + $faifilter = session::get('faifilter'); + $use_dn = preg_replace("/".normalizePreg(FAI::get_release_dn($this->dn))."/i", $faifilter['branch'], $this->dn); + if($faifilter['branch'] == "main"){ + $use_dn = $this->dn; + } + + new log("remove","fai/".get_class($this),$use_dn,$this->attributes); + + FAI::prepare_to_save_FAI_object($use_dn,array(),true); + + foreach($this->SubObjects as $name => $obj){ + $use_dn = preg_replace("/".normalizePreg(FAI::get_release_dn($this->dn))."/i", $faifilter['branch'], $obj['dn']); + if($faifilter['branch'] == "main"){ + $use_dn = $obj['dn']; + } + FAI::prepare_to_save_FAI_object($use_dn,array(),true); + } + $this->handle_post_events("remove"); + } + } + + + /* Save data to object + */ + function save_object() + { + if((isset($_POST['FAIscript_posted'])) && ($this->FAIstate != "freeze")){ + plugin::save_object(); + foreach($this->attributes as $attrs){ + if(isset($_POST[$attrs])){ + $this->$attrs = $_POST[$attrs]; + } + } + } + + /* Get sort order */ + if(isset($_GET['sort']) && in_array($_GET['sort'],array("name","priority"))){ + if($this->sort_by == $_GET['sort']){ + if($this->sort_order == "up"){ + $this->sort_order = "down"; + }elseif($this->sort_order == "down"){ + $this->sort_order = "up"; + } + } + $this->sort_by = $_GET['sort']; + } + } + + + /* Check supplied data */ + function check() + { + /* Call common method to give check the hook */ + $message= plugin::check(); + + return ($message); + } + + + /* Save to LDAP */ + function save() + { + plugin::save(); + + $ldap = $this->config->get_ldap_link(); + + FAI::prepare_to_save_FAI_object($this->dn,$this->attrs); + show_ldap_error($ldap->get_error(), sprintf(_("Creating of FAI/script with dn '%s' failed."),$this->dn)); + + if($this->initially_was_account){ + new log("modify","fai/".get_class($this),$this->dn,$this->attributes); + }else{ + new log("create","fai/".get_class($this),$this->dn,$this->attributes); + } + + /* Prepare FAIscriptEntry to write it to ldap + * First sort array. + * Because we must delete old entries first. + * After deletion, we perform add and modify + */ + $Objects = array(); + + /* We do not need to save untouched objects */ + foreach($this->SubObjects as $name => $obj){ + if($obj['status'] == "FreshLoaded"){ + unset($this->SubObjects[$name]); + } + } + + foreach($this->SubObjects as $name => $obj){ + if($obj['status'] == "delete"){ + $Objects[$name] = $obj; + } + } + foreach($this->SubObjects as $name => $obj){ + if($obj['status'] != "delete"){ + $Objects[$name] = $obj; + } + } + + foreach($Objects as $name => $obj){ + + foreach($this->sub64coded as $codeIt){ + $obj[$codeIt]=base64_encode(stripslashes($obj[$codeIt])); + } + + $tmp = array(); + $attributes = array_merge($this->sub_Load_Later,$this->subAttributes); + foreach($attributes as $attrs){ + + if(empty($obj[$attrs])){ + $obj[$attrs] = array(); + } + if(!is_array($obj[$attrs])){ + $tmp[$attrs] = stripslashes($obj[$attrs]); + }else{ + $tmp[$attrs] = $obj[$attrs]; + } + } + + $tmp['objectClass'] = $this->subClasses; + + $sub_dn = "cn=".$obj['cn'].",".$this->dn; + + if($obj['status']=="new"){ + $ldap->cat($sub_dn,array("objectClass")); + if($ldap->count()){ + $obj['status']="edited"; + } + } + + if(empty($tmp['FAIpriority'])){ + $tmp['FAIpriority'] ="0"; + } + + /* Tag object */ + $this->tag_attrs(&$tmp, $sub_dn, $this->gosaUnitTag); + + if($obj['status'] == "delete"){ + FAI::prepare_to_save_FAI_object($sub_dn,array(),true); + $this->handle_post_events("remove"); + }elseif($obj['status'] == "edited"){ + FAI::prepare_to_save_FAI_object($sub_dn,$tmp); + $this->handle_post_events("modify"); + }elseif($obj['status']=="new"){ + FAI::prepare_to_save_FAI_object($sub_dn,$tmp); + $this->handle_post_events("add"); + } + } + } + + + function PrepareForCopyPaste($source) + { + plugin::PrepareForCopyPaste($source); + + /* Read all leaf objects of this object (For FAIscript this would be FAIscriptEntry) + */ + $ldap = $this->config->get_ldap_link(); + $ldap->cd ($source['dn']); + + $attrs_to_search = $this->subAttributes; + $attrs_to_search[] = "FAIstate"; + $ldap->search("(&(objectClass=FAIclass)(objectClass=".$this->subClass."))",$attrs_to_search); + + while($object = $ldap->fetch()){ + + /* Skip objects, that are tagged as removed */ + if(isset($object['FAIstate'][0])){ + if(preg_match("/removed$/",$object['FAIstate'][0])){ + continue; + } + } + + /* Set status for save management */ + $objects = array(); + $objects['status'] = "edited"; + $objects['dn'] = $object['dn']; + $objects = $this->get_object_attributes($objects,$this->subAttributes); + $objects = $this->get_object_attributes($objects,$this->sub_Load_Later); + + $this->SubObjects[$objects['cn']] = $objects; + } + } + + + /* Return plugin informations for acl handling */ + static function plInfo() + { + return (array( + "plShortName" => _("Script"), + "plDescription" => _("FAI script"), + "plSelfModify" => FALSE, + "plDepends" => array(), + "plPriority" => 18, + "plSection" => array("administration"), + "plCategory" => array("fai"), + "plProvidedAcls" => array( + "cn" => _("Name")." ("._("Readonly").")", + "description" => _("Description")) + )); + } +} + +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/gosa-plugins/fai/admin/fai/class_faiScriptEntry.inc b/gosa-plugins/fai/admin/fai/class_faiScriptEntry.inc new file mode 100644 index 000000000..032132920 --- /dev/null +++ b/gosa-plugins/fai/admin/fai/class_faiScriptEntry.inc @@ -0,0 +1,198 @@ + "Eins ist toll", "zwei" => "Zwei ist noch besser"); + + /* attribute list for save action */ + var $ignore_account= TRUE; + var $attributes = array("cn","description","FAIpriority","FAIscript"); + var $objectclasses= array(); + + var $orig_cn = ""; + + var $dn = ""; + var $cn = ""; + var $FAIpriority = "0"; + var $FAIscript = ""; + var $description = ""; + var $status = "new"; + var $parent = NULL; + var $FAIstate = ""; + + function faiScriptEntry (&$config, $dn= NULL,$object=false) + { + plugin::plugin ($config, $dn); + if($dn != "new"){ + $this->orig_cn= $object['cn']; + $this->dn=$object['dn']; + foreach($object as $name=>$value){ + $oname = $name; + $this->$oname=$value; + } + + if(isset($this->attrs['FAIstate'][0])){ + $this->FAIstate = $this->attrs['FAIstate'][0]; + } + + }else{ + if(is_array($object)&&count($object)){ + $this->orig_cn= $object['cn']; + $this->dn=$object['dn']; + foreach($object as $name=>$value){ + $oname = $name; + $this->$oname=$value; + } + }else{ + + $this->status = "new"; + $this->orig_cn = false; + } + } + } + + function execute() + { + /* Call parent execute */ + plugin::execute(); + + /* Fill templating stuff */ + $smarty = get_smarty(); + $display = ""; + + if(isset($_POST['ImportUpload']) && $this->acl_is_writeable("FAIscript")){ + if(($_FILES['ImportFile']['error']!=0)){ + print_red(_("Please select a valid file.")); + }else + if(($_FILES['ImportFile']['size']==0)){ + print_red(_("Selected file is empty.")); + }else{ + $str = utf8_encode(addslashes(file_get_contents($_FILES['ImportFile']['tmp_name']))); + $this->FAIscript = $str; + } + } + + foreach($this->attributes as $attrs){ + if(get_magic_quotes_gpc()){ + $smarty->assign($attrs,stripslashes($this->$attrs)); + }else{ + $smarty->assign($attrs,($this->$attrs)); + } + } + + /* Create download button*/ + if($this->dn != "new" && $this->acl_is_readable("FAIscript")){ + $smarty->assign("DownMe"," + + "); + }else{ + $smarty->assign("DownMe",""); + } + + for($i =0 ; $i < 100 ; $i++){ + $FAIprioritys[$i]=$i; + } + + $tmp = $this->plInfo(); + foreach($tmp['plProvidedAcls'] as $name => $translated){ + $acl = $this->getacl($name); + if($this->FAIstate == "freezed"){ + $acl = preg_replace("/w/","",$acl); + } + $smarty->assign($name."ACL",$acl); + } + + $smarty->assign("FAIprioritys",$FAIprioritys); + if(get_magic_quotes_gpc()){ + $smarty->assign("FAIscript" , htmlentities(stripslashes($this->FAIscript))); + }else{ + $smarty->assign("FAIscript" , htmlentities($this->FAIscript)); + } + $display.= $smarty->fetch(get_template_path('faiScriptEntry.tpl', TRUE)); + return($display); + } + + /* Save data to object */ + function save_object() + { + if((isset($_POST['SubObjectFormSubmitted'])) && ($this->FAIstate != "freeze")){ + foreach($this->attributes as $attrs){ + if($this->acl_is_writeable($attrs)){ + if(isset($_POST[$attrs])){ + $this->$attrs = $_POST[$attrs]; + }else{ + $this->$attrs = ""; + } + } + } + } + } + + /* Check supplied data */ + function check() + { + /* Call common method to give check the hook */ + $message= plugin::check(); + + if(isset($this->parent->SubObjects[$this->cn]) && $this->cn != $this->orig_cn){ + $message[] =_("There is already a script with the given name."); + } + + if(empty($this->cn)){ + $message[] = _("Please enter a name."); + } + + if(empty($this->FAIscript)){ + $message[]=_("Please enter a script."); + } + + return ($message); + } + + function save() + { + $tmp=array(); + foreach($this->attributes as $attrs){ + $tmp[$attrs] = $this->$attrs; + } + + /* Strip out dos newlines */ + $tmp['FAIscript']= strtr($this->FAIscript, array("\x0D" => "")); + + if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){ + $tmp['remove']['from'] = $this->orig_cn; + $tmp['remove']['to'] = $tmp['cn']; + } + + $tmp['dn'] = $this->dn; + $tmp['status'] = $this->status; + return($tmp); + } + + + /* Return plugin informations for acl handling */ + static function plInfo() + { + return (array( + "plShortName" => _("Script entry"), + "plDescription" => _("FAI script entry"), + "plSelfModify" => FALSE, + "plDepends" => array(), + "plPriority" => 19, + "plSection" => array("administration"), + "plCategory" => array("fai"), + "plProvidedAcls" => array( + "cn" => _("Name"), + "description" => _("Description"), + "FAIscript" => _("Script entry"), + "FAIpriority" => _("Script Priority")) + )); + } + + +} +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/gosa-plugins/fai/admin/fai/class_faiSummaryTab.inc b/gosa-plugins/fai/admin/fai/class_faiSummaryTab.inc new file mode 100644 index 000000000..f2bdd51f1 --- /dev/null +++ b/gosa-plugins/fai/admin/fai/class_faiSummaryTab.inc @@ -0,0 +1,582 @@ +ui = get_userinfo(); + + /* Base object configuration */ + $this->objs = array( + "FAIscript" => array( "Image" =>"images/fai_script.png", "Name"=>_("Scripts") ,"Tree" =>get_ou('faiscriptou')) , + "FAIhook" => array( "Image" =>"images/fai_hook.png" , "Name"=>_("Hooks") ,"Tree" =>get_ou('faihookou')), + "FAIvariable" => array( "Image" =>"images/fai_variable.png", "Name"=>_("Variables") ,"Tree" =>get_ou('faivariableou')) , + "FAItemplate" => array( "Image" =>"images/fai_template.png", "Name"=>_("Templates") ,"Tree" =>get_ou('faitemplateou')) , + "FAIpartitionTable" => array( "Image" =>"images/fai_partitionTable.png","Name"=>_("Partition table") ,"Tree" =>get_ou('faipartitionou')) , + "FAIpackageList" => array( "Image" =>"images/fai_packages.png", "Name"=>_("Package list") ,"Tree" =>get_ou('faipackageou')) , + "FAIprofile" => array( "Image" =>"images/fai_profile.png", "Name"=>_("Profiles") ,"Tree" =>get_ou('faiprofileou'))); + } + + + /* Init the fai tree with objects. + If this method is called, all assigned classes and the release name + will be read from parent object. */ + function init() + { + $this->InitCalled = true; + $this->Result = array(); + + /* Get classes & release name + There are 2 different tabs which use the summary tab + faiProfile / Workstations */ + + /* Check if given parent object is fai profile tabs */ + if(isset($this->parent->by_name['faiProfile'])){ + + /* Get Classes and release */ + $this->Classes = $this->parent->by_object['faiProfile']->FAIclasses; + $this->base = $this->parent->by_object['faiProfile']->base; + $str = preg_replace("/^.*".normalizePreg(get_ou('faiprofileou'))."/","",$this->dn); + + /* Check if parent tab is work tab */ + }elseif(isset($this->parent->by_name['workstartup'])){ + $this->Classes = $this->parent->by_object['workstartup']->FAIclass; + $this->Release = $this->parent->by_object['workstartup']->FAIrelease; + + /* Check if this is a workstation or an object group */ + if(isset($this->parent->by_object['workgeneric'])){ + $this->base = $this->parent->by_object['workgeneric']->base; + }elseif(isset($this->parent->by_object['ogroup'])){ + $this->base = $this->parent->by_object['ogroup']->base; + }elseif(isset($this->parent->by_object['servgeneric'])){ + $this->base = $this->parent->by_object['servgeneric']->base; + }else{ + print_red(_("Unknown type of FAI source information. This is not a profile, workstation nor a ogroup.")); + } + + /* Append workstation class && LAST */ + if(isset($this->parent->by_object['workgeneric']->cn)){ + $this->Classes[] = $this->parent->by_object['workgeneric']->cn; + } + } + + $tmp = array_flip($this->getBranches()); + + $this->Classes[] = "LAST"; + + /* You need full access to complete collection of fai acls to view this summary */ + $acl = $this->ui->has_complete_category_acls($this->base,"fai"); + if(!preg_match("/r/",$acl)){ + $this->Classes = array(); + } + + /* Set all available releases */ + $this->Releases = $tmp; + $this->usedClasses = array(); + + /* Check the configuration */ + if(count($this->Classes) && (!empty($this->Release))){ + foreach($this->Classes as $class){ + $this->resolveObject($class); + } + } + } + + + /* Capture posts, and call opnen close tag */ + function save_object() + { + $once = true; + + if(isset($_GET['expand']) && isset($_GET['id'])){ + if(isset($this->Result[$_GET['id']])){ + $this->Result[$_GET['id']]['Open'] =true ; + } + } + + if(isset($_GET['compress']) && isset($_GET['id'])){ + if(isset($this->Result[$_GET['id']])){ + unset($this->Result[$_GET['id']]['Open']); + } + } + + foreach($_POST as $name => $value ){ + + /* check for open tag request */ + if(preg_match("/^open_/",$name) && $once){ + $once = false; + $value = preg_replace("/^open_/","",$name); + $value = preg_replace("/_.*$/","",$value); + $this->Result[$value]['Open'] =true ; + } + /* Check for close tag request */ + if(preg_match("/^close_/",$name) && $once){ + $once = false; + $value = preg_replace("/^close_/","",$name); + $value = preg_replace("/_.*$/","",$value); + unset($this->Result[$value]['Open']); + } + if(preg_match("/^reloadList/",$name)){ + $this->InitCalled = false; + } + } + } + + + /* returns an array with all possibly release types */ + function getBranches($base = false,$prefix = "") + { + if(!$base){ + $base = $this->base; + } + return(FAI::get_all_releases_from_base($base,true)); + } + + + /* This function calls all nescessary functions to generate the fai class summary tree */ + function execute() + { + + /* Skip this if fai is deactivated */ + $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs')); + if(empty($tmp)){ + $str = "

"._("You can't use this plugin until FAI is activated.")."

"; + return $str; + } + + /* Check if we must (re)init the this tab */ + if(!$this->InitCalled){ + $this->init(); + } + + if(isset($_GET['show'])){ + $ldap = $this->config->get_ldap_link(); + $ldap->cat(base64_decode($_GET['id']), array('FAIscript', 'FAIhook', 'FAItemplateFile')); + $attrs = $ldap->fetch(); + if($_GET['type'] == "FAIscript"){ + $str = $attrs['FAIscript'][0]; + }elseif($_GET['type'] == "FAIhook"){ + $str = $attrs['FAIscript'][0]; + }elseif($_GET['type'] == "FAItemplate"){ + $str = $attrs['FAItemplateFile'][0]; + } + echo "
".$str."
"; + exit(); + } + + /* Get smarty class & assign created summary results */ + $smarty = get_smarty(); + $acl = $this->ui->has_complete_category_acls($this->base,"fai"); + $smarty->assign("readable", preg_match("/r/",$acl)); + + $this->ObjectList = $this->createSummary($this->Result); + $smarty->assign("objectList",$this->ObjectList); + return($smarty->fetch (get_template_path('faiSummary.tpl', TRUE, dirname(__FILE__)))); + } + + + /* Create output of from resolved fai objects */ + function createSummary($data) + { + /* Don't generate any output, if there is no result */ + $str =" "; + if(!count($this->Result)){ + $str.="
"; + $str.= (_("This object has no FAI classes assigned.")); + $str.= "
"; + return($str); + } + + /* walk through all classes */ + foreach($data as $key => $entry){ + + $image = "".$this->objs[$key]["; + if(!isset($entry['Open'])){ + $str .= " + + + "._("Open")." "; + $str .= $image." "; + $str .= " ".$this->objs[$key]['Name'].""; + }else{ + $str .= " + + "._("Close")." "; + $str .= $image." "; + $str .= "".$this->objs[$key]['Name'].""; + + /* Display FAItemplate FAIhook FAIscript entries */ + if(in_array($key,array("FAItemplate","FAIhook","FAIscript"))){ + + $nums = array(); + $tmp = array(); + if($key == "FAIscript"){ + if(is_array($entry['Entries'])){ + foreach($entry['Entries'] as $scripts){ + foreach($scripts as $script){ + + if(!isset($nums[$script['cn'][0]])){ + $nums[$script['cn'][0]]= 0; + } + $nums[$script['cn'][0]] ++; + + $tmp[$script['FAIpriority'][0].$script['cn'][0].$script['CLASS']] = $script; + } + } + } + krsort($tmp);; + + $entry['Entries'] = $tmp; + }else{ + $tmp = array(); + foreach($entry['Entries'] as $script){ + $tmp[$script['cn'][0].$script['CLASS']] = $script; + if(!isset($nums[$script['cn'][0]])){ + $nums[$script['cn'][0]]= 0; + } + $nums[$script['cn'][0]] ++; + } + ksort($tmp); + $entry['Entries'] = $tmp; + } + + foreach($entry['Entries'] as $cn => $data){ + + if(isset($nums[$data['cn'][0]]) && ($nums[$data['cn'][0]] > 1)){ + $str .=""; + }else{ + $str .=""; + } + + $str .= ""; + $str .= $image." "; + if(isset($data['FAIpriority'][0])){ + $str .= "(".$data['FAIpriority'][0].")"; + } + + $str .= " ".$data['cn'][0]; + if(isset($data['description'][0])){ + $str .= " [".$data['description'][0]."]"; + } + $str .= ""; + $str .= "".$data['CLASS'].""; + $str .= ""; + } + } + + /* Create variable entries */ + if(in_array($key,array("FAIvariable"))) { + foreach($entry['Entries'] as $cn => $data){ + $str .=""; + $str .= $image." ".$data['cn'][0]; + if(isset($data['description'][0])){ + $str .= " [".$data['description'][0]."] "; + } + /* Only display FAIvariableContent if description dosn't contain [*] */ + if(isset($data['description'][0]) && !preg_match("#\[\*\]#",$data['description'][0])){ + $str .=" = '".$data['FAIvariableContent'][0]."'"; + } + $str .= "".$data['CLASS'].""; + $str .=""; + } + } + + /* Create packagelist entries */ + if(in_array($key,array("FAIpackageList"))) { + ksort($entry['Entries']); + foreach($entry['Entries'] as $data){ + $str .=""; + $str .= $image." ".$data['cn'][0]; + $str .= "".$data['CLASS'].""; + $str .= "";; + } + } + + /* Create partition table entries */ + if(in_array($key,array("FAIpartitionTable"))) { + foreach($entry['Entries'] as $cn => $data){ + $str .= ""; + $str .= $image." ".$data['name']; + $str .= "".$data['CLASS'].""; + $str .= ""; + ksort($data['partitions']); + + $str .= ""; + $str .= " + + + + + + + + + "; + + $i = 0; + foreach($data['partitions'] as $key => $part){ + $i ++; + + if($i%2 == 1){ + $c = " class='rowxp1'"; + $d = " class='list1'"; + }else{ + $c = " class='rowxp0'"; + $d = " class='list0'"; + } + + $str.=" + + + + + + + + "; + } + $str .="
"._("No.").""._("Name").""._("FS options").""._("Mount options").""._("Size in MB").""._("Mount point").""._("Type")."
".$i."".$part['cn'][0]."".$part['FAIfsType'][0]."".$part['FAIfsOptions'][0]."".$part['FAIpartitionSize'][0]."".$part['FAImountPoint'][0]."".$part['FAIpartitionType'][0]."
"; + } + } + } + } + $str .=""; + return($str); + } + + + /* resolve specified object to append it to our object tree */ + function resolveObject($class) + { + $ldap = $this->config->get_ldap_link(); + $dn = $this->Releases [$this->Release]; + $resolvedClasses = FAI::get_all_objects_for_given_base($dn,"(&(objectClass=FAIclass)(cn=".$class."))"); + + /* Try to fetch all types of fai objects with the given cn */ + foreach($resolvedClasses as $obj){ + + $dn = $obj['dn']; + $ldap->cat($dn); + + while($attrs = $ldap->fetch()){ + + foreach($this-> objs as $key => $rest){ + if(in_array($key,$attrs['objectClass'])){ + + if(!isset($this->usedClasses[$key][$class])){ + $this->usedClasses[$key][$class] = true; + switch($key){ + case "FAIprofile": $this->prepare_FAIprofile($attrs);break; + case "FAIscript": $this->prepare_FAIscript($attrs);break; + case "FAIhook": $this->prepare_FAIhook($attrs);break; + case "FAIvariable": $this->prepare_FAIvariable($attrs);break; + case "FAItemplate": $this->prepare_FAItemplate($attrs);break; + case "FAIpackageList": $this->prepare_FAIpackageList($attrs);break; + case "FAIpartitionTable": $this->prepare_FAIpartitionTable($attrs);break; + } + } + + } + } + } + } + } + + /* Prepare fai script */ + function prepare_FAIscript($data) + { + if(isset($this->Result['FAIscript']['Entries'])){ + $current = $this->Result['FAIscript']['Entries']; + }else{ + $current = array(); + } + $ldap = $this->config->get_ldap_link(); + $ldap->cd($data['dn']); + $ldap->search("(objectClass=FAIscriptEntry)",array("cn","description","FAIpriority")); + while($attrs = $ldap->fetch()){ + $attrs['CLASS'] = $data['cn'][0]; + $current[$attrs['FAIpriority'][0]][] = $attrs; + } + $this->Result['FAIscript']['Entries'] = $current ; + } + + + /* Prepare fai script */ + function prepare_FAIpartitionTable($data) + { + if(isset($this->Result['FAIpartitionTable']['Entries'])){ + $current = $this->Result['FAIpartitionTable']['Entries']; + }else{ + $current = array(); + } + + /* get subentries */ + $ldap = $this->config->get_ldap_link(); + $ldap->cd($data['dn']); + $ldap->search("(objectClass=FAIpartitionDisk)",array("cn","description")); + $disks = array(); + + /* Create an array which is sortable by priority */ + while($attrs = $ldap->fetch()){ + $attrs['CLASS'] = $data['cn'][0]; + $disks[$attrs['cn'][0]]= $attrs; + if(isset($attrs['description'][0])){ + $disks[$attrs['cn'][0]]['name'] = $attrs['cn'][0]." [".$attrs['description'][0]."]"; + }else{ + $disks[$attrs['cn'][0]]['name'] = $attrs['cn'][0]; + } + $disks[$attrs['cn'][0]]['dn'] = $attrs['dn']; + $disks[$attrs['cn'][0]]['partitions'] = array(); + } + + /* Sort by priority */ + foreach($disks as $key => $disk){ + $ldap->cd($disk['dn']); + $ldap->search("(objectClass=FAIpartitionEntry)",array("*")); + while($attrs = $ldap->fetch()){ + if(!isset($attrs['FAIfsOptions'][0])){ + $attrs['FAIfsOptions'][0] = ""; + } + $attrs['CLASS'] = $data['cn'][0]; + $disks[$key]['partitions'][$attrs['cn'][0]] = $attrs; + } + } + $this->Result['FAIpartitionTable']['Entries'] = $disks; + } + + + /* Create template entry */ + function prepare_FAItemplate($data) + { + $current = array(); + if(isset($this->Result['FAItemplate']['Entries'])){ + $current = $this->Result['FAItemplate']['Entries']; + } + + $ldap = $this->config->get_ldap_link(); + $ldap->cd($data['dn']); + $ldap->search("(objectClass=FAItemplateEntry)",array("cn","description")); + while($attrs = $ldap->fetch()){ + $attrs['CLASS'] = $data['cn'][0]; + $current[] = $attrs; + } + $this->Result['FAItemplate']['Entries'] = $current ; + } + + + /* Create a package list */ + function prepare_FAIpackageList($data) + { + $current = array(); + if(isset($this->Result['FAIpackageList']['Entries'])){ + $current = $this->Result['FAIpackageList']['Entries']; + } + if(isset($data['FAIpackage'])){ + unset($data['FAIpackage']['count']); + foreach($data['FAIpackage'] as $pkg){ + $attrs['CLASS'] = $data['cn'][0]; + $attrs['cn'][0] = $pkg; + $current[$pkg] = $attrs; + } + } + $this->Result['FAIpackageList']['Entries'] = $current ; + } + + + /* Create a variable entry */ + function prepare_FAIvariable($data) + { + $current = array(); + if(isset($this->Result['FAIvariable']['Entries'])){ + $current = $this->Result['FAIvariable']['Entries']; + } + $ldap = $this->config->get_ldap_link(); + $ldap->cd($data['dn']); + $ldap->search("(objectClass=FAIvariableEntry)",array("cn","description","FAIvariableContent")); + while($attrs = $ldap->fetch()){ + $attrs['CLASS'] = $data['cn'][0]; + $current[] = $attrs; + } + $this->Result['FAIvariable']['Entries'] = $current ; + } + + /* Create a hook entry */ + function prepare_FAIhook($data) + { + $current = array(); + if(isset($this->Result['FAIhook']['Entries'])){ + $current = $this->Result['FAIhook']['Entries']; + } + $ldap = $this->config->get_ldap_link(); + $ldap->cd($data['dn']); + $ldap->search("(objectClass=FAIhookEntry)",array("cn","description")); + while($attrs = $ldap->fetch()){ + $attrs['CLASS'] = $data['cn'][0]; + $current[$attrs['cn'][0]] = $attrs; + } + $this->Result['FAIhook']['Entries'] = $current ; + } + + + /* Create a new Profile entry */ + function prepare_FAIprofile($data) + { + $classes = split("\ ",$data['FAIclass'][0]); + foreach($classes as $class){ + $class = trim($class); + $this->resolveObject($class); + } + } + + /* Return plugin informations for acl handling * / + static function plInfo() + { + return (array( + "plShortName" => _("Summary"), + "plDescription" => _("FAI summary"), + "plSelfModify" => FALSE, + "plDepends" => array(), + "plPriority" => 15, + "plSection" => array("administration"), + "plCategory" => array("workstation","server","fai","ogroups") , + "plProvidedAcls"=> array( + "readable" => _("Viewable")), + )); + } + */ +} +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/gosa-plugins/fai/admin/fai/class_faiTemplate.inc b/gosa-plugins/fai/admin/fai/class_faiTemplate.inc new file mode 100644 index 000000000..54bd83267 --- /dev/null +++ b/gosa-plugins/fai/admin/fai/class_faiTemplate.inc @@ -0,0 +1,565 @@ + "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"); + + /* ObjectClasses for this Object*/ + var $objectclasses = array("top","FAIclass","FAItemplate"); + + /* Class name of the Ldap ObjectClass for the Sub Object */ + var $subClass = "FAItemplateEntry"; + var $subClasses = array("top","FAIclass","FAItemplateEntry"); + + /* Class name of the php class which allows us to edit a Sub Object */ + var $subClassName = "faiTemplateEntry"; + + /* Attributes to initialise for each subObject */ + var $subAttributes = array("cn","description","FAItemplatePath","FAIowner","FAImode"); + var $sub_Load_Later = array("FAItemplateFile"); + var $sub64coded = array(); + var $subBinary = array("FAItemplateFile"); + + /* 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 $SubObjects = array(); // All leafobjects of this object + + var $FAIstate = ""; + var $ui; + var $view_logged = FALSE; + + function faiTemplate (&$config, $dn= NULL) + { + /* Load Attributes */ + plugin::plugin ($config, $dn); + + /* If "dn==new" we try to create a new entry + * Else we must read all objects from ldap which belong to this entry. + * First read SubObjects from ldap ... and then the partition definitions for the SubObjects. + */ + if($dn != "new"){ + $this->dn =$dn; + + /* Get FAIstate + */ + if(isset($this->attrs['FAIstate'][0])){ + $this->FAIstate = $this->attrs['FAIstate'][0]; + } + + /* Read all leaf objects of this object (For FAIscript this would be FAIscriptEntry) + */ + $ldap = $this->config->get_ldap_link(); + $ldap->cd ($this->dn); + + $attrs_to_search = $this->subAttributes; + $attrs_to_search[] = "FAIstate"; + $ldap->search("(&(objectClass=FAIclass)(objectClass=".$this->subClass."))",$attrs_to_search); + + while($object = $ldap->fetch()){ + + /* Skip objects, that are tagged as removed */ + if(isset($object['FAIstate'][0])){ + if(preg_match("/removed$/",$object['FAIstate'][0])){ + continue; + } + } + + /* Set status for save management */ + $objects = array(); + $objects['status'] = "FreshLoaded"; + $objects['dn'] = $object['dn']; + $objects = $this->get_object_attributes($objects,$this->subAttributes); + $this->SubObjects[$objects['cn']] = $objects; + } + } + $this->ui = get_userinfo(); + } + + + /* Reload some attributes */ + function get_object_attributes($object,$attributes) + { + $ldap = $this->config->get_ldap_link(); + $ldap->cd($this->config->current['BASE']); + $ldap->cat($object['dn'],$attributes); + $tmp = $ldap->fetch(); + + foreach($attributes as $attrs){ + if(isset($tmp[$attrs][0])){ + $var = $tmp[$attrs][0]; + + /* Check if we must decode some attributes */ + if(in_array_ics($attrs,$this->sub64coded)){ + $var = base64_decode($var); + } + + /* check if this is a binary entry */ + if(in_array_ics($attrs,$this->subBinary)){ + $var = $ldap->get_attribute($object['dn'], $attrs,$r_array=0); + } + + $var = stripslashes($var); + + $object[$attrs] = $var; + } + } + return($object); + } + + + function execute() + { + /* Call parent execute */ + plugin::execute(); + + if($this->is_account && !$this->view_logged){ + $this->view_logged = TRUE; + new log("view","fai/".get_class($this),$this->dn); + } + + /* Fill templating stuff */ + $smarty= get_smarty(); + $display= ""; + + /* New Listhandling + */ + $once = true; + foreach($_POST as $name => $value){ + if(preg_match("/^editscript_/",$name)&&($once)){ + $once = false; + $entry = preg_replace("/^editscript_/","",$name); + $entry = base64_decode(preg_replace("/_.*/","",$entry)); + $obj = $this->SubObjects[$entry]; + + $acl_dn = $this->acl_base_for_current_object($obj['dn']); + $acl = $this->ui->get_permissions($acl_dn,"fai/faiTemplateEntry"); + if(preg_match("/r/",$acl)){ + if($obj['status'] == "FreshLoaded"){ + $obj = $this->get_object_attributes($obj,$this->sub_Load_Later); + } + $this->dialog= new $this->subClassName($this->config,$this->dn,$obj); + $this->dialog->set_acl_base($this->acl_base); + $this->dialog->set_acl_category("fai"); + + session::set('objectinfo',$obj['dn']); + $this->dialog->parent = &$this; + $this->is_dialog=true; + } + } + if(preg_match("/^deletescript_/",$name)&&($once)){ + $once = false; + $entry = preg_replace("/^deletescript_/","",$name); + $entry = base64_decode(preg_replace("/_.*/","",$entry)); + $obj = $this->SubObjects[$entry]; + + $acl_dn = $this->acl_base_for_current_object($obj['dn']); + $acl = $this->ui->get_permissions($acl_dn,"fai/faiTemplateEntry"); + if(preg_match("/d/",$acl)){ + $status = $this->SubObjects[$entry]['status']; + if($status == "edited" || $status == "FreshLoaded"){ + $this->SubObjects[$entry]['status']= "delete"; + }else{ + unset($this->SubObjects[$entry]); + } + } + } + } + + /* Edit entries via GET */ + if(isset($_GET['act']) && isset($_GET['id'])){ + if($_GET['act'] == "edit" && isset($this->SubObjects[$_GET['id']])){ + $obj = $this->SubObjects[$_GET['id']]; + if($obj['status'] == "FreshLoaded"){ + $obj = $this->get_object_attributes($obj,$this->sub_Load_Later); + } + $this->dialog= new $this->subClassName($this->config,$this->dn,$obj); + $this->dialog->acl = $this->acl; + session::set('objectinfo',$obj['dn']); + $this->dialog->parent = &$this; + $this->is_dialog=true; + } + } + + /* Add new sub object */ + if(isset($_POST['AddSubObject'])){ + $acl_dn = "cn=dummy,".$this->acl_base_for_current_object($this->dn); + $acl = $this->ui->get_permissions($acl_dn,"fai/faiTemplateEntry"); + + if(preg_match("/c/",$acl)){ + $this->dialog= new $this->subClassName($this->config,"new"); + $this->dialog->set_acl_base($this->acl_base); + $this->dialog->set_acl_category("fai"); + $this->dialog->parent = &$this; + $this->is_dialog=true; + } + } + + if($this->dn != "new"){ + session::set('objectinfo',$this->dn); + } + + /* Save Dialog */ + if(isset($_POST['SaveSubObject']) && is_object($this->dialog)){ + $this->dialog->save_object(); + $msgs = $this->dialog->check(); + if(count($msgs)>0){ + foreach($msgs as $msg){ + print_red($msg); + } + }else{ + /* Get return object */ + $obj = $this->dialog->save(); + if(isset($obj['remove'])){ + + $old_stat = $this->SubObjects[$obj['remove']['from']]['status']; + + /* Depending on status, set new status */ + if($old_stat == "edited" || $old_stat == "FreshLoaded"){ + $this->SubObjects[$obj['remove']['from']]['status'] = "delete"; + }elseif($this->SubObjects[$obj['remove']['from']]['status']=="new"){ + unset($this->SubObjects[$obj['remove']['from']]); + } + $obj['status'] = "new"; + $this->SubObjects[$obj['remove']['to']] = $obj; + unset($this->SubObjects[$obj['remove']['to']]['remove']); + }else{ + if($obj['status'] == "FreshLoaded"){ + $obj['status'] = "edited"; + } + $this->SubObjects[$obj['cn']]=$obj; + } + $this->is_dialog=false; + unset($this->dialog); + $this->dialog=FALSE; + } + } + + /* Sort entries */ + $tmp = $keys = array(); + foreach($this->SubObjects as $key => $entry){ + $keys[$key]=$key; + } + natcasesort($keys); + foreach($keys as $key){ + $tmp[$key]=$this->SubObjects[$key]; + } + $this->SubObjects = $tmp; + + /* Cancel Dialog */ + if(isset($_POST['CancelSubObject'])){ + $this->is_dialog=false; + unset($this->dialog); + $this->dialog=FALSE; + } + + /* Print dialog if $this->dialog is set */ + if(is_object($this->dialog)){ + $this->dialog->save_object(); + $display = $this->dialog->execute(); + return($display); + } + + /* Divlist Containing FAItemplates */ + $divlist = new divSelectBox("FAItemplates"); + $divlist->setHeight(400); + + $tmp = $this->getList(true); + + /* Create div list with all sub entries listed */ + foreach($this->SubObjects as $key => $name){ + + /* Skip removed entries */ + if($name['status'] == "delete") continue; + + /* Get permissions */ + $dn = $this->acl_base_for_current_object($name['dn']); + $acl = $this->ui->get_permissions($dn,"fai/faiTemplateEntry") ; + $act = ""; + + /* Hide delete icon if this object is freezed */ + if(preg_match("/freeze/",$this->FAIstate)){ + $act .= ""; + }else{ + $act .= ""; + if(preg_match("/d/",$acl)){ + $act .=""; + } + } + + /* Check acls for download icon */ + $s_acl = $this->ui->get_permissions($dn,"fai/faiTemplateEntry","FAItemplateFile") ; + if(($this->SubObjects[$key]['status'] == "new") || ($this->SubObjects[$key]['dn'] == "new") || !preg_match("/r/",$s_acl)){ + $down = ""; + }else{ + $down = " + "._("Download")." + "; + } + + /* Check if we are allowed to view this object */ + $s_acl = $this->ui->get_permissions($dn,"fai/faiTemplateEntry","cn") ; + if(preg_match("/r/",$s_acl)){ + + $edit_link = "".$tmp[$key].""; + $divlist->AddEntry(array( array("string"=> $edit_link), + array("string"=>$down , "attach" => "style='width:20px;'"), + array("string"=>str_replace("%s",base64_encode($key),$act), + "attach"=>"style='border-right: 0px;width:50px;text-align:right;'"))); + } + } + $smarty->assign("Entry_divlist",$divlist->DrawList()); + /* Divlist creation complete + */ + + /* 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){ + if(get_magic_quotes_gpc()){ + $smarty->assign($attrs,stripslashes($this->$attrs)); + }else{ + $smarty->assign($attrs,($this->$attrs)); + } + } + + $dn = $this->acl_base_for_current_object($this->dn); + $smarty->assign("sub_object_is_addable", + preg_match("/c/",$this->ui->get_permissions($dn,"fai/faiTemplateEntry")) && + !preg_match("/freeze/",$this->FAIstate)); + + foreach($this->attributes as $attr){ + $smarty->assign($attr."ACL",$this->getacl($attr)); + } + + $display.= $smarty->fetch(get_template_path('faiTemplate.tpl', TRUE)); + return($display); + } + + + function acl_base_for_current_object($dn) + { + if($dn == "new"){ + if($this->dn == "new"){ + $dn = session::get('CurrentMainBase'); + }else{ + $dn = $this->dn; + } + } + return($dn); + } + + + /* Generate listbox friendly SubObject list + */ + function getList(){ + $a_return=array(); + foreach($this->SubObjects as $obj){ + if($obj['status'] != "delete"){ + + if((isset($obj['description']))&&(!empty($obj['description']))){ + if(strlen($obj['description']) > 40){ + $obj['description'] = substr($obj['description'],0,40)."..."; + } + $a_return[$obj['cn']]= $obj['cn']." [".$obj['description']."]"; + }else{ + $a_return[$obj['cn']]= $obj['cn']; + } + } + } + return($a_return); + } + + /* Delete me, and all my subtrees + */ + function remove_from_parent() + { + $ldap = $this->config->get_ldap_link(); + $ldap->cd ($this->dn); + + $faifilter = session::get('faifilter'); + $use_dn = preg_replace("/".normalizePreg(FAI::get_release_dn($this->dn))."/i", $faifilter['branch'], $this->dn); + if($faifilter['branch'] == "main"){ + $use_dn = $this->dn; + } + + FAI::prepare_to_save_FAI_object($use_dn,array(),true); + new log("remove","fai/".get_class($this),$use_dn,$this->attributes); + + foreach($this->SubObjects as $name => $obj){ + $use_dn = preg_replace("/".normalizePreg(FAI::get_release_dn($this->dn))."/i", $faifilter['branch'], $obj['dn']); + if($faifilter['branch'] == "main"){ + $use_dn = $obj['dn']; + } + FAI::prepare_to_save_FAI_object($use_dn,array(),true); + } + $this->handle_post_events("remove"); + } + + + /* Save data to object + */ + function save_object() + { + if((isset($_POST['FAItemplate_posted'])) && (!preg_match("/freeze/",$this->FAIstate))){ + plugin::save_object(); + } + } + + + /* Check supplied data */ + function check() + { + /* Call common method to give check the hook */ + $message= plugin::check(); + + return ($message); + } + + + /* Save to LDAP */ + function save() + { + plugin::save(); + + $ldap = $this->config->get_ldap_link(); + + FAI::prepare_to_save_FAI_object($this->dn,$this->attrs); + show_ldap_error($ldap->get_error(), sprintf(_("Saving of FAI/template with dn '%s' failed."),$this->dn)); + + if($this->initially_was_account){ + new log("modify","fai/".get_class($this),$this->dn,$this->attributes); + }else{ + new log("create","fai/".get_class($this),$this->dn,$this->attributes); + } + + /* Prepare FAIscriptEntry to write it to ldap + * First sort array. + * Because we must delete old entries first. + * After deletion, we perform add and modify + */ + $Objects = array(); + foreach($this->SubObjects as $name => $obj){ + if($obj['status'] == "FreshLoaded"){ + unset($this->SubObjects[$name]); + } + } + + foreach($this->SubObjects as $name => $obj){ + if($obj['status'] == "delete"){ + $Objects[$name] = $obj; + } + } + foreach($this->SubObjects as $name => $obj){ + if($obj['status'] != "delete"){ + $Objects[$name] = $obj; + } + } + + foreach($Objects as $name => $obj){ + + foreach($this->sub64coded as $codeIt){ + $obj[$codeIt]=base64_encode($obj[$codeIt]); + } + $tmp = array(); + $attributes = array_merge($this->sub_Load_Later,$this->subAttributes); + foreach($attributes as $attrs){ + if(empty($obj[$attrs])){ + $obj[$attrs] = array(); + } + $tmp[$attrs] =($obj[$attrs]); + } + + $tmp['objectClass'] = $this->subClasses; + + $sub_dn = "cn=".$obj['cn'].",".$this->dn; + + if($obj['status']=="new"){ + $ldap->cat($sub_dn,array("objectClass")); + if($ldap->count()){ + $obj['status']="edited"; + } + } + + /* Tag object */ + $this->tag_attrs(&$tmp, $sub_dn, $this->gosaUnitTag); + + if($obj['status'] == "delete"){ + FAI::prepare_to_save_FAI_object($sub_dn,array(),true); + $this->handle_post_events("remove"); + }elseif($obj['status'] == "edited"){ + FAI::prepare_to_save_FAI_object($sub_dn,$tmp); + $this->handle_post_events("modify"); + }elseif($obj['status']=="new"){ + FAI::prepare_to_save_FAI_object($sub_dn,$tmp); + $this->handle_post_events("add"); + } + + } + } + + + function PrepareForCopyPaste($source) + { + plugin::PrepareForCopyPaste($source); + + /* Read all leaf objects of this object (For FAIscript this would be FAIscriptEntry) + */ + $ldap = $this->config->get_ldap_link(); + $ldap->cd ($source['dn']); + + $attrs_to_search = $this->subAttributes; + $attrs_to_search[] = "FAIstate"; + $ldap->search("(&(objectClass=FAIclass)(objectClass=".$this->subClass."))",$attrs_to_search); + + while($object = $ldap->fetch()){ + + /* Skip objects, that are tagged as removed */ + if(isset($object['FAIstate'][0])){ + if(preg_match("/removed$/",$object['FAIstate'][0])){ + continue; + } + } + + /* Set status for save management */ + $objects = array(); + $objects['status'] = "edited"; + $objects['dn'] = $object['dn']; + $objects = $this->get_object_attributes($objects,$this->subAttributes); + $objects = $this->get_object_attributes($objects,$this->sub_Load_Later); + + $this->SubObjects[$objects['cn']] = $objects; + } + } + + + /* Return plugin informations for acl handling */ + static function plInfo() + { + return (array( + "plShortName" => _("Template"), + "plDescription" => _("FAI template"), + "plSelfModify" => FALSE, + "plDepends" => array(), + "plPriority" => 24, + "plSection" => array("administration"), + "plCategory" => array("fai"), + "plProvidedAcls" => array( + "cn" => _("Name")." ("._("Readonly").")", + "description" => _("Description")) + )); + } +} + +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/gosa-plugins/fai/admin/fai/class_faiTemplateEntry.inc b/gosa-plugins/fai/admin/fai/class_faiTemplateEntry.inc new file mode 100644 index 000000000..a0734aa6a --- /dev/null +++ b/gosa-plugins/fai/admin/fai/class_faiTemplateEntry.inc @@ -0,0 +1,275 @@ + "Eins ist toll", "zwei" => "Zwei ist noch besser"); + + /* attribute list for save action */ + var $ignore_account= TRUE; + var $attributes = array("cn","description","FAItemplateFile","FAItemplatePath","FAImode","user","group","binary","FAIowner"); + var $objectclasses= array(); + + var $orig_cn = ""; + + 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 $parent = NULL; + var $FAIstate = ""; + + function faiTemplateEntry (&$config, $dn= NULL,$object=false) + { + plugin::plugin ($config, $dn); + + if((isset($object['cn'])) && (!empty($object['cn']))){ + $this->orig_cn= $object['cn']; + $this->dn=$object['dn']; + foreach($object as $name=>$value){ + $oname = $name; + $this->$oname=$value; + } + + if(isset($this->attrs['FAIstate'][0])){ + $this->FAIstate = $this->attrs['FAIstate'][0]; + } + + }else{ + $this->status = "new"; + $this->orig_cn= false; + } + + $this->user = explode( '.', $this->FAIowner ); + $this->group = $this->user[1]; + $this->user = $this->user[0]; + + session::set('binary',$this->FAItemplateFile); + session::set('binarytype','octet-stream'); + session::set('binaryfile',basename($this->FAItemplatePath)); + + if(!empty($this->dn) && $this->dn != "new"){ + $ldap = $this->config->get_ldap_link(); + session::set('binary',$ldap->get_attribute($this->dn,"FAItemplateFile")); + $this->FAItemplateFile = session::get('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']) && $this->acl_is_writeable("FAItemplateFile")){ + 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']; + } + + session::set('binary',$this->FAItemplateFile); + session::set('binarytype','octet-stream'); + session::set('binaryfile',basename($this->FAItemplatePath)); + } + } + + $status= _("no file uploaded yet"); + + $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 + */ + foreach($this->attributes as $attrs){ + if(get_magic_quotes_gpc()){ + $smarty->assign($attrs,stripslashes($this->$attrs)); + }else{ + $smarty->assign($attrs,($this->$attrs)); + } + } + + /* 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("FAItemplateFile",""); + + foreach($this->attributes as $attr){ + $smarty->assign($attr."ACL",$this->getacl($attr,preg_match("/freeze/",$this->FAIstate))); + } + + /* We now split cn/FAItemplatePath to make things more clear... */ + $smarty->assign("cn", basename($this->FAItemplatePath)); + $smarty->assign("templatePath", dirname($this->FAItemplatePath)); + + $display.= $smarty->fetch(get_template_path('faiTemplateEntry.tpl', TRUE)); + return($display); + } + + /* Save data to object */ + function save_object() + { + /* 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']; + } + + /* 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; + } + $this->FAImode= $tmode; + + /* Assemble cn/FAItemplatePath */ + $this->cn= preg_replace('/\/+/', '/', $this->FAItemplatePath.'/'.$this->cn); + $this->FAItemplatePath= $this->cn; + } + } + } + + + /* Check supplied data */ + function check() + { + /* Call common method to give check the hook */ + $message= plugin::check(); + + if(isset($this->parent->SubObjects[$this->cn]) && $this->cn != $this->orig_cn){ + $message[] =_("There is already a template with the given name."); + } + + if(empty($this->FAItemplateFile)){ + $message[]=_("Please specify a value for attribute 'file'."); + } + + if(!preg_match('/^\//', $this->FAItemplatePath)){ + $message[]=_("Please specify a valid value for attribute 'Destination path'."); + } + + if(empty($this->cn)){ + $message[] = _("Please enter a file name."); + } + +# echo $this->cn; +# if(preg_match('/\//', $this->cn)){ +# $message[] = _("The file name should not contain / characters."); +# # } + + 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(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); + } + + function save() + { + $tmp=array(); + foreach($this->attributes as $attrs){ + $tmp[$attrs] = $this->$attrs; + } + + if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){ + $tmp['remove']['from'] = $this->orig_cn; + $tmp['remove']['to'] = $tmp['cn']; + } + + $tmp['dn'] = $this->dn; + $tmp['status'] = $this->status; + + return($tmp); + } + + + /* Return plugin informations for acl handling */ + static 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: +?> diff --git a/gosa-plugins/fai/admin/fai/class_faiVariable.inc b/gosa-plugins/fai/admin/fai/class_faiVariable.inc new file mode 100644 index 000000000..7229e3634 --- /dev/null +++ b/gosa-plugins/fai/admin/fai/class_faiVariable.inc @@ -0,0 +1,464 @@ + "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"); + + /* ObjectClasses for this Object*/ + var $objectclasses = array("top","FAIclass","FAIvariable"); + + /* Class name of the Ldap ObjectClass for the Sub Object */ + var $subClass = "FAIvariableEntry"; + var $subClasses = array("top","FAIclass","FAIvariableEntry"); + + /* Class name of the php class which allows us to edit a Sub Object */ + var $subClassName = "faiVariableEntry"; + + /* Attributes to initialise for each subObject */ + var $subAttributes = array("cn","description","FAIvariableContent"); + var $sub64coded = array(); + + /* 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 $SubObjects = array(); // All leafobjects of this object + + var $FAIstate = ""; + var $ui ; + var $view_logged = FALSE; + + function faiVariable (&$config, $dn= NULL) + { + /* Load Attributes */ + plugin::plugin ($config, $dn); + + if($dn != "new"){ + $this->dn =$dn; + + /* Get FAIstate + */ + if(isset($this->attrs['FAIstate'][0])){ + $this->FAIstate = $this->attrs['FAIstate'][0]; + } + + /* Read all leaf objects of this object (For FAIscript this would be FAIscriptEntry) + */ + $ldap = $this->config->get_ldap_link(); + $ldap->cd ($this->dn); + + $attrs_to_search = $this->subAttributes; + $attrs_to_search[] = "FAIstate"; + $ldap->search("(&(objectClass=FAIclass)(objectClass=".$this->subClass."))",$attrs_to_search); + + while($object = $ldap->fetch()){ + + /* Skip objects, that are tagged as removed */ + if(isset($object['FAIstate'][0])){ + if(preg_match("/removed$/",$object['FAIstate'][0])){ + continue; + } + } + + /* Set status for save management */ + foreach($this->subAttributes as $attrs){ + if(!isset($object[$attrs][0])){ + $this->SubObjects[$object['cn'][0]][$attrs]=""; + }else{ + $this->SubObjects[$object['cn'][0]][$attrs]=$object[$attrs][0]; + } + } + + foreach($this->sub64coded as $codeIt){ + $this->SubObjects[$object['cn'][0]][$codeIt]=base64_decode($this->SubObjects[$object['cn'][0]][$codeIt]); + } + + $this->SubObjects[$object['cn'][0]]['status'] = "edited"; + $this->SubObjects[$object['cn'][0]]['dn'] = $object['dn']; + } + + } + $this->ui = get_userinfo(); + } + + + function acl_base_for_current_object($dn) + { + if($dn == "new"){ + if($this->dn == "new"){ + $dn = session::get('CurrentMainBase'); + }else{ + $dn = $this->dn; + } + } + return($dn); + } + + + function execute() + { + /* Call parent execute */ + plugin::execute(); + + if($this->is_account && !$this->view_logged){ + $this->view_logged = TRUE; + new log("view","fai/".get_class($this),$this->dn); + } + + /* Fill templating stuff */ + $smarty= get_smarty(); + $display= ""; + + /* Add new sub object */ + if(isset($_POST['AddSubObject'])){ + $this->dialog= new $this->subClassName($this->config,"new"); + $this->dialog->set_acl_base($this->acl_base_for_current_object($this->dn)); + $this->dialog->set_acl_category("fai"); + $this->dialog->parent = &$this; + $this->is_dialog=true; + } + + if($this->dn != "new"){ + session::set('objectinfo',$this->dn); + } + + + /* Edit selected Sub Object */ + if((isset($_POST['EditSubObject']))&&(isset($_POST['SubObject']))){ + + $var = $_POST['SubObject'][0]; + $c_dn = $this->acl_base_for_current_object($this->SubObjects[$var]['dn']); + $this->dialog= new $this->subClassName($this->config,$this->dn,$this->SubObjects[$var]); + $this->dialog->set_acl_category("fai"); + $this->dialog->set_acl_base($c_dn); + $this->dialog->parent = &$this; + session::set('objectinfo',$this->SubObjects[$var]['dn']); + $this->is_dialog=true; + } + + /* Remove Sub object */ + if((isset($_POST['DelSubObject']))&&(isset($_POST['SubObject']))){ + foreach($_POST['SubObject'] as $var){ + + $c_dn = $this->acl_base_for_current_object($this->SubObjects[$var]['dn']); + $acl = $this->ui->get_permissions($c_dn,"fai/faiVariable"); + if(preg_match("/d/",$acl)){ + if($this->SubObjects[$var]['status'] == "edited"){ + $this->SubObjects[$var]['status']= "delete"; + }else{ + unset($this->SubObjects[$var]); + } + } + } + } + + /* Save Dialog */ + if(isset($_POST['SaveSubObject'])){ + $this->dialog->save_object(); + $msgs = $this->dialog->check(); + if(count($msgs)>0){ + foreach($msgs as $msg){ + print_red($msg); + } + }else{ + $obj = $this->dialog->save(); + if(isset($obj['remove'])){ + if($this->SubObjects[$obj['remove']['from']]['status']=="edited"){ + $this->SubObjects[$obj['remove']['from']]['status'] = "delete"; + }elseif($this->SubObjects[$obj['remove']['from']]['status']=="new"){ + unset($this->SubObjects[$obj['remove']['from']]); + } + $obj['status'] = "new"; + $this->SubObjects[$obj['remove']['to']] = $obj; + unset($this->SubObjects[$obj['remove']['to']]['remove']); + }else{ + $this->SubObjects[$obj['cn']]=$obj; + } + $this->is_dialog=false; + unset($this->dialog); + $this->dialog=FALSE; + } + } + + /* Sort entries */ + $tmp = $keys = array(); + foreach($this->SubObjects as $key => $entry){ + $keys[$key]=$key; + } + natcasesort($keys); + foreach($keys as $key){ + $tmp[$key]=$this->SubObjects[$key]; + } + $this->SubObjects = $tmp; + + /* Cancel Dialog */ + if(isset($_POST['CancelSubObject'])){ + $this->is_dialog=false; + unset($this->dialog); + $this->dialog=FALSE; + } + + /* Print dialog if $this->dialog is set */ + if(is_object($this->dialog)){ + $this->dialog->save_object(); + $display = $this->dialog->execute(); + return($display); + } + + $ui = get_userinfo(); + $ret = $this->getList(); + $tmp = array(); + foreach($this->SubObjects as $key => $obj){ + $acl = $ui->get_permissions($obj['dn'],"fai/faiVariableEntry"); + if(preg_match("/r/",$acl) || $obj['dn'] == "new"){ + $tmp[$key] = $ret[$key]; + } + } + $smarty->assign("SubObjects",$tmp); + + + /* 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){ + if(get_magic_quotes_gpc()){ + $smarty->assign($attrs,htmlentities (stripslashes(utf8_decode($this->$attrs)))); + }else{ + $smarty->assign($attrs,htmlentities (utf8_decode($this->$attrs))); + } + } + + $c_dn = $this->acl_base_for_current_object($this->dn); + $smarty->assign("is_createable", preg_match("/c/",$this->ui->get_permissions($c_dn,"fai/faiVariableEntry")) && $this->FAIstate!="freeze"); + $smarty->assign("is_removeable", preg_match("/d/",$this->ui->get_permissions($c_dn,"fai/faiVariableEntry")) && $this->FAIstate!="freeze"); + + $tmp = $this->plInfo(); + foreach($tmp['plProvidedAcls'] as $name => $translation) { + $smarty->assign($name."ACL",$this->getacl($name)); + } + + + $display.= $smarty->fetch(get_template_path('faiVariable.tpl', TRUE)); + return($display); + } + + /* Generate listbox friendly SubObject list + */ + function getList(){ + $a_return=array(); + foreach($this->SubObjects as $obj){ + if($obj['status'] != "delete"){ + + if((isset($obj['description']))&&(!empty($obj['description']))&&(!preg_match("/\[\*\]/",$obj['description']))){ + if (preg_match("/\[\*\]/", $obj['description'])){ + $a_return[$obj['cn']]= $obj['cn']." [".preg_replace("/\s*\[\*\]\s*/", "", $obj['description'])."]"; + } else { + $a_return[$obj['cn']]= $obj['cn']."=".$obj['FAIvariableContent']." [".$obj['description']."]"; + } + }else{ + if (preg_match("/\[\*\]/", $obj['description'])){ + $a_return[$obj['cn']]= $obj['cn']; + } else { + $a_return[$obj['cn']]= $obj['cn']."=".$obj['FAIvariableContent']; + } + } + } + } + return($a_return); + } + + /* Delete me, and all my subtrees + */ + function remove_from_parent() + { + if($this->acl_is_removeable()){ + $ldap = $this->config->get_ldap_link(); + $ldap->cd ($this->dn); + + $faifilter = session::get('faifilter'); + $use_dn = preg_replace("/".normalizePreg(FAI::get_release_dn($this->dn))."/i", $faifilter['branch'], $this->dn); + if($faifilter['branch'] == "main"){ + $use_dn = $this->dn; + } + + FAI::prepare_to_save_FAI_object($use_dn,array(),true); + new log("remove","fai/".get_class($this),$use_dn,$this->attributes); + + foreach($this->SubObjects as $name => $obj){ + $use_dn = preg_replace("/".normalizePreg(FAI::get_release_dn($this->dn))."/i", $faifilter['branch'], $obj['dn']); + if($faifilter['branch'] == "main"){ + $use_dn = $obj['dn']; + } + FAI::prepare_to_save_FAI_object($use_dn,array(),true); + } + $this->handle_post_events("remove"); + } + } + + + /* Save data to object + */ + function save_object() + { + if((isset($_POST['FAIvariable_posted'])) && ($this->FAIstate != "freeze") ){ + plugin::save_object(); + foreach($this->attributes as $attrs){ + if(isset($_POST[$attrs])){ + $this->$attrs = $_POST[$attrs]; + } + } + } + } + + + /* Check supplied data */ + function check() + { + /* Call common method to give check the hook */ + $message= plugin::check(); + + return ($message); + } + + + /* Save to LDAP */ + function save() + { + plugin::save(); + + $ldap = $this->config->get_ldap_link(); + FAI::prepare_to_save_FAI_object($this->dn,$this->attrs); + show_ldap_error($ldap->get_error(), sprintf(_("Saving of FAI/variable with dn '%s' failed."),$this->dn)); + + if($this->initially_was_account){ + new log("modify","fai/".get_class($this),$this->dn,$this->attributes); + }else{ + new log("create","fai/".get_class($this),$this->dn,$this->attributes); + } + + /* Prepare FAIscriptEntry to write it to ldap + * First sort array. + * Because we must delete old entries first. + * After deletion, we perform add and modify + */ + $Objects = array(); + foreach($this->SubObjects as $name => $obj){ + if($obj['status'] == "delete"){ + $Objects[$name] = $obj; + } + } + foreach($this->SubObjects as $name => $obj){ + if($obj['status'] != "delete"){ + $Objects[$name] = $obj; + } + } + + foreach($Objects as $name => $obj){ + + foreach($this->sub64coded as $codeIt){ + $obj[$codeIt]=base64_encode($obj[$codeIt]); + } + + $tmp = array(); + foreach($this->subAttributes as $attrs){ + if(empty($obj[$attrs])){ + $obj[$attrs] = array(); + } + $tmp[$attrs] = $obj[$attrs]; + } + + $tmp['objectClass'] = $this->subClasses; + + $sub_dn = "cn=".$obj['cn'].",".$this->dn; + + if($obj['status']=="new"){ + $ldap->cat($sub_dn,array("objectClass")); + if($ldap->count()){ + $obj['status']="edited"; + } + } + + /* Tag object */ + $this->tag_attrs(&$tmp, $sub_dn, $this->gosaUnitTag); + + if($obj['status'] == "delete"){ + FAI::prepare_to_save_FAI_object($sub_dn,array(),true); + $this->handle_post_events("remove"); + }elseif($obj['status'] == "edited"){ + FAI::prepare_to_save_FAI_object($sub_dn,$tmp); + $this->handle_post_events("modify"); + }elseif($obj['status']=="new"){ + FAI::prepare_to_save_FAI_object($sub_dn,$tmp); + $this->handle_post_events("add"); + } + + } + } + + + function PrepareForCopyPaste($source) + { + plugin::PrepareForCopyPaste($source); + + /* Read all leaf objects of this object (For FAIscript this would be FAIscriptEntry) + */ + $ldap = $this->config->get_ldap_link(); + $ldap->cd ($source['dn']); + $attrs_to_search = $this->subAttributes; + $attrs_to_search[] = "FAIstate"; + $ldap->search("(&(objectClass=FAIclass)(objectClass=".$this->subClass."))",$attrs_to_search); + while($object = $ldap->fetch()){ + + /* Skip objects, that are tagged as removed */ + if(isset($object['FAIstate'][0])){ + if(preg_match("/removed$/",$object['FAIstate'][0])){ + continue; + } + } + + /* Set status for save management */ + foreach($this->subAttributes as $attrs){ + if(!isset($object[$attrs][0])){ + $this->SubObjects[$object['cn'][0]][$attrs]=""; + }else{ + $this->SubObjects[$object['cn'][0]][$attrs]=$object[$attrs][0]; + } + } + foreach($this->sub64coded as $codeIt){ + $this->SubObjects[$object['cn'][0]][$codeIt]=base64_decode($this->SubObjects[$object['cn'][0]][$codeIt]); + } + $this->SubObjects[$object['cn'][0]]['status'] = "edited"; + $this->SubObjects[$object['cn'][0]]['dn'] = $object['dn']; + } + } + + + /* Return plugin informations for acl handling */ + static function plInfo() + { + return (array( + "plShortName" => _("Variable"), + "plDescription" => _("FAI variable"), + "plSelfModify" => FALSE, + "plDepends" => array(), + "plPriority" => 22, + "plSection" => array("administration"), + "plCategory" => array("fai"), + "plProvidedAcls" => array( + "cn" => _("Name")." ("._("Read only").")", + "description" => _("Description")) + )); + } +} + +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/gosa-plugins/fai/admin/fai/class_faiVariableEntry.inc b/gosa-plugins/fai/admin/fai/class_faiVariableEntry.inc new file mode 100644 index 000000000..5fc6ef01e --- /dev/null +++ b/gosa-plugins/fai/admin/fai/class_faiVariableEntry.inc @@ -0,0 +1,155 @@ + "Eins ist toll", "zwei" => "Zwei ist noch besser"); + + /* attribute list for save action */ + var $ignore_account= TRUE; + var $attributes = array("cn","description","FAIvariableContent"); + var $objectclasses= array(); + + var $orig_cn = ""; + var $dn = ""; + var $cn = ""; + var $FAIvariableContent = ""; + var $description = ""; + var $status = "new"; + var $parent = NULL; + var $FAIstate = ""; + + function faiVariableEntry (&$config, $dn= NULL,$object=false) + { + plugin::plugin ($config, $dn); + if((isset($object['cn'])) && (!empty($object['cn']))){ + $this->orig_cn= $object['cn']; + $this->dn=$object['dn']; + foreach($object as $name=>$value){ + $oname = $name; + $this->$oname=addslashes($value); + } + + if(isset($this->attrs['FAIstate'][0])){ + $this->FAIstate = $this->attrs['FAIstate'][0]; + } + + }else{ + $this->status = "new"; + $this->orig_cn = false; + } + } + + function execute() + { + /* Call parent execute */ + plugin::execute(); + + /* Fill templating stuff */ + $smarty = get_smarty(); + $display = ""; + + /* 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){ + if(get_magic_quotes_gpc()){ + $smarty->assign($attrs,htmlentities (stripslashes(utf8_decode($this->$attrs)))); + }else{ + $smarty->assign($attrs,htmlentities (utf8_decode($this->$attrs))); + } + } + + $tmp = $this->plInfo(); + foreach($tmp['plProvidedAcls'] as $name => $translated){ + $acl = $this->getacl($name); + if($this->FAIstate == "freezed"){ + $acl = preg_replace("/w/","",$acl); + } + $smarty->assign($name."ACL",$acl); + } + + + + $display.= $smarty->fetch(get_template_path('faiVariableEntry.tpl', TRUE)); + return($display); + } + + /* Save data to object */ + function save_object() + { + if((isset($_POST['SubObjectFormSubmitted'])) && ($this->FAIstate != "freeze")){ + foreach($this->attributes as $attrs){ + if($this->acl_is_writeable($attrs)){ + if(isset($_POST[$attrs])){ + $this->$attrs = $_POST[$attrs]; + }else{ + $this->$attrs = ""; + } + } + } + } + } + + /* Check supplied data */ + function check() + { + /* Call common method to give check the hook */ + $message= plugin::check(); + + if(isset($this->parent->SubObjects[$this->cn]) && $this->cn != $this->orig_cn){ + $message[] =_("There is already a variable with the given name."); + } + + if(empty($this->FAIvariableContent)) { + $message[]=_("Please specify a value for the attribute 'content'."); + } + + if(empty($this->cn)){ + $message[] = _("Please enter a name."); + } + + return ($message); + } + + function save() + { + $tmp=array(); + foreach($this->attributes as $attrs){ + $tmp[$attrs] = stripslashes( $this->$attrs); + } + + if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){ + $tmp['remove']['from'] = $this->orig_cn; + $tmp['remove']['to'] = $tmp['cn']; + } + + $tmp['dn'] = $this->dn; + $tmp['status'] = $this->status; + return($tmp); + } + + /* Return plugin informations for acl handling */ + static function plInfo() + { + return (array( + "plShortName" => _("Variable entry"), + "plDescription" => _("FAI variable entry "), + "plSelfModify" => FALSE, + "plDepends" => array(), + "plPriority" => 23, + "plSection" => array("administration"), + "plCategory" => array("fai"), + "plProvidedAcls" => array( + "cn" => _("Name"), + "description" => _("Description"), + "FAIvariableContent"=> _("Variable content") ) + )); + } + + +} +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/gosa-plugins/fai/admin/fai/faiHook.tpl b/gosa-plugins/fai/admin/fai/faiHook.tpl new file mode 100644 index 000000000..6768ad92d --- /dev/null +++ b/gosa-plugins/fai/admin/fai/faiHook.tpl @@ -0,0 +1,63 @@ + + + + +
+

 {t}Generic{/t}

+ + + + + + + + + +
+ + +{render acl=$cnACL} + +{/render} +
+ + +{render acl=$descriptionACL} + +{/render} +
+
+

 

+ + + + +
+

  + {t}List of hook scripts{/t} +

+ + + + +
+ {$Entry_divlist} +{if $sub_object_is_addable} + +{else} + +{/if} +
+
+ + + + diff --git a/gosa-plugins/fai/admin/fai/faiHookEntry.tpl b/gosa-plugins/fai/admin/fai/faiHookEntry.tpl new file mode 100644 index 000000000..882da267d --- /dev/null +++ b/gosa-plugins/fai/admin/fai/faiHookEntry.tpl @@ -0,0 +1,94 @@ + + + + + + + +
+

 {t}Generic{/t}

+ + + + + + + + + +
+ {t}Name{/t}{$must}  + +{render acl=$cnACL} + +{/render} +
+ {t}Description{/t}  + +{render acl=$descriptionACL} + +{/render} +
+
+   + +

 {t}Hook attributes{/t}

+ + + + +
+ +{render acl=$FAItaskACL} + +{/render} +
+
+ + +

 

+

  + +

+ + + + +
+{render acl=$FAIscriptACL} + +{/render} +
+
+
+{render acl=$FAIscriptACL} +   +{/render} +{render acl=$FAIscriptACL} + +{/render} +{render acl=$FAIscriptACL} + {$DownMe} +{/render} +
+ +

 

+
+
+   + +
+ + + diff --git a/gosa-plugins/fai/admin/fai/faiNewBranch.tpl b/gosa-plugins/fai/admin/fai/faiNewBranch.tpl new file mode 100644 index 000000000..831e02898 --- /dev/null +++ b/gosa-plugins/fai/admin/fai/faiNewBranch.tpl @@ -0,0 +1,55 @@ +{if $iframe == false} + +
+

+{t}You are now going to create a branch or locked branch. This action clones the existing release to another release name. Branches can be modified as usual. FAI classes of locked branches cannot be modified, just additional classes are possible. Branch names should be alphanumeric, excluding the reserved names 'scripts', 'hooks', 'partitions', 'variables', 'templates' and 'fai'.{/t} +
+{t}Branches are created as subreleases of the currently selected branch. Creating a new branch named 1.0.2 in SARGE for example, will result in a new release called SARGE/1.0.2.{/t} +
+
+

+

+
+{t}Please enter a name for the branch{/t}   + +
+
+

+ +
+

+ + +

+
+ + + +{else} + +

{t}Processing the requested operation{/t}

+{t}As soon as the copy operation has finished, you can scroll down to end of the page and press the 'Continue' button to continue with the fai management dialog.{/t} +
+
+
+ +
+ +{/if} diff --git a/gosa-plugins/fai/admin/fai/faiPackage.tpl b/gosa-plugins/fai/admin/fai/faiPackage.tpl new file mode 100644 index 000000000..87c83d98e --- /dev/null +++ b/gosa-plugins/fai/admin/fai/faiPackage.tpl @@ -0,0 +1,100 @@ + + + + + +
+

 {t}Generic{/t}

+ + + + + + + + + +
+ + +{render acl=$cnACL} + +{/render} +
+ + +{render acl=$descriptionACL} + +{/render} +
+
+

 {t}Repository{/t}

+ + + + + + + + + + + + + +
+ {t}Release{/t} : + + {$release} +
+ {t}Section{/t} : + + {$section} +
+ {t}Install method{/t} : + +{render acl=$FAIinstallMethodACL} + +{/render} +
+
+

 

+ + + + +
+

 {t}Used packages{/t}

+
+ +
+{render acl=$FAIpackageACL} + +{/render} +{render acl=$FAIpackageACL} + +{/render} +{render acl=$FAIdebconfInfoACL} + +{/render} +{render acl=$FAIpackageACL} + +{/render} +
+ + + + diff --git a/gosa-plugins/fai/admin/fai/faiPackageConfiguration.tpl b/gosa-plugins/fai/admin/fai/faiPackageConfiguration.tpl new file mode 100644 index 000000000..db047590f --- /dev/null +++ b/gosa-plugins/fai/admin/fai/faiPackageConfiguration.tpl @@ -0,0 +1,9 @@ +

 {$headline}

+{$Config} +

 

+
+
+ + +
+ diff --git a/gosa-plugins/fai/admin/fai/faiPackageEntry.tpl b/gosa-plugins/fai/admin/fai/faiPackageEntry.tpl new file mode 100644 index 000000000..79f47c6c4 --- /dev/null +++ b/gosa-plugins/fai/admin/fai/faiPackageEntry.tpl @@ -0,0 +1,66 @@ + + + + + +
+
+

+ {t}List of available packages{/t} +

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

+ [i]{t}Information{/t} +

+
+
+ {t}This menu allows you to select multiple packages to add them to the currently edited package list.{/t} +
+
+
+

+ [F] + {t}Filters{/t} +

+
+
+ {$CHKS} +
+
+ + + + + +
+ {t}Display objects matching{/t} + + +
+ {$apply} +
+
+
+ + +
+ + + + diff --git a/gosa-plugins/fai/admin/fai/faiPartitionTable.tpl b/gosa-plugins/fai/admin/fai/faiPartitionTable.tpl new file mode 100644 index 000000000..f330fe67b --- /dev/null +++ b/gosa-plugins/fai/admin/fai/faiPartitionTable.tpl @@ -0,0 +1,68 @@ + + + + + + +
+

 {t}Generic{/t}

+ + + + + + + + + +
+ + +{render acl=$cnACL} + +{/render} +
+ + +{render acl=$descriptionACL} + +{/render} +
+
+   + +

  + +

+ + + + +
+
+{if $sub_object_is_addable} + +{else} + +{/if} + + + +
+
+ + + diff --git a/gosa-plugins/fai/admin/fai/faiPartitionTableEntry.tpl b/gosa-plugins/fai/admin/fai/faiPartitionTableEntry.tpl new file mode 100644 index 000000000..4379b663d --- /dev/null +++ b/gosa-plugins/fai/admin/fai/faiPartitionTableEntry.tpl @@ -0,0 +1,48 @@ + +

 {t}Device{/t}

+ + + + + +
{$must}  +{render acl=$DISKcnACL} + +{/render} +   +{render acl=$DISKdescriptionACL} + +{/render} +
+
+

 

+
+

 {t}Partition entries{/t}

+{$setup} +
+{if $sub_object_is_createable} + +{else} + +{/if} +
+
+

 

+
+
+{render acl=$allowSave} + +{/render} + +
+ + + diff --git a/gosa-plugins/fai/admin/fai/faiProfile.tpl b/gosa-plugins/fai/admin/fai/faiProfile.tpl new file mode 100644 index 000000000..090d968e7 --- /dev/null +++ b/gosa-plugins/fai/admin/fai/faiProfile.tpl @@ -0,0 +1,58 @@ + + + + + +
+

 {t}Generic{/t}

+ + + + + + + + + +
+ + +{render acl=$cnACL} + +{/render} +
+ + +{render acl=$descriptionACL} + +{/render} +
+
+ + + + +
+

 {t}FAI classes{/t}

+ + {$divlist} +
+{render acl=$FAIclassACL} + +{/render} + +
+
+ + + diff --git a/gosa-plugins/fai/admin/fai/faiProfileEntry.tpl b/gosa-plugins/fai/admin/fai/faiProfileEntry.tpl new file mode 100644 index 000000000..72e865bea --- /dev/null +++ b/gosa-plugins/fai/admin/fai/faiProfileEntry.tpl @@ -0,0 +1,73 @@ + + + + + +
+
+

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

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

+ [i]{t}Information{/t} +

+
+
+

+ {t}This menu allows you to select FAI class names and to add them to the currently edited profile.{/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}
+ + + + + +
+ {t}Display objects matching{/t} + + +
+ {$apply} +
+
+ +
+ + +
+ diff --git a/gosa-plugins/fai/admin/fai/faiScript.tpl b/gosa-plugins/fai/admin/fai/faiScript.tpl new file mode 100644 index 000000000..c0ff247b5 --- /dev/null +++ b/gosa-plugins/fai/admin/fai/faiScript.tpl @@ -0,0 +1,63 @@ + + + + +
+

 {t}Generic{/t}

+ + + + + + + + + +
+ + +{render acl=$cnACL} + +{/render} +
+ + +{render acl=$descriptionACL} + +{/render} +
+
+

 

+ + + + +
+

  + {t}List of scripts{/t} +

+ + + + +
+ {$Entry_divlist} +{if $sub_object_is_addable} + +{else} + +{/if} +
+
+ + + + diff --git a/gosa-plugins/fai/admin/fai/faiScriptEntry.tpl b/gosa-plugins/fai/admin/fai/faiScriptEntry.tpl new file mode 100644 index 000000000..cddb2bbcd --- /dev/null +++ b/gosa-plugins/fai/admin/fai/faiScriptEntry.tpl @@ -0,0 +1,92 @@ + + + + + + + +
+

 {t}Generic{/t}

+ + + + + + + + + +
+ {t}Name{/t}{$must}  + +{render acl=$cnACL} + +{/render} +
+ {t}Description{/t}  + +{render acl=$descriptionACL} + +{/render} +
+
+   + +

 {t}Script attributes{/t}

+ + + + + +
+ + +{render acl=$FAIpriorityACL} + +{/render} +
+
+

 

+

  + +

+ + + + +
+{render acl=$FAIscriptACL} + +{/render} +
+
+
+{render acl=$FAIscriptACL} +   +{/render} +{render acl=$FAIscriptACL} + +{/render} +{render acl=$FAIscriptACL} + {$DownMe} +{/render} +
+
+
+   + +
+ + + diff --git a/gosa-plugins/fai/admin/fai/faiSummary.tpl b/gosa-plugins/fai/admin/fai/faiSummary.tpl new file mode 100644 index 000000000..196f7cab8 --- /dev/null +++ b/gosa-plugins/fai/admin/fai/faiSummary.tpl @@ -0,0 +1,27 @@ + + + + + + +{if $readable} + + + + + + +{else} + + + +{/if} +
{t}FAI object tree{/t}
+ + {t}Reload class and release configuration from parent object.{/t} +
+ {$objectList} +
+ {t}You are not allowed to view the fai summary.{/t} +
+ diff --git a/gosa-plugins/fai/admin/fai/faiTemplate.tpl b/gosa-plugins/fai/admin/fai/faiTemplate.tpl new file mode 100644 index 000000000..627c5ddd5 --- /dev/null +++ b/gosa-plugins/fai/admin/fai/faiTemplate.tpl @@ -0,0 +1,52 @@ + + + + + +
+

 {t}Generic{/t}

+ + + + + + + + + +
+ + +{render acl=$cnACL} + +{/render} +
+ + +{render acl=$descriptionACL} + +{/render} +
+
+

  + {t}List of template files{/t} +

+ {$Entry_divlist} +{if $sub_object_is_addable} + +{else} + +{/if} +
+ + + + diff --git a/gosa-plugins/fai/admin/fai/faiTemplateEntry.tpl b/gosa-plugins/fai/admin/fai/faiTemplateEntry.tpl new file mode 100644 index 000000000..b8ee41a61 --- /dev/null +++ b/gosa-plugins/fai/admin/fai/faiTemplateEntry.tpl @@ -0,0 +1,203 @@ + + +

 {t}Generic{/t}

+ + + + + +
+ + + + + + + + + +
+ {t}File name{/t}{$must}  + +{render acl=$cnACL} +    +{/render} +
+ + +{render acl=$FAItemplatePathACL} + +{/render} +
+
+ {t}Description{/t}  +{render acl=$descriptionACL} + +{/render} +
+ +

 

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

 {t}Template attributes{/t}

+ + + + + + + + +
+ + + {$status} + {if $bStatus} + + {t}Save template{/t}... + + {/if} +
+
+{render acl=$FAItemplateFileACL} + +{/render} +{render acl=$FAItemplateFileACL} +   +{/render} +
+
+
+ {t}Full path{/t}  + +{render acl=$FAItemplatePathACL} + {$FAItemplatePath} +{/render} +
+
+ + + + + + + + + + +
+ + +{render acl=$FAIownerACL} + +{/render} +
+ + +{render acl=$FAIownerACL} + +{/render} +
+
+
{t}Access{/t}{$must}  + + + + + + + + + + + + + +{render acl=$FAImodeACL} + +{/render} +{render acl=$FAImodeACL} + +{/render} +{render acl=$FAImodeACL} + +{/render} + +{render acl=$FAImodeACL} + +{/render} + + + + +{render acl=$FAImodeACL} + +{/render} +{render acl=$FAImodeACL} + +{/render} +{render acl=$FAImodeACL} + +{/render} + +{render acl=$FAImodeACL} + +{/render} + + + + +{render acl=$FAImodeACL} + +{/render} +{render acl=$FAImodeACL} + +{/render} +{render acl=$FAImodeACL} + +{/render} + +{render acl=$FAImodeACL} + +{/render} + +
{t}Class{/t}{t}Read{/t}{t}Write{/t}{t}Execute{/t} {t}Special{/t} 
{t}User{/t} ({t}SUID{/t})
{t}Group{/t} ({t}SGID{/t})
{t}Others{/t} ({t}sticky{/t})
+ +
+
+
+

 

+
+
+   + +
+
+ + + + + + diff --git a/gosa-plugins/fai/admin/fai/faiVariable.tpl b/gosa-plugins/fai/admin/fai/faiVariable.tpl new file mode 100644 index 000000000..cdbdab96b --- /dev/null +++ b/gosa-plugins/fai/admin/fai/faiVariable.tpl @@ -0,0 +1,72 @@ + + + + + + +
+

 {t}Generic{/t}

+ + + + + + + + + +
+ + +{render acl=$cnACL} + +{/render} +
+ + +{render acl=$descriptionACL} + +{/render} +
+
+   + +

  + +

+ + + + +
+
+{if $is_createable} + +{else} + +{/if} + +{if $is_removeable} + +{else} + +{/if} +
+
+ + + + diff --git a/gosa-plugins/fai/admin/fai/faiVariableEntry.tpl b/gosa-plugins/fai/admin/fai/faiVariableEntry.tpl new file mode 100644 index 000000000..0fd8a4afa --- /dev/null +++ b/gosa-plugins/fai/admin/fai/faiVariableEntry.tpl @@ -0,0 +1,64 @@ + + + + + + + +
+

 {t}Generic{/t}

+ + + + + + + + + +
+ {t}Name{/t}{$must}  + +{render acl=$cnACL} + +{/render} +
+ {t}Description{/t}  + +{render acl=$descriptionACL} + +{/render} +
+
+   + +

 {t}Variable attributes{/t}

+ + + + + +
+ + +{render acl=$FAIvariableContentACL} + +{/render} +
+
+

 

+
+
+   + +
+ + + + diff --git a/gosa-plugins/fai/admin/fai/main.inc b/gosa-plugins/fai/admin/fai/main.inc new file mode 100644 index 000000000..b482e3248 --- /dev/null +++ b/gosa-plugins/fai/admin/fai/main.inc @@ -0,0 +1,56 @@ +remove_lock(); + del_lock ($ui->dn); + session::un_set ('FAI'); + } +} else { + /* Create usermanagement object on demand */ + if (!session::is_set('FAI') || (isset($_GET['reset']) && $_GET['reset'] == 1)){ + $FAI= new faiManagement($config, $ui); + $FAI->set_acl_category("fai"); + $FAI->set_acl_base(session::get('CurrentMainBase')); + session::set('FAI',$FAI); + } + $FAI = session::get('FAI'); + $FAI->save_object(); + $output= $FAI->execute(); + + /* Reset requested? */ + if (isset($_GET['reset']) && $_GET['reset'] == 1){ + del_lock ($ui->dn); + session::un_set ('FAI'); + } + /* Page header*/ + if (session::is_set('objectinfo')){ + $display= print_header(get_template_path('images/fai.png'), _("Fully Automatic Installation"), "\"\" ".@LDAP::fix(session::get('objectinfo'))); + } else { + $display= print_header(get_template_path('images/fai.png'), _("Fully Automatic Installation")); + } + $display.= $output; + + session::set('FAI',$FAI); +} + +?> diff --git a/gosa-plugins/fai/admin/fai/remove.tpl b/gosa-plugins/fai/admin/fai/remove.tpl new file mode 100644 index 000000000..10bf93dc5 --- /dev/null +++ b/gosa-plugins/fai/admin/fai/remove.tpl @@ -0,0 +1,24 @@ +
+ {t}Warning{/t} +
+ +

+ {$warning} + {t}This includes 'all' object information. Please double check if your really want to do this since there is no way for GOsa to get your data back.{/t} +

+ +

+ {t}Best thing to do before performing this action would be to save the current contents of your LDAP tree in a file. So - if you've done so - press 'Delete' to continue or 'Cancel' to abort.{/t} +

+ +

+{if $multiple} + +   + +{else} + +   + +{/if} +

diff --git a/gosa-plugins/fai/admin/fai/remove_branch.tpl b/gosa-plugins/fai/admin/fai/remove_branch.tpl new file mode 100644 index 000000000..3ed7f2329 --- /dev/null +++ b/gosa-plugins/fai/admin/fai/remove_branch.tpl @@ -0,0 +1,18 @@ +
+  {t}Warning{/t} +
+

+ {$info} + {t}This includes all account data, system access, etc. for this branch. Please double check if your really want to do this since there is no way for GOsa to get your data back.{/t} +

+ +

+ {t}So - if you're sure - press 'Delete' to continue or 'Cancel' to abort.{/t} +

+ +

+ +   + +

+ diff --git a/gosa-plugins/fai/admin/fai/tabsHook.inc b/gosa-plugins/fai/admin/fai/tabsHook.inc new file mode 100644 index 000000000..ed61e1fc8 --- /dev/null +++ b/gosa-plugins/fai/admin/fai/tabsHook.inc @@ -0,0 +1,48 @@ +addSpecialTabs(); + } + + function check($ignore_account= FALSE) + { + return (tabs::check(TRUE)); + } + + + function save($ignore_account= FALSE) + { + $baseobject= $this->by_object['faiHook']; + + $new_dn= 'cn='.$baseobject->cn.",".get_ou('faihookou').get_ou('faiou').session::get('CurrentMainBase'); + $faifilter = session::get('faifilter'); + if($faifilter['branch']!="main"){ + $new_dn ='cn='.$baseobject->cn.",".get_ou('faihookou').$faifilter['branch']; + } + + 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); + } + +} + +?> diff --git a/gosa-plugins/fai/admin/fai/tabsPackage.inc b/gosa-plugins/fai/admin/fai/tabsPackage.inc new file mode 100644 index 000000000..e678a835e --- /dev/null +++ b/gosa-plugins/fai/admin/fai/tabsPackage.inc @@ -0,0 +1,51 @@ +addSpecialTabs(); + } + + function check($ignore_account= FALSE) + { + return (tabs::check(TRUE)); + } + + + function save($ignore_account= FALSE) + { + $baseobject= $this->by_object['faiPackage']; + + $new_dn= 'cn='.$baseobject->cn.",".get_ou('faipackageou').get_ou('faiou').session::get('CurrentMainBase'); + + $faifilter = session::get('faifilter'); + + if($faifilter['branch']!="main"){ + $new_dn ='cn='.$baseobject->cn.",".get_ou('faipackageou').$faifilter['branch']; + } + + 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); + } + +} + +?> diff --git a/gosa-plugins/fai/admin/fai/tabsPartition.inc b/gosa-plugins/fai/admin/fai/tabsPartition.inc new file mode 100644 index 000000000..308d50b8a --- /dev/null +++ b/gosa-plugins/fai/admin/fai/tabsPartition.inc @@ -0,0 +1,50 @@ +addSpecialTabs(); + } + + function check($ignore_account= FALSE) + { + return (tabs::check(TRUE)); + } + + + function save($ignore_account= FALSE) + { + $baseobject= $this->by_object['faiPartitionTable']; + + $new_dn= 'cn='.$baseobject->cn.",".get_ou('faipartitionou').get_ou('faiou').session::get('CurrentMainBase'); + + $faifilter = session::get('faifilter'); + if($faifilter['branch']!="main"){ + $new_dn ='cn='.$baseobject->cn.",".get_ou('faipartitionou').$faifilter['branch']; + } + + 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); + } + +} + +?> diff --git a/gosa-plugins/fai/admin/fai/tabsProfile.inc b/gosa-plugins/fai/admin/fai/tabsProfile.inc new file mode 100644 index 000000000..ccac199c2 --- /dev/null +++ b/gosa-plugins/fai/admin/fai/tabsProfile.inc @@ -0,0 +1,50 @@ +addSpecialTabs(); + } + + function check($ignore_account= FALSE) + { + return (tabs::check(TRUE)); + } + + + function save($ignore_account= FALSE) + { + $baseobject= $this->by_object['faiProfile']; + + $new_dn= 'cn='.$baseobject->cn.",".get_ou('faiprofileou').get_ou('faiou').session::get('CurrentMainBase'); + + $faifilter = session::get('faifilter'); + if($faifilter['branch']!="main"){ + $new_dn ='cn='.$baseobject->cn.",".get_ou('faiprofileou').$faifilter['branch']; + } + + 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); + } + +} + +?> diff --git a/gosa-plugins/fai/admin/fai/tabsScript.inc b/gosa-plugins/fai/admin/fai/tabsScript.inc new file mode 100644 index 000000000..094fbb405 --- /dev/null +++ b/gosa-plugins/fai/admin/fai/tabsScript.inc @@ -0,0 +1,51 @@ +addSpecialTabs(); + } + + function check($ignore_account= FALSE) + { + return (tabs::check(TRUE)); + } + + + function save($ignore_account= FALSE) + { + $baseobject= $this->by_object['faiScript']; + + $new_dn= 'cn='.$baseobject->cn.",".get_ou('faiscriptou').get_ou('faiou').session::get('CurrentMainBase'); + + $faifilter = session::get('faifilter'); + + if($faifilter['branch']!="main"){ + $new_dn ='cn='.$baseobject->cn.",".get_ou('faiscriptou').$faifilter['branch']; + } + + 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); + } + +} + +?> diff --git a/gosa-plugins/fai/admin/fai/tabsTemplate.inc b/gosa-plugins/fai/admin/fai/tabsTemplate.inc new file mode 100644 index 000000000..5f7f8ab4c --- /dev/null +++ b/gosa-plugins/fai/admin/fai/tabsTemplate.inc @@ -0,0 +1,50 @@ +addSpecialTabs(); + } + + function check($ignore_account= FALSE) + { + return (tabs::check(TRUE)); + } + + + function save($ignore_account= FALSE) + { + $baseobject= $this->by_object['faiTemplate']; + + $new_dn= 'cn='.$baseobject->cn.",".get_ou('faitemplateou').get_ou('faiou').session::get('CurrentMainBase'); + + $faifilter = session::get('faifilter'); + if($faifilter['branch']!="main"){ + $new_dn ='cn='.$baseobject->cn.",".get_ou('faitemplateou').$faifilter['branch']; + } + + 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); + } + +} + +?> diff --git a/gosa-plugins/fai/admin/fai/tabsVariable.inc b/gosa-plugins/fai/admin/fai/tabsVariable.inc new file mode 100644 index 000000000..11694b1d1 --- /dev/null +++ b/gosa-plugins/fai/admin/fai/tabsVariable.inc @@ -0,0 +1,51 @@ +addSpecialTabs(); + } + + function check($ignore_account= FALSE) + { + return (tabs::check(TRUE)); + } + + + function save($ignore_account= FALSE) + { + $baseobject= $this->by_object['faiVariable']; + + $new_dn= 'cn='.$baseobject->cn.",".get_ou('faivariableou').get_ou('faiou').session::get('CurrentMainBase'); + + $faifilter = session::get('faifilter'); + + if($faifilter['branch']!="main"){ + $new_dn ='cn='.$baseobject->cn.",".get_ou('faivariableou').$faifilter['branch']; + } + + 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); + } + +} + +?>