vpn 用户管理修改新增修改和删除逻辑
ip地址池增加存在可用ip地址池才在策略展示
This commit is contained in:
@@ -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";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user