예제 #1
0
func (c *Archivelink) Get() {
	uri := c.Ctx.Request.RequestURI

	app.Debug("uri : %s", uri)

	var cmd string

	p := strings.Index(uri, "?")
	if p != -1 {
		cmd = uri[p+1:]
	}

	p = strings.IndexAny(cmd, "&#")
	if p != -1 {
		cmd = cmd[:p]
	}

	app.DebugSeparator()

	app.Debug("cmd : %s", cmd)

	if cmd != "" {
		switch cmd {
		case SERVERINFO:
			c.serverInfo()
		case PUTCERT:
			c.putCert()
		default:
			c.BadRequest(app.Translate("Unknown command : %s", cmd))
		}
	} else {
		c.BadRequest(app.Translate("Undefined SAP Archivelink command"))
	}
}
예제 #2
0
func (c *Archivelink) putCert() {
	var pis = ParameterInfos{
		CONTREP:   ParameterInfo{optmand: MANDATORY},
		P_VERSION: ParameterInfo{optmand: MANDATORY},
		AUTHID:    ParameterInfo{optmand: MANDATORY},
	}

	if c.check(PUTCERT, &pis) {
		contrep := models.Contrep{Name: c.Param(CONTREP)}

		err := models.Orm.Read(&contrep, "NAme")
		if err != orm.ErrNoRows {
			defer c.Ctx.Request.Body.Close()

			body, err := ioutil.ReadAll(c.Ctx.Request.Body)
			app.CheckPanic(err)

			derFile, err := app.CreateTempFile()
			app.CheckPanic(err)

			derFile.Write(body)
			derFile.Close()

			pemFilename, err := app.CreateTempFilename()
			app.CheckPanic(err)

			err = openssl.ConvertDER2PEM(derFile.Name(), pemFilename)
			app.CheckPanic(err)

			beego.Debug("read ConvertDER2PEM PEM file")

			pem, err := ioutil.ReadFile(pemFilename)
			app.CheckPanic(err)

			if contrep.IsCertProtected {
				contrep.ReceivedCert = string(pem)
				contrep.ReceivedCertDatetime = time.Now()
			} else {
				contrep.Cert = string(pem)
				contrep.CertDatetime = time.Now()
			}

			_, err = models.Orm.Update(&contrep)
			app.CheckPanic(err)
		} else {
			c.CustomAbort(406, app.Translate("Unknown Content Repository %s", c.Param(CONTREP)))
		}
	}
}