Fix missing check

This commit is contained in:
Bryan Ashby 2022-08-21 14:02:47 -06:00
parent 92ca571e40
commit 1f130347d5
No known key found for this signature in database
GPG Key ID: C2C1B501E4EFD994
1 changed files with 49 additions and 35 deletions

View File

@ -245,14 +245,52 @@ exports.getModule = class GopherModule extends ServerModule {
return cb('Not found'); return cb('Not found');
} }
isAreaAndConfExposed(confTag, areaTag) { _getConfigForConferenceTag(confTag) {
const conf = _.get(Config(), [ const sysConfig = Config();
let config = _.get(sysConfig, [
'contentServers', 'contentServers',
'gopher', 'gopher',
'messageConferences', 'exposedConfAreas',
confTag, confTag,
]); ]);
return Array.isArray(conf) && conf.includes(areaTag); if (config) {
return [config, false]; // new
}
return [
_.get(sysConfig, ['contentServers', 'gopher', 'messageConferences', confTag]),
true,
];
}
isAreaAndConfExposed(confTag, areaTag) {
const [confConfig, isLegacy] = this._getConfigForConferenceTag(confTag);
if (isLegacy) {
return Array.isArray(confConfig) && confConfig.includes(areaTag);
}
if (!Array.isArray(confConfig.include)) {
return false;
}
let exposed = false;
for (let rule of confConfig.include) {
if (wildcardMatch(areaTag, rule)) {
exposed = true;
break;
}
}
// may still be excluded
for (let rule of confConfig.exclude || []) {
if (wildcardMatch(areaTag, rule)) {
exposed = false;
break;
}
}
return exposed;
} }
prepareMessageBody(body, cb) { prepareMessageBody(body, cb) {
@ -323,17 +361,17 @@ exports.getModule = class GopherModule extends ServerModule {
const msgUuid = selectorMatch[3].replace(/\r\n|\//g, ''); const msgUuid = selectorMatch[3].replace(/\r\n|\//g, '');
const confTag = selectorMatch[1].substr(1).split('/')[0]; const confTag = selectorMatch[1].substr(1).split('/')[0];
const areaTag = selectorMatch[2].replace(/\r\n|\//g, ''); const areaTag = selectorMatch[2].replace(/\r\n|\//g, '');
return this._displayMessage(msgUuid, confTag, areaTag, cb); return this._displayMessage(selectorMatch, msgUuid, confTag, areaTag, cb);
} else if (selectorMatch[2]) { } else if (selectorMatch[2]) {
// conf/area selector -- list messages in area // conf/area selector -- list messages in area
const confTag = selectorMatch[1].substr(1).split('/')[0]; const confTag = selectorMatch[1].substr(1).split('/')[0];
const areaTag = selectorMatch[2].replace(/\r\n|\//g, ''); const areaTag = selectorMatch[2].replace(/\r\n|\//g, '');
const area = getMessageAreaByTag(areaTag); const area = getMessageAreaByTag(areaTag);
return this._listMessagesInArea(confTag, areaTag, area, cb); return this._listMessagesInArea(selectorMatch, confTag, areaTag, area, cb);
} else if (selectorMatch[1]) { } else if (selectorMatch[1]) {
// message conference selector -- list areas in this conference // message conference selector -- list areas in this conference
const confTag = selectorMatch[1].replace(/\r\n|\//g, ''); const confTag = selectorMatch[1].replace(/\r\n|\//g, '');
return this._listExposedMessageConferenceAreas(confTag, cb); return this._listExposedMessageConferenceAreas(selectorMatch, confTag, cb);
} else { } else {
// message area base selector -- list exposed message conferences // message area base selector -- list exposed message conferences
return this._listExposedMessageConferences(cb); return this._listExposedMessageConferences(cb);
@ -430,7 +468,7 @@ exports.getModule = class GopherModule extends ServerModule {
return cb(response); return cb(response);
} }
_listExposedMessageConferenceAreas(confTag, cb) { _listExposedMessageConferenceAreas(selectorMatch, confTag, cb) {
// //
// New system -- exposedConfAreas: // New system -- exposedConfAreas:
// We have a required array |include| of area tags that may // We have a required array |include| of area tags that may
@ -440,31 +478,7 @@ exports.getModule = class GopherModule extends ServerModule {
// Deprecated -- messageConferences: // Deprecated -- messageConferences:
// The key should point to an array of area tags // The key should point to an array of area tags
// //
const sysConfig = Config(); const [confConfig, isLegacy] = this._getConfigForConferenceTag(confTag);
const getConfConfig = () => {
let config = _.get(sysConfig, [
'contentServers',
'gopher',
'exposedConfAreas',
confTag,
]);
if (config) {
return [config, false]; // new
}
return [
_.get(sysConfig, [
'contentServers',
'gopher',
'messageConferences',
confTag,
]),
true,
];
};
const [confConfig, isLegacy] = getConfConfig();
const messageConference = getMessageConferenceByTag(confTag); // we need the actual conf! const messageConference = getMessageConferenceByTag(confTag); // we need the actual conf!
if (!messageConference) { if (!messageConference) {
@ -512,7 +526,7 @@ exports.getModule = class GopherModule extends ServerModule {
return this._makeAvailableMessageAreasResponse(messageConference, areas, cb); return this._makeAvailableMessageAreasResponse(messageConference, areas, cb);
} }
_listMessagesInArea(confTag, areaTag, area, cb) { _listMessagesInArea(selectorMatch, confTag, areaTag, area, cb) {
if (Message.isPrivateAreaTag(areaTag)) { if (Message.isPrivateAreaTag(areaTag)) {
this.log.warn({ areaTag }, `Gopher attempted access to private "${areaTag}"`); this.log.warn({ areaTag }, `Gopher attempted access to private "${areaTag}"`);
return cb(this.makeItem(ItemTypes.InfoMessage, 'Area is private')); return cb(this.makeItem(ItemTypes.InfoMessage, 'Area is private'));
@ -555,7 +569,7 @@ exports.getModule = class GopherModule extends ServerModule {
}); });
} }
_displayMessage(msgUuid, confTag, areaTag, cb) { _displayMessage(selectorMatch, msgUuid, confTag, areaTag, cb) {
const message = new Message(); const message = new Message();
return message.load({ uuid: msgUuid }, err => { return message.load({ uuid: msgUuid }, err => {