vpn 用户管理修改新增修改和删除逻辑
ip地址池增加存在可用ip地址池才在策略展示
This commit is contained in:
@@ -5,7 +5,9 @@ import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.ws.rs.client.Client;
|
||||
@@ -16,8 +18,10 @@ import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.UriBuilder;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.http.client.utils.HttpClientUtils;
|
||||
import org.eclipse.jetty.util.ajax.JSON;
|
||||
import org.glassfish.jersey.media.multipart.FormDataMultiPart;
|
||||
import org.glassfish.jersey.media.multipart.file.FileDataBodyPart;
|
||||
import org.slf4j.Logger;
|
||||
@@ -624,6 +628,61 @@ public class ConfigServiceUtil {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public static Map getCGIInfo(String url,String cmd,Map<String, Object> params) {
|
||||
Map<String, Object> resultMap = new HashMap<String, Object>();
|
||||
params.put("cmd", cmd);
|
||||
String recv = getCGI(url, params);
|
||||
if (StringUtils.isNotBlank(recv)) {
|
||||
resultMap = (Map<String, Object>) JSON.parse(recv);
|
||||
}
|
||||
return resultMap;
|
||||
}
|
||||
public static String getCGI(String url, Map<String, Object> params) throws MaatConvertException{
|
||||
// if(StringUtils.isBlank(searchCondition.getSearchService())){
|
||||
// throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>");
|
||||
// }
|
||||
Response response=null;
|
||||
String result = null;
|
||||
try {
|
||||
UriBuilder builder=UriBuilder.fromPath(url);
|
||||
if(params!=null) {
|
||||
for (String param : params.keySet()) {
|
||||
if(!StringUtil.isBlank(param)&¶ms.get(param)!=null) {
|
||||
builder.queryParam(param,params.get(param).toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
URI uri=builder.build();
|
||||
logger.info("cgi url:"+uri.toString());
|
||||
//创建连接
|
||||
ClientUtil.initClient();
|
||||
Client client=ClientUtil.getClient();
|
||||
WebTarget wt = client.target(uri);
|
||||
Builder header = wt.request();
|
||||
try {
|
||||
response= header.get();
|
||||
} catch (Exception e) {
|
||||
throw new MaatConvertException("<spring:message code=\"cgi_service_failed\"/>");
|
||||
}
|
||||
if(response !=null && response.getStatus() == 200){
|
||||
result= response.readEntity(String.class);
|
||||
logger.info("cgi info:"+result);
|
||||
}else{
|
||||
if(response!= null) {
|
||||
throw new MaatConvertException("<spring:message code=\"cgi_service_failed\"/>:"+response.readEntity(String.class));
|
||||
}else {
|
||||
throw new MaatConvertException("<spring:message code=\"cgi_service_failed\"/>");
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
} finally {
|
||||
if (response != null) {
|
||||
response.close();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置全量更新指令下发
|
||||
|
||||
@@ -753,4 +753,6 @@ public final class Constants {
|
||||
|
||||
// IP复用模块调用相关CGI接口URL
|
||||
public static final String IP_REUSE_CALL_CGI_URL = Configurations.getStringProperty("ip_reuse_call_cgi_url","");
|
||||
public static final String ALL_IP_GET = Configurations.getStringProperty("allIpGet","AllIpGet");
|
||||
public static final String IP_NUM_GET = Configurations.getStringProperty("ipNumGet","IpNumGet");
|
||||
}
|
||||
|
||||
@@ -373,46 +373,4 @@ public class HttpClientUtil {
|
||||
//
|
||||
// }
|
||||
|
||||
/**
|
||||
* CGI get 获取消息
|
||||
* @param destUrl 业务地址
|
||||
* @param params 参数列表
|
||||
* @return 查询结果数据json
|
||||
*/
|
||||
public static String getCGI(String destUrl, Map<String, Object> params, HttpServletRequest req) throws IOException {
|
||||
String result = null;
|
||||
Response response=null;
|
||||
String url = "";
|
||||
try {
|
||||
URIBuilder uriBuilder = new URIBuilder(destUrl);
|
||||
if(params!=null) {
|
||||
for (String param : params.keySet()) {
|
||||
if(!StringUtil.isBlank(param)&¶ms.get(param)!=null) {
|
||||
uriBuilder.addParameter(param, params.get(param).toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
System.err.println(uriBuilder);
|
||||
url=uriBuilder.toString();
|
||||
//创建连接
|
||||
WebTarget wt = ClientUtil.getWebTarger(url);
|
||||
logger.info("getMsg url:"+url);
|
||||
//获取响应结果
|
||||
Builder header = wt.request(MediaType.APPLICATION_JSON).header("Content-Type", MediaType.APPLICATION_JSON);
|
||||
response= header.get();
|
||||
result= response.readEntity(String.class);
|
||||
//调用处理数据方法
|
||||
logger.info("获取消息成功,相应内容如下: " + result);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.error("获取消息失败,相应内容如下: " + result);
|
||||
logger.error("获取消息失败 ", e);
|
||||
throw new MaatConvertException("<spring:message code=\"cgi_service_failed\"/>:");
|
||||
}finally {
|
||||
if (response != null) {
|
||||
response.close();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
package com.nis.web.controller.configuration.maintenance;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.eclipse.jetty.util.ajax.JSON;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
@@ -16,11 +21,15 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||
|
||||
import com.nis.domain.Page;
|
||||
import com.nis.domain.basics.IpReuseIpCfg;
|
||||
import com.nis.domain.basics.PolicyGroupInfo;
|
||||
import com.nis.domain.configuration.BaseIpCfg;
|
||||
import com.nis.domain.configuration.IpAddrPoolCfg;
|
||||
import com.nis.domain.configuration.IpMultiplexPoolCfg;
|
||||
import com.nis.domain.configuration.UserManage;
|
||||
import com.nis.exceptions.MaatConvertException;
|
||||
import com.nis.util.ConfigServiceUtil;
|
||||
import com.nis.util.Constants;
|
||||
import com.nis.util.StringUtil;
|
||||
import com.nis.web.controller.BaseController;
|
||||
import com.nis.web.service.configuration.IpAddrPoolCfgService;
|
||||
@@ -182,4 +191,17 @@ public class IpAddrPoolController extends BaseController{
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping(value = {"/getCGIInfo"})
|
||||
public Map<String,Object> getUserInfo(Integer addrPoolId,String cmd,HttpServletRequest request,HttpServletResponse response){
|
||||
Map<String, Object> resultMap = new HashMap<String, Object>();
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("cmd", cmd);
|
||||
params.put("addr_pool_id", addrPoolId);
|
||||
String url =Constants.IP_REUSE_CALL_CGI_URL ;
|
||||
resultMap=ConfigServiceUtil.getCGIInfo(url, cmd, params);
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -69,15 +69,39 @@ public class UserManageController extends BaseController{
|
||||
public String delete(Integer isValid
|
||||
,String ids
|
||||
,RedirectAttributes redirectAttributes,HttpServletRequest request){
|
||||
String deleteSuccessIp="";
|
||||
try{
|
||||
userManageService.delete(isValid,ids,request);
|
||||
addMessage(redirectAttributes,"delete_success");
|
||||
for (String id : ids.split(",")) {
|
||||
UserManage user=userManageService.getUserById(id);
|
||||
if(user != null && !StringUtil.isEmpty(user.getServerIp())) {
|
||||
boolean lastIp=false;
|
||||
int deleteIpLenth=1;
|
||||
String serverIp=user.getServerIp().substring(0, user.getServerIp().length()-1);
|
||||
int serverIpNum=user.getServerIp().split(",").length;
|
||||
for (String ip : user.getServerIp().split(",")) {
|
||||
try {
|
||||
if(deleteIpLenth == serverIpNum) {
|
||||
lastIp=true;
|
||||
}
|
||||
userManageService.delete(-1,user,ip,lastIp);
|
||||
deleteIpLenth++;
|
||||
} catch (MaatConvertException e) {
|
||||
logger.error("用户vpn新增失败",e);
|
||||
throw e;
|
||||
}catch (Exception e) {
|
||||
logger.error("用户vpn新增失败",e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
addMessage(redirectAttributes,"success","delete_success");
|
||||
}catch(Exception e){
|
||||
logger.error("Delete failed",e);
|
||||
if(e instanceof MaatConvertException) {
|
||||
addMessage(redirectAttributes,e.getMessage());
|
||||
addMessage(redirectAttributes,"error","cgi_service_failed");
|
||||
}else {
|
||||
addMessage(redirectAttributes,"delete_failed");
|
||||
addMessage(redirectAttributes,"error","delete_failed");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,42 +117,126 @@ public class UserManageController extends BaseController{
|
||||
Date createTime=new Date();
|
||||
String errorIp="";
|
||||
String errorType="";
|
||||
if(entity.getId()==null){
|
||||
entity.setCreateTime(createTime);
|
||||
entity.setCreatorId(entity.getCurrentUser().getId());
|
||||
entity.setIsValid(Constants.VALID_NO);
|
||||
String addIp="";
|
||||
String addSuccessIp="";
|
||||
String deleteIp="";
|
||||
String deleteSuccessIp="";
|
||||
boolean isExistUser=false;
|
||||
try {
|
||||
String[] ipArray =entity.getServerIp().split(",");
|
||||
for (String ip : ipArray) {
|
||||
userManageService.saveip(entity,ip,model,request);
|
||||
}
|
||||
UserManage oldUser=userManageService.getUserByLoginName(entity.getUserName());
|
||||
if(oldUser!=null){
|
||||
String[] ips=oldUser.getServerIp().split(",");
|
||||
String erorIp =userManageService.getMessageIp(ipArray, ips);
|
||||
if(!StringUtil.isEmpty(erorIp)){
|
||||
errorType="create";
|
||||
errorIp=entity.getUserName()+" "+erorIp;
|
||||
String serverIp =entity.getServerIp();
|
||||
if(entity.getId()==null){
|
||||
addIp=serverIp;
|
||||
entity.setCreateTime(createTime);
|
||||
entity.setCreatorId(entity.getCurrentUser().getId());
|
||||
entity.setIsValid(Constants.VALID_YES);
|
||||
for (String ip : ipArray) {
|
||||
try {
|
||||
if(!StringUtil.isEmpty(ip)) {
|
||||
if(!isExistUser) {
|
||||
entity.setServerIp(ip+",");
|
||||
userManageService.saveip(entity,ip);
|
||||
//用户第一个vpn创建成功之后即可走update
|
||||
isExistUser=true;
|
||||
}else {
|
||||
entity.setServerIp(addSuccessIp+ip+",");
|
||||
userManageService.updateip(entity,ip);
|
||||
}
|
||||
addSuccessIp+=addSuccessIp+",";
|
||||
}
|
||||
} catch (MaatConvertException e) {
|
||||
logger.error("用户vpn新增失败",e);
|
||||
throw e;
|
||||
}catch (Exception e) {
|
||||
logger.error("用户vpn新增失败",e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}else{
|
||||
entity.setEditTime(createTime);
|
||||
entity.setEditorId(entity.getCurrentUser().getId());
|
||||
String[] ipArray =entity.getServerIp().split(",");
|
||||
UserManage oldUser=userManageService.getUserById(String.valueOf(entity.getId()));
|
||||
int num=0;
|
||||
for (String ip : ipArray) {
|
||||
userManageService.updateip(entity,ip,num,model,request);
|
||||
num++;
|
||||
}
|
||||
UserManage user=userManageService.getUserById(String.valueOf(entity.getId()));
|
||||
if(user!=null){
|
||||
String[] ips=user.getServerIp().split(",");
|
||||
String erorIp =userManageService.getMessageIp(ipArray, ips);
|
||||
if(!StringUtil.isEmpty(erorIp)){
|
||||
errorType="create";
|
||||
errorIp=user.getUserName()+" "+erorIp;
|
||||
}else{
|
||||
entity.setEditTime(createTime);
|
||||
entity.setEditorId(entity.getCurrentUser().getId());
|
||||
UserManage oldUser=userManageService.getUserById(String.valueOf(entity.getId()));
|
||||
|
||||
if(oldUser != null) {
|
||||
//密码修改
|
||||
if(oldUser != null && !StringUtil.isEmpty(entity.getUserPwd()) && !entity.getUserPwd().equals(oldUser.getUserPwd())) {
|
||||
for (String ip : oldUser.getServerIp().split(",")) {
|
||||
try {
|
||||
if(!StringUtil.isEmpty(ip)) {
|
||||
entity.setServerIp(oldUser.getServerIp());
|
||||
entity.setUserPwd(entity.getUserPwd());
|
||||
entity.setNewUserPwd(entity.getUserPwd());
|
||||
userManageService.updatePwd(entity,ip);
|
||||
}
|
||||
} catch (MaatConvertException e) {
|
||||
logger.error("用户vpn密码修改失败",e);
|
||||
throw e;
|
||||
}catch (Exception e) {
|
||||
logger.error("用户vpn密码修改失败",e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//获取需求新增的vpn ip
|
||||
for (String oldIp : oldUser.getServerIp().split(",")) {
|
||||
if(!StringUtil.isEmpty(oldIp) && !serverIp.contains(oldIp)) {
|
||||
deleteIp+=oldIp+",";
|
||||
}
|
||||
}
|
||||
//获取需求删除的vpn ip
|
||||
for (String newIp : serverIp.split(",")) {
|
||||
if(!StringUtil.isEmpty(newIp) && !oldUser.getServerIp().contains(newIp)) {
|
||||
addIp+=newIp+",";
|
||||
}
|
||||
}
|
||||
//新增用户vpnip
|
||||
if(!StringUtil.isEmpty(addIp)){
|
||||
for (String ip : addIp.split(",")) {
|
||||
try {
|
||||
if(!StringUtil.isEmpty(ip)) {
|
||||
entity.setServerIp(oldUser.getServerIp()+ip+",");
|
||||
entity.setUserName(oldUser.getUserName());
|
||||
entity.setUserPwd(oldUser.getUserPwd());
|
||||
userManageService.updateip(entity,ip);
|
||||
addSuccessIp+=addSuccessIp+",";
|
||||
}
|
||||
} catch (MaatConvertException e) {
|
||||
logger.error("用户vpn新增失败",e);
|
||||
throw e;
|
||||
}catch (Exception e) {
|
||||
logger.error("用户vpn新增失败",e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
//删除用户vpnip
|
||||
if(!StringUtil.isEmpty(deleteIp)){
|
||||
for (String ip : deleteIp.split(",")) {
|
||||
try {
|
||||
if(!StringUtil.isEmpty(ip)) {
|
||||
entity.setServerIp(oldUser.getServerIp().replace(ip+",", ""));
|
||||
userManageService.deleteip(entity,ip);
|
||||
deleteSuccessIp+=deleteSuccessIp+",";
|
||||
}
|
||||
} catch (MaatConvertException e) {
|
||||
logger.error("用户vpn删除失败",e);
|
||||
throw e;
|
||||
}catch (Exception e) {
|
||||
logger.error("用户vpn删除失败",e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} catch (MaatConvertException e) {
|
||||
addMessage(redirectAttributes,"error","cgi_service_failed");
|
||||
return "redirect:" + adminPath +"/maintenance/userManage/list?cgiError="+errorIp+"&errorType="+errorType;
|
||||
} catch (Exception e) {
|
||||
addMessage(redirectAttributes,"error","save_failed");
|
||||
return "redirect:" + adminPath +"/maintenance/userManage/list?cgiError="+errorIp+"&errorType="+errorType;
|
||||
}
|
||||
return "redirect:" + adminPath +"/maintenance/userManage/list?cgiError="+errorIp+"&errorType="+errorType;
|
||||
}
|
||||
@@ -193,7 +301,7 @@ public class UserManageController extends BaseController{
|
||||
UserManage user=new UserManage();
|
||||
IpReuseIpCfg ipReuseIpCfg=ipReuseIpCfgService.getIpByIp(ip);
|
||||
//根据ip调用接口获取数据
|
||||
Map<String,String> map=userManageService.getUser(ip,userName, request);
|
||||
Map<String,String> map=userManageService.getUser(ip,userName);
|
||||
if(ipReuseIpCfg!=null ){
|
||||
map.put("serverIp", ipReuseIpCfg.getDestIpAddress());
|
||||
userManageList.add(map);
|
||||
|
||||
@@ -38,6 +38,7 @@ import com.nis.domain.configuration.IpPortCfg;
|
||||
import com.nis.domain.configuration.UserManage;
|
||||
import com.nis.domain.configuration.template.IpMultiplexPolicyTemplate;
|
||||
import com.nis.exceptions.MaatConvertException;
|
||||
import com.nis.util.ConfigServiceUtil;
|
||||
import com.nis.util.Constants;
|
||||
import com.nis.util.DictUtils;
|
||||
import com.nis.util.StringUtil;
|
||||
@@ -147,9 +148,21 @@ public class IpMultiplexController extends CommonController {
|
||||
// 获取用户信息 地址池信息
|
||||
List<UserManage> users = userManageService.findUsers();
|
||||
List<IpAddrPoolCfg> addrPools = ipAddrPoolCfgService.getEffectiveAddrPool();
|
||||
List<IpAddrPoolCfg> addrPoolsNew=new ArrayList<>();
|
||||
for (IpAddrPoolCfg addrPool : addrPools) {
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("addr_pool_id", addrPool.getAddrPoolId());
|
||||
String url =Constants.IP_REUSE_CALL_CGI_URL ;
|
||||
Map<String, Object> resultMap=ConfigServiceUtil.getCGIInfo(url, Constants.IP_NUM_GET, params);
|
||||
if(!StringUtil.isEmpty(resultMap)
|
||||
&& !StringUtil.isEmpty(resultMap.get("num"))
|
||||
&& Integer.parseInt(resultMap.get("num").toString()) > 0) {
|
||||
addrPoolsNew.add(addrPool);
|
||||
}
|
||||
}
|
||||
|
||||
model.addAttribute("users", users);
|
||||
model.addAttribute("addrPools", addrPools);
|
||||
model.addAttribute("addrPools", addrPoolsNew);
|
||||
model.addAttribute("urlPrefix","/manipulation/ipmulitiplex");
|
||||
return "/cfg/manipulation/ipmulitiplex/snatPolicyForm2";
|
||||
}
|
||||
|
||||
@@ -443,6 +443,6 @@
|
||||
<select id="findAddrPoolCfg" resultMap="addrPoolMap">
|
||||
SELECT
|
||||
<include refid="addrPoolColumns"/>,r.ADDR_POOL_NAME
|
||||
FROM ip_reuse_addr_pool r WHERE r.is_valid !=-1
|
||||
FROM ip_reuse_addr_pool r WHERE r.is_audit=1
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -92,7 +92,7 @@
|
||||
#{serverIp,jdbcType=VARCHAR},
|
||||
#{userType,jdbcType=VARCHAR},
|
||||
#{isValid,jdbcType=INTEGER},
|
||||
0,
|
||||
1,
|
||||
#{creatorId,jdbcType=INTEGER},
|
||||
#{createTime,jdbcType=TIMESTAMP},
|
||||
#{editorId,jdbcType=INTEGER},
|
||||
|
||||
@@ -24,9 +24,9 @@ import com.nis.domain.configuration.AppPolicyCfg;
|
||||
import com.nis.domain.configuration.CfgIndexInfo;
|
||||
import com.nis.domain.configuration.UserManage;
|
||||
import com.nis.exceptions.MaatConvertException;
|
||||
import com.nis.util.ConfigServiceUtil;
|
||||
import com.nis.util.Constants;
|
||||
import com.nis.util.StringUtil;
|
||||
import com.nis.util.httpclient.HttpClientUtil;
|
||||
import com.nis.web.dao.configuration.AppCfgDao;
|
||||
import com.nis.web.dao.configuration.IpCfgDao;
|
||||
import com.nis.web.dao.configuration.UserManageDao;
|
||||
@@ -77,50 +77,55 @@ public class UserManageService extends BaseService{
|
||||
}
|
||||
|
||||
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
||||
public void saveip(UserManage entity,String ips,Model model, HttpServletRequest request){
|
||||
SqlSessionFactory sqlSessionFactory=SpringContextHolder.getBean(SqlSessionFactory.class);
|
||||
SqlSession batchSqlSession = null;
|
||||
try {
|
||||
batchSqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
|
||||
UserManage user=userManageDao.getUserByLoginName(entity.getUserName());
|
||||
if(user==null){
|
||||
entity.setServerIp(ips);
|
||||
((UserManageDao) batchSqlSession.getMapper(UserManageDao.class)).insert(entity);
|
||||
}else{
|
||||
user.setServerIp(user.getServerIp()+","+ips);
|
||||
((UserManageDao) batchSqlSession.getMapper(UserManageDao.class)).update(user);
|
||||
}
|
||||
//cgi接口添加
|
||||
//循环调用接口增加
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("server_ip", ips);
|
||||
params.put("user_name", entity.getUserName());
|
||||
params.put("user_pwd", entity.getUserPwd());
|
||||
String url =Constants.IP_REUSE_CALL_CGI_URL+ Constants.NTC_IP_REUSE_USER_CREATE ;
|
||||
String recv = HttpClientUtil.getCGI(url, params, request);
|
||||
if (StringUtils.isNotBlank(recv)) {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map = (Map<String, String>) JSON.parse(recv);
|
||||
String error = map.get("error");
|
||||
if (!StringUtil.isEmpty(error)) {
|
||||
batchSqlSession.rollback();
|
||||
} else {
|
||||
batchSqlSession.commit();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (batchSqlSession != null) {
|
||||
batchSqlSession.close();
|
||||
}
|
||||
}
|
||||
public void saveip(UserManage entity,String ip)throws Exception{
|
||||
userManageDao.insert(entity);
|
||||
//cgi接口添加
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("cmd", Constants.NTC_IP_REUSE_USER_CREATE);
|
||||
params.put("server_ip", ip);
|
||||
params.put("user_name", entity.getUserName());
|
||||
params.put("user_pwd", entity.getUserPwd());
|
||||
String url =Constants.IP_REUSE_CALL_CGI_URL ;
|
||||
String recv = ConfigServiceUtil.getCGI(url, params);
|
||||
}
|
||||
|
||||
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
||||
public void updatePwd(UserManage entity,String ip){
|
||||
userManageDao.update(entity);
|
||||
//密码修改
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("cmd",Constants.NTC_IP_REUSE_USER_PASSWORD);
|
||||
params.put("server_ip", ip);
|
||||
params.put("user_name", entity.getUserName());
|
||||
params.put("user_pwd", entity.getUserName());
|
||||
String url =Constants.IP_REUSE_CALL_CGI_URL ;
|
||||
String recv = ConfigServiceUtil.getCGI(url, params);
|
||||
}
|
||||
|
||||
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
||||
public void updateip(UserManage entity,String ips,int num,Model model, HttpServletRequest request){
|
||||
SqlSessionFactory sqlSessionFactory=SpringContextHolder.getBean(SqlSessionFactory.class);
|
||||
public void deleteip(UserManage entity,String ip){
|
||||
userManageDao.update(entity);
|
||||
//循环调用接口删除
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("cmd",Constants.NTC_IP_REUSE_USER_DELETE);
|
||||
params.put("server_ip", ip);
|
||||
params.put("user_name", entity.getUserName());
|
||||
String url =Constants.IP_REUSE_CALL_CGI_URL ;
|
||||
String recv = ConfigServiceUtil.getCGI(url, params);
|
||||
}
|
||||
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
||||
public void updateip(UserManage entity,String ip){
|
||||
userManageDao.update(entity);
|
||||
//cgi接口添加
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("cmd", Constants.NTC_IP_REUSE_USER_CREATE);
|
||||
params.put("server_ip", ip);
|
||||
params.put("user_name", entity.getUserName());
|
||||
params.put("user_pwd", entity.getUserPwd());
|
||||
String url =Constants.IP_REUSE_CALL_CGI_URL ;
|
||||
String recv = ConfigServiceUtil.getCGI(url, params);
|
||||
|
||||
/*SqlSessionFactory sqlSessionFactory=SpringContextHolder.getBean(SqlSessionFactory.class);
|
||||
SqlSession batchSqlSession = null;
|
||||
try {
|
||||
batchSqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
|
||||
@@ -132,9 +137,10 @@ public class UserManageService extends BaseService{
|
||||
for(String ip :ipArray){
|
||||
//循环调用接口删除
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("cmd",Constants.NTC_IP_REUSE_USER_DELETE);
|
||||
params.put("server_ip", ip);
|
||||
params.put("user_name", olduser.getUserName());
|
||||
Map<String,String> map=getUrl(params,Constants.NTC_IP_REUSE_USER_DELETE,request);
|
||||
Map<String,String> map=getUrl(params);
|
||||
//返回处理
|
||||
}
|
||||
entity.setServerIp(ips);
|
||||
@@ -147,11 +153,12 @@ public class UserManageService extends BaseService{
|
||||
// cgi接口添加
|
||||
// 循环调用接口增加
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("cmd", Constants.NTC_IP_REUSE_USER_CREATE);
|
||||
params.put("server_ip", ips);
|
||||
params.put("user_name", entity.getUserName());
|
||||
params.put("user_pwd", entity.getUserPwd());
|
||||
String url = Constants.IP_REUSE_CALL_CGI_URL + Constants.NTC_IP_REUSE_USER_CREATE;
|
||||
String recv = HttpClientUtil.getCGI(url, params, request);
|
||||
String url = Constants.IP_REUSE_CALL_CGI_URL;
|
||||
String recv = ConfigServiceUtil.getCGI(url, params);
|
||||
if (StringUtils.isNotBlank(recv)) {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map = (Map<String, String>) JSON.parse(recv);
|
||||
@@ -162,21 +169,21 @@ public class UserManageService extends BaseService{
|
||||
batchSqlSession.commit();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (MaatConvertException e) {
|
||||
throw e;
|
||||
} finally {
|
||||
if (batchSqlSession != null) {
|
||||
batchSqlSession.close();
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
public Map<String,String> getUrl(Map<String, Object> params,String urlType,HttpServletRequest request){
|
||||
public Map<String,String> getUrl(Map<String, Object> params){
|
||||
Map<String,String> map=new HashMap<String,String>();
|
||||
try{
|
||||
String url =Constants.IP_REUSE_CALL_CGI_URL+ urlType ;
|
||||
String recv = HttpClientUtil.getCGI(url, params, request);
|
||||
String url =Constants.IP_REUSE_CALL_CGI_URL ;
|
||||
String recv = com.nis.util.ConfigServiceUtil.getCGI(url, params);
|
||||
if (StringUtils.isNotBlank(recv)) {
|
||||
map=(Map<String,String>)JSON.parse(recv);
|
||||
}
|
||||
@@ -187,14 +194,15 @@ public class UserManageService extends BaseService{
|
||||
}
|
||||
|
||||
//根据vpn服务器ip获取用户vpn服务器ip信息
|
||||
public Map<String,String> getUser(String serverIp,String userName,HttpServletRequest request){
|
||||
public Map<String,String> getUser(String serverIp,String userName){
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("cmd", Constants.NTC_IP_REUSE_USER_GET);
|
||||
params.put("server_ip", serverIp);
|
||||
params.put("user_name", userName);
|
||||
Map<String,String> map=new HashMap<String,String>();
|
||||
try{
|
||||
String url =Constants.IP_REUSE_CALL_CGI_URL+ Constants.NTC_IP_REUSE_USER_GET ;
|
||||
String recv = HttpClientUtil.getCGI(url, params, request);
|
||||
String url =Constants.IP_REUSE_CALL_CGI_URL;
|
||||
String recv = ConfigServiceUtil.getCGI(url, params);
|
||||
if (StringUtils.isNotBlank(recv)) {
|
||||
map=(Map<String,String>)JSON.parse(recv);
|
||||
}
|
||||
@@ -214,37 +222,22 @@ public class UserManageService extends BaseService{
|
||||
* @param ids compileIds
|
||||
*/
|
||||
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
||||
public void delete(Integer isValid,String ids,HttpServletRequest request){
|
||||
try{
|
||||
String[] idArray = ids.split(",");
|
||||
List<UserManage> userList=new ArrayList<UserManage>();
|
||||
for(String id :idArray){
|
||||
UserManage entity = new UserManage();
|
||||
entity=userManageDao.getUserById(id);
|
||||
if(entity!=null){
|
||||
userList.add(entity);
|
||||
}
|
||||
entity.setId(Long.valueOf(id));
|
||||
entity.setIsValid(isValid);
|
||||
entity.setEditorId(UserUtils.getUser().getId());
|
||||
entity.setEditTime(new Date());
|
||||
userManageDao.update(entity);
|
||||
public void delete(Integer isValid,UserManage entity,String ip,boolean lastIp){
|
||||
UserManage user=new UserManage();
|
||||
user.setId(entity.getId());
|
||||
if(!lastIp) {
|
||||
user.setServerIp(user.getServerIp().replace(ip+",", ""));
|
||||
}else {
|
||||
user.setIsValid(-1);
|
||||
}
|
||||
//cgi接口删除旧数据
|
||||
for (int i = 0; i < userList.size(); i++) {
|
||||
String[] ipArray = userList.get(i).getServerIp().split(",");
|
||||
for(String ip :ipArray){
|
||||
//循环调用接口删除
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("server_ip", ip);
|
||||
params.put("user_name",userList.get(i).getUserName());
|
||||
Map<String,String> map=getUrl(params,Constants.NTC_IP_REUSE_USER_DELETE,request);
|
||||
//返回处理
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("查询失败", e);
|
||||
}
|
||||
userManageDao.update(user);
|
||||
//cgi接口删除用户vpnip
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("cmd", Constants.NTC_IP_REUSE_USER_DELETE);
|
||||
params.put("server_ip", ip);
|
||||
params.put("user_name", entity.getUserName());
|
||||
String url =Constants.IP_REUSE_CALL_CGI_URL ;
|
||||
String recv = ConfigServiceUtil.getCGI(url, params);
|
||||
}
|
||||
|
||||
public List<UserManage> findUsers() {
|
||||
|
||||
@@ -565,4 +565,6 @@ userPasswordSet=UserPasswordSet
|
||||
userDelete=UserDelete
|
||||
userGet=UserGet
|
||||
userList=UserList
|
||||
ip_reuse_call_cgi_url=http://192.168.11.137:8090/command/?cmd=
|
||||
ip_reuse_call_cgi_url=http://192.168.11.137:8090/command
|
||||
ipNumGet=IpNumGet
|
||||
allIpGet=AllIpGet
|
||||
@@ -463,7 +463,8 @@ var resetIndex = function(){
|
||||
</c:forEach>
|
||||
|
||||
<br>
|
||||
<%@include file="/WEB-INF/include/form/areaInfo.jsp"%>
|
||||
<input name="isAreaEffective" type="hidden" value="0">
|
||||
<%-- <%@include file="/WEB-INF/include/form/areaInfo.jsp"%> --%>
|
||||
<br>
|
||||
<%@include file="/WEB-INF/include/form/basicInfo.jsp" %>
|
||||
</div>
|
||||
|
||||
@@ -50,15 +50,14 @@
|
||||
if(audit == 1){
|
||||
// $.getJSON(requestUrl,function(data,status){});
|
||||
$.ajax({
|
||||
type:'get',
|
||||
timeout:15000,// 超时时间
|
||||
url:requestUrl+addrPoolId,
|
||||
dataType:'jsonp',
|
||||
data:{"addrPoolId":addrPoolId,"cmd":"IpNumGet"},
|
||||
url:"${ctx}/maintenance/ipMultiplexPoolCfg/getCGIInfo",
|
||||
async:true,
|
||||
success:function(data,status){
|
||||
if(status == "success"){
|
||||
if(status == "success"){
|
||||
$(td).html(data.num);
|
||||
}
|
||||
}
|
||||
},
|
||||
complete:function(XMLHttpRequest,status){
|
||||
if(status=="timeout"){
|
||||
@@ -78,34 +77,40 @@
|
||||
});
|
||||
function getInfo(obj){
|
||||
var addrPoolId = $(obj).attr("addrPoolId");
|
||||
$.ajax({
|
||||
type:'get',
|
||||
url:'http://192.168.11.137:8090/command/?cmd=AllIpGet&addr_pool_id='+addrPoolId,
|
||||
dataType:'jsonp',
|
||||
async:true,
|
||||
success:function(data,status){
|
||||
//var dataArr = [];
|
||||
var dataArr = data.candidate_ip;
|
||||
var html = ""
|
||||
html = "<div style='width:98%;overflow: auto;margin-top: 10px;height: 300px;margin-left: 1%;margin-right: 1%;'>"
|
||||
html+="<table class='table table-bordered table-condensed text-nowrap' style='width: 100%;'>";
|
||||
html+="<tbody>";
|
||||
if(dataArr.length == 0){
|
||||
html+="<tr>";
|
||||
html+="<td>("+"<spring:message code="nothing"/>"+")</td>";
|
||||
html+="</tr>";
|
||||
}
|
||||
for(i=0;i<dataArr.length;i++){
|
||||
html+="<tr>";
|
||||
html+="<td>"+dataArr[i]+"</td>";
|
||||
html+="</tr>";
|
||||
}
|
||||
html+="</tbody>";
|
||||
html+="</table>";
|
||||
html+="</div>";
|
||||
top.$.jBox(html,{width: $(document).width()*0.4,height: 380,persistent: false,title:"<spring:message code="available_ip"/>", buttons:{"<spring:message code="close"/>":true}});
|
||||
}
|
||||
});
|
||||
$.ajax({
|
||||
timeout:15000,// 超时时间
|
||||
data:{"addrPoolId":addrPoolId,"cmd":"AllIpGet"},
|
||||
url:"${ctx}/maintenance/ipMultiplexPoolCfg/getCGIInfo",
|
||||
async:true,
|
||||
success:function(data,status){
|
||||
var dataArr = data.candidate_ip;
|
||||
var html = ""
|
||||
html = "<div style='width:98%;overflow: auto;margin-top: 10px;height: 300px;margin-left: 1%;margin-right: 1%;'><br>"
|
||||
html+="<table class='table table-bordered table-condensed text-nowrap' style='width: 100%;'>";
|
||||
html+="<tbody>";
|
||||
if(dataArr.length == 0){
|
||||
html+="<tr>";
|
||||
html+="<td>("+"<spring:message code="no_data"/>"+")</td>";
|
||||
html+="</tr>";
|
||||
}
|
||||
for(i=0;i<dataArr.length;i++){
|
||||
html+="<tr>";
|
||||
html+="<td>"+dataArr[i]+"</td>";
|
||||
html+="</tr>";
|
||||
}
|
||||
html+="</tbody>";
|
||||
html+="</table>";
|
||||
html+="</div>";
|
||||
top.$.jBox(html,{width: $(document).width()*0.4,height: 380,persistent: false,title:"<spring:message code="available_ip"/>", buttons:{"<spring:message code="close"/>":true}});
|
||||
},
|
||||
complete:function(XMLHttpRequest,status){
|
||||
if(status=="timeout"){
|
||||
$(td).html(timeout);
|
||||
}else if(status !="success"){
|
||||
$(td).html(failed);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
|
||||
@@ -48,7 +48,7 @@ var saveIp=function(){
|
||||
value="${user.serverIp}" labelName="user.serverIp"
|
||||
notAllowSelectParent="true" enableSearch="true"
|
||||
notAllowSelectRoot="true" checkedPS="ps" unCheckedPS="ps"
|
||||
labelValue="${user.serverIp}" title="vpn_ip"
|
||||
labelValue="${fn:substring(user.serverIp,0,(fn:length(user.serverIp)-1)) }" title="vpn_ip"
|
||||
url="/maintenance/userManage/treeData?isLeafShow=false&cfgType=3&specific=true" extId="0"
|
||||
checked="true" cssClass="form-control required" />
|
||||
</div>
|
||||
|
||||
@@ -239,12 +239,13 @@
|
||||
<input type="checkbox" class="i-checks child-checks" id="${indexCfg.id}" isValid="${cfg.isValid}" value="0" >
|
||||
</td>
|
||||
<td>${indexCfg.userName }</td>
|
||||
<td class="no_substr" title="${indexCfg.serverIp }"><a href="javascript:dictDetail('${indexCfg.serverIp}','${indexCfg.userName}')">
|
||||
<c:if test="${fn:length(indexCfg.serverIp)>28}">
|
||||
${fn:substring(indexCfg.serverIp,0,20)}..
|
||||
<c:set var="serverIp" value="${fn:substring(indexCfg.serverIp,0,(fn:length(indexCfg.serverIp)-1)) }"></c:set>
|
||||
<td class="no_substr" title="${serverIp }"><a href="javascript:dictDetail('${serverIp}','${indexCfg.userName}')">
|
||||
<c:if test="${fn:length(serverIp)>28}">
|
||||
${fn:substring(serverIp,0,20)}..
|
||||
</c:if>
|
||||
<c:if test="${fn:length(indexCfg.serverIp)<=28}">
|
||||
${indexCfg.serverIp }
|
||||
<c:if test="${fn:length(serverIp)<=28}">
|
||||
${serverIp }
|
||||
</c:if>
|
||||
</a></td>
|
||||
<td>${indexCfg.remarks }</td>
|
||||
|
||||
@@ -92,7 +92,7 @@
|
||||
value="${user.serverIp}" labelName="user.serverIp"
|
||||
notAllowSelectParent="true" enableSearch="true"
|
||||
notAllowSelectRoot="true" checkedPS="ps" unCheckedPS="ps"
|
||||
labelValue="${user.serverIp}" title="vpn_ip"
|
||||
labelValue="${fn:substring(user.serverIp,0,(fn:length(user.serverIp)-1)) }" title="vpn_ip"
|
||||
url="/maintenance/userManage/treeData?isLeafShow=false&cfgType=3&specific=true" extId="0"
|
||||
checked="true" cssClass="form-control required" />
|
||||
</div>
|
||||
@@ -123,9 +123,15 @@
|
||||
<form:input path="userName" htmlEscape="false" maxlength="50"
|
||||
readonly="true" class="required form-control" />
|
||||
</c:if> --%>
|
||||
|
||||
<c:if test="${!(empty user.id)}">
|
||||
<form:input path="userName" readonly="true" htmlEscape="false" maxlength="50"
|
||||
class="required form-control" />
|
||||
</c:if>
|
||||
<c:if test="${empty user.id}">
|
||||
<form:input path="userName" htmlEscape="false" maxlength="50"
|
||||
class="required form-control" />
|
||||
</c:if>
|
||||
|
||||
</div>
|
||||
<div for="userName"></div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user