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

slapos_monitoring: make instance configuration is more flexible

parent 70be8d8d
......@@ -107,7 +107,7 @@
<value> <string encoding="cdata"><![CDATA[
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
# images/ajax-loader.gif\n
CACHE:\n
......@@ -326,7 +326,7 @@ NETWORK:\n
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>950.43165.31733.30549</string> </value>
<value> <string>950.53381.7699.19968</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -344,7 +344,7 @@ NETWORK:\n
</tuple>
<state>
<tuple>
<float>1461242916.65</float>
<float>1461861221.53</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -110,7 +110,7 @@
{{#if key}}
<a rel="{{../index}}" class="prop-edit" title='Edit this value'><i class="fa fa-pencil"></i></a>
{{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}}
</td>
</tr>
......
......@@ -229,7 +229,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
<value> <string>superalain</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -243,7 +243,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>949.64120.38038.28552</string> </value>
<value> <string>950.52007.35517.18278</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -261,7 +261,7 @@
</tuple>
<state>
<tuple>
<float>1458568209.8</float>
<float>1461847634.36</float>
<string>UTC</string>
</tuple>
</state>
......
/*global window, rJS, btoa */
/*global window, rJS, btoa, Handlebars, $ */
/*jslint nomen: true, indent: 2, maxerr: 3*/
(function (window, rJS) {
(function (window, rJS, btoa, Handlebars, $) {
"use strict";
var gadget_klass = rJS(window),
......@@ -491,4 +491,4 @@
});
});
}(window, rJS));
\ No newline at end of file
}(window, rJS, btoa, Handlebars, $));
\ No newline at end of file
......@@ -225,7 +225,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
<value> <string>superalain</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -239,7 +239,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>950.3039.65061.43776</string> </value>
<value> <string>950.53037.35338.8209</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -257,7 +257,7 @@
</tuple>
<state>
<tuple>
<float>1459761305.99</float>
<float>1461861381.81</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -225,7 +225,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
<value> <string>superalain</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -239,7 +239,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>949.54108.24790.65006</string> </value>
<value> <string>950.51968.20423.17902</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -257,7 +257,7 @@
</tuple>
<state>
<tuple>
<float>1459439672.87</float>
<float>1461832953.11</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -26,6 +26,7 @@
</script>
<script src="gadget_monitoring_static.js" type="text/javascript"></script>
<script src="gadget_monitoring_tooltipster.min.js" type="text/javascript"></script>
</head>
<body>
<div data-gadget-url="gadget_monitoring_jio.html" data-gadget-scope="jio_gadget" data-gadget-sandbox="public"></div>
......@@ -73,7 +74,7 @@
<div data-gadget-url="gadget_monitoring_widget_listbox.html" data-gadget-scope="listbox"></div>
<form class="configure">
<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>
<div class="auth-block padding-lr-20 border-gray" style="display: none">
<div class="ui-form">
......@@ -84,12 +85,12 @@
</div>
<div class="ui-form">
<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="-"/>
</div>
</div>
<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>
<div class="new-password" style="display: none">
<div class="ui-form">
......
......@@ -225,7 +225,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
<value> <string>superalain</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -239,7 +239,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>950.14227.11651.3003</string> </value>
<value> <string>950.53466.15484.25019</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -257,7 +257,7 @@
</tuple>
<state>
<tuple>
<float>1459506471.61</float>
<float>1461860815.17</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -3,6 +3,14 @@
(function (window, rJS, RSVP, $, btoa, Rusha) {
"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) {
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;
......@@ -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) {
// Verify if login and password are correct for this URL
return gadget.props.login_gadget.login(url, hash)
......@@ -136,18 +171,32 @@
if (result.status === 'OK') {
return {status: 'OK'};
} else {
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(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) {
var jio_gadget,
function changeMonitorPassword(gadget, credential_dict, login, password) {
var url,
jio_gadget,
jio_options;
url = credential_dict.url;
url += (url.endsWith('/') ? '':'/') + 'config/';
jio_options = {
type: "query",
......@@ -156,15 +205,15 @@
sub_storage: {
type: "dav",
url: url,
basic_login: hash
basic_login: credential_dict.hash
}
}
};
gadget.props.gindex += 1;
return gadget.declareGadget("gadget_monitoring_jio.html",
{
element: gadget.props.element,
scope: 'jio_gadget' + gadget.props.gindex,
//element: gadget.props.element,
scope: 'jio_' + gadget.props.gindex + "_gadget",
sandbox: "public"
}
).push(function(new_gadget) {
......@@ -185,7 +234,10 @@
return new Error("Cannot get document at : " % url);
})
.push(function (result) {
return {status: 'OK'};
return gadget.props.login_gadget.updateUrlValue(credential_dict.url, login, password)
.push(function() {
return {status: 'OK'};
});
}, function (error) {
console.log(error);
return {status: 'ERROR', code: error.target.status};
......@@ -206,7 +258,6 @@
return gadget.props.jio_gadget.allDocs({})
.push(function (doc) {
if (!doc) {
console.log(doc);
gadget.props.element.querySelector('.msgtext-box')
.innerHTML += "<span class='ui-text-error'>" + url + " [ " + title + " ] is not reachable!</span><br/>";
return false;
......@@ -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
.ready(function (g) {
g.props = {};
......@@ -316,6 +359,19 @@
.push(function () {
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 () {
var promise_list = [];
promise_list.push(loopEventListener(
......@@ -515,6 +571,7 @@
cnew_password = '',
reload = true,
rows_list = gadget.props.listbox.property_dict.data_result,
not_changed_dict = {},
config_promise_list = [];
if (rows_list.length > 0) {
......@@ -556,12 +613,15 @@
for (i = 0; i < status_list.length; i += 1) {
if (status_list[i].status !== 'OK') {
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;
})
.push(function (error_msg) {
var tmp,
tmp_hash,
i;
if (error_msg !== '') {
gadget.props.element.querySelector('.configure .ui-text-error')
......@@ -572,10 +632,6 @@
}
if (username !== '' && password !== '') {
if (new_password !== '') {
old_password = password;
password = new_password;
}
for (i = 0; i < rows_list.length; i += 1) {
if (validateHttpUrl(rows_list[i].url)) {
tmp = {
......@@ -584,14 +640,13 @@
parent_url: gadget.props.opml_url
//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(
setUrlConfiguration(gadget, gadget.props.opml_url, root_name)
......@@ -603,17 +658,24 @@
var key,
promise_list = [];
if (new_password !== '') {
// Change current passwords and save them to local storage
for (key in credential_dict) {
promise_list.push(
changeMonitorPassword(
gadget,
credential_dict[key].url,
new_password,
btoa(username + ':' + old_password))
credential_dict[key],
username,
new_password)
);
}
return RSVP.all(promise_list);
} else {
// Only save provided credentials
return gadget.props.login_gadget.setUrlDict(credential_dict)
.push(function () {
return [];
});
}
return RSVP.all(promise_list);
})
.push(function (result_list) {
var i,
......@@ -621,7 +683,7 @@
for (i = 0; i < result_list.length; i += 1) {
if (result_list[i].status === '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;
}
}
......
......@@ -225,7 +225,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
<value> <string>superalain</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -239,7 +239,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>950.11430.27817.60057</string> </value>
<value> <string>950.53470.24267.49032</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -257,7 +257,7 @@
</tuple>
<state>
<tuple>
<float>1459439866.36</float>
<float>1461861122.87</float>
<string>UTC</string>
</tuple>
</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