forked from liranbg/jceConnection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjce.cpp
161 lines (149 loc) · 4.56 KB
/
jce.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
#include "jce.h"
template <typename T>
std::string to_string(T value)
{
std::ostringstream os;
os << value;
return os.str();
}
jce::jce() : userAcc()
{
recieverPage = new std::string("");
JceConnector = new sslsocket(dst_host, dst_port); //open a new ssl connection to jce
if (JceConnector->isCon())
makeFirstVisit();
else
{
puts("Error while connecting");
abort();
}
}
std::string jce::makeRequest(std::string parameters)
{
std::string msg;
msg = "POST /yedion/fireflyweb.aspx HTTP/1.1\r\n";
msg += "Host: " + to_string(dst_host) + "\r\n";
msg += "Content-Type: application/x-www-form-urlencoded\r\n";
msg += "Content-Length: " + to_string(parameters.length()) + "\r\n";
msg += "Proxy-Connection: Keep-Alive\r\n";
msg += "Accept-Charset: utf-8";
msg += "Accept: text/plain\r\n";
msg += "Connection: Keep-Alive\r\n";
msg += "\r\n";
msg += parameters;
return msg;
}
void jce::makeFurtherRequests()
{
std::string parameters;
puts("\nwrite ur command:");
std::cin >> parameters;
std::cout << parameters;
if (JceConnector->send(makeRequest(parameters)))
{
puts("message has been sent");
if (JceConnector->recieve(*recieverPage))
puts("\nrecieved");
for (auto &p : *recieverPage)
{
std::cout << p;
}
}
//delete
}
bool writeHtmlToFile(string& page)
{
ofstream myfile ("page.html");
if (myfile.is_open())
{
myfile << page;
myfile.close();
return true;
}
else
cout << "Unable to open file";
return false;
}
void jce::makeFirstVisit()
{
//making connection short path
std::string parameters = "?appname=BSHITA&prgname=LoginValidation&arguments=-N";
parameters += userAcc.getUsername();
parameters += ",-N";
parameters += userAcc.getPassword();
if (JceConnector->send(makeRequest(parameters)))
{
puts ("First login validation step");
if (JceConnector->recieve(*recieverPage))
puts("\nRecieved data");
while (true)
{
std::size_t hasspass_position1 = recieverPage->find("-A,-N"); //finds the hashed password
hasspass_position1 += 5;
std::size_t hasspass_position2 = recieverPage->find(",-A,-A", hasspass_position1);
if ((hasspass_position2 != std::string::npos) && (hasspass_position1 != std::string::npos)) {
std::string hasspass = recieverPage->substr(hasspass_position1,hasspass_position2-hasspass_position1);
userAcc.setHashedPassword(hasspass);
}
std::size_t id_position1 = recieverPage->find("e=\"-N", 0); //finds the user id
id_position1 += 5;
std::size_t id_position2 = recieverPage->find(",-A", id_position1);
if ((id_position2 != std::string::npos) && (id_position1 != std::string::npos)) {
std::string hassid = recieverPage->substr(id_position1,id_position2-id_position1);
userAcc.setUserID(hassid);
}
if (((userAcc.getUserID()).empty()) || ((userAcc.getHashedPassword()).empty()))
{
puts("conenction went wrong, reconnect. aborting");
abort();
}
else
{
puts("we got our id and hash password");
break; //we found the id and hash
}
}
//prgname=LoginValidtion1&Arguments=-N[id],-A,-N[hash],-A,-A
parameters = "prgname=LoginValidtion1&Arguments=-N";
parameters += userAcc.getUserID();
parameters += ",-A,-N";
parameters += userAcc.getHashedPassword();
parameters += ",-A,-A";
if (JceConnector->send(makeRequest(parameters)))
{
puts ("stepping out the landing page. the main html will be here soon.");
if (JceConnector->recieve(*recieverPage))
puts("\nrecieved");
}
if (JceConnector->send(makeRequest(getGradesPath("2013","0","2014","3")))) //change it in GUI (select years, semesters)
{
puts ("getting rates!");
if (JceConnector->recieve(*recieverPage))
{
puts ("printing grades!");
// const char * c =recieverPage->c_str();
// std::size_t htmlTabINdex = recieverPage->find("<html");
// c += htmlTabINdex; //getting c into the first <html> index in string
// std::string pag = to_string(c);
//writeHtmlToFile(*recieverPage); //writes string into page.html
//std::cout << pag;
Page p(*recieverPage);
std::cout << p.getString();
}
}
//makeFurtherRequests();
}
}
std::string jce::getGradesPath(std::string fromyear, std::string fromsemester,
std::string toyear,std::string tosemester)
{
std::string string = "PRGNAME=HADPASAT_MISMAHIM_LETALMID&ARGUMENTS=TZ,-N4,R1C2,R1C4,R1C1,R1C3,-A,-A,R1C5,-A,UNIQ&";
string += "TZ=" + userAcc.getUserID() + "&";
string += "UNIQ=" + userAcc.getHashedPassword() + "&";
string += "R1C2=" + fromyear + "&";
string += "R1C1=" + toyear + "&";
string += "R1C3=" + tosemester + "&";
string += "R1C4=" + fromsemester + "&";
string += "R1C5=0";
return string;
}