mirror of
https://github.com/KOHGYLW/kiftd-source.git
synced 2025-01-08 12:07:47 +08:00
kiftd-version-1.0.2v1-origin
This commit is contained in:
commit
c3ae82181d
26
.classpath
Normal file
26
.classpath
Normal file
@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
40
.project
Normal file
40
.project
Normal file
@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>kiftd</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.common.project.facet.core.builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.springframework.ide.eclipse.core.springbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.springframework.ide.eclipse.boot.validation.springbootbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.springframework.ide.eclipse.core.springnature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
4
.settings/org.eclipse.core.resources.prefs
Normal file
4
.settings/org.eclipse.core.resources.prefs
Normal file
@ -0,0 +1,4 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding//src/main/java=UTF-8
|
||||
encoding//src/test/java=UTF-8
|
||||
encoding/<project>=UTF-8
|
5
.settings/org.eclipse.jdt.core.prefs
Normal file
5
.settings/org.eclipse.jdt.core.prefs
Normal file
@ -0,0 +1,5 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
4
.settings/org.eclipse.m2e.core.prefs
Normal file
4
.settings/org.eclipse.m2e.core.prefs
Normal file
@ -0,0 +1,4 @@
|
||||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
resolveWorkspaceProjects=true
|
||||
version=1
|
4
.settings/org.eclipse.wst.common.project.facet.core.xml
Normal file
4
.settings/org.eclipse.wst.common.project.facet.core.xml
Normal file
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<faceted-project>
|
||||
<installed facet="cloudfoundry.standalone.app" version="1.0"/>
|
||||
</faceted-project>
|
BIN
conf/.DS_Store
vendored
Normal file
BIN
conf/.DS_Store
vendored
Normal file
Binary file not shown.
5
conf/account.properties
Normal file
5
conf/account.properties
Normal file
@ -0,0 +1,5 @@
|
||||
#<This is the default kiftd account setting file. >
|
||||
#Thu Jul 26 16:44:42 CST 2018
|
||||
admin.auth=cudr
|
||||
admin.pwd=000000
|
||||
authOverall=l
|
7
conf/server.properties
Normal file
7
conf/server.properties
Normal file
@ -0,0 +1,7 @@
|
||||
#<This is the default kiftd server setting file. >
|
||||
#Thu Jul 26 16:44:42 CST 2018
|
||||
port=8080
|
||||
mustLogin=O
|
||||
FS.path=DEFAULT
|
||||
log=E
|
||||
buff.size=1048576
|
BIN
filesystem/.DS_Store
vendored
Normal file
BIN
filesystem/.DS_Store
vendored
Normal file
Binary file not shown.
BIN
filesystem/filenodes/.DS_Store
vendored
Normal file
BIN
filesystem/filenodes/.DS_Store
vendored
Normal file
Binary file not shown.
BIN
filesystem/filenodes/kift.mv.db
Normal file
BIN
filesystem/filenodes/kift.mv.db
Normal file
Binary file not shown.
BIN
logs/.DS_Store
vendored
Normal file
BIN
logs/.DS_Store
vendored
Normal file
Binary file not shown.
79
logs/2018_07_30.klog
Normal file
79
logs/2018_07_30.klog
Normal file
@ -0,0 +1,79 @@
|
||||
TIME:
|
||||
2018年07月30日 08:41:13
|
||||
TYPE:
|
||||
Event
|
||||
CONTENT:
|
||||
>ACCOUNT [admin]
|
||||
>OPERATE [Upload file]
|
||||
>PATH [ROOT]
|
||||
>NAME [倾尽天下.lrc]
|
||||
|
||||
TIME:
|
||||
2018年07月30日 08:41:13
|
||||
TYPE:
|
||||
Event
|
||||
CONTENT:
|
||||
>ACCOUNT [admin]
|
||||
>OPERATE [Upload file]
|
||||
>PATH [ROOT]
|
||||
>NAME [河图.jpeg]
|
||||
|
||||
TIME:
|
||||
2018年07月30日 08:41:13
|
||||
TYPE:
|
||||
Event
|
||||
CONTENT:
|
||||
>ACCOUNT [admin]
|
||||
>OPERATE [Upload file]
|
||||
>PATH [ROOT]
|
||||
>NAME [倾尽天下.mp3]
|
||||
|
||||
TIME:
|
||||
2018年07月30日 10:07:13
|
||||
TYPE:
|
||||
Event
|
||||
CONTENT:
|
||||
>ACCOUNT [admin]
|
||||
>OPERATE [Upload file]
|
||||
>PATH [ROOT]
|
||||
>NAME [蚁人.Ant.Man.2015.中英字幕.1080p.BluRay.x264深影字幕组原创翻译.mp4]
|
||||
|
||||
TIME:
|
||||
2018年07月30日 10:07:58
|
||||
TYPE:
|
||||
Event
|
||||
CONTENT:
|
||||
>ACCOUNT [admin]
|
||||
>OPERATE [Delete file]
|
||||
>PATH [ROOT]
|
||||
>NAME [倾尽天下.lrc]
|
||||
|
||||
TIME:
|
||||
2018年07月30日 10:07:58
|
||||
TYPE:
|
||||
Event
|
||||
CONTENT:
|
||||
>ACCOUNT [admin]
|
||||
>OPERATE [Delete file]
|
||||
>PATH [ROOT]
|
||||
>NAME [倾尽天下.mp3]
|
||||
|
||||
TIME:
|
||||
2018年07月30日 10:07:58
|
||||
TYPE:
|
||||
Event
|
||||
CONTENT:
|
||||
>ACCOUNT [admin]
|
||||
>OPERATE [Delete file]
|
||||
>PATH [ROOT]
|
||||
>NAME [河图.jpeg]
|
||||
|
||||
TIME:
|
||||
2018年07月30日 10:07:58
|
||||
TYPE:
|
||||
Event
|
||||
CONTENT:
|
||||
>ACCOUNT [admin]
|
||||
>OPERATE [Delete file]
|
||||
>PATH [ROOT]
|
||||
>NAME [蚁人.Ant.Man.2015.中英字幕.1080p.BluRay.x264深影字幕组原创翻译.mp4]
|
BIN
mybatisResource/.DS_Store
vendored
Normal file
BIN
mybatisResource/.DS_Store
vendored
Normal file
Binary file not shown.
36
mybatisResource/mapperXML/FolderMapper.xml
Normal file
36
mybatisResource/mapperXML/FolderMapper.xml
Normal file
@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="kohgylw.kiftd.server.mapper.FolderMapper">
|
||||
<resultMap id="BaseResultMap" type="kohgylw.kiftd.server.model.Folder">
|
||||
<result column="folder_id" jdbcType="VARCHAR" property="folderId" />
|
||||
<result column="folder_name" jdbcType="VARCHAR" property="folderName" />
|
||||
<result column="folder_creation_date" jdbcType="VARCHAR" property="folderCreationDate" />
|
||||
<result column="folder_creator" jdbcType="VARCHAR" property="folderCreator" />
|
||||
<result column="folder_parent" jdbcType="VARCHAR" property="folderParent" />
|
||||
</resultMap>
|
||||
|
||||
<select id="queryById" parameterType="java.lang.String" resultMap="BaseResultMap">
|
||||
SELECT * FROM FOLDER WHERE folder_id = #{fid,jdbcType=VARCHAR}
|
||||
</select>
|
||||
|
||||
<select id="queryByParentId" parameterType="java.lang.String" resultMap="BaseResultMap">
|
||||
SELECT * FROM FOLDER WHERE folder_parent = #{pid,jdbcType=VARCHAR}
|
||||
</select>
|
||||
|
||||
<select id="queryByParentIdAndFolderName" parameterType="java.util.Map" resultMap="BaseResultMap">
|
||||
SELECT * FROM FOLDER WHERE folder_parent = #{parentId,jdbcType=VARCHAR} AND folder_name = #{folderName,jdbcType=VARCHAR}
|
||||
</select>
|
||||
|
||||
<insert id="insertNewFolder" parameterType="kohgylw.kiftd.server.model.Folder">
|
||||
INSERT INTO FOLDER VALUES(#{folderId,jdbcType=VARCHAR},#{folderName,jdbcType=VARCHAR},#{folderCreationDate,jdbcType=VARCHAR},#{folderCreator,jdbcType=VARCHAR},#{folderParent,jdbcType=VARCHAR});
|
||||
</insert>
|
||||
|
||||
<delete id="deleteById" parameterType="java.lang.String">
|
||||
DELETE FROM FOLDER WHERE folder_id=#{folderId,jdbcType=VARCHAR}
|
||||
</delete>
|
||||
|
||||
<update id="updateFolderNameById" parameterType="java.util.Map">
|
||||
UPDATE FOLDER SET folder_name = #{newName,jdbcType=VARCHAR} WHERE folder_id = #{folderId,jdbcType=VARCHAR}
|
||||
</update>
|
||||
|
||||
</mapper>
|
50
mybatisResource/mapperXML/NodeMapper.xml
Normal file
50
mybatisResource/mapperXML/NodeMapper.xml
Normal file
@ -0,0 +1,50 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="kohgylw.kiftd.server.mapper.NodeMapper">
|
||||
<resultMap id="BaseResultMap" type="kohgylw.kiftd.server.model.Node">
|
||||
<result column="file_id" jdbcType="VARCHAR" property="fileId" />
|
||||
<result column="file_name" jdbcType="VARCHAR" property="fileName" />
|
||||
<result column="file_size" jdbcType="VARCHAR" property="fileSize" />
|
||||
<result column="file_parent_folder" jdbcType="VARCHAR" property="fileParentFolder" />
|
||||
<result column="file_creation_date" jdbcType="VARCHAR" property="fileCreationDate" />
|
||||
<result column="file_creator" jdbcType="VARCHAR" property="fileCreator" />
|
||||
<result column="file_path" jdbcType="VARCHAR" property="filePath" />
|
||||
</resultMap>
|
||||
|
||||
<select id="queryByParentFolderId" parameterType="java.lang.String" resultMap="BaseResultMap">
|
||||
SELECT * FROM FILE WHERE file_parent_folder = #{pfid,jdbcType=VARCHAR}
|
||||
</select>
|
||||
|
||||
<insert id="insert" parameterType="kohgylw.kiftd.server.model.Node">
|
||||
INSERT INTO FILE VALUES(#{fileId,jdbcType=VARCHAR},#{fileName,jdbcType=VARCHAR},#{fileSize,jdbcType=VARCHAR},#{fileParentFolder,jdbcType=VARCHAR},#{fileCreationDate,jdbcType=VARCHAR},#{fileCreator,jdbcType=VARCHAR},#{filePath,jdbcType=VARCHAR})
|
||||
</insert>
|
||||
|
||||
<delete id="deleteByParentFolderId" parameterType="java.lang.String">
|
||||
DELETE FROM FILE WHERE file_parent_folder = #{pfid,jdbcType=VARCHAR}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteById" parameterType="java.lang.String">
|
||||
DELETE FROM FILE WHERE file_id = #{fileId,jdbcType=VARCHAR}
|
||||
</delete>
|
||||
|
||||
<select id="queryById" parameterType="java.lang.String" resultMap="BaseResultMap">
|
||||
SELECT * FROM FILE WHERE file_id = #{fileId,jdbcType=VARCHAR}
|
||||
</select>
|
||||
|
||||
<update id="updateFileNameById" parameterType="java.util.Map">
|
||||
UPDATE FILE SET file_name = #{newFileName,jdbcType=VARCHAR} WHERE file_id = #{fileId,jdbcType=VARCHAR}
|
||||
</update>
|
||||
|
||||
<select id="queryAll" resultMap="BaseResultMap">
|
||||
SELECT * FROM FILE
|
||||
</select>
|
||||
|
||||
<select id="queryByPath" parameterType="java.lang.String" resultMap="BaseResultMap">
|
||||
SELECT * FROM FILE WHERE file_path = #{path,jdbcType=VARCHAR}
|
||||
</select>
|
||||
|
||||
<select id="queryBySomeFolder" parameterType="java.lang.String" resultMap="BaseResultMap">
|
||||
SELECT * FROM FILE WHERE file_parent_folder in (SELECT file_parent_folder FROM FILE WHERE file_id = #{fileId,jdbcType=VARCHAR})
|
||||
</select>
|
||||
|
||||
</mapper>
|
7
mybatisResource/mybatis.xml
Normal file
7
mybatisResource/mybatis.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE configuration
|
||||
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-config.dtd">
|
||||
<configuration>
|
||||
|
||||
</configuration>
|
98
pom.xml
Normal file
98
pom.xml
Normal file
@ -0,0 +1,98 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>kohgylw</groupId>
|
||||
<artifactId>kiftd</artifactId>
|
||||
<version>1.0.2-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>kiftd</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<!-- Spring Boot 版本组设置 -->
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.0.2.RELEASE</version>
|
||||
</parent>
|
||||
<!-- end SpringBoot版本组 -->
|
||||
|
||||
<!-- 外部资源 -->
|
||||
<dependencies>
|
||||
<!-- SpringBoot web启动器 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<!-- end 启动器 -->
|
||||
|
||||
<!-- Gson json转化工具 -->
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
</dependency>
|
||||
<!-- end Gson -->
|
||||
|
||||
<!-- file 操作资源 -->
|
||||
<dependency>
|
||||
<groupId>commons-fileupload</groupId>
|
||||
<artifactId>commons-fileupload</artifactId>
|
||||
<version>1.3.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.4</version>
|
||||
</dependency>
|
||||
<!-- end file -->
|
||||
|
||||
<!-- h2内嵌数据库 + spring +mybatis -->
|
||||
<dependency>
|
||||
<groupId>org.mybatis</groupId>
|
||||
<artifactId>mybatis</artifactId>
|
||||
<version>3.4.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mybatis</groupId>
|
||||
<artifactId>mybatis-spring</artifactId>
|
||||
<version>1.3.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-jdbc</artifactId>
|
||||
</dependency>
|
||||
<!-- end hsm整合 -->
|
||||
|
||||
<!-- ZIP 压缩工具 -->
|
||||
<!-- https://mvnrepository.com/artifact/org.zeroturnaround/zt-zip -->
|
||||
<dependency>
|
||||
<groupId>org.zeroturnaround</groupId>
|
||||
<artifactId>zt-zip</artifactId>
|
||||
<version>1.13</version>
|
||||
</dependency>
|
||||
<!-- end ZIP -->
|
||||
|
||||
</dependencies>
|
||||
<!-- end 外部资源 -->
|
||||
|
||||
<!-- 打包工具配置 -->
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<!-- end 打包工具 -->
|
||||
|
||||
</project>
|
146
src/main/java/kohgylw/kiftd/mc/ConsoleRunner.java
Normal file
146
src/main/java/kohgylw/kiftd/mc/ConsoleRunner.java
Normal file
@ -0,0 +1,146 @@
|
||||
package kohgylw.kiftd.mc;
|
||||
|
||||
import kohgylw.kiftd.server.ctl.*;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
import kohgylw.kiftd.printer.*;
|
||||
import kohgylw.kiftd.server.util.*;
|
||||
|
||||
public class ConsoleRunner {
|
||||
private static ConsoleRunner cs;
|
||||
private static KiftdCtl ctl;
|
||||
private static String commandTips;
|
||||
|
||||
private ConsoleRunner() {
|
||||
Printer.init(false);
|
||||
ConsoleRunner.commandTips = "您可以输入以下指令以控制服务器:\r\n-start 启动服务器\r\n-stop 停止服务器\r\n-exit 停止服务器并退出应用\r\n-restart 重启服务器\r\n-status 查看服务器状态";
|
||||
}
|
||||
|
||||
public static ConsoleRunner build(final String[] args) {
|
||||
if (ConsoleRunner.cs == null) {
|
||||
ConsoleRunner.cs = new ConsoleRunner();
|
||||
}
|
||||
ConsoleRunner.cs.execute(args);
|
||||
return ConsoleRunner.cs;
|
||||
}
|
||||
|
||||
private void execute(final String[] args) {
|
||||
if (args.length > 0) {
|
||||
final String command = args[0];
|
||||
switch (command) {
|
||||
case "-console": {
|
||||
this.startKiftdByConsole();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
Printer.instance.print("kiftd:无效的指令,使用控制台模式启动请输入参数 -console,使用UI模式启动请不传入任何参数。");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void startKiftdByConsole() {
|
||||
Printer.instance.print(" 青阳网络文件系统-kiftd 控制台模式[Console model]");
|
||||
Printer.instance.print("kiftd:Character encoding with UTF-8");
|
||||
final Thread t = new Thread(() -> {
|
||||
Printer.instance.print("正在初始化服务器...");
|
||||
if (ConfigureReader.instance().getPropertiesStatus() == 0) {
|
||||
ConsoleRunner.ctl = new KiftdCtl();
|
||||
this.awaiting();
|
||||
} else {
|
||||
Printer.instance.print("服务器参数配置错误,无法启动kiftd,请检查。");
|
||||
}
|
||||
return;
|
||||
});
|
||||
t.start();
|
||||
}
|
||||
|
||||
private void startServer() {
|
||||
Printer.instance.print("执行命令:启动服务器...");
|
||||
if (ConsoleRunner.ctl.started()) {
|
||||
Printer.instance.print("错误:服务器已经启动了。");
|
||||
} else if (ConsoleRunner.ctl.start()) {
|
||||
Printer.instance.print("kiftd服务器已启动,可以正常访问了,您可以使用 -status 指令查看运行状态。");
|
||||
} else {
|
||||
Printer.instance.print("错误:kiftd服务器未能启动,请重试或检查设置。");
|
||||
}
|
||||
}
|
||||
|
||||
private void exit() {
|
||||
Printer.instance.print("执行命令:停止服务器并退出kiftd...");
|
||||
if (ConsoleRunner.ctl.started() && ConsoleRunner.ctl.stop()) {
|
||||
Printer.instance.print("服务器已关闭,停止所有访问。");
|
||||
}
|
||||
Printer.instance.print("退出应用。");
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
private void restartServer() {
|
||||
Printer.instance.print("执行命令:重启服务器...");
|
||||
if (ConsoleRunner.ctl.started()) {
|
||||
if (ConsoleRunner.ctl.stop()) {
|
||||
if (ConsoleRunner.ctl.start()) {
|
||||
Printer.instance.print("服务器重启成功,可以正常访问了。");
|
||||
} else {
|
||||
Printer.instance.print("错误:无法重新启动服务器,请尝试手动启动。");
|
||||
}
|
||||
} else {
|
||||
Printer.instance.print("错误:无法关闭服务器,请尝试手动关闭。");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void stopServer() {
|
||||
Printer.instance.print("执行命令:停止服务器...");
|
||||
if (ConsoleRunner.ctl.started()) {
|
||||
if (ConsoleRunner.ctl.stop()) {
|
||||
Printer.instance.print("服务器已关闭,停止所有访问。");
|
||||
} else {
|
||||
Printer.instance.print("错误:无法关闭服务器,您可以尝试强制关闭。");
|
||||
}
|
||||
} else {
|
||||
Printer.instance.print("错误:服务器尚未启动。");
|
||||
}
|
||||
}
|
||||
|
||||
private void awaiting() {
|
||||
Thread t = new Thread(() -> {
|
||||
Scanner reader = new Scanner(System.in);
|
||||
while (true) {
|
||||
String command = reader.nextLine();
|
||||
switch (command) {
|
||||
case "-start":
|
||||
startServer();
|
||||
break;
|
||||
case "-stop":
|
||||
stopServer();
|
||||
break;
|
||||
case "-restart":
|
||||
restartServer();
|
||||
break;
|
||||
case "-status":
|
||||
printServerStatus();
|
||||
break;
|
||||
case "-exit":
|
||||
reader.close();
|
||||
exit();
|
||||
return;
|
||||
default:
|
||||
Printer.instance.print(commandTips);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
t.start();
|
||||
}
|
||||
|
||||
private void printServerStatus() {
|
||||
Printer.instance.print("服务器状态:\r\n<Port>端口号:" + ConfigureReader.instance().getPort() + "\r\n<LogLevel>日志等级:"
|
||||
+ ConfigureReader.instance().getLogLevel() + "\r\n<BufferSize>缓冲区大小:"
|
||||
+ ConfigureReader.instance().getBuffSize() + " B\r\n<FileSystemPath>文件系统存储路径:"
|
||||
+ ConfigureReader.instance().getFileSystemPath() + "\r\n<MustLogin>是否必须登录:"
|
||||
+ ConfigureReader.instance().mustLogin() + "\r\n<Running>运行状态:" + ConsoleRunner.ctl.started());
|
||||
}
|
||||
}
|
13
src/main/java/kohgylw/kiftd/mc/MC.java
Normal file
13
src/main/java/kohgylw/kiftd/mc/MC.java
Normal file
@ -0,0 +1,13 @@
|
||||
package kohgylw.kiftd.mc;
|
||||
|
||||
public class MC
|
||||
{
|
||||
public static void main(final String[] args) {
|
||||
if (args == null || args.length == 0) {
|
||||
UIRunner.build();
|
||||
}
|
||||
else {
|
||||
ConsoleRunner.build(args);
|
||||
}
|
||||
}
|
||||
}
|
82
src/main/java/kohgylw/kiftd/mc/UIRunner.java
Normal file
82
src/main/java/kohgylw/kiftd/mc/UIRunner.java
Normal file
@ -0,0 +1,82 @@
|
||||
package kohgylw.kiftd.mc;
|
||||
|
||||
import kohgylw.kiftd.printer.*;
|
||||
import kohgylw.kiftd.ui.module.*;
|
||||
import kohgylw.kiftd.server.ctl.*;
|
||||
import kohgylw.kiftd.server.enumeration.LogLevel;
|
||||
import kohgylw.kiftd.server.util.ConfigureReader;
|
||||
import kohgylw.kiftd.server.util.ServerTimeUtil;
|
||||
import kohgylw.kiftd.ui.callback.*;
|
||||
|
||||
public class UIRunner {
|
||||
|
||||
private static UIRunner ui;
|
||||
|
||||
private UIRunner() {
|
||||
Printer.init(true);
|
||||
final ServerUIModule ui = ServerUIModule.getInsatnce();
|
||||
ui.show();
|
||||
final Thread t = new Thread(() -> {
|
||||
KiftdCtl ctl = new KiftdCtl();
|
||||
ServerUIModule.setStartServer(() -> ctl.start());
|
||||
ServerUIModule.setOnCloseServer(() -> ctl.stop());
|
||||
ServerUIModule.setGetServerTime(() -> ServerTimeUtil.getServerTime());
|
||||
ServerUIModule.setGetServerStatus(new GetServerStatus() {
|
||||
|
||||
@Override
|
||||
public boolean getServerStatus() {
|
||||
// TODO 自动生成的方法存根
|
||||
return ctl.started();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getPropertiesStatus() {
|
||||
// TODO 自动生成的方法存根
|
||||
return ConfigureReader.instance().getPropertiesStatus()==ConfigureReader.LEGAL_PROPERTIES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPort() {
|
||||
// TODO 自动生成的方法存根
|
||||
return ConfigureReader.instance().getPort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getMustLogin() {
|
||||
// TODO 自动生成的方法存根
|
||||
return ConfigureReader.instance().mustLogin();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LogLevel getLogLevel() {
|
||||
// TODO 自动生成的方法存根
|
||||
return ConfigureReader.instance().getLogLevel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFileSystemPath() {
|
||||
// TODO 自动生成的方法存根
|
||||
return ConfigureReader.instance().getFileSystemPath();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBufferSize() {
|
||||
// TODO 自动生成的方法存根
|
||||
return ConfigureReader.instance().getBuffSize();
|
||||
}
|
||||
});
|
||||
ServerUIModule.setUpdateSetting((ss)->ConfigureReader.instance().doUpdate(ss));
|
||||
if(ConfigureReader.instance().getPropertiesStatus()==ConfigureReader.LEGAL_PROPERTIES) {
|
||||
ui.updateServerStatus();
|
||||
}
|
||||
});
|
||||
t.start();
|
||||
}
|
||||
|
||||
public static UIRunner build() {
|
||||
if (UIRunner.ui == null) {
|
||||
UIRunner.ui = new UIRunner();
|
||||
}
|
||||
return UIRunner.ui;
|
||||
}
|
||||
}
|
30
src/main/java/kohgylw/kiftd/printer/Printer.java
Normal file
30
src/main/java/kohgylw/kiftd/printer/Printer.java
Normal file
@ -0,0 +1,30 @@
|
||||
package kohgylw.kiftd.printer;
|
||||
|
||||
import kohgylw.kiftd.ui.module.*;
|
||||
import kohgylw.kiftd.server.util.*;
|
||||
|
||||
public class Printer
|
||||
{
|
||||
public static Printer instance;
|
||||
private static boolean isUIModel;
|
||||
private static ServerUIModule sum;
|
||||
|
||||
public static void init(final boolean isUIModel) {
|
||||
Printer.instance = new Printer();
|
||||
if (isUIModel) {
|
||||
Printer.sum = ServerUIModule.getInsatnce();
|
||||
}
|
||||
Printer.isUIModel = isUIModel;
|
||||
}
|
||||
|
||||
public void print(final String context) {
|
||||
if (Printer.instance != null) {
|
||||
if (Printer.isUIModel) {
|
||||
Printer.sum.printMessage(context);
|
||||
}
|
||||
else {
|
||||
System.out.println("[" + ServerTimeUtil.accurateToSecond() + "]" + context + "\r\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package kohgylw.kiftd.server.configation;
|
||||
|
||||
import javax.sql.*;
|
||||
import org.springframework.jdbc.datasource.*;
|
||||
import kohgylw.kiftd.server.util.*;
|
||||
import org.springframework.context.annotation.*;
|
||||
import org.mybatis.spring.*;
|
||||
import org.springframework.beans.factory.annotation.*;
|
||||
import org.mybatis.spring.mapper.*;
|
||||
import java.io.*;
|
||||
import org.springframework.core.io.*;
|
||||
|
||||
@Configurable
|
||||
public class DataAccess
|
||||
{
|
||||
private static Resource[] mapperFiles;
|
||||
private static Resource mybatisConfg;
|
||||
|
||||
@Bean
|
||||
public DataSource dataSource() {
|
||||
final DriverManagerDataSource ds = new DriverManagerDataSource();
|
||||
ds.setDriverClassName("org.h2.Driver");
|
||||
ds.setUrl("jdbc:h2:file:" + ConfigureReader.instance().getFileNodePath() + "kift");
|
||||
ds.setUsername("root");
|
||||
ds.setPassword("301537gY");
|
||||
return (DataSource)ds;
|
||||
}
|
||||
|
||||
@Bean(name = { "sqlSessionFactory" })
|
||||
@Autowired
|
||||
public SqlSessionFactoryBean sqlSessionFactoryBean(final DataSource ds) {
|
||||
final SqlSessionFactoryBean ssf = new SqlSessionFactoryBean();
|
||||
ssf.setDataSource(ds);
|
||||
ssf.setConfigLocation(DataAccess.mybatisConfg);
|
||||
ssf.setMapperLocations(DataAccess.mapperFiles);
|
||||
return ssf;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MapperScannerConfigurer mapperScannerConfigurer() {
|
||||
final MapperScannerConfigurer msf = new MapperScannerConfigurer();
|
||||
msf.setBasePackage("kohgylw.kiftd.server.mapper");
|
||||
msf.setSqlSessionFactoryBeanName("sqlSessionFactory");
|
||||
return msf;
|
||||
}
|
||||
|
||||
static {
|
||||
final String mybatisResourceFolder = ConfigureReader.instance().getPath() + File.separator + "mybatisResource" + File.separator;
|
||||
final String mapperFilesFolder = mybatisResourceFolder + "mapperXML" + File.separator;
|
||||
DataAccess.mapperFiles = new Resource[] { new FileSystemResource(mapperFilesFolder + "NodeMapper.xml"), new FileSystemResource(mapperFilesFolder + "FolderMapper.xml") };
|
||||
DataAccess.mybatisConfg = (Resource)new FileSystemResource(mybatisResourceFolder + "mybatis.xml");
|
||||
}
|
||||
}
|
39
src/main/java/kohgylw/kiftd/server/configation/MVC.java
Normal file
39
src/main/java/kohgylw/kiftd/server/configation/MVC.java
Normal file
@ -0,0 +1,39 @@
|
||||
package kohgylw.kiftd.server.configation;
|
||||
|
||||
import org.springframework.web.servlet.resource.*;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import org.springframework.beans.factory.annotation.*;
|
||||
import org.springframework.web.servlet.config.annotation.*;
|
||||
import kohgylw.kiftd.server.util.*;
|
||||
import java.io.*;
|
||||
import javax.servlet.*;
|
||||
import org.springframework.boot.web.servlet.*;
|
||||
import org.springframework.context.annotation.*;
|
||||
|
||||
@Configurable
|
||||
@ComponentScan({ "kohgylw.kiftd.server.controller", "kohgylw.kiftd.server.service.impl", "kohgylw.kiftd.server.util" })
|
||||
@ServletComponentScan({ "kohgylw.kiftd.server.listener", "kohgylw.kiftd.server.filter" })
|
||||
@Import({ DataAccess.class })
|
||||
public class MVC extends ResourceHttpRequestHandler implements WebMvcConfigurer {
|
||||
public void addResourceHandlers(final ResourceHandlerRegistry registry) {
|
||||
registry.addResourceHandler(new String[] { "/**" }).addResourceLocations(new String[] {
|
||||
"file:" + ConfigureReader.instance().getPath() + File.separator + "webContext" + File.separator });
|
||||
registry.addResourceHandler(new String[] { "/fileblocks/**" })
|
||||
.addResourceLocations(new String[] { "file:" + ConfigureReader.instance().getFileBlockPath() });
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MultipartConfigElement multipartConfigElement() {
|
||||
final MultipartConfigFactory factory = new MultipartConfigFactory();
|
||||
factory.setMaxFileSize(-1L);
|
||||
factory.setLocation(ConfigureReader.instance().getTemporaryfilePath());
|
||||
return factory.createMultipartConfig();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Gson gson() {
|
||||
return new Gson();
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package kohgylw.kiftd.server.controller;
|
||||
|
||||
import javax.annotation.*;
|
||||
import kohgylw.kiftd.server.util.*;
|
||||
import javax.servlet.http.*;
|
||||
import kohgylw.kiftd.printer.*;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@ControllerAdvice
|
||||
@RequestMapping({ "/errorController" })
|
||||
public class ErrorController
|
||||
{
|
||||
@Resource
|
||||
private FileBlockUtil fbu;
|
||||
@Resource
|
||||
private LogUtil lu;
|
||||
|
||||
@RequestMapping({ "/pageNotFound.do" })
|
||||
public String handleError(final HttpServletRequest request, final HttpServletResponse response) {
|
||||
return response.encodeURL("/prv/error.html");
|
||||
}
|
||||
|
||||
@ExceptionHandler({ Exception.class })
|
||||
public void handleException(final Exception e) {
|
||||
this.lu.writeException(e);
|
||||
this.fbu.checkFileBlocks();
|
||||
Printer.instance.print("\u5904\u7406\u8bf7\u6c42\u65f6\u53d1\u751f\u9519\u8bef\uff1a\n\r------\u4fe1\u606f------\n\r" + e.getMessage() + "\n\r------\u4fe1\u606f------");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
@ -0,0 +1,168 @@
|
||||
package kohgylw.kiftd.server.controller;
|
||||
|
||||
import org.springframework.stereotype.*;
|
||||
import javax.annotation.*;
|
||||
import kohgylw.kiftd.server.service.*;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.*;
|
||||
import javax.servlet.http.*;
|
||||
import kohgylw.kiftd.server.model.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* <h2>主控制器</h2>
|
||||
* <p>该控制器用于负责处理kiftd主页(home.html)的所有请求,具体过程请见各个方法注释。</p>
|
||||
* @author 青阳龙野(kohgylw)
|
||||
* @version 1.0
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping({ "/homeController" })
|
||||
public class HomeController
|
||||
{
|
||||
private static final String CHARSET_BY_AJAX = "text/html; charset=utf-8";
|
||||
@Resource
|
||||
private ServerInfoService si;
|
||||
@Resource
|
||||
private AccountService as;
|
||||
@Resource
|
||||
private FolderViewService fvs;
|
||||
@Resource
|
||||
private FolderService fs;
|
||||
@Resource
|
||||
private FileService fis;
|
||||
@Resource
|
||||
private PlayVideoService pvs;
|
||||
@Resource
|
||||
private PdfViewService pdvs;
|
||||
@Resource
|
||||
private ShowPictureService sps;
|
||||
@Resource
|
||||
private PlayAudioService pas;
|
||||
|
||||
@RequestMapping({ "/getServerOS.ajax" })
|
||||
@ResponseBody
|
||||
public String getServerOS() {
|
||||
return this.si.getOSName();
|
||||
}
|
||||
|
||||
@RequestMapping(value = { "/getPublicKey.ajax" }, produces = { CHARSET_BY_AJAX })
|
||||
@ResponseBody
|
||||
public String getPublicKey() {
|
||||
return this.as.getPublicKey();
|
||||
}
|
||||
|
||||
@RequestMapping({ "/doLogin.ajax" })
|
||||
@ResponseBody
|
||||
public String doLogin(final HttpServletRequest request, final HttpSession session) {
|
||||
return this.as.checkLoginRequest(request, session);
|
||||
}
|
||||
|
||||
@RequestMapping(value = { "/getFolderView.ajax" }, produces = { CHARSET_BY_AJAX })
|
||||
@ResponseBody
|
||||
public String getFolderView(final String fid, final HttpSession session, final HttpServletRequest request) {
|
||||
return fvs.getFolderViewToJson(fid, session, request);
|
||||
}
|
||||
|
||||
@RequestMapping({ "/doLogout.do" })
|
||||
public String doLogout(final HttpSession session) {
|
||||
this.as.logout(session);
|
||||
return "redirect:/home.html";
|
||||
}
|
||||
|
||||
@RequestMapping({ "/newFolder.ajax" })
|
||||
@ResponseBody
|
||||
public String newFolder(final HttpServletRequest request) {
|
||||
return this.fs.newFolder(request);
|
||||
}
|
||||
|
||||
@RequestMapping({ "/deleteFolder.ajax" })
|
||||
@ResponseBody
|
||||
public String deleteFolder(final HttpServletRequest request) {
|
||||
return this.fs.deleteFolder(request);
|
||||
}
|
||||
|
||||
@RequestMapping({ "/renameFolder.ajax" })
|
||||
@ResponseBody
|
||||
public String renameFolder(final HttpServletRequest request) {
|
||||
return this.fs.renameFolder(request);
|
||||
}
|
||||
|
||||
@RequestMapping(value = { "/douploadFile.ajax" }, produces = { CHARSET_BY_AJAX })
|
||||
@ResponseBody
|
||||
public String douploadFile(final HttpServletRequest request, final MultipartFile file) {
|
||||
return this.fis.doUploadFile(request, file);
|
||||
}
|
||||
|
||||
@RequestMapping(value = { "/checkUploadFile.ajax" }, produces = { CHARSET_BY_AJAX })
|
||||
@ResponseBody
|
||||
public String checkUploadFile(final HttpServletRequest request) {
|
||||
return this.fis.checkUploadFile(request);
|
||||
}
|
||||
|
||||
@RequestMapping({ "/deleteFile.ajax" })
|
||||
@ResponseBody
|
||||
public String deleteFile(final HttpServletRequest request) {
|
||||
return this.fis.deleteFile(request);
|
||||
}
|
||||
|
||||
@RequestMapping({ "/downloadFile.do" })
|
||||
public void downloadFile(final HttpServletRequest request, final HttpServletResponse response) {
|
||||
this.fis.doDownloadFile(request, response);
|
||||
}
|
||||
|
||||
@RequestMapping({ "/renameFile.ajax" })
|
||||
@ResponseBody
|
||||
public String renameFile(final HttpServletRequest request) {
|
||||
return this.fis.doRenameFile(request);
|
||||
}
|
||||
|
||||
@RequestMapping(value = { "/playVideo.ajax" }, produces = { CHARSET_BY_AJAX })
|
||||
@ResponseBody
|
||||
public String playVideo(final HttpServletRequest request, final HttpServletResponse response) {
|
||||
return this.pvs.getPlayVideoJson(request);
|
||||
}
|
||||
|
||||
@RequestMapping({ "/pdfView.do" })
|
||||
public String pdfView(final HttpServletRequest request, final HttpServletResponse response) {
|
||||
final Node f = this.pdvs.foundPdf(request);
|
||||
if (f != null) {
|
||||
return "redirect:" + response.encodeURL("/pdfview/web/viewer.html?file=" + request.getContextPath() + "/fileblocks/" + f.getFilePath());
|
||||
}
|
||||
return response.encodeURL("/errorController/pageNotFound.do");
|
||||
}
|
||||
|
||||
@RequestMapping(value = { "/getPrePicture.ajax" }, produces = { CHARSET_BY_AJAX })
|
||||
@ResponseBody
|
||||
public String getPrePicture(final HttpServletRequest request) {
|
||||
return this.sps.getPreviewPictureJson(request);
|
||||
}
|
||||
|
||||
@RequestMapping({ "/deleteCheckedFiles.ajax" })
|
||||
@ResponseBody
|
||||
public String deleteCheckedFiles(final HttpServletRequest request) {
|
||||
return this.fis.deleteCheckedFiles(request);
|
||||
}
|
||||
|
||||
@RequestMapping({ "/getPackTime.ajax" })
|
||||
@ResponseBody
|
||||
public String getPackTime(final HttpServletRequest request) {
|
||||
return this.fis.getPackTime(request);
|
||||
}
|
||||
|
||||
@RequestMapping({ "/downloadCheckedFiles.ajax" })
|
||||
@ResponseBody
|
||||
public String downloadCheckedFiles(final HttpServletRequest request) {
|
||||
return this.fis.downloadCheckedFiles(request);
|
||||
}
|
||||
|
||||
@RequestMapping({ "/downloadCheckedFilesZip.do" })
|
||||
public void downloadCheckedFilesZip(final HttpServletRequest request, final HttpServletResponse response) throws Exception {
|
||||
this.fis.downloadCheckedFilesZip(request, response);
|
||||
}
|
||||
|
||||
@RequestMapping(value = { "/playAudios.ajax" }, produces = { CHARSET_BY_AJAX })
|
||||
@ResponseBody
|
||||
public String playAudios(final HttpServletRequest request) {
|
||||
return this.pas.getAudioInfoListByJson(request);
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package kohgylw.kiftd.server.controller;
|
||||
|
||||
import org.springframework.stereotype.*;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@Controller
|
||||
public class WelcomeController
|
||||
{
|
||||
@RequestMapping({ "/" })
|
||||
public String home() {
|
||||
return "redirect:/home.html";
|
||||
}
|
||||
}
|
74
src/main/java/kohgylw/kiftd/server/ctl/KiftdCtl.java
Normal file
74
src/main/java/kohgylw/kiftd/server/ctl/KiftdCtl.java
Normal file
@ -0,0 +1,74 @@
|
||||
package kohgylw.kiftd.server.ctl;
|
||||
|
||||
import org.springframework.boot.web.servlet.server.*;
|
||||
import org.springframework.boot.autoconfigure.*;
|
||||
import org.springframework.context.annotation.*;
|
||||
import kohgylw.kiftd.server.configation.*;
|
||||
import org.springframework.context.*;
|
||||
import kohgylw.kiftd.printer.*;
|
||||
import kohgylw.kiftd.server.util.*;
|
||||
import org.springframework.boot.*;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.boot.web.server.*;
|
||||
|
||||
@SpringBootApplication
|
||||
@Import({ MVC.class })
|
||||
public class KiftdCtl implements WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> {
|
||||
private static ApplicationContext context;
|
||||
private static boolean run;
|
||||
|
||||
public boolean start() {
|
||||
Printer.instance.print("\u6b63\u5728\u542f\u52a8\u670d\u52a1\u5668...");
|
||||
final String[] args = new String[0];
|
||||
if (!KiftdCtl.run) {
|
||||
if (ConfigureReader.instance().getPropertiesStatus() == 0) {
|
||||
try {
|
||||
Printer.instance.print("\u6b63\u5728\u5f00\u542f\u670d\u52a1\u5668\u5f15\u64ce...");
|
||||
KiftdCtl.context = (ApplicationContext) SpringApplication.run(KiftdCtl.class, args);
|
||||
KiftdCtl.run = (KiftdCtl.context != null);
|
||||
Printer.instance.print("\u670d\u52a1\u5668\u5f15\u64ce\u5df2\u542f\u52a8\u3002");
|
||||
return KiftdCtl.run;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Printer.instance.print(
|
||||
"\u670d\u52a1\u5668\u8bbe\u7f6e\u68c0\u67e5\u5931\u8d25\uff0c\u65e0\u6cd5\u5f00\u542f\u670d\u52a1\u5668\u3002");
|
||||
return false;
|
||||
}
|
||||
Printer.instance.print("\u670d\u52a1\u5668\u6b63\u5728\u8fd0\u884c\u4e2d\u3002");
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean stop() {
|
||||
Printer.instance.print("\u6b63\u5728\u5173\u95ed\u670d\u52a1\u5668...");
|
||||
if (KiftdCtl.context != null) {
|
||||
Printer.instance.print("\u6b63\u5728\u7ec8\u6b62\u670d\u52a1\u5668\u5f15\u64ce...");
|
||||
try {
|
||||
KiftdCtl.run = (SpringApplication.exit(KiftdCtl.context, new ExitCodeGenerator[0]) != 0);
|
||||
Printer.instance.print("\u670d\u52a1\u5668\u5f15\u64ce\u5df2\u7ec8\u6b62\u3002");
|
||||
return !KiftdCtl.run;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Printer.instance.print("\u670d\u52a1\u5668\u672a\u542f\u52a8\u3002");
|
||||
return true;
|
||||
}
|
||||
|
||||
public void customize(final ConfigurableServletWebServerFactory factory) {
|
||||
factory.setPort(ConfigureReader.instance().getPort());
|
||||
factory.addErrorPages(
|
||||
new ErrorPage[] { new ErrorPage(HttpStatus.NOT_FOUND, "/errorController/pageNotFound.do") });
|
||||
factory.addErrorPages(new ErrorPage[] {
|
||||
new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/errorController/pageNotFound.do") });
|
||||
}
|
||||
|
||||
public boolean started() {
|
||||
return KiftdCtl.run;
|
||||
}
|
||||
|
||||
static {
|
||||
KiftdCtl.run = false;
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package kohgylw.kiftd.server.enumeration;
|
||||
|
||||
public enum AccountAuth
|
||||
{
|
||||
CREATE_NEW_FOLDER,
|
||||
UPLOAD_FILES,
|
||||
DELETE_FILE_OR_FOLDER,
|
||||
RENAME_FILE_OR_FOLDER,
|
||||
DOWNLOAD_FILES;
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package kohgylw.kiftd.server.enumeration;
|
||||
|
||||
public enum LogLevel
|
||||
{
|
||||
None,
|
||||
Runtime_Exception,
|
||||
Event;
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
package kohgylw.kiftd.server.filter;
|
||||
|
||||
import javax.servlet.annotation.*;
|
||||
import javax.servlet.*;
|
||||
import kohgylw.kiftd.server.util.*;
|
||||
import javax.servlet.http.*;
|
||||
import java.io.*;
|
||||
|
||||
@WebFilter
|
||||
public class MastLoginFilter implements Filter
|
||||
{
|
||||
public void init(final FilterConfig filterConfig) throws ServletException {
|
||||
}
|
||||
|
||||
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
|
||||
final ConfigureReader cr = ConfigureReader.instance();
|
||||
final boolean s = cr.mustLogin();
|
||||
final HttpServletRequest hsq = (HttpServletRequest)request;
|
||||
final HttpServletResponse hsr = (HttpServletResponse)response;
|
||||
final String url = hsq.getServletPath();
|
||||
final HttpSession session = hsq.getSession();
|
||||
if (url.equals("//prv/login.html") || url.equals("/prv/login.html")) {
|
||||
if (s) {
|
||||
final String account = (String)session.getAttribute("ACCOUNT");
|
||||
if (cr.foundAccount(account)) {
|
||||
hsr.sendRedirect("/home.html");
|
||||
}
|
||||
else {
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
}
|
||||
else {
|
||||
hsr.sendRedirect("/home.html");
|
||||
}
|
||||
}
|
||||
else if (s) {
|
||||
if (url.equals("/") || url.endsWith(".html") || url.endsWith(".do")) {
|
||||
if (session.getAttribute("ACCOUNT") != null) {
|
||||
final String account = (String)session.getAttribute("ACCOUNT");
|
||||
if (cr.foundAccount(account)) {
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
else {
|
||||
hsr.sendRedirect("/prv/login.html");
|
||||
}
|
||||
}
|
||||
else {
|
||||
hsr.sendRedirect("/prv/login.html");
|
||||
}
|
||||
}
|
||||
else if (url.endsWith(".ajax")) {
|
||||
if (url.equals("/homeController/doLogin.ajax") || url.equals("/homeController/getPublicKey.ajax")) {
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
else if (session.getAttribute("ACCOUNT") != null) {
|
||||
final String account = (String)session.getAttribute("ACCOUNT");
|
||||
if (cr.foundAccount(account)) {
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
else {
|
||||
hsr.setCharacterEncoding("UTF-8");
|
||||
final PrintWriter pw = hsr.getWriter();
|
||||
pw.print("mustLogin");
|
||||
pw.flush();
|
||||
}
|
||||
}
|
||||
else {
|
||||
hsr.setCharacterEncoding("UTF-8");
|
||||
final PrintWriter pw2 = hsr.getWriter();
|
||||
pw2.print("mustLogin");
|
||||
pw2.flush();
|
||||
}
|
||||
}
|
||||
else {
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
}
|
||||
else {
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
}
|
||||
}
|
35
src/main/java/kohgylw/kiftd/server/filter/VCFilter.java
Normal file
35
src/main/java/kohgylw/kiftd/server/filter/VCFilter.java
Normal file
@ -0,0 +1,35 @@
|
||||
package kohgylw.kiftd.server.filter;
|
||||
|
||||
import javax.servlet.annotation.*;
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.*;
|
||||
import kohgylw.kiftd.server.util.*;
|
||||
import kohgylw.kiftd.server.enumeration.*;
|
||||
import java.io.*;
|
||||
|
||||
@WebFilter
|
||||
public class VCFilter implements Filter
|
||||
{
|
||||
public void init(final FilterConfig filterConfig) throws ServletException {
|
||||
}
|
||||
|
||||
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
|
||||
final HttpServletRequest hsr = (HttpServletRequest)request;
|
||||
final String url = hsr.getServletPath();
|
||||
if (url.startsWith("/fileblocks/") || url.startsWith("//fileblocks/")) {
|
||||
final String account = (String)hsr.getSession().getAttribute("ACCOUNT");
|
||||
if (ConfigureReader.instance().authorized(account, AccountAuth.DOWNLOAD_FILES)) {
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
else {
|
||||
hsr.getRequestDispatcher("/errorController/pageNotFound.do").forward(request, response);
|
||||
}
|
||||
}
|
||||
else {
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
}
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
package kohgylw.kiftd.server.listener;
|
||||
|
||||
import javax.servlet.annotation.*;
|
||||
import javax.servlet.*;
|
||||
import kohgylw.kiftd.printer.*;
|
||||
import kohgylw.kiftd.server.util.*;
|
||||
import java.io.*;
|
||||
import java.sql.*;
|
||||
|
||||
@WebListener
|
||||
public class H2DBinitListener implements ServletContextListener {
|
||||
public void contextInitialized(final ServletContextEvent sce) {
|
||||
Printer.instance.print("\u6587\u4ef6\u7cfb\u7edf\u521d\u59cb\u5316...");
|
||||
try {
|
||||
Class.forName("org.h2.Driver");
|
||||
final Connection conn = DriverManager.getConnection(
|
||||
"jdbc:h2:file:" + ConfigureReader.instance().getFileNodePath() + "kift", "root", "301537gY");
|
||||
final Statement state1 = conn.createStatement();
|
||||
ResultSet result = state1
|
||||
.executeQuery("SELECT count(*) from INFORMATION_SCHEMA.TABLES where TABLE_NAME='FOLDER'");
|
||||
while (result.next()) {
|
||||
if (result.getInt("count(*)") > 0) {
|
||||
continue;
|
||||
}
|
||||
final Statement state2 = conn.createStatement();
|
||||
state2.execute(
|
||||
"CREATE TABLE FOLDER(folder_id VARCHAR(128) PRIMARY KEY, folder_name VARCHAR(128) NOT NULL,folder_creation_date VARCHAR(128) NOT NULL, folder_creator VARCHAR(128) NOT NULL,folder_parent VARCHAR(128) NOT NULL)");
|
||||
state2.execute("INSERT INTO FOLDER VALUES('root', 'ROOT', '--', '--', 'null')");
|
||||
state2.close();
|
||||
}
|
||||
result = state1.executeQuery("SELECT count(*) from INFORMATION_SCHEMA.TABLES where TABLE_NAME='FILE'");
|
||||
while (result.next()) {
|
||||
if (result.getInt("count(*)") > 0) {
|
||||
continue;
|
||||
}
|
||||
final Statement state3 = conn.createStatement();
|
||||
state3.execute(
|
||||
"CREATE TABLE FILE(file_id VARCHAR(128) PRIMARY KEY,file_name VARCHAR(128) NOT NULL,file_size VARCHAR(128) NOT NULL,file_parent_folder varchar(128) NOT NULL,file_creation_date varchar(128) NOT NULL,file_creator varchar(128) NOT NULL,file_path varchar(128) NOT NULL)");
|
||||
state3.close();
|
||||
final String fileblocks = sce.getServletContext().getRealPath("/fileblocks");
|
||||
final File fb = new File(fileblocks);
|
||||
if (fb.exists() && fb.isDirectory()) {
|
||||
final String[] flist = fb.list();
|
||||
for (final String s : flist) {
|
||||
new File(fb, s).delete();
|
||||
}
|
||||
} else {
|
||||
fb.mkdirs();
|
||||
}
|
||||
}
|
||||
state1.close();
|
||||
conn.close();
|
||||
Printer.instance.print("\u521d\u59cb\u5316\u5b8c\u6210\u3002");
|
||||
} catch (Exception e) {
|
||||
Printer.instance.print("\u521d\u59cb\u5316\u5931\u8d25\u3002");
|
||||
Printer.instance.print(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void contextDestroyed(final ServletContextEvent sce) {
|
||||
}
|
||||
}
|
48
src/main/java/kohgylw/kiftd/server/listener/SCListener.java
Normal file
48
src/main/java/kohgylw/kiftd/server/listener/SCListener.java
Normal file
@ -0,0 +1,48 @@
|
||||
package kohgylw.kiftd.server.listener;
|
||||
|
||||
import javax.servlet.annotation.*;
|
||||
import javax.servlet.*;
|
||||
import kohgylw.kiftd.printer.*;
|
||||
import java.io.*;
|
||||
import org.springframework.web.context.support.*;
|
||||
import kohgylw.kiftd.server.util.*;
|
||||
import org.springframework.context.*;
|
||||
|
||||
@WebListener
|
||||
public class SCListener implements ServletContextListener {
|
||||
public void contextInitialized(final ServletContextEvent sce) {
|
||||
Printer.instance.print("\u6587\u4ef6\u7cfb\u7edf\u8282\u70b9\u4fe1\u606f\u6821\u5bf9...");
|
||||
final String fsp = ConfigureReader.instance().getFileSystemPath();
|
||||
final File fspf = new File(fsp);
|
||||
if (fspf.isDirectory() && fspf.canRead() && fspf.canWrite()) {
|
||||
final ApplicationContext context = (ApplicationContext) WebApplicationContextUtils
|
||||
.getWebApplicationContext(sce.getServletContext());
|
||||
final FileBlockUtil fbu = context.getBean(FileBlockUtil.class);
|
||||
fbu.checkFileBlocks();
|
||||
final String tfPath = ConfigureReader.instance().getTemporaryfilePath();
|
||||
final File f = new File(tfPath);
|
||||
if (!f.exists()) {
|
||||
f.mkdir();
|
||||
} else {
|
||||
final File[] listFiles = f.listFiles();
|
||||
for (final File fs : listFiles) {
|
||||
fs.delete();
|
||||
}
|
||||
}
|
||||
Printer.instance.print("\u6821\u5bf9\u5b8c\u6210\u3002");
|
||||
} else {
|
||||
Printer.instance.print(
|
||||
"\u9519\u8bef\uff1a\u6587\u4ef6\u7cfb\u7edf\u8282\u70b9\u4fe1\u606f\u6821\u5bf9\u5931\u8d25\uff0c\u5b58\u50a8\u4f4d\u7f6e\u65e0\u6cd5\u8bfb\u5199\u6216\u4e0d\u5b58\u5728\u3002");
|
||||
}
|
||||
}
|
||||
|
||||
public void contextDestroyed(final ServletContextEvent sce) {
|
||||
Printer.instance.print("\u6e05\u7406\u4e34\u65f6\u6587\u4ef6...");
|
||||
final String tfPath = ConfigureReader.instance().getTemporaryfilePath();
|
||||
final File f = new File(tfPath);
|
||||
final File[] listFiles = f.listFiles();
|
||||
for (final File fs : listFiles) {
|
||||
fs.delete();
|
||||
}
|
||||
}
|
||||
}
|
19
src/main/java/kohgylw/kiftd/server/mapper/FolderMapper.java
Normal file
19
src/main/java/kohgylw/kiftd/server/mapper/FolderMapper.java
Normal file
@ -0,0 +1,19 @@
|
||||
package kohgylw.kiftd.server.mapper;
|
||||
|
||||
import kohgylw.kiftd.server.model.*;
|
||||
import java.util.*;
|
||||
|
||||
public interface FolderMapper
|
||||
{
|
||||
Folder queryById(final String fid);
|
||||
|
||||
List<Folder> queryByParentId(final String pid);
|
||||
|
||||
Folder queryByParentIdAndFolderName(final Map<String, String> map);
|
||||
|
||||
int insertNewFolder(final Folder f);
|
||||
|
||||
int deleteById(final String folderId);
|
||||
|
||||
int updateFolderNameById(final Map<String, String> map);
|
||||
}
|
25
src/main/java/kohgylw/kiftd/server/mapper/NodeMapper.java
Normal file
25
src/main/java/kohgylw/kiftd/server/mapper/NodeMapper.java
Normal file
@ -0,0 +1,25 @@
|
||||
package kohgylw.kiftd.server.mapper;
|
||||
|
||||
import kohgylw.kiftd.server.model.*;
|
||||
import java.util.*;
|
||||
|
||||
public interface NodeMapper
|
||||
{
|
||||
List<Node> queryByParentFolderId(final String pfid);
|
||||
|
||||
int insert(final Node f);
|
||||
|
||||
int deleteByParentFolderId(final String pfid);
|
||||
|
||||
int deleteById(final String fileId);
|
||||
|
||||
Node queryById(final String fileId);
|
||||
|
||||
int updateFileNameById(final Map<String, String> map);
|
||||
|
||||
List<Node> queryAll();
|
||||
|
||||
Node queryByPath(final String path);
|
||||
|
||||
List<Node> queryBySomeFolder(final String fileId);
|
||||
}
|
50
src/main/java/kohgylw/kiftd/server/model/Folder.java
Normal file
50
src/main/java/kohgylw/kiftd/server/model/Folder.java
Normal file
@ -0,0 +1,50 @@
|
||||
package kohgylw.kiftd.server.model;
|
||||
|
||||
public class Folder
|
||||
{
|
||||
private String folderId;
|
||||
private String folderName;
|
||||
private String folderCreationDate;
|
||||
private String folderCreator;
|
||||
private String folderParent;
|
||||
|
||||
public String getFolderId() {
|
||||
return this.folderId;
|
||||
}
|
||||
|
||||
public void setFolderId(final String folderId) {
|
||||
this.folderId = folderId;
|
||||
}
|
||||
|
||||
public String getFolderName() {
|
||||
return this.folderName;
|
||||
}
|
||||
|
||||
public void setFolderName(final String folderName) {
|
||||
this.folderName = folderName;
|
||||
}
|
||||
|
||||
public String getFolderCreationDate() {
|
||||
return this.folderCreationDate;
|
||||
}
|
||||
|
||||
public void setFolderCreationDate(final String folderCreationDate) {
|
||||
this.folderCreationDate = folderCreationDate;
|
||||
}
|
||||
|
||||
public String getFolderCreator() {
|
||||
return this.folderCreator;
|
||||
}
|
||||
|
||||
public void setFolderCreator(final String folderCreator) {
|
||||
this.folderCreator = folderCreator;
|
||||
}
|
||||
|
||||
public String getFolderParent() {
|
||||
return this.folderParent;
|
||||
}
|
||||
|
||||
public void setFolderParent(final String folderParent) {
|
||||
this.folderParent = folderParent;
|
||||
}
|
||||
}
|
68
src/main/java/kohgylw/kiftd/server/model/Node.java
Normal file
68
src/main/java/kohgylw/kiftd/server/model/Node.java
Normal file
@ -0,0 +1,68 @@
|
||||
package kohgylw.kiftd.server.model;
|
||||
|
||||
public class Node
|
||||
{
|
||||
private String fileId;
|
||||
private String fileName;
|
||||
private String fileSize;
|
||||
private String fileParentFolder;
|
||||
private String fileCreationDate;
|
||||
private String fileCreator;
|
||||
private String filePath;
|
||||
|
||||
public String getFileId() {
|
||||
return this.fileId;
|
||||
}
|
||||
|
||||
public void setFileId(final String fileId) {
|
||||
this.fileId = fileId;
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
return this.fileName;
|
||||
}
|
||||
|
||||
public void setFileName(final String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
public String getFileSize() {
|
||||
return this.fileSize;
|
||||
}
|
||||
|
||||
public void setFileSize(final String fileSize) {
|
||||
this.fileSize = fileSize;
|
||||
}
|
||||
|
||||
public String getFileParentFolder() {
|
||||
return this.fileParentFolder;
|
||||
}
|
||||
|
||||
public void setFileParentFolder(final String fileParentFolder) {
|
||||
this.fileParentFolder = fileParentFolder;
|
||||
}
|
||||
|
||||
public String getFileCreationDate() {
|
||||
return this.fileCreationDate;
|
||||
}
|
||||
|
||||
public void setFileCreationDate(final String fileCreationDate) {
|
||||
this.fileCreationDate = fileCreationDate;
|
||||
}
|
||||
|
||||
public String getFileCreator() {
|
||||
return this.fileCreator;
|
||||
}
|
||||
|
||||
public void setFileCreator(final String fileCreator) {
|
||||
this.fileCreator = fileCreator;
|
||||
}
|
||||
|
||||
public String getFilePath() {
|
||||
return this.filePath;
|
||||
}
|
||||
|
||||
public void setFilePath(final String filePath) {
|
||||
this.filePath = filePath;
|
||||
}
|
||||
}
|
50
src/main/java/kohgylw/kiftd/server/pojo/AudioInfo.java
Normal file
50
src/main/java/kohgylw/kiftd/server/pojo/AudioInfo.java
Normal file
@ -0,0 +1,50 @@
|
||||
package kohgylw.kiftd.server.pojo;
|
||||
|
||||
public class AudioInfo
|
||||
{
|
||||
private String name;
|
||||
private String artist;
|
||||
private String url;
|
||||
private String cover;
|
||||
private String lrc;
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getArtist() {
|
||||
return this.artist;
|
||||
}
|
||||
|
||||
public void setArtist(final String artist) {
|
||||
this.artist = artist;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return this.url;
|
||||
}
|
||||
|
||||
public void setUrl(final String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getCover() {
|
||||
return this.cover;
|
||||
}
|
||||
|
||||
public void setCover(final String cover) {
|
||||
this.cover = cover;
|
||||
}
|
||||
|
||||
public String getLrc() {
|
||||
return this.lrc;
|
||||
}
|
||||
|
||||
public void setLrc(final String lrc) {
|
||||
this.lrc = lrc;
|
||||
}
|
||||
}
|
25
src/main/java/kohgylw/kiftd/server/pojo/AudioInfoList.java
Normal file
25
src/main/java/kohgylw/kiftd/server/pojo/AudioInfoList.java
Normal file
@ -0,0 +1,25 @@
|
||||
package kohgylw.kiftd.server.pojo;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class AudioInfoList
|
||||
{
|
||||
private List<AudioInfo> as;
|
||||
private int index;
|
||||
|
||||
public List<AudioInfo> getAs() {
|
||||
return this.as;
|
||||
}
|
||||
|
||||
public void setAs(final List<AudioInfo> as) {
|
||||
this.as = as;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return this.index;
|
||||
}
|
||||
|
||||
public void setIndex(final int index) {
|
||||
this.index = index;
|
||||
}
|
||||
}
|
71
src/main/java/kohgylw/kiftd/server/pojo/FolderView.java
Normal file
71
src/main/java/kohgylw/kiftd/server/pojo/FolderView.java
Normal file
@ -0,0 +1,71 @@
|
||||
package kohgylw.kiftd.server.pojo;
|
||||
|
||||
import java.util.*;
|
||||
import kohgylw.kiftd.server.model.*;
|
||||
|
||||
public class FolderView
|
||||
{
|
||||
private Folder folder;
|
||||
private List<Folder> parentList;
|
||||
private List<Folder> folderList;
|
||||
private List<Node> fileList;
|
||||
private String account;
|
||||
private List<String> authList;
|
||||
private String publishTime;
|
||||
|
||||
public Folder getFolder() {
|
||||
return this.folder;
|
||||
}
|
||||
|
||||
public void setFolder(final Folder folder) {
|
||||
this.folder = folder;
|
||||
}
|
||||
|
||||
public List<Folder> getParentList() {
|
||||
return this.parentList;
|
||||
}
|
||||
|
||||
public void setParentList(final List<Folder> parentList) {
|
||||
this.parentList = parentList;
|
||||
}
|
||||
|
||||
public List<Folder> getFolderList() {
|
||||
return this.folderList;
|
||||
}
|
||||
|
||||
public void setFolderList(final List<Folder> folderList) {
|
||||
this.folderList = folderList;
|
||||
}
|
||||
|
||||
public List<Node> getFileList() {
|
||||
return this.fileList;
|
||||
}
|
||||
|
||||
public void setFileList(final List<Node> fileList) {
|
||||
this.fileList = fileList;
|
||||
}
|
||||
|
||||
public List<String> getAuthList() {
|
||||
return this.authList;
|
||||
}
|
||||
|
||||
public void setAuthList(final List<String> authList) {
|
||||
this.authList = authList;
|
||||
}
|
||||
|
||||
public String getAccount() {
|
||||
return this.account;
|
||||
}
|
||||
|
||||
public void setAccount(final String account) {
|
||||
this.account = account;
|
||||
}
|
||||
|
||||
public String getPublishTime() {
|
||||
return this.publishTime;
|
||||
}
|
||||
|
||||
public void setPublishTime(final String publishTime) {
|
||||
this.publishTime = publishTime;
|
||||
}
|
||||
}
|
32
src/main/java/kohgylw/kiftd/server/pojo/LoginInfoPojo.java
Normal file
32
src/main/java/kohgylw/kiftd/server/pojo/LoginInfoPojo.java
Normal file
@ -0,0 +1,32 @@
|
||||
package kohgylw.kiftd.server.pojo;
|
||||
|
||||
public class LoginInfoPojo
|
||||
{
|
||||
private String accountId;
|
||||
private String accountPwd;
|
||||
private String time;
|
||||
|
||||
public String getAccountId() {
|
||||
return this.accountId;
|
||||
}
|
||||
|
||||
public void setAccountId(final String accountId) {
|
||||
this.accountId = accountId;
|
||||
}
|
||||
|
||||
public String getAccountPwd() {
|
||||
return this.accountPwd;
|
||||
}
|
||||
|
||||
public void setAccountPwd(final String accountPwd) {
|
||||
this.accountPwd = accountPwd;
|
||||
}
|
||||
|
||||
public String getTime() {
|
||||
return this.time;
|
||||
}
|
||||
|
||||
public void setTime(final String time) {
|
||||
this.time = time;
|
||||
}
|
||||
}
|
26
src/main/java/kohgylw/kiftd/server/pojo/PictureViewList.java
Normal file
26
src/main/java/kohgylw/kiftd/server/pojo/PictureViewList.java
Normal file
@ -0,0 +1,26 @@
|
||||
package kohgylw.kiftd.server.pojo;
|
||||
|
||||
import java.util.*;
|
||||
import kohgylw.kiftd.server.model.*;
|
||||
|
||||
public class PictureViewList
|
||||
{
|
||||
private List<Node> pictureViewList;
|
||||
private int index;
|
||||
|
||||
public List<Node> getPictureViewList() {
|
||||
return this.pictureViewList;
|
||||
}
|
||||
|
||||
public void setPictureViewList(final List<Node> pictureViewList) {
|
||||
this.pictureViewList = pictureViewList;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return this.index;
|
||||
}
|
||||
|
||||
public void setIndex(final int index) {
|
||||
this.index = index;
|
||||
}
|
||||
}
|
23
src/main/java/kohgylw/kiftd/server/pojo/PublicKeyInfo.java
Normal file
23
src/main/java/kohgylw/kiftd/server/pojo/PublicKeyInfo.java
Normal file
@ -0,0 +1,23 @@
|
||||
package kohgylw.kiftd.server.pojo;
|
||||
|
||||
public class PublicKeyInfo
|
||||
{
|
||||
private String publicKey;
|
||||
private long time;
|
||||
|
||||
public String getPublicKey() {
|
||||
return this.publicKey;
|
||||
}
|
||||
|
||||
public void setPublicKey(final String publicKey) {
|
||||
this.publicKey = publicKey;
|
||||
}
|
||||
|
||||
public long getTime() {
|
||||
return this.time;
|
||||
}
|
||||
|
||||
public void setTime(final long time) {
|
||||
this.time = time;
|
||||
}
|
||||
}
|
52
src/main/java/kohgylw/kiftd/server/pojo/ServerSetting.java
Normal file
52
src/main/java/kohgylw/kiftd/server/pojo/ServerSetting.java
Normal file
@ -0,0 +1,52 @@
|
||||
package kohgylw.kiftd.server.pojo;
|
||||
|
||||
import kohgylw.kiftd.server.enumeration.*;
|
||||
|
||||
public class ServerSetting
|
||||
{
|
||||
private boolean mustLogin;
|
||||
private int buffSize;
|
||||
private LogLevel log;
|
||||
private int port;
|
||||
private String fsPath;
|
||||
|
||||
public boolean isMustLogin() {
|
||||
return this.mustLogin;
|
||||
}
|
||||
|
||||
public void setMustLogin(final boolean mustLogin) {
|
||||
this.mustLogin = mustLogin;
|
||||
}
|
||||
|
||||
public int getBuffSize() {
|
||||
return this.buffSize;
|
||||
}
|
||||
|
||||
public void setBuffSize(final int buffSize) {
|
||||
this.buffSize = buffSize;
|
||||
}
|
||||
|
||||
public LogLevel getLog() {
|
||||
return this.log;
|
||||
}
|
||||
|
||||
public void setLog(final LogLevel log) {
|
||||
this.log = log;
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return this.port;
|
||||
}
|
||||
|
||||
public void setPort(final int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public String getFsPath() {
|
||||
return this.fsPath;
|
||||
}
|
||||
|
||||
public void setFsPath(final String fsPath) {
|
||||
this.fsPath = fsPath;
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package kohgylw.kiftd.server.service;
|
||||
|
||||
import javax.servlet.http.*;
|
||||
|
||||
public interface AccountService
|
||||
{
|
||||
String checkLoginRequest(final HttpServletRequest request, final HttpSession session);
|
||||
|
||||
void logout(final HttpSession session);
|
||||
|
||||
String getPublicKey();
|
||||
}
|
25
src/main/java/kohgylw/kiftd/server/service/FileService.java
Normal file
25
src/main/java/kohgylw/kiftd/server/service/FileService.java
Normal file
@ -0,0 +1,25 @@
|
||||
package kohgylw.kiftd.server.service;
|
||||
|
||||
import org.springframework.web.multipart.*;
|
||||
import javax.servlet.http.*;
|
||||
|
||||
public interface FileService
|
||||
{
|
||||
String checkUploadFile(final HttpServletRequest request);
|
||||
|
||||
String doUploadFile(final HttpServletRequest request, final MultipartFile file);
|
||||
|
||||
String deleteFile(final HttpServletRequest request);
|
||||
|
||||
void doDownloadFile(final HttpServletRequest request, final HttpServletResponse response);
|
||||
|
||||
String doRenameFile(final HttpServletRequest request);
|
||||
|
||||
String deleteCheckedFiles(final HttpServletRequest request);
|
||||
|
||||
String getPackTime(final HttpServletRequest request);
|
||||
|
||||
String downloadCheckedFiles(final HttpServletRequest request);
|
||||
|
||||
void downloadCheckedFilesZip(final HttpServletRequest request, final HttpServletResponse response) throws Exception;
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package kohgylw.kiftd.server.service;
|
||||
|
||||
import javax.servlet.http.*;
|
||||
|
||||
public interface FolderService
|
||||
{
|
||||
String newFolder(final HttpServletRequest request);
|
||||
|
||||
String deleteFolder(final HttpServletRequest request);
|
||||
|
||||
String renameFolder(final HttpServletRequest request);
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package kohgylw.kiftd.server.service;
|
||||
|
||||
import javax.servlet.http.*;
|
||||
|
||||
public interface FolderViewService
|
||||
{
|
||||
String getFolderViewToJson(final String fid, final HttpSession session, final HttpServletRequest request);
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package kohgylw.kiftd.server.service;
|
||||
|
||||
import javax.servlet.http.*;
|
||||
import kohgylw.kiftd.server.model.*;
|
||||
|
||||
public interface PdfViewService
|
||||
{
|
||||
Node foundPdf(final HttpServletRequest request);
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package kohgylw.kiftd.server.service;
|
||||
|
||||
import javax.servlet.http.*;
|
||||
|
||||
public interface PlayAudioService
|
||||
{
|
||||
String getAudioInfoListByJson(final HttpServletRequest request);
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package kohgylw.kiftd.server.service;
|
||||
|
||||
import javax.servlet.http.*;
|
||||
|
||||
public interface PlayVideoService
|
||||
{
|
||||
String getPlayVideoJson(final HttpServletRequest request);
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package kohgylw.kiftd.server.service;
|
||||
|
||||
public interface ServerInfoService
|
||||
{
|
||||
String getOSName();
|
||||
|
||||
String getServerTime();
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package kohgylw.kiftd.server.service;
|
||||
|
||||
import javax.servlet.http.*;
|
||||
|
||||
public interface ShowPictureService
|
||||
{
|
||||
String getPreviewPictureJson(final HttpServletRequest request);
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package kohgylw.kiftd.server.service.impl;
|
||||
|
||||
import kohgylw.kiftd.server.service.*;
|
||||
import org.springframework.stereotype.*;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.*;
|
||||
import kohgylw.kiftd.server.util.*;
|
||||
import kohgylw.kiftd.server.pojo.*;
|
||||
|
||||
@Service
|
||||
public class AccountServiceImpl implements AccountService {
|
||||
@Resource
|
||||
private KeyUtil ku;
|
||||
|
||||
private static final long TIME_OUT = 30000L;
|
||||
@Resource
|
||||
private Gson gson;
|
||||
|
||||
public String checkLoginRequest(final HttpServletRequest request, final HttpSession session) {
|
||||
final String encrypted = request.getParameter("encrypted");
|
||||
final String loginInfoStr = DecryptionUtil.dncryption(encrypted, ku.getPrivateKey());
|
||||
try {
|
||||
final LoginInfoPojo info = gson.fromJson(loginInfoStr, LoginInfoPojo.class);
|
||||
if (System.currentTimeMillis() - Long.parseLong(info.getTime()) > TIME_OUT) {
|
||||
return "error";
|
||||
}
|
||||
final ConfigureReader cr = ConfigureReader.instance();
|
||||
final String accountId = info.getAccountId();
|
||||
if (!cr.foundAccount(accountId)) {
|
||||
return "accountnotfound";
|
||||
}
|
||||
if (cr.checkAccountPwd(accountId, info.getAccountPwd())) {
|
||||
session.setAttribute("ACCOUNT", (Object) accountId);
|
||||
return "permitlogin";
|
||||
}
|
||||
return "accountpwderror";
|
||||
} catch (Exception e) {
|
||||
return "error";
|
||||
}
|
||||
}
|
||||
|
||||
public void logout(final HttpSession session) {
|
||||
session.invalidate();
|
||||
}
|
||||
|
||||
public String getPublicKey() {
|
||||
PublicKeyInfo pki = new PublicKeyInfo();
|
||||
pki.setPublicKey(ku.getPublicKey());
|
||||
pki.setTime(System.currentTimeMillis());
|
||||
return gson.toJson(pki);
|
||||
}
|
||||
}
|
@ -0,0 +1,299 @@
|
||||
package kohgylw.kiftd.server.service.impl;
|
||||
|
||||
import kohgylw.kiftd.server.service.*;
|
||||
import org.springframework.stereotype.*;
|
||||
import kohgylw.kiftd.server.mapper.*;
|
||||
import javax.annotation.*;
|
||||
import kohgylw.kiftd.server.enumeration.*;
|
||||
import kohgylw.kiftd.server.model.*;
|
||||
import org.springframework.web.multipart.*;
|
||||
import javax.servlet.http.*;
|
||||
import java.net.*;
|
||||
import java.io.*;
|
||||
import kohgylw.kiftd.server.util.*;
|
||||
import java.util.*;
|
||||
import com.google.gson.*;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
@Service
|
||||
public class FileServiceImpl implements FileService {
|
||||
@Resource
|
||||
private NodeMapper fm;
|
||||
@Resource
|
||||
private FileBlockUtil fbu;
|
||||
@Resource
|
||||
private LogUtil lu;
|
||||
@Resource
|
||||
private Gson gson;
|
||||
|
||||
public String checkUploadFile(final HttpServletRequest request) {
|
||||
final String account = (String) request.getSession().getAttribute("ACCOUNT");
|
||||
final String folderId = request.getParameter("folderId");
|
||||
final String namelist = request.getParameter("namelist");
|
||||
final List<String> namelistObj = gson.fromJson(namelist, new TypeToken<List<String>>() {
|
||||
}.getType());
|
||||
for (final String filename : namelistObj) {
|
||||
if (folderId == null || folderId.length() <= 0 || filename == null || filename.length() <= 0) {
|
||||
return "errorParameter";
|
||||
}
|
||||
if (!ConfigureReader.instance().authorized(account, AccountAuth.UPLOAD_FILES)) {
|
||||
return "noAuthorized";
|
||||
}
|
||||
final List<Node> files = this.fm.queryByParentFolderId(folderId);
|
||||
boolean duplication = false;
|
||||
for (final Node f : files) {
|
||||
if (f.getFileName().equals(filename)) {
|
||||
duplication = true;
|
||||
}
|
||||
}
|
||||
if (!duplication) {
|
||||
continue;
|
||||
}
|
||||
return "duplicationFileName:" + filename;
|
||||
}
|
||||
return "permitUpload";
|
||||
}
|
||||
|
||||
public String doUploadFile(final HttpServletRequest request, final MultipartFile file) {
|
||||
final String account = (String) request.getSession().getAttribute("ACCOUNT");
|
||||
final String folderId = request.getParameter("folderId");
|
||||
final String filename = file.getOriginalFilename();
|
||||
if (folderId == null || folderId.length() <= 0 || filename == null || filename.length() <= 0) {
|
||||
return "uploaderror";
|
||||
}
|
||||
if (!ConfigureReader.instance().authorized(account, AccountAuth.UPLOAD_FILES)) {
|
||||
return "uploaderror";
|
||||
}
|
||||
final List<Node> files = this.fm.queryByParentFolderId(folderId);
|
||||
boolean duplication = false;
|
||||
for (final Node f : files) {
|
||||
if (f.getFileName().equals(filename)) {
|
||||
duplication = true;
|
||||
}
|
||||
}
|
||||
if (duplication) {
|
||||
return "uploaderror";
|
||||
}
|
||||
final String path = this.fbu.saveToFileBlocks(request, file);
|
||||
final String fsize = this.fbu.getFileSize(file);
|
||||
if (path.equals("ERROR")) {
|
||||
return "uploaderror";
|
||||
}
|
||||
final Node f2 = new Node();
|
||||
f2.setFileId(UUID.randomUUID().toString());
|
||||
if (account != null) {
|
||||
f2.setFileCreator(account);
|
||||
} else {
|
||||
f2.setFileCreator("\u533f\u540d\u7528\u6237");
|
||||
}
|
||||
f2.setFileCreationDate(ServerTimeUtil.accurateToDay());
|
||||
f2.setFileName(filename);
|
||||
f2.setFileParentFolder(folderId);
|
||||
f2.setFilePath(path);
|
||||
f2.setFileSize(fsize);
|
||||
if (this.fm.insert(f2) > 0) {
|
||||
this.lu.writeUploadFileEvent(request, f2);
|
||||
return "uploadsuccess";
|
||||
}
|
||||
return "uploaderror";
|
||||
}
|
||||
|
||||
public String deleteFile(final HttpServletRequest request) {
|
||||
final String fileId = request.getParameter("fileId");
|
||||
final String account = (String) request.getSession().getAttribute("ACCOUNT");
|
||||
if (!ConfigureReader.instance().authorized(account, AccountAuth.DELETE_FILE_OR_FOLDER)) {
|
||||
return "noAuthorized";
|
||||
}
|
||||
if (fileId == null || fileId.length() <= 0) {
|
||||
return "errorParameter";
|
||||
}
|
||||
final Node file = this.fm.queryById(fileId);
|
||||
if (file == null) {
|
||||
return "errorParameter";
|
||||
}
|
||||
final String fileblocks = ConfigureReader.instance().getFileBlockPath();
|
||||
if (!this.fbu.deleteFromFileBlocks(fileblocks, file.getFilePath())) {
|
||||
return "cannotDeleteFile";
|
||||
}
|
||||
if (this.fm.deleteById(fileId) > 0) {
|
||||
this.lu.writeDeleteFileEvent(request, file);
|
||||
return "deleteFileSuccess";
|
||||
}
|
||||
return "cannotDeleteFile";
|
||||
}
|
||||
|
||||
public void doDownloadFile(final HttpServletRequest request, final HttpServletResponse response) {
|
||||
final String account = (String) request.getSession().getAttribute("ACCOUNT");
|
||||
if (ConfigureReader.instance().authorized(account, AccountAuth.DOWNLOAD_FILES)) {
|
||||
final String fileId = request.getParameter("fileId");
|
||||
if (fileId != null) {
|
||||
final Node f = this.fm.queryById(fileId);
|
||||
if (f != null) {
|
||||
final String fileBlocks = ConfigureReader.instance().getFileBlockPath();
|
||||
final File fo = this.fbu.getFileFromBlocks(fileBlocks, f.getFilePath());
|
||||
try {
|
||||
final FileInputStream fis = new FileInputStream(fo);
|
||||
response.setContentType("application/force-download");
|
||||
response.setHeader("Content-Length", "" + fo.length());
|
||||
response.addHeader("Content-Disposition",
|
||||
"attachment;fileName=" + URLEncoder.encode(f.getFileName(), "UTF-8"));
|
||||
final int buffersize = ConfigureReader.instance().getBuffSize();
|
||||
final byte[] buffer = new byte[buffersize];
|
||||
final BufferedInputStream bis = new BufferedInputStream(fis);
|
||||
final OutputStream os = (OutputStream) response.getOutputStream();
|
||||
int index = 0;
|
||||
while ((index = bis.read(buffer)) != -1) {
|
||||
os.write(buffer, 0, index);
|
||||
}
|
||||
bis.close();
|
||||
fis.close();
|
||||
this.lu.writeDownloadFileEvent(request, f);
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String doRenameFile(final HttpServletRequest request) {
|
||||
final String fileId = request.getParameter("fileId");
|
||||
final String newFileName = request.getParameter("newFileName");
|
||||
final String account = (String) request.getSession().getAttribute("ACCOUNT");
|
||||
if (!ConfigureReader.instance().authorized(account, AccountAuth.RENAME_FILE_OR_FOLDER)) {
|
||||
return "noAuthorized";
|
||||
}
|
||||
if (fileId == null || fileId.length() <= 0 || newFileName == null || newFileName.length() <= 0) {
|
||||
return "errorParameter";
|
||||
}
|
||||
if (!TextFormateUtil.instance().matcherFileName(newFileName)) {
|
||||
return "errorParameter";
|
||||
}
|
||||
final Node file = this.fm.queryById(fileId);
|
||||
if (file == null) {
|
||||
return "errorParameter";
|
||||
}
|
||||
final Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("fileId", fileId);
|
||||
map.put("newFileName", newFileName);
|
||||
if (this.fm.updateFileNameById(map) > 0) {
|
||||
this.lu.writeRenameFileEvent(request, file, newFileName);
|
||||
return "renameFileSuccess";
|
||||
}
|
||||
return "cannotRenameFile";
|
||||
}
|
||||
|
||||
public String deleteCheckedFiles(final HttpServletRequest request) {
|
||||
final String strIdList = request.getParameter("strIdList");
|
||||
final String account = (String) request.getSession().getAttribute("ACCOUNT");
|
||||
if (ConfigureReader.instance().authorized(account, AccountAuth.DELETE_FILE_OR_FOLDER)) {
|
||||
try {
|
||||
final List<String> idList = gson.fromJson(strIdList, new TypeToken<List<String>>() {
|
||||
}.getType());
|
||||
for (final String fileId : idList) {
|
||||
if (fileId == null || fileId.length() <= 0) {
|
||||
return "errorParameter";
|
||||
}
|
||||
final Node file = this.fm.queryById(fileId);
|
||||
if (file == null) {
|
||||
return "errorParameter";
|
||||
}
|
||||
final String fileblocks = ConfigureReader.instance().getFileBlockPath();
|
||||
if (!this.fbu.deleteFromFileBlocks(fileblocks, file.getFilePath())) {
|
||||
return "cannotDeleteFile";
|
||||
}
|
||||
if (this.fm.deleteById(fileId) <= 0) {
|
||||
return "cannotDeleteFile";
|
||||
}
|
||||
this.lu.writeDeleteFileEvent(request, file);
|
||||
}
|
||||
return "deleteFileSuccess";
|
||||
} catch (Exception e) {
|
||||
return "errorParameter";
|
||||
}
|
||||
}
|
||||
return "noAuthorized";
|
||||
}
|
||||
|
||||
public String downloadCheckedFiles(final HttpServletRequest request) {
|
||||
final String account = (String) request.getSession().getAttribute("ACCOUNT");
|
||||
if (ConfigureReader.instance().authorized(account, AccountAuth.DOWNLOAD_FILES)) {
|
||||
final String strIdList = request.getParameter("strIdList");
|
||||
try {
|
||||
final List<String> idList = gson.fromJson(strIdList, new TypeToken<List<String>>() {
|
||||
}.getType());
|
||||
if (idList.size() > 0) {
|
||||
final String fileBlocks = ConfigureReader.instance().getFileBlockPath();
|
||||
final String tfPath = ConfigureReader.instance().getTemporaryfilePath();
|
||||
final String zipname = this.fbu.createZip(idList, tfPath, fileBlocks);
|
||||
this.lu.writeDownloadCheckedFileEvent(request, idList);
|
||||
return zipname;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
}
|
||||
return "ERROR";
|
||||
}
|
||||
|
||||
public void downloadCheckedFilesZip(final HttpServletRequest request, final HttpServletResponse response)
|
||||
throws Exception {
|
||||
final String zipname = request.getParameter("zipId");
|
||||
if (zipname != null && !zipname.equals("ERROR")) {
|
||||
final String tfPath = ConfigureReader.instance().getTemporaryfilePath();
|
||||
final File zip = new File(tfPath, zipname);
|
||||
if (zip.exists()) {
|
||||
response.setContentType("application/force-download");
|
||||
response.setHeader("Content-Length", "" + zip.length());
|
||||
response.addHeader("Content-Disposition", "attachment;fileName=" + URLEncoder
|
||||
.encode("kiftd_" + ServerTimeUtil.accurateToDay() + "_\u6253\u5305\u4e0b\u8f7d.zip", "UTF-8"));
|
||||
final FileInputStream fis = new FileInputStream(zip);
|
||||
final BufferedInputStream bis = new BufferedInputStream(fis);
|
||||
final OutputStream out = (OutputStream) response.getOutputStream();
|
||||
final byte[] buffer = new byte[ConfigureReader.instance().getBuffSize()];
|
||||
int count = 0;
|
||||
while ((count = bis.read(buffer)) != -1) {
|
||||
out.write(buffer, 0, count);
|
||||
}
|
||||
bis.close();
|
||||
fis.close();
|
||||
zip.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getPackTime(final HttpServletRequest request) {
|
||||
final String account = (String) request.getSession().getAttribute("ACCOUNT");
|
||||
if (ConfigureReader.instance().authorized(account, AccountAuth.DOWNLOAD_FILES)) {
|
||||
final String strIdList = request.getParameter("strIdList");
|
||||
try {
|
||||
final List<String> idList = gson.fromJson(strIdList, new TypeToken<List<String>>() {
|
||||
}.getType());
|
||||
long packTime = 0L;
|
||||
for (final String fid : idList) {
|
||||
final Node n = this.fm.queryById(fid);
|
||||
final File f = new File(ConfigureReader.instance().getFileBlockPath(), n.getFilePath());
|
||||
if (f.exists()) {
|
||||
packTime += f.length() / 25000000L;
|
||||
}
|
||||
}
|
||||
if (packTime < 4L) {
|
||||
return "\u9a6c\u4e0a\u5b8c\u6210";
|
||||
}
|
||||
if (packTime >= 4L && packTime < 10L) {
|
||||
return "\u5927\u7ea610\u79d2";
|
||||
}
|
||||
if (packTime >= 10L && packTime < 35L) {
|
||||
return "\u4e0d\u5230\u534a\u5206\u949f";
|
||||
}
|
||||
if (packTime >= 35L && packTime < 65L) {
|
||||
return "\u5927\u7ea61\u5206\u949f";
|
||||
}
|
||||
if (packTime >= 65L) {
|
||||
return "\u8d85\u8fc7" + packTime / 60L
|
||||
+ "\u5206\u949f\uff0c\u8017\u65f6\u8f83\u957f\uff0c\u5efa\u8bae\u76f4\u63a5\u4e0b\u8f7d";
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
}
|
||||
return "0";
|
||||
}
|
||||
}
|
@ -0,0 +1,111 @@
|
||||
package kohgylw.kiftd.server.service.impl;
|
||||
|
||||
import kohgylw.kiftd.server.service.*;
|
||||
import org.springframework.stereotype.*;
|
||||
import kohgylw.kiftd.server.mapper.*;
|
||||
import javax.annotation.*;
|
||||
import javax.servlet.http.*;
|
||||
import kohgylw.kiftd.server.enumeration.*;
|
||||
import kohgylw.kiftd.server.model.*;
|
||||
import kohgylw.kiftd.server.util.*;
|
||||
import java.util.*;
|
||||
|
||||
@Service
|
||||
public class FolderServiceImpl implements FolderService {
|
||||
@Resource
|
||||
private FolderMapper fm;
|
||||
@Resource
|
||||
private FolderUtil fu;
|
||||
@Resource
|
||||
private LogUtil lu;
|
||||
|
||||
public String newFolder(final HttpServletRequest request) {
|
||||
final String parentId = request.getParameter("parentId");
|
||||
final String folderName = request.getParameter("folderName");
|
||||
final String account = (String) request.getSession().getAttribute("ACCOUNT");
|
||||
if (!ConfigureReader.instance().authorized(account, AccountAuth.CREATE_NEW_FOLDER)) {
|
||||
return "noAuthorized";
|
||||
}
|
||||
if (parentId == null || folderName == null || parentId.length() <= 0 || folderName.length() <= 0) {
|
||||
return "errorParameter";
|
||||
}
|
||||
if (!TextFormateUtil.instance().matcherFolderName(folderName)) {
|
||||
return "errorParameter";
|
||||
}
|
||||
final Folder parentFolder = this.fm.queryById(parentId);
|
||||
if (parentFolder == null) {
|
||||
return "errorParameter";
|
||||
}
|
||||
final Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("parentId", parentId);
|
||||
map.put("folderName", folderName);
|
||||
Folder f = this.fm.queryByParentIdAndFolderName(map);
|
||||
if (f != null) {
|
||||
return "folderAlreadyExist";
|
||||
}
|
||||
f = new Folder();
|
||||
f.setFolderId(UUID.randomUUID().toString());
|
||||
f.setFolderName(folderName);
|
||||
f.setFolderCreationDate(ServerTimeUtil.accurateToDay());
|
||||
if (account != null) {
|
||||
f.setFolderCreator(account);
|
||||
} else {
|
||||
f.setFolderCreator("\u533f\u540d\u7528\u6237");
|
||||
}
|
||||
f.setFolderParent(parentId);
|
||||
final int i = this.fm.insertNewFolder(f);
|
||||
if (i > 0) {
|
||||
this.lu.writeCreateFolderEvent(request, f);
|
||||
return "createFolderSuccess";
|
||||
}
|
||||
return "cannotCreateFolder";
|
||||
}
|
||||
|
||||
public String deleteFolder(final HttpServletRequest request) {
|
||||
final String folderId = request.getParameter("folderId");
|
||||
final String account = (String) request.getSession().getAttribute("ACCOUNT");
|
||||
if (!ConfigureReader.instance().authorized(account, AccountAuth.DELETE_FILE_OR_FOLDER)) {
|
||||
return "noAuthorized";
|
||||
}
|
||||
if (folderId == null || folderId.length() <= 0) {
|
||||
return "errorParameter";
|
||||
}
|
||||
final Folder folder = this.fm.queryById(folderId);
|
||||
if (folder == null) {
|
||||
return "errorParameter";
|
||||
}
|
||||
final List<Folder> l = this.fu.getParentList(folderId);
|
||||
if (this.fu.deleteAllChildFolder(request, folderId) > 0) {
|
||||
this.lu.writeDeleteFolderEvent(request, folder, l);
|
||||
return "deleteFolderSuccess";
|
||||
}
|
||||
return "cannotDeleteFolder";
|
||||
}
|
||||
|
||||
public String renameFolder(final HttpServletRequest request) {
|
||||
final String folderId = request.getParameter("folderId");
|
||||
final String newName = request.getParameter("newName");
|
||||
final String account = (String) request.getSession().getAttribute("ACCOUNT");
|
||||
if (!ConfigureReader.instance().authorized(account, AccountAuth.RENAME_FILE_OR_FOLDER)) {
|
||||
return "noAuthorized";
|
||||
}
|
||||
if (folderId == null || folderId.length() <= 0 || newName == null || newName.length() <= 0) {
|
||||
return "errorParameter";
|
||||
}
|
||||
if (!TextFormateUtil.instance().matcherFolderName(newName)) {
|
||||
return "errorParameter";
|
||||
}
|
||||
final Folder folder = this.fm.queryById(folderId);
|
||||
if (folder == null) {
|
||||
return "errorParameter";
|
||||
}
|
||||
final Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("folderId", folderId);
|
||||
map.put("newName", newName);
|
||||
if (this.fm.updateFolderNameById(map) > 0) {
|
||||
this.lu.writeRenameFolderEvent(request, folder, newName);
|
||||
return "renameFolderSuccess";
|
||||
}
|
||||
return "cannotRenameFolder";
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package kohgylw.kiftd.server.service.impl;
|
||||
|
||||
import kohgylw.kiftd.server.service.*;
|
||||
import org.springframework.stereotype.*;
|
||||
import javax.annotation.*;
|
||||
import kohgylw.kiftd.server.mapper.*;
|
||||
import javax.servlet.http.*;
|
||||
import kohgylw.kiftd.server.pojo.*;
|
||||
import java.util.*;
|
||||
import kohgylw.kiftd.server.enumeration.*;
|
||||
import kohgylw.kiftd.server.util.*;
|
||||
import com.google.gson.*;
|
||||
|
||||
@Service
|
||||
public class FolderViewServiceImpl implements FolderViewService {
|
||||
@Resource
|
||||
private FolderUtil fu;
|
||||
@Resource
|
||||
private FolderMapper fm;
|
||||
@Resource
|
||||
private NodeMapper flm;
|
||||
@Resource
|
||||
private Gson gson;
|
||||
|
||||
@Override
|
||||
public String getFolderViewToJson(final String fid, final HttpSession session, final HttpServletRequest request) {
|
||||
final ConfigureReader cr = ConfigureReader.instance();
|
||||
final FolderView fv = new FolderView();
|
||||
fv.setFolder(this.fm.queryById(fid));
|
||||
fv.setParentList(this.fu.getParentList(fid));
|
||||
fv.setFolderList(this.fm.queryByParentId(fid));
|
||||
fv.setFileList(this.flm.queryByParentFolderId(fid));
|
||||
final String account = (String) session.getAttribute("ACCOUNT");
|
||||
if (account != null) {
|
||||
fv.setAccount(account);
|
||||
}
|
||||
final List<String> authList = new ArrayList<String>();
|
||||
if (cr.authorized(account, AccountAuth.UPLOAD_FILES)) {
|
||||
authList.add("U");
|
||||
}
|
||||
if (cr.authorized(account, AccountAuth.CREATE_NEW_FOLDER)) {
|
||||
authList.add("C");
|
||||
}
|
||||
if (cr.authorized(account, AccountAuth.DELETE_FILE_OR_FOLDER)) {
|
||||
authList.add("D");
|
||||
}
|
||||
if (cr.authorized(account, AccountAuth.RENAME_FILE_OR_FOLDER)) {
|
||||
authList.add("R");
|
||||
}
|
||||
if (cr.authorized(account, AccountAuth.DOWNLOAD_FILES)) {
|
||||
authList.add("L");
|
||||
}
|
||||
fv.setAuthList(authList);
|
||||
fv.setPublishTime(ServerTimeUtil.accurateToMinute());
|
||||
return gson.toJson(fv);
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package kohgylw.kiftd.server.service.impl;
|
||||
|
||||
import kohgylw.kiftd.server.service.*;
|
||||
import org.springframework.stereotype.*;
|
||||
import kohgylw.kiftd.server.mapper.*;
|
||||
import javax.annotation.*;
|
||||
import javax.servlet.http.*;
|
||||
import kohgylw.kiftd.server.model.*;
|
||||
import kohgylw.kiftd.server.util.*;
|
||||
import kohgylw.kiftd.server.enumeration.*;
|
||||
|
||||
@Service
|
||||
public class PdfViewServiceImpl implements PdfViewService
|
||||
{
|
||||
@Resource
|
||||
private NodeMapper fm;
|
||||
|
||||
@Override
|
||||
public Node foundPdf(final HttpServletRequest request) {
|
||||
final String fileId = request.getParameter("fileId");
|
||||
if (fileId != null && fileId.length() > 0) {
|
||||
final Node f = this.fm.queryById(fileId);
|
||||
if (f != null) {
|
||||
final String account = (String)request.getSession().getAttribute("ACCOUNT");
|
||||
if (ConfigureReader.instance().authorized(account, AccountAuth.DOWNLOAD_FILES)) {
|
||||
final String fileName = f.getFileName();
|
||||
final String suffix = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
|
||||
if (suffix.equals("pdf")) {
|
||||
return f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package kohgylw.kiftd.server.service.impl;
|
||||
|
||||
import kohgylw.kiftd.server.service.*;
|
||||
import org.springframework.stereotype.*;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import kohgylw.kiftd.server.mapper.*;
|
||||
import javax.annotation.*;
|
||||
import javax.servlet.http.*;
|
||||
import kohgylw.kiftd.server.pojo.*;
|
||||
import kohgylw.kiftd.server.enumeration.*;
|
||||
import java.util.*;
|
||||
import kohgylw.kiftd.server.model.*;
|
||||
import kohgylw.kiftd.server.util.*;
|
||||
|
||||
@Service
|
||||
public class PlayAudioServiceImpl implements PlayAudioService
|
||||
{
|
||||
@Resource
|
||||
private NodeMapper fm;
|
||||
@Resource
|
||||
private AudioInfoUtil aiu;
|
||||
@Resource
|
||||
private Gson gson;
|
||||
|
||||
private AudioInfoList foundAudios(final HttpServletRequest request) {
|
||||
final String fileId = request.getParameter("fileId");
|
||||
if (fileId != null && fileId.length() > 0) {
|
||||
final String account = (String)request.getSession().getAttribute("ACCOUNT");
|
||||
if (ConfigureReader.instance().authorized(account, AccountAuth.DOWNLOAD_FILES)) {
|
||||
final List<Node> blocks = (List<Node>)this.fm.queryBySomeFolder(fileId);
|
||||
return this.aiu.transformToAudioInfoList(blocks, fileId);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getAudioInfoListByJson(final HttpServletRequest request) {
|
||||
final AudioInfoList ail = this.foundAudios(request);
|
||||
if (ail != null) {
|
||||
return gson.toJson((Object)ail);
|
||||
}
|
||||
return "ERROR";
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
package kohgylw.kiftd.server.service.impl;
|
||||
|
||||
import kohgylw.kiftd.server.service.*;
|
||||
import org.springframework.stereotype.*;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import kohgylw.kiftd.server.mapper.*;
|
||||
import javax.annotation.*;
|
||||
import javax.servlet.http.*;
|
||||
import kohgylw.kiftd.server.model.*;
|
||||
import kohgylw.kiftd.server.enumeration.*;
|
||||
import kohgylw.kiftd.server.util.*;
|
||||
|
||||
@Service
|
||||
public class PlayVideoServiceImpl implements PlayVideoService
|
||||
{
|
||||
@Resource
|
||||
private NodeMapper fm;
|
||||
@Resource
|
||||
private Gson gson;
|
||||
|
||||
private Node foundVideo(final HttpServletRequest request) {
|
||||
final String fileId = request.getParameter("fileId");
|
||||
if (fileId != null && fileId.length() > 0) {
|
||||
final Node f = this.fm.queryById(fileId);
|
||||
if (f != null) {
|
||||
final String account = (String)request.getSession().getAttribute("ACCOUNT");
|
||||
if (ConfigureReader.instance().authorized(account, AccountAuth.DOWNLOAD_FILES)) {
|
||||
final String fileName = f.getFileName();
|
||||
final String suffix = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
|
||||
if (suffix.equals("mp4") || suffix.equals("webm")) {
|
||||
return f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayVideoJson(final HttpServletRequest request) {
|
||||
final Node f = this.foundVideo(request);
|
||||
if (f != null) {
|
||||
return gson.toJson((Object)f);
|
||||
}
|
||||
return "ERROR";
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package kohgylw.kiftd.server.service.impl;
|
||||
|
||||
import kohgylw.kiftd.server.service.*;
|
||||
import org.springframework.stereotype.*;
|
||||
import java.util.*;
|
||||
import java.text.*;
|
||||
|
||||
@Service
|
||||
public class ServerInfoServiceImpl implements ServerInfoService
|
||||
{
|
||||
@Override
|
||||
public String getOSName() {
|
||||
return System.getProperty("os.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getServerTime() {
|
||||
final Date d = new Date();
|
||||
final DateFormat df = new SimpleDateFormat("YYYY\u5e74MM\u6708dd\u65e5 hh:mm");
|
||||
return df.format(d);
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
package kohgylw.kiftd.server.service.impl;
|
||||
|
||||
import kohgylw.kiftd.server.service.*;
|
||||
import org.springframework.stereotype.*;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import kohgylw.kiftd.server.mapper.*;
|
||||
import javax.annotation.*;
|
||||
import javax.servlet.http.*;
|
||||
import kohgylw.kiftd.server.pojo.*;
|
||||
import kohgylw.kiftd.server.enumeration.*;
|
||||
import kohgylw.kiftd.server.model.*;
|
||||
import java.util.*;
|
||||
import kohgylw.kiftd.server.util.*;
|
||||
|
||||
@Service
|
||||
public class ShowPictureServiceImpl implements ShowPictureService
|
||||
{
|
||||
@Resource
|
||||
private NodeMapper fm;
|
||||
@Resource
|
||||
private Gson gson;
|
||||
|
||||
private PictureViewList foundPictures(final HttpServletRequest request) {
|
||||
final String fileId = request.getParameter("fileId");
|
||||
if (fileId != null && fileId.length() > 0) {
|
||||
final String account = (String)request.getSession().getAttribute("ACCOUNT");
|
||||
if (ConfigureReader.instance().authorized(account, AccountAuth.DOWNLOAD_FILES)) {
|
||||
final List<Node> nodes = this.fm.queryBySomeFolder(fileId);
|
||||
final List<Node> pictureViewList = new ArrayList<Node>();
|
||||
int index = 0;
|
||||
for (final Node n : nodes) {
|
||||
final String fileName = n.getFileName();
|
||||
final String suffix = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
|
||||
if (suffix.equals("jpg") || suffix.equals("jpeg") || suffix.equals("gif") || suffix.equals("bmp") || suffix.equals("png")) {
|
||||
pictureViewList.add(n);
|
||||
if (!n.getFileId().equals(fileId)) {
|
||||
continue;
|
||||
}
|
||||
index = pictureViewList.size() - 1;
|
||||
}
|
||||
}
|
||||
final PictureViewList pvl = new PictureViewList();
|
||||
pvl.setIndex(index);
|
||||
pvl.setPictureViewList(pictureViewList);
|
||||
return pvl;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getPreviewPictureJson(final HttpServletRequest request) {
|
||||
final PictureViewList pvl = this.foundPictures(request);
|
||||
if (pvl != null) {
|
||||
return gson.toJson((Object)pvl);
|
||||
}
|
||||
return "ERROR";
|
||||
}
|
||||
}
|
135
src/main/java/kohgylw/kiftd/server/util/AudioInfoUtil.java
Normal file
135
src/main/java/kohgylw/kiftd/server/util/AudioInfoUtil.java
Normal file
@ -0,0 +1,135 @@
|
||||
package kohgylw.kiftd.server.util;
|
||||
|
||||
import org.springframework.stereotype.*;
|
||||
import kohgylw.kiftd.server.model.*;
|
||||
import kohgylw.kiftd.server.pojo.*;
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
|
||||
@Component
|
||||
public class AudioInfoUtil {
|
||||
private static String fileBlocks;
|
||||
private static final String ERROR_ARTIST = "\u7fa4\u661f";
|
||||
private static final String DEFAULT_LRC = "css/audio_default.lrc";
|
||||
private static final String DEFAULT_COVER = "css/audio_default.png";
|
||||
|
||||
public AudioInfoUtil() {
|
||||
AudioInfoUtil.fileBlocks = ConfigureReader.instance().getFileBlockPath();
|
||||
}
|
||||
|
||||
public AudioInfoList transformToAudioInfoList(final List<Node> nodes, final String fileId) {
|
||||
final AudioInfoList ail = new AudioInfoList();
|
||||
final List<AudioInfo> as = new ArrayList<AudioInfo>();
|
||||
int index = 0;
|
||||
for (final Node n : nodes) {
|
||||
final String suffix = n.getFileName().substring(n.getFileName().lastIndexOf(".") + 1);
|
||||
if (suffix.equalsIgnoreCase("mp3") || suffix.equalsIgnoreCase("ogg") || suffix.equalsIgnoreCase("wav")) {
|
||||
final AudioInfo ai = new AudioInfo();
|
||||
ai.setUrl("fileblocks/" + n.getFilePath());
|
||||
ai.setLrc(DEFAULT_LRC);
|
||||
ai.setArtist(ERROR_ARTIST);
|
||||
ai.setCover(DEFAULT_COVER);
|
||||
this.getAudioArtistAndName(ai, n);
|
||||
this.getLrcAndCover(ai, n, nodes);
|
||||
as.add(ai);
|
||||
if (!fileId.equals(n.getFileId())) {
|
||||
continue;
|
||||
}
|
||||
index = as.size() - 1;
|
||||
}
|
||||
}
|
||||
ail.setAs(as);
|
||||
ail.setIndex(index);
|
||||
return ail;
|
||||
}
|
||||
|
||||
private void getAudioArtistAndName(final AudioInfo ai, final Node n) {
|
||||
final File f = new File(AudioInfoUtil.fileBlocks, n.getFilePath());
|
||||
ai.setName(this.getFileName(n.getFileName()).trim());
|
||||
ai.setArtist("\u7fa4\u661f");
|
||||
try (final RandomAccessFile raf = new RandomAccessFile(f, "r")) {
|
||||
final byte[] buf = new byte[128];
|
||||
raf.seek(raf.length() - 128L);
|
||||
raf.read(buf);
|
||||
if ("TAG".equalsIgnoreCase(new String(buf, 0, 3))) {
|
||||
final String artist = this.transformCharsetEncoding(buf, 33, 30);
|
||||
final String name = this.transformCharsetEncoding(buf, 3, 30);
|
||||
if (artist.length() > 0 && name.length() > 0) {
|
||||
ai.setArtist(artist);
|
||||
ai.setName(name.trim());
|
||||
}
|
||||
}
|
||||
final byte[] buf2 = new byte[10];
|
||||
raf.seek(0L);
|
||||
raf.read(buf2);
|
||||
if ("ID3".equalsIgnoreCase(new String(buf2, 0, 3))) {
|
||||
final int length = (buf2[6] & 0x7F) * 2097152 + (buf2[7] & 0x7F) * 16384 + (buf2[8] & 0x7F) * 128
|
||||
+ (buf2[9] & 0x7F);
|
||||
final byte[] buf3 = new byte[length];
|
||||
raf.seek(10L);
|
||||
raf.read(buf3);
|
||||
int flength;
|
||||
for (int count = 0; count < length - 1; count = count + 10 + flength) {
|
||||
final String ftitle = new String(buf3, count, 4);
|
||||
flength = buf3[count + 4] * 16777216 + buf3[count + 5] * 65536 + buf3[count + 6] * 256
|
||||
+ buf3[count + 7];
|
||||
if (ftitle.equalsIgnoreCase("TIT2")) {
|
||||
if (flength != 0) {
|
||||
final String name2 = this.transformCharsetEncoding(buf3, count + 11, flength - 1);
|
||||
if (name2.length() > 0) {
|
||||
ai.setName(name2.trim());
|
||||
}
|
||||
}
|
||||
} else if (ftitle.equalsIgnoreCase("TPE1") && flength != 0) {
|
||||
final String artist2 = this.transformCharsetEncoding(buf3, count + 11, flength - 1);
|
||||
if (artist2.length() > 0) {
|
||||
ai.setArtist(artist2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
}
|
||||
|
||||
private void getLrcAndCover(final AudioInfo ai, final Node n, final List<Node> ns) {
|
||||
for (final Node e : ns) {
|
||||
final String suffix = e.getFileName().substring(e.getFileName().lastIndexOf(".") + 1);
|
||||
final String nName = this.getFileName(n.getFileName());
|
||||
if (this.getFileName(e.getFileName()).equals(nName) && suffix.equalsIgnoreCase("lrc")) {
|
||||
ai.setLrc("fileblocks/" + e.getFilePath());
|
||||
}
|
||||
if ((this.getFileName(e.getFileName()).equals(nName)
|
||||
|| ai.getArtist().equals(this.getFileName(e.getFileName())))
|
||||
&& (suffix.equals("jpg") || suffix.equals("jpeg") || suffix.equals("gif") || suffix.equals("bmp")
|
||||
|| suffix.equals("png"))) {
|
||||
ai.setCover("fileblocks/" + e.getFilePath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String getFileName(final String originName) {
|
||||
return (originName.indexOf(".") != -1) ? originName.substring(0, originName.indexOf(".")) : originName;
|
||||
}
|
||||
|
||||
private String transformCharsetEncoding(final byte[] buf, final int offset, final int length) {
|
||||
try {
|
||||
String s = new String(buf, offset, length, "UTF-8");
|
||||
if (s.length() > 0) {
|
||||
if (s.equals(new String(s.getBytes("GBK"), "GBK"))) {
|
||||
return s;
|
||||
}
|
||||
s = new String(buf, offset, length, "GBK");
|
||||
if (s.equals(new String(s.getBytes("UTF-8"), "UTF-8"))) {
|
||||
return s;
|
||||
}
|
||||
s = new String(buf, offset, length, "ISO-8859-1");
|
||||
if (s.equals(new String(s.getBytes("GBK"), "GBK"))) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
} catch (UnsupportedEncodingException ex) {
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
444
src/main/java/kohgylw/kiftd/server/util/ConfigureReader.java
Normal file
444
src/main/java/kohgylw/kiftd/server/util/ConfigureReader.java
Normal file
@ -0,0 +1,444 @@
|
||||
package kohgylw.kiftd.server.util;
|
||||
|
||||
import java.util.*;
|
||||
import kohgylw.kiftd.printer.*;
|
||||
import kohgylw.kiftd.server.enumeration.*;
|
||||
import kohgylw.kiftd.server.pojo.*;
|
||||
import java.io.*;
|
||||
|
||||
public class ConfigureReader {
|
||||
private static ConfigureReader cr;
|
||||
private Properties serverp;
|
||||
private Properties accountp;
|
||||
private int propertiesStatus;
|
||||
private String path;
|
||||
private String fileSystemPath;
|
||||
private String confdir;
|
||||
private String mustLogin;
|
||||
private int port;
|
||||
private String log;
|
||||
private String FSPath;
|
||||
private int bufferSize;
|
||||
private String fileBlockPath;
|
||||
private String fileNodePath;
|
||||
private String TFPath;
|
||||
private final String ACCOUNT_PROPERTIES_FILE = "account.properties";
|
||||
private final String SERVER_PROPERTIES_FILE = "server.properties";
|
||||
private final int DEFAULT_BUFFER_SIZE = 1048576;
|
||||
private final int DEFAULT_PORT = 8080;
|
||||
private final String DEFAULT_LOG_LEVEL = "E";
|
||||
private final String DEFAULT_MUST_LOGIN = "O";
|
||||
private final String DEFAULT_FILE_SYSTEM_PATH;
|
||||
private final String DEFAULT_FILE_SYSTEM_PATH_SETTING = "DEFAULT";
|
||||
private final String DEFAULT_ACCOUNT_ID = "admin";
|
||||
private final String DEFAULT_ACCOUNT_PWD = "000000";
|
||||
private final String DEFAULT_ACCOUNT_AUTH = "cudr";
|
||||
private final String DEFAULT_AUTH_OVERALL = "l";
|
||||
public static final int INVALID_PORT = 1;
|
||||
public static final int INVALID_LOG = 2;
|
||||
public static final int INVALID_FILE_SYSTEM_PATH = 3;
|
||||
public static final int INVALID_BUFFER_SIZE = 4;
|
||||
public static final int CANT_CREATE_FILE_BLOCK_PATH = 5;
|
||||
public static final int CANT_CREATE_FILE_NODE_PATH = 6;
|
||||
public static final int CANT_CREATE_TF_PATH = 7;
|
||||
public static final int LEGAL_PROPERTIES = 0;
|
||||
|
||||
private ConfigureReader() {
|
||||
this.propertiesStatus = -1;
|
||||
this.path = System.getProperty("user.dir");
|
||||
this.DEFAULT_FILE_SYSTEM_PATH = this.path + File.separator + "filesystem" + File.separator;
|
||||
this.confdir = this.path + File.separator + "conf" + File.separator;
|
||||
this.serverp = new Properties();
|
||||
this.accountp = new Properties();
|
||||
final File serverProp = new File(this.confdir + SERVER_PROPERTIES_FILE);
|
||||
if (!serverProp.isFile()) {
|
||||
Printer.instance.print(
|
||||
"\u670d\u52a1\u5668\u914d\u7f6e\u6587\u4ef6\u4e0d\u5b58\u5728\uff0c\u9700\u8981\u521d\u59cb\u5316\u670d\u52a1\u5668\u914d\u7f6e\u3002");
|
||||
this.createDefaultServerPropertiesFile();
|
||||
}
|
||||
final File accountProp = new File(this.confdir + ACCOUNT_PROPERTIES_FILE);
|
||||
if (!accountProp.isFile()) {
|
||||
Printer.instance.print(
|
||||
"\u7528\u6237\u8d26\u6237\u914d\u7f6e\u6587\u4ef6\u4e0d\u5b58\u5728\uff0c\u9700\u8981\u521d\u59cb\u5316\u8d26\u6237\u914d\u7f6e\u3002");
|
||||
this.createDefaultAccountPropertiesFile();
|
||||
}
|
||||
try {
|
||||
Printer.instance.print("\u6b63\u5728\u8f7d\u5165\u914d\u7f6e\u6587\u4ef6...");
|
||||
final FileInputStream serverPropIn = new FileInputStream(serverProp);
|
||||
this.serverp.load(serverPropIn);
|
||||
final FileInputStream accountPropIn = new FileInputStream(accountProp);
|
||||
this.accountp.load(accountPropIn);
|
||||
Printer.instance.print(
|
||||
"\u914d\u7f6e\u6587\u4ef6\u8f7d\u5165\u5b8c\u6bd5\u3002\u6b63\u5728\u68c0\u67e5\u914d\u7f6e...");
|
||||
this.propertiesStatus = this.testServerPropertiesAndEffect();
|
||||
if (this.propertiesStatus == 0) {
|
||||
Printer.instance.print("\u51c6\u5907\u5c31\u7eea\u3002");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Printer.instance.print(
|
||||
"\u9519\u8bef\uff1a\u65e0\u6cd5\u52a0\u8f7d\u4e00\u4e2a\u6216\u591a\u4e2a\u914d\u7f6e\u6587\u4ef6\uff08\u4f4d\u4e8e"
|
||||
+ this.confdir
|
||||
+ "\u8def\u5f84\u4e0b\uff09\uff0c\u8bf7\u5c1d\u8bd5\u5220\u9664\u65e7\u7684\u914d\u7f6e\u6587\u4ef6\u5e76\u91cd\u65b0\u542f\u52a8\u672c\u5e94\u7528\u6216\u67e5\u770b\u5b89\u88c5\u8def\u5f84\u7684\u6743\u9650\uff08\u5fc5\u987b\u53ef\u8bfb\u5199\uff09\u3002");
|
||||
}
|
||||
}
|
||||
|
||||
public static ConfigureReader instance() {
|
||||
if (ConfigureReader.cr == null) {
|
||||
ConfigureReader.cr = new ConfigureReader();
|
||||
}
|
||||
return ConfigureReader.cr;
|
||||
}
|
||||
|
||||
public boolean foundAccount(final String account) {
|
||||
final String accountPwd = this.accountp.getProperty(account + ".pwd");
|
||||
return accountPwd != null && accountPwd.length() > 0;
|
||||
}
|
||||
|
||||
public boolean checkAccountPwd(final String account, final String pwd) {
|
||||
final String apwd = this.accountp.getProperty(account + ".pwd");
|
||||
return apwd != null && apwd.equals(pwd);
|
||||
}
|
||||
|
||||
public boolean authorized(final String account, final AccountAuth auth) {
|
||||
if (account != null && account.length() > 0) {
|
||||
final StringBuffer auths = new StringBuffer();
|
||||
final String accauth = this.accountp.getProperty(account + ".auth");
|
||||
final String overall = this.accountp.getProperty("authOverall");
|
||||
if (accauth != null) {
|
||||
auths.append(accauth);
|
||||
}
|
||||
if (overall != null) {
|
||||
auths.append(overall);
|
||||
}
|
||||
switch (auth) {
|
||||
case CREATE_NEW_FOLDER: {
|
||||
return auths.indexOf("c") != -1;
|
||||
}
|
||||
case UPLOAD_FILES: {
|
||||
return auths.indexOf("u") != -1;
|
||||
}
|
||||
case DELETE_FILE_OR_FOLDER: {
|
||||
return auths.indexOf("d") != -1;
|
||||
}
|
||||
case RENAME_FILE_OR_FOLDER: {
|
||||
return auths.indexOf("r") != -1;
|
||||
}
|
||||
case DOWNLOAD_FILES: {
|
||||
return auths.indexOf("l") != -1;
|
||||
}
|
||||
default: {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
final String overall2 = this.accountp.getProperty("authOverall");
|
||||
if (overall2 == null) {
|
||||
return false;
|
||||
}
|
||||
switch (auth) {
|
||||
case CREATE_NEW_FOLDER: {
|
||||
return overall2.indexOf("c") != -1;
|
||||
}
|
||||
case UPLOAD_FILES: {
|
||||
return overall2.indexOf("u") != -1;
|
||||
}
|
||||
case DELETE_FILE_OR_FOLDER: {
|
||||
return overall2.indexOf("d") != -1;
|
||||
}
|
||||
case RENAME_FILE_OR_FOLDER: {
|
||||
return overall2.indexOf("r") != -1;
|
||||
}
|
||||
case DOWNLOAD_FILES: {
|
||||
return overall2.indexOf("l") != -1;
|
||||
}
|
||||
default: {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getBuffSize() {
|
||||
return this.bufferSize;
|
||||
}
|
||||
|
||||
public boolean inspectLogLevel(final LogLevel l) {
|
||||
int o = 0;
|
||||
int m = 0;
|
||||
if (l == null) {
|
||||
return false;
|
||||
}
|
||||
switch (l) {
|
||||
case None: {
|
||||
m = 0;
|
||||
break;
|
||||
}
|
||||
case Runtime_Exception: {
|
||||
m = 1;
|
||||
}
|
||||
case Event: {
|
||||
m = 2;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
m = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (this.log == null) {
|
||||
this.log = "";
|
||||
}
|
||||
final String log = this.log;
|
||||
switch (log) {
|
||||
case "N": {
|
||||
o = 0;
|
||||
break;
|
||||
}
|
||||
case "R": {
|
||||
o = 1;
|
||||
break;
|
||||
}
|
||||
case "E": {
|
||||
o = 2;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
o = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return o >= m;
|
||||
}
|
||||
|
||||
public boolean mustLogin() {
|
||||
return this.mustLogin != null && this.mustLogin.equals("N");
|
||||
}
|
||||
|
||||
public String getFileSystemPath() {
|
||||
return this.fileSystemPath;
|
||||
}
|
||||
|
||||
public String getFileBlockPath() {
|
||||
return this.fileBlockPath;
|
||||
}
|
||||
|
||||
public String getFileNodePath() {
|
||||
return this.fileNodePath;
|
||||
}
|
||||
|
||||
public String getTemporaryfilePath() {
|
||||
return this.TFPath;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return this.path;
|
||||
}
|
||||
|
||||
public LogLevel getLogLevel() {
|
||||
if (this.log == null) {
|
||||
this.log = "";
|
||||
}
|
||||
final String log = this.log;
|
||||
switch (log) {
|
||||
case "N": {
|
||||
return LogLevel.None;
|
||||
}
|
||||
case "R": {
|
||||
return LogLevel.Runtime_Exception;
|
||||
}
|
||||
case "E": {
|
||||
return LogLevel.Event;
|
||||
}
|
||||
default: {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return this.port;
|
||||
}
|
||||
|
||||
public int getPropertiesStatus() {
|
||||
return this.propertiesStatus;
|
||||
}
|
||||
|
||||
public boolean doUpdate(final ServerSetting ss) {
|
||||
if (ss != null) {
|
||||
Printer.instance.print("\u6b63\u5728\u66f4\u65b0\u670d\u52a1\u5668\u914d\u7f6e...");
|
||||
this.serverp.setProperty("mustLogin", ss.isMustLogin() ? "N" : "O");
|
||||
this.serverp.setProperty("buff.size", ss.getBuffSize() + "");
|
||||
String loglevelCode = "E";
|
||||
switch (ss.getLog()) {
|
||||
case Event: {
|
||||
loglevelCode = "E";
|
||||
break;
|
||||
}
|
||||
case Runtime_Exception: {
|
||||
loglevelCode = "R";
|
||||
break;
|
||||
}
|
||||
case None: {
|
||||
loglevelCode = "N";
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.serverp.setProperty("log", loglevelCode);
|
||||
this.serverp.setProperty("port", ss.getPort() + "");
|
||||
this.serverp.setProperty("FS.path",
|
||||
(ss.getFsPath() + File.separator).equals(this.DEFAULT_FILE_SYSTEM_PATH) ? "DEFAULT"
|
||||
: ss.getFsPath());
|
||||
if (this.testServerPropertiesAndEffect() == 0) {
|
||||
try {
|
||||
this.serverp.store(new FileOutputStream(this.confdir + SERVER_PROPERTIES_FILE),
|
||||
"<Kiftd server setting file is update.>");
|
||||
Printer.instance.print("\u914d\u7f6e\u66f4\u65b0\u5b8c\u6bd5\uff0c\u51c6\u5907\u5c31\u7eea\u3002");
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
Printer.instance.print(
|
||||
"\u9519\u8bef\uff1a\u66f4\u65b0\u8bbe\u7f6e\u5931\u8d25\uff0c\u65e0\u6cd5\u5b58\u5165\u8bbe\u7f6e\u6587\u4ef6\u3002");
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private int testServerPropertiesAndEffect() {
|
||||
Printer.instance.print("\u6b63\u5728\u68c0\u67e5\u670d\u52a1\u5668\u914d\u7f6e...");
|
||||
this.mustLogin = this.serverp.getProperty("mustLogin");
|
||||
if (this.mustLogin == null) {
|
||||
Printer.instance.print(
|
||||
"\u8b66\u544a\uff1a\u672a\u627e\u5230\u662f\u5426\u5fc5\u987b\u767b\u5f55\u914d\u7f6e\uff0c\u5c06\u91c7\u7528\u9ed8\u8ba4\u503c\uff08O\uff09\u3002");
|
||||
this.mustLogin = "O";
|
||||
}
|
||||
final String ports = this.serverp.getProperty("port");
|
||||
if (ports == null) {
|
||||
Printer.instance.print(
|
||||
"\u8b66\u544a\uff1a\u672a\u627e\u5230\u7aef\u53e3\u914d\u7f6e\uff0c\u5c06\u91c7\u7528\u9ed8\u8ba4\u503c\uff088080\uff09\u3002");
|
||||
this.port = 8080;
|
||||
} else {
|
||||
try {
|
||||
this.port = Integer.parseInt(ports);
|
||||
if (this.port <= 0 || this.port > 65535) {
|
||||
return 1;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
final String logs = this.serverp.getProperty("log");
|
||||
if (logs == null) {
|
||||
Printer.instance.print(
|
||||
"\u8b66\u544a\uff1a\u672a\u627e\u5230\u65e5\u5fd7\u7b49\u7ea7\u914d\u7f6e\uff0c\u5c06\u91c7\u7528\u9ed8\u8ba4\u503c\uff08E\uff09\u3002");
|
||||
this.log = "E";
|
||||
} else {
|
||||
if (!logs.equals("N") && !logs.equals("R") && !logs.equals("E")) {
|
||||
return 2;
|
||||
}
|
||||
this.log = logs;
|
||||
}
|
||||
final String bufferSizes = this.serverp.getProperty("buff.size");
|
||||
if (bufferSizes == null) {
|
||||
Printer.instance.print(
|
||||
"\u8b66\u544a\uff1a\u672a\u627e\u5230\u7f13\u51b2\u5927\u5c0f\u914d\u7f6e\uff0c\u5c06\u91c7\u7528\u9ed8\u8ba4\u503c\uff081048576\uff09\u3002");
|
||||
this.bufferSize = 1048576;
|
||||
} else {
|
||||
try {
|
||||
this.bufferSize = Integer.parseInt(bufferSizes);
|
||||
if (this.bufferSize <= 0) {
|
||||
Printer.instance
|
||||
.print("\u9519\u8bef\uff1a\u7f13\u51b2\u533a\u5927\u5c0f\u8bbe\u7f6e\u65e0\u6548\u3002");
|
||||
return 4;
|
||||
}
|
||||
} catch (Exception e2) {
|
||||
Printer.instance
|
||||
.print("\u9519\u8bef\uff1a\u7f13\u51b2\u533a\u5927\u5c0f\u8bbe\u7f6e\u65e0\u6548\u3002");
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
this.FSPath = this.serverp.getProperty("FS.path");
|
||||
if (this.FSPath == null) {
|
||||
Printer.instance.print(
|
||||
"\u8b66\u544a\uff1a\u672a\u627e\u5230\u6587\u4ef6\u7cfb\u7edf\u914d\u7f6e\uff0c\u5c06\u91c7\u7528\u9ed8\u8ba4\u503c\u3002");
|
||||
this.fileSystemPath = this.DEFAULT_FILE_SYSTEM_PATH;
|
||||
} else if (this.FSPath.equals("DEFAULT")) {
|
||||
this.fileSystemPath = this.DEFAULT_FILE_SYSTEM_PATH;
|
||||
} else {
|
||||
this.fileSystemPath = this.FSPath;
|
||||
}
|
||||
final File fsFile = new File(this.fileSystemPath);
|
||||
if (!fsFile.isDirectory() || !fsFile.canRead() || !fsFile.canWrite()) {
|
||||
Printer.instance.print("\u9519\u8bef\uff1a\u6587\u4ef6\u7cfb\u7edf\u8def\u5f84[" + this.fileSystemPath
|
||||
+ "]\u65e0\u6548\uff0c\u8be5\u8def\u5f84\u5fc5\u987b\u6307\u5411\u4e00\u4e2a\u5177\u5907\u8bfb\u5199\u6743\u9650\u7684\u6587\u4ef6\u5939\u3002");
|
||||
return 3;
|
||||
}
|
||||
this.fileBlockPath = this.fileSystemPath + "fileblocks" + File.separator;
|
||||
final File fbFile = new File(this.fileBlockPath);
|
||||
if (!fbFile.isDirectory() && !fbFile.mkdirs()) {
|
||||
Printer.instance.print("\u9519\u8bef\uff1a\u65e0\u6cd5\u521b\u5efa\u6587\u4ef6\u5757\u5b58\u653e\u533a["
|
||||
+ this.fileBlockPath + "]\u3002");
|
||||
return 5;
|
||||
}
|
||||
this.fileNodePath = this.fileSystemPath + "filenodes" + File.separator;
|
||||
final File fnFile = new File(this.fileNodePath);
|
||||
if (!fnFile.isDirectory() && !fnFile.mkdirs()) {
|
||||
Printer.instance
|
||||
.print("\u9519\u8bef\uff1a\u65e0\u6cd5\u521b\u5efa\u6587\u4ef6\u8282\u70b9\u5b58\u653e\u533a["
|
||||
+ this.fileNodePath + "]\u3002");
|
||||
return 6;
|
||||
}
|
||||
this.TFPath = this.fileSystemPath + File.separator + "temporaryfiles";
|
||||
final File tfFile = new File(this.TFPath);
|
||||
if (!tfFile.isDirectory() && !tfFile.mkdirs()) {
|
||||
Printer.instance
|
||||
.print("\u9519\u8bef\uff1a\u65e0\u6cd5\u521b\u5efa\u4e34\u65f6\u6587\u4ef6\u5b58\u653e\u533a["
|
||||
+ this.TFPath + "]\u3002");
|
||||
return 7;
|
||||
}
|
||||
Printer.instance.print("\u68c0\u67e5\u5b8c\u6bd5\u3002");
|
||||
return 0;
|
||||
}
|
||||
|
||||
private void createDefaultServerPropertiesFile() {
|
||||
Printer.instance.print("\u6b63\u5728\u751f\u6210\u521d\u59cb\u670d\u52a1\u5668\u914d\u7f6e\u6587\u4ef6\uff08"
|
||||
+ this.confdir + SERVER_PROPERTIES_FILE + "\uff09...");
|
||||
final Properties dsp = new Properties();
|
||||
dsp.setProperty("mustLogin", DEFAULT_MUST_LOGIN);
|
||||
dsp.setProperty("port", DEFAULT_PORT + "");
|
||||
dsp.setProperty("log", DEFAULT_LOG_LEVEL);
|
||||
dsp.setProperty("FS.path", DEFAULT_FILE_SYSTEM_PATH_SETTING);
|
||||
dsp.setProperty("buff.size", DEFAULT_BUFFER_SIZE + "");
|
||||
try {
|
||||
dsp.store(new FileOutputStream(this.confdir + SERVER_PROPERTIES_FILE),
|
||||
"<This is the default kiftd server setting file. >");
|
||||
Printer.instance
|
||||
.print("\u521d\u59cb\u670d\u52a1\u5668\u914d\u7f6e\u6587\u4ef6\u751f\u6210\u5b8c\u6bd5\u3002");
|
||||
} catch (FileNotFoundException e) {
|
||||
Printer.instance.print(
|
||||
"\u9519\u8bef\uff1a\u65e0\u6cd5\u751f\u6210\u521d\u59cb\u670d\u52a1\u5668\u914d\u7f6e\u6587\u4ef6\uff0c\u5b58\u50a8\u8def\u5f84\u4e0d\u5b58\u5728\u3002");
|
||||
} catch (IOException e2) {
|
||||
Printer.instance.print(
|
||||
"\u9519\u8bef\uff1a\u65e0\u6cd5\u751f\u6210\u521d\u59cb\u670d\u52a1\u5668\u914d\u7f6e\u6587\u4ef6\uff0c\u5199\u5165\u5931\u8d25\u3002");
|
||||
}
|
||||
}
|
||||
|
||||
private void createDefaultAccountPropertiesFile() {
|
||||
Printer.instance.print("\u6b63\u5728\u751f\u6210\u521d\u59cb\u8d26\u6237\u914d\u7f6e\u6587\u4ef6\uff08"
|
||||
+ this.confdir + ACCOUNT_PROPERTIES_FILE + "\uff09...");
|
||||
final Properties dap = new Properties();
|
||||
dap.setProperty(DEFAULT_ACCOUNT_ID + ".pwd", DEFAULT_ACCOUNT_PWD);
|
||||
dap.setProperty(DEFAULT_ACCOUNT_ID + ".auth", DEFAULT_ACCOUNT_AUTH);
|
||||
dap.setProperty("authOverall", DEFAULT_AUTH_OVERALL);
|
||||
try {
|
||||
dap.store(new FileOutputStream(this.confdir + ACCOUNT_PROPERTIES_FILE),
|
||||
"<This is the default kiftd account setting file. >");
|
||||
Printer.instance.print("\u521d\u59cb\u8d26\u6237\u914d\u7f6e\u6587\u4ef6\u751f\u6210\u5b8c\u6bd5\u3002");
|
||||
} catch (FileNotFoundException e) {
|
||||
Printer.instance.print(
|
||||
"\u9519\u8bef\uff1a\u65e0\u6cd5\u751f\u6210\u521d\u59cb\u8d26\u6237\u914d\u7f6e\u6587\u4ef6\uff0c\u5b58\u50a8\u8def\u5f84\u4e0d\u5b58\u5728\u3002");
|
||||
} catch (IOException e2) {
|
||||
Printer.instance.print(
|
||||
"\u9519\u8bef\uff1a\u65e0\u6cd5\u751f\u6210\u521d\u59cb\u8d26\u6237\u914d\u7f6e\u6587\u4ef6\uff0c\u5199\u5165\u5931\u8d25\u3002");
|
||||
}
|
||||
}
|
||||
}
|
53
src/main/java/kohgylw/kiftd/server/util/DecryptionUtil.java
Normal file
53
src/main/java/kohgylw/kiftd/server/util/DecryptionUtil.java
Normal file
@ -0,0 +1,53 @@
|
||||
package kohgylw.kiftd.server.util;
|
||||
|
||||
import java.util.*;
|
||||
import java.nio.charset.*;
|
||||
import java.security.spec.*;
|
||||
import java.security.*;
|
||||
import javax.crypto.*;
|
||||
|
||||
public class DecryptionUtil
|
||||
{
|
||||
private static Base64.Decoder decoder;
|
||||
private static KeyFactory kf;
|
||||
private static Cipher c;
|
||||
|
||||
public static String dncryption(final String context, final String privateKey) {
|
||||
final byte[] b = DecryptionUtil.decoder.decode(privateKey);
|
||||
final byte[] s = DecryptionUtil.decoder.decode(context.getBytes(StandardCharsets.UTF_8));
|
||||
final PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(b);
|
||||
try {
|
||||
final PrivateKey key = DecryptionUtil.kf.generatePrivate(spec);
|
||||
DecryptionUtil.c.init(2, key);
|
||||
final byte[] f = DecryptionUtil.c.doFinal(s);
|
||||
return new String(f);
|
||||
}
|
||||
catch (InvalidKeySpecException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch (InvalidKeyException e2) {
|
||||
e2.printStackTrace();
|
||||
}
|
||||
catch (IllegalBlockSizeException e3) {
|
||||
e3.printStackTrace();
|
||||
}
|
||||
catch (BadPaddingException e4) {
|
||||
e4.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static {
|
||||
DecryptionUtil.decoder = Base64.getDecoder();
|
||||
try {
|
||||
DecryptionUtil.kf = KeyFactory.getInstance("RSA");
|
||||
DecryptionUtil.c = Cipher.getInstance("RSA");
|
||||
}
|
||||
catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch (NoSuchPaddingException e2) {
|
||||
e2.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
93
src/main/java/kohgylw/kiftd/server/util/FileBlockUtil.java
Normal file
93
src/main/java/kohgylw/kiftd/server/util/FileBlockUtil.java
Normal file
@ -0,0 +1,93 @@
|
||||
package kohgylw.kiftd.server.util;
|
||||
|
||||
import org.springframework.stereotype.*;
|
||||
import kohgylw.kiftd.server.mapper.*;
|
||||
import javax.annotation.*;
|
||||
import javax.servlet.http.*;
|
||||
import org.springframework.web.multipart.*;
|
||||
import java.io.*;
|
||||
import kohgylw.kiftd.server.model.*;
|
||||
import java.util.*;
|
||||
import org.zeroturnaround.zip.*;
|
||||
|
||||
@Component
|
||||
public class FileBlockUtil {
|
||||
@Resource
|
||||
private NodeMapper fm;
|
||||
|
||||
public String saveToFileBlocks(final HttpServletRequest request, final MultipartFile f) {
|
||||
final String fileBlocks = ConfigureReader.instance().getFileBlockPath();
|
||||
final String id = UUID.randomUUID().toString().replace("-", "");
|
||||
final String path = "file_" + id + ".block";
|
||||
final File file = new File(fileBlocks, path);
|
||||
try {
|
||||
f.transferTo(file);
|
||||
return path;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return "ERROR";
|
||||
}
|
||||
}
|
||||
|
||||
public String getFileSize(final MultipartFile f) {
|
||||
final long size = f.getSize();
|
||||
final int mb = (int) (size / 1024L / 1024L);
|
||||
return "" + mb;
|
||||
}
|
||||
|
||||
public boolean deleteFromFileBlocks(final String fileblocks, final String path) {
|
||||
final File file = new File(fileblocks, path);
|
||||
return file.exists() && file.isFile() && file.delete();
|
||||
}
|
||||
|
||||
public File getFileFromBlocks(final String fileBlocks, final String path) {
|
||||
final File file = new File(fileBlocks, path);
|
||||
if (file.exists() && file.isFile()) {
|
||||
return file;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void checkFileBlocks() {
|
||||
String fileblocks = ConfigureReader.instance().getFileBlockPath();
|
||||
Thread checkThread = new Thread(() -> {
|
||||
List<Node> nodes = fm.queryAll();
|
||||
for (Node node : nodes) {
|
||||
File block = new File(fileblocks, node.getFilePath());
|
||||
if (!block.exists()) {
|
||||
fm.deleteById(node.getFileId());
|
||||
}
|
||||
}
|
||||
File blocks = new File(fileblocks);
|
||||
String[] bn = blocks.list();
|
||||
for (String n : bn) {
|
||||
Node node = fm.queryByPath(n);
|
||||
if (node == null) {
|
||||
File f = new File(fileblocks, n);
|
||||
f.delete();
|
||||
}
|
||||
}
|
||||
});
|
||||
checkThread.start();
|
||||
}
|
||||
|
||||
public String createZip(final List<String> idList, final String tfPath, final String fileBlocks) {
|
||||
final String zipname = "tf_" + UUID.randomUUID().toString() + ".zip";
|
||||
final File f = new File(tfPath, zipname);
|
||||
try {
|
||||
final ZipEntrySource[] zs = new ZipEntrySource[idList.size()];
|
||||
for (int i = 0; i < idList.size(); ++i) {
|
||||
final Node node = this.fm.queryById(idList.get(i));
|
||||
if (node != null) {
|
||||
zs[i] = (ZipEntrySource) new FileSource(node.getFileName(),
|
||||
new File(fileBlocks, node.getFilePath()));
|
||||
}
|
||||
}
|
||||
ZipUtil.pack(zs, f);
|
||||
return zipname;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
56
src/main/java/kohgylw/kiftd/server/util/FolderUtil.java
Normal file
56
src/main/java/kohgylw/kiftd/server/util/FolderUtil.java
Normal file
@ -0,0 +1,56 @@
|
||||
package kohgylw.kiftd.server.util;
|
||||
|
||||
import org.springframework.stereotype.*;
|
||||
import javax.annotation.*;
|
||||
import kohgylw.kiftd.server.mapper.*;
|
||||
import javax.servlet.http.*;
|
||||
import kohgylw.kiftd.server.model.*;
|
||||
import java.util.*;
|
||||
|
||||
@Component
|
||||
public class FolderUtil
|
||||
{
|
||||
@Resource
|
||||
private FolderMapper fm;
|
||||
@Resource
|
||||
private NodeMapper fim;
|
||||
@Resource
|
||||
private FileBlockUtil fbu;
|
||||
|
||||
public List<Folder> getParentList(final String fid) {
|
||||
Folder f = this.fm.queryById(fid);
|
||||
final List<Folder> folderList = new ArrayList<Folder>();
|
||||
if (f != null) {
|
||||
while (!f.getFolderParent().equals("null")) {
|
||||
f = this.fm.queryById(f.getFolderParent());
|
||||
folderList.add(f);
|
||||
}
|
||||
}
|
||||
Collections.reverse(folderList);
|
||||
return folderList;
|
||||
}
|
||||
|
||||
public int deleteAllChildFolder(final HttpServletRequest request, final String folderId) {
|
||||
final String fileblocks = request.getServletContext().getRealPath("/fileblocks");
|
||||
final Thread deleteChildFolderThread = new Thread(() -> this.iterationDeleteFolder(fileblocks, folderId));
|
||||
deleteChildFolderThread.start();
|
||||
return this.fm.deleteById(folderId);
|
||||
}
|
||||
|
||||
private void iterationDeleteFolder(final String fileblocks, final String folderId) {
|
||||
final List<Folder> cf = (List<Folder>)this.fm.queryByParentId(folderId);
|
||||
if (cf.size() > 0) {
|
||||
for (final Folder f : cf) {
|
||||
this.iterationDeleteFolder(fileblocks, f.getFolderId());
|
||||
}
|
||||
}
|
||||
final List<Node> files = (List<Node>)this.fim.queryByParentFolderId(folderId);
|
||||
if (files.size() > 0) {
|
||||
this.fim.deleteByParentFolderId(folderId);
|
||||
for (final Node f2 : files) {
|
||||
this.fbu.deleteFromFileBlocks(fileblocks, f2.getFilePath());
|
||||
}
|
||||
}
|
||||
this.fm.deleteById(folderId);
|
||||
}
|
||||
}
|
46
src/main/java/kohgylw/kiftd/server/util/KeyUtil.java
Normal file
46
src/main/java/kohgylw/kiftd/server/util/KeyUtil.java
Normal file
@ -0,0 +1,46 @@
|
||||
package kohgylw.kiftd.server.util;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.nio.charset.*;
|
||||
import java.security.*;
|
||||
@Component
|
||||
public class KeyUtil
|
||||
{
|
||||
private static final int KEY_SIZE = 1024;
|
||||
private Key publicKey;
|
||||
private Key privateKey;
|
||||
private Base64.Encoder encoder;
|
||||
private String publicKeyStr;
|
||||
private String privateKeyStr;
|
||||
|
||||
public KeyUtil() {
|
||||
this.encoder = Base64.getEncoder();
|
||||
try {
|
||||
final KeyPairGenerator g = KeyPairGenerator.getInstance("RSA");
|
||||
g.initialize(KEY_SIZE);
|
||||
final KeyPair pair = g.genKeyPair();
|
||||
this.publicKey = pair.getPublic();
|
||||
this.privateKey = pair.getPrivate();
|
||||
this.publicKeyStr = new String(this.encoder.encode(this.publicKey.getEncoded()), StandardCharsets.UTF_8);
|
||||
this.privateKeyStr = new String(this.encoder.encode(this.privateKey.getEncoded()), StandardCharsets.UTF_8);
|
||||
}
|
||||
catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public String getPublicKey() {
|
||||
return this.publicKeyStr;
|
||||
}
|
||||
|
||||
public String getPrivateKey() {
|
||||
return this.privateKeyStr;
|
||||
}
|
||||
|
||||
public int getKeySize() {
|
||||
return KEY_SIZE;
|
||||
}
|
||||
}
|
309
src/main/java/kohgylw/kiftd/server/util/LogUtil.java
Normal file
309
src/main/java/kohgylw/kiftd/server/util/LogUtil.java
Normal file
@ -0,0 +1,309 @@
|
||||
package kohgylw.kiftd.server.util;
|
||||
|
||||
import org.springframework.stereotype.*;
|
||||
import javax.annotation.*;
|
||||
import kohgylw.kiftd.server.mapper.*;
|
||||
import kohgylw.kiftd.server.enumeration.*;
|
||||
import javax.servlet.http.*;
|
||||
import java.util.*;
|
||||
import kohgylw.kiftd.server.model.*;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
@Component
|
||||
public class LogUtil {
|
||||
|
||||
@Resource
|
||||
private FolderUtil fu;
|
||||
@Resource
|
||||
private FolderMapper fm;
|
||||
@Resource
|
||||
private NodeMapper fim;
|
||||
|
||||
private String sep = "";
|
||||
private String logs = "";
|
||||
|
||||
public LogUtil() {
|
||||
sep = File.separator;
|
||||
logs = ConfigureReader.instance().getPath()+sep+"logs";
|
||||
File l = new File(logs);
|
||||
if (!l.exists()) {
|
||||
l.mkdir();
|
||||
} else {
|
||||
if (!l.isDirectory()) {
|
||||
l.delete();
|
||||
l.mkdir();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 以格式化记录异常信息
|
||||
* <p>
|
||||
* 创建日志文件并写入异常信息,当同日期的日志文件存在时,则在其后面追加该信息
|
||||
* </p>
|
||||
*
|
||||
* @param e
|
||||
* Exception 需要记录的异常对象
|
||||
*/
|
||||
public void writeException(Exception e) {
|
||||
if (ConfigureReader.instance().inspectLogLevel(LogLevel.Runtime_Exception)) {
|
||||
writeToLog("Exception", "[" + e + "]:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 以格式化记录新建文件夹日志
|
||||
* <p>
|
||||
* 写入新建文件夹信息,包括操作者、路劲及新文件夹名称
|
||||
* </p>
|
||||
*/
|
||||
public void writeCreateFolderEvent(HttpServletRequest request, Folder f) {
|
||||
if (ConfigureReader.instance().inspectLogLevel(LogLevel.Event)) {
|
||||
String account = (String) request.getSession().getAttribute("ACCOUNT");
|
||||
if (account == null || account.length() == 0) {
|
||||
account = "Anonymous";
|
||||
}
|
||||
String a = account;// 方便下方使用终态操作
|
||||
Thread t = new Thread(() -> {
|
||||
List<Folder> l = fu.getParentList(f.getFolderId());
|
||||
String pl = new String();
|
||||
for (Folder i : l) {
|
||||
pl = pl + i.getFolderName() + "/";
|
||||
}
|
||||
String content = ">ACCOUNT [" + a + "]\r\n>OPERATE [Create new folder]\r\n>PATH [" + pl + "]\r\n>NAME ["
|
||||
+ f.getFolderName() + "]";
|
||||
writeToLog("Event", content);
|
||||
});
|
||||
t.start();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 以格式化记录重命名文件夹日志
|
||||
* <p>
|
||||
* 写入重命名文件夹信息
|
||||
* </p>
|
||||
*/
|
||||
public void writeRenameFolderEvent(HttpServletRequest request, Folder f, String newName) {
|
||||
if (ConfigureReader.instance().inspectLogLevel(LogLevel.Event)) {
|
||||
String account = (String) request.getSession().getAttribute("ACCOUNT");
|
||||
if (account == null || account.length() == 0) {
|
||||
account = "Anonymous";
|
||||
}
|
||||
String a = account;
|
||||
Thread t = new Thread(() -> {
|
||||
List<Folder> l = fu.getParentList(f.getFolderId());
|
||||
String pl = new String();
|
||||
for (Folder i : l) {
|
||||
pl = pl + i.getFolderName() + "/";
|
||||
}
|
||||
String content = ">ACCOUNT [" + a + "]\r\n>OPERATE [Rename folder]\r\n>PATH [" + pl + "]\r\n>NAME ["
|
||||
+ f.getFolderName() + "]->[" + newName + "]";
|
||||
writeToLog("Event", content);
|
||||
});
|
||||
t.start();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 以格式化记录删除文件夹日志
|
||||
* <p>
|
||||
* 写入删除文件夹信息
|
||||
* </p>
|
||||
*/
|
||||
public void writeDeleteFolderEvent(HttpServletRequest request, Folder f, List<Folder> l) {
|
||||
if (ConfigureReader.instance().inspectLogLevel(LogLevel.Event)) {
|
||||
String account = (String) request.getSession().getAttribute("ACCOUNT");
|
||||
if (account == null || account.length() == 0) {
|
||||
account = "Anonymous";
|
||||
}
|
||||
String a = account;
|
||||
Thread t = new Thread(() -> {
|
||||
String pl = new String();
|
||||
for (Folder i : l) {
|
||||
pl = pl + i.getFolderName() + "/";
|
||||
}
|
||||
String content = ">ACCOUNT [" + a + "]\r\n>OPERATE [Delete folder]\r\n>PATH [" + pl + "]\r\n>NAME ["
|
||||
+ f.getFolderName() + "]";
|
||||
writeToLog("Event", content);
|
||||
});
|
||||
t.start();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 以格式化记录删除文件日志
|
||||
* <p>
|
||||
* 写入删除文件信息
|
||||
* </p>
|
||||
*/
|
||||
public void writeDeleteFileEvent(HttpServletRequest request, Node f) {
|
||||
if (ConfigureReader.instance().inspectLogLevel(LogLevel.Event)) {
|
||||
String account = (String) request.getSession().getAttribute("ACCOUNT");
|
||||
if (account == null || account.length() == 0) {
|
||||
account = "Anonymous";
|
||||
}
|
||||
String a = account;
|
||||
Thread t = new Thread(() -> {
|
||||
Folder folder = fm.queryById(f.getFileParentFolder());
|
||||
List<Folder> l = fu.getParentList(folder.getFolderId());
|
||||
String pl = new String();
|
||||
for (Folder i : l) {
|
||||
pl = pl + i.getFolderName() + "/";
|
||||
}
|
||||
String content = ">ACCOUNT [" + a + "]\r\n>OPERATE [Delete file]\r\n>PATH [" + pl
|
||||
+ folder.getFolderName() + "]\r\n>NAME [" + f.getFileName() + "]";
|
||||
writeToLog("Event", content);
|
||||
});
|
||||
t.start();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 以格式化记录上传文件日志
|
||||
* <p>
|
||||
* 写入上传文件信息
|
||||
* </p>
|
||||
*/
|
||||
public void writeUploadFileEvent(HttpServletRequest request, Node f) {
|
||||
if (ConfigureReader.instance().inspectLogLevel(LogLevel.Event)) {
|
||||
String account = (String) request.getSession().getAttribute("ACCOUNT");
|
||||
if (account == null || account.length() == 0) {
|
||||
account = "Anonymous";
|
||||
}
|
||||
String a = account;
|
||||
Thread t = new Thread(() -> {
|
||||
Folder folder = fm.queryById(f.getFileParentFolder());
|
||||
List<Folder> l = fu.getParentList(folder.getFolderId());
|
||||
String pl = new String();
|
||||
for (Folder i : l) {
|
||||
pl = pl + i.getFolderName() + "/";
|
||||
}
|
||||
String content = ">ACCOUNT [" + a + "]\r\n>OPERATE [Upload file]\r\n>PATH [" + pl
|
||||
+ folder.getFolderName() + "]\r\n>NAME [" + f.getFileName() + "]";
|
||||
writeToLog("Event", content);
|
||||
});
|
||||
t.start();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 以格式化记录下载文件日志
|
||||
* <p>
|
||||
* 写入下载文件信息
|
||||
* </p>
|
||||
*/
|
||||
public void writeDownloadFileEvent(HttpServletRequest request, Node f) {
|
||||
if (ConfigureReader.instance().inspectLogLevel(LogLevel.Event)) {
|
||||
String account = (String) request.getSession().getAttribute("ACCOUNT");
|
||||
if (account == null || account.length() == 0) {
|
||||
account = "Anonymous";
|
||||
}
|
||||
String a = account;
|
||||
Thread t = new Thread(() -> {
|
||||
Folder folder = fm.queryById(f.getFileParentFolder());
|
||||
List<Folder> l = fu.getParentList(folder.getFolderId());
|
||||
String pl = new String();
|
||||
for (Folder i : l) {
|
||||
pl = pl + i.getFolderName() + "/";
|
||||
}
|
||||
String content = ">ACCOUNT [" + a + "]\r\n>OPERATE [Download file]\r\n>PATH [" + pl
|
||||
+ folder.getFolderName() + "]\r\n>NAME [" + f.getFileName() + "]";
|
||||
writeToLog("Event", content);
|
||||
});
|
||||
t.start();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 以格式化记录重命名文件日志
|
||||
* <p>
|
||||
* 写入重命名文件信息
|
||||
* </p>
|
||||
*/
|
||||
public void writeRenameFileEvent(HttpServletRequest request, Node f, String newName) {
|
||||
if (ConfigureReader.instance().inspectLogLevel(LogLevel.Event)) {
|
||||
String account = (String) request.getSession().getAttribute("ACCOUNT");
|
||||
if (account == null || account.length() == 0) {
|
||||
account = "Anonymous";
|
||||
}
|
||||
String a = account;
|
||||
Thread t = new Thread(() -> {
|
||||
Folder folder = fm.queryById(f.getFileParentFolder());
|
||||
List<Folder> l = fu.getParentList(folder.getFolderId());
|
||||
String pl = new String();
|
||||
for (Folder i : l) {
|
||||
pl = pl + i.getFolderName() + "/";
|
||||
}
|
||||
String content = ">ACCOUNT [" + a + "]\r\n>OPERATE [Rename file]\r\n>PATH [" + pl
|
||||
+ folder.getFolderName() + "]\r\n>NAME [" + f.getFileName() + "]->[" + newName + "]";
|
||||
writeToLog("Event", content);
|
||||
});
|
||||
t.start();
|
||||
}
|
||||
}
|
||||
|
||||
private void writeToLog(String type, String content) {
|
||||
String t = ServerTimeUtil.accurateToLogName();
|
||||
File f = new File(logs, t + ".klog");
|
||||
FileWriter fw = null;
|
||||
if (f.exists()) {
|
||||
try {
|
||||
fw = new FileWriter(f, true);
|
||||
fw.write("\r\n\r\nTIME:\r\n" + ServerTimeUtil.accurateToSecond() + "\r\nTYPE:\r\n" + type
|
||||
+ "\r\nCONTENT:\r\n" + content);
|
||||
fw.close();
|
||||
} catch (Exception e1) {
|
||||
System.out.println("KohgylwIFT:[Log]Cannt write to file,message:" + e1.getMessage());
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
fw = new FileWriter(f, false);
|
||||
fw.write("TIME:\r\n" + ServerTimeUtil.accurateToSecond() + "\r\nTYPE:\r\n" + type + "\r\nCONTENT:\r\n"
|
||||
+ content);
|
||||
fw.close();
|
||||
} catch (IOException e1) {
|
||||
System.out.println("KohgylwIFT:[Log]Cannt write to file,message:" + e1.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 以格式化记录下载文件日志
|
||||
* <p>
|
||||
* 写入下载文件信息
|
||||
* </p>
|
||||
*/
|
||||
public void writeDownloadCheckedFileEvent(HttpServletRequest request, List<String> idList) {
|
||||
if (ConfigureReader.instance().inspectLogLevel(LogLevel.Event)) {
|
||||
String account = (String) request.getSession().getAttribute("ACCOUNT");
|
||||
if (account == null || account.length() == 0) {
|
||||
account = "Anonymous";
|
||||
}
|
||||
String a = account;
|
||||
Thread t = new Thread(() -> {
|
||||
StringBuffer content = new StringBuffer(
|
||||
">ACCOUNT [" + a + "]\r\n>OPERATE [Download checked file]\r\n----------------\r\n");
|
||||
for (String fid : idList) {
|
||||
Node f = fim.queryById(fid);
|
||||
if (f != null) {
|
||||
Folder folder = fm.queryById(f.getFileParentFolder());
|
||||
List<Folder> l = fu.getParentList(folder.getFolderId());
|
||||
String pl = new String();
|
||||
for (Folder i : l) {
|
||||
pl = pl + i.getFolderName() + "/";
|
||||
}
|
||||
content.append(
|
||||
">PATH [" + pl + folder.getFolderName() + "]\r\n>NAME [" + f.getFileName() + "]\r\n");
|
||||
}
|
||||
}
|
||||
content.append("----------------");
|
||||
writeToLog("Event", content.toString());
|
||||
});
|
||||
t.start();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
35
src/main/java/kohgylw/kiftd/server/util/ServerTimeUtil.java
Normal file
35
src/main/java/kohgylw/kiftd/server/util/ServerTimeUtil.java
Normal file
@ -0,0 +1,35 @@
|
||||
package kohgylw.kiftd.server.util;
|
||||
|
||||
import java.util.*;
|
||||
import java.text.*;
|
||||
|
||||
public class ServerTimeUtil
|
||||
{
|
||||
public static String accurateToSecond() {
|
||||
final Date d = new Date();
|
||||
final DateFormat df = new SimpleDateFormat("YYYY\u5e74MM\u6708dd\u65e5 HH:mm:ss");
|
||||
return df.format(d);
|
||||
}
|
||||
|
||||
public static String accurateToMinute() {
|
||||
final Date d = new Date();
|
||||
final DateFormat df = new SimpleDateFormat("YYYY\u5e74MM\u6708dd\u65e5 HH:mm");
|
||||
return df.format(d);
|
||||
}
|
||||
|
||||
public static String accurateToDay() {
|
||||
final Date d = new Date();
|
||||
final DateFormat df = new SimpleDateFormat("YYYY\u5e74MM\u6708dd\u65e5");
|
||||
return df.format(d);
|
||||
}
|
||||
|
||||
public static String accurateToLogName() {
|
||||
final Date d = new Date();
|
||||
final DateFormat df = new SimpleDateFormat("YYYY_MM_dd");
|
||||
return df.format(d);
|
||||
}
|
||||
|
||||
public static Date getServerTime() {
|
||||
return new Date();
|
||||
}
|
||||
}
|
28
src/main/java/kohgylw/kiftd/server/util/TextFormateUtil.java
Normal file
28
src/main/java/kohgylw/kiftd/server/util/TextFormateUtil.java
Normal file
@ -0,0 +1,28 @@
|
||||
package kohgylw.kiftd.server.util;
|
||||
|
||||
import java.util.regex.*;
|
||||
|
||||
public class TextFormateUtil
|
||||
{
|
||||
private static TextFormateUtil tfu;
|
||||
|
||||
public static TextFormateUtil instance() {
|
||||
return TextFormateUtil.tfu;
|
||||
}
|
||||
|
||||
public boolean matcherFolderName(final String folderName) {
|
||||
final Pattern p = Pattern.compile("^[0-9a-zA-Z_\u4e00-\u9fff]+$");
|
||||
final Matcher m = p.matcher(folderName);
|
||||
return m.matches();
|
||||
}
|
||||
|
||||
public boolean matcherFileName(final String fileName) {
|
||||
final Pattern p = Pattern.compile("[|\\/*<> \"]+");
|
||||
final Matcher m = p.matcher(fileName);
|
||||
return !m.find();
|
||||
}
|
||||
|
||||
static {
|
||||
TextFormateUtil.tfu = new TextFormateUtil();
|
||||
}
|
||||
}
|
20
src/main/java/kohgylw/kiftd/ui/callback/GetServerStatus.java
Normal file
20
src/main/java/kohgylw/kiftd/ui/callback/GetServerStatus.java
Normal file
@ -0,0 +1,20 @@
|
||||
package kohgylw.kiftd.ui.callback;
|
||||
|
||||
import kohgylw.kiftd.server.enumeration.*;
|
||||
|
||||
public interface GetServerStatus
|
||||
{
|
||||
boolean getPropertiesStatus();
|
||||
|
||||
boolean getServerStatus();
|
||||
|
||||
int getPort();
|
||||
|
||||
int getBufferSize();
|
||||
|
||||
LogLevel getLogLevel();
|
||||
|
||||
String getFileSystemPath();
|
||||
|
||||
boolean getMustLogin();
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package kohgylw.kiftd.ui.callback;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public interface GetServerTime
|
||||
{
|
||||
Date get();
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package kohgylw.kiftd.ui.callback;
|
||||
|
||||
public interface OnCloseServer
|
||||
{
|
||||
boolean close();
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package kohgylw.kiftd.ui.callback;
|
||||
|
||||
public interface OnStartServer
|
||||
{
|
||||
boolean start();
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package kohgylw.kiftd.ui.callback;
|
||||
|
||||
import kohgylw.kiftd.server.pojo.*;
|
||||
|
||||
public interface UpdateSetting
|
||||
{
|
||||
boolean update(final ServerSetting s);
|
||||
}
|
385
src/main/java/kohgylw/kiftd/ui/module/ServerUIModule.java
Normal file
385
src/main/java/kohgylw/kiftd/ui/module/ServerUIModule.java
Normal file
@ -0,0 +1,385 @@
|
||||
package kohgylw.kiftd.ui.module;
|
||||
|
||||
import javax.imageio.*;
|
||||
import java.io.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.border.*;
|
||||
import java.awt.*;
|
||||
import javax.swing.event.*;
|
||||
import javax.swing.*;
|
||||
import java.text.*;
|
||||
import java.util.*;
|
||||
import kohgylw.kiftd.ui.callback.*;
|
||||
|
||||
public class ServerUIModule {
|
||||
protected static JFrame window;
|
||||
private static SystemTray tray;
|
||||
private static TrayIcon trayIcon;
|
||||
private static JTextArea output;
|
||||
private static ServerUIModule instance;
|
||||
private static SettingWindow sw;
|
||||
private static OnCloseServer cs;
|
||||
private static OnStartServer ss;
|
||||
private static GetServerStatus st;
|
||||
private static GetServerTime ti;
|
||||
private static JButton start;
|
||||
private static JButton stop;
|
||||
private static JButton resatrt;
|
||||
private static JButton setting;
|
||||
private static JButton exit;
|
||||
private static JLabel serverStatusLab;
|
||||
private static JLabel portStatusLab;
|
||||
private static JLabel logLevelLab;
|
||||
private static JLabel bufferSizeLab;
|
||||
private static final String S_STOP = "停止[Stopped]";
|
||||
private static final String S_START = "运行[Running]";
|
||||
private static final String S_STARTING = "启动中[Starting]...";
|
||||
private static final String S_STOPPING = "停止中[Stopping]...";
|
||||
protected static final String L_ALL = "记录全部(ALL)";
|
||||
protected static final String L_EXCEPTION = "仅异常(EXCEPTION)";
|
||||
protected static final String L_NONE = "不记录(NONE)";
|
||||
|
||||
private ServerUIModule() {
|
||||
(ServerUIModule.window = new JFrame("kiftd-服务器控制台")).setSize(300, 550);
|
||||
ServerUIModule.window.setLocation(100, 100);
|
||||
ServerUIModule.window.setResizable(false);
|
||||
try {
|
||||
ServerUIModule.window.setIconImage(
|
||||
ImageIO.read(this.getClass().getResourceAsStream("/kohgylw/kiftd/ui/resource/icon.png")));
|
||||
} catch (FileNotFoundException ex) {
|
||||
} catch (IOException ex2) {
|
||||
}
|
||||
if (SystemTray.isSupported()) {
|
||||
ServerUIModule.window.setDefaultCloseOperation(1);
|
||||
ServerUIModule.tray = SystemTray.getSystemTray();
|
||||
try {
|
||||
(ServerUIModule.trayIcon = new TrayIcon(
|
||||
ImageIO.read(this.getClass().getResourceAsStream("/kohgylw/kiftd/ui/resource/icon_tray.png"))))
|
||||
.setToolTip("青阳网络文件系统-kiftd");
|
||||
final PopupMenu pMenu = new PopupMenu();
|
||||
final MenuItem exit = new MenuItem("退出(Exit)");
|
||||
final MenuItem show = new MenuItem("显示主窗口(Show)");
|
||||
exit.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// TODO 自动生成的方法存根
|
||||
exit();
|
||||
}
|
||||
});
|
||||
show.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// TODO 自动生成的方法存根
|
||||
show();
|
||||
}
|
||||
});
|
||||
pMenu.add(exit);
|
||||
pMenu.addSeparator();
|
||||
pMenu.add(show);
|
||||
ServerUIModule.trayIcon.setPopupMenu(pMenu);
|
||||
ServerUIModule.tray.add(ServerUIModule.trayIcon);
|
||||
} catch (FileNotFoundException ex3) {
|
||||
} catch (IOException ex4) {
|
||||
} catch (AWTException ex5) {
|
||||
}
|
||||
} else {
|
||||
ServerUIModule.window.setDefaultCloseOperation(1);
|
||||
}
|
||||
ServerUIModule.window.setLayout(new BoxLayout(ServerUIModule.window.getContentPane(), 3));
|
||||
final JPanel titlebox = new JPanel(new FlowLayout(1));
|
||||
titlebox.setBorder(new EmptyBorder(0, 0, -25, 0));
|
||||
final JLabel title = new JLabel("kiftd");
|
||||
title.setFont(new Font("宋体", 1, 30));
|
||||
titlebox.add(title);
|
||||
ServerUIModule.window.add(titlebox);
|
||||
final JPanel subtitlebox = new JPanel(new FlowLayout(1));
|
||||
subtitlebox.setBorder(new EmptyBorder(0, 0, -20, 0));
|
||||
final JLabel subtitle = new JLabel("青阳网络文件系统-服务器");
|
||||
subtitle.setFont(new Font("宋体", 0, 13));
|
||||
subtitlebox.add(subtitle);
|
||||
ServerUIModule.window.add(subtitlebox);
|
||||
final JPanel statusBox = new JPanel(new GridLayout(4, 1));
|
||||
statusBox.setBorder(BorderFactory.createEtchedBorder());
|
||||
final JPanel serverStatus = new JPanel(new FlowLayout());
|
||||
serverStatus.setBorder(new EmptyBorder(0, 0, -8, 0));
|
||||
serverStatus.add(new JLabel("服务器状态(Status):"));
|
||||
serverStatus.add(ServerUIModule.serverStatusLab = new JLabel("--"));
|
||||
statusBox.add(serverStatus);
|
||||
final JPanel portStatus = new JPanel(new FlowLayout());
|
||||
portStatus.setBorder(new EmptyBorder(0, 0, -8, 0));
|
||||
portStatus.add(new JLabel("端口号(Port):"));
|
||||
portStatus.add(ServerUIModule.portStatusLab = new JLabel("--"));
|
||||
statusBox.add(portStatus);
|
||||
final JPanel addrStatus = new JPanel(new FlowLayout());
|
||||
addrStatus.setBorder(new EmptyBorder(0, 0, -8, 0));
|
||||
addrStatus.add(new JLabel("日志等级(LogLevel):"));
|
||||
addrStatus.add(ServerUIModule.logLevelLab = new JLabel("--"));
|
||||
statusBox.add(addrStatus);
|
||||
final JPanel bufferStatus = new JPanel(new FlowLayout());
|
||||
bufferStatus.setBorder(new EmptyBorder(0, 0, -8, 0));
|
||||
bufferStatus.add(new JLabel("下载缓冲区(Buffer):"));
|
||||
bufferStatus.add(ServerUIModule.bufferSizeLab = new JLabel("--"));
|
||||
statusBox.add(bufferStatus);
|
||||
ServerUIModule.window.add(statusBox);
|
||||
final JPanel buttonBox = new JPanel(new GridLayout(5, 1));
|
||||
buttonBox.add(ServerUIModule.start = new JButton("开启(Start)>>"));
|
||||
buttonBox.add(ServerUIModule.stop = new JButton("关闭(Stop)||"));
|
||||
buttonBox.add(ServerUIModule.resatrt = new JButton("重启(Restart)~>"));
|
||||
buttonBox.add(ServerUIModule.setting = new JButton("设置(Setting)[/]"));
|
||||
buttonBox.add(ServerUIModule.exit = new JButton("退出(Exit)[X]"));
|
||||
ServerUIModule.window.add(buttonBox);
|
||||
final JPanel outputBox = new JPanel(new FlowLayout(1));
|
||||
outputBox.add(new JLabel("[输出信息(Server Message)]:"));
|
||||
(ServerUIModule.output = new JTextArea(4, 23)).setLineWrap(true);
|
||||
ServerUIModule.output.setEditable(false);
|
||||
ServerUIModule.output.setForeground(Color.RED);
|
||||
ServerUIModule.output.getDocument().addDocumentListener(new DocumentListener() {
|
||||
|
||||
@Override
|
||||
public void removeUpdate(DocumentEvent e) {
|
||||
// TODO 自动生成的方法存根
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insertUpdate(DocumentEvent e) {
|
||||
// TODO 自动生成的方法存根
|
||||
Thread t = new Thread(() -> {
|
||||
if (output.getLineCount() >= 1000) {
|
||||
int end = 0;
|
||||
try {
|
||||
end = output.getLineEndOffset(100);
|
||||
} catch (Exception exc) {
|
||||
}
|
||||
output.replaceRange("", 0, end);
|
||||
}
|
||||
output.setCaretPosition(output.getText().length());
|
||||
});
|
||||
t.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changedUpdate(DocumentEvent e) {
|
||||
// TODO 自动生成的方法存根
|
||||
output.selectAll();
|
||||
output.setCaretPosition(output.getSelectedText().length());
|
||||
output.requestFocus();
|
||||
}
|
||||
});
|
||||
outputBox.add(new JScrollPane(ServerUIModule.output));
|
||||
ServerUIModule.window.add(outputBox);
|
||||
final JPanel bottombox = new JPanel(new FlowLayout(1));
|
||||
bottombox.setBorder(new EmptyBorder(0, 0, -30, 0));
|
||||
bottombox.add(new JLabel("--青阳龙野@kohgylw--"));
|
||||
ServerUIModule.window.add(bottombox);
|
||||
ServerUIModule.start.setEnabled(false);
|
||||
ServerUIModule.stop.setEnabled(false);
|
||||
ServerUIModule.resatrt.setEnabled(false);
|
||||
ServerUIModule.setting.setEnabled(false);
|
||||
ServerUIModule.start.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// TODO 自动生成的方法存根
|
||||
start.setEnabled(false);
|
||||
setting.setEnabled(false);
|
||||
printMessage("启动服务器...");
|
||||
if (ss != null) {
|
||||
serverStatusLab.setText(S_STARTING);
|
||||
Thread t = new Thread(() -> {
|
||||
if (ss.start()) {
|
||||
printMessage("启动完成。正在检查服务器状态...");
|
||||
if (st.getServerStatus()) {
|
||||
printMessage("KIFT服务器已经启动,可以正常访问了。");
|
||||
} else {
|
||||
printMessage("KIFT服务器未能成功启动,请检查设置或查看异常信息。");
|
||||
}
|
||||
} else {
|
||||
printMessage("KIFT无法启动,请检查设置。");
|
||||
serverStatusLab.setText(S_STOP);
|
||||
}
|
||||
updateServerStatus();
|
||||
});
|
||||
t.start();
|
||||
}
|
||||
}
|
||||
});
|
||||
ServerUIModule.stop.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// TODO 自动生成的方法存根
|
||||
stop.setEnabled(false);
|
||||
resatrt.setEnabled(false);
|
||||
printMessage("关闭服务器...");
|
||||
Thread t = new Thread(() -> {
|
||||
if (cs != null) {
|
||||
serverStatusLab.setText(S_STOPPING);
|
||||
if (cs.close()) {
|
||||
printMessage("关闭完成。正在检查服务器状态...");
|
||||
if (st.getServerStatus()) {
|
||||
printMessage("KIFT服务器未能成功关闭,如有需要,可以强制关闭程序(不安全)。");
|
||||
} else {
|
||||
printMessage("KIFT服务器已经关闭,停止所有访问。");
|
||||
}
|
||||
} else {
|
||||
printMessage("KIFT服务器无法关闭,请手动结束本程序。");
|
||||
}
|
||||
updateServerStatus();
|
||||
}
|
||||
});
|
||||
t.start();
|
||||
}
|
||||
});
|
||||
ServerUIModule.exit.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// TODO 自动生成的方法存根
|
||||
exit();
|
||||
}
|
||||
});
|
||||
ServerUIModule.resatrt.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// TODO 自动生成的方法存根
|
||||
Thread t = new Thread(() -> {
|
||||
printMessage("正在重启服务器...");
|
||||
if (cs.close()) {
|
||||
if (ss.start()) {
|
||||
printMessage("重启成功,可以正常访问了。");
|
||||
} else {
|
||||
printMessage("错误:服务器已关闭但未能重新启动,请尝试手动启动服务器。");
|
||||
}
|
||||
} else {
|
||||
printMessage("错误:无法关闭服务器,请尝试手动关闭。");
|
||||
}
|
||||
});
|
||||
t.start();
|
||||
}
|
||||
});
|
||||
ServerUIModule.sw = SettingWindow.getInstance();
|
||||
ServerUIModule.setting.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// TODO 自动生成的方法存根
|
||||
Thread t = new Thread(() -> {
|
||||
sw.show();
|
||||
});
|
||||
t.start();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void show() {
|
||||
ServerUIModule.window.setVisible(true);
|
||||
}
|
||||
|
||||
public static void setOnCloseServer(final OnCloseServer cs) {
|
||||
ServerUIModule.cs = cs;
|
||||
}
|
||||
|
||||
public static ServerUIModule getInsatnce() {
|
||||
if (ServerUIModule.instance == null) {
|
||||
ServerUIModule.instance = new ServerUIModule();
|
||||
}
|
||||
return ServerUIModule.instance;
|
||||
}
|
||||
|
||||
public static void setStartServer(final OnStartServer ss) {
|
||||
ServerUIModule.ss = ss;
|
||||
}
|
||||
|
||||
public static void setGetServerStatus(final GetServerStatus st) {
|
||||
ServerUIModule.st = st;
|
||||
SettingWindow.st = st;
|
||||
}
|
||||
|
||||
public void updateServerStatus() {
|
||||
final Thread t = new Thread(() -> {
|
||||
if (ServerUIModule.st != null) {
|
||||
if (ServerUIModule.st.getServerStatus()) {
|
||||
ServerUIModule.serverStatusLab.setText(S_START);
|
||||
ServerUIModule.start.setEnabled(false);
|
||||
ServerUIModule.stop.setEnabled(true);
|
||||
ServerUIModule.resatrt.setEnabled(true);
|
||||
ServerUIModule.setting.setEnabled(false);
|
||||
} else {
|
||||
ServerUIModule.serverStatusLab.setText("停止[Stopped]");
|
||||
if (ServerUIModule.st.getPropertiesStatus()) {
|
||||
ServerUIModule.start.setEnabled(true);
|
||||
}
|
||||
ServerUIModule.stop.setEnabled(false);
|
||||
ServerUIModule.resatrt.setEnabled(false);
|
||||
ServerUIModule.setting.setEnabled(true);
|
||||
}
|
||||
ServerUIModule.portStatusLab.setText(ServerUIModule.st.getPort() + "");
|
||||
switch (st.getLogLevel()) {
|
||||
case Event: {
|
||||
ServerUIModule.logLevelLab.setText(L_ALL);
|
||||
break;
|
||||
}
|
||||
case None: {
|
||||
ServerUIModule.logLevelLab.setText(L_NONE);
|
||||
break;
|
||||
}
|
||||
case Runtime_Exception: {
|
||||
ServerUIModule.logLevelLab.setText(L_EXCEPTION);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
ServerUIModule.logLevelLab.setText("无法获取(?)");
|
||||
break;
|
||||
}
|
||||
}
|
||||
ServerUIModule.bufferSizeLab.setText(ServerUIModule.st.getBufferSize() / 1024 + " KB");
|
||||
}
|
||||
return;
|
||||
});
|
||||
t.start();
|
||||
}
|
||||
|
||||
private void exit() {
|
||||
ServerUIModule.start.setEnabled(false);
|
||||
ServerUIModule.stop.setEnabled(false);
|
||||
ServerUIModule.exit.setEnabled(false);
|
||||
ServerUIModule.resatrt.setEnabled(false);
|
||||
ServerUIModule.setting.setEnabled(false);
|
||||
this.printMessage("退出程序...");
|
||||
if (ServerUIModule.cs != null) {
|
||||
final Thread t = new Thread(() -> {
|
||||
if (ServerUIModule.st.getServerStatus()) {
|
||||
ServerUIModule.cs.close();
|
||||
}
|
||||
System.exit(0);
|
||||
return;
|
||||
});
|
||||
t.start();
|
||||
} else {
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
public void printMessage(final String context) {
|
||||
ServerUIModule.output.append("[" + this.getFormateDate() + "]" + context + "\n");
|
||||
}
|
||||
|
||||
private String getFormateDate() {
|
||||
if (ServerUIModule.ti != null) {
|
||||
final Date d = ServerUIModule.ti.get();
|
||||
return new SimpleDateFormat("YYYY-MM-dd hh:mm:ss").format(d);
|
||||
}
|
||||
return new SimpleDateFormat("YYYY-MM-dd hh:mm:ss").format(new Date());
|
||||
}
|
||||
|
||||
public static void setGetServerTime(final GetServerTime ti) {
|
||||
ServerUIModule.ti = ti;
|
||||
}
|
||||
|
||||
public static void setUpdateSetting(final UpdateSetting us) {
|
||||
SettingWindow.us = us;
|
||||
}
|
||||
}
|
219
src/main/java/kohgylw/kiftd/ui/module/SettingWindow.java
Normal file
219
src/main/java/kohgylw/kiftd/ui/module/SettingWindow.java
Normal file
@ -0,0 +1,219 @@
|
||||
package kohgylw.kiftd.ui.module;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import kohgylw.kiftd.server.enumeration.LogLevel;
|
||||
import kohgylw.kiftd.server.pojo.ServerSetting;
|
||||
import kohgylw.kiftd.ui.callback.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
public class SettingWindow {
|
||||
private static JDialog window;
|
||||
private static JTextField portinput;
|
||||
private static JTextField bufferinput;
|
||||
private static JComboBox<String> mlinput;
|
||||
private static JComboBox<String> logLevelinput;
|
||||
private static JButton cancel;
|
||||
private static JButton update;
|
||||
private static JButton changeFileSystemPath;
|
||||
private static JFileChooser changeFileSystemPathChooser;
|
||||
private static File chooserPath;
|
||||
private static SettingWindow sw;
|
||||
private static final String ML_OPEN = "是(YES)";
|
||||
private static final String ML_CLOSE = "否(CLOSE)";
|
||||
protected static GetServerStatus st;
|
||||
protected static UpdateSetting us;
|
||||
|
||||
private SettingWindow() {
|
||||
(SettingWindow.window = new JDialog(ServerUIModule.window, "kiftd-设置")).setModal(true);
|
||||
SettingWindow.window.setSize(400, 320);
|
||||
SettingWindow.window.setLocation(150, 150);
|
||||
SettingWindow.window.setDefaultCloseOperation(1);
|
||||
SettingWindow.window.setResizable(false);
|
||||
SettingWindow.window.setLayout(new BoxLayout(SettingWindow.window.getContentPane(), 3));
|
||||
final JPanel titlebox = new JPanel(new FlowLayout(1));
|
||||
titlebox.setBorder(new EmptyBorder(0, 0, -15, 0));
|
||||
final JLabel title = new JLabel("服务器设置 Server Setting");
|
||||
title.setFont(new Font("宋体", 1, 20));
|
||||
titlebox.add(title);
|
||||
SettingWindow.window.add(titlebox);
|
||||
final JPanel settingbox = new JPanel(new GridLayout(5, 1));
|
||||
settingbox.setBorder(new EtchedBorder());
|
||||
final JPanel mlbox = new JPanel(new FlowLayout(1));
|
||||
mlbox.setBorder(new EmptyBorder(0, 0, -5, 0));
|
||||
final JLabel mltitle = new JLabel("必须登入(must login):");
|
||||
(SettingWindow.mlinput = new JComboBox<String>()).addItem(ML_OPEN);
|
||||
SettingWindow.mlinput.addItem(ML_CLOSE);
|
||||
SettingWindow.mlinput.setPreferredSize(new Dimension(170, 20));
|
||||
mlbox.add(mltitle);
|
||||
mlbox.add(SettingWindow.mlinput);
|
||||
final JPanel portbox = new JPanel(new FlowLayout(1));
|
||||
portbox.setBorder(new EmptyBorder(0, 0, -20, 0));
|
||||
final JLabel porttitle = new JLabel("端口(port):");
|
||||
(SettingWindow.portinput = new JTextField()).setPreferredSize(new Dimension(100, 25));
|
||||
portbox.add(porttitle);
|
||||
portbox.add(SettingWindow.portinput);
|
||||
final JPanel bufferbox = new JPanel(new FlowLayout(1));
|
||||
bufferbox.setBorder(new EmptyBorder(0, 0, -20, 0));
|
||||
final JLabel buffertitle = new JLabel("缓存大小(buffer):");
|
||||
(SettingWindow.bufferinput = new JTextField()).setPreferredSize(new Dimension(170, 25));
|
||||
final JLabel bufferUnit = new JLabel("KB");
|
||||
bufferbox.add(buffertitle);
|
||||
bufferbox.add(SettingWindow.bufferinput);
|
||||
bufferbox.add(bufferUnit);
|
||||
final JPanel logbox = new JPanel(new FlowLayout(1));
|
||||
logbox.setBorder(new EmptyBorder(0, 0, -20, 0));
|
||||
final JLabel logtitle = new JLabel("日志等级(port):");
|
||||
(SettingWindow.logLevelinput = new JComboBox<String>()).addItem("记录全部(ALL)");
|
||||
SettingWindow.logLevelinput.addItem("仅异常(EXCEPTION)");
|
||||
SettingWindow.logLevelinput.addItem("不记录(NONE)");
|
||||
SettingWindow.logLevelinput.setPreferredSize(new Dimension(170, 20));
|
||||
logbox.add(logtitle);
|
||||
logbox.add(SettingWindow.logLevelinput);
|
||||
final JPanel filePathBox = new JPanel(new FlowLayout(1));
|
||||
filePathBox.setBorder(new EmptyBorder(0, 0, -20, 0));
|
||||
final JLabel filePathtitle = new JLabel("文件系统路径(file system path):");
|
||||
SettingWindow.changeFileSystemPath = new JButton("选择(Choose)");
|
||||
filePathBox.add(filePathtitle);
|
||||
filePathBox.add(SettingWindow.changeFileSystemPath);
|
||||
settingbox.add(portbox);
|
||||
settingbox.add(mlbox);
|
||||
settingbox.add(bufferbox);
|
||||
settingbox.add(logbox);
|
||||
settingbox.add(filePathBox);
|
||||
SettingWindow.window.add(settingbox);
|
||||
final JPanel buttonbox = new JPanel(new FlowLayout(1));
|
||||
buttonbox.setBorder(new EmptyBorder(0, 0, -20, 0));
|
||||
SettingWindow.update = new JButton("应用(Update)");
|
||||
SettingWindow.cancel = new JButton("取消(Cancel)");
|
||||
buttonbox.add(SettingWindow.update);
|
||||
buttonbox.add(SettingWindow.cancel);
|
||||
SettingWindow.window.add(buttonbox);
|
||||
changeFileSystemPathChooser = new JFileChooser();
|
||||
changeFileSystemPathChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
||||
SettingWindow.cancel.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// TODO 自动生成的方法存根
|
||||
window.setVisible(false);
|
||||
}
|
||||
});
|
||||
SettingWindow.update.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// TODO 自动生成的方法存根
|
||||
// 仅在服务器停止时才可以进行修改
|
||||
if (st.getServerStatus()) {
|
||||
getServerStatus();
|
||||
} else {
|
||||
Thread t = new Thread(() -> {
|
||||
if (us != null) {
|
||||
try {
|
||||
ServerSetting ss = new ServerSetting();
|
||||
ss.setPort(Integer.parseInt(portinput.getText()));
|
||||
ss.setBuffSize(Integer.parseInt(bufferinput.getText()));
|
||||
if (chooserPath.isDirectory()) {
|
||||
ss.setFsPath(chooserPath.getAbsolutePath());
|
||||
}
|
||||
switch (logLevelinput.getSelectedIndex()) {
|
||||
case 0:
|
||||
ss.setLog(LogLevel.Event);
|
||||
break;
|
||||
case 1:
|
||||
ss.setLog(LogLevel.Runtime_Exception);
|
||||
break;
|
||||
case 2:
|
||||
ss.setLog(LogLevel.None);
|
||||
break;
|
||||
|
||||
default:
|
||||
// 注意,当选择未知的日志等级时,不做任何操作
|
||||
break;
|
||||
}
|
||||
switch (mlinput.getSelectedIndex()) {
|
||||
case 0:
|
||||
ss.setMustLogin(true);
|
||||
break;
|
||||
case 1:
|
||||
ss.setMustLogin(false);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (us.update(ss)) {
|
||||
ServerUIModule.getInsatnce().updateServerStatus();
|
||||
window.setVisible(false);
|
||||
}
|
||||
} catch (Exception exc) {
|
||||
|
||||
}
|
||||
} else {
|
||||
window.setVisible(false);
|
||||
}
|
||||
});
|
||||
t.start();
|
||||
}
|
||||
}
|
||||
});
|
||||
SettingWindow.changeFileSystemPath.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// TODO 自动生成的方法存根
|
||||
if (changeFileSystemPathChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
|
||||
chooserPath = changeFileSystemPathChooser.getSelectedFile();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void show() {
|
||||
this.getServerStatus();
|
||||
SettingWindow.window.setVisible(true);
|
||||
}
|
||||
|
||||
private void getServerStatus() {
|
||||
final Thread t = new Thread(() -> {
|
||||
if (SettingWindow.st != null) {
|
||||
SettingWindow.bufferinput.setText(SettingWindow.st.getBufferSize() / 1024 + "");
|
||||
SettingWindow.portinput.setText(SettingWindow.st.getPort() + "");
|
||||
File fsp = new File(SettingWindow.st.getFileSystemPath());
|
||||
if (fsp.isDirectory()) {
|
||||
changeFileSystemPathChooser.setSelectedFile(fsp);
|
||||
}
|
||||
switch (st.getLogLevel()) {
|
||||
case Event: {
|
||||
SettingWindow.logLevelinput.setSelectedIndex(0);
|
||||
break;
|
||||
}
|
||||
case Runtime_Exception: {
|
||||
SettingWindow.logLevelinput.setSelectedIndex(1);
|
||||
break;
|
||||
}
|
||||
case None: {
|
||||
SettingWindow.logLevelinput.setSelectedIndex(2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (SettingWindow.st.getMustLogin()) {
|
||||
SettingWindow.mlinput.setSelectedIndex(0);
|
||||
} else {
|
||||
SettingWindow.mlinput.setSelectedIndex(1);
|
||||
}
|
||||
}
|
||||
return;
|
||||
});
|
||||
t.start();
|
||||
}
|
||||
|
||||
protected static SettingWindow getInstance() {
|
||||
if (SettingWindow.sw == null) {
|
||||
SettingWindow.sw = new SettingWindow();
|
||||
}
|
||||
return SettingWindow.sw;
|
||||
}
|
||||
}
|
BIN
src/main/java/kohgylw/kiftd/ui/resource/icon.png
Normal file
BIN
src/main/java/kohgylw/kiftd/ui/resource/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
BIN
src/main/java/kohgylw/kiftd/ui/resource/icon_tray.png
Normal file
BIN
src/main/java/kohgylw/kiftd/ui/resource/icon_tray.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 428 B |
9
target/classes/META-INF/MANIFEST.MF
Normal file
9
target/classes/META-INF/MANIFEST.MF
Normal file
@ -0,0 +1,9 @@
|
||||
Manifest-Version: 1.0
|
||||
Implementation-Title: kiftd
|
||||
Implementation-Version: 1.0.2-SNAPSHOT
|
||||
Built-By: kohgylw
|
||||
Implementation-Vendor-Id: kohgylw
|
||||
Build-Jdk: 1.8.0_131
|
||||
Implementation-URL: http://maven.apache.org
|
||||
Created-By: Maven Integration for Eclipse
|
||||
|
@ -0,0 +1,7 @@
|
||||
#Generated by Maven Integration for Eclipse
|
||||
#Mon Jul 30 10:01:53 CST 2018
|
||||
version=1.0.2-SNAPSHOT
|
||||
groupId=kohgylw
|
||||
m2e.projectName=kiftd
|
||||
m2e.projectLocation=/Users/kohgylw/program/java-workspace/kiftd
|
||||
artifactId=kiftd
|
98
target/classes/META-INF/maven/kohgylw/kiftd/pom.xml
Normal file
98
target/classes/META-INF/maven/kohgylw/kiftd/pom.xml
Normal file
@ -0,0 +1,98 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>kohgylw</groupId>
|
||||
<artifactId>kiftd</artifactId>
|
||||
<version>1.0.2-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>kiftd</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<!-- Spring Boot 版本组设置 -->
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.0.2.RELEASE</version>
|
||||
</parent>
|
||||
<!-- end SpringBoot版本组 -->
|
||||
|
||||
<!-- 外部资源 -->
|
||||
<dependencies>
|
||||
<!-- SpringBoot web启动器 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<!-- end 启动器 -->
|
||||
|
||||
<!-- Gson json转化工具 -->
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
</dependency>
|
||||
<!-- end Gson -->
|
||||
|
||||
<!-- file 操作资源 -->
|
||||
<dependency>
|
||||
<groupId>commons-fileupload</groupId>
|
||||
<artifactId>commons-fileupload</artifactId>
|
||||
<version>1.3.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.4</version>
|
||||
</dependency>
|
||||
<!-- end file -->
|
||||
|
||||
<!-- h2内嵌数据库 + spring +mybatis -->
|
||||
<dependency>
|
||||
<groupId>org.mybatis</groupId>
|
||||
<artifactId>mybatis</artifactId>
|
||||
<version>3.4.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mybatis</groupId>
|
||||
<artifactId>mybatis-spring</artifactId>
|
||||
<version>1.3.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-jdbc</artifactId>
|
||||
</dependency>
|
||||
<!-- end hsm整合 -->
|
||||
|
||||
<!-- ZIP 压缩工具 -->
|
||||
<!-- https://mvnrepository.com/artifact/org.zeroturnaround/zt-zip -->
|
||||
<dependency>
|
||||
<groupId>org.zeroturnaround</groupId>
|
||||
<artifactId>zt-zip</artifactId>
|
||||
<version>1.13</version>
|
||||
</dependency>
|
||||
<!-- end ZIP -->
|
||||
|
||||
</dependencies>
|
||||
<!-- end 外部资源 -->
|
||||
|
||||
<!-- 打包工具配置 -->
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<!-- end 打包工具 -->
|
||||
|
||||
</project>
|
BIN
target/classes/kohgylw/kiftd/mc/ConsoleRunner.class
Normal file
BIN
target/classes/kohgylw/kiftd/mc/ConsoleRunner.class
Normal file
Binary file not shown.
BIN
target/classes/kohgylw/kiftd/mc/MC.class
Normal file
BIN
target/classes/kohgylw/kiftd/mc/MC.class
Normal file
Binary file not shown.
BIN
target/classes/kohgylw/kiftd/mc/UIRunner$1.class
Normal file
BIN
target/classes/kohgylw/kiftd/mc/UIRunner$1.class
Normal file
Binary file not shown.
BIN
target/classes/kohgylw/kiftd/mc/UIRunner.class
Normal file
BIN
target/classes/kohgylw/kiftd/mc/UIRunner.class
Normal file
Binary file not shown.
BIN
target/classes/kohgylw/kiftd/printer/Printer.class
Normal file
BIN
target/classes/kohgylw/kiftd/printer/Printer.class
Normal file
Binary file not shown.
BIN
target/classes/kohgylw/kiftd/server/configation/DataAccess.class
Normal file
BIN
target/classes/kohgylw/kiftd/server/configation/DataAccess.class
Normal file
Binary file not shown.
BIN
target/classes/kohgylw/kiftd/server/configation/MVC.class
Normal file
BIN
target/classes/kohgylw/kiftd/server/configation/MVC.class
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
target/classes/kohgylw/kiftd/server/ctl/KiftdCtl.class
Normal file
BIN
target/classes/kohgylw/kiftd/server/ctl/KiftdCtl.class
Normal file
Binary file not shown.
Binary file not shown.
BIN
target/classes/kohgylw/kiftd/server/enumeration/LogLevel.class
Normal file
BIN
target/classes/kohgylw/kiftd/server/enumeration/LogLevel.class
Normal file
Binary file not shown.
BIN
target/classes/kohgylw/kiftd/server/filter/MastLoginFilter.class
Normal file
BIN
target/classes/kohgylw/kiftd/server/filter/MastLoginFilter.class
Normal file
Binary file not shown.
BIN
target/classes/kohgylw/kiftd/server/filter/VCFilter.class
Normal file
BIN
target/classes/kohgylw/kiftd/server/filter/VCFilter.class
Normal file
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user