Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
39f888e5
提交
39f888e5
authored
10月 05, 2010
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
H2 Console: new experimental feature to support file download and upload.
上级
bbebd0de
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
139 行增加
和
16 行删除
+139
-16
WebApp.java
h2/src/main/org/h2/server/web/WebApp.java
+5
-5
WebServer.java
h2/src/main/org/h2/server/web/WebServer.java
+30
-0
WebThread.java
h2/src/main/org/h2/server/web/WebThread.java
+80
-11
transfer.jsp
h2/src/main/org/h2/server/web/res/transfer.jsp
+24
-0
没有找到文件。
h2/src/main/org/h2/server/web/WebApp.java
浏览文件 @
39f888e5
...
@@ -145,7 +145,7 @@ public class WebApp {
...
@@ -145,7 +145,7 @@ public class WebApp {
}
else
if
(
"html"
.
equals
(
suffix
)
||
"do"
.
equals
(
suffix
)
||
"jsp"
.
equals
(
suffix
))
{
}
else
if
(
"html"
.
equals
(
suffix
)
||
"do"
.
equals
(
suffix
)
||
"jsp"
.
equals
(
suffix
))
{
cache
=
false
;
cache
=
false
;
mimeType
=
"text/html"
;
mimeType
=
"text/html"
;
if
(
session
==
null
)
{
if
(
session
==
null
&&
!
file
.
startsWith
(
WebServer
.
TRANSFER
)
)
{
session
=
server
.
createNewSession
(
hostAddr
);
session
=
server
.
createNewSession
(
hostAddr
);
if
(!
"notAllowed.jsp"
.
equals
(
file
))
{
if
(!
"notAllowed.jsp"
.
equals
(
file
))
{
file
=
"index.do"
;
file
=
"index.do"
;
...
@@ -155,10 +155,8 @@ public class WebApp {
...
@@ -155,10 +155,8 @@ public class WebApp {
cache
=
true
;
cache
=
true
;
mimeType
=
"text/javascript"
;
mimeType
=
"text/javascript"
;
}
else
{
}
else
{
cache
=
false
;
cache
=
true
;
mimeType
=
"text/html"
;
mimeType
=
"application/octet-stream"
;
file
=
"error.jsp"
;
trace
(
"Unknown mime type, file "
+
file
);
}
}
trace
(
"mimeType="
+
mimeType
);
trace
(
"mimeType="
+
mimeType
);
trace
(
file
);
trace
(
file
);
...
@@ -235,6 +233,8 @@ public class WebApp {
...
@@ -235,6 +233,8 @@ public class WebApp {
file
=
autoCompleteList
();
file
=
autoCompleteList
();
}
else
if
(
"tools.do"
.
equals
(
file
))
{
}
else
if
(
"tools.do"
.
equals
(
file
))
{
file
=
tools
();
file
=
tools
();
}
else
if
(
"transfer.do"
.
equals
(
file
))
{
file
=
"transfer.jsp"
;
}
else
{
}
else
{
file
=
"error.jsp"
;
file
=
"error.jsp"
;
}
}
...
...
h2/src/main/org/h2/server/web/WebServer.java
浏览文件 @
39f888e5
...
@@ -7,6 +7,7 @@
...
@@ -7,6 +7,7 @@
package
org
.
h2
.
server
.
web
;
package
org
.
h2
.
server
.
web
;
import
java.io.File
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.io.OutputStream
;
...
@@ -46,6 +47,8 @@ import org.h2.util.SortedProperties;
...
@@ -46,6 +47,8 @@ import org.h2.util.SortedProperties;
*/
*/
public
class
WebServer
implements
Service
{
public
class
WebServer
implements
Service
{
static
final
String
TRANSFER
=
"transfer"
;
private
static
final
String
DEFAULT_LANGUAGE
=
"en"
;
private
static
final
String
DEFAULT_LANGUAGE
=
"en"
;
private
static
final
String
[][]
LANGUAGES
=
{
private
static
final
String
[][]
LANGUAGES
=
{
...
@@ -138,6 +141,17 @@ public class WebServer implements Service {
...
@@ -138,6 +141,17 @@ public class WebServer implements Service {
*/
*/
byte
[]
getFile
(
String
file
)
throws
IOException
{
byte
[]
getFile
(
String
file
)
throws
IOException
{
trace
(
"getFile <"
+
file
+
">"
);
trace
(
"getFile <"
+
file
+
">"
);
if
(
file
.
startsWith
(
TRANSFER
+
"/"
)
&&
new
File
(
TRANSFER
).
exists
())
{
file
=
file
.
substring
(
TRANSFER
.
length
()
+
1
);
if
(!
isSimpleName
(
file
))
{
return
null
;
}
File
f
=
new
File
(
TRANSFER
,
file
);
if
(!
f
.
exists
())
{
return
null
;
}
return
IOUtils
.
readBytesAndClose
(
new
FileInputStream
(
f
),
-
1
);
}
byte
[]
data
=
Utils
.
getResource
(
"/org/h2/server/web/res/"
+
file
);
byte
[]
data
=
Utils
.
getResource
(
"/org/h2/server/web/res/"
+
file
);
if
(
data
==
null
)
{
if
(
data
==
null
)
{
trace
(
" null"
);
trace
(
" null"
);
...
@@ -147,6 +161,22 @@ public class WebServer implements Service {
...
@@ -147,6 +161,22 @@ public class WebServer implements Service {
return
data
;
return
data
;
}
}
/**
* Check if this is a simple name (only contains '.', '-', '_', letters, or
* digits).
*
* @param s the string
* @return true if it's a simple name
*/
boolean
isSimpleName
(
String
s
)
{
for
(
char
c
:
s
.
toCharArray
())
{
if
(
c
!=
'.'
&&
c
!=
'_'
&&
c
!=
'-'
&&
!
Character
.
isLetterOrDigit
(
c
))
{
return
false
;
}
}
return
true
;
}
/**
/**
* Remove this web thread from the set of running threads.
* Remove this web thread from the set of running threads.
*
*
...
...
h2/src/main/org/h2/server/web/WebThread.java
浏览文件 @
39f888e5
...
@@ -8,9 +8,12 @@ package org.h2.server.web;
...
@@ -8,9 +8,12 @@ package org.h2.server.web;
import
java.io.BufferedInputStream
;
import
java.io.BufferedInputStream
;
import
java.io.BufferedOutputStream
;
import
java.io.BufferedOutputStream
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.io.OutputStream
;
import
java.io.RandomAccessFile
;
import
java.net.Socket
;
import
java.net.Socket
;
import
java.net.UnknownHostException
;
import
java.net.UnknownHostException
;
import
java.util.Iterator
;
import
java.util.Iterator
;
...
@@ -18,11 +21,12 @@ import java.util.Locale;
...
@@ -18,11 +21,12 @@ import java.util.Locale;
import
java.util.Properties
;
import
java.util.Properties
;
import
java.util.StringTokenizer
;
import
java.util.StringTokenizer
;
import
org.h2.constant.SysProperties
;
import
org.h2.constant.SysProperties
;
import
org.h2.engine.Constants
;
import
org.h2.message.TraceSystem
;
import
org.h2.message.TraceSystem
;
import
org.h2.util.Utils
;
import
org.h2.util.IOUtils
;
import
org.h2.util.IOUtils
;
import
org.h2.util.NetUtils
;
import
org.h2.util.NetUtils
;
import
org.h2.util.StringUtils
;
import
org.h2.util.StringUtils
;
import
org.h2.util.Utils
;
/**
/**
* For each connection to a session, an object of this class is created.
* For each connection to a session, an object of this class is created.
...
@@ -34,6 +38,7 @@ class WebThread extends WebApp implements Runnable {
...
@@ -34,6 +38,7 @@ class WebThread extends WebApp implements Runnable {
protected
Socket
socket
;
protected
Socket
socket
;
private
Thread
thread
;
private
Thread
thread
;
private
InputStream
input
;
private
InputStream
input
;
private
int
headerBytes
;
private
String
ifModifiedSince
;
private
String
ifModifiedSince
;
WebThread
(
Socket
socket
,
WebServer
server
)
{
WebThread
(
Socket
socket
,
WebServer
server
)
{
...
@@ -160,10 +165,10 @@ class WebThread extends WebApp implements Runnable {
...
@@ -160,10 +165,10 @@ class WebThread extends WebApp implements Runnable {
while
(
it
.
hasNext
())
{
while
(
it
.
hasNext
())
{
String
s
=
it
.
next
();
String
s
=
it
.
next
();
s
=
PageParser
.
parse
(
s
,
session
.
map
);
s
=
PageParser
.
parse
(
s
,
session
.
map
);
bytes
=
StringUtils
.
utf8Encode
(
s
);
if
(
bytes
.
length
==
0
)
{
if
(
bytes
.
length
==
0
)
{
continue
;
continue
;
}
}
bytes
=
StringUtils
.
utf8Encode
(
s
);
output
.
write
(
Integer
.
toHexString
(
bytes
.
length
).
getBytes
());
output
.
write
(
Integer
.
toHexString
(
bytes
.
length
).
getBytes
());
output
.
write
(
"\r\n"
.
getBytes
());
output
.
write
(
"\r\n"
.
getBytes
());
output
.
write
(
bytes
);
output
.
write
(
bytes
);
...
@@ -203,13 +208,19 @@ class WebThread extends WebApp implements Runnable {
...
@@ -203,13 +208,19 @@ class WebThread extends WebApp implements Runnable {
private
String
readHeaderLine
()
throws
IOException
{
private
String
readHeaderLine
()
throws
IOException
{
StringBuilder
buff
=
new
StringBuilder
();
StringBuilder
buff
=
new
StringBuilder
();
while
(
true
)
{
while
(
true
)
{
int
i
=
input
.
read
();
headerBytes
++;
if
(
i
==
-
1
)
{
int
c
=
input
.
read
();
if
(
c
==
-
1
)
{
throw
new
IOException
(
"Unexpected EOF"
);
throw
new
IOException
(
"Unexpected EOF"
);
}
else
if
(
i
==
'\r'
&&
input
.
read
()
==
'\n'
||
i
==
'\n'
)
{
}
else
if
(
c
==
'\r'
)
{
headerBytes
++;
if
(
input
.
read
()
==
'\n'
)
{
return
buff
.
length
()
>
0
?
buff
.
toString
()
:
null
;
}
}
else
if
(
c
==
'\n'
)
{
return
buff
.
length
()
>
0
?
buff
.
toString
()
:
null
;
return
buff
.
length
()
>
0
?
buff
.
toString
()
:
null
;
}
else
{
}
else
{
buff
.
append
((
char
)
i
);
buff
.
append
((
char
)
c
);
}
}
}
}
}
}
...
@@ -243,6 +254,7 @@ class WebThread extends WebApp implements Runnable {
...
@@ -243,6 +254,7 @@ class WebThread extends WebApp implements Runnable {
trace
(
"parseHeader"
);
trace
(
"parseHeader"
);
int
len
=
0
;
int
len
=
0
;
ifModifiedSince
=
null
;
ifModifiedSince
=
null
;
boolean
multipart
=
false
;
while
(
true
)
{
while
(
true
)
{
String
line
=
readHeaderLine
();
String
line
=
readHeaderLine
();
if
(
line
==
null
)
{
if
(
line
==
null
)
{
...
@@ -251,14 +263,19 @@ class WebThread extends WebApp implements Runnable {
...
@@ -251,14 +263,19 @@ class WebThread extends WebApp implements Runnable {
trace
(
" "
+
line
);
trace
(
" "
+
line
);
String
lower
=
StringUtils
.
toLowerEnglish
(
line
);
String
lower
=
StringUtils
.
toLowerEnglish
(
line
);
if
(
lower
.
startsWith
(
"if-modified-since"
))
{
if
(
lower
.
startsWith
(
"if-modified-since"
))
{
ifModifiedSince
=
line
.
substring
(
line
.
indexOf
(
':'
)
+
1
).
trim
(
);
ifModifiedSince
=
getHeaderLineValue
(
line
);
}
else
if
(
lower
.
startsWith
(
"connection"
))
{
}
else
if
(
lower
.
startsWith
(
"connection"
))
{
String
conn
=
line
.
substring
(
line
.
indexOf
(
':'
)
+
1
).
trim
(
);
String
conn
=
getHeaderLineValue
(
line
);
if
(
"keep-alive"
.
equals
(
conn
))
{
if
(
"keep-alive"
.
equals
(
conn
))
{
keepAlive
=
true
;
keepAlive
=
true
;
}
}
}
else
if
(
lower
.
startsWith
(
"content-type"
))
{
String
type
=
getHeaderLineValue
(
line
);
if
(
type
.
startsWith
(
"multipart/form-data"
))
{
multipart
=
true
;
}
}
else
if
(
lower
.
startsWith
(
"content-length"
))
{
}
else
if
(
lower
.
startsWith
(
"content-length"
))
{
len
=
Integer
.
parseInt
(
line
.
substring
(
line
.
indexOf
(
':'
)
+
1
).
trim
(
));
len
=
Integer
.
parseInt
(
getHeaderLineValue
(
line
));
trace
(
"len="
+
len
);
trace
(
"len="
+
len
);
}
else
if
(
lower
.
startsWith
(
"user-agent"
))
{
}
else
if
(
lower
.
startsWith
(
"user-agent"
))
{
boolean
isWebKit
=
lower
.
indexOf
(
"webkit/"
)
>=
0
;
boolean
isWebKit
=
lower
.
indexOf
(
"webkit/"
)
>=
0
;
...
@@ -271,7 +288,7 @@ class WebThread extends WebApp implements Runnable {
...
@@ -271,7 +288,7 @@ class WebThread extends WebApp implements Runnable {
}
else
if
(
lower
.
startsWith
(
"accept-language"
))
{
}
else
if
(
lower
.
startsWith
(
"accept-language"
))
{
Locale
locale
=
session
==
null
?
null
:
session
.
locale
;
Locale
locale
=
session
==
null
?
null
:
session
.
locale
;
if
(
locale
==
null
)
{
if
(
locale
==
null
)
{
String
languages
=
line
.
substring
(
line
.
indexOf
(
':'
)
+
1
).
trim
(
);
String
languages
=
getHeaderLineValue
(
line
);
StringTokenizer
tokenizer
=
new
StringTokenizer
(
languages
,
",;"
);
StringTokenizer
tokenizer
=
new
StringTokenizer
(
languages
,
",;"
);
while
(
tokenizer
.
hasMoreTokens
())
{
while
(
tokenizer
.
hasMoreTokens
())
{
String
token
=
tokenizer
.
nextToken
();
String
token
=
tokenizer
.
nextToken
();
...
@@ -300,7 +317,9 @@ class WebThread extends WebApp implements Runnable {
...
@@ -300,7 +317,9 @@ class WebThread extends WebApp implements Runnable {
break
;
break
;
}
}
}
}
if
(
session
!=
null
&&
len
>
0
)
{
if
(
multipart
)
{
uploadMultipart
(
input
,
len
);
}
else
if
(
session
!=
null
&&
len
>
0
)
{
byte
[]
bytes
=
Utils
.
newBytes
(
len
);
byte
[]
bytes
=
Utils
.
newBytes
(
len
);
for
(
int
pos
=
0
;
pos
<
len
;)
{
for
(
int
pos
=
0
;
pos
<
len
;)
{
pos
+=
input
.
read
(
bytes
,
pos
,
len
-
pos
);
pos
+=
input
.
read
(
bytes
,
pos
,
len
-
pos
);
...
@@ -311,6 +330,56 @@ class WebThread extends WebApp implements Runnable {
...
@@ -311,6 +330,56 @@ class WebThread extends WebApp implements Runnable {
return
keepAlive
;
return
keepAlive
;
}
}
private
void
uploadMultipart
(
InputStream
in
,
int
len
)
throws
IOException
{
if
(!
new
File
(
WebServer
.
TRANSFER
).
exists
())
{
return
;
}
String
fileName
=
"temp.bin"
;
headerBytes
=
0
;
String
boundary
=
readHeaderLine
();
while
(
true
)
{
String
line
=
readHeaderLine
();
if
(
line
==
null
)
{
break
;
}
int
index
=
line
.
indexOf
(
"filename=\""
);
if
(
index
>
0
)
{
fileName
=
line
.
substring
(
index
+
"filename=\""
.
length
(),
line
.
lastIndexOf
(
'"'
));
}
trace
(
" "
+
line
);
}
if
(!
server
.
isSimpleName
(
fileName
))
{
return
;
}
len
-=
headerBytes
;
File
file
=
new
File
(
WebServer
.
TRANSFER
,
fileName
);
OutputStream
out
=
new
FileOutputStream
(
file
);
byte
[]
bytes
=
Utils
.
newBytes
(
Constants
.
IO_BUFFER_SIZE
);
while
(
len
>
0
)
{
int
l
=
Math
.
min
(
Constants
.
IO_BUFFER_SIZE
,
len
);
l
=
in
.
read
(
bytes
,
0
,
l
);
if
(
l
<
0
)
{
break
;
}
out
.
write
(
bytes
,
0
,
l
);
len
-=
l
;
}
out
.
close
();
// remove the boundary
RandomAccessFile
f
=
new
RandomAccessFile
(
file
,
"rw"
);
int
testSize
=
(
int
)
Math
.
min
(
f
.
length
(),
Constants
.
IO_BUFFER_SIZE
);
f
.
seek
(
f
.
length
()
-
testSize
);
f
.
readFully
(
bytes
,
0
,
testSize
);
String
s
=
new
String
(
bytes
,
"ASCII"
);
int
x
=
s
.
indexOf
(
boundary
);
f
.
setLength
(
f
.
length
()
-
testSize
+
x
-
2
);
f
.
close
();
}
private
String
getHeaderLineValue
(
String
line
)
{
return
line
.
substring
(
line
.
indexOf
(
':'
)
+
1
).
trim
();
}
protected
String
adminShutdown
()
{
protected
String
adminShutdown
()
{
stopNow
();
stopNow
();
return
super
.
adminShutdown
();
return
super
.
adminShutdown
();
...
...
h2/src/main/org/h2/server/web/res/transfer.jsp
0 → 100644
浏览文件 @
39f888e5
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--
Copyright 2004-2010 H2 Group.
Multiple-Licensed under the H2 License, Version 1.0,
and under the Eclipse Public License, Version 1.0
(http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html><head>
<meta
http-equiv=
"Content-Type"
content=
"text/html;charset=utf-8"
/>
<title>
Upload
</title>
<link
rel=
"stylesheet"
type=
"text/css"
href=
"stylesheet.css"
/>
</head>
<body>
<form
action=
"transfer.do"
method=
"post"
enctype=
"multipart/form-data"
>
<p>
File:
<br
/>
<input
name=
"file"
type=
"file"
size=
"50"
/><br
/><br
/>
<input
type=
"submit"
value=
"Upload"
/>
</p>
</form>
</body></html>
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论