From f455f4ffec96c5838de6f10b7b2959c860485be1 Mon Sep 17 00:00:00 2001
From: zhangzengfei <zhangzengfei@iotlink.com>
Date: 星期五, 02 四月 2021 14:47:51 +0800
Subject: [PATCH] 添加试用期校验

---
 os.go      |   28 ++++++++++++++++++++++++++++
 licence.go |   12 +++++++++++-
 2 files changed, 39 insertions(+), 1 deletions(-)

diff --git a/licence.go b/licence.go
index e81955c..96f81ec 100644
--- a/licence.go
+++ b/licence.go
@@ -154,13 +154,23 @@
 
 func _verifyLicence(licenceText []byte) uint32 {
 	var licence Licence
+	var now = time.Now().Unix()
 
 	if err := json.Unmarshal(licenceText, &licence); err != nil {
 		return ValidationErrorMalformed
 	}
 
+	// 鍒ゆ柇鏄惁鍙互璇曠敤
+	if licence.RegCode.MachineCode == "FFFFFFFF" {
+		osInstallTime := GetOSInstallationDate()
+		if now - osInstallTime > 60 * 60 * 24 * 30 {
+			return ValidationErrorExpired
+		}
+
+		return 0
+	}
+
 	// 鍒ゆ柇杩囨湡
-	now := time.Now().Unix()
 	if now > licence.Expires {
 		return ValidationErrorExpired
 	}
diff --git a/os.go b/os.go
new file mode 100644
index 0000000..af85516
--- /dev/null
+++ b/os.go
@@ -0,0 +1,28 @@
+package licence
+
+import (
+	"fmt"
+	"io/ioutil"
+	"time"
+	"syscall"
+)
+
+func GetOSInstallationDate() int64{
+	fileSystemCreateTime := time.Now().Unix()
+
+	fileSystemDir := "/etc"
+
+	fileInfoList, err := ioutil.ReadDir(fileSystemDir)
+	if err != nil {
+		fmt.Println(err)
+	}
+
+	for i := range fileInfoList {
+		stat_t := fileInfoList[i].Sys().(*syscall.Stat_t)
+		if stat_t.Ctim.Sec < fileSystemCreateTime{
+			fileSystemCreateTime = stat_t.Ctim.Sec
+		}
+	}
+
+	return fileSystemCreateTime
+}
\ No newline at end of file

--
Gitblit v1.8.0