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");
15 /* Search filter */
16 var $regex = "*";
18 /* Configurationdialog for repositories */
19 var $dialog = NULL;
21 /* Repositories */
22 var $repositories = array();
23 var $FAIrepository = array();
24 var $conflicts = array("FAIrepositoryServer");
25 var $DisplayName = "";
26 var $StatusFlag = "";
28 var $view_logged = FALSE;
29 var $fai_activated = FALSE;
31 function servrepository (&$config, $dn= NULL, $parent= NULL)
32 {
33 plugin::plugin ($config, $dn, $parent);
35 /* Skip this if fai is deactivated */
36 $tmp = search_config($this->config->data,"faiManagement","CLASS");
37 if(!empty($tmp)){
38 $this->fai_activated = TRUE;
39 }else{
40 return;
41 }
43 $this->DisplayName = _("Repository service");
45 $this->repositories = array();
46 if(isset($this->attrs['FAIrepository'])){
47 for($i = 0; $i < $this->attrs['FAIrepository']['count']; $i++){
48 $tmp = split("\|",$this->attrs['FAIrepository'][$i]);
49 $tmp2 = array();
50 $tmp3 = array();
52 if(isset($tmp[1])){
53 $tmp2['ParentServer'] = $tmp[1];
54 if(empty($tmp[1])){
55 $tmp2['ParentServer'] = "none";
56 }
57 }else{
58 $tmp2['ParentServer'] = "none";
59 }
61 if(isset($tmp[0])){
62 $tmp2['Url'] = $tmp[0];
63 }else{
64 $tmp2['Url'] = "";
65 }
67 if(isset($tmp[2])){
68 $tmp2['Release'] = $tmp[2];
69 }else{
70 $tmp2['Release'] = "";
71 }
73 if(isset($tmp[3])){
74 $tmp3 = split(",",$tmp[3]);
75 foreach($tmp3 as $sec){
76 $tmp2['Sections'][$sec]=$sec;
77 }
78 }else{
79 $tmp['Section']=array();
80 }
82 $this->repositories[$tmp[2]]=$tmp2;
83 }
84 }
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 /* Smarty vars*/
108 $smarty->assign("infoimage", get_template_path('images/info.png'));
109 $smarty->assign("search_image", get_template_path('images/search.png'));
110 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
111 $smarty->assign("tree_image", get_template_path('images/tree.png'));
112 $smarty->assign("alphabet", generate_alphabet());
113 $smarty->assign("apply", apply_filter());
114 $smarty->assign("regex", $this->regex);
116 /* Show tab dialog headers */
117 /*
118 ADD / EDIT Repository
119 Dialog Handling
120 */
121 $once = false;
122 if(isset($_POST['servRepository'])){
123 foreach($_POST as $name => $value){
125 if(preg_match("/AddRepository/",$name) && $this->acl_is_createable()){
126 $once = true;
127 $this->dialog = new servRepositorySetup($this->config,$this->dn);
128 $this->dialog->parent = $this;
129 }
131 if((preg_match("/^delete_/",$name)) && (!$once) && $this->acl_is_removeable()){
132 $once = true;
133 $value = preg_replace("/delete_/","",$name);
134 $value = base64_decode(preg_replace("/_.*$/","",$value));
136 $url = $this->repositories[$value]['Url'];
137 $release = $this->repositories[$value]['Release'];
139 $ldap = $this->config->get_ldap_link();
140 $ldap->cd ($this->config->current['BASE']);
142 $ldap->search("(&(objectClass=gotoWorkstation)(objectClass=FAIobject)(FAIdebianMirror=".$url."))",array("cn","FAIclass"));
144 $found = false;
145 $found_in = " ";
146 while($attrs = $ldap->fetch()){
147 foreach($attrs['FAIclass'] as $class){
148 if(preg_match("/".str_replace("/","\/",$release)."$/i",$class)){
149 $found = true;
150 $found_in .= $attrs['cn'][0]." ";
151 }
152 }
153 }
155 if($found){
156 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));
157 }else{
158 if(isset($this->repositories[$value])){
159 unset($this->repositories[$value]);
160 }
161 }
162 }
164 if((preg_match("/^edit_/",$name))&&(!$once)){
165 $value = preg_replace("/edit_/","",$name);
166 $value = base64_decode(preg_replace("/_.$/","",$value));
168 if(isset($this->repositories[$value])){
170 $ldap = $this->config->get_ldap_link();
171 $ldap->cd ($this->config->current['BASE']);
173 $url = $this->repositories[$value]['Url'];
174 $release = $this->repositories[$value]['Release'];
176 $ldap->search("(&(objectClass=gotoWorkstation)(objectClass=FAIobject)(FAIdebianMirror=".$url."))",array("cn","FAIclass"));
178 $found = false;
179 $found_in = " ";
180 while($attrs = $ldap->fetch()){
181 foreach($attrs['FAIclass'] as $class){
182 if(preg_match("/".str_replace("/","\/",$release)."$/i",$class)){
183 $found = true;
184 $found_in .= $attrs['cn'][0]." ";
185 }
186 }
187 }
189 if($found){
190 print_red(sprintf(_("Be careful editing this release, it is still used by these workstations [%s]."),$found_in));
191 }
193 if(isset($this->repositories[$value])){
194 $once = true;
195 $obj = $this->repositories[$value];
197 /* to be able to detect if this was renamed */
198 $obj['initialy_was'] = $obj['Release'];
199 $this->dialog = new servRepositorySetup($this->config,$this->dn,$obj);
200 $this->dialog->parent = $this;
201 }
202 }
203 }
204 }
205 }
206 if((isset($_GET['act']))&&($_GET['act']=="open")&&(isset($_GET['id']))){
207 $obj = $this->repositories[base64_decode($_GET['id'])];
208 $obj['initialy_was'] = $obj['Release'];
209 $this->dialog = new servRepositorySetup($this->config,$this->dn,$obj);
210 $this->dialog->parent = $this;
211 }
213 if(isset($_POST['repository_setup_save'])){
214 $this->dialog->save_object();
215 if(($this->dialog->is_new_name())&&(isset($this->repositories[$this->dialog->GetName()]))){
216 print_red(_("This name is already in use."));
217 }else
219 if(count($this->dialog->check())!=0){
220 foreach($this->dialog->check() as $msg){
221 print_red($msg);
222 }
223 }else{
224 $obj = $this->dialog->save();
225 if($this->dialog->is_new_name()){
226 $oldname = $this->dialog->initialy_was;
227 $this->repositories[$obj['Release']]=$obj;
228 unset($this->repositories[$oldname]);
229 }else{
230 $this->repositories[$obj['Release']]=$obj;
231 }
232 $this->dialog = NULL;
233 $this->is_dialog= false;
234 }
235 }
237 if(isset($_POST['repository_setup_cancel'])){
238 $this->dialog=NULL;
239 $this->is_dialog = false;
240 }
242 if($this->dialog != NULL){
243 $this->dialog->save_object();
244 $this->is_dialog = true;
245 return($this->dialog->execute());
246 }
248 /*
249 Repository setup dialog handling /END
250 */
252 $divlist = new divList("repositories");
253 $divlist->SetEntriesPerPage(0);
254 $divlist->setHeight(400);
255 $divlist->SetPluginMode();
257 $divlist->setHeader(array(array("string"=>_("Release"),"attach"=>"style='width:80px;'"),
258 array("string"=>_("Sections")),
259 array("string"=>_("Options"),"attach"=>"style='border-right:0px;width:55px;'")
260 ) );
262 $link = "<a href='?plug=".$_GET['plug']."&act=open&id=%s'>%s</a>";
263 $edit = "<input type='image' value='%s' name='edit_%s' src='images/edit.png'> ";
265 /* Hide delete icon, if delete is not allowed */
266 if($this->acl_is_removeable()){
267 $delete = "<input type='image' value='%s' name='delete_%s' src='images/edittrash.png'>";
268 }else{
269 $delete = "<img src='images/empty.png' alt=' '>";
270 }
272 foreach($this->repositories as $name => $reps){
274 $str = " ";
275 if(preg_match("/".str_replace("*",".*",$this->regex)."/",$reps['Release'])){
276 foreach($reps['Sections'] as $sec){
277 $str.=$sec." ";
278 }
279 $divlist->AddEntry(array(
280 array("string"=>sprintf($link,base64_encode($name),$name),"attach"=>"style='width:80px;'"),
281 array("string"=>sprintf($link,base64_encode($name),_("Sections")." :".$str)),
282 array("string"=>preg_replace("/%s/",base64_encode($name),$edit.$delete),"attach"=>"style='border-right:0px;width:55px;text-align:right;'")
283 ));
284 }
285 }
287 $smarty -> assign("Repositories",$divlist->DrawList());
289 $display.= $smarty->fetch(get_template_path('servRepository.tpl', TRUE));
290 return($display);
291 }
294 /* Save data to object */
295 function save_object()
296 {
297 plugin::save_object();
298 if(isset($_POST['regex'])){
299 $this->regex = $_POST['regex'];
300 }
301 }
304 /* Check supplied data */
305 function check()
306 {
307 /* Call common method to give check the hook */
308 $message= plugin::check();
309 return ($message);
310 }
313 /* Save to LDAP */
314 function save()
315 {
316 if(!$this->fai_activated) return;
318 plugin::save();
320 $arr = array();
321 foreach($this->repositories as $servername => $conf){
322 $str = "";
323 foreach($conf['Sections'] as $sec){
324 $str.=$sec.",";
325 }
326 $str=preg_replace("/,$/","",$str);
328 if($conf['ParentServer']=="none"){
329 $conf['ParentServer'] ="";
330 }
332 $arr[]=$conf['Url']."|".$conf['ParentServer']."|".$conf['Release']."|".$str;
333 }
334 $this->attrs['FAIrepository'] = $arr;
336 $ldap= $this->config->get_ldap_link();
337 $ldap->cd ($this->config->current['BASE']);
339 $ldap->cat($this->dn, array('dn'));
341 if($ldap->count()){
342 $ldap->cd($this->dn);
343 $this->cleanup();
344 $ldap->modify ($this->attrs);
346 $this->handle_post_events("modify");
347 }else{
348 $ldap->cd ($this->config->current['BASE']);
349 $ldap->create_missing_trees($this->dn);
350 $ldap->cd($this->dn);
351 $ldap->add($this->attrs);
352 $this->handle_post_events("add");
353 }
355 if($this->initially_was_account){
356 new log("modify","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
357 }else{
358 new log("create","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
359 }
360 }
363 function getListEntry()
364 {
365 $fields = goService::getListEntry();
366 $fields['Message'] = _("Repository service");
367 $fields['AllowEdit'] = true;
368 $fields['AllowStart'] = $fields['AllowStop'] = $fields['AllowRestart'] = false;
369 return($fields);
370 }
372 /* Return plugin informations for acl handling */
373 function plInfo()
374 {
375 return (array(
376 "plShortName" => _("Repository"),
377 "plDescription" => _("Repository service")." ("._("Services").")",
378 "plSelfModify" => FALSE,
379 "plDepends" => array(),
380 "plPriority" => 84,
381 "plSection" => array("administration"),
382 "plCategory" => array("server"),
384 "plProvidedAcls"=> array(
385 "cn" => _("Name"),
386 "start" => _("Start"),
387 "stop" => _("Stop"),
388 "restart" => _("Restart"),
389 "Release" => _("Releases"),
390 "Section" => _("Sections"),
391 "ParentServer" => _("Parent server"),
392 "Url" => _("Url"))
393 ));
394 }
395 }
397 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
398 ?>