Code

Added empty lines
[gosa.git] / plugins / admin / systems / class_terminalGeneric.inc
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= "";
16   var $gotoSndModule= "";
17   var $gotoFloppyEnable= "";
18   var $gotoCdromEnable= "";
19   var $ghCpuType= "-";
20   var $ghMemSize= "-";
21   var $macAddress= "";
22   var $ipHostNumber= "";
23   var $ghUsbSupport= "-";
24   var $ghNetNic= array();
25   var $ghIdeDev= array();
26   var $ghScsiDev= array();
27   var $ghGfxAdapter= "-";
28   var $ghSoundAdapter= "-";
29   var $gotoLastUser= "-";
31   /* Needed values and lists */
32   var $base= "";
33   var $cn= "";
34   var $orig_dn= "";
36   /* Plugin side filled */
37   var $modes= array();
39   /* attribute list for save action */
40   var $ignore_account= TRUE;
41   var $attributes= array("gotoMode", "gotoTerminalPath", "macAddress",
42       "gotoSwapServer", "gotoSyslogServer", "gotoNtpServer",
43       "gotoFloppyEnable", "gotoCdromEnable", "cn", "gotoSndModule",
44       "ghCpuType", "ghMemSize", "ipHostNumber", "ghUsbSupport",
45       "ghGfxAdapter", "ghSoundAdapter", "gotoLastUser");
46   var $objectclasses= array("top", "gotoTerminal", "GOhard");
48   function termgeneric ($config, $dn= NULL)
49   {
50     plugin::plugin ($config, $dn);
52     /* Read arrays */
53     foreach (array("ghNetNic", "ghIdeDev", "ghScsiDev") as $val){
54       if (!isset($this->attrs[$val])){
55         continue;
56       }
57       for ($i= 0; $i<$this->attrs[$val]['count']; $i++){
58         array_push($this->$val, $this->attrs[$val][$i]);
59       }
60     }
62     $this->modes["disabled"]= _("disabled");
63     $this->modes["text"]= _("text");
64     $this->modes["graphic"]= _("graphic");
66     /* Set base */
67     if ($this->dn == "new"){
68       $ui= get_userinfo();
69       $this->base= dn2base($ui->dn);
70     } else {
71       $this->base= preg_replace ("/^[^,]+,[^,]+,[^,]+,/", "", $this->dn);
72     }
74     $this->orig_dn= $this->dn;
75   }
77   function execute()
78   {
79         /* Call parent execute */
80         plugin::execute();
82     /* Do we need to flip is_account state? */
83     if (isset($_POST['modify_state'])){
84       $this->is_account= !$this->is_account;
85     }
87     if (isset($_POST['action'])){
88       switch($_POST['saction']){
89         case 'wake':
90           $cmd= search_config($this->config->data['TABS'], "termgeneric", "WAKECMD");
91           if ($cmd == ""){
92             print_red(_("No WAKECMD definition found in your gosa.conf"));
93           } else {
94             exec ($cmd." ".$this->macAddress, $dummy, $retval);
95             if ($retval != 0){
96               print_red(sprintf(_("Execution of '%s' failed!"), $cmd));
97             }
98           }
99           break;
101         case 'reboot':
102           $cmd= search_config($this->config->data['TABS'], "termgeneric", "REBOOTCMD");
103           if ($cmd == ""){
104             print_red(_("No REBOOTCMD definition found in your gosa.conf"));
105           } else {
106             exec ($cmd." ".$this->cn, $dummy, $retval);
107             if ($retval != 0){
108               print_red(sprintf(_("Execution of '%s' failed!"), $cmd));
109             }
110           }
111           break;
113         case 'halt':
114           $cmd= search_config($this->config->data['TABS'], "termgeneric", "HALTCMD");
115           if ($cmd == ""){
116             print_red(_("No HALTCMD definition found in your gosa.conf"));
117           } else {
118             exec ($cmd." ".$this->cn, $dummy, $retval);
119             if ($retval != 0){
120               print_red(sprintf(_("Execution of '%s' failed!"), $cmd));
121             }
122           }
123           break;
124       }
125     }
127     /* Do we represent a valid terminal? */
128     if (!$this->is_account && $this->parent == NULL){
129       $display= "<img alt=\"\" src=\"images/stop.png\" align=middle>&nbsp;<b>".
130         _("This 'dn' has no terminal features.")."</b>";
131       return($display);
132     }
134     /* Fill templating stuff */
135     $smarty= get_smarty();
136     $smarty->assign("cn", $this->cn);
137     $smarty->assign("staticAddress", "");
139     $smarty->assign("bases", $this->config->idepartments);
141     /* Check if terminal is online */
142     $query= "fping -q -r 1 -t 500 ".$this->cn;
143     exec ($query, $dummy, $retval);
145     /* Offline */
146     if ($retval == 0){
147       $smarty->assign("actions", array("halt" => _("Switch off"), "reboot" => _("Reboot")));
148     } else {
149       $smarty->assign("actions", array("wake" => _("Wake up")));
150     }
151     /* Arrays */
152     $smarty->assign("modes", $this->modes);
154     $tmp2 = array(); 
155     foreach($this->config->data['SERVERS']['NFS'] as $server){
156       if($server != "default"){
157         $tmp = split("\|",$server);
158         $tmp3= split(":",$tmp[0]);
160         $servername = $tmp3[0];
161         $nfsname    = $tmp3[1];  
163         $path ="";
164         if(isset($tmp[4])){
165           $path       = $tmp[4];  
166         }
168         $tmp2[$servername.":".$path]= $servername.":".$path; 
169       }else{
170         $tmp2[$server]=$server;
171       }
172     }
173   
174     $smarty->assign("nfsservers", $tmp2);
175     $smarty->assign("syslogservers", $this->config->data['SERVERS']['SYSLOG']);
176     $smarty->assign("ntpservers", $this->config->data['SERVERS']['NTP']);
178     /* Variables */
179     foreach(array("base", "gotoMode", "gotoTerminalPath", "gotoSwapServer",
180           "gotoSyslogServer", "gotoNtpServer") as $val){
182       $smarty->assign($val."_select", $this->$val);
183       $smarty->assign($val."ACL", chkacl($this->acl, $val));
184     }
185     $smarty->assign("ipHostNumber", $this->ipHostNumber);
186     $smarty->assign("macAddress", $this->macAddress);
188     /* Show main page */
189     $smarty->assign("netconfig", dirname(__FILE__)."/network.tpl");
190     $smarty->assign("actionACL", chkacl($this->acl, 'action'));
191     return($smarty->fetch (get_template_path('terminal.tpl', TRUE)));
192   }
194   function remove_from_parent()
195   {
196     $ldap= $this->config->get_ldap_link();
197     $ldap->rmdir($this->dn);
198     show_ldap_error($ldap->get_error());
200     /* Optionally execute a command after we're done */
201     $this->handle_post_events("remove");
203     /* Delete references to object groups */
204     $ldap->cd ($this->config->current['BASE']);
205     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
206     while ($ldap->fetch()){
207       $og= new ogroup($this->config, $ldap->getDN());
208       unset($og->member[$this->dn]);
209       $og->save ();
210     }
212   }
215   /* Save data to object */
216   function save_object()
217   {
218     plugin::save_object();
220     /* Save base, since this is no LDAP attribute */
221     if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){
222       $this->base= $_POST['base'];
223     }
225     /* Save terminal path to parent since it is used by termstartup, too */
226     $this->parent->by_object['termstartup']->gotoTerminalPath=
227       $this->gotoTerminalPath;
228   }
231   /* Check supplied data */
232   function check()
233   {
234     $message= array();
236     /* Permissions for that base? */
237     $this->dn= "cn=".$this->cn."ou=terminals,ou=systems,".$this->base;
239     $ui= get_userinfo();
240     $acl= get_permissions ($this->dn, $ui->subtreeACL);
241     $acl= get_module_permission($acl, "group", $this->dn);
242     if (chkacl($acl, "create") != ""){
243       $message[]= _("You have no permissions to create a terminal on this 'Base'.");
244     }
246     if ($this->cn == "" && chkacl ($this->acl, "cn") == ""){
247       $message[]= _("The required field 'Terminal name' is not set.");
248     }
250     if ($this->orig_dn == 'new'){
251       $ldap= $this->config->get_ldap_link();
252       $ldap->cd ($this->base);
253       $ldap->search ("(&(objectClass=gotoTerminal)(cn=".$this->cn."))", array("cn"));
254       if ($ldap->count() != 0){
255         while ($attrs= $ldap->fetch()){
256           if (preg_match ("/,ou=incoming,/", $ldap->getDN())){
257             continue;
258           } else {
259             if ($attrs['dn'] != $this->orig_dn){
260               $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
261               break;
262             }
263           }
264         }
265       }
266     }
268     return ($message);
269   }
272   /* Save to LDAP */
273   function save()
274   {
275     plugin::save();
277     /* Strip out 'default' values */
278     foreach (array("gotoTerminalPath", "gotoSwapServer", "gotoSyslogServer") as $val){
280       if ($this->attrs[$val] == "default"){
281         $this->attrs[$val]= array();
282       }
283     }
285     /* Add missing arrays */
286     foreach (array("ghScsiDev", "ghIdeDev", "ghNetNic") as $val){
287       if (isset ($this->$val) && count ($this->$val) != 0){
288         $this->attrs["$val"]= $this->$val;
289       }
290     }
292     /* Remove all empty values */
293     if ($this->orig_dn == 'new'){
294       $attrs= array();
295       foreach ($this->attrs as $key => $val){
296         if (is_array($val) && count($val) == 0){
297           continue;
298         }
299         $attrs[$key]= $val;
300       }
301       $this->attrs= $attrs;
302     }
304     /* Write back to ldap */
305     $ldap= $this->config->get_ldap_link();
306     if ($this->orig_dn == 'new'){
307       $ldap->cd($this->config->current['BASE']);
308       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
309       $ldap->cd($this->dn);
310       $ldap->add($this->attrs);
311       $this->handle_post_events("add");
312     } else {
313       if ($this->orig_dn != $this->dn){
314         $this->move($this->orig_dn, $this->dn);
315       }
316       $ldap->cd($this->dn);
317       $ldap->modify($this->attrs);
318       $this->handle_post_events("modify");
319     }
320     show_ldap_error($ldap->get_error());
322     /* Optionally execute a command after we're done */
323     $this->postcreate();
324   }
328 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
329 ?>