Code

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