Skip to content

Commit

Permalink
proposal: add a provider message and contact option in the dynamic key
Browse files Browse the repository at this point in the history
  • Loading branch information
daniellacosse committed Feb 2, 2024
1 parent 85ce8f8 commit 46422c7
Show file tree
Hide file tree
Showing 18 changed files with 131 additions and 26 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ GOBIND=env PATH="$(GOBIN):$(PATH)" "$(GOMOBILE)" bind
IMPORT_HOST=github.com
IMPORT_PATH=$(IMPORT_HOST)/Jigsaw-Code/outline-client

.PHONY: android apple linux windows
.PHONY: android apple linux windows browser

all: android apple linux windows

Expand Down Expand Up @@ -74,3 +74,6 @@ $(XGO): go.mod
go.mod: tools.go
go mod tidy
touch go.mod

browser:
echo 'browser environment: nothing to do'
5 changes: 5 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,10 @@ module.exports = {
'service/windows',
],
],
'type-enum': [
2,
'always',
['build', 'chore', 'ci', 'docs', 'feat', 'fix', 'perf', 'proposal', 'refactor', 'revert', 'style', 'test'],
],
},
};
2 changes: 1 addition & 1 deletion src/electron/go_vpn_tunnel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {powerMonitor} from 'electron';
import {platform} from 'os';

import {pathToEmbeddedBinary} from '../infrastructure/electron/app_paths';
import {ShadowsocksSessionConfig} from '../www/app/tunnel';
import {ShadowsocksSessionConfig} from '../www/model/shadowsocks_session_config';
import {TunnelStatus} from '../www/app/tunnel';
import {ErrorCode, fromErrorCode, UnexpectedPluginError} from '../www/model/errors';

Expand Down
2 changes: 1 addition & 1 deletion src/electron/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import autoLaunch = require('auto-launch'); // tslint:disable-line

import * as errors from '../www/model/errors';

import {ShadowsocksSessionConfig} from '../www/app/tunnel';
import {ShadowsocksSessionConfig} from '../www/model/shadowsocks_session_config';
import {TunnelStatus} from '../www/app/tunnel';
import {GoVpnTunnel} from './go_vpn_tunnel';
import {installRoutingServices, RoutingDaemon} from './routing_service';
Expand Down
2 changes: 1 addition & 1 deletion src/electron/tunnel_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import * as fs from 'fs';
import * as path from 'path';

import {ShadowsocksSessionConfig} from '../www/app/tunnel';
import {ShadowsocksSessionConfig} from '../www/model/shadowsocks_session_config';

// Format to store a tunnel configuration.
export interface SerializableTunnel {
Expand Down
21 changes: 20 additions & 1 deletion src/www/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ export class App {
// Helpers:

private makeServerListItem(server: Server): ServerListItem {
return {
const serverListItem: ServerListItem = {
disabled: false,
errorMessageId: server.errorMessageId,
isOutlineServer: server.isOutlineServer,
Expand All @@ -598,6 +598,25 @@ export class App {
id: server.id,
connectionState: ServerConnectionState.DISCONNECTED,
};

if (server.sessionConfig?.extra) {

Check warning on line 602 in src/www/app/app.ts

View check run for this annotation

Codecov / codecov/patch

src/www/app/app.ts#L601-L602

Added lines #L601 - L602 were not covered by tests
const extraParams = server.sessionConfig.extra;

if (['error', 'warning', 'info'].includes(extraParams.messageType) && extraParams.messageContent) {

Check warning on line 605 in src/www/app/app.ts

View check run for this annotation

Codecov / codecov/patch

src/www/app/app.ts#L605

Added line #L605 was not covered by tests
serverListItem.message = {
type: extraParams.messageType as 'error' | 'warning' | 'info',
content: extraParams.messageContent,
};
}

Check warning on line 610 in src/www/app/app.ts

View check run for this annotation

Codecov / codecov/patch

src/www/app/app.ts#L608-L610

Added lines #L608 - L610 were not covered by tests

if (extraParams.contactEmail) {
serverListItem.contact = {
email: extraParams.email,

Check warning on line 614 in src/www/app/app.ts

View check run for this annotation

Codecov / codecov/patch

src/www/app/app.ts#L614

Added line #L614 was not covered by tests
};
}
}

Check warning on line 617 in src/www/app/app.ts

View check run for this annotation

Codecov / codecov/patch

src/www/app/app.ts#L616-L617

Added lines #L616 - L617 were not covered by tests

return serverListItem;
}

private throttleServerConnectionChange(serverId: string, time: number) {
Expand Down
2 changes: 1 addition & 1 deletion src/www/app/cordova_main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {Tunnel, TunnelStatus} from './tunnel';
import {AbstractUpdater} from './updater';
import * as interceptors from './url_interceptor';
import {FakeOutlineTunnel} from './fake_tunnel';
import {ShadowsocksSessionConfig} from './tunnel';
import {ShadowsocksSessionConfig} from '../model/shadowsocks_session_config';
import {NoOpVpnInstaller, VpnInstaller} from './vpn_installer';

const OUTLINE_PLUGIN_NAME = 'OutlinePlugin';
Expand Down
3 changes: 2 additions & 1 deletion src/www/app/electron_outline_tunnel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

import * as errors from '../model/errors';

import {Tunnel, TunnelStatus, ShadowsocksSessionConfig} from './tunnel';
import {Tunnel, TunnelStatus} from './tunnel';
import {ShadowsocksSessionConfig} from '../model/shadowsocks_session_config';

export class ElectronOutlineTunnel implements Tunnel {
private statusChangeListener: ((status: TunnelStatus) => void) | null = null;
Expand Down
3 changes: 2 additions & 1 deletion src/www/app/fake_tunnel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

import * as errors from '../model/errors';

import {Tunnel, TunnelStatus, ShadowsocksSessionConfig} from './tunnel';
import {Tunnel, TunnelStatus} from './tunnel';
import {ShadowsocksSessionConfig} from '../model/shadowsocks_session_config';

Check warning on line 19 in src/www/app/fake_tunnel.ts

View check run for this annotation

Codecov / codecov/patch

src/www/app/fake_tunnel.ts#L17-L19

Added lines #L17 - L19 were not covered by tests
// Fake Tunnel implementation for demoing and testing.
// Note that because this implementation does not emit disconnection events, "switching" between
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {SHADOWSOCKS_URI} from 'ShadowsocksConfig';

import * as errors from '../../model/errors';

import {ShadowsocksSessionConfig} from '../tunnel';
import {ShadowsocksSessionConfig} from '../../model/shadowsocks_session_config';

// DON'T use these methods outside of this folder!

Expand All @@ -30,14 +30,15 @@ export function staticKeyToShadowsocksSessionConfig(staticKey: string): Shadowso
method: config.method.data,
password: config.password.data,
prefix: config.extra?.['prefix'],
extra: config.extra,

Check warning on line 33 in src/www/app/outline_server_repository/access_key_serialization.ts

View check run for this annotation

Codecov / codecov/patch

src/www/app/outline_server_repository/access_key_serialization.ts#L33

Added line #L33 was not covered by tests
};
} catch (cause) {
throw new errors.ServerAccessKeyInvalid('Invalid static access key.', {cause});
}
}

function parseShadowsocksSessionConfigJson(maybeJsonText: string): ShadowsocksSessionConfig | null {
const {method, password, server, server_port, prefix} = JSON.parse(maybeJsonText);
const {method, password, server, server_port, prefix, extra} = JSON.parse(maybeJsonText);

// These are the mandatory keys.
const missingKeys = [];
Expand All @@ -58,6 +59,7 @@ function parseShadowsocksSessionConfigJson(maybeJsonText: string): ShadowsocksSe
host: server,
port: server_port,
prefix,
extra,

Check warning on line 62 in src/www/app/outline_server_repository/access_key_serialization.ts

View check run for this annotation

Codecov / codecov/patch

src/www/app/outline_server_repository/access_key_serialization.ts#L62

Added line #L62 was not covered by tests
};
}

Expand Down
5 changes: 3 additions & 2 deletions src/www/app/outline_server_repository/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
import * as errors from '../../model/errors';
import * as events from '../../model/events';
import {Server, ServerType} from '../../model/server';
import {ShadowsocksSessionConfig} from '../../model/shadowsocks_session_config';

Check warning on line 18 in src/www/app/outline_server_repository/server.ts

View check run for this annotation

Codecov / codecov/patch

src/www/app/outline_server_repository/server.ts#L18

Added line #L18 was not covered by tests

import {Tunnel, TunnelStatus, ShadowsocksSessionConfig} from '../tunnel';
import {Tunnel, TunnelStatus} from '../tunnel';

import {fetchShadowsocksSessionConfig, staticKeyToShadowsocksSessionConfig} from './access_key_serialization';

Expand All @@ -28,7 +29,7 @@ export class OutlineServer implements Server {
private static readonly SUPPORTED_CIPHERS = ['chacha20-ietf-poly1305', 'aes-128-gcm', 'aes-192-gcm', 'aes-256-gcm'];

errorMessageId?: string;
private sessionConfig?: ShadowsocksSessionConfig;
sessionConfig?: ShadowsocksSessionConfig;

constructor(
public readonly id: string,
Expand Down
8 changes: 1 addition & 7 deletions src/www/app/tunnel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

export interface ShadowsocksSessionConfig {
host?: string;
port?: number;
password?: string;
method?: string;
prefix?: string;
}
import {ShadowsocksSessionConfig} from '../model/shadowsocks_session_config';

export const enum TunnelStatus {
CONNECTED,
Expand Down
5 changes: 5 additions & 0 deletions src/www/model/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import {ShadowsocksSessionConfig} from './shadowsocks_session_config';

// TODO: add guidelines for this file

export enum ServerType {
Expand All @@ -34,6 +36,9 @@ export interface Server {
// The name of this server, as given by the user.
name: string;

// The configuration used to connect to the server.
sessionConfig?: ShadowsocksSessionConfig;

// The location to pull the session config from on each connection.
sessionConfigLocation?: URL;

Expand Down
22 changes: 22 additions & 0 deletions src/www/model/shadowsocks_session_config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2024 The Outline Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

export interface ShadowsocksSessionConfig {
host?: string;
port?: number;
password?: string;
method?: string;
prefix?: string;
extra?: {[key: string]: string};
}
1 change: 1 addition & 0 deletions src/www/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
--min-supported-device-width: 320px;

--outline-primary: hsl(170, 60%, 46%);
--outline-warning: hsl(48, 52%, 53%);
--outline-error: hsl(4, 90%, 58%);

--outline-black: hsl(0, 0%, 0%);
Expand Down
4 changes: 2 additions & 2 deletions src/www/views/servers_view/server_list/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ export class ServerList extends PolymerElement {
server-row-card {
margin: 0 auto 8px auto;
height: 130px;
height: 200px;
}
server-hero-card {
height: 400px;
height: 500px;
}
</style>
Expand Down
7 changes: 7 additions & 0 deletions src/www/views/servers_view/server_list_item/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ export interface ServerListItem {
id: string;
name: string;
connectionState: ServerConnectionState;
message?: {
type: 'error' | 'warning' | 'info';
content: string;
};
contact?: {
email: string;
};
}

/**
Expand Down
54 changes: 49 additions & 5 deletions src/www/views/servers_view/server_list_item/server_card/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,41 @@ const sharedCSS = css`
grid-area: footer;
padding: var(--outline-mini-gutter) var(--outline-gutter);
text-align: end;
display: flex;
justify-content: space-between;
align-items: center;
}
.card-error {
.card-footer-button {
align-self: end;
}
.card-error,
.card-provider-message {
font-family: var(--outline-font-family);
}
.card-error,
.card-provider-message-error {
color: var(--outline-error);
margin: 0 var(--outline-slim-gutter);
}
.card-provider-message-warning {
color: var(--outline-warning);
}
.card-provider-message-warning::before {
content: '⚠️ ';
}
.card-provider-message-info,
.card-provider-message-contact {
color: var(--outline-primary);
}
.card-provider-message-contact {
cursor: pointer;
text-decoration: underline;
}
`;

Expand All @@ -140,13 +170,18 @@ const getSharedComponents = (element: ServerListItemElement & LitElement) => {
ServerConnectionState.RECONNECTING,
].includes(server.connectionState);
const hasErrorMessage = Boolean(server.errorMessageId);

const messages = {
const messages: {[key: string]: string} = {

Check warning on line 173 in src/www/views/servers_view/server_list_item/server_card/index.ts

View check run for this annotation

Codecov / codecov/patch

src/www/views/servers_view/server_list_item/server_card/index.ts#L173

Added line #L173 was not covered by tests
serverName: server.name,
error: hasErrorMessage ? localize(server.errorMessageId) : '',
connectButton: localize(isConnectedState ? 'disconnect-button-label' : 'connect-button-label'),
};

if (Boolean(server.message && server.contact) && !hasErrorMessage) {
messages.providerMessageType = server.message.type;
messages.providerMessage = localize(server.message.content);
messages.providerEmail = server.contact.email;

Check warning on line 182 in src/www/views/servers_view/server_list_item/server_card/index.ts

View check run for this annotation

Codecov / codecov/patch

src/www/views/servers_view/server_list_item/server_card/index.ts#L179-L182

Added lines #L179 - L182 were not covered by tests
}

Check warning on line 184 in src/www/views/servers_view/server_list_item/server_card/index.ts

View check run for this annotation

Codecov / codecov/patch

src/www/views/servers_view/server_list_item/server_card/index.ts#L184

Added line #L184 was not covered by tests
const dispatchers = {
beginRename: () =>
element.dispatchEvent(
Expand Down Expand Up @@ -211,8 +246,17 @@ const getSharedComponents = (element: ServerListItemElement & LitElement) => {
`,
footer: html`
<footer class="card-footer">
<span class="card-error">${messages.error}</span>
<div>
<span class="card-error">${messages.error}</span>
<span class="card-provider-message card-provider-message-${messages.providerMessageType}">
${messages.providerMessage}
<a class="card-provider-message-contact" href="mailto:${messages.providerEmail}"
>${messages.providerEmail}</a
>
</span>
</div>
<mwc-button
class="card-footer-button"

Check warning on line 259 in src/www/views/servers_view/server_list_item/server_card/index.ts

View check run for this annotation

Codecov / codecov/patch

src/www/views/servers_view/server_list_item/server_card/index.ts#L259

Added line #L259 was not covered by tests
label="${messages.connectButton}"
@click="${dispatchers.connectToggle}"
?disabled=${hasErrorMessage}
Expand Down

0 comments on commit 46422c7

Please sign in to comment.