|
@@ -50,6 +50,7 @@ import cn.com.qmth.examcloud.core.basic.api.bean.OrgBean;
|
|
import cn.com.qmth.examcloud.core.basic.api.request.GetOrgReq;
|
|
import cn.com.qmth.examcloud.core.basic.api.request.GetOrgReq;
|
|
import cn.com.qmth.examcloud.core.basic.api.response.GetOrgResp;
|
|
import cn.com.qmth.examcloud.core.basic.api.response.GetOrgResp;
|
|
import cn.com.qmth.examcloud.core.examwork.base.enums.ExamProperty;
|
|
import cn.com.qmth.examcloud.core.examwork.base.enums.ExamProperty;
|
|
|
|
+import cn.com.qmth.examcloud.core.examwork.base.util.IpUtil;
|
|
import cn.com.qmth.examcloud.core.examwork.dao.ExamIpLimitRepo;
|
|
import cn.com.qmth.examcloud.core.examwork.dao.ExamIpLimitRepo;
|
|
import cn.com.qmth.examcloud.core.examwork.dao.ExamOrgPropertyRepo;
|
|
import cn.com.qmth.examcloud.core.examwork.dao.ExamOrgPropertyRepo;
|
|
import cn.com.qmth.examcloud.core.examwork.dao.ExamPropertyRepo;
|
|
import cn.com.qmth.examcloud.core.examwork.dao.ExamPropertyRepo;
|
|
@@ -901,16 +902,18 @@ public class ExamServiceImpl implements ExamService {
|
|
Boolean totalLimit = getExamLimitProperty(examId, ipTotalLimit.getId(), false);
|
|
Boolean totalLimit = getExamLimitProperty(examId, ipTotalLimit.getId(), false);
|
|
if (totalLimit) {
|
|
if (totalLimit) {
|
|
//全部白名单模式:不在白名单中,才限制访问
|
|
//全部白名单模式:不在白名单中,才限制访问
|
|
- int count = examIpLimitRepo.countByExamIdAndLimitTypeAndIp(examId, IpLimitType.HAS_ACCESS.name(), realIp);
|
|
|
|
- if (count == 0) {
|
|
|
|
|
|
+// int count = examIpLimitRepo.countByExamIdAndLimitTypeAndIp(examId, IpLimitType.HAS_ACCESS.name(), realIp);
|
|
|
|
+// if (count == 0) {
|
|
|
|
+ if(checkInIpConfig(realIp, examId, IpLimitType.HAS_ACCESS)) {
|
|
return true;
|
|
return true;
|
|
} else {
|
|
} else {
|
|
// return getCenterLimit(manager, examId, accessUser.getUserId(), realIp);
|
|
// return getCenterLimit(manager, examId, accessUser.getUserId(), realIp);
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
//全部黑名单模式:在黑名单中,才限制访问
|
|
//全部黑名单模式:在黑名单中,才限制访问
|
|
- int count = examIpLimitRepo.countByExamIdAndLimitTypeAndIp(examId, IpLimitType.NO_ACCESS.name(), realIp);
|
|
|
|
- if (count > 0) {
|
|
|
|
|
|
+// int count = examIpLimitRepo.countByExamIdAndLimitTypeAndIp(examId, IpLimitType.NO_ACCESS.name(), realIp);
|
|
|
|
+// if (count > 0) {
|
|
|
|
+ if(!checkInIpConfig(realIp, examId, IpLimitType.NO_ACCESS)) {
|
|
return true;
|
|
return true;
|
|
} else {
|
|
} else {
|
|
// return getCenterLimit(manager, examId, accessUser.getUserId(), realIp);
|
|
// return getCenterLimit(manager, examId, accessUser.getUserId(), realIp);
|
|
@@ -919,6 +922,55 @@ public class ExamServiceImpl implements ExamService {
|
|
}
|
|
}
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ private boolean checkInIpConfig(String realIp, Long examId,IpLimitType type) {
|
|
|
|
+ List <ExamIpLimitEntity> ips=examIpLimitRepo.findByExamIdAndLimitType(examId, type.name());
|
|
|
|
+ if(CollectionUtils.isEmpty(ips)) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ for(ExamIpLimitEntity ip:ips) {
|
|
|
|
+ if(StringUtils.isNotBlank(ip.getIp())) {
|
|
|
|
+ if(checkIpEq(realIp, ip.getIp())) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private boolean checkIpEq(String realIp,String ipConfig) {
|
|
|
|
+ if(ipConfig.indexOf("-")==-1) {
|
|
|
|
+ return realIp.equals(ipConfig);
|
|
|
|
+ }else {
|
|
|
|
+ String[] ss1=realIp.split("\\.");
|
|
|
|
+ String[] ss2=ipConfig.split("\\.");
|
|
|
|
+ if(ss1.length!=ss2.length) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ for(int i=0;i<=2;i++) {
|
|
|
|
+ if(!ss1[i].equals(ss2[i])) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ String[] ssCon=ss2[3].split("-");
|
|
|
|
+ if(ssCon.length!=2) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ try {
|
|
|
|
+ int val=Integer.valueOf(ss1[3]);
|
|
|
|
+ int start=Integer.valueOf(ssCon[0]);
|
|
|
|
+ int end=Integer.valueOf(ssCon[1]);
|
|
|
|
+ if(start<=val&&val<=end) {
|
|
|
|
+ return true;
|
|
|
|
+ }else {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
// private boolean getCenterLimit(DynamicEnumManager manager, Long examId, Long studentId, String realIp) {
|
|
// private boolean getCenterLimit(DynamicEnumManager manager, Long examId, Long studentId, String realIp) {
|
|
// //学习中心访问控制
|
|
// //学习中心访问控制
|
|
@@ -958,6 +1010,7 @@ public class ExamServiceImpl implements ExamService {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void saveIpLimit(String ids, ExamIpLimitEntity entity) {
|
|
public void saveIpLimit(String ids, ExamIpLimitEntity entity) {
|
|
|
|
+ IpUtil.checkIp(entity.getIp());
|
|
//ids不为空,说明是批量设置限制类型
|
|
//ids不为空,说明是批量设置限制类型
|
|
if (StringUtils.isNotBlank(ids)) {
|
|
if (StringUtils.isNotBlank(ids)) {
|
|
List<Long> ipIds = getIdsByPath(ids);
|
|
List<Long> ipIds = getIdsByPath(ids);
|