diff --git a/README.md b/README.md index 9960ca13..1368d8dc 100644 --- a/README.md +++ b/README.md @@ -239,6 +239,37 @@ There are packages available for a few distros: +### S3 bucket configuration + +S3 bucket credentials are placed in the file `config.ini` and cannot be configured with UI. +This file is not included into installation and should be placed into the installation directory manually. +On `linux` systems it can be placed at `/etc/flameshot/config.ini`. + +You can also add `proxy` server settings. If you don't need a proxy server just remove or comment lines with a proxy settings. + +Configuration file example: +``` +[General] +HTTP_PROXY_HOST=10.0.0.1 +HTTP_PROXY_PORT=3128 + +; No authentification USER and PASSWORD should be empty +HTTP_PROXY_USER= +HTTP_PROXY_PASSWORD= + +HTTP_PROXY_TYPE=0 +; Proxy Types (0 is default): +; 0 Proxy is determined based on the application proxy set using setApplicationProxy() +; 1 Socks5 proxying is used +; 3 HTTP transparent proxying is used +; 4 Proxying for HTTP requests only +; 5 Proxying for FTP requests only + +[S3] +S3_CREDS_URL=https://api.img.example.com/ +S3_X_API_KEY=seckret_key +``` + ## Compilation To build the application in your system, you'll need to install the dependencies needed for it and Package names might be different for each distribution, see [Dependencies](#dependencies) below for more information. diff --git a/src/tools/imgs3/imgs3uploader.cpp b/src/tools/imgs3/imgs3uploader.cpp index a2de6d4c..34b71d33 100644 --- a/src/tools/imgs3/imgs3uploader.cpp +++ b/src/tools/imgs3/imgs3uploader.cpp @@ -41,15 +41,25 @@ #include #include #include +#include +#include -ImgS3Uploader::ImgS3Uploader(const QPixmap &capture, - const QString &s3CredsUrl, - const QString &s3XApiKey, - QWidget *parent) : + +ImgS3Uploader::ImgS3Uploader(const QPixmap &capture, QWidget *parent) : QWidget(parent), m_pixmap(capture) { - m_s3CredsUrl = s3CredsUrl; - m_s3XApiKey = s3XApiKey; + QSettings *pSettings = nullptr; + QString configIniPath = QDir(QDir::currentPath()).filePath("config.ini"); +#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX) + if(!(QFileInfo::exists(configIniPath) && QFileInfo(configIniPath).isFile())) { + configIniPath = "/etc/flameshot/config.ini"; + } +#endif + pSettings = new QSettings(configIniPath, QSettings::IniFormat); + pSettings->beginGroup("S3"); + m_s3CredsUrl = pSettings->value("S3_CREDS_URL").toString(); + m_s3XApiKey = pSettings->value("S3_X_API_KEY").toString(); + pSettings->endGroup(); setWindowTitle(tr("Upload to ImgS3")); setWindowIcon(QIcon(":img/app/flameshot.svg")); @@ -73,6 +83,52 @@ ImgS3Uploader::ImgS3Uploader(const QPixmap &capture, setAttribute(Qt::WA_DeleteOnClose); + QString httpProxyHost = pSettings->value("HTTP_PROXY_HOST").toString(); + if(httpProxyHost.length() > 0) { + qDebug() << "Using proxy server"; + m_proxy = new QNetworkProxy(); + + if(pSettings->contains("HTTP_PROXY_TYPE")) { + switch (pSettings->value("HTTP_PROXY_TYPE").toInt()) { + case 0: + m_proxy->setType(QNetworkProxy::DefaultProxy); + break; + case 1: + m_proxy->setType(QNetworkProxy::Socks5Proxy); + break; + case 2: + m_proxy->setType(QNetworkProxy::NoProxy); + break; + case 4: + m_proxy->setType(QNetworkProxy::HttpCachingProxy); + break; + case 5: + m_proxy->setType(QNetworkProxy::FtpCachingProxy); + break; + case 3: + default: + m_proxy->setType(QNetworkProxy::HttpProxy); + break; + } + } + + m_proxy->setHostName(httpProxyHost); + if(pSettings->contains("HTTP_PROXY_PORT")) { + m_proxy->setPort(pSettings->value("HTTP_PROXY_PORT").toInt()); + } else { + m_proxy->setPort(3128); + } + + if(pSettings->contains("HTTP_PROXY_USER")) { + m_proxy->setUser(pSettings->value("HTTP_PROXY_USER").toString()); + } + if(pSettings->contains("HTTP_PROXY_PASSWORD")) { + m_proxy->setPassword(pSettings->value("HTTP_PROXY_PASSWORD").toString()); + } + QNetworkProxy::setApplicationProxy(*m_proxy); + m_NetworkAM->setProxy(*m_proxy); + } + upload(); } diff --git a/src/tools/imgs3/imgs3uploader.h b/src/tools/imgs3/imgs3uploader.h index 78d3e3e9..1ffd9b4f 100644 --- a/src/tools/imgs3/imgs3uploader.h +++ b/src/tools/imgs3/imgs3uploader.h @@ -21,6 +21,7 @@ #include class QNetworkReply; +class QNetworkProxy; class QNetworkAccessManager; class QHBoxLayout; class QVBoxLayout; @@ -33,11 +34,7 @@ class NotificationWidget; class ImgS3Uploader : public QWidget { Q_OBJECT public: - explicit ImgS3Uploader(const QPixmap &capture, - const QString &s3CredsUrl, - const QString &s3XApiKey, - QWidget *parent = nullptr -); + explicit ImgS3Uploader(const QPixmap &capture, QWidget *parent = nullptr); private slots: void handleReply(QNetworkReply *reply); @@ -57,6 +54,7 @@ private: QString m_hostName; QPixmap m_pixmap; + QNetworkProxy *m_proxy; QNetworkAccessManager *m_NetworkAM; QNetworkAccessManager *m_NetworkAMCreds; diff --git a/src/tools/imgs3/imgs3uploadertool.cpp b/src/tools/imgs3/imgs3uploadertool.cpp index 2a2a2430..99bf1856 100644 --- a/src/tools/imgs3/imgs3uploadertool.cpp +++ b/src/tools/imgs3/imgs3uploadertool.cpp @@ -17,24 +17,12 @@ #include "imgs3uploadertool.h" #include "imgs3uploader.h" -#include #include #include #include ImgS3UploaderTool::ImgS3UploaderTool(QObject *parent) : AbstractActionTool(parent) { - QSettings *pSettings = nullptr; - QString configIniPath = QDir::currentPath() + "/config.ini"; -#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX) - if(!(QFileInfo::exists(configIniPath) && QFileInfo(configIniPath).isFile())) { - configIniPath = "/etc/flameshot/config.ini"; - } -#endif - pSettings = new QSettings(configIniPath, QSettings::IniFormat); - pSettings->beginGroup("S3"); - m_s3CredsUrl = pSettings->value("S3_CREDS_URL").toString(); - m_s3XApiKey = pSettings->value("S3_X_API_KEY").toString(); } bool ImgS3UploaderTool::closeOnButtonPressed() const { @@ -59,7 +47,7 @@ QString ImgS3UploaderTool::description() const { } QWidget *ImgS3UploaderTool::widget() { - return new ImgS3Uploader(capture, m_s3CredsUrl, m_s3XApiKey); + return new ImgS3Uploader(capture); } void ImgS3UploaderTool::setCapture(const QPixmap &pixmap) { diff --git a/src/tools/imgs3/imgs3uploadertool.h b/src/tools/imgs3/imgs3uploadertool.h index 42377526..8b1846ce 100644 --- a/src/tools/imgs3/imgs3uploadertool.h +++ b/src/tools/imgs3/imgs3uploadertool.h @@ -41,6 +41,4 @@ public slots: private: QPixmap capture; - QString m_s3CredsUrl; - QString m_s3XApiKey; };