Code

A little bit better.
[gosa.git] / plugins / admin / systems / class_terminalInfo.inc
1 <?php
2 class terminfo extends plugin
3 {
4   /* CLI vars */
5   var $cli_summary= "Retrieve informations about terminals";
6   var $cli_description= "Some longer text\nfor help";
7   var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
9   /* Generic terminal attributes */
10   var $ghCpuType= "-";
11   var $ghMemSize= "-";
12   var $macAddress= "-";
13   var $ghUsbSupport= "-";
14   var $ghNetNic= array();
15   var $ghIdeDev= array();
16   var $ghScsiDev= array();
17   var $ghGfxAdapter= "-";
18   var $ghSoundAdapter= "-";
19   var $ghInventoryNumber= "-";
20   var $gotoLastUser= "-";
21   var $gotoFloppyEnable= "";
22   var $gotoCdromEnable= "";
24   /* Needed values and lists */
25   var $base= "";
26   var $cn= "";
28   /* attribute list for save action */
29   var $ignore_account= TRUE;
30   var $attributes= array("cn", "gotoMode", "gotoTerminalPath", "gotoFloppyEnable",
31       "gotoCdromEnable", "ghInventoryNumber",
32       "gotoSwapServer", "gotoSyslogServer", "gotoNtpServer",
33       "ghCpuType", "ghMemSize", "macAddress", "ghUsbSupport",
34       "ghGfxAdapter", "ghSoundAdapter", "gotoLastUser");
35   var $objectclasses= array("GOhard");
37   function terminfo ($config, $dn= NULL)
38   {
39     plugin::plugin ($config, $dn);
41     /* Read arrays */
42     foreach (array("ghNetNic", "ghIdeDev", "ghScsiDev") as $val){
43       if (!isset($this->attrs[$val])){
44         continue;
45       }
46       for ($i= 0; $i<$this->attrs[$val]['count']; $i++){
47         array_push($this->$val, $this->attrs[$val][$i]);
48       }
49     }
51     /* Fix USB entry */
52     if ($this->ghUsbSupport == "true"){
53       $this->ghUsbSupport= _("present");
54     }
55   }
57   function execute()
58   {
59     /* Do we represent a valid terminal? */
60     if (!$this->is_account && $this->parent == NULL){
61       echo "<img alt=\"\" src=\"images/stop.png\" align=middle>&nbsp;<b>".
62         _("This 'dn' has no terminal features.")."</b>";
63       return;
64     }
66     /* Default entry? */
67     if ($this->cn == "default"){
68       $display= "<div style='height:150px;'><br><b>";
69       $display.= _("This is a virtual terminal which has no properties to show here.");
70       $display.= "</b></div>";
71     } else {
72       /* Get template object */
73       $smarty= get_smarty();
74       $display= "";
76       $smarty->assign("staticAddress", "");
77  
79       /* Prevent undefined variable .... */ 
80       $smarty->assign("load", progressbar(0,100,15,true));
81       $smarty->assign("mem", progressbar(0,100,15,true));
82       $smarty->assign("swap", progressbar(0,100,15,true));
83  
84       /* Check if terminal is online */
85       $query= "fping -q -r 1 -t 500 ".$this->cn;
86       exec ($query, $dummy, $retval);
88       if ($retval == 0){
89         $smarty->assign("status", _("online"));
90         $smarty->assign("active", "true");
92         /* Fill data if we have snmp */
93         $host= $this->cn;
94         $community= 'goto';
96         /* Get memory informations */
97         $MemFree= @snmpget($host, $community, "UCD-SNMP-MIB::memory.memAvailReal.0");
98         if ($MemFree != FALSE){
99           $MemFree= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $MemFree);
100           $MemTotal= @snmpget($host, $community, "UCD-SNMP-MIB::memory.memTotalReal.0");
101           $MemTotal= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $MemTotal);
102           if ($MemTotal != 0){
103             $smarty->assign("mem",progressbar( (int)(($MemTotal - $MemFree)*100/$MemTotal),100,15,true));
104           ;
105           }
106           $SwapFree= @snmpget($host, $community, "UCD-SNMP-MIB::memory.memAvailSwap.0");
107           $SwapFree= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $SwapFree);
108           $SwapTotal= @snmpget($host, $community, "UCD-SNMP-MIB::memory.memTotalSwap.0");
109           $SwapTotal= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $SwapTotal);
110           if ($SwapTotal != 0){
111 #$smarty->assign("swap", (int)(($SwapTotal - $SwapFree)*100/$SwapTotal));
112             $smarty->assign("swap", progressbar(0,100,15,true));
113           }
115           /* Get system uptime */
116           $sysup= @snmpget($host, $community, "SNMPv2-MIB::sysUpTime.0");
117           $smarty->assign("uptime", preg_replace('/^.* ([0-9:]+)\..*$/', '\\1', $sysup));
119           /* Get system load */
120           $sysload= @snmpget($host, $community, "UCD-SNMP-MIB::laLoad.2");
121           $sysload= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $sysload);
122           
123           $smarty->assign("load", progressbar($sysload*100,100,15,true));
125           /* Get status for key processes */
126           $processes= @snmpwalk($host, $community, "UCD-SNMP-MIB::prNames");
127           $check4= array("sshd", "cupsd", "artsd", "X", "saned");
128           foreach ($check4 as $pname){
129             $eflag= -1;
130             foreach ($processes as $key => $val){
131               $process= preg_replace('/^.*[:=] (.*)$/', '\\1', $val);
132               if ($process == $pname){
133                 $index= preg_replace('/^.*\.([0-9]+) [:=] .*$/', '\\1', $val);
134                 $res= @snmpget($host, $community, "UCD-SNMP-MIB::prErrorFlag.$index");
135                 $eflag= preg_replace('/^.*[:=] /', '', $res);
136                 break;
137               }
138             }
139             switch ($eflag){
140               case 0:
141                 $smarty->assign("$pname", "<img alt=\""._("running")."\" src=\"images/true.png\">");
142                 break;
143               case 1:
144                 $smarty->assign("$pname", "<img alt=\""._("not running")."\" src=\"images/false.png\">");
145                 break;
146               default:
147                 $smarty->assign("$pname", _("not defined"));
148             }
149           }
150         } else {
151           foreach(array("uptime", "sshd", "X", "saned", "artsd", "cupsd") as $val){
152             $smarty->assign("$val", "<i>"._("unknown status")."</i>");
153           }
154         }
156         /* Check for mounted partitions (show max 8 partitions) */
157         $partitions= "";
158         for ($n= 1; $n<9; $n++){
159           $device= @snmpget($host, $community, "UCD-SNMP-MIB::dskDevice.$n");
160           if ($device == ""){
161             break;
162           }
163           $device= preg_replace('/^STRING: */', '', $device);
164           $usage= @snmpget($host, $community, "UCD-SNMP-MIB::dskPercent.$n");
165           $usage= preg_replace('/^INTEGER: */', '', $usage);
166           $partitions.= "<tr><td><b>$device</b></td><td>".progressbar($usage,100,16,true)."</td></tr>\n";
167         }
168         $smarty->assign("partitions", $partitions);
169       } else {
170         $smarty->assign("status", _("offline"));
171         $smarty->assign("active", "false");
172       }
174       /* Set floppy and cdrom status */
175       foreach(array("Floppy", "Cdrom") as $val){
176         $name= "goto".$val."Enable";
177         if ($this->$name == "YES"){
178           $status= _("present");
179         } else {
180           $status= "-";
181         }
182         $smarty->assign($val."Device", $status);
183       }
185       /* Show main page */
186       foreach(array("ghNetNic", "ghIdeDev", "ghScsiDev") as $val){
187         if (!count($this->$val)){
188           $this->$val= "-";
189         }
190         $smarty->assign($val, $this->$val);
191       }
192       foreach(array("ghCpuType", "ghMemSize", "macAddress", "ghUsbSupport",
193             "ghGfxAdapter", "ghSoundAdapter", "gotoLastUser", "ghInventoryNumber") as $val){
195         $smarty->assign($val, $this->$val);
196       }
197       $display= $smarty->fetch (get_template_path('info.tpl', TRUE));
198     }
200     return ($display);
201   }
203   function remove_from_parent()
204   {
205     $ldap= $this->config->get_ldap_link();
206     $ldap->rmdir($this->dn);
207     show_ldap_error($ldap->get_error());
208   }
211   /* Save data to object */
212   function save_object()
213   {
214     plugin::save_object();
215   }
219   /* Save to LDAP */
220   function save()
221   {
222   }
226 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
227 ?>