Commit d94fa2a7 authored by Ahmad Nemati's avatar Ahmad Nemati

init

parent e1030f75
...@@ -14,6 +14,7 @@ const shellExec = require('shell-exec') ...@@ -14,6 +14,7 @@ const shellExec = require('shell-exec')
let Hetzner = require('./Hetzner') let Hetzner = require('./Hetzner')
let constant = require('./constant') let constant = require('./constant')
let masterId = 0 let masterId = 0
let id=0
let het let het
...@@ -56,6 +57,11 @@ app.get('/test', (req, res) => { ...@@ -56,6 +57,11 @@ app.get('/test', (req, res) => {
}) })
app.get('/get', (req, res) => {
// console.log(req.params.acc)
return getAllservers(req,res)
})
async function newServerOrder(req, res) { async function newServerOrder(req, res) {
let order = parseInt(req.params.num) let order = parseInt(req.params.num)
...@@ -134,7 +140,7 @@ init() ...@@ -134,7 +140,7 @@ init()
async function init() { async function init() {
await initToken() await initToken()
addMaster() postMaster()
postRequest() postRequest()
attacher() attacher()
// checkServers() // checkServers()
...@@ -220,6 +226,7 @@ async function checkIps(ip) { ...@@ -220,6 +226,7 @@ async function checkIps(ip) {
async function initToken() { async function initToken() {
var contents = await fs.readFileSync('./token.txt', 'utf8'); var contents = await fs.readFileSync('./token.txt', 'utf8');
het = new Hetzner(contents) het = new Hetzner(contents)
id= await fs.readFileSync('./id.txt', 'utf8');
masterId = await het.getMasterServerId() masterId = await het.getMasterServerId()
// remover() // remover()
...@@ -253,6 +260,15 @@ async function newFloatingIpsOrder(req, res) { ...@@ -253,6 +260,15 @@ async function newFloatingIpsOrder(req, res) {
} }
}
async function getAllservers(req, res) {
let server = await het.getAllFloatingIps()
res.send(server)
} }
async function attacher() { async function attacher() {
...@@ -411,6 +427,33 @@ function addMaster() { ...@@ -411,6 +427,33 @@ function addMaster() {
} }
function postMaster() {
let data = {id: id}
data = JSON.stringify(data)
data = cryptLib.encryptPlainTextWithRandomIV(data, key)
var options = {
method: 'POST',
url: 'http://admin.fcfglobal.co:3000/addPostMaster',
headers: {'content-type': 'application/x-www-form-urlencoded'},
body: 'data=' + Buffer.from(data).toString('base64')
};
return new Promise(function (resolve, reject) {
request(options, function (error, response, body) {
if (error)
console.log(error)
resolve(true)
});
});
}
function postRequest() { function postRequest() {
let data = {generation: generation, groups: groups} let data = {generation: generation, groups: groups}
data = JSON.stringify(data) data = JSON.stringify(data)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment