|  | @@ -0,0 +1,105 @@
 | 
		
	
		
			
			|  | 1 | +#include "mainclass.h"
 | 
		
	
		
			
			|  | 2 | +#include <QApplication>
 | 
		
	
		
			
			|  | 3 | +#include <QFileInfo>
 | 
		
	
		
			
			|  | 4 | +#include <iostream>
 | 
		
	
		
			
			|  | 5 | +
 | 
		
	
		
			
			|  | 6 | +MainClass::MainClass(QObject* p) : QObject(p)
 | 
		
	
		
			
			|  | 7 | +{
 | 
		
	
		
			
			|  | 8 | +	if(qApp->argc() < 2)
 | 
		
	
		
			
			|  | 9 | +	{
 | 
		
	
		
			
			|  | 10 | +		qDebug()<<"Usage:"<<QFileInfo(qApp->applicationFilePath()).fileName().toStdString().c_str()<< "loginsFile";
 | 
		
	
		
			
			|  | 11 | +		qApp->exit(-1);
 | 
		
	
		
			
			|  | 12 | +	}
 | 
		
	
		
			
			|  | 13 | +
 | 
		
	
		
			
			|  | 14 | +	m_intra = new IntraBocal(this);
 | 
		
	
		
			
			|  | 15 | +	connect(m_intra, SIGNAL(error(IntraBocal::Error)), this, SLOT(intraError(IntraBocal::Error)));
 | 
		
	
		
			
			|  | 16 | +	connect(m_intra, SIGNAL(logged()), this, SLOT(intraLogged()));
 | 
		
	
		
			
			|  | 17 | +	connect(m_intra, SIGNAL(searchFinished(QList<QList<QString> >)), this, SLOT(intraSearchFinished(QList<QList<QString> >)));
 | 
		
	
		
			
			|  | 18 | +
 | 
		
	
		
			
			|  | 19 | +	m_users = Epimafia::loadUsers();
 | 
		
	
		
			
			|  | 20 | +	for(int i = 0; i < m_users.size(); ++i)
 | 
		
	
		
			
			|  | 21 | +	{
 | 
		
	
		
			
			|  | 22 | +		EpiUser usr = m_users.at(i);
 | 
		
	
		
			
			|  | 23 | +		if(!usr.hasLogin() || usr.isUnknown() || !usr.hasPwd_ppp())
 | 
		
	
		
			
			|  | 24 | +			m_users.removeAt(i--);
 | 
		
	
		
			
			|  | 25 | +	}
 | 
		
	
		
			
			|  | 26 | +	if(m_users.isEmpty())
 | 
		
	
		
			
			|  | 27 | +	{
 | 
		
	
		
			
			|  | 28 | +		qDebug()<<"No Logins";
 | 
		
	
		
			
			|  | 29 | +		qApp->exit(-1);
 | 
		
	
		
			
			|  | 30 | +	}
 | 
		
	
		
			
			|  | 31 | +	m_intra->login(m_users.at(0).getLogin(), m_users.at(0).getPwd_ppp());
 | 
		
	
		
			
			|  | 32 | +
 | 
		
	
		
			
			|  | 33 | +	QFile logins(qApp->arguments().at(1));
 | 
		
	
		
			
			|  | 34 | +	if(!logins.open(QIODevice::ReadOnly))
 | 
		
	
		
			
			|  | 35 | +	{
 | 
		
	
		
			
			|  | 36 | +		qDebug()<<"Unable to open "<<logins.fileName();
 | 
		
	
		
			
			|  | 37 | +		qApp->exit(-1);
 | 
		
	
		
			
			|  | 38 | +	}
 | 
		
	
		
			
			|  | 39 | +	while(!logins.atEnd())
 | 
		
	
		
			
			|  | 40 | +	{
 | 
		
	
		
			
			|  | 41 | +		QString str = logins.readLine();
 | 
		
	
		
			
			|  | 42 | +		str.replace("\n", "");
 | 
		
	
		
			
			|  | 43 | +		str.replace("\r", "");
 | 
		
	
		
			
			|  | 44 | +		if(!str.isEmpty())
 | 
		
	
		
			
			|  | 45 | +			m_logins.append(str);
 | 
		
	
		
			
			|  | 46 | +	}
 | 
		
	
		
			
			|  | 47 | +	logins.close();
 | 
		
	
		
			
			|  | 48 | +}
 | 
		
	
		
			
			|  | 49 | +
 | 
		
	
		
			
			|  | 50 | +MainClass::~MainClass()
 | 
		
	
		
			
			|  | 51 | +{
 | 
		
	
		
			
			|  | 52 | +}
 | 
		
	
		
			
			|  | 53 | +
 | 
		
	
		
			
			|  | 54 | +void MainClass::intraError(IntraBocal::Error e)
 | 
		
	
		
			
			|  | 55 | +{
 | 
		
	
		
			
			|  | 56 | +	if(e == IntraBocal::BadLogin)
 | 
		
	
		
			
			|  | 57 | +	{
 | 
		
	
		
			
			|  | 58 | +		if(!m_users.isEmpty())
 | 
		
	
		
			
			|  | 59 | +		{
 | 
		
	
		
			
			|  | 60 | +			m_users.removeFirst();
 | 
		
	
		
			
			|  | 61 | +			m_intra->login(m_users.at(0).getLogin(), m_users.at(0).getPwd_ppp());
 | 
		
	
		
			
			|  | 62 | +			return;
 | 
		
	
		
			
			|  | 63 | +		}
 | 
		
	
		
			
			|  | 64 | +		else
 | 
		
	
		
			
			|  | 65 | +			qDebug()<<"No Logins with valid password";
 | 
		
	
		
			
			|  | 66 | +	}
 | 
		
	
		
			
			|  | 67 | +	else if(e == IntraBocal::NetworkError)
 | 
		
	
		
			
			|  | 68 | +		qDebug()<<"Network Error";
 | 
		
	
		
			
			|  | 69 | +	else if(e == IntraBocal::ParseError)
 | 
		
	
		
			
			|  | 70 | +		qDebug()<<"Parse Error";
 | 
		
	
		
			
			|  | 71 | +	else if(e == IntraBocal::SslError)
 | 
		
	
		
			
			|  | 72 | +		qDebug()<<"Ssl Error";
 | 
		
	
		
			
			|  | 73 | +	qApp->exit(-1);
 | 
		
	
		
			
			|  | 74 | +}
 | 
		
	
		
			
			|  | 75 | +
 | 
		
	
		
			
			|  | 76 | +void MainClass::intraLogged()
 | 
		
	
		
			
			|  | 77 | +{
 | 
		
	
		
			
			|  | 78 | +	qDebug()<<"Logged in";
 | 
		
	
		
			
			|  | 79 | +	nextSearch();
 | 
		
	
		
			
			|  | 80 | +}
 | 
		
	
		
			
			|  | 81 | +
 | 
		
	
		
			
			|  | 82 | +void MainClass::intraSearchFinished(QList<QList<QString> > users)
 | 
		
	
		
			
			|  | 83 | +{
 | 
		
	
		
			
			|  | 84 | +	if(!users.isEmpty())
 | 
		
	
		
			
			|  | 85 | +	{
 | 
		
	
		
			
			|  | 86 | +		users.removeFirst();
 | 
		
	
		
			
			|  | 87 | +
 | 
		
	
		
			
			|  | 88 | +		if(users.size() > 0)
 | 
		
	
		
			
			|  | 89 | +			std::cout<<users.at(0).at(2).toStdString().c_str()<<"."<<users.at(0).at(1).toStdString().c_str()<<"@epita.fr"<<std::endl;
 | 
		
	
		
			
			|  | 90 | +	}
 | 
		
	
		
			
			|  | 91 | +	else
 | 
		
	
		
			
			|  | 92 | +		qDebug()<<"Users empty";
 | 
		
	
		
			
			|  | 93 | +	nextSearch();
 | 
		
	
		
			
			|  | 94 | +}
 | 
		
	
		
			
			|  | 95 | +
 | 
		
	
		
			
			|  | 96 | +void MainClass::nextSearch()
 | 
		
	
		
			
			|  | 97 | +{
 | 
		
	
		
			
			|  | 98 | +	if(m_logins.isEmpty())
 | 
		
	
		
			
			|  | 99 | +	{
 | 
		
	
		
			
			|  | 100 | +		qApp->exit();
 | 
		
	
		
			
			|  | 101 | +		return;
 | 
		
	
		
			
			|  | 102 | +	}
 | 
		
	
		
			
			|  | 103 | +	m_intra->searchUser("", "", m_logins.at(0));
 | 
		
	
		
			
			|  | 104 | +	m_logins.removeFirst();
 | 
		
	
		
			
			|  | 105 | +}
 |