From 77d84113924f256e841dc0b0e9ced95f5afad12d Mon Sep 17 00:00:00 2001 From: jamiesun <âœjamiesun.net@gmail.com> Date: Thu, 23 May 2019 22:49:49 +0800 Subject: [PATCH] api --- .../toughradius/component/LangResources.java | 5 +- .../toughradius/config/AccessInterceptor.java | 56 ++++++++++--------- .../org/toughradius/config/ApiAccess.java | 11 ---- .../java/org/toughradius/config/Constant.java | 5 ++ .../org/toughradius/config/MvcConfigurer.java | 6 +- .../controller/BrasController.java | 8 +-- .../controller/ConfigController.java | 27 +++++++-- .../controller/DashboardController.java | 16 +++--- .../controller/MainController.java | 8 +-- .../controller/OnlineController.java | 22 ++------ .../controller/SubsribeController.java | 16 +++--- .../controller/SyslogController.java | 3 +- .../controller/TicketController.java | 2 +- .../org/toughradius/form/ApiConfigForm.java | 32 +++++++++++ .../toughradius/handler/RadsecHandler.java | 40 ++++++------- src/main/resources/application.properties | 3 +- src/main/resources/static/admin/config.js | 42 +++++++++++++- src/main/resources/static/admin/main.js | 2 +- src/main/resources/static/login.html | 1 + 19 files changed, 194 insertions(+), 111 deletions(-) delete mode 100644 src/main/java/org/toughradius/config/ApiAccess.java create mode 100644 src/main/java/org/toughradius/form/ApiConfigForm.java diff --git a/src/main/java/org/toughradius/component/LangResources.java b/src/main/java/org/toughradius/component/LangResources.java index 405d58a1..c882ec47 100644 --- a/src/main/java/org/toughradius/component/LangResources.java +++ b/src/main/java/org/toughradius/component/LangResources.java @@ -6,6 +6,7 @@ import org.toughradius.common.ValidateUtil; import org.toughradius.config.LangElement; +import javax.annotation.PostConstruct; import java.io.*; import java.lang.reflect.Type; import java.util.ArrayList; @@ -13,13 +14,13 @@ import java.util.List; import java.util.Map; - @Component public class LangResources { private Map langMap = new HashMap(); - public LangResources() { + @PostConstruct + public void LangResources() { try { InputStream fis = LangResources.class.getClassLoader().getResourceAsStream("lang_resource.json"); BufferedReader reader = new BufferedReader(new InputStreamReader(fis)); diff --git a/src/main/java/org/toughradius/config/AccessInterceptor.java b/src/main/java/org/toughradius/config/AccessInterceptor.java index 123eeda1..2ccdbf0d 100644 --- a/src/main/java/org/toughradius/config/AccessInterceptor.java +++ b/src/main/java/org/toughradius/config/AccessInterceptor.java @@ -4,20 +4,20 @@ import com.google.gson.Gson; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; -import org.springframework.web.method.HandlerMethod; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; +import org.toughradius.common.RestResult; import org.toughradius.common.ValidateUtil; import org.toughradius.common.coder.Base64; +import org.toughradius.component.ConfigService; import org.toughradius.component.LangResources; import org.toughradius.component.Memarylogger; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import java.lang.reflect.Method; @Configuration -public class AccessInterceptor extends HandlerInterceptorAdapter { +public class AccessInterceptor extends HandlerInterceptorAdapter implements Constant { @Autowired protected Memarylogger logger; @@ -31,36 +31,38 @@ public class AccessInterceptor extends HandlerInterceptorAdapter { @Autowired protected ApplicationConfig appConfig; + @Autowired + protected ConfigService cfgService; + @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { + String header = request.getHeader("Authorization"); response.setContentType("application/json;charset=UTF-8"); - if (handler instanceof HandlerMethod){ - String header = request.getHeader("Authorization"); - if(ValidateUtil.isNotEmpty(header) && !header.substring(0, 6).equals("Basic ")){ - response.getWriter().print(gson.toJson(langs.tr("未支持的验证方式",request.getHeader("Accept-Language")))); - return false; - } - HandlerMethod handlerMethod = (HandlerMethod) handler; - Method method = handlerMethod.getMethod(); - ApiAccess access = method.getAnnotation(ApiAccess.class); - if(access!=null){ - String basicAuthEncoded = header.substring(6); - //will contain "bob:secret" - String basicAuthAsString = new String(new Base64().decode(basicAuthEncoded.getBytes())); - if(!basicAuthAsString.trim().equals(String.format("%s:%s", appConfig.getApikey(),appConfig.getApisecret()))){ - response.getWriter().print(gson.toJson(langs.tr("未授权的操作",request.getHeader("Accept-Language")))); - return false; - }else{ - return true; - } - }else { - return true; - } - }else { + if(ValidateUtil.isEmpty(header)){ + response.setCharacterEncoding("UTF-8"); + response.setHeader("Authorization","Required"); + response.setHeader("WWW-Authentication ","Basic"); + response.setStatus(HttpServletResponse.SC_FORBIDDEN); + response.getWriter().print(gson.toJson(new RestResult(1,"Forbidden, unauthorized user"))); + return false; + } + if(ValidateUtil.isNotEmpty(header) && !header.substring(0, 6).equals("Basic ")){ + response.setStatus(HttpServletResponse.SC_FORBIDDEN); + response.getWriter().print(gson.toJson(new RestResult(1,"Unsupported authentication methods"))); + return false; + } + String basicAuthEncoded = header.substring(6); + //will contain "bob:secret" + String basicAuthAsString = new String(new Base64().decode(basicAuthEncoded.getBytes())); + if(!basicAuthAsString.trim().equals(String.format("%s:%s", + cfgService.getStringValue(API_MODULE,API_USERNAME), + cfgService.getStringValue(API_MODULE,API_PASSWD)))){ + response.getWriter().print(gson.toJson(new RestResult(1,"Authentication failure"))); + return false; + }else{ return true; } - } @Override diff --git a/src/main/java/org/toughradius/config/ApiAccess.java b/src/main/java/org/toughradius/config/ApiAccess.java deleted file mode 100644 index d429a458..00000000 --- a/src/main/java/org/toughradius/config/ApiAccess.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.toughradius.config; - -import java.lang.annotation.*; - -@Target(ElementType.METHOD) -@Retention(RetentionPolicy.RUNTIME) -@Inherited -@Documented -public @interface ApiAccess { - String value() default ""; -} diff --git a/src/main/java/org/toughradius/config/Constant.java b/src/main/java/org/toughradius/config/Constant.java index 09554c99..6ffd8cc4 100644 --- a/src/main/java/org/toughradius/config/Constant.java +++ b/src/main/java/org/toughradius/config/Constant.java @@ -14,6 +14,11 @@ public interface Constant { public final static String SYSTEM_USERNAME = "systemUsername"; public final static String SYSTEM_USERPWD = "systemUserpwd"; + public final static String API_MODULE = "api"; + public final static String API_TYPE = "apiType"; + public final static String API_USERNAME = "apiUsername"; + public final static String API_PASSWD = "apiPasswd"; + public final static String SMS_MODULE = "sms"; public final static String SMS_GATEWAY = "smsGateway"; public final static String SMS_APPID = "smsAppid"; diff --git a/src/main/java/org/toughradius/config/MvcConfigurer.java b/src/main/java/org/toughradius/config/MvcConfigurer.java index 84c7c33b..1eec287a 100644 --- a/src/main/java/org/toughradius/config/MvcConfigurer.java +++ b/src/main/java/org/toughradius/config/MvcConfigurer.java @@ -17,6 +17,10 @@ public class MvcConfigurer extends WebMvcConfigurerAdapter { @Autowired private PortalConfig portalConfig; + @Autowired + private AccessInterceptor accessInterceptor; + + @Override public void addViewControllers(ViewControllerRegistry registry) { registry.addViewController("/error").setViewName("/templates/global_error.html"); @@ -30,7 +34,7 @@ public void configurePathMatch(PathMatchConfigurer configurer) { } public void addInterceptors(InterceptorRegistry registry) { - registry.addInterceptor(new AccessInterceptor()).addPathPatterns("/api/**"); + registry.addInterceptor(accessInterceptor).addPathPatterns("/api/v6/**"); registry.addInterceptor(new SessionInterceptor()).addPathPatterns("/admin/**") .excludePathPatterns("/") .excludePathPatterns("/admin") diff --git a/src/main/java/org/toughradius/controller/BrasController.java b/src/main/java/org/toughradius/controller/BrasController.java index f7678a27..4cf29cd7 100644 --- a/src/main/java/org/toughradius/controller/BrasController.java +++ b/src/main/java/org/toughradius/controller/BrasController.java @@ -23,7 +23,7 @@ public class BrasController { @Autowired private BrasService brasService; - @GetMapping(value = {"/admin/bras/query"}) + @GetMapping(value = {"/api/v6/bras/query","/admin/bras/query"}) @ResponseBody public List queryBras(){ List result = new ArrayList(); @@ -36,7 +36,7 @@ public List queryBras(){ return result; } - @PostMapping(value = {"/admin/bras/create"}) + @PostMapping(value = {"/api/v6/bras/create","/admin/bras/create"}) @ResponseBody public RestResult addBras(Bras bras){ try{ @@ -58,7 +58,7 @@ public RestResult addBras(Bras bras){ } } - @PostMapping(value = {"/admin/bras/update"}) + @PostMapping(value = {"/api/v6/bras/update","/admin/bras/update"}) @ResponseBody public RestResult updateBras(Bras bras){ try{ @@ -73,7 +73,7 @@ public RestResult updateBras(Bras bras){ } } - @GetMapping(value = {"/admin/bras/delete"}) + @GetMapping(value = {"/api/v6/bras/delete","/admin/bras/delete"}) @ResponseBody public RestResult deleteBras(Long id){ try{ diff --git a/src/main/java/org/toughradius/controller/ConfigController.java b/src/main/java/org/toughradius/controller/ConfigController.java index 8efbee85..f941fc52 100644 --- a/src/main/java/org/toughradius/controller/ConfigController.java +++ b/src/main/java/org/toughradius/controller/ConfigController.java @@ -13,6 +13,7 @@ import org.toughradius.component.Memarylogger; import org.toughradius.config.Constant; import org.toughradius.entity.Config; +import org.toughradius.form.ApiConfigForm; import org.toughradius.form.RadiusConfigForm; import org.toughradius.form.SmsConfigForm; import org.toughradius.form.WlanCongigForm; @@ -31,7 +32,7 @@ public class ConfigController implements Constant { @Autowired private ConfigService configService; - @GetMapping(value = {"/admin/config/load/{module}"}) + @GetMapping(value = {"/api/v6/config/load/{module}","/admin/config/load/{module}"}) @ResponseBody public Map loadRadiusConfig(@PathVariable(name = "module")String module){ Map result = new HashMap(); @@ -51,7 +52,7 @@ public Map loadRadiusConfig(@PathVariable(name = "module")String module){ * @param form * @return */ - @PostMapping(value = {"/admin/config/radius/update"}) + @PostMapping(value = {"/api/v6/radius/update","/admin/config/radius/update"}) @ResponseBody public RestResult updateRadiusConfig(RadiusConfigForm form){ try{ @@ -70,7 +71,7 @@ public RestResult updateRadiusConfig(RadiusConfigForm form){ * @param form * @return */ - @PostMapping(value = {"/admin/config/sms/update"}) + @PostMapping(value = {"/api/v6/sms/update","/admin/config/sms/update"}) @ResponseBody public RestResult updateSmsConfig(SmsConfigForm form){ try{ @@ -84,13 +85,31 @@ public RestResult updateSmsConfig(SmsConfigForm form){ return new RestResult(0,"update sms config done"); } + /** + * API 配置更新呢 + * @param form + * @return + */ + @PostMapping(value = {"/admin/config/api/update"}) + @ResponseBody + public RestResult updateApiConfig(ApiConfigForm form){ + try{ + configService.updateConfig(new Config(API_MODULE,API_TYPE,form.getApiType())); + configService.updateConfig(new Config(API_MODULE,API_USERNAME,form.getApiUsername())); + configService.updateConfig(new Config(API_MODULE,API_PASSWD,form.getApiPasswd())); + }catch(Exception e){ + logger.error("update config error",e, Memarylogger.SYSTEM); + } + return new RestResult(0,"update api config done"); + } + /** * 无线认证配置更新 * @param form * @return */ - @PostMapping(value = {"/admin/config/wlan/update"}) + @PostMapping(value = {"/api/v6/wlan/update","/admin/config/wlan/update"}) @ResponseBody public RestResult updateWlanConfig(WlanCongigForm form){ try{ diff --git a/src/main/java/org/toughradius/controller/DashboardController.java b/src/main/java/org/toughradius/controller/DashboardController.java index 56e32c97..4295bb58 100644 --- a/src/main/java/org/toughradius/controller/DashboardController.java +++ b/src/main/java/org/toughradius/controller/DashboardController.java @@ -31,43 +31,43 @@ public class DashboardController { @Autowired private RadiusOnlineStat radiusOnlineStat; - @GetMapping("/admin/radius/stat") + @GetMapping({"/api/v6/radius/stat","/admin/radius/stat"}) @ResponseBody public Map queryRadiusStat(){ return radiusStat.getData(); } - @GetMapping({"/radius/caststat","/admin/radius/caststat"}) + @GetMapping({"/api/v6/radius/caststat","/admin/radius/caststat"}) @ResponseBody public Map queryRadiusCastStat(){ return radiusCastStat.getData(); } - @GetMapping({"/radius/authstat","/admin/radius/authstat"}) + @GetMapping({"/api/v6/radius/authstat","/admin/radius/authstat"}) @ResponseBody public Map queryRadiusAuthStat(){ return radiusAuthStat.getData(); } - @GetMapping({"/radius/onlinestat","/admin/radius/onlinestat"}) + @GetMapping({"/api/v6/radius/onlinestat","/admin/radius/onlinestat"}) @ResponseBody public Map queryRadiusOnlineStat(){ return radiusOnlineStat.getData(); } - @GetMapping(value = {"/admin/dashboard/cpuuse"}) + @GetMapping({"/api/v6/cpuuse","/admin/dashboard/cpuuse"}) @ResponseBody public RestResult cpuuse(){ return new RestResult(0,"ok", SystemUtil.getCpuUsage()); } - @GetMapping(value = {"/admin/dashboard/memuse"}) + @GetMapping(value = {"/api/v6/memuse","/admin/dashboard/memuse"}) @ResponseBody public RestResult memuse(){ return new RestResult(0,"ok", SystemUtil.getMemUsage()); } - @GetMapping(value = {"/admin/dashboard/diskuse"}) + @GetMapping({"/api/v6/diskuse","/admin/dashboard/diskuse"}) @ResponseBody public RestResult diskuse(){ try { @@ -78,7 +78,7 @@ public RestResult diskuse(){ } } - @GetMapping(value = {"/admin/dashboard/uptime"}) + @GetMapping({"/admin/dashboard/uptime"}) @ResponseBody public String uptime(){ return String.format(" 应用系统运行时长 %s ", DateTimeUtil.formatSecond(SystemUtil.getUptime()/1000)); diff --git a/src/main/java/org/toughradius/controller/MainController.java b/src/main/java/org/toughradius/controller/MainController.java index 5f36221f..0da3e108 100644 --- a/src/main/java/org/toughradius/controller/MainController.java +++ b/src/main/java/org/toughradius/controller/MainController.java @@ -99,15 +99,15 @@ public RestResult sessionHandeler(HttpSession session, HttpServletRequest reques @ResponseBody public RestResult loginHandler(String username, String password, HttpSession session) { try { - String sysUserName = configService.getStringValue(ConfigService.SYSTEM_MODULE,ConfigService.SYSTEM_USERNAME); - String sysUserPwd = configService.getStringValue(ConfigService.SYSTEM_MODULE,ConfigService.SYSTEM_USERPWD); + String sysUserName = configService.getStringValue(SYSTEM_MODULE,SYSTEM_USERNAME); + String sysUserPwd = configService.getStringValue(SYSTEM_MODULE,SYSTEM_USERPWD); if(ValidateUtil.isEmpty(sysUserName)){ sysUserName = "admin"; - configService.updateConfig(new Config(ConfigService.SYSTEM_MODULE,ConfigService.SYSTEM_USERNAME,sysUserName,"")); + configService.updateConfig(new Config(SYSTEM_MODULE,SYSTEM_USERNAME,sysUserName,"")); } if(ValidateUtil.isEmpty(sysUserPwd)){ sysUserPwd = CoderUtil.md5Salt("root"); - configService.updateConfig(new Config(ConfigService.SYSTEM_MODULE,ConfigService.SYSTEM_USERPWD,sysUserPwd,"")); + configService.updateConfig(new Config(SYSTEM_MODULE,SYSTEM_USERPWD,sysUserPwd,"")); } if(username.equals(sysUserName) && CoderUtil.md5Salt(password).equals(sysUserPwd)){ diff --git a/src/main/java/org/toughradius/controller/OnlineController.java b/src/main/java/org/toughradius/controller/OnlineController.java index 3eecab88..191b7499 100644 --- a/src/main/java/org/toughradius/controller/OnlineController.java +++ b/src/main/java/org/toughradius/controller/OnlineController.java @@ -3,7 +3,6 @@ import org.toughradius.common.PageResult; import org.toughradius.common.RestResult; import org.toughradius.common.ValidateUtil; -import org.toughradius.config.ApiAccess; import org.toughradius.entity.RadiusOnline; import org.toughradius.component.OnlineCache; import org.springframework.beans.factory.annotation.Autowired; @@ -20,15 +19,14 @@ public class OnlineController { private OnlineCache onlineCache; //在线查询 - @ApiAccess - @GetMapping("/admin/online/query") + @GetMapping({"/api/v6/online/query","/admin/online/query"}) public PageResult queryOnlineHandler(@RequestParam(defaultValue = "0") int start, @RequestParam(defaultValue = "40") int count, String nodeId, Integer invlan, Integer outVlan, String nasAddr, String nasId, String beginTime, String endTime, String keyword, String sort){ return onlineCache.queryOnlinePage(start,count,nodeId,invlan,outVlan,nasAddr,nasId,beginTime,endTime,keyword,sort); } - @GetMapping("/admin/online/unlock") + @GetMapping({"/api/v6/online/unlock", "/admin/online/unlock"}) public RestResult unlockOnlineHandler(@RequestParam(name = "ids")String ids, @RequestParam(name = "sessionId")String sessionId){ if(ValidateUtil.isNotEmpty(ids)){ @@ -42,13 +40,13 @@ public RestResult unlockOnlineHandler(@RequestParam(name = "ids")String ids, } } //清理在线 - @GetMapping("/admin/online/clear") + @GetMapping({"/api/v6/online/clear","/admin/online/clear"}) public RestResult clearOnlineHandler( String nodeId,Integer invlan, Integer outVlan, String nasAddr, String nasId, String beginTime, String endTime, String keyword){ onlineCache.clearOnlineByFilter(nodeId,invlan, outVlan,nasAddr,nasId,beginTime,endTime,keyword); return new RestResult(0,"success"); } //一个下线 - @GetMapping("/admin/online/delete") + @GetMapping({"/api/v6/online/delete","/admin/online/delete"}) public RestResult DeleteOnlineHandler(String ids){ for(String oid : ids.split("/admin,")){ onlineCache.removeOnline(oid); @@ -56,21 +54,11 @@ public RestResult DeleteOnlineHandler(String ids){ return new RestResult(0,"success"); } - @GetMapping("/admin/online/query/byids") + @GetMapping({"/api/v6/online/query/byids","/admin/online/query/byids"}) public List queryOnlineByIds(String ids){ return onlineCache.queryOnlineByIds(ids); } - @GetMapping("/admin/online/query/noamount") - public List queryNoAmountOnline(){ - return onlineCache.queryNoAmountOnline(); - } - - //清理在线用户(超时的) - @GetMapping("/admin/online/autoclear") - public void autoClearHandler(int interim_times){ - onlineCache.clearOvertimeTcRadiusOnline(interim_times); - } } diff --git a/src/main/java/org/toughradius/controller/SubsribeController.java b/src/main/java/org/toughradius/controller/SubsribeController.java index 102bf50d..1e6d02f4 100644 --- a/src/main/java/org/toughradius/controller/SubsribeController.java +++ b/src/main/java/org/toughradius/controller/SubsribeController.java @@ -23,7 +23,7 @@ public class SubsribeController { @Autowired protected SubscribeService subscribeService; - @GetMapping(value = {"/admin/subscribe/query"}) + @GetMapping(value = {"/api/v6/subscribe/query","/admin/subscribe/query"}) @ResponseBody public PageResult querySubscribe(@RequestParam(defaultValue = "0") int start, @RequestParam(defaultValue = "40") int count, @@ -55,7 +55,7 @@ public PageResult querySubscribe(@RequestParam(defaultValue = "0") in return result; } - @GetMapping(value = {"/admin/subscribe/detail"}) + @GetMapping(value = {"/api/v6/subscribe/detail","/admin/subscribe/detail"}) @ResponseBody public RestResult querySubscribeDetail(Long id){ try{ @@ -66,7 +66,7 @@ public RestResult querySubscribeDetail(Long id){ } } - @PostMapping(value = {"/admin/subscribe/create"}) + @PostMapping(value = {"/api/v6/subscribe/create","/admin/subscribe/create"}) @ResponseBody public RestResult addSubscribe(SubscribeForm form){ try{ @@ -90,7 +90,7 @@ public RestResult addSubscribe(SubscribeForm form){ } - @PostMapping(value = {"/admin/subscribe/batchcreate"}) + @PostMapping(value = {"/api/v6/subscribe/batchcreate","/admin/subscribe/batchcreate"}) @ResponseBody public RestResult batchAddSubscribe(SubscribeForm form){ try{ @@ -117,7 +117,7 @@ public RestResult batchAddSubscribe(SubscribeForm form){ } } - @PostMapping(value = {"/admin/subscribe/uppwd"}) + @PostMapping(value = {"/api/v6/subscribe/uppwd","/admin/subscribe/uppwd"}) @ResponseBody public RestResult updateSubscribe(SubscribeForm form){ try{ @@ -135,7 +135,7 @@ public RestResult updateSubscribe(SubscribeForm form){ } } - @GetMapping(value = {"/admin/subscribe/release"}) + @GetMapping(value = {"/api/v6/subscribe/release","/admin/subscribe/release"}) @ResponseBody public RestResult releaseSubscribe(String ids){ try{ @@ -149,7 +149,7 @@ public RestResult releaseSubscribe(String ids){ } } - @PostMapping(value = {"/admin/subscribe/update"}) + @PostMapping(value = {"/api/v6/subscribe/update","/admin/subscribe/update"}) @ResponseBody public RestResult updatePassword(SubscribeForm form){ try{ @@ -166,7 +166,7 @@ public RestResult updatePassword(SubscribeForm form){ } } - @GetMapping(value = {"/admin/subscribe/delete"}) + @GetMapping(value = {"/api/v6/subscribe/delete","/admin/subscribe/delete"}) @ResponseBody public RestResult delete(String ids){ try{ diff --git a/src/main/java/org/toughradius/controller/SyslogController.java b/src/main/java/org/toughradius/controller/SyslogController.java index 0ca78eae..3bfb2778 100644 --- a/src/main/java/org/toughradius/controller/SyslogController.java +++ b/src/main/java/org/toughradius/controller/SyslogController.java @@ -1,7 +1,6 @@ package org.toughradius.controller; import org.toughradius.common.PageResult; -import org.toughradius.common.ValidateUtil; import org.toughradius.entity.TraceMessage; import org.toughradius.component.Memarylogger; import org.springframework.beans.factory.annotation.Autowired; @@ -15,7 +14,7 @@ public class SyslogController { @Autowired private Memarylogger logger; - @GetMapping("/admin/syslog/query") + @GetMapping({"/api/v6/syslog/query","/admin/syslog/query"}) public PageResult queryTraceMessage(@RequestParam(defaultValue = "0") int start, @RequestParam(defaultValue = "40") int count, String startDate, String endDate, String type, String username, String keyword){ return logger.queryMessage(start,count,startDate,endDate,type, username,keyword); diff --git a/src/main/java/org/toughradius/controller/TicketController.java b/src/main/java/org/toughradius/controller/TicketController.java index b50274d5..f7ccacfc 100644 --- a/src/main/java/org/toughradius/controller/TicketController.java +++ b/src/main/java/org/toughradius/controller/TicketController.java @@ -21,7 +21,7 @@ public class TicketController { @Autowired private Memarylogger logger; - @GetMapping("/admin/ticket/query") + @GetMapping({"/api/v6/ticket/query","/admin/ticket/query"}) public PageResult queryTicket(@RequestParam(defaultValue = "0") int start, @RequestParam(defaultValue = "40") int count, String startDate, diff --git a/src/main/java/org/toughradius/form/ApiConfigForm.java b/src/main/java/org/toughradius/form/ApiConfigForm.java new file mode 100644 index 00000000..6e69b274 --- /dev/null +++ b/src/main/java/org/toughradius/form/ApiConfigForm.java @@ -0,0 +1,32 @@ +package org.toughradius.form; + +public class ApiConfigForm { + + private String apiType; + private String apiUsername; + private String apiPasswd; + + public String getApiType() { + return apiType; + } + + public void setApiType(String apiType) { + this.apiType = apiType; + } + + public String getApiUsername() { + return apiUsername; + } + + public void setApiUsername(String apiUsername) { + this.apiUsername = apiUsername; + } + + public String getApiPasswd() { + return apiPasswd; + } + + public void setApiPasswd(String apiPasswd) { + this.apiPasswd = apiPasswd; + } +} diff --git a/src/main/java/org/toughradius/handler/RadsecHandler.java b/src/main/java/org/toughradius/handler/RadsecHandler.java index d6637f8f..08175308 100644 --- a/src/main/java/org/toughradius/handler/RadsecHandler.java +++ b/src/main/java/org/toughradius/handler/RadsecHandler.java @@ -34,28 +34,30 @@ public void sessionCreated(IoSession session) throws Exception { } - @Scheduled(fixedRate = 100) + @Scheduled(fixedDelay = 100) public void sendRadsecCoa() { CoaRequest req; - try { - req = onlineCache.peekCoaRequest(); - }catch (NoSuchElementException ne){ - return; - } - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - try { - req.encodeRequestPacket(bos, "radsec"); - } catch (IOException e) { - e.printStackTrace(); - return; - } - byte[] data = bos.toByteArray(); - for (IoSession session : getSessionSet()){ - try{ - session.write(IoBuffer.wrap(data)); + while(true){ + try { + req = onlineCache.peekCoaRequest(); + }catch (NoSuchElementException ne){ return; - }catch (Exception ignore){ - + } + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + try { + req.encodeRequestPacket(bos, "radsec"); + } catch (IOException e) { + e.printStackTrace(); + return; + } + byte[] data = bos.toByteArray(); + for (IoSession session : getSessionSet()){ + try{ + session.write(IoBuffer.wrap(data)); + return; + }catch (Exception ignore){ + + } } } } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 4a03139e..362538e7 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -13,7 +13,8 @@ server.connection-timeout=600 server.server-header=toughradius/1.0 server.tomcat.accesslog.enabled=true server.tomcat.accesslog.directory=/var/log/toughradius -spring.application.name=toughradius +server.servlet.session.cookie.path=/ +server.servlet.session.cookie.max-age=8640000 spring.profiles.active=dev spring.freemarker.template-loader-path=classpath:/templates diff --git a/src/main/resources/static/admin/config.js b/src/main/resources/static/admin/config.js index 966861c5..08acfbdd 100644 --- a/src/main/resources/static/admin/config.js +++ b/src/main/resources/static/admin/config.js @@ -150,7 +150,47 @@ toughradius.admin.config.loadPage = function(session){ },{} ] } - } + }, + { + header:"API 设置", + body:{ + id: "api_settings", + view: "form", + paddingX:10, + elementsConfig: { + labelWidth:160, + // labelPosition:"top" + }, + url:"/admin/config/load/api", + elements: [ + { view: "fieldset", label: "API", body: { + rows:[ + {view: "richselect", name: "apiType", label: "API 类型:",value:"basic", options:[{id:"basic",value:"Basic"}]}, + {view: "text", name: "apiUsername", label: "Basic 用户"}, + {view: "text", type:"password", name: "apiPasswd", label: "Basic 密码"}, + ] + }}, + { + cols: [ + {view: "button", name: "submit", type: "form", value: "保存配置", width: 120, height:36, click: function () { + if (!$$("radius_settings").validate()){ + webix.message({type: "error", text:"请正确填写",expire:1000}); + return false; + } + var param = $$("api_settings").getValues(); + param['ctype'] = 'sms'; + webix.ajax().post('/admin/config/api/update',param).then(function (result) { + var resp = result.json(); + webix.message({type: resp.msgtype, text: resp.msg, expire: 3000}); + }); + } + }, + {} + ] + },{} + ] + } + }, ] diff --git a/src/main/resources/static/admin/main.js b/src/main/resources/static/admin/main.js index 2d1a04f7..85861e26 100644 --- a/src/main/resources/static/admin/main.js +++ b/src/main/resources/static/admin/main.js @@ -161,7 +161,7 @@ toughradius.admin.methods.requirejs = function(jsname, session,callback){ webix.ready(function() { - webix.ajax().get('/admin/session',{}).then(function (result) { + webix.ajax().get('/admin/session',{v:new Date().getTime()}).then(function (result) { var resp = result.json(); if(resp.code===1){ webix.message({type:"error",text:resp.msg}); diff --git a/src/main/resources/static/login.html b/src/main/resources/static/login.html index 8de95c2f..272e65b2 100644 --- a/src/main/resources/static/login.html +++ b/src/main/resources/static/login.html @@ -6,6 +6,7 @@ +