Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
ea471098
提交
ea471098
authored
6 年前
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add transparent key to Console tool that unlocks creation of new databases
上级
bfe98ee6
master
无相关合并请求
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
58 行增加
和
9 行删除
+58
-9
changelog.html
h2/src/docsrc/html/changelog.html
+2
-0
WebApp.java
h2/src/main/org/h2/server/web/WebApp.java
+2
-2
WebServer.java
h2/src/main/org/h2/server/web/WebServer.java
+22
-5
WebThread.java
h2/src/main/org/h2/server/web/WebThread.java
+8
-0
Console.java
h2/src/main/org/h2/tools/Console.java
+6
-1
Server.java
h2/src/main/org/h2/tools/Server.java
+18
-1
没有找到文件。
h2/src/docsrc/html/changelog.html
浏览文件 @
ea471098
...
...
@@ -21,6 +21,8 @@ Change Log
<h2>
Next Version (unreleased)
</h2>
<ul>
<li>
Issue #1751: making it easier to open console and create local databases
</li>
<li>
Issue #1750: JOIN t ON t.col IN (SELECT ...) throws AssertionError
</li>
</ul>
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/server/web/WebApp.java
浏览文件 @
ea471098
...
...
@@ -937,7 +937,7 @@ public class WebApp {
prof
.
startCollecting
();
Connection
conn
;
try
{
conn
=
server
.
getConnection
(
driver
,
url
,
user
,
password
);
conn
=
server
.
getConnection
(
driver
,
url
,
user
,
password
,
null
);
}
finally
{
prof
.
stopCollecting
();
profOpen
=
prof
.
getTop
(
3
);
...
...
@@ -998,7 +998,7 @@ public class WebApp {
session
.
put
(
"maxrows"
,
"1000"
);
boolean
isH2
=
url
.
startsWith
(
"jdbc:h2:"
);
try
{
Connection
conn
=
server
.
getConnection
(
driver
,
url
,
user
,
password
);
Connection
conn
=
server
.
getConnection
(
driver
,
url
,
user
,
password
,
(
String
)
session
.
get
(
"key"
)
);
session
.
setConnection
(
conn
);
session
.
put
(
"url"
,
url
);
session
.
put
(
"user"
,
user
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/server/web/WebServer.java
浏览文件 @
ea471098
...
...
@@ -168,6 +168,7 @@ public class WebServer implements Service {
private
ShutdownHandler
shutdownHandler
;
private
Thread
listenerThread
;
private
boolean
ifExists
=
true
;
private
String
key
;
private
boolean
trace
;
private
TranslateThread
translateThread
;
private
boolean
allowChunked
=
true
;
...
...
@@ -266,6 +267,15 @@ public class WebServer implements Service {
return
startDateTime
;
}
/**
* Sets the key for privileged connections.
*
* @param key key, or null
*/
public
void
setKey
(
String
key
)
{
this
.
key
=
key
;
}
@Override
public
void
init
(
String
...
args
)
{
// set the serverPropertiesDir, because it's used in loadProperties()
...
...
@@ -336,8 +346,12 @@ public class WebServer implements Service {
private
void
updateURL
()
{
try
{
url
=
(
ssl
?
"https"
:
"http"
)
+
"://"
+
NetUtils
.
getLocalAddress
()
+
":"
+
port
;
StringBuilder
builder
=
new
StringBuilder
(
ssl
?
"https"
:
"http"
).
append
(
"://"
)
.
append
(
NetUtils
.
getLocalAddress
()).
append
(
':'
).
append
(
port
);
if
(
key
!=
null
)
{
builder
.
append
(
"?key="
).
append
(
key
);
}
url
=
builder
.
toString
();
}
catch
(
NoClassDefFoundError
e
)
{
// Google App Engine does not allow java.net.InetAddress
}
...
...
@@ -718,10 +732,11 @@ public class WebServer implements Service {
* @param databaseUrl the database URL
* @param user the user name
* @param password the password
* @param userKey the key of privileged user
* @return the database connection
*/
Connection
getConnection
(
String
driver
,
String
databaseUrl
,
String
user
,
String
password
)
throws
SQLException
{
String
password
,
String
userKey
)
throws
SQLException
{
driver
=
driver
.
trim
();
databaseUrl
=
databaseUrl
.
trim
();
Properties
p
=
new
Properties
();
...
...
@@ -730,8 +745,10 @@ public class WebServer implements Service {
// encrypted H2 database with empty user password doesn't work
p
.
setProperty
(
"password"
,
password
);
if
(
databaseUrl
.
startsWith
(
"jdbc:h2:"
))
{
if
(
ifExists
)
{
databaseUrl
+=
";IFEXISTS=TRUE"
;
if
(
key
==
null
||
!
key
.
equals
(
userKey
))
{
if
(
ifExists
)
{
databaseUrl
+=
";IFEXISTS=TRUE"
;
}
}
}
return
JdbcUtils
.
getConnection
(
driver
,
databaseUrl
,
p
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/server/web/WebThread.java
浏览文件 @
ea471098
...
...
@@ -78,6 +78,9 @@ class WebThread extends WebApp implements Runnable {
if
(
requestedFile
.
length
()
==
0
)
{
return
"index.do"
;
}
if
(
requestedFile
.
charAt
(
0
)
==
'?'
)
{
return
"index.do"
+
requestedFile
;
}
return
requestedFile
;
}
...
...
@@ -122,10 +125,12 @@ class WebThread extends WebApp implements Runnable {
attributes
=
new
Properties
();
int
paramIndex
=
file
.
indexOf
(
'?'
);
session
=
null
;
String
key
=
null
;
if
(
paramIndex
>=
0
)
{
String
attrib
=
file
.
substring
(
paramIndex
+
1
);
parseAttributes
(
attrib
);
String
sessionId
=
attributes
.
getProperty
(
"jsessionid"
);
key
=
attributes
.
getProperty
(
"key"
);
file
=
file
.
substring
(
0
,
paramIndex
);
session
=
server
.
getSession
(
sessionId
);
}
...
...
@@ -150,6 +155,9 @@ class WebThread extends WebApp implements Runnable {
message
+=
"Content-Length: "
+
bytes
.
length
+
"\r\n"
;
}
else
{
if
(
session
!=
null
&&
file
.
endsWith
(
".jsp"
))
{
if
(
key
!=
null
)
{
session
.
put
(
"key"
,
key
);
}
String
page
=
new
String
(
bytes
,
StandardCharsets
.
UTF_8
);
if
(
SysProperties
.
CONSOLE_STREAM
)
{
Iterator
<
String
>
it
=
(
Iterator
<
String
>)
session
.
map
.
remove
(
"chunks"
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/tools/Console.java
浏览文件 @
ea471098
...
...
@@ -9,6 +9,8 @@ import java.sql.Connection;
import
java.sql.SQLException
;
import
org.h2.server.ShutdownHandler
;
import
org.h2.util.JdbcUtils
;
import
org.h2.util.MathUtils
;
import
org.h2.util.StringUtils
;
import
org.h2.util.Tool
;
import
org.h2.util.Utils
;
...
...
@@ -88,6 +90,7 @@ public class Console extends Tool implements ShutdownHandler {
boolean
tcpShutdown
=
false
,
tcpShutdownForce
=
false
;
String
tcpPassword
=
""
;
String
tcpShutdownServer
=
""
;
boolean
ifExists
=
false
;
for
(
int
i
=
0
;
args
!=
null
&&
i
<
args
.
length
;
i
++)
{
String
arg
=
args
[
i
];
if
(
arg
==
null
)
{
...
...
@@ -168,6 +171,7 @@ public class Console extends Tool implements ShutdownHandler {
// no parameters
}
else
if
(
"-ifExists"
.
equals
(
arg
))
{
// no parameters
ifExists
=
true
;
}
else
if
(
"-baseDir"
.
equals
(
arg
))
{
i
++;
}
else
{
...
...
@@ -196,7 +200,8 @@ public class Console extends Tool implements ShutdownHandler {
if
(
webStart
)
{
try
{
web
=
Server
.
createWebServer
(
args
);
String
webKey
=
ifExists
?
null
:
StringUtils
.
convertBytesToHex
(
MathUtils
.
secureRandomBytes
(
32
));
web
=
Server
.
createWebServer
(
args
,
webKey
);
web
.
setShutdownHandler
(
this
);
web
.
start
();
if
(
printStatus
)
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/tools/Server.java
浏览文件 @
ea471098
...
...
@@ -426,7 +426,19 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
* @return the server
*/
public
static
Server
createWebServer
(
String
...
args
)
throws
SQLException
{
return
createWebServer
(
args
,
null
);
}
/**
* Create a new web server, but does not start it yet.
*
* @param args the argument list
* @param key key, or null
* @return the server
*/
static
Server
createWebServer
(
String
[]
args
,
String
key
)
throws
SQLException
{
WebServer
service
=
new
WebServer
();
service
.
setKey
(
key
);
Server
server
=
new
Server
(
service
,
args
);
service
.
setShutdownHandler
(
server
);
return
server
;
...
...
@@ -492,7 +504,12 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
try
{
started
=
true
;
service
.
start
();
String
name
=
service
.
getName
()
+
" ("
+
service
.
getURL
()
+
")"
;
String
url
=
service
.
getURL
();
int
idx
=
url
.
indexOf
(
'?'
);
if
(
idx
>=
0
)
{
url
=
url
.
substring
(
0
,
idx
);
}
String
name
=
service
.
getName
()
+
" ("
+
url
+
')'
;
Thread
t
=
new
Thread
(
this
,
name
);
t
.
setDaemon
(
service
.
isDaemon
());
t
.
start
();
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论