… | |
… | |
99 | (tied %diridx)->db_sync; |
99 | (tied %diridx)->db_sync; |
100 | |
100 | |
101 | $$statdata; |
101 | $$statdata; |
102 | } |
102 | } |
103 | |
103 | |
104 | sub conn::diridx { |
|
|
105 | my $self = shift; |
|
|
106 | |
|
|
107 | my $data = $self->get_statdata; |
|
|
108 | |
|
|
109 | my $uptime = int (time - $::starttime); |
|
|
110 | $uptime = sprintf "%02dd %02d:%02d", |
|
|
111 | int ($uptime / (60 * 60 * 24)), |
|
|
112 | int ($uptime / (60 * 60)) % 24, |
|
|
113 | int ($uptime / 60) % 60; |
|
|
114 | |
|
|
115 | my $stat; |
|
|
116 | if ($data->{dlen}) { |
|
|
117 | $stat .= "<table><tr><th>Directories</th></tr>"; |
|
|
118 | $data->{dlen} += 1; |
|
|
119 | my $cols = int ((79 + $data->{dlen}) / $data->{dlen}); |
|
|
120 | $cols = @{$data->{d}} if @{$data->{d}} < $cols; |
|
|
121 | my $col = $cols; |
|
|
122 | for (@{$data->{d}}) { |
|
|
123 | if (++$col >= $cols) { |
|
|
124 | $stat .= "<tr>"; |
|
|
125 | $col = 0; |
|
|
126 | } |
|
|
127 | if ("$self->{path}$_" =~ $conn::blockuri{$self->{country}}) { |
|
|
128 | $stat .= "<td>$_ "; |
|
|
129 | } else { |
|
|
130 | $stat .= "<td><a href='".escape_uri("$_/")."'>$_</a> "; |
|
|
131 | } |
|
|
132 | } |
|
|
133 | $stat .= "</table>"; |
|
|
134 | } |
|
|
135 | if ($data->{flen}) { |
|
|
136 | $data->{flen} += 1 + $data->{slen} + 1 + 3; |
|
|
137 | my $cols = int ((79 + $data->{flen}) / $data->{flen}); |
|
|
138 | $cols = @{$data->{f}} if @{$data->{f}} < $cols; |
|
|
139 | my $col = $cols; |
|
|
140 | $stat .= "<table><tr>". ("<th align='left'>File<th>Size<th> " x $cols); |
|
|
141 | for (@{$data->{f}}) { |
|
|
142 | if (++$col >= $cols) { |
|
|
143 | $stat .= "<tr>"; |
|
|
144 | $col = 0; |
|
|
145 | } |
|
|
146 | $stat .= "<td><a href='".escape_uri($_->[0])."'>$_->[0]</a><td align='right'>$_->[1]<td> "; |
|
|
147 | } |
|
|
148 | $stat .= "</table>"; |
|
|
149 | } |
|
|
150 | |
|
|
151 | my $waiters = sprintf "%d/%d", $::transfers[0][0]->waiters+0, $::transfers[1][0]->waiters+0; |
|
|
152 | my $avgtime = sprintf "%d/%d second(s)", $::transfers[0][1], $::transfers[1][1]; |
|
|
153 | |
|
|
154 | <<EOF; |
|
|
155 | <html> |
|
|
156 | <head><title>$self->{uri}</title></head> |
|
|
157 | <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#000080" alink="#ff0000"> |
|
|
158 | <h1>$data->{path}</h1> |
|
|
159 | $data->{top} |
|
|
160 | <small><div align="right"> |
|
|
161 | <tt>$self->{remote_id}/$self->{country} - $::conns connection(s) - uptime $uptime - myhttpd/$VERSION |
|
|
162 | </tt></div></small> |
|
|
163 | <hr /> |
|
|
164 | clients waiting for data transfer: $waiters<br /> |
|
|
165 | average waiting time until transfer starts: $avgtime <small>(adjust your timeout values)</small><br /> |
|
|
166 | <hr /> |
|
|
167 | $stat |
|
|
168 | $data->{bot} |
|
|
169 | </body> |
|
|
170 | </html> |
|
|
171 | EOF |
|
|
172 | } |
|
|
173 | |
|
|
174 | sub handle_redirect { # unused |
104 | sub handle_redirect { # unused |
175 | if (-f ".redirect") { |
105 | if (-f ".redirect") { |
176 | if (open R, "<.redirect") { |
106 | if (open R, "<.redirect") { |
177 | while (<R>) { |
107 | while (<R>) { |
178 | if (/^(?:$host$port)$uri([^ \tr\n]*)[ \t\r\n]+(.*)$/) { |
108 | if (/^(?:$host$port)$uri([^ \tr\n]*)[ \t\r\n]+(.*)$/) { |
… | |
… | |
202 | } |
132 | } |
203 | } |
133 | } |
204 | } |
134 | } |
205 | } |
135 | } |
206 | |
136 | |
|
|
137 | sub format_time { |
|
|
138 | sprintf "%02dd %02d:%02d:%02d", |
|
|
139 | int ($_[0] / (60 * 60 * 24)), |
|
|
140 | int ($_[0] / (60 * 60)) % 24, |
|
|
141 | int ($_[0] / 60) % 60, |
|
|
142 | int ($_[0]) % 60; |
|
|
143 | } |
|
|
144 | |
|
|
145 | sub conn::diridx { |
|
|
146 | my $self = shift; |
|
|
147 | |
|
|
148 | my $data = $self->get_statdata; |
|
|
149 | |
|
|
150 | my $stat; |
|
|
151 | if ($data->{dlen}) { |
|
|
152 | $stat .= "<table><tr><th>Directories</th></tr>"; |
|
|
153 | $data->{dlen} += 1; |
|
|
154 | my $cols = int ((79 + $data->{dlen}) / $data->{dlen}); |
|
|
155 | $cols = @{$data->{d}} if @{$data->{d}} < $cols; |
|
|
156 | my $col = $cols; |
|
|
157 | for (@{$data->{d}}) { |
|
|
158 | if (++$col >= $cols) { |
|
|
159 | $stat .= "<tr>"; |
|
|
160 | $col = 0; |
|
|
161 | } |
|
|
162 | if ("$self->{path}$_" =~ $conn::blockuri{$self->{country}}) { |
|
|
163 | $stat .= "<td>$_ "; |
|
|
164 | } else { |
|
|
165 | $stat .= "<td><a href='".escape_uri("$_/")."'>$_</a> "; |
|
|
166 | } |
|
|
167 | } |
|
|
168 | $stat .= "</table>"; |
|
|
169 | } |
|
|
170 | if ($data->{flen}) { |
|
|
171 | $data->{flen} += 1 + $data->{slen} + 1 + 3; |
|
|
172 | my $cols = int ((79 + $data->{flen}) / $data->{flen}); |
|
|
173 | $cols = @{$data->{f}} if @{$data->{f}} < $cols; |
|
|
174 | my $col = $cols; |
|
|
175 | $stat .= "<table><tr>". ("<th align='left'>File<th>Size<th> " x $cols); |
|
|
176 | for (@{$data->{f}}) { |
|
|
177 | if (++$col >= $cols) { |
|
|
178 | $stat .= "<tr>"; |
|
|
179 | $col = 0; |
|
|
180 | } |
|
|
181 | $stat .= "<td><a href='".escape_uri($_->[0])."'>$_->[0]</a><td align='right'>$_->[1]<td> "; |
|
|
182 | } |
|
|
183 | $stat .= "</table>"; |
|
|
184 | } |
|
|
185 | |
|
|
186 | <<EOF; |
|
|
187 | <html> |
|
|
188 | <head><title>$self->{uri}</title></head> |
|
|
189 | <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#000080" alink="#ff0000"> |
|
|
190 | <h1>$data->{path}</h1> |
|
|
191 | $data->{top} |
|
|
192 | <hr /> |
|
|
193 | <a href="/internal/status">Server Status Page & Queueing Info</a> |
|
|
194 | <hr /> |
|
|
195 | $stat |
|
|
196 | $data->{bot} |
|
|
197 | </body> |
|
|
198 | </html> |
|
|
199 | EOF |
|
|
200 | } |
|
|
201 | |
|
|
202 | $::internal{status} = sub { |
|
|
203 | my $self = shift; |
|
|
204 | |
|
|
205 | my $uptime = format_time ($::NOW - $::starttime); |
|
|
206 | |
|
|
207 | my $content = <<EOF; |
|
|
208 | <html> |
|
|
209 | <head><title>Server Status Page</title></head> |
|
|
210 | <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#000080" alink="#ff0000"> |
|
|
211 | <h1>Server Status Page</h1> |
|
|
212 | <h2>Myhttpd</h2> |
|
|
213 | version <b>$VERSION</b>; current connections count: <b>$::conns</b>; uptime: <b>$uptime</b>;<br /> |
|
|
214 | client-iD <b>$self->{remote_id}</b>, client country <b>$self->{country}</b>;<br /> |
|
|
215 | <h2>Queue Statistics</h2> |
|
|
216 | <ul> |
|
|
217 | EOF |
|
|
218 | |
|
|
219 | my @queuename = ("Small Queue", "Large Queue"); |
|
|
220 | for (@::transfers) { |
|
|
221 | my $name = shift @queuename; |
|
|
222 | if ($_->waiters) { |
|
|
223 | $content .= "<li>$name<table border='1'><tr><th>Remote ID</th><th>CN</th><th>Waiting</th><th>URI</th></tr>"; |
|
|
224 | for ($_->waiters) { |
|
|
225 | my $conn = $_->{conn}; |
|
|
226 | my $time = format_time ($::NOW - $conn->{time}); |
|
|
227 | $content .= "<tr>". |
|
|
228 | "<td>$conn->{remote_id}</td>". |
|
|
229 | "<td>$conn->{country}</td>". |
|
|
230 | "<td>$time</td>". |
|
|
231 | "<td>".escape_html($conn->{name})."</td>". |
|
|
232 | "</tr>"; |
|
|
233 | } |
|
|
234 | $content .= "</table></li>"; |
|
|
235 | } else { |
|
|
236 | $content .= "<li>$name<br />(empty)</li>"; |
|
|
237 | } |
|
|
238 | } |
|
|
239 | |
|
|
240 | $content .= <<EOF; |
|
|
241 | </ul> |
|
|
242 | </body> |
|
|
243 | </html> |
|
|
244 | EOF |
|
|
245 | |
|
|
246 | $self->response(200, "ok", |
|
|
247 | { |
|
|
248 | "Content-Type" => "text/html", |
|
|
249 | "Content-Length" => length $content, |
|
|
250 | }, |
|
|
251 | $content); |
|
|
252 | }; |
|
|
253 | |
207 | 1; |
254 | 1; |