disable http and ws when navigating AriaNg via https

This commit is contained in:
MaysWind 2017-10-08 22:48:30 +08:00
parent ccac9d82a2
commit 71e1d5ce37
7 changed files with 55 additions and 23 deletions

View file

@ -179,9 +179,12 @@ Minutes=分
Seconds=秒 Seconds=秒
Milliseconds=毫秒 Milliseconds=毫秒
Http=Http Http=Http
Http (Disabled)=Http (禁用)
Https=Https Https=Https
WebSocket=WebSocket WebSocket=WebSocket
WebSocket (Disabled)=WebSocket (禁用)
WebSocket (Security)=WebSocket (安全) WebSocket (Security)=WebSocket (安全)
Http and WebSocket would be disabled when navigating AriaNg via Https.=使用 Https 访问 AriaNg 时Http 和 WebSocket 将被禁用.
POST=POST POST=POST
GET=GET GET=GET
Disabled=禁用 Disabled=禁用

View file

@ -179,9 +179,12 @@ Minutes=分
Seconds=秒 Seconds=秒
Milliseconds=毫秒 Milliseconds=毫秒
Http=Http Http=Http
Http (Disabled)=Http (禁用)
Https=Https Https=Https
WebSocket=WebSocket WebSocket=WebSocket
WebSocket (Disabled)=WebSocket (禁用)
WebSocket (Security)=WebSocket (安全) WebSocket (Security)=WebSocket (安全)
Http and WebSocket would be disabled when navigating AriaNg via Https.=使用 Https 訪問 AriaNg 時Http 和 WebSocket 將被禁用.
POST=POST POST=POST
GET=GET GET=GET
Disabled=禁用 Disabled=禁用

View file

@ -10,6 +10,7 @@
languageFileExtension: '.txt', languageFileExtension: '.txt',
defaultLanguage: 'en', defaultLanguage: 'en',
defaultHost: 'localhost', defaultHost: 'localhost',
defaultSecureProtocol: 'https',
globalStatStorageCapacity: 120, globalStatStorageCapacity: 120,
taskStatStorageCapacity: 300, taskStatStorageCapacity: 300,
lazySaveTimeout: 500, lazySaveTimeout: 500,

View file

@ -183,9 +183,12 @@
'Seconds': 'Seconds', 'Seconds': 'Seconds',
'Milliseconds': 'Milliseconds', 'Milliseconds': 'Milliseconds',
'Http': 'Http', 'Http': 'Http',
'Http (Disabled)': 'Http (Disabled)',
'Https': 'Https', 'Https': 'Https',
'WebSocket': 'WebSocket', 'WebSocket': 'WebSocket',
'WebSocket (Disabled)': 'WebSocket (Disabled)',
'WebSocket (Security)': 'WebSocket (Security)', 'WebSocket (Security)': 'WebSocket (Security)',
'Http and WebSocket would be disabled when navigating AriaNg via Https.': 'Http and WebSocket would be disabled when navigating AriaNg via Https.',
'POST': 'POST', 'POST': 'POST',
'GET': 'GET', 'GET': 'GET',
'Disabled': 'Disabled', 'Disabled': 'Disabled',

View file

@ -38,6 +38,7 @@
availableTime: ariaNgCommonService.getTimeOptions([1000, 2000, 3000, 5000, 10000, 30000, 60000], true), availableTime: ariaNgCommonService.getTimeOptions([1000, 2000, 3000, 5000, 10000, 30000, 60000], true),
trueFalseOptions: [{name: 'True', value: true}, {name: 'False', value: false}], trueFalseOptions: [{name: 'True', value: true}, {name: 'False', value: false}],
showRpcSecret: false, showRpcSecret: false,
isInsecureProtocolDisabled: ariaNgSettingService.isInsecureProtocolDisabled(),
settings: ariaNgSettingService.getAllOptions(), settings: ariaNgSettingService.getAllOptions(),
sessionSettings: ariaNgSettingService.getAllSessionOptions(), sessionSettings: ariaNgSettingService.getAllSessionOptions(),
rpcSettings: ariaNgSettingService.getAllRpcSettings() rpcSettings: ariaNgSettingService.getAllRpcSettings()

View file

@ -18,6 +18,12 @@
} }
}; };
var isInsecureProtocolDisabled = function () {
var protocol = $location.protocol();
return protocol === 'https';
};
var getLanguageNameFromAlias = function (alias) { var getLanguageNameFromAlias = function (alias) {
for (var langName in ariaNgLanguages) { for (var langName in ariaNgLanguages) {
if (!ariaNgLanguages.hasOwnProperty(langName)) { if (!ariaNgLanguages.hasOwnProperty(langName)) {
@ -100,6 +106,20 @@
options = angular.extend({}, ariaNgDefaultOptions); options = angular.extend({}, ariaNgDefaultOptions);
options.language = getDefaultLanguage(); options.language = getDefaultLanguage();
if (!options.rpcHost) {
initRpcSettingWithDefaultHostAndProtocol(options);
}
if (angular.isArray(options.extendRpcServers)) {
for (var i = 0; i < options.extendRpcServers.length; i++) {
var rpcSetting = options.extendRpcServers[i];
if (!rpcSetting.rpcHost) {
initRpcSettingWithDefaultHostAndProtocol(rpcSetting);
}
}
}
setOptions(options); setOptions(options);
fireFirstVisitEvent(); fireFirstVisitEvent();
} }
@ -129,6 +149,14 @@
setOptions(options); setOptions(options);
}; };
var initRpcSettingWithDefaultHostAndProtocol = function (setting) {
setting.rpcHost = getDefaultRpcHost();
if (isInsecureProtocolDisabled()) {
setting.protocol = ariaNgConstants.defaultSecureProtocol;
}
};
var cloneRpcSetting = function (setting) { var cloneRpcSetting = function (setting) {
return { return {
rpcAlias: setting.rpcAlias, rpcAlias: setting.rpcAlias,
@ -144,7 +172,8 @@
var createNewRpcSetting = function () { var createNewRpcSetting = function () {
var setting = cloneRpcSetting(ariaNgDefaultOptions); var setting = cloneRpcSetting(ariaNgDefaultOptions);
setting.rpcId = ariaNgCommonService.generateUniqueId(); setting.rpcId = ariaNgCommonService.generateUniqueId();
setting.rpcHost = getDefaultRpcHost();
initRpcSettingWithDefaultHostAndProtocol(setting);
return setting; return setting;
}; };
@ -153,10 +182,6 @@
getAllOptions: function () { getAllOptions: function () {
var options = angular.extend({}, ariaNgDefaultOptions, getOptions()); var options = angular.extend({}, ariaNgDefaultOptions, getOptions());
if (!options.rpcHost) {
options.rpcHost = getDefaultRpcHost();
}
if (options.secret) { if (options.secret) {
options.secret = base64.decode(options.secret); options.secret = base64.decode(options.secret);
} }
@ -165,10 +190,6 @@
for (var i = 0; i < options.extendRpcServers.length; i++) { for (var i = 0; i < options.extendRpcServers.length; i++) {
var rpcSetting = options.extendRpcServers[i]; var rpcSetting = options.extendRpcServers[i];
if (!rpcSetting.rpcHost) {
rpcSetting.rpcHost = getDefaultRpcHost();
}
if (rpcSetting.secret) { if (rpcSetting.secret) {
rpcSetting.secret = base64.decode(rpcSetting.secret); rpcSetting.secret = base64.decode(rpcSetting.secret);
} }
@ -199,6 +220,9 @@
getAllSessionOptions: function () { getAllSessionOptions: function () {
return angular.copy(sessionSettings); return angular.copy(sessionSettings);
}, },
isInsecureProtocolDisabled: function () {
return isInsecureProtocolDisabled();
},
applyLanguage: function (lang) { applyLanguage: function (lang) {
if (!ariaNgLanguages[lang]) { if (!ariaNgLanguages[lang]) {
return false; return false;
@ -248,26 +272,21 @@
setOption('browserNotification', value); setOption('browserNotification', value);
}, },
getCurrentRpcUrl: function () { getCurrentRpcUrl: function () {
var protocol = getOption('protocol'); var options = getOptions();
var rpcHost = getOption('rpcHost'); var protocol = options.protocol;
var rpcPort = getOption('rpcPort'); var rpcHost = options.rpcHost;
var rpcInterface = getOption('rpcInterface'); var rpcPort = options.rpcPort;
var rpcInterface = options.rpcInterface;
if (!rpcHost) {
rpcHost = getDefaultRpcHost();
}
return protocol + '://' + rpcHost + ':' + rpcPort + '/' + rpcInterface; return protocol + '://' + rpcHost + ':' + rpcPort + '/' + rpcInterface;
}, },
getCurrentRpcProtocol: function () {
return getOption('protocol');
},
getCurrentRpcHttpMethod: function () { getCurrentRpcHttpMethod: function () {
return getOption('httpMethod'); return getOption('httpMethod');
}, },
isCurrentRpcUseWebSocket: function (protocol) { isCurrentRpcUseWebSocket: function (protocol) {
if (!protocol) { if (!protocol) {
protocol = this.getCurrentRpcProtocol(); var options = getOptions();
protocol = options.protocol;
} }
return protocol === 'ws' || protocol === 'wss'; return protocol === 'ws' || protocol === 'wss';

View file

@ -171,12 +171,14 @@
<div class="setting-key setting-key-without-desc col-sm-4"> <div class="setting-key setting-key-without-desc col-sm-4">
<span translate>Aria2 RPC Protocol</span> <span translate>Aria2 RPC Protocol</span>
<span class="asterisk">*</span> <span class="asterisk">*</span>
<i class="icon-primary fa fa-question-circle" ng-tooltip-container="body" ng-tooltip-placement="top"
ng-tooltip="{{'Http and WebSocket would be disabled when navigating AriaNg via Https.' | translate}}"></i>
</div> </div>
<div class="setting-value col-sm-8"> <div class="setting-value col-sm-8">
<select class="form-control" style="width: 100%;" ng-model="setting.protocol" ng-change="updateRpcSetting(setting, 'protocol')"> <select class="form-control" style="width: 100%;" ng-model="setting.protocol" ng-change="updateRpcSetting(setting, 'protocol')">
<option value="http" translate>Http</option> <option value="http" ng-disabled="::(context.isInsecureProtocolDisabled)" ng-bind="('Http' + (context.isInsecureProtocolDisabled ? ' (Disabled)' : '')) | translate">Http</option>
<option value="https" translate>Https</option> <option value="https" translate>Https</option>
<option value="ws" translate>WebSocket</option> <option value="ws" ng-disabled="::(context.isInsecureProtocolDisabled)" ng-bind="('WebSocket' + (context.isInsecureProtocolDisabled ? ' (Disabled)' : '')) | translate">WebSocket</option>
<option value="wss" translate>WebSocket (Security)</option> <option value="wss" translate>WebSocket (Security)</option>
</select> </select>
</div> </div>