vogelor
2008-12-02 fb4c27e329659f7ebfb72855297549ac01a54f02
commit | author | age
8793b3 1 <?php
36d307 2 /*
V 3 Copyright (c) 2007-2008, Till Brehm, projektfarm Gmbh and Oliver Vogel www.muv.com
4 All rights reserved.
5
6 Redistribution and use in source and binary forms, with or without modification,
7 are permitted provided that the following conditions are met:
8
9     * Redistributions of source code must retain the above copyright notice,
10       this list of conditions and the following disclaimer.
11     * Redistributions in binary form must reproduce the above copyright notice,
12       this list of conditions and the following disclaimer in the documentation
13       and/or other materials provided with the distribution.
14     * Neither the name of ISPConfig nor the names of its contributors
15       may be used to endorse or promote products derived from this software without
16       specific prior written permission.
17
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
22 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
25 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
8793b3 29 function showServerLoad(){
V 30     global $app;
31
32     /* fetch the Data from the DB */
33     $record = $app->db->queryOneRecord("SELECT data, state FROM monitor_data WHERE type = 'server_load' and server_id = " . $_SESSION['monitor']['server_id'] . " order by created desc");
34
35     if(isset($record['data'])) {
36         $data = unserialize($record['data']);
37
38         /*
39         Format the data
40         */
716255 41         $html =
9cd0f6 42            '<div class="systemmonitor-state systemmonitor-state-' . $record['state'] . '">
V 43             <div class="systemmonitor-state-' . $record['state'] . '-icon">
44             <table>
8793b3 45             <tr>
V 46             <td>' . $app->lng("Server online since").':</td>
47             <td>' . $data['up_days'] . ' days, ' . $data['up_hours'] . ':' . $data['up_minutes'] . ' hours</center></td>
48             </tr>
49             <tr>
50             <td>' . $app->lng("Users online").':</td>
51             <td>' . $data['user_online'] . '</td>
52             </tr>' .
53             '<tr>
54             <td>' . $app->lng("System load 1 minute") . ':</td>
55             <td>' . $data['load_1'] . '</td>
56             </tr>
57             <tr>
58             <td>' . $app->lng("System load 5 minutes") . ':</td>
59             <td>' . $data['load_5'] . '</td>
60             </tr>
61             <tr>
62             <td>'.$app->lng("System load 15 minutes").':</td>
63             <td>' . $data['load_15'] . '</td>
64             </tr>
9cd0f6 65             </table>
V 66             </div>
67             </div>';
8793b3 68     } else {
V 69         $html = '<p>'.$app->lng("no_data_serverload_txt").'</p>';
70     }
71
72     return $html;
73 }
74
75 function showDiskUsage () {
76     global $app;
77
78     /* fetch the Data from the DB */
79     $record = $app->db->queryOneRecord("SELECT data, state FROM monitor_data WHERE type = 'disk_usage' and server_id = " . $_SESSION['monitor']['server_id'] . " order by created desc");
80
81     if(isset($record['data'])) {
82         $data = unserialize($record['data']);
83
84         /*
85         Format the data
86         */
9cd0f6 87         $html =
V 88            '<div class="systemmonitor-state systemmonitor-state-' . $record['state'] . '">
89             <div class="systemmonitor-state-' . $record['state'] . '-icon">
90             <table>
91             <tr>
92             <td>Filesystem</td>
93             <td>1K-blocks</td>
94             <td>Used</td>
95             <td>Available</td>
96             <td>Use%</td>
97             <td>Mounted on</td>
98             </tr>';
8793b3 99         foreach($data as $line) {
V 100             $html .= '<tr>';
101             foreach ($line as $item) {
102                 $html .= '<td>' . $item . '</td>';
103             }
104             $html .= '</tr>';
105         }
106         $html .= '</table>';
9cd0f6 107         $html .= '</div></div>';
8793b3 108     } else {
V 109         $html = '<p>'.$app->lng("no_data_diskusage_txt").'</p>';
110     }
111
112
113     return $html;
114 }
115
116
117 function showMemUsage ()
118 {
119     global $app;
120
121     /* fetch the Data from the DB */
122     $record = $app->db->queryOneRecord("SELECT data, state FROM monitor_data WHERE type = 'mem_usage' and server_id = " . $_SESSION['monitor']['server_id'] . " order by created desc");
123
124     if(isset($record['data'])) {
125         $data = unserialize($record['data']);
126
127         /*
128         Format the data
129         */
9cd0f6 130         $html =
V 131            '<div class="systemmonitor-state systemmonitor-state-' . $record['state'] . '">
132             <div class="systemmonitor-state-' . $record['state'] . '-icon">
133             <table>';
8793b3 134
V 135         foreach($data as $key => $value){
136             if ($key != '') {
137                 $html .= '<tr>
138                     <td>' . $key . ':</td>
139                     <td>' . $value . '</td>
140                     </tr>';
141             }
142         }
143         $html .= '</table>';
9cd0f6 144         $html .= '</div></div>';
V 145
8793b3 146     } else {
V 147         $html = '<p>'.$app->lng("no_data_memusage_txt").'</p>';
148     }
149
150     return $html;
151 }
152
153 function showCpuInfo ()
154 {
155     global $app;
156
157     /* fetch the Data from the DB */
158     $record = $app->db->queryOneRecord("SELECT data, state FROM monitor_data WHERE type = 'cpu_info' and server_id = " . $_SESSION['monitor']['server_id'] . " order by created desc");
159
160     if(isset($record['data'])) {
161         $data = unserialize($record['data']);
162
163         /*
164         Format the data
165         */
9cd0f6 166         $html = 
V 167            '<div class="systemmonitor-state systemmonitor-state-' . $record['state'] . '">
168             <div class="systemmonitor-state-' . $record['state'] . '-icon">
169             <table>';
8793b3 170         foreach($data as $key => $value){
V 171             if ($key != '') {
172                 $html .= '<tr>
173                     <td>' . $key . ':</td>
174                     <td>' . $value . '</td>
175                     </tr>';
176             }
177         }
178         $html .= '</table>';
9cd0f6 179         $html .= '</div></div>';
8793b3 180     } else {
V 181         $html = '<p>'.$app->lng("no_data_cpuinfo_txt").'</p>';
182     }
183
184     return $html;
185 }
186
187 function showServices ()
188 {
189     global $app;
190
191     /* fetch the Data from the DB */
192     $record = $app->db->queryOneRecord("SELECT data, state FROM monitor_data WHERE type = 'services' and server_id = " . $_SESSION['monitor']['server_id'] . " order by created desc");
193
194     if(isset($record['data'])) {
195         $data = unserialize($record['data']);
196
197         /*
198         Format the data
199         */
9cd0f6 200         $html =
V 201            '<div class="systemmonitor-state systemmonitor-state-' . $record['state'] . '">
202             <div class="systemmonitor-state-' . $record['state'] . '-icon">
203             <table>';
8793b3 204
V 205         if($data['webserver'] != -1) {
206             if($data['webserver'] == 1) {
207                 $status = '<span class="online">Online</span>';
208             } else {
209                 $status = '<span class="offline">Offline</span>';
210             }
211             $html .= '<tr>
212             <td>Web-Server:</td>
213             <td>'.$status.'</td>
214             </tr>';
215         }
216
217
218         if($data['ftpserver'] != -1) {
219             if($data['ftpserver'] == 1) {
220                 $status = '<span class="online">Online</span>';
221             } else {
222                 $status = '<span class="offline">Offline</span>';
223             }
224             $html .= '<tr>
225             <td>FTP-Server:</td>
226             <td>'.$status.'</td>
227             </tr>';
228         }
229
230         if($data['smtpserver'] != -1) {
231             if($data['smtpserver'] == 1) {
232                 $status = '<span class="online">Online</span>';
233             } else {
234                 $status = '<span class="offline">Offline</span>';
235             }
236             $html .= '<tr>
237             <td>SMTP-Server:</td>
238             <td>'.$status.'</td>
239             </tr>';
240         }
241
242         if($data['pop3server'] != -1) {
243             if($data['pop3server'] == 1) {
244                 $status = '<span class="online">Online</span>';
245             } else {
246                 $status = '<span class="offline">Offline</span>';
247             }
248             $html .= '<tr>
249             <td>POP3-Server:</td>
250             <td>'.$status.'</td>
251             </tr>';
252         }
253
254         if($data['imapserver'] != -1) {
255             if($data['imapserver'] == 1) {
256                 $status = '<span class="online">Online</span>';
257             } else {
258                 $status = '<span class="offline">Offline</span>';
259             }
260             $html .= '<tr>
261             <td>IMAP-Server:</td>
262             <td>'.$status.'</td>
263             </tr>';
264         }
265
266         if($data['bindserver'] != -1) {
267             if($data['bindserver'] == 1) {
268                 $status = '<span class="online">Online</span>';
269             } else {
270                 $status = '<span class="offline">Offline</span>';
271             }
272             $html .= '<tr>
273             <td>DNS-Server:</td>
274             <td>'.$status.'</td>
275             </tr>';
276         }
277
278         if($data['mysqlserver'] != -1) {
279             if($data['mysqlserver'] == 1) {
280                 $status = '<span class="online">Online</span>';
281             } else {
282                 $status = '<span class="offline">Offline</span>';
283             }
284             $html .= '<tr>
285             <td>mySQL-Server:</td>
286             <td>'.$status.'</td>
287             </tr>';
288         }
289
290
9cd0f6 291         $html .= '</table></div></div>';
8793b3 292     } else {
V 293         $html = '<p>'.$app->lng("no_data_services_txt").'</p>';
294     }
295
296
297     return $html;
298 }
716255 299
V 300 function showSystemUpdate()
301 {
302     global $app;
303
304     /* fetch the Data from the DB */
305     $record = $app->db->queryOneRecord("SELECT data, state FROM monitor_data WHERE type = 'system_update' and server_id = " . $_SESSION['monitor']['server_id'] . " order by created desc");
306
307     if(isset($record['data'])) {
9cd0f6 308         $html =
V 309            '<div class="systemmonitor-state systemmonitor-state-' . $record['state'] . '">
310             <div class="systemmonitor-state-' . $record['state'] . '-icon">';
36d307 311         /*
V 312          * First, we have to detect, if there is any monitoring-data.
313          * If not (because the destribution is not supported) show this.
314          */
315         if ($record['state'] == 'no_state'){
9cd0f6 316             $html .= "Your distribution is not supported for this monitoring";
36d307 317         }
V 318         else {
319             $data = unserialize($record['data']);
9cd0f6 320             $html .= nl2br($data['output']);
36d307 321         }
9cd0f6 322         $html .= '</div></div>';
716255 323     } else {
V 324         $html = '<p>' . "No Update-Data available" . '</p>';
325     }
326
327     return $html;
328 }
329
36d307 330 function showRaidState()
V 331 {
332     global $app;
333
334     /* fetch the Data from the DB */
335     $record = $app->db->queryOneRecord("SELECT data, state FROM monitor_data WHERE type = 'raid_state' and server_id = " . $_SESSION['monitor']['server_id'] . " order by created desc");
336
337     if(isset($record['data'])) {
9cd0f6 338         $html =
V 339            '<div class="systemmonitor-state systemmonitor-state-' . $record['state'] . '">
340             <div class="systemmonitor-state-' . $record['state'] . '-icon">';
341
36d307 342         /*
V 343          * First, we have to detect, if there is any monitoring-data.
344          * If not (because the destribution is not supported) show this.
345          */
346         if ($record['state'] == 'no_state'){
9cd0f6 347             $html .= '<p>' . "mdadm ist not installed or your Server has no supported RAID" . '</p>';
36d307 348         }
V 349         else {
350             $data = unserialize($record['data']);
9cd0f6 351             $html .= nl2br($data['output']);
36d307 352         }
9cd0f6 353         $html .= '</div></div>';
V 354
36d307 355     } else {
V 356         $html = '<p>' . "No RAID-Data available" . '</p>';
357     }
358
359     return $html;
360 }
716255 361
fb4c27 362 function showRKHunter()
V 363 {
364     global $app;
365
366     /* fetch the Data from the DB */
367     $record = $app->db->queryOneRecord("SELECT data, state FROM monitor_data WHERE type = 'rkhunter' and server_id = " . $_SESSION['monitor']['server_id'] . " order by created desc");
368
369     if(isset($record['data'])) {
370         $html =
371            '<div class="systemmonitor-state systemmonitor-state-' . $record['state'] . '">
372             <div class="systemmonitor-state-' . $record['state'] . '-icon">';
373
374         /*
375          * First, we have to detect, if there is any monitoring-data.
376          * If not (because the destribution is not supported) show this.
377          */
378         $data = unserialize($record['data']);
379         if ($data['output'] == ''){
380             $html .= '<p>' . "rkhunter ist not installed, so there is no log data" . '</p>';
381         }
382         else {
383             $html .= nl2br($data['output']);
384         }
385         $html .= '</div></div>';
386
387     } else {
388         $html = '<p>' . "No RKHunter-Data available" . '</p>';
389     }
390
391     return $html;
392 }
393
716255 394 function showMailq()
V 395 {
396     global $app;
397
398     /* fetch the Data from the DB */
399     $record = $app->db->queryOneRecord("SELECT data, state FROM monitor_data WHERE type = 'mailq' and server_id = " . $_SESSION['monitor']['server_id'] . " order by created desc");
400
401     if(isset($record['data'])) {
402         $data = unserialize($record['data']);
403         $html = nl2br($data['output']);
404     } else {
405         $html = '<p>' . "No Mailq-Data available" . '</p>';
406     }
407
408     return $html;
409 }
fb4c27 410
V 411 function getDataTime($type) {
412     global $app;
413
414     /* fetch the Data from the DB */
415     $record = $app->db->queryOneRecord("SELECT created FROM monitor_data WHERE type = '" . $type . "' and server_id = " . $_SESSION['monitor']['server_id'] . " order by created desc");
416
417     if(isset($record['created'])) {
418         $res = date('Y-m-d H:i', $record['created']);
419     } else {
420         $res = '????-??-?? ??:??';
421     }
422     return $res;
423 }
8793b3 424 ?>