Ejemplo n.º 1
0
func (ctx *context) load() {
	ctx.Lock()
	defer ctx.Unlock()

	// clear handlers
	for _, suffix := range ctx.markdowns {
		delete(handlers, suffix)
	}
	for _, suffix := range ctx.templates {
		delete(handlers, suffix)
	}
	delete(handlers, "page")
	delete(handlers, "system")

	// load
	conf := ctx.app.Configs
	conf.SetSection("h2object")

	ctx.site_name = conf.StringDefault("site.name", "")
	ctx.site_description = conf.StringDefault("site.description", "")
	ctx.site_author = conf.StringDefault("site.author", "h2object")
	ctx.site_contact = conf.StringDefault("site.author", "*****@*****.**")

	appid_dft, _ := util.AlphaStringRange(24, 32)
	secret_dft, _ := util.AlphaStringRange(32, 36)
	appid := conf.StringDefault("appid", appid_dft)
	secret := conf.StringDefault("secret", secret_dft)

	ctx.host = conf.StringDefault("host", ctx.app.Options.HTTPAddress)
	ctx.index = conf.StringDefault("index", "")
	ctx.signature = util.SignString(secret, appid)
	ctx.markdowns = conf.MultiStringDefault("markdown.suffix", ",", []string{"md", "markdown"})
	ctx.templates = conf.MultiStringDefault("template.suffix", ",", []string{"html", "htm", "tpl"})
	ctx.cache_duration = conf.DurationDefault("markdown.cache", 10*time.Minute)
	ctx.devmode = conf.BoolDefault("develope.mode", false)

	ctx.storage = uint64(util.FolderSize(ctx.app.Options.Root, nil))
	ctx.storage_max = ctx.app.Options.StorageMax
	if ctx.storage_max > 0 {
		ctx.Info("application storage current size (%s), max size (%s)",
			humanize.IBytes(ctx.storage), humanize.IBytes(ctx.storage_max))
	}

	// reset handlers
	for _, suffix := range ctx.markdowns {
		handlers[suffix] = do_markdown
	}
	for _, suffix := range ctx.templates {
		handlers[suffix] = do_template
	}
	if ctx.devmode {
		handlers["page"] = do_page
		handlers["click"] = do_click
		handlers["system"] = do_system
	}
}
Ejemplo n.º 2
0
func NewAdminAuth(appid, secret string) Auth {
	auth := NewHeaderAuth()
	auth.Del("Authorization")
	auth.Add("Authorization", fmt.Sprintf("H2OBJECT %s", util.SignString(secret, appid)))
	return auth
}
Ejemplo n.º 3
0
func (api *APIController) sign(secret, appid string) string {
	api.signature = util.SignString(secret, appid)
	return api.signature
}