-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog_script.cgi
executable file
·125 lines (110 loc) · 3 KB
/
log_script.cgi
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
#!/usr/bin/perl
use strict;
my $buffer = $ENV{'QUERY_STRING'};
my ($channel,$date,$enc) = split(/&/,$buffer);
my $i;
my @nick;
my @colors = ('aqua','yellow','lime','fuchsia','orange','Teal','red','Purple','Maroon','Green');
my $logDir = "/home/2TB/irclog/";
my $script_name = "log_script.cgi";
print "Content-type: text/html", "\n\n";
print <<EOM;
<html>\n <head>\n
<link rel="stylesheet" type="text/css" href="../../irclog.css">\n
</head>\n <body>\n<div id="main">
EOM
chdir("$logDir");
my @follist= glob "*/";
if ($buffer == undef){
&getfol;
}elsif($date == undef){
&getfiles;
}else{
&getlog;
}
print <<EOM;
</div>\n</body>\n</html>\n
EOM
sub getlog{
my $folname = $follist[$channel - 1];
print "$folname<br>\n";
chdir("$logDir$folname");
open(IN, $date);
# my $line;
# while ( $line = <IN>) {
# print &rewrite($line);
# }
foreach my $line (<IN>){
print &rewrite($line);
}
print @nick;
close(IN);
}
sub getfiles{
my $req = $channel;
my $folname = $follist[$req - 1];
print "$folname<br>\n aa\n";
chdir("$logDir$folname");
my @filelist= glob "*.txt";
foreach my $file (sort @filelist){
next if( $file =~ /^\.{1,2}$/ );
&href("$script_name?$channel&$file",$file,"br");
}
}
sub getfol{
my $i = 1;
foreach my $direct (@follist){
next if( $direct =~ /^\.{1,2}$/ );
&href("$script_name?$i",$direct,"br");
$i = $i + 1;
}
}
sub href {
my($url, $alt, $br) = @_;
print"<a href\=$url>$alt<\/a>";
if ($br eq "br") {print "<br>";}
print "\n";
}
sub rewrite{
my $string = @_[0];
my $tmp;
my $nick_color;
if($string =~ m/^(\d\d:\d\d)\s\W(\S+?:)/){
$tmp = $2 . "<br>";
if (!grep(/$tmp/,@nick)){
push(@nick,$tmp);
}
}
$nick_color = @colors[(&nick_search($tmp,@nick) % scalar(@colors))];
$string =~ s/</\<\;/g;
$string =~ s/^(\d\d:\d\d)\s\W(\S+?:)/<span style="color:blue;">\1<\/span><span style="color:$nick_color ;"> \2<\/span>/;
if ($string =~ m/.*(http.*?)\s/o){
$tmp = $1;
$string =~ s/(s?https?:\/\/[-_.!~*'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)/<a href=\"$1\" target="_blank" >$1 <\/a>/gi;
if($tmp =~ /(jpg)|(png)|(gif)$/){
return "<img height=200 src=\"$tmp \"><br>" . $string . "<br>\n";
}elsif($tmp =~ /http:\/\/www\.youtube\.com\/.*v=([^&]+).*/){
return "<img height=200 src=\"http\:\/\/i.ytimg\.com\/vi\/$1/default.jpg \"><br>" . $string . "<br>\n";
}elsif($tmp =~ /http:\/\/www\.nicovideo\.jp\/watch\/.*sm([^&]+).*/){
return "<img height=200 src=http://tn-skr2.smilevideo.jp/smile?i=$1 \"><br>" . $string . "<br>\n";
}elsif($tmp =~ /http:\/\/shindanmaker.com\/([^&]+).*/){
return $string ."<br>\n";
}else{
return "<img src=\"http\:\/\/capture.heartrails.com\/\?$tmp \"><br>" . $string . "<br>\n";
}
return $string ."<br>\n";
}else{
return $string . "<br>\n";
}
}
sub rewrite_time{
my $time =@_;
}
sub nick_search {
my $area;
my ($what, @area) = @_;
foreach my $idx (0..$#area) {
if ($area[$idx] =~ /$what/) { return $idx }
}
return -1;
}