/* * Copyright 2007-2017 Charles du Jeu - Abstrium SAS * This file is part of Pydio. * * Pydio is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Pydio 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with Pydio. If not, see . * * The latest code can be found at . */ (function(global){ const Panel = React.createClass({ componentDidMount: function(){ this.loadKeys(); }, getInitialState: function(){ return {loaded: false, keys: {}} }, generateAllowed: function(){ return this.props.pydio.getPluginConfigs("authfront.keystore").get("USER_GENERATE_KEYS"); }, loadKeys: function(){ this.setState({loaded: false}); PydioApi.getClient().request({ get_action: 'keystore_list_tokens' }, function(transport) { if (transport.responseJSON){ this.setState({keys: transport.responseJSON}); } this.setState({loaded: true}); }.bind(this)); }, removeKey: function(k){ if(!window.confirm(MessageHash['keystore.7'])){ return; } let params = {get_action:'keystore_revoke_tokens'}; if(k){ params['key_id'] = k; } PydioApi.getClient().request(params, () => {this.loadKeys()}); }, generateKey: function(){ if(!this.generateAllowed()) return; PydioApi.getClient().request({ get_action:"keystore_generate_auth_token" }, function(transport){ const data = transport.responseJSON; this.setState({ newKey:data//'Token : ' + data['t'] + '
Private : ' + data['p'] }); this.loadKeys(); }.bind(this)) }, render: function(){ let keys = []; for(let k in this.state.keys){ if(!this.state.keys.hasOwnProperty(k)) continue; let item = this.state.keys[k]; let remove = function(){ this.removeKey(k); }.bind(this); let deviceId = item['DEVICE_ID'] || ''; deviceId = deviceId.substring(0 , 13) + (deviceId.length > 13 ? '...' : ''); const primaryText = item.DEVICE_DESC + (item.DEVICE_OS !== item.DEVICE_DESC ? ' - ' + item.DEVICE_OS : ''); const secondaryText = 'From: ' + (item.DEVICE_IP === '::1' ? 'Local' : item.DEVICE_IP) + (deviceId ? ' - Id: ' + deviceId : ''); const leftIcon = const rightIcon = keys.push( ); } let mess = this.props.pydio.MessageHash; let tokenResult; if(this.state.newKey){ const getMessage = id => mess[id]; tokenResult = (
{this.setState({newKey: null})}}/>
); } let list = this.state.loaded ? {keys} : ; return (
{mess['keystore.9']}
{this.generateAllowed() && } {this.removeKey();}} iconStyle={{color:'white'}}/>
{tokenResult} {list}
); } }); global.ApiKeys = { Panel: MaterialUI.Style.muiThemeable()(Panel) }; })(window);