import React, { Component } from 'react'; import Button from 'react-bootstrap/Button'; import Form from 'react-bootstrap/Form'; import Accordion from 'react-bootstrap/Accordion'; import Card from 'react-bootstrap/Card'; export default class ServerConfig extends Component { constructor(props) { super(props); this.state = { validated: false, config: {}, }; this.updateState = this.updateState.bind(this); this.applyConfiguration = this.applyConfiguration.bind(this); this.deleteConfiguration = this.deleteConfiguration.bind(this); this.fetchConfig = this.fetchConfig.bind(this); this.setConfigState = this.setConfigState.bind(this); this.validate = this.validate.bind(this); } componentDidMount() { this.fetchConfig(); } fetchConfig() { if (!window.require) { return; } const { ipcRenderer } = window.require('electron'); const cfg = ipcRenderer.sendSync('config-get', { repoID: this.props.repoID }); console.log('got config', cfg); this.setState({ config: cfg, validated: false, }); } onChangeServerType(e) { } setConfigState(cfg) { let d = { ...this.state.config }; for (let k in cfg) { d[k] = cfg[k]; } this.setState({ config: d, }); } updateState(e) { let d = { ...this.state.config }; d[e.target.id] = e.target.value; this.setState({ config: d, }); } isDescriptionValid() { return this.state.config.description !== ""; } isRemoteServerAddressValid() { if (!this.state.config.remoteServer) { return true; } return this.isValidHttpsURL(this.state.config.remoteServerAddress); } isRemoteServerPasswordValid() { if (!this.state.config.remoteServer) { return true; } return !!this.state.config.remoteServerPassword; } isRemoteServerCertValid() { if (!this.state.config.remoteServer) { return true; } return this.isValidSHA256(this.state.config.remoteServerCertificateSHA256); } validate() { if (!this.isDescriptionValid()) { return false; } if (!this.isRemoteServerAddressValid()) { return false; } if (!this.isRemoteServerPasswordValid()) { return false; } if (!this.isRemoteServerCertValid()) { return false; } return true; } applyConfiguration() { this.setState({ validated: true, }); if (!this.validate()) { return; } if (window.require) { const { ipcRenderer } = window.require('electron'); ipcRenderer.sendSync('config-save', { repoID: this.props.repoID, config: this.state.config }); } } deleteConfiguration() { if (window.require) { const { ipcRenderer } = window.require('electron'); ipcRenderer.sendSync('config-delete', { repoID: this.props.repoID, }); } } isValidHttpsURL(v) { try { const url = new URL(v); return url.protocol === "https:"; } catch (_) { return false; } } isValidSHA256(v) { const re = /^[0-9A-Fa-f]{64}$/g; return re.test(v); } render() { return <>
Description Description must be provided this.setConfigState({ remoteServer: false })} /> {!this.state.config.remoteServer &&
Show Advanced Options Override Path To kopia executable Uses embedded executable if not set. Override Configuration File Uses default configuration path, if not set.
} this.setConfigState({ remoteServer: true })} /> {this.state.config.remoteServer &&
Server Address Enter server URL https://server:port Must be valid server url starting with https:// Server Password Password cannot be empty. Server Certificate Fingerprint Must be valid server fingerprint
}

    {/* {JSON.stringify(this.state)} */} ; } }