Commit 5f6fb6b3 authored by Alain Takoudjou's avatar Alain Takoudjou

slapos_monitoring: make instance configuration is more flexible

parent 70be8d8d
...@@ -107,7 +107,7 @@ ...@@ -107,7 +107,7 @@
<value> <string encoding="cdata"><![CDATA[ <value> <string encoding="cdata"><![CDATA[
CACHE MANIFEST\n CACHE MANIFEST\n
# generated on Fri, 21 April 2016 11:47:33 +0000\n # generated on Fri, 28 April 2016 11:47:33 +0000\n
# XXX + fonts\n # XXX + fonts\n
# images/ajax-loader.gif\n # images/ajax-loader.gif\n
CACHE:\n CACHE:\n
...@@ -326,7 +326,7 @@ NETWORK:\n ...@@ -326,7 +326,7 @@ NETWORK:\n
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>950.43165.31733.30549</string> </value> <value> <string>950.53381.7699.19968</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -344,7 +344,7 @@ NETWORK:\n ...@@ -344,7 +344,7 @@ NETWORK:\n
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1461242916.65</float> <float>1461861221.53</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -110,7 +110,7 @@ ...@@ -110,7 +110,7 @@
{{#if key}} {{#if key}}
<a rel="{{../index}}" class="prop-edit" title='Edit this value'><i class="fa fa-pencil"></i></a> <a rel="{{../index}}" class="prop-edit" title='Edit this value'><i class="fa fa-pencil"></i></a>
{{else}} {{else}}
<a><span class="ui-text-desabled" title='Edit this value'><i class="fa fa-pencil"></i></sapn></a> <a><span class="ui-text-desabled" title='Edit this value'><i class="fa fa-pencil"></i></span></a>
{{/if}} {{/if}}
</td> </td>
</tr> </tr>
......
...@@ -229,7 +229,7 @@ ...@@ -229,7 +229,7 @@
</item> </item>
<item> <item>
<key> <string>actor</string> </key> <key> <string>actor</string> </key>
<value> <string>zope</string> </value> <value> <string>superalain</string> </value>
</item> </item>
<item> <item>
<key> <string>comment</string> </key> <key> <string>comment</string> </key>
...@@ -243,7 +243,7 @@ ...@@ -243,7 +243,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>949.64120.38038.28552</string> </value> <value> <string>950.52007.35517.18278</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -261,7 +261,7 @@ ...@@ -261,7 +261,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1458568209.8</float> <float>1461847634.36</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
/*global window, rJS, btoa */ /*global window, rJS, btoa, Handlebars, $ */
/*jslint nomen: true, indent: 2, maxerr: 3*/ /*jslint nomen: true, indent: 2, maxerr: 3*/
(function (window, rJS) { (function (window, rJS, btoa, Handlebars, $) {
"use strict"; "use strict";
var gadget_klass = rJS(window), var gadget_klass = rJS(window),
...@@ -491,4 +491,4 @@ ...@@ -491,4 +491,4 @@
}); });
}); });
}(window, rJS)); }(window, rJS, btoa, Handlebars, $));
\ No newline at end of file \ No newline at end of file
...@@ -225,7 +225,7 @@ ...@@ -225,7 +225,7 @@
</item> </item>
<item> <item>
<key> <string>actor</string> </key> <key> <string>actor</string> </key>
<value> <string>zope</string> </value> <value> <string>superalain</string> </value>
</item> </item>
<item> <item>
<key> <string>comment</string> </key> <key> <string>comment</string> </key>
...@@ -239,7 +239,7 @@ ...@@ -239,7 +239,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>950.3039.65061.43776</string> </value> <value> <string>950.53037.35338.8209</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -257,7 +257,7 @@ ...@@ -257,7 +257,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1459761305.99</float> <float>1461861381.81</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -225,7 +225,7 @@ ...@@ -225,7 +225,7 @@
</item> </item>
<item> <item>
<key> <string>actor</string> </key> <key> <string>actor</string> </key>
<value> <string>zope</string> </value> <value> <string>superalain</string> </value>
</item> </item>
<item> <item>
<key> <string>comment</string> </key> <key> <string>comment</string> </key>
...@@ -239,7 +239,7 @@ ...@@ -239,7 +239,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>949.54108.24790.65006</string> </value> <value> <string>950.51968.20423.17902</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -257,7 +257,7 @@ ...@@ -257,7 +257,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1459439672.87</float> <float>1461832953.11</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
</script> </script>
<script src="gadget_monitoring_static.js" type="text/javascript"></script> <script src="gadget_monitoring_static.js" type="text/javascript"></script>
<script src="gadget_monitoring_tooltipster.min.js" type="text/javascript"></script>
</head> </head>
<body> <body>
<div data-gadget-url="gadget_monitoring_jio.html" data-gadget-scope="jio_gadget" data-gadget-sandbox="public"></div> <div data-gadget-url="gadget_monitoring_jio.html" data-gadget-scope="jio_gadget" data-gadget-sandbox="public"></div>
...@@ -73,7 +74,7 @@ ...@@ -73,7 +74,7 @@
<div data-gadget-url="gadget_monitoring_widget_listbox.html" data-gadget-scope="listbox"></div> <div data-gadget-url="gadget_monitoring_widget_listbox.html" data-gadget-scope="listbox"></div>
<form class="configure"> <form class="configure">
<label class="configure-auth"> <label class="configure-auth">
<input type="checkbox" name="configure-auth">Set Authentication for these URLs <input type="checkbox" name="configure-auth">Set or update credentials
</label> </label>
<div class="auth-block padding-lr-20 border-gray" style="display: none"> <div class="auth-block padding-lr-20 border-gray" style="display: none">
<div class="ui-form"> <div class="ui-form">
...@@ -84,12 +85,12 @@ ...@@ -84,12 +85,12 @@
</div> </div>
<div class="ui-form"> <div class="ui-form">
<div class="ui-field-contain"> <div class="ui-field-contain">
<label data-i18n="Password:">Password:</label> <label data-i18n="Password:">Password <span class='tooltip'>(?)</span>:</label>
<input type="password" name="password" required value="-"/> <input type="password" name="password" required value="-"/>
</div> </div>
</div> </div>
<label class="configure-auth"> <label class="configure-auth">
<input type="checkbox" name="configure-newpwd">Configure new password now <input type="checkbox" name="configure-newpwd">Change all current password(s)
</label> </label>
<div class="new-password" style="display: none"> <div class="new-password" style="display: none">
<div class="ui-form"> <div class="ui-form">
......
...@@ -225,7 +225,7 @@ ...@@ -225,7 +225,7 @@
</item> </item>
<item> <item>
<key> <string>actor</string> </key> <key> <string>actor</string> </key>
<value> <string>zope</string> </value> <value> <string>superalain</string> </value>
</item> </item>
<item> <item>
<key> <string>comment</string> </key> <key> <string>comment</string> </key>
...@@ -239,7 +239,7 @@ ...@@ -239,7 +239,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>950.14227.11651.3003</string> </value> <value> <string>950.53466.15484.25019</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -257,7 +257,7 @@ ...@@ -257,7 +257,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1459506471.61</float> <float>1461860815.17</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -3,6 +3,14 @@ ...@@ -3,6 +3,14 @@
(function (window, rJS, RSVP, $, btoa, Rusha) { (function (window, rJS, RSVP, $, btoa, Rusha) {
"use strict"; "use strict";
var gadget_klass = rJS(window),
templater = gadget_klass.__template_element,
opml_url_template = Handlebars.compile(
templater.getElementById("template-opmlurl-list").innerHTML
),
hashCode = new Rusha().digestFromString;
function validateHttpUrl(value) { function validateHttpUrl(value) {
if (/\(?(?:(http|https):\/\/)(?:((?:[^\W\s]|\.|-|[:]{1})+)@{1})?((?:www.)?(?:[^\W\s]|\.|-)+[\.][^\W\s]{2,4}|localhost(?=\/)|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|\[[\dabcedf:]+\])(?::(\d*))?([\/]?[^\s\?]*[\/]{1})*(?:\/?([^\s\n\?\[\]\{\}\#]*(?:(?=\.)){1}|[^\s\n\?\[\]\{\}\.\#]*)?([\.]{1}[^\s\?\#]*)?)?(?:\?{1}([^\s\n\#\[\]]*))?([\#][^\s\n]*)?\)?/i.test(value)) { if (/\(?(?:(http|https):\/\/)(?:((?:[^\W\s]|\.|-|[:]{1})+)@{1})?((?:www.)?(?:[^\W\s]|\.|-)+[\.][^\W\s]{2,4}|localhost(?=\/)|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|\[[\dabcedf:]+\])(?::(\d*))?([\/]?[^\s\?]*[\/]{1})*(?:\/?([^\s\n\?\[\]\{\}\#]*(?:(?=\.)){1}|[^\s\n\?\[\]\{\}\.\#]*)?([\.]{1}[^\s\?\#]*)?)?(?:\?{1}([^\s\n\#\[\]]*))?([\#][^\s\n]*)?\)?/i.test(value)) {
return true; return true;
...@@ -129,6 +137,33 @@ ...@@ -129,6 +137,33 @@
}); });
} }
function loginFromLocalCredential(gadget, url) {
/* Try to login from registered credential */
return gadget.props.login_gadget.getUrlInfo( hashCode(url) )
.push(function (credential_dict) {
if (!credential_dict) {
return {};
}
return credential_dict;
})
.push(function (credential) {
if (credential) {
return gadget.props.login_gadget.login(credential.url, credential.hash)
.then(function(result) {
if (result.status === 'OK') {
return credential.hash;
} else {
return undefined;
}
}, function(error) {
return undefined;
});
} else {
return undefined;
}
});
}
function checkCredential(gadget, url, hash) { function checkCredential(gadget, url, hash) {
// Verify if login and password are correct for this URL // Verify if login and password are correct for this URL
return gadget.props.login_gadget.login(url, hash) return gadget.props.login_gadget.login(url, hash)
...@@ -136,18 +171,32 @@ ...@@ -136,18 +171,32 @@
if (result.status === 'OK') { if (result.status === 'OK') {
return {status: 'OK'}; return {status: 'OK'};
} else { } else {
return loginFromLocalCredential(gadget, url)
.push(function (result) {
if (result) {
return {status: 'OK', hash: result, url: url};
}
return {status: 'KO', msg: error.msg + ' (' + url + ')'}; return {status: 'KO', msg: error.msg + ' (' + url + ')'};
});
} }
}, function(error) { }, function(error) {
return {status: 'KO', msg: error.msg + '(' + url + ')'}; return loginFromLocalCredential(gadget, url)
.push(function (result) {
if (result) {
return {status: 'OK', hash: result, url: url};
}
return {status: 'KO', msg: error.msg + ' (' + url + ')'};
});
}); });
} }
function changeMonitorPassword(gadget, url, password, hash) { function changeMonitorPassword(gadget, credential_dict, login, password) {
var jio_gadget, var url,
jio_gadget,
jio_options; jio_options;
url = credential_dict.url;
url += (url.endsWith('/') ? '':'/') + 'config/'; url += (url.endsWith('/') ? '':'/') + 'config/';
jio_options = { jio_options = {
type: "query", type: "query",
...@@ -156,15 +205,15 @@ ...@@ -156,15 +205,15 @@
sub_storage: { sub_storage: {
type: "dav", type: "dav",
url: url, url: url,
basic_login: hash basic_login: credential_dict.hash
} }
} }
}; };
gadget.props.gindex += 1; gadget.props.gindex += 1;
return gadget.declareGadget("gadget_monitoring_jio.html", return gadget.declareGadget("gadget_monitoring_jio.html",
{ {
element: gadget.props.element, //element: gadget.props.element,
scope: 'jio_gadget' + gadget.props.gindex, scope: 'jio_' + gadget.props.gindex + "_gadget",
sandbox: "public" sandbox: "public"
} }
).push(function(new_gadget) { ).push(function(new_gadget) {
...@@ -185,7 +234,10 @@ ...@@ -185,7 +234,10 @@
return new Error("Cannot get document at : " % url); return new Error("Cannot get document at : " % url);
}) })
.push(function (result) { .push(function (result) {
return gadget.props.login_gadget.updateUrlValue(credential_dict.url, login, password)
.push(function() {
return {status: 'OK'}; return {status: 'OK'};
});
}, function (error) { }, function (error) {
console.log(error); console.log(error);
return {status: 'ERROR', code: error.target.status}; return {status: 'ERROR', code: error.target.status};
...@@ -206,7 +258,6 @@ ...@@ -206,7 +258,6 @@
return gadget.props.jio_gadget.allDocs({}) return gadget.props.jio_gadget.allDocs({})
.push(function (doc) { .push(function (doc) {
if (!doc) { if (!doc) {
console.log(doc);
gadget.props.element.querySelector('.msgtext-box') gadget.props.element.querySelector('.msgtext-box')
.innerHTML += "<span class='ui-text-error'>" + url + " [ " + title + " ] is not reachable!</span><br/>"; .innerHTML += "<span class='ui-text-error'>" + url + " [ " + title + " ] is not reachable!</span><br/>";
return false; return false;
...@@ -216,14 +267,6 @@ ...@@ -216,14 +267,6 @@
}); });
} }
var gadget_klass = rJS(window),
templater = gadget_klass.__template_element,
opml_url_template = Handlebars.compile(
templater.getElementById("template-opmlurl-list").innerHTML
),
hashCode = new Rusha().digestFromString;
gadget_klass gadget_klass
.ready(function (g) { .ready(function (g) {
g.props = {}; g.props = {};
...@@ -316,6 +359,19 @@ ...@@ -316,6 +359,19 @@
.push(function () { .push(function () {
return $(gadget.props.element.querySelector("a[href='#config-" + gadget.props.selected + "']")).trigger('click'); return $(gadget.props.element.querySelector("a[href='#config-" + gadget.props.selected + "']")).trigger('click');
}) })
.push(function () {
var text = "Give user name and password that you have.<br/>If required " +
"credentials will be updated from what you provided.";
return $('.tooltip').tooltipster({
animation: 'fade',
delay: 200,
theme: 'tooltipster-shadow',
touchDevices: true,
content: $("<h2><strong>Configure Private Access</strong></h2><p>" + text + "</p>"),
interactive: true,
trigger: 'hover'
});
})
.push(function () { .push(function () {
var promise_list = []; var promise_list = [];
promise_list.push(loopEventListener( promise_list.push(loopEventListener(
...@@ -515,6 +571,7 @@ ...@@ -515,6 +571,7 @@
cnew_password = '', cnew_password = '',
reload = true, reload = true,
rows_list = gadget.props.listbox.property_dict.data_result, rows_list = gadget.props.listbox.property_dict.data_result,
not_changed_dict = {},
config_promise_list = []; config_promise_list = [];
if (rows_list.length > 0) { if (rows_list.length > 0) {
...@@ -556,12 +613,15 @@ ...@@ -556,12 +613,15 @@
for (i = 0; i < status_list.length; i += 1) { for (i = 0; i < status_list.length; i += 1) {
if (status_list[i].status !== 'OK') { if (status_list[i].status !== 'OK') {
error_msg += 'Login/password invalid for: ' + rows_list[i].title + '. ' + status_list[i].msg + '<br/>'; error_msg += 'Login/password invalid for: ' + rows_list[i].title + '. ' + status_list[i].msg + '<br/>';
} else if (status_list[i].hasOwnProperty('url')) {
not_changed_dict[ hashCode( status_list[i].url ) ] = status_list[i].hash;
} }
} }
return error_msg; return error_msg;
}) })
.push(function (error_msg) { .push(function (error_msg) {
var tmp, var tmp,
tmp_hash,
i; i;
if (error_msg !== '') { if (error_msg !== '') {
gadget.props.element.querySelector('.configure .ui-text-error') gadget.props.element.querySelector('.configure .ui-text-error')
...@@ -572,10 +632,6 @@ ...@@ -572,10 +632,6 @@
} }
if (username !== '' && password !== '') { if (username !== '' && password !== '') {
if (new_password !== '') {
old_password = password;
password = new_password;
}
for (i = 0; i < rows_list.length; i += 1) { for (i = 0; i < rows_list.length; i += 1) {
if (validateHttpUrl(rows_list[i].url)) { if (validateHttpUrl(rows_list[i].url)) {
tmp = { tmp = {
...@@ -584,13 +640,12 @@ ...@@ -584,13 +640,12 @@
parent_url: gadget.props.opml_url parent_url: gadget.props.opml_url
//parent_title: root_name //parent_title: root_name
}; };
credential_dict[ hashCode( tmp.url ) ] = tmp; tmp_hash = hashCode( tmp.url );
if (not_changed_dict.hasOwnProperty(tmp_hash)) {
tmp.hash = not_changed_dict[tmp_hash];
} }
credential_dict[ tmp_hash ] = tmp;
} }
if (credential_dict) {
config_promise_list.push(
gadget.props.login_gadget.setUrlDict(credential_dict)
);
} }
} }
config_promise_list.push( config_promise_list.push(
...@@ -603,17 +658,24 @@ ...@@ -603,17 +658,24 @@
var key, var key,
promise_list = []; promise_list = [];
if (new_password !== '') { if (new_password !== '') {
// Change current passwords and save them to local storage
for (key in credential_dict) { for (key in credential_dict) {
promise_list.push( promise_list.push(
changeMonitorPassword( changeMonitorPassword(
gadget, gadget,
credential_dict[key].url, credential_dict[key],
new_password, username,
btoa(username + ':' + old_password)) new_password)
); );
} }
}
return RSVP.all(promise_list); return RSVP.all(promise_list);
} else {
// Only save provided credentials
return gadget.props.login_gadget.setUrlDict(credential_dict)
.push(function () {
return [];
});
}
}) })
.push(function (result_list) { .push(function (result_list) {
var i, var i,
...@@ -621,7 +683,7 @@ ...@@ -621,7 +683,7 @@
for (i = 0; i < result_list.length; i += 1) { for (i = 0; i < result_list.length; i += 1) {
if (result_list[i].status === 'ERROR') { if (result_list[i].status === 'ERROR') {
gadget.props.element.querySelector('.configure .ui-text-error') gadget.props.element.querySelector('.configure .ui-text-error')
.innerHTML += 'ERROR ' + result_list[i].code + ': Failed to save new password!'; .innerHTML += 'ERROR ' + result_list[i].code + ': Failed to save password! Please try again. <br/>';
has_error = true; has_error = true;
} }
} }
......
...@@ -225,7 +225,7 @@ ...@@ -225,7 +225,7 @@
</item> </item>
<item> <item>
<key> <string>actor</string> </key> <key> <string>actor</string> </key>
<value> <string>zope</string> </value> <value> <string>superalain</string> </value>
</item> </item>
<item> <item>
<key> <string>comment</string> </key> <key> <string>comment</string> </key>
...@@ -239,7 +239,7 @@ ...@@ -239,7 +239,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>950.11430.27817.60057</string> </value> <value> <string>950.53470.24267.49032</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -257,7 +257,7 @@ ...@@ -257,7 +257,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1459439866.36</float> <float>1461861122.87</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment