de42cecfb929b592940532a6697e304d723fe129
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 $mirrors = array(); // The combination of server/release/section
46 var $confDir = "";
47 var $usedPackages = array();
49 function faiPackage ($config, $dn= NULL)
50 {
51 /* Load Attributes */
52 plugin::plugin ($config, $dn);
54 /* If "dn==new" we try to create a new entry
55 * Else we must read all objects from ldap which belong to this entry.
56 * First read SubObjects from ldap ... and then the partition definitions for the SubObjects.
57 */
58 if($dn != "new"){
59 $this->dn =$dn;
60 }
62 if(isset($this->attrs['FAIpackage'])){
63 unset($this->attrs['FAIpackage']['count']);
64 foreach($this->attrs['FAIpackage'] as $pkg){
65 $this->usedPackages[$pkg] = $pkg;
66 }
67 }else{
68 $this->usedPackages = array();
69 }
70 $this->confDir = CONFIG_DIR."/fai/";
71 $this->FAIpackage = array();
72 }
74 function execute()
75 {
76 /* Fill templating stuff */
77 $smarty= get_smarty();
78 $display= "";
80 $disableRelease = false;
81 $disableMirror = false;
82 $disableOptions = false;
83 $disableSection = false;
85 /* Assign variables */
86 foreach($this->attributes as $attrs){
87 $smarty->assign($attrs,$this->$attrs);
88 }
90 /* Post handling for Section, Release and Mirror Setup */
91 if(isset($_POST['SetSection'])){
92 $this->FAIdebianSection = $_POST['FAIdebianSectionS'];
93 }
94 if(isset($_POST['SetRelease'])){
95 $this->FAIdebianRelease = $_POST['FAIdebianReleaseS'];
96 }
97 if(isset($_POST['SetMirror'])){
98 $this->FAIdebianMirror = $_POST['FAIdebianMirrorS'];
99 }
101 if(empty($this->FAIdebianRelease)){
102 $disableSection = $disableMirror = $disableOptions = true;
103 }elseif(empty($this->FAIdebianSection)){
104 $disableRelease = $disableMirror = $disableOptions = true;
105 }elseif(empty($this->FAIdebianMirror)){
106 $disableRelease = $disableSection = $disableOptions = true;
107 }else{
108 $disableRelease = $disableSection = true;
109 }
111 $smarty->assign("ReleaseACL" , "");
112 $smarty->assign("MirrorACL" , "");
113 $smarty->assign("OptionACL" , "");
114 $smarty->assign("SectionACL" , "");
116 if($disableOptions){
117 $smarty->assign("OptionACL"," disabled ");
118 }
119 if($disableRelease){
120 $smarty->assign("ReleaseACL"," disabled ");
121 }
122 if($disableMirror){
123 $smarty->assign("MirrorACL"," disabled ");
124 }
125 if($disableSection){
126 $smarty->assign("SectionACL"," disabled ");
127 }
129 $this->genMirror();
131 $availableServer = array();
132 foreach($this->mirrors as $mir){
133 if(($mir['release'] == $this->FAIdebianRelease)&&($mir['section']==$this->FAIdebianSection)){
134 $availableServer[$mir['mirror']]=$mir['mirror'];
135 }
136 }
138 if($disableMirror){
139 $availableServer[$mir['mirror']]=array("---");
140 }
142 if(isset($_POST['Addpkg'])){
143 $this->dialog = new faiPackageEntry($this->config, $this->dn,$this->confDir.$this->FAIdebianMirror."/".$this->FAIdebianRelease."/".$this->FAIdebianSection,$this->usedPackages);
144 $this->is_dialog =true;
145 }
147 if(isset($_POST['Delpkg'])){
148 unset($this->usedPackages[$_POST['usedPackages']]);
149 }
151 if(isset($_POST['CancelSubObject'])){
152 $this->dialog = false;
153 $this->is_dialog=false;
154 }
156 if(isset($_POST['SaveSubObject'])) {
157 $this->dialog->save_object();
158 if(count($this->dialog->check())){
159 foreach($this->dialog->check() as $msgs){
160 print_red($msgs);
161 }
162 }else{
163 $use = $this->dialog->save();
164 $this->usedPackages = $use;
165 $this->dialog = false;
166 $this->is_dialog=false;
167 }
168 }
170 if($this->is_dialog){
171 return $this->dialog->execute();
172 }
174 $smarty->assign("mirrors" ,$availableServer);
175 $smarty->assign("mirror" ,$this->FAIdebianMirror);
176 $smarty->assign("releases",$this->releases);
177 $smarty->assign("release" ,$this->FAIdebianRelease);
178 $smarty->assign("sections",$this->sections);
179 $smarty->assign("section" ,$this->FAIdebianSection);
180 $smarty->assign("usedPackages",$this->printUsedPackages());
181 $display.= $smarty->fetch(get_template_path('faiPackage.tpl', TRUE));
182 return($display);
183 }
185 function genMirror(){
186 $confDir = $this->confDir;
187 if(!is_readable($confDir)){
188 print_red(sprintf(_("Can't read configuration folder '%s'."),$confDir));
189 }else{
191 /* Try to catch all available mirrors
192 Possibly check if each server is reachable
193 */
195 $this->servers= array();
196 $this->releases=array();
197 $this->sections=array();
198 $this->mirrors= array();
199 $fd = opendir($confDir);
200 while($mirror = readdir($fd)){
201 if((is_dir($confDir.$mirror."/"))&&(($mirror != "." )&&($mirror!=".."))){
203 $mirrorDir = $confDir.$mirror."/";
205 $fe = opendir($mirrorDir);
206 while($release = readdir($fe)){
207 if((is_dir($mirrorDir.$release))&&(($release != "." )&&($release!=".."))){
209 $releaseDir = $mirrorDir.$release."/";
211 $ff = opendir($releaseDir);
212 while($section = readdir($ff)){
213 if((is_file($releaseDir.$section))&&(($section != "." )&&($section!="..")&&(!preg_match("/.*\.in$/",$section)))){
215 $this->servers[$mirror]=$mirror;
216 $this->releases[$release]=$release;
217 $this->sections[$section]=$section;
219 if(empty($this->FAIdebianRelease)){
220 $this->servers= array("---");
221 }
222 if(empty($this->FAIdebianSection)){
223 $this->releases= array("---");
224 }
225 if(empty($this->FAIdebianSection)){
226 $this->FAIdebianSection = $section;
227 }
229 $arr=array();
230 $arr['mirror'] = $mirror;
231 $arr['release']= $release;
232 $arr['section']= $section;
234 $this->mirrors[] = $arr ;
235 }
236 }
237 fclose($ff);
238 }
239 }
240 fclose($fe);
241 }
242 }
243 fclose($fd);
244 }
247 }
249 /* Delete me, and all my subtrees
250 */
251 function remove_from_parent()
252 {
253 $ldap = $this->config->get_ldap_link();
254 $ldap->cd ($this->dn);
255 $ldap->rmdir_recursive($this->dn);
256 $this->handle_post_events("remove");
257 }
260 /* Save data to object
261 */
262 function save_object()
263 {
265 plugin::save_object();
266 foreach($this->attributes as $attrs){
267 if(isset($_POST[$attrs])){
268 $this->$attrs = $_POST[$attrs];
269 }
270 }
271 }
274 /* Check supplied data */
275 function check()
276 {
277 $message= array();
279 if(count($this->usedPackages)==0){
280 $message[]=_("Please select a least one Package.");
281 }
283 if((empty($this->FAIdebianRelease))||(empty($this->FAIdebianSection))||(empty($this->FAIdebianMirror))){
284 $message[]=_("Please choose a valid combination for your repository setup.");
285 }
287 return ($message);
288 }
290 function printUsedPackages(){
291 $a_ret=array();
292 if(is_array($this->usedPackages)) {
293 foreach($this->usedPackages as $usedName){
294 $a_ret[$usedName] = $usedName;
295 }
296 }
297 return($a_ret);
298 }
300 /* Save to LDAP */
301 function save()
302 {
303 plugin::save();
305 $ldap = $this->config->get_ldap_link();
307 $this->attrs['FAIpackage'] = array();
308 foreach($this->usedPackages as $pkg => $obj){
309 $this->attrs['FAIpackage'][] = $pkg;
310 }
312 $ldap->cat($this->dn);
313 if($ldap->count()!=0){
314 /* Write FAIscript to ldap*/
315 $ldap->cd($this->dn);
316 $ldap->modify($this->attrs);
317 }else{
318 /* Write FAIscript to ldap*/
319 $ldap->cd($this->config->current['BASE']);
320 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
321 $ldap->cd($this->dn);
322 $ldap->add($this->attrs);
323 }
324 show_ldap_error($ldap->get_error());
325 }
326 }
328 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
329 ?>