-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·222 lines (168 loc) · 9.04 KB
/
index.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
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
'use strict'
const express = require('express')
const bodyParser = require('body-parser')
const request = require('request')
const app = express()
var https = require('https');
var fs = require('fs');
var database = require('./schema.js');
var Q = require('q');
var leve = require('levenshtein');
var c = require('./config.js');
var dof = require('./dofunc.js');
var mess = require('./messenger.js');
var sort = require('./sort.js');
var ssl = {
key: fs.readFileSync('/etc/letsencrypt/live/www.diuda.me/privkey.pem'),
cert: fs.readFileSync('/etc/letsencrypt/live/www.diuda.me/cert.pem'),
ca: fs.readFileSync('/etc/letsencrypt/live/www.diuda.me/chain.pem')
};
https.createServer(ssl, app).listen(444);
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
const token = c['fb'].page_token;
app.get('/', function(req, res) {
if (req.query['hub.verify_token'] === token) {
res.send(req.query['hub.challenge'])
}
res.send(req.query['hub.challenge']);
})
app.post('/status',function(req,res){
console.log(req.body)
sendStatus(req.body);
})
app.get('/status', function(req, res){
})
const user_token = c['do'].auth_token;
var status = 0;
app.post('/', function(req, res) {
let msg_event = req.body.entry[0].messaging;
for (var i = 0; i < msg_event.length; i++) {
let event = req.body.entry[0].messaging[i];
let sender = event.sender.id.toString();
if ((event.message != undefined) && (!event.message.is_echo)) {
// console.log("hello");
if (sort.info[sender] == undefined) {
mess.findToken(sender).then(function(body) {
console.log(body)
sort.info[sender] = { token: body };
mess.sendTextMessage(sender, "Welcome!!!")
}, function(err) {
// console.log(err);
});
} else {
// console.log("hello");
//similarity between two strings
var distance = function(str1, str2) {
var l = new leve(str1, str2);
return (1 - (l.distance / Math.max(str1.length, str2.length))) * 100;
}
console.log(distance("hello", "hel"));
if (event.message && event.message.text) {
let text = event.message.text;
if (distance('token', text.toLowerCase())>=85) {
console.log(distance('token', text.toLowerCase()))
sort.states.UserState[sender] = { module: "eToken", stage: 1 };
} else if (distance('update token', text.toLowerCase())>=85) {
sort.states.UserState[sender] = { module: "uToken", stage: 1 };
} else if (distance('list droplet', text.toLowerCase())>=85) {
sort.states.UserState[sender] = { module: "lDroplet", stage: 1 };
}else if (distance('list actions', text.toLowerCase())>=85) {
sort.states.UserState[sender] = { module: "lActions", stage: 1 };
} else if (distance('list domains', text.toLowerCase())>=85) {
console.log(distance('list domains', text.toLowerCase()))
sort.states.UserState[sender] = { module: "lDomains", stage: 1 };
}
else if(distance('add domain', text.toLowerCase())>=85){
sort.states.UserState[sender] = {module: "aDomain", stage: 1};
}
else if(distance('delete domain', text.toLowerCase())>=85){
sort.states.UserState[sender] = {module: "dDomain", stage: 1};
}
else if(distance('add domain record', text.toLowerCase())>=85){
sort.states.UserState[sender] = {module: "aDomainRecord", stage: 1};
}
else if (distance('list domain records', text.toLowerCase())>=85) {
sort.states.UserState[sender] = { module: "lDomainRecords", stage: 1 };
}
else if(distance('delete domain record', text.toLowerCase())>=85){
sort.states.UserState[sender] = { module: "dDomainRecord", stage: 1}
}
else if (distance('list snapshots', text.toLowerCase())>=85) {
sort.states.UserState[sender] = { module: "lSnapshots", stage: 1 };
}
else if(distance('delete snapshot', text.toLowerCase())>=85){
sort.states.UserState[sender] = { module: "dSnapshot", stage: 1};
}
else if (distance('list regions', text.toLowerCase())>=85) {
sort.states.UserState[sender] = { module: "lRegions", stage: 1 };
} else if (distance('list sizes', text.toLowerCase())>=85) {
sort.states.UserState[sender] = { module: "lSizes", stage: 1 };
}
else if (distance('delete droplet', text.toLowerCase())>=85) {
sort.states.UserState[sender] = { module: "dDroplet", stage: 1 };
}
else if (distance('create droplet', text.toLowerCase())>=85) {
sort.states.UserState[sender] = { module: "cDroplet", stage: 1 };
}
//TODO list backups for droplet
else if (distance('droplet action', text.toLowerCase())>=85) {
sort.states.UserState[sender] = { module: "aDroplet", stage: 1 };
}
else if(distance('list images', text.toLowerCase())>=85){
sort.states.UserState[sender] = {module: "lImage", stage: 1};
sort.info[sender].count = 10;
}
else if(distance('list distribution images', text.toLowerCase())>=85){
sort.states.UserState[sender] = {module: "lDImage", stage: 1};
sort.info[sender].count = 10;
}
else if(distance('list application images', text.toLowerCase())>=85){
sort.states.UserState[sender] = {module: "lAImage", stage: 1};
sort.info[sender].count = 10;
}
else if(distance('list user images', text.toLowerCase())>=85){
sort.states.UserState[sender] = {module: "lUImage", stage: 1};
}
else if(distance('delete image', text.toLowerCase())>=85){
sort.states.UserState[sender] = {module: "dImage", stage: 1};
}
else if(distance('image actions', text.toLowerCase())>=85){
sort.states.UserState[sender] = {module: "aImage", stage: 1}
}
else if(distance('list block storage', text.toLowerCase())>=85){
sort.states.UserState[sender] = {module: "lBlock", stage: 1}
}
else if(distance('create block storage', text.toLowerCase())>=85){
sort.states.UserState[sender] = { module: "cBlock", stage: 1}
}
else if(distance('create storage snapshot', text.toLowerCase())>=85){
sort.states.UserState[sender] = { module: "cBlockSnap", stage: 1}
}
else if(distance('delete storage', text.toLowerCase())>=85){
sort.states.UserState[sender] = { module: "dBlock", stage: 1}
}
else if(distance('storage action', text.toLowerCase())>=85){
sort.states.UserState[sender] = { module: "aStorage", stage: 1}
}
else if(distance('status', text.toLowerCase())>=85){
//CALL THE BASH FILE HERE
}
// console.log("hell");
if (sort.states.UserState[sender] != undefined) {
mess.checkStatus(sort.info[sender].token, status, sender, text, function(messbody) {
mess.sendTextMessage(sender, messbody)
// console.log("sup")
});
// console.log("xyz");
}
}
}
}
}
res.sendStatus(200);
})
function sendStatus(status) {
console.log(status);
return;
}