forked from ftde0/yt2009
-
Notifications
You must be signed in to change notification settings - Fork 0
/
yt2009setup.js
158 lines (141 loc) · 4.42 KB
/
yt2009setup.js
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
const fs = require("fs")
const readline = require("readline-sync")
let cfg = {}
console.log(`
[yt2009] yt2009 setup`)
// port
let port;
while(isNaN(parseInt(port))) {
port = parseInt(
readline.question("\nwhat port should yt2009 run on? ")
)
}
cfg.port = port;
// usage environment
let env = ""
console.log(`
what environment should be used? (dev/prod)
dev:
- logs usage in terminal
- doesn't require access tokens
- no possibility of creating an ssl version
prod:
- doesn't log normal activity
- if enabled, will create a bunch of random tokens users will have to enter to use
- will be possible to create an ssl version on a separate port`)
while(env !== "dev" && env !== "prod") {
env = readline.question("environment (dev/prod): ")
}
cfg.env = env;
// ip
let ip = ""
console.log(`
what IP should be used where it needs to be coded in?
(eg. the flash player related)
preferably use your IP you will use to connect to yt2009. localhost/127.0.0.1
isn't recommended because it may break as soon as you use a different pc.`)
ip = readline.question("IP address: ")
cfg.ip = ip;
// prod-only
if(env == "prod") {
// SSL
cfg.useSSL = false;
console.log(`
since you chose your environment as prod,
do you want to use SSL on a second port?`)
let rawSSlResponse = ""
while(rawSSlResponse !== "n"
&& rawSSlResponse !== "y") {
rawSSlResponse = readline.question("use SSL? (y/n): ")
}
if(rawSSlResponse.toLowerCase() == "y") {
cfg.useSSL = true;
// SSL file paths and port
cfg.SSLCertPath = readline.question(
"\nspecify an absolute path to your ssl **certificate**.: "
)
cfg.SSLKeyPath = readline.question(
"\nspecify an absolute path to your ssl **private key**.: "
)
while(isNaN(parseInt(cfg.SSLPort))
|| cfg.port == cfg.SSLPort) {
cfg.SSLPort = readline.question(
"\nspecify a different port for the SSL yt2009 version: "
)
}
}
// tokens
let rawTokens = ""
while(rawTokens !== "n"
&& rawTokens !== "y") {
rawTokens = readline.question(
"\n\ndisable tokens requirement? will set tokens as [\"*\"]. (y/n): "
).toLowerCase()
if(rawTokens == "y") {
cfg.tokens = ["*"]
}
}
// public
let public = ""
console.log(`
set your instance as a public instance? enter its publicly-reachable IP
address or the domain name if so. leave empty/reply with "N" otherwise.
setting your instance as a public one will allow it to show up on
the public instances list, available at either of those sites:
http://orzeszek.website:203/
https://orzeszek.website:204/`)
public = readline.question("\npublic IP address. leave empty if none: ")
if(public.length > 5) {
cfg.public = public;
}
}
cfg.auto_mtaintain = false;
console.log(`
enable auto_maintain?
auto_maintain will automatically clear your instance
to prevent it from becoming unusably slow over time.`)
let rawAMResponse = ""
while(rawAMResponse !== "n"
&& rawAMResponse !== "y") {
rawAMResponse = readline.question("use auto_maintain? (y/n): ")
}
if(rawAMResponse.toLowerCase() == "y") {
cfg.auto_mtaintain = true;
// auto_maintain sizes
let maxSize = readline.question(
"\nspecify the max size the instance should use in GB. leave empty for default (10): "
)
if(maxSize.length > 0) {
while(isNaN(parseInt(maxSize))) {
maxSize = readline.question(
"\nspecify the max size the instance should use in GB. leave empty for default (10): "
)
}
cfg.maintain_max_size = parseInt(maxSize)
}
let maxCSize = readline.question(
"\nspecify the max size per cache file in MB. leave empty for default (15): "
)
if(maxCSize.length > 0) {
while(isNaN(parseInt(maxCSize))) {
maxCSize = readline.question(
"\nspecify the max size per cache file in MB. leave empty for default (15): "
)
}
cfg.maintain_max_cache_size = parseInt(maxCSize)
}
}
// confirmation
console.log(`
writing configuration to back/config.json.
you can always rerun this setup in the future to make changes.
`)
fs.writeFileSync(`${__dirname}/back/config.json`, JSON.stringify(cfg))
console.log(`
if this is your first time setting up yt2009 in this directory,
make sure to run
======
node post_config_setup.js
=====
for the next part.
`)