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!
37 var $fai_base = "";
39 function __construct($config,$ui)
40 {
41 $this->config = $config;
42 $this->fai_base = get_ou("faiBaseRDN").$this->config->current['BASE'];
43 $this->ui = $ui;
44 $this->storagePoints = array(
45 get_ou('faiPartitionRDN'),
46 get_ou('faiPackageRDN'),
47 get_ou('faiScriptRDN'),
48 get_ou('faiVariableRDN'),
49 get_ou('faiHookRDN'),
50 get_ou('faiProfileRDN'),get_ou('faiTemplateRDN'));
52 // Build filter
53 if (session::global_is_set(get_class($this)."_filter")){
54 $filter= session::global_get(get_class($this)."_filter");
55 } else {
56 $filter = new filter(get_template_path("fai-filter.xml", true));
57 $filter->setObjectStorage($this->storagePoints);
58 }
59 $this->setFilter($filter);
61 // Build headpage
62 $headpage = new listing(get_template_path("fai-list.xml", true));
63 $headpage->setFilter($filter);
64 $headpage->registerElementFilter("filterProperties", "faiManagement::filterProperties");
66 // Add copy&paste and snapshot handler.
67 if ($this->config->boolValueIsTrue("main", "copyPaste")){
68 $this->cpHandler = new CopyPasteHandler($this->config);
69 }
70 if($this->config->get_cfg_value("enableSnapshots") == "true"){
71 $this->snapHandler = new SnapshotHandler($this->config);
72 }
73 $this->registerAction("editByGroup","editByGroup");
74 $this->registerAction("createBranch","createBranch");
75 parent::__construct($config, $ui, "roles", $headpage);
76 }
79 function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
80 {
81 $headpage = $this->getHeadpage();
82 if(count($target) == 1){
83 $entry = $headpage->getEntry($target[0]);
84 if($entry){
85 if(count($entry['GROUPS']) == 1){
86 $data = array_pop($entry['GROUPS']);
87 $type = $this->get_type($data);
88 management::editEntry('editEntry',array($data['dn']),array(),$type[0],$type[2],$type[1]);
89 }else{
90 $this->dialogObject = new faiGroupHandle($entry['GROUPS'],"edit");
91 }
92 }
93 }
94 }
97 function removeEntryRequested($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
98 {
99 $headpage = $this->getHeadpage();
100 if(count($target) == 1){
101 $entry = $headpage->getEntry($target[0]);
102 if($entry){
103 $this->dialogObject = new faiGroupHandle($entry['GROUPS'],"remove");
104 }
105 }
106 }
109 function editByGroup()
110 {
111 if($this->dialogObject instanceOf faiGroupHandle && $this->dialogObject->get_mode() == "edit"){
112 $this->dialogObject->save_object();
113 $entry = $this->dialogObject->get_selected();
114 $this->closeDialogs();
115 $data = array_pop($entry);
116 $type = $this->get_type($data);
117 management::editEntry('editEntry',array($data['dn']),array(),$type[0],$type[2],$type[1]);
118 }elseif($this->dialogObject instanceOf faiGroupHandle && $this->dialogObject->get_mode() == "remove"){
119 $this->dialogObject->save_object();
120 $to_delete = $entry = $this->dialogObject->get_selected();
121 $dns = array();
124 // Check FAIstate to ensure that we do not remove frozen objects
125 // additionally check ACLs
126 $locked = array();
127 $disallowed = array();
128 foreach($to_delete as $obj){
129 if(isset($obj['FAIstate']) && preg_match('/^freeze/', $obj['FAIstate'])){
130 $locked[] = $obj['dn'];
131 }else{
132 $type = $this->get_type($obj);
133 $acl = $this->ui->get_permissions($obj['dn'], 'acl/'.$type[1]);
134 if(!preg_match("/d/",$acl)){
135 $disallowed[] = $obj['dn'];
136 }else{
137 $dns[] = $obj['dn'];
138 }
139 }
140 }
142 // Display info dialog about locked and not removeable entries
143 if(count($locked)){
144 msg_dialog::display(_("Branch locked"),sprintf(_("The following entries are locked, you can't remove them %s."),
145 msgPool::buildList($locked)));
146 }
148 // Display info dialog about not removeable entries due to permissions
149 if(count($disallowed)){
150 msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
151 }
153 // There are entries left to be removed
154 if(count($dns)){
155 $this->closeDialogs();
156 $this->dns = $dns;
158 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Entry removel requested!");
160 // check locks
161 if ($user= get_multiple_locks($this->dns)){
162 return(gen_locked_message($user,$this->dns));
163 }
165 // Add locks
166 $dns_names = array();
167 foreach($this->dns as $dn){
168 $dns_names[] =LDAP::fix($dn);
169 }
170 add_lock ($this->dns, $this->ui->dn);
172 // Display confirmation dialog.
173 $smarty = get_smarty();
174 $smarty->assign("info", msgPool::deleteInfo($dns_names,_($this->objectName)));
175 $smarty->assign("multiple", true);
176 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
177 }else{
178 $this->closeDialogs();
179 }
180 }
181 }
184 /*! \brief Object removal was confirmed, now remove the requested entries.
185 *
186 * @param String 'action' The name of the action which was the used as trigger.
187 * @param Array 'target' A list of object dns, which should be affected by this method.
188 * @param Array 'all' A combination of both 'action' and 'target'.
189 */
190 function removeEntryConfirmed($action="",$target=array(),$all=array(),
191 $altTabClass="",$altTabType="",$altAclCategory="")
192 {
193 $ldap = $this->config->get_ldap_link();
194 $ldap->cd($this->config->current['BASE']);
195 foreach($this->dns as $key => $dn){
196 $ldap->cat($dn);
197 if($ldap->count()){
198 $attrs = $ldap->fetch();
199 $type= $this->get_type($attrs);
200 management::removeEntryConfirmed($action,array($dn),$all,$type[0],$type[2],$type[1]);
202 // Now save changes
203 FAI::save_release_changes_now();
204 $to_del = FAI::clean_up_releases($dn);
205 foreach($to_del as $dn){
206 $ldap->rmdir_recursive($dn);
207 }
208 }
209 }
210 }
212 protected function saveChanges()
213 {
214 management::saveChanges();
216 // Now save changes
217 FAI::save_release_changes_now();
218 $to_del = FAI::clean_up_releases($this->last_dn);
219 foreach($to_del as $dn){
220 $ldap->rmdir_recursive($dn);
221 }
222 }
224 protected function applyChanges()
225 {
226 management::applyChanges();
228 // Now save changes
229 FAI::save_release_changes_now();
230 $to_del = FAI::clean_up_releases($this->last_dn);
231 foreach($to_del as $dn){
232 $ldap->rmdir_recursive($dn);
233 }
234 }
236 function detectPostActions()
237 {
238 $action = management::detectPostActions();
239 if(isset($_POST['faiGroupHandle_cancel'])) $action['action'] = "cancel";
240 if(isset($_POST['faiGroupHandle_apply'])) $action['action'] = "editByGroup";
241 if(isset($_GET['act']) && $_GET['act'] == "branch_branch") $action['action'] = "createBranch";
243 foreach($_POST as $name => $value){
244 if(preg_match("/^edit_([0-9]*)_([a-z]*)_(x|y)/i", $name)){
245 $id = preg_replace("/^edit_([0-9]*)_([a-z]*)_(x|y)/i","\\1", $name);
246 $tab = preg_replace("/^edit_([0-9]*)_([a-z]*)_(x|y)/i","\\2", $name);
247 $headpage = $this->getHeadpage();
248 if(isset($headpage->entries[$id]['GROUPS'][$tab])){
249 $data =$headpage->entries[$id]['GROUPS'][$tab];
250 $type = $this->get_type($data);
251 management::editEntry('editEntry',array($data['dn']),array(),$type[0],$type[2],$type[1]);
252 }
253 break;
254 }
255 }
256 return($action);
257 }
260 function renderList()
261 {
262 $filter = $this->getFilter();
263 $headpage = $this->getHeadpage();
264 $filter->setComboBoxOptions("RELEASE",$this->getReleaseList());
266 if(isset($_POST['RELEASE'])){
267 $this->fai_release = get_post('RELEASE');
268 }
269 $headpage->setBase($this->fai_release);
270 $headpage->update();
271 $smarty = get_smarty();
272 $smarty->assign("fai_release", $this->fai_release);
273 $smarty->assign("fai_base", $this->fai_base);
274 $r = $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'));
275 $c = $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs'));
276 $smarty->assign("allow_create", $c);
277 $smarty->assign("allow_remove", $r);
278 $display = $headpage->render();
279 return($this->getHeader().$display);
280 }
282 function getReleaseList($base = "", $prefix ="")
283 {
284 $list = array();
285 if(empty($base)){
286 $base = $this->fai_base;
287 $list[$base] = "/";
288 }
290 $ldap = $this->config->get_ldap_link();
291 $ldap->ls("(objectClass=FAIbranch)",$base,array("ou","FAIstate"));
292 $cfg_rel = $this->config->search("faiManagement","DEFAULTFAIRELEASE",array("menu"));
294 while($release = $ldap->fetch()){
295 $list[$release['dn']] = $prefix.$release['ou'][0];
297 // Preset to prefered releaes if necessary
298 if(empty($this->fai_release) && $cfg_rel == $release['dn']){
299 $this->fai_release = $release['dn'];
300 }
302 $list = array_merge($list,$this->getReleaseList($release['dn'],$prefix." "));
303 }
304 return($list);
305 }
308 static function filterProperties($row, $classes)
309 {
310 $objects = array(
311 "FAIpartitionTable" => array("IMG"=> "plugins/fai/images/fai_partitionTable.png",
312 "NAME"=>_("Partition table"),"KZL"=> "PT", "VAR"=>"ShowPartitions"),
313 "FAIpackageList" => array("IMG"=> "plugins/fai/images/fai_packages.png",
314 "NAME"=>_("Package list") , "KZL"=> "PL", "VAR"=>"ShowPackages"),
315 "FAIscript" => array("IMG"=> "plugins/fai/images/fai_script.png",
316 "NAME"=>_("Scripts") , "KZL"=> "S", "VAR"=>"ShowScripts"),
317 "FAIvariable" => array("IMG"=> "plugins/fai/images/fai_variable.png",
318 "NAME"=>_("Variables") , "KZL"=> "V", "VAR"=>"ShowVariables"),
319 "FAIhook" => array("IMG"=> "plugins/fai/images/fai_hook.png",
320 "NAME"=>_("Hooks"), "KZL"=> "H", "VAR"=>"ShowHooks"),
321 "FAIprofile" => array("IMG"=> "plugins/fai/images/fai_profile.png",
322 "NAME"=>_("Profile") , "KZL"=> "P", "VAR"=>"ShowProfiles"),
323 "FAItemplate" => array("IMG"=> "plugins/fai/images/fai_template.png",
324 "NAME"=>_("Templates") , "KZL"=> "T", "VAR"=>"ShowTemplates"),
325 "opsi_netboot" => array("IMG"=> "plugins/opsi/images/netboot_package.png",
326 "NAME"=>_("OPSI netboot product") , "KZL"=> "ON", "VAR"=>"ShowOpsiNetboot"),
327 "opsi_local" => array("IMG"=> "plugins/opsi/images/local_package.png",
328 "NAME"=>_("OPSI localboot product") , "KZL"=> "OL", "VAR"=>"ShowOpsiLocal"));
330 $icon_list = "";
331 foreach($objects as $type => $type_data){
332 if(in_array($type, $classes)){
333 $icon_list .= "<input type='image' src='".$type_data['IMG']."' title='".$type_data['NAME']."'
334 alt='".$type_data['KZL']."' class='center' name='edit_".$row."_".$type."'>\n";
335 }else{
336 $icon_list .= "<img src='images/empty.png' alt=' ' class='center'>\n";
337 }
338 }
340 return $icon_list;
341 }
344 function createBranch()
345 {
346 $smarty = get_smarty();
347 $this->dispNewBranch=true;
348 $smarty->assign("iframe",false);
349 $smarty->assign("BranchName","");
350 return($smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__))));
351 }
354 function get_type($array){
355 if(!isset($array['objectClass'])) return(array());
356 if(in_array("FAIpartitionTable",$array['objectClass'])){
357 return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
358 }
359 if(in_array("FAIscript",$array['objectClass'])){
360 return(array("tabsScript","faiScript","FAISCRIPTTABS"));
361 }
362 if(in_array("FAItemplate",$array['objectClass'])){
363 return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
364 }
365 if(in_array("FAIhook",$array['objectClass'])){
366 return(array("tabsHook","faiHook","FAIHOOKTABS"));
367 }
368 if(in_array("FAIvariable",$array['objectClass'])){
369 return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
370 }
371 if(in_array("FAIprofile",$array['objectClass'])){
372 return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
373 }
374 if(in_array("FAIpackageList",$array['objectClass'])){
375 return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
376 }
377 return(array());
378 }
379 }
380 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
381 ?>