4640786b87b45373d64b34af12e8c6f4d2d118b9
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();
25 function servrepository ($config, $dn= NULL, $parent= NULL)
26 {
27 plugin::plugin ($config, $dn, $parent);
29 $ui = get_userinfo();
30 $tmp= get_permissions ($this->dn, $ui->subtreeACL);
31 $this->acl= get_module_permission($tmp, "FAIclass", $this->dn);
33 $this->repositories = array();
34 if(isset($this->attrs['FAIrepository'])){
35 for($i = 0; $i < $this->attrs['FAIrepository']['count']; $i++){
36 $tmp = split("\|",$this->attrs['FAIrepository'][$i]);
37 $tmp2 = array();
38 $tmp3 = array();
40 if(isset($tmp[1])){
41 $tmp2['ParentServer'] = $tmp[1];
42 if(empty($tmp[1])){
43 $tmp2['ParentServer'] = "none";
44 }
45 }else{
46 $tmp2['ParentServer'] = "none";
47 }
49 if(isset($tmp[0])){
50 $tmp2['Url'] = $tmp[0];
51 }else{
52 $tmp2['Url'] = "";
53 }
55 if(isset($tmp[2])){
56 $tmp2['Release'] = $tmp[2];
57 }else{
58 $tmp2['Release'] = "";
59 }
61 if(isset($tmp[3])){
62 $tmp3 = split(",",$tmp[3]);
63 foreach($tmp3 as $sec){
64 $tmp2['Sections'][$sec]=$sec;
65 }
66 }else{
67 $tmp['Section']=array();
68 }
70 $this->repositories[$tmp[2]]=$tmp2;
71 }
72 }
73 }
75 function execute()
76 {
77 /* Call parent execute */
78 plugin::execute();
80 /* Fill templating stuff */
81 $smarty= get_smarty();
82 $display= "";
84 $ui = get_userinfo();
85 $tmp= get_permissions ($this->dn, $ui->subtreeACL);
86 $this->acl= get_module_permission($tmp, "FAIclass", $this->dn);
87 $allow_edit = !preg_match("/disabled/i",chkacl($this->acl,"FAIclass"));
90 /* Smarty vars*/
91 $smarty->assign("infoimage", get_template_path('images/info.png'));
92 $smarty->assign("search_image", get_template_path('images/search.png'));
93 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
94 $smarty->assign("tree_image", get_template_path('images/tree.png'));
95 $smarty->assign("alphabet", generate_alphabet());
96 $smarty->assign("apply", apply_filter());
97 $smarty->assign("regex", $this->regex);
100 /* Do we need to flip is_account state? */
101 if (isset($_POST['modify_state'])){
102 $this->is_account= !$this->is_account;
103 }
105 /* Show tab dialog headers */
106 if ($this->is_account){
107 $display= $this->show_header(_("Remove FAI repository extension."),
108 _("This server has FAI repository features enabled. You can disable them by clicking below."));
109 } else {
110 $display= $this->show_header(_("Add FAI repository extension."),
111 _("This server has FAI repository features disabled. You can enable them by clicking below."));
112 return ($display);
113 }
115 /*
116 ADD / EDIT Repository
117 Dialog Handling
118 */
120 $once = false;
121 if(isset($_POST['servRepository'])){
122 foreach($_POST as $name => $value){
124 if(preg_match("/AddRepository/",$name) && !$once && $allow_edit){
125 $once = true;
126 $this->dialog = new servRepositorySetup($this->config,$this->dn);
127 $this->dialog->acl = $this->acl;
128 }
130 if((preg_match("/^delete_/",$name))&&(!$once) && $allow_edit){
131 $once = true;
132 $value = preg_replace("/delete_/","",$name);
133 $value = base64_decode(preg_replace("/_.*$/","",$value));
135 $url = $this->repositories[$value]['Url'];
136 $release = $this->repositories[$value]['Release'];
138 $ldap = $this->config->get_ldap_link();
139 $ldap->cd ($this->config->current['BASE']);
141 $ldap->search("(&(objectClass=gotoWorkstation)(objectClass=FAIobject)(FAIdebianMirror=".$url."))",array("cn","FAIclass"));
143 $found = false;
144 $found_in = " ";
145 while($attrs = $ldap->fetch()){
146 foreach($attrs['FAIclass'] as $class){
147 if(preg_match("/".str_replace("/","\/",$release)."$/i",$class)){
148 $found = true;
149 $found_in .= $attrs['cn'][0]." ";
150 }
151 }
152 }
154 if($found){
155 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));
156 }else{
157 if(isset($this->repositories[$value])){
158 unset($this->repositories[$value]);
159 }
160 }
161 }
163 if((preg_match("/^edit_/",$name))&&(!$once) && $allow_edit){
164 $value = preg_replace("/edit_/","",$name);
165 $value = base64_decode(preg_replace("/_.$/","",$value));
167 if(isset($this->repositories[$value])){
169 $ldap = $this->config->get_ldap_link();
170 $ldap->cd ($this->config->current['BASE']);
172 $url = $this->repositories[$value]['Url'];
173 $release = $this->repositories[$value]['Release'];
175 $ldap->search("(&(objectClass=gotoWorkstation)(objectClass=FAIobject)(FAIdebianMirror=".$url."))",array("cn","FAIclass"));
177 $found = false;
178 $found_in = " ";
179 while($attrs = $ldap->fetch()){
180 foreach($attrs['FAIclass'] as $class){
181 if(preg_match("/".str_replace("/","\/",$release)."$/i",$class)){
182 $found = true;
183 $found_in .= $attrs['cn'][0]." ";
184 }
185 }
186 }
188 if($found){
189 print_red(sprintf(_("Be careful editing this release, it is still used by these workstations [%s]."),$found_in));
190 }
192 if(isset($this->repositories[$value])){
193 $once = true;
194 $obj = $this->repositories[$value];
196 /* to be able to detect if this was renamed */
197 $obj['initialy_was'] = $obj['Release'];
198 $this->dialog = new servRepositorySetup($this->config,$this->dn,$obj);
199 $this->dialog->acl = $this->acl;
200 }
201 }
202 }
203 }
204 }
205 if((isset($_GET['act']))&&($_GET['act']=="open")&&(isset($_GET['id'])) && $allow_edit){
206 $obj = $this->repositories[base64_decode($_GET['id'])];
207 $obj['initialy_was'] = $obj['Release'];
208 $this->dialog = new servRepositorySetup($this->config,$this->dn,$obj);
209 $this->dialog->acl = $this->acl;
210 }
212 /*
213 if(isset($_POST['AddRepository'])){
214 $this->dialog = new servRepositorySetup($this->config,$this->dn);
215 $this->dialog->acl = $this->acl;
216 }
217 */
219 if(isset($_POST['repository_setup_save'])){
220 $this->dialog->save_object();
221 if(($this->dialog->is_new_name())&&(isset($this->repositories[$this->dialog->GetName()]))){
222 print_red(_("This name is already in use."));
223 }else
225 if(count($this->dialog->check())!=0){
226 foreach($this->dialog->check() as $msg){
227 print_red($msg);
228 }
229 }else{
230 $obj = $this->dialog->save();
231 if($this->dialog->is_new_name()){
232 $oldname = $this->dialog->initialy_was;
233 $this->repositories[$obj['Release']]=$obj;
234 unset($this->repositories[$oldname]);
235 }else{
236 $this->repositories[$obj['Release']]=$obj;
237 }
238 $this->dialog = NULL;
239 $this->is_dialog= false;
240 }
241 }
243 if(isset($_POST['repository_setup_cancel'])){
244 $this->dialog=NULL;
245 $this->is_dialog = false;
246 }
248 if($this->dialog != NULL){
249 $this->dialog->save_object();
250 $this->is_dialog = true;
251 return($this->dialog->execute());
252 }
254 /*
255 Repository setup dialog handling /END
256 */
258 $divlist = new divList("repositories");
259 $divlist->SetEntriesPerPage(0);
260 $divlist->setHeight(400);
262 $divlist->setHeader(array(array("string"=>_("Release"),"attach"=>"style='width:80px;'"),
263 array("string"=>_("Sections")),
264 array("string"=>_("Options"),"attach"=>"style='border-right:0px;width:55px;'")
265 ) );
267 $link = "<a href='?plug=".$_GET['plug']."&act=open&id=%s'>%s</a>";
268 $edit = "<input type='image' value='%s' name='edit_%s' src='images/edit.png'> ";
269 $delete = "<input type='image' value='%s' name='delete_%s' src='images/edittrash.png'>";
271 foreach($this->repositories as $name => $reps){
273 $str = " ";
274 if(preg_match("/".str_replace("*",".*",$this->regex)."/",$reps['Release'])){
276 foreach($reps['Sections'] as $sec){
277 $str.=$sec." ";
278 }
280 if($allow_edit){
281 $link_str = sprintf($link,base64_encode($name),$name);
282 $sections = sprintf($link,base64_encode($name),_("Sections")." :".$str);
283 $options = preg_replace("/%s/",base64_encode($name),$edit.$delete);
284 }else{
285 $link_str = $name;
286 $sections = _("Sections")." :".$str;
287 $options = "";
288 }
291 $divlist->AddEntry(array(
292 array("string"=>$link_str,"attach"=>"style='width:80px;'"),
293 array("string"=>$sections),
294 array("string"=>$options,"attach"=>"style='border-right:0px;width:55px;text-align:right;'")));
295 }
296 }
298 $smarty -> assign("Repositories",$divlist->DrawList());
299 $smarty -> assign("FAIclassACL",chkacl($this->acl,"FAIclass"));
301 $display.= $smarty->fetch(get_template_path('servRepository.tpl', TRUE));
302 return($display);
303 }
305 function remove_from_parent()
306 {
307 /* Skip if not allowed */
308 $ui = get_userinfo();
309 $tmp= get_permissions ($this->dn, $ui->subtreeACL);
310 $this->acl= get_module_permission($tmp, "FAIclass", $this->dn);
312 if(preg_match("/disabled/",chkacl($this->acl,"FAIclass"))) return;
314 plugin::remove_from_parent();
315 $ldap= $this->config->get_ldap_link();
316 $ldap->cd ($this->config->current['BASE']);
318 $ldap->cat($this->dn, array('dn'));
320 if($ldap->count()){
321 $ldap->cd($this->dn);
322 $this->cleanup();
323 $ldap->modify ($this->attrs);
325 $this->handle_post_events("modify");
326 }
327 }
330 /* Save data to object */
331 function save_object()
332 {
333 plugin::save_object();
334 if(isset($_POST['regex'])){
335 $this->regex = $_POST['regex'];
336 }
337 }
340 /* Check supplied data */
341 function check()
342 {
343 /* Call common method to give check the hook */
344 $message= plugin::check();
346 return ($message);
347 }
350 /* Save to LDAP */
351 function save()
352 {
354 /* Skip if not allowed */
355 $ui = get_userinfo();
356 $tmp= get_permissions ($this->dn, $ui->subtreeACL);
357 $this->acl= get_module_permission($tmp, "FAIclass", $this->dn);
359 if(preg_match("/disabled/",chkacl($this->acl,"FAIclass"))) return;
360 plugin::save();
362 $arr = array();
363 foreach($this->repositories as $servername => $conf){
364 $str = "";
365 foreach($conf['Sections'] as $sec){
366 $str.=$sec.",";
367 }
368 $str=preg_replace("/,$/","",$str);
370 if($conf['ParentServer']=="none"){
371 $conf['ParentServer'] ="";
372 }
374 $arr[]=$conf['Url']."|".$conf['ParentServer']."|".$conf['Release']."|".$str;
375 }
376 $this->attrs['FAIrepository'] = $arr;
378 $ldap= $this->config->get_ldap_link();
379 $ldap->cd ($this->config->current['BASE']);
381 $ldap->cat($this->dn, array('dn'));
383 if($ldap->count()){
384 $ldap->cd($this->dn);
385 $this->cleanup();
386 $ldap->modify ($this->attrs);
388 $this->handle_post_events("modify");
389 }else{
390 $ldap->cd ($this->config->current['BASE']);
391 $ldap->create_missing_trees($this->dn);
392 $ldap->cd($this->dn);
393 $ldap->add($this->attrs);
394 $this->handle_post_events("add");
395 }
396 }
398 }
400 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
401 ?>