Android 使用NanoHTTPD框架搭建web的後端伺服器(一)
使用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())) { MapmMap = 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; }}
<br/>function myrefresh()<br/>{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部落格 ” ,連結:http://blog.itpub.net/964/viewspace-2812504/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Android之利用NanoHttpd搭建伺服器AndroidNaNhttpd伺服器
- Android開發利用NanoHttpd搭建伺服器AndroidNaNhttpd伺服器
- 基於 NanoHttpd 的 Android 視訊伺服器開發NaNhttpdAndroid伺服器
- 基於GORM框架的web後端開發(一): GORM連線MySQLGoORM框架Web後端MySql
- Android服務端開發之使用Eclipse搭建Java Web服務端Android服務端EclipseJavaWeb
- 光速搭建阿里雲後端伺服器阿里後端伺服器
- 從零搭建自己的Vue管理端框架(一)Vue框架
- 學習使用 Goframe 框架搭建後臺GoFrame框架
- 在 Android 裝置上搭建 Web 伺服器AndroidWeb伺服器
- 快速搭建一個go語言web後端服務腳手架GoWeb後端
- app後端和web後端的區別APP後端Web
- ASP.NET Core 實戰:使用 ASP.NET Core Web API 和 Vue.js,搭建前後端分離框架ASP.NETWebAPIVue.js後端框架
- 基於Gin框架的web後端開發(八): Gin框架的請求重定向框架Web後端
- .Net Core 3.1瀏覽器後端服務(一) Web API專案搭建瀏覽器後端WebAPI
- 使用Django搭建web伺服器(最最正確的方式)DjangoWeb伺服器
- [Rust]使用Rocket框架搭建簡單Web服務Rust框架Web
- 使用python搭建伺服器並實現Android端與之通訊Python伺服器Android
- GO隨筆-搭建一個Web伺服器GoWeb伺服器
- golang web框架——gin使用教程(一)GolangWeb框架
- 如何應用於Web框架的搭建Web框架
- 後端渲染:基於Deno的全新全棧Web框架Fresh介紹後端全棧Web框架
- 探討後端選型中不同語言及對應的Web框架後端Web框架
- 基於Gin框架的web後端開發(七): Gin框架的檔案上傳詳解框架Web後端
- 004、v3admin學習,使用ci4搭建後端伺服器後端伺服器
- node搭建web伺服器Web伺服器
- 使用C#的後端Web API:循序漸進教程後端WebAPI
- 從零搭建自己的SpringBoot後臺框架(一)Spring Boot框架
- 一個小時搭建一個全棧 Web 應用框架全棧Web框架
- [Android]後端之路--intellij IDEA Maven專案的搭建(1)Android後端IntelliJIdeaMaven
- 基於Gin框架的web後端開發(二): JSON資料生成框架Web後端JSON
- Web開發從前端、後端、程式語言、到框架的初學指南Web前端後端框架
- 使用 frp 搭建內網穿透伺服器 Web 使用例項FRP內網穿透伺服器Web
- 基於Gin框架的web後端開發(十): Gin框架-中介軟體(定義、使用、通訊與例項)詳解框架Web後端
- 前後端分離之JWT(JSON Web Token)的使用後端JWTJSONWeb
- Android元件化框架搭建Android元件化框架
- nodejs搭建web伺服器NodeJSWeb伺服器
- 從零搭建自己的Vue管理端框架Vue框架
- Django+Vue.js搭建前後端分離專案 web前後端分離專案實踐DjangoVue.js後端Web