// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved. // See License.txt for license information. var Client = require('../../utils/client.jsx'); var AsyncClient = require('../../utils/async_client.jsx'); var crypto = require('crypto'); export default class SqlSettings extends React.Component { constructor(props) { super(props); this.handleChange = this.handleChange.bind(this); this.handleSubmit = this.handleSubmit.bind(this); this.handleGenerate = this.handleGenerate.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.SqlSettings.Trace = React.findDOMNode(this.refs.Trace).checked; config.SqlSettings.AtRestEncryptKey = React.findDOMNode(this.refs.AtRestEncryptKey).value.trim(); if (config.SqlSettings.AtRestEncryptKey === '') { config.SqlSettings.AtRestEncryptKey = crypto.randomBytes(256).toString('base64').substring(0, 32); React.findDOMNode(this.refs.AtRestEncryptKey).value = config.SqlSettings.AtRestEncryptKey; } var MaxOpenConns = 10; if (!isNaN(parseInt(React.findDOMNode(this.refs.MaxOpenConns).value, 10))) { MaxOpenConns = parseInt(React.findDOMNode(this.refs.MaxOpenConns).value, 10); } config.SqlSettings.MaxOpenConns = MaxOpenConns; React.findDOMNode(this.refs.MaxOpenConns).value = MaxOpenConns; var MaxIdleConns = 10; if (!isNaN(parseInt(React.findDOMNode(this.refs.MaxIdleConns).value, 10))) { MaxIdleConns = parseInt(React.findDOMNode(this.refs.MaxIdleConns).value, 10); } config.SqlSettings.MaxIdleConns = MaxIdleConns; React.findDOMNode(this.refs.MaxIdleConns).value = MaxIdleConns; 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'); } ); } handleGenerate(e) { e.preventDefault(); React.findDOMNode(this.refs.AtRestEncryptKey).value = crypto.randomBytes(256).toString('base64').substring(0, 32); var s = {saveNeeded: true, serverError: this.state.serverError}; this.setState(s); } render() { var serverError = ''; if (this.state.serverError) { serverError =
; } var saveClass = 'btn'; if (this.state.saveNeeded) { saveClass = 'btn btn-primary'; } var dataSource = '**********' + this.props.config.SqlSettings.DataSource.substring(this.props.config.SqlSettings.DataSource.indexOf('@')); var dataSourceReplicas = ''; this.props.config.SqlSettings.DataSourceReplicas.forEach((replica) => { dataSourceReplicas += '[**********' + replica.substring(replica.indexOf('@')) + '] '; }); if (this.props.config.SqlSettings.DataSourceReplicas.length === 0) { dataSourceReplicas = 'none'; } return (

{'Note:'}

{'Changing properties in this section will require a server restart before taking effect.'}

{'SQL Settings'}

{this.props.config.SqlSettings.DriverName}

{dataSource}

{dataSourceReplicas}

{'Maximum number of idle connections held open to the database.'}

{'Maximum number of open connections held open to the database.'}

{'32-character salt available to encrypt and decrypt sensitive fields in database.'}

{'(Development Mode) When true, executing SQL statements are written to the log.'}

{serverError}
); } } SqlSettings.propTypes = { config: React.PropTypes.object };