Code

Starting move
[gosa.git] / gosa-core / plugins / admin / systems / services / repository / class_servRepository.inc
1 <?php
3 class servrepository extends goService
4 {
5   /* CLI vars */
6   var $cli_summary          = "Manage server basic objects";
7   var $cli_description      = "Some longer text\nfor help";
8   var $cli_parameters       = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
10   /* attribute list for save action */
11   //  var $ignore_account         = TRUE;
12   var $attributes             = array("FAIrepository");
13   var $objectclasses          = array("FAIrepositoryServer");
14   
15   /* Repositories */
16   var $repositories          = array();
17   var $FAIrepository         = array();
18   var $conflicts             = array("FAIrepositoryServer");
19   var $DisplayName           = "";
20   var $StatusFlag            = "";
21   
22   var $view_logged            = FALSE;
23   var $fai_activated          = FALSE;
25   var $divlist = NULL;
27   function servrepository (&$config, $dn= NULL, $parent= NULL)
28   {
29     plugin::plugin ($config, $dn, $parent);
31     $this->DisplayName = _("Repository service");
33     /* Skip this if fai is deactivated */
34     $tmp= $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
35     if(!empty($tmp)){
36       $this->fai_activated = TRUE;    
37     }else{
38       return;
39     }
41     $this->repositories = array();
42     if(isset($this->attrs['FAIrepository'])){
43       for($i = 0; $i < $this->attrs['FAIrepository']['count']; $i++){
44         $tmp = split("\|",$this->attrs['FAIrepository'][$i]);
45         $tmp2 = array();  
46         $tmp3 = array();   
48         if(isset($tmp[1])){
49           $tmp2['ParentServer'] = $tmp[1];
50           if(empty($tmp[1])){
51             $tmp2['ParentServer'] = "none";
52           }
53         }else{
54           $tmp2['ParentServer'] = "none";
55         }
57         if(isset($tmp[0])){
58           $tmp2['Url']          = $tmp[0];
59         }else{
60           $tmp2['Url']          = "";
61         }
62   
63         if(isset($tmp[2])){
64           $tmp2['Release']      = $tmp[2];
65         }else{
66           $tmp2['Release']      = "";
67         }
69         if(isset($tmp[3])){
70           $tmp3 = split(",",$tmp[3]);
71           foreach($tmp3 as $sec){
72             $tmp2['Sections'][$sec]=$sec;
73           }    
74         }else{
75           $tmp['Section']=array();
76         }
78         $this->repositories[$tmp[2]]=$tmp2;      
79       }
80     }
83     /* Create divlist */
84     $this->divlist = new divListRepository($this->config,$this);
85   }
87   function execute()
88   {
89     /* Call parent execute */
90     plugin::execute();
92     if($this->is_account && !$this->view_logged){
93       $this->view_logged = TRUE;
94       new log("view","server/".get_class($this),$this->dn);
95     }
97     if(!$this->fai_activated){
98       $str = "<h2>"._("You can't use this plugin until FAI is activated.")."</h2>";
99       return $str;
100     }
102     /* Fill templating stuff */
103     $smarty= get_smarty();
104     $smarty->assign("is_createable",$this->acl_is_createable());
105     $display= "";
107     /* Show tab dialog headers */
108     /*
109        ADD / EDIT Repository
110        Dialog Handling
111      */
112     $once = false;
113     if(isset($_POST['servRepository'])){
114       foreach($_POST as $name => $value){
116         if(preg_match("/AddRepository/",$name) && $this->acl_is_createable()){
117           $once = true;
118           $this->dialog = new servRepositorySetup($this->config,$this->dn);
119           $this->dialog->parent = $this;
120         }
122         if((preg_match("/^delete_/",$name)) && (!$once) && $this->acl_is_removeable()){
123           $once = true;
124           $value = preg_replace("/delete_/","",$name);
125           $value = base64_decode(preg_replace("/_.*$/","",$value));
127           $url = $this->repositories[$value]['Url'];
128           $release = $this->repositories[$value]['Release'];
130           $ldap = $this->config->get_ldap_link();
131           $ldap->cd ($this->config->current['BASE']);
133           $ldap->search("(&(objectClass=gotoWorkstation)(objectClass=FAIobject)(FAIdebianMirror=".$url."))",array("cn","FAIclass"));
135           $found = false;
136           $found_in = " ";
137           while($attrs = $ldap->fetch()){
138             foreach($attrs['FAIclass'] as $class){
139               if(preg_match("/".str_replace("/","\/",$release)."$/i",$class)){
140                 $found = true;  
141                 $found_in .= $attrs['cn'][0]." ";
142               }
143             }
144           }
146           if($found){
147             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));
148           }else{
149             if(isset($this->repositories[$value])){
150               unset($this->repositories[$value]);
151             }
152           }
153         }
155         if((preg_match("/^edit_/",$name))&&(!$once)){
156           $value = preg_replace("/edit_/","",$name);
157           $value = base64_decode(preg_replace("/_.$/","",$value));
159           if(isset($this->repositories[$value])){
161             $ldap = $this->config->get_ldap_link();
162             $ldap->cd ($this->config->current['BASE']);
164             $url = $this->repositories[$value]['Url'];
165             $release = $this->repositories[$value]['Release'];
167             $ldap->search("(&(objectClass=gotoWorkstation)(objectClass=FAIobject)(FAIdebianMirror=".$url."))",array("cn","FAIclass"));
169             $found = false;
170             $found_in = " ";
171             while($attrs = $ldap->fetch()){
172               foreach($attrs['FAIclass'] as $class){
173                 if(preg_match("/".str_replace("/","\/",$release)."$/i",$class)){
174                   $found = true;
175                   $found_in .= $attrs['cn'][0]." ";
176                 }
177               }
178             }
180             if($found){
181               print_red(sprintf(_("Be careful editing this release, it is still used by these workstations [%s]."),$found_in));
182             } 
184             if(isset($this->repositories[$value])){
185               $once = true;
186               $obj = $this->repositories[$value];
188               /* to be able to detect if this was renamed */
189               $obj['initialy_was'] = $obj['Release'];
190               $this->dialog = new servRepositorySetup($this->config,$this->dn,$obj);
191               $this->dialog->parent = $this;
192             }
193           }
194         }
195       }
196     }
197     if((isset($_GET['act']))&&($_GET['act']=="open_repository")&&(isset($_GET['id']))){
198       $obj = $this->repositories[base64_decode($_GET['id'])];
199       $obj['initialy_was'] = $obj['Release'];
200       $this->dialog = new servRepositorySetup($this->config,$this->dn,$obj);
201       $this->dialog->parent = $this;
202     }
204     if(isset($_POST['repository_setup_save']) && is_object($this->dialog)){
205       $this->dialog->save_object();
206       if(($this->dialog->is_new_name())&&(isset($this->repositories[$this->dialog->GetName()]))){
207         print_red(_("This name is already in use."));
208       }else
210       if(count($this->dialog->check())!=0){
211         foreach($this->dialog->check() as $msg){
212           print_red($msg);
213         }
214       }else{
215         $obj = $this->dialog->save();
216         if($this->dialog->is_new_name()){
217           $oldname = $this->dialog->initialy_was;
218           $this->repositories[$obj['Release']]=$obj;        
219           unset($this->repositories[$oldname]);
220         }else{ 
221           $this->repositories[$obj['Release']]=$obj;        
222         }
223         $this->dialog = FALSE;
224         $this->is_dialog= false;
225       }
226     }
228     if(isset($_POST['repository_setup_cancel'])){
229       $this->dialog=FALSE;
230       $this->is_dialog = false;
231     }
232    
233     if(is_object($this->dialog)){
234       $this->dialog->save_object();
235       $this->is_dialog = true;
236       return($this->dialog->execute());
237     }
239     /*
240       Repository setup dialog handling /END
241     */
244     $link   = "<a href='?plug=".$_GET['plug']."&amp;act=open_repository&amp;id=%s'>%s</a>";
245     $edit   = "<input type='image' value='%s' name='edit_%s'   src='images/edit.png'>&nbsp;";
246    
247     /* Hide delete icon, if delete is not allowed */ 
248     if($this->acl_is_removeable()){
249       $delete = "<input type='image' value='%s' name='delete_%s' src='images/edittrash.png'>";
250     }else{
251       $delete = "<img src='images/empty.png' alt='&nbsp;'>";
252     }
254     $this->divlist->execute(); 
255     $this->divlist->setEntries($this->repositories);
256     $smarty->assign("Repositories",$this->divlist->Draw());
257     $display.= $smarty->fetch(get_template_path('servRepository.tpl', TRUE));
258     return($display);
259   }
262   /* Save data to object */
263   function save_object()
264   {
265     plugin::save_object();
266     if(is_object($this->divlist)){
267       $this->divlist->save_object();
268     }
269   }
272   /* Check supplied data */
273   function check()
274   {
275     /* Call common method to give check the hook */
276     $message= plugin::check();
277     return ($message);
278   }
281   /* Save to LDAP */
282   function save()
283   {
284     if(!$this->fai_activated) return;
286     plugin::save();
288     $arr = array();
289     foreach($this->repositories as $servername => $conf){
290       $str = "";
291       foreach($conf['Sections'] as $sec){
292         $str.=$sec.",";
293       }
294       $str=preg_replace("/,$/","",$str);
295         
296       if($conf['ParentServer']=="none"){
297         $conf['ParentServer'] ="";
298       }    
299     
300       $arr[]=$conf['Url']."|".$conf['ParentServer']."|".$conf['Release']."|".$str;
301     }
302     $this->attrs['FAIrepository'] = $arr;
304     $ldap= $this->config->get_ldap_link();
305     $ldap->cd ($this->config->current['BASE']);
306     
307     $ldap->cat($this->dn, array('dn'));
308     
309     if($ldap->count()){
310       $ldap->cd($this->dn);
311       $this->cleanup();
312       $ldap->modify ($this->attrs);       
314       $this->handle_post_events("modify");
315     }else{
316       $ldap->cd ($this->config->current['BASE']);
317       $ldap->create_missing_trees($this->dn);
318       $ldap->cd($this->dn);
319       $ldap->add($this->attrs);
320       $this->handle_post_events("add");
321     }
323     if($this->initially_was_account){
324       new log("modify","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
325     }else{
326       new log("create","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
327     }
328   }
331   function getListEntry()
332   {
333     $fields = goService::getListEntry();
334     $fields['Message']    = _("Repository service");
335     $fields['AllowEdit']  = true;
336     $fields['AllowStart'] = $fields['AllowStop'] = $fields['AllowRestart'] = false;
337     return($fields);
338   }
340   /* Return plugin informations for acl handling */
341   static function plInfo()
342   {
343     return (array(
344           "plShortName"   => _("Repository"),
345           "plDescription" => _("Repository service")." ("._("Services").")",
346           "plSelfModify"  => FALSE,
347           "plDepends"     => array(),
348           "plPriority"    => 84,
349           "plSection"     => array("administration"),
350           "plCategory"    => array("server"),
352           "plProvidedAcls"=> array(
353               "cn"            => _("Name"),
354               "start"         => _("Start"),
355               "stop"          => _("Stop"),
356               "restart"       => _("Restart"),
357               "Release"       => _("Releases"),
358               "Section"       => _("Sections"),
359               "ParentServer"  => _("Parent server"),
360               "Url"           => _("Url"))
361             ));
362   }
365 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
366 ?>