Ejemplo n.º 1
0
func (this *FastResponse) Init(reqest FastRequestInterface) {
	this.ReqSessionId = reqest.GetReqSessionId()
	this.ReqActionId = reqest.GetReqActionId()
	this.ReqStartTime = reqest.GetReqStartTime()

	this.RspFinishTime = utils.StrTime()

	if this.GetRspRetId() == comm.NULL_STR {
		this.RspRetId = msg.MSG_SUCCESS
	}

	if this.GetRspRetLevel() == comm.NULL_STR {
		this.RspRetLevel = msg.MSG_LEVEL_INFO
	}

}
Ejemplo n.º 2
0
func (this *FastResponse) SetRspRetId(retId string) {
	this.RspRetId = retId
	this.RspFinishTime = utils.StrTime()

	msgInfo, ok := msg.Item(retId)

	if !ok {
		this.RspRetLevel = msg.MSG_LEVEL_INFO
		this.RspRetMsg = retId
		return
	}

	this.RspRetLevel = msgInfo.Level
	this.RspRetMsg = msgInfo.MsgInfo

	return
}
Ejemplo n.º 3
0
func (this *logMgrImpl) ParseLogs(sessionId string) {
	sessMgr := SessionMgr()
	session, ok := sessMgr.GetSession(sessionId)
	if !ok {
		return
	}

	padinDir, err := os.Open(this.getPadinPath())
	utils.VerifyErr(err)
	defer padinDir.Close()

	logFiles, err := padinDir.Readdir(0)
	utils.VerifyErr(err)
	for _, logFileInfo := range logFiles {

		if logFileInfo.IsDir() {
			continue
		}
		logFileName := logFileInfo.Name()
		if !strings.HasSuffix(logFileName, ".json") {
			continue
		}
		if !strings.HasPrefix(logFileName, "PadLog") {
			continue
		}

		fmt.Println("PadLog file,name=", this.getPadinPath()+"/"+logFileName)
		file, err := os.Open(this.getPadinPath() + "/" + logFileName)
		utils.VerifyErr(err)
		defer func() {
			file.Close()
			os.Remove(this.getPadinPath() + "/" + logFileName)
		}()

		bytes, err := ioutil.ReadAll(file)
		utils.VerifyErr(err)
		if len(bytes) < 20 {
			continue
		}

		if bytes[len(bytes)-1] == ',' {
			bytes[len(bytes)-1] = ']'
		} else if bytes[len(bytes)-2] == ',' {
			bytes[len(bytes)-2] = ']'
		} else if bytes[len(bytes)-3] == ',' {
			bytes[len(bytes)-3] = ']'
		} else if bytes[len(bytes)-4] == ',' {
			bytes[len(bytes)-4] = ']'
		} else if bytes[len(bytes)-5] == ',' {
			bytes[len(bytes)-5] = ']'
		}

		logs := []OperateLog{}
		err = json.Unmarshal(bytes, &logs)
		utils.VerifyErr(err)

		for _, log := range logs {
			log.OperateRetDetail = "Import By " + session.GetUserName() + " at " + utils.StrTime()
			this.WriteRawLog(&log)
		}

	}

}
Ejemplo n.º 4
0
func (this *SafeSession) KeepAlive() {
	this.KeepAliveTime = utils.StrTime()
	return
}
Ejemplo n.º 5
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
}
Ejemplo n.º 6
0
func (this *FastResponse) SetBeforeSend() {
	this.RspFinishTime = utils.StrTime()
}