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;
43 $this->storagePoints = array(
44 get_ou('faiPartitionRDN'),
45 get_ou('faiPackageRDN'),
46 get_ou('faiScriptRDN'),
47 get_ou('faiVariableRDN'),
48 get_ou('faiHookRDN'),
49 get_ou('faiProfileRDN'),get_ou('faiTemplateRDN'));
51 // Build filter
52 # if (session::global_is_set(get_class($this)."_filter")){
53 # $filter= session::global_get(get_class($this)."_filter");
54 # } else {
55 $filter = new filter(get_template_path("fai-filter.xml", true));
56 $filter->setObjectStorage($this->storagePoints);
57 # }
58 $this->setFilter($filter);
60 // Build headpage
61 $headpage = new listing(get_template_path("fai-list.xml", true));
62 $headpage->setFilter($filter);
63 $headpage->registerElementFilter("filterProperties", "faiManagement::filterProperties");
65 // Add copy&paste and snapshot handler.
66 if ($this->config->boolValueIsTrue("main", "copyPaste")){
67 $this->cpHandler = new CopyPasteHandler($this->config);
68 }
69 if($this->config->get_cfg_value("enableSnapshots") == "true"){
70 $this->snapHandler = new SnapshotHandler($this->config);
71 }
72 $this->registerAction("editByGroup","editByGroup");
73 parent::__construct($config, $ui, "roles", $headpage);
74 }
77 function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
78 {
79 $headpage = $this->getHeadpage();
80 if(count($target) == 1){
81 $entry = $headpage->getEntry($target[0]);
82 if($entry){
83 if(count($entry['GROUPS']) == 1){
84 $data = array_pop($entry['GROUPS']);
85 $type = $this->get_type($data);
86 management::editEntry('editEntry',array($data['dn']),array(),$type[0],$type[2],$type[1]);
87 }else{
88 $this->dialogObject = new faiGroupHandle($entry['GROUPS'],"edit");
89 }
90 }
91 }
92 }
95 function removeEntryRequested($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
96 {
97 $headpage = $this->getHeadpage();
98 if(count($target) == 1){
99 $entry = $headpage->getEntry($target[0]);
100 if($entry){
101 $this->dialogObject = new faiGroupHandle($entry['GROUPS'],"remove");
102 }
103 }
104 }
107 function editByGroup()
108 {
109 if($this->dialogObject instanceOf faiGroupHandle && $this->dialogObject->get_mode() == "edit"){
110 $this->dialogObject->save_object();
111 $entry = $this->dialogObject->get_selected();
112 $this->closeDialogs();
113 $data = array_pop($entry);
114 $type = $this->get_type($data);
115 management::editEntry('editEntry',array($data['dn']),array(),$type[0],$type[2],$type[1]);
116 }elseif($this->dialogObject instanceOf faiGroupHandle && $this->dialogObject->get_mode() == "remove"){
117 $this->dialogObject->save_object();
118 $to_delete = $entry = $this->dialogObject->get_selected();
119 $dns = array();
122 // Check FAIstate to ensure that we do not remove frozen objects
123 // additionally check ACLs
124 $locked = array();
125 $disallowed = array();
126 foreach($to_delete as $obj){
127 if(isset($obj['FAIstate']) && preg_match('/^freeze/', $obj['FAIstate'])){
128 $locked[] = $obj['dn'];
129 }else{
130 $type = $this->get_type($obj);
131 $acl = $this->ui->get_permissions($obj['dn'], 'acl/'.$type[1]);
132 if(!preg_match("/d/",$acl)){
133 $disallowed[] = $obj['dn'];
134 }else{
135 $dns[] = $obj['dn'];
136 }
137 }
138 }
140 // Display info dialog about locked and not removeable entries
141 if(count($locked)){
142 msg_dialog::display(_("Branch locked"),sprintf(_("The following entries are locked, you can't remove them %s."),
143 msgPool::buildList($locked)));
144 }
146 // Display info dialog about not removeable entries due to permissions
147 if(count($disallowed)){
148 msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
149 }
151 // There are entries left to be removed
152 if(count($dns)){
153 $this->closeDialogs();
154 $this->dns = $dns;
156 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Entry removel requested!");
158 // check locks
159 if ($user= get_multiple_locks($this->dns)){
160 return(gen_locked_message($user,$this->dns));
161 }
163 // Add locks
164 $dns_names = array();
165 foreach($this->dns as $dn){
166 $dns_names[] =LDAP::fix($dn);
167 }
168 add_lock ($this->dns, $this->ui->dn);
170 // Display confirmation dialog.
171 $smarty = get_smarty();
172 $smarty->assign("info", msgPool::deleteInfo($dns_names,_($this->objectName)));
173 $smarty->assign("multiple", true);
174 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
175 }else{
176 $this->closeDialogs();
177 }
178 }
179 }
182 function detectPostActions()
183 {
184 $action = management::detectPostActions();
185 if(isset($_POST['faiGroupHandle_cancel'])) $action['action'] = "cancel";
186 if(isset($_POST['faiGroupHandle_apply'])) $action['action'] = "editByGroup";
187 return($action);
188 }
191 function renderList()
192 {
193 $filter = $this->getFilter();
194 $headpage = $this->getHeadpage();
195 $filter->setComboBoxOptions("RELEASE",$this->getReleaseList());
197 if(isset($_POST['RELEASE'])){
198 $this->fai_release = get_post('RELEASE');
199 }
200 $headpage->setBase($this->fai_release);
201 $headpage->update();
202 $display = $headpage->render();
203 return($this->getHeader().$display);
204 }
206 function getReleaseList($base = "", $prefix ="")
207 {
208 $list = array();
209 if(empty($base)){
210 $base = get_ou('faiBaseRDN').$this->config->current['BASE'];
211 $list[$base] = "/";
212 }
214 $ldap = $this->config->get_ldap_link();
215 $ldap->ls("(objectClass=FAIbranch)",$base,array("ou","FAIstate"));
216 $cfg_rel = $this->config->search("faiManagement","DEFAULTFAIRELEASE",array("menu"));
218 while($release = $ldap->fetch()){
219 $list[$release['dn']] = $prefix.$release['ou'][0];
221 // Preset to prefered releaes if necessary
222 if(empty($this->fai_release) && $cfg_rel == $release['dn']){
223 $this->fai_release = $release['dn'];
224 }
226 $list = array_merge($list,$this->getReleaseList($release['dn'],$prefix." "));
227 }
228 return($list);
229 }
232 static function filterProperties($row, $classes)
233 {
234 $objects = array(
235 "FAIpartitionTable" => array("IMG"=> "plugins/fai/images/fai_partitionTable.png",
236 "NAME"=>_("Partition table"),"KZL"=> "PT", "VAR"=>"ShowPartitions"),
237 "FAIpackageList" => array("IMG"=> "plugins/fai/images/fai_packages.png",
238 "NAME"=>_("Package list") , "KZL"=> "PL", "VAR"=>"ShowPackages"),
239 "FAIscript" => array("IMG"=> "plugins/fai/images/fai_script.png",
240 "NAME"=>_("Scripts") , "KZL"=> "S", "VAR"=>"ShowScripts"),
241 "FAIvariable" => array("IMG"=> "plugins/fai/images/fai_variable.png",
242 "NAME"=>_("Variables") , "KZL"=> "V", "VAR"=>"ShowVariables"),
243 "FAIhook" => array("IMG"=> "plugins/fai/images/fai_hook.png",
244 "NAME"=>_("Hooks"), "KZL"=> "H", "VAR"=>"ShowHooks"),
245 "FAIprofile" => array("IMG"=> "plugins/fai/images/fai_profile.png",
246 "NAME"=>_("Profile") , "KZL"=> "P", "VAR"=>"ShowProfiles"),
247 "FAItemplate" => array("IMG"=> "plugins/fai/images/fai_template.png",
248 "NAME"=>_("Templates") , "KZL"=> "T", "VAR"=>"ShowTemplates"),
249 "opsi_netboot" => array("IMG"=> "plugins/opsi/images/netboot_package.png",
250 "NAME"=>_("OPSI netboot product") , "KZL"=> "ON", "VAR"=>"ShowOpsiNetboot"),
251 "opsi_local" => array("IMG"=> "plugins/opsi/images/local_package.png",
252 "NAME"=>_("OPSI localboot product") , "KZL"=> "OL", "VAR"=>"ShowOpsiLocal"));
254 $icon_list = "";
255 foreach($objects as $type => $type_data){
256 if(in_array($type, $classes)){
257 $icon_list .= "<input type='image' src='".$type_data['IMG']."' title='".$type_data['NAME']."'
258 alt='".$type_data['KZL']."' class='center' name='edit_".$row."_".$type."'>\n";
259 }else{
260 $icon_list .= "<img src='images/empty.png' alt=' ' class='center'>\n";
261 }
262 }
264 return $icon_list;
265 }
268 function get_type($array){
269 if(!isset($array['objectClass'])) return(array());
270 if(in_array("FAIpartitionTable",$array['objectClass'])){
271 return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
272 }
273 if(in_array("FAIscript",$array['objectClass'])){
274 return(array("tabsScript","faiScript","FAISCRIPTTABS"));
275 }
276 if(in_array("FAItemplate",$array['objectClass'])){
277 return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
278 }
279 if(in_array("FAIhook",$array['objectClass'])){
280 return(array("tabsHook","faiHook","FAIHOOKTABS"));
281 }
282 if(in_array("FAIvariable",$array['objectClass'])){
283 return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
284 }
285 if(in_array("FAIprofile",$array['objectClass'])){
286 return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
287 }
288 if(in_array("FAIpackageList",$array['objectClass'])){
289 return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
290 }
291 return(array());
292 }
293 }
294 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
295 ?>