1 <?php
2 /*
3 * This code is part of GOsa (http://www.gosa-project.org)
4 * Copyright (C) 2003-2008 GONICUS GmbH
5 *
6 * ID: $$Id: class_roleManagement.inc 14742 2009-11-04 13:18:33Z hickert $$
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
23 class faiManagement extends management
24 {
25 var $plHeadline = "Software deployment";
26 var $plDescription = "Manage software packages and deployment reciepes";
27 var $plIcon = "plugins/fai/images/plugin.png";
29 // Tab definition
30 protected $tabClass = "roletabs";
31 protected $tabType = "ROLETABS";
32 protected $aclCategory = "roles";
33 protected $aclPlugin = "role";
34 protected $objectName = "role";
36 var $fai_release = ""; // The currently selected release while in release management mode!
38 function __construct($config,$ui)
39 {
40 $this->config = $config;
41 $this->ui = $ui;
42 $this->storagePoints = array(
43 get_ou('faiPartitionRDN'),
44 get_ou('faiPackageRDN'),
45 get_ou('faiScriptRDN'),
46 get_ou('faiVariableRDN'),
47 get_ou('faiHookRDN'),
48 get_ou('faiProfileRDN'),get_ou('faiTemplateRDN'));
50 // Build filter
51 if (session::global_is_set(get_class($this)."_filter")){
52 $filter= session::global_get(get_class($this)."_filter");
53 } else {
54 $filter = new filter(get_template_path("fai-filter.xml", true));
55 $filter->setObjectStorage($this->storagePoints);
56 }
57 $this->setFilter($filter);
59 // Build headpage
60 $headpage = new listing(get_template_path("fai-list.xml", true));
61 $headpage->setFilter($filter);
62 $headpage->registerElementFilter("filterProperties", "faiManagement::filterProperties");
64 // Add copy&paste and snapshot handler.
65 if ($this->config->boolValueIsTrue("main", "copyPaste")){
66 $this->cpHandler = new CopyPasteHandler($this->config);
67 }
68 if($this->config->get_cfg_value("enableSnapshots") == "true"){
69 $this->snapHandler = new SnapshotHandler($this->config);
70 }
71 $this->registerAction("editByGroup","editByGroup");
72 parent::__construct($config, $ui, "roles", $headpage);
73 }
76 function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
77 {
78 $headpage = $this->getHeadpage();
79 if(count($target) == 1){
80 $entry = $headpage->getEntry($target[0]);
81 if($entry){
82 if(count($entry['GROUPS']) == 1){
83 $data = array_pop($entry['GROUPS']);
84 $type = $this->get_type($data);
85 management::editEntry('editEntry',array($data['dn']),array(),$type[0],$type[2],$type[1]);
86 }else{
87 $this->dialogObject = new faiGroupHandle($entry['GROUPS'],"edit");
88 }
89 }
90 }
91 }
94 function removeEntryRequested($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
95 {
96 $headpage = $this->getHeadpage();
97 if(count($target) == 1){
98 $entry = $headpage->getEntry($target[0]);
99 if($entry){
100 $this->dialogObject = new faiGroupHandle($entry['GROUPS'],"remove");
101 }
102 }
103 }
106 function editByGroup()
107 {
108 if($this->dialogObject instanceOf faiGroupHandle && $this->dialogObject->get_mode() == "edit"){
109 $this->dialogObject->save_object();
110 $entry = $this->dialogObject->get_selected();
111 $this->closeDialogs();
112 $data = array_pop($entry);
113 $type = $this->get_type($data);
114 management::editEntry('editEntry',array($data['dn']),array(),$type[0],$type[2],$type[1]);
115 }elseif($this->dialogObject instanceOf faiGroupHandle && $this->dialogObject->get_mode() == "remove"){
116 $this->dialogObject->save_object();
117 $to_delete = $entry = $this->dialogObject->get_selected();
118 $dns = array();
121 // Check FAIstate to ensure that we do not remove frozen objects
122 // additionally check ACLs
123 $locked = array();
124 $disallowed = array();
125 foreach($to_delete as $obj){
126 if(isset($obj['FAIstate']) && preg_match('/^freeze/', $obj['FAIstate'])){
127 $locked[] = $obj['dn'];
128 }else{
129 $type = $this->get_type($obj);
130 $acl = $this->ui->get_permissions($obj['dn'], 'acl/'.$type[1]);
131 if(!preg_match("/d/",$acl)){
132 $disallowed[] = $obj['dn'];
133 }else{
134 $dns[] = $obj['dn'];
135 }
136 }
137 }
139 // Display info dialog about locked and not removeable entries
140 if(count($locked)){
141 msg_dialog::display(_("Branch locked"),sprintf(_("The following entries are locked, you can't remove them %s."),
142 msgPool::buildList($locked)));
143 }
145 // Display info dialog about not removeable entries due to permissions
146 if(count($disallowed)){
147 msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
148 }
150 // There are entries left to be removed
151 if(count($dns)){
152 $this->closeDialogs();
153 $this->dns = $dns;
155 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Entry removel requested!");
157 // check locks
158 if ($user= get_multiple_locks($this->dns)){
159 return(gen_locked_message($user,$this->dns));
160 }
162 // Add locks
163 $dns_names = array();
164 foreach($this->dns as $dn){
165 $dns_names[] =LDAP::fix($dn);
166 }
167 add_lock ($this->dns, $this->ui->dn);
169 // Display confirmation dialog.
170 $smarty = get_smarty();
171 $smarty->assign("info", msgPool::deleteInfo($dns_names,_($this->objectName)));
172 $smarty->assign("multiple", true);
173 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
174 }else{
175 $this->closeDialogs();
176 }
177 }
178 }
181 /*! \brief Object removal was confirmed, now remove the requested entries.
182 *
183 * @param String 'action' The name of the action which was the used as trigger.
184 * @param Array 'target' A list of object dns, which should be affected by this method.
185 * @param Array 'all' A combination of both 'action' and 'target'.
186 */
187 function removeEntryConfirmed($action="",$target=array(),$all=array(),
188 $altTabClass="",$altTabType="",$altAclCategory="")
189 {
190 $ldap = $this->config->get_ldap_link();
191 $ldap->cd($this->config->current['BASE']);
192 foreach($this->dns as $key => $dn){
193 $ldap->cat($dn);
194 if($ldap->count()){
195 $attrs = $ldap->fetch();
196 $type= $this->get_type($attrs);
197 management::removeEntryConfirmed($action,array($dn),$all,$type[0],$type[2],$type[1]);
199 // Now save changes
200 FAI::save_release_changes_now();
201 $to_del = FAI::clean_up_releases($dn);
202 foreach($to_del as $dn){
203 $ldap->rmdir_recursive($dn);
204 }
205 }
206 }
207 }
209 protected function saveChanges()
210 {
211 management::saveChanges();
213 // Now save changes
214 FAI::save_release_changes_now();
215 $to_del = FAI::clean_up_releases($this->last_dn);
216 foreach($to_del as $dn){
217 $ldap->rmdir_recursive($dn);
218 }
219 }
221 protected function applyChanges()
222 {
223 management::applyChanges();
225 // Now save changes
226 FAI::save_release_changes_now();
227 $to_del = FAI::clean_up_releases($this->last_dn);
228 foreach($to_del as $dn){
229 $ldap->rmdir_recursive($dn);
230 }
231 }
233 function detectPostActions()
234 {
235 $action = management::detectPostActions();
236 if(isset($_POST['faiGroupHandle_cancel'])) $action['action'] = "cancel";
237 if(isset($_POST['faiGroupHandle_apply'])) $action['action'] = "editByGroup";
239 foreach($_POST as $name => $value){
240 if(preg_match("/^edit_([0-9]*)_([a-z]*)_(x|y)/i", $name)){
241 $id = preg_replace("/^edit_([0-9]*)_([a-z]*)_(x|y)/i","\\1", $name);
242 $tab = preg_replace("/^edit_([0-9]*)_([a-z]*)_(x|y)/i","\\2", $name);
243 $headpage = $this->getHeadpage();
244 if(isset($headpage->entries[$id]['GROUPS'][$tab])){
245 $data =$headpage->entries[$id]['GROUPS'][$tab];
246 $type = $this->get_type($data);
247 management::editEntry('editEntry',array($data['dn']),array(),$type[0],$type[2],$type[1]);
248 }
249 break;
250 }
251 }
252 return($action);
253 }
256 function renderList()
257 {
258 $filter = $this->getFilter();
259 $headpage = $this->getHeadpage();
260 $filter->setComboBoxOptions("RELEASE",$this->getReleaseList());
262 if(isset($_POST['RELEASE'])){
263 $this->fai_release = get_post('RELEASE');
264 }
265 $headpage->setBase($this->fai_release);
266 $headpage->update();
267 $smarty = get_smarty();
268 $smarty->assign("fai_release", $this->fai_release);
269 $smarty->assign("fai_base", get_ou('faiBaseRDN').$this->config->current['BASE']);
270 $r = $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'));
271 $c = $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs'));
272 $smarty->assign("allow_create", $c);
273 $smarty->assign("allow_remove", $r);
274 $smarty->assign("fai_base", get_ou('faiBaseRDN').$this->config->current['BASE']);
275 $display = $headpage->render();
276 return($this->getHeader().$display);
277 }
279 function getReleaseList($base = "", $prefix ="")
280 {
281 $list = array();
282 if(empty($base)){
283 $base = get_ou('faiBaseRDN').$this->config->current['BASE'];
284 $list[$base] = "/";
285 }
287 $ldap = $this->config->get_ldap_link();
288 $ldap->ls("(objectClass=FAIbranch)",$base,array("ou","FAIstate"));
289 $cfg_rel = $this->config->search("faiManagement","DEFAULTFAIRELEASE",array("menu"));
291 while($release = $ldap->fetch()){
292 $list[$release['dn']] = $prefix.$release['ou'][0];
294 // Preset to prefered releaes if necessary
295 if(empty($this->fai_release) && $cfg_rel == $release['dn']){
296 $this->fai_release = $release['dn'];
297 }
299 $list = array_merge($list,$this->getReleaseList($release['dn'],$prefix." "));
300 }
301 return($list);
302 }
305 static function filterProperties($row, $classes)
306 {
307 $objects = array(
308 "FAIpartitionTable" => array("IMG"=> "plugins/fai/images/fai_partitionTable.png",
309 "NAME"=>_("Partition table"),"KZL"=> "PT", "VAR"=>"ShowPartitions"),
310 "FAIpackageList" => array("IMG"=> "plugins/fai/images/fai_packages.png",
311 "NAME"=>_("Package list") , "KZL"=> "PL", "VAR"=>"ShowPackages"),
312 "FAIscript" => array("IMG"=> "plugins/fai/images/fai_script.png",
313 "NAME"=>_("Scripts") , "KZL"=> "S", "VAR"=>"ShowScripts"),
314 "FAIvariable" => array("IMG"=> "plugins/fai/images/fai_variable.png",
315 "NAME"=>_("Variables") , "KZL"=> "V", "VAR"=>"ShowVariables"),
316 "FAIhook" => array("IMG"=> "plugins/fai/images/fai_hook.png",
317 "NAME"=>_("Hooks"), "KZL"=> "H", "VAR"=>"ShowHooks"),
318 "FAIprofile" => array("IMG"=> "plugins/fai/images/fai_profile.png",
319 "NAME"=>_("Profile") , "KZL"=> "P", "VAR"=>"ShowProfiles"),
320 "FAItemplate" => array("IMG"=> "plugins/fai/images/fai_template.png",
321 "NAME"=>_("Templates") , "KZL"=> "T", "VAR"=>"ShowTemplates"),
322 "opsi_netboot" => array("IMG"=> "plugins/opsi/images/netboot_package.png",
323 "NAME"=>_("OPSI netboot product") , "KZL"=> "ON", "VAR"=>"ShowOpsiNetboot"),
324 "opsi_local" => array("IMG"=> "plugins/opsi/images/local_package.png",
325 "NAME"=>_("OPSI localboot product") , "KZL"=> "OL", "VAR"=>"ShowOpsiLocal"));
327 $icon_list = "";
328 foreach($objects as $type => $type_data){
329 if(in_array($type, $classes)){
330 $icon_list .= "<input type='image' src='".$type_data['IMG']."' title='".$type_data['NAME']."'
331 alt='".$type_data['KZL']."' class='center' name='edit_".$row."_".$type."'>\n";
332 }else{
333 $icon_list .= "<img src='images/empty.png' alt=' ' class='center'>\n";
334 }
335 }
337 return $icon_list;
338 }
341 function get_type($array){
342 if(!isset($array['objectClass'])) return(array());
343 if(in_array("FAIpartitionTable",$array['objectClass'])){
344 return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
345 }
346 if(in_array("FAIscript",$array['objectClass'])){
347 return(array("tabsScript","faiScript","FAISCRIPTTABS"));
348 }
349 if(in_array("FAItemplate",$array['objectClass'])){
350 return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
351 }
352 if(in_array("FAIhook",$array['objectClass'])){
353 return(array("tabsHook","faiHook","FAIHOOKTABS"));
354 }
355 if(in_array("FAIvariable",$array['objectClass'])){
356 return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
357 }
358 if(in_array("FAIprofile",$array['objectClass'])){
359 return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
360 }
361 if(in_array("FAIpackageList",$array['objectClass'])){
362 return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
363 }
364 return(array());
365 }
366 }
367 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
368 ?>