Skip to content

Commit

Permalink
update 2024-10-26 10:38:22
Browse files Browse the repository at this point in the history
  • Loading branch information
kenzok8 committed Oct 26, 2024
1 parent 55eea9c commit 25a0842
Show file tree
Hide file tree
Showing 534 changed files with 126,162 additions and 0 deletions.
47 changes: 47 additions & 0 deletions luci-app-autoshell/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
include $(TOPDIR)/rules.mk

PKG_NAME:=luci-app-autoshell
PKG_VERSION:=1.2.3
PKG_RELEASE:=1

PKG_MAINTAINER:=Brukamen <[email protected]>
PKG_LICENSE:=GPL-3.0-or-later

include $(INCLUDE_DIR)/package.mk

define Package/luci-app-autoshell
SECTION:=luci
CATEGORY:=LuCI
SUBMENU:=3. Applications
TITLE:=LuCI support for autoshell
DEPENDS:=+curl
endef

define Build/Prepare
endef

define Build/Compile
endef

define Package/luci-app-autoshell/install
$(INSTALL_DIR) $(1)/etc/config
$(INSTALL_DATA) ./autoshell $(1)/etc/config/

$(INSTALL_DIR) $(1)/usr/lib/lua/luci/controller
$(INSTALL_DATA) ./controller/autoshell.lua $(1)/usr/lib/lua/luci/controller/

$(INSTALL_DIR) $(1)/usr/lib/lua/luci/model/cbi/
$(INSTALL_DATA) ./cbi/autoshell.lua $(1)/usr/lib/lua/luci/model/cbi/
$(INSTALL_DATA) ./cbi/autoshell_log.lua $(1)/usr/lib/lua/luci/model/cbi/

$(INSTALL_DIR) $(1)/etc/init.d/
$(foreach file,$(wildcard ./init.d/*), \
$(INSTALL_BIN) $(file) $(1)/etc/init.d/$(notdir $(file)); \
)

$(INSTALL_DIR) $(1)/etc
$(INSTALL_BIN) ./etc/autoshells.sh $(1)/etc/
chmod +x $(1)/etc/autoshells.sh
endef

$(eval $(call BuildPackage,$(PKG_NAME)))
13 changes: 13 additions & 0 deletions luci-app-autoshell/autoshell
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
要在Microsoft Edge浏览器中使用自带的开发工具来抓取cURL命令,您可以按照以下步骤操作:

1. 打开Microsoft Edge浏览器并导航到需要进行登录的网页(校园网认证页)。
2. 按下`F12`键或右键点击页面上的任何元素,然后选择"检查"选项来打开开发者工具。
3. 在开发者工具窗口中,切换到"网络"选项卡。在开发者工具的"网络"选项卡中勾选保留日志。
4. 在浏览器中进行登录操作,填写用户名和密码,并点击登录按钮。
5. 您将看到网页加载过程中的所有网络请求和响应信息。
6. 找到包含登录请求的条目,通常是名为"login"、"signin"或类似的条目(如果找不到就选第一个条目)。右键该条目以复制我们要的curl(cmd)内容。
将curl粘贴到此处覆盖此说明,点击下方"保存抓包",然后就可以点击生成脚本了,创建成功后就可以启动脚本开始认证了。
请注意,Microsoft Edge开发者工具的界面可能因不同版本而有所不同,但通常您应该能够在"网络"选项卡中找到登录请求并获取相应的cURL命令。
记住:在复制curl时不要搞错,一定选择复制curl(cmd),否则脚本可能无法发送正确请求
=====================================================================================================================================
在本输入框输入"禁用"并保存可以停用认证功能,届时重启后将不再进行自动认证以及网络守护【仍然可以手动认证】
56 changes: 56 additions & 0 deletions luci-app-autoshell/cbi/autoshell.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
local fs = require "nixio.fs"
local uci = require "luci.model.uci".cursor()
local conffile = "/etc/config/autoshell"

f = SimpleForm("logview", translate("web抓包认证"), translate("在这里粘贴你抓包的curl,系统将自动生成对应请求脚本并实时保持网络在线。"))
f.reset = false
f.submit = translate("保存抓包")

t = f:field(TextValue, "conf")
t.rmempty = true
t.rows = 20
function t.cfgvalue()
local value = fs.readfile(conffile)
return value or ""
end
function t.write(self, section, value)
if value then
fs.writefile(conffile, value)
end
end

btn_generate = f:field(Button, "generate", "")
btn_generate.inputtitle = "生成脚本"

function btn_generate.write()
local scriptExist = luci.sys.call("[ -f /etc/autoshell.sh ]") == 0
if scriptExist then
luci.http.write('<script>alert("脚本已更新!!");</script>')
os.execute("sh /etc/autoshells.sh")
else
luci.http.write('<script>alert("脚本创建成功!!");</script>')
os.execute("sh /etc/autoshells.sh")
end
end

local pid = luci.sys.exec("pgrep -f '/etc/autoshell.sh'")

if pid == "" then
btn_authenticate = f:field(Button, "authenticate", "")
btn_authenticate.inputtitle = "开始认证"

function btn_authenticate.write()
luci.http.redirect(luci.dispatcher.build_url("admin", "services", "webauto"))
os.execute("sh /etc/autoshell.sh &")
end
else
btn_stop = f:field(Button, "stop", "")
btn_stop.inputtitle = "停止脚本"

function btn_stop.write()
os.execute("killall sh /etc/autoshell.sh")
luci.http.redirect(luci.dispatcher.build_url("admin", "services", "webauto"))
end
end

return f
32 changes: 32 additions & 0 deletions luci-app-autoshell/cbi/autoshell_log.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
local fs = require "nixio.fs"
local conffile = "/tmp/log/autoshell.log"

f = SimpleForm("logview", translate("日志"), translate("日志不能实时更新,需要手动刷新界面"))
f.reset = false
f.submit = false

t = f:field(TextValue, "conf")
t.rmempty = true
t.rows = 20
function t.cfgvalue()
return fs.readfile(conffile) or ""
end

t.readonly="readonly"

btn_clear = f:field(Button, "clear", "")
btn_clear.inputtitle = "清除日志"

function btn_clear.write()
fs.writefile(conffile, "日志已清除")
luci.http.redirect(luci.dispatcher.build_url("admin", "services", "webauto", "log"))
end

btn_read = f:field(Button, "read", "")
btn_read.inputtitle = "刷新日志"

function btn_read.write()
t.value = fs.readfile(conffile) or ""
end

return f
7 changes: 7 additions & 0 deletions luci-app-autoshell/controller/autoshell.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module("luci.controller.autoshell", package.seeall)

function index()
entry({"admin", "services", "webauto"}, alias("admin", "services", "webauto", "settings"), _("Web认证"), 99).index = true
entry({"admin", "services", "webauto", "settings"}, cbi("autoshell"), _("认证设置"), 1)
entry({"admin", "services", "webauto", "log"}, cbi("autoshell_log"), _("认证日志"), 2)
end
77 changes: 77 additions & 0 deletions luci-app-autoshell/etc/autoshells.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/bin/sh

conffile="/etc/config/autoshell"
output_file="/etc/autoshell.sh"

url=""
headers=""
data=""

while read -r line; do
if [[ "$line" =~ "curl" ]]; then
url=$(echo "$line" | grep -oE 'curl "([^"]+)"' | cut -d'"' -f2)
elif [[ "$line" =~ "-H" ]]; then
header=$(echo "$line" | grep -oE '^ *-H "[^"]+"' | cut -d'"' -f2)
headers="$headers\n$header"
elif [[ "$line" =~ "--data-raw" ]]; then
data=$(echo "$line" | grep -oE '\-\-data-raw "[^"]+"' | cut -d'"' -f2)
data=$(echo "$data" | tr -d '^')
fi
done < "$conffile"

headers=$(echo -e "$headers")
headers=$(echo "$headers" | sed 's/\^\%\^/^/g')

cat <<EOF > "$output_file"
#!/bin/sh
url="$url"
headers="$headers"
data="$data"
log_file="/tmp/log/autoshell.log"
log_time=\$(date '+%Y-%m-%d %H:%M:%S')
echo "[\$log_time] 开始运行" >> "\$log_file"
while true; do
while true; do
log_time=\$(date '+%Y-%m-%d %H:%M:%S')
if ping -c 1 8.8.8.8 >/dev/null; then
echo "[\$log_time] 网络守护日志输出-目前网络正常" >> "\$log_file"
log_line_count=\$(wc -l < "\$log_file")
if [ "\$log_line_count" -gt 100 ]; then
echo "[\$log_time] 日志达到上限,已覆盖" > "\$log_file"
fi
sleep 30
else
echo "[\$log_time] 网络异常,进行二次网络监测,避免误测" >> "\$log_file"
sleep 3
break
fi
done
while true; do
log_time=\$(date '+%Y-%m-%d %H:%M:%S')
if ping -c 1 8.8.8.8 >/dev/null; then
break
else
echo "[\$log_time] 确认网络异常,将发起认证请求!" >> "\$log_file"
response=\$(curl -s -X POST -H "\$(echo "\$headers" | tr '\n' '\r\n')" -d "\$data" "\$url")
sleep 5
if [ \${#response} -lt 1 ]; then
echo "[\$log_time] 服务器未返回信息,等待网络检测结果" >> "\$log_file"
else
result=\$(echo "\$response" | grep -o '"result":"[^"]*"' | sed 's/"result":"\([^"]*\)"/\1/')
message=\$(echo "\$response" | grep -o '"message":"[^"]*"' | sed 's/"message":"\([^"]*\)"/\1/')
echo "[\$log_time] 服务器返回:\$response" >> "\$log_file"
fi
fi
done
done
EOF

chmod +x "$output_file"
exit 0
40 changes: 40 additions & 0 deletions luci-app-autoshell/init.d/autoreboot
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/sh /etc/rc.common

START=90

run_reboot()
{
local enable
config_get_bool enable $1 enable

if [ $enable ]; then
local minute
local hour

config_get minute $1 minute
config_get hour $1 hour

sed '/reboot/ d' /etc/crontabs/root > /tmp/crontab_root_tmp
cp /tmp/crontab_root_tmp /etc/crontabs/root
echo "$minute $hour * * * reboot &" >> /etc/crontabs/root

echo "Auto REBOOT has started."
/etc/init.d/cron restart
else
sed '/reboot/ d' /etc/crontabs/root > /tmp/crontab_root_tmp
cp /tmp/crontab_root_tmp /etc/crontabs/root
echo "Auto REBOOT has started."
/etc/init.d/cron restart
fi
}

start()
{
config_load autoreboot
config_foreach run_reboot login
}

stop()
{
echo "Auto REBOOT has stoped."
}
35 changes: 35 additions & 0 deletions luci-app-autoshell/init.d/autoshell
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/sh /etc/rc.common

START=99

log_file="/tmp/log/autoshell.log"

start() {
state=$(pgrep -f "/etc/autoshell.sh")

config_content=$(cat /etc/config/autoshell)
if echo "$config_content" | grep -q "禁用"; then
echo "[$(date "+%Y-%m-%d %H:%M:%S")]: 脚本已禁用" >> "$log_file"
return 1

else
/etc/autoshell.sh &
echo "[$(date "+%Y-%m-%d %H:%M:%S")]: 已启动认证脚本" >> "$log_file"
fi
}

stop() {
kill -9 $(pgrep -f "/etc/autoshell.sh") 2>/dev/null
echo "$(date "+%Y-%m-%d %H:%M:%S"): 已停止认证" >>
}

restart() {
stop
sleep 1
start
echo "$(date "+%Y-%m-%d %H:%M:%S"): 已重新启动 /etc/autoshell.sh"
}

disable() {
echo "禁用功能未实现"
}
22 changes: 22 additions & 0 deletions luci-app-chongyoung/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#
# Copyright (C) 2008-2014 The LuCI Team <[email protected]>
#
# This is free software, licensed under the Apache License, Version 2.0 .
#

include $(TOPDIR)/rules.mk

LUCI_TITLE:=chongyoung for luci
LUCI_DEPENDS:=
LUCI_PKGARCH:=all
PKG_VERSION:=4.1.1
PKG_RELEASE:=4

define Package/luci-app-chongyoung/postinst
#!/bin/sh
chmod +x $(1)/etc/init.d/*
exit 0
endef

include $(TOPDIR)/feeds/luci/luci.mk
# call BuildPackage - OpenWrt buildroot signature
8 changes: 8 additions & 0 deletions luci-app-chongyoung/luasrc/controller/chongyoung.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module("luci.controller.chongyoung", package.seeall)

function index()
entry({"admin", "school", "chongyoung"}, alias("admin", "school", "chongyoung", "settings"), _("飞young"), 100).index = true
entry({"admin", "school", "chongyoung", "settings"}, cbi("chongyoung"), _("认证设置"), 1)
entry({"admin", "school", "chongyoung", "passwd"}, cbi("chongyoung2"), _("密码管理"), 2)
entry({"admin", "school", "chongyoung", "log"}, cbi("chongyoung_log"), _("认证日志"), 3)
end
16 changes: 16 additions & 0 deletions luci-app-chongyoung/luasrc/model/cbi/chongyoung.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
m = Map("chongyoung", translate("湖北飞young认证--冲young"))

s = m:section(TypedSection, "chongyoung", "")
s.anonymous = true

enabled = s:option(Flag, "enabled", "启用")
user = s:option(Value, "user", "账号")
time = s:option(Value, "time", "网络监测间隔/秒")

local apply = luci.http.formvalue("cbi.apply")
if apply then
io.popen("/etc/init.d/chongyoung start")
end


return m
26 changes: 26 additions & 0 deletions luci-app-chongyoung/luasrc/model/cbi/chongyoung2.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
local fs = require "nixio.fs"
local uci = require "luci.model.uci".cursor()
local conffile = "/etc/config/userprofile"

f = SimpleForm("logview", translate("密码管理"), translate("填入算号器算出的密码以及账号,如果没有算号程序请加入QQ群555201601 获取"))
f.reset = false
f.submit = translate("保存参数")

t = f:field(TextValue, "conf")
t.rmempty = true
t.rows = 20
function t.cfgvalue()
local value = fs.readfile(conffile)
return value or ""
end

-- 在保存前,将Windows换行符 (\r\n) 替换为Linux换行符 (\n),否则会导致读取密码时发生错误。。。
function t.write(self, section, value)
if value then
-- 将 \r\n 替换为 \n
value = value:gsub("\r\n", "\n")
fs.writefile(conffile, value)
end
end

return f
Loading

0 comments on commit 25a0842

Please sign in to comment.