-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathserver.ts
More file actions
263 lines (227 loc) · 8.62 KB
/
server.ts
File metadata and controls
263 lines (227 loc) · 8.62 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
const axios = require('axios');
const express = require('express');
const multer = require('multer');
const path = require('path');
const fs = require('fs');
const unzipper = require('unzipper');
const bodyParser = require('body-parser');
const app = express();
const util = require('util');
const exec = util.promisify(require('child_process').exec); // Promisify exec
require('dotenv').config();
// Setup Multer for file uploads
const upload = multer({ dest: 'uploads/' });
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use('/signed', express.static(path.join(__dirname, 'signed')));
app.use(express.static(path.join(__dirname, 'view')));
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'view', 'index.html'));
});
// Endpoint to handle the signing process
app.post('/upload', upload.fields([{ name: 'ipa' }, { name: 'zip' }]), async (req, res) => {
try {
let ipaPath = ''
const zipPath = req.files['zip'][0].path;
const password = req.body.password;
const app = req.body.app
const sessionId = Math.random().toString(36).substring(7);
const bundleId = 'sign.khoindvn.io.vn' + '.' + app;
console.log('app:', app)
switch (app) {
case 'Esign':
ipaPath = path.join(__dirname, 'apps', 'Esign.ipa');
break;
case 'Scarlet':
ipaPath = path.join(__dirname, 'apps', 'Scarlet.ipa');
break;
}
if (!ipaPath) {
res.status(400).json({ error: 'Invalid app' });
throw new Error('Invalid app');
}
await fs.promises.mkdir(path.join(__dirname, 'uploads', sessionId), { recursive: true });
// Create a directory to unzip the contents
const unzipDir = path.join(__dirname, 'uploads', sessionId, 'unzipped');
await fs.promises.mkdir(unzipDir, { recursive: true });
// Unzip the uploaded file
await fs.createReadStream(zipPath)
.pipe(unzipper.Extract({ path: unzipDir }))
.promise();
// Find the unzipped P12 and mobileprovision files
const files = await fs.promises.readdir(unzipDir);
console.log('Files:', files);
let p12Path = files.find(file => file.endsWith('.p12'));
let mobileProvisionPath = files.find(file => file.endsWith('.mobileprovision'));
if (!p12Path || !mobileProvisionPath) {
// find a folder inside it
const folders = await fs.promises.readdir(path.join(unzipDir, files[0]));
// find the files again in the folder
p12Path = folders.find(file => file.endsWith('.p12'));
mobileProvisionPath = folders.find(file => file.endsWith('.mobileprovision'));
if (!p12Path || !mobileProvisionPath) {
res.status(400).json({ error: 'Missing P12 or mobile provisioning file in the ZIP' });
throw new Error('Missing P12 or mobile provisioning file in the ZIP');
}
// Update the paths
p12Path = path.join(files[0], p12Path);
mobileProvisionPath = path.join(files[0], mobileProvisionPath);
}
// Path for the extracted files
const fullP12Path = path.join(unzipDir, p12Path);
const fullMobileProvisionPath = path.join(unzipDir, mobileProvisionPath);
const outputDir = path.join(__dirname, 'signed', sessionId);
fs.mkdirSync(outputDir, { recursive: true });
const signedIpaPath = path.join(__dirname, 'signed', sessionId, 'signed.ipa');
// zsign command
let command = `./zsign -k "${fullP12Path}" -p "${password}" -m "${fullMobileProvisionPath}" -o "${signedIpaPath}" -b ${bundleId} "${ipaPath}"`;
console.log('Signing command:', command);
// Execute the signing process
const { stdout, stderr } = await exec(command);
if (stderr) {
console.error(`Error signing app: ${stderr}`);
res.status(500).json({ error: stderr });
return; // Stop further execution
}
console.log(stdout);
createPlist(signedIpaPath, bundleId, app, sessionId, (err, plistPath) => {
if (err) {
return res.status(500).json({ error: 'Failed to generate manifest.plist' });
}
const otaLink = `itms-services://?action=download-manifest&url=https://sign.khoindvn.io.vn/signed/${sessionId}/manifest.plist`;
axios.post(`https://api.tinyurl.com/create?api_token=${process.env.TINY_KEY}`, {
url: otaLink,
}).then((response) => {
console.log('TinyURL:', response.data.data.tiny_url);
res.status(200).json({ otaLink: otaLink, tinyUrl: response.data.data.tiny_url });
}).catch((error) => {
console.error('Error creating TinyURL:', error);
res.status(200).json({ otaLink: otaLink });
});
});
} catch (err) {
console.error('Error:', err);
res.status(500).json({ error: err });
}
});
app.get('/show',(req,res) => {
const uuid = req.query.UDID
const device = req.query.DEVICE_PRODUCT
console.log('----------------------------')
console.log('query:', req.query)
res.send(uuidHTML(uuid, device));
})
app.listen(3000, () => {
console.log('Server running on port 3000');
});
function createPlist(signedIpaPath, bundleId, appName, sessionId, callback) {
const plistContent = `
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>items</key>
<array>
<dict>
<key>assets</key>
<array>
<dict>
<key>kind</key>
<string>software-package</string>
<key>url</key>
<string>https://sign.khoindvn.io.vn/signed/${sessionId}/signed.ipa</string>
</dict>
</array>
<key>metadata</key>
<dict>
<key>bundle-identifier</key>
<string>${bundleId}</string>
<key>bundle-version</key>
<string>1.0.0</string> <!-- Update version dynamically if needed -->
<key>kind</key>
<string>software</string>
<key>title</key>
<string>${appName}</string>
</dict>
</dict>
</array>
</dict>
</plist>`;
const plistPath = path.join(__dirname, 'signed', sessionId, 'manifest.plist');
console.log('Plist path:', plistPath);
console.log('signedIpaPath:', signedIpaPath);
fs.writeFile(plistPath, plistContent, (err) => {
if (err) {
return callback(`Error creating plist: ${err}`);
}
callback(null, plistPath);
});
}
const uuidHTML = (uuid, device) => {
return `
<html></html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Device Info</title>
<style>
body {
background-color: #121212;
color: #fff;
height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
margin: 0;
font-family: Arial, sans-serif;
text-align: center;
}
h1 {
font-size: 24px;
margin-bottom: 20px;
}
p {
font-size: 20px;
margin-bottom: 30px;
}
.copy {
padding: 10px 20px;
background-color: #1e88e5;
color: white;
border-radius: 5px;
cursor: pointer;
font-size: 18px;
width: 100px;
margin: 0 auto;
transition: background-color 0.3s ease;
}
.copy:hover {
background-color: #1565c0;
}
.container {
background-color: #242424;
margin: 0 2em;
border-radius: 2em;
padding: 2em;
}
</style>
</head>
<body>
<div class="container">
<h1>UUID của bạn là:</h1>
<p>${uuid}</p>
<div id="copy" class="copy">Copy</div>
<p>Copy UDID Xong ra gửi cho mình nhé</p>
</div>
<script>
document.getElementById('copy').addEventListener('click', function (e) {
e.preventDefault();
navigator.clipboard.writeText("${uuid}");
alert('Copied to clipboard');
});
</script>
</body>
</html>
`
}