|
本帖最后由 花妆男 于 2021-3-27 10:26 编辑
效果如图:可以自己DIY
修改步骤逻辑准备:
1. 主要修改登录逻辑就是把老毛子的http验证改为手动提交验证
2. 固件需要修改的文件也就只有一个:trunk/user/httpd/httpd.c 文件
3. 编写一个登录页面,放到 trunk/user/www 下面,(因为默认是拷贝这整个文件夹,无需关注makefile文件)
httpd.c 需要关注的重点
登录状态说明:
- /* 517 行
- * attempt login check, result
- * 0: can not login, has other loginer
- * 1: can login, this is localhost (always allow w/o auth)
- * 2: can login, no loginer
- * 3: can login, loginer is our
- */
- 0: 无法登录,有其他登录者
- 1:可以登录,这是本地主机
- 2: 可以登录,没有登录者
- 3: 可以登录,登录者是我们
复制代码 判断登录的逻辑
- /* 983 行*/
- if (handler->need_auth && login_state > 1 && !do_logout) {
- if (!auth_check(authorization)) {
- http_logout(&conn_ip);
- if (method_id == HTTP_METHOD_POST)
- eat_post_data(conn_fp, clen);
- send_authenticate(conn_fp);
- return;
- }
-
- if (login_state == 2)
- http_login(&conn_ip);
- }
复制代码
返回调用http认证的函数- /* 641 行 */
- static void
- send_authenticate( FILE *conn_fp )
- {
- char header[128], *realm;
- realm = nvram_safe_get("computer_name");
- if (strlen(realm) < 1)
- realm = nvram_safe_get("productid");
- snprintf(header, sizeof(header), "WWW-Authenticate: Basic realm="%s"", realm);
- send_error( 401, "Unauthorized", header, "Authorization required.", conn_fp );
- }
复制代码
具体修改:
httpd.c
1. 修改登录逻辑,取消了状态 3 的验证,因为这样就可以减少很多的工作
2. 可以把 http 认证函数直接删了- if (handler->need_auth && login_state > 1 && !do_logout) {
- /*
- 没登录需要验证
- */
- if (login_state == 2){
- if(auth_check(authorization)){
- http_login(&conn_ip);
- send_headers( 200, "OK", NULL, NULL, NULL, conn_fp );
- return;
- }else {
- http_logout(&conn_ip);
- if (method_id == HTTP_METHOD_POST)
- eat_post_data(conn_fp, clen);
- file = "Login.asp";
- query = NULL;
- }
- }
复制代码
Login.asp (根据上面修改来命名的)
1. 核心就是用xhr head 提交一次验证
这个是把账号密码加密bease64(因为我们没有修改路由器的验证密码方式,所以这里拼接加密还是根据路由来,就是http的验证)
支持ie10+ 是因为 btoa 函数,需要兼容低版本可以手写加密函数或者其他- function basicB64Encode(user,password) {
- return 'Basic ' + btoa(encodeURIComponent(user.toString()+':'+password.toString()).replace(/%([0-9A-F]{2})/g,
- function(match, p1) {
- return String.fromCharCode('0x' + p1);
- }));
- }
复制代码 新建xhr对象,然后把认证参数通过 HEAD 方法提交给路由器
提交结束后在本地跳转到首页
- var req
- try{
- if (window.XMLHttpRequest)
- req=new XMLHttpRequest()
- else
- req=new ActiveXObject("Microsoft.XMLHTTP")
- }catch (e){
- req=null
- }
- if (req != null){
- req.open("HEAD","/",true)
- req.setRequestHeader('Authorization',basicB64Encode(data.u,data.p))
- req.onreadystatechange = function() {
- if (req.readyState === 4){
- window.location.href = "/"
- }
- }
- req.send(null)
- }
复制代码 最后:
有啥问题不会的欢迎留言讨论!!!!
优点:修改地方少,简单,快速,比之前登录好看,而且不会出现手机上的一些问题
缺点:账号密码服务端错误不会提示,会直接再返回登录页
不会修改的可以直接下载附件替换编译就可以用了
附件:
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
×
|