Exemplo n.º 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)
}
Exemplo n.º 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
}
Exemplo n.º 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)
}
Exemplo n.º 4
0
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)
}
Exemplo n.º 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
	}
}
Exemplo n.º 6
0
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
	}
}
Exemplo n.º 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)
}
Exemplo n.º 8
0
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)
	}
}
Exemplo n.º 9
0
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?")
}
Exemplo n.º 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})
}
Exemplo n.º 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)
}
Exemplo n.º 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})
}
Exemplo n.º 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
}
Exemplo n.º 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
	}
}
Exemplo n.º 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()
	}
}
Exemplo n.º 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)
	}
}
Exemplo n.º 17
0
// 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)
	}
}
Exemplo n.º 18
0
// 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)
	}
}
Exemplo n.º 19
0
func (e *Editor) UnWatch(name string) {
	log4go.Finest("UnWatch(%s)", name)
	delete(e.watchedFiles, name)
}
Exemplo n.º 20
0
func (ve ViewEvent) Call(v *View) {
	log4go.Finest("ViewEvent")
	for i := range ve {
		ve[i](v)
	}
}
Exemplo n.º 21
0
func (we WindowEvent) Call(w *Window) {
	log4go.Finest("WindowEvent")
	for i := range we {
		we[i](w)
	}
}
Exemplo n.º 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
}