1. <?php
  2. /**
  3.  * AbyssWS Log Splitter: v0.1b3
  4.  * Created by: Josh (TRUSTAbyss)
  5.  *
  6.  * Provided by: trustabyss.com and
  7.  * sourceforge.net
  8.  *
  9.  * AbyssWS Log Splitter
  10.  * Copyright (C) 2007 Joshua H.
  11.  *
  12.  * This program is free software; you can redistribute it and/or
  13.  * modify it under the terms of the GNU General Public License
  14.  * as published by the Free Software Foundation; either version 2
  15.  * of the License, or (at your option) any later version.
  16.  *
  17.  * This program is distributed in the hope that it will be useful,
  18.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20.  * GNU General Public License for more details.
  21.  *
  22.  * License Information:
  23.  * http://www.gnu.org/licenses/gpl.txt
  24.  */
  25.  
  26.  
  27. // Please provide the full path to your log file, using forward
  28. // slashes in the path. Default is given.
  29.  
  30. $log_file = "C:/Program Files/Abyss Web Server/log/access.log";
  31.  
  32. // Please provide the Output Directory where your seperated log files
  33. // will be stored. Default is given.
  34.  
  35. $output_dir = "C:/Program Files/Abyss Web Server/log";
  36.  
  37. // Warning! Don't Edit Anthing Else!
  38. // No more configuration is needed. Enjoy!
  39.  
  40. print "Reading log file. Please wait...\n";
  41.  
  42. $start = time();
  43.  
  44. $date_array = array();
  45.  
  46. $fp = fopen($log_file, "r");
  47.  
  48. while (!feof($fp)) {
  49.  
  50. $buffer = fgets($fp, 1024);
  51.  
  52. if (preg_match("/^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\s.+\s.+\s\[[0-9]+\/([a-zA-Z]+)\/([0-9]+)/", $buffer, $match)) {
  53.  
  54. if (!in_array("$match[1]-$match[2]", $date_array)) {
  55.  
  56. $date_array[] = "$match[1]-$match[2]";
  57. }
  58. }
  59. }
  60. fclose($fp);
  61.  
  62. $base_file = basename($log_file);
  63.  
  64. print "Your log file is being seperated. Please wait...\n";
  65.  
  66. foreach ($date_array as $month_year) {
  67.  
  68. $fp = fopen($log_file, "r");
  69.  
  70. $nfp = fopen("$output_dir/$month_year-$base_file", "a");
  71.  
  72. while (!feof($fp)) {
  73.  
  74. $buffer = fgets($fp, 1024);
  75.  
  76. $date_part = explode("-", $month_year);
  77.  
  78. if (preg_match("/^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\s.+\s.+\s\[[0-9]+\/$date_part[0]\/$date_part[1]/", $buffer, $match)) {
  79.  
  80. fwrite($nfp, $buffer);
  81. }
  82. }
  83. fclose($nfp);
  84. }
  85. fclose($fp);
  86.  
  87. $stop = time();
  88.  
  89. $uptime = $stop - $start;
  90.  
  91. $day = floor($uptime/86400);
  92. $hour = floor(($uptime%86400)/3600);
  93. $min = floor(($uptime%3600)/60);
  94. $sec = ($uptime % 60);
  95. $time = "$day Day(s), $hour Hour(s), $min Min(s), $sec Sec(s)";
  96.  
  97. print "\n\nFinished!\n\nTotal Time: " . $time . "\n\n";
  98. ?>