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