1 <?php
3 class terminfo extends plugin
4 {
5 /* Generic terminal attributes */
6 var $ghCpuType= "-";
7 var $ghMemSize= "-";
8 var $macAddress= "-";
9 var $ghUsbSupport= "-";
10 var $ghNetNic= array();
11 var $ghIdeDev= array();
12 var $ghScsiDev= array();
13 var $ghGfxAdapter= "-";
14 var $ghSoundAdapter= "-";
15 var $ghInventoryNumber= "-";
16 var $gotoLastUser= "-";
17 var $gotoFloppyEnable= "";
18 var $gotoCdromEnable= "";
20 /* Needed values and lists */
21 var $base= "";
22 var $cn= "";
23 var $view_logged = FALSE;
25 /* attribute list for save action */
26 var $ignore_account= TRUE;
27 var $attributes= array("cn", "gotoMode", "gotoTerminalPath", "gotoFloppyEnable",
28 "gotoCdromEnable", "ghInventoryNumber",
29 "gotoSwapServer", "gotoSyslogServer", "gotoNtpServer",
30 "ghCpuType", "ghMemSize", "macAddress", "ghUsbSupport",
31 "ghGfxAdapter", "ghSoundAdapter", "gotoLastUser");
32 var $objectclasses= array("GOhard");
34 function terminfo (&$config, $dn= NULL, $parent= NULL)
35 {
36 plugin::plugin ($config,$dn);
38 /* Read arrays */
39 foreach (array("ghNetNic", "ghIdeDev", "ghScsiDev") as $val){
40 if (!isset($this->attrs[$val])){
41 continue;
42 }
43 for ($i= 0; $i<$this->attrs[$val]['count']; $i++){
44 array_push($this->$val, $this->attrs[$val][$i]);
45 }
46 }
48 /* Fix USB entry */
49 if ($this->ghUsbSupport == "true"){
50 $this->ghUsbSupport= _("present");
51 }
52 }
55 function execute()
56 {
57 /* Call parent execute */
58 plugin::execute();
60 if($this->is_account && !$this->view_logged){
61 $this->view_logged = TRUE;
62 new log("view","terminal/".get_class($this),$this->dn);
63 }
65 /* Do we represent a valid terminal? */
66 if (!$this->is_account && $this->parent === NULL){
67 return("<img alt=\"\" src=\"images/small-error.png\" align=middle> <b>".
68 msgPool::noValidExtension(_("terminal"))."</b>");
69 }
71 $smarty= get_smarty();
72 $display= "";
73 $smarty->assign("ACL",TRUE);
74 if(!preg_match("/r/",$this->getacl(""))){
75 $smarty->assign("ACL",FALSE);
76 }elseif(!is_callable("snmpget")){
78 $smarty->assign("load", progressbar(0,100,15,true));
79 $smarty->assign("mem", progressbar(0,100,15,true));
80 $smarty->assign("swap", progressbar(0,100,15,true));
81 foreach(array("uptime", "sshd", "X", "saned", "artsd", "cupsd","status","ghNetNic", "ghIdeDev", "ghScsiDev","FloppyDevice", "CdromDevice","active") as $val){
82 $smarty->assign("$val", "<i>"._("unknown status, SNMP support missing")."</i>");
83 }
86 $display ="";
87 }else
88 /* Default entry? */
89 if ($this->cn == "default"){
90 $display= "<div style='height:150px;'><br><b>";
91 $display.= _("This is a virtual terminal which has no properties to show here.");
92 $display.= "</b></div>";
93 } else {
95 /* Get template object */
96 $smarty->assign("staticAddress", "");
98 /* Prevent undefined variable .... */
99 $smarty->assign("load", progressbar(0,100,15,true));
100 $smarty->assign("mem", progressbar(0,100,15,true));
101 $smarty->assign("swap", progressbar(0,100,15,true));
103 /* Check if terminal is online */
104 if (gosaSupportDaemon::ping($this->macAddress)){
105 $smarty->assign("status", _("online"));
106 $smarty->assign("active", "true");
108 /* Fill data if we have snmp */
109 $host= $this->cn;
111 /* Use 'goto' as snmp community or the configured value from the config */
112 $community= 'goto';
113 $str= $this->config->search("terminfo", "SNMPCOMMUNITY", array('tabs'));
114 if(!empty($str)){
115 $community = $str;
116 }
118 /* Get memory informations */
119 if(!is_callable("snmpget")){
120 $MemFree = false;
121 }else{
122 $MemFree= @snmpget($host, $community, "UCD-SNMP-MIB::memory.memAvailReal.0");
123 }
124 if ($MemFree != FALSE){
125 $MemFree= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $MemFree);
126 $MemTotal= @snmpget($host, $community, "UCD-SNMP-MIB::memory.memTotalReal.0");
127 $MemTotal= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $MemTotal);
128 if ($MemTotal != 0){
129 $smarty->assign("mem",progressbar( (int)(($MemTotal - $MemFree)*100/$MemTotal),100,15,true));
130 ;
131 }
132 $SwapFree= @snmpget($host, $community, "UCD-SNMP-MIB::memory.memAvailSwap.0");
133 $SwapFree= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $SwapFree);
134 $SwapTotal= @snmpget($host, $community, "UCD-SNMP-MIB::memory.memTotalSwap.0");
135 $SwapTotal= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $SwapTotal);
136 if ($SwapTotal != 0){
137 #$smarty->assign("swap", (int)(($SwapTotal - $SwapFree)*100/$SwapTotal));
138 $smarty->assign("swap", progressbar(0,100,15,true));
139 }
141 /* Get system uptime */
142 $sysup= @snmpget($host, $community, "SNMPv2-MIB::sysUpTime.0");
143 $smarty->assign("uptime", preg_replace('/^.* ([0-9:]+)\..*$/', '\\1', $sysup));
145 /* Get system load */
146 $sysload= @snmpget($host, $community, "UCD-SNMP-MIB::laLoad.2");
147 $sysload= preg_replace('/^.*[=:] ([0-9.]+)$/', '\\1', $sysload);
149 $smarty->assign("load", progressbar($sysload*100,100,15,true));
151 /* Get status for key processes */
152 $processes= @snmpwalk($host, $community, "UCD-SNMP-MIB::prNames");
153 $check4= array("sshd", "cupsd", "artsd", "X", "saned");
154 foreach ($check4 as $pname){
155 $eflag= -1;
156 foreach ($processes as $key => $val){
157 $process= preg_replace('/^.*[:=] (.*)$/', '\\1', $val);
158 if ($process == $pname){
159 $index= preg_replace('/^.*\.([0-9]+) [:=] .*$/', '\\1', $val);
160 $res= @snmpget($host, $community, "UCD-SNMP-MIB::prErrorFlag.$index");
161 $eflag= preg_replace('/^.*[:=] /', '', $res);
162 break;
163 }
164 }
165 switch ($eflag){
166 case 0:
167 $smarty->assign("$pname", "<img alt=\""._("running")."\" src=\"images/true.png\">");
168 break;
169 case 1:
170 $smarty->assign("$pname", "<img alt=\""._("not running")."\" src=\"images/false.png\">");
171 break;
172 default:
173 $smarty->assign("$pname", _("not defined"));
174 }
175 }
176 } else {
177 foreach(array("uptime", "sshd", "X", "saned", "artsd", "cupsd") as $val){
178 $smarty->assign("$val", "<i>"._("unknown status")."</i>");
179 }
180 }
181 /* Check for mounted partitions (show max 8 partitions) */
182 $partitions= "";
183 for ($n= 1; $n<9; $n++){
184 $device= @snmpget($host, $community, "UCD-SNMP-MIB::dskDevice.$n");
185 if ($device == ""){
186 break;
187 }
188 $device= preg_replace('/^STRING: */', '', $device);
189 $usage= @snmpget($host, $community, "UCD-SNMP-MIB::dskPercent.$n");
190 $usage= preg_replace('/^INTEGER: */', '', $usage);
191 $partitions.= "<tr><td><b>$device</b></td><td>".progressbar($usage,100,16,true)."</td></tr>\n";
192 }
193 $smarty->assign("partitions", $partitions);
194 } else {
195 $smarty->assign("status", _("offline"));
196 $smarty->assign("active", "false");
197 }
199 /* Set floppy and cdrom status */
200 foreach(array("Floppy", "Cdrom") as $val){
201 $name= "goto".$val."Enable";
202 if ($this->$name == "YES"){
203 $status= _("present");
204 } else {
205 $status= "-";
206 }
207 $smarty->assign($val."Device", $status);
208 }
210 /* Show main page */
211 foreach(array("ghNetNic", "ghIdeDev", "ghScsiDev") as $val){
212 if (!count($this->$val)){
213 $this->$val= "-";
214 }
215 $smarty->assign($val, $this->$val);
216 }
217 }
218 foreach(array("ghCpuType", "ghMemSize", "macAddress", "ghUsbSupport",
219 "ghGfxAdapter", "ghSoundAdapter", "gotoLastUser", "ghInventoryNumber") as $val){
221 $smarty->assign($val, $this->$val);
222 }
223 $display= $smarty->fetch (get_template_path('info.tpl', TRUE, dirname(__FILE__)));
225 return ($display);
226 }
228 function remove_from_parent()
229 {
230 }
233 /* Save data to object */
234 function save_object()
235 {
236 plugin::save_object();
237 }
240 /* Save to LDAP */
241 function save()
242 {
243 }
246 /* Return plugin informations for acl handling */
247 static function plInfo()
248 {
249 return (array(
250 "plShortName" => _("System info"),
251 "plDescription" => _("System informations"),
252 "plSelfModify" => FALSE,
253 "plDepends" => array(),
254 "plPriority" => 33,
255 "plSection" => array("administration"),
256 "plCategory" => array("workstation","server","terminal"),
257 "plProvidedAcls"=> array()
258 ));
259 }
260 }
262 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
263 ?>