Script to find error log files (specified by php.ini) at and below current directory. With option to view or delete files.
By : opus006
<html><body>
<?php
/*
script: FindErrLog
by: Wayne Nelson
for: codewalkers code forum
scrip to display all error logs at, or below current directory.
Uses log file specified in php.ini: error_log=XXXXXXXXXX
*/
function GetListArray( $fileRoot, $matchFile, $isWin) {
$foundList = array();
$subList = array();
$filePath = ""; //file path relative to current file $ web directories
$path = $fileRoot;
do {
$path = $fileRoot.$filePath;
$Hdir = opendir($path);
if ($Hdir) {
while (false !== ($file = readdir($Hdir))) {
if (($file != '.') && ($file != '..')) {
if ($isWin) {
if ($file === $matchFile)
array_push($foundList, $filePath."\\".$file);
if (is_dir( $fileRoot.$filePath."\\".$file ))
array_push($subList, $filePath."\\".$file);
} // if isWin
else {
if ($file === $matchFile)
array_push($foundList, $filePath.'/'.$file);
if (is_dir( $fileRoot.$filePath.'/'.$file ))
array_push($subList, $filePath.'/'.$file);
} // else isWin
} // if . or ..
} // while file
}// if Hdir
$continue= false;
if (list($key, $val)= each($subList)) {
$continue=true;
$filePath = $val;
array_shift($subList);
} // if subList
} while ($continue);
sort($foundList);
return $foundList;
} // GetListArray function;
//###############################
// main code
//###############################
if (isset($_GET['delete'])) {
$tmp = $_GET['delete'];
// var_dump($tmp);
unlink($tmp);
}
$errFile = ini_get('error_log');
$me = $_SERVER['SCRIPT_NAME'];
$sub = substr( $_SERVER['SCRIPT_NAME'], 0, strrpos($_SERVER['SCRIPT_NAME'], '/'));
$webRoot = 'http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].$sub;
$dirRoot = getcwd();
$isWin = (strrpos($dirRoot, '\\')=== FALSE) ? FALSE : TRUE;
$List = GetListArray( $dirRoot, $errFile, $isWin);
?>
<table width="100%" border="1" cellspacing="2" cellpadding="0">
<tr>
<td></td>
<td><p>List of all log files (specified by "error_log" in php.ini file) at or below the current directory.</p>
<?php
print "<p>error_log setting: $errFile</p>\n";
print "<p>current web directory: $webRoot</p>\n";
print "<p>current file direcory: $dirRoot</p>\n";
foreach ($List as $dir){
$tmp = str_replace("\\", '/', $dir);
$ds = $me.'?delete='.$dirRoot.$dir;
print '<tr><td><a href="'.$webRoot.$tmp.'" target="_blank">view</a></td><td>'.$dir.'</td><td><a href="'.$ds.'">delete</a></td></tr>'."\n";
} // foreach list
print '<tr><td></td><td><form action ="'.$me.'" method="get" name="FindErrLog">'."\n";
?>
<p><input type="submit" name="bnStart" value="Search" border="0"></p>
</form></td>
</table>
</body>
</html>
<?php
flush();
exit;
?>
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More File Manipulation Code Articles
More By Codewalkers
developerWorks - FREE Tools! |
Learn field-tested SOA principles, methodology, technology and implementation from the global SOA market leader - in a new e-book by an IBM SOA expert. Written by IBM Certified SOA Solution Designer Bobby Woolf, "Exploring IBM SOA Technology & Practice" is the ultimate insider's guide to SOA - a PDF e-book packed cover to cover with IBM's specific advice on how to make your SOA implementation a success. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download a free trial version of WebSphere Business Modeler Advanced V6.1.1, IBM’s premier business process modeling and analysis tool for business users that offers process modeling, simulation, and analysis capabilities. IBM WebSphere Business Modeler helps you visualize, understand, and document business processes for continuous improvement. FREE! Go There Now!
|
|
|
|
Join us for this web seminar to learn how you can defend your web applications from attack. Learn about the 3 most common web application attacks, including how they occur and what can be done to prevent them. We’ll also discuss manual versus automated approaches for scanning and identifying web application vulnerabilities and how IBM Rational AppScan, an automated vulnerability scanner, can help you automate more of what you are doing manually today. FREE! Go There Now!
|
|
|
|
Rational Modeling Extension for Microsoft .NET enhances usability for code generation supporting a more intelligent refactoring. The latest enhancements enable organizations with Java and .NET systems and software development maintain architectural integrity across heterogeneous platforms. FREE! Go There Now!
|
|
|
|
Join this Rational Talks to You teleconference on November 29 at 1:00 pm ET to participate in an interactive discusssion with Grady Booch around architecture and reuse. Get your questions answered! FREE! Go There Now!
|
|
|
|
This paper is about the critical role that a discipline called integrated requirements management can play in helping to ensure that your business goals and IT investments are continuously aligned—whether you are sourcing, integrating, building or maintaining software. It also looks at ways that automated IBM Rational® products can work together to help you use requirements in the very best way. FREE! Go There Now!
|
|
|
|
Informix Dynamic Server (IDS) Express Edition offers outstanding online transaction processing (OLTP) database performance, while helping to simplify and automate many of the tasks associated with deploying databases for small business applications. IDS 11 further extends the ease of management and applications integration with the Admin API and Scheduler, high availability with Continuous Log Restore for backup server recovery in case of a primary server failure, and column level encryption to protect personal and company private data. FREE! Go There Now!
|
|
|
|
Join this Rational Talks to You teleconference, to hear how Enterprise Generation Language (EGL) eliminates the need for tedious and error-prone low level coding, so developers can focus on business requirements. EGL extends the Rational software development platform with a simplified programming language that enables developers who have little or no experience with Java, Web technologies or Service Oriented Architecture, to create enterprise-class applications and services quickly and easily. It also allows developers who may have little or no mainframe programming experience to quickly create traditional mainframe components. FREE! Go There Now!
|
|
|
|
Viper 2 brings a great value to developer communities including SQL, XML, PHP, Ruby, .NET and Java. You probably already know that DB2 Express-C is free for developers to develop, deploy and distribute. Viper 2 provides a variety of means that help move your application from the development stage to deployment more rapidly. This webcast shows how to best utilize the latest tools available for developing DB2 applications. FREE! Go There Now!
|
|
|
|
Explore how Rational and WebSphere software enable enterprise documentation in SOA environments. Specifically, a new integration between IBM WebSphere® Business Modeler and IBM Rational® Method Composer software can help technical writers more easily keep enterprise operations manuals in sync with changes that are made to business processes, resulting in more accurate and timely documentation that benefits the entire enterprise. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |