From 9af01c87bfb3007e0a169b57bf9762c88098dff9 Mon Sep 17 00:00:00 2001 From: Dengfeng Liu Date: Tue, 5 Apr 2022 01:53:59 +0000 Subject: [PATCH] xfrpc: fast reverve proxy client in c language Signed-off-by: Dengfeng Liu --- net/xfrpc/Makefile | 54 ++++++++++++++++++++++ net/xfrpc/files/xfrpc.conf | 31 +++++++++++++ net/xfrpc/files/xfrpc.init | 93 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 178 insertions(+) create mode 100644 net/xfrpc/Makefile create mode 100644 net/xfrpc/files/xfrpc.conf create mode 100755 net/xfrpc/files/xfrpc.init diff --git a/net/xfrpc/Makefile b/net/xfrpc/Makefile new file mode 100644 index 0000000000..cce5519a39 --- /dev/null +++ b/net/xfrpc/Makefile @@ -0,0 +1,54 @@ +# +# Copyright (C) 2022 Dengfeng Liu +# +# This is free software, licensed under the GNU General Public License v3. +# See /LICENSE for more information. +# + +include $(TOPDIR)/rules.mk + +PKG_NAME:=xfrpc +PKG_VERSION:=1.04.515 +PKG_RELEASE:=1 + +PKG_SOURCE_PROTO:=git +PKG_SOURCE_URL:=https://github.com/liudf0716/xfrpc.git +PKG_SOURCE_VERSION:=$(PKG_VERSION) +PKG_MIRROR_HASH:=1fd9b3dc9a38236dfd5bf4a8ad908d370820b4841f111b3078c5994bdaf3273e + +PKG_MAINTAINER:=Dengfeng Liu +PKG_LICENSE:=GPL-3.0-or-later +PKG_LICENSE_FILES:=COPYING + +include $(INCLUDE_DIR)/package.mk +include $(INCLUDE_DIR)/cmake.mk + +define Package/xfrpc + SUBMENU:=Web Servers/Proxies + SECTION:=net + CATEGORY:=Network + DEPENDS:=+zlib +libjson-c +libevent2 +libevent2-openssl + TITLE:= C language fast reverse proxy client + URL:=https://github.com/liudf0716/xfrpc +endef + +define Package/xfrpc/description + xfrpc is C language fast reverse proxy client + compare with golang version frpc + xfrpc can run in almost all openwrt device +endef + +define Package/xfrpc/conffiles +/etc/config/xfrpc +endef + +define Package/xfrpc/install + $(INSTALL_DIR) $(1)/usr/bin + $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/xfrpc $(1)/usr/bin/xfrpc + $(INSTALL_DIR) $(1)/etc/init.d + $(INSTALL_BIN) ./files/xfrpc.init $(1)/etc/init.d/xfrpc + $(INSTALL_DIR) $(1)/etc/config + $(CP) ./files/xfrpc.conf $(1)/etc/config/xfrpc +endef + +$(eval $(call BuildPackage,xfrpc)) diff --git a/net/xfrpc/files/xfrpc.conf b/net/xfrpc/files/xfrpc.conf new file mode 100644 index 0000000000..a6cd8688b1 --- /dev/null +++ b/net/xfrpc/files/xfrpc.conf @@ -0,0 +1,31 @@ +config xfrp 'init' + option disabled 1 + option loglevel 7 + +config xfrpc 'common' + option server_addr 127.0.0.1 + option server_port 7000 + option auth_token abdesf13d + +config xfrpc 'ssh01' + option type tcp + option local_ip 127.0.0.1 + option local_port 22 + option remote_port 6000 + +#config xfrpc 'ftp01' +# option type ftp +# option local_ip 127.0.01 +# option local_port 21 +# option remote_port 8021 +# option remote_data_port 8022 + +#config xfrpc 'web01' +# option type http +# option local_ip 127.0.0.1 +# option local_port 8080 + +#config xfrpc 'web02' +# option type https +# option local_ip 127.0.0.1 +# option local_port 8443 diff --git a/net/xfrpc/files/xfrpc.init b/net/xfrpc/files/xfrpc.init new file mode 100755 index 0000000000..f4f31bc5e1 --- /dev/null +++ b/net/xfrpc/files/xfrpc.init @@ -0,0 +1,93 @@ +#!/bin/sh /etc/rc.common +# Copyright (C) 2022 Dengfeng Liu +# +# This is free software, licensed under the GNU General Public License v3. +# See /LICENSE for more information. +# + +START=99 +USE_PROCD=1 + +NAME=xfrpc +PROG=/usr/bin/$NAME + + +handle_xfrpc() { + local name="$1" + local config="$2" + + echo "[$name]" >> "$config" + + handle_type() { + uci_validate_section xfrpc xfrpc "$name" \ + 'type:or("tcp", "udp", "ftp", "http", "https")' \ + 'local_ip:ipaddr:127.0.0.1' \ + 'local_port:uinteger' + + echo "type = $type" >> "$config" + echo "local_ip = $local_ip" >> "$config" + echo "local_port = $local_port" >> "$config" + case "$type" in + "tcp"|"udp") + config_get remote_port "$name" remote_port + echo "remote_port = $remote_port" >> "$config" + ;; + "ftp") + config_get remote_port "$name" remote_port + config_get remote_data_port "$name" remote_data_port + echo "remote_port = $remote_port" >> "$config" + echo "remote_data_port = $remote_data_port" >> "$config" + ;; + esac + } + + if [ "$name" = "common" ]; then + uci_validate_section xfrpc xfrpc "$name" \ + 'server_addr:ipaddr' \ + 'server_port:uinteger' \ + 'auth_token:string' + + [ -z "$auth_token" ] && { + echo "no auth_token" + exit + } + echo "server_addr = $server_addr" >> "$config" + echo "server_port = $server_port" >> "$config" + echo "auth_token = $auth_token" >> "$config" + else + handle_type + fi +} + +service_triggers() { + procd_add_reload_trigger "$NAME" +} + +start_service() { + local conf_file="/var/etc/$NAME.ini" + + > "$conf_file" + config_load "$NAME" + + uci_validate_section xfrpc xfrpc init \ + 'disabled:bool:1' \ + 'loglevel:uinteger:0' + + if [ $disabled = 1 ]; then + echo "xfrpc service disabled" + return + fi + + config_foreach handle_xfrpc xfrpc "$conf_file" + + procd_open_instance + procd_set_param command "$PROG" -c "$conf_file" -f -d $loglevel + procd_set_param file "$conf_file" + procd_set_param respawn + procd_close_instance +} + +reload_service() { + stop + start +} -- 2.30.2