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","FAIdebianSection","FAIdebianRelease","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 $FAIdebianSection = ""; // The selected section
38 var $FAIdebianRelease = ""; // selected release
39 var $FAIdebianMirror = ""; // selected mirror
41 var $servers = array(); // All available servers
42 var $sections = array(); // All possible sections
43 var $releases = array(); // All release types
45 var $disableRepository = false;
47 var $mirrors = array(); // The combination of server/section/release
48 var $confDir = "";
49 var $usedPackages = array();
51 function faiPackage ($config, $dn= NULL)
52 {
53 /* Load Attributes */
54 plugin::plugin ($config, $dn);
56 /* If "dn==new" we try to create a new entry
57 * Else we must read all objects from ldap which belong to this entry.
58 * First read SubObjects from ldap ... and then the partition definitions for the SubObjects.
59 */
60 if($dn != "new"){
61 $this->dn =$dn;
62 }
64 if(isset($this->attrs['FAIdebianRelease'])){
65 $this->disableRepository=true;
66 }
68 if(isset($this->attrs['FAIpackage'])){
69 unset($this->attrs['FAIpackage']['count']);
70 foreach($this->attrs['FAIpackage'] as $pkg){
71 $this->usedPackages[$pkg] = $pkg;
72 }
73 }else{
74 $this->usedPackages = array();;
75 }
76 $this->confDir = CONFIG_DIR."/fai/";
77 $this->FAIpackage = array();
78 }
80 function execute()
81 {
82 /* Fill templating stuff */
83 $smarty= get_smarty();
84 $display= "";
86 /* Assign variables */
87 foreach($this->attributes as $attrs){
88 $smarty->assign($attrs,$this->$attrs);
89 }
91 $this->genMirror();
93 $availableServer = array();
94 foreach($this->mirrors as $mir){
95 if(($mir['section'] == $this->FAIdebianSection)&&($mir['release']==$this->FAIdebianRelease)){
96 $availableServer[$mir['mirror']]=$mir['mirror'];
97 }
98 }
100 if(isset($_POST['Addpkg'])){
101 $this->dialog = new faiPackageEntry($this->config, $this->dn,$this->confDir.$this->mirror."/".$this->section."/".$this->release,$this->usedPackages);
102 $this->is_dialog =true;
103 }
105 if(isset($_POST['Delpkg'])){
106 unset($this->usedPackages[$_POST['usedPackages']]);
107 }
109 if(isset($_POST['CancelSubObject'])){
110 $this->dialog = false;
111 $this->is_dialog=false;
112 }
114 if(isset($_POST['SaveSubObject'])) {
115 $this->dialog->save_object();
116 if(count($this->dialog->check())){
117 foreach($this->dialog->check() as $msgs){
118 print_red($msgs);
119 }
120 }else{
121 $use = $this->dialog->save();
122 $this->usedPackages = $use;
123 $this->dialog = false;
124 $this->is_dialog=false;
125 $this->disableRepository =true;
126 }
127 }
129 if($this->is_dialog){
130 return $this->dialog->execute();
131 }
133 if($this->disableRepository == true){
134 $smarty->assign("mirrorACL" ," disabled ");
135 $smarty->assign("sectionACL" ," disabled ");
136 $smarty->assign("releaseACL" ," disabled ");
137 }else{
138 $smarty->assign("mirrorACL" ,"");
139 $smarty->assign("sectionACL" ,"");
140 $smarty->assign("releaseACL" ,"");
141 }
142 $smarty->assign("mirrors" ,$availableServer);
143 $smarty->assign("mirror" ,$this->FAIdebianMirror);
144 $smarty->assign("sections",$this->sections);
145 $smarty->assign("section" ,$this->FAIdebianSection);
146 $smarty->assign("releases",$this->releases);
147 $smarty->assign("release" ,$this->FAIdebianRelease);
148 $smarty->assign("usedPackages",$this->printUsedPackages());
149 $display.= $smarty->fetch(get_template_path('faiPackage.tpl', TRUE));
150 return($display);
151 }
153 function genMirror(){
154 $confDir = $this->confDir;
155 if(!is_readable($confDir)){
156 print_red(sprintf(_("Can't read configuration folder '%s'."),$confDir));
157 }else{
159 /* Try to catch all available mirrors
160 Possibly check if each server is reachable
161 */
162 $this->mirrors= array();
163 $fd = opendir($confDir);
164 while($mirror = readdir($fd)){
165 if((is_dir($confDir.$mirror."/"))&&(($mirror != "." )&&($mirror!=".."))){
167 $mirrorDir = $confDir.$mirror."/";
169 $fe = opendir($mirrorDir);
170 while($section = readdir($fe)){
171 if((is_dir($mirrorDir.$section))&&(($section != "." )&&($section!=".."))){
173 $sectionDir = $mirrorDir.$section."/";
175 $ff = opendir($sectionDir);
176 while($release = readdir($ff)){
177 if((is_file($sectionDir.$release))&&(($release != "." )&&($release!="..")&&(!preg_match("/.*\.in$/",$release)))){
179 $this->servers[$mirror]=$mirror;
180 $this->sections[$section]=$section;
181 $this->releases[$release]=$release;
183 if(empty($this->FAIdebianMirror)){
184 $this->FAIdebianMirror= $mirror;
185 }
186 if(empty($this->FAIdebianSection)){
187 $this->FAIdebianSection = $section;
188 }
189 if(empty($this->FAIdebianRelease)){
190 $this->FAIdebianRelease = $release;
191 }
193 $arr=array();
194 $arr['mirror'] = $mirror;
195 $arr['section']= $section;
196 $arr['release']= $release;
198 $this->mirrors[] = $arr ;
199 }
200 }
201 fclose($ff);
202 }
203 }
204 fclose($fe);
205 }
206 }
207 fclose($fd);
208 }
211 }
213 /* Delete me, and all my subtrees
214 */
215 function remove_from_parent()
216 {
217 $ldap = $this->config->get_ldap_link();
218 $ldap->cd ($this->dn);
219 $ldap->rmdir_recursive($this->dn);
220 $this->handle_post_events("remove");
221 }
224 /* Save data to object
225 */
226 function save_object()
227 {
228 plugin::save_object();
229 foreach($this->attributes as $attrs){
230 if(isset($_POST[$attrs])){
231 $this->$attrs = $_POST[$attrs];
232 }
233 }
234 }
237 /* Check supplied data */
238 function check()
239 {
240 $message= array();
242 if((empty($this->FAIdebianSection))||(empty($this->FAIdebianRelease))||(empty($this->FAIdebianMirror))){
243 $message[]=_("Please choose a valid combination for your repository setup.");
244 }
246 return ($message);
247 }
249 function printUsedPackages(){
250 $a_ret=array();
251 if(is_array($this->usedPackages)) {
252 foreach($this->usedPackages as $usedName){
253 $a_ret[$usedName] = $usedName;
254 }
255 }
256 return($a_ret);
257 }
259 /* Save to LDAP */
260 function save()
261 {
262 plugin::save();
264 $ldap = $this->config->get_ldap_link();
266 $this->attrs['FAIpackage'] = array();
267 foreach($this->usedPackages as $pkg => $obj){
268 $this->attrs['FAIpackage'][] = $pkg;
269 }
271 $ldap->cat($this->dn);
272 if($ldap->count()!=0){
273 /* Write FAIscript to ldap*/
274 $ldap->cd($this->dn);
275 $ldap->modify($this->attrs);
276 }else{
277 /* Write FAIscript to ldap*/
278 $ldap->cd($this->config->current['BASE']);
279 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
280 $ldap->cd($this->dn);
281 $ldap->add($this->attrs);
282 }
283 show_ldap_error($ldap->get_error());
284 }
285 }
287 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
288 ?>