@@ -46,14 +46,6 @@ const managerPagePort = 8001
4646
4747const testGatewayDomainName = 'www.google.com'
4848
49- // -
50- const IsSslConnect = ( buffer : Buffer ) => {
51-
52- const kk = buffer . toString ( 'hex' , 0 , 4 )
53-
54- return / ^ 1 6 0 3 ( 0 1 | 0 2 | 0 3 | 0 0 ) | ^ 8 0 ..0 1 0 3 | ^ ( 1 4 | 1 5 | 1 7 ) 0 3 ( 0 0 | 0 1 ) / . test ( kk )
55- }
56-
5749export const checkDomainInBlackList = ( BlackLisk : string [ ] , domain : string , CallBack ) => {
5850
5951 if ( Net . isIP ( domain ) ) {
@@ -277,10 +269,8 @@ export const isAllBlackedByFireWall = ( hostName: string, ip6: boolean, gatway:
277269}
278270
279271const isSslFromBuffer = ( buffer ) => {
280- console . log ( buffer . toString ( 'hex' ) )
281- const ret = / ^ \x16 [ \x2c - \xff ] \x01 \x00 [ \x00 - \x05 ] .[ \x00 - \x09 ] [ \x00 - \x1f ] | ^ \x80 [ \x0f - \xff ] \x01 [ \x00 - \x09 ] [ \x00 - \x1f ] [ \x00 - \x05 ] .\x00 .\x00 ./ . test ( buffer )
282-
283- console . log ( `ret [${ ret } ]` )
272+
273+ const ret = / ^ \x16 \x03 | ^ \x80 / . test ( buffer )
284274 return ret
285275}
286276const httpProxy = ( clientSocket : Net . Socket , buffer : Buffer , useGatWay : boolean , ip6 : boolean , connectTimeOut : number ,
@@ -351,6 +341,14 @@ const httpProxy = ( clientSocket: Net.Socket, buffer: Buffer, useGatWay: boolean
351341
352342}
353343
344+ const getPac = ( hostIp : string , port : number ) => {
345+
346+ const FindProxyForURL = `function FindProxyForURL ( url, host ) { return SOCKS ${ hostIp } :${ port . toString ( ) } ;}`
347+
348+ return res . _HTTP_200 ( FindProxyForURL )
349+ }
350+
351+
354352export class proxyServer {
355353
356354 private hostLocalIpv4 : { network : string , address : string } [ ] = [ ]
@@ -399,40 +397,23 @@ export class proxyServer {
399397 } )
400398
401399 }
402- /*
403- private getPac ( remoteIp: string, port: string ) {
404-
405- const ip6 = Net.isIP ( remoteIp )
406- const hostIp = Ip.isPrivate ( remoteIp ) ? ip6 === 6 ? this.hostLocalIpv6 : Nekudo.getLocalNetWorkIp ( this.hostLocalIpv4, remoteIp ) : ip6 === 6 ? this.hostGlobalIpV6: this.hostGlobalIpV4
407-
408- const FindProxyForURL = `function FindProxyForURL ( url, host ) {return SOCKS5 ${ hostIp }:${ port };}`
409-
410- return _HTTP_200 ( FindProxyForURL )
411- }
412- */
413- constructor ( public whiteIpList : string [ ] , public domainListPool : Map < string , domainData > ,
400+
401+ constructor ( public whiteIpList : string [ ] , public domainListPool : Map < string , domainData > , private localProxyServerIP : string ,
414402 private port : number , private securityPath : string , private serverIp : string , private serverPort : number , private password : string , public checkAgainTimeOut : number ,
415403 public connectHostTimeOut : number , public useGatWay : boolean , public domainBlackList : string [ ] ) {
416404 this . getGlobalIp ( this . gateway )
417405 let socks = null
418406 const server = Net . createServer ( socket => {
419407 const ip = socket . remoteAddress
420408 const isWhiteIp = this . whiteIpList . find ( n => { return n === ip } ) ? true : false
421-
422409 socket . once ( 'data' , ( data : Buffer ) => {
423- /*
424- if ( ! isWhiteIp ) {
425- console.log ('! isWhiteIp', data.toString ('utf8'))
426- if ( testLogin ( data, this.securityPath )) {
427-
428- this.whiteIpList.push ( ip )
429- this.saveWhiteIpList ()
430- return socket.end ( this.getPac ( ip, port.toString ()))
431- }
432-
433- return socket.end ()
410+ if ( / G E T \/ p a c / . test ( data . toString ( ) ) ) {
411+ const ret = getPac ( this . localProxyServerIP , this . port )
412+ saveLog ( `/GET \/pac from :[${ socket . remoteAddress } ]` )
413+ return socket . end ( ret )
434414 }
435- */
415+
416+
436417 switch ( data . readUInt8 ( 0 ) ) {
437418 case 0x4 :
438419 socks = new Socks . sockt4 ( socket , data , this )
@@ -476,6 +457,7 @@ interface proxyServerInfo {
476457 allToGateway : boolean
477458 localPort : number
478459}
460+
479461let flag = 'w'
480462const QTGateFolder = Path . join ( Os . homedir ( ) , '.QTGate' )
481463const proxyLogFile = Path . join ( QTGateFolder , 'proxy.log' )
@@ -489,7 +471,7 @@ const saveLog = ( log: string ) => {
489471
490472remote . getCurrentWindow ( ) . once ( 'firstCallBack' , ( data : IConnectCommand ) => {
491473 console . log ( data )
492- const server = new proxyServer ( [ ] , new Map ( ) , data . localServerPort , 'pac' , data . gateWayIpAddress , data . gateWayPort , data . imapData . randomPassword ,
474+ const server = new proxyServer ( [ ] , new Map ( ) , data . localServerIp , data . localServerPort , 'pac' , data . gateWayIpAddress , data . gateWayPort , data . imapData . randomPassword ,
493475 5000 , 50000 , data . AllDataToGateway , [ ] )
494476
495477} )
0 commit comments