• R/O
  • HTTP
  • SSH
  • HTTPS

packages: Commit

Community maintained packages for ImmortalWrt.


Commit MetaInfo

Revisione691a25cb3398b83bedc9581ef119382760cfacc (tree)
Time2022-12-05 17:03:51
AuthorRichard Yu <yurichard3839@gmai...>
CommiterRichard Yu

Log Message

natmap: add new package

NATMap is a program for opening port behind full cone NAT (NAT-1),
without the need for using UPnP or another port forward settings.

More details can be found at original repo: https://github.com/heiher/natmap

Signed-off-by: Richard Yu <yurichard3839@gmail.com>

Change Summary

Incremental Difference

--- /dev/null
+++ b/net/natmap/Makefile
@@ -0,0 +1,40 @@
1+include $(TOPDIR)/rules.mk
2+
3+PKG_NAME:=natmap
4+PKG_VERSION:=20221203
5+PKG_RELEASE:=1
6+
7+PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
8+PKG_SOURCE_URL:=https://github.com/heiher/natmap/releases/download/$(PKG_VERSION)
9+PKG_HASH:=c7aa0bb1f3e057bf1fa987ad6166ba7c2e80510a89593e04f4fe0f36f1873338
10+
11+PKG_MAINTAINER:=Richard Yu <yurichard3839@gmail.com>
12+PKG_LICENSE:=MIT
13+PKG_LICENSE_FILES:=License
14+
15+PKG_USE_MIPS16:=0
16+PKG_BUILD_PARALLEL:=1
17+
18+include $(INCLUDE_DIR)/package.mk
19+
20+define Package/natmap
21+ SECTION:=net
22+ CATEGORY:=Network
23+ TITLE:=TCP/UDP port mapping tool for full cone NAT
24+ URL:=https://github.com/heiher/natmap
25+endef
26+
27+MAKE_FLAGS += REV_ID="$(PKG_VERSION)"
28+
29+define Package/natmap/install
30+ $(INSTALL_DIR) $(1)/usr/bin
31+ $(INSTALL_BIN) $(PKG_BUILD_DIR)/bin/natmap $(1)/usr/bin/
32+ $(INSTALL_DIR) $(1)/usr/lib/natmap/
33+ $(INSTALL_BIN) ./files/natmap-update.sh $(1)/usr/lib/natmap/update.sh
34+ $(INSTALL_DIR) $(1)/etc/config/
35+ $(INSTALL_CONF) ./files/natmap.config $(1)/etc/config/natmap
36+ $(INSTALL_DIR) $(1)/etc/init.d/
37+ $(INSTALL_BIN) ./files/natmap.init $(1)/etc/init.d/natmap
38+endef
39+
40+$(eval $(call BuildPackage,natmap))
--- /dev/null
+++ b/net/natmap/files/natmap-update.sh
@@ -0,0 +1,17 @@
1+#!/bin/sh
2+
3+. /usr/share/libubox/jshn.sh
4+
5+(
6+ json_init
7+ json_add_string ip "$1"
8+ json_add_int port "$2"
9+ json_add_int inner_port "$4"
10+ json_add_string protocol "$5"
11+ json_dump > /var/run/natmap/$PPID.json
12+)
13+
14+[ -n "${NOTIFY_SCRIPT}" ] && {
15+ export -n NOTIFY_SCRIPT
16+ exec "${NOTIFY_SCRIPT}" "$@"
17+}
--- /dev/null
+++ b/net/natmap/files/natmap.config
@@ -0,0 +1,13 @@
1+config natmap
2+ option enable '0'
3+ option ipv4 '0'
4+ option ipv6 '0'
5+ option udp_mode '1'
6+ option interface ''
7+ option interval ''
8+ option stun_server 'stun.stunprotocol.org'
9+ option http_server 'example.com'
10+ option port '8080'
11+ option forward_target ''
12+ option notify_script ''
13+
--- /dev/null
+++ b/net/natmap/files/natmap.init
@@ -0,0 +1,113 @@
1+#!/bin/sh /etc/rc.common
2+
3+START=99
4+USE_PROCD=1
5+
6+NAME=natmap
7+PROG=/usr/bin/$NAME
8+
9+STATUS_PATH=/var/run/natmap
10+
11+load_interfaces() {
12+ config_get interface "$1" interface
13+ config_get enable "$1" enable 1
14+
15+ [ "${enable}" = "1" ] && interfaces=" ${interface} ${interfaces}"
16+}
17+
18+validate_section_natmap() {
19+ uci_load_validate "${NAME}" natmap "$1" "$2" \
20+ 'enable:bool:1' \
21+ 'ipv4:bool:0' \
22+ 'ipv6:bool:0' \
23+ 'udp_mode:bool:0' \
24+ 'interface:string' \
25+ 'interval:uinteger' \
26+ 'stun_server:host' \
27+ 'http_server:host' \
28+ 'port:port' \
29+ 'forward_target:host' \
30+ 'notify_script:file'
31+}
32+
33+natmap_instance() {
34+ [ "$2" = 0 ] || {
35+ echo "validation failed"
36+ return 1
37+ }
38+
39+ [ "${enable}" = 0 ] && return 1
40+
41+ procd_open_instance "$1"
42+ procd_set_param command "$PROG" \
43+ ${interval:+-k $interval} \
44+ ${stun_server:+-s "$stun_server"} \
45+ ${http_server:+-h "$http_server"}
46+
47+ [ "${ipv4}" = 1 ] && procd_append_param command -4
48+ [ "${ipv6}" = 1 ] && procd_append_param command -6
49+ [ "${udp_mode}" = 1 ] && procd_append_param command -u
50+
51+ [ -n "$interface" ] && {
52+ local ifname
53+
54+ network_get_device ifname "$interface" || ifname="$interface"
55+ procd_append_param command -i "$ifname"
56+ procd_append_param netdev "$ifname"
57+ }
58+
59+ if [ -n "$forward_target" ]; then
60+ procd_append_param command -t "$forward_target" -p $port
61+ else
62+ procd_append_param command -b $port
63+ fi
64+
65+ [ -n "${notify_script}" ] && procd_set_param env "NOTIFY_SCRIPT=${notify_script}"
66+ procd_append_param command -e /usr/lib/natmap/update.sh
67+
68+ procd_set_param respawn
69+ procd_set_param stdout 1
70+ procd_set_param stderr 1
71+
72+ procd_close_instance
73+}
74+
75+clear_status_files() {
76+ find "${STATUS_PATH}" -type f -print0 | xargs -0 rm -f --
77+}
78+
79+service_triggers() {
80+ local interfaces
81+
82+ procd_add_reload_trigger "${NAME}"
83+
84+ config_load "${NAME}"
85+ config_foreach load_interfaces natmap
86+
87+ [ -n "${interfaces}" ] && {
88+ for n in $interfaces ; do
89+ procd_add_reload_interface_trigger $n
90+ done
91+ }
92+
93+ procd_add_validation validate_section_natmap
94+}
95+
96+start_service() {
97+ . /lib/functions/network.sh
98+
99+ mkdir -p "${STATUS_PATH}"
100+ clear_status_files
101+
102+ config_load "${NAME}"
103+ config_foreach validate_section_natmap natmap natmap_instance
104+}
105+
106+reload_service() {
107+ stop
108+ start
109+}
110+
111+service_stopped() {
112+ clear_status_files
113+}
--- /dev/null
+++ b/net/natmap/test.sh
@@ -0,0 +1,3 @@
1+#!/bin/sh
2+
3+"$1" 2>&1 | grep "$2"
Show on old repository browser