Skip to content

Commit 106e5e9

Browse files
Peter XiePeter Xie
authored andcommitted
v0.9.0
1 parent e84b8d6 commit 106e5e9

File tree

10 files changed

+142
-145
lines changed

10 files changed

+142
-145
lines changed

app/gateway.ts

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -62,29 +62,38 @@ class hostLookupResponse extends Stream.Writable {
6262
export default class gateWay {
6363

6464
private userAgent = null
65+
private currentGatewayPoint = 0
66+
private currentgateway: multipleGateway
67+
68+
private request ( str: string, gateway: multipleGateway ) {
69+
return Buffer.from ( otherRequestForNet ( str, gateway.gateWayIpAddress, gateway.gateWayPort, this.userAgent ), 'utf8' )
70+
}
6571

66-
private request ( str: string ) {
67-
return Buffer.from ( otherRequestForNet ( str, this.serverIp, this.serverPort, this.userAgent ), 'utf8' )
72+
private getCurrentGateway () {
73+
if ( ++ this.currentGatewayPoint > this.multipleGateway.length - 1 ) {
74+
this.currentGatewayPoint = 0
75+
}
76+
return this.multipleGateway [ this.currentGatewayPoint ]
6877
}
6978

70-
constructor ( public serverIp: string, public serverPort: number, private password: string ) {
79+
constructor ( private multipleGateway: multipleGateway[]) {
7180
}
7281

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

7584

7685
const _data = new Buffer ( JSON.stringify ({ hostName: hostName }), 'utf8' )
77-
78-
const encrypt = new Compress.encryptStream ( this.password, 3000, ( str: string ) => {
79-
return this.request ( str )
86+
const gateway = this.getCurrentGateway ()
87+
const encrypt = new Compress.encryptStream ( gateway.password, 3000, ( str: string ) => {
88+
return this.request ( str, gateway )
8089
})
8190

8291
const finish = new hostLookupResponse ( CallBack )
8392
const httpBlock = new Compress.getDecryptClientStreamFromHttp ()
84-
const decrypt = new Compress.decryptStream ( this.password )
93+
const decrypt = new Compress.decryptStream ( gateway.password )
8594

8695

87-
const _socket = Net.createConnection ({ port: this.serverPort, host: this.serverIp }, () => {
96+
const _socket = Net.createConnection ({ port: gateway.gateWayPort, host: gateway.gateWayIpAddress }, () => {
8897
encrypt.write ( _data )
8998
})
9099

@@ -107,41 +116,20 @@ export default class gateWay {
107116

108117
public requestGetWay ( id: string, uuuu: VE_IPptpStream, userAgent: string, socket: Net.Socket ) {
109118
this.userAgent = userAgent
110-
const decrypt = new Compress.decryptStream ( this.password )
111-
const encrypt = new Compress.encryptStream ( this.password, 3000, ( str: string ) => {
112-
return this.request ( str )
119+
const gateway = this.getCurrentGateway ()
120+
const decrypt = new Compress.decryptStream ( gateway.password )
121+
const encrypt = new Compress.encryptStream ( gateway.password, 3000, ( str: string ) => {
122+
return this.request ( str, gateway )
113123
})
114124
const httpBlock = new Compress.getDecryptClientStreamFromHttp ()
115125
httpBlock.once ( 'error', err => {
116126
socket.end ( res._HTTP_404 )
117127
})
118-
const _socket = Net.createConnection ({ port: this.serverPort, host: this.serverIp }, () => {
128+
const _socket = Net.createConnection ({ port: gateway.gateWayPort||80, host: gateway.gateWayIpAddress }, () => {
119129

120130
encrypt.write ( Buffer.from ( JSON.stringify ( uuuu ), 'utf8' ))
121131
})
122132
encrypt.pipe ( _socket ).pipe ( httpBlock ).pipe ( decrypt ).pipe ( socket ).pipe ( encrypt )
123-
124-
}
125-
126-
public requestGetWayTest ( id: string, uuuu: VE_IPptpStream, userAgent: string, socket: Net.Socket ) {
127-
console.log ('connect to test port!')
128-
const _socket = Net.createConnection ({ port: this.serverPort + 1, host: this.serverIp })
129-
130-
_socket.on ( 'connect', () => {
131-
const ls = new Compress.printStream ('>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
132-
const ls1 = new Compress.printStream ('<<<<<<<<<<<<<<<<<<<<<<<<<<<<')
133-
_socket.pipe ( socket ).pipe ( _socket )
134-
const _buf = Buffer.from ( otherRequestForNet ( Buffer.from ( JSON.stringify ( uuuu ), 'utf8' ).toString ( 'base64' ), this.serverIp, this.serverPort, this.userAgent ), 'utf8' )
135-
_socket.write ( _buf )
136-
137-
})
138-
139-
_socket.on ( 'end', () => {
140-
return console.log ( 'test gateway END' )
141-
})
142-
143-
_socket.on ( 'error', error => {
144-
return console.log ( 'test gateway ERROR:', error.message )
145-
})
133+
console.log (`new requestGetWay use gateway[${ gateway.gateWayIpAddress }]`)
146134
}
147135
}

app/proxyServer.ts

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ const httpProxy = ( clientSocket: Net.Socket, buffer: Buffer, useGatWay: boolean
295295
const isIp = Net.isIP ( hostName )
296296
const hostIp: domainData = ! isIp ? domainListPool.get ( hostName ) : { dns: [{ family: isIp, address: hostName, expire: null, connect: [] }], expire: null }
297297

298-
if ( ! hostIp ) {
298+
if ( ! hostIp && ! this.useGatWay ) {
299299

300300
return isAllBlackedByFireWall ( hostName, ip6, gatway, userAgent, domainListPool, ( err, _hostIp ) => {
301301
if ( err ) {
@@ -361,7 +361,8 @@ export class proxyServer {
361361
private hostGlobalIpV6: string = null
362362
private network = false
363363
private getGlobalIpRunning = false
364-
public gateway = new gateWay ( this.serverIp, this.serverPort, this.password )
364+
public gateway = new gateWay ( this.multipleGateway )
365+
365366
private saveWhiteIpList () {
366367
if ( this.whiteIpList.length > 0 )
367368
Fs.writeFile ( Path.join( __dirname, whiteIpFile ), JSON.stringify( this.whiteIpList ), { encoding: 'utf8' }, err => {
@@ -393,16 +394,15 @@ export class proxyServer {
393394

394395
const domain = data
395396
if ( ! domain )
396-
return console.log ( `[${ gateWay.serverIp } : ${ gateWay.serverPort }] Gateway connect Error!` )
397-
console.log ( `[${ gateWay.serverIp } : ${ gateWay.serverPort }] Gateway connect success!` )
397+
return console.log ( `[] Gateway connect Error!` )
398398
console.log ( '****************************************' )
399399

400400
})
401401

402402
}
403403

404404
constructor ( public whiteIpList: string[], public domainListPool: Map < string, domainData >, private localProxyServerIP: string,
405-
private port: number, private securityPath: string, private serverIp: string, private serverPort: number, private password: string, public checkAgainTimeOut: number,
405+
private port: number, private securityPath: string, public checkAgainTimeOut: number, private multipleGateway: multipleGateway[],
406406
public connectHostTimeOut: number, public useGatWay: boolean, public domainBlackList: string[] ) {
407407
this.getGlobalIp ( this.gateway )
408408
let socks = null
@@ -451,24 +451,20 @@ export class proxyServer {
451451
})
452452

453453
server.listen ( port, () => {
454-
console.log (`remote server: [${ serverIp }]:[${ serverPort }]`)
455454
return console.log ( 'proxy start success on port :', port, 'security path = ', securityPath )
456-
457455
})
458456

459457

460458

461459
}
462460

463461
public changeDocker ( data: IConnectCommand ) {
464-
if ( !data.gateWayIpAddress || !data.gateWayPort || !data.imapData.randomPassword ) {
465-
return saveLog (`ERROR: changeDocker data ERROR: gateWayIpAddress [${ data.gateWayIpAddress }] gateWayPort [${ data.gateWayPort }] data.imapData.randomPassword [${ data.imapData.randomPassword }]`)
462+
if ( !data.requestMultipleGateway && (!data.gateWayIpAddress || !data.gateWayPort || !data.imapData.randomPassword ) || data.requestMultipleGateway > 1 && ( !data.multipleGateway || data.multipleGateway.length !== data.requestMultipleGateway )) {
463+
return saveLog ( `ERROR: changeDocker data ERROR: gateWayIpAddress [${ data.gateWayIpAddress }] gateWayPort [${ data.gateWayPort }] data.imapData.randomPassword [${ data.imapData.randomPassword }]`)
466464
}
467-
this.serverIp = data.gateWayIpAddress
468-
this.serverPort = data.gateWayPort
469-
this.password = data.imapData.randomPassword
470-
this.gateway = new gateWay ( this.serverIp, this.serverPort, this.password )
471-
saveLog (`changeDocker gateWayIpAddress [${ data.gateWayIpAddress }] gateWayPort [${ data.gateWayPort }] data.imapData.randomPassword [${ data.imapData.randomPassword }]`)
465+
this.multipleGateway = data.multipleGateway
466+
this.gateway = new gateWay ( this.multipleGateway )
467+
saveLog (`changeDocker [${ JSON.stringify ( this.multipleGateway )}]`)
472468
}
473469

474470
}
@@ -494,14 +490,11 @@ const saveLog = ( log: string ) => {
494490
let server: proxyServer = null
495491
remote.getCurrentWindow().once ( 'firstCallBack', ( data: IConnectCommand ) => {
496492
saveLog ( `************************** start proxyServer *****************************\r\n ${ JSON.stringify( data )}\r\n` )
497-
server = new proxyServer ([], new Map(), data.localServerIp, data.localServerPort, 'pac', data.gateWayIpAddress, data.gateWayPort, data.imapData.randomPassword,
498-
5000, 50000, data.AllDataToGateway, [] )
499-
493+
console.log (`with gateway = [${data.multipleGateway}]`)
494+
server = new proxyServer ( [], new Map(), data.localServerIp, data.localServerPort, 'pac', 5000, data.multipleGateway, 50000, data.AllDataToGateway, [] )
500495
})
501496
remote.getCurrentWindow().on( 'changeDocker', ( data: IConnectCommand ) => {
502497
saveLog ( `got changeDocker event! data [${ JSON.stringify ( data )}]`)
503498
server.changeDocker ( data )
504499
})
505-
506-
507500
remote.getCurrentWindow().emit ( 'first' )

app/public/scripts/home.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,7 @@ const infoDefine = [
596596
unavailable: '准备中',
597597
proxyDomain: '域名解释全程使用QTGate代理服务器端',
598598
setupCardTitle: '使用连接技术:',
599+
MultipleGateway: '同时使用代理服务器数:',
599600
dataTransfer: '数据通讯:',
600601
dataTransfer_datail: ['全程使用代理服务器', '当本地不能够到达目标主机时使用'],
601602
proxyDataCache: '浏览数据本地缓存:',
@@ -1141,6 +1142,7 @@ const infoDefine = [
11411142
unavailable: '準備しています',
11421143
proxyDomain: 'ドメイン検索はQTGateゲットウェイ側に依頼します。',
11431144
setupCardTitle: '接続技術:',
1145+
MultipleGateway: '同時使用ゲットウェイ数:',
11441146
dataTransfer: '通信データは:',
11451147
dataTransfer_datail: ['全てのデータをOPN経由', 'ターゲットサーバ到達不能時だけ'],
11461148
proxyDataCache: 'Webキャッシュ:',
@@ -1332,7 +1334,7 @@ const infoDefine = [
13321334
proxyServerIp: '<p>Proxy setup: <span style="color: red;">Automatic or Auto-Config</span></p>',
13331335
proxyServerPort: 'HTTP & HTTPS proxy setup:',
13341336
proxyServerPassword: 'SOCKS proxy setup:',
1335-
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.',
1337+
title: 'Local proxy server is running at background. MacOS and windows user may close this window. All other devices can access internet via local proxy setup to use the QTGate OPN.',
13361338
title1: 'MacOS proxy setup',
13371339
info: [{
13381340
title: 'Open the control panel, click on network.',
@@ -1491,12 +1493,12 @@ const infoDefine = [
14911493
emailNotVerifi: 'Key pair has not been signed by QTGate yet.',
14921494
emailVerified: 'Key pair signed by QTGate.',
14931495
NickName: 'Nick name:',
1494-
creatDate: 'Key pair creation date:',
1495-
keyLength: 'Key pair bit Length:',
1496+
creatDate: 'Creation date:',
1497+
keyLength: 'Bit Length:',
14961498
password: '5-character minimum password.',
14971499
password1: 'Key pair password.',
14981500
logout: 'Logout',
1499-
keyID: 'Key pair ID:',
1501+
keyID: 'ID:',
15001502
deleteKeyPairInfo: 'Note: By deleting your key pair, you will lose your current account settings. You will need to set up QTGate account settings again. If your email address is the same as the one used previously, you may restore your QTGate account balance.',
15011503
delete: 'Delete',
15021504
locked: 'Please enter your key pair password to continue.',
@@ -1585,9 +1587,10 @@ const infoDefine = [
15851587
unavailable: 'Unavailable',
15861588
proxyDomain: 'Domain lookup via QTGate gateway side.',
15871589
setupCardTitle: 'connecting with:',
1590+
MultipleGateway: 'Gateway count:',
15881591
dataViaGateway: 'All internet data transfered via QTGate gateway.',
15891592
dataTransfer: 'Data:',
1590-
dataTransfer_datail: ['All data on QTGate gateway.', `Data on QTGate gateway only when cannot connect to target server.`],
1593+
dataTransfer_datail: ['All data on QTGate gateway.', `Only when cannot connect to target server.`],
15911594
proxyDataCache: 'Web cache:',
15921595
proxyDataCache_detail: ['Yes', 'No'],
15931596
clearCache: 'Delete all cache now',
@@ -2000,6 +2003,7 @@ const infoDefine = [
20002003
unavailable: '準備中',
20012004
proxyDomain: '域名解釋全程使用QTGate代理伺服器端',
20022005
setupCardTitle: '使用連接技術:',
2006+
MultipleGateway: '同時使用代理服務器數:',
20032007
connectQTGate: '正在獲得代理伺服器區域信息...',
20042008
dataTransfer: '數據通訊:',
20052009
dataTransfer_datail: ['全程使用QTGate代理伺服器', '當本地不能夠到達目標伺服器時使用'],
@@ -2294,7 +2298,9 @@ const dummyIConnectCommand = {
22942298
connectPeer: null,
22952299
connectType: null,
22962300
localServerIp: null,
2297-
localServerPort: null
2301+
localServerPort: null,
2302+
account: null,
2303+
AllDataToGateway: null,
22982304
};
22992305
var view_layout;
23002306
(function (view_layout) {
@@ -2787,6 +2793,8 @@ var view_layout;
27872793
this.QTGateRegionInfo = ko.observable(false);
27882794
this.QTGateConnect_SelectTech = ko.observable(-1);
27892795
this.QTGateConnect1 = ko.observable('');
2796+
this.QTGateMultipleGateway = ko.observable(1);
2797+
this.QTGateMultipleGatewayPool = ko.observableArray([1, 2]);
27902798
this.QTGateConnect2 = ko.observable(false);
27912799
this.QTGateConnectSelectImap = ko.observable(-1);
27922800
this.QTGateAllData = ko.observable(false);
@@ -3475,7 +3483,7 @@ var view_layout;
34753483
this.ConnectGatewayShow(true);
34763484
const body = $("html, body");
34773485
body.stop().animate({ scrollTop: 0 }, 100, 'swing', () => {
3478-
return this.overflowShow(false);
3486+
return this.overflowShow(true);
34793487
});
34803488
return $('.popupField').popup({
34813489
on: 'click',
@@ -3512,7 +3520,9 @@ var view_layout;
35123520
AllDataToGateway: !this.QTGateConnect2(),
35133521
error: null,
35143522
fingerprint: null,
3515-
localServerIp: null
3523+
localServerIp: null,
3524+
multipleGateway: [],
3525+
requestMultipleGateway: this.QTGateMultipleGateway()
35163526
};
35173527
data.error(-1);
35183528
//root.QTGateConnectRegionActive ( false )

0 commit comments

Comments
 (0)