示例#1
0
func (this *SshRulesController) reloadRules(conn *sql.DB, sshRulesOb models.SshRule, logid int64) error {
	sshKeyOb := new(models.SshKeysManage)
	keylist, err := sshKeyOb.GetAll(conn, strconv.Itoa(sshRulesOb.Uid), logid)
	if err != nil {
		logs.Error("ssh key get all error:", err, "logid:", logid)
		return err
	}
	if len(keylist) <= 0 {
		return nil
	}
	err = models.UpdateRule([]models.SshRule{sshRulesOb}, keylist, logid)
	if err != nil {
		logs.Error("update rule error:", err, "rule list:", sshRulesOb, "key list:", keylist, "logid:", logid)
	}
	return err
}
示例#2
0
func (this *SshKeysController) reloadSshPublicKeys(dbconn *sql.DB, uid string, logid int64) error {
	sshKeysM := new(models.SshKeysManage)
	pubSshKeyMap, errall := sshKeysM.GetAll(dbconn, uid, logid)
	logs.Normal("reloadSshPublicKeys get sshkey map:", pubSshKeyMap, "logid:", logid)
	if errall != nil {
		logs.Error("sshKeysM.GetAll error!", errall, " uid:", uid, "logid:", logid)
		return errall
	}
	//check ssh rules,if the rules is null,then only change ssh keys;
	// if the rules is not null,then change the proxy server
	sshRuleM := new(models.SshRuleManage)
	rulelist, err := sshRuleM.QueryByUid(dbconn, uid, logid)
	if err != nil {
		logs.Error("sshRuleM.QueryByUid error!", err, " uid:", uid, "logid:", logid)
		return err
	}
	logs.Normal("sshRuleM.QueryByUid get rule list:", rulelist, "logid:", logid)
	if len(rulelist) > 0 {
		err = models.UpdateRule(rulelist, pubSshKeyMap, logid)
	}
	return err
}