123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- #include "mainclass.h"
- #include <QApplication>
- #include <QFileInfo>
- #include <iostream>
-
- MainClass::MainClass(QObject* p) : QObject(p)
- {
- if(qApp->argc() < 2)
- {
- qDebug()<<"Usage:"<<QFileInfo(qApp->applicationFilePath()).fileName().toStdString().c_str()<< "loginsFile";
- qApp->exit(-1);
- }
-
- m_intra = new IntraBocal(this);
- connect(m_intra, SIGNAL(error(IntraBocal::Error)), this, SLOT(intraError(IntraBocal::Error)));
- connect(m_intra, SIGNAL(logged()), this, SLOT(intraLogged()));
- connect(m_intra, SIGNAL(searchFinished(QList<QList<QString> >)), this, SLOT(intraSearchFinished(QList<QList<QString> >)));
-
- m_users = Epimafia::loadUsers();
- for(int i = 0; i < m_users.size(); ++i)
- {
- EpiUser usr = m_users.at(i);
- if(!usr.hasLogin() || usr.isUnknown() || !usr.hasPwd_ppp())
- m_users.removeAt(i--);
- }
- if(m_users.isEmpty())
- {
- qDebug()<<"No Logins";
- qApp->exit(-1);
- }
- m_intra->login(m_users.at(0).getLogin(), m_users.at(0).getPwd_ppp());
-
- QFile logins(qApp->arguments().at(1));
- if(!logins.open(QIODevice::ReadOnly))
- {
- qDebug()<<"Unable to open "<<logins.fileName();
- qApp->exit(-1);
- }
- while(!logins.atEnd())
- {
- QString str = logins.readLine();
- str.replace("\n", "");
- str.replace("\r", "");
- if(!str.isEmpty())
- m_logins.append(str);
- }
- logins.close();
- }
-
- MainClass::~MainClass()
- {
- }
-
- void MainClass::intraError(IntraBocal::Error e)
- {
- if(e == IntraBocal::BadLogin)
- {
- if(!m_users.isEmpty())
- {
- m_users.removeFirst();
- m_intra->login(m_users.at(0).getLogin(), m_users.at(0).getPwd_ppp());
- return;
- }
- else
- qDebug()<<"No Logins with valid password";
- }
- else if(e == IntraBocal::NetworkError)
- qDebug()<<"Network Error";
- else if(e == IntraBocal::ParseError)
- qDebug()<<"Parse Error";
- else if(e == IntraBocal::SslError)
- qDebug()<<"Ssl Error";
- qApp->exit(-1);
- }
-
- void MainClass::intraLogged()
- {
- qDebug()<<"Logged in";
- nextSearch();
- }
-
- void MainClass::intraSearchFinished(QList<QList<QString> > users)
- {
- if(!users.isEmpty())
- {
- users.removeFirst();
-
- if(users.size() > 0)
- std::cout<<users.at(0).at(2).toStdString().c_str()<<"."<<users.at(0).at(1).toStdString().c_str()<<"@epita.fr"<<std::endl;
- }
- else
- qDebug()<<"Users empty";
- nextSearch();
- }
-
- void MainClass::nextSearch()
- {
- if(m_logins.isEmpty())
- {
- qApp->exit();
- return;
- }
- m_intra->searchUser("", "", m_logins.at(0));
- m_logins.removeFirst();
- }
|