luci-app-jd-dailybonus: Keep up to date from jerrykuku (#6253)
* luci-app-jd-dailybonus: Keep up to date from jerrykuku * luci-app-jd-dailybonus: Keep up to date from jerrykuku
This commit is contained in:
parent
b927a69df8
commit
434b834160
@ -44,6 +44,7 @@ define Package/luci-app-jd-dailybonus/install
|
|||||||
$(INSTALL_DIR) $(1)/usr/share/jd-dailybonus
|
$(INSTALL_DIR) $(1)/usr/share/jd-dailybonus
|
||||||
$(INSTALL_BIN) ./root/usr/share/jd-dailybonus/*.sh $(1)/usr/share/jd-dailybonus/
|
$(INSTALL_BIN) ./root/usr/share/jd-dailybonus/*.sh $(1)/usr/share/jd-dailybonus/
|
||||||
$(INSTALL_DATA) ./root/usr/share/jd-dailybonus/*.js $(1)/usr/share/jd-dailybonus/
|
$(INSTALL_DATA) ./root/usr/share/jd-dailybonus/*.js $(1)/usr/share/jd-dailybonus/
|
||||||
|
$(INSTALL_DATA) ./root/usr/share/jd-dailybonus/*.lua $(1)/usr/share/jd-dailybonus/
|
||||||
|
|
||||||
$(INSTALL_DIR) $(1)/usr/share/rpcd/acl.d
|
$(INSTALL_DIR) $(1)/usr/share/rpcd/acl.d
|
||||||
$(INSTALL_DATA) ./root/usr/share/rpcd/acl.d/* $(1)/usr/share/rpcd/acl.d
|
$(INSTALL_DATA) ./root/usr/share/rpcd/acl.d/* $(1)/usr/share/rpcd/acl.d
|
||||||
@ -51,9 +52,6 @@ define Package/luci-app-jd-dailybonus/install
|
|||||||
$(INSTALL_DIR) $(1)/usr/lib/node
|
$(INSTALL_DIR) $(1)/usr/lib/node
|
||||||
cp -pR ./root/usr/lib/node/* $(1)/usr/lib/node
|
cp -pR ./root/usr/lib/node/* $(1)/usr/lib/node
|
||||||
|
|
||||||
$(INSTALL_DIR) $(1)/www/jd-dailybonus
|
|
||||||
$(INSTALL_DATA) ./root//www/jd-dailybonus/* $(1)/www/jd-dailybonus
|
|
||||||
|
|
||||||
$(INSTALL_DIR) $(1)/usr/lib/lua/luci/controller
|
$(INSTALL_DIR) $(1)/usr/lib/lua/luci/controller
|
||||||
$(INSTALL_DATA) ./luasrc/controller/* $(1)/usr/lib/lua/luci/controller/
|
$(INSTALL_DATA) ./luasrc/controller/* $(1)/usr/lib/lua/luci/controller/
|
||||||
|
|
||||||
@ -63,6 +61,9 @@ define Package/luci-app-jd-dailybonus/install
|
|||||||
$(INSTALL_DIR) $(1)/usr/lib/lua/luci/view/jd-dailybonus
|
$(INSTALL_DIR) $(1)/usr/lib/lua/luci/view/jd-dailybonus
|
||||||
$(INSTALL_DATA) ./luasrc/view/jd-dailybonus/* $(1)/usr/lib/lua/luci/view/jd-dailybonus/
|
$(INSTALL_DATA) ./luasrc/view/jd-dailybonus/* $(1)/usr/lib/lua/luci/view/jd-dailybonus/
|
||||||
|
|
||||||
|
$(INSTALL_DIR) $(1)/lib/upgrade/keep.d
|
||||||
|
$(INSTALL_DATA) ./root/lib/upgrade/keep.d/* $(1)/lib/upgrade/keep.d/
|
||||||
|
|
||||||
endef
|
endef
|
||||||
|
|
||||||
$(eval $(call BuildPackage,luci-app-jd-dailybonus))
|
$(eval $(call BuildPackage,luci-app-jd-dailybonus))
|
||||||
|
@ -17,13 +17,6 @@ function index()
|
|||||||
entry({'admin', 'services', 'jd-dailybonus', 'check_login'}, call('check_login')) -- 获取二维码
|
entry({'admin', 'services', 'jd-dailybonus', 'check_login'}, call('check_login')) -- 获取二维码
|
||||||
end
|
end
|
||||||
|
|
||||||
-- 写入配置
|
|
||||||
function write_json(file, content)
|
|
||||||
local json = require 'luci.jsonc'
|
|
||||||
local f = assert(io.open(file, 'w'))
|
|
||||||
f:write(json.stringify(content, 1))
|
|
||||||
f:close()
|
|
||||||
end
|
|
||||||
-- 执行程序
|
-- 执行程序
|
||||||
function run()
|
function run()
|
||||||
local e = {}
|
local e = {}
|
||||||
@ -31,14 +24,7 @@ function run()
|
|||||||
local data = luci.http.formvalue()
|
local data = luci.http.formvalue()
|
||||||
uci:tset('jd-dailybonus', '@global[0]', data)
|
uci:tset('jd-dailybonus', '@global[0]', data)
|
||||||
uci:commit('jd-dailybonus')
|
uci:commit('jd-dailybonus')
|
||||||
local json_data = {
|
luci.sys.call('lua /usr/share/jd-dailybonus/gen_cookieset.lua')
|
||||||
CookieJD = data.cookie,
|
|
||||||
CookieJD2 = data.cookie2:len() == 0 and nil or data.cookie2,
|
|
||||||
JD_DailyBonusDelay = data.stop,
|
|
||||||
JD_DailyBonusTimeOut = data.out
|
|
||||||
}
|
|
||||||
write_json('/root/CookieSet.json', json_data)
|
|
||||||
write_json('/www/CookieSet.json', json_data)
|
|
||||||
luci.sys.call('/usr/share/jd-dailybonus/newapp.sh -r')
|
luci.sys.call('/usr/share/jd-dailybonus/newapp.sh -r')
|
||||||
luci.sys.call('/usr/share/jd-dailybonus/newapp.sh -a')
|
luci.sys.call('/usr/share/jd-dailybonus/newapp.sh -a')
|
||||||
e.error = 0
|
e.error = 0
|
||||||
@ -129,15 +115,8 @@ function check_login()
|
|||||||
local pt_pin = luci.sys.exec("echo -n $(cat "..cookie.." | grep pt_pin | awk '{print $7}')")
|
local pt_pin = luci.sys.exec("echo -n $(cat "..cookie.." | grep pt_pin | awk '{print $7}')")
|
||||||
local cookieStr = 'pt_key=' .. pt_key .. ';pt_pin=' .. pt_pin .. ';'
|
local cookieStr = 'pt_key=' .. pt_key .. ';pt_pin=' .. pt_pin .. ';'
|
||||||
uci:set('jd-dailybonus', '@global[0]', id, cookieStr)
|
uci:set('jd-dailybonus', '@global[0]', id, cookieStr)
|
||||||
local json_data = {
|
|
||||||
CookieJD = uci:get('jd-dailybonus', '@global[0]', 'cookie'),
|
|
||||||
CookieJD2 = uci:get('jd-dailybonus', '@global[0]', 'cookie2'),
|
|
||||||
JD_DailyBonusDelay = uci:get('jd-dailybonus', '@global[0]', 'stop'),
|
|
||||||
JD_DailyBonusTimeOut = uci:get('jd-dailybonus', '@global[0]', 'out')
|
|
||||||
}
|
|
||||||
write_json('/root/CookieSet.json', json_data)
|
|
||||||
write_json('/www/CookieSet.json', json_data)
|
|
||||||
uci:commit('jd-dailybonus')
|
uci:commit('jd-dailybonus')
|
||||||
|
luci.sys.call('lua /usr/share/jd-dailybonus/gen_cookieset.lua')
|
||||||
return_json.cookie = cookieStr
|
return_json.cookie = cookieStr
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,9 +1,5 @@
|
|||||||
<%+cbi/valueheader%>
|
<%+cbi/valueheader%>
|
||||||
<script src="/jd-dailybonus/jquery.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/qrcode_js@1.0.0/qrcode.min.js"></script>
|
||||||
<script src="/jd-dailybonus/qrcode.min.js"></script>
|
|
||||||
<script type="text/javascript">
|
|
||||||
var jq=$.noConflict();
|
|
||||||
</script>
|
|
||||||
<style>
|
<style>
|
||||||
.modals-bg {
|
.modals-bg {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
@ -42,8 +38,6 @@ var jq=$.noConflict();
|
|||||||
opacity: 0;
|
opacity: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
.modals.hide {
|
.modals.hide {
|
||||||
visibility: hidden;
|
visibility: hidden;
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
@ -55,13 +49,13 @@ var jq=$.noConflict();
|
|||||||
color: #fff;
|
color: #fff;
|
||||||
background: transparent;
|
background: transparent;
|
||||||
padding: 0 !important;
|
padding: 0 !important;
|
||||||
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.modals h3 {
|
.modals h3 {
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
color: #f5365c !important;
|
color: #f5365c !important;
|
||||||
background: transparent;
|
background: transparent;
|
||||||
margin: 0 0 1em 0;
|
|
||||||
padding: 0 0 0.5em 0;
|
padding: 0 0 0.5em 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,7 +70,8 @@ var jq=$.noConflict();
|
|||||||
outline: none;
|
outline: none;
|
||||||
padding-left: 3px;
|
padding-left: 3px;
|
||||||
padding-right: 22px;
|
padding-right: 22px;
|
||||||
overflow: hidden
|
overflow: hidden;
|
||||||
|
resize: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.cbi-value-version {
|
.cbi-value-version {
|
||||||
@ -199,7 +194,7 @@ var jq=$.noConflict();
|
|||||||
<%+cbi/valueheader%>
|
<%+cbi/valueheader%>
|
||||||
<label class="cbi-value-title"><%= translate("更新脚本") %></label>
|
<label class="cbi-value-title"><%= translate("更新脚本") %></label>
|
||||||
<div class="cbi-value-field">
|
<div class="cbi-value-field">
|
||||||
<input class="cbi-button cbi-button-reload" id="update_script" type="button" size="0"
|
<input class="cbi-button cbi-button-reload" id="update_script" type="button" size="0" onclick="check_version()" data-version="<%= self.version %>"
|
||||||
value="<%= translate("手动检查脚本更新,当前版本:v")..self.version %>">
|
value="<%= translate("手动检查脚本更新,当前版本:v")..self.version %>">
|
||||||
</div>
|
</div>
|
||||||
<%+cbi/valuefooter%>
|
<%+cbi/valuefooter%>
|
||||||
@ -209,7 +204,7 @@ var jq=$.noConflict();
|
|||||||
<div id="refresh_qrcode" class="hidden">
|
<div id="refresh_qrcode" class="hidden">
|
||||||
<div>
|
<div>
|
||||||
<h3>二维码已失效</h3>
|
<h3>二维码已失效</h3>
|
||||||
<div class="refresh">刷新</div>
|
<div class="refresh" onclick="get_code()">刷新</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="qrcode"></div>
|
<div id="qrcode"></div>
|
||||||
@ -226,215 +221,163 @@ var jq=$.noConflict();
|
|||||||
const UPDATE_URL = '<%=luci.dispatcher.build_url("admin", "services", "jd-dailybonus","update")%>';
|
const UPDATE_URL = '<%=luci.dispatcher.build_url("admin", "services", "jd-dailybonus","update")%>';
|
||||||
const CHECKING_TEXT = '<%= translate("正在检查是否存在新的版本 ...") %>';
|
const CHECKING_TEXT = '<%= translate("正在检查是否存在新的版本 ...") %>';
|
||||||
const UPDATING_TEXT = '<%= translate("正在更新脚本,请稍候 ...") %>';
|
const UPDATING_TEXT = '<%= translate("正在更新脚本,请稍候 ...") %>';
|
||||||
const NEW_VERSION = '<%= translate("当前已是最新版本。") %>';
|
const NEW_VERSION = '<%= translate("当前已是最新版本:") %>';
|
||||||
const UPDATE_TEXT = '<%= translate("有新的版本,请点击更新") %>';
|
|
||||||
|
|
||||||
var needUpdate = false;
|
|
||||||
var newVersion;
|
|
||||||
var _responseLen;
|
|
||||||
var noChange = 0;
|
var noChange = 0;
|
||||||
var ckid = 0;
|
var ckid = 0;
|
||||||
var modal = '<div class="modals-bg hide">' +
|
var modal = `<div class="modals-bg hide">
|
||||||
'<div class="modals hide">' +
|
<div class="modals hide">
|
||||||
'<h2>签到信息</h2>' +
|
<h2>签到信息</h2>
|
||||||
'<h3 style="margin-left:0;">服务正在执行中,请勿刷新!</h3>' +
|
<h3 style="margin-left:0;">服务正在执行中,请勿刷新!</h3>
|
||||||
'<textarea cols="63" rows="28" wrap="on" readonly="readonly" id="log_content3" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"></textarea>' +
|
<textarea cols="63" rows="28" wrap="on" readonly="readonly" id="log_content3" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"></textarea>
|
||||||
'</div>' +
|
</div>
|
||||||
'</div>';
|
</div>`;
|
||||||
|
|
||||||
//显示并开始刷新订阅
|
//显示并开始刷新订阅
|
||||||
function update_service() {
|
function update_service() {
|
||||||
jq("body").append(modal);
|
document.body.insertAdjacentHTML('beforeend', modal);
|
||||||
jq(".modals-bg").removeClass("hide");
|
document.getElementsByClassName("modals-bg")[0].classList.remove("hide");
|
||||||
setTimeout(function(){
|
setTimeout(() => {
|
||||||
jq(".modals").removeClass("hide");
|
document.getElementsByClassName("modals")[0].classList.remove("hide");
|
||||||
}, 100);
|
}, 100);
|
||||||
setTimeout("get_realtime_log();", 500);
|
setTimeout(get_realtime_log, 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
function el(dom_el){
|
function el(dom_el){
|
||||||
let prefix_array = jq("#cbi-jd-dailybonus-global .cbi-section-node").attr("id").split("-");
|
let prefix = document.getElementById("cbi-jd-dailybonus-global").getElementsByClassName("cbi-section-node")[0].id.split("-").pop();
|
||||||
let prefix = prefix_array[prefix_array.length - 1];
|
return document.querySelector(`[name='cbid.jd-dailybonus.${prefix}.${dom_el}']`);
|
||||||
return jq("[name='cbid.jd-dailybonus." + prefix + "." + dom_el + "']");
|
|
||||||
}
|
}
|
||||||
//保存订阅按钮
|
//保存订阅按钮
|
||||||
jq("#update_service").click(function () {
|
document.getElementById("update_service").onclick = () => {
|
||||||
if(el("cookie").val() == ""){
|
if(el("cookie").value == ""){
|
||||||
alert("请至少填写cookie1");
|
alert("请至少填写cookie1");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
var json = {
|
let json = {
|
||||||
auto_update: el("auto_update").is(":checked")?"1":"0",
|
auto_update: el("auto_update").checked?"1":"0",
|
||||||
auto_update_time: el("auto_update").is(":checked")?el("auto_update_time").val():"0",
|
auto_update_time: el("auto_update").checked?el("auto_update_time").value:"0",
|
||||||
auto_run: el("auto_run").is(":checked")?"1":"0",
|
auto_run: el("auto_run").checked?"1":"0",
|
||||||
auto_run_time_h: el("auto_run").is(":checked")?el("auto_run_time_h").val():"0",
|
auto_run_time_h: el("auto_run").checked?el("auto_run_time_h").value:"0",
|
||||||
auto_run_time_h: el("auto_run").is(":checked")?el("auto_run_time_m").val():"0",
|
auto_run_time_m: el("auto_run").checked?el("auto_run_time_m").value:"0",
|
||||||
cookie: el("cookie").val(),
|
cookie: el("cookie").value,
|
||||||
cookie2: el("cookie2").val(),
|
cookie2: el("cookie2").value,
|
||||||
stop: el("stop").val(),
|
stop: el("stop").value,
|
||||||
out: el("out").val(),
|
out: el("out").value,
|
||||||
serverchan: el("serverchan").val(),
|
serverchan: el("serverchan").value,
|
||||||
tg_token: el("tg_token").val(),
|
tg_token: el("tg_token").value,
|
||||||
tg_userid: el("tg_userid").val(),
|
tg_userid: el("tg_userid").value,
|
||||||
serverurl: el("serverurl").val(),
|
serverurl: el("serverurl").value,
|
||||||
remote_url: el("remote_url").val()
|
remote_url: el("remote_url").value
|
||||||
}
|
}
|
||||||
jq.ajax({
|
XHR.get(SAVE_URL, json, (x, d) => {
|
||||||
type: "post",
|
if (d.error == 0) {
|
||||||
url: SAVE_URL,
|
update_service();
|
||||||
dataType: "json",
|
} else {
|
||||||
data: json,
|
alert("请填写cookies");
|
||||||
success: function (d) {
|
|
||||||
if (d.error == 0) {
|
|
||||||
update_service();
|
|
||||||
} else {
|
|
||||||
alert("请填写cookies");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
});
|
}
|
||||||
|
|
||||||
|
//获取实时日志
|
||||||
|
function get_realtime_log() {
|
||||||
|
XHR.poll(1, "/JD_DailyBonus.htm", null, x => {
|
||||||
|
let retArea = document.getElementById("log_content3");
|
||||||
|
if (x.response.search(" 秒") != -1) {
|
||||||
|
noChange++;
|
||||||
|
}
|
||||||
|
if (noChange > 5) {
|
||||||
|
location.reload();
|
||||||
|
}
|
||||||
|
retArea.value = x.response;
|
||||||
|
retArea.scrollTop = retArea.scrollHeight;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
//更新脚本
|
//更新脚本
|
||||||
jq("#update_script").click(function () {
|
function check_version() {
|
||||||
check_version()
|
let btn = document.getElementById("update_script");
|
||||||
return false;
|
let version = btn.getAttribute("data-version");
|
||||||
});
|
btn.disabled = true;
|
||||||
|
btn.value = CHECKING_TEXT;
|
||||||
|
XHR.get(CHECK_URL, null, (x,d) => {
|
||||||
|
if (d.new_version == 501){
|
||||||
|
btn.disabled = false;
|
||||||
|
btn.value = "无法获取新版本,请重试!";
|
||||||
|
}else if (d.new_version > version) {
|
||||||
|
btn.disabled = true;
|
||||||
|
btn.value = `${UPDATING_TEXT} v${d.new_version}`;
|
||||||
|
|
||||||
function updateS(){
|
XHR.get(UPDATE_URL, {version: version}, (x, r) => {
|
||||||
jq("#update_script").attr("disabled", true);
|
if (r.error == 0) {
|
||||||
jq("#update_script").val(UPDATING_TEXT);
|
btn.value = `${NEW_VERSION} v${d.new_version}`;
|
||||||
//console.log(data);
|
btn.setAttribute("data-version", d.new_version);
|
||||||
var data = {
|
|
||||||
version: jq("#update_script").attr("data-version")
|
|
||||||
}
|
|
||||||
jq.ajax({
|
|
||||||
type: "post",
|
|
||||||
url: UPDATE_URL,
|
|
||||||
dataType: "json",
|
|
||||||
data: data,
|
|
||||||
success: function (d) {
|
|
||||||
if (d.error == 0) {
|
|
||||||
jq("#update_script").val(NEW_VERSION);
|
|
||||||
jq(".cbi-value-version").text("v" + newVersion);
|
|
||||||
} else {
|
} else {
|
||||||
jq("#update_script").attr("disabled", false);
|
btn.disabled = false;
|
||||||
alert("更新错误请重试");
|
alert("更新错误请重试");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function get_realtime_log() {
|
|
||||||
jq.ajax({
|
|
||||||
url: '/JD_DailyBonus.htm?v=' + parseInt(Math.random() * 100000000),
|
|
||||||
dataType: 'html',
|
|
||||||
error: function (xhr) {
|
|
||||||
setTimeout("get_realtime_log();", 1000);
|
|
||||||
},
|
|
||||||
success: function (response) {
|
|
||||||
var retArea = document.getElementById("log_content3");
|
|
||||||
if (response.search(" 秒") != -1) {
|
|
||||||
noChange++;
|
|
||||||
}
|
|
||||||
console.log(noChange);
|
|
||||||
if (noChange > 10) {
|
|
||||||
window.location.href = '<%=luci.dispatcher.build_url("admin", "services", "jd-dailybonus")%>';
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
setTimeout("get_realtime_log();", 250);
|
|
||||||
}
|
|
||||||
retArea.value = response;
|
|
||||||
retArea.scrollTop = retArea.scrollHeight;
|
|
||||||
_responseLen = response.length;
|
|
||||||
},
|
|
||||||
error: function () {
|
|
||||||
setTimeout("get_realtime_log();", 500);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function check_version() {
|
|
||||||
jq("#update_script").attr("disabled", true);
|
|
||||||
jq("#update_script").val(CHECKING_TEXT);
|
|
||||||
jq.ajax({
|
|
||||||
url: CHECK_URL,
|
|
||||||
dataType: 'json',
|
|
||||||
error: function (xhr) {
|
|
||||||
|
|
||||||
},
|
|
||||||
success: function (data) {
|
|
||||||
if(data.new_version == 501){
|
|
||||||
jq("#update_script").attr("disabled", false);
|
|
||||||
jq("#update_script").val("无法获取新版本,请重试!");
|
|
||||||
}else if (data.new_version > <%= self.version %>) {
|
|
||||||
jq("#update_script").attr("disabled", false);
|
|
||||||
jq("#update_script").val(UPDATE_TEXT + " v" + data.new_version);
|
|
||||||
jq("#update_script").attr("data-version", data.new_version);
|
|
||||||
newVersion = data.new_version;
|
|
||||||
updateS();
|
|
||||||
} else {
|
|
||||||
updateS();
|
|
||||||
jq("#update_script").val(NEW_VERSION + " v" + data.new_version);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
qrcode = new QRCode(document.getElementById("qrcode"),
|
|
||||||
{
|
|
||||||
text: "sample",
|
|
||||||
correctLevel: QRCode.CorrectLevel.L
|
|
||||||
});
|
});
|
||||||
|
|
||||||
//获取二维码
|
}else{
|
||||||
|
btn.value = `${NEW_VERSION} v${d.new_version}`;
|
||||||
function get_code(){
|
|
||||||
let timeStamp = (new Date()).getTime()
|
|
||||||
jq.ajax({
|
|
||||||
url: QRCODE_URL+"?t="+timeStamp,
|
|
||||||
dataType: 'json',
|
|
||||||
error: function () {
|
|
||||||
alert("出错了请重试。")
|
|
||||||
},
|
|
||||||
success: function (data) {
|
|
||||||
jq("#qrcontainer").removeClass("hidden")
|
|
||||||
jq("#refresh_qrcode").addClass("hidden")
|
|
||||||
console.log(data.qrcode_url)
|
|
||||||
qrcode.clear();
|
|
||||||
qrcode.makeCode(data.qrcode_url);
|
|
||||||
checkLogin(data.check_url);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
//初始化二维码
|
||||||
|
(function(){
|
||||||
|
let cookieBtn = Array.prototype.slice.call(document.getElementsByClassName("cookie-button"));
|
||||||
|
try {
|
||||||
|
qrcode = new QRCode(document.getElementById("qrcode"),
|
||||||
|
{
|
||||||
|
text: "sample",
|
||||||
|
correctLevel: QRCode.CorrectLevel.L
|
||||||
|
});
|
||||||
|
cookieBtn.forEach(e => {
|
||||||
|
e.onclick = () => {
|
||||||
|
ckid = e.getAttribute("data-rel");
|
||||||
|
get_code();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
alert("网络离线状态无法使用二维码获取Cookie,请刷新后重试!")
|
||||||
|
cookieBtn.forEach(e => {
|
||||||
|
e.disabled = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}());
|
||||||
|
|
||||||
|
//获取二维码
|
||||||
|
function get_code(){
|
||||||
|
XHR.get(QRCODE_URL, null, (x,d) => {
|
||||||
|
document.getElementById("qrcontainer").classList.remove("hidden");
|
||||||
|
document.getElementById("refresh_qrcode").classList.add("hidden");
|
||||||
|
qrcode.clear();
|
||||||
|
qrcode.makeCode(d.qrcode_url);
|
||||||
|
checkLogin(d.check_url);
|
||||||
|
});
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
jq(".cookie-button").click(function(){
|
|
||||||
ckid = jq(this).attr("data-rel");
|
|
||||||
get_code()
|
|
||||||
return false;
|
|
||||||
})
|
|
||||||
|
|
||||||
jq('.refresh').click(get_code);
|
|
||||||
|
|
||||||
function checkLogin(check_url){
|
function checkLogin(check_url){
|
||||||
var timeId = setInterval(() => {
|
let cname = ckid == 1?"cookie":"cookie2"
|
||||||
let cname = ckid == 1?"cookie":"cookie2"
|
XHR.poll(3, CHECK_LOGIN_URL, { check_url: check_url, id: cname }, (x, d) => {
|
||||||
jq.post( CHECK_LOGIN_URL, { check_url:check_url,id: cname}, function( data ) {
|
if (d.error == 0) {
|
||||||
if (data.error == 0) {
|
XHR.halt();
|
||||||
clearInterval(timeId)
|
XHR._q = [];
|
||||||
jq("#qrcontainer").addClass("hidden")
|
document.getElementById("qrcontainer").classList.add("hidden");
|
||||||
jq("#refresh_qrcode").addClass("hidden")
|
document.getElementById("refresh_qrcode").classList.add("hidden");
|
||||||
let prefix_array = jq(".cbi-input-text").eq(0).attr("id").split(".");
|
let prefix_array = document.getElementsByClassName("cbi-input-text")[0].getAttribute("id").split(".")
|
||||||
prefix_array.pop()
|
prefix_array.pop()
|
||||||
let prefix = prefix_array.join(".")+".";
|
let id = `${prefix_array.join(".")}.${cname}`;
|
||||||
document.getElementById(prefix+cname).value =data.cookie
|
document.getElementById(id).value = d.cookie
|
||||||
} else if (data.error == 21 || data.error == 261) {
|
} else if (d.error == 21 || d.error == 261) {
|
||||||
clearInterval(timeId)
|
XHR.halt();
|
||||||
jq("#refresh_qrcode").removeClass("hidden")
|
XHR._q = [];
|
||||||
}
|
document.getElementById("refresh_qrcode").classList.remove("hidden");
|
||||||
}, "json");
|
}
|
||||||
}, 3000)
|
});
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
@ -0,0 +1 @@
|
|||||||
|
/usr/share/jd-dailybonus/CookieSet.json
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
京东多合一签到脚本
|
京东多合一签到脚本
|
||||||
|
|
||||||
更新时间: 2021.01.07 17:00 v1.90
|
更新时间: 2021.01.20 20:00 v1.91
|
||||||
有效接口: 40+
|
有效接口: 40+
|
||||||
脚本兼容: QuantumultX, Surge, Loon, JSBox, Node.js
|
脚本兼容: QuantumultX, Surge, Loon, JSBox, Node.js
|
||||||
电报频道: @NobyDa
|
电报频道: @NobyDa
|
||||||
@ -90,7 +90,7 @@ hostname = api.m.jd.com
|
|||||||
|
|
||||||
var LogDetails = false; //是否开启响应日志, true则开启
|
var LogDetails = false; //是否开启响应日志, true则开启
|
||||||
|
|
||||||
var stop = 0; //自定义延迟签到,单位毫秒. 默认分批并发无延迟. 延迟作用于每个签到接口, 如填入延迟则切换顺序签到(耗时较长), VPN重启或越狱用户建议填写1, Surge用户请注意在SurgeUI界面调整脚本超时
|
var stop = '0'; //自定义延迟签到, 单位毫秒. 默认分批并发无延迟; 该参数接受随机或指定延迟(例: '2000'则表示延迟2秒; '2000-5000'则表示延迟最小2秒,最大5秒内的随机延迟), 如填入延迟则切换顺序签到(耗时较长), Surge用户请注意在SurgeUI界面调整脚本超时; 注: 该参数Node.js或JSbox环境下已配置数据持久化, 留空(var stop = '')即可清除.
|
||||||
|
|
||||||
var DeleteCookie = false; //是否清除Cookie, true则开启.
|
var DeleteCookie = false; //是否清除Cookie, true则开启.
|
||||||
|
|
||||||
@ -121,7 +121,7 @@ async function all() {
|
|||||||
JingDongShake(stop), //京东摇一摇
|
JingDongShake(stop), //京东摇一摇
|
||||||
JDSecKilling(stop), //京东秒杀
|
JDSecKilling(stop), //京东秒杀
|
||||||
JRLuckyLottery(stop), //金融抽奖顶部签到
|
JRLuckyLottery(stop), //金融抽奖顶部签到
|
||||||
JingDongBuyCar(stop, '5fc3c1f2e91f46f09ab2b722e10d92bf'), //京东汽车
|
JingDongBuyCar(stop, '319fd268c5df469192d9420a2de4d8d2'), //京东汽车
|
||||||
JingRongDoll(stop, 'JRDoll', '京东金融-签壹', '4D25A6F482'),
|
JingRongDoll(stop, 'JRDoll', '京东金融-签壹', '4D25A6F482'),
|
||||||
JingRongDoll(stop, 'JRTwoDoll', '京东金融-签贰', '3A3E839252'),
|
JingRongDoll(stop, 'JRTwoDoll', '京东金融-签贰', '3A3E839252'),
|
||||||
JingRongDoll(stop, 'JRThreeDoll', '京东金融-签叁', '69F5EC743C'),
|
JingRongDoll(stop, 'JRThreeDoll', '京东金融-签叁', '69F5EC743C'),
|
||||||
@ -135,7 +135,6 @@ async function all() {
|
|||||||
JDUserSignPre(stop, 'JDBaby', '京东商城-母婴', '3BbAVGQPDd6vTyHYjmAutXrKAos6'), //京东母婴馆
|
JDUserSignPre(stop, 'JDBaby', '京东商城-母婴', '3BbAVGQPDd6vTyHYjmAutXrKAos6'), //京东母婴馆
|
||||||
JDUserSignPre(stop, 'JD3C', '京东商城-数码', '4SWjnZSCTHPYjE5T7j35rxxuMTb6'), //京东数码电器馆
|
JDUserSignPre(stop, 'JD3C', '京东商城-数码', '4SWjnZSCTHPYjE5T7j35rxxuMTb6'), //京东数码电器馆
|
||||||
// JDUserSignPre(stop, 'JDSubsidy', '京东晚市-补贴', 'xK148m4kWj5hBcTPuJUNNXH3AkJ'), //京东晚市补贴金
|
// JDUserSignPre(stop, 'JDSubsidy', '京东晚市-补贴', 'xK148m4kWj5hBcTPuJUNNXH3AkJ'), //京东晚市补贴金
|
||||||
// JDUserSignPre(stop, 'JDDrug', '京东商城-医药', '3tqTG5sF1xCUyC6vgEF5CLCxGn7w'), //京东医药馆
|
|
||||||
JDUserSignPre(stop, 'JDWomen', '京东商城-女装', 'DpSh7ma8JV7QAxSE2gJNro8Q2h9'), //京东女装馆
|
JDUserSignPre(stop, 'JDWomen', '京东商城-女装', 'DpSh7ma8JV7QAxSE2gJNro8Q2h9'), //京东女装馆
|
||||||
JDUserSignPre(stop, 'JDFineWine', '京东商城-酒饮', 'zGwAUzL3pVGjptBBGeYfpKjYdtX'), //京东酒饮馆
|
JDUserSignPre(stop, 'JDFineWine', '京东商城-酒饮', 'zGwAUzL3pVGjptBBGeYfpKjYdtX'), //京东酒饮馆
|
||||||
JDUserSignPre(stop, 'JDBook', '京东商城-图书', '3SC6rw5iBg66qrXPGmZMqFDwcyXi'), //京东图书
|
JDUserSignPre(stop, 'JDBook', '京东商城-图书', '3SC6rw5iBg66qrXPGmZMqFDwcyXi'), //京东图书
|
||||||
@ -146,10 +145,10 @@ async function all() {
|
|||||||
JDUserSignPre(stop, 'JDClothing', '京东商城-服饰', '4RBT3H9jmgYg1k2kBnHF8NAHm7m8'), //京东服饰
|
JDUserSignPre(stop, 'JDClothing', '京东商城-服饰', '4RBT3H9jmgYg1k2kBnHF8NAHm7m8'), //京东服饰
|
||||||
JDUserSignPre(stop, 'JDUnderwear', '京东商城-内衣', '4PgpL1xqPSW1sVXCJ3xopDbB1f69'), //京东内衣馆
|
JDUserSignPre(stop, 'JDUnderwear', '京东商城-内衣', '4PgpL1xqPSW1sVXCJ3xopDbB1f69'), //京东内衣馆
|
||||||
JDUserSignPre(stop, 'JDSuitcase', '京东商城-箱包', 'ZrH7gGAcEkY2gH8wXqyAPoQgk6t'), //京东箱包馆
|
JDUserSignPre(stop, 'JDSuitcase', '京东商城-箱包', 'ZrH7gGAcEkY2gH8wXqyAPoQgk6t'), //京东箱包馆
|
||||||
JDUserSignPre(stop, 'JDSchool', '京东商城-校园', '4812pn2PAcUyfNdWr7Cvpww5MCyW'), //京东校园
|
JDUserSignPre(stop, 'JDSchool', '京东商城-校园', '2QUxWHx5BSCNtnBDjtt5gZTq7zdZ'), //京东校园
|
||||||
JDUserSignPre(stop, 'JDHealth', '京东商城-健康', 'w2oeK5yLdHqHvwef7SMMy4PL8LF'), //京东健康
|
JDUserSignPre(stop, 'JDHealth', '京东商城-健康', 'w2oeK5yLdHqHvwef7SMMy4PL8LF'), //京东健康
|
||||||
// JDUserSignPre(stop, 'JDPet', '京东商城-宠物', '37ta5sh5ocrMZF3Fz5UMJbTsL42'), //京东宠物馆
|
// JDUserSignPre(stop, 'JDPet', '京东商城-宠物', '37ta5sh5ocrMZF3Fz5UMJbTsL42'), //京东宠物馆
|
||||||
// JDUserSignPre(stop, 'JDShand', '京东拍拍-二手', '3S28janPLYmtFxypu37AYAGgivfp'), //京东拍拍二手
|
JDUserSignPre(stop, 'JDShand', '京东拍拍-二手', '3S28janPLYmtFxypu37AYAGgivfp'), //京东拍拍二手
|
||||||
JDUserSignPre(stop, 'JDClean', '京东商城-清洁', '2Tjm6ay1ZbZ3v7UbriTj6kHy9dn6'), //京东清洁馆
|
JDUserSignPre(stop, 'JDClean', '京东商城-清洁', '2Tjm6ay1ZbZ3v7UbriTj6kHy9dn6'), //京东清洁馆
|
||||||
JDUserSignPre(stop, 'JDCare', '京东商城-个护', 'NJ1kd1PJWhwvhtim73VPsD1HwY3'), //京东个人护理馆
|
JDUserSignPre(stop, 'JDCare', '京东商城-个护', 'NJ1kd1PJWhwvhtim73VPsD1HwY3'), //京东个人护理馆
|
||||||
JDUserSignPre(stop, 'JDJewels', '京东商城-珠宝', 'zHUHpTHNTaztSRfNBFNVZscyFZU'), //京东珠宝馆
|
JDUserSignPre(stop, 'JDJewels', '京东商城-珠宝', 'zHUHpTHNTaztSRfNBFNVZscyFZU'), //京东珠宝馆
|
||||||
@ -161,53 +160,52 @@ async function all() {
|
|||||||
await JingRongDoll(stop, 'JDDouble', '金融京豆-双签', 'F68B2C3E71', '', '', '', 'jingdou'); //京东金融 京豆双签
|
await JingRongDoll(stop, 'JDDouble', '金融京豆-双签', 'F68B2C3E71', '', '', '', 'jingdou'); //京东金融 京豆双签
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
await JingDongBean(stop); //京东京豆
|
await JingDongBean(0); //京东京豆
|
||||||
await JingDongStore(stop); //京东超市
|
await JingDongStore(Wait(stop)); //京东超市
|
||||||
await JingDongWebcasts(stop); //京东直播
|
await JingDongWebcasts(Wait(stop)); //京东直播
|
||||||
await JingRongBean(stop); //金融简单赚钱
|
await JingRongBean(Wait(stop)); //金融简单赚钱
|
||||||
await JingRongSteel(stop); //金融钢镚
|
await JingRongSteel(Wait(stop)); //金融钢镚
|
||||||
await JingDongTurn(stop); //京东转盘
|
await JingDongTurn(Wait(stop)); //京东转盘
|
||||||
await JDFlashSale(stop); //京东闪购
|
await JDFlashSale(Wait(stop)); //京东闪购
|
||||||
await JingDongCash(stop); //京东现金红包
|
await JingDongCash(Wait(stop)); //京东现金红包
|
||||||
await JDMagicCube(stop, 2); //京东小魔方
|
await JDMagicCube(Wait(stop), 2); //京东小魔方
|
||||||
await JingDongGetCash(stop); //京东领现金
|
await JingDongGetCash(Wait(stop)); //京东领现金
|
||||||
await JingDongSubsidy(stop); //京东金贴
|
await JingDongSubsidy(Wait(stop)); //京东金贴
|
||||||
await JingDongShake(stop); //京东摇一摇
|
await JingDongShake(Wait(stop)); //京东摇一摇
|
||||||
await JDSecKilling(stop); //京东秒杀
|
await JDSecKilling(Wait(stop)); //京东秒杀
|
||||||
await JRLuckyLottery(stop); //金融抽奖顶部签到
|
await JRLuckyLottery(Wait(stop)); //金融抽奖顶部签到
|
||||||
await JingDongBuyCar(stop, '5fc3c1f2e91f46f09ab2b722e10d92bf'); //京东汽车
|
await JingDongBuyCar(Wait(stop), '319fd268c5df469192d9420a2de4d8d2'); //京东汽车
|
||||||
await JingRongDoll(stop, 'JRTwoDoll', '京东金融-签贰', '3A3E839252');
|
await JingRongDoll(Wait(stop), 'JRTwoDoll', '京东金融-签贰', '3A3E839252');
|
||||||
await JingRongDoll(stop, 'JRThreeDoll', '京东金融-签叁', '69F5EC743C');
|
await JingRongDoll(Wait(stop), 'JRThreeDoll', '京东金融-签叁', '69F5EC743C');
|
||||||
await JingRongDoll(stop, 'JRFourDoll', '京东金融-签肆', '30C4F86264');
|
await JingRongDoll(Wait(stop), 'JRFourDoll', '京东金融-签肆', '30C4F86264');
|
||||||
await JingRongDoll(stop, 'JRFiveDoll', '京东金融-签伍', '1D06AA3B0F');
|
await JingRongDoll(Wait(stop), 'JRFiveDoll', '京东金融-签伍', '1D06AA3B0F');
|
||||||
await JingRongDoll(stop, 'JRDoll', '京东金融-签壹', '4D25A6F482');
|
await JingRongDoll(Wait(stop), 'JRDoll', '京东金融-签壹', '4D25A6F482');
|
||||||
await JingRongDoll(stop, 'XJDouble', '金融现金-双签', 'F68B2C3E71', '', '', '', 'xianjin'); //京东金融 现金双签
|
await JingRongDoll(Wait(stop), 'XJDouble', '金融现金-双签', 'F68B2C3E71', '', '', '', 'xianjin'); //京东金融 现金双签
|
||||||
await JingRongDoll(stop, 'JTDouble', '京东金贴-双签', '1DF13833F7'); //京东金融 金贴双签
|
await JingRongDoll(Wait(stop), 'JTDouble', '京东金贴-双签', '1DF13833F7'); //京东金融 金贴双签
|
||||||
await JDUserSignPre(stop, 'JDUnderwear', '京东商城-内衣', '4PgpL1xqPSW1sVXCJ3xopDbB1f69'); //京东内衣馆
|
await JDUserSignPre(Wait(stop), 'JDUnderwear', '京东商城-内衣', '4PgpL1xqPSW1sVXCJ3xopDbB1f69'); //京东内衣馆
|
||||||
await JDUserSignPre(stop, 'JDSuitcase', '京东商城-箱包', 'ZrH7gGAcEkY2gH8wXqyAPoQgk6t'); //京东箱包馆
|
await JDUserSignPre(Wait(stop), 'JDSuitcase', '京东商城-箱包', 'ZrH7gGAcEkY2gH8wXqyAPoQgk6t'); //京东箱包馆
|
||||||
await JDUserSignPre(stop, 'JDClothing', '京东商城-服饰', '4RBT3H9jmgYg1k2kBnHF8NAHm7m8'); //京东服饰
|
await JDUserSignPre(Wait(stop), 'JDClothing', '京东商城-服饰', '4RBT3H9jmgYg1k2kBnHF8NAHm7m8'); //京东服饰
|
||||||
await JDUserSignPre(stop, 'JDSchool', '京东商城-校园', '4812pn2PAcUyfNdWr7Cvpww5MCyW'); //京东校园
|
await JDUserSignPre(Wait(stop), 'JDSchool', '京东商城-校园', '2QUxWHx5BSCNtnBDjtt5gZTq7zdZ'); //京东校园
|
||||||
await JDUserSignPre(stop, 'JDHealth', '京东商城-健康', 'w2oeK5yLdHqHvwef7SMMy4PL8LF'); //京东健康
|
await JDUserSignPre(Wait(stop), 'JDHealth', '京东商城-健康', 'w2oeK5yLdHqHvwef7SMMy4PL8LF'); //京东健康
|
||||||
await JDUserSignPre(stop, 'JDShoes', '京东商城-鞋靴', '4RXyb1W4Y986LJW8ToqMK14BdTD'); //京东鞋靴
|
await JDUserSignPre(Wait(stop), 'JDShoes', '京东商城-鞋靴', '4RXyb1W4Y986LJW8ToqMK14BdTD'); //京东鞋靴
|
||||||
await JDUserSignPre(stop, 'JDCalendar', '京东日历-翻牌', '36V2Qw59VPNsuLxY84vCFtxFzrFs'); //京东日历翻牌
|
await JDUserSignPre(Wait(stop), 'JDCalendar', '京东日历-翻牌', '36V2Qw59VPNsuLxY84vCFtxFzrFs'); //京东日历翻牌
|
||||||
await JDUserSignPre(stop, 'JDChild', '京东商城-童装', '3Af6mZNcf5m795T8dtDVfDwWVNhJ'); //京东童装馆
|
await JDUserSignPre(Wait(stop), 'JDChild', '京东商城-童装', '3Af6mZNcf5m795T8dtDVfDwWVNhJ'); //京东童装馆
|
||||||
await JDUserSignPre(stop, 'JDBaby', '京东商城-母婴', '3BbAVGQPDd6vTyHYjmAutXrKAos6'); //京东母婴馆
|
await JDUserSignPre(Wait(stop), 'JDBaby', '京东商城-母婴', '3BbAVGQPDd6vTyHYjmAutXrKAos6'); //京东母婴馆
|
||||||
await JDUserSignPre(stop, 'JD3C', '京东商城-数码', '4SWjnZSCTHPYjE5T7j35rxxuMTb6'); //京东数码电器馆
|
await JDUserSignPre(Wait(stop), 'JD3C', '京东商城-数码', '4SWjnZSCTHPYjE5T7j35rxxuMTb6'); //京东数码电器馆
|
||||||
// await JDUserSignPre(stop, 'JDSubsidy', '京东晚市-补贴', 'xK148m4kWj5hBcTPuJUNNXH3AkJ'); //京东晚市补贴金
|
// await JDUserSignPre(Wait(stop), 'JDSubsidy', '京东晚市-补贴', 'xK148m4kWj5hBcTPuJUNNXH3AkJ'); //京东晚市补贴金
|
||||||
// await JDUserSignPre(stop, 'JDClocks', '京东商城-钟表', '2BcJPCVVzMEtMUynXkPscCSsx68W'); //京东钟表馆
|
// await JDUserSignPre(Wait(stop), 'JDClocks', '京东商城-钟表', '2BcJPCVVzMEtMUynXkPscCSsx68W'); //京东钟表馆
|
||||||
// await JDUserSignPre(stop, 'JDDrug', '京东商城-医药', '3tqTG5sF1xCUyC6vgEF5CLCxGn7w'); //京东医药馆
|
await JDUserSignPre(Wait(stop), 'JDWomen', '京东商城-女装', 'DpSh7ma8JV7QAxSE2gJNro8Q2h9'); //京东女装馆
|
||||||
await JDUserSignPre(stop, 'JDWomen', '京东商城-女装', 'DpSh7ma8JV7QAxSE2gJNro8Q2h9'); //京东女装馆
|
// await JDUserSignPre(Wait(stop), 'JDPet', '京东商城-宠物', '37ta5sh5ocrMZF3Fz5UMJbTsL42'); //京东宠物馆
|
||||||
// await JDUserSignPre(stop, 'JDPet', '京东商城-宠物', '37ta5sh5ocrMZF3Fz5UMJbTsL42'); //京东宠物馆
|
await JDUserSignPre(Wait(stop), 'JDBook', '京东商城-图书', '3SC6rw5iBg66qrXPGmZMqFDwcyXi'); //京东图书
|
||||||
await JDUserSignPre(stop, 'JDBook', '京东商城-图书', '3SC6rw5iBg66qrXPGmZMqFDwcyXi'); //京东图书
|
await JDUserSignPre(Wait(stop), 'JDShand', '京东拍拍-二手', '3S28janPLYmtFxypu37AYAGgivfp'); //京东拍拍二手
|
||||||
// await JDUserSignPre(stop, 'JDShand', '京东拍拍-二手', '3S28janPLYmtFxypu37AYAGgivfp'); //京东拍拍二手
|
await JDUserSignPre(Wait(stop), 'JDMakeup', '京东商城-美妆', '2smCxzLNuam5L14zNJHYu43ovbAP'); //京东美妆馆
|
||||||
await JDUserSignPre(stop, 'JDMakeup', '京东商城-美妆', '2smCxzLNuam5L14zNJHYu43ovbAP'); //京东美妆馆
|
await JDUserSignPre(Wait(stop), 'JDFineWine', '京东商城-酒饮', 'zGwAUzL3pVGjptBBGeYfpKjYdtX'); //京东酒饮馆
|
||||||
await JDUserSignPre(stop, 'JDFineWine', '京东商城-酒饮', 'zGwAUzL3pVGjptBBGeYfpKjYdtX'); //京东酒饮馆
|
await JDUserSignPre(Wait(stop), 'JDVege', '京东商城-菜场', 'Wcu2LVCFMkBP3HraRvb7pgSpt64'); //京东菜场
|
||||||
await JDUserSignPre(stop, 'JDVege', '京东商城-菜场', 'Wcu2LVCFMkBP3HraRvb7pgSpt64'); //京东菜场
|
await JDUserSignPre(Wait(stop), 'JDClean', '京东商城-清洁', '2Tjm6ay1ZbZ3v7UbriTj6kHy9dn6'); //京东清洁馆
|
||||||
await JDUserSignPre(stop, 'JDClean', '京东商城-清洁', '2Tjm6ay1ZbZ3v7UbriTj6kHy9dn6'); //京东清洁馆
|
await JDUserSignPre(Wait(stop), 'JDCare', '京东商城-个护', 'NJ1kd1PJWhwvhtim73VPsD1HwY3'); //京东个人护理馆
|
||||||
await JDUserSignPre(stop, 'JDCare', '京东商城-个护', 'NJ1kd1PJWhwvhtim73VPsD1HwY3'); //京东个人护理馆
|
await JDUserSignPre(Wait(stop), 'JDJewels', '京东商城-珠宝', 'zHUHpTHNTaztSRfNBFNVZscyFZU'); //京东珠宝馆
|
||||||
await JDUserSignPre(stop, 'JDJewels', '京东商城-珠宝', 'zHUHpTHNTaztSRfNBFNVZscyFZU'); //京东珠宝馆
|
await JingRongDoll(Wait(stop), 'JDDouble', '金融京豆-双签', 'F68B2C3E71', '', '', '', 'jingdou'); //京东金融 京豆双签
|
||||||
await JingRongDoll(stop, 'JDDouble', '金融京豆-双签', 'F68B2C3E71', '', '', '', 'jingdou'); //京东金融 京豆双签
|
await JingDongSpeedUp(Wait(stop)); //京东天天加速
|
||||||
await JingDongSpeedUp(stop); //京东天天加速
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
@ -316,11 +314,12 @@ function ReadCookie() {
|
|||||||
if ($nobyda.isJSBox || $nobyda.isNode) {
|
if ($nobyda.isJSBox || $nobyda.isNode) {
|
||||||
if (Key) $nobyda.write(Key, EnvInfo);
|
if (Key) $nobyda.write(Key, EnvInfo);
|
||||||
if (DualKey) $nobyda.write(DualKey, EnvInfo2);
|
if (DualKey) $nobyda.write(DualKey, EnvInfo2);
|
||||||
|
if (stop !== '0') $nobyda.write(stop, "JD_DailyBonusDelay");
|
||||||
}
|
}
|
||||||
add = DualKey || $nobyda.read(EnvInfo2) ? true : false
|
add = DualKey || $nobyda.read(EnvInfo2) ? true : false
|
||||||
KEY = Key ? Key : $nobyda.read(EnvInfo)
|
KEY = Key ? Key : $nobyda.read(EnvInfo)
|
||||||
out = parseInt($nobyda.read("JD_DailyBonusTimeOut")) || out
|
out = parseInt($nobyda.read("JD_DailyBonusTimeOut")) || out
|
||||||
stop = parseInt($nobyda.read("JD_DailyBonusDelay")) || stop
|
stop = Wait($nobyda.read("JD_DailyBonusDelay"), true) || Wait(stop, true)
|
||||||
boxdis = $nobyda.read("JD_Crash_disable") === "false" || $nobyda.isNode || $nobyda.isJSBox ? false : boxdis
|
boxdis = $nobyda.read("JD_Crash_disable") === "false" || $nobyda.isNode || $nobyda.isJSBox ? false : boxdis
|
||||||
LogDetails = $nobyda.read("JD_DailyBonusLog") === "true" || LogDetails
|
LogDetails = $nobyda.read("JD_DailyBonusLog") === "true" || LogDetails
|
||||||
ReDis = ReDis ? $nobyda.write("", "JD_DailyBonusDisables") : ""
|
ReDis = ReDis ? $nobyda.write("", "JD_DailyBonusDisables") : ""
|
||||||
@ -2189,6 +2188,21 @@ function disable(Val, name, way) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function Wait(readDelay, ini) {
|
||||||
|
if (!readDelay || readDelay === '0') return 0
|
||||||
|
if (typeof(readDelay) == 'string') {
|
||||||
|
var readDelay = readDelay.replace(/"|"|'|'/g, ''); //prevent novice
|
||||||
|
if (readDelay.indexOf('-') == -1) return parseInt(readDelay) || 0;
|
||||||
|
const raw = readDelay.split("-").map(Number);
|
||||||
|
const plan = parseInt(Math.random() * (raw[1] - raw[0] + 1) + raw[0], 10);
|
||||||
|
if (ini) console.log(`\n初始化随机延迟: 最小${raw[0]/1000}秒, 最大${raw[1]/1000}秒`);
|
||||||
|
// else console.log(`\n预计等待: ${(plan / 1000).toFixed(2)}秒`);
|
||||||
|
return ini ? readDelay : plan
|
||||||
|
} else if (typeof(readDelay) == 'number') {
|
||||||
|
return readDelay > 0 ? readDelay : 0
|
||||||
|
} else return 0
|
||||||
|
}
|
||||||
|
|
||||||
function GetCookie() {
|
function GetCookie() {
|
||||||
try {
|
try {
|
||||||
if ($request.headers && $request.url.match(/api\.m\.jd\.com.*=signBean/)) {
|
if ($request.headers && $request.url.match(/api\.m\.jd\.com.*=signBean/)) {
|
||||||
|
@ -0,0 +1,19 @@
|
|||||||
|
#!/usr/bin/lua
|
||||||
|
local uci = require "luci.model.uci".cursor()
|
||||||
|
local json = require 'luci.jsonc'
|
||||||
|
|
||||||
|
function write_json(file, content)
|
||||||
|
local json = require 'luci.jsonc'
|
||||||
|
local f = assert(io.open(file, 'w'))
|
||||||
|
f:write(json.stringify(content, 1))
|
||||||
|
f:close()
|
||||||
|
end
|
||||||
|
|
||||||
|
local data = {
|
||||||
|
CookieJD = uci:get('jd-dailybonus', '@global[0]', 'cookie'),
|
||||||
|
CookieJD2 = uci:get('jd-dailybonus', '@global[0]', 'cookie2'),
|
||||||
|
JD_DailyBonusDelay = uci:get('jd-dailybonus', '@global[0]', 'stop'),
|
||||||
|
JD_DailyBonusTimeOut = uci:get('jd-dailybonus', '@global[0]', 'out')
|
||||||
|
}
|
||||||
|
|
||||||
|
write_json('/usr/share/jd-dailybonus/CookieSet.json', data)
|
@ -1,168 +0,0 @@
|
|||||||
-- Copyright (C) 2021 jerrykuku <jerrykuku@gmail.com>
|
|
||||||
-- Licensed to the public under the GNU General Public License v3.
|
|
||||||
|
|
||||||
local uci = require 'luci.model.uci'.cursor()
|
|
||||||
local config = 'jd-dailybonus'
|
|
||||||
package.path = package.path .. ';/usr/share/jd-dailybonus/?.lua'
|
|
||||||
local requests = require 'requests'
|
|
||||||
local socket = require 'socket'
|
|
||||||
local tinsert = table.insert
|
|
||||||
local ssub, slen, schar, sbyte, sformat, sgsub = string.sub, string.len, string.char, string.byte, string.format, string.gsub
|
|
||||||
local User_Agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36'
|
|
||||||
local Host = 'plogin.m.jd.com'
|
|
||||||
local jd_cookie = {}
|
|
||||||
|
|
||||||
--打印table
|
|
||||||
function print_r(t)
|
|
||||||
local print_r_cache = {}
|
|
||||||
local function sub_print_r(t, indent)
|
|
||||||
if (print_r_cache[tostring(t)]) then
|
|
||||||
print(indent .. '*' .. tostring(t))
|
|
||||||
else
|
|
||||||
print_r_cache[tostring(t)] = true
|
|
||||||
if (type(t) == 'table') then
|
|
||||||
for pos, val in pairs(t) do
|
|
||||||
if (type(val) == 'table') then
|
|
||||||
print(indent .. '[' .. pos .. '] => ' .. tostring(t) .. ' {')
|
|
||||||
sub_print_r(val, indent .. string.rep(' ', string.len(pos) + 8))
|
|
||||||
print(indent .. string.rep(' ', string.len(pos) + 6) .. '}')
|
|
||||||
elseif (type(val) == 'string') then
|
|
||||||
print(indent .. '[' .. pos .. '] => "' .. val .. '"')
|
|
||||||
else
|
|
||||||
print(indent .. '[' .. pos .. '] => ' .. tostring(val))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
print(indent .. tostring(t))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if (type(t) == 'table') then
|
|
||||||
print(tostring(t) .. ' {')
|
|
||||||
sub_print_r(t, ' ')
|
|
||||||
print('}')
|
|
||||||
else
|
|
||||||
sub_print_r(t, ' ')
|
|
||||||
end
|
|
||||||
print()
|
|
||||||
end
|
|
||||||
|
|
||||||
-- 分割字符串
|
|
||||||
local function split(full, sep)
|
|
||||||
full = full:gsub('%z', '') -- 这里不是很清楚 有时候结尾带个\0
|
|
||||||
local off, result = 1, {}
|
|
||||||
while true do
|
|
||||||
local nStart, nEnd = full:find(sep, off)
|
|
||||||
if not nEnd then
|
|
||||||
local res = ssub(full, off, slen(full))
|
|
||||||
if #res > 0 then -- 过滤掉 \0
|
|
||||||
tinsert(result, res)
|
|
||||||
end
|
|
||||||
break
|
|
||||||
else
|
|
||||||
tinsert(result, ssub(full, off, nStart - 1))
|
|
||||||
off = nEnd + 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return result
|
|
||||||
end
|
|
||||||
|
|
||||||
--获取unix时间戳
|
|
||||||
function jd_cookie.timestamp()
|
|
||||||
return math.floor(socket.gettime() * 1000)
|
|
||||||
end
|
|
||||||
|
|
||||||
--延时函数
|
|
||||||
function sleep(n)
|
|
||||||
os.execute('sleep ' .. n)
|
|
||||||
end
|
|
||||||
|
|
||||||
--解析cookie
|
|
||||||
function praseSetCookies(rcookie)
|
|
||||||
local tbl = {}
|
|
||||||
for k, v in rcookie:gmatch('([^;%s]+)=([^;]+)') do
|
|
||||||
tbl[k] = v
|
|
||||||
end
|
|
||||||
return tbl
|
|
||||||
end
|
|
||||||
|
|
||||||
--获取二维码链接和检测URL
|
|
||||||
function jd_cookie.get_qrcode()
|
|
||||||
local timeStamp = jd_cookie.timestamp()
|
|
||||||
local url =
|
|
||||||
'https://plogin.m.jd.com/cgi-bin/mm/new_login_entrance?lang=chs&appid=300&returnurl=https://wq.jd.com/passport/LoginRedirect?state=' ..
|
|
||||||
timeStamp .. '&returnurl=https://home.m.jd.com/myJd/newhome.action?sceneval=2&ufc=&/myJd/home.action&source=wq_passport'
|
|
||||||
local xformHeaders = {
|
|
||||||
['Content-Type'] = 'application/x-www-form-urlencoded',
|
|
||||||
['Connection'] = 'Keep-Alive',
|
|
||||||
['Accept'] = 'application/json, text/plain, */*',
|
|
||||||
['Accept-Language'] = 'zh-cn',
|
|
||||||
['Referer'] = 'https://plogin.m.jd.com/login/login?appid=300&returnurl=https://wq.jd.com/passport/LoginRedirect?state=' ..
|
|
||||||
timeStamp .. '&returnurl=https://home.m.jd.com/myJd/newhome.action?sceneval=2&ufc=&/myJd/home.action&source=wq_passport',
|
|
||||||
['User-Agent'] = User_Agent,
|
|
||||||
['Host'] = Host
|
|
||||||
}
|
|
||||||
local response = requests.get {url, headers = xformHeaders}
|
|
||||||
local s_token = response.json().s_token
|
|
||||||
local dat = split(string.gsub(response.headers['set-cookie'], ' DOMAIN=.plogin.m.jd.com', ''), ';')
|
|
||||||
local cookies = string.gsub(dat[1] .. dat[4] .. dat[6] .. dat[8], ',', ';') .. ';'
|
|
||||||
|
|
||||||
local timeStamp = jd_cookie.timestamp()
|
|
||||||
local url = 'https://plogin.m.jd.com/cgi-bin/m/tmauthreflogurl?s_token=' .. s_token .. '&v=' .. timeStamp .. '&remember=true'
|
|
||||||
local xformHeaders = {
|
|
||||||
['Content-Type'] = 'application/x-www-form-urlencoded',
|
|
||||||
['Connection'] = 'Keep-Alive',
|
|
||||||
['Accept'] = 'application/json, text/plain, */*',
|
|
||||||
['Accept-Language'] = 'zh-cn',
|
|
||||||
['Referer'] = 'https://plogin.m.jd.com/login/login?appid=300&returnurl=https://wq.jd.com/passport/LoginRedirect?state=' ..
|
|
||||||
timeStamp .. '&returnurl=https://home.m.jd.com/myJd/newhome.action?sceneval=2&ufc=&/myJd/home.action&source=wq_passport',
|
|
||||||
['User-Agent'] = User_Agent,
|
|
||||||
['Host'] = Host
|
|
||||||
}
|
|
||||||
local response = requests.post {url, cookies = cookies, headers = xformHeaders}
|
|
||||||
local json_body, error = response.json()
|
|
||||||
local token = json_body['token']
|
|
||||||
local ou_state = json_body['ou_state']
|
|
||||||
local okl_token = praseSetCookies(response.headers['set-cookie']).okl_token
|
|
||||||
local return_json = {
|
|
||||||
qrcode_url = 'https://plogin.m.jd.com/cgi-bin/m/tmauth?appid=300&client_type=m&token=' .. token,
|
|
||||||
check_url = 'https://plogin.m.jd.com/cgi-bin/m/tmauthchecktoken?&token=' .. token .. '&ou_state=' .. ou_state .. '&okl_token=' .. okl_token,
|
|
||||||
cookies = cookies
|
|
||||||
}
|
|
||||||
return return_json
|
|
||||||
end
|
|
||||||
|
|
||||||
--检测扫码状态 并返回cookie
|
|
||||||
function jd_cookie.checkLogin(url, cookies)
|
|
||||||
local xformHeaders = {
|
|
||||||
['Content-Type'] = 'application/x-www-form-urlencoded',
|
|
||||||
['Connection'] = 'Keep-Alive',
|
|
||||||
['Accept'] = 'application/json, text/plain, */*',
|
|
||||||
['Accept-Language'] = 'zh-cn',
|
|
||||||
['Referer'] = 'https://plogin.m.jd.com/login/login?appid=300&returnurl=https://wqlogin2.jd.com/passport/LoginRedirect?state=',
|
|
||||||
['User-Agent'] = User_Agent,
|
|
||||||
['Host'] = Host
|
|
||||||
}
|
|
||||||
local data =
|
|
||||||
'lang=chs&appid=300&source=wq_passport&returnurl=https://wqlogin2.jd.com/passport/LoginRedirect?state=1100399130787&returnurl=//home.m.jd.com/myJd/newhome.action?sceneval=2&ufc=&/myJd/home.action'
|
|
||||||
local response = requests.post {url, data = data, cookies = cookies, headers = xformHeaders}
|
|
||||||
--local cookie = jd_cookie.praseSetCookies(response.headers['set-cookie'])
|
|
||||||
local json = response.json()
|
|
||||||
local return_json = {}
|
|
||||||
if json.errcode == 0 then
|
|
||||||
local ucookie = praseSetCookies(response.headers['set-cookie'])
|
|
||||||
return_json = {
|
|
||||||
error = 0,
|
|
||||||
cookie = ucookie
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return_json = {
|
|
||||||
error = json.errcode,
|
|
||||||
msg = json.message
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
return return_json
|
|
||||||
end
|
|
||||||
|
|
||||||
return jd_cookie
|
|
@ -97,10 +97,11 @@ notify() {
|
|||||||
run() {
|
run() {
|
||||||
echo -e $(date '+%Y-%m-%d %H:%M:%S %A') >$LOG_HTM 2>/dev/null
|
echo -e $(date '+%Y-%m-%d %H:%M:%S %A') >$LOG_HTM 2>/dev/null
|
||||||
[ ! -f "/usr/bin/node" ] && echo -e "未安装node.js,请安装后再试!\nNode.js is not installed, please try again after installation!" >>$LOG_HTM && exit 1
|
[ ! -f "/usr/bin/node" ] && echo -e "未安装node.js,请安装后再试!\nNode.js is not installed, please try again after installation!" >>$LOG_HTM && exit 1
|
||||||
node $JD_SCRIPT >>$LOG_HTM 2>/dev/null && notify &
|
(cd /usr/share/jd-dailybonus/ && node $JD_SCRIPT >>$LOG_HTM 2>/dev/null && notify &)
|
||||||
}
|
}
|
||||||
|
|
||||||
save() {
|
save() {
|
||||||
|
lua /usr/share/jd-dailybonus/gen_cookieset.lua
|
||||||
add_cron
|
add_cron
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,303 +0,0 @@
|
|||||||
-- Lua Requests library for http ease
|
|
||||||
|
|
||||||
local http_socket = require('socket.http')
|
|
||||||
local https_socket = require('ssl.https')
|
|
||||||
local url_parser = require('socket.url')
|
|
||||||
local ltn12 = require('ltn12')
|
|
||||||
local json = require('cjson.safe')
|
|
||||||
local md5sum = require('md5') -- TODO: Make modular?
|
|
||||||
local mime = require('mime')
|
|
||||||
|
|
||||||
local requests = {
|
|
||||||
_DESCRIPTION = 'Http requests made simpler',
|
|
||||||
http_socket = http_socket,
|
|
||||||
https_socket = https_socket
|
|
||||||
}
|
|
||||||
|
|
||||||
local _requests = {}
|
|
||||||
|
|
||||||
--User facing function the make a request use Digest Authentication
|
|
||||||
--TODO: Determine what else should live in authentication
|
|
||||||
function requests.HTTPDigestAuth(user, password)
|
|
||||||
return { _type = 'digest', user = user, password = password}
|
|
||||||
end
|
|
||||||
|
|
||||||
--User facing function the make a request use Basic Authentication
|
|
||||||
--TODO: Determine what else should live in authentication
|
|
||||||
function requests.HTTPBasicAuth(user, password)
|
|
||||||
return { _type = 'basic', user = user, password = password}
|
|
||||||
end
|
|
||||||
|
|
||||||
function requests.post(url, args)
|
|
||||||
return requests.request("POST", url, args)
|
|
||||||
end
|
|
||||||
|
|
||||||
function requests.get(url, args)
|
|
||||||
return requests.request("GET", url, args)
|
|
||||||
end
|
|
||||||
|
|
||||||
function requests.delete(url, args)
|
|
||||||
return requests.request("DELETE", url, args)
|
|
||||||
end
|
|
||||||
|
|
||||||
function requests.patch(url, args)
|
|
||||||
return requests.request("PATCH", url, args)
|
|
||||||
end
|
|
||||||
|
|
||||||
function requests.put(url, args)
|
|
||||||
return requests.request("PUT", url, args)
|
|
||||||
end
|
|
||||||
|
|
||||||
function requests.options(url, args)
|
|
||||||
return requests.request("OPTIONS", url, args)
|
|
||||||
end
|
|
||||||
|
|
||||||
function requests.head(url, args)
|
|
||||||
return requests.request("HEAD", url, args)
|
|
||||||
end
|
|
||||||
|
|
||||||
function requests.trace(url, args)
|
|
||||||
return requests.request("TRACE", url, args)
|
|
||||||
end
|
|
||||||
|
|
||||||
--Sets up all the data for a request and makes the request
|
|
||||||
function requests.request(method, url, args)
|
|
||||||
local request
|
|
||||||
|
|
||||||
if type(url) == "table" then
|
|
||||||
request = url
|
|
||||||
if not request.url and request[1] then
|
|
||||||
request.url = table.remove(request, 1)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
request = args or {}
|
|
||||||
request.url = url
|
|
||||||
end
|
|
||||||
|
|
||||||
request.method = method
|
|
||||||
_requests.parse_args(request)
|
|
||||||
|
|
||||||
-- TODO: Find a better way to do this
|
|
||||||
if request.auth and request.auth._type == 'digest' then
|
|
||||||
local response = _requests.make_request(request)
|
|
||||||
return _requests.use_digest(response, request)
|
|
||||||
else
|
|
||||||
return _requests.make_request(request)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
--Makes a request
|
|
||||||
function _requests.make_request(request)
|
|
||||||
local response_body = {}
|
|
||||||
local full_request = {
|
|
||||||
method = request.method,
|
|
||||||
url = request.url,
|
|
||||||
headers = request.headers,
|
|
||||||
sink = ltn12.sink.table(response_body),
|
|
||||||
redirect = request.allow_redirects,
|
|
||||||
proxy = request.proxy
|
|
||||||
}
|
|
||||||
if request.data then
|
|
||||||
full_request.source = ltn12.source.string(request.data)
|
|
||||||
end
|
|
||||||
|
|
||||||
local response = {}
|
|
||||||
local ok
|
|
||||||
local socket = string.find(full_request.url, '^https:') and not request.proxy and https_socket or http_socket
|
|
||||||
|
|
||||||
ok, response.status_code, response.headers, response.status = socket.request(full_request)
|
|
||||||
|
|
||||||
assert(ok, 'error in '..request.method..' request: '..response.status_code)
|
|
||||||
response.text = table.concat(response_body)
|
|
||||||
response.json = function () return json.decode(response.text) end
|
|
||||||
|
|
||||||
return response
|
|
||||||
end
|
|
||||||
|
|
||||||
--Parses through all the possible arguments for a request
|
|
||||||
function _requests.parse_args(request)
|
|
||||||
_requests.check_url(request)
|
|
||||||
_requests.check_data(request)
|
|
||||||
_requests.create_header(request)
|
|
||||||
_requests.check_timeout(request.timeout)
|
|
||||||
_requests.check_redirect(request.allow_redirects)
|
|
||||||
end
|
|
||||||
|
|
||||||
--Format the the url based on the params argument
|
|
||||||
function _requests.format_params(url, params) -- TODO: Clean
|
|
||||||
if not params or next(params) == nil then return url end
|
|
||||||
|
|
||||||
url = url..'?'
|
|
||||||
for key, value in pairs(params) do
|
|
||||||
if tostring(value) then
|
|
||||||
url = url..tostring(key)..'='
|
|
||||||
|
|
||||||
if type(value) == 'table' then
|
|
||||||
local val_string = ''
|
|
||||||
|
|
||||||
for _, val in ipairs(value) do
|
|
||||||
val_string = val_string..tostring(val)..','
|
|
||||||
end
|
|
||||||
|
|
||||||
url = url..val_string:sub(0, -2)
|
|
||||||
else
|
|
||||||
url = url..tostring(value)
|
|
||||||
end
|
|
||||||
|
|
||||||
url = url..'&'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return url:sub(0, -2)
|
|
||||||
end
|
|
||||||
|
|
||||||
--Check that there is a URL given and append to it if params are passed in.
|
|
||||||
function _requests.check_url(request)
|
|
||||||
assert(request.url, 'No url specified for request')
|
|
||||||
request.url = _requests.format_params(request.url, request.params)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Add to the HTTP header
|
|
||||||
function _requests.create_header(request)
|
|
||||||
request.headers = request.headers or {}
|
|
||||||
if request.data then
|
|
||||||
request.headers['Content-Length'] = request.data:len()
|
|
||||||
end
|
|
||||||
|
|
||||||
if request.cookies then
|
|
||||||
if request.headers.cookie then
|
|
||||||
request.headers.cookie = request.headers.cookie..'; '..request.cookies
|
|
||||||
else
|
|
||||||
request.headers.cookie = request.cookies
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if request.auth then
|
|
||||||
_requests.add_auth_headers(request)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
--Makes sure that the data is in a format that can be sent
|
|
||||||
function _requests.check_data(request)
|
|
||||||
if type(request.data) == "table" then
|
|
||||||
request.data = json.encode(request.data)
|
|
||||||
elseif request.data then
|
|
||||||
request.data = tostring(request.data)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
--Set the timeout
|
|
||||||
function _requests.check_timeout(timeout)
|
|
||||||
http_socket.TIMEOUT = timeout or 5
|
|
||||||
https_socket.TIMEOUT = timeout or 5
|
|
||||||
end
|
|
||||||
|
|
||||||
--Checks is allow_redirects parameter is set correctly
|
|
||||||
function _requests.check_redirect(allow_redirects)
|
|
||||||
if allow_redirects and type(allow_redirects) ~= "boolean" then
|
|
||||||
error("allow_redirects expects a boolean value. received type = "..type(allow_redirects))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
--Create the Authorization header for Basic Auth
|
|
||||||
function _requests.basic_auth_header(request)
|
|
||||||
local encoded = mime.b64(request.auth.user..':'..request.auth.password)
|
|
||||||
request.headers.Authorization = 'Basic '..encoded
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Create digest authorization string for request header TODO: Could be better, but it should work
|
|
||||||
function _requests.digest_create_header_string(auth)
|
|
||||||
local authorization = 'Digest username="'..auth.user..'", realm="'..auth.realm..'", nonce="'..auth.nonce
|
|
||||||
authorization = authorization..'", uri="'..auth.uri..'", qop='..auth.qop..', nc='..auth.nc
|
|
||||||
authorization = authorization..', cnonce="'..auth.cnonce..'", response="'..auth.response..'"'
|
|
||||||
|
|
||||||
if auth.opaque then
|
|
||||||
authorization = authorization..', opaque="'..auth.opaque..'"'
|
|
||||||
end
|
|
||||||
|
|
||||||
return authorization
|
|
||||||
end
|
|
||||||
|
|
||||||
--MD5 hash all parameters
|
|
||||||
local function md5_hash(...)
|
|
||||||
return md5sum.sumhexa(table.concat({...}, ":"))
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Creates response hash TODO: Add functionality
|
|
||||||
function _requests.digest_hash_response(auth_table)
|
|
||||||
return md5_hash(
|
|
||||||
md5_hash(auth_table.user, auth_table.realm, auth_table.password),
|
|
||||||
auth_table.nonce,
|
|
||||||
auth_table.nc,
|
|
||||||
auth_table.cnonce,
|
|
||||||
auth_table.qop,
|
|
||||||
md5_hash(auth_table.method, auth_table.uri)
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Add digest authentication to the request header
|
|
||||||
function _requests.digest_auth_header(request)
|
|
||||||
if not request.auth.nonce then return end
|
|
||||||
|
|
||||||
request.auth.cnonce = request.auth.cnonce or string.format("%08x", os.time())
|
|
||||||
|
|
||||||
request.auth.nc_count = request.auth.nc_count or 0
|
|
||||||
request.auth.nc_count = request.auth.nc_count + 1
|
|
||||||
|
|
||||||
request.auth.nc = string.format("%08x", request.auth.nc_count)
|
|
||||||
|
|
||||||
local url = url_parser.parse(request.url)
|
|
||||||
request.auth.uri = url_parser.build{path = url.path, query = url.query}
|
|
||||||
request.auth.method = request.method
|
|
||||||
request.auth.qop = 'auth'
|
|
||||||
|
|
||||||
request.auth.response = _requests.digest_hash_response(request.auth)
|
|
||||||
|
|
||||||
request.headers.Authorization = _requests.digest_create_header_string(request.auth)
|
|
||||||
end
|
|
||||||
|
|
||||||
--Checks the resonse code and adds additional headers for Digest Auth
|
|
||||||
-- TODO: Rename this
|
|
||||||
function _requests.use_digest(response, request)
|
|
||||||
if response.status_code == 401 then
|
|
||||||
_requests.parse_digest_response_header(response,request)
|
|
||||||
_requests.create_header(request)
|
|
||||||
response = _requests.make_request(request)
|
|
||||||
response.auth = request.auth
|
|
||||||
response.cookies = request.headers.cookie
|
|
||||||
return response
|
|
||||||
else
|
|
||||||
response.auth = request.auth
|
|
||||||
response.cookies = request.headers.cookie
|
|
||||||
return response
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
--Parse the first response from the host to make the Authorization header
|
|
||||||
function _requests.parse_digest_response_header(response, request)
|
|
||||||
for key, value in response.headers['www-authenticate']:gmatch('(%w+)="(%S+)"') do
|
|
||||||
request.auth[key] = value
|
|
||||||
end
|
|
||||||
|
|
||||||
if request.headers.cookie then
|
|
||||||
request.headers.cookie = request.headers.cookie..'; '..response.headers['set-cookie']
|
|
||||||
else
|
|
||||||
request.headers.cookie = response.headers['set-cookie']
|
|
||||||
end
|
|
||||||
|
|
||||||
request.auth.nc_count = 0
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Call the correct authentication header function
|
|
||||||
function _requests.add_auth_headers(request)
|
|
||||||
local auth_func = {
|
|
||||||
basic = _requests.basic_auth_header,
|
|
||||||
digest = _requests.digest_auth_header
|
|
||||||
}
|
|
||||||
|
|
||||||
auth_func[request.auth._type](request)
|
|
||||||
end
|
|
||||||
|
|
||||||
--Return public functions
|
|
||||||
requests._private = _requests
|
|
||||||
return requests
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user