-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBotcpp.cpp
176 lines (120 loc) · 4.39 KB
/
Botcpp.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
#include<curl/curl.h>
#include<string>
#include<iostream>
#include <sstream>
#include<vector>
using namespace std;
vector<string> stringream(string &readBuffer, string check, int *pos)
{
*pos = 0;
int i = 0;
int flag = 100;
vector<string> c;
istringstream iss(readBuffer);
do
{
string word;
iss >> word;
if (word == check)
{
*pos = i;
flag = 0;
}
c.push_back(word);
flag++;
i++;
if (flag == 6)
return c;
} while (iss);
return c;
}
static size_t WriteCallback(void* contents, size_t size, size_t nmemb, void* userp)
{
((std::string*)userp)->append((char*)contents, size * nmemb);
return size * nmemb;
}
void main()
{
string readBuffer;
string MainPageurl = "MAIN_PAGEURL";
string SUBJECT = "SUBBJECT_URL";
string SUBJECT = "SUBBJECT_URL";
string SUBJECT = "SUBBJECT_URL";
string SUBJECT = "SUBBJECT_URL";
string SUBJECT= "SUBBJECT_URL";
auto curl = curl_easy_init();
if (curl)
{
curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64)");
curl_easy_setopt(curl, CURLOPT_AUTOREFERER, 1);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, TRUE);
curl_easy_setopt(curl, CURLOPT_COOKIEJAR, "");
curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
curl_easy_setopt(curl, CURLOPT_URL, MainPageurl.c_str());
curl_easy_perform(curl);
vector<string> c,b,a,d;
int pos;
//using stringstream to split it into words
string check = "name=\"logintoken\"" ;
string check2 = "M.cfg";
string check4 = "type=\"radio\"";
string check3 = "attendance</a></td>";
string token,sesskey;
c = stringream(readBuffer,check, &pos);
token = c[pos + 1];
string finaltoken,Sesskey,id,ID;
for (int i = token.size() - 3; i > 6; i--)
{
finaltoken = token[i]+finaltoken;
}
/// <summary>
/// iterate the sentance to obtain the value required
/// </summary>
string username,password;
cin>>username;
cin>>password;
string adds = "logintoken="+finaltoken+"&username="+username+"&password="+password;
readBuffer = "";
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, adds.c_str());
curl_easy_perform(curl);
readBuffer = "";
curl_easy_setopt(curl, CURLOPT_URL, test.c_str());
curl_easy_perform(curl);
//we now find the nested link for the submit button
string furl,finalURL,sessid;
a = stringream(readBuffer,check3,&pos);
furl = a[pos - 1];
cout << furl;
for (int i = 6; i <furl.size()-8; i++)
{
finalURL = finalURL + furl[i];
}
for (int i = 66; i < finalURL.size()-23; i++)
{
sessid = sessid + finalURL[i];
}
readBuffer = "";
curl_easy_setopt(curl, CURLOPT_URL, finalURL.c_str());
curl_easy_perform(curl);
//we get the sessid for the submit form to post via the url
b = stringream(readBuffer,check4,&pos);
id = b[pos + 4];
for (int i = 14; i < id.size() - 1; i++)
{
ID = ID + id[i];
}
//This id is used to realise how to post the status, beacuse present doesnt have the same code across
for (int i = 84; i < finalURL.size(); i++)
{
Sesskey = Sesskey + finalURL[i];
}
string form = "sessid="+sessid + "&"+"sesskey=" + Sesskey + "&"+"sesskey=" + Sesskey + "&_qf__mod_attendance_student_attendance_form=1&mform_isexpanded_id_session=1&status=" + ID + "&submitbutton=Save+changes";
curl_easy_setopt(curl, CURLOPT_POSTFIELDS,form.c_str());
///readBuffer = "";
curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
cout<< readBuffer;
}