mirror of https://github.com/micromata/borgbackup-butler.git

Fin Reinhard
22.51.2019 1c087fae322a1b07bb7bd554ee10ff473c47c727
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
import React from 'react';
import {Alert} from 'reactstrap';
import {
    FormCheckbox,
    FormField,
    FormGroup,
    FormInput,
    FormLabel,
    FormLabelField,
    FormLabelInputField,
    FormOption,
    FormSelect
} from '../../general/forms/FormComponents';
import {getRestServiceUrl} from '../../../utilities/global';
import I18n from '../../general/translation/I18n';
import ErrorAlertGenericRestFailure from '../../general/ErrorAlertGenericRestFailure';
import Loading from '../../general/Loading';
 
class ConfigServerTab extends React.Component {
    loadConfig = () => {
        this.setState({
            loading: true,
            failed: false
        });
        fetch(getRestServiceUrl('configuration/config'), {
            method: 'GET',
            dataType: 'JSON',
            headers: {
                'Content-Type': 'text/plain; charset=utf-8'
            }
        })
            .then((resp) => {
                return resp.json()
            })
            .then((data) => {
                this.setState({
                    loading: false,
                    borgBinary: data.borgVersion.borgBinary,
                    borgCommand: data.borgVersion.borgCommand,
                    ...data
                })
            })
            .catch((error) => {
                console.log("error", error);
                this.setState({
                    loading: false,
                    failed: true
                });
            })
    };
 
    constructor(props) {
        super(props);
 
        this.state = {
            loading: true,
            failed: false,
            port: 9042,
            webdevelopmentMode: false,
            showDemoRepos: true,
            maxArchiveContentCacheCapacityMb: 100,
            redirect: false,
            borgCommand: null,
            borgBinary: null
        };
 
        this.handleTextChange = this.handleTextChange.bind(this);
        this.handleCheckboxChange = this.handleCheckboxChange.bind(this);
        this.loadConfig = this.loadConfig.bind(this);
    }
 
    componentDidMount() {
        this.loadConfig();
    }
 
    handleTextChange = event => {
        event.preventDefault();
        this.setState({[event.target.name]: event.target.value});
    }
 
    handleCheckboxChange = event => {
        this.setState({[event.target.name]: event.target.checked});
    }
 
    save() {
        var config = {
            port: this.state.port,
            maxArchiveContentCacheCapacityMb: this.state.maxArchiveContentCacheCapacityMb,
            webDevelopmentMode: this.state.webDevelopmentMode,
            showDemoRepos: this.state.showDemoRepos,
            borgVersion: {
                borgCommand: this.state.borgCommand,
                borgBinary: this.state.borgBinary
            }
        };
        return fetch(getRestServiceUrl("configuration/config"), {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify(config)
        })
    }
 
    static clearAllCaches() {
        fetch(getRestServiceUrl('configuration/clearAllCaches'), {
            method: 'GET',
            dataType: 'JSON',
            headers: {
                'Content-Type': 'text/plain; charset=utf-8'
            }
        })
    }
 
    render() {
        if (this.state.loading) {
            return <Loading/>;
        }
 
        if (this.state.failed) {
            return <ErrorAlertGenericRestFailure handleClick={this.loadConfig}/>;
        }
        const borgVersion = this.state.borgVersion;
        let borgInfoColor = 'success';
        let borgInfoMessage = `Borg version '${borgVersion.version}' is OK.`;
        if (!borgVersion.versionOK) {
            borgInfoColor = 'danger';
            borgInfoMessage = borgVersion.statusMessage;
        }
        return (
            <React.Fragment>
                <form>
                    <FormGroup>
                        <FormLabel>{'Borg command'}</FormLabel>
                        <FormField length={2}>
                            <FormSelect
                                value={this.state.borgBinary}
                                name={'borgBinary'}
                                onChange={this.handleTextChange}
                                hint={`Choose your OS and BorgButler will download and use a ready to run borg binary from ${borgVersion.binariesDownloadUrl} or choose a manual installed version.`}
                            >
                                {borgVersion.borgBinaries
                                    .map((binary, index) => <FormOption label={binary[1]} value={binary[0]}
                                                                        key={index}/>)}
                                <FormOption label={'Manual'} value={'manual'}/>
                            </FormSelect>
                        </FormField>
                        <FormInput fieldLength={8} name={'borgCommand'} value={this.state.borgCommand}
                                   onChange={this.handleTextChange}
                                   placeholder="Enter path of borg command"
                                   disabled={this.state.borgBinary !== "manual"}/>
                    </FormGroup>
                    <FormGroup>
                        <FormField length={4}/>
                        <Alert className={'col-sm-8'} color={borgInfoColor}>
                            {borgInfoMessage}
                        </Alert>
                    </FormGroup>
                    <FormLabelInputField label={'Port'} fieldLength={2} type="number" min={0} max={65535}
                                         step={1}
                                         name={'port'} value={this.state.port}
                                         onChange={this.handleTextChange}
                                         placeholder="Enter port"/>
                    <FormLabelInputField label={'Maximum disc capacity (MB)'} fieldLength={2} type="number" min={50}
                                         max={10000}
                                         step={50}
                                         name={'maxArchiveContentCacheCapacityMb'}
                                         value={this.state.maxArchiveContentCacheCapacityMb}
                                         onChange={this.handleTextChange}
                                         placeholder="Enter maximum Capacity"
                                         hint={`Limits the cache size of archive file lists in the local cache directory: ${this.state.cacheDir}`}/>
                    <FormLabelField label={'Show demo repositories'} fieldLength={2}>
                        <FormCheckbox checked={this.state.showDemoRepos}
                                      hint={'If true, some demo repositories are shown for testing the functionality of BorgButler without any further configuration and running borg backups.'}
                                      name="showDemoRepos"
                                      onChange={this.handleCheckboxChange}/>
                    </FormLabelField>
                    <FormLabelField label={<I18n name={'configuration.webDevelopmentMode'}/>} fieldLength={2}>
                        <FormCheckbox checked={this.state.webDevelopmentMode}
                                      hintKey={'configuration.webDevelopmentMode.hint'}
                                      name="webDevelopmentMode"
                                      onChange={this.handleCheckboxChange}/>
                    </FormLabelField>
                </form>
            </React.Fragment>
        );
    }
}
 
export default ConfigServerTab;