keewebhttp: fix server restart
This commit is contained in:
parent
3d2046260a
commit
969a6f83e0
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"version": "0.0.1",
|
||||
"version": "0.0.2",
|
||||
"manifestVersion": "0.1.0",
|
||||
"name": "keewebhttp",
|
||||
"description": "KeeWebHttp allows to use browser extensions with KeeWeb",
|
||||
|
@ -11,7 +11,8 @@
|
|||
"licence": "MIT",
|
||||
"url": "https://plugins.keeweb.info/plugins/keewebhttp",
|
||||
"resources": {
|
||||
"js": "EhaKYdn0BmZ5u0V3PNNlsvTUF1WkL2vFnFS8eYw2VFf672HPnlDTOIO28otTP94IdPiGhSYiQM6q1wuUSBf7GGoqeJfTEXL3ZmcNXU9ahjFoEdTQcKtOdgUBlujvGeuxHLofmPdgnVnD5Jq/626SfSxRt+ujdrEzffHQsaMzDdhXFl48ghWsa0bptHpODCVHd/JUXan6Ad5F8MJ2c2bbKGPpoZlLudpCD+EyrIyV8fZyW7IFUHJmFujZTpjK0ZNVtv6Ama9n7GMUSuTOnMSjhr6a9GLC9kJDnQ0NSG1ufANMmx25OC5OPECQphPWh7OM5WJH2xspgcVgqViHCFpuag=="
|
||||
"js": "t09aSrObT2zZUcu1VyVkVW/w/dlOS3Cw/XZJg9pMf4J7ufbdJDDdNEqguu3sZKJUt6l9cm1AbZc8IUCnQKLR9X0U9y7MkH0l2HwaG0Cs8kpqSeQtuDfFJsMGHFxidn6Hb322xFhQrVH2uIr/5LOKsboPuQ0MI7TbzbOE22WL+E2OYJ7l8Z8U3Q1B1emvXVeZUDQeGUs2And9i4Dh1OwflsUX/SogMwgG8HIPJlcgsboT4wu1w77XexF0+mc3TZKGTWo2cEawCdx9QbhNtWv9MhCFdDUioS8hgfDgkmWlz0PHQuF4fWoq1gcB3jZjq4oBzj7Uf7dc+jJf2+YITptYWw=="
|
||||
},
|
||||
"publicKey": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0oZB2Kt7AzRFNqf8FuO3C3kepHPAIQYiDPYdQxHcsiaFCwyKVx6K1cE/3vBhb8/2rj+QIIWNfAAuu1Y+2VK90ZBeq6HciukWzQRO/HWhfdy0c7JwDAslmyGI5olj0ZQkNLhkde1MiMxjDPpRhZtdJaryVO5cFJaJESpv3dV6m0qXsaQCluWYOSNfSjP9C8o2zRVjSi3ZQZnZIV5pnk9K2MtlZIPXrN9iJiM5zZ9DTSnqApI6dC9mX4R3LvGN+GTovm9C8Crl+qb106nGRR3LcweicDnPyMtZLa/E0DBpWYxUVLDp6WeLhxoUBr+6+t3Xp9IDnPoANDQXJXD0f1vQxQIDAQAB"
|
||||
}
|
||||
"publicKey": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0oZB2Kt7AzRFNqf8FuO3C3kepHPAIQYiDPYdQxHcsiaFCwyKVx6K1cE/3vBhb8/2rj+QIIWNfAAuu1Y+2VK90ZBeq6HciukWzQRO/HWhfdy0c7JwDAslmyGI5olj0ZQkNLhkde1MiMxjDPpRhZtdJaryVO5cFJaJESpv3dV6m0qXsaQCluWYOSNfSjP9C8o2zRVjSi3ZQZnZIV5pnk9K2MtlZIPXrN9iJiM5zZ9DTSnqApI6dC9mX4R3LvGN+GTovm9C8Crl+qb106nGRR3LcweicDnPyMtZLa/E0DBpWYxUVLDp6WeLhxoUBr+6+t3Xp9IDnPoANDQXJXD0f1vQxQIDAQAB",
|
||||
"desktop": true
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ const http = nodeRequire('http');
|
|||
const crypto = nodeRequire('crypto');
|
||||
const fs = nodeRequire('fs');
|
||||
const path = nodeRequire('path');
|
||||
const electron = nodeRequire('electron');
|
||||
|
||||
const AutoType = require('auto-type/index');
|
||||
const AutoTypeFilter = require('auto-type/auto-type-filter');
|
||||
|
@ -13,7 +14,6 @@ const Alerts = require('comp/alerts');
|
|||
// const appModel = ...; TODO: use AppModel.instance
|
||||
|
||||
const Version = '1.8.4.2';
|
||||
const KeyPrefix = 'plugin:keewebhttp:key_';
|
||||
const SignatureError = 'Request signature missing';
|
||||
|
||||
const keys = {};
|
||||
|
@ -58,6 +58,16 @@ function init() {
|
|||
}
|
||||
logger.debug(`Server running at http://${hostname}:${port}/`);
|
||||
});
|
||||
server.on('connection', function(conn) {
|
||||
const key = conn.remoteAddress + ':' + conn.remotePort;
|
||||
server.conn[key] = conn;
|
||||
conn.on('close', () => {
|
||||
if (server) {
|
||||
delete server.conn[key];
|
||||
}
|
||||
});
|
||||
});
|
||||
server.conn = {};
|
||||
}
|
||||
|
||||
function handleRequest(req) {
|
||||
|
@ -130,7 +140,7 @@ function encrypt(resp, value) {
|
|||
|
||||
function verifyRequest(req) {
|
||||
if (req.Id && !keys[req.Id]) {
|
||||
keys[req.Id] = AutoType.appModel.settings.get(KeyPrefix + req.Id);
|
||||
// TODO: get key
|
||||
}
|
||||
const decrypted = decrypt(req, req.Verifier);
|
||||
if (decrypted !== req.Nonce) {
|
||||
|
@ -167,6 +177,7 @@ function testAssociate(req) {
|
|||
|
||||
function associate(req) {
|
||||
verifyRequest(req);
|
||||
electron.remote.app.getMainWindow().focus();
|
||||
return new Promise((resolve, reject) => {
|
||||
Alerts.yesno({
|
||||
header: 'Plugin Connecting',
|
||||
|
@ -177,7 +188,6 @@ function associate(req) {
|
|||
});
|
||||
}).then(() => {
|
||||
const id = 'KeeWeb_' + new Date().toISOString() + '_' + crypto.randomBytes(16).toString('hex');
|
||||
AutoType.appModel.settings.set(KeyPrefix + id, req.Key);
|
||||
keys[id] = req.Key;
|
||||
fs.writeFileSync(path.join(__dirname, 'keys.json'), JSON.stringify(keys));
|
||||
return wrapResponse({
|
||||
|
@ -244,6 +254,9 @@ function generatePassword(req) {
|
|||
module.exports.uninstall = function() {
|
||||
if (server) {
|
||||
server.close();
|
||||
for (const key of Object.keys(server.conn)) {
|
||||
server.conn[key].destroy();
|
||||
}
|
||||
server = null;
|
||||
}
|
||||
uninstalled = true;
|
||||
|
|
Loading…
Reference in New Issue