1 <?php
3 class terminfo extends plugin
4 {
5 /* CLI vars */
6 var $cli_summary= "Retrieve informations about terminals";
7 var $cli_description= "Some longer text\nfor help";
8 var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
10 /* Generic terminal attributes */
11 var $ghCpuType= "-";
12 var $ghMemSize= "-";
13 var $macAddress= "-";
14 var $ghUsbSupport= "-";
15 var $ghNetNic= array();
16 var $ghIdeDev= array();
17 var $ghScsiDev= array();
18 var $ghGfxAdapter= "-";
19 var $ghSoundAdapter= "-";
20 var $ghInventoryNumber= "-";
21 var $gotoLastUser= "-";
22 var $gotoFloppyEnable= "";
23 var $gotoCdromEnable= "";
25 /* Needed values and lists */
26 var $base= "";
27 var $cn= "";
28 var $view_logged = FALSE;
30 /* attribute list for save action */
31 var $ignore_account= TRUE;
32 var $attributes= array("cn", "gotoMode", "gotoTerminalPath", "gotoFloppyEnable",
33 "gotoCdromEnable", "ghInventoryNumber",
34 "gotoSwapServer", "gotoSyslogServer", "gotoNtpServer",
35 "ghCpuType", "ghMemSize", "macAddress", "ghUsbSupport",
36 "ghGfxAdapter", "ghSoundAdapter", "gotoLastUser");
37 var $objectclasses= array("GOhard");
39 function terminfo (&$config, $dn= NULL, $parent= NULL)
40 {
41 plugin::plugin ($config,$dn);
43 /* Read arrays */
44 foreach (array("ghNetNic", "ghIdeDev", "ghScsiDev") as $val){
45 if (!isset($this->attrs[$val])){
46 continue;
47 }
48 for ($i= 0; $i<$this->attrs[$val]['count']; $i++){
49 array_push($this->$val, $this->attrs[$val][$i]);
50 }
51 }
53 /* Fix USB entry */
54 if ($this->ghUsbSupport == "true"){
55 $this->ghUsbSupport= _("present");
56 }
57 }
60 function execute()
61 {
62 /* Call parent execute */
63 plugin::execute();
65 if($this->is_account && !$this->view_logged){
66 $this->view_logged = TRUE;
67 new log("view","terminal/".get_class($this),$this->dn);
68 }
70 /* Do we represent a valid terminal? */
71 if (!$this->is_account && $this->parent === NULL){
72 echo "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
73 _("This 'dn' has no terminal features.")."</b>";
74 return;
75 }
77 $smarty= get_smarty();
78 $display= "";
79 if(!is_callable("snmpget")){
80 print_red(_("There is no php snmp module installed, can't gather any informations."));
82 $smarty->assign("load", progressbar(0,100,15,true));
83 $smarty->assign("mem", progressbar(0,100,15,true));
84 $smarty->assign("swap", progressbar(0,100,15,true));
85 foreach(array("uptime", "sshd", "X", "saned", "artsd", "cupsd","status","ghNetNic", "ghIdeDev", "ghScsiDev","FloppyDevice", "CdromDevice","active") as $val){
86 $smarty->assign("$val", "<i>"._("unknown status")."</i>");
87 }
90 $display ="";
91 }else
92 /* Default entry? */
93 if ($this->cn == "default"){
94 $display= "<div style='height:150px;'><br><b>";
95 $display.= _("This is a virtual terminal which has no properties to show here.");
96 $display.= "</b></div>";
97 } else {
99 /* Get template object */
100 $smarty->assign("staticAddress", "");
102 /* Prevent undefined variable .... */
103 $smarty->assign("load", progressbar(0,100,15,true));
104 $smarty->assign("mem", progressbar(0,100,15,true));
105 $smarty->assign("swap", progressbar(0,100,15,true));
107 /* Check if terminal is online */
108 $query= "fping -q -r 1 -t 500 ".$this->cn;
109 exec ($query, $dummy, $retval);
111 if ($retval == 0){
112 $smarty->assign("status", _("online"));
113 $smarty->assign("active", "true");
115 /* Fill data if we have snmp */
116 $host= $this->cn;
118 /* Use 'goto' as snmp community or the configured value from the config */
119 $community= 'goto';
120 $str = search_config($this->config->data['TABS'],"terminfo","SNMPCOMMUNITY");
121 if(!empty($str)){
122 $community = $str;
123 }
125 /* Get memory informations */
126 if(!is_callable("snmpget")){
127 $MemFree = false;
128 }else{
129 $MemFree= @snmpget($host, $community, "UCD-SNMP-MIB::memory.memAvailReal.0");
130 }
131 if ($MemFree != FALSE){
132 $MemFree= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $MemFree);
133 $MemTotal= @snmpget($host, $community, "UCD-SNMP-MIB::memory.memTotalReal.0");
134 $MemTotal= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $MemTotal);
135 if ($MemTotal != 0){
136 $smarty->assign("mem",progressbar( (int)(($MemTotal - $MemFree)*100/$MemTotal),100,15,true));
137 ;
138 }
139 $SwapFree= @snmpget($host, $community, "UCD-SNMP-MIB::memory.memAvailSwap.0");
140 $SwapFree= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $SwapFree);
141 $SwapTotal= @snmpget($host, $community, "UCD-SNMP-MIB::memory.memTotalSwap.0");
142 $SwapTotal= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $SwapTotal);
143 if ($SwapTotal != 0){
144 #$smarty->assign("swap", (int)(($SwapTotal - $SwapFree)*100/$SwapTotal));
145 $smarty->assign("swap", progressbar(0,100,15,true));
146 }
148 /* Get system uptime */
149 $sysup= @snmpget($host, $community, "SNMPv2-MIB::sysUpTime.0");
150 $smarty->assign("uptime", preg_replace('/^.* ([0-9:]+)\..*$/', '\\1', $sysup));
152 /* Get system load */
153 $sysload= @snmpget($host, $community, "UCD-SNMP-MIB::laLoad.2");
154 $sysload= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $sysload);
156 $smarty->assign("load", progressbar($sysload*100,100,15,true));
158 /* Get status for key processes */
159 $processes= @snmpwalk($host, $community, "UCD-SNMP-MIB::prNames");
160 $check4= array("sshd", "cupsd", "artsd", "X", "saned");
161 foreach ($check4 as $pname){
162 $eflag= -1;
163 foreach ($processes as $key => $val){
164 $process= preg_replace('/^.*[:=] (.*)$/', '\\1', $val);
165 if ($process == $pname){
166 $index= preg_replace('/^.*\.([0-9]+) [:=] .*$/', '\\1', $val);
167 $res= @snmpget($host, $community, "UCD-SNMP-MIB::prErrorFlag.$index");
168 $eflag= preg_replace('/^.*[:=] /', '', $res);
169 break;
170 }
171 }
172 switch ($eflag){
173 case 0:
174 $smarty->assign("$pname", "<img alt=\""._("running")."\" src=\"images/true.png\">");
175 break;
176 case 1:
177 $smarty->assign("$pname", "<img alt=\""._("not running")."\" src=\"images/false.png\">");
178 break;
179 default:
180 $smarty->assign("$pname", _("not defined"));
181 }
182 }
183 } else {
184 foreach(array("uptime", "sshd", "X", "saned", "artsd", "cupsd") as $val){
185 $smarty->assign("$val", "<i>"._("unknown status")."</i>");
186 }
187 }
188 /* Check for mounted partitions (show max 8 partitions) */
189 $partitions= "";
190 for ($n= 1; $n<9; $n++){
191 $device= @snmpget($host, $community, "UCD-SNMP-MIB::dskDevice.$n");
192 if ($device == ""){
193 break;
194 }
195 $device= preg_replace('/^STRING: */', '', $device);
196 $usage= @snmpget($host, $community, "UCD-SNMP-MIB::dskPercent.$n");
197 $usage= preg_replace('/^INTEGER: */', '', $usage);
198 $partitions.= "<tr><td><b>$device</b></td><td>".progressbar($usage,100,16,true)."</td></tr>\n";
199 }
200 $smarty->assign("partitions", $partitions);
201 } else {
202 $smarty->assign("status", _("offline"));
203 $smarty->assign("active", "false");
204 }
206 /* Set floppy and cdrom status */
207 foreach(array("Floppy", "Cdrom") as $val){
208 $name= "goto".$val."Enable";
209 if ($this->$name == "YES"){
210 $status= _("present");
211 } else {
212 $status= "-";
213 }
214 $smarty->assign($val."Device", $status);
215 }
217 /* Show main page */
218 foreach(array("ghNetNic", "ghIdeDev", "ghScsiDev") as $val){
219 if (!count($this->$val)){
220 $this->$val= "-";
221 }
222 $smarty->assign($val, $this->$val);
223 }
224 }
225 foreach(array("ghCpuType", "ghMemSize", "macAddress", "ghUsbSupport",
226 "ghGfxAdapter", "ghSoundAdapter", "gotoLastUser", "ghInventoryNumber") as $val){
228 $smarty->assign($val, $this->$val);
229 }
230 $display= $smarty->fetch (get_template_path('info.tpl', TRUE, dirname(__FILE__)));
232 return ($display);
233 }
235 function remove_from_parent()
236 {
237 }
240 /* Save data to object */
241 function save_object()
242 {
243 plugin::save_object();
244 }
247 /* Save to LDAP */
248 function save()
249 {
250 }
252 }
254 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
255 ?>