only create preflight channel if channels are enabled
This commit is contained in:
parent
7232d7f8f8
commit
d0edde7452
213
lib.overlay.js
213
lib.overlay.js
|
@ -11,6 +11,7 @@ const config = require('./lib.config');
|
||||||
const logic = require('./logic');
|
const logic = require('./logic');
|
||||||
const dialect = require('./lib.dialect');
|
const dialect = require('./lib.dialect');
|
||||||
const loki_crypt = require('./lib.loki_crypt');
|
const loki_crypt = require('./lib.loki_crypt');
|
||||||
|
const platformConfigUtil = require('./server/lib/lib.config');
|
||||||
|
|
||||||
// used for creating a default token for user 1
|
// used for creating a default token for user 1
|
||||||
const ADN_SCOPES = 'basic stream write_post follow messages update_profile files export';
|
const ADN_SCOPES = 'basic stream write_post follow messages update_profile files export';
|
||||||
|
@ -85,118 +86,126 @@ const setup = (cache, dispatcher) => {
|
||||||
dialect.setup({ dispatcher });
|
dialect.setup({ dispatcher });
|
||||||
storage.start(disk_config);
|
storage.start(disk_config);
|
||||||
|
|
||||||
dataAccess.getChannel(1, {}, async (err, chnl, meta) => {
|
// only set up a channels, if channels enabled (open group mode)
|
||||||
if (err) console.error('channel 1 get err', err);
|
if (platformConfigUtil.moduleEnabled('channels')) {
|
||||||
if (chnl && chnl.id) {
|
console.log('Open group mode detected')
|
||||||
const configWhitelistEnabled = !!disk_config.whitelist;
|
dataAccess.getChannel(1, {}, async (err, chnl, meta) => {
|
||||||
// do read permissions match?
|
if (err) console.error('channel 1 get err', err);
|
||||||
// write shouldn't matter, if you can't get a token/user, you can't write
|
if (chnl && chnl.id) {
|
||||||
const channelWhitelistEnabled = chnl.reader !== 0;
|
const configWhitelistEnabled = !!disk_config.whitelist;
|
||||||
console.log('configWhitelistEnabled', configWhitelistEnabled);
|
// do read permissions match?
|
||||||
console.log('channelWhitelistEnabled', channelWhitelistEnabled);
|
// write shouldn't matter, if you can't get a token/user, you can't write
|
||||||
if (configWhitelistEnabled != channelWhitelistEnabled) {
|
const channelWhitelistEnabled = chnl.reader !== 0;
|
||||||
console.log('Need to fix up channel permissions');
|
console.log('configWhitelistEnabled', configWhitelistEnabled);
|
||||||
// this will disable public reading of the channel
|
console.log('channelWhitelistEnabled', channelWhitelistEnabled);
|
||||||
|
if (configWhitelistEnabled != channelWhitelistEnabled) {
|
||||||
|
console.log('Need to fix up channel permissions');
|
||||||
|
// this will disable public reading of the channel
|
||||||
|
|
||||||
// would this work with proxy-admin system?
|
// would this work with proxy-admin system?
|
||||||
// 0 = public, 1 = any user (has token)
|
// 0 = public, 1 = any user (has token)
|
||||||
dataAccess.updateChannel(1, { reader: configWhitelistEnabled ? 1 : 0 }, function(err, channel) {
|
dataAccess.updateChannel(1, { reader: configWhitelistEnabled ? 1 : 0 }, function(err, channel) {
|
||||||
if (err) console.error('overlay updateChannel err', err);
|
if (err) console.error('overlay updateChannel err', err);
|
||||||
else console.log('updated channel permissions', channel);
|
else console.log('updated channel permissions', channel);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (configWhitelistEnabled) {
|
if (configWhitelistEnabled) {
|
||||||
// just make sure our owner is whitelisted for proxy mod actions
|
// just make sure our owner is whitelisted for proxy mod actions
|
||||||
console.log('checking', chnl.ownerid);
|
console.log('checking', chnl.ownerid);
|
||||||
if (chnl.ownerid) {
|
if (chnl.ownerid) {
|
||||||
const alreadyWhitelisted = await storage.isWhitelisted(chnl.ownerid);
|
const alreadyWhitelisted = await storage.isWhitelisted(chnl.ownerid);
|
||||||
if (!alreadyWhitelisted) {
|
if (!alreadyWhitelisted) {
|
||||||
console.log('whitelisting channel owner, userid:', chnl.ownerid);
|
console.log('whitelisting channel owner, userid:', chnl.ownerid);
|
||||||
logic.whitelistUserForServer(chnl.ownerid);
|
logic.whitelistUserForServer(chnl.ownerid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
return;
|
console.log('need to create initial channel');
|
||||||
}
|
// FIXME: user token_helpers's findOrCreateUser?
|
||||||
console.log('need to create initial channel');
|
dataAccess.getUser(1, async (err2, user, meta2) => {
|
||||||
// FIXME: user token_helpers's findOrCreateUser?
|
if (err2) console.error('get user 1 err', err2);
|
||||||
dataAccess.getUser(1, async (err2, user, meta2) => {
|
// if no user, create the user...
|
||||||
if (err2) console.error('get user 1 err', err2);
|
// user === null when D.N.E.
|
||||||
// if no user, create the user...
|
// console.log('user', user);
|
||||||
// user === null when D.N.E.
|
var privKey, pubKey;
|
||||||
// console.log('user', user);
|
if (!user || !user.length) {
|
||||||
var privKey, pubKey;
|
console.log('need to create initial user');
|
||||||
if (!user || !user.length) {
|
// block until this is complete
|
||||||
console.log('need to create initial user');
|
user = await new Promise((resolve, rej) => {
|
||||||
// block until this is complete
|
const ourKey = libsignal.curve.generateKeyPair();
|
||||||
user = await new Promise((resolve, rej) => {
|
privKey = ourKey.privKey;
|
||||||
const ourKey = libsignal.curve.generateKeyPair();
|
pubKey = ourKey.pubKey;
|
||||||
privKey = ourKey.privKey;
|
var pubKeyhex = bb.wrap(ourKey.pubKey).toString('hex')
|
||||||
pubKey = ourKey.pubKey;
|
dataAccess.addUser(pubKeyhex, '', async function(err4, user, meta4) {
|
||||||
var pubKeyhex = bb.wrap(ourKey.pubKey).toString('hex')
|
if (err4) console.error('add user 1 err', err4);
|
||||||
dataAccess.addUser(pubKeyhex, '', async function(err4, user, meta4) {
|
// maybe some annotation to set the profile name...
|
||||||
if (err4) console.error('add user 1 err', err4);
|
// maybe a session icon?
|
||||||
// maybe some annotation to set the profile name...
|
// console.log('schemaType', storage.schemaType)
|
||||||
// maybe a session icon?
|
if (storage.schemaType === 'memory') {
|
||||||
// console.log('schemaType', storage.schemaType)
|
// lets prompt him to mod too...
|
||||||
if (storage.schemaType === 'memory') {
|
console.log('Giving temp mod to', user.id)
|
||||||
// lets prompt him to mod too...
|
config.addTempModerator(user.id)
|
||||||
console.log('Giving temp mod to', user.id)
|
if (config.inWhiteListMode()) {
|
||||||
config.addTempModerator(user.id)
|
// add them to the white list...
|
||||||
if (config.inWhiteListMode()) {
|
const result = await logic.whitelistUserForServer(user.id);
|
||||||
// add them to the white list...
|
if (!result) {
|
||||||
const result = await logic.whitelistUserForServer(user.id);
|
console.warn('could not whitelist!')
|
||||||
if (!result) {
|
}
|
||||||
console.warn('could not whitelist!')
|
|
||||||
}
|
}
|
||||||
|
// generate a token for server/tests
|
||||||
|
cache.createOrFindUserToken(user.id, 'messenger', ADN_SCOPES, function(err5, token) {
|
||||||
|
if (err5) console.error('add user 1 token err', err5);
|
||||||
|
console.log('generated token', JSON.parse(JSON.stringify(token)));
|
||||||
|
})
|
||||||
}
|
}
|
||||||
// generate a token for server/tests
|
resolve(user);
|
||||||
cache.createOrFindUserToken(user.id, 'messenger', ADN_SCOPES, function(err5, token) {
|
});
|
||||||
if (err5) console.error('add user 1 token err', err5);
|
|
||||||
console.log('generated token', JSON.parse(JSON.stringify(token)));
|
|
||||||
})
|
|
||||||
}
|
|
||||||
resolve(user);
|
|
||||||
});
|
});
|
||||||
|
console.log('user', user.id, 'created!');
|
||||||
|
}
|
||||||
|
// no channel, so we need to create this public channel
|
||||||
|
dataAccess.addChannel(1, {
|
||||||
|
type: 'network.loki.messenger.chat.public',
|
||||||
|
reader: 0,
|
||||||
|
writer: 1,
|
||||||
|
readedit: 1,
|
||||||
|
writeedit: 1,
|
||||||
|
editedit: 1,
|
||||||
|
readers: [],
|
||||||
|
writers: [],
|
||||||
|
editors: [],
|
||||||
|
}, (err3, chnl, meta3) => {
|
||||||
|
if (err3) console.error('addChannel err', err3);
|
||||||
|
if (chnl && chnl.id) {
|
||||||
|
console.log('channel', chnl.id, 'created');
|
||||||
|
addChannelNote(chnl.id);
|
||||||
|
// only can do this if we just created the userid 1
|
||||||
|
if (privKey) {
|
||||||
|
//console.log('need to create message 1!')
|
||||||
|
addChannelMessage(privKey, chnl.id);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.error('Unable to set up channel')
|
||||||
|
}
|
||||||
});
|
});
|
||||||
console.log('user', user.id, 'created!');
|
|
||||||
}
|
|
||||||
// no channel, so we need to create this public channel
|
|
||||||
dataAccess.addChannel(1, {
|
|
||||||
type: 'network.loki.messenger.chat.public',
|
|
||||||
reader: 0,
|
|
||||||
writer: 1,
|
|
||||||
readedit: 1,
|
|
||||||
writeedit: 1,
|
|
||||||
editedit: 1,
|
|
||||||
readers: [],
|
|
||||||
writers: [],
|
|
||||||
editors: [],
|
|
||||||
}, (err3, chnl, meta3) => {
|
|
||||||
if (err3) console.error('addChannel err', err3);
|
|
||||||
if (chnl && chnl.id) {
|
|
||||||
console.log('channel', chnl.id, 'created');
|
|
||||||
}
|
|
||||||
addChannelNote(chnl.id);
|
|
||||||
// only can do this if we just created the userid 1
|
|
||||||
if (privKey) {
|
|
||||||
//console.log('need to create message 1!')
|
|
||||||
addChannelMessage(privKey, chnl.id);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
// the race was causing this to create a duplicate annotation
|
||||||
// the race was causing this to create a duplicate annotation
|
/*
|
||||||
/*
|
dataAccess.getAnnotations('channel', 1, (notes, err, meta) => {
|
||||||
dataAccess.getAnnotations('channel', 1, (notes, err, meta) => {
|
if (err) console.error('getAnnotations channel err', err);
|
||||||
if (err) console.error('getAnnotations channel err', err);
|
//console.log('notes', notes);
|
||||||
//console.log('notes', notes);
|
if (!notes || !notes.length) {
|
||||||
if (!notes || !notes.length) {
|
console.log('adding note')
|
||||||
console.log('adding note')
|
addChannelNote(1);
|
||||||
addChannelNote(1);
|
}
|
||||||
}
|
});
|
||||||
});
|
*/
|
||||||
*/
|
} else {
|
||||||
|
console.log('File server mode detected')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return { storage, logic, config, dialect, cache };
|
return { storage, logic, config, dialect, cache };
|
||||||
|
|
Loading…
Reference in New Issue