示例#1
0
//curl localhost:9090/sshKeys/123456
func (this *SshKeysController) Get() {
	uid := this.Ctx.Input.Params[":objectId"]
	if uid == "" {
		this.Ctx.Output.SetStatus(403)
		this.Ctx.Output.Body([]byte(`{"result":1,"error":"param error"}`))
		this.StopRun()
	}

	dbconn, err := models.InitDbConn(0)
	if err != nil {
		logs.Error("db init error!", err, 0)
		this.Ctx.Output.SetStatus(500)
		this.Ctx.Output.Body([]byte(`{"result":1,"error":"init db conn error"}`))
		this.StopRun()
	}
	defer dbconn.Close()

	sshKeysM := new(models.SshKeysManage)
	sshKeysOb, err := sshKeysM.GetAll(dbconn, uid, 0)
	if err != nil {
		logs.Error("sshkeysM getall error:", err, 0)
		this.Ctx.Output.SetStatus(500)
		this.Ctx.Output.Body([]byte(`{"result":1,"error":"` + err.Error() + `"}`))
		this.StopRun()
	}
	this.Data["json"] = sshKeysOb
	this.ServeJson()
}
示例#2
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
}
示例#3
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
}