c48e29ec3435a1655615f021fd2a0e48c124427d
1 <?php
3 class faiPackage 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;
13 /* Attributes for this Object */
14 var $attributes = array("cn","description","FAIpackage","FAIdebianRelease","FAIdebianSection","FAIdebianMirror");
16 /* ObjectClasses for this Object*/
17 var $objectclasses = array("top","FAIclass","FAIpackageList","FAIrepository");
19 /* Class name of the Ldap ObjectClass for the Sub Object */
20 var $subClass = "";
21 var $subClasses = array("top","FAIclass","FAIscriptEntry");
23 /* Class name of the php class which allows us to edit a Sub Object */
24 var $subClassName = "";
26 /* Attributes to initialise for each subObject */
27 var $subAttributes = array("cn","description");
28 var $sub64coded = array();
30 /* Specific attributes */
31 var $cn = ""; // The class name for this object
32 var $description = ""; // The description for this set of partitions
33 var $is_dialog = false; // specifies which buttons will be shown to save or abort
34 var $dialog = NULL; // a dialog, e.g. new disk dialog
35 var $SubObjects = array(); // All leafobjects of this object
37 var $FAIdebianRelease = ""; // The selected release
38 var $FAIdebianSection = ""; // selected section
39 var $FAIdebianMirror = ""; // selected mirror
41 var $servers = array(); // All available servers
42 var $releases = array(); // All possible releases
43 var $sections = array(); // All section types
45 var $list = array();
47 var $mirrors = array(); // The combination of server/release/section
48 var $confDir = "";
49 var $usedPackages = array();
51 var $strID ="";
53 function faiPackage ($config, $dn= NULL)
54 {
55 /* Load Attributes */
56 plugin::plugin ($config, $dn);
58 /* If "dn==new" we try to create a new entry
59 * Else we must read all objects from ldap which belong to this entry.
60 * First read SubObjects from ldap ... and then the partition definitions for the SubObjects.
61 */
62 if($dn != "new"){
63 $this->dn =$dn;
64 }
66 if(isset($this->attrs['FAIpackage'])){
67 unset($this->attrs['FAIpackage']['count']);
68 foreach($this->attrs['FAIpackage'] as $pkg){
69 $this->usedPackages[$pkg] = $pkg;
70 }
71 }else{
72 $this->usedPackages = array();
73 }
74 $this->confDir = CONFIG_DIR."/fai/";
75 $this->FAIpackage = array();
76 }
78 function execute()
79 {
80 /* Fill templating stuff */
81 $smarty= get_smarty();
82 $display= "";
84 $disableRelease = false;
85 $disableMirror = false;
86 $disableOptions = false;
87 $disableSection = false;
89 /* Assign variables */
90 foreach($this->attributes as $attrs){
91 $smarty->assign($attrs,$this->$attrs);
92 }
94 /* Post handling for Section, Release and Mirror Setup */
95 if(isset($_POST['SetSection'])){
96 $this->FAIdebianSection = $_POST['FAIdebianSectionS'];
97 }
98 if(isset($_POST['SetRelease'])){
99 $this->FAIdebianRelease = $_POST['FAIdebianReleaseS'];
100 }
101 if(isset($_POST['SetMirror'])){
102 $this->FAIdebianMirror = $_POST['FAIdebianMirrorS'];
103 }
105 if(empty($this->FAIdebianRelease)){
106 $disableSection = $disableMirror = $disableOptions = true;
107 $this->sections=array("---");
108 }elseif(empty($this->FAIdebianSection)){
109 $disableRelease = $disableMirror = $disableOptions = true;
110 }elseif(empty($this->FAIdebianMirror)){
111 $disableRelease = $disableSection = $disableOptions = true;
112 }else{
113 $disableRelease = $disableSection = true;
114 }
116 $this->genMirror();
118 $availableServer = array();
119 foreach($this->mirrors as $mir){
120 if(($mir['release'] == $this->FAIdebianRelease)&&($mir['section']==$this->FAIdebianSection)){
121 $availableServer[$mir['mirror']]=$mir['mirror'];
122 }
123 }
125 if(($disableMirror==false)&&(count($availableServer)==0)){
126 $this->FAIdebianRelease = $this->FAIdebianSection = $this->FAIdebianMirror = "";
127 $disableSection = $disableMirror = $disableOptions = true;
128 $disableRelease = false;
129 }
131 if(count($availableServer)==0){
132 $availableServer=array("---");
133 }
135 $smarty->assign("ReleaseACL" , "");
136 $smarty->assign("MirrorACL" , "");
137 $smarty->assign("OptionACL" , "");
138 $smarty->assign("SectionACL" , "");
140 if($disableOptions){
141 $smarty->assign("OptionACL"," disabled ");
142 }
143 if($disableRelease){
144 $smarty->assign("ReleaseACL"," disabled ");
145 }
146 if($disableMirror){
147 $smarty->assign("MirrorACL"," disabled ");
148 }
149 if($disableSection){
150 $smarty->assign("SectionACL"," disabled ");
151 }
153 $this->strID = $this->confDir.$this->FAIdebianMirror."/".$this->FAIdebianRelease."/".$this->FAIdebianSection;
154 if(!$disableOptions){
155 if(!isset($this->list[$this->strID])){
156 $tmp = new faiPackageEntry($this->config, $this->dn,$this->strID,$this->usedPackages);
157 $this->list[$this->strID]=$tmp->genPkgs();
158 }
159 }
161 if(isset($_POST['Addpkg'])){
162 $this->dialog = new faiPackageEntry($this->config, $this->dn,$this->strID,$this->usedPackages);
163 $this->dialog->buffer[$this->strID]= $this->list[$this->strID];
164 $this->is_dialog =true;
165 }
167 if(isset($_POST['Delpkg'])){
168 unset($this->usedPackages[$_POST['usedPackages']]);
169 }
171 if(isset($_POST['CancelSubObject'])){
172 $this->dialog = false;
173 $this->is_dialog=false;
174 }
176 if(isset($_POST['SaveSubObject'])) {
177 $this->dialog->save_object();
178 if(count($this->dialog->check())){
179 foreach($this->dialog->check() as $msgs){
180 print_red($msgs);
181 }
182 }else{
183 $use = $this->dialog->save();
184 $this->usedPackages = $use;
185 $this->dialog = false;
186 $this->is_dialog=false;
187 }
188 }
190 if(isset($_POST['Conpkg'])){
191 $this->dialog = new faiPackageConfiguration($this->config, $this->dn,"none");
192 $this->is_dialog =true;
193 }
195 if(isset($_POST['SaveObjectConfig'])){
196 $this->dialog = false;
197 $this->is_dialog=false;
198 }
200 if(isset($_POST['CancelObjectConfig'])){
201 $this->dialog = false;
202 $this->is_dialog=false;
203 }
205 if($this->is_dialog){
206 return $this->dialog->execute();
207 }
209 $smarty->assign("mirrors" ,$availableServer);
210 $smarty->assign("mirror" ,$this->FAIdebianMirror);
211 $smarty->assign("releases",$this->releases);
212 $smarty->assign("release" ,$this->FAIdebianRelease);
213 $smarty->assign("sections",$this->sections);
214 $smarty->assign("section" ,$this->FAIdebianSection);
215 $smarty->assign("usedPackages",$this->printUsedPackages());
216 $display.= $smarty->fetch(get_template_path('faiPackage.tpl', TRUE));
217 return($display);
218 }
220 function genMirror(){
221 $confDir = $this->confDir;
222 if(!is_readable($confDir)){
223 print_red(sprintf(_("Can't read configuration folder '%s'."),$confDir));
224 }else{
226 /* Try to catch all available mirrors
227 Possibly check if each server is reachable
228 */
230 $this->servers= array();
231 $this->releases=array();
232 $this->sections=array();
233 $this->mirrors= array();
234 $fd = opendir($confDir);
235 while($mirror = readdir($fd)){
236 if((is_dir($confDir.$mirror."/"))&&(($mirror != "." )&&($mirror!=".."))){
238 $mirrorDir = $confDir.$mirror."/";
240 $fe = opendir($mirrorDir);
241 while($release = readdir($fe)){
242 if((is_dir($mirrorDir.$release))&&(($release != "." )&&($release!=".."))){
244 $releaseDir = $mirrorDir.$release."/";
246 $ff = opendir($releaseDir);
247 while($section = readdir($ff)){
248 if((is_file($releaseDir.$section))&&(($section != "." )&&($section!="..")&&(!preg_match("/.*\.in$/",$section)))){
250 $this->servers[$mirror]=$mirror;
251 $this->releases[$release]=$release;
252 $this->sections[$section]=$section;
254 if(empty($this->FAIdebianRelease)){
255 $this->sections= array("---");
256 }
258 $arr=array();
259 $arr['mirror'] = $mirror;
260 $arr['release']= $release;
261 $arr['section']= $section;
263 $this->mirrors[] = $arr ;
264 }
265 }
266 fclose($ff);
267 }
268 }
269 fclose($fe);
270 }
271 }
272 fclose($fd);
273 }
276 }
278 /* Delete me, and all my subtrees
279 */
280 function remove_from_parent()
281 {
282 $ldap = $this->config->get_ldap_link();
283 $ldap->cd ($this->dn);
284 $ldap->rmdir_recursive($this->dn);
285 $this->handle_post_events("remove");
286 }
289 /* Save data to object
290 */
291 function save_object()
292 {
294 plugin::save_object();
295 foreach($this->attributes as $attrs){
296 if(isset($_POST[$attrs])){
297 $this->$attrs = $_POST[$attrs];
298 }
299 }
300 }
303 /* Check supplied data */
304 function check()
305 {
306 $message= array();
308 if(count($this->usedPackages)==0){
309 $message[]=_("Please select a least one Package.");
310 }
312 if((empty($this->FAIdebianRelease))||(empty($this->FAIdebianSection))||(empty($this->FAIdebianMirror))){
313 $message[]=_("Please choose a valid combination for your repository setup.");
314 }
316 return ($message);
317 }
319 function printUsedPackages(){
320 $a_ret=array();
321 if(is_array($this->usedPackages)) {
322 foreach($this->usedPackages as $usedName){
323 if(isset($this->list[$this->strID][$usedName][1])){
324 $a_ret[$usedName] = $usedName." [".$this->list[$this->strID][$usedName][1]."]";
325 }else{
326 $a_ret[$usedName] = $usedName;
327 }
328 }
329 }
330 return($a_ret);
331 }
333 /* Save to LDAP */
334 function save()
335 {
336 plugin::save();
338 $ldap = $this->config->get_ldap_link();
340 $this->attrs['FAIpackage'] = array();
341 foreach($this->usedPackages as $pkg => $obj){
342 $this->attrs['FAIpackage'][] = $pkg;
343 }
345 $ldap->cat($this->dn);
346 if($ldap->count()!=0){
347 /* Write FAIscript to ldap*/
348 $ldap->cd($this->dn);
349 $ldap->modify($this->attrs);
350 }else{
351 /* Write FAIscript to ldap*/
352 $ldap->cd($this->config->current['BASE']);
353 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
354 $ldap->cd($this->dn);
355 $ldap->add($this->attrs);
356 }
357 show_ldap_error($ldap->get_error());
358 }
359 }
361 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
362 ?>