diff --git a/lp.key b/lp.key new file mode 100644 index 0000000..5c02810 --- /dev/null +++ b/lp.key @@ -0,0 +1 @@ +BFEBFBFF000B06710025_38BC_21C3_A29D. \ No newline at end of file diff --git a/modules/common/src/main/java/com/zhehekeji/common/encryptor/Encryptor.java b/modules/common/src/main/java/com/zhehekeji/common/encryptor/Encryptor.java new file mode 100644 index 0000000..be48731 --- /dev/null +++ b/modules/common/src/main/java/com/zhehekeji/common/encryptor/Encryptor.java @@ -0,0 +1,30 @@ +package com.zhehekeji.common.encryptor; +import java.lang.reflect.Field; + +public class Encryptor { + public static String encryptStr(String str){ + long ulMacTmp = 0; + for (int i = 0; i < str.length(); i++) { + ulMacTmp = ulMacTmp << 4; + char cStr = str.charAt(i); + if (cStr >= '0' && cStr <= '9') { + ulMacTmp += (long)(str.charAt(i) - '0'); + } else if (cStr >= 'a' && cStr <= 'f') { + ulMacTmp += (long)(str.charAt(i) - 'a' + 10); + } else if (cStr >= 'A' && cStr <= 'F') { + ulMacTmp += (long)(str.charAt(i) - 'A' + 10); + } else { + ulMacTmp += 0; + } + } + str = String.valueOf(ulMacTmp); + return str; + } + public static void main(String[] args) + { + + String noEncrypt = "BFEBFBFF000B06710025_38BC_21C3_A29D."; + String encrypt = Encryptor.encryptStr(noEncrypt); + System.out.println(encrypt); + } +} diff --git a/modules/filter/src/main/java/com/zhehekeji/filter/aspect/LPLicense.java b/modules/filter/src/main/java/com/zhehekeji/filter/aspect/LPLicense.java new file mode 100644 index 0000000..3c5c0f0 --- /dev/null +++ b/modules/filter/src/main/java/com/zhehekeji/filter/aspect/LPLicense.java @@ -0,0 +1,149 @@ +package com.zhehekeji.filter.aspect; + +import com.alibaba.fastjson.JSONObject; +import com.sun.management.OperatingSystemMXBean; +import com.zhehekeji.common.encryptor.Encryptor; +import com.zhehekeji.common.util.FileUtil; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; + +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; +import java.lang.management.ManagementFactory; +import java.net.NetworkInterface; +import java.net.SocketException; +import java.time.LocalDateTime; +import java.util.Enumeration; +import java.util.Scanner; + +@Slf4j +public class LPLicense { + + private static LocalDateTime lastUpdate = null; + + private static String lic_str = null; + + private static String lic_path = "./lp.lic"; + + private static String key_path = "./lp.key"; + + private static String CPU_INFO = null; + + private static String DEVICE_INFO = null; + + /** + * 初始的时候创建 + */ + public static void createLicKeyIfNotExist() { + File file = new File(key_path); + if (!file.exists()) { + String cpu = getCpuInfo(); + CPU_INFO = cpu; + String device = getDeviceId(); + DEVICE_INFO = device; + FileUtil.save(cpu + device, key_path); + } + } + + private static String getCpuInfo() { + String os = System.getProperty("os.name").toLowerCase(); + String command = ""; + if (os.contains("win")) { + command = "wmic cpu get ProcessorId"; + } else if (os.contains("nix") || os.contains("nux") || os.contains("mac")) { + command = "dmidecode -t processor | grep ID"; + } else { + return "Unsupported operating system"; + } + + try { + Process process = Runtime.getRuntime().exec(command); + BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); + StringBuilder output = new StringBuilder(); + String line; + while ((line = reader.readLine()) != null) { + output.append(line.trim()); + } + reader.close(); + + if (os.contains("win")) { + return output.substring(output.indexOf("Id") + 1).trim(); + } else if (os.contains("nix") || os.contains("nux") || os.contains("mac")) { + return output.toString().replace("ID:", "").trim(); + } else { + return "Unknown CPU ID"; + } + } catch (IOException e) { + e.printStackTrace(); + return "Error retrieving CPU ID"; + } + + } + + public static void main(String[] args) { + System.out.println(getDeviceId()); + } + private static String getDeviceId() { + String deviceId = null; + try { + Process process = Runtime.getRuntime().exec("sudo dmidecode -s system-uuid"); + BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); + deviceId = reader.readLine(); + reader.close(); + process.waitFor(); + } catch (IOException | InterruptedException e) { + e.printStackTrace(); + } + return deviceId != null ? deviceId : "Unknown"; + } + + private static boolean isVirtualNetworkInterface(NetworkInterface networkInterface) throws SocketException { + return networkInterface.isVirtual() || networkInterface.getName().contains("Virtual"); + } + private static String getDiskInfo() { + try { + Process process = Runtime.getRuntime().exec( + new String[]{"lshw", "-c", "network", "|", "grep serial", "|", "head -n 1"}); + process.getOutputStream().close(); + Scanner sc = new Scanner(process.getInputStream()); + String property = sc.next(); + String disk = sc.next(); + return disk; + } catch (IOException e) { + log.error("Get DISK error:{}", e); + return null; + } + } + + public static String getLic() { + //每小时读取一次lic文件 + if (lastUpdate == null || LocalDateTime.now().toLocalTime().getHour() != lastUpdate.toLocalTime().getHour()) { + lastUpdate = LocalDateTime.now(); + lic_str = FileUtil.getText(lic_path); + CPU_INFO = getCpuInfo(); + DEVICE_INFO = getDeviceId(); + } + return lic_str; + } + + public static boolean checkLic(String licStr) { + return CPU_INFO != null && DEVICE_INFO != null && licStr.equals(Encryptor.encryptStr(CPU_INFO + DEVICE_INFO)); + + } + + public static boolean checkLic() { + String licStr = getLic(); + if (StringUtils.isEmpty(licStr)) { + return false; + } + return checkLic(licStr); + } + +// public static void main(String[] args) { +// +// createLicKeyIfNotExist(); +// +// } +} diff --git a/modules/filter/src/main/java/com/zhehekeji/filter/aspect/LicenseAspect.java b/modules/filter/src/main/java/com/zhehekeji/filter/aspect/LicenseAspect.java new file mode 100644 index 0000000..e305531 --- /dev/null +++ b/modules/filter/src/main/java/com/zhehekeji/filter/aspect/LicenseAspect.java @@ -0,0 +1,25 @@ +package com.zhehekeji.filter.aspect; + +import com.zhehekeji.core.util.Assert; +import lombok.extern.slf4j.Slf4j; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Before; +import org.springframework.stereotype.Component; + +@Aspect +@Component +@Slf4j +public class LicenseAspect { + + /** + * leaper..*.controller + * leaper 到controller多级目录 + * + * @param + */ + @Before("execution(public * com.zhehekeji..*.controller.*.*(..))") + public void handler(){ + Assert.isTrue(LPLicense.checkLic(),"未获取授权!!请将lp.key发送给授权人员"); + //Assert.isTrue(true,"未获取授权!!请将lp.key发送给授权人员"); + } +} diff --git a/out/artifacts/lia_monitor_backend_jar/mysqlLogin.jar b/out/artifacts/lia_monitor_backend_jar/mysqlLogin.jar deleted file mode 100644 index a7aec16..0000000 Binary files a/out/artifacts/lia_monitor_backend_jar/mysqlLogin.jar and /dev/null differ diff --git a/web/src/main/java/com/zhehekeji/web/controller/CameraController.java b/web/src/main/java/com/zhehekeji/web/controller/CameraController.java index 340f29a..386e22d 100644 --- a/web/src/main/java/com/zhehekeji/web/controller/CameraController.java +++ b/web/src/main/java/com/zhehekeji/web/controller/CameraController.java @@ -197,4 +197,29 @@ public class CameraController { return Result.success(); } + @GetMapping("/rtcConfig") + @ApiOperation(value = "获取rtcConfig") + public Result rtcConfig(String rtcServer) { + List cameraList = cameraService.getCamerasByRtcServer(rtcServer); + JSONObject jsonObject = new JSONObject(); + JSONObject server = new JSONObject(); + server.put("http_port",":8083"); + String [] strings = new String[1]; + strings[0] = "stun:stun.l.google.com:19302"; + server.put("ice_servers",strings); + server.put("ice_username",""); + server.put("ice_credential",""); + jsonObject.put("server",server); + JSONObject streams = new JSONObject(); + cameraList.forEach(camera -> { + JSONObject obj = new JSONObject(); + obj.put("on_demand",false); + obj.put("disable_audio",true); + obj.put("url",camera.getRtsp()); + streams.put("camera"+camera.getId(),obj); + }); + jsonObject.put("streams",streams); + + return Result.success(jsonObject.toJSONString()); + } } diff --git a/web/src/main/java/com/zhehekeji/web/service/CameraService.java b/web/src/main/java/com/zhehekeji/web/service/CameraService.java index 5ac22d5..7c45883 100644 --- a/web/src/main/java/com/zhehekeji/web/service/CameraService.java +++ b/web/src/main/java/com/zhehekeji/web/service/CameraService.java @@ -1,6 +1,7 @@ package com.zhehekeji.web.service; import com.alibaba.excel.EasyExcel; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.zhehekeji.core.util.Assert; @@ -59,6 +60,13 @@ public class CameraService { private CameraControlLoginModule cameraControlLoginModule; + public List getCamerasByRtcServer(String rtcServer){ + if(StringUtils.isEmpty(rtcServer)){ + rtcServer = "127.0.0.1"; + } + return cameraMapper.selectList(new QueryWrapper().eq("rtc_server",rtcServer)); + } + public void setCameraControlModule(CameraControlModule cameraControlModule){ this.cameraControlModule = cameraControlModule; } diff --git a/web/src/main/java/com/zhehekeji/web/service/InitService.java b/web/src/main/java/com/zhehekeji/web/service/InitService.java index 31a61d3..d4b381a 100644 --- a/web/src/main/java/com/zhehekeji/web/service/InitService.java +++ b/web/src/main/java/com/zhehekeji/web/service/InitService.java @@ -1,5 +1,6 @@ package com.zhehekeji.web.service; +import com.zhehekeji.filter.aspect.LPLicense; import com.zhehekeji.web.config.ConfigProperties; import com.zhehekeji.web.entity.Camera; import com.zhehekeji.web.entity.Street; @@ -84,6 +85,7 @@ public class InitService implements ApplicationRunner { LoginThread loginThread = new LoginThread(camera); loginThread.start(); }); + LPLicense.createLicKeyIfNotExist(); //plc连接 if(configProperties.getServerMode() == 0){ log.info("PLC TCP MODE"); diff --git a/web/src/main/resources/application.yml b/web/src/main/resources/application.yml index 35ee836..589dc9c 100644 --- a/web/src/main/resources/application.yml +++ b/web/src/main/resources/application.yml @@ -12,6 +12,8 @@ spring: path: /api/ cache: type: simple + config: + additional-location: mybatis-plus: mapper-locations: classpath*:mapper/**/*.xml #实体扫描,多个package用逗号或者分号分隔 @@ -31,4 +33,4 @@ zhehe: enable: true postToken: w89euijon2&UHBTY$%huni34ri logging: - config: classpath:logback-spring.xml \ No newline at end of file + config: classpath:logback-spring.xml diff --git a/web/src/main/resources/logback-spring.xml b/web/src/main/resources/logback-spring.xml index 278dbcf..f087b39 100644 --- a/web/src/main/resources/logback-spring.xml +++ b/web/src/main/resources/logback-spring.xml @@ -1,6 +1,6 @@ - + diff --git a/web/src/main/resources/mapper/StreetMapper.xml b/web/src/main/resources/mapper/StreetMapper.xml index 8c73b87..00c8e41 100644 --- a/web/src/main/resources/mapper/StreetMapper.xml +++ b/web/src/main/resources/mapper/StreetMapper.xml @@ -5,15 +5,15 @@