Make data limits a permanent feature (#698)

This commit is contained in:
alalamav 2020-07-20 17:32:29 -04:00 • committed by GitHub
parent 6c23cc52f8
commit b63606e90c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 133 additions and 96 deletions

View file

@ -22,9 +22,10 @@
"confirmation-server-remove": "This action removes your server from the Outline Manager, but does not block proxy access to users. You will still need to manually delete the Outline server from your host machine.", "confirmation-server-remove": "This action removes your server from the Outline Manager, but does not block proxy access to users. You will still need to manually delete the Outline server from your host machine.",
"confirmation-server-remove-title": "Remove Server?", "confirmation-server-remove-title": "Remove Server?",
"data-limits": "Data limits", "data-limits": "Data limits",
"data-limits-description": "Set a 30 day trailing data transfer limit for access keys on this server. Available at least until {date}.", "data-limits-description": "Set a 30 day trailing data transfer limit for access keys on this server.",
"data-limits-dialog-text": "Go to the Settings tab to set a data transfer limit for access keys on this server.", "data-limits-dialog-text": "Go to the Settings tab to set a data transfer limit for access keys on this server.",
"data-limits-dialog-title": "Avoid data overages", "data-limits-dialog-title": "Avoid data overages",
"data-limits-disclaimer": "Since you are currently reporting metrics, use of the data limits feature will be included. Please see the {openLink}data collection policy{closeLink} for more details.",
"data-limits-usage": "{used} of {total} used", "data-limits-usage": "{used} of {total} used",
"destroy": "Destroy", "destroy": "Destroy",
"digitalocean-disconnect": "Disconnect", "digitalocean-disconnect": "Disconnect",

View file

@ -126,14 +126,8 @@
"description": "This string appears as a title in a section to configure access key data transfer limits." "description": "This string appears as a title in a section to configure access key data transfer limits."
}, },
"data_limits_description": { "data_limits_description": {
"message": "Set a 30 day trailing data transfer limit for access keys on this server. Available at least until $DATE$.", "message": "Set a 30 day trailing data transfer limit for access keys on this server.",
"description": "This string appears as an explanation to the access key data transfer limits feature.", "description": "This string appears as an explanation to the access key data transfer limits feature."
"placeholders": {
"DATE": {
"content": "{date}",
"example": "December 9, 2019"
}
}
}, },
"data_limits_dialog_text": { "data_limits_dialog_text": {
"message": "Go to the Settings tab to set a data transfer limit for access keys on this server.", "message": "Go to the Settings tab to set a data transfer limit for access keys on this server.",
@ -143,6 +137,18 @@
"message": "Avoid data overages", "message": "Avoid data overages",
"description": "This string appears as a title in a dialog to advertise the data limits feature." "description": "This string appears as a title in a dialog to advertise the data limits feature."
}, },
"data_limits_disclaimer": {
"message": "Since you are currently reporting metrics, use of the data limits feature will be included. Please see the $START_OF_LINK$data collection policy$END_OF_LINK$ for more details.",
"description": "This string provides a data collection disclaimer to opting into the data limits features.",
"placeholders": {
"END_OF_LINK": {
"content": "{closeLink}"
},
"START_OF_LINK": {
"content": "{openLink}"
}
}
},
"data_limits_usage": { "data_limits_usage": {
"message": "$USED$ of $TOTAL$ used", "message": "$USED$ of $TOTAL$ used",
"description": "This string appears in a tooltip when the data limits feature is enabled. It lets the user know how much data an access key has used, relative to the limit.", "description": "This string appears in a tooltip when the data limits feature is enabled. It lets the user know how much data an access key has used, relative to the limit.",

View file

@ -247,7 +247,7 @@ function createTestApp(
return new App( return new App(
polymerAppRoot, VERSION, fakeDigitalOceanSessionFactory, polymerAppRoot, VERSION, fakeDigitalOceanSessionFactory,
fakeDigitalOceanServerRepositoryFactory, manualServerRepo, displayServerRepository, fakeDigitalOceanServerRepositoryFactory, manualServerRepo, displayServerRepository,
digitalOceanTokenManager, new FakeSurveys()); digitalOceanTokenManager);
} }
enum AppRootScreen { enum AppRootScreen {

View file

@ -20,7 +20,6 @@ import * as digitalocean_api from '../cloud/digitalocean_api';
import * as errors from '../infrastructure/errors'; import * as errors from '../infrastructure/errors';
import {sleep} from '../infrastructure/sleep'; import {sleep} from '../infrastructure/sleep';
import * as server from '../model/server'; import * as server from '../model/server';
import {Surveys} from '../model/survey';
import {TokenManager} from './digitalocean_oauth'; import {TokenManager} from './digitalocean_oauth';
import * as digitalocean_server from './digitalocean_server'; import * as digitalocean_server from './digitalocean_server';
@ -37,8 +36,6 @@ const UNUSED_DIGITALOCEAN_REFERRAL_CODE = '5ddb4219b716';
const CHANGE_KEYS_PORT_VERSION = '1.0.0'; const CHANGE_KEYS_PORT_VERSION = '1.0.0';
const DATA_LIMITS_VERSION = '1.1.0'; const DATA_LIMITS_VERSION = '1.1.0';
const CHANGE_HOSTNAME_VERSION = '1.2.0'; const CHANGE_HOSTNAME_VERSION = '1.2.0';
// Date by which the data limits feature experiment will be permanently added or removed.
export const DATA_LIMITS_AVAILABILITY_DATE = new Date('2020-06-02');
const MAX_ACCESS_KEY_DATA_LIMIT_BYTES = 50 * (10 ** 9); // 50GB const MAX_ACCESS_KEY_DATA_LIMIT_BYTES = 50 * (10 ** 9); // 50GB
function dataLimitToDisplayDataAmount(limit: server.DataLimit): DisplayDataAmount|null { function dataLimitToDisplayDataAmount(limit: server.DataLimit): DisplayDataAmount|null {
@ -88,6 +85,13 @@ async function computeDefaultAccessKeyDataLimit(
} }
} }
// Returns whether the user has seen a notification for the updated feature metrics data collection
// policy.
function hasSeenFeatureMetricsNotification(): boolean {
return !!window.localStorage.getItem('dataLimitsHelpBubble-dismissed') &&
!!window.localStorage.getItem('dataLimits-feature-collection-notification');
}
async function showHelpBubblesOnce(serverView: ServerView) { async function showHelpBubblesOnce(serverView: ServerView) {
if (!window.localStorage.getItem('addAccessKeyHelpBubble-dismissed')) { if (!window.localStorage.getItem('addAccessKeyHelpBubble-dismissed')) {
await serverView.showAddAccessKeyHelpBubble(); await serverView.showAddAccessKeyHelpBubble();
@ -131,7 +135,7 @@ export class App {
private createDigitalOceanServerRepository: DigitalOceanServerRepositoryFactory, private createDigitalOceanServerRepository: DigitalOceanServerRepositoryFactory,
private manualServerRepository: server.ManualServerRepository, private manualServerRepository: server.ManualServerRepository,
private displayServerRepository: DisplayServerRepository, private displayServerRepository: DisplayServerRepository,
private digitalOceanTokenManager: TokenManager, private surveys: Surveys) { private digitalOceanTokenManager: TokenManager) {
appRoot.setAttribute('outline-version', this.version); appRoot.setAttribute('outline-version', this.version);
appRoot.addEventListener('ConnectToDigitalOcean', (event: CustomEvent) => { appRoot.addEventListener('ConnectToDigitalOcean', (event: CustomEvent) => {
@ -838,10 +842,10 @@ export class App {
view.serverPortForNewAccessKeys = selectedServer.getPortForNewAccessKeys(); view.serverPortForNewAccessKeys = selectedServer.getPortForNewAccessKeys();
view.serverCreationDate = localizeDate(selectedServer.getCreatedDate(), this.appRoot.language); view.serverCreationDate = localizeDate(selectedServer.getCreatedDate(), this.appRoot.language);
view.serverVersion = selectedServer.getVersion(); view.serverVersion = selectedServer.getVersion();
view.dataLimitsAvailabilityDate =
localizeDate(DATA_LIMITS_AVAILABILITY_DATE, this.appRoot.language);
view.accessKeyDataLimit = dataLimitToDisplayDataAmount(selectedServer.getAccessKeyDataLimit()); view.accessKeyDataLimit = dataLimitToDisplayDataAmount(selectedServer.getAccessKeyDataLimit());
view.isAccessKeyDataLimitEnabled = !!view.accessKeyDataLimit; view.isAccessKeyDataLimitEnabled = !!view.accessKeyDataLimit;
view.showFeatureMetricsDisclaimer = selectedServer.getMetricsEnabled() &&
!selectedServer.getAccessKeyDataLimit() && !hasSeenFeatureMetricsNotification();
const version = this.selectedServer.getVersion(); const version = this.selectedServer.getVersion();
if (version) { if (version) {
@ -1029,7 +1033,9 @@ export class App {
this.appRoot.showNotification(this.appRoot.localize('saved')); this.appRoot.showNotification(this.appRoot.localize('saved'));
serverView.accessKeyDataLimit = dataLimitToDisplayDataAmount(limit); serverView.accessKeyDataLimit = dataLimitToDisplayDataAmount(limit);
this.refreshTransferStats(this.selectedServer, serverView); this.refreshTransferStats(this.selectedServer, serverView);
this.surveys.presentDataLimitsEnabledSurvey(); // Don't display the feature collection disclaimer anymore.
serverView.showFeatureMetricsDisclaimer = false;
window.localStorage.setItem('dataLimits-feature-collection-notification', 'true');
} catch (error) { } catch (error) {
console.error(`Failed to set access key data limit: ${error}`); console.error(`Failed to set access key data limit: ${error}`);
this.appRoot.showError(this.appRoot.localize('error-set-data-limit')); this.appRoot.showError(this.appRoot.localize('error-set-data-limit'));
@ -1045,7 +1051,6 @@ export class App {
await this.selectedServer.removeAccessKeyDataLimit(); await this.selectedServer.removeAccessKeyDataLimit();
this.appRoot.showNotification(this.appRoot.localize('saved')); this.appRoot.showNotification(this.appRoot.localize('saved'));
this.refreshTransferStats(this.selectedServer, serverView); this.refreshTransferStats(this.selectedServer, serverView);
this.surveys.presentDataLimitsDisabledSurvey();
} catch (error) { } catch (error) {
console.error(`Failed to remove access key data limit: ${error}`); console.error(`Failed to remove access key data limit: ${error}`);
this.appRoot.showError(this.appRoot.localize('error-remove-data-limit')); this.appRoot.showError(this.appRoot.localize('error-remove-data-limit'));

View file

@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
import IntlMessageFormat from 'intl-messageformat';
import '../ui_components/outline-about-dialog'; import '../ui_components/outline-about-dialog';
import '../ui_components/outline-do-oauth-step'; import '../ui_components/outline-do-oauth-step';
import '../ui_components/outline-feedback-dialog'; import '../ui_components/outline-feedback-dialog';
@ -21,6 +19,7 @@ import '../ui_components/outline-share-dialog';
import '../ui_components/outline-sort-span'; import '../ui_components/outline-sort-span';
import '../ui_components/outline-survey-dialog'; import '../ui_components/outline-survey-dialog';
import IntlMessageFormat from 'intl-messageformat';
import {css, customElement, html, LitElement, property} from 'lit-element'; import {css, customElement, html, LitElement, property} from 'lit-element';
async function makeLocalize(language: string) { async function makeLocalize(language: string) {
@ -97,7 +96,8 @@ export class TestApp extends LitElement {
<div class="widget"> <div class="widget">
<h2>outline-about-dialog</h2> <h2>outline-about-dialog</h2>
<button @tap=${() => this.select('outline-about-dialog').open()}>Open Dialog</button> <button @tap=${() => this.select('outline-about-dialog').open()}>Open Dialog</button>
<outline-about-dialog .localize=${this.localize} dir=${this.dir} outline-version="1.2.3"></outline-about-dialog> <outline-about-dialog .localize=${this.localize} dir=${
this.dir} outline-version="1.2.3"></outline-about-dialog>
</div> </div>
<div class="widget"> <div class="widget">
@ -107,30 +107,34 @@ export class TestApp extends LitElement {
<div class="widget"> <div class="widget">
<h2>outline-feedback-dialog</h2> <h2>outline-feedback-dialog</h2>
<button @tap=${() => this.select('outline-feedback-dialog').open('Pre-populated message', false) <button @tap=${
}>Open Dialog</button> () => this.select('outline-feedback-dialog')
<outline-feedback-dialog .localize=${this.localize} dir=${this.dir}></outline-feedback-dialog> .open('Pre-populated message', false)}>Open Dialog</button>
<outline-feedback-dialog .localize=${this.localize} dir=${
this.dir}></outline-feedback-dialog>
</div> </div>
<div class="widget"> <div class="widget">
<h2>outline-share-dialog</h2> <h2>outline-share-dialog</h2>
<button @tap=${() => this.select('outline-share-dialog').open('<ACCESS_KEY>', '<INVITE_URL>') <button @tap=${
}>Open Dialog</button> () => this.select('outline-share-dialog')
.open('<ACCESS_KEY>', '<INVITE_URL>')}>Open Dialog</button>
<outline-share-dialog .localize=${this.localize} dir=${this.dir}></outline-share-dialog> <outline-share-dialog .localize=${this.localize} dir=${this.dir}></outline-share-dialog>
</div> </div>
<div class="widget"> <div class="widget">
<h2>outline-sort-icon</h2> <h2>outline-sort-icon</h2>
<outline-sort-span dir=${this.dir} direction=1 @tap=${() => { <outline-sort-span dir=${this.dir} direction=1 @tap=${() => {
const el = this.select('outline-sort-span'); const el = this.select('outline-sort-span');
el.direction *= -1; el.direction *= -1;
}}>Column Header</outline-sort-span> }}>Column Header</outline-sort-span>
</div> </div>
<div class="widget"> <div class="widget">
<h2>outline-survey-dialog</h2> <h2>outline-survey-dialog</h2>
<button @tap=${() => this.select('outline-survey-dialog').open('Survey title', 'https://getoutline.org') <button @tap=${
}>Open Dialog</button> () => this.select('outline-survey-dialog')
.open('Survey title', 'https://getoutline.org')}>Open Dialog</button>
<outline-survey-dialog .localize=${this.localize} dir=${this.dir}></outline-survey-dialog> <outline-survey-dialog .localize=${this.localize} dir=${this.dir}></outline-survey-dialog>
</div> </div>
`; `;

View file

@ -18,15 +18,18 @@ import * as digitalocean_api from '../cloud/digitalocean_api';
import * as i18n from '../infrastructure/i18n'; import * as i18n from '../infrastructure/i18n';
import {getSentryApiUrl} from '../infrastructure/sentry'; import {getSentryApiUrl} from '../infrastructure/sentry';
import {App, DATA_LIMITS_AVAILABILITY_DATE} from './app'; import {App} from './app';
import {DigitalOceanTokenManager} from './digitalocean_oauth'; import {DigitalOceanTokenManager} from './digitalocean_oauth';
import * as digitalocean_server from './digitalocean_server'; import * as digitalocean_server from './digitalocean_server';
import {DisplayServerRepository} from './display_server'; import {DisplayServerRepository} from './display_server';
import {ManualServerRepository} from './manual_server'; import {ManualServerRepository} from './manual_server';
import {DEFAULT_PROMPT_IMPRESSION_DELAY_MS, OutlineSurveys} from './survey';
import {AppRoot} from './ui_components/app-root.js'; import {AppRoot} from './ui_components/app-root.js';
type LanguageDef = {id: string, name: string, dir: string}; type LanguageDef = {
id: string,
name: string,
dir: string
};
const SUPPORTED_LANGUAGES: {[key: string]: LanguageDef} = { const SUPPORTED_LANGUAGES: {[key: string]: LanguageDef} = {
'am': {id: 'am', name: 'አማርኛ', dir: 'ltr'}, 'am': {id: 'am', name: 'አማርኛ', dir: 'ltr'},
'ar': {id: 'ar', name: 'العربية', dir: 'rtl'}, 'ar': {id: 'ar', name: 'العربية', dir: 'rtl'},
@ -120,10 +123,7 @@ document.addEventListener('WebComponentsReady', () => {
new App( new App(
appRoot, version, digitalocean_api.createDigitalOceanSession, appRoot, version, digitalocean_api.createDigitalOceanSession,
digitalOceanServerRepositoryFactory, new ManualServerRepository('manualServers'), digitalOceanServerRepositoryFactory, new ManualServerRepository('manualServers'),
new DisplayServerRepository(), new DigitalOceanTokenManager(), new DisplayServerRepository(), new DigitalOceanTokenManager())
new OutlineSurveys(
appRoot.$.surveyDialog, localStorage, DEFAULT_PROMPT_IMPRESSION_DELAY_MS,
DATA_LIMITS_AVAILABILITY_DATE))
.start(); .start();
}); });

View file

@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
import * as semver from 'semver';
import * as errors from '../infrastructure/errors'; import * as errors from '../infrastructure/errors';
import * as server from '../model/server'; import * as server from '../model/server';
@ -63,30 +65,36 @@ export class ShadowboxServer implements server.Server {
return this.apiRequest<void>('access-keys/' + accessKeyId, {method: 'DELETE'}); return this.apiRequest<void>('access-keys/' + accessKeyId, {method: 'DELETE'});
} }
setAccessKeyDataLimit(limit: server.DataLimit): Promise<void> { async setAccessKeyDataLimit(limit: server.DataLimit): Promise<void> {
console.info(`Setting access key data limit: ${JSON.stringify(limit)}`); console.info(`Setting access key data limit: ${JSON.stringify(limit)}`);
const requestOptions = { const requestOptions = {
method: 'PUT', method: 'PUT',
headers: new Headers({'Content-Type': 'application/json'}), headers: new Headers({'Content-Type': 'application/json'}),
body: JSON.stringify({limit}) body: JSON.stringify({limit})
}; };
return this.apiRequest<void>('experimental/access-key-data-limit', requestOptions).then(() => { await this.apiRequest<void>(this.getAccessKeyDataLimitPath(), requestOptions);
this.serverConfig.accessKeyDataLimit = limit; this.serverConfig.accessKeyDataLimit = limit;
});
} }
removeAccessKeyDataLimit(): Promise<void> { async removeAccessKeyDataLimit(): Promise<void> {
console.info(`Removing access key data limit`); console.info(`Removing access key data limit`);
return this.apiRequest<void>('experimental/access-key-data-limit', {method: 'DELETE'}) await this.apiRequest<void>(this.getAccessKeyDataLimitPath(), {method: 'DELETE'});
.then(() => { delete this.serverConfig.accessKeyDataLimit;
delete this.serverConfig.accessKeyDataLimit;
});
} }
getAccessKeyDataLimit(): server.DataLimit|undefined { getAccessKeyDataLimit(): server.DataLimit|undefined {
return this.serverConfig.accessKeyDataLimit; return this.serverConfig.accessKeyDataLimit;
} }
private getAccessKeyDataLimitPath(): string {
const version = this.getVersion();
if (semver.gte(version, '1.4.0')) {
// Data limits became a permanent feature in shadowbox v1.4.0.
return 'server/access-key-data-limit';
}
return 'experimental/access-key-data-limit';
}
getDataUsage(): Promise<server.DataUsageByAccessKey> { getDataUsage(): Promise<server.DataUsageByAccessKey> {
return this.apiRequest<server.DataUsageByAccessKey>('metrics/transfer'); return this.apiRequest<server.DataUsageByAccessKey>('metrics/transfer');
} }

View file

@ -100,6 +100,12 @@ Polymer({
width: 120px; width: 120px;
} }
} }
.data-limits-disclaimer {
margin: 0 0 8px 0;
}
.data-limits-disclaimer p {
width: 100%;
}
.detail { .detail {
margin-top: 0px; margin-top: 0px;
font-size: 12px; font-size: 12px;
@ -142,12 +148,9 @@ Polymer({
cursor: pointer; cursor: pointer;
background-color: #eee; background-color: #eee;
} }
#data-limits-container .selection-container h3 {
font-weight: normal;
margin-bottom: 8px;
}
#data-limits-container .selection-container p { #data-limits-container .selection-container p {
margin: 0 0 24px 0; margin: 0 0 24px 0;
width: 80%;
} }
#data-limits-container .selection-container span { #data-limits-container .selection-container span {
display: block; display: block;
@ -191,6 +194,39 @@ Polymer({
<paper-input readonly="" value="[[serverVersion]]" label="[[localize('settings-server-version')]]" hidden\$="[[!serverVersion]]" always-float-label="" maxlength="100"></paper-input> <paper-input readonly="" value="[[serverVersion]]" label="[[localize('settings-server-version')]]" hidden\$="[[!serverVersion]]" always-float-label="" maxlength="100"></paper-input>
</div> </div>
</div> </div>
<!-- Data limits -->
<div class="setting card-section" hidden\$="[[!supportsAccessKeyDataLimit]]">
<iron-icon class="setting-icon" icon="icons:perm-data-setting"></iron-icon>
<div id="data-limits-container">
<div class="selection-container">
<div class="content">
<h3>[[localize('data-limits')]]</h3>
<p>[[localize('data-limits-description')]]</p>
</div>
<!-- NOTE: The dropdown is not automatically sized to the button's width:
https://github.com/PolymerElements/paper-dropdown-menu/issues/229 -->
<paper-dropdown-menu no-label-float="" horizontal-align="left">
<paper-listbox slot="dropdown-content" selected="{{_computeDataLimitsEnabledName(isAccessKeyDataLimitEnabled)}}" attr-for-selected="name" on-selected-changed="_accessKeyDataLimitEnabledChanged">
<paper-item name="enabled">[[localize('enabled')]]</paper-item>
<paper-item name="disabled">[[localize('disabled')]]</paper-item>
</paper-listbox>
</paper-dropdown-menu>
</div>
<div class="sub-section data-limits-disclaimer" hidden\$="[[!showFeatureMetricsDisclaimer]]">
<iron-icon icon="icons:error-outline"></iron-icon>
<p inner-h-t-m-l="[[localize('data-limits-disclaimer', 'openLink', '<a href=https://s3.amazonaws.com/outline-vpn/index.html#/en/support/dataCollection>', 'closeLink', '</a>')]]"></p>
</div>
<div class="data-limits-input" hidden\$="[[!isAccessKeyDataLimitEnabled]]">
<paper-input id="accessKeyDataLimitInput" value="[[accessKeyDataLimit.value]]" label="Data limit per key" always-float-label="" allowed-pattern="[0-9]+" required="" auto-validate="" maxlength="9" on-keydown="_handleAccessKeyDataLimitInputKeyDown" on-blur="_requestSetAccessKeyDataLimit"></paper-input>
<paper-dropdown-menu no-label-float="">
<paper-listbox id="accessKeyDataLimitUnits" slot="dropdown-content" selected="[[accessKeyDataLimit.unit]]" attr-for-selected="name" on-selected-changed="_requestSetAccessKeyDataLimit">
<paper-item name="MB">MB</paper-item>
<paper-item name="GB">GB</paper-item>
</paper-listbox>
</paper-dropdown-menu>
</div>
</div>
</div>
<!-- Experiments --> <!-- Experiments -->
<div id="experiments" class="setting card-section" hidden\$="[[!shouldShowExperiments]]"> <div id="experiments" class="setting card-section" hidden\$="[[!shouldShowExperiments]]">
<iron-icon class="setting-icon" icon="icons:build"></iron-icon> <iron-icon class="setting-icon" icon="icons:build"></iron-icon>
@ -201,34 +237,6 @@ Polymer({
<iron-icon icon="icons:error-outline"></iron-icon> <iron-icon icon="icons:error-outline"></iron-icon>
<p inner-h-t-m-l="[[localize('experiments-disclaimer', 'openLink', '<a href=https://s3.amazonaws.com/outline-vpn/index.html#/en/support/dataCollection>', 'closeLink', '</a>')]]"></p> <p inner-h-t-m-l="[[localize('experiments-disclaimer', 'openLink', '<a href=https://s3.amazonaws.com/outline-vpn/index.html#/en/support/dataCollection>', 'closeLink', '</a>')]]"></p>
</div> </div>
<div id="data-limits-container" hidden\$="[[!supportsAccessKeyDataLimit]]">
<div class="selection-container">
<div class="content">
<h3>[[localize('data-limits')]]</h3>
<p>
[[localize('data-limits-description', 'date', dataLimitsAvailabilityDate)]]<br>
<span inner-h-t-m-l="[[localize('experiments-feedback', 'openLink', '<a href=https://docs.google.com/forms/d/e/1FAIpQLSfP7q9GnJCQyWMpFTLd9zwCm7cvUa-2NR8a8SznwMSbuRnrWg/viewform>', 'closeLink', '</a>')]]"></span>
</p>
</div>
<!-- NOTE: The dropdown is not automatically sized to the button's width:
https://github.com/PolymerElements/paper-dropdown-menu/issues/229 -->
<paper-dropdown-menu no-label-float="" horizontal-align="left">
<paper-listbox slot="dropdown-content" selected="{{_computeDataLimitsEnabledName(isAccessKeyDataLimitEnabled)}}" attr-for-selected="name" on-selected-changed="_accessKeyDataLimitEnabledChanged">
<paper-item name="enabled">[[localize('enabled')]]</paper-item>
<paper-item name="disabled">[[localize('disabled')]]</paper-item>
</paper-listbox>
</paper-dropdown-menu>
</div>
<div class="data-limits-input" hidden\$="[[!isAccessKeyDataLimitEnabled]]">
<paper-input id="accessKeyDataLimitInput" value="[[accessKeyDataLimit.value]]" label="Data limit per key" always-float-label="" allowed-pattern="[0-9]+" required="" auto-validate="" maxlength="9" on-keydown="_handleAccessKeyDataLimitInputKeyDown" on-blur="_requestSetAccessKeyDataLimit"></paper-input>
<paper-dropdown-menu no-label-float="">
<paper-listbox id="accessKeyDataLimitUnits" slot="dropdown-content" selected="[[accessKeyDataLimit.unit]]" attr-for-selected="name" on-selected-changed="_requestSetAccessKeyDataLimit">
<paper-item name="MB">MB</paper-item>
<paper-item name="GB">GB</paper-item>
</paper-listbox>
</paper-dropdown-menu>
</div>
</div>
</div> </div>
</div> </div>
<!-- Metrics controls --> <!-- Metrics controls -->
@ -264,16 +272,14 @@ Polymer({
accessKeyDataLimit: {type: Object, value: null}, // type: app.DisplayDataAmount accessKeyDataLimit: {type: Object, value: null}, // type: app.DisplayDataAmount
supportsAccessKeyDataLimit: supportsAccessKeyDataLimit:
{type: Boolean, value: false}, // Whether the server supports data limits. {type: Boolean, value: false}, // Whether the server supports data limits.
dataLimitsAvailabilityDate: showFeatureMetricsDisclaimer: {type: Boolean, value: false},
{type: String}, // Date by which the feature stops being an experiment.
isHostnameEditable: {type: Boolean, value: true}, isHostnameEditable: {type: Boolean, value: true},
serverCreationDate: {type: String, value: null}, serverCreationDate: {type: String, value: null},
serverLocation: {type: String, value: null}, serverLocation: {type: String, value: null},
serverMonthlyCost: {type: String, value: null}, serverMonthlyCost: {type: String, value: null},
serverMonthlyTransferLimit: {type: String, value: null}, serverMonthlyTransferLimit: {type: String, value: null},
localize: {type: Function, readonly: true}, localize: {type: Function, readonly: true},
shouldShowExperiments: shouldShowExperiments: {type: Boolean, value: false},
{type: Boolean, computed: '_computeShouldShowExperiments(supportsAccessKeyDataLimit)'},
}, },
setServerName: function(name) { setServerName: function(name) {
@ -346,10 +352,6 @@ Polymer({
return isAccessKeyDataLimitEnabled ? 'enabled' : 'disabled'; return isAccessKeyDataLimitEnabled ? 'enabled' : 'disabled';
}, },
_computeShouldShowExperiments: function(supportsAccessKeyDataLimit) {
return supportsAccessKeyDataLimit;
},
_validatePort: function(value) { _validatePort: function(value) {
const port = Number(value); const port = Number(value);
const valid = !Number.isNaN(port) && port >= 1 && port <= 65535 && Number.isInteger(port); const valid = !Number.isNaN(port) && port >= 1 && port <= 65535 && Number.isInteger(port);

View file

@ -556,7 +556,7 @@ export class ServerView extends DirMixin(PolymerElement) {
</div> </div>
</div> </div>
<div name="settings"> <div name="settings">
<outline-server-settings id="serverSettings" server-id="[[serverId]]" server-hostname="[[serverHostname]]" server-name="[[serverName]]" server-version="[[serverVersion]]" is-hostname-editable="[[isHostnameEditable]]" server-management-api-url="[[serverManagementApiUrl]]" server-port-for-new-access-keys="[[serverPortForNewAccessKeys]]" is-access-key-port-editable="[[isAccessKeyPortEditable]]" access-key-data-limit="{{accessKeyDataLimit}}" is-access-key-data-limit-enabled="{{isAccessKeyDataLimitEnabled}}" data-limits-availability-date="[[dataLimitsAvailabilityDate]]" supports-access-key-data-limit="[[supportsAccessKeyDataLimit]]" server-creation-date="[[serverCreationDate]]" server-monthly-cost="[[monthlyCost]]" server-monthly-transfer-limit="[[_formatBytesTransferred(monthlyOutboundTransferBytes)]]" is-server-managed="[[isServerManaged]]" server-location="[[serverLocation]]" metrics-enabled="[[metricsEnabled]]" localize="[[localize]]"> <outline-server-settings id="serverSettings" server-id="[[serverId]]" server-hostname="[[serverHostname]]" server-name="[[serverName]]" server-version="[[serverVersion]]" is-hostname-editable="[[isHostnameEditable]]" server-management-api-url="[[serverManagementApiUrl]]" server-port-for-new-access-keys="[[serverPortForNewAccessKeys]]" is-access-key-port-editable="[[isAccessKeyPortEditable]]" access-key-data-limit="{{accessKeyDataLimit}}" is-access-key-data-limit-enabled="{{isAccessKeyDataLimitEnabled}}" supports-access-key-data-limit="[[supportsAccessKeyDataLimit]]" show-feature-metrics-disclaimer="[[showFeatureMetricsDisclaimer]]" server-creation-date="[[serverCreationDate]]" server-monthly-cost="[[monthlyCost]]" server-monthly-transfer-limit="[[_formatBytesTransferred(monthlyOutboundTransferBytes)]]" is-server-managed="[[isServerManaged]]" server-location="[[serverLocation]]" metrics-enabled="[[metricsEnabled]]" localize="[[localize]]">
</outline-server-settings> </outline-server-settings>
</div> </div>
</iron-pages> </iron-pages>
@ -601,7 +601,7 @@ export class ServerView extends DirMixin(PolymerElement) {
accessKeyDataLimit: {type: Object}, accessKeyDataLimit: {type: Object},
isAccessKeyDataLimitEnabled: {type: Boolean}, isAccessKeyDataLimitEnabled: {type: Boolean},
supportsAccessKeyDataLimit: {type: Boolean}, supportsAccessKeyDataLimit: {type: Boolean},
dataLimitsAvailabilityDate: {type: String}, showFeatureMetricsDisclaimer: {type: Boolean},
isServerManaged: Boolean, isServerManaged: Boolean,
isServerReachable: Boolean, isServerReachable: Boolean,
retryDisplayingServer: Function, retryDisplayingServer: Function,
@ -650,8 +650,7 @@ export class ServerView extends DirMixin(PolymerElement) {
this.isAccessKeyDataLimitEnabled = false; this.isAccessKeyDataLimitEnabled = false;
/** Whether the server supports data limits. */ /** Whether the server supports data limits. */
this.supportsAccessKeyDataLimit = false; this.supportsAccessKeyDataLimit = false;
/** Date by which the feature stops being an experiment. */ this.showFeatureMetricsDisclaimer = false;
this.dataLimitsAvailabilityDate = '';
this.isServerManaged = false; this.isServerManaged = false;
this.isServerReachable = false; this.isServerReachable = false;
/** /**
@ -747,7 +746,7 @@ export class ServerView extends DirMixin(PolymerElement) {
return row return row
} }
return {...row, name: displayName}; return {...row, name: displayName};
}); });
}, },
revertName: () => { revertName: () => {
input.value = accessKey.name; input.value = accessKey.name;

View file

@ -1,7 +1,7 @@
{ {
"name": "outline-server", "name": "outline-server",
"private": true, "private": true,
"version": "1.3.1", "version": "1.4.0",
"description": "Outline server", "description": "Outline server",
"main": "build/server/main.js", "main": "build/server/main.js",
"author": "Outline", "author": "Outline",

View file

@ -77,6 +77,10 @@ export function bindService(
apiServer: restify.Server, apiPrefix: string, service: ShadowsocksManagerService) { apiServer: restify.Server, apiPrefix: string, service: ShadowsocksManagerService) {
apiServer.put(`${apiPrefix}/name`, service.renameServer.bind(service)); apiServer.put(`${apiPrefix}/name`, service.renameServer.bind(service));
apiServer.get(`${apiPrefix}/server`, service.getServer.bind(service)); apiServer.get(`${apiPrefix}/server`, service.getServer.bind(service));
apiServer.put(
`${apiPrefix}/server/access-key-data-limit`, service.setAccessKeyDataLimit.bind(service));
apiServer.del(
`${apiPrefix}/server/access-key-data-limit`, service.removeAccessKeyDataLimit.bind(service));
apiServer.put( apiServer.put(
`${apiPrefix}/server/hostname-for-access-keys`, `${apiPrefix}/server/hostname-for-access-keys`,
service.setHostnameForAccessKeys.bind(service)); service.setHostnameForAccessKeys.bind(service));
@ -94,13 +98,21 @@ export function bindService(
apiServer.get(`${apiPrefix}/metrics/enabled`, service.getShareMetrics.bind(service)); apiServer.get(`${apiPrefix}/metrics/enabled`, service.getShareMetrics.bind(service));
apiServer.put(`${apiPrefix}/metrics/enabled`, service.setShareMetrics.bind(service)); apiServer.put(`${apiPrefix}/metrics/enabled`, service.setShareMetrics.bind(service));
// Experimental APIs // Redirect former experimental APIs
apiServer.put( apiServer.put(
`${apiPrefix}/experimental/access-key-data-limit`, `${apiPrefix}/experimental/access-key-data-limit`,
service.setAccessKeyDataLimit.bind(service)); redirect(`${apiPrefix}/server/access-key-data-limit`));
apiServer.del( apiServer.del(
`${apiPrefix}/experimental/access-key-data-limit`, `${apiPrefix}/experimental/access-key-data-limit`,
service.removeAccessKeyDataLimit.bind(service)); redirect(`${apiPrefix}/server/access-key-data-limit`));
}
// Returns a request handler that redirects a bound request path to `url` with HTTP status code 308.
function redirect(url: string): restify.RequestHandlerType {
return (req: restify.Request, res: restify.Response, next: restify.Next) => {
logging.debug(`Redirecting ${req.url} => ${url}`);
res.redirect(308, url, next);
};
} }
function validateAccessKeyId(accessKeyId: unknown): string { function validateAccessKeyId(accessKeyId: unknown): string {