Debugging V4 and adding some security logic.

This commit is contained in:
Rodrigo Rodriguez 2018-09-03 13:43:09 -03:00
parent 2584717ae8
commit f6bf1068bb
6 changed files with 190 additions and 68 deletions

View file

@ -53,81 +53,84 @@ export class AdminDialog extends IGBDialog {
let deployer = new GBDeployer(min.core, importer); let deployer = new GBDeployer(min.core, importer);
min.dialogs.add("/admin", [ min.dialogs.add("/admin", [
async (dc, args) => { async (dc, args) => {
const prompt = "Please, authenticate:"; const prompt = "Please, authenticate:";
await dc.prompt('textPrompt', prompt); await dc.prompt('textPrompt', prompt);
}, },
async (dc, value) => { async (dc, value) => {
var text = value.response; let text = value;
const user = min.userState.get(dc.context); const user = min.userState.get(dc.context);
if ( if (
!user.authenticated || !user.authenticated ||
text === GBConfigService.get("ADMIN_PASS") text === GBConfigService.get("ADMIN_PASS")
) { ) {
user.authenticated = true; user.authenticated = true;
dc.context.sendActivity( dc.context.sendActivity(
"Welcome to Pragmatismo.io GeneralBots Administration." "Welcome to Pragmatismo.io GeneralBots Administration."
); );
await dc.prompt('textPrompt', "Which task do you wanna run now?"); await dc.prompt('textPrompt', "Which task do you wanna run now?");
} else { } else {
dc.endAll(); dc.endAll();
} }
}, },
async (dc, value) => { async (dc, value) => {
var text = value; var text = value;
const user = min.userState.get(dc.context); const user = min.userState.get(dc.context);
if (text === "quit") { if (text === "quit") {
user.authenticated = false; user.authenticated = false;
dc.replace("/"); dc.replace("/");
} else if (text === "sync") { } else if (text === "sync") {
min.core.syncDatabaseStructure(() => { }); min.core.syncDatabaseStructure(() => { });
dc.context.sendActivity("Sync started..."); dc.context.sendActivity("Sync started...");
dc.replace("/admin", {
firstRun: false
});
} else if (text.split(" ")[0] === "rebuildIndex") {
AdminDialog.rebuildIndexCommand(min, dc, () =>
dc.replace("/admin", { dc.replace("/admin", {
firstRun: false firstRun: false
}); })
} else if (text.split(" ")[0] === "rebuildIndex") { );
AdminDialog.rebuildIndexCommand(min, dc, () => } else if (text.split(" ")[0] === "deployPackage") {
AdminDialog.deployPackageCommand(text, dc, deployer, min, () =>
dc.replace("/admin", {
firstRun: false
})
);
} else if (text.split(" ")[0] === "redeployPackage") {
AdminDialog.undeployPackageCommand(text, min, dc, () => {
AdminDialog.deployPackageCommand(text, dc, deployer, min, () => {
dc.context.sendActivity("Redeploy done.");
dc.replace("/admin", { dc.replace("/admin", {
firstRun: false firstRun: false
})
);
} else if (text.split(" ")[0] === "deployPackage") {
AdminDialog.deployPackageCommand(text, dc, deployer, min, () =>
dc.replace("/admin", {
firstRun: false
})
);
} else if (text.split(" ")[0] === "redeployPackage") {
AdminDialog.undeployPackageCommand(text, min, dc, () => {
AdminDialog.deployPackageCommand(text, dc, deployer, min, () => {
dc.context.sendActivity("Redeploy done.");
dc.replace("/admin", {
firstRun: false
});
}); });
}); });
} else if (text.split(" ")[0] === "undeployPackage") { });
AdminDialog.undeployPackageCommand(text, min, dc, () => } else if (text.split(" ")[0] === "undeployPackage") {
dc.replace("/admin", { AdminDialog.undeployPackageCommand(text, min, dc, () =>
firstRun: false
})
);
} else if (text.split(" ")[0] === "applyPackage") {
dc.context.sendActivity("Applying in progress...");
min.core.loadInstance(text.split(" ")[1], (item, err) => {
dc.context.sendActivity("Applying done...");
dc.replace("/");
});
dc.replace("/admin", { dc.replace("/admin", {
firstRun: false firstRun: false
}); })
} );
} else if (text.split(" ")[0] === "applyPackage") {
dc.context.sendActivity("Applying in progress...");
min.core.loadInstance(text.split(" ")[1], (item, err) => {
dc.context.sendActivity("Applying done...");
dc.replace("/");
});
dc.replace("/admin", {
firstRun: false
});
} else if (text.split(" ")[0] === "rat") {
min.conversationalService.sendEvent(dc, "play", { playerType: "login", data: null });
dc.context.sendActivity("Realize login clicando no botão de login, por favor...");
} }
]) }
])
} }
static undeployPackageCommand(text: any, min: GBMinInstance, dc, cb) { static undeployPackageCommand(text: any, min: GBMinInstance, dc, cb) {
let packageName = text.split(" ")[1]; let packageName = text.split(" ")[1];
let importer = new GBImporter(min.core); let importer = new GBImporter(min.core);

View file

@ -56,7 +56,8 @@ export class WelcomeDialog extends IGBDialog {
date < 12 ? "bom dia" : date < 18 ? "boa tarde" : "boa noite"; date < 12 ? "bom dia" : date < 18 ? "boa tarde" : "boa noite";
let messages = [`Oi, ${msg}.`, `Oi!`, `Olá, ${msg}`, `Olá!`]; let messages = [`Oi, ${msg}.`, `Oi!`, `Olá, ${msg}`, `Olá!`];
dc.context.sendActivity(messages[0]);
if (dc.context.activity && dc.context.activity.text != "") { if (dc.context.activity && dc.context.activity.text != "") {
await dc.replace("/answer", { query: dc.context.activity.text }); await dc.replace("/answer", { query: dc.context.activity.text });
} }

View file

@ -240,13 +240,18 @@ export class GBMinService {
const state = conversationState.get(context); const state = conversationState.get(context);
const dc = min.dialogs.createContext(context, state); const dc = min.dialogs.createContext(context, state);
const user = min.userState.get(dc.context); const user = min.userState.get(dc.context);
if (!user.loaded) { if (!user.loaded) {
min.conversationalService.sendEvent( min.conversationalService.sendEvent(
dc, dc,
"loadInstance", "loadInstance",
min.instance // TODO: Send just necessary values. {
instanceId: instance.instanceId,
botId: instance.botId,
theme: instance.theme,
secret: instance.webchatKey, // TODO: Use token.
}
); );
user.loaded = true; user.loaded = true;
@ -263,10 +268,12 @@ export class GBMinService {
// Check to see if anyone replied. If not then start echo dialog // Check to see if anyone replied. If not then start echo dialog
if (!context.responded) { if (!user.once) {
await dc.begin('/'); await dc.begin('/');
} else if (context.activity.name === "whoAmI") { } else if (context.activity.name === "whoAmI") {
dc.begin("/whoAmI"); dc.begin("/whoAmI");
} else if (context.activity.text === "admin") {
dc.begin("/admin");
} else if (context.activity.name === "showSubjects") { } else if (context.activity.name === "showSubjects") {
dc.begin("/menu"); dc.begin("/menu");
} else if (context.activity.name === "giveFeedback") { } else if (context.activity.name === "giveFeedback") {

View file

@ -1,6 +1,6 @@
{ {
"name": "default.gbui", "name": "default.gbui",
"version": "0.0.10", "version": "0.0.11",
"private": true, "private": true,
"homepage": ".", "homepage": ".",
"dependencies": { "dependencies": {
@ -8,6 +8,7 @@
"botframework-webchat": "^0.14.2", "botframework-webchat": "^0.14.2",
"deep-extend": "^0.6.0", "deep-extend": "^0.6.0",
"fetch": "^1.1.0", "fetch": "^1.1.0",
"msal": "^0.2.2",
"react": "^16.4.2", "react": "^16.4.2",
"react-dom": "^16.4.2", "react-dom": "^16.4.2",
"react-helmet": "^5.2.0", "react-helmet": "^5.2.0",

View file

@ -34,6 +34,7 @@ import React from "react";
import GBMarkdownPlayer from "./players/GBMarkdownPlayer.js"; import GBMarkdownPlayer from "./players/GBMarkdownPlayer.js";
import GBImagePlayer from "./players/GBImagePlayer.js"; import GBImagePlayer from "./players/GBImagePlayer.js";
import GBVideoPlayer from "./players/GBVideoPlayer.js"; import GBVideoPlayer from "./players/GBVideoPlayer.js";
import GBLoginPlayer from "./players/GBLoginPlayer.js";
import GBBulletPlayer from "./players/GBBulletPlayer.js"; import GBBulletPlayer from "./players/GBBulletPlayer.js";
import SidebarMenu from "./components/SidebarMenu.js"; import SidebarMenu from "./components/SidebarMenu.js";
import GBCss from "./components/GBCss.js"; import GBCss from "./components/GBCss.js";
@ -223,6 +224,16 @@ class GBUIApp extends React.Component {
/> />
); );
break; break;
case "login":
playerComponent = (
<GBLoginPlayer
app={this}
ref={player => {
this.player = player;
}}
/>
);
break;
default: default:
console.log( console.log(
"GBERROR: Unknow player type specified on message from server." "GBERROR: Unknow player type specified on message from server."

View file

@ -0,0 +1,99 @@
/*****************************************************************************\
| ( )_ _ |
| _ _ _ __ _ _ __ ___ ___ _ _ | ,_)(_) ___ ___ _ |
| ( '_`\ ( '__)/'_` ) /'_ `\/' _ ` _ `\ /'_` )| | | |/',__)/' _ `\ /'_`\ |
| | (_) )| | ( (_| |( (_) || ( ) ( ) |( (_| || |_ | |\__, \| ( ) |( (_) ) |
| | ,__/'(_) `\__,_)`\__ |(_) (_) (_)`\__,_)`\__)(_)(____/(_) (_)`\___/' |
| | | ( )_) | |
| (_) \___/' |
| |
| General Bots Copyright (c) Pragmatismo.io. All rights reserved. |
| Licensed under the AGPL-3.0. |
| |
| According to our dual licensing model, this program can be used either |
| under the terms of the GNU Affero General Public License, version 3, |
| or under a proprietary license. |
| |
| The texts of the GNU Affero General Public License with an additional |
| permission and of our proprietary license can be found at and |
| in the LICENSE file you have received along with this program. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. |
| |
| "General Bots" is a registered trademark of Pragmatismo.io. |
| The licensing of the program under the AGPLv3 does not imply a |
| trademark license. Therefore any rights, title and interest in |
| our trademarks remain entirely with us. |
| |
\*****************************************************************************/
import React from "react";
import { UserAgentApplication } from "msal";
class GBLoginPlayer extends React.Component {
constructor() {
super();
this.state = {
token: "",
};
}
login() {
let config = {
tenant: "pragmatismo.onmicrosoft.com", //"6ecb2a67-15af-4582-ab85-cc65096ce471",
signUpSignInPolicy: "b2c_1_susi",
clientID: '47cbaa05-dbb4-46f8-8608-da386c5131f1'}
let authority = "https://login.microsoftonline.com/tfp/" +
config.tenant + "/" +
config.signUpSignInPolicy;
let userAgentApplication = new UserAgentApplication(
config.clientID, authority,
function (errorDesc, token, error, tokenType) {
console.log(token);
}
);
let graphScopes = ["Directory.AccessAsUser.All"];
userAgentApplication.loginPopup(graphScopes).then(function (idToken) {
userAgentApplication.acquireTokenSilent(graphScopes).then(function (accessToken) {
console.log(accessToken);
}, function (error) {
userAgentApplication.acquireTokenPopup(graphScopes).then(function (accessToken) {
console.log(accessToken);
}, function (error) {
console.log(error);
});
})
}, function (error) {
console.log(error);
});
}
play() {
}
render() {
return (
<button
value="Login"
onClick={this.login}
/>
);
}
}
export default GBLoginPlayer;