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