Code

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