Skip to content

Commit

Permalink
0.4 Re-engineer the apply & save logic
Browse files Browse the repository at this point in the history
  • Loading branch information
makeding committed Sep 4, 2024
1 parent f33fec2 commit fd42997
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 27 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ include $(TOPDIR)/rules.mk

PKG_NAME:=luci-app-fleth
LUCI_TITLE:=LuCI Support for Flet'h
LUCI_DESCRIPTION:=luci-app-fleth is a helper that can configure your IPv4 over IPv6 tunnel automatically.
PKG_VERSION:=0.3
PKG_RELEASE:=2
LUCI_DESCRIPTION:=luci-app-fleth is a helper that can configure IPv4 over IPv6 tunnel automatically in Japan.
PKG_VERSION:=0.4
PKG_RELEASE:=1

LUCI_PKGARCH:=all
LUCI_DEPENDS:=+luci-base +lua +map +ds-lite +luci-proto-ipv6
Expand Down
32 changes: 11 additions & 21 deletions htdocs/luci-static/resources/view/fleth.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ return view.extend({
)
);

s = m.section(form.NamedSection, "global", "fleth");
s = m.section(form.NamedSection, "global");
s.tab("info", _("Information"));
s.tab("general", _("General Settings"));

Expand Down Expand Up @@ -99,16 +99,20 @@ return view.extend({
form.Flag,
"ip6prefix_enabled",
_("Auto Add IPv6 PD in IPv6 Interface"),
_(
"We recommend enabling it in MAP-E and when not using Hikari Denwa."
)
_("We recommend enabling it in MAP-E and when not using Hikari Denwa.")
);
o.rmempty = false;
o.default = "0";

// o = s.taboption('general', form.Flag, 'ip6relay_enabled', _('Auto Configure IPv6 with relay mode'));
// o = s.taboption(
// "general",
// form.Flag,
// "ip6relay_enabled",
// _("Auto Configure lan side IPv6"),
// _("You can hold both ISP and ULA address simultaneously.")
// );
// o.rmempty = false;
// o.default = '0';
// o.default = "0";

// o = s.taboption('general', form.ListValue, 'type', _('Tunnel Type'), _('Now only support DS-Lite'))
// o.value('auto', _('Auto'))
Expand Down Expand Up @@ -148,19 +152,5 @@ return view.extend({
o.default = "1460";

return m.render();
},
handleSaveApply: async function (ev) {
await this.__base__.handleSaveApply(ev);
// console.log('triggered save & apply button');
try {
await fs.exec("/usr/sbin/fleth", ["ip6prefix"]);
} catch (error) {
console.warn(error);
}
try {
await fs.exec("/usr/sbin/fleth", ["auto"]);
} catch (error) {
console.warn(error);
}
},
}
});
17 changes: 17 additions & 0 deletions root/etc/init.d/fleth
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh /etc/rc.common

START=99
USE_PROCD=1
NAME="fleth"

start_service() {
config_load "$NAME"
/usr/sbin/fleth auto
}
reload_service() {
config_load "$NAME"
/usr/sbin/fleth auto
}
service_triggers() {
procd_add_reload_trigger "$NAME"
}
2 changes: 1 addition & 1 deletion root/etc/uci-defaults/luci-app-fleth
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

chmod +x /usr/sbin/fleth
chmod +x /usr/sbin/fleth /etc/init.d/fleth /etc/hotplug.d/iface/25-fleth-ip6prefix

if [ ! -f /etc/config/fleth ]; then
cat <<EOF > /etc/config/fleth
Expand Down
5 changes: 3 additions & 2 deletions root/usr/sbin/fleth
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ e_AREA="UNKNOWN"
# domain iptvf.jp xxxx-east.jp <- point
get_area(){
# east or west
wget --timeout=1 -s "http://[2404:1a8:f401:100::1]/l/__healthcheck" -O/tmp/null > /dev/null 2>&1
wget --timeout=1 -s "http://[2404:1a8:f401:100::1]/l/__healthcheck" -O /tmp/null > /dev/null 2>&1
if [ $? -eq 0 ]; then
e_AREA="EAST"
DNS=$DNS_E
else
wget --timeout=1 -s "http://[2001:a7ff:ff0e:1::2]/l/__healthcheck" -O/tmp/null > /dev/null 2>&1
wget --timeout=1 -s "http://[2001:a7ff:ff0e:1::2]/l/__healthcheck" -O /tmp/null > /dev/null 2>&1
if [ $? -eq 0 ]; then
e_AREA="WEST"
DNS=$DNS_W
Expand Down Expand Up @@ -224,6 +224,7 @@ EOF
}

if [ "$1" = "auto" ]; then
logger -t fleth "is running $h_ENABLED"
$0 ip6prefix &
if [ "$h_ENABLED" == "1" ]; then
get_area
Expand Down

0 comments on commit fd42997

Please sign in to comment.