Skip to content

Commit e7f2298

Browse files
Peter XiePeter Xie
authored andcommitted
v0.8.40
1 parent a13143c commit e7f2298

File tree

11 files changed

+95
-67
lines changed

11 files changed

+95
-67
lines changed

app/httpProxy.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export default class httpProxy {
8888
}
8989

9090
get isConnect () {
91-
console.log (`isConnect:`, this.commandWithLine)
91+
9292
return ( /^connect /i.test ( this.commandWithLine[0] ) )
9393
}
9494

@@ -169,7 +169,6 @@ export default class httpProxy {
169169
const vv = this.commandWithLine[0].split(':')
170170
if ( vv.length > 1 ) {
171171
const kk = vv[1].split (' ')[0]
172-
console.log ( `kk = [${ kk }]`)
173172
return parseInt ( kk )
174173
}
175174

app/proxyServer.ts

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const testGatewayDomainName = 'www.google.com'
4949
export const checkDomainInBlackList = ( BlackLisk: string[], domain: string, CallBack ) => {
5050

5151
if ( Net.isIP ( domain )) {
52-
console.log ( `checkDomainInBlackList domain [${ domain }] is IP address! `)
52+
5353
return CallBack ( null, BlackLisk.find ( n => { return n === domain }) ? true : false )
5454
}
5555

@@ -281,7 +281,7 @@ const httpProxy = ( clientSocket: Net.Socket, buffer: Buffer, useGatWay: boolean
281281
const userAgent = httpHead.headers [ 'user-agent' ]
282282

283283
const CallBack = ( err?: Error, _data?: Buffer ) => {
284-
console.log ( `tryConnectHost callback err [${ err }], _data[${ _data }]`)
284+
285285
if ( err ) {
286286

287287
if ( useGatWay && _data && _data.length && clientSocket.writable ) {
@@ -296,7 +296,6 @@ const httpProxy = ( clientSocket: Net.Socket, buffer: Buffer, useGatWay: boolean
296296
}
297297

298298
const id = `[${ clientSocket.remoteAddress.split(':')[3] }:${ clientSocket.remotePort }][${ uuuu.uuid }] `
299-
console.log (uuuu)
300299
return gatway.requestGetWay ( id, uuuu, userAgent, clientSocket )
301300

302301
}
@@ -318,7 +317,7 @@ const httpProxy = ( clientSocket: Net.Socket, buffer: Buffer, useGatWay: boolean
318317
const hostIp: domainData = ! isIp ? domainListPool.get ( hostName ) : { dns: [{ family: isIp, address: hostName, expire: null, connect: [] }], expire: null }
319318

320319
if ( ! hostIp ) {
321-
console.log ( `domain connect to [${ hostName }]`)
320+
322321
return isAllBlackedByFireWall ( hostName, ip6, gatway, userAgent, domainListPool, ( err, _hostIp ) => {
323322
if ( err ) {
324323
console.log ( `[${ hostName }] Blocked!`)
@@ -335,17 +334,40 @@ const httpProxy = ( clientSocket: Net.Socket, buffer: Buffer, useGatWay: boolean
335334
return tryConnectHost ( hostName, _hostIp, port, buffer, clientSocket, httpHead.isConnect, checkAgainTime, connectTimeOut, useGatWay, CallBack )
336335
})
337336
}
338-
console.log ( `checkDomainInBlackList CallBack hostName[${ hostName }] is IP address, now do tryConnectHost `)
337+
339338
return tryConnectHost ( hostName, hostIp, port, buffer, clientSocket, httpHead.isConnect, checkAgainTime, connectTimeOut, useGatWay, CallBack )
340339

341340
})
342341

343342
}
344-
345-
346-
const getPac = ( hostIp: string, port: number, http: boolean ) => {
347-
348-
const FindProxyForURL = `function FindProxyForURL ( url, host ) { return "${ http ? 'PROXY': 'SOCKS' } ${ hostIp }:${ port.toString() }";}`
343+
/*
344+
declare const isInNet:( a: string, y: string, z: string ) => string
345+
declare const dnsResolve :( a: any ) => string
346+
function FindProxyForURL ( url, host )
347+
{
348+
if ( isInNet ( dnsResolve( host ), "0.0.0.0", "255.0.0.0") ||
349+
isInNet( dnsResolve( host ), "172.16.0.0", "255.240.255.0") ||
350+
isInNet( dnsResolve( host ), "127.0.0.0", "255.255.255.0") ||
351+
isInNet ( dnsResolve( host ), "192.168.0.0", "255.255.0.0" ) ||
352+
isInNet ( dnsResolve( host ), "10.0.0.0", "255.0.0.0" )) {
353+
return "DIRECT";
354+
}
355+
return "${ http ? 'PROXY': ( sock5 ? 'SOCKS5' : 'SOCKS' ) } ${ hostIp }:${ port.toString() }";
356+
}
357+
*/
358+
const getPac = ( hostIp: string, port: number, http: boolean, sock5: boolean ) => {
359+
360+
const FindProxyForURL = `function FindProxyForURL ( url, host )
361+
{
362+
if ( isInNet ( dnsResolve( host ), "0.0.0.0", "255.0.0.0") ||
363+
isInNet( dnsResolve( host ), "172.16.0.0", "255.240.255.0") ||
364+
isInNet( dnsResolve( host ), "127.0.0.0", "255.255.255.0") ||
365+
isInNet ( dnsResolve( host ), "192.168.0.0", "255.255.0.0" ) ||
366+
isInNet ( dnsResolve( host ), "10.0.0.0", "255.0.0.0" )) {
367+
return "DIRECT";
368+
}
369+
return "${ http ? 'PROXY': ( sock5 ? 'SOCKS5' : 'SOCKS' ) } ${ hostIp }:${ port.toString() }";
370+
}`
349371

350372
return res._HTTP_200 ( FindProxyForURL )
351373
}
@@ -408,22 +430,28 @@ export class proxyServer {
408430
const server = Net.createServer ( socket => {
409431
const ip = socket.remoteAddress
410432
const isWhiteIp = this.whiteIpList.find ( n => { return n === ip }) ? true : false
411-
433+
let agent = 'Mozilla/5.0'
434+
console.log (`new socket!`)
412435
socket.once ( 'data', ( data: Buffer ) => {
413436
const dataStr = data.toString()
414437
if ( /^GET \/pac/.test ( dataStr )) {
415-
let ret = getPac ( this.localProxyServerIP, this.port, false )
438+
const httpHead = new HttpProxyHeader ( data )
439+
agent = httpHead.headers['user-agent']
440+
const sock5 = /Windows NT|Darwin/i.test ( agent ) && ! /CFNetwork/i.test (agent)
441+
442+
let ret = getPac ( this.localProxyServerIP, this.port, false, sock5 )
416443
if ( /pacHttp/.test( dataStr ))
417-
ret = getPac ( this.localProxyServerIP, this.port, true )
418-
saveLog ( `/GET \/pac from :[${ socket.remoteAddress }]`)
444+
ret = getPac ( this.localProxyServerIP, this.port, true, sock5 )
445+
console.log ( `/GET \/pac from :[${ socket.remoteAddress }] sock5 [${ sock5 }] agent [${ agent }] httpHead.headers [${ Object.keys(httpHead.headers)}]`)
446+
console.log ( dataStr )
419447
return socket.end ( ret )
420448
}
421449

422450
switch ( data.readUInt8 ( 0 )) {
423451
case 0x4:
424-
return socks = new Socks.sockt4 ( socket, data, this )
452+
return socks = new Socks.sockt4 ( socket, data, agent, this )
425453
case 0x5:
426-
return socks = new Socks.socks5 ( socket, this )
454+
return socks = new Socks.socks5 ( socket, agent, this )
427455
default:
428456
return httpProxy ( socket, data, useGatWay, this.hostGlobalIpV6 ? true : false, connectHostTimeOut, domainListPool, this.gateway, checkAgainTimeOut, domainBlackList )
429457
}

app/public/scripts/home.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -620,9 +620,9 @@ const infoDefine = [
620620
useInfoMacOS: {
621621
title: '<p>本地代理服务器已在后台运行,MacOS和Windows用户可以关闭本窗口。</p>您的其他电子设备,可通过设置本地Proxy伺服器,来使用QTGate连接到互联网',
622622
title1: 'MacOS 本地代理服务器设定',
623-
proxyServerIp: '本地代理服务器地址:',
624-
proxyServerPort: '本地代理服务器端口:',
625-
proxyServerPassword: '本地代理服务器登陆用户名和密码:无需设定',
623+
proxyServerIp: '<p>代理设置选择:<span style="color: red;">自动代理设置</p>',
624+
proxyServerPort: 'HTTP和HTTPS代理设定:',
625+
proxyServerPassword: 'SOCKS代理设定:',
626626
info: [{
627627
title: '打开控制面板,点击网络',
628628
titleImage: '/images/macOsControl.jpg',
@@ -834,9 +834,9 @@ const infoDefine = [
834834
useInfoMacOS: {
835835
title: 'ローカルプロキシサーバはバックグランドで実行しています。MacoSとWindowsユーザーはこのウィンドウを閉じても構わないです。他のデバイスはローカルプロキシに設定による、QTGate利用してインターネットへアクセスができます。',
836836
title1: 'MacOS プロキシ設定',
837-
proxyServerIp: 'プロキシサーバアドレス:',
838-
proxyServerPort: 'サーバポート:',
839-
proxyServerPassword: '登録ユーザ名とパスワード:なし',
837+
proxyServerIp: '<p>プロキシの設定に:<span style="color:red;">自動設置</span></p>',
838+
proxyServerPort: 'HTTPとHTTPSプロキシは:',
839+
proxyServerPassword: 'SOCKSプロキシは:',
840840
info: [{
841841
title: 'コントロールパネルを開いて、ネットワークをクリックしてください。',
842842
titleImage: '/images/macOsControl.jpg',
@@ -1324,9 +1324,9 @@ const infoDefine = [
13241324
}]
13251325
},
13261326
useInfoMacOS: {
1327-
proxyServerIp: 'Proxy server address:',
1328-
proxyServerPort: 'Server port:',
1329-
proxyServerPassword: 'Proxy server login username and password: none',
1327+
proxyServerIp: '<p>Proxy setup: <span style="color: red;">Automatic or Auto-Config</span></p>',
1328+
proxyServerPort: 'HTTP & HTTPS proxy setup:',
1329+
proxyServerPassword: 'SOCKS proxy setup:',
13301330
title: 'Local proxy server is running at background. MacOS and windows user may close this window. All other devices can doing internet via local proxy setup use the QTGate system.',
13311331
title1: 'MacOS proxy setup',
13321332
info: [{
@@ -1693,9 +1693,9 @@ const infoDefine = [
16931693
useInfoMacOS: {
16941694
title: '本地代理伺服器已在後台運行,MacOS和Windows用戶可以關閉本窗口。您的其他電子設備,可通過設置本地Proxy伺服器,來使用QTGate連接到互聯網',
16951695
title1: 'MacOS 本地代理伺服器設定',
1696-
proxyServerIp: '本地代理伺服器地址:',
1697-
proxyServerPort: '本地代理伺服器端口:',
1698-
proxyServerPassword: '本地代理伺服器登陸用戶名和密碼:無需設定',
1696+
proxyServerIp: '<p>代理設定選擇:<span style="color: red;">自動設定</p>',
1697+
proxyServerPort: 'HTTP和HTTPS代理的設定為:',
1698+
proxyServerPassword: 'SOCKS代理的設定為:',
16991699
info: [{
17001700
title: '打開控制面板,點擊【網絡】',
17011701
titleImage: '/images/macOsControl.jpg',

app/public/scripts/home.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -680,9 +680,9 @@ const infoDefine = [
680680
useInfoMacOS: {
681681
title:'<p>本地代理服务器已在后台运行,MacOS和Windows用户可以关闭本窗口。</p>您的其他电子设备,可通过设置本地Proxy伺服器,来使用QTGate连接到互联网',
682682
title1:'MacOS 本地代理服务器设定',
683-
proxyServerIp:'本地代理服务器地址:',
684-
proxyServerPort: '本地代理服务器端口:',
685-
proxyServerPassword: '本地代理服务器登陆用户名和密码:无需设定',
683+
proxyServerIp:'<p>代理设置选择:<span style="color: red;">自动代理设置</p>',
684+
proxyServerPort: 'HTTP和HTTPS代理设定:',
685+
proxyServerPassword: 'SOCKS代理设定:',
686686
info:[{
687687
title:'打开控制面板,点击网络',
688688
titleImage:'/images/macOsControl.jpg',
@@ -900,9 +900,9 @@ const infoDefine = [
900900
useInfoMacOS: {
901901
title:'ローカルプロキシサーバはバックグランドで実行しています。MacoSとWindowsユーザーはこのウィンドウを閉じても構わないです。他のデバイスはローカルプロキシに設定による、QTGate利用してインターネットへアクセスができます。',
902902
title1:'MacOS プロキシ設定',
903-
proxyServerIp:'プロキシサーバアドレス:',
904-
proxyServerPort: 'サーバポート:',
905-
proxyServerPassword: '登録ユーザ名とパスワード:なし',
903+
proxyServerIp:'<p>プロキシの設定に:<span style="color:red;">自動設置</span></p>',
904+
proxyServerPort: 'HTTPとHTTPSプロキシは:',
905+
proxyServerPassword: 'SOCKSプロキシは:',
906906
info:[{
907907
title:'コントロールパネルを開いて、ネットワークをクリックしてください。',
908908
titleImage:'/images/macOsControl.jpg',
@@ -1404,9 +1404,9 @@ const infoDefine = [
14041404
}]
14051405
},
14061406
useInfoMacOS: {
1407-
proxyServerIp:'Proxy server address:',
1408-
proxyServerPort: 'Server port:',
1409-
proxyServerPassword: 'Proxy server login username and password: none',
1407+
proxyServerIp:'<p>Proxy setup: <span style="color: red;">Automatic or Auto-Config</span></p>',
1408+
proxyServerPort: 'HTTP & HTTPS proxy setup:',
1409+
proxyServerPassword: 'SOCKS proxy setup:',
14101410
title:'Local proxy server is running at background. MacOS and windows user may close this window. All other devices can doing internet via local proxy setup use the QTGate system.',
14111411
title1:'MacOS proxy setup',
14121412
info:[{
@@ -1788,9 +1788,9 @@ const infoDefine = [
17881788
useInfoMacOS: {
17891789
title:'本地代理伺服器已在後台運行,MacOS和Windows用戶可以關閉本窗口。您的其他電子設備,可通過設置本地Proxy伺服器,來使用QTGate連接到互聯網',
17901790
title1:'MacOS 本地代理伺服器設定',
1791-
proxyServerIp:'本地代理伺服器地址:',
1792-
proxyServerPort: '本地代理伺服器端口:',
1793-
proxyServerPassword: '本地代理伺服器登陸用戶名和密碼:無需設定',
1791+
proxyServerIp:'<p>代理設定選擇:<span style="color: red;">自動設定</p>',
1792+
proxyServerPort: 'HTTP和HTTPS代理的設定為:',
1793+
proxyServerPassword: 'SOCKS代理的設定為:',
17941794
info:[{
17951795

17961796
title:'打開控制面板,點擊【網絡】',

app/qtGate_emailClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ const httpImapProxy = ( imapClass: imapClass.imapClientControl, clientSocket: Ne
279279
const isIp = Net.isIP ( hostName )
280280
const hostIp: domainData = ! isIp ? domainListPool.get ( hostName ) : { dns: [{ family: isIp, address: hostName, expire: null, connect: [] }], expire: null }
281281
if ( ! hostIp ) {
282-
console.log ( `domain connect to [${ hostName }]`)
282+
283283
return isAllBlackedByFireWall ( hostName, false, checkAgainTimeOut, imapClass, domainListPool, ( err, _hostIp ) => {
284284
if ( err ) {
285285
console.log ( `isAllBlackedByFireWall [${ hostName }] got Error!`, err )

app/rfc1928.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@
207207

208208
public request_4_granted ( targetIp: string, targetPort: number) {
209209
if ( !targetIp )
210-
return Buffer.from ('005a0000000000','hex')
210+
return Buffer.from ('005a000000000000','hex')
211211
const ret = Buffer.from ('005a000000000000','hex')
212212
ret.writeUInt16BE ( targetPort, 2 )
213213
const u = targetIp.split ('.')

app/server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const Net = require("net");
2929
const Imap = require("./imap");
3030
const freePort = require("portastic");
3131
const Stream = require("stream");
32-
const DEBUG = false;
32+
const DEBUG = true;
3333
const openpgp = require('openpgp');
3434
const Express = require('express');
3535
const cookieParser = require('cookie-parser');

app/socket5ForiOpn.ts

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export class socks5 {
7575

7676
const id = `[${ this.clientIP }:${ this.port }][${ Util.inspect(uuuu) }] `
7777

78-
return this.proxyServer.gateway.requestGetWay ( id, uuuu, 'Mozilla/5.0', this.socket )
78+
return this.proxyServer.gateway.requestGetWay ( id, uuuu, this.agent, this.socket )
7979

8080
}
8181

@@ -108,7 +108,7 @@ export class socks5 {
108108
return this.closeSocks5 ( retBuffer.buffer )
109109
}
110110
if ( this.host ) {
111-
return proxyServer.isAllBlackedByFireWall ( this.host, false, this.proxyServer.gateway, 'Mozilla/5.0', this.proxyServer.domainListPool, ( err, _hostIp ) => {
111+
return proxyServer.isAllBlackedByFireWall ( this.host, false, this.proxyServer.gateway, this.agent, this.proxyServer.domainListPool, ( err, _hostIp ) => {
112112
if ( err ) {
113113
console.log ( `[${ this.host }] Blocked!`)
114114
retBuffer.REP = Rfc1928.Replies.CONNECTION_NOT_ALLOWED_BY_RULESET
@@ -150,10 +150,11 @@ export class socks5 {
150150
//.serverIP = this.socket.localAddress.split (':')[3]
151151

152152
// IPv6 not support!
153-
console.log ( this.cmd )
153+
154154
switch ( this.cmd ) {
155155

156156
case Rfc1928.CMD.CONNECT: {
157+
console.log (`sock5 [${ this.host }]`)
157158
this.keep = true
158159
break
159160
}
@@ -183,7 +184,7 @@ export class socks5 {
183184
return this.connectStat2_after ( req )
184185
}
185186

186-
constructor ( private socket: Net.Socket, private proxyServer: proxyServer.proxyServer ) {
187+
constructor ( private socket: Net.Socket,private agent: string, private proxyServer: proxyServer.proxyServer ) {
187188

188189
this.socket.once ( 'data', ( chunk: Buffer ) => {
189190
return this.connectStat2 ( chunk )
@@ -202,7 +203,7 @@ export class sockt4 {
202203
private targetDomainData: domainData = null
203204
private clientIP = this.socket
204205
private keep = false
205-
constructor ( private socket: Net.Socket, private buffer: Buffer, private proxyServer: proxyServer.proxyServer ) {
206+
constructor ( private socket: Net.Socket, private buffer: Buffer, private agent: string, private proxyServer: proxyServer.proxyServer ) {
206207
switch ( this.cmd ) {
207208
case Rfc1928.CMD.CONNECT: {
208209
this.keep = true
@@ -242,11 +243,8 @@ export class sockt4 {
242243
port: this.port,
243244
ssl: isSslFromBuffer ( _data )
244245
}
245-
246246
const id = `[${ this.clientIP }:${ this.port }][${ uuuu.uuid }] `
247-
console.log ( ` ${id} [${ this.host }]`, 'try use gateway\n' )
248-
return this.proxyServer.gateway.requestGetWay ( id, uuuu, 'Mozilla/5.0', this.socket )
249-
247+
return this.proxyServer.gateway.requestGetWay ( id, uuuu, this.agent, this.socket )
250248
}
251249

252250
return this.socket.end ( res.HTTP_403 )
@@ -255,11 +253,10 @@ export class sockt4 {
255253
}
256254

257255
this.socket.once ( 'data', ( _data: Buffer ) => {
258-
console.log ( _data.toString ())
256+
console.log (`connectStat2 [${ this.host||this.targetIpV4 }]get data `)
259257
proxyServer.tryConnectHost ( this.host, this.targetDomainData, this.port, _data, this.socket, false, this.proxyServer.checkAgainTimeOut,
260258
this.proxyServer.connectHostTimeOut, this.proxyServer.useGatWay, CallBack )
261259
})
262-
console.log ( `this.socket.write ( this.req.request_granted )`)
263260
const buffer = this.req.request_4_granted ( !this.host ? null: this.targetDomainData.dns[0].address, this.port )
264261
this.socket.write ( buffer )
265262
return this.socket.resume ()
@@ -268,15 +265,14 @@ export class sockt4 {
268265
if ( this.host ) {
269266
this.targetDomainData = this.proxyServer.domainListPool.get ( this.host )
270267
}
271-
console.log ( `connectStat1 `)
272268
return proxyServer.checkDomainInBlackList ( this.proxyServer.domainBlackList, this.host || this.targetIpV4, ( err, result: boolean ) => {
273269
if ( result ) {
274270
console.log ( `[${ this.host }] Blocked!`)
275271
return this.socket.end ( this.req.request_failed )
276272
}
277273
if ( this.host ) {
278-
console.log ( `this.host [${ this.host }]`)
279-
return proxyServer.isAllBlackedByFireWall ( this.host, false, this.proxyServer.gateway, 'Mozilla/5.0', this.proxyServer.domainListPool, ( err, _hostIp ) => {
274+
console.log (`socks4 host [${ this.host }]`)
275+
return proxyServer.isAllBlackedByFireWall ( this.host, false, this.proxyServer.gateway, this.agent, this.proxyServer.domainListPool, ( err, _hostIp ) => {
280276
if ( err ) {
281277
console.log ( `[${ this.host }] Blocked!`)
282278
return this.socket.end ( this.req.request_failed )
@@ -292,6 +288,7 @@ export class sockt4 {
292288
return this.connectStat2 ()
293289
})
294290
}
291+
console.log (`socks4 ipaddress [${ this.targetIpV4 }]`)
295292
return this.connectStat2 ()
296293

297294
})

0 commit comments

Comments
 (0)