-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMonitor.cpp
More file actions
40 lines (31 loc) · 777 Bytes
/
Copy pathMonitor.cpp
File metadata and controls
40 lines (31 loc) · 777 Bytes
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
#include "Includes/Monitor.h"
#include <array>
#include <cstdio>
#include <regex>
void Monitor::Start(LoginCallback callback)
{
FILE* pipe =
popen(
"journalctl -f -n 0 -u ssh -u sshd --no-pager",
"r"
);
if (!pipe)
return;
std::array<char,4096> buffer{};
std::regex regex(
R"(Accepted (?:password|publickey|keyboard-interactive) for (\S+) from ([0-9a-fA-F:.]+))"
);
while (fgets(buffer.data(), buffer.size(), pipe))
{
std::string line(buffer.data());
std::smatch match;
if (std::regex_search(line, match, regex))
{
callback(
match[1].str(),
match[2].str()
);
}
}
pclose(pipe);
}