0bca5192ed72c2d5f65a123eec207d26227e4d2b
1 <?php
3 class faiProfile 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","FAIclass");
16 /* ObjectClasses for this Object*/
17 var $objectclasses = array("top","FAIclass","FAIprofile");
19 /* Class name of the Ldap ObjectClass for the Sub Object */
20 var $subClass = "FAIscriptEntry";
21 var $subClasses = array("top","FAIclass","FAIscriptEntry");
23 /* Specific attributes */
24 var $old_cn = "";
25 var $cn = ""; // The class name for this object
26 var $description = ""; // The description for this set of partitions
27 var $is_dialog = false; // specifies which buttons will be shown to save or abort
28 var $dialog = NULL; // a dialog, e.g. new disk dialog
29 var $FAIclass = ""; // Classnames used for this profile
30 var $FAIclasses = array(); // Contains classname seperated in an array
31 var $FAIAllclasses = array(); // Contains all possible Classnames
33 function faiProfile($config, $dn= NULL)
34 {
35 /* Load Attributes */
36 plugin::plugin ($config, $dn);
37 $ldap=$this->config->get_ldap_link();
39 $tmp = split(" ",$this->FAIclass);
41 foreach($tmp as $class){
42 if(!empty($class)){
43 $this->FAIclasses[trim($class)] = trim($class);
44 }
45 }
46 natcasesort($this->FAIclasses);
47 reset($this->FAIclasses) ;
49 $categories = array("FAIscript","FAItemplate","FAIhook","FAIvariable","FAIpartitionTAble","FAIpackage");
51 $sort = array();
53 $base = $_SESSION['faifilter']['base'];
54 $ldap->cd($base);
55 $ldap->search("(objectClass=*)",array("*"));
56 while($attrs = $ldap->fetch()){
57 foreach($categories as $cat){
58 if(in_array($cat,$attrs['objectClass'])){
59 $this->FAIAllclasses[$attrs['cn'][0]][$cat]=$attrs;
60 $sort[strtolower($attrs['cn'][0])] = $attrs['cn'][0];
61 }
62 }
63 }
64 ksort($sort);
65 foreach($sort as $name){
66 $tmp[$name] =$this->FAIAllclasses[$name];
67 }
68 $this->FAIAllclasses = array();
69 $this->FAIAllclasses = $tmp;
71 if($dn != "new"){
72 $this->dn =$dn;
73 }
74 $this->old_cn = $this->cn;
75 }
77 function execute()
78 {
79 /* Fill templating stuff */
80 $smarty= get_smarty();
81 $display= "";
83 $s_entry = "";
84 $s_action = "";
86 /* Remove class name From list */
87 foreach($_POST as $name => $post){
88 if(preg_match("/DEL_/i",$name)){
89 $s_action = "delete";
90 $s_entry = preg_replace("/DEL_/","",$name);
91 $s_entry = preg_replace("/_.*$/","",$s_entry);
92 }elseif(preg_match("/Add_class/i",$name)){
93 $s_action = "add";
94 }
95 }
97 if($s_action == "delete"){
98 unset($this->FAIclasses[$s_entry]);
99 }
101 if($s_action == "add"){
102 $this->dialog = new faiProfileEntry($this->config,$this->dn,$this->FAIclasses);
103 $this->is_dialog =true;
104 }
106 /* Save Dialog */
107 if(isset($_POST['SaveSubObject'])){
108 $this->dialog->save_object();
109 $msgs= $this->dialog->check();
110 if(count($msgs)){
111 print_red($msgs);
112 }else{
113 $ret = $this->dialog->save();
114 foreach($ret as $class){
115 $this->FAIclasses[$class] =$class;
116 }
117 $this->is_dialog=false;
118 unset($this->dialog);
119 $this->dialog=NULL;
120 }
121 }
123 /* Cancel Dialog */
124 if(isset($_POST['CancelSubObject'])){
125 $this->is_dialog=false;
126 unset($this->dialog);
127 $this->dialog=NULL;
128 }
130 if(isset($this->dialog)){
131 $this->dialog->save_object();
132 return($this->dialog->execute());
133 }
135 $divlist =new divlist("Profile");
136 $divlist->SetSummary(_("This list displays all assigned class names for this profile."));
137 $divlist->SetEntriesPerPage(10);
139 $divlist->SetHeader(array(array("string"=>"Class name"),
140 array("string"=>"Objects","attach"=>"style='width:120px;'"),
141 array("string"=>"Options","attach"=>"style='border-right:none;width:60px;'")));
142 $listhead =
143 "<div style='background:#F0F0F9;padding:5px;'>".
144 "<input type='image' align='middle' src='images/editpaste.png' title='"._("Append new class names")."' alt='"._("Add")."' name='Add_class'> ".
145 "</div>";
147 $objTypes['FAIhook'] = "<image src='images/fai_hook.png' title='"._("Hook bundle")."' alt=''>";
148 $objTypes['FAItemplate'] = "<image src='images/fai_template.png' title='"._("Template bundle")."' alt=''>";
149 $objTypes['FAIscript'] = "<image src='images/fai_script.png' title='"._("Script bundle")."' alt=''>";
150 $objTypes['FAIvariable'] = "<image src='images/fai_variable.png' title='"._("Variable bundle")."' alt=''>";
151 $objTypes['FAIpackages'] = "<image src='images/fai_packages.png' title='"._("Packages bundle")."' alt=''>";
152 $objTypes['FAIpartitionTable'] = "<image src='images/fai_partitionTable.png' title='"._("Partition table")."' alt=''>";
154 $actions = "<input type='image' src='images/editdelete.png' title='"._("Remove class from profile")."' name='DEL_%KEY%'>";
156 foreach($this->FAIclasses as $usedClass){
157 $str = "";
158 if(isset($this->FAIAllclasses[$usedClass])){
159 foreach($this->FAIAllclasses[$usedClass] as $class => $obj){
160 $str.= $objTypes[$class];
161 }
162 }
164 $field1 = array("string"=> $usedClass,"attach"=>"");
165 $field2 = array("string"=> $str,"attach"=>"");
166 $field3 = array("string"=> preg_replace("/%KEY%/",$usedClass,$actions),"attach"=>"style='border-right:none;'");
167 $divlist->AddEntry(array($field1,$field2,$field3));
168 }
170 $smarty->assign("divlisthead" ,$listhead);
171 $smarty->assign("divlist" ,$divlist->DrawList());
173 /* Assign variables */
174 foreach($this->attributes as $attrs){
175 $smarty->assign($attrs,$this->$attrs);
176 }
178 $display.= $smarty->fetch(get_template_path('faiProfile.tpl', TRUE));
179 return($display);
180 }
182 function remove_from_parent()
183 {
184 $ldap = $this->config->get_ldap_link();
185 $ldap->cd ($this->dn);
186 $ldap->rmdir_recursive($this->dn);
187 $this->handle_post_events("remove");
188 }
190 /* Save data to object
191 */
192 function save_object()
193 {
194 plugin::save_object();
195 foreach($this->attributes as $attrs){
196 if(isset($_POST[$attrs])){
197 $this->$attrs = $_POST[$attrs];
198 }
199 }
200 }
203 /* Check supplied data */
204 function check()
205 {
206 $message= array();
207 $str = utf8_encode("üöä");
208 if((empty($this->description))){
209 $message[] =_("Please specify a description for this profile.");
210 }
212 if((preg_match("/[^a-z0-9".$str."\.,;:\-_\? ]/i",$this->description))){
213 $message[]=_("Please enter a valid description.");
214 }
216 if((empty($this->cn))||(preg_match("/[^a-z0-9]/i",$this->cn))){
217 $message[]=_("Please enter a valid name. Only 0-9 a-Z are allowed here.");
218 }
220 if(count($this->FAIclasses) == 0){
221 $message[]=_("Please assign at least one class to this profile.");
222 }
224 $ldap = $this->config->get_ldap_link();
225 $ldap->cd($_SESSION['faifilter']['base']);
226 $ldap->search("(&(objectClass=FAIprofile)(cn=".$this->cn.")(!cn=".$this->old_cn."))",array("*"));
228 if($ldap->count()){
229 $message[]=_("There is already a profile with this class name defined.");
230 }
232 return ($message);
233 }
236 /* Save to LDAP */
237 function save()
238 {
239 plugin::save();
241 $ldap = $this->config->get_ldap_link();
243 $this->FAIclass = "";
244 foreach($this->FAIclasses as $class){
245 $this->FAIclass.=$class." ";
246 }
248 $this->attrs['FAIclass']=trim($this->FAIclass);
250 $ldap->cat($this->dn);
251 if($ldap->count()!=0){
252 /* Write FAIscript to ldap*/
253 $ldap->cd($this->dn);
254 $ldap->modify($this->attrs);
255 }else{
256 /* Write FAIscript to ldap*/
257 $ldap->cd($this->config->current['BASE']);
258 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
259 $ldap->cd($this->dn);
260 $ldap->add($this->attrs);
261 }
262 show_ldap_error($ldap->get_error());
263 }
264 }
266 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
267 ?>