Detect self-signed cert errors

This commit is contained in:
Lorenz Hübschle-Schneider 2014-04-22 19:03:12 +02:00
parent e7d7f39c95
commit e732d72550
2 changed files with 17 additions and 3 deletions

View File

@ -42,6 +42,9 @@
<div class="alert alert-danger" ng-show="errorMessage"> <div class="alert alert-danger" ng-show="errorMessage">
<strong>Connection error</strong> The client was unable to connect to the WeeChat relay <strong>Connection error</strong> The client was unable to connect to the WeeChat relay
</div> </div>
<div class="alert alert-danger" ng-show="sslError">
<strong>Secure connection error</strong> A secure connection with the WeeChat relay could not be initiated. This is most likely because your browser does not trust your relay's certificate. Please read the encryption instructions below!
</div>
<div class="panel-group" id="accordion"> <div class="panel-group" id="accordion">
<div class="panel"> <div class="panel">
<div class="panel-heading"> <div class="panel-heading">

View File

@ -337,14 +337,22 @@ function($rootScope,
}; };
var onclose = function () { var onclose = function (evt) {
/* /*
* Handles websocket disconnection * Handles websocket disconnection
*/ */
$log.info("Disconnected from relay"); $log.info("Disconnected from relay");
failCallbacks('disconnection'); failCallbacks('disconnection');
$rootScope.connected = false; $rootScope.connected = false;
$rootScope.$emit('relayDisconnect'); if ($rootScope.waseverconnected) {
$rootScope.$emit('relayDisconnect');
} else if (ssl && evt.code === 1006) {
// A password error doesn't trigger onerror, but certificate issues do. Check time of last error.
if (typeof $rootScope.lastError !== "undefined" && (Date.now() - $rootScope.lastError) < 1000) {
// abnormal disconnect by client, most likely ssl error
$rootScope.sslError = true;
}
}
$rootScope.$apply(); $rootScope.$apply();
}; };
@ -353,7 +361,8 @@ function($rootScope,
* Handles cases when connection issues come from * Handles cases when connection issues come from
* the relay. * the relay.
*/ */
$log.error("Relay error" + evt.data); $log.error("Relay error", evt);
$rootScope.lastError = Date.now();
if (evt.type === "error" && this.readyState !== 1) { if (evt.type === "error" && this.readyState !== 1) {
failCallbacks('error'); failCallbacks('error');
@ -946,6 +955,8 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
$scope.connect = function() { $scope.connect = function() {
$scope.requestNotificationPermission(); $scope.requestNotificationPermission();
$rootScope.sslError = false;
$rootScope.errorMessage = false;
connection.connect($scope.host, $scope.port, $scope.password, $scope.ssl); connection.connect($scope.host, $scope.port, $scope.password, $scope.ssl);
}; };
$scope.disconnect = function() { $scope.disconnect = function() {