api_give_auth_patch.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. package route
  2. import (
  3. "opennamu/route/tool"
  4. )
  5. func Api_give_auth_patch(config tool.Config) string {
  6. db := tool.DB_connect()
  7. defer tool.DB_close(db)
  8. other_set := map[string]string{}
  9. json.Unmarshal([]byte(config.Other_set), &other_set)
  10. new_data := make(map[string]any)
  11. ip := config.IP
  12. user_name := other_set["user_name"]
  13. if user_name != "" {
  14. auth_check := false
  15. auth_name := tool.Get_user_auth(db, user_name)
  16. auth_data := tool.Get_auth_group_info(db, auth_name)
  17. if tool.Auth_include_upper_auth(auth_data) {
  18. if tool.Check_acl(db, "", "", "owner_auth", ip) {
  19. auth_check = true
  20. }
  21. } else {
  22. if tool.Check_acl(db, "", "", "give_auth", ip) {
  23. auth_check = true
  24. }
  25. }
  26. if !auth_check {
  27. new_data["response"] = "require auth"
  28. } else {
  29. auth_check = false
  30. auth_data = tool.Get_auth_group_info(db, other_set["change_auth"])
  31. if tool.Auth_include_upper_auth(auth_data) {
  32. if tool.Check_acl(db, "", "", "owner_auth", ip) {
  33. auth_check = true
  34. }
  35. } else {
  36. if tool.Check_acl(db, "", "", "give_auth", ip) {
  37. auth_check = true
  38. }
  39. }
  40. if !auth_check {
  41. new_data["response"] = "require auth"
  42. } else {
  43. tool.Exec_DB(
  44. db,
  45. "delete from user_set where id = ? and name = 'acl'",
  46. user_name,
  47. )
  48. tool.Exec_DB(
  49. db,
  50. "insert into user_set (id, name, data) values (?, 'acl', ?)",
  51. user_name, other_set["change_auth"],
  52. )
  53. new_data["response"] = "ok"
  54. }
  55. }
  56. } else {
  57. auth_check := false
  58. auth_data := tool.Get_auth_group_info(db, other_set["auth"])
  59. if tool.Auth_include_upper_auth(auth_data) {
  60. if tool.Check_acl(db, "", "", "owner_auth", config.IP) {
  61. auth_check = true
  62. }
  63. } else {
  64. if tool.Check_acl(db, "", "", "give_auth", config.IP) {
  65. auth_check = true
  66. }
  67. }
  68. if !auth_check {
  69. new_data["response"] = "require auth"
  70. } else {
  71. auth_check = false
  72. auth_data = tool.Get_auth_group_info(db, other_set["change_auth"])
  73. if tool.Auth_include_upper_auth(auth_data) {
  74. if tool.Check_acl(db, "", "", "owner_auth", config.IP) {
  75. auth_check = true
  76. }
  77. } else {
  78. if tool.Check_acl(db, "", "", "give_auth", config.IP) {
  79. auth_check = true
  80. }
  81. }
  82. if !auth_check {
  83. new_data["response"] = "require auth"
  84. } else {
  85. tool.Exec_DB(
  86. db,
  87. "update user_set set data = ? where name = 'acl' and data = ?",
  88. other_set["change_auth"], other_set["auth"],
  89. )
  90. new_data["response"] = "ok"
  91. }
  92. }
  93. }
  94. json_data, _ := json.Marshal(new_data)
  95. return string(json_data)
  96. }