Skip to content

Commit 65889b4

Browse files
committed
20191024-1
1 parent 86a0fbc commit 65889b4

33 files changed

+3672
-2145
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ CoNET平台集成了一系列應用來使用[CoNET](https://github.com/QTGate/Co
1515

1616
## Download ダウンロード 下載
1717

18-
### Come soon./準備中/即將推出
18+
# Come soon./準備中/即將推出
1919
CoNET official node have not ready yet./CoNET公式ノード準備中/CoNET官方節點停機中
2020

2121
## CoNET APPs

app/localWebServer.js

Lines changed: 53 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
Object.defineProperty(exports, "__esModule", { value: true });
1818
const Express = require("express");
1919
const Path = require("path");
20-
const cookieParser = require("cookie-parser");
2120
const HTTP = require("http");
2221
const SocketIo = require("socket.io");
2322
const Tool = require("./tools/initSystem");
@@ -29,9 +28,11 @@ const Uuid = require("node-uuid");
2928
const Imap = require("./tools/imap");
3029
const coNETConnect_1 = require("./tools/coNETConnect");
3130
const Crypto = require("crypto");
32-
const coSearchServer_1 = require("./tools/coSearchServer");
33-
const JSZip = require("jszip");
31+
const mime = require("mime-types");
3432
Express.static.mime.define({ 'multipart/related': ['mht'] });
33+
//Express.static.mime.define({ 'message/rfc822' : ['mhtml','mht'] })
34+
Express.static.mime.define({ 'application/x-mimearchive': ['mhtml', 'mht'] });
35+
Express.static.mime.define({ 'multipart/related': ['mhtml', 'mht'] });
3536
let logFileFlag = 'w';
3637
const conetImapAccount = /^qtgate_test\d\d?@icloud.com$/i;
3738
const saveLog = (err) => {
@@ -106,27 +107,17 @@ class localServer {
106107
key: ''
107108
}];
108109
this.requestPool = new Map();
110+
//Express.static.mime.define({ 'message/rfc822' : ['mhtml','mht'] })
111+
//Express.static.mime.define ({ 'multipart/related' : ['mhtml','mht'] })
112+
Express.static.mime.define({ 'application/x-mimearchive': ['mhtml', 'mht'] });
109113
this.expressServer.set('views', Path.join(__dirname, 'views'));
110114
this.expressServer.set('view engine', 'pug');
111-
this.expressServer.use(cookieParser());
112115
this.expressServer.use(Express.static(Tool.QTGateFolder));
113116
this.expressServer.use(Express.static(Path.join(__dirname, 'public')));
114117
this.expressServer.use(Express.static(Path.join(__dirname, 'html')));
115118
this.expressServer.get('/', (req, res) => {
116119
res.render('home', { title: 'home', proxyErr: false });
117120
});
118-
this.expressServer.get('/CoSearch', (req, res) => {
119-
const sessionHash = req.query.sessionHash;
120-
const _index = this.sessionHashPool.indexOf(sessionHash);
121-
if (!sessionHash || _index < 0) {
122-
console.log(`sessionHashPool have not this [${sessionHash}]!\n${this.sessionHashPool}`);
123-
return res.render('home', { title: 'home', proxyErr: false });
124-
}
125-
this.socketServer_CoSearch.once('connection', socket => {
126-
return this.socketServer_CoSearchConnected(socket, sessionHash);
127-
});
128-
return res.render('CoSearch', { title: 'CoSearch', sessionHash: sessionHash });
129-
});
130121
this.socketServer.on('connection', socker => {
131122
return this.socketServerConnected(socker);
132123
});
@@ -151,7 +142,7 @@ class localServer {
151142
});
152143
}
153144
catchCmd(mail, uuid) {
154-
console.log(`Get response from CoNET [${uuid}] length [${mail.length}]`);
145+
console.log(`Get response from CoNET uuid [${uuid}] length [${mail.length}]`);
155146
const socket = this.requestPool.get(uuid);
156147
if (!socket) {
157148
return console.log(`Get cmd that have no matched socket \n\n`, mail);
@@ -263,71 +254,61 @@ class localServer {
263254
}
264255
return this.tryConnectCoNET(socket, sessionHash);
265256
});
266-
socket.on('requestActivEmail', CallBack1 => {
267-
saveLog(`on requestActivEmail`);
268-
const com = {
269-
command: 'requestActivEmail',
270-
Args: [],
271-
error: null,
272-
subCom: null
273-
};
274-
return this.sendRequest(socket, com, sessionHash, (err, res) => {
275-
console.log(`requestActivEmail sendrequest callback! `);
276-
return CallBack1(err, res);
277-
});
278-
});
279257
socket.on('checkActiveEmailSubmit', (text, CallBack1) => {
280-
saveLog(`on checkActiveEmailSubmit`);
281-
if (!text || !text.length || !/^-----BEGIN PGP MESSAGE-----/.test(text)) {
282-
CallBack1(0);
283-
return saveLog(`checkActiveEmailSubmit, no text.length ! [${text}]`);
284-
}
285-
return Tool.decryptoMessage(this.openPgpKeyOption, text, (err, data) => {
286-
if (err) {
287-
CallBack1(1);
288-
return saveLog(`checkActiveEmailSubmit, decryptoMessage error [${err.message ? err.message : null}]\n${text}`);
289-
}
290-
let pass = null;
291-
try {
292-
pass = JSON.parse(data);
293-
}
294-
catch (ex) {
295-
return CallBack1(1);
296-
}
297-
const com = {
298-
command: 'activePassword',
299-
Args: [pass],
300-
error: null,
301-
subCom: null
302-
};
303-
console.log(Util.inspect(com));
304-
return this.sendRequest(socket, com, sessionHash, (err, data) => {
258+
console.log(`on checkActiveEmailSubmit`);
259+
const key = Buffer.from(text, 'base64').toString();
260+
if (key && key.length) {
261+
console.log(`active key success! \n[${key}]`);
262+
this.keyPair.publicKey = this.config.keypair.publicKey = key;
263+
this.keyPair.verified = this.config.keypair.verified = true;
264+
return Tool.saveConfig(this.config, err => {
305265
if (err) {
306-
return CallBack1(err);
307-
}
308-
if (data.error > -1) {
309-
return CallBack1(null, data);
310-
}
311-
const key = Buffer.from(data.Args[0], 'base64').toString();
312-
if (key && key.length) {
313-
saveLog(`active key success! \n[${key}]`);
314-
CallBack1();
315-
this.keyPair.publicKey = this.config.keypair.publicKey = key;
316-
this.keyPair.verified = this.config.keypair.verified = true;
317-
return Tool.saveConfig(this.config, err => {
318-
if (err) {
319-
saveLog(`Tool.saveConfig return Error: [${err.message}]`);
320-
}
321-
});
266+
saveLog(`Tool.saveConfig return Error: [${err.message}]`);
322267
}
268+
CallBack1();
323269
});
324-
});
270+
}
325271
});
326272
socket.on('doingRequest', (uuid, request, CallBack) => {
327273
this.requestPool.set(uuid, socket);
328274
saveLog(`doingRequest on ${uuid}`);
329275
return this.CoNETConnectCalss.requestCoNET_v1(uuid, request, CallBack);
330276
});
277+
socket.on('getFilesFromImap', (files, CallBack) => {
278+
console.log(`socket.on ('getFilesFromImap')`, files);
279+
if (typeof files !== 'string' || !files.length) {
280+
return CallBack(new Error('invalidRequest'));
281+
}
282+
const _files = files.split(',');
283+
console.log(`socket.on ('getFilesFromImap') _files = [${_files}] _files.length = [${_files.length}]`);
284+
let ret = '';
285+
return Async.eachSeries(_files, (n, next) => {
286+
console.log(`Async.eachSeries _files[${n}]`);
287+
return this.CoNETConnectCalss.getFile(n, (err, data) => {
288+
if (err) {
289+
return next(err);
290+
}
291+
ret += data.toString();
292+
return next();
293+
});
294+
}, err => {
295+
if (err) {
296+
return CallBack(err);
297+
}
298+
console.log(`******************** getFilesFromImap success all fies!\n\n${ret.length}\n\n`);
299+
return CallBack(null, ret);
300+
});
301+
});
302+
socket.on('sendMedia', (uuid, rawData, CallBack) => {
303+
return this.CoNETConnectCalss.sendDataToUuidFolder(Buffer.from(rawData).toString('base64'), uuid, CallBack);
304+
});
305+
socket.on('mime', (_mime, CallBack) => {
306+
let y = mime.lookup(_mime);
307+
if (!y) {
308+
return CallBack(new Error('no mime'));
309+
}
310+
return CallBack(null, y);
311+
});
331312
}
332313
doingCheckImap(socket) {
333314
this.imapConnectData.imapTestResult = false;
@@ -583,14 +564,5 @@ class localServer {
583564
console.log(`this.sessionHashPool.push!\n${this.sessionHashPool}\n${this.sessionHashPool.length}`);
584565
});
585566
}
586-
socketServer_CoSearchConnected(socket, sessionHash) {
587-
const clientName = `[${socket.id}][ ${socket.conn.remoteAddress}]`;
588-
//saveLog (`socketServer_CoSearchConnected make new coSearceServer for [${ clientName }]`)
589-
let _coSearchServer = new coSearchServer_1.default(sessionHash, socket, saveLog, clientName, this);
590-
socket.once('disconnect', reason => {
591-
_coSearchServer = null;
592-
return saveLog(`socketServer_CoSearchConnected destroy coSearceServer for [${clientName}]`);
593-
});
594-
}
595567
}
596568
exports.default = localServer;

0 commit comments

Comments
 (0)