Code

Fixed dns zone creation , if server is new
[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            = "";
30   var $fai_activated          = FALSE;
32   function servrepository ($config, $dn= NULL, $parent= NULL)
33   {
34     plugin::plugin ($config, $dn, $parent);
36     /* Skip this if fai is deactivated */
37     $tmp = search_config($this->config->data,"faiManagement","CLASS");
38     if(!empty($tmp)){
39       $this->fai_activated = TRUE;    
40     }else{
41       return;
42     }
44     $this->DisplayName = _("Repository service");
46     $this->repositories = array();
47     if(isset($this->attrs['FAIrepository'])){
48       for($i = 0; $i < $this->attrs['FAIrepository']['count']; $i++){
49         $tmp = split("\|",$this->attrs['FAIrepository'][$i]);
50         $tmp2 = array();  
51         $tmp3 = array();   
53         if(isset($tmp[1])){
54           $tmp2['ParentServer'] = $tmp[1];
55           if(empty($tmp[1])){
56             $tmp2['ParentServer'] = "none";
57           }
58         }else{
59           $tmp2['ParentServer'] = "none";
60         }
62         if(isset($tmp[0])){
63           $tmp2['Url']          = $tmp[0];
64         }else{
65           $tmp2['Url']          = "";
66         }
67   
68         if(isset($tmp[2])){
69           $tmp2['Release']      = $tmp[2];
70         }else{
71           $tmp2['Release']      = "";
72         }
74         if(isset($tmp[3])){
75           $tmp3 = split(",",$tmp[3]);
76           foreach($tmp3 as $sec){
77             $tmp2['Sections'][$sec]=$sec;
78           }    
79         }else{
80           $tmp['Section']=array();
81         }
83         $this->repositories[$tmp[2]]=$tmp2;      
84       }
85     }
86   }
88   function execute()
89   {
90     /* Call parent execute */
91     plugin::execute();
93     if(!$this->fai_activated){
94       $str = "<h2>"._("You can't use this plugin until FAI is activated.")."</h2>";
95       return $str;
96     }
98     /* Fill templating stuff */
99     $smarty= get_smarty();
100     $smarty->assign("is_createable",$this->acl_is_createable());
101     $display= "";
103     /* Smarty vars*/
104     $smarty->assign("infoimage",    get_template_path('images/info.png'));
105     $smarty->assign("search_image", get_template_path('images/search.png'));
106     $smarty->assign("launchimage",  get_template_path('images/small_filter.png'));
107     $smarty->assign("tree_image",   get_template_path('images/tree.png'));
108     $smarty->assign("alphabet",     generate_alphabet());
109     $smarty->assign("apply",        apply_filter());
110     $smarty->assign("regex",        $this->regex);
112     /* Show tab dialog headers */
113     /*
114        ADD / EDIT Repository
115        Dialog Handling
116      */
117     $once = false;
118     if(isset($_POST['servRepository'])){
119       foreach($_POST as $name => $value){
121         if(preg_match("/AddRepository/",$name) && $this->acl_is_createable()){
122           $once = true;
123           $this->dialog = new servRepositorySetup($this->config,$this->dn);
124           $this->dialog->parent = $this;
125         }
127         if((preg_match("/^delete_/",$name)) && (!$once) && $this->acl_is_removeable()){
128           $once = true;
129           $value = preg_replace("/delete_/","",$name);
130           $value = base64_decode(preg_replace("/_.*$/","",$value));
132           $url = $this->repositories[$value]['Url'];
133           $release = $this->repositories[$value]['Release'];
135           $ldap = $this->config->get_ldap_link();
136           $ldap->cd ($this->config->current['BASE']);
138           $ldap->search("(&(objectClass=gotoWorkstation)(objectClass=FAIobject)(FAIdebianMirror=".$url."))",array("cn","FAIclass"));
140           $found = false;
141           $found_in = " ";
142           while($attrs = $ldap->fetch()){
143             foreach($attrs['FAIclass'] as $class){
144               if(preg_match("/".str_replace("/","\/",$release)."$/i",$class)){
145                 $found = true;  
146                 $found_in .= $attrs['cn'][0]." ";
147               }
148             }
149           }
151           if($found){
152             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));
153           }else{
154             if(isset($this->repositories[$value])){
155               unset($this->repositories[$value]);
156             }
157           }
158         }
160         if((preg_match("/^edit_/",$name))&&(!$once)){
161           $value = preg_replace("/edit_/","",$name);
162           $value = base64_decode(preg_replace("/_.$/","",$value));
164           if(isset($this->repositories[$value])){
166             $ldap = $this->config->get_ldap_link();
167             $ldap->cd ($this->config->current['BASE']);
169             $url = $this->repositories[$value]['Url'];
170             $release = $this->repositories[$value]['Release'];
172             $ldap->search("(&(objectClass=gotoWorkstation)(objectClass=FAIobject)(FAIdebianMirror=".$url."))",array("cn","FAIclass"));
174             $found = false;
175             $found_in = " ";
176             while($attrs = $ldap->fetch()){
177               foreach($attrs['FAIclass'] as $class){
178                 if(preg_match("/".str_replace("/","\/",$release)."$/i",$class)){
179                   $found = true;
180                   $found_in .= $attrs['cn'][0]." ";
181                 }
182               }
183             }
185             if($found){
186               print_red(sprintf(_("Be careful editing this release, it is still used by these workstations [%s]."),$found_in));
187             } 
189             if(isset($this->repositories[$value])){
190               $once = true;
191               $obj = $this->repositories[$value];
193               /* to be able to detect if this was renamed */
194               $obj['initialy_was'] = $obj['Release'];
195               $this->dialog = new servRepositorySetup($this->config,$this->dn,$obj);
196               $this->dialog->parent = $this;
197             }
198           }
199         }
200       }
201     }
202     if((isset($_GET['act']))&&($_GET['act']=="open")&&(isset($_GET['id']))){
203       $obj = $this->repositories[base64_decode($_GET['id'])];
204       $obj['initialy_was'] = $obj['Release'];
205       $this->dialog = new servRepositorySetup($this->config,$this->dn,$obj);
206       $this->dialog->parent = $this;
207     }
209     if(isset($_POST['repository_setup_save'])){
210       $this->dialog->save_object();
211       if(($this->dialog->is_new_name())&&(isset($this->repositories[$this->dialog->GetName()]))){
212         print_red(_("This name is already in use."));
213       }else
215       if(count($this->dialog->check())!=0){
216         foreach($this->dialog->check() as $msg){
217           print_red($msg);
218         }
219       }else{
220         $obj = $this->dialog->save();
221         if($this->dialog->is_new_name()){
222           $oldname = $this->dialog->initialy_was;
223           $this->repositories[$obj['Release']]=$obj;        
224           unset($this->repositories[$oldname]);
225         }else{ 
226           $this->repositories[$obj['Release']]=$obj;        
227         }
228         $this->dialog = NULL;
229         $this->is_dialog= false;
230       }
231     }
233     if(isset($_POST['repository_setup_cancel'])){
234       $this->dialog=NULL;
235       $this->is_dialog = false;
236     }
237    
238     if($this->dialog != NULL){
239       $this->dialog->save_object();
240       $this->is_dialog = true;
241       return($this->dialog->execute());
242     }
244     /*
245       Repository setup dialog handling /END
246     */
248     $divlist = new divList("repositories");
249     $divlist->SetEntriesPerPage(0);
250     $divlist->setHeight(400);
252     $divlist->setHeader(array(array("string"=>_("Release"),"attach"=>"style='width:80px;'"),
253                               array("string"=>_("Sections")),
254                               array("string"=>_("Options"),"attach"=>"style='border-right:0px;width:55px;'")
255                        )     );
257     $link   = "<a href='?plug=".$_GET['plug']."&amp;act=open&amp;id=%s'>%s</a>";
258     $edit   = "<input type='image' value='%s' name='edit_%s'   src='images/edit.png'>&nbsp;";
259    
260     /* Hide delete icon, if delete is not allowed */ 
261     if($this->acl_is_removeable()){
262       $delete = "<input type='image' value='%s' name='delete_%s' src='images/edittrash.png'>";
263     }else{
264       $delete = "<img src='images/empty.png' alt='&nbsp;'>";
265     }
266   
267     foreach($this->repositories as $name => $reps){
269       $str = " ";
270       if(preg_match("/".str_replace("*",".*",$this->regex)."/",$reps['Release'])){
271       foreach($reps['Sections'] as $sec){
272         $str.=$sec." ";  
273       }    
274       $divlist->AddEntry(array(
275           array("string"=>sprintf($link,base64_encode($name),$name),"attach"=>"style='width:80px;'"),
276           array("string"=>sprintf($link,base64_encode($name),_("Sections")." :".$str)),
277           array("string"=>preg_replace("/%s/",base64_encode($name),$edit.$delete),"attach"=>"style='border-right:0px;width:55px;text-align:right;'")
278                               ));
279       }
280     }
281  
282     $smarty -> assign("Repositories",$divlist->DrawList());
284     $display.= $smarty->fetch(get_template_path('servRepository.tpl', TRUE));
285     return($display);
286   }
289   /* Save data to object */
290   function save_object()
291   {
292     plugin::save_object();
293     if(isset($_POST['regex'])){
294       $this->regex = $_POST['regex'];
295     }
296   }
299   /* Check supplied data */
300   function check()
301   {
302     /* Call common method to give check the hook */
303     $message= plugin::check();
304     return ($message);
305   }
308   /* Save to LDAP */
309   function save()
310   {
311     if(!$this->fai_activated) return;
313     plugin::save();
315     $arr = array();
316     foreach($this->repositories as $servername => $conf){
317       $str = "";
318       foreach($conf['Sections'] as $sec){
319         $str.=$sec.",";
320       }
321       $str=preg_replace("/,$/","",$str);
322         
323       if($conf['ParentServer']=="none"){
324         $conf['ParentServer'] ="";
325       }    
326     
327       $arr[]=$conf['Url']."|".$conf['ParentServer']."|".$conf['Release']."|".$str;
328     }
329     $this->attrs['FAIrepository'] = $arr;
331     $ldap= $this->config->get_ldap_link();
332     $ldap->cd ($this->config->current['BASE']);
333     
334     $ldap->cat($this->dn, array('dn'));
335     
336     if($ldap->count()){
337       $ldap->cd($this->dn);
338       $this->cleanup();
339       $ldap->modify ($this->attrs);       
341       $this->handle_post_events("modify");
342     }else{
343       $ldap->cd ($this->config->current['BASE']);
344       $ldap->create_missing_trees($this->dn);
345       $ldap->cd($this->dn);
346       $ldap->add($this->attrs);
347       $this->handle_post_events("add");
348     }
349   }
352   function getListEntry()
353   {
354     $fields = goService::getListEntry();
355     $fields['Message']    = _("Repository service");
356     $fields['AllowEdit']  = true;
357     $fields['AllowStart'] = $fields['AllowStop'] = $fields['AllowRestart'] = false;
358     return($fields);
359   }
361   /* Return plugin informations for acl handling */
362   function plInfo()
363   {
364     return (array(
365           "plShortName"   => _("Repository"),
366           "plDescription" => _("Repository service")." ("._("Services").")",
367           "plSelfModify"  => FALSE,
368           "plDepends"     => array(),
369           "plPriority"    => 84,
370           "plSection"     => array("administration"),
371           "plCategory"    => array("server"),
373           "plProvidedAcls"=> array(
374               "cn"            => _("Name"),
375               "start"         => _("Start"),
376               "stop"          => _("Stop"),
377               "restart"       => _("Restart"),
378               "Release"       => _("Releases"),
379               "Section"       => _("Sections"),
380               "ParentServer"  => _("Parent server"),
381               "Url"           => _("Url"))
382             ));
383   }
386 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
387 ?>