Code

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