* Added cache flush functionality to dashboard

* added rest method to flush cache
* Fixed tabletools "stuff" left behind, removing all this on any "main link" click
This commit is contained in:
Adolfo Gómez 2013-12-04 04:12:06 +00:00
parent 732840df42
commit 64382b5afe
9 changed files with 162 additions and 47 deletions

View File

@ -11,6 +11,7 @@ encoding//src/server/urls.py=utf-8
encoding//src/uds/REST/__init__.py=utf-8
encoding//src/uds/REST/handlers.py=utf-8
encoding//src/uds/REST/methods/authenticators.py=utf-8
encoding//src/uds/REST/methods/cache.py=utf-8
encoding//src/uds/REST/methods/gui_callback.py=utf-8
encoding//src/uds/REST/methods/login_logout.py=utf-8
encoding//src/uds/REST/methods/networks.py=utf-8
@ -107,6 +108,7 @@ encoding//src/uds/core/util/ThreadPool.py=utf-8
encoding//src/uds/core/util/UniqueIDGenerator.py=utf-8
encoding//src/uds/core/util/UniqueMacGenerator.py=utf-8
encoding//src/uds/core/util/UniqueNameGenerator.py=utf-8
encoding//src/uds/core/util/__init__.py=utf-8
encoding//src/uds/core/util/connection.py=utf-8
encoding//src/uds/core/util/html.py=utf-8
encoding//src/uds/core/util/log.py=utf-8

View File

@ -0,0 +1,74 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2014 Virtual Cable S.L.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# * Neither the name of Virtual Cable S.L. nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
'''
@author: Adolfo Gómez, dkmaster at dkmon dot com
'''
from __future__ import unicode_literals
from uds.core.util.Cache import Cache as uCache
from uds.REST import Handler, RequestError, NotFound
import logging
logger = logging.getLogger(__name__)
# Enclosed methods under /auth path
class Cache(Handler):
authenticated = True # Public method
needs_staff = True #
def get(self):
'''
This login uses parameters to generate auth token
The alternative is to use the template tag inside "REST" that is called auth_token, that extracts an auth token from an user session
We can use any of this forms due to the fact that the auth token is in fact a session key
Parameters:
mandatory:
username:
password:
auth:
optional:
locale: (defaults to "en")
Result:
on success: { 'result': 'ok', 'auth': [auth_code] }
on error: { 'result: 'error', 'error': [error string] }
'''
logger.debug('Params: {0}'.format(self._params))
if len(self._args) == 0:
return {}
if len(self._args) != 1:
raise RequestError('Invalid Request')
uCache.purge()
return 'done'

View File

@ -47,24 +47,6 @@ class Callback(Handler):
needs_staff = True #
def get(self):
'''
This login uses parameters to generate auth token
The alternative is to use the template tag inside "REST" that is called auth_token, that extracts an auth token from an user session
We can use any of this forms due to the fact that the auth token is in fact a session key
Parameters:
mandatory:
username:
password:
auth:
optional:
locale: (defaults to "en")
Result:
on success: { 'result': 'ok', 'auth': [auth_code] }
on error: { 'result: 'error', 'error': [error string] }
'''
logger.debug('Params: {0}'.format(self._params))
if len(self._args) != 1:
raise RequestError('Invalid Request')

View File

@ -30,6 +30,7 @@
'''
@author: Adolfo Gómez, dkmaster at dkmon dot com
'''
from __future__ import unicode_literals
from server.settings import RSA_KEY
from Crypto.PublicKey import RSA
@ -59,17 +60,18 @@ class CryptoManager(object):
def encrypt(self, string):
atfork()
return self._rsa.encrypt(string, '')[0].encode(CryptoManager.CODEC)
return self._rsa.encrypt(string.encode('utf-8'), '')[0].encode(CryptoManager.CODEC)
def decrypt(self, string):
atfork()
return self._rsa.decrypt(string.decode(CryptoManager.CODEC))
return self._rsa.decrypt(string.decode(CryptoManager.CODEC)).decode('utf-8')
def xor(self, s1, s2):
s1, s2 = s1.encode('utf-8'), s2.encode('utf-8')
mult = (len(s1)/len(s2)) + 1
s1 = array.array('B', s1)
s2 = array.array('B', s2 * mult)
return array.array('B', (s1[i] ^ s2[i] for i in range(len(s1)))).tostring()
s1 = array.array(b'B', s1)
s2 = array.array(b'B', s2 * mult)
return array.array(b'B', (s1[i] ^ s2[i] for i in range(len(s1)))).tostring()
def loadPrivateKey(self, rsaKey):
try:

View File

@ -30,6 +30,7 @@
'''
@author: Adolfo Gómez, dkmaster at dkmon dot com
'''
from __future__ import unicode_literals
from django.conf import settings
from uds.models import Config as dbConfig

View File

@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2012 Virtual Cable S.L.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# * Neither the name of Virtual Cable S.L. nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
'''
@author: Adolfo Gómez, dkmaster at dkmon dot com
'''
from __future__ import unicode_literals

View File

@ -243,7 +243,7 @@ gui.connectivity.link = function(event) {
});
});
},
onDelete: function(value, event, table, refreshFnc) {
onDelete: function(value, event, table, refreshFncs) {
// TODO: Add confirmation to deletion
gui.connectivity.transports.rest.del(value.id, function(){
refreshFnc();
@ -258,3 +258,15 @@ gui.connectivity.link = function(event) {
});
};
// Tools
gui.clear_cache = new BasicGuiElement('Clear cache');
gui.clear_cache.link = function() {
"use strict";
api.getJson('cache/flush', {
success: function() {
gui.launchModal(gettext('Cache'), gettext('Cache has been flushed'), ' ' );
},
});
};

View File

@ -151,7 +151,8 @@
};
gui.setLinksEvents = function() {
var sidebarLinks = [ {
var sidebarLinks = [
{
id : 'lnk-dashboard',
exec : gui.dashboard.link,
}, {
@ -169,14 +170,22 @@
}, {
id : 'lnk-deployed_services',
exec : gui.deployed_services
}, ];
}, {
id : 'lnk-clear_cache',
exec : gui.clear_cache.link,
},
];
$.each(sidebarLinks, function(index, value) {
gui.doLog('Adding ' + value.id);
$('.' + value.id).unbind('click').click(function(event) {
event.preventDefault();
if ($('.navbar-toggle').css('display') != 'none') {
$(".navbar-toggle").trigger("click");
}
$('html, body').scrollTop(0);
// Tabletools creates divs at end that do not get removed, here is a good place to ensure there is no garbage left behind
// And anyway, if this div does not exists, it creates a new one...
$('.DTTT_dropdown').remove();
value.exec(event);
});
});

View File

@ -3,7 +3,7 @@
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
<span class="sr-only">{% trans 'toggle navigation'|capfirst %}</span>
<span class="sr-only">{% trans 'Toggle navigation' %}</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
@ -24,7 +24,7 @@
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="fa fa-caret-square-o-down"></i> Tools <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="#">{% trans 'Configuration' %}</a></li>
<li><a href="#">Another Item</a></li>
<li><a class="lnk-clear_cache" href="#">{% trans 'Clear cache' %}</a></li>
<li><a href="#">Third Item</a></li>
<li><a href="#">Last Item</a></li>
</ul>
@ -54,8 +54,8 @@
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="fa fa-dashboard"></i> {{ user.real_name }} <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="{% url 'uds.web.views.index' %}"><span class="fa fa-user"></span> {% trans 'Exit dashboard' %}</a></li>
<li><a href="/logout"><span class="fa fa-power-off text-danger"></span> {% trans 'logout'|capfirst %}</a></li>
<li><a href="{% url 'uds.web.views.index' %}"><span class="fa fa-user"></span> {% trans 'Exit' %}</a></li>
<li><a href="/logout"><span class="fa fa-power-off text-danger"></span> {% trans 'Logout' %}</a></li>
</ul>
</li>