fix(app.ts): Preparing to use 4 or more SSL certificates.

This commit is contained in:
Alan 2023-05-25 21:20:40 -03:00
parent a969abbcc4
commit 72b645fd2a
19 changed files with 142 additions and 98 deletions

View file

@ -60,7 +60,7 @@ import QrScanner from 'qr-scanner';
import pkg from 'whatsapp-web.js';
import { ActivityTypes } from 'botbuilder';
const { List, Buttons } = pkg;
import mime from 'mime';
import mime from 'mime-types';
/**
* Default check interval for user replay

View file

@ -45,26 +45,26 @@ import { Sequelize } from 'sequelize-typescript';
export class GBHubSpotPackage implements IGBPackage {
public sysPackages: IGBPackage[];
public async loadBot (min: GBMinInstance): Promise<void> {
public async loadBot(min: GBMinInstance): Promise<void> {
GBLog.verbose(`loadBot called.`);
}
public async getDialogs (min: GBMinInstance) {
public async getDialogs(min: GBMinInstance) {
GBLog.verbose(`getDialogs called.`);
}
public async loadPackage (core: IGBCoreService, sequelize: Sequelize): Promise<void> {
public async loadPackage(core: IGBCoreService, sequelize: Sequelize): Promise<void> {
GBLog.verbose(`loadPackage called.`);
}
public async unloadPackage (core: IGBCoreService): Promise<void> {
public async unloadPackage(core: IGBCoreService): Promise<void> {
GBLog.verbose(`unloadPackage called.`);
}
public async unloadBot (min: GBMinInstance): Promise<void> {
public async unloadBot(min: GBMinInstance): Promise<void> {
GBLog.verbose(`unloadBot called.`);
}
public async onNewSession (min: GBMinInstance, step: GBDialogStep): Promise<void> {
public async onNewSession(min: GBMinInstance, step: GBDialogStep): Promise<void> {
GBLog.verbose(`onNewSession called.`);
}
public async onExchangeData (min: GBMinInstance, kind: string, data: any) {
public async onExchangeData(min: GBMinInstance, kind: string, data: any) {
GBLog.verbose(`onExchangeData called.`);
}
}

View file

@ -38,4 +38,4 @@ import * as hubspot from '@hubspot/api-client';
/**
* Support for Hub Spot XRM.
*/
export class HubSpotServices extends GBService {}
export class HubSpotServices extends GBService { }

View file

@ -107,10 +107,10 @@ export class AskDialog extends IGBDialog {
if (step.options && step.options.firstTime) {
text = Messages[locale].ask_first_time;
}
else if (step.options && step.options.isReturning && !step.context.activity.group) {
text = Messages[locale].anything_else;
}
else if (step.context.activity.group || (step.options && step.options.emptyPrompt)) {
else if (step.options && step.options.isReturning && !step.context.activity.group) {
text = Messages[locale].anything_else;
}
else if (step.context.activity.group || (step.options && step.options.emptyPrompt)) {
text = '';
} else if (user.subjects.length > 0) {
text = Messages[locale].which_question;
@ -409,7 +409,7 @@ export class AskDialog extends IGBDialog {
// Gets dialog name and file handling
let dialogName = step.result.replace('.', '');
let dialogName = step.result.replace('.', '');
const docx = urlJoin(`${min.botId}.gbdialog`, `${dialogName}.docx`);
const sys = new SystemKeywords();
const document = await sys.internalCreateDocument(min, docx, response);
@ -439,7 +439,7 @@ export class AskDialog extends IGBDialog {
await step.endDialog();
await GBVMService.callVM(dialogName.toLowerCase(),
min, step, user, this.deployer, false);
min, step, user, this.deployer, false);
}
}
];

View file

@ -53,7 +53,7 @@ export class FaqDialog extends IGBDialog {
* @param bot The bot adapter.
* @param min The minimal bot instance data.
*/
public static setup (bot: BotAdapter, min: GBMinInstance) {
public static setup(bot: BotAdapter, min: GBMinInstance) {
const service = new KBService(min.core.sequelize);
min.dialogs.add(

View file

@ -64,13 +64,13 @@ export class MenuDialog extends IGBDialog {
* @param bot The bot adapter.
* @param min The minimal bot instance data.
*/
public static setup (bot: BotAdapter, min: GBMinInstance) {
public static setup(bot: BotAdapter, min: GBMinInstance) {
const service = new KBService(min.core.sequelize);
min.dialogs.add(new WaterfallDialog('/menu', MenuDialog.getMenuDialog(min, service)));
}
private static getMenuDialog (min: GBMinInstance, service: KBService) {
private static getMenuDialog(min: GBMinInstance, service: KBService) {
return [
async step => {
if (step.context.activity.channelId !== 'msteams' && process.env.ENABLE_AUTH) {

View file

@ -48,26 +48,26 @@ import { GuaribasAnswer, GuaribasQuestion, GuaribasSubject } from './models/inde
*/
export class GBKBPackage implements IGBPackage {
public sysPackages: IGBPackage[];
public async getDialogs (min: GBMinInstance) {
public async getDialogs(min: GBMinInstance) {
GBLog.verbose(`getDialogs called.`);
}
public async unloadPackage (core: IGBCoreService): Promise<void> {
public async unloadPackage(core: IGBCoreService): Promise<void> {
GBLog.verbose(`unloadPackage called.`);
}
public async unloadBot (min: GBMinInstance): Promise<void> {
public async unloadBot(min: GBMinInstance): Promise<void> {
GBLog.verbose(`unloadBot called.`);
}
public async onNewSession (min: GBMinInstance, step: GBDialogStep): Promise<void> {
public async onNewSession(min: GBMinInstance, step: GBDialogStep): Promise<void> {
GBLog.verbose(`onNewSession called.`);
}
public async onExchangeData (min: GBMinInstance, kind: string, data: any) {
public async onExchangeData(min: GBMinInstance, kind: string, data: any) {
GBLog.verbose(`onExchangeData called.`);
}
public async loadPackage (core: IGBCoreService, sequelize: Sequelize): Promise<void> {
public async loadPackage(core: IGBCoreService, sequelize: Sequelize): Promise<void> {
core.sequelize.addModels([GuaribasAnswer, GuaribasQuestion, GuaribasSubject]);
}
public async loadBot (min: GBMinInstance): Promise<void> {
public async loadBot(min: GBMinInstance): Promise<void> {
AskDialog.setup(min.bot, min);
FaqDialog.setup(min.bot, min);
MenuDialog.setup(min.bot, min);

View file

@ -646,7 +646,7 @@ export class KBService implements IGBKBService {
packageId: pkg.packageId,
prevId: 0
};
const a =await GuaribasAnswer.create(answer);
const a = await GuaribasAnswer.create(answer);
question['answerId'] = a.answerId;
const q = await GuaribasQuestion.create(question);

View file

@ -44,7 +44,7 @@ import { Messages } from '../strings.js';
* Dialogs for handling Menu control.
*/
export class OAuthDialog extends IGBDialog {
public static getOAuthDialog (min: GBMinInstance) {
public static getOAuthDialog(min: GBMinInstance) {
return {
id: '/auth',
waterfall: [

View file

@ -45,7 +45,7 @@ import * as phone from 'google-libphonenumber';
* Dialogs for handling Menu control.
*/
export class ProfileDialog extends IGBDialog {
public static getNameDialog (min: GBMinInstance) {
public static getNameDialog(min: GBMinInstance) {
return {
id: '/profile_name',
waterfall: [
@ -83,7 +83,7 @@ export class ProfileDialog extends IGBDialog {
};
}
public static getMobileDialog (min: GBMinInstance) {
public static getMobileDialog(min: GBMinInstance) {
return {
id: '/profile_mobile',
waterfall: [
@ -126,7 +126,7 @@ export class ProfileDialog extends IGBDialog {
};
}
public static getMobileConfirmDialog (min: GBMinInstance) {
public static getMobileConfirmDialog(min: GBMinInstance) {
return {
id: '/profile_mobile_confirm',
waterfall: [
@ -167,7 +167,7 @@ export class ProfileDialog extends IGBDialog {
};
}
public static getEmailDialog (min: GBMinInstance) {
public static getEmailDialog(min: GBMinInstance) {
return {
id: '/profile_email',
waterfall: [

View file

@ -47,7 +47,7 @@ import { GuaribasGroup, GuaribasUser, GuaribasUserGroup } from './models/index.j
*/
export class GBSecurityPackage implements IGBPackage {
public sysPackages: IGBPackage[];
public async getDialogs (min: GBMinInstance) {
public async getDialogs(min: GBMinInstance) {
const out = [
ProfileDialog.getNameDialog(min),
ProfileDialog.getEmailDialog(min),
@ -60,23 +60,23 @@ export class GBSecurityPackage implements IGBPackage {
}
return out;
}
public async unloadPackage (core: IGBCoreService): Promise<void> {
public async unloadPackage(core: IGBCoreService): Promise<void> {
GBLog.verbose(`unloadPackage called.`);
}
public async loadBot (min: GBMinInstance): Promise<void> {
public async loadBot(min: GBMinInstance): Promise<void> {
GBLog.verbose(`loadBot called.`);
}
public async unloadBot (min: GBMinInstance): Promise<void> {
public async unloadBot(min: GBMinInstance): Promise<void> {
GBLog.verbose(`unloadBot called.`);
}
public async onNewSession (min: GBMinInstance, step: GBDialogStep): Promise<void> {
public async onNewSession(min: GBMinInstance, step: GBDialogStep): Promise<void> {
GBLog.verbose(`onNewSession called.`);
}
public async onExchangeData (min: GBMinInstance, kind: string, data: any) {
public async onExchangeData(min: GBMinInstance, kind: string, data: any) {
GBLog.verbose(`onExchangeData called.`);
}
public async loadPackage (core: IGBCoreService, sequelize: Sequelize): Promise<void> {
public async loadPackage(core: IGBCoreService, sequelize: Sequelize): Promise<void> {
core.sequelize.addModels([GuaribasGroup, GuaribasUser, GuaribasUserGroup]);
}
}

View file

@ -9,7 +9,7 @@ import { FindOptions } from 'sequelize';
* Security service layer.
*/
export class SecService extends GBService {
public async ensureUser (
public async ensureUser(
instanceId: number,
userSystemId: string,
userName: string,
@ -41,7 +41,7 @@ export class SecService extends GBService {
/**
* Retrives a conversation reference from contact phone.
*/
public async getConversationReference (phone: string): Promise<ConversationReference> {
public async getConversationReference(phone: string): Promise<ConversationReference> {
const options = <FindOptions>{ rejectOnEmpty: true, where: { phone: phone } };
const user = await GuaribasUser.findOne(options);
@ -51,7 +51,7 @@ export class SecService extends GBService {
/**
* Updates a conversation reference from contact phone.
*/
public async updateConversationReference (phone: string, conversationReference: string) {
public async updateConversationReference(phone: string, conversationReference: string) {
const options = <FindOptions>{ where: { phone: phone } };
const user = await GuaribasUser.findOne(options);
@ -59,7 +59,7 @@ export class SecService extends GBService {
await user.save();
}
public async updateConversationReferenceById (userId: number, conversationReference: string) {
public async updateConversationReferenceById(userId: number, conversationReference: string) {
const options = <FindOptions>{ where: { userId: userId } };
const user = await GuaribasUser.findOne(options);
@ -67,7 +67,7 @@ export class SecService extends GBService {
await user.save();
}
public async updateUserLocale (userId: number, locale: any): Promise<GuaribasUser> {
public async updateUserLocale(userId: number, locale: any): Promise<GuaribasUser> {
const user = await GuaribasUser.findOne({
where: {
userId: userId
@ -78,7 +78,7 @@ export class SecService extends GBService {
return await user.save();
}
public async updateUserHearOnDialog (userId: number, dialogName: string): Promise<GuaribasUser> {
public async updateUserHearOnDialog(userId: number, dialogName: string): Promise<GuaribasUser> {
const user = await GuaribasUser.findOne({
where: {
userId: userId
@ -89,7 +89,7 @@ export class SecService extends GBService {
return await user.save();
}
public async updateUserInstance (userSystemId: string, instanceId: number): Promise<GuaribasUser> {
public async updateUserInstance(userSystemId: string, instanceId: number): Promise<GuaribasUser> {
const user = await GuaribasUser.findOne({
where: {
userSystemId: userSystemId
@ -103,7 +103,7 @@ export class SecService extends GBService {
/**
* Finds and update user agent information to a next available person.
*/
public async updateHumanAgent (
public async updateHumanAgent(
userSystemId: string,
instanceId: number,
agentSystemId: string
@ -150,7 +150,7 @@ export class SecService extends GBService {
return user;
}
public async isAgentSystemId (systemId: string): Promise<Boolean> {
public async isAgentSystemId(systemId: string): Promise<Boolean> {
const user = await GuaribasUser.findOne({
where: {
userSystemId: systemId
@ -164,7 +164,7 @@ export class SecService extends GBService {
return user.agentMode === 'self';
}
public async assignHumanAgent (
public async assignHumanAgent(
min: GBMinInstance,
userSystemId: string,
agentSystemId: string = null
@ -194,7 +194,7 @@ export class SecService extends GBService {
return agentSystemId;
}
public async getUserFromId (instanceId: number, userId: string): Promise<GuaribasUser> {
public async getUserFromId(instanceId: number, userId: string): Promise<GuaribasUser> {
return await GuaribasUser.findOne({
where: {
instanceId: instanceId,
@ -203,7 +203,7 @@ export class SecService extends GBService {
});
}
public async getUserFromSystemId (systemId: string): Promise<GuaribasUser> {
public async getUserFromSystemId(systemId: string): Promise<GuaribasUser> {
return await GuaribasUser.findOne({
where: {
userSystemId: systemId
@ -211,7 +211,7 @@ export class SecService extends GBService {
});
}
public async getUserFromAgentSystemId (systemId: string): Promise<GuaribasUser> {
public async getUserFromAgentSystemId(systemId: string): Promise<GuaribasUser> {
return await GuaribasUser.findOne({
where: {
agentSystemId: systemId
@ -219,7 +219,7 @@ export class SecService extends GBService {
});
}
public async getAllUsers (instanceId: number): Promise<GuaribasUser[]> {
public async getAllUsers(instanceId: number): Promise<GuaribasUser[]> {
return await GuaribasUser.findAll({
where: {
instanceId: instanceId
@ -235,7 +235,7 @@ export class SecService extends GBService {
* @param name Name of param to get from instance.
* @param defaultValue Value returned when no param is defined.
*/
public getParam<T> (user: GuaribasUser, name: string, defaultValue?: T): any {
public getParam<T>(user: GuaribasUser, name: string, defaultValue?: T): any {
let value = null;
if (user.params) {
const params = JSON.parse(user.params);
@ -254,8 +254,7 @@ export class SecService extends GBService {
if (user['dataValues'] && !value) {
value = user['dataValues'][name];
if (value === null) {
switch(name)
{
switch (name) {
case 'language':
value = 'en';
break;
@ -269,14 +268,13 @@ export class SecService extends GBService {
* Saves user instance object to the storage handling
* multi-column JSON based store 'params' field.
*/
public async setParam (userId: number, name: string, value:any) {
public async setParam(userId: number, name: string, value: any) {
const options = { where: {} };
options.where = { userId: userId };
let user = await GuaribasUser.findOne(options);
// tslint:disable-next-line:prefer-object-spread
let obj = JSON.parse(user.params);
if (!obj)
{
let obj = JSON.parse(user.params);
if (!obj) {
obj = {};
}
obj[name] = value;

View file

@ -44,25 +44,25 @@ import { Sequelize } from 'sequelize-typescript';
*/
export class GBSharePointPackage implements IGBPackage {
public sysPackages: IGBPackage[];
public async getDialogs (min: GBMinInstance) {
public async getDialogs(min: GBMinInstance) {
GBLog.verbose(`getDialogs called.`);
}
public async loadPackage (core: IGBCoreService, sequelize: Sequelize): Promise<void> {
public async loadPackage(core: IGBCoreService, sequelize: Sequelize): Promise<void> {
GBLog.verbose(`loadPackage called.`);
}
public async unloadPackage (core: IGBCoreService): Promise<void> {
public async unloadPackage(core: IGBCoreService): Promise<void> {
GBLog.verbose(`unloadPackage called.`);
}
public async loadBot (min: GBMinInstance): Promise<void> {
public async loadBot(min: GBMinInstance): Promise<void> {
GBLog.verbose(`loadBot called.`);
}
public async unloadBot (min: GBMinInstance): Promise<void> {
public async unloadBot(min: GBMinInstance): Promise<void> {
GBLog.verbose(`unloadBot called.`);
}
public async onNewSession (min: GBMinInstance, step: GBDialogStep): Promise<void> {
public async onNewSession(min: GBMinInstance, step: GBDialogStep): Promise<void> {
GBLog.verbose(`onNewSession called.`);
}
public async onExchangeData (min: GBMinInstance, kind: string, data: any) {
public async onExchangeData(min: GBMinInstance, kind: string, data: any) {
GBLog.verbose(`onExchangeData called.`);
}
}

View file

@ -39,4 +39,4 @@
/**
* Service facade for SharePoint Online.
*/
export class GBSharePointService {}
export class GBSharePointService { }

View file

@ -38,7 +38,7 @@ import AdmZip from 'adm-zip';
* Support for Whatsapp.
*/
export class TeamsService extends GBService {
public async getAppFile (manifest) {
public async getAppFile(manifest) {
var zip = new AdmZip();
zip.addFile('manifest.json', Buffer.from(manifest, 'utf8'), 'Built with General Bots™.');
zip.addLocalFile('teams-color.png', null, 'color.png');
@ -46,7 +46,7 @@ export class TeamsService extends GBService {
return zip.toBuffer();
}
public async getManifest (marketplaceId, botName, botDescription, id, packageName, yourName) {
public async getManifest(marketplaceId, botName, botDescription, id, packageName, yourName) {
let content = Fs.readFileSync('teams-manifest.json', 'utf8');
content = content.replace(/\@\@marketplaceId/gi, marketplaceId);

View file

@ -46,26 +46,26 @@ import { WhatsappDirectLine } from './services/WhatsappDirectLine.js';
export class GBWhatsappPackage implements IGBPackage {
public sysPackages: IGBPackage[];
public async loadBot (min: GBMinInstance): Promise<void> {
public async loadBot(min: GBMinInstance): Promise<void> {
GBLog.verbose(`loadBot called.`);
}
public async getDialogs (min: GBMinInstance) {
public async getDialogs(min: GBMinInstance) {
GBLog.verbose(`getDialogs called.`);
}
public async loadPackage (core: IGBCoreService, sequelize: Sequelize): Promise<void> {
public async loadPackage(core: IGBCoreService, sequelize: Sequelize): Promise<void> {
GBLog.verbose(`loadPackage called.`);
}
public async unloadPackage (core: IGBCoreService): Promise<void> {
public async unloadPackage(core: IGBCoreService): Promise<void> {
GBLog.verbose(`unloadPackage called.`);
}
public async unloadBot (min: GBMinInstance): Promise<void> {
public async unloadBot(min: GBMinInstance): Promise<void> {
GBLog.verbose(`unloadBot called.`);
}
public async onNewSession (min: GBMinInstance, step: GBDialogStep): Promise<void> {
public async onNewSession(min: GBMinInstance, step: GBDialogStep): Promise<void> {
GBLog.verbose(`onNewSession called.`);
}
public async onExchangeData (min: GBMinInstance, kind: string, data: any) {
public async onExchangeData(min: GBMinInstance, kind: string, data: any) {
GBLog.verbose(`onExchangeData called.`);
}
}

View file

@ -192,11 +192,10 @@ export class WhatsappDirectLine extends GBService {
});
client.initialize();
};
if (setUrl){
if (setUrl) {
createClient.bind(this)();
}
else
{
else {
this.customClient = minBoot.whatsAppDirectLine.customClient;
}
setUrl = false;
@ -998,14 +997,14 @@ export class WhatsappDirectLine extends GBService {
let urlMin: any = GBServer.globals.minInstances.filter(p => p.instance.botId === botId)[0];
const botNumber = urlMin ? urlMin.core.getParam(urlMin.instance, 'Bot Number', null) : null;
if (botNumber){
if (botNumber) {
user = await sec.updateUserInstance(user.userSystemId, urlMin.instance.instanceId);
}
let activeMin;
// Processes group behaviour.
text = text.replace(/\@\d+ /gi, '');
text = text.replace(/\@\d+ /gi, '');
let group;
if (provider === 'chatapi') {

View file

@ -282,15 +282,62 @@ export class GBServer {
};
const httpsServer = https.createServer(options1, server).listen(port, mainCallback);
GBServer.globals.httpsServer = httpsServer;
if (process.env.CERTIFICATE2_PFX) {
const options2 = {
passphrase: process.env.CERTIFICATE2_PASSPHRASE,
pfx: Fs.readFileSync(process.env.CERTIFICATE2_PFX)
};
httpsServer.addContext(process.env.CERTIFICATE2_DOMAIN, options2);
for (let i = 2; ; i++) {
const certPfxEnv = `CERTIFICATE${i}_PFX`;
const certPassphraseEnv = `CERTIFICATE${i}_PASSPHRASE`;
const certDomainEnv = `CERTIFICATE${i}_DOMAIN`;
if (process.env[certPfxEnv] && process.env[certPassphraseEnv] && process.env[certDomainEnv]) {
const options = {
passphrase: process.env[certPassphraseEnv],
pfx: Fs.readFileSync(process.env[certPfxEnv])
};
httpsServer.addContext(process.env[certDomainEnv], options);
} else {
break;
}
}
} else {
}
else {
server.listen(port, mainCallback);
}
}
}
/*
--------------------------------------------------------------------------------------------
if (process.env.CERTIFICATE_PFX) {
const options1 = {
passphrase: process.env.CERTIFICATE_PASSPHRASE,
pfx: Fs.readFileSync(process.env.CERTIFICATE_PFX)
};
const httpsServer = https.createServer(options1, server).listen(port, mainCallback);
GBServer.globals.httpsServer = httpsServer;
if (process.env.CERTIFICATE2_PFX) {
const options2 = {
passphrase: process.env.CERTIFICATE2_PASSPHRASE,
pfx: Fs.readFileSync(process.env.CERTIFICATE2_PFX)
};
httpsServer.addContext(process.env.CERTIFICATE2_DOMAIN, options2);
}
if (process.env.CERTIFICATE3_PFX) {
const options3 = {
passphrase: process.env.CERTIFICATE3_PASSPHRASE,
pfx: Fs.readFileSync(process.env.CERTIFICATE3_PFX)
};
httpsServer.addContext(process.env.CERTIFICATE3_DOMAIN, options3);
}
if (process.env.CERTIFICATE4_PFX) {
const options4 = {
passphrase: process.env.CERTIFICATE4_PASSPHRASE,
pfx: Fs.readFileSync(process.env.CERTIFICATE4_PFX)
};
httpsServer.addContext(process.env.CERTIFICATE4_DOMAIN, options4);
}
}
------------------------------------------------------------------------------------------
*/