diff --git a/web/libs/css/super.configEditor.css b/web/libs/css/super.configEditor.css index 03279023..7c47821d 100644 --- a/web/libs/css/super.configEditor.css +++ b/web/libs/css/super.configEditor.css @@ -1,6 +1,14 @@ .better-json-editor h3 { font-size: initial; - margin: 0 10px 10px 0; + margin: 10px 10px 20px 0; +} +.better-json-editor h3 > span{ + color: #bd4147; + background-color: #f8f9fa; + padding: 7px 10px; + border-radius: .25rem; + font-family: Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; + margin-bottom: 5px; } .better-json-editor .well .well { margin-left:20px; @@ -24,6 +32,9 @@ .better-json-editor table { width: 100%!important; margin-bottom: 10px; + overflow: hidden; + border-radius: 5px; + background: #fbfbfb; } .better-json-editor .floating-json textarea.form-control { padding: 20px; @@ -42,6 +53,9 @@ .better-json-editor .row { margin: 0; } +.better-json-editor .row p:visible:last-child{ + margin: 0; +} .better-json-editor .row > div { border: 1px solid #eee; border-radius: 5px; diff --git a/web/libs/js/super.configEditor.js b/web/libs/js/super.configEditor.js index aef66fb5..cab833fd 100644 --- a/web/libs/js/super.configEditor.js +++ b/web/libs/js/super.configEditor.js @@ -1,284 +1,303 @@ - -var schema = { - "title": "Shinobi Configuration", - "type": "object", - "properties": { - "subscriptionId": { - "type": "string", - }, - "port": { - "type": "integer", - "default": 8080 - }, - "passwordType": { - "type": "string", - "enum": [ - "sha256", - "sha512", - "md5" - ], - "default": "sha256" - }, - "addStorage": { - "type": "array", - "format": "table", - "title": "Additional Storage", - "description": "Separate storage locations that can be set for different monitors.", - "uniqueItems": true, - "items": { - "type": "object", - "title": "Storage Array", - "properties": { - "name": { - "type": "string", - }, - "path": { - "type": "string", - "default": "__DIR__/videos2" - } - } - }, - "default": [ - { - "name": "second", - "path": "__DIR__/videos2" - } - ] - }, - "plugins": { - "type": "array", - "format": "table", - "title": "Plugins", - "descripton": "Elaborate Plugin connection settings.", - "uniqueItems": true, - "items": { - "type": "object", - "title": "Plugin", - "properties": { - "plug": { - "type": "string", - "default": "pluginName" - }, - "key": { - "type": "string" - }, - "mode": { - "type": "string", - "enum": [ - "host", - "client" - ], - "default": "client" - }, - "https": { - "type": "boolean", - "descripton": "Only for Host mode.", - "default": false - }, - "host": { - "type": "string", - "descripton": "Only for Host mode.", - "default": "localhost" - }, - "port": { - "type": "integer", - "descripton": "Only for Host mode.", - "default": 8082 - }, - "type": { - "type": "string", - "default": "detector" - } - } - }, - "default": [ - { - "name": "second", - "path": "__DIR__/videos2" - } - ] - }, - "pluginKeys": { +$(document).ready(function(){ + var schema = { + "title": "Shinobi Configuration", "type": "object", - "format": "table", - "title": "Plugin Keys", - "description": "Quick client connection setup for plugins. Just add the plugin key to make it ready for incoming connections.", - "uniqueItems": true, - "items": { - "type": "object", - "title": "Plugin Key", - "properties": {} - } - }, - "db": { - "type": "object", - "format": "table", - "title": "Database Options", - "description": "Credentials to connect to where detailed information is stored.", - "properties": { - "host": { + "properties": { + "subscriptionId": { "type": "string", - "default": "127.0.0.1" }, - "user": { - "type": "string", - "default": "majesticflame" + "port": { + "type": "integer", + "default": 8080 + }, + "passwordType": { + "type": "string", + "enum": [ + "sha256", + "sha512", + "md5" + ], + "default": "sha256" + }, + "addStorage": { + "type": "array", + "format": "table", + "title": "Additional Storage", + "description": "Separate storage locations that can be set for different monitors.", + "uniqueItems": true, + "items": { + "type": "object", + "title": "Storage Array", + "properties": { + "name": { + "type": "string", + }, + "path": { + "type": "string", + "default": "__DIR__/videos2" + } + } }, - "password": { - "type": "string", - "default": "" + "default": [ + { + "name": "second", + "path": "__DIR__/videos2" + } + ] + }, + "plugins": { + "type": "array", + "format": "table", + "title": "Plugins", + "descripton": "Elaborate Plugin connection settings.", + "uniqueItems": true, + "items": { + "type": "object", + "title": "Plugin", + "properties": { + "plug": { + "type": "string", + "default": "pluginName" + }, + "key": { + "type": "string" + }, + "mode": { + "type": "string", + "enum": [ + "host", + "client" + ], + "default": "client" + }, + "https": { + "type": "boolean", + "descripton": "Only for Host mode.", + "default": false + }, + "host": { + "type": "string", + "descripton": "Only for Host mode.", + "default": "localhost" + }, + "port": { + "type": "integer", + "descripton": "Only for Host mode.", + "default": 8082 + }, + "type": { + "type": "string", + "default": "detector" + } + } }, - "database": { - "type": "string", - "default": "ccio" - }, - "port": { - "type": "integer", - "default": 3306 + "default": [ + { + "name": "second", + "path": "__DIR__/videos2" + } + ] + }, + "pluginKeys": { + "type": "object", + "format": "table", + "title": "Plugin Keys", + "description": "Quick client connection setup for plugins. Just add the plugin key to make it ready for incoming connections.", + "uniqueItems": true, + "items": { + "type": "object", + "title": "Plugin Key", + "properties": {} } }, - "default": { - "host": "127.0.0.1", - "user": "majesticflame", - "password": "", - "database": "ccio", - "port":3306 - } - }, - "cron": { - "type": "object", - "format": "table", - "title": "CRON Options", - "properties": { - "key": { - "type": "string", - }, - "deleteOld": { - "type": "boolean", - "description": "cron will delete videos older than Max Number of Days per account.", - "default": true - }, - "deleteNoVideo": { - "type": "boolean", - "description": "cron will delete SQL rows that it thinks have no video files.", - "default": true - }, - "deleteOverMax": { - "type": "boolean", - "description": "cron will delete files that are over the set maximum storage per account.", - "default": true - }, - } - }, - "mail": { - "type": "object", - "format": "table", - "title": "Email Options", - "properties": { - "service": { - "type": "string", - }, - "host": { - "type": "string", - }, - "auth": { + "db": { "type": "object", + "format": "table", + "title": "Database Options", + "description": "Credentials to connect to where detailed information is stored.", "properties": { - "user": { - "type": "string", - }, - "pass": { - "type": "string", - }, + "host": { + "type": "string", + "default": "127.0.0.1" + }, + "user": { + "type": "string", + "default": "majesticflame" + }, + "password": { + "type": "string", + "default": "" + }, + "database": { + "type": "string", + "default": "ccio" + }, + "port": { + "type": "integer", + "default": 3306 + } }, - }, - "secure": { - "type": "boolean", - "default": false - }, - "ignoreTLS": { - "type": "boolean", - }, - "requireTLS": { - "type": "boolean", - }, - "port": { - "type": "integer", - } + "default": { + "host": "127.0.0.1", + "user": "majesticflame", + "password": "", + "database": "ccio", + "port":3306 + } + }, + "cron": { + "type": "object", + "format": "table", + "title": "CRON Options", + "properties": { + "key": { + "type": "string", + }, + "deleteOld": { + "type": "boolean", + "description": "cron will delete videos older than Max Number of Days per account.", + "default": true + }, + "deleteNoVideo": { + "type": "boolean", + "description": "cron will delete SQL rows that it thinks have no video files.", + "default": true + }, + "deleteOverMax": { + "type": "boolean", + "description": "cron will delete files that are over the set maximum storage per account.", + "default": true + }, + } + }, + "mail": { + "type": "object", + "format": "table", + "title": "Email Options", + "properties": { + "service": { + "type": "string", + }, + "host": { + "type": "string", + }, + "auth": { + "type": "object", + "properties": { + "user": { + "type": "string", + }, + "pass": { + "type": "string", + }, + }, + }, + "secure": { + "type": "boolean", + "default": false + }, + "ignoreTLS": { + "type": "boolean", + }, + "requireTLS": { + "type": "boolean", + }, + "port": { + "type": "integer", + } + } + }, + "detectorMergePamRegionTriggers": { + "type": "boolean", + "default": true + }, + "doSnapshot": { + "type": "boolean", + "default": true + }, + "discordBot": { + "type": "boolean", + "default": false + }, + "dropInEventServer": { + "type": "boolean", + "default": false + }, + "ftpServer": { + "type": "boolean", + "default": false + }, + "oldPowerVideo": { + "type": "boolean", + "default": false + }, + "defaultMjpeg": { + "type": "string", + }, + "streamDir": { + "type": "string", + }, + "videosDir": { + "type": "string", + }, + "windowsTempDir": { + "type": "string", + } + } + }; + + var configurationTab = $('#config') + var configurationForm = configurationTab.find('form') + + // Set default options + JSONEditor.defaults.options.theme = 'bootstrap3'; + JSONEditor.defaults.options.iconlib = 'fontawesome4'; + + // Initialize the editor + var configurationEditor = new JSONEditor(document.getElementById("configForHumans"),{ + theme: 'bootstrap3', + schema: schema + }); + + configurationEditor.setValue(shinobiConfig); + + // configurationEditor.on("change", function() { + // // Do something... + // }); + var submitConfiguration = function(){ + var errors = configurationEditor.validate(); + console.log(errors.length) + console.log(errors) + if(errors.length === 0) { + var newConfiguration = JSON.stringify(configurationEditor.getValue(),null,3) + var html = '

This is a change being applied to the configuration file (conf.json). Are you sure you want to do this? You must restart Shinobi for these changes to take effect. The JSON below is what you are about to save.

' + html += `
${newConfiguration}
` + $.confirm.create({ + title: 'Save Configuration conf.json', + body: html, + clickOptions: { + class: 'btn-success', + title: lang.Save, + }, + clickCallback: function(){ + $.post('<%=originalURL%><%=config.webPaths.superApiPrefix%>'+$user.sessionKey+'/system/configure',{ + data: newConfiguration + },function(data){ + // console.log(data) + }) + } + }) + }else{ + new PNotify({text:'Invalid JSON Syntax, Cannot Save.',type:'error'}) } - }, - "detectorMergePamRegionTriggers": { - "type": "boolean", - "default": true - }, - "doSnapshot": { - "type": "boolean", - "default": true - }, - "discordBot": { - "type": "boolean", - "default": false - }, - "dropInEventServer": { - "type": "boolean", - "default": false - }, - "ftpServer": { - "type": "boolean", - "default": false - }, - "oldPowerVideo": { - "type": "boolean", - "default": false - }, - "defaultMjpeg": { - "type": "string", - }, - "streamDir": { - "type": "string", - }, - "videosDir": { - "type": "string", - }, - "windowsTempDir": { - "type": "string", } - } -}; - -// Set default options -JSONEditor.defaults.options.theme = 'bootstrap3'; -JSONEditor.defaults.options.iconlib = 'fontawesome4'; - -// Initialize the editor -var editor = new JSONEditor(document.getElementById("configForHumans"),{ - theme: 'bootstrap3', - schema: schema, - //schema: { - // type: "object", - // properties: { - // name: { "type": "string" } - // } - //} -}); - -// Set the value -editor.setValue(shinobiConfig); -//editor.setValue({ -// name: "John Smith" -//}); - -// Get the value -var data = editor.getValue(); -console.log(data); // "John Smith" - -// Validate -var errors = editor.validate(); -if(errors.length) { - // Not valid -} - -// Listen for changes -editor.on("change", function() { - // Do something... -}); + configurationTab.find('.submit').click(function(){ + submitConfiguration() + }) + configurationForm.submit(function(e){ + e.preventDefault() + submitConfiguration() + return false; + }) + window.configurationEditor = configurationEditor +}) diff --git a/web/libs/js/super.preferences.js b/web/libs/js/super.preferences.js new file mode 100644 index 00000000..e31b2b93 --- /dev/null +++ b/web/libs/js/super.preferences.js @@ -0,0 +1,18 @@ +$(document).ready(function(){ + var changeSuperPreferencesTab = $('#changeSuperPreferences') + var changeSuperPreferencesForm = changeSuperPreferencesTab.find('form') + changeSuperPreferencesTab.find('.submit').click(function(){ + changeSuperPreferencesForm.submit() + }) + changeSuperPreferencesForm.submit(function(e){ + e.preventDefault() + var formValues = $(this).serializeObject() + // $.ccio.cx({f:'accounts',ff:'saveSuper',form:formValues}) + $.post(superApiPrefix + $user.sessionKey + '/accounts/saveSettings',{ + data: JSON.stringify(formValues) + },function(data){ + console.log(data) + }) + return false + }) +}) diff --git a/web/libs/js/super.systemTab.js b/web/libs/js/super.systemTab.js new file mode 100644 index 00000000..196891bf --- /dev/null +++ b/web/libs/js/super.systemTab.js @@ -0,0 +1,70 @@ +$(document).ready(function(){ + var systemsControlsTab = $('#system') + systemsControlsTab.find('[system]').click(function(e){ + switch($(this).attr('system')){ + case'deleteLogs': + var html = 'Do you want to delete these logs? User logs will not be deleted.' + $.confirm.create({ + title: `${lang['Delete Logs']} ${e.u}`, + body: html, + clickOptions: { + class: 'btn-danger', + title: lang.Delete, + }, + clickCallback: function(){ + $.get(superApiPrefix + $user.sessionKey + '/logs/delete',function(data){ + console.log(data) + }) + $.logs.e.find('table').empty() + } + }) + break; + case'update': + var html = 'Updating Shinobi means overwriting files. If you have modified any files yourself you should update Shinobi manually.' + $.confirm.create({ + title: `${lang.Update} Shinobi?`, + body: html, + clickOptions: { + class: 'btn-danger', + title: lang.Update, + }, + clickCallback: function(){ + $.get(superApiPrefix + $user.sessionKey + '/system/update',function(data){ + console.log(data) + }) + } + }) + break; + } + }) + systemsControlsTab.find('[restart]').click(function(e){ + var html = '' + var target = $(this).attr('restart').split(',') + target.forEach(function(v){ + switch(v){ + case'system': + html += '

Do you want to restart the core (camera.js)? plugins will not be restarted. They will reconnect when Shinobi is back online.

' + break; + case'cron': + html += '

Do you want to restart the CRON (cron.js)?

' + break; + case'logs': + html += '

Flush PM2 console logs? The logs saved in the database will not be deleted.

' + break; + } + }) + $.confirm.create({ + title: `${lang.Restart}?`, + body: html, + clickOptions: { + class: 'btn-danger', + title: lang.Restart, + }, + clickCallback: function(){ + $.get(superApiPrefix + $user.sessionKey + '/system/restart/'+encodeURIComponent(target),function(data){ + console.log(data) + }) + } + }) + }) +}) diff --git a/web/pages/blocks/changeSuperPreferences.ejs b/web/pages/blocks/changeSuperPreferences.ejs index a668083f..af088f10 100644 --- a/web/pages/blocks/changeSuperPreferences.ejs +++ b/web/pages/blocks/changeSuperPreferences.ejs @@ -37,3 +37,4 @@ + diff --git a/web/pages/blocks/superConfigEditor.ejs b/web/pages/blocks/superConfigEditor.ejs index c3bd404c..b2402dfe 100644 --- a/web/pages/blocks/superConfigEditor.ejs +++ b/web/pages/blocks/superConfigEditor.ejs @@ -15,12 +15,7 @@
-
- -
-
- -
+
diff --git a/web/pages/blocks/superSystemTab.ejs b/web/pages/blocks/superSystemTab.ejs new file mode 100644 index 00000000..400cac34 --- /dev/null +++ b/web/pages/blocks/superSystemTab.ejs @@ -0,0 +1,33 @@ + +
+
+
+ diff --git a/web/pages/super.ejs b/web/pages/super.ejs index d79e0106..424679c2 100644 --- a/web/pages/super.ejs +++ b/web/pages/super.ejs @@ -111,38 +111,7 @@ <% include blocks/superConfigEditor.ejs %>
- -
-
-
+ <% include blocks/superSystemTab.ejs %>
<% include blocks/changeSuperPreferences.ejs %> @@ -314,130 +283,6 @@ $.ccio.init=function(x,d,z,k){ } //logs $.logs={e:$('#logs')} -//config editor -<% - var stringedConfig = JSON.stringify(plainConfig) -%> -var config = <%- JSON.stringify(plainConfig) || [] %> -$.conf={e:$('#config')}; -$.conf.f = $.conf.e.find('form') -$.conf.draw=$.conf.e.find('[name="json"]') -$.conf.valid=1; -$.conf.draw.val(JSON.stringify(<%-stringedConfig%>,null,3)) -$.conf.draw.keyup(function(){ - var msg='' - var color='' - try{ - config = $.parseJSON($.conf.draw.val()) - msg = 'Valid JSON' - color = 'success' - $.conf.valid = 1 - }catch(er){ - msg = 'Not a valid JSON' - color = 'danger' - $.conf.valid = 0 - } - new PNotify({text:msg,type:color}) -}) -$.conf.e.find('.submit').click(function(e){ - $.conf.f.submit() -}) -$.conf.f.submit(function(e){ - e.preventDefault() - if($.conf.valid===1){ - $.confirm.e.modal('show'); - $.confirm.title.html('Save Configuration conf.json') - e.html='

This is a change being applied to the configuration file (conf.json). Are you sure you want to do this? You must restart Shinobi for these changes to take effect. The JSON below is what you are about to save.

' - e.html+='
'+JSON.stringify($.parseJSON($.conf.draw.val()),null,3)+'
' - $.confirm.body.html(e.html) - $.confirm.click({title:lang.Save,class:'btn-success'},function(){ - $.post('<%=originalURL%><%=config.webPaths.superApiPrefix%>'+$user.sessionKey+'/system/configure',{ - data: $.conf.draw.val() - },function(data){ - // console.log(data) - }) - // $.ccio.cx({f:'system',ff:'configure',data:$.parseJSON($.conf.draw.val())}) - }); - }else{ - new PNotify({text:'Invalid JSON Syntax, Cannot Save.',type:'error'}) - } - return false; -}) -//sys controls -$.system={e:$('#system')} -$.system.e.find('[system]').click(function(e){ - switch($(this).attr('system')){ - case'deleteLogs': - $.confirm.e.modal('show'); - $.confirm.title.html('<%=lang['Delete Logs']%> '+e.u+'') - e.html='Do you want to delete these logs? User logs will not be deleted.' - $.confirm.body.html(e.html) - $.confirm.click({title:lang.Delete,class:'btn-danger'},function(){ - // $.ccio.cx({f:'logs',ff:'delete',ke:'$'}) - $.get('<%=originalURL%><%=config.webPaths.superApiPrefix%>'+$user.sessionKey+'/logs/delete',function(data){ - console.log(data) - }) - $.logs.e.find('table').empty() - }); - break; - case'update': - $.confirm.e.modal('show') - $.confirm.title.html('<%=lang.Update%> Shinobi?') - $.confirm.body.html('Updating Shinobi means overwriting files. If you have modified any files yourself you should update Shinobi manually.') - $.confirm.click({title:lang.Update,class:'btn-danger'},function(){ - // $.ccio.cx({f:'system',ff:'update'}) - $.get('<%=originalURL%><%=config.webPaths.superApiPrefix%>'+$user.sessionKey+'/system/update',function(data){ - console.log(data) - }) - }) - break; - } -}) -$.system.e.find('[restart]').click(function(e){ - $.confirm.e.modal('show'); - e.html='' - e.title='' - e.target=$(this).attr('restart').split(',') - e.target.forEach(function(v){ - switch(v){ - case'system': - e.html+='

Do you want to restart the core (camera.js)? plugins will not be restarted. They will reconnect when Shinobi is back online.

' - break; - case'cron': - e.html+='

Do you want to restart the CRON (cron.js)?

' - break; - case'logs': - e.html+='

Flush PM2 console logs? The logs saved in the database will not be deleted.

' - break; - } - }) - $.confirm.title.html('<%=lang.Restart%>?') - $.confirm.body.html(e.html) - $.confirm.click({title:lang.Restart,class:'btn-danger'},function(){ - // $.ccio.cx({f:'system',ff:'restart',target:e.target}) - $.get('<%=originalURL%><%=config.webPaths.superApiPrefix%>'+$user.sessionKey+'/system/restart/'+encodeURIComponent(e.target),function(data){ - console.log(data) - }) - }); -}) -$.changeSuperPreferences = { - window : $('#changeSuperPreferences') -} -$.changeSuperPreferences.form = $.changeSuperPreferences.window.find('form') -$.changeSuperPreferences.form.find('.submit').click(function(){ - $.changeSuperPreferences.form.submit() -}) -$.changeSuperPreferences.form.submit(function(e){ - e.preventDefault() - var formValues = $(this).serializeObject() - // $.ccio.cx({f:'accounts',ff:'saveSuper',form:formValues}) - $.post('<%=originalURL%><%=config.webPaths.superApiPrefix%>'+$user.sessionKey+'/accounts/saveSettings',{ - data: JSON.stringify(formValues) - },function(data){ - console.log(data) - }) - return false -}) //// $(document).ready(function(){ <% if(!users || !(users instanceof Array)){ %>