Code

Large translation update
[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)
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();
63     return;
65     /* Do we represent a valid terminal? */
66     if (!$this->is_account && $this->parent == NULL){
67       echo "<img alt=\"\" src=\"images/stop.png\" align=middle>&nbsp;<b>".
68         _("This 'dn' has no terminal features.")."</b>";
69       return;
70     }
72     $smarty= get_smarty();
73     $display= "";
74     if(!is_callable("snmpget")){
75       print_red(_("There is no php snmp module installed, can't gather any informations."));
77       $smarty->assign("load", progressbar(0,100,15,true));
78       $smarty->assign("mem", progressbar(0,100,15,true));
79       $smarty->assign("swap", progressbar(0,100,15,true));
80       foreach(array("uptime", "sshd", "X", "saned", "artsd", "cupsd","status","ghNetNic", "ghIdeDev", "ghScsiDev","FloppyDevice", "CdromDevice","active") as $val){
81         $smarty->assign("$val", "<i>"._("unknown status")."</i>");
82       }
85       $display ="";
86     }else
87       /* Default entry? */
88       if ($this->cn == "default"){
89         $display= "<div style='height:150px;'><br><b>";
90         $display.= _("This is a virtual terminal which has no properties to show here.");
91         $display.= "</b></div>";
92       } else {
93         /* Get template object */
95         $smarty->assign("staticAddress", "");
98         /* Prevent undefined variable .... */ 
99         $smarty->assign("load", progressbar(0,100,15,true));
100         $smarty->assign("mem", progressbar(0,100,15,true));
101         $smarty->assign("swap", progressbar(0,100,15,true));
103         /* Check if terminal is online */
104         $query= "fping -q -r 1 -t 500 ".$this->cn;
105         exec ($query, $dummy, $retval);
107         if ($retval == 0){
108           $smarty->assign("status", _("online"));
109           $smarty->assign("active", "true");
111           /* Fill data if we have snmp */
112           $host= $this->cn;
113           $community= 'goto';
115           /* Get memory informations */
116           if(is_callable("snmpget")){
117             $MemFree = false;
118           }else{
119             $MemFree= @snmpget($host, $community, "UCD-SNMP-MIB::memory.memAvailReal.0");
120           }
121           if ($MemFree != FALSE){
122             $MemFree= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $MemFree);
123             $MemTotal= @snmpget($host, $community, "UCD-SNMP-MIB::memory.memTotalReal.0");
124             $MemTotal= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $MemTotal);
125             if ($MemTotal != 0){
126               $smarty->assign("mem",progressbar( (int)(($MemTotal - $MemFree)*100/$MemTotal),100,15,true));
127               ;
128             }
129             $SwapFree= @snmpget($host, $community, "UCD-SNMP-MIB::memory.memAvailSwap.0");
130             $SwapFree= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $SwapFree);
131             $SwapTotal= @snmpget($host, $community, "UCD-SNMP-MIB::memory.memTotalSwap.0");
132             $SwapTotal= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $SwapTotal);
133             if ($SwapTotal != 0){
134 #$smarty->assign("swap", (int)(($SwapTotal - $SwapFree)*100/$SwapTotal));
135               $smarty->assign("swap", progressbar(0,100,15,true));
136             }
138             /* Get system uptime */
139             $sysup= @snmpget($host, $community, "SNMPv2-MIB::sysUpTime.0");
140             $smarty->assign("uptime", preg_replace('/^.* ([0-9:]+)\..*$/', '\\1', $sysup));
142             /* Get system load */
143             $sysload= @snmpget($host, $community, "UCD-SNMP-MIB::laLoad.2");
144             $sysload= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $sysload);
146             $smarty->assign("load", progressbar($sysload*100,100,15,true));
148             /* Get status for key processes */
149             $processes= @snmpwalk($host, $community, "UCD-SNMP-MIB::prNames");
150             $check4= array("sshd", "cupsd", "artsd", "X", "saned");
151             foreach ($check4 as $pname){
152               $eflag= -1;
153               foreach ($processes as $key => $val){
154                 $process= preg_replace('/^.*[:=] (.*)$/', '\\1', $val);
155                 if ($process == $pname){
156                   $index= preg_replace('/^.*\.([0-9]+) [:=] .*$/', '\\1', $val);
157                   $res= @snmpget($host, $community, "UCD-SNMP-MIB::prErrorFlag.$index");
158                   $eflag= preg_replace('/^.*[:=] /', '', $res);
159                   break;
160                 }
161               }
162               switch ($eflag){
163                 case 0:
164                   $smarty->assign("$pname", "<img alt=\""._("running")."\" src=\"images/true.png\">");
165                   break;
166                 case 1:
167                   $smarty->assign("$pname", "<img alt=\""._("not running")."\" src=\"images/false.png\">");
168                   break;
169                 default:
170                   $smarty->assign("$pname", _("not defined"));
171               }
172             }
173           } else {
174             foreach(array("uptime", "sshd", "X", "saned", "artsd", "cupsd") as $val){
175               $smarty->assign("$val", "<i>"._("unknown status")."</i>");
176             }
177           }
178           /* Check for mounted partitions (show max 8 partitions) */
179           $partitions= "";
180           for ($n= 1; $n<9; $n++){
181             $device= @snmpget($host, $community, "UCD-SNMP-MIB::dskDevice.$n");
182             if ($device == ""){
183               break;
184             }
185             $device= preg_replace('/^STRING: */', '', $device);
186             $usage= @snmpget($host, $community, "UCD-SNMP-MIB::dskPercent.$n");
187             $usage= preg_replace('/^INTEGER: */', '', $usage);
188             $partitions.= "<tr><td><b>$device</b></td><td>".progressbar($usage,100,16,true)."</td></tr>\n";
189           }
190           $smarty->assign("partitions", $partitions);
191         } else {
192           $smarty->assign("status", _("offline"));
193           $smarty->assign("active", "false");
194         }
196         /* Set floppy and cdrom status */
197         foreach(array("Floppy", "Cdrom") as $val){
198           $name= "goto".$val."Enable";
199           if ($this->$name == "YES"){
200             $status= _("present");
201           } else {
202             $status= "-";
203           }
204           $smarty->assign($val."Device", $status);
205         }
207         /* Show main page */
208         foreach(array("ghNetNic", "ghIdeDev", "ghScsiDev") as $val){
209           if (!count($this->$val)){
210             $this->$val= "-";
211           }
212           $smarty->assign($val, $this->$val);
213         }
214       }
215       foreach(array("ghCpuType", "ghMemSize", "macAddress", "ghUsbSupport",
216             "ghGfxAdapter", "ghSoundAdapter", "gotoLastUser", "ghInventoryNumber") as $val){
218         $smarty->assign($val, $this->$val);
219       }
220       $display= $smarty->fetch (get_template_path('info.tpl', TRUE));
222     return ($display);
223   }
225   function remove_from_parent()
226   {
227   }
230   /* Save data to object */
231   function save_object()
232   {
233     plugin::save_object();
234   }
237   /* Save to LDAP */
238   function save()
239   {
240   }
244 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
245 ?>