-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchecker.cpp
55 lines (40 loc) · 1.18 KB
/
checker.cpp
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
#include <iostream>
#include <string>
#include <cstring>
#include <memory>
#define INTERFACE "enp0s3"
#define CHECKER_GATEWAY "http://192.168.0.146/checker/"
#include <unistd.h>
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstdint>
#include <curl/curl.h>
#include "services.h"
#include "crypto.hpp"
#include "util.hpp"
int main(int argc, char **argv)
{
byte iv[BLOCK_SIZE];
byte *key = (byte *) "2c1cd7ae142f3499f8db3813eef961b2";
EVP_add_cipher(EVP_aes_256_cbc());
crypto::gen_params(iv);
/**
* packet format for 5 services:
* IP:1:1:1:1:1 - 1 is up
* IP:0:1:0:1:0 - 0 is down
*/
char p[100];
std::snprintf(p, sizeof(p), "%s:%d", util::getLocalIP(), util::getServiceStatus("nginx"), util::getServiceStatus("apache2"));
p[strlen(p)] = '\0';
secure_string ptext = p;
secure_string ctext, rtext;
crypto::aes_encrypt(key, iv, ptext, ctext);
ctext.append("::");
ctext.append((char *)iv, BLOCK_SIZE);
OPENSSL_cleanse(iv, BLOCK_SIZE);
secure_string b64text = crypto::base64_encode(ctext);
// TODO: Push to the checker's gateway
util::pushServiceStatus(b64text);
exit(EXIT_SUCCESS);
}