0.0.1-SNAPSHOT
wangbing 5 years ago
parent c0017343e9
commit 7c07a55bad

@ -8,32 +8,28 @@ import com.example.frame.utils.*;
import com.example.module.admin.ent.NginxCtrl;
import com.example.module.admin.ent.Service;
import com.example.module.admin.mgr.MappingManager;
import com.example.module.admin.req.MappingCreateRequest;
import com.example.module.admin.req.MappingDeleteRequest;
import com.example.module.admin.req.MappingFindRequest;
import com.example.module.admin.req.MappingUpdateRequest;
import com.example.module.admin.req.*;
import com.example.module.admin.rsp.LoginResponse;
import com.example.module.admin.rsp.MappingFindResponse;
import com.example.module.admin.rsp.PortLoadResponse;
import freemarker.cache.ClassTemplateLoader;
import freemarker.cache.MultiTemplateLoader;
import freemarker.cache.TemplateLoader;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import freemarker.template.TemplateExceptionHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.util.ClassUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
import xyz.wbsite.wsqlite.ObjectClient;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
@ -48,6 +44,10 @@ public class AjaxController {
private ObjectClient objectClient;
@Autowired
private FreeMarkerConfigurer freeMarkerConfigurer;
@Value("${admin.username}")
private String username;
@Value("${admin.password}")
private String password;
@RequestMapping("/ajax")
@ResponseBody
@ -74,8 +74,8 @@ public class AjaxController {
jsonString = in.readLine();
switch (method) {
// 示例
case "ajax.example.example":
case "ajax.login":
baseResponse = login(jsonString, token);
break;
case "nginx.start":
baseResponse = nginxStart(jsonString, token);
@ -89,22 +89,25 @@ public class AjaxController {
// 创建映射
case "ajax.admin.mapping.create":
baseResponse = createMapping(jsonString, token);
flushConfig();
break;
// 删除映射
case "ajax.admin.mapping.delete":
baseResponse = deleteMapping(jsonString, token);
flushConfig();
break;
// 修改映射
case "ajax.admin.mapping.update":
baseResponse = updateMapping(jsonString, token);
flushConfig();
break;
// 查询映射
case "ajax.admin.mapping.find":
baseResponse = findMapping(jsonString, token);
break;
case "ajax.admin.port.load":
case "ajax.admin.service.load":
baseResponse = loadPort(jsonString, token);
break;
case "ajax.admin.config.flush":
flushConfig();
baseResponse = new BaseResponse();
break;
default:
baseResponse.addError(ErrorType.INVALID_PARAMETER, Message.NOT_EXIST_METHOD);
break;
@ -122,6 +125,29 @@ public class AjaxController {
return baseResponse;
}
private BaseResponse login(String jsonString, Token token) {
LoginRequest loginRequest = MapperUtil.toJava(jsonString, LoginRequest.class);
LoginResponse loginResponse = new LoginResponse();
ValidationUtil.validate(loginRequest, loginResponse);
if (loginResponse.hasError()) {
return loginResponse;
}
if (!loginRequest.getUsername().endsWith(username)) {
loginResponse.addError(ErrorType.BUSINESS_ERROR, "用户不存在!");
return loginResponse;
}
if (!loginRequest.getPassword().endsWith(password)) {
loginResponse.addError(ErrorType.BUSINESS_ERROR, "密码错误!");
return loginResponse;
}
String yyyyMMdd = new SimpleDateFormat("yyyyMMdd").format(new Date());
String encode = MD5Util.encode(yyyyMMdd + username + password);
LocalData.getResponse().addCookie(new Cookie("token", encode));
return loginResponse;
}
private BaseResponse nginxStart(String jsonString, Token token) {
BaseResponse baseResponse = new BaseResponse();
if (nginxCtrl.isRunning()) {
@ -142,7 +168,7 @@ public class AjaxController {
return baseResponse;
}
private BaseResponse nginxReload(String jsonString, Token token) {
private synchronized BaseResponse nginxReload(String jsonString, Token token) {
BaseResponse baseResponse = new BaseResponse();
if (!nginxCtrl.isRunning()) {
baseResponse.addError(ErrorType.BUSINESS_ERROR, "程序尚未运行");
@ -194,7 +220,7 @@ public class AjaxController {
for (Service service : select) {
MappingFindRequest mappingFindRequest = new MappingFindRequest();
mappingFindRequest.setPortId(service.getId());
mappingFindRequest.setServiceId(service.getId());
mappingFindRequest.setPageSize(0);
MappingFindResponse mappingFindResponse = mappingManager.find(mappingFindRequest, token);
if (mappingFindResponse.hasError()) {
@ -212,14 +238,14 @@ public class AjaxController {
return response;
}
private void flushConfig() {
private synchronized void flushConfig() {
Writer wr = null;
try {
File config = nginxCtrl.getConfig();
HashMap<String, Object> context = new HashMap<>();
PortLoadResponse portLoadResponse = (PortLoadResponse) loadPort("", LocalData.getSysToken());
context.put("services",portLoadResponse.getResult());
context.put("services", portLoadResponse.getResult());
Template template = freeMarkerConfigurer.getConfiguration().getTemplate("nginx.conf.ftl");
wr = new OutputStreamWriter(new FileOutputStream(config), "UTF-8");
//写入

@ -43,7 +43,7 @@ public class NginxConfig {
nginxHome = new File(jarFile.getParent(), "nginx");
if (!nginxHome.exists()) {
ClassPathResource classPathResource = new ClassPathResource("nginx-1.14.2.zip");
ClassPathResource classPathResource = new ClassPathResource("nginx-1.16.1.zip");
try {
InputStream inputStream = classPathResource.getInputStream();
File nginxDir = new File(jarFile.getParent(), "nginx");

@ -1,5 +1,6 @@
package com.example.config;
import com.example.frame.utils.MD5Util;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -12,7 +13,11 @@ import org.springframework.security.core.Authentication;
import com.example.frame.base.Token;
import com.example.frame.utils.CookieUtil;
import com.example.frame.utils.LocalData;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.Date;
@Configuration
@EnableGlobalMethodSecurity(securedEnabled = true)
@ -21,6 +26,10 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
private String[] excluded;
@Value("${spring.mvc.static-path-pattern}")
private String[] staticPath;
@Value("${admin.username}")
private String username;
@Value("${admin.password}")
private String password;
@Override
protected void configure(HttpSecurity http) throws Exception {
@ -36,7 +45,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
/**
*
*
* <p>
* Using generated security password: f6b42a66-71b1-4c31-b6a8-942838c81408
*
* @return
@ -54,25 +63,38 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
// 获取Token
String token = request.getParameter("token");
if (token == null || token.isEmpty()){
if (token == null || token.isEmpty()) {
token = CookieUtil.getCookieValue(request.getCookies(), "token");
}
String yyyyMMdd = new SimpleDateFormat("yyyyMMdd").format(new Date());
String encode = MD5Util.encode(yyyyMMdd + username + password);
if (token == null) {
LocalData.setToken(LocalData.getTempToken());
}else {
// 组装Token ~ 这边根据实际的业务组装Token
} else if (!encode.equals(token)) {
LocalData.setToken(LocalData.getTempToken());
} else {
Token token1 = new Token();
token1.setId(1L);
token1.setUserId(1L);
token1.setUserName("admin");
//继承临时Token
token1.addResourceSet(LocalData.getTempToken());
//管理员特有资源(这边请用正则表达式)
token1.putResource("/admin/.*\\.htm");
token1.setUserName(username);
token1.putResource("/");
token1.putResource("/mapping.htm");
token1.putResource("/sse/.*");
token1.putResource("/ajax");
token1.putResource("ajax.login");
token1.putResource("nginx.start");
token1.putResource("nginx.stop");
token1.putResource("nginx.reload");
token1.putResource("ajax.admin.mapping.create");
token1.putResource("ajax.admin.mapping.delete");
token1.putResource("ajax.admin.mapping.update");
token1.putResource("ajax.admin.service.load");
token1.putResource("ajax.admin.config.flush");
LocalData.setToken(token1);
}
String servletPath = request.getServletPath();
// 授权
Token token_ = LocalData.getToken();
if (token_.hasResource(request.getServletPath())) {

@ -28,13 +28,9 @@ public class LocalData {
temp.setId(-1);
temp.setUserId(-1);
temp.setUserName("游客");
temp.putResource("/");
temp.putResource("/login.htm");
temp.putResource("/ajax");
temp.putResource("/upload");
temp.putResource("/index.htm");
temp.putResource("/home.htm");
temp.putResource("/app.htm");
temp.putResource(".*");
temp.putResource("ajax.login");
system = new Token();
system.setId(0);
system.setUserId(0);

@ -30,6 +30,8 @@ public class Mapping {
@TableField
private String context;
@TableField
private String type;
@TableField
private String location;
@TableField
private String bz;
@ -38,6 +40,14 @@ public class Mapping {
@TableField
private boolean isDeleted;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public Long getServiceId() {
return serviceId;
}

@ -51,6 +51,20 @@ public class MappingManagerImpl implements MappingManager {
return response;
}
try {
Mapping where = new Mapping();
where.setContext(request.getContext());
List<Mapping> select = objectClient.select(Mapping.class, 1, 0, "SERVICEID = " + request.getServiceId()+" AND CONTEXT =" +request.getContext());
if (select.size() > 0) {
}
} catch (SQLException | ClassNotFoundException e) {
response.addError(ErrorType.BUSINESS_ERROR, "Sqlite错误");
return response;
}
long id = IDgenerator.nextId();
Mapping entity = MapperUtil.map(request, Mapping.class);
entity.setId(id);
@ -139,7 +153,7 @@ public class MappingManagerImpl implements MappingManager {
}
try {
List<Mapping> select = objectClient.select(Mapping.class, 1, 0);
List<Mapping> select = objectClient.select(Mapping.class, 1, 0, "SERVICEID=" + request.getServiceId());
response.setResult(select);
} catch (SQLException | ClassNotFoundException e) {
e.printStackTrace();

@ -0,0 +1,38 @@
package com.example.module.admin.req;
import com.example.frame.base.BaseRequest;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
/**
* MappingCreateRequest -
*
* @author author
* @version 0.0.1
* @since 2019-09-28
*/
public class LoginRequest extends BaseRequest {
@NotNull(message = "用户名不能为空")
private String username;
@NotNull(message = "密码不能为空")
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}

@ -18,29 +18,22 @@ import xyz.wbsite.wsqlite.anonation.TableField;
*/
public class MappingCreateRequest extends BaseRequest {
/**
* NAME -
*/
@NotNull(message = "映射名称不能为空")
private String name;
@NotNull(message = "服务Id不能为空")
private Long serviceId;
/**
* VALUE -
*/
@NotNull(message = "映射值不能为空")
@Pattern(regexp = "[^/]*", message = "映射值不能存在/")
@Pattern(regexp = "\\w*", message = "映射值需为英文")
@NotNull(message = "映射路径不能为空")
@Pattern(regexp = "^/[a-zA-Z][a-zA-Z0-9_-]*$|^[A-Z]:/.*$|^/$", message = "映射路径须是(/)或(/+字母+字母数字及_")
private String context;
@TableField
@NotNull(message = "映射类型不能为空")
private String type;
@NotNull(message = "映射地址不能为空")
private String location;
/**
* BZ -
*/
private String bz;
public Long getServiceId() {
@ -63,6 +56,14 @@ public class MappingCreateRequest extends BaseRequest {
return context;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public void setContext(String context) {
this.context = context;
}

@ -14,13 +14,13 @@ public class MappingFindRequest extends BaseFindRequest {
/**
*
*/
private Long portId;
private Long serviceId;
public Long getPortId() {
return portId;
public Long getServiceId() {
return serviceId;
}
public void setPortId(Long portId) {
this.portId = portId;
public void setServiceId(Long serviceId) {
this.serviceId = serviceId;
}
}

@ -19,37 +19,35 @@ import javax.validation.constraints.Pattern;
*/
public class MappingUpdateRequest extends BaseUpdateRequest {
/**
*
*/
@NotNull(message = "主键不能为NULL")
private Long id;
@NotNull(message = "服务Id不能为空")
private Long serviceId;
/**
* NAME -
*/
@NotNull(message = "映射名称不能为空")
private String name;
/**
* VALUE -
*/
@NotNull(message = "映射值不能为空")
@Pattern(regexp = "[^/]*", message = "映射值不能存在/")
@Pattern(regexp = "\\w*", message = "映射值需为英文")
@NotNull(message = "映射路径不能为空")
@Pattern(regexp = "^/[a-zA-Z][a-zA-Z0-9_-]*$|^[A-Z]:/.*$|^/$", message = "映射路径须是(/)或(/+字母+字母数字及_")
private String context;
@TableField
@NotNull(message = "映射类型不能为空")
private String type;
@NotNull(message = "映射地址不能为空")
private String location;
/**
* BZ -
*/
private String bz;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getName() {
return name;
}

@ -0,0 +1,9 @@
package com.example.module.admin.rsp;
import com.example.frame.base.BaseResponse;
public class LoginResponse extends BaseResponse {
}

@ -12,9 +12,9 @@ spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
server.tomcat.uri-encoding=UTF-8
# 根路径、欢迎页
web.welcome.page=/index.htm
web.welcome.page=/mapping.htm
# 不需要验证授权, 或该请求有自己的验证机制
web.url.auth.excluded=/favicon.ico,/static/**,/api,/login.htm,/mapping.htm,/sse/**
web.url.auth.excluded=/favicon.ico,/static/**,/api,/login.htm,/sse/**
# 日志配置
logging.path=D://
logging.levels=DEBUG
@ -48,4 +48,6 @@ spring.servlet.multipart.resolveLazily=false
spring.servlet.multipart.max-file-size=100MB
spring.servlet.multipart.max-request-size=100MB
dbpath=
nginx-path=
nginx-path=
admin.username=admin
admin.password=admin

@ -12,7 +12,7 @@ spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
server.tomcat.uri-encoding=UTF-8
# 根路径、欢迎页
web.welcome.page=/index.htm
web.welcome.page=/mapping.htm
# 不需要验证授权, 或该请求有自己的验证机制
web.url.auth.excluded=/favicon.ico,/static/**,/api,/login.htm
# 日志配置

@ -97,9 +97,9 @@ fileRequest = function (config) {
})
};
window.ajax = {
example: function (data) {
login: function (data) {
return jsonRequest({
method: "ajax.example.example",
method: "ajax.login",
data: data
})
},
@ -146,21 +146,15 @@ window.ajax = {
data: JSON.stringify(data),
})
},
mappingFind: function (data) {
serviceLoad: function(data) {
return jsonRequest({
method:"ajax.admin.mapping.find",
method:"ajax.admin.service.load",
data: JSON.stringify(data),
})
},
mappingGet: function(data) {
configFlush: function(data) {
return jsonRequest({
method:"ajax.admin.mapping.get",
data: JSON.stringify(data),
})
},
portLoad: function(data) {
return jsonRequest({
method:"ajax.admin.port.load",
method:"ajax.admin.config.flush",
data: JSON.stringify(data),
})
},

@ -17,12 +17,24 @@ events {
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
keepalive_timeout 65;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
<#list services as item>
server {
listen 8888;
listen ${item.value};
server_name localhost;
#charset koi8-r;
@ -30,26 +42,23 @@ http {
#access_log logs/host.access.log main;
<#list item.mappingList as mapping>
location /${mapping.context} {
proxy_pass ${mapping.location};
proxy_redirect off;
<#if mapping.type="HTTP">
location ${mapping.context} {
proxy_pass ${mapping.location};
proxy_set_header Host $remote_addr:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header request_uri $scheme://$remote_addr:$server_port$request_uri;
proxy_set_header proxy_context /${mapping.context};
client_max_body_size 50m;
client_body_buffer_size 128k;
proxy_connect_timeout 300;
proxy_send_timeout 300;
proxy_read_timeout 300;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
proxy_set_header proxy_context ${mapping.context};
index index.html index.htm index.jsp index.do;
}
<#elseif mapping.type="FILE">
location ${mapping.context} {
root ${mapping.location};
index index.html index.htm;
autoindex on;
}
</#if>
</#list>
error_page 500 502 503 504 /50x.html;

@ -4,9 +4,9 @@
<div class="login-title">系统登录</div>
<el-form :model="form" :rules="rules" ref="form" class="form">
<el-form-item prop="name">
<el-input placeholder="用户名" v-model="form.name">
<template slot="prepend"><i class="icon iconfont el-icon-example"></i></template>
<el-form-item prop="username">
<el-input placeholder="用户名" v-model="form.username">
<template slot="prepend"><i class="icon iconfont el-icon-user"></i></template>
</el-input>
</el-form-item>
@ -95,11 +95,11 @@
el: "#app",
data: {
form: {
name: '',
username: '',
password: ''
},
rules: {
name: [
username: [
{required: true, message: '请输入用户名', trigger: 'blur'}
],
password: [
@ -116,11 +116,14 @@
this.$refs[formName].validate(function (valid) {
if (valid) {
this.isLogin = true;
setTimeout(function(){
nav.i("登录成功!", function () {
location.href = "/index.htm"
});
},1000)
ajax.login(this.form).then(function (response) {
this.isLogin = false;
if (response.errors.length > 0) {
nav.e(response.errors[0].message);
} else {
location.href = "/"
}
}.bind(this))
} else {
return false;
}

@ -5,7 +5,7 @@
<el-col :span="3">
<a>Nginx 控制中心</a>
</el-col>
<el-col :span="2">
<el-col :span="5">
<a @click="nginxStart">
<el-image v-if="run" :src="'${Uri.getUrl('/static/img/start_.png')}'"
style="width: 50px; height: 50px"
@ -14,8 +14,6 @@
style="width: 50px; height: 50px"
fit="fill"></el-image>
</a>
</el-col>
<el-col :span="2">
<a @click="nginxStop">
<el-image v-if="run" :src="'${Uri.getUrl('/static/img/stop.png')}'"
style="width: 50px; height: 50px"
@ -24,8 +22,6 @@
style="width: 50px; height: 50px"
fit="fill"></el-image>
</a>
</el-col>
<el-col :span="2">
<a @click="nginxReload">
<el-image v-if="run" :src="'${Uri.getUrl('/static/img/reload.png')}'"
style="width: 50px; height: 50px"
@ -40,13 +36,13 @@
<el-card class="box-card" v-for="item in services" :key="item.id">
<el-row>
<el-col :span="5">
<el-col :span="4">
<el-input size="small" v-model="item.value" placeholder="请输入端口" style="width: 160px;text-align: center"
suffix-icon="el-icon-edit">
<template slot="prepend">端口</template>
</el-input>
</el-col>
<el-col :span="6">
<el-col :span="5">
<el-input size="small" v-model="item.bz" placeholder="请输入备注" style="width: 200px;text-align: center"
suffix-icon="el-icon-collection-tag">
<template slot="prepend">备注</template>
@ -55,37 +51,12 @@
<el-col :span="2">
<el-button type="primary" size="small" icon="el-icon-refresh">保存</el-button>
</el-col>
<el-col :span="11">
<el-col :span="13">
<span style="float: right;">
<el-button type="success" size="small" icon="el-icon-plus" @click="onAction(['create',item])">新增
</el-button>
<el-button size="small" icon="el-icon-refresh" @click="onFind"></el-button>
<el-button size="small" icon="el-icon-refresh" @click="onRefresh"></el-button>
</span>
<el-dialog :title="form.title" :visible.sync="form.dialog">
<el-form :model="form" :rules="formRules" ref="form" label-width="90px"
style="width: 290px;">
<el-form-item label="名称" prop="name">
<el-input v-model="form.name" clearable size="small" placeholder="简要描述"></el-input>
</el-form-item>
<el-form-item label="路径" prop="context">
<el-input v-model="form.context" clearable size="small" placeholder="字母数字组合">
<template slot="prepend">:{{form.port}}/</template>
</el-input>
</el-form-item>
<el-form-item label="地址" prop="location">
<el-input v-model="form.location" clearable size="small" placeholder="路径或URL"></el-input>
</el-form-item>
<el-form-item label="备注" prop="bz">
<el-input type="textarea" v-model="form.bz" clearable size="small"
placeholder="备注信息"></el-input>
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button size="small" @click="form.dialog = false">取 消</el-button>
<el-button size="small" type="primary" @click="onAction(['save',''])">保存</el-button>
</span>
</el-dialog>
</el-col>
</el-row>
@ -108,12 +79,12 @@
</template>
</el-table-column>
<el-table-column
width="150px"
width="130px"
label="路径"
prop="context">
</el-table-column>
<el-table-column
width="150px"
width="220px"
label="地址"
prop="location">
</el-table-column>
@ -143,17 +114,75 @@
<el-button
size="mini"
type="danger"
@click="onAction('delete', scope.row)">删除
@click="onAction(['delete', scope.row])">删除
</el-button>
</template>
</el-table-column>
</el-table>
</el-card>
<el-dialog :title="form.title" :visible.sync="form.dialog" width="550px">
<el-form :model="form" :rules="formRules" ref="form" label-width="80px"
style="width: 400px;margin: 0 auto">
<el-form-item label="映射名称" required prop="name">
<el-row>
<el-col :span="22">
<el-input v-model="form.name" clearable size="small" placeholder="映射名称"></el-input>
</el-col>
</el-row>
</el-form-item>
<el-form-item label="映射路径" required prop="context">
<el-row>
<el-col :span="22">
<el-input v-model="form.context" clearable size="small" placeholder="字母数字组合">
<template slot="prepend">:{{form.port}}</template>
</el-input>
</el-col>
</el-row>
</el-form-item>
<el-form-item label="映射类型" required prop="type">
<el-radio v-model="form.type" label="HTTP">HTTP</el-radio>
<el-radio v-model="form.type" label="FILE">FILE</el-radio>
</el-form-item>
<el-form-item label="映射地址" required prop="location">
<el-row>
<el-col :span="22">
<el-input v-model="form.location" clearable size="small"
:placeholder="form.type=='HTTP'?'代理地址http://':'文件地址D:\ or /root'"></el-input>
</el-col>
<el-col :span="2" style="text-align: right">
<el-popover
placement="top-start"
width="200"
trigger="hover"
content="映射类型为文件时,映射路径名需和即将映射的文件夹一样,且不以“\”结尾,映射地址为该文件夹的上一层,则可正常访问。">
<i slot="reference" class="el-icon-warning-outline"></i>
</el-popover>
</el-col>
</el-row>
</el-form-item>
<el-form-item label="映射备注" prop="bz">
<el-row>
<el-col :span="22">
<el-input type="textarea" :autosize="{ minRows: 3, maxRows: 5}" v-model="form.bz" clearable
size="small"
placeholder="备注信息"></el-input>
</el-col>
</el-row>
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button size="small" @click="form.dialog = false">取 消</el-button>
<el-button size="small" type="primary" @click="onAction(['save',''])">保存</el-button>
</span>
</el-dialog>
</div>
<style>
#app {
padding: 10px;
width: 900px;
margin: 0 auto;
width: 1080px;
}
.box-card {
@ -187,19 +216,41 @@
title: "",
dialog: false,
id: '',
type: 'HTTP',
context: '',
location: '',
name: '',
bz: ''
},
formRules: {
roleName: [
{required: true, message: '不能为空', trigger: 'blur'},
name: [
{required: true, message: '映射名称不能为空', trigger: 'blur'},
{min: 1, max: 50, message: '长度在 1 到 50 字符', trigger: 'blur'}
],
roleCode: [
{required: true, message: '不能为空', trigger: 'blur'},
{min: 1, max: 50, message: '长度在 1 到 50 个字符', trigger: 'blur'}
context: [
{required: true, message: '映射路径不能为空', trigger: 'blur'},
{pattern: "^/[a-zA-Z][a-zA-Z0-9_-]*$|^/$", message: '上下文须是(/)或(/+字母+字母数字及_', trigger: 'blur'},
],
location: [
{required: true, message: '映射地址不能为空', trigger: 'change'},
{
validator: function (rule, value, callback) {
if (app.form.type == "HTTP") {
if (value.match("http:\/\/.*")) {
callback();
} else {
callback(new Error("需以http://协议开始"))
}
}
if (app.form.type == "FILE") {
if (value.match("^[A-Z]:\\\\.*$|^[A-Z]:/.*$|^/.*$")) {
callback();
} else {
callback(new Error("windows目录(C:\\)或linux目录(\\)"))
}
}
}, trigger: 'blur'
}
],
},
services: [],
@ -207,7 +258,7 @@
},
methods: {
onFind: function () {
ajax.portLoad().then(function (response) {
ajax.serviceLoad().then(function (response) {
if (response.errors.length > 0) {
nav.e(response.errors[0].message);
} else {
@ -228,6 +279,7 @@
this.form.id = '';
this.form.name = '';
this.form.context = '';
this.form.type = 'HTTP';
this.form.location = '';
this.form.bz = '';
this.form.dialog = true;
@ -239,32 +291,45 @@
this.form.port = arg[2].value;
this.form.name = arg[1].name;
this.form.context = arg[1].context;
this.form.type = arg[1].type;
this.form.location = arg[1].location;
this.form.bz = arg[1].bz;
this.form.dialog = true;
break;
case "save":
if (this.form.id) {
ajax.mappingUpdate(this.form).then(function (response) {
if (response.errors.length > 0) {
nav.e(response.errors[0].message);
} else {
this.onFind();
this.nginxReload();
this.form.dialog = false;
}
}.bind(this))
} else {
ajax.mappingCreate(this.form).then(function (response) {
if (response.errors.length > 0) {
nav.e(response.errors[0].message);
this.$refs['form'].validate(function (valid) {
if (valid) {
if (this.form.id) {
ajax.mappingUpdate(this.form).then(function (response) {
if (response.errors.length > 0) {
nav.e(response.errors[0].message);
} else {
this.onFind();
this.form.dialog = false;
this.configFlush();
if (this.run) {
this.nginxReload();
}
}
}.bind(this))
} else {
this.onFind();
this.nginxReload();
this.form.dialog = false;
ajax.mappingCreate(this.form).then(function (response) {
if (response.errors.length > 0) {
nav.e(response.errors[0].message);
} else {
this.onFind();
this.form.dialog = false;
this.configFlush();
if (this.run) {
this.nginxReload();
}
}
}.bind(this))
}
}.bind(this))
}
} else {
return false;
}
}.bind(this));
break;
case "delete":
this.$confirm('将删除该项, 是否继续?', '提示', {
@ -278,7 +343,10 @@
} else {
nav.s("删除成功");
this.onFind();
this.nginxReload();
this.configFlush();
if (this.run) {
this.nginxReload();
}
}
}.bind(this))
}.bind(this)).catch(function (action) {
@ -298,7 +366,8 @@
this.$notify.info({
title: '提示',
message: "Nginx 运行状态发生变化:"
message: "Nginx 运行状态发生变化。",
duration: 5000
});
this.run = msg.object.run;
}
@ -326,13 +395,19 @@
}
}.bind(this))
},
configFlush: function () {
ajax.configFlush();
},
onRefresh: function () {
this.configFlush();
this.onFind();
},
nginxReload: function () {
ajax.nginxReload().then(function (response) {
if (response.errors.length > 0) {
nav.e(response.errors[0].message);
} else {
this.onFind();
this.form.dialog = false;
}
}.bind(this))
}

@ -126,19 +126,19 @@ public class Client {
*
*/
public void destroyed() {
try {
if (null != resultSet) {
resultSet.close();
resultSet = null;
}
if (null != connection) {
connection.close();
connection = null;
}
} catch (SQLException e) {
e.printStackTrace();
}
// try {
// if (null != resultSet) {
// resultSet.close();
// resultSet = null;
// }
//
// if (null != connection) {
// connection.close();
// connection = null;
// }
//
// } catch (SQLException e) {
// e.printStackTrace();
// }
}
}

@ -5,7 +5,6 @@ import xyz.wbsite.wsqlite.anonation.TableField;
import java.io.File;
import java.lang.reflect.Field;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.*;
/**
@ -102,8 +101,7 @@ public class ObjectClient extends Client {
f.setAccessible(true);
fieldsSql.append(f.getName().toUpperCase());
valueSql.append("?");
Object o = f.get(po);
values[i] = o;
values[i] = f.get(po);
if (i != fs.size() - 1) {
fieldsSql.append(",");
valueSql.append(",");
@ -197,7 +195,7 @@ public class ObjectClient extends Client {
return 0;
}
public <T> List<T> select(Class<T> poClass, int pageNumber, int pageSize, String... wheres) throws SQLException, ClassNotFoundException {
public <T> List<T> select(Class<T> poClass, int pageNumber, int pageSize, T po, String... wheres) throws SQLException, ClassNotFoundException {
ArrayList<T> list = new ArrayList<>();
try {
Class aClass = classMap.get(poClass.getName());
@ -209,6 +207,8 @@ public class ObjectClient extends Client {
//获取字段列表
List<Field> fs = getFields(poClass);
List<String> poWhere = new ArrayList();
List<Object> args = new ArrayList();
for (int i = 0; i < fs.size(); i++) {
Field f = fs.get(i);
@ -216,15 +216,23 @@ public class ObjectClient extends Client {
if (i != fs.size() - 1) {
sql.append(",");
}
if (po != null) {
if (f.get(po) != null) {
poWhere.add(" " + f.getName().toUpperCase() + " = ? ");
args.add(f.get(po));
}
}
}
sql.append(" FROM ");
sql.append(aClass.getSimpleName());
poWhere.addAll(Arrays.asList(wheres));
//条件参数
if (wheres.length > 0) {
if (poWhere.size() + wheres.length > 0) {
sql.append(" WHERE ");
for (int i = 0; i < wheres.length; i++) {
for (int i = 0; i < poWhere.size(); i++) {
String where = wheres[i];
sql.append(where);
sql.append(i != wheres.length - 1 ? " AND " : "");
@ -232,13 +240,15 @@ public class ObjectClient extends Client {
}
//分页参数
if(pageSize > 0){
if (pageSize > 0) {
sql.append(" LIMIT " + (pageNumber - 1) + "," + pageSize);
}
System.out.println("SQL ==> " + sql.toString());
list.addAll(executeQuery(sql.toString(), poClass));
list.addAll(executeQuery(poClass, sql.toString(), args));
}
} catch (IllegalAccessException e) {
e.printStackTrace();
} finally {
destroyed();
}
@ -254,10 +264,10 @@ public class ObjectClient extends Client {
* @throws SQLException
* @throws ClassNotFoundException
*/
public <T> List<T> executeQuery(String sql, Class<T> poClass) throws SQLException, ClassNotFoundException {
public <T> List<T> executeQuery(Class<T> poClass, String sql, Object... args) throws SQLException, ClassNotFoundException {
List<T> rsList = new ArrayList<T>();
try {
resultSet = executeQuery(sql);
resultSet = executeQuery(sql, args);
//获取字段列表
List<Field> fs = getFields(poClass);
@ -300,7 +310,7 @@ public class ObjectClient extends Client {
byte[] v = resultSet.getBytes(f.getName());
f.set(o, v);
} else if (f.getType() == Date.class) {
Date v = resultSet.getTimestamp(f.getName());
Date v = resultSet.getDate(f.getName());
f.set(o, v);
} else {
String v = resultSet.getString(f.getName());

Loading…
Cancel
Save

Powered by TurnKey Linux.