Nick Peng 2 місяців тому
батько
коміт
9e5980ec06

+ 1 - 2
etc/smartdns/smartdns.conf

@@ -440,7 +440,7 @@ log-level info
 # plugin [path/to/file] [args]
 
 # web ui plugin
-# plugin /usr/lib/libsmartdns-ui.so
+# plugin smartdns_ui.so
 # smartdns-ui.www-root /usr/share/smartdns/wwwroot
 # smartdns-ui.ip http://0.0.0.0:6080
 # smartdns-ui.ip https://0.0.0.0:6080
@@ -450,4 +450,3 @@ log-level info
 # smartdns-ui.enable-cors yes
 # smartdns-ui.user admin
 # smartdns-ui.password password
-

+ 1 - 0
package/linux/install

@@ -149,6 +149,7 @@ uninstall_smartdns()
 	rmdir $PREFIX$SMARTDNS_CONF_DIR 2>/dev/null
 	rm -f $PREFIX/usr/sbin/smartdns
 	rm -f $PREFIX/etc/default/smartdns
+	rm -f $PREFIX/etc/init.d/smartdns
 
 	if [ $ISWSL -eq 0 ]; then
 		sed -i '\#%sudo ALL=NOPASSWD: /etc/init.d/smartdns#d' /etc/sudoers 2>/dev/null

+ 1 - 1
package/openwrt/Makefile

@@ -93,7 +93,7 @@ define Package/smartdns-ui/install
 	$(INSTALL_DIR) $(1)/usr/lib
 	$(INSTALL_DIR) $(1)/etc/smartdns/conf.d/
 	$(INSTALL_DIR) $(1)/usr/share/smartdns/wwwroot
-	$(INSTALL_BIN) $(PKG_BUILD_DIR)/plugin/smartdns-ui/target/libsmartdns_ui.so $(1)/usr/lib/libsmartdns_ui.so
+	$(INSTALL_BIN) $(PKG_BUILD_DIR)/plugin/smartdns-ui/target/smartdns_ui.so $(1)/usr/lib/smartdns_ui.so
 	$(CP) $(PKG_BUILD_DIR)/smartdns-webui/out/* $(1)/usr/share/smartdns/wwwroot
 endef
 

+ 1 - 1
package/openwrt/files/etc/init.d/smartdns

@@ -867,7 +867,7 @@ load_service()
 		config_get ui_data_dir "$section" "ui_data_dir" "/var/lib/smartdns"
 		config_get ui_log_max_age "$section" "ui_log_max_age" "30"
 
-		conf_append "plugin" "/usr/lib/libsmartdns_ui.so"
+		conf_append "plugin" "smartdns_ui.so"
 		conf_append "smartdns-ui.www-root" "/usr/share/smartdns/wwwroot"
 		conf_append "smartdns-ui.ip" "http://0.0.0.0:$ui_port"
 		conf_append "data-dir" "$ui_data_dir"

+ 1 - 1
plugin/demo/Makefile

@@ -14,7 +14,7 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-BIN=smartdns-demo.so 
+BIN=smartdns_demo.so 
 OBJS_MAIN=$(patsubst %.c,%.o,$(wildcard *.c))
 OBJS=$(OBJS_MAIN)
 

+ 16 - 15
plugin/smartdns-ui/Cargo.toml

@@ -7,30 +7,31 @@ edition = "2021"
 crate-type = ["cdylib", "lib"]
 
 [dependencies]
-ctor = "0.2.9"
+ctor = "0.4.2"
 bytes = "1.10.0"
-rusqlite = { version = "0.32.1", features = ["bundled"] }
+rusqlite = { version = "0.37.0", features = ["bundled"] }
 hyper = { version = "1.6.0", features = ["full"] }
-hyper-util = { version = "0.1.10", features = ["full"] }
-hyper-tungstenite = "0.14.0"
-tokio = { version = "1.43.0", features = ["full"] }
+hyper-util = { version = "0.1.16", features = ["full"] }
+hyper-tungstenite = "0.18.0"
+tokio = { version = "1.46.1", features = ["full"] }
 serde = { version = "1.0.217", features = ["derive"] }
-tokio-rustls = { version = "0.26.1", optional = true}
+tokio-rustls = { version = "0.26.2", optional = true}
 rustls-pemfile = { version = "2.2.0", optional = true}
-serde_json = "1.0.138"
-http-body-util = "0.1.2"
-getopts = "0.2.21"
+serde_json = "1.0.141"
+http-body-util = "0.1.3"
+getopts = "0.2.23"
 url = "2.5.4"
 jsonwebtoken = "9"
 matchit = "0.8.6"
 futures = "0.3.31"
-socket2 = "0.5.8"
-cfg-if = "1.0.0"
+socket2 = "0.6.0"
+cfg-if = "1.0.1"
 urlencoding = "2.1.3"
-chrono = "0.4.39"
-nix = "0.29.0"
+chrono = "0.4.41"
+nix = "0.30.1"
 tokio-fd = "0.3.0"
-pbkdf2 = { version = "0.12", features = ["simple"] }
+pbkdf2 = { version = "0.12.2", features = ["simple"] }
+rand_core = { version = "0.6", features = ["std"] }
 
 [features]
 build-release = []
@@ -52,4 +53,4 @@ lto = true
 opt-level = "s"
 strip = true
 codegen-units = 1
-panic = "abort"
+panic = "abort"

+ 3 - 3
plugin/smartdns-ui/Makefile

@@ -109,10 +109,10 @@ test-prepare:
 
 $(BIN):
 	MAKEFLAGS= RUSTFLAGS="$(CARGO_RUSTFLAGS) $(RUSTFLAGS)" $(CARGO_BUILD_ENV) cargo build $(CARGO_BUILD_ARGS) --features "build-release"
-	cp $(CARGO_BUILD_PATH)/libsmartdns_ui.so target/ 
+	cp $(CARGO_BUILD_PATH)/libsmartdns_ui.so target/smartdns_ui.so
 
 install: $(BIN)
-	install -v -m 0644 -D -t $(DESTDIR)$(SLIBDIR)/smartdns target/libsmartdns_ui.so
+	install -v -m 0644 -D -t $(DESTDIR)$(SLIBDIR)/smartdns target/smartdns_ui.so
 
 test: test-prepare
 	MAKEFLAGS= cargo test
@@ -120,4 +120,4 @@ test: test-prepare
 clean:
 	cargo clean
 	$(MAKE) -C $(SMARTDNS_SRC_DIR) clean
-	rm -rf target/libsmartdns_ui.so
+	rm -rf target/smartdns_ui.so

+ 5 - 5
plugin/smartdns-ui/src/http_server_stream.rs

@@ -85,7 +85,7 @@ pub async fn serve_log_stream(
                         binary_msg.push(0);
                         binary_msg.push(msg.level as u8);
                         binary_msg.extend_from_slice(msg.msg.as_bytes());
-                        let msg = Message::Binary(binary_msg);
+                        let msg = Message::Binary(binary_msg.into());
                         websocket.send(msg).await?;
                     }
                     None => {
@@ -185,11 +185,11 @@ pub async fn serve_metrics(
                 match metrics {
                     Ok(metrics) => {
                         let data_server = api_msg_gen_metrics_data(&metrics);
-                        let msg = Message::Text(data_server);
+                        let msg = Message::Text(data_server.into());
                         websocket.send(msg).await?;
                     }
                     Err(e) => {
-                        let msg = Message::Text(format!("{{\"error\": \"{}\"}}", e));
+                        let msg = Message::Text(format!("{{\"error\": \"{}\"}}", e).into());
                         websocket.send(msg).await?;
                     }
                 }
@@ -352,7 +352,7 @@ pub async fn serve_term(websocket: HyperWebsocket) -> Result<(), Error> {
         let mut buf = [0u8; 4096];
         buf[0] = TermMessageType::Err as u8;
         buf[1..msg.len() + 1].copy_from_slice(msg.as_bytes());
-        let msg = Message::Binary(buf[..msg.len() + 1].to_vec());
+        let msg = Message::Binary(buf[..msg.len() + 1].to_vec().into());
         let _ = ws.send(msg);
 
         let msg = Message::Close(None);
@@ -381,7 +381,7 @@ pub async fn serve_term(websocket: HyperWebsocket) -> Result<(), Error> {
 
                         data_len = n + 1;
                         data_type[0] = TermMessageType::Data as u8;
-                        let msg = Message::Binary(buf[..data_len].to_vec());
+                        let msg = Message::Binary(buf[..data_len].to_vec().into());
                         websocket.send(msg).await?;
                     }
                     Err(e) => {

+ 49 - 7
src/dns_conf/plugin.c

@@ -19,6 +19,8 @@
 #include "plugin.h"
 #include "smartdns/lib/stringutil.h"
 
+#include <stdio.h>
+
 struct dns_conf_plugin_table dns_conf_plugin_table;
 
 static struct dns_conf_plugin *_config_get_plugin(const char *file)
@@ -69,6 +71,25 @@ const char *dns_conf_get_plugin_conf(const char *key)
 
 int _config_plugin(void *data, int argc, char *argv[])
 {
+	// clang-format off
+	const char *plugin_dir [] = {
+#if UINTPTR_MAX == 0xFFFFFFFFFFFFFFFFULL
+		"/lib64/smartdns",
+		"/usr/lib64/smartdns",
+		"/usr/local/lib64/smartdns",
+		"/lib64",
+		"/usr/lib64",
+		"/usr/local/lib64",
+#endif
+		"/lib/smartdns",
+		"/usr/lib/smartdns",
+		"/usr/local/lib/smartdns",
+		"/lib",
+		"/usr/lib",
+		"/usr/local/lib",
+	};
+	// clang-format on
+	const int plugin_dir_len = sizeof(plugin_dir) / sizeof(plugin_dir[0]);
 #ifdef BUILD_STATIC
 	tlog(TLOG_ERROR, "plugin not support in static release, please install dynamic release.");
 	goto errout;
@@ -84,23 +105,44 @@ int _config_plugin(void *data, int argc, char *argv[])
 		goto errout;
 	}
 
-	conf_get_conf_fullpath(argv[1], file, sizeof(file));
-	if (file[0] == '\0') {
+	if (argv[1] == NULL || argv[1][0] == '\0') {
 		tlog(TLOG_ERROR, "plugin: invalid parameter.");
 		goto errout;
 	}
 
+	file[0] = '\0';
+	if (strstr(argv[1], "/") == NULL) {
+		/* relative path, search in plugin dir */
+		for (i = 0; i < plugin_dir_len; i++) {
+			snprintf(file, sizeof(file), "%s/%s", plugin_dir[i], argv[1]);
+			if (access(file, F_OK) == 0) {
+				break;
+			}
+		}
+		if (i == plugin_dir_len) {
+			file[0] = '\0';
+		}
+	}
+
+	if (file[0] == '\0') {
+		conf_get_conf_fullpath(argv[1], file, sizeof(file));
+		if (file[0] == '\0') {
+			tlog(TLOG_ERROR, "plugin: invalid parameter.");
+			goto errout;
+		}
+
+		if (access(file, F_OK) != 0) {
+			tlog(TLOG_ERROR, "plugin '%s' not exists.", argv[1]);
+			goto errout;
+		}
+	}
+
 	struct dns_conf_plugin *plugin = _config_get_plugin(file);
 	if (plugin != NULL) {
 		tlog(TLOG_ERROR, "plugin '%s' already exists.", file);
 		goto errout;
 	}
 
-	if (access(file, F_OK) != 0) {
-		tlog(TLOG_ERROR, "plugin '%s' not exists.", file);
-		goto errout;
-	}
-
 	plugin = malloc(sizeof(*plugin));
 	if (plugin == NULL) {
 		goto errout;

+ 2 - 0
src/dns_plugin.c

@@ -194,6 +194,8 @@ static int _dns_plugin_load_library(struct dns_plugin *plugin)
 	dns_plugin_init_func init_func = NULL;
 	dns_plugin_exit_func exit_func = NULL;
 
+	tlog(TLOG_DEBUG, "load plugin %s", plugin->file);
+
 	handle = dlopen(plugin->file, RTLD_LAZY | RTLD_LOCAL);
 	if (!handle) {
 		tlog(TLOG_ERROR, "load plugin %s failed: %s", plugin->file, dlerror());