잉여개발기 (SPDV) 2 лет назад
Родитель
Сommit
515e047082

+ 4 - 0
app.py

@@ -748,6 +748,10 @@ app.route('/api/v2/setting/<name>', methods = ['GET', 'PUT'], defaults = { 'db_s
 
 app.route('/api/v2/user/setting/editor', methods = ['GET', 'POST', 'DELETE'], defaults = { 'db_set' : db_set_str })(api_user_setting_editor)
 
+app.route('/api/v2/ip/<everything:data>', defaults = { 'db_set' : db_set_str })(api_func_ip)
+app.route('/api/v2/ip_menu/<everything:ip>', defaults = { 'db_set' : db_set_str })(api_func_ip_menu)
+app.route('/api/v2/user_menu/<everything:ip>', defaults = { 'db_set' : db_set_str, 'option' : 'user' })(api_func_ip_menu)
+
 # Func-main
 # 여기도 전반적인 조정 시행 예정
 app.route('/other')(main_tool_other)

+ 1 - 0
route/__init__.py

@@ -180,6 +180,7 @@ from route.go_api_func_llm import api_func_llm
 from route.go_api_func_language import api_func_language
 from route.go_api_func_sha224 import api_func_sha224
 from route.go_api_func_ip import api_func_ip
+from route.go_api_func_ip_menu import api_func_ip_menu
 from route.go_api_func_auth_list import api_func_auth_list
 
 from route.go_api_search import api_search

+ 23 - 0
route/go_api_func_ip_menu.py

@@ -0,0 +1,23 @@
+from .tool.func import *
+
+def api_func_ip_menu(db_set, ip = "Test", option = ""):
+    other_set = {}
+    other_set["ip"] = ip
+    other_set["my_ip"] = ip_check()
+    other_set["option"] = option
+    other_set = json.dumps(other_set)
+
+    if platform.system() == 'Linux':
+        if platform.machine() in ["AMD64", "x86_64"]:
+            data = subprocess.Popen([os.path.join(".", "route_go", "bin", "main.amd64.bin"), sys._getframe().f_code.co_name, db_set, other_set], stdout = subprocess.PIPE).communicate()[0]
+        else:
+            data = subprocess.Popen([os.path.join(".", "route_go", "bin", "main.arm64.bin"), sys._getframe().f_code.co_name, db_set, other_set], stdout = subprocess.PIPE).communicate()[0]
+    else:
+        if platform.machine() in ["AMD64", "x86_64"]:
+            data = subprocess.Popen([os.path.join(".", "route_go", "bin", "main.amd64.exe"), sys._getframe().f_code.co_name, db_set, other_set], stdout = subprocess.PIPE).communicate()[0]
+        else:
+            data = subprocess.Popen([os.path.join(".", "route_go", "bin", "main.arm64.exe"), sys._getframe().f_code.co_name, db_set, other_set], stdout = subprocess.PIPE).communicate()[0]
+
+    data = data.decode('utf8')
+
+    return flask.Response(response = data, status = 200, mimetype = 'application/json')

BIN
route_go/bin/main.amd64.exe


+ 2 - 0
route_go/main.go

@@ -75,6 +75,8 @@ func main() {
 		route_data = route.Api_setting(call_arg[1:])
 	} else if call_arg[0] == "api_setting_edit" {
 		route_data = route.Api_setting_edit(call_arg[1:])
+	} else if call_arg[0] == "api_func_ip_menu" {
+		route_data = route.Api_func_ip_menu(call_arg[1:])
 	} else {
 		log.Fatal(call_arg[0] + " is 404")
 	}

+ 26 - 0
route_go/route/api_func_ip_menu.go

@@ -0,0 +1,26 @@
+package route
+
+import (
+	"encoding/json"
+
+	"opennamu/route/tool"
+)
+
+func Api_func_ip_menu(call_arg []string) string {
+	db_set := map[string]string{}
+	json.Unmarshal([]byte(call_arg[0]), &db_set)
+
+	other_set := map[string]string{}
+	json.Unmarshal([]byte(call_arg[1]), &other_set)
+
+	db := tool.DB_connect(db_set)
+	defer db.Close()
+
+	ip_data := tool.IP_menu(db, db_set, other_set["ip"], other_set["my_ip"], other_set["option"])
+
+	new_data := make(map[string]interface{})
+	new_data["data"] = ip_data
+
+	json_data, _ := json.Marshal(new_data)
+	return string(json_data)
+}

+ 66 - 1
route_go/route/tool/ip_parser.go

@@ -209,6 +209,71 @@ func IP_preprocess(db *sql.DB, db_set map[string]string, ip string, my_ip string
 	return []string{ip, ip_change}
 }
 
+func IP_menu(db *sql.DB, db_set map[string]string, ip string, my_ip string, option string) map[string][][]string {
+	menu := map[string][][]string{}
+
+	if ip == my_ip && option == "" {
+		stmt, err := db.Prepare(DB_change(db_set, "select count(*) from user_notice where name = ? and readme = ''"))
+		if err != nil {
+			log.Fatal(err)
+		}
+		defer stmt.Close()
+
+		var alarm_count string
+
+		err = stmt.QueryRow(my_ip).Scan(&alarm_count)
+		if err != nil {
+			if err == sql.ErrNoRows {
+				alarm_count = "0"
+			} else {
+				log.Fatal(err)
+			}
+		}
+
+		if IP_or_user(my_ip) {
+			menu[Get_language(db, db_set, "login", false)] = [][]string{
+				{"/login", Get_language(db, db_set, "login", false)},
+				{"/register", Get_language(db, db_set, "register", false)},
+				{"/change", Get_language(db, db_set, "user_setting", false)},
+				{"/login/find", Get_language(db, db_set, "password_search", false)},
+				{"/alarm" + Url_parser(my_ip), Get_language(db, db_set, "alarm", false) + " (" + alarm_count + ")"},
+			}
+		} else {
+			menu[Get_language(db, db_set, "login", false)] = [][]string{
+				{"/logout", Get_language(db, db_set, "logout", false)},
+				{"/change", Get_language(db, db_set, "user_setting", false)},
+			}
+
+			menu[Get_language(db, db_set, "tool", false)] = [][]string{
+				{"/watch_list", Get_language(db, db_set, "watch_list", false)},
+				{"/star_doc", Get_language(db, db_set, "star_doc", false)},
+				{"/challenge", Get_language(db, db_set, "challenge_and_level_manage", false)},
+				{"/acl/user:" + Url_parser(my_ip), Get_language(db, db_set, "user_document_acl", false)},
+				{"/alarm" + Url_parser(my_ip), Get_language(db, db_set, "alarm", false) + " (" + alarm_count + ")"},
+			}
+		}
+	}
+
+	auth_name := Get_user_auth(db, db_set, my_ip)
+	if auth_name != "" {
+		menu[Get_language(db, db_set, "admin", false)] = [][]string{
+			{"/auth/give/ban/" + Url_parser(ip), Get_language(db, db_set, "ban", false) + " | " + Get_language(db, db_set, "release", false)},
+			{"/list/user/check/" + Url_parser(ip), Get_language(db, db_set, "check", false)},
+		}
+	}
+
+	menu[Get_language(db, db_set, "other", false)] = [][]string{
+		{"/record/" + Url_parser(ip), Get_language(db, db_set, "edit_record", false)},
+		{"/record/topic/" + Url_parser(ip), Get_language(db, db_set, "discussion_record", false)},
+		{"/record/bbs/" + Url_parser(ip), Get_language(db, db_set, "bbs_record", false)},
+		{"/record/bbs_comment/" + Url_parser(ip), Get_language(db, db_set, "bbs_comment_record", false)},
+		{"/topic/user:" + Url_parser(ip), Get_language(db, db_set, "user_discussion", false)},
+		{"/count/" + Url_parser(ip), Get_language(db, db_set, "count", false)},
+	}
+
+	return menu
+}
+
 func IP_parser(db *sql.DB, db_set map[string]string, ip string, my_ip string) string {
 	ip_pre_data := IP_preprocess(db, db_set, ip, my_ip)
 	if ip_pre_data[0] == "" {
@@ -263,7 +328,7 @@ func IP_parser(db *sql.DB, db_set map[string]string, ip string, my_ip string) st
 			ip = user_title + ip
 		}
 
-		ip += " <a href=\"/user/" + Url_parser(raw_ip) + "\">(" + Get_language(db, db_set, "tool", false) + ")</a>"
+		ip += " <a href=\"javascript:opennamu_do_ip_click(this);\">(" + Get_language(db, db_set, "tool", false) + ")</a>"
 
 		return ip
 	}

+ 17 - 1
views/main_css/js/func/func.js

@@ -42,11 +42,27 @@ function opennamu_do_id_check(data) {
     }
 }
 
+function opennamu_do_ip_click(obj) {
+    fetch('/api/v2/ip_menu/' + opennamu_do_url_encode('test')).then(function(res) {
+        return res.json();
+    }).then(function(data) {
+        data = data["data"];
+
+        let data_html = '';
+
+        for(let key in data) {
+            for(let for_a = 0; for_a < key.length; for_a++) {
+                data_html += data[key][for_a][1] + ' | ';
+            }
+        }
+    });
+}
+
 function opennamu_do_ip_render() {
     for(let for_a = 0; for_a < document.getElementsByClassName('opennamu_render_ip').length; for_a++) {
         let ip = document.getElementsByClassName('opennamu_render_ip')[for_a].innerHTML.replace(/&amp;/g, '&');
 
-        fetch('/api/ip/' + opennamu_do_url_encode(ip)).then(function(res) {
+        fetch('/api/v2/ip/' + opennamu_do_url_encode(ip)).then(function(res) {
             return res.json();
         }).then(function(data) {
             if(document.getElementsByClassName('opennamu_render_ip')[for_a].id !== "opennamu_render_end") {