void TorManager::reportTorCheckResults(int page) { QString statusbar; QNetworkProxy proxy = BrowserApplication::instance()->networkAccessManager()->currentProxy(); QFile file(QLatin1String(":/torcheck.html")); if (!file.open(QIODevice::ReadOnly)) { qWarning() << "WebPage::handleUnsupportedContent" << "Unable to open torcheck.html"; return; } QString tororaIssues; QString issuesfile; #if defined(TORORA) issuesfile = QLatin1String(":/TORORA_ISSUES"); #else issuesfile = QLatin1String(":/ARORA_ISSUES"); #endif QFile issues(issuesfile); QString title, headline, bulletone, bullettwo, bulletthree, bulletfour, img; switch (page) { case TOR_CHECK: if (m_checkTorSilently) return; title = tr("Checking Tor.."); headline = tr("Checking Tor.."); bulletone = tr("Torora is checking https://check.torproject.org."); bullettwo = tr("Once Torora is sure you can browse anonymously, browsing will be enabled."); bulletthree = tr("This check may take a few seconds, so please be patient."); img = QLatin1String(":graphics/tor-checking.png"); statusbar = QLatin1String("Checking Tor..."); break; case USING_TOR: /*FIXME: Pseudorandom intervals may not be enough to prevent an attacker guessing who is testing */ #define TOR_CHECK_PERIOD (60 * 1000 * ((qrand() % 10) + 1)) m_timer->start(TOR_CHECK_PERIOD); // qDebug() << "TOR_CHECK_PERIOD " << TOR_CHECK_PERIOD << endl; if (m_checkTorSilently) return; if (!issues.open(QIODevice::ReadOnly)) { qWarning() << "WebPage::handleUnsupportedContent" << "Unable to open " << issuesfile; return; } tororaIssues = QString(QLatin1String(issues.readAll())); title = tr("Torora Ready For Use.."); headline = tr("Tor is Working Properly. You Can Browse Anonymously."); bulletone = tr("You can confirm this yourself by visiting <a href='https://check.torproject.org'>https://check.torproject.org</a>"); bullettwo = tr("The bookmark toolbar contains some well known hidden services you can check out."); bulletthree = tr("You can check Tor at any time by pressing F12 or clicking <b>Tools->Check Tor.</b>"); img = QLatin1String(":graphics/tor-on.png"); statusbar = QLatin1String("Tor Check Successful"); break; default: setBrowsingEnabled(false); /* Stop the periodic tor checks until we're back up */ m_timer->stop(); title = tr("Check Your Tor Installation"); if (!m_torIsRunning) { headline = tr("Tor Is Not Running On Your Computer!"); bulletone = tr("Check that you have installed Tor."); bullettwo = tr("Check that you have started Tor."); } else if (page == NOT_USING_TOR) { headline = tr("Torora May Be By-Passing Tor!"); bulletone = tr("Testing at https://check.torproject.org indicated that you are not using Tor."); bullettwo = tr("Your set-up seems OK, Tor is running and seem to be correctly configured."); bulletfour = tr("<li>Click 'Change Identity' in Vidalia or TorK and try again. The exit node used for the test may not be listed with the checking service yet.</li>"); } else { headline = tr("The Tor Check Website May Be Down!"); bulletone = tr("Check that https://check.torproject.org is available using another browser."); bullettwo = tr("There may be a temporary issue with the website."); bulletfour = tr("<li>Click 'Change Identity' in Vidalia or TorK and try again. The exit node used for the test may not be listed with the checking service yet.</li>"); } bulletthree = tr("Press F12 or <b>Tools->Check Tor</b> to test Tor again."); img = QLatin1String(":graphics/tor-off.png"); statusbar = QLatin1String("Tor Check Failed"); tororaIssues = QString(QLatin1String("<table align='center'><tr><td></td> <td>" "<object type=\"application/x-qt-plugin\" classid=\"QPushButton\" " "name=\"TryAgainButton\" height=25 width=110></object>\n" "<script>\n" "document.TryAgainButton.text = 'Try Again';\n" "</script>\n" "</td> <td></td></tr></table>\n")); /* Create a new circuit for the next test, just in case we used an exit that isn't listed yet */ if (torcontrol) torcontrol->newIdentity(); setBrowsingEnabled(false); break; } QString html = QString(QLatin1String(file.readAll())) .arg(title) .arg(QString()) .arg(headline) .arg(bulletone) .arg(bullettwo) .arg(bulletthree) .arg(bulletfour) .arg(tororaIssues); QBuffer imageBuffer; imageBuffer.open(QBuffer::ReadWrite); QIcon icon = QIcon(img); QPixmap pixmap = icon.pixmap(QSize(32, 32)); if (pixmap.save(&imageBuffer, "PNG")) { html.replace(QLatin1String("IMAGE_BINARY_DATA_HERE"), QString(QLatin1String(imageBuffer.buffer().toBase64()))); } if (page == USING_TOR) { imageBuffer.open(QBuffer::ReadWrite); icon = QIcon(QLatin1String(":graphics/info.png")); pixmap = icon.pixmap(QSize(32, 32)); if (pixmap.save(&imageBuffer, "PNG")) { html.replace(QLatin1String("INFO_IMAGE_HERE"), QString(QLatin1String(imageBuffer.buffer().toBase64()))); } imageBuffer.open(QBuffer::ReadWrite); icon = QIcon(QLatin1String(":graphics/important.png")); pixmap = icon.pixmap(QSize(32, 32)); if (pixmap.save(&imageBuffer, "PNG")) { html.replace(QLatin1String("WARNING_IMAGE_HERE"), QString(QLatin1String(imageBuffer.buffer().toBase64()))); } imageBuffer.open(QBuffer::ReadWrite); icon = QIcon(QLatin1String(":graphics/help.png")); pixmap = icon.pixmap(QSize(32, 32)); if (pixmap.save(&imageBuffer, "PNG")) { html.replace(QLatin1String("QUESTION_IMAGE_HERE"), QString(QLatin1String(imageBuffer.buffer().toBase64()))); } } BrowserApplication::instance()->mainWindow()->currentTab()->page()->mainFrame()->setHtml(html, QUrl()); if (!m_checkTorSilently && page == USING_TOR) connectToTor(); if (!m_checkTorSilently) { m_statusbar=statusbar; QTimer::singleShot(1000, this, SLOT(displayStatusResult())); if (page != TOR_CHECK) BrowserApplication::instance()->mainWindow()->setStatusBarMessagesEnabled(true); } }
static void s_TrapErrors(const CJsonNode& request, const CJsonNode& reply, CSocket& sock, SNetStorage::SConfig::EErrMode err_mode) { const string server_address(sock.GetPeerAddress()); CJsonNode issues(reply.GetByKeyOrNull("Warnings")); if (issues) { for (CJsonIterator it = issues.Iterate(); it; ++it) { const SIssue issue(*it); LOG_POST(Warning << "NetStorage server " << server_address << " issued warning " << issue); } } const string status = reply.GetString("Status"); const bool status_ok = status == "OK"; issues = reply.GetByKeyOrNull("Errors"); // Got errors if (!status_ok || issues) { if (status_ok && err_mode != SNetStorage::SConfig::eThrow) { if (err_mode == SNetStorage::SConfig::eLog) { for (CJsonIterator it = issues.Iterate(); it; ++it) { const SIssue issue(*it); LOG_POST(Error << "NetStorage server " << server_address << " issued error " << issue); } } } else { Int8 code = CNetStorageServerError::eUnknownError; Int8 sub_code = SIssue::kEmptySubCode; ostringstream errors; if (!issues) errors << status; else { const char* prefix = "error "; for (CJsonIterator it = issues.Iterate(); it; ++it) { const SIssue issue(*it); code = issue.code; sub_code = issue.sub_code; errors << prefix << issue; prefix = ", error "; } } string err_msg = FORMAT("Error while executing " << request.GetString("Type") << " " "on NetStorage server " << sock.GetPeerAddress() << ". " "Server returned " << errors.str()); s_ThrowError(code, sub_code, err_msg); } } if (reply.GetInteger("RE") != request.GetInteger("SN")) { NCBI_THROW_FMT(CNetStorageException, eServerError, "Message serial number mismatch " "(NetStorage server: " << sock.GetPeerAddress() << "; " "request: " << request.Repr() << "; " "reply: " << reply.Repr() << ")."); } }