-
Notifications
You must be signed in to change notification settings - Fork 0
/
file_logger_plugin.cpp
179 lines (135 loc) · 7.22 KB
/
file_logger_plugin.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
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
#include "file_logger_plugin.h"
VSFFileLoggerPlugin::VSFFileLoggerPlugin(VSFPluginArchitecture & arch, std::string filePath)
: VSFPlugin(arch), logfile(filePath.c_str(), std::ios_base::out | std::ios_base::app), PlArch(arch) {
printf("VSFFileLoggerPlugin starting :)\n");
arch.registerEventHandler(*this, Event_Number_Chmod);
arch.registerEventHandler(*this, Event_Number_Connection);
arch.registerEventHandler(*this, Event_Number_Delete);
arch.registerEventHandler(*this, Event_Number_Download);
arch.registerEventHandler(*this, Event_Number_FailedLogin);
arch.registerEventHandler(*this, Event_Number_Login);
arch.registerEventHandler(*this, Event_Number_Mkdir);
arch.registerEventHandler(*this, Event_Number_Rename);
arch.registerEventHandler(*this, Event_Number_Rmdir);
arch.registerEventHandler(*this, Event_Number_Upload);
arch.registerEventHandler(*this, Event_Number_CliEnd);
arch.registerRequestHandler(*this, Request_Number_Login);
arch.registerRequestHandler(*this, Request_Number_ReadFile);
arch.registerRequestHandler(*this, Request_Number_ReadDirectory);
arch.registerRequestHandler(*this, Request_Number_WriteFile);
arch.registerRequestHandler(*this, Request_Number_WriteDirectory);
printf("VSFFileLoggerPlugin requests all done :)\n");
printf("VSFFileLoggerPlugin constructor all done :)\n");
}
VSFFileLoggerPlugin::~VSFFileLoggerPlugin()
{
PlArch.unregisterEventHandler(*this, Event_Number_Chmod);
PlArch.unregisterEventHandler(*this, Event_Number_Connection);
PlArch.unregisterEventHandler(*this, Event_Number_Delete);
PlArch.unregisterEventHandler(*this, Event_Number_Download);
PlArch.unregisterEventHandler(*this, Event_Number_FailedLogin);
PlArch.unregisterEventHandler(*this, Event_Number_Login);
PlArch.unregisterEventHandler(*this, Event_Number_Mkdir);
PlArch.unregisterEventHandler(*this, Event_Number_Rename);
PlArch.unregisterEventHandler(*this, Event_Number_Rmdir);
PlArch.unregisterEventHandler(*this, Event_Number_Upload);
PlArch.unregisterEventHandler(*this, Event_Number_CliEnd);
PlArch.unregisterRequestHandler(*this, Request_Number_Login);
PlArch.unregisterRequestHandler(*this, Request_Number_ReadFile);
PlArch.unregisterRequestHandler(*this, Request_Number_ReadDirectory);
PlArch.unregisterRequestHandler(*this, Request_Number_WriteFile);
PlArch.unregisterRequestHandler(*this, Request_Number_WriteDirectory);
logfile << "[destructor] server going down, bye\n";
}
void VSFFileLoggerPlugin::handleEvent(const EventChmod & e) {
}
void VSFFileLoggerPlugin::handleEvent(const EventConnection & e) {
}
void VSFFileLoggerPlugin::handleEvent(const EventDelete & e) {
}
void VSFFileLoggerPlugin::handleEvent(const EventDownload & e) {
logfile << "A download occured: ";
logfile << "File: " << e.getData()->fileInfo.path << "/" << e.getData()->fileInfo.name;
logfile << " (size : " << e.getData()->fileInfo.size << " )";
logfile << " user name : " << e.getData()->sharedInfo.user_name;
logfile << " timestamp : " << e.getData()->sharedInfo.timestamp.tv_sec << " sec " << e.getData()->sharedInfo.timestamp.tv_usec << " usec";
logfile << " ip: " << e.getData()->sharedInfo.remote_ip.sin_addr.s_addr << std::endl;
}
void VSFFileLoggerPlugin::handleEvent(const EventFailedLogin & e) {
logfile << "Failed login occured";
logfile << " password used: " << e.getData()->failed_password;
logfile << " user name : " << e.getData()->sharedInfo.user_name;
logfile << " timestamp : " << e.getData()->sharedInfo.timestamp.tv_sec << " sec " << e.getData()->sharedInfo.timestamp.tv_usec << " usec";
logfile << " ip: " << e.getData()->sharedInfo.remote_ip.sin_addr.s_addr << std::endl;
}
void VSFFileLoggerPlugin::handleEvent(const EventLogin & e) {
logfile << "Successful login occured: " << ( (e.getData()->is_anonymous) ? "(anonymous)" : "(non-anonymous)");
logfile << " user name : " << e.getData()->sharedInfo.user_name;
logfile << " timestamp : " << e.getData()->sharedInfo.timestamp.tv_sec << " sec " << e.getData()->sharedInfo.timestamp.tv_usec << " usec";
logfile << " ip: " << e.getData()->sharedInfo.remote_ip.sin_addr.s_addr << std::endl;
}
void VSFFileLoggerPlugin::handleEvent(const EventMkdir & e) {
logfile << "Wow ! a directory has been created, oh joy! ";
logfile << " path : " << e.getData()->path;
logfile << " user name : " << e.getData()->sharedInfo.user_name;
logfile << " timestamp : " << e.getData()->sharedInfo.timestamp.tv_sec << " sec " << e.getData()->sharedInfo.timestamp.tv_usec << " usec";
logfile << " ip: " << e.getData()->sharedInfo.remote_ip.sin_addr.s_addr << std::endl;
}
void VSFFileLoggerPlugin::handleEvent(const EventRename & e) {
}
void VSFFileLoggerPlugin::handleEvent(const EventRmdir & e) {
}
void VSFFileLoggerPlugin::handleEvent(const EventCliEnd & e) {
logfile << "A client parted";
logfile << " timestamp : " << e.getData()->timestamp.tv_sec << " sec " << e.getData()->timestamp.tv_usec << " usec";
logfile << std::endl;
}
void VSFFileLoggerPlugin::handleEvent(const EventUpload & e) {
logfile << "Upload occured " << std::endl;
}
struct Request_Result VSFFileLoggerPlugin::handleRequest(const RequestLogin & r) {
struct Request_Result retStruct = Request_Result_Init;
logfile << "request login, name: " << r.getData()->sharedInfo.user_name << " login: " << r.getData()->login << std::endl;
return retStruct;
}
struct Request_Result_And_Reason VSFFileLoggerPlugin::handleRequest(const RequestReadFile & r) {
struct Request_Result_And_Reason retStruct = Request_Result_And_Reason_Init;
printf("RequestReadFile: name: %s, path: %s, fullName: %s\n", r.getData()->name, r.getData()->path, r.getData()->fullName);
if (std::string(r.getData()->name).find("nogo") != std::string::npos)
{
retStruct.result = -1;
}
return retStruct;
}
struct Request_Result_And_Reason VSFFileLoggerPlugin::handleRequest(const RequestReadDirectory & r) {
struct Request_Result_And_Reason retStruct = Request_Result_And_Reason_Init;
printf("RequestReadDirectory: name: %s, parentPath: %s\n", r.getData()->name, r.getData()->parentPath);
if (std::string(r.getData()->name).find("nogo") != std::string::npos)
{
retStruct.result = -1;
}
return retStruct;
}
struct Request_Result_And_Reason VSFFileLoggerPlugin::handleRequest(const RequestWriteDirectory & r) {
struct Request_Result_And_Reason retStruct = Request_Result_And_Reason_Init;
printf("RequestWriteDirectory: name: %s, parentPath: %s\n", r.getData()->name, r.getData()->parentPath);
if (std::string(r.getData()->name).find("nogo") != std::string::npos)
{
retStruct.result = -1;
}
return retStruct;
}
struct Request_Result_And_Reason VSFFileLoggerPlugin::handleRequest(const RequestWriteFile & r) {
struct Request_Result_And_Reason retStruct = Request_Result_And_Reason_Init;
printf("RequestWriteFile: name: %s, path: %s, fullName: %s, doesExist:%d\n", r.getData()->name, r.getData()->path, r.getData()->fullName, r.getData()->does_exist);
if (std::string(r.getData()->name).find("nogo") != std::string::npos)
{
retStruct.result = -1;
}
return retStruct;
}
struct Request_Result_Homedir VSFFileLoggerPlugin::handleRequest(const RequestHomedir & r) {
struct Request_Result_Homedir toRet = Request_Result_Homedir_Init;
toRet.homedir = "/";
return toRet;
}