コード例 #1
0
ファイル: users.go プロジェクト: protosam/hostcontrol
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"
}
コード例 #2
0
ファイル: web.users.go プロジェクト: protosam/hostcontrol
func sudo(ctx *macaron.Context) string {
	hcuser, auth := util.Auth(ctx, "sysusers")
	if !auth {
		ctx.Redirect("/", 302)
		return ""
	}

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

	if !util.ChkPaternity(hcuser.System_username, username) {
		set_error("Failed to sudo to "+username+"!", ctx)
		ctx.Redirect("/users", 302)
		return "failed!"

	}

	ctx.SetCookie("sudo", username, 864000)
	set_error("You are now logged in as "+username+"! Clicking logout will switch back to "+hcuser.System_username+".", ctx)
	ctx.Redirect("/dashboard", 302)
	return "success"
}