1 <?php
3 class faiScript 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");
16 /* ObjectClasses for this Object*/
17 var $objectclasses = array("top","FAIclass","FAIscript");
19 /* Specific attributes */
20 var $cn = ""; // The class name for this object
21 var $description = ""; // The description for this set of partitions
22 var $is_dialog = false; // specifies which buttons will be shown to save or abort
23 var $dialog = NULL; // a dialog, e.g. new disk dialog
24 var $SubObjects = array(); // All leafobjects of this object
26 /* new dn*/
27 var $use_dn ="";
29 function faiScript ($config, $dn= NULL)
30 {
31 /* Load Attributes */
32 plugin::plugin ($config, $dn);
33 }
35 function execute()
36 {
37 /* Fill templating stuff */
38 $smarty= get_smarty();
39 $display= "";
41 /* Add new sub object */
42 if(isset($_POST['AddSubObject'])){
43 $this->dialog= new faiScriptEntry($this->config,"new");
44 $this->dialog->parent = &$this;
45 $this->is_dialog=true;
46 }
48 /* Edit selected Sub Object */
49 if((isset($_POST['EditSubObject']))&&(isset($_POST['SubObject']))){
50 $this->dialog= new faiScriptEntry($this->config,$this->SubObjects[$_POST['SubObject']]['dn']);
51 $this->dialog->parent = &$this;
52 $this->is_dialog=true;
53 }
55 /* Remove Sub object */
56 if((isset($_POST['DelSubObject']))&&(isset($_POST['SubObject']))){
57 $tmp = new faiScriptEntry($this->config,$this->SubObjects[$_POST['SubObject']]['dn']);
58 $tmp->remove_from_parent();
59 unset($tmp);
60 }
62 /* Save Dialog */
63 if(isset($_POST['SaveSubObject'])){
64 $this->dialog->save_object();
65 $msgs = $this->dialog->check();
66 if(count($msgs)>0){
67 foreach($msgs as $msg){
68 print_red($msg);
69 }
70 }else{
71 $this->dialog->save_object();
72 $this->dialog->save();
73 $this->is_dialog=false;
74 unset($this->dialog);
75 $this->dialog=NULL;
76 }
77 }
79 /* Cancel Dialog */
80 if(isset($_POST['CancelSubObject'])){
81 $this->is_dialog=false;
82 unset($this->dialog);
83 $this->dialog=NULL;
84 }
86 /* Print dialog if $this->dialog is set */
87 if($this->dialog){
88 $this->dialog->save_object();
89 $display = $this->dialog->execute();
90 return($display);
91 }
93 $buffer = $this->getList();
94 $smarty->assign("SubObjects",$buffer);
95 $smarty->assign("SubObjectKeys",array_flip($buffer));
97 /* Magic quotes GPC, escapes every ' " \, to solve some security risks
98 * If we post the escaped strings they will be escaped again
99 */
100 foreach($this->attributes as $attrs){
101 if(get_magic_quotes_gpc()){
102 $smarty->assign($attrs,stripslashes($this->$attrs));
103 }else{
104 $smarty->assign($attrs,($this->$attrs));
105 }
106 }
108 $display.= $smarty->fetch(get_template_path('faiScript.tpl', TRUE));
109 return($display);
110 }
112 /* Generate listbox friendly SubObject list
113 */
114 function getList(){
115 $a_return = array();
116 $this->SubObjects = array();
118 $ldap = $this->config->get_ldap_link();
119 $ldap->cd ($this->config->current['BASE']);
120 $ldap->cd ($this->dn);
122 $ldap->search("(objectClass=FAIscriptEntry)",array("cn"));
124 while($entry = $ldap->fetch()){
125 $tmp = array();
126 $tmp['cn'] = $entry['cn'][0];
127 $tmp['dn']=$entry['dn'];
128 $this->SubObjects[$tmp['cn']] = $tmp;
130 if(isset($entry['description'][0])){
131 $a_return[$tmp['cn']] = $tmp['cn']." [".$entry['description'][0]."]";
132 }else{
133 $a_return[$tmp['cn']] = $tmp['cn'];
134 }
135 }
136 return($a_return);
137 }
139 /* Delete me, and all my subtrees
140 */
141 function remove_from_parent()
142 {
143 $ldap = $this->config->get_ldap_link();
144 $ldap->cd ($this->dn);
145 $ldap->rmdir_recursive($this->dn);
146 show_ldap_error($ldap->get_error());
147 $this->handle_post_events("remove");
148 }
151 /* Save data to object
152 */
153 function save_object()
154 {
155 if(isset($_POST['FAIscript_submit'])){
156 plugin::save_object();
157 foreach($this->attributes as $attrs){
158 if(isset($_POST[$attrs])){
159 $this->$attrs = $_POST[$attrs];
160 }
161 }
162 }
163 }
166 /* Check supplied data */
167 function check()
168 {
169 $message= array();
170 return ($message);
171 }
174 /* Save to LDAP */
175 function save()
176 {
177 plugin::save();
179 if($this->dn == "new"){
180 $this->dn = $this->use_dn;
181 }
183 $ldap = $this->config->get_ldap_link();
184 $ldap->cat($this->dn);
185 if($ldap->count()!=0){
186 /* Write FAIscript to ldap*/
187 $ldap->cd($this->dn);
188 $ldap->modify($this->attrs);
189 }else{
190 /* Write FAIscript to ldap*/
191 $ldap->cd($this->config->current['BASE']);
192 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
193 $ldap->cd($this->dn);
194 $ldap->add($this->attrs);
195 }
196 show_ldap_error($ldap->get_error());
197 }
198 }
200 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
201 ?>