From 4dbe5aa5a9dd3f41144b3159260e41257ac98d85 Mon Sep 17 00:00:00 2001 From: "Vyacheslav N. Boyko" Date: Sun, 25 Jun 2017 00:07:29 +0300 Subject: [PATCH] implemented sending system uuid --- pom.xml | 2 +- .../licenseserverjclient/LicenseChecker.java | 1 + .../bvn13/licenseserverjclient/SystemID.java | 119 ++++++++++++++++++ .../soap/CheckClientLicense.java | 29 +++++ .../soap/CheckLicenseRequest.java | 28 +++++ 5 files changed, 178 insertions(+), 1 deletion(-) create mode 100644 src/main/java/ru/bvn13/licenseserverjclient/SystemID.java diff --git a/pom.xml b/pom.xml index db416b1..4c65292 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ ru.bvn13 licenseserverjclient - 1.5 + 1.6 LicenseServerJClient diff --git a/src/main/java/ru/bvn13/licenseserverjclient/LicenseChecker.java b/src/main/java/ru/bvn13/licenseserverjclient/LicenseChecker.java index c343bd8..0094a09 100644 --- a/src/main/java/ru/bvn13/licenseserverjclient/LicenseChecker.java +++ b/src/main/java/ru/bvn13/licenseserverjclient/LicenseChecker.java @@ -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); diff --git a/src/main/java/ru/bvn13/licenseserverjclient/SystemID.java b/src/main/java/ru/bvn13/licenseserverjclient/SystemID.java new file mode 100644 index 0000000..ab7cff8 --- /dev/null +++ b/src/main/java/ru/bvn13/licenseserverjclient/SystemID.java @@ -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; + } + + +} diff --git a/src/main/java/ru/bvn13/licenseserverjclient/soap/CheckClientLicense.java b/src/main/java/ru/bvn13/licenseserverjclient/soap/CheckClientLicense.java index 6007ff2..c1bcd67 100644 --- a/src/main/java/ru/bvn13/licenseserverjclient/soap/CheckClientLicense.java +++ b/src/main/java/ru/bvn13/licenseserverjclient/soap/CheckClientLicense.java @@ -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. * diff --git a/src/main/java/ru/bvn13/licenseserverjclient/soap/CheckLicenseRequest.java b/src/main/java/ru/bvn13/licenseserverjclient/soap/CheckLicenseRequest.java index 59836ee..81ba96d 100644 --- a/src/main/java/ru/bvn13/licenseserverjclient/soap/CheckLicenseRequest.java +++ b/src/main/java/ru/bvn13/licenseserverjclient/soap/CheckLicenseRequest.java @@ -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. *