Code

Created trunk inside of 2.6-lhm
[gosa.git] / trunk / gosa-plugins / goto / admin / systems / goto / class_terminalInfo.inc
1 <?php
3 class terminfo extends plugin
4 {
5   /* Generic terminal attributes */
6   var $ghCpuType= "-";
7   var $ghMemSize= "-";
8   var $macAddress= "-";
9   var $ghUsbSupport= "-";
10   var $ghNetNic= array();
11   var $ghIdeDev= array();
12   var $ghScsiDev= array();
13   var $ghGfxAdapter= "-";
14   var $ghSoundAdapter= "-";
15   var $ghInventoryNumber= "-";
16   var $gotoLastUser= "-";
17   var $gotoFloppyEnable= "";
18   var $gotoCdromEnable= "";
20   /* Needed values and lists */
21   var $base= "";
22   var $cn= "";
23   var $view_logged = FALSE;
25   /* attribute list for save action */
26   var $ignore_account= TRUE;
27   var $attributes= array("cn", "gotoMode", "gotoTerminalPath", "gotoFloppyEnable",
28       "gotoCdromEnable", "ghInventoryNumber",
29       "gotoSwapServer", "gotoSyslogServer", "gotoNtpServer",
30       "ghCpuType", "ghMemSize", "macAddress", "ghUsbSupport",
31       "ghGfxAdapter", "ghSoundAdapter", "gotoLastUser");
32   var $objectclasses= array("GOhard");
34   function terminfo (&$config, $dn= NULL, $parent= NULL)
35   {
36     plugin::plugin ($config,$dn);
38     /* Read arrays */
39     foreach (array("ghNetNic", "ghIdeDev", "ghScsiDev") as $val){
40       if (!isset($this->attrs[$val])){
41         continue;
42       }
43       for ($i= 0; $i<$this->attrs[$val]['count']; $i++){
44         array_push($this->$val, $this->attrs[$val][$i]);
45       }
46     }
48     /* Fix USB entry */
49     if ($this->ghUsbSupport == "true"){
50       $this->ghUsbSupport= _("present");
51     }
52   }
55   function execute()
56   {
57     /* Call parent execute */
58     plugin::execute();
60     if($this->is_account && !$this->view_logged){
61       $this->view_logged = TRUE;
62       new log("view","terminal/".get_class($this),$this->dn);
63     }
65     /* Do we represent a valid terminal? */
66     if (!$this->is_account && $this->parent === NULL){
67       return("<img alt=\"\" src=\"images/small-error.png\" align=middle>&nbsp;<b>".
68         msgPool::noValidExtension(_("terminal"))."</b>");
69     }
71     $smarty= get_smarty();
72     $display= "";
73     $smarty->assign("ACL",TRUE);
74     if(!preg_match("/r/",$this->getacl(""))){
75       $smarty->assign("ACL",FALSE);
76     }elseif(!is_callable("snmpget")){
77       msg_dialog::display(_("Configuration error"), msgPool::missingext("snmp"), ERROR_DIALOG);
79       $smarty->assign("load", progressbar(0,100,15,true));
80       $smarty->assign("mem", progressbar(0,100,15,true));
81       $smarty->assign("swap", progressbar(0,100,15,true));
82       foreach(array("uptime", "sshd", "X", "saned", "artsd", "cupsd","status","ghNetNic", "ghIdeDev", "ghScsiDev","FloppyDevice", "CdromDevice","active") as $val){
83         $smarty->assign("$val", "<i>"._("unknown status")."</i>");
84       }
87       $display ="";
88     }else
89       /* Default entry? */
90       if ($this->cn == "default"){
91         $display= "<div style='height:150px;'><br><b>";
92         $display.= _("This is a virtual terminal which has no properties to show here.");
93         $display.= "</b></div>";
94       } else {
96         /* Get template object */
97         $smarty->assign("staticAddress", "");
99         /* Prevent undefined variable .... */ 
100         $smarty->assign("load", progressbar(0,100,15,true));
101         $smarty->assign("mem", progressbar(0,100,15,true));
102         $smarty->assign("swap", progressbar(0,100,15,true));
104         /* Check if terminal is online */
105         if (gosaSupportDaemon::ping($this->macAddress)){
106           $smarty->assign("status", _("online"));
107           $smarty->assign("active", "true");
109           /* Fill data if we have snmp */
110           $host= $this->cn;
112           /* Use 'goto' as snmp community or the configured value from the config */
113           $community= 'goto';
114           $str= $this->config->search("terminfo", "SNMPCOMMUNITY", array('tabs'));
115           if(!empty($str)){
116             $community = $str;
117           }
119           /* Get memory informations */
120           if(!is_callable("snmpget")){
121             $MemFree = false;
122           }else{
123             $MemFree= @snmpget($host, $community, "UCD-SNMP-MIB::memory.memAvailReal.0");
124           }
125           if ($MemFree != FALSE){
126             $MemFree= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $MemFree);
127             $MemTotal= @snmpget($host, $community, "UCD-SNMP-MIB::memory.memTotalReal.0");
128             $MemTotal= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $MemTotal);
129             if ($MemTotal != 0){
130               $smarty->assign("mem",progressbar( (int)(($MemTotal - $MemFree)*100/$MemTotal),100,15,true));
131               ;
132             }
133             $SwapFree= @snmpget($host, $community, "UCD-SNMP-MIB::memory.memAvailSwap.0");
134             $SwapFree= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $SwapFree);
135             $SwapTotal= @snmpget($host, $community, "UCD-SNMP-MIB::memory.memTotalSwap.0");
136             $SwapTotal= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $SwapTotal);
137             if ($SwapTotal != 0){
138 #$smarty->assign("swap", (int)(($SwapTotal - $SwapFree)*100/$SwapTotal));
139               $smarty->assign("swap", progressbar(0,100,15,true));
140             }
142             /* Get system uptime */
143             $sysup= @snmpget($host, $community, "SNMPv2-MIB::sysUpTime.0");
144             $smarty->assign("uptime", preg_replace('/^.* ([0-9:]+)\..*$/', '\\1', $sysup));
146             /* Get system load */
147             $sysload= @snmpget($host, $community, "UCD-SNMP-MIB::laLoad.2");
148             $sysload= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $sysload);
150             $smarty->assign("load", progressbar($sysload*100,100,15,true));
152             /* Get status for key processes */
153             $processes= @snmpwalk($host, $community, "UCD-SNMP-MIB::prNames");
154             $check4= array("sshd", "cupsd", "artsd", "X", "saned");
155             foreach ($check4 as $pname){
156               $eflag= -1;
157               foreach ($processes as $key => $val){
158                 $process= preg_replace('/^.*[:=] (.*)$/', '\\1', $val);
159                 if ($process == $pname){
160                   $index= preg_replace('/^.*\.([0-9]+) [:=] .*$/', '\\1', $val);
161                   $res= @snmpget($host, $community, "UCD-SNMP-MIB::prErrorFlag.$index");
162                   $eflag= preg_replace('/^.*[:=] /', '', $res);
163                   break;
164                 }
165               }
166               switch ($eflag){
167                 case 0:
168                   $smarty->assign("$pname", "<img alt=\""._("running")."\" src=\"images/true.png\">");
169                   break;
170                 case 1:
171                   $smarty->assign("$pname", "<img alt=\""._("not running")."\" src=\"images/false.png\">");
172                   break;
173                 default:
174                   $smarty->assign("$pname", _("not defined"));
175               }
176             }
177           } else {
178             foreach(array("uptime", "sshd", "X", "saned", "artsd", "cupsd") as $val){
179               $smarty->assign("$val", "<i>"._("unknown status")."</i>");
180             }
181           }
182           /* Check for mounted partitions (show max 8 partitions) */
183           $partitions= "";
184           for ($n= 1; $n<9; $n++){
185             $device= @snmpget($host, $community, "UCD-SNMP-MIB::dskDevice.$n");
186             if ($device == ""){
187               break;
188             }
189             $device= preg_replace('/^STRING: */', '', $device);
190             $usage= @snmpget($host, $community, "UCD-SNMP-MIB::dskPercent.$n");
191             $usage= preg_replace('/^INTEGER: */', '', $usage);
192             $partitions.= "<tr><td><b>$device</b></td><td>".progressbar($usage,100,16,true)."</td></tr>\n";
193           }
194           $smarty->assign("partitions", $partitions);
195         } else {
196           $smarty->assign("status", _("offline"));
197           $smarty->assign("active", "false");
198         }
200         /* Set floppy and cdrom status */
201         foreach(array("Floppy", "Cdrom") as $val){
202           $name= "goto".$val."Enable";
203           if ($this->$name == "YES"){
204             $status= _("present");
205           } else {
206             $status= "-";
207           }
208           $smarty->assign($val."Device", $status);
209         }
211         /* Show main page */
212         foreach(array("ghNetNic", "ghIdeDev", "ghScsiDev") as $val){
213           if (!count($this->$val)){
214             $this->$val= "-";
215           }
216           $smarty->assign($val, $this->$val);
217         }
218       }
219       foreach(array("ghCpuType", "ghMemSize", "macAddress", "ghUsbSupport",
220             "ghGfxAdapter", "ghSoundAdapter", "gotoLastUser", "ghInventoryNumber") as $val){
222         $smarty->assign($val, $this->$val);
223       }
224       $display= $smarty->fetch (get_template_path('info.tpl', TRUE, dirname(__FILE__)));
226     return ($display);
227   }
229   function remove_from_parent()
230   {
231   }
234   /* Save data to object */
235   function save_object()
236   {
237     plugin::save_object();
238   }
241   /* Save to LDAP */
242   function save()
243   {
244   }
247   /* Return plugin informations for acl handling */
248   static function plInfo()
249   {
250     return (array(
251           "plShortName"   => _("System info"),
252           "plDescription" => _("System informations"),
253           "plSelfModify"  => FALSE,
254           "plDepends"     => array(),
255           "plPriority"    => 33,
256           "plSection"     => array("administration"),
257           "plCategory"    => array("workstation","server","terminal"),
258           "plProvidedAcls"=> array()
259             ));
260   }
263 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
264 ?>