Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
b876d231
Unverified
提交
b876d231
authored
2月 24, 2019
作者:
Evgenij Ryazanov
提交者:
GitHub
2月 24, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1753 from katzyn/console
Add transparent key to Console tool that unlocks creation of new databases
上级
bfe98ee6
0b01dd77
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
100 行增加
和
11 行删除
+100
-11
changelog.html
h2/src/docsrc/html/changelog.html
+2
-0
tutorial.html
h2/src/docsrc/html/tutorial.html
+3
-2
WebApp.java
h2/src/main/org/h2/server/web/WebApp.java
+6
-2
WebServer.java
h2/src/main/org/h2/server/web/WebServer.java
+50
-5
WebThread.java
h2/src/main/org/h2/server/web/WebThread.java
+8
-0
Console.java
h2/src/main/org/h2/tools/Console.java
+8
-1
Server.java
h2/src/main/org/h2/tools/Server.java
+23
-1
没有找到文件。
h2/src/docsrc/html/changelog.html
浏览文件 @
b876d231
...
@@ -21,6 +21,8 @@ Change Log
...
@@ -21,6 +21,8 @@ Change Log
<h2>
Next Version (unreleased)
</h2>
<h2>
Next Version (unreleased)
</h2>
<ul>
<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>
Issue #1750: JOIN t ON t.col IN (SELECT ...) throws AssertionError
</li>
</li>
</ul>
</ul>
...
...
h2/src/docsrc/html/tutorial.html
浏览文件 @
b876d231
...
@@ -484,8 +484,9 @@ Auto-creation of databases can be disabled, see
...
@@ -484,8 +484,9 @@ Auto-creation of databases can be disabled, see
<a
href=
"features.html#database_only_if_exists"
>
Opening a Database Only if it Already Exists
</a>
.
<a
href=
"features.html#database_only_if_exists"
>
Opening a Database Only if it Already Exists
</a>
.
</p>
</p>
<p>
<p>
H2 Console does not allow creation of databases by default.
H2 Console does not allow creation of databases by default unless a browser window is opened by Console during its
If H2 Console is launched with icon in the system tray its context menu can be used to create a new database.
startup or from its icon in the system tray and remote access is not enabled.
A context menu of the tray icon can also be used to create a new database.
</p>
</p>
<h2
id=
"using_server"
>
Using the Server
</h2>
<h2
id=
"using_server"
>
Using the Server
</h2>
...
...
h2/src/main/org/h2/server/web/WebApp.java
浏览文件 @
b876d231
...
@@ -281,6 +281,10 @@ public class WebApp {
...
@@ -281,6 +281,10 @@ public class WebApp {
if
(
b
!=
null
&&
b
)
{
if
(
b
!=
null
&&
b
)
{
return
true
;
return
true
;
}
}
String
key
=
server
.
getKey
();
if
(
key
!=
null
&&
key
.
equals
(
session
.
get
(
"key"
)))
{
return
true
;
}
session
.
put
(
"adminBack"
,
file
);
session
.
put
(
"adminBack"
,
file
);
return
false
;
return
false
;
}
}
...
@@ -937,7 +941,7 @@ public class WebApp {
...
@@ -937,7 +941,7 @@ public class WebApp {
prof
.
startCollecting
();
prof
.
startCollecting
();
Connection
conn
;
Connection
conn
;
try
{
try
{
conn
=
server
.
getConnection
(
driver
,
url
,
user
,
password
);
conn
=
server
.
getConnection
(
driver
,
url
,
user
,
password
,
null
);
}
finally
{
}
finally
{
prof
.
stopCollecting
();
prof
.
stopCollecting
();
profOpen
=
prof
.
getTop
(
3
);
profOpen
=
prof
.
getTop
(
3
);
...
@@ -998,7 +1002,7 @@ public class WebApp {
...
@@ -998,7 +1002,7 @@ public class WebApp {
session
.
put
(
"maxrows"
,
"1000"
);
session
.
put
(
"maxrows"
,
"1000"
);
boolean
isH2
=
url
.
startsWith
(
"jdbc:h2:"
);
boolean
isH2
=
url
.
startsWith
(
"jdbc:h2:"
);
try
{
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
.
setConnection
(
conn
);
session
.
put
(
"url"
,
url
);
session
.
put
(
"url"
,
url
);
session
.
put
(
"user"
,
user
);
session
.
put
(
"user"
,
user
);
...
...
h2/src/main/org/h2/server/web/WebServer.java
浏览文件 @
b876d231
...
@@ -168,6 +168,8 @@ public class WebServer implements Service {
...
@@ -168,6 +168,8 @@ public class WebServer implements Service {
private
ShutdownHandler
shutdownHandler
;
private
ShutdownHandler
shutdownHandler
;
private
Thread
listenerThread
;
private
Thread
listenerThread
;
private
boolean
ifExists
=
true
;
private
boolean
ifExists
=
true
;
private
String
key
;
private
boolean
allowSecureCreation
;
private
boolean
trace
;
private
boolean
trace
;
private
TranslateThread
translateThread
;
private
TranslateThread
translateThread
;
private
boolean
allowChunked
=
true
;
private
boolean
allowChunked
=
true
;
...
@@ -266,6 +268,36 @@ public class WebServer implements Service {
...
@@ -266,6 +268,36 @@ public class WebServer implements Service {
return
startDateTime
;
return
startDateTime
;
}
}
/**
* Returns the key for privileged connections.
*
* @return key key, or null
*/
String
getKey
()
{
return
key
;
}
/**
* Sets the key for privileged connections.
*
* @param key key, or null
*/
public
void
setKey
(
String
key
)
{
if
(!
allowOthers
)
{
this
.
key
=
key
;
}
}
/**
* @param allowSecureCreation
* whether creation of databases using the key should be allowed
*/
public
void
setAllowSecureCreation
(
boolean
allowSecureCreation
)
{
if
(!
allowOthers
)
{
this
.
allowSecureCreation
=
allowSecureCreation
;
}
}
@Override
@Override
public
void
init
(
String
...
args
)
{
public
void
init
(
String
...
args
)
{
// set the serverPropertiesDir, because it's used in loadProperties()
// set the serverPropertiesDir, because it's used in loadProperties()
...
@@ -325,6 +357,9 @@ public class WebServer implements Service {
...
@@ -325,6 +357,9 @@ public class WebServer implements Service {
for
(
String
[]
lang
:
LANGUAGES
)
{
for
(
String
[]
lang
:
LANGUAGES
)
{
languages
.
add
(
lang
[
0
]);
languages
.
add
(
lang
[
0
]);
}
}
if
(
allowOthers
)
{
key
=
null
;
}
updateURL
();
updateURL
();
}
}
...
@@ -336,8 +371,12 @@ public class WebServer implements Service {
...
@@ -336,8 +371,12 @@ public class WebServer implements Service {
private
void
updateURL
()
{
private
void
updateURL
()
{
try
{
try
{
url
=
(
ssl
?
"https"
:
"http"
)
+
"://"
+
StringBuilder
builder
=
new
StringBuilder
(
ssl
?
"https"
:
"http"
).
append
(
"://"
)
NetUtils
.
getLocalAddress
()
+
":"
+
port
;
.
append
(
NetUtils
.
getLocalAddress
()).
append
(
':'
).
append
(
port
);
if
(
key
!=
null
)
{
builder
.
append
(
"?key="
).
append
(
key
);
}
url
=
builder
.
toString
();
}
catch
(
NoClassDefFoundError
e
)
{
}
catch
(
NoClassDefFoundError
e
)
{
// Google App Engine does not allow java.net.InetAddress
// Google App Engine does not allow java.net.InetAddress
}
}
...
@@ -495,6 +534,9 @@ public class WebServer implements Service {
...
@@ -495,6 +534,9 @@ public class WebServer implements Service {
}
}
void
setAllowOthers
(
boolean
b
)
{
void
setAllowOthers
(
boolean
b
)
{
if
(
b
)
{
key
=
null
;
}
allowOthers
=
b
;
allowOthers
=
b
;
}
}
...
@@ -718,10 +760,11 @@ public class WebServer implements Service {
...
@@ -718,10 +760,11 @@ public class WebServer implements Service {
* @param databaseUrl the database URL
* @param databaseUrl the database URL
* @param user the user name
* @param user the user name
* @param password the password
* @param password the password
* @param userKey the key of privileged user
* @return the database connection
* @return the database connection
*/
*/
Connection
getConnection
(
String
driver
,
String
databaseUrl
,
String
user
,
Connection
getConnection
(
String
driver
,
String
databaseUrl
,
String
user
,
String
password
)
throws
SQLException
{
String
password
,
String
userKey
)
throws
SQLException
{
driver
=
driver
.
trim
();
driver
=
driver
.
trim
();
databaseUrl
=
databaseUrl
.
trim
();
databaseUrl
=
databaseUrl
.
trim
();
Properties
p
=
new
Properties
();
Properties
p
=
new
Properties
();
...
@@ -730,8 +773,10 @@ public class WebServer implements Service {
...
@@ -730,8 +773,10 @@ public class WebServer implements Service {
// encrypted H2 database with empty user password doesn't work
// encrypted H2 database with empty user password doesn't work
p
.
setProperty
(
"password"
,
password
);
p
.
setProperty
(
"password"
,
password
);
if
(
databaseUrl
.
startsWith
(
"jdbc:h2:"
))
{
if
(
databaseUrl
.
startsWith
(
"jdbc:h2:"
))
{
if
(
ifExists
)
{
if
(!
allowSecureCreation
||
key
==
null
||
!
key
.
equals
(
userKey
))
{
databaseUrl
+=
";IFEXISTS=TRUE"
;
if
(
ifExists
)
{
databaseUrl
+=
";IFEXISTS=TRUE"
;
}
}
}
}
}
return
JdbcUtils
.
getConnection
(
driver
,
databaseUrl
,
p
);
return
JdbcUtils
.
getConnection
(
driver
,
databaseUrl
,
p
);
...
...
h2/src/main/org/h2/server/web/WebThread.java
浏览文件 @
b876d231
...
@@ -78,6 +78,9 @@ class WebThread extends WebApp implements Runnable {
...
@@ -78,6 +78,9 @@ class WebThread extends WebApp implements Runnable {
if
(
requestedFile
.
length
()
==
0
)
{
if
(
requestedFile
.
length
()
==
0
)
{
return
"index.do"
;
return
"index.do"
;
}
}
if
(
requestedFile
.
charAt
(
0
)
==
'?'
)
{
return
"index.do"
+
requestedFile
;
}
return
requestedFile
;
return
requestedFile
;
}
}
...
@@ -122,10 +125,12 @@ class WebThread extends WebApp implements Runnable {
...
@@ -122,10 +125,12 @@ class WebThread extends WebApp implements Runnable {
attributes
=
new
Properties
();
attributes
=
new
Properties
();
int
paramIndex
=
file
.
indexOf
(
'?'
);
int
paramIndex
=
file
.
indexOf
(
'?'
);
session
=
null
;
session
=
null
;
String
key
=
null
;
if
(
paramIndex
>=
0
)
{
if
(
paramIndex
>=
0
)
{
String
attrib
=
file
.
substring
(
paramIndex
+
1
);
String
attrib
=
file
.
substring
(
paramIndex
+
1
);
parseAttributes
(
attrib
);
parseAttributes
(
attrib
);
String
sessionId
=
attributes
.
getProperty
(
"jsessionid"
);
String
sessionId
=
attributes
.
getProperty
(
"jsessionid"
);
key
=
attributes
.
getProperty
(
"key"
);
file
=
file
.
substring
(
0
,
paramIndex
);
file
=
file
.
substring
(
0
,
paramIndex
);
session
=
server
.
getSession
(
sessionId
);
session
=
server
.
getSession
(
sessionId
);
}
}
...
@@ -150,6 +155,9 @@ class WebThread extends WebApp implements Runnable {
...
@@ -150,6 +155,9 @@ class WebThread extends WebApp implements Runnable {
message
+=
"Content-Length: "
+
bytes
.
length
+
"\r\n"
;
message
+=
"Content-Length: "
+
bytes
.
length
+
"\r\n"
;
}
else
{
}
else
{
if
(
session
!=
null
&&
file
.
endsWith
(
".jsp"
))
{
if
(
session
!=
null
&&
file
.
endsWith
(
".jsp"
))
{
if
(
key
!=
null
)
{
session
.
put
(
"key"
,
key
);
}
String
page
=
new
String
(
bytes
,
StandardCharsets
.
UTF_8
);
String
page
=
new
String
(
bytes
,
StandardCharsets
.
UTF_8
);
if
(
SysProperties
.
CONSOLE_STREAM
)
{
if
(
SysProperties
.
CONSOLE_STREAM
)
{
Iterator
<
String
>
it
=
(
Iterator
<
String
>)
session
.
map
.
remove
(
"chunks"
);
Iterator
<
String
>
it
=
(
Iterator
<
String
>)
session
.
map
.
remove
(
"chunks"
);
...
...
h2/src/main/org/h2/tools/Console.java
浏览文件 @
b876d231
...
@@ -9,6 +9,8 @@ import java.sql.Connection;
...
@@ -9,6 +9,8 @@ import java.sql.Connection;
import
java.sql.SQLException
;
import
java.sql.SQLException
;
import
org.h2.server.ShutdownHandler
;
import
org.h2.server.ShutdownHandler
;
import
org.h2.util.JdbcUtils
;
import
org.h2.util.JdbcUtils
;
import
org.h2.util.MathUtils
;
import
org.h2.util.StringUtils
;
import
org.h2.util.Tool
;
import
org.h2.util.Tool
;
import
org.h2.util.Utils
;
import
org.h2.util.Utils
;
...
@@ -88,6 +90,7 @@ public class Console extends Tool implements ShutdownHandler {
...
@@ -88,6 +90,7 @@ public class Console extends Tool implements ShutdownHandler {
boolean
tcpShutdown
=
false
,
tcpShutdownForce
=
false
;
boolean
tcpShutdown
=
false
,
tcpShutdownForce
=
false
;
String
tcpPassword
=
""
;
String
tcpPassword
=
""
;
String
tcpShutdownServer
=
""
;
String
tcpShutdownServer
=
""
;
boolean
ifExists
=
false
,
webAllowOthers
=
false
;
for
(
int
i
=
0
;
args
!=
null
&&
i
<
args
.
length
;
i
++)
{
for
(
int
i
=
0
;
args
!=
null
&&
i
<
args
.
length
;
i
++)
{
String
arg
=
args
[
i
];
String
arg
=
args
[
i
];
if
(
arg
==
null
)
{
if
(
arg
==
null
)
{
...
@@ -109,6 +112,7 @@ public class Console extends Tool implements ShutdownHandler {
...
@@ -109,6 +112,7 @@ public class Console extends Tool implements ShutdownHandler {
webStart
=
true
;
webStart
=
true
;
}
else
if
(
"-webAllowOthers"
.
equals
(
arg
))
{
}
else
if
(
"-webAllowOthers"
.
equals
(
arg
))
{
// no parameters
// no parameters
webAllowOthers
=
true
;
}
else
if
(
"-webDaemon"
.
equals
(
arg
))
{
}
else
if
(
"-webDaemon"
.
equals
(
arg
))
{
// no parameters
// no parameters
}
else
if
(
"-webSSL"
.
equals
(
arg
))
{
}
else
if
(
"-webSSL"
.
equals
(
arg
))
{
...
@@ -168,6 +172,7 @@ public class Console extends Tool implements ShutdownHandler {
...
@@ -168,6 +172,7 @@ public class Console extends Tool implements ShutdownHandler {
// no parameters
// no parameters
}
else
if
(
"-ifExists"
.
equals
(
arg
))
{
}
else
if
(
"-ifExists"
.
equals
(
arg
))
{
// no parameters
// no parameters
ifExists
=
true
;
}
else
if
(
"-baseDir"
.
equals
(
arg
))
{
}
else
if
(
"-baseDir"
.
equals
(
arg
))
{
i
++;
i
++;
}
else
{
}
else
{
...
@@ -196,7 +201,9 @@ public class Console extends Tool implements ShutdownHandler {
...
@@ -196,7 +201,9 @@ public class Console extends Tool implements ShutdownHandler {
if
(
webStart
)
{
if
(
webStart
)
{
try
{
try
{
web
=
Server
.
createWebServer
(
args
);
String
webKey
=
webAllowOthers
?
null
:
StringUtils
.
convertBytesToHex
(
MathUtils
.
secureRandomBytes
(
32
));
web
=
Server
.
createWebServer
(
args
,
webKey
,
!
ifExists
);
web
.
setShutdownHandler
(
this
);
web
.
setShutdownHandler
(
this
);
web
.
start
();
web
.
start
();
if
(
printStatus
)
{
if
(
printStatus
)
{
...
...
h2/src/main/org/h2/tools/Server.java
浏览文件 @
b876d231
...
@@ -426,7 +426,24 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
...
@@ -426,7 +426,24 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
* @return the server
* @return the server
*/
*/
public
static
Server
createWebServer
(
String
...
args
)
throws
SQLException
{
public
static
Server
createWebServer
(
String
...
args
)
throws
SQLException
{
return
createWebServer
(
args
,
null
,
false
);
}
/**
* Create a new web server, but does not start it yet.
*
* @param args
* the argument list
* @param key
* key, or null
* @param allowSecureCreation
* whether creation of databases using the key should be allowed
* @return the server
*/
static
Server
createWebServer
(
String
[]
args
,
String
key
,
boolean
allowSecureCreation
)
throws
SQLException
{
WebServer
service
=
new
WebServer
();
WebServer
service
=
new
WebServer
();
service
.
setKey
(
key
);
service
.
setAllowSecureCreation
(
allowSecureCreation
);
Server
server
=
new
Server
(
service
,
args
);
Server
server
=
new
Server
(
service
,
args
);
service
.
setShutdownHandler
(
server
);
service
.
setShutdownHandler
(
server
);
return
server
;
return
server
;
...
@@ -492,7 +509,12 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
...
@@ -492,7 +509,12 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
try
{
try
{
started
=
true
;
started
=
true
;
service
.
start
();
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
);
Thread
t
=
new
Thread
(
this
,
name
);
t
.
setDaemon
(
service
.
isDaemon
());
t
.
setDaemon
(
service
.
isDaemon
());
t
.
start
();
t
.
start
();
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论