使用NanoHTTPD框架搭建web的后端服务器:
第一步添加WebHttpdServer.java,内容如下:
package com.example.weblanguagetest;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import fi.iki.elonen.NanoHTTPD;
import fi.iki.elonen.NanoHTTPD.Response.Status;
public class WebHttpdServer extends NanoHTTPD {
public static final String tag = "debug";private String mFilePath = null;private String sessionId = "";private String DEFAULT_FILE_PATH = "/storage/sdcard0/www";public static final String MIME_PLAINTEXT = "text/plain";public static final String MIME_HTML = "text/html";public static final String MIME_JS = "application/javascript";public static final String MIME_CSS = "text/css";public static final String MIME_PNG = "image/png";public static final String MIME_DEFAULT_BINARY = "application/octet-stream";public static final String MIME_XML = "text/xml";public static final String MIME_MP4 = "video/mp4";public static final String MIME_MP3 = "audio/mpeg";public static final String EN_CONTENT_TYPE_MULT_DATA = "multipart/form-data";public static final String EN_CONTENT_TYPE_DEFAUL = "application/x-www-form-urlencoded";private static Timer timer = null;private static TimerTask task = null;private static WebHttpdServer mInterface = null;public static WebHttpdServer newInstance() { if (mInterface == null) {
mInterface = new WebHttpdServer(8080);
}
return mInterface;
}public WebHttpdServer(int port) { super(8080);
}@Overridepublic Response serve(IHTTPSession session) {
String url = session.getUri();
Method method = session.getMethod(); //Log.e(tag, "session.getUri()= " + url);
//Log.e(tag, "session.getMethod()= " + method);
if (url.equals("/")) {
url = "/index.htm";
}
if (url.contains(".js") || url.contains(".gif") || url.contains(".jpeg") || url.contains(".jpeg")
|| url.contains(".png") || url.contains(".css") || url.contains(".ico")) { // 不做任何处理
} else { // 获取sessionId值
String session_Id = session.getCookies().read("sessionId"); if (sessionId.equals("") || !session_Id.equals(sessionId)) { // 登录鉴权
if (Method.POST.equals(session.getMethod())) {
Map mMap = new HashMap();
Map mFile = new HashMap(); try {
session.parseBody(mFile);
mMap = session.getParms(); if (mMap != null) {
String nonce = mMap.get("nonce");
String encoded = mMap.get("encoded"); // MD5 计算
String password = "123456"; // GlobalConfigUtils.get("Password");
String pwd = password + ":" + nonce;
String md5Encode = Md5Utils.encode(pwd); // 校验登录密码
if (md5Encode.equals(encoded)) { // 跳到index.htm
StringBuilder FileName = new StringBuilder();
FileName = readFile(DEFAULT_FILE_PATH + "/index.htm"); // 随机产生一个session id值
sessionId = randomNumber();
Cookie cookies = new Cookie("sessionId", sessionId);
Response deResponse = NanoHTTPD.newFixedLengthResponse(Status.OK, MIME_HTML, FileName.toString());
deResponse.addHeader("Set-Cookie", cookies.getHTTPHeader()); return deResponse;
} else { // 返回登录界面
return cgiReadFile(DEFAULT_FILE_PATH + "/logon.htm", MIME_HTML);
}
}
} catch (IOException e) {
e.printStackTrace();
} catch (ResponseException e) {
e.printStackTrace();
}
} // 随机产生一个session id 值
// Cookie cookies = new Cookie("sessionId", randomNumber());
// deResponse.addHeader("Set-Cookie", cookies.getHTTPHeader());
return cgiReadFile(DEFAULT_FILE_PATH + "/logon.htm", MIME_HTML);
}
}
if (Method.GET.equals(method)) {
mFilePath = DEFAULT_FILE_PATH + url; //Log.e(tag, "mFilePath = " + mFilePath);
if (mFilePath != null) { if (mFilePath.contains(".js")) { return cgiReadFile(mFilePath, MIME_JS);
} else if (mFilePath.contains(".css")) { return cgiReadFile(mFilePath, MIME_CSS);
} else if (mFilePath.contains(".htm") || mFilePath.contains(".html")) { return cgiReadFile(mFilePath, MIME_HTML);
} else if (mFilePath.contains(".png")) { return cgiReadFile(mFilePath, MIME_PNG);
} else { // other operation
}
}
} else if (Method.POST.equals(method)) {
Map Headers = null;
Map mFile = new HashMap();
Map mMap = new HashMap(); try {
session.parseBody(mFile); // 把上传的文件存到指定位置
// copyFile(mFile.get("file"), NEW_FILE_PATH);
mMap = session.getParms();
Headers = session.getHeaders(); if (Headers.size() == 0) { return newFixedLengthResponse(Status.INTERNAL_ERROR, NanoHTTPD.MIME_PLAINTEXT, "SERVER ERROR: Headers");
} if (mMap == null) { return newFixedLengthResponse(Status.INTERNAL_ERROR, NanoHTTPD.MIME_PLAINTEXT, "SERVER ERROR: session.getParms");
}
String type = Headers.get("content-type"); if (type.equalsIgnoreCase(EN_CONTENT_TYPE_MULT_DATA)) { /* 文件上传 */
} else if (type.equalsIgnoreCase(EN_CONTENT_TYPE_DEFAUL)) { /* 配置上传 */
// F5 刷新时,如需post请求时重新响应index.htm界面
if (url.equals("/index.htm")) { return cgiReadFile(DEFAULT_FILE_PATH + "/index.htm", MIME_HTML);
} //Log.e(tag, "先保存配置后动作!!!!!!!!");
// 先保存配置后动作
//cfgSaveGlobalVar(mMap);
return cgiDoCgi(url.substring(url.lastIndexOf("/") + 1));
}
} catch (IOException ioe) { return newFixedLengthResponse(Status.INTERNAL_ERROR, NanoHTTPD.MIME_PLAINTEXT, "SERVER INTERNAL ERROR: IOException: " + ioe.getMessage());
} catch (ResponseException re) { return newFixedLengthResponse(re.getStatus(), NanoHTTPD.MIME_PLAINTEXT, re.getMessage());
}
} return response404(url);
}// 创建定时器(web页面超时时返回登录界面)Handler handler = new Handler() { public void handleMessage(Message msg) { if (msg.what == 1) { //Log.e(tag, "超时重设 session id, 并返回登录界面!!!!!!!!");
sessionId = "";
} super.handleMessage(msg);
};
};private void startTimer() { if (timer == null) {
timer = new Timer();
} if (task == null) {
task = new TimerTask() { @Override
public void run() {
Message message = new Message();
message.what = 1; if (handler != null) {
handler.sendMessage(message);
}
}
};
} if (timer != null && task != null)
timer.schedule(task, 10000, 10000);
}private void stopTimer() { if (timer != null) {
timer.cancel();
timer = null;
} if (task != null) {
task.cancel();
task = null;
}
}// 配置上传的cgi : psot处理private Response cgiDoCgi(String url) { if (url == null) { return responseError();
} if (url.equalsIgnoreCase("logout.cgi")) { // 返回登录界面,赋值sessionId为空
sessionId = ""; return cgiReadFile(DEFAULT_FILE_PATH + "/logon.htm", MIME_HTML);
} else if (url.equalsIgnoreCase("language.cgi")) {
Log.e(tag, "has match language.cgi!"); return cgiReadFile(DEFAULT_FILE_PATH + "/post.htm", MIME_HTML);
} else {
Log.e(tag, "no match cgi!"); return cgiReadFile(DEFAULT_FILE_PATH + "/logon.htm", MIME_HTML);
}
}// 生成随机数private String randomNumber() {
Random rand = new Random(); int num = rand.nextInt(); return String.valueOf(num);
}// 拷贝文件到指定路径private void copyFile(String oldPath, String newPath) { try { int bytesum = 0; int byteread = 0;
File oldfile = new File(oldPath); if (oldfile.exists()) {
File newfile = new File(newPath); if (!newfile.exists()) {
newfile.createNewFile();
}
InputStream inStream = new FileInputStream(oldPath); // 读入原文件
FileOutputStream fs = new FileOutputStream(newPath); byte[] buffer = new byte[8192]; int length; while ((byteread = inStream.read(buffer)) != -1) { // 字节数 文件大小
bytesum += byteread;
fs.write(buffer, 0, byteread);
}
inStream.close();
}
} catch (Exception e) {
Log.e(tag, "copy file failed!");
e.printStackTrace();
}
}// 响应文件没找到public Response response404(String url) {
StringBuilder builder = new StringBuilder();
builder.append("html>");
builder.append("Sorry, Can't Found " + url + " !");
builder.append("n"); return newFixedLengthResponse(builder.toString());
}public Response responseError() {
StringBuilder builder = new StringBuilder();
builder.append("html>");
builder.append("Sorry, Can't Found file !");
builder.append("n"); return newFixedLengthResponse(builder.toString());
}// cgiReadFilepublic Response cgiReadFile(String mFilePath, String MIME_TYPE) { if (MIME_TYPE.equals(MIME_PNG)) {
InputStream mbuffer = null; try {
mbuffer = new FileInputStream(mFilePath);
} catch (FileNotFoundException e) {
e.printStackTrace();
} return newChunkedResponse(Status.OK, MIME_PNG, mbuffer);
} else {
StringBuilder FileName = new StringBuilder();
FileName = readFile(mFilePath); return newFixedLengthResponse(Status.OK, MIME_TYPE, FileName.toString());
}
}// nanohttpd: get请求 时读取文件private StringBuilder readFile(String FileName) { try {
Boolean isHtmlFile = false;
StringBuilder sb = new StringBuilder(""); if (FileName.contains(".html") || FileName.contains(".htm")) {
isHtmlFile = true;
}
File file = new File(FileName); try {
InputStream instream = new FileInputStream(file); if (instream != null) {
InputStreamReader inputreader = new InputStreamReader(instream);
BufferedReader buffreader = new BufferedReader(inputreader);
String line = null; while ((line = buffreader.readLine()) != null) { if (isHtmlFile) { if (line.contains("~%") && line.contains("%~")) { // String mLine = line;
// mLine = line.substring(line.indexOf("~%"),
// line.indexOf("%~") + 2);
// line = line.replace(mLine, "vogtec");
// sb.append(line + "n");
sb.append(replaceMatchValue(line) + "n");
} else {
sb.append(line + "n");
}
} else {
sb.append(line + "n");
}
}
instream.close(); return sb;
}
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
} return null;
}// 替换行中存在~% *** %~ 中的参数public String replaceMatchValue(String line) { int mCount = 0;
String temp = "";
String mLine = null; if (line == null) { return temp;
}
mLine = line; while (line.contains("~%") == true && line.contains("%~") == true) {
mCount++;
mLine = line.substring(line.indexOf("~%"), line.indexOf("%~") + 2);
temp = cgiGetParams(mLine);
line = line.replace(mLine, temp); if (mCount > 3) { break;
}
} return line;
}// 获取~% *** %~ 内的参数public String cgiGetParams(String line) {
String temp = null;
String replaceLine = "";
String[] mStr = null;
List argv = new ArrayList(); if (line == null) { return replaceLine;
} if (!line.contains("(")) { return replaceLine;
} if (!line.contains(")")) { return replaceLine;
} // 获取第一个参数
temp = line.substring(line.indexOf("~%") + 2, line.indexOf("(")).trim(); if (temp == null) { return replaceLine;
} else {
argv.add(temp);
} // 获取()内参数
temp = line.substring(line.indexOf("(") + 1, line.indexOf(")")); if (temp != null) { if (temp.contains(",")) {
mStr = temp.split("\,"); for (int i = 0; i argv) {
String value = ""; if (argv == null || argv.size() == 0) { return value;
} if (argv.get(0).toString().equals("GetGlobal")) { //value = getGlobalDbVar(argv);
} else if (argv.get(0).equals("GetOutTime")) {
value = getOutTime(argv);
} else if (argv.get(0).equals("GetPostResult")) {
value = getPostResult(argv);
} else if (argv.get(0).equals("GetHttpsPrivateKey")) {
value = getHttpsPrivateKey(argv);
} else if (argv.get(0).equals("GetHttpsCertificate")) {
value = getHttpsCertificate(argv);
} else if (argv.get(0).equals("GetDhcpOpt66")) {
value = getDhcpOpt66(argv);
} else if (argv.get(0).equals("GetDhcpOpt43")) {
value = getDhcpOpt43(argv);
} else if (argv.get(0).equals("GetDhcpClient")) {
value = getDhcpClient(argv);
} else if (argv.get(0).equals("GetRegState")) {
value = getRegState(argv);
} else if (argv.get(0).equals("GetRegCode")) {
value = getRegCode(argv);
} else if (argv.get(0).equals("GetProductModel")) {
value = getProductModel(argv);
} else if (argv.get(0).equals("GetBootVer")) {
value = getBootVer(argv);
} else if (argv.get(0).equals("GetSystemTime")) {
value = getSystemTime(argv);
} else if (argv.get(0).equals("GetFirmwareVer")) {
value = getFirmwareVer(argv);
} else if (argv.get(0).equals("GetWanInfo")) {
value = getWanInfo(argv);
} else if (argv.get(0).equals("GetLangName")) {
value = getLangName(argv);
} else if (argv.get(0).equals("CGI_GetErrPwdFlag")) {
value = getErrPwdFlag(argv);
} else if (argv.get(0).equals("CGI_GetDumpState")) {
value = getDumpState(argv);
} else if (argv.get(0).equals("CGI_AccessFile")) {
value = getAccessFile(argv);
} else { return "";
} return value;
}public String getOutTime(List argv) {
String replaceLine = "1830"; return replaceLine;
}public String getPostResult(List argv) {
String replaceLine = "5060"; return replaceLine;
}public String getHttpsPrivateKey(List argv) {
String replaceLine = ""; return replaceLine;
}public String getHttpsCertificate(List argv) {
String replaceLine = ""; return replaceLine;
}public String getDhcpOpt66(List argv) {
String replaceLine = ""; return replaceLine;
}public String getDhcpOpt43(List argv) {
String replaceLine = ""; return replaceLine;
}public String getDhcpClient(List argv) {
String replaceLine = ""; return replaceLine;
}public String getRegState(List argv) {
String replaceLine = ""; return replaceLine;
}public String getRegCode(List argv) {
String replaceLine = ""; return replaceLine;
}public String getProductModel(List argv) {
String replaceLine = ""; return replaceLine;
}public String getBootVer(List argv) {
String replaceLine = ""; return replaceLine;
}public String getSystemTime(List argv) {
String replaceLine = "";
SimpleDateFormat sDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
Date curDate = new Date(System.currentTimeMillis());
replaceLine = sDateFormat.format(curDate); return replaceLine;
}public String getFirmwareVer(List argv) {
String replaceLine = ""; return replaceLine;
}public String getWanInfo(List argv) {
String replaceLine = ""; return replaceLine;
}public String getLangName(List argv) {
String replaceLine = ""; return replaceLine;
}public String getErrPwdFlag(List argv) {
String replaceLine = ""; return replaceLine;
}public String getDumpState(List argv) {
String replaceLine = ""; return replaceLine;
}public String getAccessFile(List argv) {
String replaceLine = ""; return replaceLine;
}
}
添加Md5Utils.java
package com.example.weblanguagetest;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class Md5Utils {
public static String encode(String password){ try {
MessageDigest digest = MessageDigest.getInstance("MD5"); byte[] result = digest.digest(password.getBytes());
StringBuffer sb = new StringBuffer(); for(byte b : result){ int number = (int)(b & 0xff) ;
String str = Integer.toHexString(number); if(str.length()==1){
sb.append("0");
}
sb.append(str);
} return sb.toString();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace(); //can't reach
return "";
}
}
}
添加StatusUtils.java
package com.example.weblanguagetest;
public class StatusUtils {
/* post.htm */public static final int EN_WEB_AUTH_FAIL = 0;// 验证登录用户失败public static final int EN_WEB_AUTH_PASS = 1;// 验证登录用户通过public static final int EN_WEB_GET_REQ = 2;// GET请求public static final int EN_WEB_POST_SUCC = 3;// 提交成功public static final int EN_WEB_USER_NO_PERM = 4;// 用户没有权限提交public static final int EN_WEB_UPLOAD_FAILURE = 5;// 上传失败public static final int EN_WEB_DOWNLOAD_FAILURE = 6;// 下载失败public static final int EN_WEB_UPLOAD_FILE_TOO_BIG = 7;// 上传数据太大public static final int EN_WEB_INVALID_IMAGE = 8;// 无效的IMAGEpublic static final int EN_WEB_INVALID_FILENAME = 9;// 无效的文件名public static final int EN_WEB_CONTENT_TYPE_ERROR = 10; // 不能处理的提交类型,目前支持POST(application/x-www-form-urlencoded,multipart/form-data)public static final int EN_CGI_PACKCAPTURE = 11;public static final int EN_CGI_CONFIG = 12;public static final int EN_CGI_EXPORT_LOG_UPDATE = 13;public static final int EN_CGI_CRASH_LOG = 14;public static final int EN_WEB_EXTRACT_PWD_ERROR = 15; // 证书提取密码错误public static final int EN_WEB_CERT_INSTALL_FAILED = 16; // 证书安装失败public static final int EN_WEB_CERT_INSTALL_SUCCESSED = 17; // 证书安装成功public static final int EN_WEB_CERT_INSTALL_INVALID = 18; // 证书无效public static final int EN_WEB_OPERATION_FAILED = 19; // 操作失败public static final int EN_WEB_EXPORT_LOG = 20; // 导出日记public static final int EN_WEB_PCAP = 21;public static final String BROAD_EXTRACT_PWD_ERROR = "broad_extract_pwd_error"; // 证书提取密码错误广播public static final String BROAD_CERT_INSTALL_FAILED = "broad_cert_install_failed"; // 证书安装失败广播public static final String BROAD_CERT_INSTALL_SUCCESSED = "broad_cert_install_successed"; // 证书安装成功广播public static final String BROAD_CERT_INSTALL_INVALID = "broad_cert_install_invaild"; // 证书无效广播public static final int EN_CGI_LOGOUT = 100; // 返回登录界面public static final int EN_CGI_PROCESSED = 101; // 配置提交成功public static final int EN_CGI_FIRMWARE_INVALID = 102;public static final int EN_CGI_CONFIG_INVALID = 103; // 无效配置public static final int EN_CGI_CERTIFICATE_INVALID = 104;public static final int EN_CGI_PRIVATE_INVALID = 105;public static final int EN_CGI_CER_KEY_DONOT_MATCH = 106;public static final int EN_CGI_LANGUAGEPACK_INVALID = 107;public static final int EN_CGI_WAVFILE_INVALID = 108;public static final int EN_CGI_UNKNOWN_ERROR = 109;/* 页面动作与代码的交互信息 */public static final String BC_REQUEST_SIP = "bc_request_sip";public static final String BC_REQUEST_FEATURE = "bc_request_feature";public static final String BC_CONTACT_UPDATE = "bc_contact_update";public static final String BC_MANUL_TIME = "bc_manul_time";public static final String BC_SNTP_SETTING = "bc_sntp_setting";public static final String BC_REQUEST_WIFI = "bc_request_wifi";public static final String BC_REQUEST_QOS = "qosvlan.cgi";public static final String BC_AUTO_PROVISION = "autoprovision.cgi";public static final String BC_LANGUAGE = "language.cgi";public static final String BC_NATTRAVEL = "nattravel.cgi";public static final String CA_CERT_PURPOSES = "ca.cert.purposes";public static final String CA_CERT_NAME = "ca.cert.name";public static final String USER_CERT_PWD = "user.cert.pwd";public static final String USER_CERT_NAME = "user.cert.name";public static final String USER_CERT_PURPOSES = "user.cert.purposes";public static final String USER_EDIT_NAME = "user_edit_name";// 保存web端上传时用户填写的名称public static final String CERT_TYPE = "cert_type";// 用户上传时选择的证书用途public static final String CERT_PASSWORD = "cert_password";// 用户上传时选择的证书提取密码public static final String CERT_VPN = "VPN";// 证书用途是VPNpublic static final String CERT_WIFI = "WIFI";// 证书用途是WIFIpublic static final int CERT_CA = 0;// CA证书public static final int CERT_USER = 1;// 用户证书public static final String WEB_WWW_EN = "www";public static final String WEB_WWW_CN = "www_zh";public static final String WEB_WWW_IT = "www_it";public static final String WEB_WWW_ES = "www_es";public static String SAVE_CERT = "save_cert_"; // 保存用户证书的相关信息到本地private int resultStatus;public int getResultStatus() {return resultStatus;
}public void setResultStatus(int resultStatus) {this.resultStatus = resultStatus;
}
}
在MainActivity.java添加服务启动
package com.example.weblanguagetest;
import java.io.IOException;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class MainActivity extends Activity {
private WebHttpdServer myHttpServer;@Overrideprotected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myHttpServer = WebHttpdServer.newInstance(); if (myHttpServer != null) { try {
myHttpServer.start();
} catch (IOException e) {
Log.e("debug", "start http server IOException.");
e.printStackTrace();
}
Log.e("debug", "start http server.");
} else {
Log.e("debug", "start http server failed.");
}
}@Overridepublic void onDestroy() { super.onDestroy(); if (myHttpServer != null) {
myHttpServer.stop();
Log.e("debug", "stop http server.");
}
}
}
页面文件 logon.html
// e.g: var lang = "en";var langArray = new Array("en", "zh", "it", "es");var langIndex = "~%getCurrentLanguage()%~";
if (!isNaN(langIndex)){
var i = parseInt(langIndex, 10); if (i strings_zh.properties 如找不到则用默认的strings.properties来显示
callback:function(){
$("[data-locale]").each(function(){
console.log($(this).data("locale"));
$(this).html($.i18n.prop($(this).data("locale")));
});
}
});
}function alertOutString(obj){ return $.i18n.prop(obj);
}
function initButton(){
document.getElementById('nonce').value = alertOutString('login');
}
var l = openAnyWindow.arguments.length;var w = "";var h = "";var features = "";for (i = 2; i 2) code += ", '" + features; code += "')";eval(code);
}
function array(n)
{
for (i = 0; i}
function integer(n)
{return n % (0xffffffff + 1);}
function shr(a, b)
{a = integer(a); b = integer(b);if (a - 0x80000000 >= 0) { a = a % 0x80000000; a >>= b; a += 0x40000000 >> (b - 1); }else a >>= b;return a;}
function shl1(a)
{a = a % 0x80000000;if (a & 0x40000000 == 0x40000000) { a -= 0x40000000; a *= 2; a += 0x80000000; }else a *= 2;return a;}
function shl(a, b)
{a = integer(a); b = integer(b);for (var i = 0; i}
function and (a, b)
{a = integer(a); b = integer(b);var t1 = (a - 0x80000000);var t2 = (b - 0x80000000);if (t1 >= 0) if (t2 >= 0) return ((t1 & t2) + 0x80000000); else return (t1 & b);else if (t2 >= 0) return (a & t2);else return (a & b);}
function or (a, b)
{a = integer(a); b = integer(b);var t1 = (a - 0x80000000);var t2 = (b - 0x80000000);if (t1 >= 0) if (t2 >= 0) return ((t1 | t2) + 0x80000000); else return ((t1 | b) + 0x80000000);else if (t2 >= 0) return ((a | t2) + 0x80000000);else return (a | b);}
function xor(a, b)
{a = integer(a); b = integer(b);var t1 = (a - 0x80000000);var t2 = (b - 0x80000000);if (t1 >= 0) if (t2 >= 0) return (t1 ^ t2); else return ((t1 ^ b) + 0x80000000);else if (t2 >= 0) return ((a ^ t2) + 0x80000000);else return (a ^ b);}
function not(a)
{a = integer(a);return (0xffffffff - a);}
/ Here begin the real algorithm /
var state = new array(4);
var count = new array(2);
count[0] = 0;
count[1] = 0;
var buffer = new array(64);
var transformBuffer = new array(16);
var digestBits = new array(16);
var S11 = 7;
var S12 = 12;
var S13 = 17;
var S14 = 22;
var S21 = 5;
var S22 = 9;
var S23 = 14;
var S24 = 20;
var S31 = 4;
var S32 = 11;
var S33 = 16;
var S34 = 23;
var S41 = 6;
var S42 = 10;
var S43 = 15;
var S44 = 21;
function F(x, y, z)
{return or ( and (x, y), and (not(x), z));}
function G(x, y, z)
{return or ( and (x, z), and (y, not(z)));}
function H(x, y, z)
{return xor(xor(x, y), z);}
function I(x, y, z)
{return xor(y, or (x, not(z)));}
function rotateLeft(a, n)
{return or (shl(a, n), (shr(a, (32 - n))));}
function FF(a, b, c, d, x, s, ac)
{a = a + F(b, c, d) + x + ac; a = rotateLeft(a, s); a = a + b;return a;}
function GG(a, b, c, d, x, s, ac)
{a = a + G(b, c, d) + x + ac; a = rotateLeft(a, s); a = a + b;return a;}
function HH(a, b, c, d, x, s, ac)
{a = a + H(b, c, d) + x + ac; a = rotateLeft(a, s); a = a + b;return a;}
function II(a, b, c, d, x, s, ac)
{a = a + I(b, c, d) + x + ac; a = rotateLeft(a, s); a = a + b;return a;}
function transform(buf, offset)
{var a = 0, b = 0, c = 0, d = 0;var x = transformBuffer; a = state[0]; b = state[1]; c = state[2]; d = state[3];for (i = 0; i}
function init()
{count[0] = count[1] = 0; state[0] = 0x67452301; state[1] = 0xefcdab89; state[2] = 0x98badcfe; state[3] = 0x10325476;for (i = 0; i}
function update(b)
{var index, i; index = and (shr(count[0], 3) , 0x3f);if (count[0] = 63) { transform(buffer, 0); }}
function finish()
{var bits = new array(8);var padding;var i = 0, index = 0, padLen = 0;for (i = 0; i}
/ End of the MD5 algorithm /
function hexa(n)
{var hexa_h = "0123456789abcdef";var hexa_c = "";var hexa_m = n;for (hexa_i = 0; hexa_i}
var ascii = "01234567890123456789012345678901" + " !"#" + "$" + "%&'()*+,-./0123456789:;?@ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "[]^_`abcdefghijklmnopqrstuvwxyz{|}~";
function md5(entree)
{var l, s, k, ka, kb, kc, kd; init();for (k = 0; k}
function encode()
{GetNonce(); document.submitForm.encoded.value = md5(document.getElementById("password").value + ":" + document.getElementById("nonce").value); // sets the hidden field value to whatever md5 returns.//alert(document.getElementById("nonce").value);//alert(document.submitForm.encoded.value);}
function KeyDown(event)
{if (event.keyCode == 13) { event.returnValue = false; event.cancel = true; document.submitForm.goto.click(); }}
function refreshpage()
{document.getElementById("password").focus();if (window.top.parent.frames["main"] != null) parent.location.href = parent.location.href;}
function ShowSystemTime()
{var dateTime = new Date();var yy = dateTime.getFullYear(); document.getElementById("system_time").innerHTML = yy;}
function randomString(len)
{len = len || 32;var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';var maxPos = $chars.length;var pwd = '';for (i = 0; i}
function GetNonce()
{document.getElementById("nonce").value = randomString(32);}
document.onkeydown = function(e)
{e = e || event;if (e.keyCode == 116) { return false; }}
window.location.href = 'logon.htm';}
function pwdtips()
{if (~%CGI_GetErrPwdFlag()%~) { document.getElementById("PWDTIPS").style.display = 'block'; setTimeout('myrefresh()', 1000); }else{ document.getElementById("PWDTIPS").style.display = 'none'; }}
Copyright © 2012 - All Rights Reserved.index页面如下:
Wi-Fi SIP Phone
menu.html页面:
}
.unOperater {position: fixed; left: 0px; top: 0px; width: 100%; height: 100%; z-index: 3; background: #003366;Opacity: 0.2; filter: Alpha(opacity =20);}
/ left menu style /
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/964/viewspace-2812504/ ,如需转载,请注明出处,否则将追究法律责任。