9a3114e80a317c724535f7b809264afb504bc60e
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)
26 {
27 plugin::plugin ($config, $dn);
29 $this->repositories = array();
30 if(isset($this->attrs['FAIrepository'])){
31 for($i = 0; $i < $this->attrs['FAIrepository']['count']; $i++){
32 $tmp = split("\|",$this->attrs['FAIrepository'][$i]);
33 $tmp2 = array();
34 $tmp3 = array();
36 if(isset($tmp[1])){
37 $tmp2['ParentServer'] = $tmp[1];
38 if(empty($tmp[1])){
39 $tmp2['ParentServer'] = "none";
40 }
41 }else{
42 $tmp2['ParentServer'] = "none";
43 }
45 if(isset($tmp[0])){
46 $tmp2['Url'] = $tmp[0];
47 }else{
48 $tmp2['Url'] = "";
49 }
51 if(isset($tmp[2])){
52 $tmp2['Release'] = $tmp[2];
53 }else{
54 $tmp2['Release'] = "";
55 }
57 if(isset($tmp[3])){
58 $tmp3 = split(",",$tmp[3]);
59 foreach($tmp3 as $sec){
60 $tmp2['Sections'][$sec]=$sec;
61 }
62 }else{
63 $tmp['Section']=array();
64 }
66 $this->repositories[$tmp[2]]=$tmp2;
67 }
68 }
69 }
71 function execute()
72 {
73 /* Call parent execute */
74 plugin::execute();
76 /* Fill templating stuff */
77 $smarty= get_smarty();
78 $display= "";
80 /* Smarty vars*/
81 $smarty->assign("infoimage", get_template_path('images/info.png'));
82 $smarty->assign("search_image", get_template_path('images/search.png'));
83 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
84 $smarty->assign("tree_image", get_template_path('images/tree.png'));
85 $smarty->assign("alphabet", generate_alphabet());
86 $smarty->assign("apply", apply_filter());
87 $smarty->assign("regex", $this->regex);
90 /* Do we need to flip is_account state? */
91 if (isset($_POST['modify_state'])){
92 $this->is_account= !$this->is_account;
93 }
95 /* Show tab dialog headers */
96 if ($this->is_account){
97 $display= $this->show_header(_("Remove FAI repository extension."),
98 _("This server has FAI repository features enabled. You can disable them by clicking below."));
99 } else {
100 $display= $this->show_header(_("Add FAI repository extension."),
101 _("This server has FAI repository features disabled. You can enable them by clicking below."));
102 return ($display);
103 }
105 /*
106 ADD / EDIT Repository
107 Dialog Handling
108 */
110 $once = false;
111 if(isset($_POST['servRepository'])){
112 foreach($_POST as $name => $value){
114 if(preg_match("/AddRepository/",$name)){
115 $once = true;
116 $this->dialog = new servRepositorySetup($this->config,$this->dn);
117 $this->dialog->acl = $this->acl;
118 }
120 if((preg_match("/^delete_/",$name))&&(!$once)){
121 $once = true;
122 $value = preg_replace("/delete_/","",$name);
123 $value = base64_decode(preg_replace("/_.*$/","",$value));
125 $url = $this->repositories[$value]['Url'];
126 $release = $this->repositories[$value]['Release'];
128 $ldap = $this->config->get_ldap_link();
129 $ldap->cd ($this->config->current['BASE']);
131 $ldap->search("(&(objectClass=gotoWorkstation)(objectClass=FAIobject)(FAIdebianMirror=".$url."))",array("cn","FAIclass"));
133 $found = false;
134 $found_in = " ";
135 while($attrs = $ldap->fetch()){
136 foreach($attrs['FAIclass'] as $class){
137 if(preg_match("/".str_replace("/","\/",$release)."$/i",$class)){
138 $found = true;
139 $found_in .= $attrs['cn'][0]." ";
140 }
141 }
142 }
144 if($found){
145 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));
146 }else{
147 if(isset($this->repositories[$value])){
148 unset($this->repositories[$value]);
149 }
150 }
151 }
153 if((preg_match("/^edit_/",$name))&&(!$once)){
154 $value = preg_replace("/edit_/","",$name);
155 $value = base64_decode(preg_replace("/_.$/","",$value));
157 if(isset($this->repositories[$value])){
159 $ldap = $this->config->get_ldap_link();
160 $ldap->cd ($this->config->current['BASE']);
162 $url = $this->repositories[$value]['Url'];
163 $release = $this->repositories[$value]['Release'];
165 $ldap->search("(&(objectClass=gotoWorkstation)(objectClass=FAIobject)(FAIdebianMirror=".$url."))",array("cn","FAIclass"));
167 $found = false;
168 $found_in = " ";
169 while($attrs = $ldap->fetch()){
170 foreach($attrs['FAIclass'] as $class){
171 if(preg_match("/".str_replace("/","\/",$release)."$/i",$class)){
172 $found = true;
173 $found_in .= $attrs['cn'][0]." ";
174 }
175 }
176 }
178 if($found){
179 print_red(sprintf(_("Be careful editing this release, it is still used by these workstations [%s]."),$found_in));
180 }
182 if(isset($this->repositories[$value])){
183 $once = true;
184 $obj = $this->repositories[$value];
186 /* to be able to detect if this was renamed */
187 $obj['initialy_was'] = $obj['Release'];
188 $this->dialog = new servRepositorySetup($this->config,$this->dn,$obj);
189 $this->dialog->acl = $this->acl;
190 }
191 }
192 }
193 }
194 }
195 if((isset($_GET['act']))&&($_GET['act']=="open")&&(isset($_GET['id']))){
196 $obj = $this->repositories[base64_decode($_GET['id'])];
197 $obj['initialy_was'] = $obj['Release'];
198 $this->dialog = new servRepositorySetup($this->config,$this->dn,$obj);
199 $this->dialog->acl = $this->acl;
200 }
202 /*
203 if(isset($_POST['AddRepository'])){
204 $this->dialog = new servRepositorySetup($this->config,$this->dn);
205 $this->dialog->acl = $this->acl;
206 }
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 }
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']."&act=open&id=%s'>%s</a>";
258 $edit = "<input type='image' value='%s' name='edit_%s' src='images/edit.png'> ";
259 $delete = "<input type='image' value='%s' name='delete_%s' src='images/edittrash.png'>";
261 foreach($this->repositories as $name => $reps){
263 $str = " ";
265 if(preg_match("/".str_replace("*",".*",$this->regex)."/",$reps['Release'])){
268 foreach($reps['Sections'] as $sec){
269 $str.=$sec." ";
270 }
272 $divlist->AddEntry(array(
273 array("string"=>sprintf($link,base64_encode($name),$name),"attach"=>"style='width:80px;'"),
274 array("string"=>sprintf($link,base64_encode($name),_("Sections")." :".$str)),
275 array("string"=>preg_replace("/%s/",base64_encode($name),$edit.$delete),"attach"=>"style='border-right:0px;width:55px;text-align:right;'")
276 ));
277 }
278 }
280 $smarty -> assign("Repositories",$divlist->DrawList());
282 $display.= $smarty->fetch(get_template_path('servRepository.tpl', TRUE));
283 return($display);
284 }
286 function remove_from_parent()
287 {
288 plugin::remove_from_parent();
289 $ldap= $this->config->get_ldap_link();
290 $ldap->cd ($this->config->current['BASE']);
292 $ldap->cat($this->dn, array('dn'));
294 if($ldap->count()){
295 $ldap->cd($this->dn);
296 $this->cleanup();
297 $ldap->modify ($this->attrs);
299 $this->handle_post_events("modify");
300 }
301 }
304 /* Save data to object */
305 function save_object()
306 {
307 plugin::save_object();
308 if(isset($_POST['regex'])){
309 $this->regex = $_POST['regex'];
310 }
311 }
314 /* Check supplied data */
315 function check()
316 {
317 /* Call common method to give check the hook */
318 $message= plugin::check();
320 return ($message);
321 }
324 /* Save to LDAP */
325 function save()
326 {
327 plugin::save();
329 $arr = array();
330 foreach($this->repositories as $servername => $conf){
331 $str = "";
332 foreach($conf['Sections'] as $sec){
333 $str.=$sec.",";
334 }
335 $str=preg_replace("/,$/","",$str);
337 if($conf['ParentServer']=="none"){
338 $conf['ParentServer'] ="";
339 }
341 $arr[]=$conf['Url']."|".$conf['ParentServer']."|".$conf['Release']."|".$str;
342 }
343 $this->attrs['FAIrepository'] = $arr;
345 $ldap= $this->config->get_ldap_link();
346 $ldap->cd ($this->config->current['BASE']);
348 $ldap->cat($this->dn, array('dn'));
350 if($ldap->count()){
351 $ldap->cd($this->dn);
352 $this->cleanup();
353 $ldap->modify ($this->attrs);
355 $this->handle_post_events("modify");
356 }else{
357 $ldap->cd ($this->config->current['BASE']);
358 $ldap->create_missing_trees($this->dn);
359 $ldap->cd($this->dn);
360 $ldap->add($this->attrs);
361 $this->handle_post_events("add");
362 }
363 }
365 }
367 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
368 ?>