#include "autofillmodel.h" #include "qupzilla.h" #include "webview.h" #include "mainapplication.h" #include "autofillnotification.h" AutoFillModel::AutoFillModel(QupZilla* mainClass, QObject *parent) : QObject(parent) ,p_QupZilla(mainClass) ,m_isStoring(false) { QTimer::singleShot(0, this, SLOT(loadSettings())); } void AutoFillModel::loadSettings() { QSettings settings(MainApplication::getInstance()->getActiveProfil()+"settings.ini", QSettings::IniFormat); settings.beginGroup("Web-Browser-Settings"); m_isStoring = settings.value("AutoFillForms",true).toBool(); settings.endGroup(); } bool AutoFillModel::isStored(const QUrl &url) { QString server = url.host(); QSqlQuery query; query.exec("SELECT count(id) FROM autofill WHERE server='"+server+"'"); query.next(); if (query.value(0).toInt()>0) return true; return false; } bool AutoFillModel::isStoringEnabled(const QUrl &url) { if (!m_isStoring) return false; QString server = url.host(); QSqlQuery query; query.exec("SELECT count(id) FROM autofill_exceptions WHERE server='"+server+"'"); query.next(); if (query.value(0).toInt()>0) return false; return true; } void AutoFillModel::blockStoringfor (const QUrl &url) { QString server = url.host(); QSqlQuery query; query.exec("INSERT INTO autofill_exceptions (server) VALUES ('"+server+"')"); } QString AutoFillModel::getUsername(const QUrl &url) { QString server = url.host(); QSqlQuery query; query.exec("SELECT username FROM autofill WHERE server='"+server+"'"); query.next(); return query.value(0).toString(); } QString AutoFillModel::getPassword(const QUrl &url) { QString server = url.host(); QSqlQuery query; query.exec("SELECT password FROM autofill WHERE server='"+server+"'"); query.next(); return query.value(0).toString(); } ///HTTP Authorization bool AutoFillModel::addEntry(const QUrl &url, const QString &name, const QString &pass) { QSqlQuery query; query.exec("SELECT username FROM autofill WHERE server='"+url.host()+"'"); if (query.next()) return false; query.prepare("INSERT INTO autofill (server, username, password) VALUES (?,?,?)"); query.bindValue(0, url.host()); query.bindValue(1, name); query.bindValue(2, pass); return query.exec(); } ///WEB Form bool AutoFillModel::addEntry(const QUrl &url, const QByteArray &data, const QString &pass) { QSqlQuery query; query.exec("SELECT data FROM autofill WHERE server='"+url.host()+"'"); if (query.next()) return false; query.prepare("INSERT INTO autofill (server, data, password) VALUES (?,?,?)"); query.bindValue(0, url.host()); query.bindValue(1, data); query.bindValue(2, pass); return query.exec(); } void AutoFillModel::completePage(WebView* view) { if (!isStored(view->url())) return; QWebFrame* frame = view->page()->mainFrame(); QWebElementCollection inputs = frame->findAllElements("input"); QSqlQuery query; query.exec("SELECT data FROM autofill WHERE server='"+view->url().host()+"'"); query.next(); QByteArray data = query.value(0).toByteArray(); if (data.isEmpty()) return; QList > arguments = QUrl::fromEncoded(QByteArray("http://bla.com/?"+data)).queryItems(); for (int i = 0; iwebSettings()->testAttribute(QWebSettings::PrivateBrowsingEnabled)) return; m_lastOutgoingData = outgoingData; QVariant v = request.attribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 100)); QWebPage* webPage = (QWebPage*)(v.value()); v = request.attribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 102)); WebView* webView = (WebView*)(v.value()); if (!webPage || !webView) return; v = request.attribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 101)); QWebPage::NavigationType type = (QWebPage::NavigationType)v.toInt(); if (type!=QWebPage::NavigationTypeFormSubmitted) return; QString passwordName=""; QWebFrame* frame = webPage->mainFrame(); QWebElementCollection inputs = frame->findAllElements("input"); for (int i = 0; i > arguments = QUrl::fromEncoded(QByteArray("http://bla.com/?"+outgoingData)).queryItems(); for (int i = 0; iaddNotification(aWidget); }