1 <?php
3 class servservice 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 var $goExportEntry = array();
11 var $goTimeSource = array();
12 var $goLdapBase= "";
13 var $goXdmcpIsEnabled ="";
14 var $goFontPath= "";
15 var $goNTPServer="";
16 var $goLdapServer="";
17 var $goTerminalServer="";
18 var $goSyslogServer="";
19 var $goCupsServer="";
21 /* attribute list for save action */
22 var $ignore_account= TRUE;
23 var $attributes = array("goLdapBase","goXdmcpIsEnabled","goFontPath");
24 var $possible_objectclasses= array( "goNfsServer", "goNtpServer", "goServer", "goLdapServer",
25 "goTerminalServer", "goSyslogServer", "goCupsServer");
26 var $objectclasses = array("top","goServer");
27 var $additionaloc = array( "goNfsServer" => array("goExportEntry"),
28 "goNtpServer" => array("goTimeSource"),
29 "goLdapServer" => array("goLdapBase"),
30 "goTerminalServer"=> array("goXdmcpIsEnabled", "goFontPath"),
31 "goSyslogServer" => array(),
32 "goCupsServer" => array());
34 function servservice ($config, $dn= NULL)
35 {
36 plugin::plugin ($config, $dn);
38 /* Assemble final object class list */
39 foreach ($this->additionaloc as $oc => $dummy){
40 if (isset($this->attrs['objectClass']) && in_array($oc, $this->attrs['objectClass'])){
41 $this->objectclasses[$oc]= $oc;
42 }
43 }
45 /* Load arrays */
46 foreach (array("goTimeSource", "goExportEntry") as $name){
47 $tmp= array();
48 if (isset($this->attrs[$name])){
49 for ($i= 0; $i<$this->attrs[$name]['count']; $i++){
50 $tmp[$this->attrs[$name][$i]]= $this->attrs[$name][$i];
51 }
52 }
53 $this->$name= $tmp;
54 }
56 /* Always is account... */
57 $this->is_account= TRUE;
58 }
61 function execute()
62 {
63 /* Fill templating stuff */
64 $smarty= get_smarty();
66 $smarty->assign("staticAddress", "");
68 /* Here we add a new entry */
69 if(isset($_POST['NewNfsAdd']) && $_POST['NewNfsExport'] != "") {
70 $this->goExportEntry[$_POST['NewNfsExport']]= $_POST['NewNfsExport'];
71 asort($this->goExportEntry);
72 }
74 /* Deleting an Entry, is a bit more complicated than adding one*/
75 if(isset($_POST['DelNfsEnt']) && isset($_POST['goExportEntry'])) {
76 foreach ($_POST['goExportEntry'] as $entry){
77 if (isset($this->goExportEntry[$entry])){
78 unset($this->goExportEntry[$entry]);
79 }
80 }
81 }
83 /* Here we add a new entry */
84 if(isset($_POST['NewNTPAdd']) && $_POST['NewNTPExport'] != "") {
85 $this->goTimeSource[$_POST['NewNTPExport']]= $_POST['NewNTPExport'];
86 asort($this->goTimeSource);
87 }
89 /* Deleting an Entry, is a bit more complicated than adding one*/
90 if(isset($_POST['DelNTPEnt'])) {
91 foreach ($_POST['goTimeSource'] as $entry){
92 if (isset($this->goTimeSource[$entry])){
93 unset($this->goTimeSource[$entry]);
94 }
95 }
96 }
98 /* Attributes */
99 foreach ($this->attributes as $attr){
100 $smarty->assign("$attr", $this->$attr);
101 $smarty->assign("$attr"."ACL", chkacl($this->acl, $attr));
102 $smarty->assign($attr."State","");
103 }
105 /* Arrays */
106 foreach (array("goTimeSource", "goExportEntry") as $name){
107 $smarty->assign("$name", $this->$name);
108 $smarty->assign("$name"."ACL", chkacl($this->acl, $name));
109 $smarty->assign($name."State","");
110 }
112 /* Classes... */
113 foreach ($this->additionaloc as $oc => $dummy){
114 if (isset($this->objectclasses[$oc])){
115 $smarty->assign("$oc", "checked");
116 $smarty->assign("$oc"."State", "");
117 $smarty->assign("$oc"."ACL", chkacl($this->acl, $oc));
119 } else {
120 $smarty->assign("$oc", "");
121 $smarty->assign("$oc"."ACL", chkacl($this->acl, $oc));
122 $smarty->assign("$oc"."State", "disabled");
123 }
124 }
126 /* Different handling for checkbox */
127 if($this->goXdmcpIsEnabled == "true"){
128 $smarty->assign("goXdmcpIsEnabled","checked");
129 } else {
130 $smarty->assign("goXdmcpIsEnabled","");
131 }
133 return($smarty->fetch (get_template_path('servservice.tpl', TRUE)));
134 }
137 function remove_from_parent()
138 {
139 /* This cannot be removed... */
140 }
143 /* Save data to object */
144 function save_object()
145 {
146 if (isset($_POST['servicetab'])){
147 plugin::save_object();
149 /* Save checkbox state */
150 foreach ($this->additionaloc as $oc => $dummy){
151 if (chkacl($this->acl, $oc) == ""){
152 if (isset($_POST[$oc]) && $_POST[$oc] == '1'){
153 $this->objectclasses[$oc]= $oc;
154 } else {
155 unset($this->objectclasses[$oc]);
156 }
157 }
158 }
160 /* Save xdmcp is enabled flag */
161 if (isset($_POST['goXdmcpIsEnabled'])){
162 $this->goXdmcpIsEnabled= "true";
163 } else {
164 $this->goXdmcpIsEnabled= "false";
165 }
167 }
168 }
171 /* Check supplied data */
172 function check()
173 {
174 $message= array();
176 if((isset($_POST['goTerminalServer']))&&(empty($this->goFontPath))){
177 $message[]=_("Terminal server, must have fontpath specified.");
178 }
180 return ($message);
181 }
184 /* Save to LDAP */
185 function save()
186 {
187 plugin::save();
189 $tmp= array();
191 /* Remove all from this plugin */
192 foreach($this->attrs['objectClass'] as $oc){
193 if (!in_array_ics($oc, $this->possible_objectclasses)){
194 $tmp[]= $oc;
195 }
196 }
198 /* Merge our current objectclasses */
199 foreach($this->objectclasses as $oc){
200 if (!in_array_ics($oc, $tmp)){
201 $tmp[]= $oc;
202 }
203 }
205 /* Reassign cleaned value */
206 $this->attrs['objectClass']= $tmp;
208 /* Remove illegal attributes */
209 foreach ($this->additionaloc as $oc => $attrs){
210 if (!in_array($oc, $this->objectclasses)){
211 foreach ($attrs as $attr){
212 $this->attrs[$attr]= array();
213 }
214 }
215 }
217 /* Arrays */
218 foreach (array("goTimeSource", "goExportEntry") as $name){
219 $this->attrs[$name]= array();
220 foreach ($this->$name as $element){
221 $this->attrs[$name][]= $element;
222 }
223 }
225 /* Write to LDAP */
226 $ldap= $this->config->get_ldap_link();
227 $ldap->cd($this->dn);
228 $ldap->modify($this->attrs);
229 show_ldap_error($ldap->get_error());
231 /* Optionally execute a command after we're done */
232 if ($this->initially_was_account == $this->is_account){
233 if ($this->is_modified){
234 $this->handle_post_events("mofify");
235 }
236 } else {
237 $this->handle_post_events("add");
238 }
239 }
241 }
243 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
244 ?>