api_give_auth_patch.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. package route
  2. import (
  3. "log"
  4. "opennamu/route/tool"
  5. jsoniter "github.com/json-iterator/go"
  6. )
  7. func Api_give_auth_patch(call_arg []string) string {
  8. var json = jsoniter.ConfigCompatibleWithStandardLibrary
  9. other_set := map[string]string{}
  10. json.Unmarshal([]byte(call_arg[0]), &other_set)
  11. db := tool.DB_connect()
  12. defer db.Close()
  13. new_data := make(map[string]interface{})
  14. ip := other_set["ip"]
  15. user_name := other_set["user_name"]
  16. if user_name != "" {
  17. auth_check := false
  18. auth_name := tool.Get_user_auth(db, user_name)
  19. auth_data := tool.Get_auth_group_info(db, auth_name)
  20. if tool.Auth_include_upper_auth(auth_data) {
  21. if tool.Check_acl(db, "", "", "owner_auth", ip) {
  22. auth_check = true
  23. }
  24. } else {
  25. if tool.Check_acl(db, "", "", "give_auth", ip) {
  26. auth_check = true
  27. }
  28. }
  29. if !auth_check {
  30. new_data["response"] = "require auth"
  31. } else {
  32. auth_check = false
  33. auth_data = tool.Get_auth_group_info(db, other_set["change_auth"])
  34. if tool.Auth_include_upper_auth(auth_data) {
  35. if tool.Check_acl(db, "", "", "owner_auth", ip) {
  36. auth_check = true
  37. }
  38. } else {
  39. if tool.Check_acl(db, "", "", "give_auth", ip) {
  40. auth_check = true
  41. }
  42. }
  43. if !auth_check {
  44. new_data["response"] = "require auth"
  45. } else {
  46. stmt, err := db.Prepare(tool.DB_change("delete from user_set where id = ? and name = 'acl'"))
  47. if err != nil {
  48. log.Fatal(err)
  49. }
  50. defer stmt.Close()
  51. _, err = stmt.Exec(user_name)
  52. if err != nil {
  53. log.Fatal(err)
  54. }
  55. stmt, err = db.Prepare(tool.DB_change("insert into user_set (id, name, data) values (?, 'acl', ?)"))
  56. if err != nil {
  57. log.Fatal(err)
  58. }
  59. defer stmt.Close()
  60. _, err = stmt.Exec(user_name, other_set["change_auth"])
  61. if err != nil {
  62. log.Fatal(err)
  63. }
  64. new_data["response"] = "ok"
  65. }
  66. }
  67. } else {
  68. auth_check := false
  69. auth_data := tool.Get_auth_group_info(db, other_set["auth"])
  70. if tool.Auth_include_upper_auth(auth_data) {
  71. if tool.Check_acl(db, "", "", "owner_auth", other_set["ip"]) {
  72. auth_check = true
  73. }
  74. } else {
  75. if tool.Check_acl(db, "", "", "give_auth", other_set["ip"]) {
  76. auth_check = true
  77. }
  78. }
  79. if !auth_check {
  80. new_data["response"] = "require auth"
  81. } else {
  82. auth_check = false
  83. auth_data = tool.Get_auth_group_info(db, other_set["change_auth"])
  84. if tool.Auth_include_upper_auth(auth_data) {
  85. if tool.Check_acl(db, "", "", "owner_auth", other_set["ip"]) {
  86. auth_check = true
  87. }
  88. } else {
  89. if tool.Check_acl(db, "", "", "give_auth", other_set["ip"]) {
  90. auth_check = true
  91. }
  92. }
  93. if !auth_check {
  94. new_data["response"] = "require auth"
  95. } else {
  96. stmt, err := db.Prepare(tool.DB_change("update user_set set data = ? where name = 'acl' and data = ?"))
  97. if err != nil {
  98. log.Fatal(err)
  99. }
  100. defer stmt.Close()
  101. _, err = stmt.Exec(other_set["change_auth"], other_set["auth"])
  102. if err != nil {
  103. log.Fatal(err)
  104. }
  105. new_data["response"] = "ok"
  106. }
  107. }
  108. }
  109. json_data, _ := json.Marshal(new_data)
  110. return string(json_data)
  111. }