root/trunk/getmtime/getmtime.cgi

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

maintenance

Line 
1 #!/usr/bin/perl
2 #
3 # �~�XGetModifiedTime rev 1.00
4 #
5 # ���̃t�@�C���͎��Ȃ��N���v�g�ł��B
6 # �ݒ� conf.cgi �ōs���܂��B
7 # �o�[�W�����A�b�v���ɍ����ւ����”\�ł��B
8 #
9 # �g����  HTML�ɋL�q�����O�̕��@
10 #     <!--#include virtual="�p�X/getmtime.cgi?no=�e���v���[�g�ԍ�&see=����gi�����p�X*����gi�����p�X*etc..." -->
11 #   �L�q��#     <!--#include virtual="./cgi-bin/ccgetmtime/getmtime.cgi?no=1&see=../../htdocs/index.html" -->
12 #     <!--#include virtual="./cgi-bin/ccgetmtime/getmtime.cgi?no=1&see=../../htdocs/index.html*../../htdocs/update.html" -->
13 #
14 # �~�ϑ���l�i���̃T�C�g�j
15 # http://www.akiyan.com/
16 #
17 # �Ƃقق�SI�� http://tohoho.wakusei.ne.jp/wwwssi.htm
18 #
19 # �X�V���� 2002/01/02 rev1.00 ��B
20 #
21 require 'jcode.pl';
22 require 'conf.cgi';
23 &get_query_string();
24
25         $MESSAGE{'file_error'} = '[CC GetModifiedTime error. Was not able to acquire the information on the file(s).]';
26         $MESSAGE{'none_argument_error'} = '[CC GetModifiedTime error. There is no argument. Or, an argument is not right.]';
27         @SEE = split(/\*/, $FORM{'see'});
28         print &content_type('text/html');
29         if ($#SEE >= 0 && $FORM{'no'} > 0 && $FORM{'no'} < 10) {
30                 &put(&main());
31                 exit;
32         }
33         &put($MESSAGE{'none_argument_error'});
34         exit;
35
36 sub main
37 {
38         local %data;
39         local ($body, $bk_time, $latest_time) = ($CONF{'template'.$FORM{'no'}}, 0, 0);
40         foreach my $path (@SEE) {
41                 my $mtime = (stat($path))[9];
42                 $latest_time = ($mtime > $bk_time) ? $mtime : $bk_time;
43                 $bk_time = $mtime;
44         }
45         if ($latest_time > 0) {
46                 ($data{'sec'}
47                 ,$data{'min'}
48                 ,$data{'hour'}
49                 ,$data{'mday'}
50                 ,$data{'mon'}
51                 ,$data{'YEAR'}
52                 ,$data{'wday'}
53                 ,$data{'yday'}
54                 ,$data{'isdst'}) = localtime($latest_time + $CONF{'timediff'});
55                 $data{'YEAR'} += ($data{'YEAR'} < 1900) ? 1900 : 0;
56                 $data{'year'} = substr($data{'YEAR'}, 2);
57                 $data{'MON'}  = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec')[$data{'mon'}];
58                 $data{'mon'}  = &enforce_figure($data{'mon'} + 1, 2);
59                 $data{'mday'} = &enforce_figure($data{'mday'}, 2);
60                 $data{'WDAY'} = ('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat')[$data{'wday'}];
61                 $data{'wday'} = ('����', '��, '��', '��, '�� 'y')[$data{'wday'}];
62                 $data{'hour'} = &enforce_figure($data{'hour'}, 2);
63                 $data{'min'}  = &enforce_figure($data{'min'}, 2);
64                 $data{'sec'}  = &enforce_figure($data{'sec'}, 2);
65                 $body = &replace_hash(*data, $body);
66                 return($body);
67         } else {
68                 return($MESSAGE{'file_error'});
69         }
70 }
71
72 sub put
73 {
74         local($html) = @_;
75         if ($CONF{'charset'} ne "" && $CONF{'charset'} ne "sjis") {
76                 &jcode'convert(*html, $CONF{'charset'});
77         }
78         print $html;
79 }
80
81 #____�T�u���[�`���Q
82
83 ###
84 # �N�G���[������ǂݍ���
85 #
86 # @return void
87 #
88 sub get_query_string
89 {
90         local($conv) = @_;
91         local($a, $name, $value, $query_string);
92         if ($ENV{'REQUEST_METHOD'} eq "POST") {
93                 read(STDIN, $query_string, $ENV{'CONTENT_LENGTH'});
94         } else {
95                 $query_string = $ENV{'QUERY_STRING'};
96         }
97         @a = split(/\&/, $query_string);
98         foreach $a (@a) {
99                 ($name, $value) = split(/=/, $a);
100                 $value =~ tr/+/ /;
101                 $value =~ s/%([0-9a-fA-F][0-9a-fA-F])/pack("C", hex($1))/eg;
102                 if ( $conv ne "" ) {
103                         &jcode::convert(\$value,$conv);
104                 }
105                 $FORM{$name} = $value;
106         }
107 }
108
109 ###
110 # content-type�w�b�_
111 # @param string
112 #
113 # @return string
114 #
115 sub content_type
116 {
117         if ($_content_type_printed) {
118                 return("");
119         }
120         $_content_type_printed = 1;
121         return("Content-type: $_[0]\n\n");
122 }
123
124 ###
125 # {}�Ɉ͂܂ꂽ�L�[��b�V���Œu��
126 #
127 # @param *hash �u�������[�ƒl
128 # @param string �u���Ώ�
129 #
130 # @return string �u���ς̑Ώ�
131 #
132 sub replace_hash
133 {
134         local(*hash, $body) = @_;
135         local($key, $value);
136         while ( ($key, $value) = each %hash) {
137         $body =~ s/\{$key\}/$value/g;
138         }
139         return($body);
140 }
141
142 ###
143 # �t�@�C���̏��𓾂�# @param string �p�X
144 #
145 # @return hash �t�@�C���̏�
146 #
147 sub file_state
148 {
149         my($path) = @_;
150         my %data;
151         ($data{'dev'},
152          $data{'ino'},
153          $data{'mode'},
154          $data{'nlink'},
155          $data{'uid'},
156          $data{'gid'},
157          $data{'rdev'},
158          $data{'size'},
159          $data{'atime'},
160          $data{'mtime'},
161          $data{'ctime'},
162          $data{'blksize'},
163          $data{'blocks'}) = stat($path);
164         return(%data);
165 }
166
167 sub enforce_figure
168 {
169         local($string, $figure) = @_;
170         return(substr('0000000000000000' . $string, 16 + length($string) - $figure, $figure));
171 }
Note: See TracBrowser for help on using the browser.