root/eaccelerator/branches/0.9.5/control.php

Revision 264, 11.4 kB (checked in by bart, 2 years ago)

* Fix stupid bug (#159)
* Handle returning null instead of array (#156)

  • Property svn:keywords set to svn:eol-style
Line 
1 <?php
2 /*
3    +----------------------------------------------------------------------+
4    | eAccelerator control panel                                           |
5    +----------------------------------------------------------------------+
6    | Copyright (c) 2004-2006 eAccelerator                                  |
7    | http://eaccelerator.net                                              |
8    +----------------------------------------------------------------------+
9    | This source file is subject to version 2.00 of the Zend license,     |
10    | that is bundled with this package in the file LICENSE, and is        |
11    | available through the world-wide-web at the following url:           |
12    | http://www.zend.com/license/2_00.txt.                                |
13    | If you did not receive a copy of the Zend license and are unable to  |
14    | obtain it through the world-wide-web, please send a note to          |
15    | license@zend.com so we can mail you a copy immediately.              |
16    +----------------------------------------------------------------------+
17
18    $ Id: $
19 */
20
21 if (!function_exists('eaccelerator_info')) {
22     die('eAccelerator isn\'t installed or isn\'t compiled with info support!');
23 }
24
25 /** config **/
26 $user = "admin";
27 $pw = "eAccelerator";
28 /** /config **/
29
30 /* {{{ auth */
31 if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_USER']) ||
32         $_SERVER['PHP_AUTH_USER'] != $user || $_SERVER['PHP_AUTH_PW'] != $pw) {
33     header('WWW-Authenticate: Basic realm="eAccelerator control panel"');
34     header('HTTP/1.0 401 Unauthorized');
35     exit;
36 }
37 /* }}} */
38
39 /* {{{ process any commands */
40 $info = eaccelerator_info();
41 if (isset($_POST['caching'])) {
42     if ($info['cache']) {
43         eaccelerator_caching(false);
44     } else {
45         eaccelerator_caching(true);
46     }
47 } else if (isset($_POST['optimizer']) && function_exists('eaccelerator_optimizer')) {
48     if ($info['optimizer']) {
49         eaccelerator_optimizer(false);
50     } else {
51         eaccelerator_optimizer(true);
52     }
53 } else if (isset($_POST['clear'])) {
54     eaccelerator_clear();
55 } else if (isset($_POST['clean'])) {
56     eaccelerator_clean();
57 } else if (isset($_POST['purge'])) {
58     eaccelerator_purge();
59 }
60 $info = eaccelerator_info();
61 if (!is_array($info)) {
62     die('An error occured getting eAccelerator information, this is caused if eAccelerator isn\'t initalised properly');
63 }
64 /* }}} */
65
66 function compare($x, $y)
67 {
68   global $sortby;
69
70   if ( $x[$sortby] == $y[$sortby] )
71     return 0;
72   else if ( $x[$sortby] < $y[$sortby] )
73     return -1;
74   else
75     return 1;
76 }
77
78 function revcompare($x, $y)
79 {
80   global $sortby;
81
82   if ( $x[$sortby] == $y[$sortby] )
83     return 0;
84   else if ( $x[$sortby] < $y[$sortby] )
85     return 1;
86   else
87     return -1;
88 }
89   
90 /* {{{ create_script_table */
91 function create_script_table($list) {
92   global $sortby;
93
94   if (isset($_GET['order']) && ($_GET['order'] == "asc" || $_GET['order'] =="desc")) {
95     $order = $_GET['order'];
96   } else {
97     $order = "asc";
98   }
99  
100   if (isset($_GET['sort'])) {
101     switch ($_GET['sort']) {
102       case "mtime":
103       case "size":
104       case "reloads":
105       case "hits":
106         $sortby = $_GET['sort'];
107         ($order == "asc" ? uasort($list, 'compare') : uasort($list, 'revcompare'));
108         break;
109       default:
110         $sortby = "file";
111         ($order == "asc" ? uasort($list, 'compare') : uasort($list, 'revcompare'));
112     }
113   }
114
115 ?>
116     <table>
117         <tr>
118             <th><a href="<?=$_SERVER['PHP_SELF']?>?sort=file&order=<?=($order == "asc" ? "desc" : "asc")?>">Filename</a>&nbsp;<? if($sortby == "file") echo ($order == "asc" ? "&darr;" : "&uarr;")?></th>
119             <th><a href="<?=$_SERVER['PHP_SELF']?>?sort=mtime&order=<?=($order == "asc" ? "desc" : "asc")?>">MTime</a>&nbsp;<? if($sortby == "mtime") echo ($order == "asc" ? "&darr;" : "&uarr;")?></th>
120             <th><a href="<?=$_SERVER['PHP_SELF']?>?sort=size&order=<?=($order == "asc" ? "desc" : "asc")?>">Size</a>&nbsp;<? if($sortby == "size") echo ($order == "asc" ? "&darr;" : "&uarr;")?></th>
121             <th><a href="<?=$_SERVER['PHP_SELF']?>?sort=reloads&order=<?=($order == "asc" ? "desc" : "asc")?>">Reloads</a>&nbsp;<? if($sortby == "reloads") echo ($order == "asc" ? "&darr;" : "&uarr;")?></th>
122             <th><a href="<?=$_SERVER['PHP_SELF']?>?sort=hits&order=<?=($order == "asc" ? "desc" : "asc")?>">Hits</a>&nbsp;<? if($sortby == "hits") echo ($order == "asc" ? "&darr;" : "&uarr;")?></th>
123         </tr>
124     <?php
125           switch ($sortby) {
126             case "mtime":
127             case "size":
128             case "reloads":
129             case "hits":
130               ($order == "asc" ? uasort($list, 'compare') : uasort($list, 'revcompare'));
131               break;
132             case "file":
133             default:
134               $sortby = "file";
135               ($order == "asc" ? uasort($list, 'compare') : uasort($list, 'revcompare'));
136               
137           }
138
139           foreach($list as $script) { ?>
140         <tr>
141     <?php   if (function_exists('eaccelerator_dasm_file')) { ?>
142             <td class="e"><a href="dasm.php?file=<?php echo $script['file']; ?>"><?php echo $script['file']; ?></a></td>
143     <?php   } else { ?>
144             <td class="e"><?php echo $script['file']; ?></td>
145     <?php   } ?>
146             <td class="vr"><?php echo date('Y-m-d H:i', $script['mtime']); ?></td>
147             <td class="vr"><?php echo number_format($script['size'] / 1024, 2); ?> KB</td>
148             <td class="vr"><?php echo $script['reloads']; ?> (<?php echo $script['usecount']; ?>)</td>
149             <td class="vr"><?php echo $script['hits']; ?></td>
150         </tr>
151     <?php } ?>
152     </table>
153 <?php
154 }
155 /* }}} */
156
157 /* {{{ create_key_table */
158 function create_key_table($list) {
159 ?>
160     <table class="key">
161         <tr>
162             <th>Name</th>
163             <th>Created</th>
164             <th>Size</th>
165             <th>ttl</th>
166         </tr>
167 <?php
168     foreach($list as $key) {
169 ?>
170         <tr>
171             <td class="e"><?php echo $key['name']; ?></td>
172             <td class="vr"><?php echo date('Y-m-d H:i', $key['created']); ?></td>
173             <td class="vr"><?php echo number_format($key['size']/1024, 3); ?>KB</td>
174             <td class="vr"><?php
175                 if ($key['ttl'] == -1) {
176                     echo 'expired';
177                 } elseif ($key['ttl'] == 0) {
178                     echo 'none';
179                 } else {
180                     echo date('Y-m-d H:i', $key['ttl']);
181                 }
182             ?></td>
183         </tr>
184 <?php
185     }
186 ?>
187     </table>
188 <?php
189 }
190 /* }}} */
191
192 /* {{{ print_header */
193 function print_header() { ?>
194 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
195 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
196 <head>
197     <title>eAccelerator control panel</title>
198     <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
199     <meta http-equiv="Content-Style-Type" content="text/css" />
200     <meta http-equiv="Content-Language" content="en" />
201
202     <style type="text/css" media="all">
203         body {background-color: #ffffff; color: #000000;}
204         body, td, th, h1, h2 {font-family: sans-serif;}
205         pre {margin: 0px; font-family: monospace;}
206         a:link {color: #000099; text-decoration: none}
207         a:hover {text-decoration: underline;}
208         table {border-collapse: collapse; width: 800px;}
209         .center {text-align: center;}
210         .center table { margin-left: auto; margin-right: auto; text-align: left;}
211         .center th { text-align: center !important; }
212         td, th { border: 1px solid #000000; font-size: 75%; vertical-align: baseline;}
213         h1 {font-size: 150%;}
214         h2 {font-size: 125%;}
215         .p {text-align: left;}
216         .e {background-color: #ccccff; font-weight: bold; color: #000000;}
217         .h,th {background-color: #9999cc; font-weight: bold; color: #000000;}
218         .v,td {background-color: #cccccc; color: #000000;}
219         .vr{background-color: #cccccc; text-align: right; color: #000000; white-space: nowrap;}
220         img {float: right; border: 0px;}
221         hr {width: 600px; background-color: #cccccc; border: 0px; height: 1px; color: #000000;}
222         input {width: 150px}
223         h1 {width: 800px;  border: 1px solid #000000; margin-left: auto; margin-right: auto; background-color: #9999cc;}
224     </style>
225 </head>
226 <?php
227 }
228 /* }}} */
229 ?>
230
231 <?php print_header(); ?>
232 <body class="center">
233 <h1>eAccelerator <?php echo $info['version']; ?> control panel</h1>
234
235 <!-- {{{ information -->
236 <h2>Information</h2>
237 <table>
238 <tr>
239     <td class="e">Caching enabled</td>
240     <td><?php echo $info['cache'] ? 'yes':'no' ?></td>
241 </tr>
242 <tr>
243     <td class="e">Optimizer enabled</td>
244     <td><?php echo $info['optimizer'] ? 'yes':'no' ?></td>
245 </tr>
246 <tr>
247     <td class="e">Memory usage</td>
248     <td><?php echo number_format(100 * $info['memoryAllocated'] / $info['memorySize'], 2); ?>%
249         (<?php echo number_format($info['memoryAllocated'] / (1024*1024), 2); ?>MB/
250         <?php echo number_format($info['memorySize'] / (1024*1024), 2); ?>MB)</td>
251 </tr>
252 <tr>
253     <td class="e">Free memory</td>
254     <td><?php echo number_format($info['memoryAvailable'] / (1024*1024), 2); ?>MB</td>
255 </tr>
256 <tr>
257     <td class="e">Cached scripts</td>
258     <td><?php echo $info['cachedScripts']; ?></td>
259 </tr>
260 <tr>
261     <td class="e">Removed scripts</td>
262     <td><?php echo $info['removedScripts']; ?></td>
263 </tr>
264 <tr>
265     <td class="e">Cached keys</td>
266     <td><?php echo $info['cachedKeys']; ?></td>
267 </tr>
268 </table>
269 <!-- }}} -->
270
271 <!-- {{{ control -->
272 <h2>Actions</h2>
273 <form name="ea_control" method="post">
274     <table>
275         <tr>
276             <td class="e">Caching</td>
277             <td><input type="submit" name="caching" value="<?php echo $info['cache']?'disable':'enable'; ?>" /></td>
278         </tr>
279         <tr>
280             <td class="e">Optimizer</td>
281             <td><input type="submit" name="optimizer" value="<?php echo $info['optimizer']?'disable':'enable'; ?>" /></td>
282         </tr>
283         <tr>
284             <td class="e">Clear cache</td>
285             <td><input type="submit" name="clear" value="clear" title="remove all unused scripts and data from shared memory and disk cache" /></td>
286         </tr>
287         <tr>
288             <td class="e">Clean cache</td>
289             <td><input type="submit" name="clean" value="clean" title=" remove all expired scripts and data from shared memory and disk cache" /></td>
290         </tr>
291         <tr>
292             <td class="e">Purge cache</td>
293             <td><input type="submit" name="purge" value="purge" title="remove all 'removed' scripts from shared memory" /></td>
294         </tr>
295     </table>
296 </form>
297 <!-- }}} -->
298
299 <h2>Cached scripts</h2>
300 <?php create_script_table(eaccelerator_cached_scripts()); ?>
301
302 <h2>Removed scripts</h2>
303 <?php create_script_table(eaccelerator_removed_scripts()); ?>
304
305 <?php
306 if (function_exists('eaccelerator_get')) {
307     echo "<h2>Cached keys</h2>";
308     create_key_table(eaccelerator_list_keys());
309 }
310 ?>
311
312 <!-- {{{ footer -->
313 <br /><br />
314 <table>
315     <tr><td class="center">
316     <a href="http://eaccelerator.net"><img src="?=<?php echo $info['logo']; ?>" alt="eA logo" /></a>
317     <strong>Created by the eAccelerator team, <a href="http://eaccelerator.net">http://eaccelerator.net</a></strong><br /><br />
318     <nobr>eAccelerator <?php echo $info['version']; ?> [shm:<?php echo $info['shm_type']?> sem:<?php echo $info['sem_type']; ?>]</nobr><br />
319     <nobr>PHP <?php echo phpversion();?> [ZE <?php echo zend_version(); ?>]</nobr><br />
320     <nobr>Using <?php echo php_sapi_name();?> on <?php echo php_uname(); ?></nobr><br />
321     </td></tr>
322 </table>
323 <!-- }}} -->
324 </body>
325 </html>
326
327 <?php
328
329 /*
330  * Local variables:
331  * tab-width: 4
332  * c-basic-offset: 4
333  * End:
334  * vim600: noet sw=4 ts=4 fdm=marker
335  * vim<600: noet sw=4 ts=4
336  */
337
338 ?>
339
Note: See TracBrowser for help on using the browser.