#26 Add option to ignore cert validation
parent
568fb92ada
commit
b14f87c5a7
|
@ -36,16 +36,18 @@ WebDAV::WebDAV()
|
|||
_username = Util::accessConfig<string>(Action::IReadString,"username",{});
|
||||
_password = Util::accessConfig<string>(Action::IReadSecret,"password",{});
|
||||
_url = Util::accessConfig<string>(Action::IReadString, "url",{});
|
||||
_ignoreCert = Util::accessConfig<int>(Action::IReadInt, "ignoreCert",{});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::vector<WebDAVItem> WebDAV::login(const string &Url, const string &Username, const string &Pass)
|
||||
std::vector<WebDAVItem> WebDAV::login(const string &Url, const string &Username, const string &Pass, bool ignoreCert)
|
||||
{
|
||||
string uuid;
|
||||
|
||||
_password = Pass;
|
||||
_username = Username;
|
||||
_ignoreCert = ignoreCert;
|
||||
|
||||
std::size_t found = Url.find(NEXTCLOUD_ROOT_PATH);
|
||||
if (found != std::string::npos)
|
||||
|
@ -69,6 +71,7 @@ std::vector<WebDAVItem> WebDAV::login(const string &Url, const string &Username,
|
|||
Util::accessConfig<string>( Action::IWriteString, "username", _username);
|
||||
Util::accessConfig<string>( Action::IWriteString, "UUID", uuid);
|
||||
Util::accessConfig<string>( Action::IWriteSecret, "password", _password);
|
||||
Util::accessConfig<int>( Action::IWriteInt, "ignoreCert", _ignoreCert);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -232,8 +235,12 @@ string WebDAV::propfind(const string &pathUrl)
|
|||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, Util::writeCallback);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
|
||||
|
||||
if (iv_access(CACERT_PATH.c_str(), R_OK) == 0)
|
||||
curl_easy_setopt(curl, CURLOPT_CAINFO, CACERT_PATH.c_str());
|
||||
if(_ignoreCert)
|
||||
{
|
||||
Log::writeInfoLog("Cert ignored");
|
||||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
|
||||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
|
||||
}
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "<\?xml version=\"1.0\" encoding=\"UTF-8\"\?> \
|
||||
<d:propfind xmlns:d=\"DAV:\"><d:prop xmlns:oc=\"http://owncloud.org/ns\"> \
|
||||
|
@ -314,8 +321,12 @@ bool WebDAV::get(WebDAVItem &item)
|
|||
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, false);
|
||||
curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, Util::progress_callback);
|
||||
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
|
||||
if (iv_access(CACERT_PATH.c_str(), R_OK) == 0)
|
||||
curl_easy_setopt(curl, CURLOPT_CAINFO, CACERT_PATH.c_str());
|
||||
if(_ignoreCert)
|
||||
{
|
||||
Log::writeInfoLog("Cert ignored");
|
||||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
|
||||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
|
||||
}
|
||||
res = curl_easy_perform(curl);
|
||||
curl_easy_cleanup(curl);
|
||||
iv_fclose(fp);
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
const std::string NEXTCLOUD_ROOT_PATH = "/remote.php/dav/files/";
|
||||
const std::string NEXTCLOUD_START_PATH = "/remote.php/";
|
||||
const std::string NEXTCLOUD_PATH = "/mnt/ext1/system/config/nextcloud";
|
||||
const std::string CACERT_PATH = NEXTCLOUD_PATH + "/customCert.pem";
|
||||
|
||||
class WebDAV
|
||||
{
|
||||
|
@ -29,7 +28,7 @@ class WebDAV
|
|||
*/
|
||||
WebDAV();
|
||||
|
||||
std::vector<WebDAVItem> login(const std::string &Url, const std::string &Username, const std::string &Pass);
|
||||
std::vector<WebDAVItem> login(const std::string &Url, const std::string &Username, const std::string &Pass, bool ignoreCert = false);
|
||||
|
||||
void logout(bool deleteFiles = false);
|
||||
|
||||
|
@ -51,6 +50,7 @@ class WebDAV
|
|||
std::string _username;
|
||||
std::string _password;
|
||||
std::string _url;
|
||||
bool _ignoreCert;
|
||||
|
||||
};
|
||||
#endif
|
||||
|
|
|
@ -371,7 +371,7 @@ int EventHandler::pointerHandler(const int type, const int par1, const int par2)
|
|||
{
|
||||
ShowHourglassForce();
|
||||
|
||||
std::vector<WebDAVItem> currentWebDAVItems = _webDAV.login(_loginView->getURL(), _loginView->getUsername(), _loginView->getPassword());
|
||||
std::vector<WebDAVItem> currentWebDAVItems = _webDAV.login(_loginView->getURL(), _loginView->getUsername(), _loginView->getPassword(), _loginView->getIgnoreCert());;
|
||||
if (currentWebDAVItems.empty())
|
||||
{
|
||||
Message(ICON_ERROR, "Error", "Login failed.", 1000);
|
||||
|
|
|
@ -22,6 +22,7 @@ LoginView::LoginView(const irect &contentRect) : _contentRect(contentRect)
|
|||
|
||||
int contentHeight = contentRect.h / 2;
|
||||
int contentWidth = _contentRect.w * 0.9;
|
||||
int checkBoxWidth = _contentRect.w * 0.1;
|
||||
|
||||
int beginY = 0.4 * contentHeight;
|
||||
int beginX = (_contentRect.w - contentWidth) / 2;
|
||||
|
@ -46,7 +47,11 @@ LoginView::LoginView(const irect &contentRect) : _contentRect(contentRect)
|
|||
DrawTextRect(_passwordButton.x, _passwordButton.y - _loginFontHeight - _loginFontHeight/4, _passwordButton.w, _passwordButton.h, "Password:", ALIGN_LEFT);
|
||||
DrawRect(_passwordButton.x - 1, _passwordButton.y - 1, _passwordButton.w + 2, _passwordButton.h + 2, BLACK);
|
||||
|
||||
_loginButton = iRect(beginX, beginY + 6 * contents, contentWidth, contents, ALIGN_CENTER);
|
||||
_ignoreCertButton = iRect(_contentRect.w - 2 * checkBoxWidth, beginY + 6 * contents, checkBoxWidth, contents, ALIGN_CENTER);
|
||||
DrawTextRect(beginX, _ignoreCertButton.y, contentWidth, _ignoreCertButton.h, "Ignore Cert (unsecure):", ALIGN_LEFT);
|
||||
DrawRect(_ignoreCertButton.x - 1, _ignoreCertButton.y - 1, _ignoreCertButton.w + 2, _ignoreCertButton.h + 2, BLACK);
|
||||
|
||||
_loginButton = iRect(beginX, beginY + 8 * contents, contentWidth, contents, ALIGN_CENTER);
|
||||
|
||||
FillAreaRect(&_loginButton, BLACK);
|
||||
SetFont(_loginFont, WHITE);
|
||||
|
@ -90,6 +95,19 @@ int LoginView::logginClicked(int x, int y)
|
|||
|
||||
return 1;
|
||||
}
|
||||
else if (IsInRect(x, y, &_ignoreCertButton))
|
||||
{
|
||||
_ignoreCert = !_ignoreCert;
|
||||
FillAreaRect(&_ignoreCertButton, WHITE);
|
||||
if(_ignoreCert)
|
||||
FillArea(_ignoreCertButton.x - 1, _ignoreCertButton.y - 1, _ignoreCertButton.w + 2, _ignoreCertButton.h + 2, BLACK);
|
||||
else
|
||||
DrawRect(_ignoreCertButton.x - 1, _ignoreCertButton.y - 1, _ignoreCertButton.w + 2, _ignoreCertButton.h + 2, BLACK);
|
||||
|
||||
PartialUpdate(_ignoreCertButton.x, _ignoreCertButton.y, _ignoreCertButton.w, _ignoreCertButton.h);
|
||||
|
||||
return 1;
|
||||
}
|
||||
else if (IsInRect(x, y, &_loginButton))
|
||||
{
|
||||
if (_username.empty() || _password.empty() || _url.empty())
|
||||
|
|
|
@ -47,6 +47,7 @@ public:
|
|||
std::string getUsername() { return _username; };
|
||||
std::string getPassword() { return _password; };
|
||||
std::string getURL() { return _url; };
|
||||
bool getIgnoreCert() { return _ignoreCert; };
|
||||
|
||||
private:
|
||||
static std::unique_ptr<LoginView> _loginViewStatic;
|
||||
|
@ -57,10 +58,12 @@ private:
|
|||
irect _loginButton;
|
||||
irect _usernameButton;
|
||||
irect _passwordButton;
|
||||
irect _ignoreCertButton;
|
||||
KeyboardTarget _target;
|
||||
std::string _username;
|
||||
std::string _password;
|
||||
std::string _url;
|
||||
bool _ignoreCert = false;
|
||||
std::string _temp;
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue