view_list_recent_block.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. package route
  2. import (
  3. "database/sql"
  4. "opennamu/route/tool"
  5. )
  6. func Get_ui_recent_block(db *sql.DB, config tool.Config, data_all [][]string) string {
  7. auth_name := tool.Get_user_auth(db, config.IP)
  8. auth_info := tool.Get_auth_group_info(db, auth_name)
  9. data_html := ""
  10. for_count := 1
  11. for _, in_data := range data_all {
  12. // for_count_str := strconv.Itoa(for_count)
  13. for_count += 1
  14. left := ""
  15. ban_auth := false
  16. if _, ok := auth_info["owner"]; ok {
  17. ban_auth = true
  18. } else if _, ok := auth_info["ban"]; ok {
  19. ban_auth = true
  20. }
  21. ip := in_data[1]
  22. url_match := ""
  23. switch in_data[7] {
  24. case "":
  25. url_match = "ban"
  26. case "private":
  27. url_match = "ban"
  28. ip += " (" + tool.Get_language(db, "private", true) + ")"
  29. case "cidr":
  30. url_match = "ban_cidr"
  31. ip += " (" + tool.Get_language(db, "cidr", true) + ")"
  32. default:
  33. url_match = "ban_regex"
  34. ip += " (" + tool.Get_language(db, "regex", true) + ")"
  35. }
  36. if ban_auth {
  37. ip = `<a href="/auth/` + url_match + `/` + tool.Url_parser(in_data[1]) + `">` + ip + `</a>`;
  38. }
  39. if in_data[8] == "1" {
  40. ip = `<s>` + ip + `</s>`
  41. }
  42. left += ip + ` ← ` + in_data[4]
  43. end := ""
  44. switch in_data[5] {
  45. case "release":
  46. end = tool.Get_language(db, "release", true)
  47. case "":
  48. end = tool.Get_language(db, "limitless", true)
  49. default:
  50. end = in_data[5]
  51. }
  52. right := end + "<br>" + in_data[6]
  53. bottom := ""
  54. if in_data[0] != "" {
  55. if in_data[0] == "edit filter" {
  56. bottom = `<a href="/edit_filter/` + tool.Url_parser(in_data[1]) + `">edit filter</a>`
  57. } else {
  58. bottom = Get_safe_send_data(tool.HTML_escape(in_data[0]))
  59. }
  60. }
  61. data_html += tool.Get_list_ui(left, right, bottom, "")
  62. }
  63. return data_html
  64. }
  65. func View_list_recent_block(config tool.Config, num string, set_type string, why string, user_name string) string {
  66. db := tool.DB_connect()
  67. defer tool.DB_close(db)
  68. data_html := ""
  69. sub := ""
  70. if set_type == "" {
  71. set_type = "all"
  72. }
  73. menu_option := [][]string{
  74. { "all", tool.Get_language(db, "all", true) },
  75. { "regex", tool.Get_language(db, "regex", true) },
  76. { "cidr", tool.Get_language(db, "cidr", true) },
  77. { "private", tool.Get_language(db, "private", true) },
  78. { "ongoing", tool.Get_language(db, "in_progress", true) },
  79. }
  80. for _, option := range menu_option {
  81. data_html += `<a href="/recent_block/` + option[0] + `/1">(` + option[1] + `)</a> `
  82. if option[0] == set_type && set_type != "all" {
  83. sub = "(" + option[1] + ")"
  84. }
  85. }
  86. menu_option = [][]string{
  87. { "/manager/11", tool.Get_language(db, "blocked", true) },
  88. { "/manager/12", tool.Get_language(db, "admin", true) },
  89. { "/manager/19", tool.Get_language(db, "why", true) },
  90. }
  91. for _, option := range menu_option {
  92. data_html += `<a href="` + option[0] + `">(` + option[1] + `)</a> `
  93. }
  94. data_html += "<hr class=\"main_hr\">"
  95. api_data := Api_list_recent_block(config, num, set_type, why, user_name)
  96. api_data_list := api_data["data"].([][]string)
  97. data_html += Get_ui_recent_block(db, config, api_data_list)
  98. base_url := "/recent_block/" + tool.Url_parser(set_type)
  99. if user_name != "" {
  100. base_url += "/" + tool.Url_parser(user_name)
  101. }
  102. base_url += "/{}/"
  103. if why != "" {
  104. base_url += "/" + tool.Url_parser(why)
  105. }
  106. data_html += tool.Get_page_control(
  107. db,
  108. tool.Str_to_int(num),
  109. len(api_data_list),
  110. 50,
  111. base_url,
  112. )
  113. out := tool.Get_template(
  114. db,
  115. config,
  116. tool.Get_language(db, "recent_ban", true),
  117. data_html,
  118. []any{ sub },
  119. [][]any{
  120. { "other", tool.Get_language(db, "return", true) },
  121. },
  122. map[string]string{},
  123. )
  124. return out
  125. }