Skip to content

Commit

Permalink
Add tlog-rec-session.conf config
Browse files Browse the repository at this point in the history
  • Loading branch information
sabbaka committed Jun 22, 2018
1 parent 3110dcb commit 56f4c17
Show file tree
Hide file tree
Showing 5 changed files with 346 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"bootstrap-datepicker": "1.8.0",
"c3": "0.4.23",
"bootstrap-datetime-picker": "2.4.4",
"comment-json": "^1.1.3",
"d3": "3.5.17",
"jquery": "3.3.1",
"jquery-flot": "0.8.3",
Expand Down
54 changes: 54 additions & 0 deletions pkg/session_recording/config.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<!DOCTYPE html>
<!--
This file is part of Cockpit.
Copyright (C) 2017 Red Hat, Inc.
Cockpit is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
Cockpit is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with Cockpit; If not, see <http://www.gnu.org/licenses/>.
-->
<html>

<head>
<title translate>Journal</title>
<meta charset="utf-8">
<link href="../base1/patternfly.css" rel="stylesheet">
<link href="table.css" rel="stylesheet">
<script type="text/javascript" src="../base1/cockpit.js"></script>
<script src="../*/po.js"></script>
</head>

<body>
<div>
<div class="container-fluid">
<div class="row">
<div class="col-md-4">
<ol class="breadcrumb">
<li><a href="/cockpit/@localhost/session_recording/index.html">Session Recording</a></li>
<li class="active">Configuration</li>
</ol>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="panel panel-default" >
<div class="panel-heading"><span>Configuration</span></div>
<div class="panel-body" id="view"></div>
</div>
</div>
</div>
</div>
<script type="text/javascript" src="config.js"></script>
</body>

</html>
279 changes: 279 additions & 0 deletions pkg/session_recording/config.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,279 @@
/*
* This file is part of Cockpit.
*
* Copyright (C) 2017 Red Hat, Inc.
*
* Cockpit is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Cockpit is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Cockpit; If not, see <http://www.gnu.org/licenses/>.
*/

(function() {
"use strict";

let cockpit = require("cockpit");
let React = require("react");
let json = require('comment-json');

let Config = class extends React.Component {
constructor(props) {
super(props);
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.file = null;
this.state = {
config: null,
file_error: null,
submitting: "none",
}
}

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
}
}

handleSubmit(event) {
this.setState({submitting:"block"});
console.log(event);
this.prepareConfig();
this.file.replace(this.state.config).done( () => {
console.log('updated');
this.setState({submitting:"none"});
}).fail( (error) => {
console.log(error);
});
event.preventDefault();
}

setConfig(data) {
console.log(data);
this.setState({config: data});
}

fileReadFailed(reason) {
console.log(reason);
this.setState({file_error: reason});
console.log('failed to read file');
}

componentDidMount() {
let parseFunc = function(data) {
console.log(data);
// return data;
return json.parse(data, null, true);
};

let stringifyFunc = function(data) {
return json.stringify(data, null, true);
};
// needed for cockpit.file usage
let syntax_object = {
parse: parseFunc,
stringify: stringifyFunc,
};

this.file = cockpit.file("/etc/tlog/tlog-rec-session.conf", {
syntax: syntax_object,
// binary: boolean,
// max_read_size: int,
superuser: true,
// host: string
});

console.log(this.file);

let promise = this.file.read();

promise.done((data) => {
if (data === null) {
this.fileReadFailed
return;
}
this.setConfig(data);
}).fail( (data) => {
this.fileReadFailed(data);
});
}

render() {
if (this.state.config != null && this.state.file_error === null) {
return (
<form onSubmit={this.handleSubmit}>
<table className="form-table-ct col-sm-3">
<tbody>
<tr>
<td className="top"><label htmlFor="shell" className="control-label">Shell</label></td>
<td>
<input type="text" id="shell" name="shell" value={this.state.config.shell}
className="form-control" onChange={this.handleInputChange} />
</td>
</tr>
<tr>
<td className="top"><label htmlFor="notice" className="control-label">Notice</label></td>
<td>
<input type="text" id="notice" name="notice" value={this.state.config.notice}
className="form-control" onChange={this.handleInputChange} />
</td>
</tr>
<tr>
<td className="top"><label htmlFor="latency" className="control-label">Latency</label></td>
<td>
<input type="text" id="latency" name="latency" value={this.state.config.latency}
className="form-control" onChange={this.handleInputChange} />
</td>
</tr>
<tr>
<td className="top"><label htmlFor="latency" className="control-label">Payload Size, bytes</label></td>
<td>
<input type="text" id="payload" name="payload" value={this.state.config.payload}
className="form-control" onChange={this.handleInputChange} />
</td>
</tr>
<tr>
<td className="top"><label htmlFor="input" className="control-label">Log User's Input</label></td>
<td>
<input type="checkbox" id="input" name="input" defaultChecked={this.state.config.log.input}
onChange={this.handleInputChange} />
</td>
</tr>
<tr>
<td className="top"><label htmlFor="output" className="control-label">Log User's Output</label></td>
<td>
<input type="checkbox" id="output" name="output" defaultChecked={this.state.config.log.output}
onChange={this.handleInputChange} />
</td>
</tr>
<tr>
<td className="top"><label htmlFor="window" className="control-label">Log Window Resize</label></td>
<td>
<input type="checkbox" id="window" name="window" defaultChecked={this.state.config.log.window}
onChange={this.handleInputChange} />
</td>
</tr>

<tr>
<td className="top"><label htmlFor="rate" className="control-label">Limit Rate, bytes/sec</label></td>
<td>
<input type="text" id="rate" name="rate" value={this.state.config.limit.rate}
className="form-control" onChange={this.handleInputChange} />
</td>
</tr>
<tr>
<td className="top"><label htmlFor="burst" className="control-label">Burst, bytes</label></td>
<td>
<input type="text" id="burst" name="burst" value={this.state.config.limit.burst}
className="form-control" onChange={this.handleInputChange} />
</td>
</tr>
<tr>
<td className="top"><label htmlFor="action" className="control-label">Logging Limit Action</label></td>
<td>
<select name="action" id="action" onChange={this.handleInputChange} value={this.state.config.limit.action}>
<option value=""></option>
<option value="pass">Pass</option>
<option value="delay">Delay</option>
<option value="drop">Drop</option>
</select>
</td>
</tr>
<tr>
<td className="top"><label htmlFor="path" className="control-label">File Path</label></td>
<td>
<input type="text" id="path" name="path" defaultChecked={this.state.config.file.path}
className="form-control" onChange={this.handleInputChange} />
</td>
</tr>
<tr>
<td className="top"><label htmlFor="facility" className="control-label">Syslog Facility</label></td>
<td>
<input type="text" id="facility" name="facility" value={this.state.config.syslog.facility}
className="form-control" onChange={this.handleInputChange} />
</td>
</tr>
<tr>
<td className="top"><label htmlFor="syslog_priority" className="control-label">Syslog Priority</label></td>
<td>
<input type="text" id="syslog_priority" name="syslog_priority" value={this.state.config.syslog.priority}
className="form-control" onChange={this.handleInputChange} />
</td>
</tr>
<tr>
<td className="top"><label htmlFor="path" className="control-label">Journal Priority</label></td>
<td>
<select name="journal_priority" id="journal_priority" onChange={this.handleInputChange} value={this.state.config.journal.priority}>
<option value=""></option>
<option value="info">Info</option>
</select>
</td>
</tr>
<tr>
<td className="top"><label htmlFor="path" className="control-label">Journal Augment</label></td>
<td>
<input type="checkbox" id="augment" name="augment" defaultChecked={this.state.config.journal.augment}
onChange={this.handleInputChange} />
</td>

</tr>
<tr>
<td className="top"><label htmlFor="path" className="control-label">Writer</label></td>
<td>
<select name="writer" id="writer" onChange={this.handleInputChange} value={this.state.config.writer}>
<option value=""></option>
<option value="journal">Journal</option>
<option value="syslog">Syslog</option>
<option value="file">File</option>
</select>
</td>
</tr>
<tr>
<td className="top">
</td>
<div className="spinner spinner-sm" style={{display: this.state.submitting}}></div>
<td>
<button className="btn btn-default" type="submit">Save</button>

</td>
</tr>
</tbody>
</table>
</form>
);
} else {
return (
<div className="alert alert-danger">
<span className="pficon pficon-error-circle-o"></span>
<p><strong>There is no configuration file of tlog present in your system.</strong></p>
<p>Please, check the /etc/tlog/tlog-rec-session.conf or if tlog is installed.</p>
<p><strong>{this.state.file_error}</strong></p>
</div>
);
}
}
}

React.render(<Config />, document.getElementById('view'));
}());
7 changes: 7 additions & 0 deletions pkg/session_recording/recordings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,13 @@
<UserPicker onUsernameChange={this.props.onUsernameChange}
username={this.props.username} />
</td>
<td className="top">
<label className="control-label" for="config">Configuration</label>
</td>
<td className="top">
<a href="/cockpit/@localhost/session_recording/config.html" className="btn btn-default" data-toggle="modal">
<i className="fa fa-cog" aria-hidden="true"></i></a>
</td>
</th>
</table>
</div>
Expand Down
5 changes: 5 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ var info = {
"session_recording/recordings.css",
],

"session_recording/config": [
"session_recording/config.jsx",
],

"systemd/services": [
"systemd/init.js",
"systemd/services.css",
Expand Down Expand Up @@ -261,6 +265,7 @@ var info = {

"session_recording/manifest.json",
"session_recording/index.html",
"session_recording/config.html",

"systemd/index.html",
"systemd/logs.html",
Expand Down

0 comments on commit 56f4c17

Please sign in to comment.