| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- package route
- import (
- "log"
- "opennamu/route/tool"
- jsoniter "github.com/json-iterator/go"
- )
- func Api_give_auth_patch(call_arg []string) string {
- var json = jsoniter.ConfigCompatibleWithStandardLibrary
- other_set := map[string]string{}
- json.Unmarshal([]byte(call_arg[0]), &other_set)
- db := tool.DB_connect()
- defer db.Close()
- new_data := make(map[string]interface{})
- ip := other_set["ip"]
- user_name := other_set["user_name"]
- if user_name != "" {
- auth_check := false
- auth_name := tool.Get_user_auth(db, user_name)
- auth_data := tool.Get_auth_group_info(db, auth_name)
- if tool.Auth_include_upper_auth(auth_data) {
- if tool.Check_acl(db, "", "", "owner_auth", ip) {
- auth_check = true
- }
- } else {
- if tool.Check_acl(db, "", "", "give_auth", ip) {
- auth_check = true
- }
- }
- if !auth_check {
- new_data["response"] = "require auth"
- } else {
- auth_check = false
- auth_data = tool.Get_auth_group_info(db, other_set["change_auth"])
- if tool.Auth_include_upper_auth(auth_data) {
- if tool.Check_acl(db, "", "", "owner_auth", ip) {
- auth_check = true
- }
- } else {
- if tool.Check_acl(db, "", "", "give_auth", ip) {
- auth_check = true
- }
- }
- if !auth_check {
- new_data["response"] = "require auth"
- } else {
- stmt, err := db.Prepare(tool.DB_change("delete from user_set where id = ? and name = 'acl'"))
- if err != nil {
- log.Fatal(err)
- }
- defer stmt.Close()
- _, err = stmt.Exec(user_name)
- if err != nil {
- log.Fatal(err)
- }
- stmt, err = db.Prepare(tool.DB_change("insert into user_set (id, name, data) values (?, 'acl', ?)"))
- if err != nil {
- log.Fatal(err)
- }
- defer stmt.Close()
- _, err = stmt.Exec(user_name, other_set["change_auth"])
- if err != nil {
- log.Fatal(err)
- }
- new_data["response"] = "ok"
- }
- }
- } else {
- auth_check := false
- auth_data := tool.Get_auth_group_info(db, other_set["auth"])
- if tool.Auth_include_upper_auth(auth_data) {
- if tool.Check_acl(db, "", "", "owner_auth", other_set["ip"]) {
- auth_check = true
- }
- } else {
- if tool.Check_acl(db, "", "", "give_auth", other_set["ip"]) {
- auth_check = true
- }
- }
- if !auth_check {
- new_data["response"] = "require auth"
- } else {
- auth_check = false
- auth_data = tool.Get_auth_group_info(db, other_set["change_auth"])
- if tool.Auth_include_upper_auth(auth_data) {
- if tool.Check_acl(db, "", "", "owner_auth", other_set["ip"]) {
- auth_check = true
- }
- } else {
- if tool.Check_acl(db, "", "", "give_auth", other_set["ip"]) {
- auth_check = true
- }
- }
- if !auth_check {
- new_data["response"] = "require auth"
- } else {
- stmt, err := db.Prepare(tool.DB_change("update user_set set data = ? where name = 'acl' and data = ?"))
- if err != nil {
- log.Fatal(err)
- }
- defer stmt.Close()
- _, err = stmt.Exec(other_set["change_auth"], other_set["auth"])
- if err != nil {
- log.Fatal(err)
- }
- new_data["response"] = "ok"
- }
- }
- }
- json_data, _ := json.Marshal(new_data)
- return string(json_data)
- }
|