All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the author nor the names of his contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. CREDITS ==================================================================================== 1. Ray for inspiration. 2. Larry for testing, debugging and documentation. DEAD EASY 3-STEPS INSTALLATION ==================================================================================== 1. Create a new directory "log" in the web public root. 2. Create a new file name "index.php", and copy this source over. 3. Make change to the define statements below to fit your site. **/ // Configuration - Change to fit your thingie ========================== define('ACTIVE', TRUE); define('logsDIR', '/home/example.com/logs/'); define('siteNAME', 'simpleLogReader'); define('sysURL', 'http://example.com/log/'); // assuming index.php in dir /log define('userNAME', 'ray'); define('passWORD', 'pistol'); // Don't need to change from here down! It works as is ================= if (!ACTIVE) die('not active - need to turn it on.'); define('VERSION', '1.01'); define('SOURCE', 'http://56degrees.com/free/simpleLogReader.txt'); ini_set('memory_limit','16M'); session_start(); session_regenerate_id(); if (empty($_SESSION['search'])) $_SESSION['search'] = ''; // Authentication if (!empty($_POST['userName']) && !empty($_POST['passWord'])) { $_SESSION['userName'] = htmlspecialchars($_POST['userName']); $_SESSION['passWord'] = htmlspecialchars($_POST['passWord']); if (!authentic()) { unset($_SESSION['userName']); unset($_SESSION['passWord']); header('location:'.sysURL); } } // Default value if (empty($_SESSION['n'])) $_SESSION['n'] = 'access'; if (!empty($_GET['n'])) { $_GET['n'] = htmlspecialchars($_GET['n']); // Log out => to unset authentication info if ($_GET['n'] == 'logout') { unset($_SESSION['userName']); unset($_SESSION['passWord']); } // Tranfer from $_GET to $_SESSION (stateless to state) elseif ($_GET['n'] == 'archive')$_SESSION['n'] = $_GET['n']; elseif ($_GET['n'] == 'access') $_SESSION['n'] = $_GET['n']; elseif ($_GET['n'] == 'error') $_SESSION['n'] = $_GET['n']; elseif ($_GET['n'] == 'stuff') $_SESSION['n'] = $_GET['n']; elseif ($_GET['n'] == 'phpinfo')$_SESSION['n'] = $_GET['n']; elseif ($_GET['n'] == 'faq') $_SESSION['n'] = $_GET['n']; elseif ($_GET['n'] == 'about') $_SESSION['n'] = $_GET['n']; else { $arr = scandir(logsDIR); if (in_array($_GET['n'], $arr)) { $_SESSION['n'] = $_GET['n']; } } header('location:'.sysURL); } // HTML ========================================================================= // ============================================================================== echo '' ."\n"; echo '' ."\n"; echo '' .siteNAME. ' - simpleLogReader' ."\n"; echo '' ."\n"; echo cssStyleSheet(); echo '' ."\n"; echo '' ."\n"; if (empty($_SESSION['userName'])) echo loginForm(); else { // menu echo ''.siteNAME.':  '; echo 'access log . '; echo 'error log . '; echo 'archive    |    '; echo 'stuff . '; echo 'phpinfo . '; echo 'FAQ    |    '; echo 'logout . '; echo 'about'; echo '
'; // content if ($_SESSION['n'] == 'access') displayLOG(); elseif ($_SESSION['n'] == 'error') displayLOG(); elseif ($_SESSION['n'] == 'archive') echo archiveLogs(); elseif ($_SESSION['n'] == 'stuff') stuff(); elseif ($_SESSION['n'] == 'phpinfo') phpinfo(); elseif ($_SESSION['n'] == 'faq') faq(); elseif ($_SESSION['n'] == 'about') about(); else echo displayArchiveLOG(); } echo '' ."\n"; echo '' ."\n"; exit(); // ============================================================================== // HTML ========================================================================= function displayLOG() { if (!empty($_POST['sBox'])) $_SESSION['search'] = $_POST['sBox']; echo searchForm(); echo "
";
		if (empty($_POST['sBox'])) system("cat -n ".logsDIR.$_SESSION['n']. "_log");
		elseif (empty($_SESSION['search'])) system("cat -n ".logsDIR.$_SESSION['n']. "_log");
		else system("grep '" .$_SESSION['search']. "' ".logsDIR.$_SESSION['n']. "_log | cat -n");
		echo "
"; } function displayArchiveLOG() { if (!empty($_POST['sBox'])) $_SESSION['search'] = $_POST['sBox']; echo searchForm(); $filename = logsDIR.$_SESSION['n']; echo '
';
		if (empty($_POST['sBox'])) system("gzip -dc ".$filename. " | cat -n");
		elseif (empty($_SESSION['search'])) system("gzip -dc ".$filename. " | cat -n");
		else system("gzip -dc ".$filename. " | grep '" .$_SESSION['search']. "' | cat -n");
		echo '
'; } function archiveLogs() { $txt = ''; $arr = scandir(logsDIR); foreach($arr as $file) { if ($file == '.') continue; if ($file == '..') continue; if ($file == '.nodelete') continue; if ($file == 'access_log') continue; if ($file == 'error_log') continue; $txt.= ''.$file.'
'; } $txt = "
" .$txt. "
"; return $txt; } function loginForm() { $str = ''.siteNAME.'
'; $str.= version(); $str.= '
' ."\n"; $str.= '
' ."\n"; $str.= '

' ."\n"; $str.= '' ."\n"; $str.= ''; $str.= '
' ."\n"; $str.= '' ."\n"; $str.= ''; $str.= '
' ."\n"; $str.= '' ."\n"; $str.= ''; $str.= '
' ."\n"; $str.= '
' ."\n"; $str.= '
' ."\n"; $str.= '
' ."\n"; return $str; } function searchForm() { $str = '
' ."\n"; $str.= '
' ."\n"; $str.= '
' ."\n"; $str.= ''; $str.= ''; $str.= '
' ."\n"; $str.= '
' ."\n"; return $str; } function cssStyleSheet() { $str = '' ."\n"; return $str; } function authentic() { return ($_SESSION['userName'] == userNAME) && ($_SESSION['passWord'] == passWORD); } function version() { $str = file_get_contents(SOURCE); if (empty($str)) { $temp = dirname(__FILE__). '/temp' .rand(). '.txt'; $cmd = 'curl ' .SOURCE. ' > ' .$temp; system($cmd); if (is_file($temp)) { $str = file_get_contents($temp); unlink($temp); } } if (empty($str)) return ''; preg_match('/(?<=\'VERSION\',) *\'[\d\.]*\'/', $str, $arr); $latest = str_replace(' ', '', $arr[0]); $latest = str_replace("'", '', $latest); $str = ''; if ($latest != VERSION) { $str = 'current version: ' .VERSION. ' '; $str.= '(latest version: ' .$latest. ' source here)
'; } return $str; } function stuff() { echo '
';
		echo "
"; system('date "+%b %e, %Y. %H:%M"'); echo "IP: " .$_SERVER['REMOTE_ADDR']. "\n"; echo "\n"; echo "still under construction\n"; echo '
'; } function faq() { echo '
';
		echo "
"; echo "1. What is simpleLogReader?\n"; echo "The simpleLogReader is a program that sits on your web page that displays \n"; echo "the contents of your web logs in a plain-text format.\n"; echo "
"; echo "2. What is a log?\n"; echo "A log is merely a listing of actions regarding your web pages.\n"; echo "If someone requests a page, that gets recorded. If, in order to access the page,\n"; echo "several other files are requested, those requests also get recorded. In essence,\n"; echo "every request for information that is sent to your web site is recorded: the time\n"; echo "of the request, who requested it, and what they requested.\n"; echo "
"; echo "3. Are there different kinds of logs?\n"; echo "There are basically two different kinds of logs for a web page, access logs\n"; echo "and error logs. The access logs give information about requests for information\n"; echo "from your web page. That who is accessing the information on your site and what\n"; echo "information they are trying to access.\n"; echo "
"; echo "The error logs record activities that result in web-site errors. The errors could\n"; echo "be requests for pages that don't exist, or they could be more serious errors.\n"; echo "An example of pages that might not exist robots.txt files. Search engines look for\n"; echo "these in case the web-site owner wishes to give them special instructions.\n"; echo "Generally, they aren't necessary.\n"; echo "
"; echo "More serious errors include errors resulting from any bugs in server-side\n"; echo "programming your site might have. If your site serves up only static pages with no\n"; echo "javascripting, includes, data base calls and the like, then error logs are pretty\n"; echo "much useless. If however, you are having problems with your site and you do have\n"; echo "some php, ruby, perl or other such scripts, then viewing error logs can help you\n"; echo "track down coding bugs.\n"; echo "
"; echo "4. Why do I need a log reader?\n"; echo "Reading one's logs is a good way to find and track problems, especially scripting\n"; echo "problems (error logs). You can also track site traffic, i.e. where people are \n"; echo "coming from and what they are requesting. If the requests aren't being fulfilled, \n"; echo "you can find out why and fix those problems. Generally, if you just want to know\n"; echo "how many people are visiting, where from, and what they're looking at, there are\n"; echo "easier-to-use-tools available, such as Google Analytics or AWStats.\n"; echo "
"; echo "5. How do I use simpleLogReader?\n"; echo "You install the source program on a part of your web site and then request the\n"; echo "address of that location on your site. The log file will appear in your browser\n"; echo "window. Installing the program basically means you copy the program into a \n"; echo "folder on your computer and then make some simple edits (see 7.).\n"; echo "
"; echo "For example, if your site is mySite.com and you installed the program into a\n"; echo "subdirectory called 'log', you could enter, mySite.com/log/ in your browser \n"; echo "window. You will then get a log-in page. Once you enter the appropriate data, \n"; echo "you get the current day's log along with links to archives of past logs, error \n"; echo "logs, and several administrative pages, e.g. about and FAQ. To use \n"; echo "simpleLogReader, you do need to be running a web site that allows php scripting.\n"; echo "
"; echo "6. How else can I read my logs?\n"; echo "If you understand Unix, you can log in to your user shell and read the logs\n"; echo "using a command like 'cat' or 'more'. You might have to unzip the log first,\n"; echo "since servers generally store old logs in zipped format.\n"; echo "
"; echo "You can also ftp (or sftp) the log files to your home computer, unzip them\n"; echo "there and then read them in a plain-text viewer, such as TextPad. Windows\n"; echo "NotePad would be a bad choice because for viewing. Not only is it a mediocre\n"; echo "program, but it can only read small files. It also has problems translating\n"; echo "from Unix format to Windows format.\n"; echo "
"; echo "If you use WinZip, it has an internal viewer you can use to view your log files.\n"; echo "
"; echo "There are a host of other viewing options in addition to the ones we mentioned.\n"; echo "Virtually all available viewing options are more complicated than using\n"; echo "simpleLogReader.\n"; echo "
"; echo "7. How do I set simpleLogReader up on my computer?\n"; echo "Setting up is a dead-easy, three-step process.\n"; echo "Just follow the 3 Cs (Create, Copy, Change) and you'll be good to go.\n"; echo "
"; echo " 1. Create a new directory named 'log' in the web public root.\n"; echo "
"; echo " 2. Copy the source code over to 'log' and SaveAs 'index.php'.\n"; echo " You can copy it from the browser window into a\n"; echo " text editor (ctrl+A, ctrl+C, ctrl+V).\n"; echo "
"; echo " 3. Change the 'define()' statements after the program header\n"; echo " documentation to fit your site.\n"; echo " The important ones are\n"; echo " a. logs dir [i.e. where the actual logs are kept on the web server]:\n"; echo " e.g. /users/home/yourUserName/logs/\n"; echo " tor perhaps ~yourUserName/logs/\n"; echo " b. simpleLogReader url: e.g. mySite.com/log\n"; echo " c. log-in name: user name of your choice [e.g. 'ray']\n"; echo " d. password: your favorite password [e.g. 'pistol']\n"; echo "
"; echo "8. Who did this?\n"; echo "This is another creation by the ever-egotistical ngungo.\n"; echo "For another of his useful webmaster tools, check out Monpage.com.\n"; echo "
"; echo "9. Can I give you guys money?\n"; echo "At the moment, simpleLogReader is free.\n"; echo "Some day, perhaps, we'll let you subsidize our efforts.\n"; echo "
"; echo '
'; } function about() { echo version(); echo '
';
		echo "
"; echo "ray said build something.\n"; echo "i built something.\n"; echo "\n"; echo "it's not much, but kinda convenient way to look at the logs.\n"; echo "well! once in a while when I asked something,\n"; echo "linda told me go to look at the logs.\n"; echo "looking at the logs the ssh way is kinda painful for me.\n"; echo "so that's why. Here you can find the latest source.\n"; echo '
'; } ?>