-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogmon2_t.cpp
More file actions
233 lines (224 loc) · 6.72 KB
/
logmon2_t.cpp
File metadata and controls
233 lines (224 loc) · 6.72 KB
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
223
224
225
226
227
228
229
230
231
232
233
#include "logmon2_t.h"
//#include <iostream>
#include <curl/curl.h>
#include <string.h>
#include <fstream>
#include <vector>
#include <sys/stat.h>
struct MemoryStruct {
char *memory;
size_t size;
};
static size_t noop(void *contents, size_t size, size_t nmemb, void *userp){}
static size_t
WriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp)
{
size_t realsize = size * nmemb;
struct MemoryStruct *mem = (struct MemoryStruct *)userp;
char *ptr =(char*) realloc(mem->memory, mem->size + realsize + 1);
if(ptr == NULL) {
/* out of memory! */
printf("not enough memory (realloc returned NULL)\n");
return 0;
}
mem->memory = ptr;
memcpy(&(mem->memory[mem->size]), contents, realsize);
mem->size += realsize;
mem->memory[mem->size] = 0;
return realsize;
}
void writestr (std::string *str,char *fil){
if (!(*str).empty())
{
std::ofstream myfile;// ("example.txt");
myfile.open (fil);
if (myfile.is_open())
{
std::cout<<"writing to file.."<<"\n";
myfile <<*str<<"\n";
myfile.close();
}
else std::cout << "Unable to open file";
}
}
bool fileExists(const std::string& filename)
{
struct stat buf;
if (stat(filename.c_str(), &buf) != -1)
{
return true;
}
return false;
}
char filename[100];
void getlogfilename(char* name)
{
int i=0;
sprintf(filename,"%s%d.txt",name,i);
while(fileExists(filename))
{
sprintf(filename,"%s%d.txt",name,i);
i++;
}
}
void writev (std::vector<std::string> *v)
{
if (v->empty()) return;
std::ofstream myfile;// ("example.txt");
myfile.open (filename); // Append mode
if (myfile.is_open())
{
//std::cout <<"size "<< v->size();
for (int i=0;i<v->size();i++)
{myfile <<(*v)[i];
//std::cout <<"size "<<(*v)[i];
}
myfile.close();
}
else std::cout << "Unable to open file";
}
CURL *curl_handle1;
CURL *curl_handle2;
void* logworker(void *td)
{
thread_data *tdata= (thread_data*)td;
DataStruct* ipss=tdata->datapointer;
CURL *curl_handlew;
CURLcode res;
struct MemoryStruct chunk;
char *plog;
int chunkadd;
std::string str;
std::string *pstrlog;
if (tdata->thread_id==1) // locallog
{
plog=ipss->locallog;chunkadd=4000;pstrlog=&ipss->str1;curl_handlew=curl_handle1;
}
else
{
plog=ipss->remotelog;chunkadd=6240;pstrlog=&ipss->str2;curl_handlew=curl_handle2;
}
(*pstrlog).empty();
chunk.memory =(char*) malloc(1); /* will be grown as needed by the realloc above */
//curl_handle = curl_easy_init();
curl_easy_setopt(curl_handlew, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
curl_easy_setopt(curl_handlew, CURLOPT_WRITEDATA, (void *)&chunk);
curl_easy_setopt(curl_handlew, CURLOPT_USERAGENT, "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.162 Safari/537.36");
curl_easy_setopt(curl_handlew, CURLOPT_COOKIEFILE, ipss->cookies);
curl_easy_setopt(curl_handlew, CURLOPT_URL, plog);
chunk.size = 0;
res = curl_easy_perform(curl_handlew);
//writez(chunk.memory);
if(res != CURLE_OK)
{
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
}
else
{
str=(chunk.memory+chunkadd);
size_t found = str.find("FALSE>");
if (found != std::string::npos)
{
size_t found2 = str.find("</te",found);
*pstrlog=str.substr((size_t)found+6,(size_t)(found2-(found+6)));
//std::cout<<pstrlog.size()<<"\n";
/* if (pstrlog->size()<16)
{
pstrlog->clear();
}*/
}
}
// curl_easy_cleanup(curl_handle);
free(chunk.memory);
pthread_exit(NULL);
}
std::string ip;
void getStatic(DataStruct *ipss)
{
char* url="https://hackerwars.io/ajax.php";
char *postdata="func=getStatic";
CURL *curl_handle;
CURLcode res;
struct MemoryStruct chunk;
chunk.memory =(char*) malloc(1);
curl_handle = curl_easy_init();
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&chunk);
// curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.162 Safari/537.36");
curl_easy_setopt(curl_handle, CURLOPT_COOKIEFILE, ipss->cookies);
curl_easy_setopt(curl_handle, CURLOPT_URL, url);
curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDS, postdata);
chunk.size = 0;
std::string str;
std::string *pstrlog;
res = curl_easy_perform(curl_handle);
if(res != CURLE_OK)
{
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
}
else
{
str=(chunk.memory);
size_t found = str.find("ip\\");
if (found != std::string::npos)
{
size_t found2 = str.find(",",found);
ip=str.substr((size_t)found+7,(size_t)((found2-2)-(found+7)));
}
}
curl_easy_cleanup(curl_handle);
free(chunk.memory);
}
void* deletelogsworker(void *td)
{
thread_data *tdata= (thread_data*)td;
DataStruct* ipss=tdata->datapointer;
CURL *curl_handle;
CURLcode res;
char *ppost;
if (tdata->thread_id==2) // locallog
{
ppost=ipss->localpost;
}
else
{
ppost=ipss->remotepost;
}
curl_handle = curl_easy_init();
// curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
// curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&chunk);
// curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.162 Safari/537.36");
curl_easy_setopt(curl_handle, CURLOPT_COOKIEFILE, ipss->cookies);
curl_easy_setopt(curl_handle, CURLOPT_URL, ipss->postURL);
curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDS, ppost);
res = curl_easy_perform(curl_handle);
curl_easy_cleanup(curl_handle);
pthread_exit(NULL);
}
void* completetasksworker(void *td)
{
thread_data *tdata= (thread_data*)td;
DataStruct* ipss=tdata->datapointer;
CURL *curl_handle;
CURLcode res;
char *pid;
if (tdata->thread_id==1) // locallog
{
pid=ipss->pid1;
}
else
{
pid=ipss->pid2;
}
char buff[100];
sprintf(buff,"%s%s", ipss->completetask,pid);
curl_handle = curl_easy_init();
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, noop);
curl_easy_setopt(curl_handle, CURLOPT_COOKIEFILE, ipss->cookies);
curl_easy_setopt(curl_handle, CURLOPT_URL, buff);
res = curl_easy_perform(curl_handle);
curl_easy_cleanup(curl_handle);
pthread_exit(NULL);
}