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