// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. // See License.txt for license information. import $ from 'jquery'; import ReactDOM from 'react-dom'; import Client from 'utils/web_client.jsx'; import * as AsyncClient from 'utils/async_client.jsx'; import {injectIntl, intlShape, defineMessages, FormattedMessage, FormattedHTMLMessage} from 'react-intl'; const DefaultSessionLength = 30; const DefaultMaximumLoginAttempts = 10; const DefaultSessionCacheInMinutes = 10; var holders = defineMessages({ listenExample: { id: 'admin.service.listenExample', defaultMessage: 'Ex ":8065"' }, attemptExample: { id: 'admin.service.attemptExample', defaultMessage: 'Ex "10"' }, segmentExample: { id: 'admin.service.segmentExample', defaultMessage: 'Ex "g3fgGOXJAQ43QV7rAh6iwQCkV4cA1Gs"' }, googleExample: { id: 'admin.service.googleExample', defaultMessage: 'Ex "7rAh6iwQCkV4cA1Gsg3fgGOXJAQ43QV"' }, sessionDaysEx: { id: 'admin.service.sessionDaysEx', defaultMessage: 'Ex "30"' }, corsExample: { id: 'admin.service.corsEx', defaultMessage: 'http://example.com' }, saving: { id: 'admin.service.saving', defaultMessage: 'Saving Config...' } }); import React from 'react'; class ServiceSettings extends React.Component { constructor(props) { super(props); this.handleChange = this.handleChange.bind(this); this.handleSubmit = this.handleSubmit.bind(this); this.state = { saveNeeded: false, serverError: null }; } handleChange() { var s = {saveNeeded: true, serverError: this.state.serverError}; this.setState(s); } handleSubmit(e) { e.preventDefault(); $('#save-button').button('loading'); var config = this.props.config; config.ServiceSettings.ListenAddress = ReactDOM.findDOMNode(this.refs.ListenAddress).value.trim(); if (config.ServiceSettings.ListenAddress === '') { config.ServiceSettings.ListenAddress = ':8065'; ReactDOM.findDOMNode(this.refs.ListenAddress).value = config.ServiceSettings.ListenAddress; } config.ServiceSettings.SegmentDeveloperKey = ReactDOM.findDOMNode(this.refs.SegmentDeveloperKey).value.trim(); config.ServiceSettings.GoogleDeveloperKey = ReactDOM.findDOMNode(this.refs.GoogleDeveloperKey).value.trim(); config.ServiceSettings.EnableIncomingWebhooks = ReactDOM.findDOMNode(this.refs.EnableIncomingWebhooks).checked; config.ServiceSettings.EnableOutgoingWebhooks = ReactDOM.findDOMNode(this.refs.EnableOutgoingWebhooks).checked; config.ServiceSettings.EnablePostUsernameOverride = ReactDOM.findDOMNode(this.refs.EnablePostUsernameOverride).checked; config.ServiceSettings.EnablePostIconOverride = ReactDOM.findDOMNode(this.refs.EnablePostIconOverride).checked; config.ServiceSettings.EnableTesting = ReactDOM.findDOMNode(this.refs.EnableTesting).checked; config.ServiceSettings.EnableDeveloper = ReactDOM.findDOMNode(this.refs.EnableDeveloper).checked; config.ServiceSettings.EnableSecurityFixAlert = ReactDOM.findDOMNode(this.refs.EnableSecurityFixAlert).checked; config.ServiceSettings.EnableInsecureOutgoingConnections = ReactDOM.findDOMNode(this.refs.EnableInsecureOutgoingConnections).checked; config.ServiceSettings.EnableCommands = ReactDOM.findDOMNode(this.refs.EnableCommands).checked; config.ServiceSettings.EnableOnlyAdminIntegrations = ReactDOM.findDOMNode(this.refs.EnableOnlyAdminIntegrations).checked; if (this.refs.EnableMultifactorAuthentication) { config.ServiceSettings.EnableMultifactorAuthentication = ReactDOM.findDOMNode(this.refs.EnableMultifactorAuthentication).checked; } //config.ServiceSettings.EnableOAuthServiceProvider = ReactDOM.findDOMNode(this.refs.EnableOAuthServiceProvider).checked; var MaximumLoginAttempts = DefaultMaximumLoginAttempts; if (!isNaN(parseInt(ReactDOM.findDOMNode(this.refs.MaximumLoginAttempts).value, 10))) { MaximumLoginAttempts = parseInt(ReactDOM.findDOMNode(this.refs.MaximumLoginAttempts).value, 10); } if (MaximumLoginAttempts < 1) { MaximumLoginAttempts = 1; } config.ServiceSettings.MaximumLoginAttempts = MaximumLoginAttempts; ReactDOM.findDOMNode(this.refs.MaximumLoginAttempts).value = MaximumLoginAttempts; var SessionLengthWebInDays = DefaultSessionLength; if (!isNaN(parseInt(ReactDOM.findDOMNode(this.refs.SessionLengthWebInDays).value, 10))) { SessionLengthWebInDays = parseInt(ReactDOM.findDOMNode(this.refs.SessionLengthWebInDays).value, 10); } if (SessionLengthWebInDays < 1) { SessionLengthWebInDays = 1; } config.ServiceSettings.SessionLengthWebInDays = SessionLengthWebInDays; ReactDOM.findDOMNode(this.refs.SessionLengthWebInDays).value = SessionLengthWebInDays; var SessionLengthMobileInDays = DefaultSessionLength; if (!isNaN(parseInt(ReactDOM.findDOMNode(this.refs.SessionLengthMobileInDays).value, 10))) { SessionLengthMobileInDays = parseInt(ReactDOM.findDOMNode(this.refs.SessionLengthMobileInDays).value, 10); } if (SessionLengthMobileInDays < 1) { SessionLengthMobileInDays = 1; } config.ServiceSettings.SessionLengthMobileInDays = SessionLengthMobileInDays; ReactDOM.findDOMNode(this.refs.SessionLengthMobileInDays).value = SessionLengthMobileInDays; var SessionLengthSSOInDays = DefaultSessionLength; if (!isNaN(parseInt(ReactDOM.findDOMNode(this.refs.SessionLengthSSOInDays).value, 10))) { SessionLengthSSOInDays = parseInt(ReactDOM.findDOMNode(this.refs.SessionLengthSSOInDays).value, 10); } if (SessionLengthSSOInDays < 1) { SessionLengthSSOInDays = 1; } config.ServiceSettings.SessionLengthSSOInDays = SessionLengthSSOInDays; ReactDOM.findDOMNode(this.refs.SessionLengthSSOInDays).value = SessionLengthSSOInDays; var SessionCacheInMinutes = DefaultSessionCacheInMinutes; if (!isNaN(parseInt(ReactDOM.findDOMNode(this.refs.SessionCacheInMinutes).value, 10))) { SessionCacheInMinutes = parseInt(ReactDOM.findDOMNode(this.refs.SessionCacheInMinutes).value, 10); } if (SessionCacheInMinutes < -1) { SessionCacheInMinutes = -1; } config.ServiceSettings.SessionCacheInMinutes = SessionCacheInMinutes; ReactDOM.findDOMNode(this.refs.SessionCacheInMinutes).value = SessionCacheInMinutes; config.ServiceSettings.AllowCorsFrom = ReactDOM.findDOMNode(this.refs.AllowCorsFrom).value.trim(); Client.saveConfig( config, () => { AsyncClient.getConfig(); this.setState({ serverError: null, saveNeeded: false }); $('#save-button').button('reset'); }, (err) => { this.setState({ serverError: err.message, saveNeeded: true }); $('#save-button').button('reset'); } ); } render() { const {formatMessage} = this.props.intl; var serverError = ''; if (this.state.serverError) { serverError =
; } var saveClass = 'btn'; if (this.state.saveNeeded) { saveClass = 'btn btn-primary'; } let mfaSetting; if (global.window.mm_license.IsLicensed === 'true' && global.window.mm_license.MFA === 'true') { mfaSetting = (

); } return (

{mfaSetting}

{serverError}
); } } //
// //
// // //

{'When enabled Mattermost will act as an OAuth2 Provider. Changing this will require a server restart before taking effect.'}

//
//
ServiceSettings.propTypes = { intl: intlShape.isRequired, config: React.PropTypes.object }; export default injectIntl(ServiceSettings);