root/trunk/dlcounter/dlcounter.cgi

Revision 115, 7.4 kB (checked in by akiyan, 2 years ago)

maintenance

Line 
1 #!/usr/local/bin/perl
2
3 # �������c�c�E�E����
4
5 # ���C�u�����ւ̃p�X
6 require './cclib.pl';
7
8 # �Ǘ��p�X���[�h�i�K���ύX���邱�ƁI�I�j
9 $password = '1234';
10
11 # CGI�t�@�C����
12 $cgifilename = 'dlcounter.cgi';
13
14 # ���O�t�@�C����
15 $logfilename = 'dlcounter.log';
16
17 # �������c�c�E�E�ݒ肱���܂�
18
19         $admin_bgcolor       = "#FFFFFF" ;
20         $admin_bgcolor_table = "#DDDDDD" ;
21         $admin_fontcolor     = "#000000" ;
22         $admin_bordercolor   = "#666666" ;
23
24         &formdecord();
25         $f_name = $FORM{'name'};
26         $f_url  = $FORM{'url'};
27
28         if ( ( $FORM{'url'} ne "" ) and ( $FORM{'name'} ne "" ) ) { &mode_download(); exit }
29         if ( ( $FORM{'url'} ne "" ) and ( $FORM{'name'} eq "" ) ) { &error('�p�����[�^���������� exit }
30         if ( ( $FORM{'mode'} eq "admin" ) && ( $FORM{'password'} eq $password ) ) { &mode_admin(); exit; }
31         if ( ( $FORM{'mode'} eq "edit" ) && ( $FORM{'password'} eq $password ) ) { &mode_edit(); exit; }
32         if ( ( $FORM{'mode'} eq "editwrite" ) && ( $FORM{'password'} eq $password ) ) { &mode_editwrite(); exit; }
33         &mode_login();
34
35 exit;
36
37 # �������c�c�E�E�_�E�����[�h
38 sub mode_download {
39
40         # ���O�ǂݍ���
41         open ( IN , "< $logfilename" );
42         chop(@log = <IN>);
43         close(IN);
44
45         foreach $fr (@log) {
46                 @data = split(/\t/,$fr);
47                 ( $count{$data[1]} , $name{$data[1]} , $url{$data[1]} , $date{$data[1]} ) = @data;
48         }
49
50         $count{$f_name}++;
51         $name{$f_name} = $f_name;
52         $url{$f_name} = $f_url;
53         $time = time();
54         $date{$f_name} = $time;
55
56         # ���O�����o��
57         open ( OUT , "> $logfilename" );
58         while (($key , $value) = each(%name)) {
59                 print (OUT "$count{$key}\t$name{$key}\t$url{$key}\t$date{$key}\n");
60         }
61         close(OUT);
62         print "location: $f_url\n\n";
63 }
64
65 # �������c�c�E�E���O�C�����[�h
66
67 sub mode_login
68 {
69         $message = "�p�X���[�h��͂��Ă�������";
70         if ( $FORM{'mode'} eq "admin" ) {
71                 $message = "<b><font color=red>�p�X���[�h���Ԉ��Ă��܂�</font></b>";
72         }
73         &htmlheader();
74         &puthtml("top","�~�X�_�E�����[�h�J�E���^�[�Ǘ��y�[�W","$admin_fontcolor","$admin_bgcolor");
75         print <<"HTML";
76 <h2 style="font-size:100%">�� ���O�C��</h2>
77 <form name="form" method="post" action="$cgifilename" style="display:inline">
78 <div style="margin-left:2em">
79 $message<br>
80 <input type="password" name="password" size="12" value="">
81 <input type="submit" name="submit" value="���O�C��">
82 <input type="hidden" name="mode" value="admin">
83 </div>
84 </form>
85 HTML
86         &puthtml("bottom");
87 }
88
89 # �������c�c�E�E�Ǘ����[�h
90
91 sub mode_admin
92 {
93         &loadlog();
94         &htmlheader();
95         &puthtml("top","�~�X�_�E�����[�h�J�E���^�[�Ǘ��y�[�W");
96         $tdmargin = "20";
97         print <<"HTML";
98 <div align="center">
99 <table frame="border" rules="groups" border="1" bordercolor="$admin_bordercolor" cellspacing="0" cellpadding="4">
100 <thead><tr style="font-weight:bold;background-color:$admin_bgcolor_table"><td>����/td><td>���O</td><td>DL��</td><td>�ŏIDL��></tr></thead>
101 <tbody>
102 HTML
103
104         $no = 1;
105         $count_total = 0;
106         foreach $fr (@s_count) {
107                 ( $a , $name ) = split ( /\t/ , $fr );
108                 &maketime($date{$name});
109                 print <<"HTML";
110 <tr style="font-size: 90% ; line-height: 130%"><td style="text-align:right">$no</td><td><a href=$url{$name}>$name</a></td><td style="text-align:right">$count{$name}</td><td>$year/$mon/$mday $hour:$min</td></tr>
111 HTML
112                 $no++;
113                 $count_total += $count{$name};
114         }
115
116         print <<"HTML";
117 <tr style="font-size: 90% ; line-height: 130%;background-color:$admin_bgcolor_table"><td style="text-align:right"></td><td><strong>�v</strong></td><td style="text-align:right"><strong>$count_total</strong></td><td></td></tr>
118 </tbody>
119 </table>
120 </div>
121 <div align="center">
122 <form name="form" method="post" action="$cgifilename" style="display:inline">
123 <input type="hidden" name="mode" value="admin">
124 <input type="hidden" name="password" value="$password">
125 <input type="submit" name="submit" value="�X�V">
126 </form>
127 <form name="form" method="post" action="$cgifilename" style="display:inline">
128 <input type="hidden" name="mode" value="edit">
129 <input type="hidden" name="password" value="$password">
130 <input type="submit" name="submit" value="�f�[�^�ҏW">
131 </form>
132 </div>
133 HTML
134         &puthtml("bottom");
135 }
136
137 # �������c�c�E�E�f�[�^�ҏW���[�h
138
139 sub mode_edit
140 {
141         &loadlog();
142         &htmlheader();
143         &puthtml("top","�~�X�_�E�����[�h�J�E���^�[�Ǘ��y�[�W");
144         $tdmargin = "20";
145         print <<"HTML";
146 <form name="form" method="post" action="$cgifilename">
147 <UL>
148 <LI>���ڂ�������ꍇ�́A���O������ɂ��ĉ�����</LI>
149 <LI>���ڂ��������ꍇ�́A�ʼn��ʂ̋󗓂ɓ�ĉ�����</LI>
150 </UL>
151 <div align="center">
152 <table frame="border" rules="groups" border="1" bordercolor="$admin_bordercolor" cellspacing="0" cellpadding="4">
153 <thead>
154 <tr style="font-weight: bold" bgcolor="$admin_bgcolor_table"><td>���O</td><td>DL��</td></tr></thead>
155 <tbody>
156 HTML
157
158         $no = 1;
159         foreach $fr (@s_count) {
160                 ( $a , $name ) = split ( /\t/ , $fr );
161                 # &maketime($date{$name});
162                 print <<"HTML";
163 <tr style="font-size: 90% ; line-height: 130%">
164 <td><input type="text" name="name$no" value="$name" size="16"></td>
165 <td><input type="text" name="count$no" value="$count{$name}" size="10"></td>
166 <input type="hidden" name="nameold$no" value="$name">
167 <input type="hidden" name="url$no" value="$url{$name}">
168 <input type="hidden" name="date$no" value="$date{$name}">
169 </tr>
170 HTML
171                 $no++;
172         }
173         $date = time();
174         print <<"HTML";
175 <tr style="font-size: 90% ; line-height: 130%">
176 <td><input type="text" name="name$no" value="" size="16"></td>
177 <td align="right"><input type="text" name="count$no" value="" size="10"></td>
178 <input type="hidden" name="url$no" value="">
179 <input type="hidden" name="date$no" value="$date">
180 </tr>
181 HTML
182
183         print <<"HTML";
184 </tbody>
185 </table>
186 <input type="hidden" name="mode" value="editwrite">
187 <input type="hidden" name="password" value="$password">
188 <input type="hidden" name="dataquantity" value="$no">
189 <p>
190 <input type="submit" name="submit" value="���M">
191 </p>
192 </form>
193 <form name="form" method="post" action="$cgifilename">
194 <input type="hidden" name="mode" value="admin">
195 <input type="hidden" name="password" value="$password">
196 <input type="submit" name="submit" value="�߂�
197 </form>
198 </div>
199 HTML
200         &puthtml("bottom");
201 }
202
203 # �������c�c�E�E�f�[�^����������s
204 sub mode_editwrite()
205 {
206         # ���O�����o��
207         open ( OUT , "> $logfilename" );
208         for ( $fo = 1 ; $fo <= $FORM{dataquantity} ; $fo++ ) {
209                 $count = $FORM{'count'.$fo};
210                 $name = $FORM{'name'.$fo};
211                 $url = $FORM{'url'.$fo};
212                 $date = $FORM{'date'.$fo};
213                 if ( $name ne "" ) {
214                         print (OUT "$count\t$name\t$url\t$date\n");
215                 }
216         }
217         close(OUT);
218         &mode_admin();
219 }
220
221 # �������c�c�E�E����GI��L�̃��C�u�������[�`��
222 sub loadlog {
223         # ���O�ǂݍ���
224         open ( IN , "< $logfilename" );
225         chop(@log = <IN>);
226         close(IN);
227
228         foreach $fr (@log) {
229                 @data = split(/\t/,$fr);
230                 ( $count , $name , $url , $date ) = @data;
231                 ( $count{$name} , $name{$name} , $url{$name} , $date{$name} ) = @data;
232                 $count = substr ( '0000000000'.$count , length ( $count ) );
233                 push ( @s_count , "$count\t$name" );
234                 push ( @s_name  , "$name\t$name" );
235                 push ( @s_url   , "$url\t$name" );
236                 push ( @s_date  , "$date\t$name" );
237         }
238         @s_count = reverse ( sort ( @s_count ) );
239         @s_name  = sort ( @s_name );
240         @s_url   = sort ( @s_url );
241         @s_date  = reverse ( sort ( @s_date ) );
242 }
243
244 # �������c�c�E�E���C�u�������[�`��
245
246 # �G���[�\��
247 sub error {
248         print <<"HTML";
249 <head>
250 <meta http-equiv="Content-Type" content="text/html; charset=x-sjis">
251 <title>�_�E�����[�h�J�E���^�[�G���[</title>
252 </head>
253 <body>
254 <h3>�_�E�����[�h�J�E���^�[�G���[</h3>
255 <hr>
256 $_[0]
257 </body>
258 HTML
259 }
Note: See TracBrowser for help on using the browser.