Code

* Created "old" branch and moved stuff
[gosa.git] / branches / old / 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     if(!is_callable("snmpget")){
74       msg_dialog::display(_("Configuration error"), msgPool::missingext("snmp"), ERROR_DIALOG);
76       $smarty->assign("load", progressbar(0,100,15,true));
77       $smarty->assign("mem", progressbar(0,100,15,true));
78       $smarty->assign("swap", progressbar(0,100,15,true));
79       foreach(array("uptime", "sshd", "X", "saned", "artsd", "cupsd","status","ghNetNic", "ghIdeDev", "ghScsiDev","FloppyDevice", "CdromDevice","active") as $val){
80         $smarty->assign("$val", "<i>"._("unknown status")."</i>");
81       }
84       $display ="";
85     }else
86       /* Default entry? */
87       if ($this->cn == "default"){
88         $display= "<div style='height:150px;'><br><b>";
89         $display.= _("This is a virtual terminal which has no properties to show here.");
90         $display.= "</b></div>";
91       } else {
93         /* Get template object */
94         $smarty->assign("staticAddress", "");
96         /* Prevent undefined variable .... */ 
97         $smarty->assign("load", progressbar(0,100,15,true));
98         $smarty->assign("mem", progressbar(0,100,15,true));
99         $smarty->assign("swap", progressbar(0,100,15,true));
101         /* Check if terminal is online */
102         if (gosaSupportDaemon::ping($this->macAddress)){
103           $smarty->assign("status", _("online"));
104           $smarty->assign("active", "true");
106           /* Fill data if we have snmp */
107           $host= $this->cn;
109           /* Use 'goto' as snmp community or the configured value from the config */
110           $community= 'goto';
111           $str= $this->config->search("terminfo", "SNMPCOMMUNITY", array('tabs'));
112           if(!empty($str)){
113             $community = $str;
114           }
116           /* Get memory informations */
117           if(!is_callable("snmpget")){
118             $MemFree = false;
119           }else{
120             $MemFree= @snmpget($host, $community, "UCD-SNMP-MIB::memory.memAvailReal.0");
121           }
122           if ($MemFree != FALSE){
123             $MemFree= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $MemFree);
124             $MemTotal= @snmpget($host, $community, "UCD-SNMP-MIB::memory.memTotalReal.0");
125             $MemTotal= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $MemTotal);
126             if ($MemTotal != 0){
127               $smarty->assign("mem",progressbar( (int)(($MemTotal - $MemFree)*100/$MemTotal),100,15,true));
128               ;
129             }
130             $SwapFree= @snmpget($host, $community, "UCD-SNMP-MIB::memory.memAvailSwap.0");
131             $SwapFree= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $SwapFree);
132             $SwapTotal= @snmpget($host, $community, "UCD-SNMP-MIB::memory.memTotalSwap.0");
133             $SwapTotal= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $SwapTotal);
134             if ($SwapTotal != 0){
135 #$smarty->assign("swap", (int)(($SwapTotal - $SwapFree)*100/$SwapTotal));
136               $smarty->assign("swap", progressbar(0,100,15,true));
137             }
139             /* Get system uptime */
140             $sysup= @snmpget($host, $community, "SNMPv2-MIB::sysUpTime.0");
141             $smarty->assign("uptime", preg_replace('/^.* ([0-9:]+)\..*$/', '\\1', $sysup));
143             /* Get system load */
144             $sysload= @snmpget($host, $community, "UCD-SNMP-MIB::laLoad.2");
145             $sysload= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $sysload);
147             $smarty->assign("load", progressbar($sysload*100,100,15,true));
149             /* Get status for key processes */
150             $processes= @snmpwalk($host, $community, "UCD-SNMP-MIB::prNames");
151             $check4= array("sshd", "cupsd", "artsd", "X", "saned");
152             foreach ($check4 as $pname){
153               $eflag= -1;
154               foreach ($processes as $key => $val){
155                 $process= preg_replace('/^.*[:=] (.*)$/', '\\1', $val);
156                 if ($process == $pname){
157                   $index= preg_replace('/^.*\.([0-9]+) [:=] .*$/', '\\1', $val);
158                   $res= @snmpget($host, $community, "UCD-SNMP-MIB::prErrorFlag.$index");
159                   $eflag= preg_replace('/^.*[:=] /', '', $res);
160                   break;
161                 }
162               }
163               switch ($eflag){
164                 case 0:
165                   $smarty->assign("$pname", "<img alt=\""._("running")."\" src=\"images/true.png\">");
166                   break;
167                 case 1:
168                   $smarty->assign("$pname", "<img alt=\""._("not running")."\" src=\"images/false.png\">");
169                   break;
170                 default:
171                   $smarty->assign("$pname", _("not defined"));
172               }
173             }
174           } else {
175             foreach(array("uptime", "sshd", "X", "saned", "artsd", "cupsd") as $val){
176               $smarty->assign("$val", "<i>"._("unknown status")."</i>");
177             }
178           }
179           /* Check for mounted partitions (show max 8 partitions) */
180           $partitions= "";
181           for ($n= 1; $n<9; $n++){
182             $device= @snmpget($host, $community, "UCD-SNMP-MIB::dskDevice.$n");
183             if ($device == ""){
184               break;
185             }
186             $device= preg_replace('/^STRING: */', '', $device);
187             $usage= @snmpget($host, $community, "UCD-SNMP-MIB::dskPercent.$n");
188             $usage= preg_replace('/^INTEGER: */', '', $usage);
189             $partitions.= "<tr><td><b>$device</b></td><td>".progressbar($usage,100,16,true)."</td></tr>\n";
190           }
191           $smarty->assign("partitions", $partitions);
192         } else {
193           $smarty->assign("status", _("offline"));
194           $smarty->assign("active", "false");
195         }
197         /* Set floppy and cdrom status */
198         foreach(array("Floppy", "Cdrom") as $val){
199           $name= "goto".$val."Enable";
200           if ($this->$name == "YES"){
201             $status= _("present");
202           } else {
203             $status= "-";
204           }
205           $smarty->assign($val."Device", $status);
206         }
208         /* Show main page */
209         foreach(array("ghNetNic", "ghIdeDev", "ghScsiDev") as $val){
210           if (!count($this->$val)){
211             $this->$val= "-";
212           }
213           $smarty->assign($val, $this->$val);
214         }
215       }
216       foreach(array("ghCpuType", "ghMemSize", "macAddress", "ghUsbSupport",
217             "ghGfxAdapter", "ghSoundAdapter", "gotoLastUser", "ghInventoryNumber") as $val){
219         $smarty->assign($val, $this->$val);
220       }
221       $display= $smarty->fetch (get_template_path('info.tpl', TRUE, dirname(__FILE__)));
223     return ($display);
224   }
226   function remove_from_parent()
227   {
228   }
231   /* Save data to object */
232   function save_object()
233   {
234     plugin::save_object();
235   }
238   /* Save to LDAP */
239   function save()
240   {
241   }
245 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
246 ?>