Code

Updated serverService : Set acl base/category for services
[gosa.git] / plugins / admin / systems / class_servRepository.inc
1 <?php
3 require_once("class_goService.inc");
5 class servrepository extends goService
6 {
7   /* CLI vars */
8   var $cli_summary          = "Manage server basic objects";
9   var $cli_description      = "Some longer text\nfor help";
10   var $cli_parameters       = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
12   /* attribute list for save action */
13   //  var $ignore_account         = TRUE;
14   var $attributes             = array("FAIrepository");
15   var $objectclasses          = array("FAIrepositoryServer");
16   
17   /* Search filter */
18   var $regex                  = "*";
20   /* Configurationdialog for repositories */
21   var $dialog                 = NULL;
23   /* Repositories */
24   var $repositories          = array();
25   var $FAIrepository         = array();
26   var $conflicts             = array("FAIrepositoryServer");
27   var $DisplayName           = "";
28   var $StatusFlag            = "";
31   function servrepository ($config, $dn= NULL, $parent= NULL)
32   {
33     plugin::plugin ($config, $dn, $parent);
35     $this->DisplayName = _("Repository service");
37     $this->repositories = array();
38     if(isset($this->attrs['FAIrepository'])){
39       for($i = 0; $i < $this->attrs['FAIrepository']['count']; $i++){
40         $tmp = split("\|",$this->attrs['FAIrepository'][$i]);
41         $tmp2 = array();  
42         $tmp3 = array();   
44         if(isset($tmp[1])){
45           $tmp2['ParentServer'] = $tmp[1];
46           if(empty($tmp[1])){
47             $tmp2['ParentServer'] = "none";
48           }
49         }else{
50           $tmp2['ParentServer'] = "none";
51         }
53         if(isset($tmp[0])){
54           $tmp2['Url']          = $tmp[0];
55         }else{
56           $tmp2['Url']          = "";
57         }
58   
59         if(isset($tmp[2])){
60           $tmp2['Release']      = $tmp[2];
61         }else{
62           $tmp2['Release']      = "";
63         }
65         if(isset($tmp[3])){
66           $tmp3 = split(",",$tmp[3]);
67           foreach($tmp3 as $sec){
68             $tmp2['Sections'][$sec]=$sec;
69           }    
70         }else{
71           $tmp['Section']=array();
72         }
74         $this->repositories[$tmp[2]]=$tmp2;      
75       }
76     }
77   }
79   function execute()
80   {
81     /* Call parent execute */
82     plugin::execute();
84     /* Fill templating stuff */
85     $smarty= get_smarty();
86     $smarty->assign("is_createable",$this->acl_is_createable());
87     $display= "";
89     /* Smarty vars*/
90     $smarty->assign("infoimage",    get_template_path('images/info.png'));
91     $smarty->assign("search_image", get_template_path('images/search.png'));
92     $smarty->assign("launchimage",  get_template_path('images/small_filter.png'));
93     $smarty->assign("tree_image",   get_template_path('images/tree.png'));
94     $smarty->assign("alphabet",     generate_alphabet());
95     $smarty->assign("apply",        apply_filter());
96     $smarty->assign("regex",        $this->regex);
98     /* Show tab dialog headers */
99     /*
100        ADD / EDIT Repository
101        Dialog Handling
102      */
103     $once = false;
104     if(isset($_POST['servRepository'])){
105       foreach($_POST as $name => $value){
107         if(preg_match("/AddRepository/",$name) && $this->acl_is_createable()){
108           $once = true;
109           $this->dialog = new servRepositorySetup($this->config,$this->dn);
110           $this->dialog->parent = $this;
111         }
113         if((preg_match("/^delete_/",$name)) && (!$once) && $this->acl_is_removeable()){
114           $once = true;
115           $value = preg_replace("/delete_/","",$name);
116           $value = base64_decode(preg_replace("/_.*$/","",$value));
118           $url = $this->repositories[$value]['Url'];
119           $release = $this->repositories[$value]['Release'];
121           $ldap = $this->config->get_ldap_link();
122           $ldap->cd ($this->config->current['BASE']);
124           $ldap->search("(&(objectClass=gotoWorkstation)(objectClass=FAIobject)(FAIdebianMirror=".$url."))",array("cn","FAIclass"));
126           $found = false;
127           $found_in = " ";
128           while($attrs = $ldap->fetch()){
129             foreach($attrs['FAIclass'] as $class){
130               if(preg_match("/".str_replace("/","\/",$release)."$/i",$class)){
131                 $found = true;  
132                 $found_in .= $attrs['cn'][0]." ";
133               }
134             }
135           }
137           if($found){
138             print_red(sprintf(_("You can't delete this release, it is still used by these workstations [%s]. Please solve this dependencies first, to keep data base consistency."),$found_in));
139           }else{
140             if(isset($this->repositories[$value])){
141               unset($this->repositories[$value]);
142             }
143           }
144         }
146         if((preg_match("/^edit_/",$name))&&(!$once)){
147           $value = preg_replace("/edit_/","",$name);
148           $value = base64_decode(preg_replace("/_.$/","",$value));
150           if(isset($this->repositories[$value])){
152             $ldap = $this->config->get_ldap_link();
153             $ldap->cd ($this->config->current['BASE']);
155             $url = $this->repositories[$value]['Url'];
156             $release = $this->repositories[$value]['Release'];
158             $ldap->search("(&(objectClass=gotoWorkstation)(objectClass=FAIobject)(FAIdebianMirror=".$url."))",array("cn","FAIclass"));
160             $found = false;
161             $found_in = " ";
162             while($attrs = $ldap->fetch()){
163               foreach($attrs['FAIclass'] as $class){
164                 if(preg_match("/".str_replace("/","\/",$release)."$/i",$class)){
165                   $found = true;
166                   $found_in .= $attrs['cn'][0]." ";
167                 }
168               }
169             }
171             if($found){
172               print_red(sprintf(_("Be careful editing this release, it is still used by these workstations [%s]."),$found_in));
173             } 
175             if(isset($this->repositories[$value])){
176               $once = true;
177               $obj = $this->repositories[$value];
179               /* to be able to detect if this was renamed */
180               $obj['initialy_was'] = $obj['Release'];
181               $this->dialog = new servRepositorySetup($this->config,$this->dn,$obj);
182               $this->dialog->parent = $this;
183             }
184           }
185         }
186       }
187     }
188     if((isset($_GET['act']))&&($_GET['act']=="open")&&(isset($_GET['id']))){
189       $obj = $this->repositories[base64_decode($_GET['id'])];
190       $obj['initialy_was'] = $obj['Release'];
191       $this->dialog = new servRepositorySetup($this->config,$this->dn,$obj);
192       $this->dialog->parent = $this;
193     }
195     if(isset($_POST['repository_setup_save'])){
196       $this->dialog->save_object();
197       if(($this->dialog->is_new_name())&&(isset($this->repositories[$this->dialog->GetName()]))){
198         print_red(_("This name is already in use."));
199       }else
201       if(count($this->dialog->check())!=0){
202         foreach($this->dialog->check() as $msg){
203           print_red($msg);
204         }
205       }else{
206         $obj = $this->dialog->save();
207         if($this->dialog->is_new_name()){
208           $oldname = $this->dialog->initialy_was;
209           $this->repositories[$obj['Release']]=$obj;        
210           unset($this->repositories[$oldname]);
211         }else{ 
212           $this->repositories[$obj['Release']]=$obj;        
213         }
214         $this->dialog = NULL;
215         $this->is_dialog= false;
216       }
217     }
219     if(isset($_POST['repository_setup_cancel'])){
220       $this->dialog=NULL;
221       $this->is_dialog = false;
222     }
223    
224     if($this->dialog != NULL){
225       $this->dialog->save_object();
226       $this->is_dialog = true;
227       return($this->dialog->execute());
228     }
230     /*
231       Repository setup dialog handling /END
232     */
234     $divlist = new divList("repositories");
235     $divlist->SetEntriesPerPage(0);
236     $divlist->setHeight(400);
238     $divlist->setHeader(array(array("string"=>_("Release"),"attach"=>"style='width:80px;'"),
239                               array("string"=>_("Sections")),
240                               array("string"=>_("Options"),"attach"=>"style='border-right:0px;width:55px;'")
241                        )     );
243     $link   = "<a href='?plug=".$_GET['plug']."&amp;act=open&amp;id=%s'>%s</a>";
244     $edit   = "<input type='image' value='%s' name='edit_%s'   src='images/edit.png'>&nbsp;";
245    
246     /* Hide delete icon, if delete is not allowed */ 
247     if($this->acl_is_removeable()){
248       $delete = "<input type='image' value='%s' name='delete_%s' src='images/edittrash.png'>";
249     }else{
250       $delete = "<img src='images/empty.png' alt='&nbsp;'>";
251     }
252   
253     foreach($this->repositories as $name => $reps){
255       $str = " ";
256       if(preg_match("/".str_replace("*",".*",$this->regex)."/",$reps['Release'])){
257       foreach($reps['Sections'] as $sec){
258         $str.=$sec." ";  
259       }    
260       $divlist->AddEntry(array(
261           array("string"=>sprintf($link,base64_encode($name),$name),"attach"=>"style='width:80px;'"),
262           array("string"=>sprintf($link,base64_encode($name),_("Sections")." :".$str)),
263           array("string"=>preg_replace("/%s/",base64_encode($name),$edit.$delete),"attach"=>"style='border-right:0px;width:55px;text-align:right;'")
264                               ));
265       }
266     }
267  
268     $smarty -> assign("Repositories",$divlist->DrawList());
270     $display.= $smarty->fetch(get_template_path('servRepository.tpl', TRUE));
271     return($display);
272   }
275   /* Save data to object */
276   function save_object()
277   {
278     plugin::save_object();
279     if(isset($_POST['regex'])){
280       $this->regex = $_POST['regex'];
281     }
282   }
285   /* Check supplied data */
286   function check()
287   {
288     /* Call common method to give check the hook */
289     $message= plugin::check();
290     return ($message);
291   }
294   /* Save to LDAP */
295   function save()
296   {
297     plugin::save();
299     $arr = array();
300     foreach($this->repositories as $servername => $conf){
301       $str = "";
302       foreach($conf['Sections'] as $sec){
303         $str.=$sec.",";
304       }
305       $str=preg_replace("/,$/","",$str);
306         
307       if($conf['ParentServer']=="none"){
308         $conf['ParentServer'] ="";
309       }    
310     
311       $arr[]=$conf['Url']."|".$conf['ParentServer']."|".$conf['Release']."|".$str;
312     }
313     $this->attrs['FAIrepository'] = $arr;
315     $ldap= $this->config->get_ldap_link();
316     $ldap->cd ($this->config->current['BASE']);
317     
318     $ldap->cat($this->dn, array('dn'));
319     
320     if($ldap->count()){
321       $ldap->cd($this->dn);
322       $this->cleanup();
323       $ldap->modify ($this->attrs);       
325       $this->handle_post_events("modify");
326     }else{
327       $ldap->cd ($this->config->current['BASE']);
328       $ldap->create_missing_trees($this->dn);
329       $ldap->cd($this->dn);
330       $ldap->add($this->attrs);
331       $this->handle_post_events("add");
332     }
333   }
336   function getListEntry()
337   {
338     $fields = goService::getListEntry();
339     $fields['Message']    = _("Repository service");
340     $fields['AllowEdit']  = true;
341     return($fields);
342   }
344   /* Return plugin informations for acl handling */
345   function plInfo()
346   {
347     return (array(
348           "plShortName"   => _("Repository"),
349           "plDescription" => _("Repository service"),
350           "plSelfModify"  => FALSE,
351           "plDepends"     => array(),
352           "plPriority"    => 0,
353           "plSection"     => array("administration"),
354           "plCategory"    => array("server"),
356           "plProvidedAcls"=> array(
357               "cn"            => _("Name"),
358               "Release"       => _("Releases"),
359               "Section"       => _("Sections"),
360               "ParentServer"  => _("Parent server"),
361               "Url"           => _("Url"))
362             ));
363   }
366 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
367 ?>