Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
NetWork
Opentracker
提交
bee364a6
O
Opentracker
项目概览
NetWork
/
Opentracker
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
Opentracker
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
bee364a6
编写于
12月 05, 2007
作者:
E
erdgeist
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
/ can now be redirected to any URL
上级
31d876d5
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
21 addition
and
10 deletion
+21
-10
opentracker.c
opentracker.c
+7
-4
ot_http.c
ot_http.c
+10
-4
ot_stats.c
ot_stats.c
+3
-2
ot_stats.h
ot_stats.h
+1
-0
未找到文件。
opentracker.c
浏览文件 @
bee364a6
...
...
@@ -35,6 +35,7 @@
/* Globals */
time_t
g_now
;
char
*
g_redirecturl
=
NULL
;
/* To always have space for error messages ;) */
static
char
static_inbuf
[
8192
];
...
...
@@ -60,7 +61,7 @@ static void signal_handler( int s ) {
}
static
void
usage
(
char
*
name
)
{
fprintf
(
stderr
,
"Usage: %s [-i ip] [-p port] [-P port] [-d dir] [-A ip]"
fprintf
(
stderr
,
"Usage: %s [-i ip] [-p port] [-P port] [-
r redirect] [-
d dir] [-A ip]"
#ifdef WANT_BLACKLISTING
" [-b blacklistfile]"
#elif defined ( WANT_CLOSED_TRACKER )
...
...
@@ -76,6 +77,7 @@ static void help( char *name ) {
HELPLINE
(
"-i ip"
,
"specify ip to bind to (default: *, you may specify more than one)"
);
HELPLINE
(
"-p port"
,
"specify tcp port to bind to (default: 6969, you may specify more than one)"
);
HELPLINE
(
"-P port"
,
"specify udp port to bind to (default: 6969, you may specify more than one)"
);
HELPLINE
(
"-r redirecturl"
,
"specify url where / should be redirected to (default none)"
);
HELPLINE
(
"-d dir"
,
"specify directory to try to chroot to (default:
\"
.
\"
)"
);
HELPLINE
(
"-A ip"
,
"bless an ip address as admin address (e.g. to allow syncs from this address)"
);
#ifdef WANT_BLACKLISTING
...
...
@@ -124,10 +126,10 @@ static ssize_t handle_read( const int64 clientsocket ) {
array_catb
(
&
h
->
request
,
static_inbuf
,
l
);
if
(
array_failed
(
&
h
->
request
)
)
return
http_issue_error
(
clientsocket
,
"500 Server Error"
,
"Request too long."
);
return
http_issue_error
(
clientsocket
,
CODE_HTTPERROR_500
);
if
(
(
array_bytes
(
&
h
->
request
)
>
8192
)
&&
!
accesslist_isblessed
(
(
char
*
)
&
h
->
ip
,
OT_PERMISSION_MAY_SYNC
)
)
return
http_issue_error
(
clientsocket
,
"500 request too long"
,
"You sent too much headers"
);
return
http_issue_error
(
clientsocket
,
CODE_HTTPERROR_500
);
if
(
memchr
(
array_start
(
&
h
->
request
),
'\n'
,
array_bytes
(
&
h
->
request
)
)
)
return
http_handle_request
(
clientsocket
,
array_start
(
&
h
->
request
),
array_bytes
(
&
h
->
request
)
);
...
...
@@ -248,7 +250,7 @@ int main( int argc, char **argv ) {
#endif
while
(
scanon
)
{
switch
(
getopt
(
argc
,
argv
,
":i:p:A:P:d:"
switch
(
getopt
(
argc
,
argv
,
":i:p:A:P:d:
r:
"
#ifdef WANT_BLACKLISTING
"b:"
#elif defined( WANT_CLOSED_TRACKER )
...
...
@@ -265,6 +267,7 @@ int main( int argc, char **argv ) {
case
'p'
:
ot_try_bind
(
serverip
,
(
uint16
)
atol
(
optarg
),
1
);
bound
++
;
break
;
case
'P'
:
ot_try_bind
(
serverip
,
(
uint16
)
atol
(
optarg
),
0
);
bound
++
;
break
;
case
'd'
:
serverdir
=
optarg
;
break
;
case
'r'
:
g_redirecturl
=
optarg
;
break
;
case
'A'
:
scan_ip4
(
optarg
,
tmpip
);
accesslist_blessip
(
tmpip
,
0xffff
);
/* Allow everything for now */
...
...
ot_http.c
浏览文件 @
bee364a6
...
...
@@ -32,6 +32,7 @@
#define OT_MAXMULTISCRAPE_COUNT 64
static
ot_hash
multiscrape_buf
[
OT_MAXMULTISCRAPE_COUNT
];
extern
char
*
g_redirecturl
;
enum
{
SUCCESS_HTTP_HEADER_LENGTH
=
80
,
...
...
@@ -79,6 +80,7 @@ static void http_senddata( const int64 client_socket, char *buffer, size_t size
}
}
#define HTTPERROR_302 return http_issue_error( client_socket, CODE_HTTPERROR_302 )
#define HTTPERROR_400 return http_issue_error( client_socket, CODE_HTTPERROR_400 )
#define HTTPERROR_400_PARAM return http_issue_error( client_socket, CODE_HTTPERROR_400_PARAM )
#define HTTPERROR_400_COMPACT return http_issue_error( client_socket, CODE_HTTPERROR_400_COMPACT )
...
...
@@ -86,13 +88,16 @@ static void http_senddata( const int64 client_socket, char *buffer, size_t size
#define HTTPERROR_404 return http_issue_error( client_socket, CODE_HTTPERROR_404 )
#define HTTPERROR_500 return http_issue_error( client_socket, CODE_HTTPERROR_500 )
ssize_t
http_issue_error
(
const
int64
client_socket
,
int
code
)
{
char
*
error_code
[]
=
{
"400 Invalid Request"
,
"400 Invalid Request"
,
"400 Invalid Request"
,
char
*
error_code
[]
=
{
"
302 Found"
,
"
400 Invalid Request"
,
"400 Invalid Request"
,
"400 Invalid Request"
,
"403 Access Denied"
,
"404 Not Found"
,
"500 Internal Server Error"
};
char
*
title
=
error_code
[
code
];
size_t
reply_size
;
if
(
code
==
CODE_HTTPERROR_302
)
reply_size
=
sprintf
(
static_outbuf
,
"HTTP/1.0 302 Found
\r\n
Content-Length: 0
\r\n
Location: %s
\r\n\r\n
"
,
g_redirecturl
);
else
reply_size
=
sprintf
(
static_outbuf
,
"HTTP/1.0 %s
\r\n
Content-Type: text/html
\r\n
Connection: close
\r\n
Content-Length: %zd
\r\n\r\n
<title>%s</title>
\n
"
,
title
,
strlen
(
title
)
+
16
-
4
,
title
+
4
);
size_t
reply_size
=
sprintf
(
static_outbuf
,
"HTTP/1.0 %s
\r\n
Content-Type: text/html
\r\n
Connection: close
\r\n
Content-Length: %zd
\r\n\r\n
<title>%s</title>
\n
"
,
title
,
2
*
strlen
(
title
)
+
16
-
4
,
title
+
4
);
#ifdef _DEBUG_HTTPERROR
fprintf
(
stderr
,
"DEBUG: invalid request was: %s
\n
"
,
debug_request
);
#endif
...
...
@@ -506,6 +511,7 @@ ssize_t http_handle_request( const int64 client_socket, char *data, size_t recv_
len
=
scan_urlencoded_query
(
&
c
,
data
=
c
,
SCAN_PATH
);
/* If parsing returned an error, leave with not found*/
if
(
g_redirecturl
&&
(
len
==
-
2
)
)
HTTPERROR_302
;
if
(
len
<=
0
)
HTTPERROR_404
;
/* This is the hardcore match for announce*/
...
...
ot_stats.c
浏览文件 @
bee364a6
...
...
@@ -265,9 +265,10 @@ static size_t stats_peers_mrtg( char * reply ) {
}
static
size_t
stats_httperrors_txt
(
char
*
reply
)
{
return
sprintf
(
reply
,
"400 ... %llu
\n
400 PAR %llu
\n
400 COM %llu
\n
403 IP %llu
\n
404 INV %llu
\n
500 SRV %llu
\n
"
,
return
sprintf
(
reply
,
"
302 RED %llu
\n
400 ... %llu
\n
400 PAR %llu
\n
400 COM %llu
\n
403 IP %llu
\n
404 INV %llu
\n
500 SRV %llu
\n
"
,
ot_failed_request_counts
[
0
],
ot_failed_request_counts
[
1
],
ot_failed_request_counts
[
2
],
ot_failed_request_counts
[
3
],
ot_failed_request_counts
[
4
],
ot_failed_request_counts
[
5
]);
ot_failed_request_counts
[
3
],
ot_failed_request_counts
[
4
],
ot_failed_request_counts
[
5
],
ot_failed_request_counts
[
6
]
);
}
size_t
return_stats_for_tracker
(
char
*
reply
,
int
mode
,
int
format
)
{
...
...
ot_stats.h
浏览文件 @
bee364a6
...
...
@@ -21,6 +21,7 @@ typedef enum {
}
ot_status_event
;
enum
{
CODE_HTTPERROR_302
,
CODE_HTTPERROR_400
,
CODE_HTTPERROR_400_PARAM
,
CODE_HTTPERROR_400_COMPACT
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录