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