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 {
88 /* Get template object */
89 $smarty->assign("staticAddress", "");
91 /* Prevent undefined variable .... */
92 $smarty->assign("load", progressbar(0,100,15,true));
93 $smarty->assign("mem", progressbar(0,100,15,true));
94 $smarty->assign("swap", progressbar(0,100,15,true));
96 /* Check if terminal is online */
97 $query= "fping -q -r 1 -t 500 ".$this->cn;
98 exec ($query, $dummy, $retval);
100 if ($retval == 0){
101 $smarty->assign("status", _("online"));
102 $smarty->assign("active", "true");
104 /* Fill data if we have snmp */
105 $host= $this->cn;
107 /* Use goto as snmp community or the configured value from the config */
108 $community= 'goto';
109 $str = search_config($this->config->data['TABS'],"terminfo","SNMPCOMMUNITY");
110 if(!empty($str)){
111 $community = $str;
112 }
114 /* Get memory informations */
115 if(!is_callable("snmpget")){
116 $MemFree = false;
117 }else{
118 $MemFree= @snmpget($host, $community, "UCD-SNMP-MIB::memory.memAvailReal.0");
119 }
120 if ($MemFree != FALSE){
121 $MemFree= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $MemFree);
122 $MemTotal= @snmpget($host, $community, "UCD-SNMP-MIB::memory.memTotalReal.0");
123 $MemTotal= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $MemTotal);
124 if ($MemTotal != 0){
125 $smarty->assign("mem",progressbar( (int)(($MemTotal - $MemFree)*100/$MemTotal),100,15,true));
126 ;
127 }
128 $SwapFree= @snmpget($host, $community, "UCD-SNMP-MIB::memory.memAvailSwap.0");
129 $SwapFree= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $SwapFree);
130 $SwapTotal= @snmpget($host, $community, "UCD-SNMP-MIB::memory.memTotalSwap.0");
131 $SwapTotal= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $SwapTotal);
132 if ($SwapTotal != 0){
133 #$smarty->assign("swap", (int)(($SwapTotal - $SwapFree)*100/$SwapTotal));
134 $smarty->assign("swap", progressbar(0,100,15,true));
135 }
137 /* Get system uptime */
138 $sysup= @snmpget($host, $community, "SNMPv2-MIB::sysUpTime.0");
139 $smarty->assign("uptime", preg_replace('/^.* ([0-9:]+)\..*$/', '\\1', $sysup));
141 /* Get system load */
142 $sysload= @snmpget($host, $community, "UCD-SNMP-MIB::laLoad.2");
143 $sysload= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $sysload);
145 $smarty->assign("load", progressbar($sysload*100,100,15,true));
147 /* Get status for key processes */
148 $processes= @snmpwalk($host, $community, "UCD-SNMP-MIB::prNames");
149 $check4= array("sshd", "cupsd", "artsd", "X", "saned");
150 foreach ($check4 as $pname){
151 $eflag= -1;
152 foreach ($processes as $key => $val){
153 $process= preg_replace('/^.*[:=] (.*)$/', '\\1', $val);
154 if ($process == $pname){
155 $index= preg_replace('/^.*\.([0-9]+) [:=] .*$/', '\\1', $val);
156 $res= @snmpget($host, $community, "UCD-SNMP-MIB::prErrorFlag.$index");
157 $eflag= preg_replace('/^.*[:=] /', '', $res);
158 break;
159 }
160 }
161 switch ($eflag){
162 case 0:
163 $smarty->assign("$pname", "<img alt=\""._("running")."\" src=\"images/true.png\">");
164 break;
165 case 1:
166 $smarty->assign("$pname", "<img alt=\""._("not running")."\" src=\"images/false.png\">");
167 break;
168 default:
169 $smarty->assign("$pname", _("not defined"));
170 }
171 }
172 } else {
173 foreach(array("uptime", "sshd", "X", "saned", "artsd", "cupsd") as $val){
174 $smarty->assign("$val", "<i>"._("unknown status")."</i>");
175 }
176 }
177 /* Check for mounted partitions (show max 8 partitions) */
178 $partitions= "";
179 for ($n= 1; $n<9; $n++){
180 $device= @snmpget($host, $community, "UCD-SNMP-MIB::dskDevice.$n");
181 if ($device == ""){
182 break;
183 }
184 $device= preg_replace('/^STRING: */', '', $device);
185 $usage= @snmpget($host, $community, "UCD-SNMP-MIB::dskPercent.$n");
186 $usage= preg_replace('/^INTEGER: */', '', $usage);
187 $partitions.= "<tr><td><b>$device</b></td><td>".progressbar($usage,100,16,true)."</td></tr>\n";
188 }
189 $smarty->assign("partitions", $partitions);
190 } else {
191 $smarty->assign("status", _("offline"));
192 $smarty->assign("active", "false");
193 }
195 /* Set floppy and cdrom status */
196 foreach(array("Floppy", "Cdrom") as $val){
197 $name= "goto".$val."Enable";
198 if ($this->$name == "YES"){
199 $status= _("present");
200 } else {
201 $status= "-";
202 }
203 $smarty->assign($val."Device", $status);
204 }
206 /* Show main page */
207 foreach(array("ghNetNic", "ghIdeDev", "ghScsiDev") as $val){
208 if (!count($this->$val)){
209 $this->$val= "-";
210 }
211 $smarty->assign($val, $this->$val);
212 }
213 }
214 foreach(array("ghCpuType", "ghMemSize", "macAddress", "ghUsbSupport",
215 "ghGfxAdapter", "ghSoundAdapter", "gotoLastUser", "ghInventoryNumber") as $val){
217 $smarty->assign($val, $this->$val);
218 }
219 $display= $smarty->fetch (get_template_path('info.tpl', TRUE));
221 return ($display);
222 }
224 function remove_from_parent()
225 {
226 }
229 /* Save data to object */
230 function save_object()
231 {
232 plugin::save_object();
233 }
236 /* Save to LDAP */
237 function save()
238 {
239 }
241 }
243 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
244 ?>