1
0
mirror of https://github.com/ansible/awx.git synced 2024-10-31 15:21:13 +03:00

adding 'start new connection' to Socket lib class

for security purposes
This commit is contained in:
Jared Tabor 2014-10-27 14:18:20 -04:00
parent c6180d3928
commit 7b113f4924

View File

@ -27,7 +27,8 @@ angular.module('SocketIO', ['AuthService', 'Utilities'])
host = $location.host(),
endpoint = params.endpoint,
protocol = $location.protocol(),
config, socketPort, url;
config, socketPort,
handshakeData, url;
// Since some pages are opened in a new tab, we might get here before AnsibleConfig is available.
// In that case, load from local storage.
@ -61,23 +62,34 @@ angular.module('SocketIO', ['AuthService', 'Utilities'])
scope: scope,
url: url,
socket: null,
init: function() {
var self = this,
token = Authorization.getToken();
if (!$rootScope.sessionTimer || ($rootScope.sessionTimer && !$rootScope.sessionTimer.isExpired())) {
// We have a valid session token, so attmempt socket connection
// We have a valid session token, so attempt socket connection
$log.debug('Socket connecting to: ' + url);
self.scope.socket_url = url;
self.socket = io.connect(url, { headers:
{
handshakeData = {
headers: {
'Authorization': 'Token ' + token,
'X-Auth-Token': 'Token ' + token
},
}
}
self.socket = io.connect(url, {
// headers:
// {
// 'Authorization': 'Token ' + token,
// 'X-Auth-Token': 'Token ' + token
// },
'connect timeout': 3000,
'try multiple transports': false,
'max reconneciton attemps': 3,
'reconnection limit': 3000,
'force new connection': true,
});
self.socket.on('connection', function() {
$log.debug('Socket connecting...');
self.scope.$apply(function () {
@ -168,6 +180,19 @@ angular.module('SocketIO', ['AuthService', 'Utilities'])
});
});
},
disconnect: function(){
var self = this;
$rootScope.disconnect_timer = setInterval(function(){disconnectSocket()}, 1000);
function disconnectSocket() {
self.socket.socket.disconnect();
window.clearInterval($rootScope.disconnect_timer);
}
// self.scope.$apply(function () {
// });
},
emit: function (eventName, data, callback) {
var self = this;
self.socket.emit(eventName, data, function () {