/** * Gets the calendar list from the ownCloud server * for the settings dialog */ void OwnCloudService::settingsGetCalendarList(SettingsDialog *dialog) { settingsDialog = dialog; QUrl url(serverUrl + calendarPath); QNetworkRequest r(url); addAuthHeader(&r); // build the request body QString body = "<d:propfind xmlns:d=\"DAV:\" " "xmlns:cs=\"http://sabredav.org/ns\" xmlns:c=\"urn:ietf:params:xml:ns:caldav\"> \ <d:prop> \ <d:resourcetype /> \ <d:displayname /> \ <cs:getctag /> \ <c:supported-calendar-component-set /> \ </d:prop> \ </d:propfind>"; QByteArray *dataToSend = new QByteArray(body.toLatin1()); r.setHeader(QNetworkRequest::ContentLengthHeader, dataToSend->size()); QBuffer *buffer = new QBuffer(dataToSend); QNetworkReply *reply = networkManager->sendCustomRequest(r, "PROPFIND", buffer); QObject::connect(reply, SIGNAL(sslErrors(QList<QSslError>)), reply, SLOT(ignoreSslErrors())); }
/** * Ignores ssl errors for a QNetworkReply if allowed */ void OwnCloudService::ignoreSslErrorsIfAllowed(QNetworkReply *reply) { QSettings settings; if (settings.value("networking/ignoreSSLErrors", true).toBool()) { QObject::connect(reply, SIGNAL(sslErrors(QList<QSslError>)), reply, SLOT(ignoreSslErrors())); } }
void SyncConnector::urlTested(QNetworkReply* reply) { ignoreSslErrors(reply); if (reply->error() == QNetworkReply::TimeoutError || reply->error() == QNetworkReply::ConnectionRefusedError) { shutdownINotifyProcess(); mpConnectionAvailabilityTimer->start(1000); } else { ConnectionState connectionInfo = api::APIHandlerFactory<QNetworkReply>().getConnectionVersionInfo(reply); int versionNumber = getCurrentVersion(connectionInfo.first); if (mAPIHandler == nullptr || mAPIHandler->version != versionNumber) { mAPIHandler = std::unique_ptr<api::APIHandlerBase>( api::APIHandlerFactory<QNetworkReply>().getAPIForVersion(versionNumber)); } mConnectionStateCallback(connectionInfo); mpConnectionAvailabilityTimer->stop(); mpConnectionHealthTimer->start(mConnectionHealthTime); checkAndSpawnINotifyProcess(false); } reply->deleteLater(); }
/** * @brief Restores a note on the server */ void OwnCloudService::restoreTrashedNoteOnServer(QString notesPath, QString fileName, int timestamp, MainWindow *mainWindow) { this->mainWindow = mainWindow; QUrl url(serverUrl + restoreTrashedNotePath); QString serverNotesPath = getServerNotesPath(notesPath); url.setUserName(userName); url.setPassword(password); QUrlQuery q; q.addQueryItem("format", format); q.addQueryItem("file_name", serverNotesPath + fileName); q.addQueryItem("timestamp", QString::number(timestamp)); url.setQuery(q); qDebug() << url; QNetworkRequest r(url); addAuthHeader(&r); QNetworkReply *reply = networkManager->get(r); QObject::connect(reply, SIGNAL(sslErrors(QList<QSslError>)), reply, SLOT(ignoreSslErrors())); }
//! [0] SslClient::SslClient(QObject *parent) : QObject(parent) , m_socket(0) , m_sslErrorControl(new SslErrorControl(this)) , m_hostName("www.blackberry.com") , m_port(443) , m_sessionActive(false) , m_cipher("<none>") { // User input to the SSL error dialog is forwarded to us via signals connect(m_sslErrorControl, SIGNAL(ignoreSslErrors()), this, SLOT(ignoreSslErrors())); connect(m_sslErrorControl, SIGNAL(viewCertificateChainRequested()), this, SIGNAL(viewCertificateChainRequested())); }
void DefaultConnection::onSocketSSLErrors(const QList<QSslError> &AErrors) { FSSLError = true; if (!FIgnoreSSLErrors) emit sslErrors(AErrors); else ignoreSslErrors(); }
/** Esta función entra a las diversas páginas, saca la info, calcula la diferencia entre los recursos y mensajes nuevos y antiguos. En varios pasos Si hay nuevo mensaje emite nuevoMensaje(int cantidad, QStringList ramos) Si hay nuevo recurso emite nuevoRecurso(int cantidad, QStringList ramos) */ void Widget::revisar(){ qDebug()<<"Pidiendo página inicial..."; QNetworkRequest req; req.setUrl(QUrl(URI_MAIN)); pagForm = manager->get(req); QObject::connect(pagForm, SIGNAL(sslErrors(QList<QSslError>)), pagForm, SLOT(ignoreSslErrors())); QObject::connect(pagForm, SIGNAL(finished()), SLOT(revisar2())); }
/* Start acknowledging: */ void UIDownloader::sltStartAcknowledging() { /* Setup HEAD request: */ QNetworkRequest request; request.setUrl(m_source); QNetworkReply *pReply = gNetworkManager->head(request); connect(pReply, SIGNAL(sslErrors(QList<QSslError>)), pReply, SLOT(ignoreSslErrors())); connect(pReply, SIGNAL(finished()), this, SLOT(sltFinishAcknowledging())); }
/** * @brief Gets the todo list from the ownCloud server for the todo list dialog */ void OwnCloudService::todoGetTodoList(QString calendarName, TodoDialog *dialog) { this->todoDialog = dialog; this->calendarName = calendarName; QSettings settings; QStringList todoCalendarEnabledList = settings.value( "ownCloud/todoCalendarEnabledList").toStringList(); int index = todoCalendarEnabledList.indexOf(calendarName); // return if we did't find the calendar, this should not happen if (index == -1) { return; } QStringList todoCalendarEnabledUrlList = settings.value( "ownCloud/todoCalendarEnabledUrlList").toStringList(); // return if there are to few items in the url list if (todoCalendarEnabledUrlList.size() < todoCalendarEnabledList.size()) { return; } QString calendarUrl = settings.value( "ownCloud/todoCalendarEnabledUrlList").toStringList().at(index); QUrl url(calendarUrl); QNetworkRequest r(url); addAuthHeader(&r); // ownCloud needs depth to be set to 1 r.setRawHeader(QByteArray("DEPTH"), QByteArray("1")); // build the request body, we only want VTODO items QString body = "<c:calendar-query xmlns:d=\"DAV:\" " "xmlns:c=\"urn:ietf:params:xml:ns:caldav\"> \ <d:prop> \ <d:getetag /> \ <d:getlastmodified /> \ </d:prop> \ <c:filter> \ <c:comp-filter name=\"VCALENDAR\"> \ <c:comp-filter name=\"VTODO\" /> \ </c:comp-filter> \ </c:filter> \ </c:calendar-query>"; QByteArray *dataToSend = new QByteArray(body.toLatin1()); r.setHeader(QNetworkRequest::ContentLengthHeader, dataToSend->size()); QBuffer *buffer = new QBuffer(dataToSend); QNetworkReply *reply = networkManager->sendCustomRequest(r, "REPORT", buffer); QObject::connect(reply, SIGNAL(sslErrors(QList<QSslError>)), reply, SLOT(ignoreSslErrors())); }
void CachedImage::_printErrors(const QList<QSslError>& errors) { foreach(auto e, errors) qDebug() << e.errorString(); auto reply = qobject_cast<QNetworkReply*>(sender()); Q_ASSERT(reply); if (reply) reply->ignoreSslErrors(); }
/* Start downloading: */ void UIDownloader::sltStartDownloading() { /* Setup GET request: */ QNetworkRequest request; request.setUrl(m_source); QNetworkReply *pReply = gNetworkManager->get(request); connect(pReply, SIGNAL(sslErrors(QList<QSslError>)), pReply, SLOT(ignoreSslErrors())); connect(pReply, SIGNAL(downloadProgress(qint64, qint64)), this, SIGNAL(sigDownloadProgress(qint64, qint64))); connect(pReply, SIGNAL(finished()), this, SLOT(sltFinishDownloading())); }
void SyncConnector::currentConfigReceived(QNetworkReply *reply) { ignoreSslErrors(reply); QByteArray replyData; if (reply->error() == QNetworkReply::NoError) { replyData = reply->readAll(); } mFolders = mAPIHandler->getCurrentFolderList(replyData); reply->deleteLater(); }
void Connection::onSslErrors(const QList<QSslError> &errors) { qWarning() << "ssl errors:" << errors; // Ignore self-signed cert errors. QList<QSslError> expectedErrors; foreach (QSslError error, errors) { if (error.error() == QSslError::SelfSignedCertificate) { expectedErrors.append(error); } } ignoreSslErrors(expectedErrors); }
/** * The constructor initializes the socket and the timeout timer and connects all the needed signals and slots. The constructor also calls ClientProtocolIODevice::prepareDevice() to prepare the socket for use. * @param parent Optional parent for the QObject */ ClientProtocolTcp::ClientProtocolTcp(QObject *parent) : ClientProtocolIODevice(parent) { QXT_INIT_PRIVATE(ClientProtocolTcp); qxt_d().timer.setInterval(10000); connect(&qxt_d().timer, SIGNAL(timeout()), &qxt_d(), SLOT(ping())); #ifndef QT_NO_OPENSSL connect(&qxt_d().socket, SIGNAL(sslErrors(QList<QSslError>)), &qxt_d().socket, SLOT(ignoreSslErrors())); #endif connect(&qxt_d().socket, SIGNAL(disconnected()), &qxt_d().timer, SLOT(stop())); connect(&qxt_d().socket, SIGNAL(disconnected()), this, SIGNAL(disconnected())); qxt_d().lastPing = QDateTime::currentDateTime(); prepareDevice(&qxt_d().socket); }
/** * @brief Removes a todo list item from the ownCloud server */ void OwnCloudService::removeCalendarItem(CalendarItem calItem, TodoDialog *dialog) { this->todoDialog = dialog; this->calendarName = calendarName; QUrl url(calItem.getUrl()); QNetworkRequest r(url); addAuthHeader(&r); QNetworkReply *reply = networkManager->sendCustomRequest(r, "DELETE"); QObject::connect(reply, SIGNAL(sslErrors(QList<QSslError>)), reply, SLOT(ignoreSslErrors())); }
//Permet de renseigner le client avec qui le socket doit communiquer bool Socket::setDescriptor(int socketDescriptor) { if(this->state()==QAbstractSocket::ConnectedState) return false; if(!this->setSocketDescriptor(socketDescriptor)) return false; //On récupère la clé privée du serveur QFile file(PRIVATEKEY_FILE); if(!file.open(QIODevice::ReadOnly)) { qDebug("La clé privée du serveur est introuvable."); return false; } QSslKey key(&file, QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey, "pass"); if (key.isNull()) { qDebug("La clé privée du serveur est nulle"); return false; } file.close(); setPrivateKey(key); //on charge le certificat du client setLocalCertificate( LOCALCERTIFICATE_FILE ); //on charge le certificat de notre ca if(!addCaCertificates(CACERTIFICATES_FILE)) { qDebug("Impossible de charger le certificat du CA."); return false; } //on supprime la vérification des certificats des clients //seuls ces derniers vérifient les clés et certificat du serveur setPeerVerifyMode(QSslSocket::VerifyNone); //on ignore les erreurs car on a un certificat auto signé ignoreSslErrors(); //on se connecte au serveur startServerEncryption(); //On attends au plus 30secondes pour que la connexion s'établisse bool result = waitForConnected(); if(!result) return result; result=waitForEncrypted(); return result; }
void SyncConnector::connectionHealthReceived(QNetworkReply* reply) { ignoreSslErrors(reply); QByteArray replyData; if (reply->error() == QNetworkReply::NoError) { replyData = reply->readAll(); } auto result = mAPIHandler->getConnections(replyData); auto traffic = mAPIHandler->getCurrentTraffic(replyData); emit(onNetworkActivityChanged(std::get<0>(traffic) + std::get<1>(traffic) > kNetworkNoiseFloor)); emit(onConnectionHealthChanged({result, traffic})); reply->deleteLater(); }
/** slot que se activa al terminar la carga de la página */ void Widget::revisar2(){ qDebug()<<"Procesando página inicial..."; QString paginaCompleta(pagForm->readAll()); pagForm->deleteLater(); QRegExp re; re.setPattern("usuario=(.+)&id=(.+)\" scroll"); re.indexIn(paginaCompleta); sesionUser = re.cap(1); sesionId = re.cap(2); qDebug()<<"Se ha terminado de procesar la página inicial. Usuario:"<<sesionUser<<" ID:"<<sesionId; QNetworkRequest req; req.setUrl(QUrl(QString(URI_LISTA_CURSOS).arg(sesionId).arg(sesionUser))); pagForm = manager->get(req); QObject::connect(pagForm, SIGNAL(sslErrors(QList<QSslError>)), pagForm, SLOT(ignoreSslErrors())); QObject::connect(pagForm, SIGNAL(finished()), SLOT(revisar3())); }
/** Realiza un GET a la página inicial (para obtener cookie) - YA NO. Realiza un POST al formulario de inicio de sesión. Conecta un par de funciones para pasar al siguiente paso */ void Widget::iniciarSesion(){ qDebug()<<"Iniciando sesion..."; QNetworkRequest req; QByteArray datos; // req.setUrl(QUrl(URIPORTADA)); // // da = que se pierda. Es para recuperar la cookie // pagPortada = manager->get(req); // QObject::connect(pagPortada, SIGNAL(finished()), SLOT(sesion1())); req.setUrl(QUrl(URI_FORM)); req.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); datos.append(QString("time=%1&rut=%2&clave=%3").arg(QDateTime::currentMSecsSinceEpoch()).arg(user).arg(pass)); pagForm = manager->post(req, datos); QObject::connect(pagForm, SIGNAL(sslErrors(QList<QSslError>)), pagForm, SLOT(ignoreSslErrors())); QObject::connect(pagForm, SIGNAL(finished()), SLOT(sesion2())); }
/** * @brief OwnCloudService::loadVersions */ void OwnCloudService::loadVersions(QString notesPath, QString fileName, MainWindow *mainWindow) { this->mainWindow = mainWindow; QUrl url(serverUrl + versionListPath); QString serverNotesPath = getServerNotesPath(notesPath); url.setUserName(userName); url.setPassword(password); QUrlQuery q; q.addQueryItem("format", format); q.addQueryItem("file_name", serverNotesPath + fileName); url.setQuery(q); QNetworkRequest r(url); addAuthHeader(&r); QNetworkReply *reply = networkManager->get(r); QObject::connect(reply, SIGNAL(sslErrors(QList<QSslError>)), reply, SLOT(ignoreSslErrors())); }
void OwnCloudService::postCalendarItemToServer(CalendarItem calendarItem, TodoDialog *dialog) { this->todoDialog = dialog; calendarItem.generateNewICSData(); QUrl url(calendarItem.getUrl()); QNetworkRequest r; addAuthHeader(&r); r.setUrl(url); // build the request body QString body = calendarItem.getICSData(); QByteArray *dataToSend = new QByteArray(body.toLatin1()); r.setHeader(QNetworkRequest::ContentLengthHeader, dataToSend->size()); QBuffer *buffer = new QBuffer(dataToSend); QNetworkReply *reply = networkManager->sendCustomRequest(r, "PUT", buffer); QObject::connect(reply, SIGNAL(sslErrors(QList<QSslError>)), reply, SLOT(ignoreSslErrors())); }
/** * @brief Loads and updates the icsData of a calendar item with data from the calendar server * @return */ bool OwnCloudService::updateICSDataOfCalendarItem(CalendarItem *calItem) { QNetworkAccessManager *manager = new QNetworkAccessManager(this); QUrl url(calItem->getUrl()); QNetworkRequest r; addAuthHeader(&r); r.setUrl(url); QEventLoop loop; QTimer timer; timer.setSingleShot(true); connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit())); connect(manager, SIGNAL(finished(QNetworkReply * )), &loop, SLOT(quit())); // 5 sec timeout for the request timer.start(5000); QNetworkReply *reply = manager->get(r); QObject::connect(reply, SIGNAL(sslErrors(QList<QSslError>)), reply, SLOT(ignoreSslErrors())); loop.exec(); if (timer.isActive()) { // get the text from the network reply QString icsData = reply->readAll(); // set the new ics data calItem->setICSData(icsData); return true; } // timer elapsed, no reply from network request return false; }
void OwnCloudClient::auth() { m_username = SettingsManager::instance()->getUserName(); m_password = SettingsManager::instance()->getUserPassword(); QUrl url(SettingsManager::instance()->getOwnCloudHost()); url.setPort(SettingsManager::instance()->getOwnCloudPort().toInt()); QString path = SettingsManager::instance()->getOwnCloudPath() + SettingsManager::instance()->getApiMusicCollection(); url.setPath(path); url.setUserName(SettingsManager::instance()->getUserName()); url.setPassword(SettingsManager::instance()->getUserPassword()); qDebug() << url; QNetworkRequest request(url); addAuthHeader(&request); QNetworkReply* reply = m_networkManager.get(request); connect(reply, SIGNAL(sslErrors(QList<QSslError>)), reply, SLOT(ignoreSslErrors())); }
void OwnCloudService::loadTodoItems(QString &data) { QDomDocument doc; doc.setContent(data, true); // fetch all urls that are currently in the calendar QList<QUrl> calendarItemUrlRemoveList = CalendarItem::fetchAllUrlsByCalendar(calendarName); QDomNodeList responseNodes = doc.elementsByTagNameNS(NS_DAV, "response"); int responseNodesCount = responseNodes.length(); int requestCount = 0; // set the preliminary maximum of the progress bar this->todoDialog->todoItemLoadingProgressBarSetMaximum(responseNodesCount); // loop all response blocks for (int i = 0; i < responseNodesCount; ++i) { QDomNode responseNode = responseNodes.at(i); if (responseNode.isElement()) { QDomElement elem = responseNode.toElement(); // check if we have an url QDomNodeList urlPartNodes = elem.elementsByTagNameNS(NS_DAV, "href"); if (urlPartNodes.length()) { QString urlPart = urlPartNodes.at(0).toElement().text(); if (urlPart == "") { continue; } QUrl calendarItemUrl = QUrl(serverUrlWithoutPath + urlPart); // check if we have an etag QDomNodeList etagNodes = elem.elementsByTagNameNS(NS_DAV, "getetag"); if (etagNodes.length()) { QString etag = etagNodes.at(0).toElement().text(); etag.replace("\"", ""); qDebug() << __func__ << " - 'etag': " << etag; // check if we have a last modified date QDomNodeList lastModifiedNodes = elem.elementsByTagNameNS( NS_DAV, "getlastmodified"); if (lastModifiedNodes.length()) { const QString lastModified = lastModifiedNodes.at( 0).toElement().text(); bool fetchItem = false; // try to fetch the calendar item by url CalendarItem calItem = CalendarItem::fetchByUrl( calendarItemUrl); if (calItem.isFetched()) { // check if calendar item was modified if (calItem.getETag() != etag) { // store etag and last modified date calItem.setETag(etag); calItem.setLastModifiedString(lastModified); calItem.store(); // we want to update the item from server fetchItem = true; } } else { // calendar item was not found // create calendar item for fetching CalendarItem::addCalendarItemForRequest( calendarName, calendarItemUrl, etag, lastModified); fetchItem = true; } // remove the url from the list of calendar item urls // to remove if (calendarItemUrlRemoveList.contains( calendarItemUrl)) { calendarItemUrlRemoveList.removeAll( calendarItemUrl); } // fetch the calendar item if (fetchItem) { QNetworkRequest r(calendarItemUrl); addAuthHeader(&r); QNetworkReply *reply = networkManager->get(r); QObject::connect(reply, SIGNAL(sslErrors( QList<QSslError>)), reply, SLOT(ignoreSslErrors())); requestCount++; } } } } } } // set the real maximum of the progress bar this->todoDialog->todoItemLoadingProgressBarSetMaximum(requestCount); // hide progress bar if there were no updates if (requestCount == 0) { this->todoDialog->todoItemLoadingProgressBarHide(); } // remove all not found items for (int i = 0; i < calendarItemUrlRemoveList.length(); ++i) { QUrl url = calendarItemUrlRemoveList.at(i); CalendarItem calItem = CalendarItem::fetchByUrl(url); if (calItem.isFetched()) { calItem.remove(); } } // reload the existing items this->todoDialog->reloadTodoListItems(); qDebug() << CalendarItem::fetchAllByCalendar(calendarName); }
/** * @brief OwnCloudService::connectionTest */ void OwnCloudService::settingsConnectionTest(SettingsDialog *dialog) { settingsDialog = dialog; // qDebug() << serverUrl; // qDebug() << userName; // qDebug() << password; QSettings settings; QString notesPath = settings.value("notesPath").toString(); QUrl url(serverUrl); QNetworkRequest r(url); // direct server url request without auth header QNetworkReply *reply = networkManager->get(r); QObject::connect(reply, SIGNAL(sslErrors(QList<QSslError>)), reply, SLOT(ignoreSslErrors())); QUrlQuery q; q.addQueryItem("format", format); url.setQuery(q); addAuthHeader(&r); url.setUrl(serverUrl + capabilitiesPath); r.setUrl(url); reply = networkManager->get(r); url.setUrl(serverUrl + ownCloudTestPath); r.setUrl(url); reply = networkManager->get(r); url.setUrl(serverUrl + appInfoPath); QString serverNotesPath = getServerNotesPath(notesPath); q.addQueryItem("notes_path", serverNotesPath); url.setQuery(q); r.setUrl(url); reply = networkManager->get(r); QString localOwnCloudPath = settings.value( "ownCloud/localOwnCloudPath").toString(); if (localOwnCloudPath != "") { QDir d = QDir(localOwnCloudPath); if (d.exists()) { if (notesPath.startsWith(localOwnCloudPath)) { if (notesPath != localOwnCloudPath) { settingsDialog->setOKLabelData(5, "ok", SettingsDialog::OK); } else { settingsDialog->setOKLabelData( 5, QString("note path and ownCloud path are equal") .arg(notesPath), SettingsDialog::Warning); } } else { settingsDialog->setOKLabelData(5, QString("note path\n(%1)\nnot in ownCloud path").arg( notesPath).arg( localOwnCloudPath), SettingsDialog::Failure); } } else { settingsDialog->setOKLabelData(5, "does not exist", SettingsDialog::Failure); } } else { settingsDialog->setOKLabelData(5, "empty", SettingsDialog::Failure); } }