cb96d63aba093c7bd2beb09e58ae95373060b5ef
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 $attributes= array("cn", "gotoMode", "gotoTerminalPath", "gotoFloppyEnable",
30 "gotoCdromEnable", "ghInventoryNumber",
31 "gotoSwapServer", "gotoSyslogServer", "gotoNtpServer",
32 "ghCpuType", "ghMemSize", "macAddress", "ghUsbSupport",
33 "ghGfxAdapter", "ghSoundAdapter", "gotoLastUser");
34 var $objectclasses= array("GOhard");
36 function terminfo ($config, $dn= NULL)
37 {
38 plugin::plugin ($config, $dn);
40 /* Read arrays */
41 foreach (array("ghNetNic", "ghIdeDev", "ghScsiDev") as $val){
42 if (!isset($this->attrs[$val])){
43 continue;
44 }
45 for ($i= 0; $i<$this->attrs[$val]['count']; $i++){
46 array_push($this->$val, $this->attrs[$val][$i]);
47 }
48 }
50 /* Fix USB entry */
51 if ($this->ghUsbSupport == "true"){
52 $this->ghUsbSupport= _("present");
53 }
54 }
56 function execute()
57 {
58 /* Do we represent a valid terminal? */
59 if (!$this->is_account && $this->parent == NULL){
60 echo "<img src=\"images/stop.png\" align=center> <b>".
61 _("This 'dn' has no terminal features.")."</b>";
62 return;
63 }
65 /* Default entry? */
66 if ($this->cn == "default"){
67 $display= "<div style='height:150px;'><br><b>";
68 $display.= _("This is a virtual terminal which has no properties to show here.");
69 $display.= "</b></div>";
70 } else {
71 /* Get template object */
72 $smarty= get_smarty();
73 $display= "";
75 /* Check if terminal is online */
76 $query= "fping -q -r 1 -t 500 ".$this->cn;
77 exec ($query, $dummy, $retval);
79 if ($retval == 0){
80 $smarty->assign("status", _("online"));
81 $smarty->assign("active", "true");
83 /* Fill data if we have snmp */
84 $host= $this->cn;
85 $community= 'goto';
87 /* Get memory informations */
88 $MemFree= @snmpget($host, $community, "UCD-SNMP-MIB::memory.memAvailReal.0");
89 if ($MemFree != FALSE){
90 $MemFree= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $MemFree);
91 $MemTotal= @snmpget($host, $community, "UCD-SNMP-MIB::memory.memTotalReal.0");
92 $MemTotal= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $MemTotal);
93 if ($MemTotal != 0){
94 $smarty->assign("mem", (int)(($MemTotal - $MemFree)*100/$MemTotal));
95 }
96 $SwapFree= @snmpget($host, $community, "UCD-SNMP-MIB::memory.memAvailSwap.0");
97 $SwapFree= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $SwapFree);
98 $SwapTotal= @snmpget($host, $community, "UCD-SNMP-MIB::memory.memTotalSwap.0");
99 $SwapTotal= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $SwapTotal);
100 if ($SwapTotal != 0){
101 #$smarty->assign("swap", (int)(($SwapTotal - $SwapFree)*100/$SwapTotal));
102 $smarty->assign("swap", 0);
103 }
105 /* Get system uptime */
106 $sysup= @snmpget($host, $community, "SNMPv2-MIB::sysUpTime.0");
107 $smarty->assign("uptime", preg_replace('/^.* ([0-9:]+)\..*$/', '\\1', $sysup));
109 /* Get system load */
110 $sysload= @snmpget($host, $community, "UCD-SNMP-MIB::laLoad.2");
111 $sysload= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $sysload);
112 $smarty->assign("load", $sysload*100);
114 /* Get status for key processes */
115 $processes= @snmpwalk($host, $community, "UCD-SNMP-MIB::prNames");
116 $check4= array("sshd", "cupsd", "artsd", "X", "saned");
117 foreach ($check4 as $pname){
118 $eflag= -1;
119 foreach ($processes as $key => $val){
120 $process= preg_replace('/^.*[:=] (.*)$/', '\\1', $val);
121 if ($process == $pname){
122 $index= preg_replace('/^.*\.([0-9]+) [:=] .*$/', '\\1', $val);
123 $res= @snmpget($host, $community, "UCD-SNMP-MIB::prErrorFlag.$index");
124 $eflag= preg_replace('/^.*[:=] /', '', $res);
125 break;
126 }
127 }
128 switch ($eflag){
129 case 0:
130 $smarty->assign("$pname", "<img alt=\""._("running")."\" src=\"images/true.png\">");
131 break;
132 case 1:
133 $smarty->assign("$pname", "<img alt=\""._("not running")."\" src=\"images/false.png\">");
134 break;
135 default:
136 $smarty->assign("$pname", _("not defined"));
137 }
138 }
139 } else {
140 foreach(array("uptime", "sshd", "X", "saned", "artsd", "cupsd") as $val){
141 $smarty->assign("$val", "<i>"._("unknown status")."</i>");
142 }
143 }
145 /* Check for mounted partitions (show max 8 partitions) */
146 $partitions= "";
147 for ($n= 1; $n<9; $n++){
148 $device= @snmpget($host, $community, "UCD-SNMP-MIB::dskDevice.$n");
149 if ($device == ""){
150 break;
151 }
152 $device= preg_replace('/^STRING: */', '', $device);
153 $usage= @snmpget($host, $community, "UCD-SNMP-MIB::dskPercent.$n");
154 $usage= preg_replace('/^INTEGER: */', '', $usage);
155 $partitions.= "<tr><td><b>$device</b></td><td><img src=\"progress.php?x=100&y=16&p=$usage\" align=\"center\"></td></tr>\n";
156 }
157 $smarty->assign("partitions", $partitions);
158 } else {
159 $smarty->assign("status", _("offline"));
160 $smarty->assign("active", "false");
161 }
163 /* Set floppy and cdrom status */
164 foreach(array("Floppy", "Cdrom") as $val){
165 $name= "goto".$val."Enable";
166 if ($this->$name == "YES"){
167 $status= _("present");
168 } else {
169 $status= "-";
170 }
171 $smarty->assign($val."Device", $status);
172 }
174 /* Show main page */
175 foreach(array("ghNetNic", "ghIdeDev", "ghScsiDev") as $val){
176 if (!count($this->$val)){
177 $this->$val= "-";
178 }
179 $smarty->assign($val, $this->$val);
180 }
181 foreach(array("ghCpuType", "ghMemSize", "macAddress", "ghUsbSupport",
182 "ghGfxAdapter", "ghSoundAdapter", "gotoLastUser", "ghInventoryNumber") as $val){
184 $smarty->assign($val, $this->$val);
185 }
186 $display= $smarty->fetch (get_template_path('info.tpl', TRUE));
187 }
189 return ($display);
190 }
192 function remove_from_parent()
193 {
194 $ldap= $this->config->get_ldap_link();
195 $ldap->rmdir($this->dn);
196 show_ldap_error($ldap->get_error());
197 }
200 /* Save data to object */
201 function save_object()
202 {
203 plugin::save_object();
204 }
208 /* Save to LDAP */
209 function save()
210 {
211 }
213 }
215 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
216 ?>