You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

133 lines
4.1 KiB

  1. /*!
  2. * jQuery JavaScript Library v1.4.2
  3. * http://jquery.com/
  4. *
  5. * Copyright 2010, John Resig
  6. * Dual licensed under the MIT or GPL Version 2 licenses.
  7. * http://jquery.org/license
  8. *
  9. * Includes Sizzle.js
  10. * http://sizzlejs.com/
  11. * Copyright 2010, The Dojo Foundation
  12. * Released under the MIT, BSD, and GPL Licenses.
  13. *
  14. * Date: Sat Feb 13 22:33:48 2010 -0500
  15. */
  16. /**
  17. * 登录注销js接口
  18. * 产生登录注销信息,也就是url
  19. * 使用说明:
  20. * 1. 登录
  21. * var aclogon = new ACLogon();
  22. * var url = aclogon.logon("https://200.200.65.145/cgi-bin/caauth.cgi?ui=web&opr=logon&chk_cookie=0&info=","用户名","显示名","组路径");
  23. * 将产生的url放入浏览器地址栏,或者使用ajax提交均可
  24. * 如:使用jquery ajax提交
  25. * $.get(url,[option],[callback]);
  26. * 2. 注销
  27. * 将urlprefix改为"https://200.200.65.145/cgi-bin/caauth.cgi?ui=web&opr=logout&chk_cookie=0&info=""即可
  28. *
  29. * @file ACLogon.js
  30. * @author asongnic@gmail.com
  31. * @date 2010/09/30
  32. */
  33. function ACLogon() {
  34. var encoding_table = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";// 64个
  35. var base64_encode = function(plain) {
  36. var cipher,i,len;
  37. var c1,c2,c3;
  38. i = 0;
  39. cipher="";
  40. len = plain.length;
  41. while (i<len) {
  42. c1 = plain.charCodeAt(i++) & 0xff;
  43. if (i == len) {
  44. cipher += encoding_table.charAt(c1>>2);
  45. cipher += encoding_table.charAt((c1&0x3) << 4);
  46. cipher += "==";
  47. break;
  48. }
  49. c2 = plain.charCodeAt(i++);
  50. if (i == len) {
  51. cipher += encoding_table.charAt(c1>>2);
  52. cipher += encoding_table.charAt(((c1&0x3) << 4)|((c2&0xF0)>>4));
  53. cipher += encoding_table.charAt((c2 & 0xF) << 2);
  54. break;
  55. }
  56. c3 = plain.charCodeAt(i++);
  57. cipher += encoding_table.charAt(c1 >> 2);
  58. cipher += encoding_table.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4));
  59. cipher += encoding_table.charAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >>6));
  60. cipher += encoding_table.charAt(c3 & 0x3F);
  61. }
  62. return cipher;
  63. };
  64. //
  65. var toUTF8 = function(str) {
  66. var out, i, len, c;
  67. out = "";
  68. len = str.length;
  69. for(i = 0; i < len; i++) {
  70. c = str.charCodeAt(i);
  71. if ((c >= 0x0001) && (c <= 0x007F)) {
  72. out += str.charAt(i);
  73. } else if (c > 0x07FF) {
  74. out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
  75. out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F));
  76. out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
  77. } else {
  78. out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F));
  79. out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
  80. }
  81. }
  82. return out;
  83. };
  84. /**
  85. * @description, 产生发送到AC认证的信息
  86. * @param {String} urlprefix,如 https://200.200.65.145/cgi-bin/caauth.cgi?ui=web&opr=logon&chk_cookie=0&info=
  87. *
  88. * 登录发送urlprefix可以为:https://200.200.65.145/cgi-bin/caauth.cgi?ui=web&opr=logon&chk_cookie=0&info=
  89. * 注销urlprefix可以为:https://200.200.65.145/cgi-bin/caauth.cgi?ui=web&opr=logout&chk_cookie=0&info=
  90. *
  91. * @param {String} ip ,认证用户的ip地址
  92. * @param {String} username,认证用户的用户名
  93. * @param {String} group 认证用户的组路径
  94. * @return {String} 发送的url
  95. * @notes 不检查参数的合法性
  96. */
  97. this.logon = function(urlprefix,ip,username,group){
  98. var plain = toUTF8(ip+"/"+username+"/"+""+"/"+(group?group:""));
  99. var info = encodeURIComponent(base64_encode(plain));
  100. return urlprefix+info;
  101. };
  102. }
  103. /**
  104. * @description, 产生发送到AC认证的信息
  105. * @param {String} acip ,AC的ip
  106. * @param {String} opr ,"logon"或者"logout"
  107. * @param {String} ip ,认证用户的ip地址
  108. * @param {String} username,认证用户的用户名
  109. * @param {String} group 认证用户的组路径
  110. * @return {String} 发送的url
  111. * @notes 不检查参数的合法性
  112. */
  113. function sendToAc(acip,opr,ip,usr,group ){
  114. var lo = new ACLogon();
  115. var url = "http://"+acip+":85/cgi-bin/caauth.cgi?ui=web&opr="+opr+"&chk_cookie=0&info=";
  116. url = lo.logon(url,ip,usr,group);
  117. var ifr = $('<iframe id="ifr_hide_send_to_ac" style="display:none;"></iframe>');
  118. ifr.attr("src",url);
  119. if (!!$('#ifr_hide_send_to_ac')[0]){
  120. $('#ifr_hide_send_to_ac').remove();
  121. }
  122. $('body').append(ifr);
  123. }