ab32135f8dd27370177f1964d2db3a6672087ca0
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 /* 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 /* Default entry? */
67 if ($this->cn == "default"){
68 $display= "<div style='height:150px;'><br><b>";
69 $display.= _("This is a virtual terminal which has no properties to show here.");
70 $display.= "</b></div>";
71 } else {
72 /* Get template object */
73 $smarty= get_smarty();
74 $display= "";
76 $smarty->assign("staticAddress", "");
79 /* Prevent undefined variable .... */
80 $smarty->assign("load", progressbar(0,100,15));
81 $smarty->assign("mem", progressbar(0,100,15));
82 $smarty->assign("swap", progressbar(0,100,15));
84 /* Check if terminal is online */
85 $query= "fping -q -r 1 -t 500 ".$this->cn;
86 exec ($query, $dummy, $retval);
88 if ($retval == 0){
89 $smarty->assign("status", _("online"));
90 $smarty->assign("active", "true");
92 /* Fill data if we have snmp */
93 $host= $this->cn;
94 $community= 'goto';
96 /* Get memory informations */
97 $MemFree= @snmpget($host, $community, "UCD-SNMP-MIB::memory.memAvailReal.0");
98 if ($MemFree != FALSE){
99 $MemFree= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $MemFree);
100 $MemTotal= @snmpget($host, $community, "UCD-SNMP-MIB::memory.memTotalReal.0");
101 $MemTotal= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $MemTotal);
102 if ($MemTotal != 0){
103 $smarty->assign("mem", (int)(($MemTotal - $MemFree)*100/$MemTotal));
104 }
105 $SwapFree= @snmpget($host, $community, "UCD-SNMP-MIB::memory.memAvailSwap.0");
106 $SwapFree= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $SwapFree);
107 $SwapTotal= @snmpget($host, $community, "UCD-SNMP-MIB::memory.memTotalSwap.0");
108 $SwapTotal= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $SwapTotal);
109 if ($SwapTotal != 0){
110 #$smarty->assign("swap", (int)(($SwapTotal - $SwapFree)*100/$SwapTotal));
111 $smarty->assign("swap", 0);
112 }
114 /* Get system uptime */
115 $sysup= @snmpget($host, $community, "SNMPv2-MIB::sysUpTime.0");
116 $smarty->assign("uptime", preg_replace('/^.* ([0-9:]+)\..*$/', '\\1', $sysup));
118 /* Get system load */
119 $sysload= @snmpget($host, $community, "UCD-SNMP-MIB::laLoad.2");
120 $sysload= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $sysload);
122 $smarty->assign("load", progressbar($sysload*100,100,20));
124 /* Get status for key processes */
125 $processes= @snmpwalk($host, $community, "UCD-SNMP-MIB::prNames");
126 $check4= array("sshd", "cupsd", "artsd", "X", "saned");
127 foreach ($check4 as $pname){
128 $eflag= -1;
129 foreach ($processes as $key => $val){
130 $process= preg_replace('/^.*[:=] (.*)$/', '\\1', $val);
131 if ($process == $pname){
132 $index= preg_replace('/^.*\.([0-9]+) [:=] .*$/', '\\1', $val);
133 $res= @snmpget($host, $community, "UCD-SNMP-MIB::prErrorFlag.$index");
134 $eflag= preg_replace('/^.*[:=] /', '', $res);
135 break;
136 }
137 }
138 switch ($eflag){
139 case 0:
140 $smarty->assign("$pname", "<img alt=\""._("running")."\" src=\"images/true.png\">");
141 break;
142 case 1:
143 $smarty->assign("$pname", "<img alt=\""._("not running")."\" src=\"images/false.png\">");
144 break;
145 default:
146 $smarty->assign("$pname", _("not defined"));
147 }
148 }
149 } else {
150 foreach(array("uptime", "sshd", "X", "saned", "artsd", "cupsd") as $val){
151 $smarty->assign("$val", "<i>"._("unknown status")."</i>");
152 }
153 }
155 /* Check for mounted partitions (show max 8 partitions) */
156 $partitions= "";
157 for ($n= 1; $n<9; $n++){
158 $device= @snmpget($host, $community, "UCD-SNMP-MIB::dskDevice.$n");
159 if ($device == ""){
160 break;
161 }
162 $device= preg_replace('/^STRING: */', '', $device);
163 $usage= @snmpget($host, $community, "UCD-SNMP-MIB::dskPercent.$n");
164 $usage= preg_replace('/^INTEGER: */', '', $usage);
165 $partitions.= "<tr><td><b>$device</b></td><td>".progressbar($usage,100;16,true)."</td></tr>\n";
166 }
167 $smarty->assign("partitions", $partitions);
168 } else {
169 $smarty->assign("status", _("offline"));
170 $smarty->assign("active", "false");
171 }
173 /* Set floppy and cdrom status */
174 foreach(array("Floppy", "Cdrom") as $val){
175 $name= "goto".$val."Enable";
176 if ($this->$name == "YES"){
177 $status= _("present");
178 } else {
179 $status= "-";
180 }
181 $smarty->assign($val."Device", $status);
182 }
184 /* Show main page */
185 foreach(array("ghNetNic", "ghIdeDev", "ghScsiDev") as $val){
186 if (!count($this->$val)){
187 $this->$val= "-";
188 }
189 $smarty->assign($val, $this->$val);
190 }
191 foreach(array("ghCpuType", "ghMemSize", "macAddress", "ghUsbSupport",
192 "ghGfxAdapter", "ghSoundAdapter", "gotoLastUser", "ghInventoryNumber") as $val){
194 $smarty->assign($val, $this->$val);
195 }
196 $display= $smarty->fetch (get_template_path('info.tpl', TRUE));
197 }
199 return ($display);
200 }
202 function remove_from_parent()
203 {
204 $ldap= $this->config->get_ldap_link();
205 $ldap->rmdir($this->dn);
206 show_ldap_error($ldap->get_error());
207 }
210 /* Save data to object */
211 function save_object()
212 {
213 plugin::save_object();
214 }
218 /* Save to LDAP */
219 function save()
220 {
221 }
223 }
225 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
226 ?>