lincense
parent
5b77236450
commit
6495622320
|
|
@ -60,7 +60,7 @@ public class AppRun {
|
||||||
springApplication.addListeners(new ApplicationPidFileWriter());
|
springApplication.addListeners(new ApplicationPidFileWriter());
|
||||||
springApplication.addListeners(new MyApiDictListener());
|
springApplication.addListeners(new MyApiDictListener());
|
||||||
springApplication.run(args);
|
springApplication.run(args);
|
||||||
log.info(JSONUtil.toJsonStr(LicenseValidate.getDeviceInfo()));
|
log.info(JSONUtil.toJsonStr(LicenseValidate.getSystem_price()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
|
|
||||||
|
|
@ -101,20 +101,16 @@ public class SysAppUpdateController {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@PutMapping
|
@PutMapping
|
||||||
@Log("修改app_update")
|
@Log("修改app_update")
|
||||||
@ApiOperation("修改app_update")
|
@ApiOperation("修改app_update")
|
||||||
@PreAuthorize("@el.check('sysAppUpdate:edit')")
|
@PreAuthorize("@el.check('sysAppUpdate:edit')")
|
||||||
public ResponseEntity<Object> updateSysAppUpdate(@Validated @RequestBody SysAppUpdate resources){
|
public ResponseEntity<Object> updateSysAppUpdate(@Validated @RequestBody SysAppUpdate resources){
|
||||||
sysAppUpdateService.update(resources);
|
sysAppUpdateService.update(resources);
|
||||||
|
|
||||||
for (Channel client : ServerListenerHandler.clients) {
|
for (Channel client : ServerListenerHandler.clients) {
|
||||||
String devce_ip =((InetSocketAddress)client.remoteAddress()).getAddress().getHostAddress();
|
String devce_ip =((InetSocketAddress)client.remoteAddress()).getAddress().getHostAddress();
|
||||||
NettyUtils.light_on(devce_ip,NettyUtils.light_1,null);
|
NettyUtils.light_on(devce_ip,NettyUtils.light_1,null);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,10 @@
|
||||||
package com.youchain.modules.license;
|
package com.youchain.modules.license;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import com.youchain.modules.license.domain.LicenseCheck;
|
import com.youchain.modules.license.domain.LicenseCheck;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.net.NetworkInterface;
|
|
||||||
import java.net.SocketException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Enumeration;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public abstract class AGxServerInfos {
|
public abstract class AGxServerInfos {
|
||||||
|
|
||||||
|
|
@ -30,15 +25,7 @@ public abstract class AGxServerInfos {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>获取IP地址</p>
|
|
||||||
*/
|
|
||||||
protected abstract List<String> getIpAddress() throws Exception;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>获取Mac地址</p>
|
|
||||||
*/
|
|
||||||
protected abstract List<String> getMacAddress() throws Exception;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>获取CPU序列号</p>
|
* <p>获取CPU序列号</p>
|
||||||
|
|
@ -53,53 +40,6 @@ public abstract class AGxServerInfos {
|
||||||
/**
|
/**
|
||||||
* <p>获取当前服务器所有符合条件的InetAddress</p>
|
* <p>获取当前服务器所有符合条件的InetAddress</p>
|
||||||
*/
|
*/
|
||||||
protected List<InetAddress> getLocalAllInetAddress() throws Exception {
|
|
||||||
|
|
||||||
List<InetAddress> result = new ArrayList<>(4);
|
|
||||||
|
|
||||||
// 遍历所有的网络接口
|
|
||||||
for (Enumeration networkInterfaces = NetworkInterface.getNetworkInterfaces(); networkInterfaces.hasMoreElements(); ) {
|
|
||||||
NetworkInterface ni = (NetworkInterface) networkInterfaces.nextElement();
|
|
||||||
// 在所有的接口下再遍历IP
|
|
||||||
for (Enumeration addresses = ni.getInetAddresses(); addresses.hasMoreElements(); ) {
|
|
||||||
InetAddress address = (InetAddress) addresses.nextElement();
|
|
||||||
//排除LoopbackAddress、SiteLocalAddress、LinkLocalAddress、MulticastAddress类型的IP地址
|
|
||||||
if(!address.isLoopbackAddress() /*&& !inetAddr.isSiteLocalAddress()*/
|
|
||||||
&& !address.isLinkLocalAddress() && !address.isMulticastAddress()){
|
|
||||||
result.add(address);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>获取某个网络地址对应的Mac地址</p>
|
|
||||||
*/
|
|
||||||
protected String getMacByInetAddress(InetAddress inetAddr){
|
|
||||||
|
|
||||||
try {
|
|
||||||
byte[] mac = NetworkInterface.getByInetAddress(inetAddr).getHardwareAddress();
|
|
||||||
StringBuffer sb = new StringBuffer();
|
|
||||||
for(int i=0;i<mac.length;i++){
|
|
||||||
if(i != 0) {
|
|
||||||
sb.append("-");
|
|
||||||
}
|
|
||||||
|
|
||||||
//将十六进制byte转化为字符串
|
|
||||||
String temp = Integer.toHexString(mac[i] & 0xff);
|
|
||||||
if(temp.length() == 1){
|
|
||||||
sb.append("0" + temp);
|
|
||||||
}else{
|
|
||||||
sb.append(temp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return sb.toString().toUpperCase();
|
|
||||||
} catch (SocketException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,122 +1,179 @@
|
||||||
package com.youchain.modules.license;
|
package com.youchain.modules.license;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateUnit;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import cn.hutool.core.io.FileUtil;
|
||||||
import cn.hutool.core.io.file.FileReader;
|
import cn.hutool.core.io.file.FileReader;
|
||||||
import cn.hutool.core.io.file.FileWriter;
|
import cn.hutool.core.io.file.FileWriter;
|
||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
|
|
||||||
import com.youchain.config.FileProperties;
|
import com.youchain.config.FileProperties;
|
||||||
import com.youchain.config.RsaProperties;
|
import com.youchain.config.RsaProperties;
|
||||||
import com.youchain.exception.BadRequestException;
|
import com.youchain.exception.BadRequestException;
|
||||||
import com.youchain.modules.license.domain.LicenseCheck;
|
import com.youchain.modules.license.domain.LicenseCheck;
|
||||||
import com.youchain.utils.RsaUtils;
|
import com.youchain.utils.RsaUtils;
|
||||||
import com.youchain.utils.SpringContextHolder;
|
import com.youchain.utils.SpringContextHolder;
|
||||||
|
import com.youchain.utils.StringUtils;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import org.apache.commons.codec.binary.Base64;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
public class LicenseValidate {
|
public class LicenseValidate {
|
||||||
|
|
||||||
public static void validate() throws Exception {
|
public static LicenseCheck getKey_price() throws Exception{
|
||||||
//读取本地文件
|
//读取本地文件
|
||||||
FileProperties properties = SpringContextHolder.getBean(FileProperties.class);
|
FileProperties properties= SpringContextHolder.getBean(FileProperties.class);
|
||||||
|
log.info(properties.getPath().getPath());
|
||||||
String result = "";
|
String result="";
|
||||||
try {
|
try{
|
||||||
FileReader fileReader = new FileReader(properties.getPath().getPath() + "key/" + "license.key");
|
FileReader fileReader = new FileReader(properties.getPath().getPath()+"key/"+"license.key");
|
||||||
result = fileReader.readString();
|
result = fileReader.readString();
|
||||||
|
|
||||||
} catch (Exception e) {
|
}catch (Exception e){
|
||||||
throw new BadRequestException("License不存在,请上传License");
|
throw new BadRequestException("License不存在,请上传License");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.error(result);
|
||||||
String rsaResult = RsaUtils.decryptByPublicKey(RsaProperties.licenseKey, result);
|
String rsaResult= RsaUtils.decryptByPublicKey(RsaProperties.licenseKey,result);
|
||||||
|
log.error("------------------------解密完成-----------------------");
|
||||||
LicenseCheck key_price = JSONUtil.toBean(rsaResult, LicenseCheck.class);
|
LicenseCheck key_price = JSONUtil.toBean(rsaResult, LicenseCheck.class);
|
||||||
LicenseCheck system_price = getDeviceInfo();
|
return key_price;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (key_price.getMainBoardSerial().equals(system_price.getMainBoardSerial())) {
|
public static LicenseCheck getSystem_price(){
|
||||||
|
|
||||||
} else {
|
FileProperties properties= SpringContextHolder.getBean(FileProperties.class);
|
||||||
|
String device_path=properties.getPath().getPath()+"key/"+"device.key";
|
||||||
|
String deviceInfo_json=ReadDeviceFile();
|
||||||
|
if(StringUtils.isNotBlank(deviceInfo_json)){
|
||||||
|
try{
|
||||||
|
LicenseCheck licenseCheck =JSONUtil.toBean(deviceInfo_json,LicenseCheck.class);
|
||||||
|
BasicFileAttributes attributes = Files.readAttributes(Paths.get(device_path), BasicFileAttributes.class);
|
||||||
|
String creationTime = attributes.creationTime().toString();
|
||||||
|
String lastModifiedTime = attributes.lastModifiedTime().toString();
|
||||||
|
Date licenseCheck_date = DateUtil.parse(licenseCheck.getCreateTime(), "yyyy-MM-dd");
|
||||||
|
Date F_creationTime = DateUtil.parse(creationTime, "yyyy-MM-dd");
|
||||||
|
Date F_lastModifiedTime = DateUtil.parse(lastModifiedTime, "yyyy-MM-dd");
|
||||||
|
|
||||||
|
long betweenDay = DateUtil.between(licenseCheck_date, F_creationTime, DateUnit.DAY);
|
||||||
|
long betweenDay2 = DateUtil.between(licenseCheck_date, F_lastModifiedTime, DateUnit.DAY);
|
||||||
|
if(betweenDay==0&&betweenDay2==0){
|
||||||
|
//文件时间校验通过,不需要重新生成
|
||||||
|
return licenseCheck;
|
||||||
|
}else{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}catch (Exception e){
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CreateDeviceFileOrRead();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void validate() throws Exception{
|
||||||
|
|
||||||
|
LicenseCheck key_price=getKey_price();
|
||||||
|
|
||||||
|
LicenseCheck system_price = getSystem_price();
|
||||||
|
if(system_price==null){
|
||||||
|
throw new BadRequestException("设备码异常");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key_price.getMainBoardSerial().equals(system_price.getMainBoardSerial())){
|
||||||
|
|
||||||
|
}else{
|
||||||
|
log.error("主板匹配失败");
|
||||||
throw new BadRequestException("主板匹配失败");
|
throw new BadRequestException("主板匹配失败");
|
||||||
}
|
}
|
||||||
if (key_price.getCpuSerial().equals(system_price.getCpuSerial())) {
|
if(key_price.getCpuSerial().equals(system_price.getCpuSerial())){
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
|
}else{
|
||||||
|
log.error("CPU匹配失败");
|
||||||
throw new BadRequestException("CPU匹配失败");
|
throw new BadRequestException("CPU匹配失败");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try{
|
||||||
Date end_date = DateUtil.parse(key_price.getEndTime());
|
Date end_date = DateUtil.parse(key_price.getEndTime());
|
||||||
Date now_date = DateUtil.date();
|
Date now_date = DateUtil.date();
|
||||||
|
|
||||||
if (end_date.before(now_date)) {
|
if(end_date.before(now_date)){
|
||||||
throw new BadRequestException("过期的License,请重新生成");
|
throw new BadRequestException("过期的License,请重新生成");
|
||||||
} else {
|
}else{
|
||||||
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
}catch (Exception e){
|
||||||
throw new BadRequestException("无效的License,请重新生成");
|
throw new BadRequestException("无效的License,请重新生成");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void saveCode(String license_code) throws Exception {
|
public static void saveCode(String license_code) throws Exception{
|
||||||
//读取本地文件
|
//读取本地文件
|
||||||
|
log.error(license_code);
|
||||||
String rsaResult = "";
|
String rsaResult="";
|
||||||
try {
|
try{
|
||||||
rsaResult = RsaUtils.decryptByPublicKey(RsaProperties.licenseKey, license_code);
|
rsaResult= RsaUtils.decryptByPublicKey(RsaProperties.licenseKey,license_code);
|
||||||
} catch (Exception e) {
|
}catch (Exception e){
|
||||||
throw new BadRequestException("License无效,请重新生成");
|
throw new BadRequestException("License无效,请重新生成");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//log.error(rsaResult);
|
||||||
|
|
||||||
LicenseCheck key_price = JSONUtil.toBean(rsaResult, LicenseCheck.class);
|
LicenseCheck key_price = JSONUtil.toBean(rsaResult, LicenseCheck.class);
|
||||||
LicenseCheck system_price = getDeviceInfo();
|
|
||||||
|
|
||||||
|
|
||||||
if (key_price.getMainBoardSerial().equals(system_price.getMainBoardSerial())) {
|
LicenseCheck system_price =getSystem_price();
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
|
if(key_price.getMainBoardSerial().equals(system_price.getMainBoardSerial())){
|
||||||
|
log.error("主板匹配成功");
|
||||||
|
}else{
|
||||||
|
log.error("主板匹配失败");
|
||||||
throw new BadRequestException("主板匹配失败");
|
throw new BadRequestException("主板匹配失败");
|
||||||
}
|
}
|
||||||
if (key_price.getCpuSerial().equals(system_price.getCpuSerial())) {
|
if(key_price.getCpuSerial().equals(system_price.getCpuSerial())){
|
||||||
|
log.error("CPU匹配成功");
|
||||||
} else {
|
}else{
|
||||||
|
log.error("CPU匹配失败");
|
||||||
throw new BadRequestException("CPU匹配失败");
|
throw new BadRequestException("CPU匹配失败");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try{
|
||||||
Date end_date = DateUtil.parse(key_price.getEndTime());
|
Date end_date = DateUtil.parse(key_price.getEndTime());
|
||||||
Date now_date = DateUtil.date();
|
Date now_date = DateUtil.date();
|
||||||
|
|
||||||
if (end_date.before(now_date)) {
|
if(end_date.before(now_date)){
|
||||||
throw new BadRequestException("过期的License,请重新生成");
|
throw new BadRequestException("过期的License,请重新生成");
|
||||||
} else {
|
}else{
|
||||||
|
log.error("有效期验证通过");
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
}catch (Exception e){
|
||||||
throw new BadRequestException("无效的License,请重新生成");
|
throw new BadRequestException("无效的License,请重新生成");
|
||||||
}
|
}
|
||||||
|
|
||||||
FileProperties properties = SpringContextHolder.getBean(FileProperties.class);
|
FileProperties properties= SpringContextHolder.getBean(FileProperties.class);
|
||||||
|
log.info(properties.getPath().getPath());
|
||||||
|
|
||||||
|
FileWriter writer = new FileWriter(properties.getPath().getPath()+"key/"+"license.key");
|
||||||
FileWriter writer = new FileWriter(properties.getPath().getPath() + "key/" + "license.key");
|
|
||||||
writer.write(license_code);
|
writer.write(license_code);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static LicenseCheck getDeviceInfo() {
|
|
||||||
String osName = System.getProperty("os.name");
|
|
||||||
|
private static LicenseCheck getDeviceInfo(){
|
||||||
|
String osName = System.getProperty("os.name");
|
||||||
osName = osName.toLowerCase();
|
osName = osName.toLowerCase();
|
||||||
AGxServerInfos abstractServerInfos;
|
AGxServerInfos abstractServerInfos;
|
||||||
//根据不同操作系统类型选择不同的数据获取方法
|
//根据不同操作系统类型选择不同的数据获取方法
|
||||||
|
|
@ -124,10 +181,133 @@ public class LicenseValidate {
|
||||||
abstractServerInfos = new WindowsServerInfos();
|
abstractServerInfos = new WindowsServerInfos();
|
||||||
} else if (osName.startsWith("linux")) {
|
} else if (osName.startsWith("linux")) {
|
||||||
abstractServerInfos = new LinuxServerInfos();
|
abstractServerInfos = new LinuxServerInfos();
|
||||||
} else {//其他服务器类型
|
}else{//其他服务器类型
|
||||||
abstractServerInfos = new LinuxServerInfos();
|
abstractServerInfos = new LinuxServerInfos();
|
||||||
}
|
}
|
||||||
return abstractServerInfos.getServerInfos();
|
return abstractServerInfos.getServerInfos();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static String ReadDeviceFile(){
|
||||||
|
FileProperties properties= SpringContextHolder.getBean(FileProperties.class);
|
||||||
|
String path=properties.getPath().getPath()+"key/"+"device.key";
|
||||||
|
try{
|
||||||
|
FileReader fileReader=new FileReader(path);
|
||||||
|
String jiami_content=fileReader.readString();
|
||||||
|
String jiemi1= new String(Base64.decodeBase64(jiami_content));
|
||||||
|
String jiemi2= new String(Base64.decodeBase64(jiemi1));
|
||||||
|
return jiemi2;
|
||||||
|
}catch (Exception e){
|
||||||
|
log.error("设备码文件不存在");
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void CreateDeviceFileOrRead(){
|
||||||
|
FileProperties properties= SpringContextHolder.getBean(FileProperties.class);
|
||||||
|
String device_path=properties.getPath().getPath()+"key/"+"device.key";
|
||||||
|
System.out.println("获取配置文件路径:"+device_path);
|
||||||
|
String deviceInfo_json=ReadDeviceFile();
|
||||||
|
if(StringUtils.isNotBlank(deviceInfo_json)){
|
||||||
|
try{
|
||||||
|
LicenseCheck licenseCheck =JSONUtil.toBean(deviceInfo_json,LicenseCheck.class);
|
||||||
|
BasicFileAttributes attributes = Files.readAttributes(Paths.get(device_path), BasicFileAttributes.class);
|
||||||
|
String creationTime = attributes.creationTime().toString();
|
||||||
|
String lastModifiedTime = attributes.lastModifiedTime().toString();
|
||||||
|
System.out.println(creationTime+"-------------"+lastModifiedTime);
|
||||||
|
Date licenseCheck_date = DateUtil.parse(licenseCheck.getCreateTime(), "yyyy-MM-dd");
|
||||||
|
Date F_creationTime = DateUtil.parse(creationTime, "yyyy-MM-dd");
|
||||||
|
Date F_lastModifiedTime = DateUtil.parse(lastModifiedTime, "yyyy-MM-dd");
|
||||||
|
|
||||||
|
long betweenDay = DateUtil.between(licenseCheck_date, F_creationTime, DateUnit.DAY);
|
||||||
|
long betweenDay2 = DateUtil.between(licenseCheck_date, F_lastModifiedTime, DateUnit.DAY);
|
||||||
|
log.info(betweenDay+"-------------"+betweenDay2);
|
||||||
|
if(betweenDay==0&&betweenDay2==0){
|
||||||
|
//文件时间校验通过,不需要重新生成
|
||||||
|
System.out.println("------------------------文件时间校验通过,不需要重新生成-----------------------");
|
||||||
|
return ;
|
||||||
|
}else{
|
||||||
|
System.out.println("------------------------文件时间校验失败,重新生成-----------------------");
|
||||||
|
}
|
||||||
|
|
||||||
|
}catch (Exception e){
|
||||||
|
System.out.println("检验异常:"+e.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.out.println("文件不存在,或者文件校验失败,删除文件,重新生成");
|
||||||
|
//文件不存在,或者文件校验失败,删除文件,重新生成
|
||||||
|
FileUtil.del(new File(device_path));
|
||||||
|
System.out.println("文件不存在,或者文件校验失败,删除文件,重新生成2");
|
||||||
|
|
||||||
|
LicenseCheck licenseCheck=getDeviceInfo();
|
||||||
|
if(!StringUtils.isNotBlank(licenseCheck.getCpuSerial())){
|
||||||
|
String cpuSerial=""+ (new java.util.Random().nextInt(89999999)+10000000);
|
||||||
|
licenseCheck.setCpuSerial(cpuSerial);
|
||||||
|
}
|
||||||
|
if(!StringUtils.isNotBlank(licenseCheck.getMainBoardSerial())){
|
||||||
|
String macSerial=""+ (new java.util.Random().nextInt(89999999)+10000000);
|
||||||
|
licenseCheck.setMainBoardSerial(macSerial);
|
||||||
|
}
|
||||||
|
licenseCheck.setCreateTime(DateUtil.today());
|
||||||
|
|
||||||
|
String rest= JSONUtil.toJsonStr(licenseCheck).trim();
|
||||||
|
|
||||||
|
|
||||||
|
String jiami_1= Base64.encodeBase64String(rest.getBytes());
|
||||||
|
String jiami_2= Base64.encodeBase64String(jiami_1.getBytes());
|
||||||
|
|
||||||
|
FileWriter writer = new FileWriter(properties.getPath().getPath()+"key/"+"device.key");
|
||||||
|
writer.write(jiami_2);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void CreateDeviceFileTT(){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* FileProperties properties= SpringContextHolder.getBean(FileProperties.class);
|
||||||
|
|
||||||
|
LicenseCheck licenseCheck=getDeviceInfo();
|
||||||
|
if(!StringUtils.isNotBlank(licenseCheck.getCpuSerial())){
|
||||||
|
licenseCheck.setCpuSerial("");
|
||||||
|
}
|
||||||
|
if(!StringUtils.isNotBlank(licenseCheck.getMainBoardSerial())){
|
||||||
|
licenseCheck.setMainBoardSerial("");
|
||||||
|
}
|
||||||
|
licenseCheck.setCreateTime(DateUtil.today());
|
||||||
|
|
||||||
|
String rest= JSONUtil.toJsonStr(licenseCheck).trim();
|
||||||
|
log.error("------------------------初始化完成-----------------------");
|
||||||
|
log.error(rest);
|
||||||
|
|
||||||
|
String jiami_1= Base64.encodeBase64String(rest.getBytes());
|
||||||
|
String jiami_2= Base64.encodeBase64String(jiami_1.getBytes());
|
||||||
|
|
||||||
|
log.error("------------------------加密完成-----------------------");
|
||||||
|
log.error(jiami_2);
|
||||||
|
|
||||||
|
FileWriter writer = new FileWriter(properties.getPath().getPath()+"key/"+"device.key");
|
||||||
|
writer.write(jiami_2);
|
||||||
|
|
||||||
|
FileReader fileReader=new FileReader(properties.getPath().getPath()+"key/"+"device.key");
|
||||||
|
String jiami_content=fileReader.readString();
|
||||||
|
|
||||||
|
String jiemi1= new String(Base64.decodeBase64(jiami_content));
|
||||||
|
String jiemi2= new String(Base64.decodeBase64(jiemi1));
|
||||||
|
log.error("------------------------解密完成-----------------------");
|
||||||
|
log.error(jiemi2);*/
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,62 +4,36 @@ import com.youchain.utils.StringUtils;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>用于获取客户Linux服务器的基本信息</p>
|
* <p>用于获取客户Linux服务器的基本信息</p>
|
||||||
*/
|
*/
|
||||||
public class LinuxServerInfos extends AGxServerInfos {
|
public class LinuxServerInfos extends AGxServerInfos {
|
||||||
|
|
||||||
@Override
|
|
||||||
protected List<String> getIpAddress() throws Exception {
|
|
||||||
List<String> result = null;
|
|
||||||
|
|
||||||
//获取所有网络接口
|
|
||||||
List<InetAddress> inetAddresses = getLocalAllInetAddress();
|
|
||||||
|
|
||||||
if(inetAddresses != null && inetAddresses.size() > 0){
|
|
||||||
result = inetAddresses.stream().map(InetAddress::getHostAddress).distinct().map(String::toLowerCase).collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected List<String> getMacAddress() throws Exception {
|
|
||||||
List<String> result = null;
|
|
||||||
|
|
||||||
//1. 获取所有网络接口
|
|
||||||
List<InetAddress> inetAddresses = getLocalAllInetAddress();
|
|
||||||
|
|
||||||
if(inetAddresses != null && inetAddresses.size() > 0){
|
|
||||||
//2. 获取所有网络接口的Mac地址
|
|
||||||
result = inetAddresses.stream().map(this::getMacByInetAddress).distinct().collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getCPUSerial() throws Exception {
|
protected String getCPUSerial() throws Exception {
|
||||||
//序列号
|
//序列号
|
||||||
String serialNumber = "";
|
String serialNumber = "";
|
||||||
|
|
||||||
//使用dmidecode命令获取CPU序列号
|
try{
|
||||||
String[] shell = {"/bin/bash","-c","dmidecode -t processor | grep 'ID' | awk -F ':' '{print $2}' | head -n 1"};
|
String[] shell = {"/bin/bash","-c","dmidecode -t processor | grep 'ID' | awk -F ':' '{print $2}' | head -n 1"};
|
||||||
Process process = Runtime.getRuntime().exec(shell);
|
Process process = Runtime.getRuntime().exec(shell);
|
||||||
process.getOutputStream().close();
|
process.getOutputStream().close();
|
||||||
|
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||||
|
|
||||||
String line = reader.readLine().trim();
|
String line = reader.readLine().trim();
|
||||||
if(StringUtils.isNotBlank(line)){
|
if(StringUtils.isNotBlank(line)){
|
||||||
serialNumber = line;
|
serialNumber = line;
|
||||||
|
}
|
||||||
|
reader.close();
|
||||||
|
}catch (Exception e){
|
||||||
|
serialNumber="";
|
||||||
}
|
}
|
||||||
|
//使用dmidecode命令获取CPU序列号
|
||||||
|
|
||||||
reader.close();
|
|
||||||
return serialNumber;
|
return serialNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -67,20 +41,22 @@ public class LinuxServerInfos extends AGxServerInfos {
|
||||||
protected String getMainBoardSerial() throws Exception {
|
protected String getMainBoardSerial() throws Exception {
|
||||||
//序列号
|
//序列号
|
||||||
String serialNumber = "";
|
String serialNumber = "";
|
||||||
|
try{
|
||||||
|
//使用dmidecode命令获取主板序列号
|
||||||
|
String[] shell = {"/bin/bash","-c","dmidecode | grep 'Serial Number' | awk -F ':' '{print $2}' | head -n 1"};
|
||||||
|
Process process = Runtime.getRuntime().exec(shell);
|
||||||
|
process.getOutputStream().close();
|
||||||
|
|
||||||
//使用dmidecode命令获取主板序列号
|
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||||
String[] shell = {"/bin/bash","-c","dmidecode | grep 'Serial Number' | awk -F ':' '{print $2}' | head -n 1"};
|
|
||||||
Process process = Runtime.getRuntime().exec(shell);
|
|
||||||
process.getOutputStream().close();
|
|
||||||
|
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
String line = reader.readLine().trim();
|
||||||
|
if(StringUtils.isNotBlank(line)){
|
||||||
String line = reader.readLine().trim();
|
serialNumber = line;
|
||||||
if(StringUtils.isNotBlank(line)){
|
}
|
||||||
serialNumber = line;
|
reader.close();
|
||||||
|
}catch (Exception e){
|
||||||
|
serialNumber = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
reader.close();
|
|
||||||
return serialNumber;
|
return serialNumber;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,63 +1,38 @@
|
||||||
package com.youchain.modules.license;
|
package com.youchain.modules.license;
|
||||||
|
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>用于获取客户Windows服务器的基本信息</p>
|
* <p>用于获取客户Windows服务器的基本信息</p>
|
||||||
*/
|
*/
|
||||||
public class WindowsServerInfos extends AGxServerInfos {
|
public class WindowsServerInfos extends AGxServerInfos {
|
||||||
|
|
||||||
@Override
|
|
||||||
protected List<String> getIpAddress() throws Exception {
|
|
||||||
List<String> result = null;
|
|
||||||
|
|
||||||
//获取所有网络接口
|
|
||||||
List<InetAddress> inetAddresses = getLocalAllInetAddress();
|
|
||||||
|
|
||||||
if(inetAddresses != null && inetAddresses.size() > 0){
|
|
||||||
result = inetAddresses.stream().map(InetAddress::getHostAddress).distinct().map(String::toLowerCase).collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected List<String> getMacAddress() throws Exception {
|
|
||||||
List<String> result = null;
|
|
||||||
|
|
||||||
//1. 获取所有网络接口
|
|
||||||
List<InetAddress> inetAddresses = getLocalAllInetAddress();
|
|
||||||
|
|
||||||
if(inetAddresses != null && inetAddresses.size() > 0){
|
|
||||||
//2. 获取所有网络接口的Mac地址
|
|
||||||
result = inetAddresses.stream().map(this::getMacByInetAddress).distinct().collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getCPUSerial() throws Exception {
|
protected String getCPUSerial() throws Exception {
|
||||||
//序列号
|
//序列号
|
||||||
String serialNumber = "";
|
String serialNumber = "";
|
||||||
|
|
||||||
//使用WMIC获取CPU序列号
|
try{
|
||||||
Process process = Runtime.getRuntime().exec("wmic cpu get processorid");
|
//使用WMIC获取CPU序列号
|
||||||
process.getOutputStream().close();
|
Process process = Runtime.getRuntime().exec("wmic cpu get processorid");
|
||||||
Scanner scanner = new Scanner(process.getInputStream());
|
process.getOutputStream().close();
|
||||||
|
Scanner scanner = new Scanner(process.getInputStream());
|
||||||
|
|
||||||
if(scanner.hasNext()){
|
if(scanner.hasNext()){
|
||||||
scanner.next();
|
scanner.next();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(scanner.hasNext()){
|
||||||
|
serialNumber = scanner.next().trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
scanner.close();
|
||||||
|
}catch (Exception e){
|
||||||
|
serialNumber = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
if(scanner.hasNext()){
|
|
||||||
serialNumber = scanner.next().trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
scanner.close();
|
|
||||||
return serialNumber;
|
return serialNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -66,20 +41,24 @@ public class WindowsServerInfos extends AGxServerInfos {
|
||||||
//序列号
|
//序列号
|
||||||
String serialNumber = "";
|
String serialNumber = "";
|
||||||
|
|
||||||
//使用WMIC获取主板序列号
|
try{
|
||||||
Process process = Runtime.getRuntime().exec("wmic baseboard get serialnumber");
|
//使用WMIC获取主板序列号
|
||||||
process.getOutputStream().close();
|
Process process = Runtime.getRuntime().exec("wmic baseboard get serialnumber");
|
||||||
Scanner scanner = new Scanner(process.getInputStream());
|
process.getOutputStream().close();
|
||||||
|
Scanner scanner = new Scanner(process.getInputStream());
|
||||||
|
|
||||||
|
if(scanner.hasNext()){
|
||||||
|
scanner.next();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(scanner.hasNext()){
|
||||||
|
serialNumber = scanner.next().trim();
|
||||||
|
}
|
||||||
|
scanner.close();
|
||||||
|
}catch (Exception e){
|
||||||
|
|
||||||
if(scanner.hasNext()){
|
|
||||||
scanner.next();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(scanner.hasNext()){
|
|
||||||
serialNumber = scanner.next().trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
scanner.close();
|
|
||||||
return serialNumber;
|
return serialNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package com.youchain.modules.license.domain;
|
package com.youchain.modules.license.domain;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class LicenseCheck implements Serializable {
|
public class LicenseCheck implements Serializable {
|
||||||
|
|
||||||
|
|
@ -18,6 +17,18 @@ public class LicenseCheck implements Serializable {
|
||||||
* 失效时间
|
* 失效时间
|
||||||
*/
|
*/
|
||||||
private String endTime;
|
private String endTime;
|
||||||
|
/**
|
||||||
|
* 文件创建时间
|
||||||
|
*/
|
||||||
|
private String CreateTime;
|
||||||
|
|
||||||
|
public String getCreateTime() {
|
||||||
|
return CreateTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreateTime(String createTime) {
|
||||||
|
CreateTime = createTime;
|
||||||
|
}
|
||||||
|
|
||||||
public String getEndTime() {
|
public String getEndTime() {
|
||||||
return endTime;
|
return endTime;
|
||||||
|
|
@ -27,11 +38,12 @@ public class LicenseCheck implements Serializable {
|
||||||
this.endTime = endTime;
|
this.endTime = endTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LicenseCheck() {
|
public LicenseCheck(){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public String getCpuSerial() {
|
public String getCpuSerial() {
|
||||||
return cpuSerial;
|
return cpuSerial;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -202,7 +202,7 @@ public class AuthorizationController {
|
||||||
@ApiOperation("获取服务器信息")
|
@ApiOperation("获取服务器信息")
|
||||||
@AnonymousGetMapping(value = "/deviceinfo")
|
@AnonymousGetMapping(value = "/deviceinfo")
|
||||||
public ResponseEntity<Object> getDeviceInfo() {
|
public ResponseEntity<Object> getDeviceInfo() {
|
||||||
LicenseCheck licenseCheck= LicenseValidate.getDeviceInfo();
|
LicenseCheck licenseCheck= LicenseValidate.getSystem_price();
|
||||||
String rest= Base64.encodeBase64String(JSONUtil.toJsonStr(licenseCheck).trim().getBytes());
|
String rest= Base64.encodeBase64String(JSONUtil.toJsonStr(licenseCheck).trim().getBytes());
|
||||||
return ResponseEntity.ok(rest);
|
return ResponseEntity.ok(rest);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue