/
index.php
97 lines (85 loc) · 2.48 KB
/
index.php
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
<?php
define("LOGDIR", "./logs/");
main();
/**
* Ich bin die Mainfunktion und werde beim Starten dieses Scripts ausgefuehrt
*/
function main() {
$fn = pathinfo(strip_tags($_GET['show']));
$fn = $fn['filename'];
if(isset($_GET['show'])) {
if($fn == "latest")
$fn=getLatestFile();
$title = "Log vom " . $fn;
$content = getLog($_GET['show']);
} else {
$title = "Channellog";
$files = @scandir(LOGDIR);
rsort($files);
foreach($files AS $file)
if (!strstr($file, "."))
{
$day = substr($file, 5, 2)%2;
$content .= "<tt class='color".$day."'><a href=show/$file>$file</a><br /></tt>";
}
}
echo fillTpl(array($title, $content));
}
/**
* Ich tue die daten aus dem Array title,contents
* in das template index.tpl
*/
function fillTpl($contents) {
$fc = file_get_contents("index.tpl");
$token = array('%title%', '%content%');
$tpl = str_replace($token, $contents, $fc);
return $tpl;
}
/**
* Ich finde die neuste Logdatei anhand ihres names im format YYYY-MM-DD
*/
function getLatestFile() {
$files = @scandir(LOGDIR);
rsort($files);
return $files[0];
}
/**
* Ich lese die Daten aus der Datei mit dem uebergebenen Namen ein
*/
function getLog($name) {
$fn = pathinfo(strip_tags($_GET['show']));
$fn = $fn['filename'];
if($fn == "latest") {
$fn = getLatestFile();
}
if(!is_file(LOGDIR.$fn))
die('you should not do bad requests');
$c = file_get_contents(LOGDIR.$fn, "r");
return return_formated($c);
}
/**
* Ich formatiere das uebergebene Chattlog
*/
function return_formated($string) {
$find = array('/(\[??:??:??\] <)(\w+)([^>]*>)/e',
"/(\[??:??:??\] ! )(\w+)([^\n]*\n)/e",
'`((?:https?|ftp)://\S+[[:alnum:]]([^>\)])/?)`si',
'`((?<!//)(www\.\S+[[:alnum:]]([^>\)])/?))`si');
$replace = array("'] <span class=\"user\"><\\2></span>'",
"'] <span class=\"other\"> ! \\2\\3</span>'",
'<a href="$1" rel="nofollow">$1</a>',
'<a href="http://$1" rel="nofollow">$1</a>');
$uml_orig = array("\n", "ä", "Ä", "ö", "Ö", "ü", "Ü", "ß");
$uml_repl = array("<br />\n" ,"ä", "Ä", "ö", "Ö", "ü", "Ü", "ß");
$string = htmlspecialchars($string);
$string = preg_replace($find, $replace, $string);
$string = str_replace($uml_orig, $uml_repl, $string);
/* $string = explode('</span>', $string);
print_r($string);
foreach($string as &$str) {
$str = "<a name=".md5($str)." href=#".md5($str).">".$str."</a>";
}
$string = implode($string);
*/
return '<tt>'.$string.'</tt>';
}