Code

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