Code

4b41bfbfdfd8603d1f49b7255881e2f0c0a5ca13
[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       /* Check if terminal is online */
77       $query= "fping -q -r 1 -t 500 ".$this->cn;
78       exec ($query, $dummy, $retval);
80       if ($retval == 0){
81         $smarty->assign("status", _("online"));
82         $smarty->assign("active", "true");
84         /* Fill data if we have snmp */
85         $host= $this->cn;
86         $community= 'goto';
88         /* Get memory informations */
89         $MemFree= @snmpget($host, $community, "UCD-SNMP-MIB::memory.memAvailReal.0");
90         if ($MemFree != FALSE){
91           $MemFree= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $MemFree);
92           $MemTotal= @snmpget($host, $community, "UCD-SNMP-MIB::memory.memTotalReal.0");
93           $MemTotal= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $MemTotal);
94           if ($MemTotal != 0){
95             $smarty->assign("mem", (int)(($MemTotal - $MemFree)*100/$MemTotal));
96           }
97           $SwapFree= @snmpget($host, $community, "UCD-SNMP-MIB::memory.memAvailSwap.0");
98           $SwapFree= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $SwapFree);
99           $SwapTotal= @snmpget($host, $community, "UCD-SNMP-MIB::memory.memTotalSwap.0");
100           $SwapTotal= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $SwapTotal);
101           if ($SwapTotal != 0){
102 #$smarty->assign("swap", (int)(($SwapTotal - $SwapFree)*100/$SwapTotal));
103             $smarty->assign("swap", 0);
104           }
106           /* Get system uptime */
107           $sysup= @snmpget($host, $community, "SNMPv2-MIB::sysUpTime.0");
108           $smarty->assign("uptime", preg_replace('/^.* ([0-9:]+)\..*$/', '\\1', $sysup));
110           /* Get system load */
111           $sysload= @snmpget($host, $community, "UCD-SNMP-MIB::laLoad.2");
112           $sysload= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $sysload);
113           $smarty->assign("load", $sysload*100);
115           /* Get status for key processes */
116           $processes= @snmpwalk($host, $community, "UCD-SNMP-MIB::prNames");
117           $check4= array("sshd", "cupsd", "artsd", "X", "saned");
118           foreach ($check4 as $pname){
119             $eflag= -1;
120             foreach ($processes as $key => $val){
121               $process= preg_replace('/^.*[:=] (.*)$/', '\\1', $val);
122               if ($process == $pname){
123                 $index= preg_replace('/^.*\.([0-9]+) [:=] .*$/', '\\1', $val);
124                 $res= @snmpget($host, $community, "UCD-SNMP-MIB::prErrorFlag.$index");
125                 $eflag= preg_replace('/^.*[:=] /', '', $res);
126                 break;
127               }
128             }
129             switch ($eflag){
130               case 0:
131                 $smarty->assign("$pname", "<img alt=\"\" alt=\""._("running")."\" src=\"images/true.png\">");
132                 break;
133               case 1:
134                 $smarty->assign("$pname", "<img alt=\"\" alt=\""._("not running")."\" src=\"images/false.png\">");
135                 break;
136               default:
137                 $smarty->assign("$pname", _("not defined"));
138             }
139           }
140         } else {
141           foreach(array("uptime", "sshd", "X", "saned", "artsd", "cupsd") as $val){
142             $smarty->assign("$val", "<i>"._("unknown status")."</i>");
143           }
144         }
146         /* Check for mounted partitions (show max 8 partitions) */
147         $partitions= "";
148         for ($n= 1; $n<9; $n++){
149           $device= @snmpget($host, $community, "UCD-SNMP-MIB::dskDevice.$n");
150           if ($device == ""){
151             break;
152           }
153           $device= preg_replace('/^STRING: */', '', $device);
154           $usage= @snmpget($host, $community, "UCD-SNMP-MIB::dskPercent.$n");
155           $usage= preg_replace('/^INTEGER: */', '', $usage);
156           $partitions.= "<tr><td><b>$device</b></td><td><img alt=\"\" src=\"progress.php?x=100&amp;y=16&amp;p=$usage\" align=\"middle\"></td></tr>\n";
157         }
158         $smarty->assign("partitions", $partitions);
159       } else {
160         $smarty->assign("status", _("offline"));
161         $smarty->assign("active", "false");
162       }
164       /* Set floppy and cdrom status */
165       foreach(array("Floppy", "Cdrom") as $val){
166         $name= "goto".$val."Enable";
167         if ($this->$name == "YES"){
168           $status= _("present");
169         } else {
170           $status= "-";
171         }
172         $smarty->assign($val."Device", $status);
173       }
175       /* Show main page */
176       foreach(array("ghNetNic", "ghIdeDev", "ghScsiDev") as $val){
177         if (!count($this->$val)){
178           $this->$val= "-";
179         }
180         $smarty->assign($val, $this->$val);
181       }
182       foreach(array("ghCpuType", "ghMemSize", "macAddress", "ghUsbSupport",
183             "ghGfxAdapter", "ghSoundAdapter", "gotoLastUser", "ghInventoryNumber") as $val){
185         $smarty->assign($val, $this->$val);
186       }
187       $display= $smarty->fetch (get_template_path('info.tpl', TRUE));
188     }
190     return ($display);
191   }
193   function remove_from_parent()
194   {
195     $ldap= $this->config->get_ldap_link();
196     $ldap->rmdir($this->dn);
197     show_ldap_error($ldap->get_error());
198   }
201   /* Save data to object */
202   function save_object()
203   {
204     plugin::save_object();
205   }
209   /* Save to LDAP */
210   function save()
211   {
212   }
216 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
217 ?>