示例#1
0
// This is a URL handler that handles updating permissions for a user on an object
func denyPrivilegesHandler(w http.ResponseWriter, r *http.Request) {

	log.Finest("Inside deny privileges.")

	c, service, object, body, err := getRequestData(w, r, true)
	if err != nil {
		// Already responded in getBody call
		return
	}

	for _, val := range body {

		_, key, user, privileges := getItemData(w, val, true, true)
		if key == "" || user == "" {
			// Couldn't get proper data from body.  Already responded in getItemData call
			return
		}

		log.Finest("Denying privilege")

		_, err = ACL{}.Deny(c, service, object, key, user, privileges)

		if err != nil {
			log.Error("An error occurred denying privileges. Body: %s\n URL: %s\nMessage: %s",
				r.Body, r.URL.RequestURI(), err)
			http.Error(w, "An error occurred granting privileges", 500)
			return
		}
	}

	w.WriteHeader(204)
}
示例#2
0
func (ch *commandHandler) Register(name string, cmd interface{}) error {
	var r = false
	log4go.Finest("Want to register %s", name)
	if ac, ok := cmd.(ApplicationCommand); ok {
		if _, ok := ch.ApplicationCommands[name]; ok {
			return fmt.Errorf("%s is already a registered command", name)
		}
		r = true
		ch.ApplicationCommands[name] = ac
	}
	if wc, ok := cmd.(WindowCommand); ok {
		if _, ok := ch.WindowCommands[name]; ok {
			return fmt.Errorf("%s is already a registered command", name)
		}
		r = true
		ch.WindowCommands[name] = wc
	}
	if tc, ok := cmd.(TextCommand); ok {
		if _, ok := ch.TextCommands[name]; ok {
			return fmt.Errorf("%s is already a registered command", name)
		}
		r = true
		ch.TextCommands[name] = tc
	}
	if !r {
		return fmt.Errorf("Command wasn't registered in any list: %s", name)
	} else if ch.verbose {
		log4go.Finest("Successfully registered command %s", name)
	}
	return nil
}
示例#3
0
func unWatch(name string) {
	if err := watcher.RemoveWatch(name); err != nil {
		log4go.Error("Couldn't unwatch file: %v", err)
	}
	log4go.Finest("UnWatch(%s)", name)
	delete(watchedPlugins, name)
}
示例#4
0
文件: editor.go 项目: jeppojeps/lime
func (e *Editor) UnWatch(name string) {
	if err := e.watcher.RemoveWatch(name); err != nil {
		log4go.Error("Couldn't unwatch file: %v", err)
	}
	log4go.Finest("UnWatch(%s)", name)
	delete(e.watchedFiles, name)
}
示例#5
0
func watch(plugin *backend.WatchedPackage) {
	log4go.Finest("Watch(%v)", plugin)
	if err := watcher.Watch(plugin.Name()); err != nil {
		log4go.Error("Could not watch plugin: %v", err)
	} else {
		watchedPlugins[plugin.Name()] = plugin
	}
}
示例#6
0
文件: editor.go 项目: jeppojeps/lime
func (e *Editor) Watch(file Watched) {
	log4go.Finest("Watch(%v)", file)
	if err := e.watcher.Watch(file.Name()); err != nil {
		log4go.Error("Could not watch file: %v", err)
	} else {
		e.watchedFiles[file.Name()] = file
	}
}
示例#7
0
// Sets the privileges to a whole new ACL
func (a ACL) Set(c *mgo.Collection, service string, object string, key string, user string, privileges map[string]interface{}) (*mgo.ChangeInfo, error) {
	selector := bson.M{"service": service, "object": object, "key": key, "user": user}
	update := copyMap(selector)
	update["privileges"] = privileges

	log.Finest("Setting Privilege: %s", update)
	return c.Upsert(selector, update)
}
示例#8
0
文件: editor.go 项目: EDi-nabi/lime
func (e *Editor) inputthread() {
	pc := 0
	var lastBindings KeyBindings
	doinput := func(kp KeyPress) {
		defer func() {
			if r := recover(); r != nil {
				log4go.Error("Panic in inputthread: %v\n%s", r, string(debug.Stack()))
				if pc > 0 {
					panic(r)
				}
				pc++
			}
		}()
		p := Prof.Enter("hi")
		defer p.Exit()

		lvl := log4go.FINE
		if e.loginput {
			lvl++
		}
		log4go.Logf(lvl, "Key: %v", kp)
		if lastBindings.keyOff == 0 {
			lastBindings = e.keyBindings
		}
	try_again:
		possible_actions := lastBindings.Filter(kp)
		lastBindings = possible_actions

		// TODO?
		var (
			wnd *Window
			v   *View
		)
		if wnd = e.ActiveWindow(); wnd != nil {
			v = wnd.ActiveView()
		}

		if action := possible_actions.Action(v); action != nil {
			p2 := Prof.Enter("hi.perform")
			e.RunCommand(action.Command, action.Args)
			p2.Exit()
		} else if possible_actions.keyOff > 1 {
			lastBindings = e.keyBindings
			goto try_again
		} else if kp.IsCharacter() {
			p2 := Prof.Enter("hi.character")
			log4go.Finest("kp: %v, pos: %v", kp, possible_actions)
			if err := e.CommandHandler().RunTextCommand(v, "insert", Args{"characters": string(rune(kp.Key))}); err != nil {
				log4go.Debug("Couldn't run textcommand: %s", err)
			}
			p2.Exit()
		}
	}
	for kp := range e.keyInput {
		doinput(kp)
	}
}
func main() {
	// Load the configuration (isn't this easy?)
	l4g.LoadConfiguration("example.xml")

	// And now we're ready!
	l4g.Finest("This will only go to those of you really cool UDP kids!  If you change enabled=true.")
	l4g.Debug("Oh no!  %d + %d = %d!", 2, 2, 2+2)
	l4g.Info("About that time, eh chaps?")
}
示例#10
0
// Revokes the privileges from the existing ACL
func (a ACL) Revoke(c *mgo.Collection, service string, object string, key string, user string, privileges []string) (*mgo.ChangeInfo, error) {
	selector := bson.M{"service": service, "object": object, "key": key, "user": user}
	toRevoke := map[string]interface{}{}
	for _, privilege := range privileges {
		toRevoke["privileges."+privilege] = ""
	}
	log.Finest("Revoking Privilege: %s, %s", selector, toRevoke)
	return c.Upsert(selector, bson.M{"$unset": toRevoke})
}
示例#11
0
// Retrieves the ACL from the collection using the object's key and the user, if the user is granted privileges
func (a ACL) Has(c *mgo.Collection, service string, object string, key string, user string, privileges []string) error {
	selector := bson.M{"service": service, "object": object, "key": key, "user": user}
	for _, privilege := range privileges {
		selector["privileges."+privilege] = "allow"
	}

	log.Finest("Checking user has privilege: %s", selector)
	result := ACL{}
	return c.Find(selector).One(&result)
}
示例#12
0
// Denies the privileges from the existing ACL
func (a ACL) Deny(c *mgo.Collection, service string, object string, key string, user string, privileges []string) (*mgo.ChangeInfo, error) {
	selector := bson.M{"service": service, "object": object, "key": key, "user": user}
	update := copyMap(selector)

	for _, privilege := range privileges {
		update["privileges."+privilege] = "deny"
	}

	log.Finest("Denying Privilege: %s", update)
	return c.Upsert(selector, bson.M{"$set": update})
}
示例#13
0
// Retrieves a list of the keys for a service/object/user combo that the user has "allow" privileges for
func (a ACL) Match(c *mgo.Collection, service string, object string, user string, privileges []string) ([]string, error) {
	selector := bson.M{"service": service, "object": object, "user": user}
	for _, privilege := range privileges {
		selector["privileges."+privilege] = "allow"
	}

	log.Finest("Matching user privileges to keys: %s", selector)
	result := []string{}
	err := c.Find(selector).Distinct("key", &result)
	return result, err
}
示例#14
0
// Gets common data from a request for certain request handlers
func getRequestData(w http.ResponseWriter, r *http.Request, processBody bool) (*mgo.Collection,
	string, string, []map[string]interface{}, error) {
	c := context.Get(r, "mongoColl").(*mgo.Collection)
	vars := mux.Vars(r)
	service := vars["service"]
	object := vars["object"]

	log.Finest("Request URL Info: service: %s object: %s", service, object)

	if processBody {
		body, err := getBody(w, r)
		return c, service, object, body, err
	} else {
		return c, service, object, nil, nil
	}
}
示例#15
0
func (t *tbfe) renderthread() {
	pc := 0
	dorender := func() {
		defer func() {
			if r := recover(); r != nil {
				log4go.Error("Panic in renderthread: %v\n%s", r, string(debug.Stack()))
				if pc > 1 {
					panic(r)
				}
				pc++
			}
		}()
		termbox.Clear(defaultFg, defaultBg)
		w, h := termbox.Size()
		for y := 0; y < h; y++ {
			for x := 0; x < w; x++ {
				termbox.SetCell(x, y, ' ', defaultFg, defaultBg)
			}
		}
		t.lock.Lock()
		vs := make([]*backend.View, 0, len(t.layout))
		l := make([]layout, 0, len(t.layout))
		for k, v := range t.layout {
			vs = append(vs, k)
			l = append(l, v)
		}
		t.lock.Unlock()
		for i, v := range vs {
			t.renderView(v, l[i])
		}
		t.lock.Lock()
		runes := []rune(t.status_message)
		t.lock.Unlock()
		for i := 0; i < w && i < len(runes); i++ {
			termbox.SetCell(i, h-1, runes[i], defaultFg, defaultBg)
		}
		termbox.Flush()
	}
	for a := range t.dorender {
		_ = a
		log4go.Finest("Rendering")
		dorender()
	}
}
示例#16
0
func (o *WatchedUserFile) Reload() {
	log4go.Finest("\"%v\".Reload()", o)

	view := o.view
	filename := o.Name()

	if saving, ok := view.Settings().Get("lime.saving", false).(bool); ok && saving {
		// This reload was triggered by ourselves saving to this file, so don't reload it
		return
	}
	if !GetEditor().Frontend().OkCancelDialog("File was changed by another program, reload?", "reload") {
		return
	}

	if d, err := ioutil.ReadFile(filename); err != nil {
		log4go.Error("Could not read file: %s\n. Error was: %v", filename, err)
	} else {
		edit := view.BeginEdit()
		end := view.Buffer().Size()
		view.Replace(edit, Region{0, end}, string(d))
		view.EndEdit(edit)
	}
}
示例#17
0
文件: events.go 项目: Unverified/lime
// Trigger this ViewEvent by calling all the registered callbacks in order of registration.
func (ve *ViewEvent) Call(v *View) {
	log4go.Finest("%s(%v)", evNames[ve], v.Id())
	for _, ev := range *ve {
		ev(v)
	}
}
示例#18
0
文件: events.go 项目: Unverified/lime
// Trigger this WindowEvent by calling all the registered callbacks in order of registration.
func (we *WindowEvent) Call(w *Window) {
	log4go.Finest("%s(%v)", wevNames[we], w.Id())
	for _, ev := range *we {
		ev(w)
	}
}
示例#19
0
func (e *Editor) UnWatch(name string) {
	log4go.Finest("UnWatch(%s)", name)
	delete(e.watchedFiles, name)
}
示例#20
0
文件: events.go 项目: kiawin/lime
func (ve ViewEvent) Call(v *View) {
	log4go.Finest("ViewEvent")
	for i := range ve {
		ve[i](v)
	}
}
示例#21
0
文件: events.go 项目: kiawin/lime
func (we WindowEvent) Call(w *Window) {
	log4go.Finest("WindowEvent")
	for i := range we {
		we[i](w)
	}
}
示例#22
0
func (c *TextCommandGlue) Run(v *backend.View, e *backend.Edit) error {
	l := py.NewLock()
	defer l.Unlock()

	p0 := util.Prof.Enter("tc.run")
	defer p0.Exit()
	var (
		pyv, pye, pyargs, obj py.Object
		err                   error
	)
	if pyv, err = toPython(v); err != nil {
		return pyError(err)
	}
	defer pyv.Decref()

	if pye, err = toPython(e); err != nil {
		return pyError(err)
	}
	defer pye.Decref()

	if pyargs, err = c.CreatePyArgs(c.args); err != nil {
		return pyError(err)
	}
	defer pyargs.Decref()

	init := util.Prof.Enter("tc.init")
	if obj, err = c.inner.Base().CallFunctionObjArgs(pyv); err != nil {
		return pyError(err)
	}
	defer obj.Decref()
	init.Exit()
	// interrupt := true
	// defer func() { interrupt = false }()
	// go func() {
	// 	<-time.After(time.Second * 5)
	// 	if interrupt {
	// 		py.SetInterrupt()
	// 	}
	// }()
	exec := util.Prof.Enter("tc.exec")
	defer exec.Exit()
	if obj.Base().HasAttrString("run_") {
		// The plugin is probably trying to bypass the undostack...
		old := v.IsScratch()
		v.SetScratch(true)
		log4go.Finest("Discarded: %s", e)
		v.EndEdit(e)
		v.SetScratch(old)
		ret, err := obj.Base().CallMethodObjArgs("run_", pye, pyargs)
		if ret != nil {
			ret.Decref()
		}
		if err != nil {
			return pyError(err)
		}
		return nil
	}
	ret, err := obj.Base().CallMethodObjArgs("run__", pye, pyargs)
	if ret != nil {
		ret.Decref()
	}
	if err != nil {
		return pyError(err)
	}
	return nil
}