Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- <?php
- require("colorparser.php");
- function makeClickableLinks($s)
- {
- return preg_replace('@(https?://([-\w\.]+[-\w])+(:\d+)?(/([\w/_\.#-]*(\?\S+)?[^\.\s])?)?)@', '<a href="$1" target="_blank">$1</a>', $s);
- }
- function parseLine($line)
- {
- /**
- * "Normal" lines.
- */
- if (preg_match('/^\[(?<time>\d{2}:\d{2}(:\d{2})?)\] <(?<nick>\S+)> (?<line>.+)$/', $line, $matches)) {
- $line = "[$matches[time]] <$matches[nick]> $matches[line]";
- /**
- * "Join" lines.
- */
- } elseif (preg_match('/^\[(?<time>\d{2}:\d{2}(:\d{2})?)\] \*\*\* Joins: (?<nick>\S+) \((?<host>\S+)\)$/', $line, $matches)) {
- $line = "<font color=\"green\">[$matches[time]] *** Joins: $matches[nick] ($matches[host])</font>";
- /**
- * "Quit" lines.
- */
- } elseif (preg_match('/^\[(?<time>\d{2}:\d{2}(:\d{2})?)\] \*\*\* Quits: (?<nick>\S+) \((?<host>\S+)\) \((?<reason>.*\))$/', $line, $matches)) {
- $line = "<font color=\"red\">[$matches[time]] *** Quits: $matches[nick] ($matches[host]) ($matches[reason])</font>";
- /**
- * "Mode" lines.
- */
- } elseif (preg_match('/^\[(?<time>\d{2}:\d{2}(:\d{2})?)\] \*\*\* (?<nick_performing>\S+) sets mode: (?<modes>[-+][ov]+([-+][ov]+)?) (?<nicks_undergoing>\S+( \S+)*)$/', $line, $matches)) {
- $modenum = 0;
- $nicks_undergoing = explode(' ', $matches['nicks_undergoing']);
- for ($i = 0, $j = strlen($matches['modes']); $i < $j; $i++) {
- $mode = substr($matches['modes'], $i, 1);
- if ($mode === '-' || $mode === '+') {
- $modesign = $mode;
- } else {
- $line = "<font color=\"darkgrey\">[$matches[time]] $matches[nick_performing] sets mode: $modesign$mode on $nicks_undergoing[$modenum]</font>";
- $modenum++;
- }
- }
- //Actions
- } elseif (preg_match('/^\[(?<time>\d{2}:\d{2}(:\d{2})?)\] \* (?<line>(?<nick_performing>\S+) ((?<slap>[sS][lL][aA][pP][sS]( (?<nick_undergoing>\S+)( .+)?)?)|(.+)))$/', $line, $matches)) {
- $line = "<font color=\"purple\">[$matches[time]] * $matches[line]</font>";
- //"Nickchange" lines.
- } elseif (preg_match('/^\[(?<time>\d{2}:\d{2}(:\d{2})?)\] \*\*\* (?<nick_performing>\S+) is now known as (?<nick_undergoing>\S+)$/', $line, $matches)) {
- $line = "<font color=\"blue\">[$matches[time]] *** $matches[nick_performing] is now known as $matches[nick_undergoing]</font>";
- //"Part" lines.
- } elseif (preg_match('/^\[(?<time>\d{2}:\d{2}(:\d{2})?)\] \*\*\* Parts: (?<nick>\S+) \(\S+\)( \(.*\))?$/', $line, $matches)) {
- //$line = "<font color=\"red\">
- /**$this->set_part($matches['time'], $matches['nick']);
- * "Topic" lines.
- */
- } elseif (preg_match('/^\[(?<time>\d{2}:\d{2}(:\d{2})?)\] \*\*\* (?<nick>\S+) changes topic to \'(?<line>.+)\'$/', $line, $matches)) {
- /**if ($matches['line'] !== ' ') {
- $this->set_topic($matches['time'], $matches['nick'], $matches['line']);
- }
- * "Kick" lines.
- */
- } elseif (preg_match('/^\[(?<time>\d{2}:\d{2}(:\d{2})?)\] \*\*\* (?<line>(?<nick_undergoing>\S+) was kicked by (?<nick_performing>\S+) \(.*\))$/', $line, $matches)) {
- /** $this->set_kick($matches['time'], $matches['nick_performing'], $matches['nick_undergoing'], $matches['line']); */
- }
- return $line;
- }
- $escaped = preg_replace('/[^A-Za-z0-9_\-]\./', '_', $_GET['log']);
- $buffer = ob_get_clean();
- $tidy = new tidy();
- if (!isset($_GET['plain'])) {
- $buffer = "<head>
- <title>OCLogs: $escaped</title>
- <script type=\"text/javascript\"
- src=\"//ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js\">
- </script>
- <script type=\"text/javascript\" language=\"javascript\">
- $(function () {
- $('#scrlBotm').click(function () {
- $('html, body').animate({
- scrollTop: $(document).height()
- },
- 1500);
- return false;
- });
- $('#scrlTop').click(function () {
- $('html, body').animate({
- scrollTop: '0px'
- },
- 1500);
- return false;
- });
- });
- </script>
- </head>
- </body>";
- }
- $mcp = new MircColorParser();
- $linenum = 1;
- if ($escaped != "") {
- $handle = fopen($escaped, "r");
- if (!isset($_GET['plain'])) {
- date_default_timezone_set(timezone_name_from_abbr("CST"));
- $yesterday = date('Y-m-d', strtotime( str_replace(".log", "", $escaped) . ' -1 day' ));
- $tomorrow = date('Y-m-d', strtotime( str_replace(".log", "", $escaped) . ' +1 day' ));
- if (file_exists($yesterday . ".log")) {
- $buffer .= "<a href=\"parser?log=$yesterday.log\"><<Prev</a> ";
- }
- if (file_exists($tomorrow . ".log")) {
- $buffer .= "<a href=\"parser?log=$tomorrow.log\">Next>></a> ";
- }
- $buffer .= "<a id=\"scrlBotm\" href=\"#\">Scroll to Bottom</a> <a href=\"parser?log=$escaped&refresh#bottom\">Auto Refresh</a><br>";
- }
- if ($handle) {
- while (($line = fgets($handle)) !== false) {
- $line = htmlspecialchars($line);
- if (!isset($_GET['plain'])) {
- //$line = parseToHTML($line);
- $line = $mcp->colorize($line);
- $line = parseLine($line);
- }
- if (isset($_GET['linenum'])) {
- $line = "$linenum: " . $line;
- }
- $line = makeClickableLinks($line);
- $buffer .= $line . "<br>";
- $linenum++;
- }
- fclose($handle);
- } else {
- // error opening the file.
- }
- if (!isset($_GET['plain'])) {
- date_default_timezone_set(timezone_name_from_abbr("CST"));
- $yesterday = date('Y-m-d', strtotime( str_replace(".log", "", $escaped) . ' -1 day' ));
- $tomorrow = date('Y-m-d', strtotime( str_replace(".log", "", $escaped) . ' +1 day' ));
- if (file_exists($yesterday . ".log")) {
- $buffer .= "<a href=\"parser?log=$yesterday.log\"><<Prev</a> ";
- }
- if (file_exists($tomorrow . ".log")) {
- $buffer .= "<a href=\"parser?log=$tomorrow.log\">Next>></a> ";
- }
- $buffer .= "<a id=\"scrlTop\" href=\"#\">Scroll to Top</a> ";
- if (!isset($_GET['refresh'])) {
- $buffer .= "<a href=\"parser?log=$escaped&refresh#bottom\">Auto Refresh</a> ";
- } else {
- $buffer .= "<a href=\"parser?log=$escaped#bottom\">Stop Auto Refresh</a> ";
- $buffer .= "<script type=\"text/javascript\">
- window.setInterval(function() {
- window.location.href = '\parser?log=$escaped&refresh#bottom';
- location.reload();
- }, 5000);
- </script>";
- }
- $buffer .= "<a name=\"bottom\"> </a></body></html>";
- $buffer = $tidy->repairString($buffer, array(
- 'preserve-entities' => true
- ), "utf8");
- }
- echo $buffer;
- } else {
- echo "No log file specified";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment