Skip to content
This repository was archived by the owner on Aug 10, 2024. It is now read-only.

Commit ec8d204

Browse files
committed
Store key in url param
Nit pick
1 parent 6a6ac96 commit ec8d204

File tree

4 files changed

+39
-17
lines changed

4 files changed

+39
-17
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Use the `-encrypt {password}` option to encrypt your data End-to-End using the A
3737
```bash
3838
$ ping google.com | cli2cloud -encrypt 1234
3939
Your client ID: CGYWdD
40-
Share and monitor it live from https://cli2cloud.com/CGYWdD
40+
Share and monitor it live from https://cli2cloud.com/CGYWdD?key=1234
4141

4242
PING google.com (172.217.22.142): 56 data bytes
4343
64 bytes from 172.217.22.142: icmp_seq=0 ttl=112 time=14.154 ms
@@ -52,12 +52,12 @@ Use the option `-encrypt-random` to generate a random secure password with 16 sy
5252
$ ping google.com | cli2cloud -encrypt-random
5353
Your password: mruI3ubFXTww1QYf
5454
Your client ID: 56xY35
55-
Share and monitor it live from https://cli2cloud.com/56xY35
55+
Share and monitor it live from https://cli2cloud.com/56xY35?key=mruI3ubFXTww1QYf
5656

5757
PING google.com (142.250.201.174): 56 data bytes
5858
64 bytes from 142.250.201.174: icmp_seq=0 ttl=116 time=3.322 ms
5959
64 bytes from 142.250.201.174: icmp_seq=1 ttl=116 time=2.648 ms
60-
...
60+
..mruI3ubFXTww1QYf.
6161
```
6262

6363
## Feedback

cli/cli2cloud/cli2cloud.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import (
1414
)
1515

1616
const (
17-
serverIP = "167.99.140.19:50051"
17+
//serverIP = "localhost:50051" // local dev
18+
serverIP = "167.99.140.19:50051" // production
1819
randomPasswordLength = 16
1920
)
2021

@@ -55,7 +56,13 @@ func sendPipedMessages(c proto.Cli2CloudClient, ctx context.Context, password *s
5556

5657
clientId, err := c.RegisterClient(ctx, &client)
5758
fmt.Printf("Your client ID: %s\n", clientId.Id)
58-
fmt.Printf("Share and monitor it live from https://cli2cloud.com/%s\n\n", clientId.Id)
59+
60+
keyURLSuffix := ""
61+
if password != nil {
62+
keyURLSuffix = fmt.Sprintf("?key=%s", *password)
63+
}
64+
65+
fmt.Printf("Share and monitor it live from https://cli2cloud.com/%s%s\n\n", clientId.Id, keyURLSuffix)
5966
// Wait 2 seconds for user to copy the client ID
6067
time.Sleep(2 * time.Second)
6168

@@ -114,7 +121,6 @@ func parseFlags() *string {
114121
if err != nil {
115122
log.Fatal("Error while generating the random password", err)
116123
}
117-
118124
fmt.Printf("Your password: %s\n", *password)
119125
}
120126

webapp/src/pages/Documentation.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export const Documentation = () => {
6161
<code className={styles.codeStyle}>
6262
$ ping google.com | cli2cloud -encrypt 1234 <br/>
6363
Your client ID: CGYWdD <br/>
64-
Share and monitor it live from https://cli2cloud.com/CGYWdD <br/>
64+
Share and monitor it live from https://cli2cloud.com/CGYWdD?key=1234<br/>
6565
<br/>
6666
PING google.com (172.217.22.142): 56 data bytes <br/>
6767
64 bytes from 172.217.22.142: icmp_seq=0 ttl=112 time=14.154 ms <br/>
@@ -82,7 +82,7 @@ export const Documentation = () => {
8282
$ ping google.com | cli2cloud -encrypt-random <br/>
8383
Your password: mruI3ubFXTww1QYf <br/>
8484
Your client ID: 56xY35 <br/>
85-
Share and monitor it live from https://cli2cloud.com/56xY35 <br/>
85+
Share and monitor it live from https://cli2cloud.com/56xY35?key=mruI3ubFXTww1QYf<br/>
8686
<br/>
8787
PING google.com (142.250.201.174): 56 data bytes <br/>
8888
64 bytes from 142.250.201.174: icmp_seq=0 ttl=116 time=3.322 ms <br/>

webapp/src/pages/Monitor.tsx

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ interface Row {
1515
interface State {
1616
encrypted: boolean,
1717
enterPwdFirstTime: boolean,
18+
password: string | null,
1819
decryptor: DecryptionService | null,
1920
rows: Row[],
2021
raw: boolean,
@@ -31,18 +32,19 @@ export class Monitor extends Component<{}, State> {
3132

3233
this.state = {
3334
encrypted: false,
35+
enterPwdFirstTime: !(new URLSearchParams(new URL(window.location.href).search).has("key")),
36+
password: new URLSearchParams(new URL(window.location.href).search).get("key"),
3437
decryptor: null,
35-
enterPwdFirstTime: true,
3638
rows: [],
3739
raw: new URLSearchParams(new URL(window.location.href).search).has("raw"),
3840
};
3941

4042
this.numLines = 1;
41-
this.cli2CloudService = new Cli2CloudClient("https://cli2cloud.com:1443", null, null);
43+
this.cli2CloudService = new Cli2CloudClient("https://cli2cloud.com:1443", null, null); // production
44+
//this.cli2CloudService = new Cli2CloudClient("http://localhost:8000", null, null); // local dev
4245

43-
const id = window.location.pathname.substring(1);
44-
4546
this.clientId = new ClientId();
47+
const id = window.location.pathname.substring(1);
4648
this.clientId.setId(id);
4749

4850
this.client = this.cli2CloudService.getClientById(this.clientId, {})
@@ -56,16 +58,27 @@ export class Monitor extends Component<{}, State> {
5658
this.switchToRawData = this.switchToRawData.bind(this);
5759

5860
this.client.then((client) => {this.setState({encrypted: client.getEncrypted()})});
61+
62+
if (!this.state.enterPwdFirstTime) {
63+
this.createDecryptor();
64+
}
65+
5966
this.loadContent();
6067
}
6168

6269
private updatePassword(newPassword: string) {
63-
this.createDecryptor(newPassword);
70+
this.setURLParams("key", newPassword);
71+
this.setState({password: newPassword});
72+
this.createDecryptor();
6473
}
6574

66-
private createDecryptor(password: string) {
75+
private createDecryptor() {
76+
if (this.state.password === null) {
77+
console.log("Can't create decryptor");
78+
return;
79+
}
6780
this.client.then((client: Client) => {
68-
this.setState({decryptor: new DecryptionService(password, client.getSalt(), client.getIv())});
81+
this.setState({decryptor: new DecryptionService(this.state.password!, client.getSalt(), client.getIv())});
6982
});
7083
}
7184

@@ -142,11 +155,14 @@ export class Monitor extends Component<{}, State> {
142155
);
143156
}
144157

145-
private switchToRawData() {
158+
private setURLParams(key: string, value: string) {
146159
let params = new URLSearchParams(new URL(window.location.href).search);
147-
params.set("raw", "true");
160+
params.set(key, value);
148161
window.location.search = params.toString()
162+
}
149163

164+
private switchToRawData() {
165+
this.setURLParams("raw", "true");
150166
this.setState({raw: true});
151167
}
152168

0 commit comments

Comments
 (0)