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 if (gosaSupportDaemon::ping($this->macAddress)){
108 $smarty->assign("status", _("online"));
109 $smarty->assign("active", "true");
111 /* Fill data if we have snmp */
112 $host= $this->cn;
114 /* Use 'goto' as snmp community or the configured value from the config */
115 $community= 'goto';
116 $str= $this->config->search("terminfo", "SNMPCOMMUNITY", array('tabs'));
117 if(!empty($str)){
118 $community = $str;
119 }
121 /* Get memory informations */
122 if(!is_callable("snmpget")){
123 $MemFree = false;
124 }else{
125 $MemFree= @snmpget($host, $community, "UCD-SNMP-MIB::memory.memAvailReal.0");
126 }
127 if ($MemFree != FALSE){
128 $MemFree= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $MemFree);
129 $MemTotal= @snmpget($host, $community, "UCD-SNMP-MIB::memory.memTotalReal.0");
130 $MemTotal= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $MemTotal);
131 if ($MemTotal != 0){
132 $smarty->assign("mem",progressbar( (int)(($MemTotal - $MemFree)*100/$MemTotal),100,15,true));
133 ;
134 }
135 $SwapFree= @snmpget($host, $community, "UCD-SNMP-MIB::memory.memAvailSwap.0");
136 $SwapFree= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $SwapFree);
137 $SwapTotal= @snmpget($host, $community, "UCD-SNMP-MIB::memory.memTotalSwap.0");
138 $SwapTotal= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $SwapTotal);
139 if ($SwapTotal != 0){
140 #$smarty->assign("swap", (int)(($SwapTotal - $SwapFree)*100/$SwapTotal));
141 $smarty->assign("swap", progressbar(0,100,15,true));
142 }
144 /* Get system uptime */
145 $sysup= @snmpget($host, $community, "SNMPv2-MIB::sysUpTime.0");
146 $smarty->assign("uptime", preg_replace('/^.* ([0-9:]+)\..*$/', '\\1', $sysup));
148 /* Get system load */
149 $sysload= @snmpget($host, $community, "UCD-SNMP-MIB::laLoad.2");
150 $sysload= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $sysload);
152 $smarty->assign("load", progressbar($sysload*100,100,15,true));
154 /* Get status for key processes */
155 $processes= @snmpwalk($host, $community, "UCD-SNMP-MIB::prNames");
156 $check4= array("sshd", "cupsd", "artsd", "X", "saned");
157 foreach ($check4 as $pname){
158 $eflag= -1;
159 foreach ($processes as $key => $val){
160 $process= preg_replace('/^.*[:=] (.*)$/', '\\1', $val);
161 if ($process == $pname){
162 $index= preg_replace('/^.*\.([0-9]+) [:=] .*$/', '\\1', $val);
163 $res= @snmpget($host, $community, "UCD-SNMP-MIB::prErrorFlag.$index");
164 $eflag= preg_replace('/^.*[:=] /', '', $res);
165 break;
166 }
167 }
168 switch ($eflag){
169 case 0:
170 $smarty->assign("$pname", "<img alt=\""._("running")."\" src=\"images/true.png\">");
171 break;
172 case 1:
173 $smarty->assign("$pname", "<img alt=\""._("not running")."\" src=\"images/false.png\">");
174 break;
175 default:
176 $smarty->assign("$pname", _("not defined"));
177 }
178 }
179 } else {
180 foreach(array("uptime", "sshd", "X", "saned", "artsd", "cupsd") as $val){
181 $smarty->assign("$val", "<i>"._("unknown status")."</i>");
182 }
183 }
184 /* Check for mounted partitions (show max 8 partitions) */
185 $partitions= "";
186 for ($n= 1; $n<9; $n++){
187 $device= @snmpget($host, $community, "UCD-SNMP-MIB::dskDevice.$n");
188 if ($device == ""){
189 break;
190 }
191 $device= preg_replace('/^STRING: */', '', $device);
192 $usage= @snmpget($host, $community, "UCD-SNMP-MIB::dskPercent.$n");
193 $usage= preg_replace('/^INTEGER: */', '', $usage);
194 $partitions.= "<tr><td><b>$device</b></td><td>".progressbar($usage,100,16,true)."</td></tr>\n";
195 }
196 $smarty->assign("partitions", $partitions);
197 } else {
198 $smarty->assign("status", _("offline"));
199 $smarty->assign("active", "false");
200 }
202 /* Set floppy and cdrom status */
203 foreach(array("Floppy", "Cdrom") as $val){
204 $name= "goto".$val."Enable";
205 if ($this->$name == "YES"){
206 $status= _("present");
207 } else {
208 $status= "-";
209 }
210 $smarty->assign($val."Device", $status);
211 }
213 /* Show main page */
214 foreach(array("ghNetNic", "ghIdeDev", "ghScsiDev") as $val){
215 if (!count($this->$val)){
216 $this->$val= "-";
217 }
218 $smarty->assign($val, $this->$val);
219 }
220 }
221 foreach(array("ghCpuType", "ghMemSize", "macAddress", "ghUsbSupport",
222 "ghGfxAdapter", "ghSoundAdapter", "gotoLastUser", "ghInventoryNumber") as $val){
224 $smarty->assign($val, $this->$val);
225 }
226 $display= $smarty->fetch (get_template_path('info.tpl', TRUE, dirname(__FILE__)));
228 return ($display);
229 }
231 function remove_from_parent()
232 {
233 }
236 /* Save data to object */
237 function save_object()
238 {
239 plugin::save_object();
240 }
243 /* Save to LDAP */
244 function save()
245 {
246 }
248 }
250 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
251 ?>