diff --git a/src/config.jsx b/src/config.jsx index 6367663..e3fbc6a 100644 --- a/src/config.jsx +++ b/src/config.jsx @@ -32,36 +32,72 @@ this.handleInputChange = this.handleInputChange.bind(this); this.handleSubmit = this.handleSubmit.bind(this); this.setConfig = this.setConfig.bind(this); - this.prepareConfig = this.prepareConfig.bind(this); this.fileReadFailed = this.fileReadFailed.bind(this); + this.readConfig = this.readConfig.bind(this); this.file = null; + this.config = null; this.state = { - config: null, - file_error: null, + config_loaded: false, + file_error: false, submitting: "none", + shell: "", + notice: "", + latency: "", + payload: "", + log_input: false, + log_output: true, + log_window: true, + limit_rate: "", + limit_burst: "", + limit_action: "", + file_path: "", + syslog_facility: "", + syslog_priority: "", + journal_augment: "", + journal_priority: "", + writer: "", }; } handleInputChange(e) { const value = e.target.type === 'checkbox' ? e.target.checked : e.target.value; const name = e.target.name; - const config = this.state.config; - config[name] = value; - - this.forceUpdate(); - } - - prepareConfig() { - this.state.config.latency = parseInt(this.state.config.latency); - if (this.state.config.input === true) { - // log.input - } + const state = {}; + state[name] = value; + this.setState(state); } handleSubmit(event) { this.setState({submitting:"block"}); - this.prepareConfig(); - this.file.replace(this.state.config).done(() => { + let config = { + shell: this.state.shell, + notice: this.state.notice, + latency: parseInt(this.state.latency), + payload: parseInt(this.state.payload), + log: { + input: this.state.log_input, + output: this.state.log_output, + window: this.state.log_window, + }, + limit: { + rate: parseInt(this.state.limit_rate), + burst: parseInt(this.state.limit_burst), + action: this.state.limit_action, + }, + file: { + path: this.state.file_path, + }, + syslog: { + facility: this.state.syslog_facility, + priority: this.state.syslog_priority, + }, + journal: { + priority: this.state.journal_priority, + augment: this.state.journal_augment + }, + writer: this.state.writer + }; + this.file.replace(config).done(() => { this.setState({submitting:"none"}); }) .fail((error) => { @@ -71,15 +107,47 @@ } setConfig(data) { - this.setState({config: data}); + delete data.configuration; + delete data.args; + var flattenObject = function(ob) { + var toReturn = {}; + + for (var i in ob) { + if (!ob.hasOwnProperty(i)) continue; + + if ((typeof ob[i]) == 'object') { + var flatObject = flattenObject(ob[i]); + for (var x in flatObject) { + if (!flatObject.hasOwnProperty(x)) continue; + + toReturn[i + '_' + x] = flatObject[x]; + } + } else { + toReturn[i] = ob[i]; + } + } + return toReturn; + }; + let state = flattenObject(data); + state.config_loaded = true; + this.setState(state); } - fileReadFailed(reason) { - console.log(reason); - this.setState({file_error: reason}); + getConfig() { + let proc = cockpit.spawn(["tlog-rec-session", "--configuration"]); + + proc.stream((data) => { + this.setConfig(json.parse(data, null, true)); + proc.close(); + }); + + proc.fail((fail) => { + console.log(fail); + this.readConfig(); + }); } - componentDidMount() { + readConfig() { let parseFunc = function(data) { return json.parse(data, null, true); }; @@ -95,27 +163,37 @@ this.file = cockpit.file("/etc/tlog/tlog-rec-session.conf", { syntax: syntax_object, - // binary: boolean, - // max_read_size: int, superuser: true, - // host: string }); - + /* let promise = this.file.read(); promise.done((data) => { if (data === null) { this.fileReadFailed(); - return; } - this.setConfig(data); }).fail((data) => { this.fileReadFailed(data); }); + */ + } + + fileReadFailed(reason) { + console.log(reason); + this.setState({file_error: reason}); + } + + componentWillMount() { + this.getConfig(); + this.readConfig(); } render() { - if (this.state.config != null && this.state.file_error === null) { + if (this.state.config_loaded === false && this.state.file_error === false) { + return ( +
Loading
+ ); + } else if (this.state.config_loaded === true && this.state.file_error === false) { return (
@@ -123,71 +201,68 @@ - + - + - + - + - + - + - + - + - - - - - + + + + + - + - + @@ -292,11 +370,12 @@ } setConfig(data) { + console.log(data); const config = {...data['session_recording']}; this.setState(config); } - componentDidMount() { + componentWillMount() { let syntax_object = { parse: ini.parse, stringify: ini.stringify @@ -319,10 +398,11 @@ handleSubmit(e) { this.setState({submitting:"block"}); const obj = {}; - obj.users = this.state.users; - obj.groups = this.state.groups; - obj.scope = this.state.scope; - obj['session_recording'] = this.state; + obj.session_recording = {}; + obj.session_recording.scope = this.state.scope; + obj.session_recording.users = this.state.users; + obj.session_recording.groups = this.state.groups; + let _this = this; this.file.replace(obj).done(function() { _this.setState({submitting:"none"}); @@ -350,6 +430,7 @@ + {this.state.scope === "some" && + } + {this.state.scope === "some" && + } -
-
-
-
-
- +
- +
- +
-
-
- @@ -196,59 +271,62 @@
-
-
- -
-
- + +
+
- +
- + -
+
+ Saving...
@@ -358,19 +439,21 @@ className="form-control" onChange={this.handleInputChange} />
+ value={this.state.groups} + className="form-control" onChange={this.handleInputChange} />
+ - - + Saving...