PageRenderTime 61ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/tools/cleaner.php

https://bitbucket.org/kristovaher/wave-framework
PHP | 222 lines | 139 code | 31 blank | 52 comment | 56 complexity | d01e057208551237b47f501fe4cd3345 MD5 | raw file
Possible License(s): LGPL-3.0
  1. <?php
  2. /**
  3. * Wave Framework <http://www.waveframework.com>
  4. * Filesystem Cleaner
  5. *
  6. * This script is used to clear Wave Framework system generated filesystem. It should be used
  7. * for debugging purposes during development or for maintenance once system is deployed. This
  8. * script can be configured by running it with a GET variable. Possible values are 'maintenance'
  9. * (clears only cache and temporary files), 'all' (clears everything), 'output' (clears output
  10. * cache), 'images' (clears images cache), 'resources' (clears cache of JavaScript and CSS),
  11. * 'custom' (clears custom cache), 'tags' (clears cache tags), 'messenger' (clears State Messenger
  12. * data), 'errors' (clears debugging errors), 'limiter' (clears request data of user agent IP's),
  13. * 'logs' (clears system logs), 'tokens' (clears API session tokens), 'tmp' (clears folder from
  14. * everything that might be stored here), 'data' (clears the folder intended for database
  15. * storage), 'backups' and 'updates' (clears folders that store backup and update archives)
  16. * and 'userdata' (entirely custom storage folder). Please make sure to use 'all' carefully,
  17. * since it might remove sensitive data. The script runs in 'maintenance' mode by default.
  18. *
  19. * @package Tools
  20. * @author Kristo Vaher <kristo@waher.net>
  21. * @copyright Copyright (c) 2012, Kristo Vaher
  22. * @license GNU Lesser General Public License Version 3
  23. * @tutorial /doc/pages/guide_tools.htm
  24. * @since 1.4.9
  25. * @version 3.6.0
  26. */
  27. // This initializes tools and authentication
  28. require('.'.DIRECTORY_SEPARATOR.'tools_autoload.php');
  29. // Log is printed out in plain text format
  30. header('Content-Type: text/html;charset=utf-8');
  31. ?>
  32. <!DOCTYPE html>
  33. <html lang="en">
  34. <head>
  35. <title>Cleaner</title>
  36. <meta charset="utf-8">
  37. <meta name="viewport" content="width=device-width"/>
  38. <link type="text/css" href="style.css" rel="stylesheet" media="all"/>
  39. <link rel="icon" href="../favicon.ico" type="image/x-icon"/>
  40. <link rel="icon" href="../favicon.ico" type="image/vnd.microsoft.icon"/>
  41. <meta content="noindex,nocache,nofollow,noarchive,noimageindex,nosnippet" name="robots"/>
  42. <meta http-equiv="cache-control" content="no-cache"/>
  43. <meta http-equiv="pragma" content="no-cache"/>
  44. <meta http-equiv="expires" content="0"/>
  45. </head>
  46. <body>
  47. <?php
  48. // Pops up an alert about default password
  49. passwordNotification($config['http-authentication-password']);
  50. if(isset($_GET['cutoff'])){
  51. $cutoff=$_GET['cutoff'];
  52. } else {
  53. $cutoff=time();
  54. }
  55. // Header
  56. echo '<h1>Filesystem cleaner</h1>';
  57. echo '<h4 class="highlight">';
  58. foreach($softwareVersions as $software=>$version){
  59. // Adding version numbers
  60. echo '<b>'.$software.'</b> ('.$version.') ';
  61. }
  62. echo '</h4>';
  63. echo '<h2>Log</h2>';
  64. // Log will be stored in this array
  65. $log=array();
  66. // Clears /filesystem/cache/output/
  67. if(isset($_GET['all']) || isset($_GET['maintenance']) || isset($_GET['cache']) || isset($_GET['output'])){
  68. $directory='..'.DIRECTORY_SEPARATOR.'filesystem'.DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR.'output'.DIRECTORY_SEPARATOR;
  69. $log=array_merge($log,dirCleaner($directory,$cutoff));
  70. }
  71. // Clears images cache
  72. if(isset($_GET['all']) || isset($_GET['maintenance']) || isset($_GET['cache']) || isset($_GET['images'])){
  73. $directory='..'.DIRECTORY_SEPARATOR.'filesystem'.DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR.'images'.DIRECTORY_SEPARATOR;
  74. $log=array_merge($log,dirCleaner($directory,$cutoff));
  75. }
  76. // Clears cache of JavaScript and CSS
  77. if(isset($_GET['all']) || isset($_GET['maintenance']) || isset($_GET['cache']) || isset($_GET['resources'])){
  78. $directory='..'.DIRECTORY_SEPARATOR.'filesystem'.DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR;
  79. $log=array_merge($log,dirCleaner($directory,$cutoff));
  80. }
  81. // Clears cache of JavaScript and CSS
  82. if(isset($_GET['all']) || isset($_GET['maintenance']) || isset($_GET['cache']) || isset($_GET['custom'])){
  83. $directory='..'.DIRECTORY_SEPARATOR.'filesystem'.DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR.'custom'.DIRECTORY_SEPARATOR;
  84. $log=array_merge($log,dirCleaner($directory,$cutoff));
  85. }
  86. // Clears cache tags
  87. if(isset($_GET['all']) || isset($_GET['maintenance']) || isset($_GET['cache']) || isset($_GET['tags'])){
  88. $directory='..'.DIRECTORY_SEPARATOR.'filesystem'.DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR.'tags'.DIRECTORY_SEPARATOR;
  89. $log=array_merge($log,dirCleaner($directory,$cutoff));
  90. }
  91. // Clears API session tokens
  92. if(isset($_GET['all']) || isset($_GET['maintenance']) || isset($_GET['tokens'])){
  93. $directory='..'.DIRECTORY_SEPARATOR.'filesystem'.DIRECTORY_SEPARATOR.'tokens'.DIRECTORY_SEPARATOR;
  94. $log=array_merge($log,dirCleaner($directory,$cutoff));
  95. }
  96. // Clears user sessions
  97. if(isset($_GET['all']) || isset($_GET['maintenance']) || isset($_GET['sessions'])){
  98. $directory='..'.DIRECTORY_SEPARATOR.'filesystem'.DIRECTORY_SEPARATOR.'sessions'.DIRECTORY_SEPARATOR;
  99. $log=array_merge($log,dirCleaner($directory,$cutoff));
  100. }
  101. // Clears cache of JavaScript and CSS
  102. if(isset($_GET['all']) || isset($_GET['maintenance']) || isset($_GET['messenger'])){
  103. $directory='..'.DIRECTORY_SEPARATOR.'filesystem'.DIRECTORY_SEPARATOR.'messenger'.DIRECTORY_SEPARATOR;
  104. $log=array_merge($log,dirCleaner($directory,$cutoff));
  105. }
  106. // Clears request data of user agent IP's
  107. if(isset($_GET['all']) || isset($_GET['maintenance']) || isset($_GET['errors'])){
  108. $directory='..'.DIRECTORY_SEPARATOR.'filesystem'.DIRECTORY_SEPARATOR.'errors'.DIRECTORY_SEPARATOR;
  109. $log=array_merge($log,dirCleaner($directory,$cutoff));
  110. }
  111. // Clears system log
  112. if(isset($_GET['all']) || isset($_GET['maintenance']) || isset($_GET['logs'])){
  113. $directory='..'.DIRECTORY_SEPARATOR.'filesystem'.DIRECTORY_SEPARATOR.'logs'.DIRECTORY_SEPARATOR;
  114. $log=array_merge($log,dirCleaner($directory,$cutoff));
  115. }
  116. // Clears folder from everything that might be stored here
  117. if(isset($_GET['all']) || isset($_GET['maintenance']) || isset($_GET['tmp'])){
  118. $directory='..'.DIRECTORY_SEPARATOR.'filesystem'.DIRECTORY_SEPARATOR.'tmp'.DIRECTORY_SEPARATOR;
  119. $log=array_merge($log,dirCleaner($directory,$cutoff));
  120. }
  121. // Clears request data of user agent IP's
  122. if(isset($_GET['all']) || isset($_GET['limiter'])){
  123. $directory='..'.DIRECTORY_SEPARATOR.'filesystem'.DIRECTORY_SEPARATOR.'limiter'.DIRECTORY_SEPARATOR;
  124. $log=array_merge($log,dirCleaner($directory,$cutoff));
  125. }
  126. // Clears backups
  127. if(isset($_GET['all']) || isset($_GET['backups'])){
  128. $directory='..'.DIRECTORY_SEPARATOR.'filesystem'.DIRECTORY_SEPARATOR.'backups'.DIRECTORY_SEPARATOR;
  129. $log=array_merge($log,dirCleaner($directory,$cutoff));
  130. }
  131. // Clears update archive
  132. if(isset($_GET['all']) || isset($_GET['updates'])){
  133. $directory='..'.DIRECTORY_SEPARATOR.'filesystem'.DIRECTORY_SEPARATOR.'updates'.DIRECTORY_SEPARATOR;
  134. $log=array_merge($log,dirCleaner($directory,$cutoff));
  135. }
  136. // Clears database folder
  137. if(isset($_GET['all']) || isset($_GET['data'])){
  138. $directory='..'.DIRECTORY_SEPARATOR.'filesystem'.DIRECTORY_SEPARATOR.'data'.DIRECTORY_SEPARATOR;
  139. $log=array_merge($log,dirCleaner($directory,$cutoff));
  140. }
  141. // Clears custom user data folder
  142. if(isset($_GET['all']) || isset($_GET['userdata'])){
  143. $directory='..'.DIRECTORY_SEPARATOR.'filesystem'.DIRECTORY_SEPARATOR.'userdata'.DIRECTORY_SEPARATOR;
  144. $log=array_merge($log,dirCleaner($directory,$cutoff));
  145. }
  146. // Clears certificate and key folder
  147. if(isset($_GET['all']) || isset($_GET['keys'])){
  148. $directory='..'.DIRECTORY_SEPARATOR.'filesystem'.DIRECTORY_SEPARATOR.'keys'.DIRECTORY_SEPARATOR;
  149. $log=array_merge($log,dirCleaner($directory,$cutoff));
  150. }
  151. // Clears static files from filesystem
  152. if(isset($_GET['all']) || isset($_GET['static'])){
  153. $directory='..'.DIRECTORY_SEPARATOR.'filesystem'.DIRECTORY_SEPARATOR.'static'.DIRECTORY_SEPARATOR;
  154. $log=array_merge($log,dirCleaner($directory,$cutoff));
  155. }
  156. // Printing out log, if it is not empty
  157. if(!empty($log)){
  158. // Log is returned in plain text format, every log entry in a separate line
  159. echo '<p>';
  160. echo implode('</p><p>',$log);
  161. echo '</p>';
  162. } else {
  163. echo '<p class="box bold">Did not find files to clean</p>';
  164. }
  165. echo '<h2>Modes</h2>';
  166. echo '<p><a href="cleaner.php?maintenance&cutoff='.$cutoff.'">Maintenance</a> - Removes all cache, logs, cookie sessions and temporary files</p>';
  167. echo '<p><a href="cleaner.php?cache&cutoff='.$cutoff.'">Cache</a> - Removes all cache files</p>';
  168. echo '<p><a href="cleaner.php?output&cutoff='.$cutoff.'">Output</a> - API and web cache</p>';
  169. echo '<p><a href="cleaner.php?images&cutoff='.$cutoff.'">Images</a> - On-demand images cache</p>';
  170. echo '<p><a href="cleaner.php?resources&cutoff='.$cutoff.'">Resources</a> - Static resources cache</p>';
  171. echo '<p><a href="cleaner.php?custom&cutoff='.$cutoff.'">Custom</a> - API created cache</p>';
  172. echo '<p><a href="cleaner.php?tags&cutoff='.$cutoff.'">Cache Tags</a> - Cache tag indexes</p>';
  173. echo '<p><a href="cleaner.php?sessions&cutoff='.$cutoff.'">Sessions</a> - User session storage</p>';
  174. echo '<p><a href="cleaner.php?messenger&cutoff='.$cutoff.'">State Messenger</a> - State Messenger database</p>';
  175. echo '<p><a href="cleaner.php?errors&cutoff='.$cutoff.'">Errors</a> - Debugging errors</p>';
  176. echo '<p><a href="cleaner.php?logs&cutoff='.$cutoff.'">Logs</a> - Request logs</p>';
  177. echo '<p><a href="cleaner.php?tmp&cutoff='.$cutoff.'">Temporary Files</a> - Temporary files only</p>';
  178. echo '<p><a href="cleaner.php?limiter&cutoff='.$cutoff.'">Limiter</a> - Request limiter database</p>';
  179. echo '<p><a href="cleaner.php?tokens&cutoff='.$cutoff.'">Tokens</a> - API session tokens</p>';
  180. echo '<p><a href="cleaner.php?backups&cutoff='.$cutoff.'">Backups</a> - Backup archive files</p>';
  181. echo '<p><a href="cleaner.php?updates&cutoff='.$cutoff.'">Updates</a> - Update archive files</p>';
  182. echo '<p><a href="cleaner.php?data&cutoff='.$cutoff.'">Data</a> - Database files, such as for SQLite</p>';
  183. echo '<p><a href="cleaner.php?userdata&cutoff='.$cutoff.'">User Data</a> - Custom files folder for project use</p>';
  184. echo '<p><a href="cleaner.php?keys&cutoff='.$cutoff.'">Keys</a> - Various cryptography keys</p>';
  185. echo '<p><a href="cleaner.php?static&cutoff='.$cutoff.'">Static</a> - Custom static files</p>';
  186. echo '<p><a href="cleaner.php?all&cutoff='.$cutoff.'">All</a> - <b>Caution!</b> Removes all created files and resets entire filesystem folder</p>';
  187. // Footer
  188. echo '<p class="footer small bold">Generated at '.date('d.m.Y h:i').' GMT '.date('P').' for '.$_SERVER['HTTP_HOST'].'</p>';
  189. ?>
  190. </body>
  191. </html>