PageRenderTime 12ms CodeModel.GetById 2ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/tools/cleaner.php

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