implemented sending system uuid
parent
9eb1e50e80
commit
4dbe5aa5a9
2
pom.xml
2
pom.xml
|
@ -6,7 +6,7 @@
|
|||
|
||||
<groupId>ru.bvn13</groupId>
|
||||
<artifactId>licenseserverjclient</artifactId>
|
||||
<version>1.5</version>
|
||||
<version>1.6</version>
|
||||
|
||||
|
||||
<name>LicenseServerJClient</name>
|
||||
|
|
|
@ -40,6 +40,7 @@ public class LicenseChecker {
|
|||
CheckClientLicense.Request params = new CheckClientLicense.Request();
|
||||
params.setClientId(clientId);
|
||||
params.setProperties(properties);
|
||||
params.setSystemId(SystemID.encode(SystemID.getSystemID()));
|
||||
|
||||
CheckClientLicenseResponse.Response result = checkLicenseWS.checkClientLicense(params);
|
||||
|
||||
|
|
|
@ -0,0 +1,119 @@
|
|||
package ru.bvn13.licenseserverjclient;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Base64;
|
||||
|
||||
/**
|
||||
* Created by bvn13 on 24.06.2017.
|
||||
*/
|
||||
public abstract class SystemID {
|
||||
|
||||
private static String OS = System.getProperty("os.name").toLowerCase();
|
||||
|
||||
private static boolean isWindows()
|
||||
{
|
||||
return (OS.indexOf("win") >= 0);
|
||||
}
|
||||
private static boolean isUnix()
|
||||
{
|
||||
return (OS.indexOf("win") < 0); //(OS.indexOf("nux") >= 0);
|
||||
}
|
||||
|
||||
private static String getVolumeUUID()
|
||||
{
|
||||
Process p;
|
||||
BufferedReader reader;
|
||||
String line = "NOT FOUND";
|
||||
|
||||
if(isWindows()) {
|
||||
|
||||
String userDir = new File(System.getProperty("user.dir")).getAbsolutePath();
|
||||
String rootDir = userDir.substring(0, userDir.indexOf(File.separator)+1);
|
||||
String drive = ""+rootDir.substring(0,1);
|
||||
String query = "cmd /c"+" vol "+drive+":";
|
||||
|
||||
try {
|
||||
p = Runtime.getRuntime().exec(query);
|
||||
p.waitFor();
|
||||
reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
|
||||
|
||||
if (isWindows()) {
|
||||
reader.readLine();
|
||||
}
|
||||
line = reader.readLine();
|
||||
line = line.substring(line.lastIndexOf(" ") + 1);
|
||||
} catch(IOException ex) {
|
||||
//ex.printStackTrace();
|
||||
} catch (InterruptedException e) {
|
||||
//e.printStackTrace();
|
||||
}
|
||||
|
||||
return line;
|
||||
|
||||
} else if(isUnix()) {
|
||||
|
||||
String query = "lsblk --nodeps -o name,serial";
|
||||
|
||||
try {
|
||||
p = Runtime.getRuntime().exec(query);
|
||||
p.waitFor();
|
||||
reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
|
||||
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if (line.startsWith("sda ")) {
|
||||
line = line.substring(line.lastIndexOf(" ") + 1);
|
||||
return line;
|
||||
}
|
||||
}
|
||||
|
||||
} catch(IOException ex) {
|
||||
//ex.printStackTrace();
|
||||
} catch (InterruptedException e) {
|
||||
//e.printStackTrace();
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
//System.out.println("WRONG SYSTEM");
|
||||
return "WRONG SYSTEM";
|
||||
}
|
||||
|
||||
return line;
|
||||
}
|
||||
|
||||
|
||||
public static String getSystemID() {
|
||||
String systemInfo = "System info: ";
|
||||
|
||||
systemInfo += "\n" + "Available processors (cores): " + Runtime.getRuntime().availableProcessors();
|
||||
long maxMemory = Runtime.getRuntime().maxMemory();
|
||||
systemInfo += "\n" + "Maximum memory (bytes): " + (maxMemory == Long.MAX_VALUE ? "no limit" : maxMemory);
|
||||
String userDir = new File(System.getProperty("user.dir")).getAbsolutePath();
|
||||
String rootDir = userDir.substring(0, userDir.indexOf(File.separator)+1);
|
||||
systemInfo += "\n" + "Root dir: "+rootDir;
|
||||
systemInfo += "\n" + "Root volume UUID: "+getVolumeUUID();
|
||||
File[] roots = File.listRoots();
|
||||
for (File root : roots) {
|
||||
if (root.getAbsolutePath().equals(rootDir)) {
|
||||
systemInfo += "\n" + "Root dir total space: "+root.getTotalSpace();
|
||||
}
|
||||
}
|
||||
|
||||
return systemInfo;
|
||||
}
|
||||
|
||||
|
||||
public static String encode(String data) {
|
||||
Base64.Encoder encoder = Base64.getEncoder();
|
||||
return encoder.encodeToString(data.getBytes());
|
||||
}
|
||||
|
||||
public static String decode(String data) throws UnsupportedEncodingException {
|
||||
Base64.Decoder decoder = Base64.getDecoder();
|
||||
byte[] base64decodedBytes = decoder.decode(data);
|
||||
String decodedString = new String(base64decodedBytes, "utf-8");
|
||||
return decodedString;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -23,6 +23,7 @@ import javax.xml.bind.annotation.XmlType;
|
|||
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
|
||||
* <sequence>
|
||||
* <element name="clientId" type="{http://www.w3.org/2001/XMLSchema}string" form="qualified"/>
|
||||
* <element name="systemId" type="{http://www.w3.org/2001/XMLSchema}string" form="qualified"/>
|
||||
* <element name="properties" type="{http://www.w3.org/2001/XMLSchema}string" form="qualified"/>
|
||||
* </sequence>
|
||||
* </restriction>
|
||||
|
@ -82,6 +83,7 @@ public class CheckClientLicense {
|
|||
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
|
||||
* <sequence>
|
||||
* <element name="clientId" type="{http://www.w3.org/2001/XMLSchema}string" form="qualified"/>
|
||||
* <element name="systemId" type="{http://www.w3.org/2001/XMLSchema}string" form="qualified"/>
|
||||
* <element name="properties" type="{http://www.w3.org/2001/XMLSchema}string" form="qualified"/>
|
||||
* </sequence>
|
||||
* </restriction>
|
||||
|
@ -94,6 +96,7 @@ public class CheckClientLicense {
|
|||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(name = "", propOrder = {
|
||||
"clientId",
|
||||
"systemId",
|
||||
"properties"
|
||||
})
|
||||
public static class Request {
|
||||
|
@ -101,6 +104,8 @@ public class CheckClientLicense {
|
|||
@XmlElement(required = true)
|
||||
protected String clientId;
|
||||
@XmlElement(required = true)
|
||||
protected String systemId;
|
||||
@XmlElement(required = true)
|
||||
protected String properties;
|
||||
|
||||
/**
|
||||
|
@ -127,6 +132,30 @@ public class CheckClientLicense {
|
|||
this.clientId = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the systemId property.
|
||||
*
|
||||
* @return
|
||||
* possible object is
|
||||
* {@link String }
|
||||
*
|
||||
*/
|
||||
public String getSystemId() {
|
||||
return systemId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the systemId property.
|
||||
*
|
||||
* @param value
|
||||
* allowed object is
|
||||
* {@link String }
|
||||
*
|
||||
*/
|
||||
public void setSystemId(String value) {
|
||||
this.systemId = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the properties property.
|
||||
*
|
||||
|
|
|
@ -19,6 +19,7 @@ import javax.xml.bind.annotation.XmlType;
|
|||
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
|
||||
* <sequence>
|
||||
* <element name="clientId" type="{http://www.w3.org/2001/XMLSchema}string" form="qualified"/>
|
||||
* <element name="systemId" type="{http://www.w3.org/2001/XMLSchema}string" form="qualified"/>
|
||||
* <element name="properties" type="{http://www.w3.org/2001/XMLSchema}string" form="qualified"/>
|
||||
* </sequence>
|
||||
* </restriction>
|
||||
|
@ -31,6 +32,7 @@ import javax.xml.bind.annotation.XmlType;
|
|||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(name = "", propOrder = {
|
||||
"clientId",
|
||||
"systemId",
|
||||
"properties"
|
||||
})
|
||||
@XmlRootElement(name = "checkLicenseRequest")
|
||||
|
@ -39,6 +41,8 @@ public class CheckLicenseRequest {
|
|||
@XmlElement(required = true)
|
||||
protected String clientId;
|
||||
@XmlElement(required = true)
|
||||
protected String systemId;
|
||||
@XmlElement(required = true)
|
||||
protected String properties;
|
||||
|
||||
/**
|
||||
|
@ -65,6 +69,30 @@ public class CheckLicenseRequest {
|
|||
this.clientId = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the systemId property.
|
||||
*
|
||||
* @return
|
||||
* possible object is
|
||||
* {@link String }
|
||||
*
|
||||
*/
|
||||
public String getSystemId() {
|
||||
return systemId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the systemId property.
|
||||
*
|
||||
* @param value
|
||||
* allowed object is
|
||||
* {@link String }
|
||||
*
|
||||
*/
|
||||
public void setSystemId(String value) {
|
||||
this.systemId = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the properties property.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue