Skip to content

Commit a13143c

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

File tree

19 files changed

+304
-306
lines changed

19 files changed

+304
-306
lines changed

app/gateway.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export default class gateWay {
7171

7272
public hostLookup ( hostName: string, userAgent: string, CallBack: ( err?: Error, hostIp?: domainData ) => void ) {
7373

74-
console.log (`try get nslookup data from remote!`)
74+
7575
const _data = new Buffer ( JSON.stringify ({ hostName: hostName }), 'utf8' )
7676

7777
const encrypt = new Compress.encryptStream ( this.password, 0, ( str: string ) => {
@@ -85,12 +85,10 @@ export default class gateWay {
8585

8686
const _socket = Net.createConnection ({ port: this.serverPort, host: this.serverIp }, () => {
8787
encrypt.write ( _data )
88-
console.log ( `send data to remote!` )
89-
console.log ( `*************\n${_data.toString ()}\n*********`)
9088
})
9189

9290
_socket.once ( 'end', () => {
93-
console.log ( `_socket.once end!` )
91+
//console.log ( `_socket.once end!` )
9492
})
9593

9694
httpBlock.once ( 'error', err => {
@@ -117,7 +115,6 @@ export default class gateWay {
117115
socket.end ( res._HTTP_404 )
118116
})
119117
const _socket = Net.createConnection ({ port: this.serverPort, host: this.serverIp }, () => {
120-
console.log ( 'requestGetWay connect:', uuuu.host, uuuu.port )
121118

122119
encrypt.write ( Buffer.from ( JSON.stringify ( uuuu ), 'utf8' ))
123120
})

app/httpProxy.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ export default class httpProxy {
8888
}
8989

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

9495
get isGet () {
@@ -147,11 +148,34 @@ export default class httpProxy {
147148
return null
148149

149150
}
151+
150152
get preBodyLength () {
151153
const body = this._parts [1]
152154
return body.length
153155
}
154156

157+
get Port () {
158+
console.log ( this.commandWithLine )
159+
const uu = this.commandWithLine[0].split(/\/\//)
160+
if ( uu.length > 1 ) {
161+
const kk = uu[1].split (':')
162+
if ( kk.length > 1 ) {
163+
const ret = kk[1].split (' ')[0]
164+
console.log ( `ret = [${ ret }]`)
165+
return parseInt ( ret )
166+
}
167+
return 80
168+
}
169+
const vv = this.commandWithLine[0].split(':')
170+
if ( vv.length > 1 ) {
171+
const kk = vv[1].split (' ')[0]
172+
console.log ( `kk = [${ kk }]`)
173+
return parseInt ( kk )
174+
}
175+
176+
return 443
177+
}
178+
155179
get BodyLength () {
156180
return parseInt ( this.headers[ 'content-length' ])
157181
}

app/proxyServer.ts

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@ 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! `)
5253
return CallBack ( null, BlackLisk.find ( n => { return n === domain }) ? true : false )
5354
}
55+
5456
const domainS = domain.split ('.')
5557
return Async.some ( BlackLisk, ( n, next ) => {
5658
const nS = n.split ('.')
@@ -216,9 +218,6 @@ export const tryConnectHost = ( hostname: string, hostIp: domainData, port: numb
216218

217219
const now = new Date ().getTime ()
218220

219-
console.log ( 'tryConnectHost do Async.someSeries hostIp:' )
220-
console.log ( hostIp )
221-
222221
Async.someSeries ( hostIp.dns, ( n, next ) => {
223222
console.log ( n )
224223

@@ -273,6 +272,7 @@ const isSslFromBuffer = ( buffer ) => {
273272
const ret = /^\x16\x03|^\x80/.test ( buffer )
274273
return ret
275274
}
275+
276276
const httpProxy = ( clientSocket: Net.Socket, buffer: Buffer, useGatWay: boolean, ip6: boolean, connectTimeOut: number,
277277
domainListPool: Map < string, domainData >, gatway: gateWay, checkAgainTime: number, blackDomainList: string[] ) => {
278278

@@ -291,12 +291,12 @@ const httpProxy = ( clientSocket: Net.Socket, buffer: Buffer, useGatWay: boolean
291291
buffer: _data.toString ( 'base64' ),
292292
cmd: Rfc1928.CMD.CONNECT,
293293
ATYP: Rfc1928.ATYP.IP_V4,
294-
port: parseInt ( httpHead.Url.port || httpHead.isHttps ? '443' : '80' ),
294+
port: httpHead.Port,
295295
ssl: isSslFromBuffer ( _data )
296296
}
297297

298298
const id = `[${ clientSocket.remoteAddress.split(':')[3] }:${ clientSocket.remotePort }][${ uuuu.uuid }] `
299-
console.log ( ` ${id} [${ hostName }]`, 'try use gateway\n' )
299+
console.log (uuuu)
300300
return gatway.requestGetWay ( id, uuuu, userAgent, clientSocket )
301301

302302
}
@@ -307,11 +307,12 @@ const httpProxy = ( clientSocket: Net.Socket, buffer: Buffer, useGatWay: boolean
307307
}
308308

309309
return checkDomainInBlackList ( blackDomainList, hostName, ( err, result: boolean ) => {
310-
310+
311311
if ( result ) {
312+
console.log (`checkDomainInBlackList CallBack result === true`)
312313
return clientSocket.end ( res.HTTP_403 )
313314
}
314-
315+
315316
const port = parseInt ( httpHead.Url.port || httpHead.isHttps ? '443' : '80' )
316317
const isIp = Net.isIP ( hostName )
317318
const hostIp: domainData = ! isIp ? domainListPool.get ( hostName ) : { dns: [{ family: isIp, address: hostName, expire: null, connect: [] }], expire: null }
@@ -334,23 +335,25 @@ const httpProxy = ( clientSocket: Net.Socket, buffer: Buffer, useGatWay: boolean
334335
return tryConnectHost ( hostName, _hostIp, port, buffer, clientSocket, httpHead.isConnect, checkAgainTime, connectTimeOut, useGatWay, CallBack )
335336
})
336337
}
337-
338+
console.log ( `checkDomainInBlackList CallBack hostName[${ hostName }] is IP address, now do tryConnectHost `)
338339
return tryConnectHost ( hostName, hostIp, port, buffer, clientSocket, httpHead.isConnect, checkAgainTime, connectTimeOut, useGatWay, CallBack )
339340

340341
})
341342

342343
}
343344

344-
const getPac = ( hostIp: string, port: number ) => {
345345

346-
const FindProxyForURL = `function FindProxyForURL ( url, host ) { return SOCKS ${ hostIp }:${ port.toString() };}`
346+
const getPac = ( hostIp: string, port: number, http: boolean ) => {
347+
348+
const FindProxyForURL = `function FindProxyForURL ( url, host ) { return "${ http ? 'PROXY': 'SOCKS' } ${ hostIp }:${ port.toString() }";}`
347349

348350
return res._HTTP_200 ( FindProxyForURL )
349351
}
350-
351352

352-
export class proxyServer {
353353

354+
355+
export class proxyServer {
356+
public UdpServer = new Socks.UdpDgram ()
354357
private hostLocalIpv4: { network: string, address: string } []= []
355358
private hostLocalIpv6: string = null
356359
private hostGlobalIpV4: string = null
@@ -367,7 +370,6 @@ export class proxyServer {
367370
})
368371
}
369372

370-
371373
private getGlobalIp = ( gateWay: gateWay ) => {
372374
if ( this.getGlobalIpRunning )
373375
return
@@ -406,20 +408,21 @@ export class proxyServer {
406408
const server = Net.createServer ( socket => {
407409
const ip = socket.remoteAddress
408410
const isWhiteIp = this.whiteIpList.find ( n => { return n === ip }) ? true : false
411+
409412
socket.once ( 'data', ( data: Buffer ) => {
410-
if ( /GET \/pac/.test ( data.toString())) {
411-
const ret = getPac ( this.localProxyServerIP, this.port )
413+
const dataStr = data.toString()
414+
if ( /^GET \/pac/.test ( dataStr )) {
415+
let ret = getPac ( this.localProxyServerIP, this.port, false )
416+
if ( /pacHttp/.test( dataStr ))
417+
ret = getPac ( this.localProxyServerIP, this.port, true )
412418
saveLog ( `/GET \/pac from :[${ socket.remoteAddress }]`)
413419
return socket.end ( ret )
414420
}
415-
416-
421+
417422
switch ( data.readUInt8 ( 0 )) {
418423
case 0x4:
419-
socks = new Socks.sockt4 ( socket, data, this )
420-
return console.log ( 'SOCK4 connect' )
424+
return socks = new Socks.sockt4 ( socket, data, this )
421425
case 0x5:
422-
console.log ( 'socks5 connect' )
423426
return socks = new Socks.socks5 ( socket, this )
424427
default:
425428
return httpProxy ( socket, data, useGatWay, this.hostGlobalIpV6 ? true : false, connectHostTimeOut, domainListPool, this.gateway, checkAgainTimeOut, domainBlackList )
@@ -446,6 +449,8 @@ export class proxyServer {
446449

447450
})
448451

452+
453+
449454
}
450455

451456
}

app/public/css/pages.css

Lines changed: 39 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -465,101 +465,70 @@ h1>.badge, h2>.badge, h3>.badge, h4>.badge,h5>.badge,h6>.badge {
465465
opacity: 0.5;
466466
}
467467
.localIP {
468-
position: absolute;
469-
left: 18em;
468+
position: relative;
469+
left: 19em;
470+
top: 7.8em;
470471
color: blue;
471472

472473
}
473-
.WindowsUseInfoLocalServerIp {
474-
position: absolute;
475-
left: 13.9em;
476-
top: 27.2em;
474+
.localIPPort {
475+
position: relative;
476+
left: 3.9em;
477+
top: 8.8em;
477478
color: blue;
479+
478480
}
479-
.firefoxUseLocalIp{
480-
position: absolute;
481-
left: 12em;
482-
top: 16.8em;
481+
.WindowsUseInfoLocalServerIp {
482+
position: relative;
483+
left: 13.2em;
484+
top: 15.5em;
483485
color: blue;
484486
}
485-
.firefoxUseLocalPort{
486-
position: absolute;
487-
left: 28em;
488-
top: 16.8em;
487+
.WindowsUseInfoPort{
488+
position: relative;
489+
left: -1.9em;
490+
top: 16.5em;
489491
color: blue;
490492
}
491-
.firefoxUseLocalIp1{
492-
position: absolute;
493-
left: 12em;
494-
top: 20.1em;
495-
color: rgba(0, 0, 0, 0.199)
496-
}
497-
.firefoxUseLocalPort1{
498-
position: absolute;
499-
left: 28em;
500-
top: 20.1em;
501-
color: rgba(0, 0, 0, 0.199)
502-
}
503-
.firefoxUseLocalIp2{
504-
position: absolute;
505-
left: 12em;
506-
top: 21.9em;
507-
color: rgba(0, 0, 0, 0.199)
508-
}
509-
.firefoxUseLocalPort2{
510-
position: absolute;
511-
left: 28em;
512-
top: 21.9em;
513-
color: rgba(0, 0, 0, 0.199)
514-
}
515-
.firefoxUseLocalIp3{
516-
position: absolute;
517-
left: 12em;
518-
top: 23.7em;
519-
color: rgba(0, 0, 0, 0.199)
520-
}
521-
.firefoxUseLocalPort3{
522-
position: absolute;
523-
left: 28em;
524-
top: 23.7em;
525-
color: rgba(0, 0, 0, 0.199)
493+
.firefoxUseLocalIp{
494+
position: relative;
495+
left: 4.5em;
496+
top: 32.2em;
497+
color: blue;
526498
}
527-
.WindowsUseInfoPort{
528-
position: absolute;
529-
left: 21.4em;
530-
top: 27.2em;
499+
.firefoxUseLocalPort{
500+
position: relative;
501+
left: -10.6em;
502+
top: 33.3em;
531503
color: blue;
532504
}
505+
506+
533507
.iOSUseInfoLocalServerIp{
534-
position: absolute;
535-
left: 4em;
536-
top: 14.1em;
508+
position: relative;
509+
left: 2em;
510+
top: 12.6em;
537511
color: blue;
538512
}
539513
.iOSUseInfoPort{
540-
position: absolute;
541-
left: 4em;
542-
top: 16.1em;
514+
position: relative;
515+
left: -13.1em;
516+
top: 13.7em;
543517
color: blue;
544518
}
545519
.androidUseInfoLocalServerIp{
546-
position: absolute;
547-
left: 7em;
548-
top: 10em;
520+
position: relative;
521+
left: 6em;
522+
top: 7.7em;
549523
color: blue;
550524
}
551525
.androidUseInfoPort{
552-
position: absolute;
553-
left: 7em;
554-
top: 14.5em;
526+
position: relative;
527+
left: -9.1em;
528+
top: 8.8em;;
555529
color: blue;
556530
}
557-
.localIPPort {
558-
position: absolute;
559-
left: 30.7em;
560-
color: blue;
561531

562-
}
563532
.feedBack:hover{
564533
opacity: 0.8;
565534
}

app/public/images/android3.jpg

-15 KB
Loading

app/public/images/android4.jpg

-53 KB
Binary file not shown.

app/public/images/firefox3.jpg

-447 KB
Loading

app/public/images/iOS4.jpg

-336 KB
Loading
-343 KB
Loading
-216 KB
Loading

0 commit comments

Comments
 (0)