mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	Give Subsurface a distinct User Agent string
When accessing websites (divelogs.de, subsurface website) we shouldn't pretend to be Mozilla 5. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
		
							parent
							
								
									ebdeddb9b9
								
							
						
					
					
						commit
						526ba82b53
					
				
					 5 changed files with 34 additions and 14 deletions
				
			
		|  | @ -1,6 +1,7 @@ | |||
| #include "subsurfacewebservices.h" | ||||
| #include "webservice.h" | ||||
| #include "mainwindow.h" | ||||
| #include "usersurvey.h" | ||||
| #include <libxml/parser.h> | ||||
| #include <zip.h> | ||||
| #include <errno.h> | ||||
|  | @ -219,6 +220,7 @@ WebServices::WebServices(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f | |||
| 	ui.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false); | ||||
| 	timeout.setSingleShot(true); | ||||
| 	defaultApplyText = ui.buttonBox->button(QDialogButtonBox::Apply)->text(); | ||||
| 	userAgent = UserSurvey::getVersion().replace("\n", " "); | ||||
| } | ||||
| 
 | ||||
| void WebServices::hidePassword() | ||||
|  | @ -397,6 +399,7 @@ void SubsurfaceWebServices::startDownload() | |||
| 	QNetworkRequest request; | ||||
| 	request.setUrl(url); | ||||
| 	request.setRawHeader("Accept", "text/xml"); | ||||
| 	request.setRawHeader("User-Agent", userAgent.toUtf8()); | ||||
| 	reply = manager()->get(request); | ||||
| 	ui.status->setText(tr("Connecting...")); | ||||
| 	ui.progressBar->setEnabled(true); | ||||
|  | @ -674,6 +677,7 @@ void DivelogsDeWebServices::startUpload() | |||
| 	QNetworkRequest request; | ||||
| 	request.setUrl(QUrl("https://divelogs.de/DivelogsDirectImport.php")); | ||||
| 	request.setRawHeader("Accept", "text/xml, application/xml"); | ||||
| 	request.setRawHeader("User-Agent", userAgent.toUtf8()); | ||||
| 
 | ||||
| 	QHttpPart part; | ||||
| 	part.setRawHeader("Content-Disposition", "form-data; name=\"user\""); | ||||
|  | @ -705,6 +709,7 @@ void DivelogsDeWebServices::startDownload() | |||
| 	QNetworkRequest request; | ||||
| 	request.setUrl(QUrl("https://divelogs.de/xml_available_dives.php")); | ||||
| 	request.setRawHeader("Accept", "text/xml, application/xml"); | ||||
| 	request.setRawHeader("User-Agent", userAgent.toUtf8()); | ||||
| 	request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); | ||||
| 
 | ||||
| #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) | ||||
|  | @ -749,6 +754,7 @@ void DivelogsDeWebServices::listDownloadFinished() | |||
| 	QNetworkRequest request; | ||||
| 	request.setUrl(QUrl("https://divelogs.de/DivelogsDirectExport.php")); | ||||
| 	request.setRawHeader("Accept", "application/zip, */*"); | ||||
| 	request.setRawHeader("User-Agent", userAgent.toUtf8()); | ||||
| 	request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); | ||||
| 
 | ||||
| #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) | ||||
|  | @ -923,6 +929,7 @@ QNetworkReply* UserSurveyServices::sendSurvey(QString values) | |||
| 	QNetworkRequest request; | ||||
| 	request.setUrl(QString("http://subsurface.hohndel.org/survey?%1").arg(values)); | ||||
| 	request.setRawHeader("Accept", "text/xml"); | ||||
| 	request.setRawHeader("User-Agent", userAgent.toUtf8()); | ||||
| 	reply = manager()->get(request); | ||||
| 	return reply; | ||||
| } | ||||
|  |  | |||
|  | @ -43,6 +43,7 @@ protected: | |||
| 	QTimer timeout; | ||||
| 	QByteArray downloadedData; | ||||
| 	QString defaultApplyText; | ||||
| 	QString userAgent; | ||||
| }; | ||||
| 
 | ||||
| class SubsurfaceWebServices : public WebServices { | ||||
|  |  | |||
|  | @ -1,4 +1,5 @@ | |||
| #include "updatemanager.h" | ||||
| #include "usersurvey.h" | ||||
| #include <QtNetwork> | ||||
| #include <QMessageBox> | ||||
| #include "subsurfacewebservices.h" | ||||
|  | @ -24,7 +25,12 @@ void UpdateManager::checkForUpdates() | |||
| 
 | ||||
| 	QString version = VERSION_STRING; | ||||
| 	QString url = QString("http://subsurface.hohndel.org/updatecheck.html?os=%1&ver=%2").arg(os, version); | ||||
| 	connect(SubsurfaceWebServices::manager()->get(QNetworkRequest(QUrl(url))), SIGNAL(finished()), this, SLOT(requestReceived())); | ||||
| 	QNetworkRequest request; | ||||
| 	request.setUrl(url); | ||||
| 	request.setRawHeader("Accept", "text/xml"); | ||||
| 	QString userAgent = UserSurvey::getVersion().replace("\n", " "); | ||||
| 	request.setRawHeader("User-Agent", userAgent.toUtf8()); | ||||
| 	connect(SubsurfaceWebServices::manager()->get(request), SIGNAL(finished()), this, SLOT(requestReceived())); | ||||
| } | ||||
| 
 | ||||
| void UpdateManager::requestReceived() | ||||
|  |  | |||
|  | @ -14,7 +14,6 @@ | |||
| UserSurvey::UserSurvey(QWidget *parent) : QDialog(parent), | ||||
| 	ui(new Ui::UserSurvey) | ||||
| { | ||||
| 	QString osArch, arch; | ||||
| 	ui->setupUi(this); | ||||
| 	this->adjustSize(); | ||||
| 	QShortcut *closeKey = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), this); | ||||
|  | @ -22,24 +21,30 @@ UserSurvey::UserSurvey(QWidget *parent) : QDialog(parent), | |||
| 	QShortcut *quitKey = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this); | ||||
| 	connect(quitKey, SIGNAL(activated()), parent, SLOT(close())); | ||||
| 
 | ||||
| 	// fill in the system data
 | ||||
| 	QString sysInfo = QString("Subsurface %1").arg(VERSION_STRING); | ||||
| 	os = QString("ssrfVers=%1").arg(VERSION_STRING); | ||||
| 	sysInfo.append(tr("\nOperating System: %1").arg(SubsurfaceSysInfo::prettyOsName())); | ||||
| 	os.append(QString("&prettyOsName=%1").arg(SubsurfaceSysInfo::prettyOsName())); | ||||
| 	arch = SubsurfaceSysInfo::cpuArchitecture(); | ||||
| 	sysInfo.append(tr("\nCPU Architecture: %1").arg(arch)); | ||||
| 	QString arch = SubsurfaceSysInfo::cpuArchitecture(); | ||||
| 	os.append(QString("&appCpuArch=%1").arg(arch)); | ||||
| 	if (arch == "i386") { | ||||
| 		osArch = SubsurfaceSysInfo::osArch(); | ||||
| 		if (!osArch.isEmpty()) { | ||||
| 			sysInfo.append(tr("\nOS CPU Architecture: %1").arg(osArch)); | ||||
| 			os.append(QString("&osCpuArch=%1").arg(osArch)); | ||||
| 		} | ||||
| 		QString osArch = SubsurfaceSysInfo::osArch(); | ||||
| 		os.append(QString("&osCpuArch=%1").arg(osArch)); | ||||
| 	} | ||||
| 	sysInfo.append(tr("\nLanguage: %1").arg(uiLanguage(NULL))); | ||||
| 	os.append(QString("&uiLang=%1").arg(uiLanguage(NULL))); | ||||
| 	ui->system->setPlainText(sysInfo); | ||||
| 	ui->system->setPlainText(getVersion()); | ||||
| } | ||||
| 
 | ||||
| QString UserSurvey::getVersion() | ||||
| { | ||||
| 	QString arch; | ||||
| 	// fill in the system data
 | ||||
| 	QString sysInfo = QString("Subsurface %1").arg(VERSION_STRING); | ||||
| 	sysInfo.append(tr("\nOperating System: %1").arg(SubsurfaceSysInfo::prettyOsName())); | ||||
| 	arch = SubsurfaceSysInfo::cpuArchitecture(); | ||||
| 	sysInfo.append(tr("\nCPU Architecture: %1").arg(arch)); | ||||
| 	if (arch == "i386") | ||||
| 		sysInfo.append(tr("\nOS CPU Architecture: %1").arg(SubsurfaceSysInfo::osArch())); | ||||
| 	sysInfo.append(tr("\nLanguage: %1").arg(uiLanguage(NULL))); | ||||
| 	return sysInfo; | ||||
| } | ||||
| 
 | ||||
| UserSurvey::~UserSurvey() | ||||
|  |  | |||
|  | @ -15,6 +15,7 @@ class UserSurvey : public QDialog { | |||
| public: | ||||
| 	explicit UserSurvey(QWidget *parent = 0); | ||||
| 	~UserSurvey(); | ||||
| 	static QString getVersion(); | ||||
| 
 | ||||
| private | ||||
| slots: | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue