35b001d341b8df2b240800f57172b28767e699f6
1 <?php
3 class termgeneric extends plugin
4 {
5 /* CLI vars */
6 var $cli_summary= "Manage terminal base 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 /* Generic terminal attributes */
11 var $gotoMode= "disabled";
12 var $gotoTerminalPath= "";
13 var $gotoSwapServer= "";
14 var $gotoSyslogServer= "";
15 var $gotoNtpServer= array();
16 var $gotoSndModule= "";
17 var $gotoFloppyEnable= "";
18 var $gotoCdromEnable= "";
19 var $ghCpuType= "-";
20 var $ghMemSize= "-";
21 var $ghUsbSupport= "-";
22 var $ghNetNic= array();
23 var $ghIdeDev= array();
24 var $ghScsiDev= array();
25 var $ghGfxAdapter= "-";
26 var $ghSoundAdapter= "-";
27 var $gotoLastUser= "-";
28 var $netConfigDNS;
29 /* Needed values and lists */
30 var $base= "";
31 var $cn= "";
32 var $orig_dn= "";
34 /* Plugin side filled */
35 var $modes= array();
37 /* attribute list for save action */
38 var $ignore_account= TRUE;
39 var $attributes= array("gotoMode", "gotoTerminalPath",
40 "gotoSwapServer", "gotoSyslogServer", "gotoNtpServer",
41 "gotoFloppyEnable", "gotoCdromEnable", "cn", "gotoSndModule",
42 "ghCpuType", "ghMemSize","ghUsbSupport",
43 "ghGfxAdapter", "ghSoundAdapter", "gotoLastUser");
44 var $objectclasses= array("top", "gotoTerminal", "GOhard");
46 function termgeneric ($config, $dn= NULL)
47 {
48 plugin::plugin ($config, $dn);
49 $this->netConfigDNS = new termDNS($this->config,$this->dn,$this->objectclasses);
50 /* Read arrays */
51 foreach (array("ghNetNic", "ghIdeDev", "ghScsiDev") as $val){
52 if (!isset($this->attrs[$val])){
53 continue;
54 }
55 for ($i= 0; $i<$this->attrs[$val]['count']; $i++){
56 array_push($this->$val, $this->attrs[$val][$i]);
57 }
58 }
60 /* Create used ntp server array */
61 $this->gotoNtpServer= array();
62 if(isset($this->attrs['gotoNtpServer'])){
63 unset($this->attrs['gotoNtpServer']['count']);
64 foreach($this->attrs['gotoNtpServer'] as $server){
65 $this->gotoNtpServer[$server] = $server;
66 }
67 }
69 $this->modes["disabled"]= _("disabled");
70 $this->modes["text"]= _("text");
71 $this->modes["graphic"]= _("graphic");
73 /* Set base */
74 if ($this->dn == "new"){
75 $ui= get_userinfo();
76 $this->base= dn2base($ui->dn);
77 } else {
78 $this->base= preg_replace ("/^[^,]+,[^,]+,[^,]+,/", "", $this->dn);
79 }
81 $this->orig_dn= $this->dn;
82 }
84 function execute()
85 {
86 /* Call parent execute */
87 plugin::execute();
89 /* Do we need to flip is_account state? */
90 if (isset($_POST['modify_state'])){
91 $this->is_account= !$this->is_account;
92 }
94 if (isset($_POST['action'])){
95 switch($_POST['saction']){
96 case 'wake':
97 $cmd= search_config($this->config->data['TABS'], "termgeneric", "WAKECMD");
98 if ($cmd == ""){
99 print_red(_("No WAKECMD definition found in your gosa.conf"));
100 } else {
101 exec ($cmd." ".$this->netConfigDNS->macAddress, $dummy, $retval);
102 if ($retval != 0){
103 print_red(sprintf(_("Execution of '%s' failed!"), $cmd));
104 }
105 }
106 break;
108 case 'reboot':
109 $cmd= search_config($this->config->data['TABS'], "termgeneric", "REBOOTCMD");
110 if ($cmd == ""){
111 print_red(_("No REBOOTCMD definition found in your gosa.conf"));
112 } else {
113 exec ($cmd." ".$this->cn, $dummy, $retval);
114 if ($retval != 0){
115 print_red(sprintf(_("Execution of '%s' failed!"), $cmd));
116 }
117 }
118 break;
120 case 'halt':
121 $cmd= search_config($this->config->data['TABS'], "termgeneric", "HALTCMD");
122 if ($cmd == ""){
123 print_red(_("No HALTCMD definition found in your gosa.conf"));
124 } else {
125 exec ($cmd." ".$this->cn, $dummy, $retval);
126 if ($retval != 0){
127 print_red(sprintf(_("Execution of '%s' failed!"), $cmd));
128 }
129 }
130 break;
131 }
132 }
134 /* Base select dialog */
135 $once = true;
136 foreach($_POST as $name => $value){
137 if(preg_match("/^chooseBase/",$name) && $once){
138 $once = false;
139 $this->dialog = new baseSelectDialog($this->config);
140 $this->dialog->setCurrentBase($this->base);
141 }
142 }
144 /* Dialog handling */
145 if(is_object($this->dialog)){
146 /* Must be called before save_object */
147 $this->dialog->save_object();
149 if($this->dialog->isClosed()){
150 $this->dialog = false;
151 }elseif($this->dialog->isSelected()){
152 $this->base = $this->dialog->isSelected();
153 $this->dialog= false;
154 }else{
155 return($this->dialog->execute());
156 }
157 }
159 /* Do we represent a valid terminal? */
160 if (!$this->is_account && $this->parent == NULL){
161 $display= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
162 _("This 'dn' has no terminal features.")."</b>";
163 return($display);
164 }
166 if((isset($_POST['addNtpServer'])) && (isset($_POST['gotoNtpServers']))){
167 $this->gotoNtpServer[$_POST['gotoNtpServers']] = $_POST['gotoNtpServers'];
168 }
170 if((isset($_POST['delNtpServer'])) && (isset($_POST['gotoNtpServerSelected']))){
171 foreach($_POST['gotoNtpServerSelected'] as $name){
172 unset($this->gotoNtpServer[$name]);
173 }
174 if(count($this->gotoNtpServer) == 0){
175 $this->gotoNtpServer['default'] = "default";
176 }
177 }
180 /* Fill templating stuff */
181 $smarty= get_smarty();
182 $smarty->assign("cn", $this->cn);
183 $smarty->assign("staticAddress", "");
185 $smarty->assign("bases", $this->config->idepartments);
187 /* Check if terminal is online */
188 $query= "fping -q -r 1 -t 500 ".$this->cn;
189 exec ($query, $dummy, $retval);
191 /* Offline */
192 if ($retval == 0){
193 $smarty->assign("actions", array("halt" => _("Switch off"), "reboot" => _("Reboot")));
194 } else {
195 $smarty->assign("actions", array("wake" => _("Wake up")));
196 }
197 /* Arrays */
198 $smarty->assign("modes", $this->modes);
200 $tmp2 = array();
201 foreach($this->config->data['SERVERS']['NFS'] as $server){
202 if($server != "default"){
203 $tmp = split("\|",$server);
204 $tmp3= split(":",$tmp[0]);
206 $servername = $tmp3[0];
207 $nfsname = $tmp3[1];
209 $path ="";
210 if(isset($tmp[4])){
211 $path = $tmp[4];
212 }
214 $tmp2[$servername.":".$path]= $servername.":".$path;
215 }else{
216 $tmp2[$server]=$server;
217 }
218 }
220 $smarty->assign("nfsservers", $tmp2);
221 $smarty->assign("syslogservers", $this->config->data['SERVERS']['SYSLOG']);
222 $smarty->assign("ntpservers", $this->config->data['SERVERS']['NTP']);
224 /* Variables */
225 foreach(array("base", "gotoMode", "gotoTerminalPath", "gotoSwapServer",
226 "gotoSyslogServer", "gotoNtpServer") as $val){
228 $smarty->assign($val."_select", $this->$val);
229 $smarty->assign($val."ACL", chkacl($this->acl, $val));
230 }
232 /* Show main page */
233 $smarty->assign("netconfig", $this->netConfigDNS->execute());
234 $smarty->assign("actionACL", chkacl($this->acl, 'action'));
235 return($smarty->fetch (get_template_path('terminal.tpl', TRUE)));
236 }
238 function remove_from_parent()
239 {
241 $ldap= $this->config->get_ldap_link();
242 $ldap->cd($this->dn);
243 $ldap->cat($this->dn);
244 if($ldap->count()){
245 $this->netConfigDNS->remove_from_parent();
246 $ldap->rmDir($this->dn);
247 show_ldap_error($ldap->get_error());
249 /* Optionally execute a command after we're done */
250 $this->handle_post_events("remove");
252 /* Delete references to object groups */
253 $ldap->cd ($this->config->current['BASE']);
254 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
255 while ($ldap->fetch()){
256 $og= new ogroup($this->config, $ldap->getDN());
257 unset($og->member[$this->dn]);
258 $og->save ();
259 }
260 }
261 }
264 /* Save data to object */
265 function save_object()
266 {
267 plugin::save_object();
268 $this->netConfigDNS->save_object();
269 /* Save base, since this is no LDAP attribute */
270 if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){
271 $this->base= $_POST['base'];
272 }
274 /* Save terminal path to parent since it is used by termstartup, too */
275 $this->parent->by_object['termstartup']->gotoTerminalPath=
276 $this->gotoTerminalPath;
277 }
280 /* Check supplied data */
281 function check()
282 {
283 /* Call common method to give check the hook */
284 $message= plugin::check();
285 $message= array_merge($message, $this->netConfigDNS->check());
287 /* Permissions for that base? */
288 $this->dn= "cn=".$this->cn."ou=terminals,ou=systems,".$this->base;
290 $ui= get_userinfo();
291 $acl= get_permissions ($this->dn, $ui->subtreeACL);
292 $acl= get_module_permission($acl, "group", $this->dn);
293 if (chkacl($acl, "create") != ""){
294 $message[]= _("You have no permissions to create a terminal on this 'Base'.");
295 }
297 if ($this->cn == "" && chkacl ($this->acl, "cn") == ""){
298 $message[]= _("The required field 'Terminal name' is not set.");
299 }
301 if ($this->orig_dn == 'new'){
302 $ldap= $this->config->get_ldap_link();
303 $ldap->cd ($this->base);
304 $ldap->search ("(&(objectClass=gotoTerminal)(cn=".$this->cn."))", array("cn"));
305 if ($ldap->count() != 0){
306 while ($attrs= $ldap->fetch()){
307 if (preg_match ("/,ou=incoming,/", $ldap->getDN())){
308 continue;
309 } else {
310 if ($attrs['dn'] != $this->orig_dn){
311 $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
312 break;
313 }
314 }
315 }
316 }
317 }
319 return ($message);
320 }
323 /* Save to LDAP */
324 function save()
325 {
326 plugin::save();
328 /* Strip out 'default' values */
329 foreach (array("gotoTerminalPath", "gotoSwapServer", "gotoSyslogServer") as $val){
331 if ($this->attrs[$val] == "default"){
332 $this->attrs[$val]= array();
333 }
334 }
336 /* Add missing arrays */
337 foreach (array("ghScsiDev", "ghIdeDev", "ghNetNic") as $val){
338 if (isset ($this->$val) && count ($this->$val) != 0){
339 $this->attrs["$val"]= $this->$val;
340 }
341 }
343 /* Remove all empty values */
344 if ($this->orig_dn == 'new'){
345 $attrs= array();
346 foreach ($this->attrs as $key => $val){
347 if (is_array($val) && count($val) == 0){
348 continue;
349 }
350 $attrs[$key]= $val;
351 }
352 $this->attrs= $attrs;
353 }
355 /* Write back to ldap */
356 $ldap= $this->config->get_ldap_link();
357 if ($this->orig_dn == 'new'){
358 $ldap->cd($this->config->current['BASE']);
359 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
360 $ldap->cd($this->dn);
361 $ldap->add($this->attrs);
362 $this->handle_post_events("add");
363 } else {
364 if ($this->orig_dn != $this->dn){
365 $this->move($this->orig_dn, $this->dn);
366 }
367 $ldap->cd($this->dn);
368 $this->cleanup();
369 $ldap->modify ($this->attrs);
371 $this->handle_post_events("modify");
372 }
373 $this->netConfigDNS->cn = $this->cn;
374 $this->netConfigDNS->save($this->dn);
375 show_ldap_error($ldap->get_error());
377 /* Optionally execute a command after we're done */
378 $this->postcreate();
379 }
381 }
383 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
384 ?>