Skip to content

Commit 2cd2015

Browse files
Peter XiePeter Xie
authored andcommitted
v0.9.3
1 parent 89e4a55 commit 2cd2015

File tree

20 files changed

+3343
-434
lines changed

20 files changed

+3343
-434
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ QTGATE提供本地Proxy服務器對應HTTP, HTTPS, SOCKS 4,4a,5。其他設備
1616
このプロジェクトはQTGATE端末用ソフトです.
1717
QTGATEとは、eMailの通信プロトコルIMAPを使用して、端末とサーバの間に、仮想のネットワークトンネルを構築し、さらにVPNをカプセル化にしたことで、どんな端末からも利用することができます。QTGATEの一番重要な特徴は,端末とサーバの通信がIPアドレスではなく、一つのeMailアカウントを使います。それによって世界中に安全と自由な通信ができるようになります。
1818
QTGATEはローカルプロキシサーバを提供して、HTTP, HTTPS, SOCKS 4,4a,5をカバーすることで、他のデバイスはローカルプロキシサーバを経由QTGATEサービスをご利用いただきます。
19-
![http protocol](/resources/startScreen.jpg?raw=true)
19+
![http protocol](/app/public/html/canada150.html?raw=true)
2020

2121
![http protocol](/resources/vpn.email11.jpg?raw=true)
2222

app/imap.js

Lines changed: 66 additions & 44 deletions
Large diffs are not rendered by default.

app/imap.ts

Lines changed: 62 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import * as Crypto from 'crypto'
2626
import * as Util from 'util'
2727
import { join } from 'path'
2828
import { homedir }from 'os'
29+
import { setTimeout, clearTimeout } from 'timers';
2930

3031
const MAX_INT = 9007199254740992
3132
const debug = true
@@ -158,15 +159,16 @@ class ImapServerSwitchStream extends Stream.Transform {
158159
this.doCommandCallback ( null, commandLine )
159160
return callback ()
160161
}
161-
this.doCommandCallback ( new Error ( cmdArray.slice (2).join(' ')))
162+
const errs = cmdArray.slice (2).join(' ')
163+
this.doCommandCallback ( new Error (errs ))
162164
return callback ()
163165

164166
}
165167
default:
166168
return this.serverCommandError ( new Error (`_commandPreProcess got switch default error!` ), callback )
167169
}
168170
}
169-
this.login ( commandLine, cmdArray, _next, callback )
171+
return this.login ( commandLine, cmdArray, _next, callback )
170172
}
171173

172174
private checkFetchEnd () {
@@ -215,11 +217,11 @@ class ImapServerSwitchStream extends Stream.Transform {
215217
return
216218
}
217219

218-
const _buf = this._buffer.slice(0, index)
219-
if (_buf.length) {
220-
return this.preProcessCommane(_buf.toString(), next, () => {
220+
const _buf = this._buffer.slice ( 0, index )
221+
if ( _buf.length ) {
222+
return this.preProcessCommane ( _buf.toString (), next, () => {
221223
this._buffer = this._buffer.slice ( index + 2 )
222-
return doLine()
224+
return doLine ()
223225
})
224226
}
225227
if (! this.callback ) {
@@ -332,7 +334,7 @@ class ImapServerSwitchStream extends Stream.Transform {
332334
this.flagsDeleted ( newMailIds, next )
333335
},
334336
( data, next ) => {
335-
saveLog (`Async.waterfall ( data[${ typeof data }], next ${ typeof next}) `)
337+
336338
this.expunge ( next )
337339
}
338340
], ( err, newMail ) => {
@@ -459,12 +461,16 @@ class ImapServerSwitchStream extends Stream.Transform {
459461

460462
private login ( text: string, cmdArray: string[], next, _callback ) {
461463

462-
this.doCommandCallback = ( err ) => {
464+
this.doCommandCallback = ( err: Error ) => {
465+
463466
if ( ! err ) {
467+
saveLog (`login this.doCommandCallback no err `)
464468
return this.capability ()
465469
}
466-
return this.imapServer.destroyAll( err )
470+
471+
return this.imapServer.destroyAll ( err )
467472
}
473+
468474
this.commandProcess = ( text: string, cmdArray: string[], next, callback ) => {
469475
switch ( cmdArray[0] ) {
470476
case '+':
@@ -475,7 +481,9 @@ class ImapServerSwitchStream extends Stream.Transform {
475481
return callback ()
476482
}
477483
}
484+
478485
switch ( cmdArray[0] ) {
486+
479487
case '*': { ///// *
480488
// check imap server is login ok
481489
if ( /^ok$/i.test ( cmdArray [1]) && this.first ) {
@@ -492,6 +500,7 @@ class ImapServerSwitchStream extends Stream.Transform {
492500
return _callback ()
493501
}
494502
default:
503+
495504
return this.serverCommandError ( new Error ( `login switch default ERROR!` ), _callback )
496505
}
497506

@@ -806,10 +815,10 @@ class ImapServerSwitchStream extends Stream.Transform {
806815
}
807816

808817
private expunge ( callback ) {
809-
console.trace (callback.toString())
818+
810819
let newSwitchRet = false
811820
this.doCommandCallback = ( err ) => {
812-
console.trace (callback.toString())
821+
813822
return callback ( err, newSwitchRet )
814823
}
815824
this.commandProcess = ( text: string, cmdArray: string[], next , _callback ) => {
@@ -919,6 +928,9 @@ export class qtGateImap extends Event.EventEmitter {
919928
constructor ( public IMapConnect: imapConnect, public listenFolder: string, private isEachMail: boolean, public deleteBoxWhenEnd: boolean, public writeFolder: string, private debug: boolean, public newMail: ( mail ) => void ) {
920929
super ()
921930
this.connect ()
931+
this.once (`error`, err => {
932+
saveLog (`qtGateImap on error [${err.messag}]` )
933+
})
922934
/*
923935
process.once ( 'uncaughtException', err => {
924936
console.log ( err )
@@ -1135,21 +1147,20 @@ export const imapAccountTest = ( IMapConnect: imapConnect, CallBack ) => {
11351147

11361148
}
11371149

1138-
const pingPongTimeOut = 1000 * 10
1150+
const pingPongTimeOut = 1000 * 15
11391151

11401152
export class imapPeer extends Event.EventEmitter {
11411153
private mailPool = []
1142-
private keepConnectTime: NodeJS.Timer = null
11431154
private rImapReady = false
1144-
private waitingReplyTimeOut = null
1145-
private lastReplyPongTime = null
1155+
private waitingReplyTimeOut: NodeJS.Timer = null
11461156
private pingUuid = null
11471157
private doingDestroy = false
11481158
private wImapReady = false
11491159
private peerReady = false
11501160
private sendFirstPing = false
11511161
public newMail: ( data: any ) => void
11521162

1163+
11531164
private mail ( email: Buffer ) {
11541165

11551166
const attr = getMailAttached ( email ).toString ()
@@ -1188,6 +1199,7 @@ export class imapPeer extends Event.EventEmitter {
11881199
return saveLog (`Invalid ping uuid`)
11891200
saveLog ( `imapPeer connected`)
11901201
this.pingUuid = null
1202+
clearTimeout ( this.waitingReplyTimeOut )
11911203
return this.emit ('ready')
11921204
}
11931205
return this.newMail (uu )
@@ -1201,9 +1213,12 @@ export class imapPeer extends Event.EventEmitter {
12011213
}
12021214

12031215
public trySendToRemote ( email: Buffer, CallBack ) {
1204-
if ( this.wImap ) {
1216+
if ( this.wImap && this.wImapReady ) {
12051217
return this.wImap.append ( email.toString ( 'base64' ), err => {
1206-
if ( err ) {
1218+
if ( err) {
1219+
if ( err.message && /TRYCREATE/i.test( err.message )) {
1220+
this.emit ('wFolder')
1221+
}
12071222
saveLog (`this.wImap.append ERROR: [${ err.message ? err.message : '' }]`)
12081223
}
12091224
return CallBack ( err )
@@ -1223,6 +1238,12 @@ export class imapPeer extends Event.EventEmitter {
12231238
})
12241239
})
12251240
}
1241+
1242+
private setTimeOutOfPing () {
1243+
return this.waitingReplyTimeOut = setTimeout (() => {
1244+
this.emit ( 'pingTimeOut' )
1245+
}, pingPongTimeOut)
1246+
}
12261247

12271248
public Ping () {
12281249

@@ -1232,7 +1253,9 @@ export class imapPeer extends Event.EventEmitter {
12321253
if ( err ) {
12331254
return saveLog ( `Ping enCrypto error: [${ err.message }]`)
12341255
}
1235-
this.trySendToRemote ( Buffer.from ( data ), () => {})
1256+
return this.trySendToRemote ( Buffer.from ( data ), () => {
1257+
return this.setTimeOutOfPing ()
1258+
})
12361259
})
12371260
}
12381261

@@ -1252,23 +1275,27 @@ export class imapPeer extends Event.EventEmitter {
12521275
}
12531276

12541277
private newWriteImap() {
1278+
saveLog (`newWriteImap`)
12551279
this.wImap = new qtGateImapwrite ( this.imapData, this.writeBox )
12561280

12571281
this.wImap.once ( 'end', err => {
12581282
saveLog ( `this.wImap.once end ! [${ err && err.message ? err.message : null }]!` )
12591283
this.wImap = null
1284+
this.wImapReady = false
12601285
if ( this.sendMailPool.length > 0 ) {
12611286
saveLog ( `this.wImap.once end ! sendMailPool.length > 0 [${ this.sendMailPool.length }] newWriteImap () ` )
12621287
return this.newWriteImap ()
12631288
}
12641289
})
12651290

12661291
this.wImap.once ( 'error', err => {
1267-
if ( err && err.message && /AUTH|certificate/i.test ( err.message )) {
1292+
if ( err && err.message && /AUTH|certificate|LOGIN/i.test ( err.message )) {
12681293
return this.destroy (1)
12691294
}
12701295
saveLog ( `imapPeer this.wImap on error [${ err.message }]`)
1271-
this.wImap.destroyAll(null)
1296+
this.wImapReady = false
1297+
this.wImap = null
1298+
//this.wImap.destroyAll(null)
12721299
})
12731300

12741301
this.wImap.once ( 'ready', () => {
@@ -1280,18 +1307,21 @@ export class imapPeer extends Event.EventEmitter {
12801307
}
12811308

12821309
this.sendFirstPing = true
1310+
this.Ping ()
12831311
if ( /outlook\.com/i.test ( this.imapData.imapServer )) {
12841312
saveLog ( `outlook support!`)
1285-
this.once ( 'wFolder', () => {
1313+
return this.once ( 'wFolder', () => {
12861314
saveLog ( `this.once ( 'wFolder') do makeWriteFolder!`)
1287-
return this.makeWriteFolder ()
1315+
return this.makeWriteFolder (() => {
1316+
return this.Ping ()
1317+
})
12881318
})
12891319
}
1290-
return this.Ping ()
12911320
})
12921321
}
12931322

12941323
private newReadImap() {
1324+
saveLog (`newReadImap!`)
12951325
this.rImap = new qtGateImapRead ( this.imapData, this.listenBox, false, false, email => {
12961326
this.mail ( email )
12971327
this.rImap.emit ('nextNewMail')
@@ -1309,17 +1339,19 @@ export class imapPeer extends Event.EventEmitter {
13091339
})
13101340
this.rImap.once ( 'error', err => {
13111341
saveLog ( `rImap on Error [${ err.message }]`)
1312-
if ( err && err.message && /AUTH|certificate/i.test ( err.message )) {
1342+
if ( err && err.message && /AUTH|certificate|LOGIN/i.test ( err.message )) {
13131343
return this.destroy (1)
13141344
}
13151345
this.rImap.destroyAll (null)
13161346

13171347
})
13181348
this.rImap.once ( 'end', err => {
1319-
saveLog (`rImap.once ( 'end' ) this.doingDestroy [${ this.doingDestroy }]`)
1349+
13201350
this.rImap = null
1321-
if ( !this.doingDestroy )
1351+
if ( !this.doingDestroy && !err ) {
13221352
return this.newReadImap ()
1353+
}
1354+
this.exit ( err )
13231355
})
13241356
}
13251357

@@ -1334,25 +1366,27 @@ export class imapPeer extends Event.EventEmitter {
13341366
this.newReadImap ()
13351367
}
13361368

1337-
private makeWriteFolder () {
1369+
private makeWriteFolder (CallBack) {
13381370

13391371
let uu = new qtGateImapRead ( this.imapData, this.writeBox, false, false, email => {})
13401372
uu.once ( 'ready', () => {
13411373
uu.destroyAll ( null )
13421374
this.pingUuid = null
13431375
this.wImap.destroyAll (null)
1376+
return CallBack ()
13441377
})
13451378
uu.once ( 'error', err => {
13461379
saveLog ( `makeWriteFolder error! do again!`)
13471380
uu = null
1348-
return this.makeWriteFolder ()
1381+
return this.makeWriteFolder ( CallBack )
13491382
})
13501383
uu.once ( 'end', () => {
13511384
uu = null
13521385
})
13531386
}
13541387

13551388
public destroy ( err?: number ) {
1389+
console.trace ('destroy')
13561390
if ( this.doingDestroy )
13571391
return
13581392
this.doingDestroy = true

app/public/css/canada150.css

Lines changed: 102 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/public/css/pages.css

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,14 @@ h1>.badge, h2>.badge, h3>.badge, h4>.badge,h5>.badge,h6>.badge {
389389
margin: 0px;
390390
display: block;
391391
width: 100%;
392+
position: absolute;
393+
}
394+
.coverNextButton {
395+
opacity: 0.5;
396+
background: cadetblue;
397+
}
398+
.coverNextButton:hover {
399+
opacity: 0.8;
392400
}
393401
.languageText {
394402
width: 100%;
@@ -400,7 +408,7 @@ h1>.badge, h2>.badge, h3>.badge, h4>.badge,h5>.badge,h6>.badge {
400408
opacity: 0.4;
401409
}
402410
.titleText{
403-
top:120px;
411+
top: 5em;
404412
text-align: center;
405413
z-index: 99;
406414
position: relative;
@@ -426,7 +434,7 @@ h1>.badge, h2>.badge, h3>.badge, h4>.badge,h5>.badge,h6>.badge {
426434
color: white!important;
427435
}
428436
.VideoBoxButtom {
429-
top: 230px;
437+
top: 22em;
430438
position: relative;
431439
width: 100%;
432440
z-index: 98;
@@ -438,7 +446,7 @@ h1>.badge, h2>.badge, h3>.badge, h4>.badge,h5>.badge,h6>.badge {
438446
}
439447
.company {
440448
top: -110px;
441-
left: 80%;
449+
left: 82%;
442450
width: 130px;
443451
font-weight: lighter!important;
444452
color: white;

app/public/favicon.ico

361 KB
Binary file not shown.

0 commit comments

Comments
 (0)