From b9e0aae1e4cf4a2c47727fcf949ea05cd10cfe0b Mon Sep 17 00:00:00 2001 From: Chaiwat Ekkaewnumchai Date: Wed, 14 Aug 2019 06:11:02 -0700 Subject: [PATCH] Add Warning for FB Employee Summary: Add warning dialog when FB employee uses OSS Flipper Reviewed By: passy, danielbuechele Differential Revision: D16783408 fbshipit-source-id: 3e7e533c5b96d4204fc38570a4e65c23ac0aaa25 --- src/chrome/WarningEmployee.tsx | 55 ++++++++++++++++++++++++++++++++++ src/fb-stubs/config.tsx | 1 + src/init.js | 41 +++++++++++++++++++------ src/utils/fbEmployee.js | 25 ++++++++++++++++ 4 files changed, 113 insertions(+), 9 deletions(-) create mode 100644 src/chrome/WarningEmployee.tsx create mode 100644 src/utils/fbEmployee.js diff --git a/src/chrome/WarningEmployee.tsx b/src/chrome/WarningEmployee.tsx new file mode 100644 index 000000000..f9ced1d92 --- /dev/null +++ b/src/chrome/WarningEmployee.tsx @@ -0,0 +1,55 @@ +/** + * Copyright 2019-present Facebook. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * @format + */ + +import {styled, FlexColumn, Text, Button, colors} from 'flipper'; + +import React from 'react'; + +const Container = styled(FlexColumn)({ + height: '100%', + width: '100%', + justifyContent: 'center', + alignItems: 'center', + backgroundColor: colors.light02, +}); + +const Box = styled(FlexColumn)({ + justifyContent: 'center', + alignItems: 'center', + background: colors.white, + borderRadius: 10, + boxShadow: '0 1px 3px rgba(0,0,0,0.25)', + paddingBottom: 16, +}); + +const Warning = styled(Text)({ + fontSize: 24, + fontWeight: 300, + textAlign: 'center', + margin: 16, +}); + +const AckButton = styled(Button)({ + type: 'warning', +}); + +export default function WarningEmployee(props: { + onClick: (event: React.MouseEvent) => any; +}) { + return ( + + + + You are using the open-source version of Flipper. You will get access + to more plugins. To use the internal version, please install it from + Managed Software Center + + Okay + + + ); +} diff --git a/src/fb-stubs/config.tsx b/src/fb-stubs/config.tsx index 2de59bef7..6edb5c1fe 100644 --- a/src/fb-stubs/config.tsx +++ b/src/fb-stubs/config.tsx @@ -10,4 +10,5 @@ export default { bugReportButtonVisible: false, showLogin: false, showFlipperRating: false, + warnFBEmployees: true, }; diff --git a/src/init.js b/src/init.js index 244b8e2d7..fd88f165c 100644 --- a/src/init.js +++ b/src/init.js @@ -7,6 +7,7 @@ import {Provider} from 'react-redux'; import ReactDOM from 'react-dom'; +import {useState, useEffect} from 'react'; import {ContextMenuProvider} from 'flipper'; import GK from './fb-stubs/GK.tsx'; import {init as initLogger} from './fb-stubs/Logger.tsx'; @@ -22,7 +23,10 @@ import config from './utils/processConfig.tsx'; import {stateSanitizer} from './utils/reduxDevToolsConfig.tsx'; import {initLauncherHooks} from './utils/launcher.tsx'; import initCrashReporter from './utils/electronCrashReporter.tsx'; +import fbConfig from './fb-stubs/config.tsx'; +import {isFBEmployee} from './utils/fbEmployee.js'; import path from 'path'; +import WarningEmployee from './chrome/WarningEmployee.tsx'; const store = createStore( reducers, @@ -35,15 +39,34 @@ const bugReporter = new BugReporter(logger, store); GK.init(); -const AppFrame = () => ( - - - - - - - -); +const AppFrame = () => { + const [warnEmployee, setWarnEmployee] = useState(false); + useEffect(() => { + if (fbConfig.warnFBEmployees) { + isFBEmployee().then(isEmployee => { + setWarnEmployee(isEmployee); + }); + } + }, []); + + return ( + + + + {warnEmployee ? ( + { + setWarnEmployee(false); + }} + /> + ) : ( + + )} + + + + ); +}; function init() { // $FlowFixMe: this element exists! diff --git a/src/utils/fbEmployee.js b/src/utils/fbEmployee.js new file mode 100644 index 000000000..4641d34df --- /dev/null +++ b/src/utils/fbEmployee.js @@ -0,0 +1,25 @@ +/** + * Copyright 2019-present Facebook. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * @format + */ + +import util from 'util'; +const exec = util.promisify(require('child_process').exec); + +const cmd = 'klist --json'; +const endWith = '@THEFACEBOOK.COM'; + +export function isFBEmployee(): Promise { + return exec(cmd).then( + (stdobj: {stderr: string, stdout: string}) => { + const principal = String(JSON.parse(stdobj.stdout).principal); + + return principal.endsWith(endWith); + }, + err => { + return false; + }, + ); +}