OpenWrt_Luci_Lua/Mi_Lua/luci/view/mobile/init/hello.htm

112 lines
4.2 KiB
HTML
Raw Normal View History

2015-05-09 10:48:46 +00:00
<!DOCTYPE html>
<%
local ver = require("xiaoqiang.XQVersion").webVersion
local sys = require("xiaoqiang.util.XQSysUtil")
if sys.getInitInfo() then
luci.template.render("mobile/sysauth")
else
sys.setSysPasswordDefault()
end
%>
<html lang="zh-CN">
<head>
<!-- Meta, title, CSS, favicons, etc. -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<title>小米路由器</title>
<link href="<%=resource%>/mobile/css/bc.css?v=<%=ver%>" rel="stylesheet">
<link href="<%=resource%>/mobile/css/hello.css?v=<%=ver%>" rel="stylesheet">
</head>
<body>
<article class="mod-hello">
<div class="content">
<p>
<label for="agree"><img id="agree" class="check" src="<%=resource%>/mobile/img/bg_checked.png" data-checked="checked"> <span>我已阅读并同意小米路由器</span></label><a target="_blank" href="<%=luci.dispatcher.build_url("mobile", "agreement")%>">用户协议</a></a>
</p>
<a id="toInit" href="#" class="btn btn-primary btn-block">开始</a>
</div>
<form style="display:none" id="prelogin" name="prelogin" method="post" action="<%=luci.dispatcher.build_url("mobile", "guide")%>">
<input type="hidden" name="username" value="admin"/>
<input type="hidden" name="password" value="admin"/>
</form>
</article>
<!-- <p class="testp"></p> -->
<%include("mobile/inc/footer")%>
<script src="<%=resource%>/mobile/js/zepto.js"></script>
<script src="/js/crypto-js/rollups/sha1.js?v=<%=ver%>"></script>
<script src="/js/crypto-js/rollups/aes.js?v=<%=ver%>"></script>
<script>
var global_event = {};
global_event.crypto = {
key: 'a2ffa5c9be07488bbb04a3a47d3c5f6a',
iv: '64175472480004614961023454661220',
nonce: (function(){
var type = 0;
var deviceId = '<%=mac%>';
var time = Math.floor(new Date().getTime() / 1000);
var random = Math.floor(Math.random() * 10000);
return [type, deviceId, time, random].join('_');
})(),
oldPwd : function(pwd){
return CryptoJS.SHA1(this.nonce + CryptoJS.SHA1(pwd + this.key).toString()).toString();
},
newPwd: function(pwd, newpwd){
var key = CryptoJS.SHA1(pwd + this.key).toString();
key = CryptoJS.enc.Hex.parse(key).toString();
key = key.substr(0, 32);
key = CryptoJS.enc.Hex.parse(key);
var password = CryptoJS.SHA1(newpwd + this.key).toString();
var iv = CryptoJS.enc.Hex.parse(this.iv);
var aes = CryptoJS.AES.encrypt(
password,
key,
{iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 }
).toString();
return aes;
}
};
$(function(){
function buildUrl(token, path){
var tpl = 'http://miwifi.com/cgi-bin/luci/;stok={$token}/{$path}';
var _path = path.join('/');
return tpl.replace('{$token}', token).replace( '{$path}', _path );
}
function getToken( url ) {
var re = /.*stok=([0-9a-z]*)\/.*/;
return re.exec( url )[1];
}
$('#toInit').on('click', function(e){
e.preventDefault();
if ($('#agree').attr('data-checked') == 'checked') {
var nonce = global_event.crypto.nonce;
var oldPwd = global_event.crypto.oldPwd( 'admin' );
$.post('<%=luci.dispatcher.build_url("api", "xqsystem", "login")%>',
{ nonce: nonce, password: oldPwd, username: 'admin' }, function(rsp){
var rsp = $.parseJSON(rsp);
if (rsp.code == 0) {
window.location.href = buildUrl( getToken( rsp.url ), ['mobile', 'guide'] );
}
});
// $('#prelogin').submit();
}
});
$('#agree').on('click', function(e){
if ($('#agree').attr('data-checked') == 'checked') {
$(this).attr('data-checked', '').attr('src','<%=resource%>/mobile/img/bg_check.png');
$('#toInit').addClass('btn-disabled');
}else{
$(this).attr('data-checked', 'checked').attr('src','<%=resource%>/mobile/img/bg_checked.png');
$('#toInit').removeClass('btn-disabled');
}
});
$('body').on('orientationchange', function(){
// window.location.reload(true);
});
});
</script>
</body>
</html>