1 <?php
3 class servrepository extends plugin
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");
15 /* Search filter */
16 var $regex = "*";
18 /* Configurationdialog for repositories */
19 var $dialog = NULL;
21 /* Repositories */
22 var $repositories = array();
23 var $FAIrepository = array();
26 var $conflicts = array("FAIrepositoryServer");
27 var $DisplayName = "";
28 var $StatusFlag = "";
31 function servrepository ($config, $dn= NULL)
32 {
33 plugin::plugin ($config, $dn);
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 }
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 $display= "";
88 /* Smarty vars*/
89 $smarty->assign("infoimage", get_template_path('images/info.png'));
90 $smarty->assign("search_image", get_template_path('images/search.png'));
91 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
92 $smarty->assign("tree_image", get_template_path('images/tree.png'));
93 $smarty->assign("alphabet", generate_alphabet());
94 $smarty->assign("apply", apply_filter());
95 $smarty->assign("regex", $this->regex);
97 /* Show tab dialog headers */
98 /*
99 ADD / EDIT Repository
100 Dialog Handling
101 */
102 $once = false;
103 if(isset($_POST['servRepository'])){
104 foreach($_POST as $name => $value){
106 if(preg_match("/AddRepository/",$name)){
107 $once = true;
108 $this->dialog = new servRepositorySetup($this->config,$this->dn);
109 $this->dialog->acl = $this->acl;
110 }
112 if((preg_match("/^delete_/",$name))&&(!$once)){
113 $once = true;
114 $value = preg_replace("/delete_/","",$name);
115 $value = base64_decode(preg_replace("/_.*$/","",$value));
117 $url = $this->repositories[$value]['Url'];
118 $release = $this->repositories[$value]['Release'];
120 $ldap = $this->config->get_ldap_link();
121 $ldap->cd ($this->config->current['BASE']);
123 $ldap->search("(&(objectClass=gotoWorkstation)(objectClass=FAIobject)(FAIdebianMirror=".$url."))",array("cn","FAIclass"));
125 $found = false;
126 $found_in = " ";
127 while($attrs = $ldap->fetch()){
128 foreach($attrs['FAIclass'] as $class){
129 if(preg_match("/".str_replace("/","\/",$release)."$/i",$class)){
130 $found = true;
131 $found_in .= $attrs['cn'][0]." ";
132 }
133 }
134 }
136 if($found){
137 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));
138 }else{
139 if(isset($this->repositories[$value])){
140 unset($this->repositories[$value]);
141 }
142 }
143 }
145 if((preg_match("/^edit_/",$name))&&(!$once)){
146 $value = preg_replace("/edit_/","",$name);
147 $value = base64_decode(preg_replace("/_.$/","",$value));
149 if(isset($this->repositories[$value])){
151 $ldap = $this->config->get_ldap_link();
152 $ldap->cd ($this->config->current['BASE']);
154 $url = $this->repositories[$value]['Url'];
155 $release = $this->repositories[$value]['Release'];
157 $ldap->search("(&(objectClass=gotoWorkstation)(objectClass=FAIobject)(FAIdebianMirror=".$url."))",array("cn","FAIclass"));
159 $found = false;
160 $found_in = " ";
161 while($attrs = $ldap->fetch()){
162 foreach($attrs['FAIclass'] as $class){
163 if(preg_match("/".str_replace("/","\/",$release)."$/i",$class)){
164 $found = true;
165 $found_in .= $attrs['cn'][0]." ";
166 }
167 }
168 }
170 if($found){
171 print_red(sprintf(_("Be careful editing this release, it is still used by these workstations [%s]."),$found_in));
172 }
174 if(isset($this->repositories[$value])){
175 $once = true;
176 $obj = $this->repositories[$value];
178 /* to be able to detect if this was renamed */
179 $obj['initialy_was'] = $obj['Release'];
180 $this->dialog = new servRepositorySetup($this->config,$this->dn,$obj);
181 $this->dialog->acl = $this->acl;
182 }
183 }
184 }
185 }
186 }
187 if((isset($_GET['act']))&&($_GET['act']=="open")&&(isset($_GET['id']))){
188 $obj = $this->repositories[base64_decode($_GET['id'])];
189 $obj['initialy_was'] = $obj['Release'];
190 $this->dialog = new servRepositorySetup($this->config,$this->dn,$obj);
191 $this->dialog->acl = $this->acl;
192 }
194 /*
195 if(isset($_POST['AddRepository'])){
196 $this->dialog = new servRepositorySetup($this->config,$this->dn);
197 $this->dialog->acl = $this->acl;
198 }
199 */
201 if(isset($_POST['repository_setup_save'])){
202 $this->dialog->save_object();
203 if(($this->dialog->is_new_name())&&(isset($this->repositories[$this->dialog->GetName()]))){
204 print_red(_("This name is already in use."));
205 }else
207 if(count($this->dialog->check())!=0){
208 foreach($this->dialog->check() as $msg){
209 print_red($msg);
210 }
211 }else{
212 $obj = $this->dialog->save();
213 if($this->dialog->is_new_name()){
214 $oldname = $this->dialog->initialy_was;
215 $this->repositories[$obj['Release']]=$obj;
216 unset($this->repositories[$oldname]);
217 }else{
218 $this->repositories[$obj['Release']]=$obj;
219 }
220 $this->dialog = NULL;
221 $this->is_dialog= false;
222 }
223 }
225 if(isset($_POST['repository_setup_cancel'])){
226 $this->dialog=NULL;
227 $this->is_dialog = false;
228 }
230 if($this->dialog != NULL){
231 $this->dialog->save_object();
232 $this->is_dialog = true;
233 return($this->dialog->execute());
234 }
236 /*
237 Repository setup dialog handling /END
238 */
240 $divlist = new divList("repositories");
241 $divlist->SetEntriesPerPage(0);
242 $divlist->setHeight(400);
244 $divlist->setHeader(array(array("string"=>_("Release"),"attach"=>"style='width:80px;'"),
245 array("string"=>_("Sections")),
246 array("string"=>_("Options"),"attach"=>"style='border-right:0px;width:55px;'")
247 ) );
249 $link = "<a href='?plug=".$_GET['plug']."&act=open&id=%s'>%s</a>";
250 $edit = "<input type='image' value='%s' name='edit_%s' src='images/edit.png'> ";
251 $delete = "<input type='image' value='%s' name='delete_%s' src='images/edittrash.png'>";
253 foreach($this->repositories as $name => $reps){
255 $str = " ";
257 if(preg_match("/".str_replace("*",".*",$this->regex)."/",$reps['Release'])){
260 foreach($reps['Sections'] as $sec){
261 $str.=$sec." ";
262 }
264 $divlist->AddEntry(array(
265 array("string"=>sprintf($link,base64_encode($name),$name),"attach"=>"style='width:80px;'"),
266 array("string"=>sprintf($link,base64_encode($name),_("Sections")." :".$str)),
267 array("string"=>preg_replace("/%s/",base64_encode($name),$edit.$delete),"attach"=>"style='border-right:0px;width:55px;text-align:right;'")
268 ));
269 }
270 }
272 $smarty -> assign("Repositories",$divlist->DrawList());
274 $display.= $smarty->fetch(get_template_path('servRepository.tpl', TRUE));
275 return($display);
276 }
278 function remove_from_parent()
279 {
280 plugin::remove_from_parent();
282 /* Remove status flag, it is not a memeber of
283 this->attributes, so ensure that it is deleted too */
284 if(!empty($this->StatusFlag)){
285 $this->attrs[$this->StatusFlag] = array();
286 }
288 $ldap= $this->config->get_ldap_link();
289 $ldap->cd ($this->config->current['BASE']);
291 $ldap->cat($this->dn, array('dn'));
293 if($ldap->count()){
294 $ldap->cd($this->dn);
295 $this->cleanup();
296 $ldap->modify ($this->attrs);
298 $this->handle_post_events("modify");
299 }
300 }
303 /* Save data to object */
304 function save_object()
305 {
306 plugin::save_object();
307 if(isset($_POST['regex'])){
308 $this->regex = $_POST['regex'];
309 }
310 }
313 /* Check supplied data */
314 function check()
315 {
316 /* Call common method to give check the hook */
317 $message= plugin::check();
319 return ($message);
320 }
323 /* Save to LDAP */
324 function save()
325 {
326 plugin::save();
328 $arr = array();
329 foreach($this->repositories as $servername => $conf){
330 $str = "";
331 foreach($conf['Sections'] as $sec){
332 $str.=$sec.",";
333 }
334 $str=preg_replace("/,$/","",$str);
336 if($conf['ParentServer']=="none"){
337 $conf['ParentServer'] ="";
338 }
340 $arr[]=$conf['Url']."|".$conf['ParentServer']."|".$conf['Release']."|".$str;
341 }
342 $this->attrs['FAIrepository'] = $arr;
344 $ldap= $this->config->get_ldap_link();
345 $ldap->cd ($this->config->current['BASE']);
347 $ldap->cat($this->dn, array('dn'));
349 if($ldap->count()){
350 $ldap->cd($this->dn);
351 $this->cleanup();
352 $ldap->modify ($this->attrs);
354 $this->handle_post_events("modify");
355 }else{
356 $ldap->cd ($this->config->current['BASE']);
357 $ldap->create_missing_trees($this->dn);
358 $ldap->cd($this->dn);
359 $ldap->add($this->attrs);
360 $this->handle_post_events("add");
361 }
362 }
364 /* Get updates for status flag */
365 function updateStatusState()
366 {
367 if(empty($this->StatusFlag)) return;
369 $attrs = array();
370 $flag = $this->StatusFlag;
371 $ldap = $this->config->get_ldap_link();
372 $ldap->cd($this->cn);
373 $ldap->cat($this->dn,array($flag));
374 if($ldap->count()){
375 $attrs = $ldap->fetch();
376 }
377 if(isset($attrs[$flag][0])){
378 $this->$flag = $attrs[$flag][0];
379 }
380 }
383 function getListEntry()
384 {
385 $this->updateStatusState();
386 $flag = $this->StatusFlag;
387 if(empty($flag)){
388 $fields['Status'] = "";
389 }else{
390 $fields['Status'] = $this->$flag;
391 }
392 $fields['Message'] = _("Repository service");
393 $fields['AllowStart'] = true;
394 $fields['AllowStop'] = true;
395 $fields['AllowRestart'] = true;
396 $fields['AllowRemove']= true;
397 $fields['AllowEdit'] = true;
398 return($fields);
399 }
402 /* Directly save new status flag */
403 function setStatus($value)
404 {
405 if($value == "none") return;
406 if(!$this->initially_was_account) return;
407 if(empty($this->StatusFlag)) return;
408 $ldap = $this->config->get_ldap_link();
409 $ldap->cd($this->dn);
410 $ldap->cat($this->dn,array("objectClass"));
411 if($ldap->count()){
413 $tmp = $ldap->fetch();
414 for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
415 $attrs['objectClass'][] = $tmp['objectClass'][$i];
416 }
417 $flag = $this->StatusFlag;
418 $attrs[$flag] = $value;
419 $this->$flag = $value;
420 $ldap->modify($attrs);
421 show_ldap_error($ldap->get_error(), sprintf(_("Set status flag for server services/repository with dn '%s' failed."),$this->dn));
422 $this->action_hook();
423 }
424 }
427 /* Return plugin informations for acl handling */
428 function plInfo()
429 {
430 return (array(
431 "plShortName" => _("Repository"),
432 "plDescription" => _("Repository service"),
433 "plSelfModify" => FALSE,
434 "plDepends" => array(),
435 "plPriority" => 0,
436 "plSection" => array("administration"),
437 "plCategory" => array("server"),
439 "plProvidedAcls"=> array(
440 "cn" => _("Name"),
441 "Release" => _("Releases"),
442 "ParentServer" => _("Parent server"),
443 "Url" => _("Url"))
444 ));
445 }
446 }
448 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
449 ?>