mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-02-09 03:18:41 -05:00
improved error message in webui: show full path of file if read failed
This commit is contained in:
parent
9897def2cc
commit
ff9bf71aa8
@ -6,6 +6,8 @@
|
|||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
#include <util/rsdir.h>
|
||||||
|
|
||||||
// for filestreamer
|
// for filestreamer
|
||||||
#include <retroshare/rsfiles.h>
|
#include <retroshare/rsfiles.h>
|
||||||
|
|
||||||
@ -70,7 +72,7 @@ namespace resource_api{
|
|||||||
|
|
||||||
std::string getDefaultDocroot()
|
std::string getDefaultDocroot()
|
||||||
{
|
{
|
||||||
return RsAccounts::DataDirectory() + "/webui";
|
return RsAccounts::DataDirectory(false) + "/webui";
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* API_ENTRY_PATH = "/api/v2";
|
const char* API_ENTRY_PATH = "/api/v2";
|
||||||
@ -403,6 +405,21 @@ static void sendMessage(MHD_Connection *connection, unsigned int status, std::st
|
|||||||
MHD_destroy_response(resp);
|
MHD_destroy_response(resp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// convert all character to hex html entities
|
||||||
|
static std::string escape_html(std::string in)
|
||||||
|
{
|
||||||
|
std::string out;
|
||||||
|
for(int i = 0; i < in.size(); i++)
|
||||||
|
{
|
||||||
|
char a = (in[i]&0xF0)>>4;
|
||||||
|
a = a < 10? a+'0': a-10+'A';
|
||||||
|
char b = (in[i]&0x0F);
|
||||||
|
b = b < 10? b+'0': b-10+'A';
|
||||||
|
out += std::string("&#x")+a+b+";";
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
ApiServerMHD::ApiServerMHD(ApiServer *server):
|
ApiServerMHD::ApiServerMHD(ApiServer *server):
|
||||||
mConfigOk(false), mDaemon(0), mApiServer(server)
|
mConfigOk(false), mDaemon(0), mApiServer(server)
|
||||||
{
|
{
|
||||||
@ -589,8 +606,12 @@ int ApiServerMHD::accessHandlerCallback(MHD_Connection *connection,
|
|||||||
#endif
|
#endif
|
||||||
if(fd == -1)
|
if(fd == -1)
|
||||||
{
|
{
|
||||||
#warning sending untrusted string to the browser
|
std::string direxists;
|
||||||
std::string msg = "<html><body><p>Error: can't open the requested file. Path is ""+filename+""</p></body></html>";
|
if(RsDirUtil::checkDirectory(mRootDir))
|
||||||
|
direxists = "directory ""+mRootDir+"" exists";
|
||||||
|
else
|
||||||
|
direxists = "directory ""+mRootDir+"" does not exist!";
|
||||||
|
std::string msg = "<html><body><p>Error: can't open the requested file. path=""+escape_html(filename)+""</p><p>"+direxists+"</p></body></html>";
|
||||||
sendMessage(connection, MHD_HTTP_NOT_FOUND, msg);
|
sendMessage(connection, MHD_HTTP_NOT_FOUND, msg);
|
||||||
return MHD_YES;
|
return MHD_YES;
|
||||||
}
|
}
|
||||||
|
@ -132,7 +132,13 @@ namespace RsAccounts
|
|||||||
{
|
{
|
||||||
// Directories.
|
// Directories.
|
||||||
std::string ConfigDirectory(); // aka Base Directory. (normally ~/.retroshare)
|
std::string ConfigDirectory(); // aka Base Directory. (normally ~/.retroshare)
|
||||||
std::string DataDirectory(); // you can call this method even before initialisation (you can't with the other methods)
|
/**
|
||||||
|
* @brief DataDirectory
|
||||||
|
* you can call this method even before initialisation (you can't with the other methods)
|
||||||
|
* @param check if set to true and directory does not exist, return empty string
|
||||||
|
* @return path where global platform independent files are stored, like bdboot.txt or webinterface files
|
||||||
|
*/
|
||||||
|
std::string DataDirectory(bool check = true);
|
||||||
std::string PGPDirectory();
|
std::string PGPDirectory();
|
||||||
std::string AccountDirectory();
|
std::string AccountDirectory();
|
||||||
|
|
||||||
|
@ -743,7 +743,7 @@ static bool checkAccount(std::string accountdir, AccountDetails &account,std::ma
|
|||||||
//#include <CFBundle.h>
|
//#include <CFBundle.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*static*/ std::string RsAccountsDetail::PathDataDirectory()
|
/*static*/ std::string RsAccountsDetail::PathDataDirectory(bool check)
|
||||||
{
|
{
|
||||||
std::string dataDirectory;
|
std::string dataDirectory;
|
||||||
|
|
||||||
@ -809,6 +809,9 @@ static bool checkAccount(std::string accountdir, AccountDetails &account,std::ma
|
|||||||
#endif
|
#endif
|
||||||
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
||||||
|
|
||||||
|
if(!check)
|
||||||
|
return dataDirectory;
|
||||||
|
|
||||||
/* Make sure the directory exists, else return emptyString */
|
/* Make sure the directory exists, else return emptyString */
|
||||||
if (!RsDirUtil::checkDirectory(dataDirectory))
|
if (!RsDirUtil::checkDirectory(dataDirectory))
|
||||||
{
|
{
|
||||||
@ -1246,7 +1249,7 @@ bool RsInit::LoadPassword(const std::string& id, const std::string& inPwd)
|
|||||||
|
|
||||||
// Directories.
|
// Directories.
|
||||||
std::string RsAccounts::ConfigDirectory() { return rsAccounts->PathBaseDirectory(); }
|
std::string RsAccounts::ConfigDirectory() { return rsAccounts->PathBaseDirectory(); }
|
||||||
std::string RsAccounts::DataDirectory() { return RsAccountsDetail::PathDataDirectory(); }
|
std::string RsAccounts::DataDirectory(bool check) { return RsAccountsDetail::PathDataDirectory(check); }
|
||||||
std::string RsAccounts::PGPDirectory() { return rsAccounts->PathPGPDirectory(); }
|
std::string RsAccounts::PGPDirectory() { return rsAccounts->PathPGPDirectory(); }
|
||||||
std::string RsAccounts::AccountDirectory() { return rsAccounts->PathAccountDirectory(); }
|
std::string RsAccounts::AccountDirectory() { return rsAccounts->PathAccountDirectory(); }
|
||||||
|
|
||||||
|
@ -74,7 +74,12 @@ class RsAccountsDetail
|
|||||||
bool checkAccountDirectory();
|
bool checkAccountDirectory();
|
||||||
|
|
||||||
// Paths.
|
// Paths.
|
||||||
static std::string PathDataDirectory();
|
/**
|
||||||
|
* @brief PathDataDirectory
|
||||||
|
* @param check if set to true and directory does not exist, return empty string
|
||||||
|
* @return path where global platform independent files are stored, like bdboot.txt or webinterface files
|
||||||
|
*/
|
||||||
|
static std::string PathDataDirectory(bool check = true);
|
||||||
std::string PathBaseDirectory();
|
std::string PathBaseDirectory();
|
||||||
|
|
||||||
// PGP Path is only dependent on BaseDirectory.
|
// PGP Path is only dependent on BaseDirectory.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user