-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.tsx
More file actions
164 lines (147 loc) · 4.26 KB
/
Copy pathindex.tsx
File metadata and controls
164 lines (147 loc) · 4.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import type { NextPage } from 'next';
import { useState } from 'react';
import Head from 'next/head';
import styles from '../styles/Home.module.css';
import Webplayer from '@corellium/corellium-webplayer';
const Home: NextPage = () => {
const [text, setText] = useState('Add your endpoint and press Connect');
const [show, setShow] = useState(false);
const [endpoint, setEndpoint] = useState('');
const [features, setFeatures] = useState({
connect: true,
files: true,
apps: true,
network: true,
coretrace: true,
messaging: true,
settings: true,
frida: true,
console: true,
portForwarding: true,
sensors: true,
snapshots: true,
powerManagement: true,
});
const handleCreateDevice = async () => {
setText('Creating device...');
try {
const createdDevice = await fetch('/api/createDevice', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
endpoint,
}),
});
setText('Device created successfully');
const json = await createdDevice.json();
if (json.error) {
setText(json.error);
}
if (!json.error) {
handleCreateSession(json.projectId, json.instanceId);
}
} catch (error: unknown) {
console.error(error);
setText('Error creating device!');
}
};
const handleCreateSession = async (projectId: string, instanceId: string) => {
setText('Getting token...');
try {
setText('Getting token...');
// get JWT using access token
const res = await fetch('/api/createSession', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
domain: endpoint,
projectId,
instanceId,
features,
}),
});
const { token, ...data } = await res.json();
console.log('received JWT', token, data);
if (token) {
setText('Token recieved and connecting ...');
const webplayer = new Webplayer({
token,
domain: endpoint,
instanceId,
containerId: 'container',
});
webplayer.on('success', (data) => {
console.log('data', data);
setText('Connected!');
setTimeout(() => {
setShow(true);
}, 1000);
});
webplayer.on('error', (data) => {
console.error('webplayer error', data);
// @ts-ignore
setText(data.message);
});
}
} catch (err) {
console.log('server err :>> ', err);
setText('Error!');
}
};
return (
<div className={styles.container}>
<Head>
<title>Corellium - Webplayer Example</title>
<meta name="description" content="Corellium Webplayer Example" />
<link rel="icon" href="/favicon.ico" />
</Head>
<main className={styles.main}>
<div className={styles.field}>
<label htmlFor="corelliumDomain">Enterprise Endpoint</label>
<input
type="text"
name="corelliumDomain"
onChange={(e) => setEndpoint(e.target.value)}
/>
</div>
<div className={styles.features}>
{Object.keys(features).map((feature, index) => (
<div className={styles.featuresWrapper} key={index}>
<input
type="checkbox"
name={feature}
id={feature}
checked={features[feature as keyof typeof features]}
onChange={(e) =>
setFeatures({
...features,
[feature]: e.target.checked,
})
}
/>
<label className={styles.label} htmlFor={feature}>
{feature}
</label>
</div>
))}
</div>
<div className={styles.field}>
<button className={styles.btn} onClick={handleCreateDevice}>
Connect
</button>
</div>
<h1>{text}</h1>
<div
className={styles.container}
id="container"
style={{ opacity: show ? 1 : 0 }}
></div>
</main>
</div>
);
};
export default Home;