Esempio n. 1
0
func buildDeveloper() {
	licenseInfo := &FastLicenseInfo{}
	licenseInfo.Reset()

	licenseInfo.Distributor = "liuyong"
	licenseInfo.DistributeId = "liuyong1024"

	licenseInfo.LicenseId = "develop"
	licenseInfo.LicenseType = LICENSE_TYPE_DEVELOP

	licenseInfo.CustomerId = "FFFFFFFFFFFF"
	licenseInfo.CustomerName = "developer"

	licenseInfo.BindNetCard = comm.NULL_STR
	licenseInfo.BindDisk = comm.NULL_STR
	licenseInfo.BindCPU = comm.NULL_STR

	licenseInfo.ExpiryDate = "2015-09-15 23:59:59"
	licenseInfo.Remark = comm.NULL_STR

	licenseInfo.AllowInt["clientOnlineLimit"] = 5
	licenseInfo.AllowInt["lockLimit"] = 10000
	licenseInfo.AllowInt["userGroupLimit"] = 256
	licenseInfo.AllowInt["timeTableLimit"] = 8
	licenseInfo.AllowInt["commonDoorLimit"] = 53

	givePads := []string{}
	givePads = append(givePads, "superpad")
	givePads = append(givePads, "353723050291384")
	givePads = append(givePads, "869274012114451")
	givePads = append(givePads, "861519010479951")
	givePads = append(givePads, "BX9034PWKC")
	givePads = append(givePads, "2F32000200000001")
	givePads = append(givePads, "021YHB2133052646")

	licenseInfo.AllowStrs["givePads"] = givePads

	byteLicense, err := json.MarshalIndent(licenseInfo, "", "  ")
	utils.VerifyErr(err)

	licenseContent := utils.EnCodeBase64(string(byteLicense))
	licenseContent = utils.EnCodeBase64(licenseContent)
	licenseContent = utils.EnCodeBase64(licenseContent)

	fmt.Println(licenseContent)

	licenseFile := "developlicense.lic"
	fout, err := os.Create(licenseFile)
	defer fout.Close()
	if err != nil {
		fmt.Println(licenseFile, err)
		return
	}

	fout.Write([]byte(licenseContent))

}
Esempio n. 2
0
func (this *licenseMgr) ClearLicense() {
	if !utils.SysParaMgr().ExistPara(LICENSE_PARA_NAME) {
		return
	}

	emptyLicense := &FastLicenseInfo{}
	emptyLicense.Reset()

	byteEmptyLicense, err := json.MarshalIndent(emptyLicense, "", "  ")
	utils.VerifyErr(err)

	emptyLicenseStr := utils.EnCodeBase64(string(byteEmptyLicense))
	emptyLicenseStr = utils.EnCodeBase64(emptyLicenseStr)
	emptyLicenseStr = utils.EnCodeBase64(emptyLicenseStr)

	utils.SysParaMgr().ChangePara(LICENSE_PARA_NAME, emptyLicenseStr)

	return
}
Esempio n. 3
0
func (this *ConsultSessionAction) Post() {
	reqMsg := &ConsultSessionRequest{}
	if !this.GetReqJson(reqMsg) {
		return
	}

	rspMsg := &ConsultSessionResponse{}
	rspMsg.Init(reqMsg)

	rspMsg.SessionSeed = utils.RandStr() + "sessionId"
	rspMsg.SessionSeed = utils.EnCodeBase64(rspMsg.SessionSeed)
	rspMsg.SessionSeed = utils.Md5(rspMsg.SessionSeed)

	this.SendJson(rspMsg)
}
Esempio n. 4
0
func (this *sessionMgrImpl) login(req *http.Request, userName, pasword, hostIp, hostName string) (session *SafeSession, msgId string, ok bool) {
	session = nil
	msgId = comm.NULL_STR
	ok = false

	userName = strings.TrimSpace(userName)
	pasword = strings.TrimSpace(pasword)

	if userName == comm.NULL_STR || pasword == comm.NULL_STR {
		msgId = msg.MSG_PARA_ABSENT
		return
	}

	user, ok := UserMgr().getUserByName(userName)
	if !ok {
		msgId = MSG_USER_INVALID
		return
	}

	msgId, ok = UserMgr().isValid(user.GetId())
	if !ok {
		return
	}

	pasword = utils.PasswordBySeed(pasword, user.GetId())

	if user.Password != pasword {
		msgId = MSG_PASSWORD_ERROR
		ok = false
		return
	}

	if this.IsOnLine(userName) {
		this.Offline(userName)
	}

	clientOnlineLimit := LicenseMgr().GetAllowInt("clientOnlineLimit")
	activateClient := len(this.mapSessions)
	if activateClient >= clientOnlineLimit && !LicenseMgr().IsEmpty() {
		msgId = msg.MSG_LICENSE_NOENOUGH
		ok = false
		return
	}

	session = &SafeSession{}

	session.LoginUserId = user.Id
	session.LoginUserName = user.Name

	session.RandId = utils.RandStr()
	session.ConnTime = utils.StrTime()

	session.ClientIp = hostIp
	session.ClientHost = hostName
	session.ServerIp = req.Host
	session.ServerHost = req.Host

	session.KeepAliveTime = session.ConnTime
	session.SessionStatus = SAFE_SESSION_LOGIN

	session.Id = session.LoginUserName + "&" + session.ConnTime + "&" + utils.RandStr()
	session.Id = utils.EnCodeBase64(session.GetId())
	session.Id = utils.Md5(session.GetId())

	this.mapSessions[session.GetId()] = session

	db := ds.DB()
	defer db.Close()

	insertSql := "insert into fast.safeSession values($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11)"
	insertStmt, err := db.Prepare(insertSql)
	utils.VerifyErr(err)
	insertStmt.Exec(
		session.Id,
		session.RandId,
		session.ConnTime,
		session.LoginUserId,
		session.LoginUserName,
		session.ClientIp,
		session.ClientHost,
		session.ServerIp,
		session.ServerHost,
		session.KeepAliveTime,
		session.SessionStatus)

	insertStmt.Close()

	msgId = msg.MSG_SUCCESS
	ok = true

	return
}