Fixed connection issuess

This commit is contained in:
Liran BG 2015-02-04 10:37:28 +02:00
parent 1eec1a9d5d
commit 01243b59d1
3 changed files with 375 additions and 334 deletions

View file

@ -132,6 +132,7 @@ bool jceSSLClient::sendData(QString str)
if (isConnected()) //if connected
{
statusBar->setIconConnectionStatus(jceStatusBar::Sending);
qDebug() << Q_FUNC_INFO << "sent:\n" << str;
amount = write(str.toStdString().c_str(),str.length());
qDebug() << Q_FUNC_INFO << "lenght send: " << str.length() << "lenght recieved: " << amount;
if (amount == -1)
@ -172,7 +173,7 @@ bool jceSSLClient::recieveData(QString *str)
disconnect(this, SIGNAL(readyRead()), this, SLOT(readIt()));
str->append(packet);
// qDebug() << *str; //if you want to see the whole packet, unmark me
qDebug() << *str; //if you want to see the whole packet, unmark me
qDebug() << Q_FUNC_INFO << "packet size: " << packetSizeRecieved << "received data lenght: " << str->length();
qDebug() << Q_FUNC_INFO << "return with flag: " << recieveLastPacket;
@ -196,7 +197,7 @@ void jceSSLClient::readIt()
do
{
// qDebug() << Q_FUNC_INFO << "packet size" << packSize;
// qDebug() << Q_FUNC_INFO << "packet size" << packSize;
if (doTimes++ > 0) //for debbuging, checking thread looping times
qDebug() << Q_FUNC_INFO << "do loop" << doTimes;

View file

@ -4,6 +4,7 @@
#include "../../src/jceSettings/user.h"
#define dst_host "yedion.jce.ac.il"
#define Boundry "----WebKitFormBoundaryN43Wu4LWxLef6EfL"
#define dst_port 443
/**
@ -16,11 +17,25 @@ class jceLoginHtmlScripts
{
private:
jceLoginHtmlScripts();
public:
static QString makeLoginRequest(QString parameters)
{
QString msg;
msg = "POST https://yedion.jce.ac.il/yedion/fireflyweb.aspx HTTP/1.1\r\n";
msg += "Host: yedion.jce.ac.il\r\n";
msg += "Content-Length: " + QString::number(parameters.length()) + "\r\n";
msg += "Content-Type: multipart/form-data; boundary=" + QString(Boundry) + "\r\n";
msg += "Proxy-Connection: Keep-Alive\r\n";
msg += "Connection: Keep-Alive\r\n";
msg += "\r\n";
msg += parameters;
return msg;
}
static QString makeRequest(QString parameters)
{
QString msg;
@ -39,10 +54,33 @@ public:
const static QString getFirstValidationStep(const user &usr)
{
QString parameters = "?appname=BSHITA&prgname=LoginValidation&arguments=-N";
QString parameters;
parameters += "--";
parameters += QString(Boundry);
parameters += "\nContent-Disposition: form-data; name=\"PRGNAME\"";
parameters += "\n\n";
parameters += "LoginValidation";
parameters += "\n";
parameters += "--";
parameters += QString(Boundry);
parameters += "\nContent-Disposition: form-data; name=\"ARGUMENTS\"";
parameters += "\n\n";
parameters += "R1C1,R1C2,-A,-A";
parameters += "\n";
parameters += "--";
parameters += QString(Boundry);
parameters += "\nContent-Disposition: form-data; name=\"R1C1\"";
parameters += "\n\n";
parameters += usr.getUsername();
parameters += ",-N";
parameters += "\n";
parameters += "--";
parameters += QString(Boundry);
parameters += "\nContent-Disposition: form-data; name=\"R1C2\"";
parameters += "\n\n";
parameters += usr.getPassword();
parameters += "\n";
parameters += "--";
parameters += QString(Boundry) + "--";
return parameters;
}

View file

@ -58,7 +58,7 @@ int jceLogin::makeConnection()
if (returnMode == (int)true) //check if username and password are matching
{
// status = jceStatus::JCE_VALIDATION_PASSED;
returnMode = makeSecondVisit();
//returnMode = makeSecondVisit();
if (returnMode == (int)true) //siging in the website
{
qDebug() << Q_FUNC_INFO << "Signed in succeesfully";
@ -152,7 +152,7 @@ void jceLogin::reMakeConnection()
*/
int jceLogin::makeFirstVisit()
{
if (JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getFirstValidationStep(*jceA))))
if (JceConnector->sendData(jceLoginHtmlScripts::makeLoginRequest(jceLoginHtmlScripts::getFirstValidationStep(*jceA))))
{
if (!JceConnector->recieveData(recieverPage))
return jceLogin::ERROR_ON_GETTING_INFO;
@ -248,34 +248,36 @@ bool jceLogin::checkValidation()
{
//finds the hashed password
QString constUserID_TAG = "value=\"-N";
QString constHassID_TAG = "-A,-N";
QString startingIndex = "javascript:send_form('Menu','";
QString constUserID_TAG = "-N";
QString constHassID_TAG = ",-A,-N";
QString hasspass,hassid;
int hasspass_position1,hasspass_position2;
int id_position1,id_position2;
hasspass_position1 = this->recieverPage->indexOf(constHassID_TAG); //looking for hasspass index
if (hasspass_position1 == -1) //didnt find the tag
return false;
else
hasspass_position1 += constHassID_TAG.length(); //skip the index of tag
hasspass_position2 = this->recieverPage->indexOf(",-A,-A", hasspass_position1);
//finds the hass pass
if (hasspass_position2 != -1) //found the hasspass! storing it
hasspass = recieverPage->mid(hasspass_position1,hasspass_position2-hasspass_position1);
else
return false;
//finds the user id
id_position1 = this->recieverPage->indexOf(constUserID_TAG, 0); //looking for hassid index
id_position1 = this->recieverPage->indexOf(constUserID_TAG,this->recieverPage->indexOf(startingIndex));
if (id_position1 == -1) //didnt find the tag
return false;
else
id_position1 += constUserID_TAG.length(); //skip the index of tag
id_position2 = this->recieverPage->indexOf(",-A", id_position1);
if (id_position2 != -1) //found the hassid! storing it
id_position2 = this->recieverPage->indexOf(constHassID_TAG,id_position1);
if (id_position2 != -1) //found the hasspass! storing it
hassid = recieverPage->mid(id_position1,id_position2-id_position1);
else
return false;
hasspass_position1 = this->recieverPage->indexOf(constHassID_TAG,this->recieverPage->indexOf(startingIndex)); //looking for hasspass index
if (hasspass_position1 == -1) //didnt find the tag
return false;
else
hasspass_position1 += constHassID_TAG.length(); //skip the index of tag
hasspass_position2 = this->recieverPage->indexOf(",-N150", hasspass_position1);
//finds the hass pass
if (hasspass_position2 != -1) //found the hasspass! storing it
hasspass = recieverPage->mid(hasspass_position1,hasspass_position2-hasspass_position1);
else
return false;
//setting user information with given data hassid and hasspass
jceA->setHashedPassword(hasspass);
jceA->setUserID(hassid);