-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
77 lines (66 loc) · 2.5 KB
/
app.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
const PlanetHosterAPI = require('./planethoster.js');
const crypto = require("crypto");
const DOMAIN = process.env.DOMAIN;
// Getting World Account List
async function getAccounts() {
const response = await PlanetHosterAPI.getWorldAccount();
//console.log(response.data.world_accounts);
return response.data.world_accounts
}
// Creating World Account with domain and country specified
async function createWorld(domain, country) {
const response = await PlanetHosterAPI.createWorldAccount(domain, country);
console.log("Creating account...")
console.log(response.data);
if (response.data.account_created){
console.log("Account created with ID: " + response.data.id);
return response.data.id
}
}
// Modify World Account ressources
async function modifyWorld(id, cpu, mem, io) {
const response = await PlanetHosterAPI.modifyWorldAccount(id, cpu, mem, io);
if (response.data.cpu_updated){
console.log("CPU Updated");
}
if (response.data.mem_updated) {
console.log("Memory Updated");
}
if (response.data.io_updated) {
console.log("I/O Updated");
}
}
// install Wordpress
async function installWP(id, domain) {
const adminUser = crypto.randomBytes(8).toString("base64").slice(0, 8);
const adminPassword = crypto.randomBytes(20).toString("base64").slice(0, 20);
const adminEmail = "wordpress@" + domain
const path = "/"
const title = "PlanetHosterAPI is Amazing"
const locale = "fr_FR"
console.log("Installing Wordpress...")
const response = await PlanetHosterAPI.createWordpress(id, adminUser, adminPassword, adminEmail, domain, path, title, locale)
console.log(response.data)
}
async function main(domain) {
const accountList = await getAccounts()
console.log(accountList)
const account = accountList.find(account => account.domain === domain)
if (account) {
console.log("Account " + domain + " exist")
// This endpoint doesn't exist yet
// console.log(await PlanetHosterAPI.getAvailablePhpVersions(account.id))
const wpList = await PlanetHosterAPI.getWordpress(account.id)
if (wpList.data.data.length > 0){
console.log("Listing Wordpress Installs")
console.log(wpList.data)
} else {
installWP(account.id, domain)
}
} else {
console.log("Account " + domain + " not found")
const worldId = await createWorld(domain, 'CA')
modifyWorld(worldId, 2, 2, 2)
}
}
main(DOMAIN);