-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpasswords.js
More file actions
83 lines (74 loc) · 2.35 KB
/
passwords.js
File metadata and controls
83 lines (74 loc) · 2.35 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
import { Password } from "@hosterai/passwords";
import crypto from "crypto";
import {
loadConfig,
saveConfig,
loadPasswords,
savePasswords,
} from "./config.js";
import { exit } from "process";
const args = process.argv.slice(2);
const hostname = args[0];
const force = args[1] || null;
if(!hostname) {
console.log("Please provide a server hostname in order to generate passwords");
console.log("Example: node passwords.js myserver.streamings.gr");
exit(1);
}
const passwords = await loadPasswords();
if (passwords && force===null) {
console.log("Passwords already exist");
console.log("-------------------------");
printConfig(
passwords.adminPassword,
passwords.streamSecret,
passwords.expire,
passwords.hash,
hostname
);
exit(0);
}
if(force) {
console.log("Forcing new passwords generation");
console.log("Please restart the server (pm2 restart stream)");
console.log("-------------------------");
}
const password = new Password();
const adminPassword = password.generate(10);
const streamSecret = password
.lowercaseLength(4)
.uppercaseLength(4)
.symbolsLength(0)
.numbersLength(4)
.generate(12);
const expire = Math.floor(Date.now() / 1000) + 50 * 365 * 24 * 60 * 60;
const streamName = "/live/stream";
const hashString = `${streamName}-${expire}-${streamSecret}`;
console.log(`[hashString: ${hashString}]`);
const hash = crypto.createHash("md5").update(hashString).digest("hex");
const config = await loadConfig();
await updateConfig(config);
printConfig(adminPassword, streamSecret, expire, hash, hostname);
savePasswords({
adminPassword,
streamSecret,
expire,
hash,
});
function printConfig(adminPassword, streamSecret, expire, hash, hostname) {
console.log(`Admin username: admin`);
console.log(`Admin password: ${adminPassword}`);
console.log(`Stream secret: ${streamSecret}`);
console.log('');
console.log(`rtmp url: rtmp://${hostname}/live/stream?sign=${expire}-${hash}`);
console.log(`http url: http://${hostname}/live/stream.flv?sign=${expire}-${hash}`);
console.log(`ws url: ws://${hostname}/live/stream.flv?sign=${expire}-${hash}`);
console.log('');
console.log(`rtmp for player: rtmp://${hostname}:1935/live/index.m3u8}`)
}
async function updateConfig(config) {
config.auth.api_pass = adminPassword;
config.auth.secret = streamSecret;
await saveConfig(config);
return config;
}