Exemplo n.º 1
0
	void AuthManager::handleRequestAuthTokenFinished ()
	{
		QNetworkReply *reply = qobject_cast<QNetworkReply*> (sender ());
		if (!reply)
			return;

		Account *acc = Reply2Account_.take (reply);
		reply->deleteLater ();

		const auto& res = Util::ParseJson (reply, Q_FUNC_INFO);
		if (res.isNull ())
			return;

		const auto& map = res.toMap ();

		if (map.contains ("error"))
			return;

		if (map.contains ("access_token"))
			acc->SetAccessToken (map ["access_token"].toString ());
		if (map.contains ("uid"))
			acc->SetUserID (map ["uid"].toString ());
		acc->SetTrusted (true);

		emit authSuccess (acc);
	}
Exemplo n.º 2
0
	void AuthManager::handleRequestAuthTokenFinished ()
	{
		QNetworkReply *reply = qobject_cast<QNetworkReply*> (sender ());
		if (!reply)
			return;

		PicasaAccount *acc = Reply2Account_.take (reply);
		reply->deleteLater ();

		QByteArray data = reply->readAll ();

		bool ok = false;
		QVariant res = QJson::Parser ().parse (data, &ok);
		if (!ok)
			return;

		QVariantMap map = res.toMap ();

		if (map.contains ("error"))
		{
			qWarning () << Q_FUNC_INFO
					<< "there is error in answer"
					<< map;
			return;
		}

		if (map.contains ("refresh_token"))
			acc->SetRefreshToken (map ["refresh_token"].toString ());

		emit authSuccess (acc);
	}
Exemplo n.º 3
0
	void AuthManager::handleRequestAuthTokenFinished ()
	{
		QNetworkReply *reply = qobject_cast<QNetworkReply*> (sender ());
		if (!reply)
			return;

		Account *acc = Reply2Account_.take (reply);
		reply->deleteLater ();

		QByteArray data = reply->readAll ();

		bool ok = false;
		QVariant res = QJson::Parser ().parse (data, &ok);
		if (!ok)
			return;

		QVariantMap map = res.toMap ();

		if (map.contains ("error"))
			return;

		if (map.contains ("access_token"))
			acc->SetAccessToken (map ["access_token"].toString ());
		if (map.contains ("refresh_token"))
			acc->SetRefreshToken (map ["refresh_token"].toString ());
		acc->SetTrusted (true);

		emit authSuccess (acc);
	}
Exemplo n.º 4
0
void MainWindow::login()
{
    oauth = new OAuthN();
    oauth->setGeometry(100,0,500,400);
    //oauth->setParent(this);
    connect(oauth, SIGNAL(authSuccess(QString,QString)),this, SLOT(getToken(QString, QString)));
    connect(this,SIGNAL(haveToken()),this, SLOT(loginSuccess())); // FIXME : Change getGroups slot - to Login Succesfull slot acessuble from qml
    oauth->show();
}
void VkLoginDialog::getTokenFromUrl(const QUrl &url)
{
    QUrlQuery query(QUrl(QString(url.toString()).replace("#", "?")));

    if (query.hasQueryItem("error"))
    {
        emit authFail(query.queryItemValue("error"), query.queryItemValue("error_description"));
        this->done(QDialog::Rejected);

        return;
    }

    if (query.hasQueryItem("access_token"))
    {
        //qDebug() << query.toString();
        emit authSuccess(query.queryItemValue("access_token"), query.queryItemValue("expires_in").toInt(),
                query.queryItemValue("user_id").toInt());
        this->done(QDialog::Accepted);
        return;
    }
}
Exemplo n.º 6
0
void ConnectorOld::stringParser(QByteArray recv)
{
  QString recvStr = codec->toUnicode(recv);
  QChar category = recvStr[0];                        // First symbol of string
  QStringList message = recvStr.mid(1).split("\t");   // Remove first symbol & splitting
  QString cmd;
  switch (category.toAscii())
  {
  case 'R':       // Authentification request
    qDebug() << "CONN :: Auth_req:" << message;
    emit authRequestRecv(message.at(0));
    break;
  case 'b':       // Information
    qDebug() << "CONN :: Inform:" << message;
    emit infoMessage(message.at(0));
    // Verify for success auth string
    if (message.at(0).split(" ").count() == 7)
      if (message.at(0).split(" ").at(2).at(8) == ',')
        emit authSuccess();
    break;
  case 'd':       // Board
    cmd = message.at(0);
    if (cmd == "channels")  // Receved channel list
    {
      qDebug() << "CONN :: Board: channels recv";
      message.pop_front();    // Remove command from message
      emit boardChannelsRecv(parseBoardChannels(message.join("\t")));
    }
    else
    {
      if (cmd == "new")  // New messages
      {
        qDebug() << "CONN :: Board: new messages avaible";
        emit boardNewMessages();
      }
      else
      {
        if (cmd == "skins")
        {
          qDebug() << "CONN :: Board: \"skins\" cmd recv";
        }
        else
        {
          if (cmd == "admin")
          {
            qDebug() << "CONN :: Board: \"admin\" cmd recv";
          }
          else
          {
            qDebug() << "CONN :: Board: messages recv";
            emit boardMessagesRecv(parseBoardMessages(message.join("\t")));
          }
        }
      }
    }
//    qDebug() << "DBoard :: " << message;
    break;
  case 'c':       // Chat
    cmd = message.at(0);
    message.pop_front();    // Remove command from message
    if (cmd == "main")
    {
      qDebug() << "CONN :: Chat: channel message recv";
      emit chatPublicMessage(message.at(0),
                             getUserIdByName(message.at(0), message.at(2)),
                             message.at(3));
    }
    else
    {
      if (cmd == "enter")
      {
        QString channelId = message.at(0);
        if (QHostAddress().setAddress(channelId))
        {
          qDebug() << "CONN :: Host entered"
                   << message.at(2) << "@" << channelId;
        }
        else
        {
          qDebug() << "CONN :: Chat: new user entered" << message.at(3);
          emit chatUserEnter(channelId, parseEnteredUser(message));
        }
      }
      else
      {
        if (cmd == "leave")
        {
          QString channelId = message.at(0);
          if (QHostAddress().setAddress(channelId))
          {
            qDebug() << "CONN :: Host leave"
                     << message.at(2) << "@" << channelId;
          }
          else
          {
            shared_ptr<ChatChannel> ch =
                getChatInstance()->getChannel(channelId);
            bool online; // Verify for user connect state
            ch->getUser(message.at(2), &online);
            if (online)
            {
              qDebug() << "CONN :: Chat: user leave" << message.at(3);
              emit chatUserLeave(channelId, message.at(2));
            }
          }
        }
        else
        {
          if (cmd == "private")
          {
            qDebug() << "CONN :: Chat: new private message";
            emit chatPrivateMessage(parseChatPrivate(message));
          }
          else
          {
            if (cmd == "infoGet")
            {
              qDebug() << "CONN :: Chat: \"infoGet\" cmd recv";
            }
            else
            {
              if (cmd == "channels")
              {
                qDebug() << "CONN :: Chat: channels recv";
                emit chatChannelsRecv(parseChatChannels(message.join("\t")));
              }
              else
              {
                if (cmd == "userlist")
                {
                  qDebug() << "CONN :: Chat: userlist recv";
                  emit chatUsersRecv(message.at(0), parseChatUsers(message));
                }
                else
                {
                  if (cmd == "privateresived")
                  {
                    emit chatPrivateDelivered(
                          message.at(0), message.at(1), message.at(2));
                  }
                  else
                    qDebug() << "CONN ::" << cmd << message;
                }
              }
            }
          }
        }
      }
    }
//    qDebug() << "Chat   :: " << message;
    break;
  default:       // Uncategorised
    qDebug() << "Unctg  :: " << recvStr;
  }
}
Exemplo n.º 7
0
FenPrincipale::FenPrincipale(QWidget *parent) :
    QMainWindow(parent), ui(new Ui::FenPrincipale), m_fenOptions(NULL), m_trayWarningShown(false), m_auth(new Auth(this)), m_handler(new DownloadHandler(this)),
    m_infoExtractor(new InfoExtractor(this)), m_vitesseTransfert(new VitesseTransfert(this, DOWNLOAD_SPEED_UPDATE_INTERVAL, DOWNLOAD_SPEED_AVERAGE_TIME)),
    m_versionCheck(new VersionCheckThread(this, VERSION_HOST, APP_NAME, VERSION, VERSION_NBR)), m_currentDownload(), m_waitTimer(new QTimer(this)),
    m_updateDownloadTimer(new QTimer(this)), m_waitTime(0), m_isDownloading(false)
{
    ui->setupUi(this);
    setWindowTitle(APP_NAME " - v" VERSION);

    //Icône système
    m_menu = new QMenu(this);
    m_retablirAction = new QAction("Rétablir", m_menu);
    m_startAction = new QAction("Télécharger", m_menu);
    m_stopAction = new QAction("Arrêter", m_menu);
    m_quitterAction = new QAction("Quitter", m_menu);
    m_tray = new QSystemTrayIcon(windowIcon(), this);

    m_menu->addAction(m_retablirAction);
    m_menu->addAction(m_startAction);
    m_menu->addAction(m_stopAction);
    m_menu->addAction(m_quitterAction);
    m_retablirAction->setVisible(false);
    m_stopAction->setVisible(false);
    m_tray->setContextMenu(m_menu);
    m_tray->show();

    qApp->setActiveWindow(this);
    loadSettings();

    //UI
    connect(ui->adresse, SIGNAL(returnPressed()), this, SLOT(on_btn_ajouter_clicked()));
    connect(m_waitTimer, SIGNAL(timeout()), this, SLOT(waitTimerTick()));
    connect(m_infoExtractor, SIGNAL(infoAvailable(QString,QString,QString,QString)), this, SLOT(infoAvailable(QString,QString,QString,QString)));
    connect(m_infoExtractor, SIGNAL(infoUnavailable(QString,ExtractionError)), this, SLOT(infoUnavailable(QString,ExtractionError)));
    connect(m_updateDownloadTimer, SIGNAL(timeout()), this, SLOT(updateDownloadTick()));
    connect(m_versionCheck, SIGNAL(update(QString, QString)), this, SLOT(updateAvailable(QString, QString)));
    connect(m_tray, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(trayClicked(QSystemTrayIcon::ActivationReason)));
    connect(m_retablirAction, SIGNAL(triggered()), this, SLOT(retablir()));
    connect(m_startAction, SIGNAL(triggered()), this, SLOT(on_btn_go_clicked()));
    connect(m_stopAction, SIGNAL(triggered()), this, SLOT(on_btn_arreter_clicked()));
    connect(m_quitterAction, SIGNAL(triggered()), qApp, SLOT(quit()));
    connect(QApplication::clipboard(), SIGNAL(changed(QClipboard::Mode)), this, SLOT(clipboardChange()));

    //Raccourcis
    connect(new QShortcut(QKeySequence("Ctrl+Q"), this), SIGNAL(activated()), qApp, SLOT(quit()));
    connect(new QShortcut(QKeySequence("Ctrl+D"), this), SIGNAL(activated()), ui->btn_details, SLOT(toggle()));
    connect(new QShortcut(QKeySequence("Ctrl+Up"), this), SIGNAL(activated()), this, SLOT(on_btn_monter_clicked()));
    connect(new QShortcut(QKeySequence("Ctrl+Shift+Up"), this), SIGNAL(activated()), this, SLOT(on_btn_monter_clicked()));
    connect(new QShortcut(QKeySequence("Ctrl+Down"), this), SIGNAL(activated()), this, SLOT(on_btn_descendre_clicked()));
    connect(new QShortcut(QKeySequence("Ctrl+Shift+Down"), this), SIGNAL(activated()), this, SLOT(on_btn_descendre_clicked()));
    connect(new QShortcut(QKeySequence("Del"), this), SIGNAL(activated()), this, SLOT(on_btn_supprimer_clicked()));

    //Téléchargement
    connect(m_auth, SIGNAL(authed(AuthInfo)), this, SLOT(authSuccess(AuthInfo)));
    connect(m_auth, SIGNAL(authError(AuthError)), this, SLOT(authFail(AuthError)));
    connect(m_handler, SIGNAL(error(DownloadError)), this, SLOT(error(DownloadError)));
    connect(m_handler, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(updateDownload(qint64, qint64)));
    connect(m_handler, SIGNAL(finished()), this, SLOT(downloadComplete()));
    connect(m_handler, SIGNAL(waitTime(int, QString)), this, SLOT(waitTimerStart(int, QString)));

    console("Authentification...");
    m_auth->login(m_login, m_password);
    m_updateDownloadTimer->setInterval(DOWNLOAD_SPEED_UPDATE_INTERVAL);
    m_versionCheck->start();
    m_waitTimer->setInterval(1000);
    clipboardChange();  //Initialise la zone d'adresse avec les adresses déjà présentes en mémoire.
    setDetailsVisible(ui->btn_details->isChecked());
    ui->btn_arreter->hide();
    ui->liste->setCurrentRow(0);

    sLog->out(APP_NAME " startup.");
}
bool FilezillaAdminConnection::parseAuthData()
{
    if(mDataRead.length() < 5)
    {
        emit connFail("Data length below 5");
        return false;
    }
    if((mDataRead[0] & 0x03) > 2)
    {
        emit connFail("Unknown command type");
        mSocket->abort();
        return false;
    }

    int len = *reinterpret_cast<const uint32_t*>(&mDataRead.data()[1]);
    if(len + 5 <= mDataRead.length())
    {
        int iCmdId = (mDataRead[0] & 0x7C) >> 2;
        int iType = mDataRead[0] & 0x03;
        if(iCmdId == 0 && iType == 0)
        {
            if(len < 4)
            {
                emit connFail("Invalid auth data");
                mSocket->abort();
                return false;
            }

            int nonceLen1 = mDataRead[5]*256+mDataRead[6];
            if((nonceLen1+2) > (len-2))
            {
                emit connFail("Invalid auth data 2");
                mSocket->abort();
                return false;
            }

            int nonceLen2 = mDataRead[5+2+nonceLen1]*256 + mDataRead[5+2+1+nonceLen1];
            if((nonceLen1+nonceLen2+4) > len)
            {
                emit connFail("Invalid auth data 3");
                mSocket->abort();
                return false;
            }

            MD5 md5;
            if(nonceLen1)
            {
                md5.update(reinterpret_cast<const unsigned char*>(&mDataRead.data()[7]), nonceLen1);
            }

            md5.update(reinterpret_cast<const unsigned char*>(mPassword.toUtf8().data()), mPassword.length());

            if(nonceLen2)
            {
                md5.update(reinterpret_cast<const unsigned char*>(&mDataRead.data()[5+4+nonceLen1]), nonceLen2);
            }

            md5.finalize();

            //removeParsedData(len-5);

            mDataRead.clear();


            char *digest = reinterpret_cast<char*>(md5.raw_digest());
            SendCommand(0, digest, 16);
            mConnState = NORMAL;
        }
        else if(iType == 1 && iCmdId == 0)
        {
            mDataRead.clear();
            SendCommand(2);
            mConnState = NORMAL;
        }
        else
        {
            emit connFail("Protocol error, unknown command ID " + QString().setNum(iCmdId));
            mSocket->abort();
            return false;
        }

        if(mConnState == NORMAL)
        {
            emit authSuccess();
        }

        return true;
    }