Commit 1d2cf4f3 authored by Stavros Sachtouris's avatar Stavros Sachtouris Committed by Giorgos Korfiatis
Browse files

Implement "get credentials" button in settings GUI

parent 07cab2e5
......@@ -44,7 +44,8 @@ class GUI(WebSocketBaseClient):
'/home/saxtouri/node-webkit-v0.11.6-linux-x64/nw',
# self.gui_exec_path,
abspath('gui/gui.nw'),
fp.name])
fp.name,
'--data-path', abspath('~/.agkyra')])
LOG.debug('GUI process closed, remove temp file')
os.remove(fp.name)
......
......@@ -112,9 +112,9 @@ menu.append(new gui.MenuItem({
label: 'Launch Pithos+ page',
icon: 'images/pithos.png',
click: function () {
var pithos_url = globals['settings']['pithos_url'];
console.log('Visit ' + pithos_url);
gui.Shell.openExternal(pithos_url);
var pithos_ui = globals['settings']['pithos_ui'];
console.log('Visit ' + pithos_ui);
gui.Shell.openExternal(pithos_ui);
}
}));
......
......@@ -12,5 +12,6 @@
"name": "Synnefo Development Team",
"web": "http://www.synnefo.org"
}],
"licences": [{"type": "GPLv3"}]
"licences": [{"type": "GPLv3"}],
"chromium-args": "--incognito"
}
......@@ -16,8 +16,7 @@ var globals = {
'url': null,
'container': null,
'directory': null,
'pithos_url': null,
'weblogin': null,
'pithos_ui': null,
'exclude': null
},
'status': {"progress": null, "paused": null}
......
......@@ -21,9 +21,8 @@
exclude = get_setting('exclude');
if (exclude) $('#exclude').val(
fs.readFileSync(exclude, encoding='utf-8'));
var weblogin = get_setting('weblogin');
var pithos_url = get_setting('pithos_url');
if (weblogin && pithos_url) {
var pithos_ui = get_setting('pithos_ui');
if (pithos_ui) {
$('#get_creds').show();
} else {
console.log('No pithos view, remove credential button');
......@@ -49,17 +48,13 @@
var gui = require('nw.gui');
function extract_cookie(url) {
var cookie_name = '_pithos2_a';
var w = gui.Window.open(url, {
focus: true, width: 520, height: 841
var logout_url = 'https://accounts.okeanos.grnet.gr/ui/logout'
var w = gui.Window.open(logout_url, {
focus: false, width: 20, height: 20
});
w.cookies.getAll({name: cookie_name}, function(cookies) {
if (cookies.length) {
console.log('Already logged in');
extract_credentials(cookies[0]);
w.close();
} else {
console.log('Not logged in');
}
w.close();
var w = gui.Window.open(logout_url, {
focus: true, width: 520, height: 920
});
w.cookies.onChanged.addListener(function(info) {
if (info.cookie.name === cookie_name) {
......@@ -71,9 +66,8 @@
}
function get_credentials() {
var weblogin = get_setting('weblogin')
var pithos_url = get_setting('url');
extract_cookie(weblogin + '?next=' + pithos_url);
var pithos_ui = get_setting('pithos_ui');
extract_cookie(pithos_ui);
}
</script>
</head>
......
......@@ -3,6 +3,9 @@ import json
import logging
from os.path import abspath
from titanic import syncer
from config import AgkyraConfig
from kamaki.clients.astakos import AstakosClient
from kamaki.clients.pithos import PithosClient
LOG = logging.getLogger(__name__)
......@@ -61,15 +64,54 @@ class WebSocketProtocol(WebSocket):
gui_id = None
accepted = False
settings = dict(
token='token',
url='https://accounts.okeanos.grnet.gr/identity/v2.0',
container='pithos',
directory='/tmp/.',
exclude=abspath('exclude.cnf'),
pithos_url='https://pithos.okeanos.grnet.gr/ui/',
weblogin='https://accounts.okeanos.grnet.gr/ui')
token=None, url=None,
container=None, directory=None,
exclude=None, pithos_ui=None)
status = dict(progress=0, paused=True)
file_syncer = None
cnf = AgkyraConfig()
def _load_settings(self):
sync = self.cnf.get('global', 'default_sync')
cloud = self.cnf.get_sync(sync, 'cloud')
url = self.cnf.get_cloud(cloud, 'url')
token = self.cnf.get_cloud(cloud, 'token')
astakos = AstakosClient(url, token)
self.settings['url'], self.settings['token'] = url, token
try:
endpoints = astakos.get_endpoints()['access']['serviceCatalog']
for endpoint in endpoints:
if endpoint['type'] == PithosClient.service_type:
pithos_ui = endpoint['endpoints'][0]['SNF:uiURL']
self.settings['pithos_ui'] = pithos_ui
break
except Exception as e:
LOG.debug('Failed to retrieve pithos_ui: %s' % e)
for option in ('container', 'directory', 'exclude'):
self.settings[option] = self.cnf.get_sync(sync, option)
def _dump_settings(self):
sync = self.cnf.get('global', 'default_sync')
cloud = self.cnf.get_sync(sync, 'cloud')
old_url = self.cnf.get_cloud(cloud, 'url')
while old_url != self.settings['url']:
cloud = '%s_%s' % (cloud, sync)
try:
self.cnf.get_cloud(cloud, 'url')
except KeyError:
break
self.cnf.set_cloud(cloud, 'url', self.settings['url'])
self.cnf.set_cloud(cloud, 'token', self.settings['token'])
self.cnf.set_sync(sync, 'cloud', cloud)
for option in ('directory', 'container', 'exclude'):
self.cnf.set_sync(sync, option, self.settings[option])
# Syncer-related methods
def get_status(self):
......@@ -79,10 +121,12 @@ class WebSocketProtocol(WebSocket):
return self.status
def get_settings(self):
self._load_settings()
return self.settings
def set_settings(self, new_settings):
self.settings = new_settings
self._dump_settings()
def pause_sync(self):
self.status['paused'] = True
......@@ -93,6 +137,7 @@ class WebSocketProtocol(WebSocket):
# WebSocket connection methods
def opened(self):
LOG.debug('Helper: connection established')
self._load_settings()
def closed(self, *args):
LOG.debug('Helper: connection closed')
......
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