Skip to content

Commit

Permalink
feature: secret/env editor
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeTWC1984 committed Feb 18, 2021
1 parent c3ce293 commit a4daafe
Show file tree
Hide file tree
Showing 17 changed files with 1,907 additions and 1,951 deletions.
1 change: 1 addition & 0 deletions htdocs/index-dev.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<script src="codemirror/mode/shell/shell.js"></script>
<script src="codemirror/mode/groovy/groovy.js"></script>
<script src="codemirror/mode/clike/clike.js"></script>
<script src="codemirror/mode/properties/properties.js"></script>
<style>

.data_table tr:hover td {
Expand Down
6 changes: 3 additions & 3 deletions htdocs/js/pages/admin/APIKeys.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Class.add( Page.Admin, {
html += this.getSidebarTabs( 'api_keys',
[
['activity', "Activity Log"],
['conf_keys', "Config Keys"],
['conf_keys', "Configs"],
['api_keys', "API Keys"],
['categories', "Categories"],
['plugins', "Plugins"],
Expand Down Expand Up @@ -95,7 +95,7 @@ Class.add( Page.Admin, {
html += this.getSidebarTabs( 'new_api_key',
[
['activity', "Activity Log"],
['conf_keys', "Config Keys"],
['conf_keys', "Configs"],
['api_keys', "API Keys"],
['new_api_key', "New API Key"],
['categories', "Categories"],
Expand Down Expand Up @@ -188,7 +188,7 @@ Class.add( Page.Admin, {
html += this.getSidebarTabs( 'edit_api_key',
[
['activity', "Activity Log"],
['conf_keys', "Config Keys"],
['conf_keys', "Configs"],
['api_keys', "API Keys"],
['edit_api_key', "Edit API Key"],
['categories', "Categories"],
Expand Down
18 changes: 15 additions & 3 deletions htdocs/js/pages/admin/Activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ Class.add( Page.Admin, {
'^plugin': '<i class="fa fa-plug">&nbsp;</i>Plugin',
// '^apikey': '<i class="fa fa-key">&nbsp;</i>API Key',
'^apikey': '<i class="mdi mdi-key-variant">&nbsp;</i>API Key',
'^confkey': '<i class="fa fa-wrench">&nbsp;</i>Config',
'^confkey': '<i class="fa fa-wrench">&nbsp;</i>Config',
'^secret': '<i class="fa fa-lock">&nbsp;</i>Secret',
'^event': '<i class="fa fa-clock-o">&nbsp;</i>Event',
'^user': '<i class="fa fa-user">&nbsp;&nbsp;</i>User',
'server': '<i class="mdi mdi-desktop-tower mdi-lg">&nbsp;</i>Server',
Expand Down Expand Up @@ -41,7 +42,7 @@ Class.add( Page.Admin, {
html += this.getSidebarTabs( 'activity',
[
['activity', "Activity Log"],
['conf_keys', "Config Keys"],
['conf_keys', "Configs"],
['api_keys', "API Keys"],
['categories', "Categories"],
['plugins', "Plugins"],
Expand Down Expand Up @@ -128,8 +129,19 @@ Class.add( Page.Admin, {
case 'apikey_delete':
desc = 'API Key deleted: <b>' + item.api_key.title + '</b> (Key: ' + item.api_key.key + ')';
break;

// secrets
case 'secret_create':
desc = 'New Secret created: <b>' + item.secret + '</b> (encrypted: ' + item.encrypted + ')';
break;
case 'secret_update':
desc = 'Secret updated: <b>' + item.secret + '</b> (encrypted: ' + item.encrypted + ')';
break;
case 'secret_delete':
desc = 'Secret deleted: <b>' + item.secret + '</b> (encrypted: ' + item.encrypted + ')';
break;

// config keys
// Configs
case 'confkey_create':
desc = 'Config created: <b>' + item.conf_key.title + '</b> : ' + item.conf_key.key;
actions.push( '<a href="#Admin?sub=edit_config_key&id='+item.conf_key.id+'">Edit Config</a>' );
Expand Down
6 changes: 3 additions & 3 deletions htdocs/js/pages/admin/Categories.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Class.add( Page.Admin, {
html += this.getSidebarTabs( 'categories',
[
['activity', "Activity Log"],
['conf_keys', "Config Keys"],
['conf_keys', "Configs"],
['api_keys', "API Keys"],
['categories', "Categories"],
['plugins', "Plugins"],
Expand Down Expand Up @@ -103,7 +103,7 @@ Class.add( Page.Admin, {
html += this.getSidebarTabs( 'new_category',
[
['activity', "Activity Log"],
['conf_keys', "Config Keys"],
['conf_keys', "Configs"],
['api_keys', "API Keys"],
['categories', "Categories"],
['new_category', "New Category"],
Expand Down Expand Up @@ -199,7 +199,7 @@ Class.add( Page.Admin, {
html += this.getSidebarTabs( 'edit_category',
[
['activity', "Activity Log"],
['conf_keys', "Config Keys"],
['conf_keys', "Configs"],
['api_keys', "API Keys"],
['categories', "Categories"],
['edit_category', "Edit Category"],
Expand Down
101 changes: 77 additions & 24 deletions htdocs/js/pages/admin/ConfigKeys.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
// Cronicle Admin Page -- Config Keys
// Cronicle Admin Page -- Configs

Class.add( Page.Admin, {

gosub_conf_keys: function(args) {
gosub_conf_keys: function (args) {
// show Config Key list
app.setWindowTitle( "Config Keys" );
this.div.addClass('loading');
app.api.post( 'app/get_conf_keys', copy_object(args), this.receive_confkeys.bind(this) );
app.setWindowTitle("Configs");
var self = this;
self.div.addClass('loading');
self.secret = {};
app.api.post('/api/app/get_secret', { id: 'globalenv' }, function (resp) {
//if(err) console.log('failed to retreive secret');
if (resp.secret) self.secret = resp.secret;
app.api.post('app/get_conf_keys', copy_object(args), self.receive_confkeys.bind(self));
});
},

receive_confkeys: function(resp) {
// receive all Config Keys from server, render them sorted
// receive all Configs from server, render them sorted
this.lastConfigKeysResp = resp;

var html = '';
Expand All @@ -29,7 +35,7 @@ Class.add( Page.Admin, {
html += this.getSidebarTabs( 'conf_keys',
[
['activity', "Activity Log"],
['conf_keys', "Config Keys"],
['conf_keys', "Configs"],
['api_keys', "API Keys"],
['categories', "Categories"],
['plugins', "Plugins"],
Expand All @@ -43,36 +49,83 @@ Class.add( Page.Admin, {
html += '<div style="padding:20px 20px 30px 20px">';

html += '<div class="subtitle">';
html += 'Config Keys';
let env_lock = this.secret.encrypted ? '<i class="fa fa-lock">&nbsp;&nbsp;</i>' : ''
html += `Configs &nbsp;&nbsp;<span id="fe_env_lock">${env_lock}</span>`;

var showEnvEditor = app.showEnvEditor ? 'checked' : ''

html += `<div class="subtitle_widget"><a href="/conf" ><b>Config Viewer</b></a></div>`
html += `<div class="subtitle_widget" ><input ${showEnvEditor} id="fe_ee_env_toggle" onclick="$('#fe_ee_env').toggle();editor.refresh();app.showEnvEditor=!app.showEnvEditor;" type="checkbox"></input><label for="fe_ee_env_toggle">Show Env Editor</label></div>`

html += '<div class="clear"></div>';
html += '</div>';

var self = this;
html += this.getBasicTable( this.conf_keys, cols, 'key', function(item, idx) {

html += `
<div class="plugin_params_content" id="fe_ee_env" style="${app.showEnvEditor ? '' : 'display: none'}">
<textarea id="fe_ee_env_editor" ></textarea>
<div style="height:10px;"></div>
<center><table><tr>
<td><div id="env_enc_button" class="button" style="width:130px;" onMouseUp="$P().toggle_env_encryption()">${this.secret.encrypted ? 'Decrypt' : 'Encrypt'}</div></td>
<td width="40">&nbsp;</td>
<td><div class="button" style="width:130px;" onMouseUp="$P().update_globalenv()"><i class="fa fa-save">&nbsp;&nbsp;</i>Save</div></td>
</tr></table></center>
</div>
<script>
var editor = CodeMirror.fromTextArea(document.getElementById("fe_ee_env_editor"), {
mode: "text/x-properties",
styleActiveLine: true,
lineWrapping: false,
scrollbarStyle: "overlay",
lineNumbers: true,
matchBrackets: true
});
editor.setValue($P().secret.data);
</script>
`
html += this.getBasicTable(this.conf_keys, cols, 'key', function (item, idx) {
var actions = [
'<span class="link" onMouseUp="$P().edit_conf_key('+idx+')"><b>Edit</b></span>',
'<span class="link" onMouseUp="$P().delete_conf_key('+idx+')"><b>Delete</b></span>'
'<span class="link" onMouseUp="$P().edit_conf_key(' + idx + ')"><b>Edit</b></span>',
'<span class="link" onMouseUp="$P().delete_conf_key(' + idx + ')"><b>Delete</b></span>'
];

return [
`<div style="white-space:nowrap;" title="${item.description}" ><i class="fa fa-wrench">&nbsp;&nbsp;</i><b>${item.title}<b></div>`
, `<div class="activity_desc">${item.key}</div>`
, '<div style="white-space:nowrap;">' + actions.join(' | ') + '</div>'
];
} );
});

html += '<div style="height:30px;"></div>';
html += '<center><table><tr>';
html += '<td><div class="button" style="width:130px;" onMouseUp="$P().edit_conf_key(-1)"><i class="fa fa-plus-circle">&nbsp;&nbsp;</i>Add Config Key...</div></td>';
html += '<td width="40">&nbsp;</td>';
html += '<td><div class="button" style="width:130px;" onMouseUp="$P().do_reload_conf_key()"><i class="fa fa-refresh">&nbsp;&nbsp;</i>Reload</div></td>';
html += '<td><div class="button" style="width:130px;" onMouseUp="$P().edit_conf_key(-1)"><i class="fa fa-plus-circle">&nbsp;&nbsp;</i>Add Config Key...</div></td>';
html += '<td width="40">&nbsp;</td>';
html += '<td><div class="button" style="width:130px;" onMouseUp="$P().do_reload_conf_key()"><i class="fa fa-refresh">&nbsp;&nbsp;</i>Reload</div></td>';
html += '</tr></table></center>';

html += '</div>'; // padding
html += '</div>'; // sidebar tabs

this.div.html( html );

this.div.html(html);
},

update_globalenv: function () {
this.secret.data = editor.getValue();
app.showProgress(1.0, "Updating Enviroment Data...");

app.api.post('/api/app/update_secret', this.secret, function (resp) {
app.hideProgress();
if (resp.code == 0) app.showMessage('success', "Enviroment Data has been updated successfully.");

});
},

toggle_env_encryption: function () {
this.secret.encrypted = !this.secret.encrypted;
$("#env_enc_button").html(this.secret.encrypted ? 'Decrypt' : 'Encrypt');
$("#fe_env_lock").html(this.secret.encrypted ? '<i class="fa fa-lock">&nbsp;&nbsp;</i>' : '')

},

edit_conf_key: function(idx) {
Expand All @@ -96,7 +149,7 @@ Class.add( Page.Admin, {
html += this.getSidebarTabs( 'new_conf_key',
[
['activity', "Activity Log"],
['conf_keys', "Config Keys"],
['conf_keys', "Configs"],
['new_conf_key', "New Config Key"],
['api_keys', "API Keys"],
['categories', "Categories"],
Expand Down Expand Up @@ -189,7 +242,7 @@ Class.add( Page.Admin, {
html += this.getSidebarTabs( 'edit_conf_key',
[
['activity', "Activity Log"],
['conf_keys', "Config Keys"],
['conf_keys', "Configs"],
['edit_conf_key', "Edit Config Key"],
['api_keys', "API Keys"],
['categories', "Categories"],
Expand Down Expand Up @@ -260,7 +313,7 @@ Class.add( Page.Admin, {
reload_conf_key_finish: function(resp, tx) {
// new Config Key saved successfully
app.hideProgress();
app.showMessage('success', "Config Keys were reloaded successfully.");
app.showMessage('success', "Configs were reloaded successfully.");
window.scrollTo( 0, 0 );
},

Expand Down
6 changes: 3 additions & 3 deletions htdocs/js/pages/admin/Plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Class.add( Page.Admin, {
html += this.getSidebarTabs( 'plugins',
[
['activity', "Activity Log"],
['conf_keys', "Config Keys"],
['conf_keys', "Configs"],
['api_keys', "API Keys"],
['categories', "Categories"],
['plugins', "Plugins"],
Expand Down Expand Up @@ -134,7 +134,7 @@ Class.add( Page.Admin, {
html += this.getSidebarTabs( 'new_plugin',
[
['activity', "Activity Log"],
['conf_keys', "Config Keys"],
['conf_keys', "Configs"],
['api_keys', "API Keys"],
['categories', "Categories"],
['plugins', "Plugins"],
Expand Down Expand Up @@ -231,7 +231,7 @@ Class.add( Page.Admin, {
html += this.getSidebarTabs( 'edit_plugin',
[
['activity', "Activity Log"],
['conf_keys', "Config Keys"],
['conf_keys', "Configs"],
['api_keys', "API Keys"],
['categories', "Categories"],
['plugins', "Plugins"],
Expand Down
2 changes: 1 addition & 1 deletion htdocs/js/pages/admin/Servers.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Class.add( Page.Admin, {
html += this.getSidebarTabs( 'servers',
[
['activity', "Activity Log"],
['conf_keys', "Config Keys"],
['conf_keys', "Configs"],
['api_keys', "API Keys"],
['categories', "Categories"],
['plugins', "Plugins"],
Expand Down
6 changes: 3 additions & 3 deletions htdocs/js/pages/admin/Users.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Class.add(Page.Admin, {
html += this.getSidebarTabs('users',
[
['activity', "Activity Log"],
['conf_keys', "Config Keys"],
['conf_keys', "Configs"],
['api_keys', "API Keys"],
['categories', "Categories"],
['plugins', "Plugins"],
Expand Down Expand Up @@ -123,7 +123,7 @@ Class.add(Page.Admin, {
html += this.getSidebarTabs('new_user',
[
['activity', "Activity Log"],
['conf_keys', "Config Keys"],
['conf_keys', "Configs"],
['api_keys', "API Keys"],
['categories', "Categories"],
['plugins', "Plugins"],
Expand Down Expand Up @@ -271,7 +271,7 @@ Class.add(Page.Admin, {
html += this.getSidebarTabs('edit_user',
[
['activity', "Activity Log"],
['conf_keys', "Config Keys"],
['conf_keys', "Configs"],
['api_keys', "API Keys"],
['categories', "Categories"],
['plugins', "Plugins"],
Expand Down
3 changes: 2 additions & 1 deletion lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ module.exports = Class.create({
require('./api/job.js'),
require('./api/admin.js'),
require('./api/apikey.js'),
require('./api/confkey.js')
require('./api/confkey.js'),
require('./api/secret.js')
],

api_ping: function (args, callback) {
Expand Down
8 changes: 4 additions & 4 deletions lib/api/confkey.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Cronicle API Layer - Config Keys
// Cronicle API Layer - Configs
// Copyright (c) 2015 Joseph Huckaby
// Released under the MIT License

Expand Down Expand Up @@ -227,13 +227,13 @@ module.exports = Class.create({
args.user = user;
args.session = session;

self.logDebug(6, "Reloading Config Keys: ", params);
self.logDebug(6, "Reloading Configs: ", params);

let config = self.server.config.get()

self.storage.listGet('global/conf_keys', 0, 0, function (err, items, list) {
if (err) {
return self.doError('conf_key', "Failed to reload Config Keys: " + err, callback);
return self.doError('conf_key', "Failed to reload Configs: " + err, callback);
}
if (items) { // items only would exist on master
for (i = 0; i < items.length; i++) {
Expand All @@ -242,7 +242,7 @@ module.exports = Class.create({
}
}

self.logDebug(6, "Successfully Reloaded Config Keys: ");
self.logDebug(6, "Successfully Reloaded Configs: ");

callback({ code: 0 });

Expand Down
Loading

0 comments on commit a4daafe

Please sign in to comment.