rufengsuixing 5 years ago
parent
commit
031fd9b4a1

+ 9 - 3
luasrc/model/cbi/AdGuardHome.lua

@@ -11,7 +11,7 @@ local binpath=uci:get("AdGuardHome","AdGuardHome","binpath")
 if (binpath==nil) then
 binpath="/usr/bin/AdGuardHome/AdGuardHome"
 end
-local httpport=luci.sys.exec("awk '/bind_port:/{printf($2)}' "..configpath.." 2>nul")
+local httpport=luci.sys.exec("awk '/bind_port:/{printf($2);exit;}' "..configpath.." 2>nul")
 if (httpport=="") then
 httpport=uci:get("AdGuardHome","AdGuardHome","httpport")
 end
@@ -59,7 +59,7 @@ o.template = "AdGuardHome/AdGuardHome_check"
 o.description=string.format(translate("目前运行主程序版本").."<strong><font color=\"green\">: %s </font></strong>",e)
 
 ---- port warning not safe
-local port=luci.sys.exec("awk '/  port:/{printf($2)}' "..configpath.." 2>nul")
+local port=luci.sys.exec("awk '/  port:/{printf($2);exit;}' "..configpath.." 2>nul")
 if (port=="") then
 port="?"
 end
@@ -105,7 +105,13 @@ end
 o = s:option(Value, "gfwupstream", translate("gfw upstream dns server"), translate("gfwlist domain upstream dns service"))
 o.default     = "tcp://208.67.220.220#5353"
 o.datatype    = "string"
-o.rempty      = false
+o.rmempty      = false
+---- chpass
+o = s:option(Value, "hashpass", translate("更改密码"), translate("点击计算后应用设置"))
+o.default     = ""
+o.datatype    = "string"
+o.rmempty     = false
+o.template = "AdGuardHome/AdGuardHome_chpass"
 
 local apply = luci.http.formvalue("cbi.apply")
  if apply then

+ 52 - 0
luasrc/view/AdGuardHome/AdGuardHome_chpass.htm

@@ -0,0 +1,52 @@
+<%+cbi/valueheader%>
+<script type="text/javascript">//<![CDATA[
+function chpass(btn)
+	{
+		btn.disabled = true;
+		btn.value    = 'working';
+		if (typeof bcryptloaded == 'undefined' ){
+		var theHead = document.getElementsByTagName('head').item(0);
+		//创建脚本的dom对象实例
+		var myScript = document.createElement('script');
+		myScript.src = '<%=resource%>/twin-bcrypt.min.js';            //指定脚本路径
+		myScript.type = 'text/javascript';    //指定脚本类型
+		myScript.defer = true;                //程序下载完后再解析和执行
+		theHead.appendChild(myScript);
+		bcryptloaded=1;
+		btn.value    = '计算';
+		btn.disabled = false;
+		return
+		}
+		var lv = document.getElementById('cbid.AdGuardHome.AdGuardHome.hashpass');
+		if (lv.value != ""){
+		var hash = TwinBcrypt.hashSync(lv.value);
+		lv.value=hash;
+		btn.value    = '请提交';
+		}else{
+		btn.value    = '为空';
+		btn.disabled = false;
+		}
+	}
+//]]>
+</script>
+		<input data-update="change"<%=
+		attr("id", cbid) ..
+		attr("name", cbid) ..
+		attr("type", self.password and "password" or "text") ..
+		attr("class", self.password and "cbi-input-password" or "cbi-input-text") ..
+		attr("value", self:cfgvalue(section) or self.default) ..
+		ifattr(self.size, "size") ..
+		ifattr(self.placeholder, "placeholder") ..
+		ifattr(self.readonly, "readonly") ..
+		ifattr(self.maxlength, "maxlength") ..
+		ifattr(self.datatype, "data-type", self.datatype) ..
+		ifattr(self.datatype, "data-optional", self.optional or self.rmempty) ..
+		ifattr(self.combobox_manual, "data-manual", self.combobox_manual) ..
+		ifattr(#self.keylist > 0, "data-choices", { self.keylist, self.vallist })
+	%> />
+	<% if self.password then %><img src="<%=resource%>/cbi/reload.gif" style="vertical-align:middle" title="<%:Reveal/hide password%>" onclick="var e = document.getElementById('<%=cbid%>'); e.type = (e.type=='password') ? 'text' : 'password';" /><% end %>
+	
+	<input class="cbi-button cbi-button-apply" name="cbid.AdGuardHome.AdGuardHome.applychpass" id="cbid.AdGuardHome.AdGuardHome.applychpass" value="加载计算模块" onclick="return chpass(this)"/>
+
+	
+<%+cbi/valuefooter%>

+ 9 - 3
root/etc/init.d/AdGuardHome

@@ -149,8 +149,7 @@ do_redirect()
 	ipv6_server=0
 	tcp_server=0
 	enabled=$1
-	
-	
+
 	config_get "redirect" "$section" "redirect" "none"
 	config_get "old_redirect" "$section" "old_redirect" "none"
 	config_get "old_port" "$section" "old_port" "0"
@@ -225,6 +224,12 @@ start_service() {
 	config_load "${CONFIGURATION}"
 	local enabled
 	local ADDITIONAL_ARGS=""
+		
+	config_get hashpass $CONFIGURATION hashpass ""
+	if [ ! -z "$hashpass" ]; then
+		sed -i "1,50{/  password:/c\  password: $hashpass}" $configpath
+		uci set $CONFIGURATION.$CONFIGURATION.hashpass=""
+	fi
 	config_get_bool enabled $CONFIGURATION enabled 0
 	config_get httpport $CONFIGURATION httpport 3000
 	ADDITIONAL_ARGS="$ADDITIONAL_ARGS -p $httpport"
@@ -239,6 +244,7 @@ start_service() {
 	if [ ! -z "$logfile" ]; then
 		ADDITIONAL_ARGS="$ADDITIONAL_ARGS -l $logfile"
 	fi
+	
 	config_get binpath $CONFIGURATION binpath "/usr/bin/AdGuardHome/AdGuardHome"
 	mkdir -p ${binpath%/*}
 	if [ ! -f "$binpath" ]; then
@@ -248,7 +254,7 @@ start_service() {
 	elif [ ! -f "$configpath" ]; then
 		do_redirect 0
 	fi 
-	
+
 	config_get_bool verbose $CONFIGURATION verbose 0
 	if [ "$verbose" -eq 1 ]; then
 		ADDITIONAL_ARGS="$ADDITIONAL_ARGS -v"

File diff suppressed because it is too large
+ 5 - 0
www/luci-static/resources/twin-bcrypt.min.js


Some files were not shown because too many files changed in this diff