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 $objectclasses = array("top","goServer");
25 var $additionaloc = array( "goNfsServer" => array("goExportEntry"),
26 "goNtpServer" => array("goTimeSource"),
27 "goLdapServer" => array("goLdapBase"),
28 "goTerminalServer"=> array("goXdmcpIsEnabled", "goFontPath"),
29 "goSyslogServer" => array(),
30 "goCupsServer" => array());
32 function servservice ($config, $dn= NULL)
33 {
34 plugin::plugin ($config, $dn);
36 /* Assemble final object class list */
37 foreach ($this->additionaloc as $oc => $dummy){
38 if (isset($this->attrs['objectClass']) && in_array($oc, $this->attrs['objectClass'])){
39 $this->objectclasses[$oc]= $oc;
40 }
41 }
43 /* Load arrays */
44 foreach (array("goTimeSource", "goExportEntry") as $name){
45 $this->$name= array();
46 if (isset($this->attrs[$name])){
47 for ($i= 0; $i<$this->attrs[$name]['count']; $i++){
48 $this->$name[$this->attrs[$name][$i]]= $this->attrs[$name][$i];
49 }
50 }
51 }
53 /* Always is account... */
54 $this->is_account= TRUE;
55 }
58 function execute()
59 {
60 /* Fill templating stuff */
61 $smarty= get_smarty();
63 $smarty->assign("staticAddress", "");
65 /* Here we add a new entry */
66 if(isset($_POST['NewNfsAdd']) && $_POST['NewNfsExport'] != "") {
67 $this->goExportEntry[$_POST['NewNfsExport']]= $_POST['NewNfsExport'];
68 asort($this->goExportEntry);
69 }
71 /* Deleting an Entry, is a bit more complicated than adding one*/
72 if(isset($_POST['DelNfsEnt']) && isset($_POST['goExportEntry'])) {
73 foreach ($_POST['goExportEntry'] as $entry){
74 if (isset($this->goExportEntry[$entry])){
75 unset($this->goExportEntry[$entry]);
76 }
77 }
78 }
80 /* Here we add a new entry */
81 if(isset($_POST['NewNTPAdd']) && $_POST['NewNTPExport'] != "") {
82 $this->goTimeSource[$_POST['NewNTPExport']]= $_POST['NewNTPExport'];
83 asort($this->goTimeSource);
84 }
86 /* Deleting an Entry, is a bit more complicated than adding one*/
87 if(isset($_POST['DelNTPEnt'])) {
88 foreach ($_POST['goTimeSource'] as $entry){
89 if (isset($this->goTimeSource[$entry])){
90 unset($this->goTimeSource[$entry]);
91 }
92 }
93 }
95 /* Attributes */
96 foreach ($this->attributes as $attr){
97 $smarty->assign("$attr", $this->$attr);
98 $smarty->assign("$attr"."ACL", chkacl($this->acl, $attr));
99 $smarty->assign($attr."State","");
100 }
102 /* Arrays */
103 foreach (array("goTimeSource", "goExportEntry") as $name){
104 $smarty->assign("$name", $this->$name);
105 $smarty->assign("$name"."ACL", chkacl($this->acl, $name));
106 $smarty->assign($name."State","");
107 }
109 /* Classes... */
110 foreach ($this->additionaloc as $oc => $dummy){
111 if (isset($this->objectclasses[$oc])){
112 $smarty->assign("$oc", "checked");
113 $smarty->assign("$oc"."State", "");
114 $smarty->assign("$oc"."ACL", chkacl($this->acl, $oc));
116 } else {
117 $smarty->assign("$oc", "");
118 $smarty->assign("$oc"."ACL", chkacl($this->acl, $oc));
119 $smarty->assign("$oc"."State", "disabled");
120 }
121 }
123 /* Different handling for checkbox */
124 if($this->goXdmcpIsEnabled == "true"){
125 $smarty->assign("goXdmcpIsEnabled","checked");
126 } else {
127 $smarty->assign("goXdmcpIsEnabled","");
128 }
130 return($smarty->fetch (get_template_path('servservice.tpl', TRUE)));
131 }
134 function remove_from_parent()
135 {
136 /* This cannot be removed... */
137 }
140 /* Save data to object */
141 function save_object()
142 {
143 if (isset($_POST['servicetab'])){
144 plugin::save_object();
146 /* Save checkbox state */
147 foreach ($this->additionaloc as $oc => $dummy){
148 if (chkacl($this->acl, $oc) == ""){
149 if (isset($_POST[$oc]) && $_POST[$oc] == '1'){
150 $this->objectclasses[$oc]= $oc;
151 } else {
152 unset($this->objectclasses[$oc]);
153 }
154 }
155 }
157 /* Save xdmcp is enabled flag */
158 if (isset($_POST['goXdmcpIsEnabled'])){
159 $this->goXdmcpIsEnabled= "true";
160 } else {
161 $this->goXdmcpIsEnabled= "false";
162 }
164 }
165 }
168 /* Check supplied data */
169 function check()
170 {
171 $message= array();
173 return ($message);
174 }
177 /* Save to LDAP */
178 function save()
179 {
181 /* Normalize lazy objectclass arrays */
182 $objectclasses= array();
183 foreach($this->objectclasses as $oc){
184 $objectclasses[]= $oc;
185 }
186 $this->objectclasses= $objectclasses;
188 plugin::save();
190 /* Normalize objectclasses */
191 $this->attrs['objectClass']= $this->objectclasses;
193 /* Remove illegal attributes */
194 foreach ($this->additionaloc as $oc => $attrs){
195 if (!in_array($oc, $this->objectclasses)){
196 foreach ($attrs as $attr){
197 $this->attrs[$attr]= array();
198 }
199 }
200 }
202 /* Write to LDAP */
203 $ldap= $this->config->get_ldap_link();
204 $ldap->cd($this->dn);
205 $ldap->modify($this->attrs);
206 show_ldap_error($ldap->get_error());
208 /* Optionally execute a command after we're done */
209 if ($this->initially_was_account == $this->is_account){
210 if ($this->is_modified){
211 $this->handle_post_events("mofify");
212 }
213 } else {
214 $this->handle_post_events("add");
215 }
216 }
218 }
220 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
221 ?>