Exemple #1
0
func Deleteuser(ctx *macaron.Context) string {
	hcuser, auth := util.Auth(ctx, "sysusers")
	if !auth {
		return "not_authorized"
	}

	username := util.Query(ctx, "username")

	if username == "" || username == "root" {
		return "username_required"
	}

	db, _ := util.MySQL()
	defer db.Close()

	// check if user actually owns child
	if !util.ChkPaternity(hcuser.System_username, username) {
		return "failed_ownership_check"
	}

	users := make(map[string]map[string]string)
	users = util.Getusers(username, users, db)
	for _, subuser := range users {
		cleanupuserdata(subuser["system_username"], ctx)
		// delete the user and homedir
		util.Cmd("userdel", []string{subuser["system_username"], "-f", "-r"})
		// remove the user
		stmt, _ := db.Prepare("delete from hostcontrol_users where system_username=?")
		stmt.Exec(subuser["system_username"])
		stmt.Close()

	}

	cleanupuserdata(username, ctx)

	// delete the user and homedir
	util.Cmd("userdel", []string{username, "-f", "-r"})

	// make sure user was delete
	_, lookup_err2 := user.Lookup(username)
	if lookup_err2 == nil {
		return "failed_to_delete_user"
	}

	// remove the user
	stmt, _ := db.Prepare("delete from hostcontrol_users where system_username=?")
	stmt.Exec(username)
	stmt.Close()

	return "success"
}
Exemple #2
0
func Listusers(ctx *macaron.Context) string {
	hcuser, auth := util.Auth(ctx, "sysusers")

	if !auth {
		return "not_authorized"
	}

	db, _ := util.MySQL()
	defer db.Close()

	data := make(map[string]map[string]string)
	data = util.Getusers(hcuser.System_username, data, db)

	output, err := json.Marshal(data)
	if err != nil {
		return "json_out_failed: " + string(err.Error())
	}

	return string(output)
}