protected void Page_Load(object sender, EventArgs e) { string ret = webAPIFunc.GetRetString(ErrType.UnkownErr); string LinuxServer = ConfigurationManager.AppSettings["LinuxServer"]; try { string post = WFHttpWebResponse.PostInput(Request.InputStream); if (string.IsNullOrEmpty(post))//没有这两个变量 { ret = webAPIFunc.GetRetString(ErrType.MissParam); Response.Write(ret); return; } post = post.Substring(0, post.Length - 1); byte[] rx = StringsFunction.strToHexByte(post, ""); byte[] DeviceID = new byte[4]; byte[] SSID = new byte[4]; byte[] data = null; if (rx.Length == (0x401 * 0x08)) { for (int i = 0; i < 4; i++) { DeviceID[i] = rx[i]; SSID[i] = rx[4 + i]; } data = new byte[(0x400 * 0x08)]; for (int i = 0; i < (0x400 * 0x08); i++) { data[i] = rx[8 + i]; } } else if (rx.Length == (0x801 * 0x08)) { for (int i = 0; i < 4; i++) { DeviceID[i] = rx[i]; SSID[i] = rx[4 + i]; } data = new byte[(0x800 * 0x08)]; for (int i = 0; i < (0x800 * 0x08); i++) { data[i] = rx[8 + i]; } } else { webAPIFunc.GetRetString(ErrType.ErrFileLen); Response.Write(ret); return; } byte[] txData = GlobalFunc.Encrypt(data, DeviceID, SSID); string strDeviceID = StringsFunction.byteToHexStr(DeviceID, ""); string strSSID = StringsFunction.byteToHexStr(SSID, ""); DeviceInfoData did = DeviceInfoDataDBOption.Get(strDeviceID); if (did == null) { ret = webAPIFunc.GetRetString(ErrType.NoRegDevice); Response.Write(ret); return; } else { int ut = HPassWorkLogDataDBOption.GetUseTimes(strDeviceID); if (ut > did.HPassTimes) { ret = webAPIFunc.GetRetString(ErrType.MaxUseTimes); Response.Write(ret); return; } } int index = HPassWorkLogDataDBOption.GetIndex(strDeviceID, strSSID); index++; string fileName = strDeviceID + strSSID + "_" + index.ToString() + ".txt"; WFHttpWebResponse web = new WFHttpWebResponse(); HttpWebResponse webRet = web.CreateGetHttpResponse(LinuxServer); if (webRet == null) { ret = webAPIFunc.GetRetString(ErrType.MissServer); Response.Write(ret); return; } webRet = web.CreatePostHttpResponse(LinuxServer + @"/login", "username=root&password=root"); if (webRet == null) { ret = webAPIFunc.GetRetString(ErrType.MissServer); Response.Write(ret); return; } webRet = web.CreateGetHttpResponse(LinuxServer + @"/search_m1_user"); if (webRet == null) { ret = webAPIFunc.GetRetString(ErrType.MissServer); Response.Write(ret); return; } HttpWebRequest request = null; request = WebRequest.Create(LinuxServer + @"/m1_user_search_add") as HttpWebRequest; request.Method = "POST"; string boundary = DateTime.Now.Ticks.ToString("x"); //请求 request.ContentType = "multipart/form-data; boundary=---------------------------" + boundary; request.CookieContainer = new CookieContainer(); if (web.Cookies != null && web.Cookies.Count != 0) { foreach (Cookie c in web.Cookies) { request.CookieContainer.Add(c); } } //组织表单数据 StringBuilder sb = new StringBuilder(); sb.Append("-----------------------------" + boundary); sb.Append("\r\n"); sb.Append("Content-Disposition: form-data; name=\"search_source\"; filename=\"" + fileName + "\""); sb.Append("\r\n"); sb.Append("Content-Type: text/plain"); sb.Append("\r\n\r\n"); string head = sb.ToString(); byte[] form_data = Encoding.ASCII.GetBytes(head); //结尾 byte[] foot_data = Encoding.ASCII.GetBytes("\r\n-----------------------------" + boundary + "--\r\n"); //数据 StringBuilder sb1 = new StringBuilder(); if (rx.Length == (0x401 * 0x08)) { for (int i = 0; i < 0x400; i++) { sb1.Append(StringsFunction.byteToHexStr(txData, i * 8, 8, " ")); sb1.Append("\r\n"); } } else { for (int i = 0; i < 0x800; i++) { sb1.Append(StringsFunction.byteToHexStr(txData, i * 8, 8, " ")); sb1.Append("\r\n"); } } sb1.Remove(sb1.Length - 2, 2); TextLog.AddTextLog(sb1.ToString(), Global.txtLogFolder + "HPassLog\\" + fileName, false); byte[] pBuf = Encoding.ASCII.GetBytes(sb1.ToString()); //post总长度 long length = form_data.Length + pBuf.Length + foot_data.Length; request.ContentLength = length; using (Stream requestStream = request.GetRequestStream()) { requestStream.Write(form_data, 0, form_data.Length); //文件内容 requestStream.Write(pBuf, 0, pBuf.Length); //结尾 requestStream.Write(foot_data, 0, foot_data.Length); } try { HttpWebResponse fileResponse = request.GetResponse() as HttpWebResponse; string Content; if (fileResponse.Headers["ContentEncoding"] != null) { Stream receiveStream = fileResponse.GetResponseStream(); StreamReader sr = new StreamReader(receiveStream, Encoding.GetEncoding(fileResponse.Headers["ContentEncoding"].ToString())); Content = sr.ReadToEnd(); } else { try { Stream receiveStream = fileResponse.GetResponseStream(); StreamReader sr = new StreamReader(receiveStream); Content = sr.ReadToEnd(); } catch { } } if (fileResponse.StatusCode == HttpStatusCode.OK) { ret = webAPIFunc.GetRetString(ErrType.retOK, fileName); HPassWorkLogData hl = new HPassWorkLogData(); hl.DeviceID = strDeviceID; hl.SSID = strSSID; hl.FileName = fileName; hl.IP = aspNetFunc.getIp(); HPassWorkLogDataDBOption.Insert(hl); Response.Write(ret); return; } } catch (System.Exception ex) { ret = webAPIFunc.GetRetString(ErrType.UnkownErr); Response.Write(ret); TextLog.AddTextLog("Add_updatafile:" + ex.Message, Global.txtLogFolder + "HPass.txt", true); return; } } catch (System.Exception ex) { ret = webAPIFunc.GetRetString(ErrType.UnkownErr); TextLog.AddTextLog("Add_Unkown:" + ex.Message, Global.txtLogFolder + "HPass.txt", true); } Response.Write(ret); }
protected void Page_Load(object sender, EventArgs e) { string DeviceID, serverid, SSID; string ret = ""; try { DeviceID = Request.QueryString["DeviceID"]; serverid = Request.QueryString["serverid"]; SSID = Request.QueryString["SSID"]; //信息|用户id|实验id,实验名,实验室; if (string.IsNullOrEmpty(DeviceID) || string.IsNullOrEmpty(serverid) || string.IsNullOrEmpty(SSID))//没有这两个变量 { ret = webAPIFunc.GetRetString(ErrType.MissParam); Response.Write(ret); return; } string LinuxServer = ConfigurationManager.AppSettings["LinuxServer"]; Linux_101 WebResponse = new Linux_101(); string xml = string.Format("<?xml version=\"1.0\"?><query><client>{0}</client><id>{1}</id></query>", DeviceID, serverid); int retry = 10; string status; string progress; int x; while (retry != 0) { HttpWebResponse response = WebResponse.CreatePostHttpResponse(LinuxServer + "/cgi-device/device.cgi?command=status101", xml); if (response == null) { //textBox1.AppendText("连接服务器失败\r\n"); retry--; continue; } x = WebResponse.Content.IndexOf("no such request"); if (x != -1) { ret = webAPIFunc.GetRetString(ErrType.ErrServerRet); Response.Write(ret); return; } x = WebResponse.Content.IndexOf("<status>"); if (x == -1) { //textBox1.AppendText("未查询到status数据\r\n"); retry--; continue; } status = WebResponse.Content.Substring(x + "<status>".Length, WebResponse.Content.IndexOf("</status>") - x - "<status>".Length); if (status == "finished") { x = WebResponse.Content.IndexOf("<result>"); if (x == -1) { ret = webAPIFunc.GetRetString(ErrType.retOK); Response.Write(ret); return; } else { x = WebResponse.Content.IndexOf("<query>"); string query, answer; if (x == -1) { ret = webAPIFunc.GetRetString(ErrType.retOK); Response.Write(ret); return; } else { query = WebResponse.Content.Substring(x + "<query>".Length, WebResponse.Content.IndexOf("</query>") - x - "<query>".Length); } x = WebResponse.Content.IndexOf("<answer>"); if (x == -1) { ret = webAPIFunc.GetRetString(ErrType.retOK); Response.Write(ret); return; } else { answer = WebResponse.Content.Substring(x + "<answer>".Length, WebResponse.Content.IndexOf("</answer>") - x - "<answer>".Length); } byte[] ss1 = WFNetLib.StringFunc.StringsFunction.strToHexByte(query, " "); byte[] ss2 = WFNetLib.StringFunc.StringsFunction.strToHexByte(answer, " "); DPassRecodeData dr = new DPassRecodeData(); dr.Dealer = WFNetLib.StringFunc.StringsFunction.byteToHexStr(ss1, ""); dr.DPass = WFNetLib.StringFunc.StringsFunction.byteToHexStr(ss2, ""); DPassRecodeDataDBOption.Insert(dr); DPassWorkLogData dl = new DPassWorkLogData(); dl.DeviceID = DeviceID; dl.IP = WFNetLib.aspNetFunc.getIp(); dl.Pass = dr.Dealer; dl.Ret = dr.DPass; dl.SSID = SSID; DPassWorkLogDataDBOption.Insert(dl); byte[] dID = WFNetLib.StringFunc.StringsFunction.strToHexByte(DeviceID, ""); byte[] sID = WFNetLib.StringFunc.StringsFunction.strToHexByte(SSID, ""); byte[] DPass = WFNetLib.StringFunc.StringsFunction.strToHexByte(dr.DPass, ""); byte[] DDPass = GlobalFunc.Encrypt(DPass, dID, sID); ret = "1," + dr.Dealer + "-" + WFNetLib.StringFunc.StringsFunction.byteToHexStr(DDPass, ""); Response.Write(ret); return; } } else if (status == "rejected") { ret = "4,"; Response.Write(ret); return; } else if (status == "queued") { x = WebResponse.Content.IndexOf("<queue>"); if (x != -1) { progress = WebResponse.Content.Substring(x + "<queue>".Length, WebResponse.Content.IndexOf("</queue>") - x - "<queue>".Length); ret = "3," + progress; Response.Write(ret); return; } else { ret = "3,-1"; Response.Write(ret); return; } } else if (status == "inprogress") { x = WebResponse.Content.IndexOf("<progress>"); if (x != -1) { progress = WebResponse.Content.Substring(x + "<progress>".Length, WebResponse.Content.IndexOf("</progress>") - x - "<progress>".Length); ret = "2," + progress; Response.Write(ret); return; } else { ret = "2,-1"; Response.Write(ret); return; } } } if (retry == 0) { ret = "-99,"; Response.Write(ret); return; } } catch (System.Exception ex) { ret = webAPIFunc.GetRetString(ErrType.UnkownErr); TextLog.AddTextLog("Status_Unkown:" + ex.Message, Global.txtLogFolder + "DPass.txt", true); } Response.Write(ret); }
protected void Page_Load(object sender, EventArgs e) { string DeviceID, Dealer, SSID; string ret = ""; try { DeviceID = Request.QueryString["DeviceID"]; Dealer = Request.QueryString["pass"]; SSID = Request.QueryString["SSID"]; //信息|用户id|实验id,实验名,实验室; if (string.IsNullOrEmpty(DeviceID) || string.IsNullOrEmpty(Dealer) || string.IsNullOrEmpty(SSID))//没有这两个变量 { ret = webAPIFunc.GetRetString(ErrType.MissParam); Response.Write(ret); return; } DeviceInfoData did = DeviceInfoDataDBOption.Get(DeviceID); if (did == null) { ret = webAPIFunc.GetRetString(ErrType.NoRegDevice); Response.Write(ret); return; } else { int ut = DPassWorkLogDataDBOption.GetUseTimes(DeviceID); if (ut > did.DPassTimes) { ret = webAPIFunc.GetRetString(ErrType.MaxUseTimes); Response.Write(ret); return; } } DataTable dt = DPassRecodeDataDBOption.DataTableSelect(Dealer); if (dt.Rows.Count != 0) { byte[] dID = WFNetLib.StringFunc.StringsFunction.strToHexByte(DeviceID, ""); byte[] sID = WFNetLib.StringFunc.StringsFunction.strToHexByte(SSID, ""); byte[] DPass = WFNetLib.StringFunc.StringsFunction.strToHexByte(dt.Rows[0]["DPass"].ToString(), ""); byte[] DDPass = GlobalFunc.Encrypt(DPass, dID, sID); DPassWorkLogData dl = new DPassWorkLogData(); dl.DeviceID = DeviceID; dl.IP = WFNetLib.aspNetFunc.getIp(); dl.Pass = dt.Rows[0]["Dealer"].ToString(); dl.Ret = dt.Rows[0]["DPass"].ToString(); dl.SSID = SSID; DPassWorkLogDataDBOption.Insert(dl); ret = "2," + dt.Rows[0]["Dealer"] + "-" + WFNetLib.StringFunc.StringsFunction.byteToHexStr(DDPass, ""); Response.Write(ret); return; } else { string LinuxServer = ConfigurationManager.AppSettings["LinuxServer"]; Linux_101 WebResponse = new Linux_101(); byte[] bD = WFNetLib.StringFunc.StringsFunction.strToHexByte(Dealer, ""); string Dealer1 = WFNetLib.StringFunc.StringsFunction.byteToHexStr(bD, " "); string xml = string.Format("<?xml version=\"1.0\"?><query><client>{0}</client><data>{1}</data></query>", DeviceID, Dealer1); HttpWebResponse response = WebResponse.CreatePostHttpResponse(LinuxServer + "/cgi-device/device.cgi?command=search101", xml); if (response == null) { ret = webAPIFunc.GetRetString(ErrType.MissServer); Response.Write(ret); return; } string id = ""; int x; x = WebResponse.Content.IndexOf("<id>"); if (x == -1) { ret = webAPIFunc.GetRetString(ErrType.ErrServerRet); Response.Write(ret); return; } id = WebResponse.Content.Substring(x + "<id>".Length, WebResponse.Content.IndexOf("</id>") - x - "<id>".Length); ret = webAPIFunc.GetRetString(ErrType.retOK, id); } } catch (System.Exception ex) { ret = webAPIFunc.GetRetString(ErrType.UnkownErr); TextLog.AddTextLog("Add_Unkown:" + ex.Message, Global.txtLogFolder + "DPass.txt", true); } Response.Write(ret); }