mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-02-04 09:05:34 -05:00
fixed retroshare_service with embedded webui
This commit is contained in:
parent
2123ad7645
commit
997501a24d
@ -518,6 +518,14 @@ bool JsonApiServer::revokeAuthToken(const std::string& token)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void JsonApiServer::connectToConfigManager(p3ConfigMgr *cfgmgr)
|
||||||
|
{
|
||||||
|
cfgmgr->addConfiguration("jsonapi.cfg",this);
|
||||||
|
|
||||||
|
RsFileHash hash;
|
||||||
|
loadConfiguration(hash);
|
||||||
|
}
|
||||||
|
|
||||||
bool JsonApiServer::authorizeUser(const std::string& user,const std::string& passwd)
|
bool JsonApiServer::authorizeUser(const std::string& user,const std::string& passwd)
|
||||||
{
|
{
|
||||||
if(!is_alphanumeric(user) || !is_alphanumeric(passwd))
|
if(!is_alphanumeric(user) || !is_alphanumeric(passwd))
|
||||||
|
@ -58,6 +58,8 @@ public:
|
|||||||
virtual void setBindingAddress(const std::string& address) override { RestbedService::setBindAddress(address); }
|
virtual void setBindingAddress(const std::string& address) override { RestbedService::setBindAddress(address); }
|
||||||
virtual int status() const override;
|
virtual int status() const override;
|
||||||
|
|
||||||
|
virtual void connectToConfigManager(p3ConfigMgr *cfgmgr);
|
||||||
|
|
||||||
virtual bool authorizeUser(const std::string& alphanumeric_user,const std::string& alphanumeric_passwd) override;
|
virtual bool authorizeUser(const std::string& alphanumeric_user,const std::string& alphanumeric_passwd) override;
|
||||||
virtual std::map<std::string,std::string> getAuthorizedTokens() override;
|
virtual std::map<std::string,std::string> getAuthorizedTokens() override;
|
||||||
bool revokeAuthToken(const std::string& user) override;
|
bool revokeAuthToken(const std::string& user) override;
|
||||||
|
@ -31,6 +31,7 @@ public:
|
|||||||
{
|
{
|
||||||
_service = std::make_shared<restbed::Service>(); // this is a place holder, in case we request some internal values.
|
_service = std::make_shared<restbed::Service>(); // this is a place holder, in case we request some internal values.
|
||||||
_listening_port = 1984;
|
_listening_port = 1984;
|
||||||
|
_binding_address = "127.0.0.1";
|
||||||
}
|
}
|
||||||
|
|
||||||
void runloop() override
|
void runloop() override
|
||||||
@ -58,7 +59,7 @@ public:
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
std::cerr << "(II) Starting restbed service on port " << std::dec << _listening_port << std::endl;
|
std::cerr << "(II) Starting restbed service on port " << std::dec << _listening_port << " and binding address \"" << _binding_address << "\"" << std::endl;
|
||||||
_service->start( settings );
|
_service->start( settings );
|
||||||
}
|
}
|
||||||
catch(std::exception& e)
|
catch(std::exception& e)
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
class p3ConfigMgr;
|
||||||
|
|
||||||
class RsJsonAPI
|
class RsJsonAPI
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -40,6 +42,8 @@ public:
|
|||||||
virtual void setBindingAddress(const std::string& address) =0;
|
virtual void setBindingAddress(const std::string& address) =0;
|
||||||
virtual void setListeningPort(uint16_t port) =0;
|
virtual void setListeningPort(uint16_t port) =0;
|
||||||
|
|
||||||
|
virtual void connectToConfigManager(p3ConfigMgr *cfgmgr)=0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get status of the json api server
|
* @brief Get status of the json api server
|
||||||
* @jsonapi{development}
|
* @jsonapi{development}
|
||||||
|
@ -48,11 +48,13 @@ static constexpr char *mime_types[3] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
#ifdef WINDOWS_SYS
|
#ifdef WINDOWS_SYS
|
||||||
static std::string _base_directory = "data/webui";
|
const std::string RsWebUI::DEFAULT_BASE_DIRECTORY = "data/webui";
|
||||||
#else
|
#else
|
||||||
static std::string _base_directory = "/usr/share/retroshare/webui/";
|
const std::string RsWebUI::DEFAULT_BASE_DIRECTORY = "/usr/share/retroshare/webui/";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static std::string _base_directory = RsWebUI::DEFAULT_BASE_DIRECTORY;
|
||||||
|
|
||||||
|
|
||||||
template<int MIME_TYPE_INDEX> class handler
|
template<int MIME_TYPE_INDEX> class handler
|
||||||
{
|
{
|
||||||
|
@ -61,6 +61,7 @@
|
|||||||
#include "gxstunnel/p3gxstunnel.h"
|
#include "gxstunnel/p3gxstunnel.h"
|
||||||
#include "retroshare/rsgxsdistsync.h"
|
#include "retroshare/rsgxsdistsync.h"
|
||||||
#include "file_sharing/p3filelists.h"
|
#include "file_sharing/p3filelists.h"
|
||||||
|
#include "jsonapi/jsonapi.h"
|
||||||
|
|
||||||
#define ENABLE_GROUTER
|
#define ENABLE_GROUTER
|
||||||
|
|
||||||
@ -391,6 +392,22 @@ int RsInit::InitRetroShare(const RsConfigOptions& conf)
|
|||||||
if(!RsAccounts::init(rsInitConfig->optBaseDir,error_code))
|
if(!RsAccounts::init(rsInitConfig->optBaseDir,error_code))
|
||||||
return error_code ;
|
return error_code ;
|
||||||
|
|
||||||
|
#ifdef RS_JSONAPI
|
||||||
|
// We create the JsonApiServer this early, because it is needed *before* login
|
||||||
|
|
||||||
|
RsInfo() << "Allocating jsonAPI server (not launched yet) " << std::endl;
|
||||||
|
JsonApiServer *jas = new JsonApiServer();
|
||||||
|
jas->setListeningPort(conf.jsonApiPort);
|
||||||
|
jas->setBindingAddress(conf.jsonApiBindAddress);
|
||||||
|
|
||||||
|
if(conf.jsonApiPort != NULL)
|
||||||
|
{
|
||||||
|
RsInfo() << "Launching jsonAPI server on port " << conf.jsonApiPort << std::endl;
|
||||||
|
jas->restart();
|
||||||
|
}
|
||||||
|
|
||||||
|
rsJsonAPI = jas;
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef RS_AUTOLOGIN
|
#ifdef RS_AUTOLOGIN
|
||||||
/* check that we have selected someone */
|
/* check that we have selected someone */
|
||||||
@ -408,16 +425,6 @@ int RsInit::InitRetroShare(const RsConfigOptions& conf)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef RS_JSONAPI
|
|
||||||
if(rsInitConfig->jsonApiPort)
|
|
||||||
{
|
|
||||||
rsJsonAPI->setListeningPort(rsInitConfig->jsonApiPort);
|
|
||||||
rsJsonAPI->setBindingAddress(rsInitConfig->jsonApiBindAddress);
|
|
||||||
rsJsonAPI->restart();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // ifdef RS_JSONAPI
|
|
||||||
|
|
||||||
return RS_INIT_OK;
|
return RS_INIT_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1217,13 +1224,10 @@ int RsServer::StartupRetroShare()
|
|||||||
mPluginsManager->loadPlugins(programatically_inserted_plugins) ;
|
mPluginsManager->loadPlugins(programatically_inserted_plugins) ;
|
||||||
|
|
||||||
#ifdef RS_JSONAPI
|
#ifdef RS_JSONAPI
|
||||||
mJsonAPIServer = new JsonApiServer;
|
// add jsonapi server to config manager so that it can save/load its tokens
|
||||||
rsJsonAPI = mJsonAPIServer;
|
|
||||||
|
|
||||||
mConfigMgr->addConfiguration("jsonapi.cfg",mJsonAPIServer);
|
if(rsJsonAPI)
|
||||||
|
rsJsonAPI->connectToConfigManager(mConfigMgr);
|
||||||
RsFileHash dummyHash;
|
|
||||||
mJsonAPIServer->loadConfiguration(dummyHash);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**** Reputation system ****/
|
/**** Reputation system ****/
|
||||||
|
@ -202,8 +202,6 @@ void WebuiPage::onAllIPCBClicked(bool /*checked*/)
|
|||||||
}
|
}
|
||||||
void WebuiPage::onApplyClicked()
|
void WebuiPage::onApplyClicked()
|
||||||
{
|
{
|
||||||
QString errmsg;
|
|
||||||
|
|
||||||
rsWebUI->setUserPassword(ui.password_LE->text().toStdString());
|
rsWebUI->setUserPassword(ui.password_LE->text().toStdString());
|
||||||
|
|
||||||
if(!restart())
|
if(!restart())
|
||||||
|
@ -22,7 +22,11 @@
|
|||||||
#include "retroshare/rsinit.h"
|
#include "retroshare/rsinit.h"
|
||||||
|
|
||||||
#ifdef RS_JSONAPI
|
#ifdef RS_JSONAPI
|
||||||
#include "jsonapi/jsonapi.h"
|
#include "retroshare/rsjsonapi.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef RS_WEBUI
|
||||||
|
#include "retroshare/rswebui.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static CrashStackTrace gCrashStackTrace;
|
static CrashStackTrace gCrashStackTrace;
|
||||||
@ -120,8 +124,10 @@ int main(int argc, char* argv[])
|
|||||||
std::string prefUserString;
|
std::string prefUserString;
|
||||||
RsConfigOptions conf;
|
RsConfigOptions conf;
|
||||||
|
|
||||||
|
std::string webui_base_directory = RsWebUI::DEFAULT_BASE_DIRECTORY;
|
||||||
|
|
||||||
#ifdef RS_JSONAPI
|
#ifdef RS_JSONAPI
|
||||||
conf.jsonApiPort = JsonApiServer::DEFAULT_PORT; // enable JSonAPI by default
|
conf.jsonApiPort = RsJsonAPI::DEFAULT_PORT; // enable JSonAPI by default
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
argstream as(argc,argv);
|
argstream as(argc,argv);
|
||||||
@ -148,7 +154,7 @@ int main(int argc, char* argv[])
|
|||||||
"[node Id] Selected account to use and asks for passphrase"
|
"[node Id] Selected account to use and asks for passphrase"
|
||||||
". Use \"-U list\" in order to list available accounts.",
|
". Use \"-U list\" in order to list available accounts.",
|
||||||
false );
|
false );
|
||||||
#endif // RS_SERVICE_TERMINAL_LOGIN
|
#endif
|
||||||
|
|
||||||
#ifdef RS_JSONAPI
|
#ifdef RS_JSONAPI
|
||||||
as >> parameter( 'J', "jsonApiPort", conf.jsonApiPort, "TCP Port",
|
as >> parameter( 'J', "jsonApiPort", conf.jsonApiPort, "TCP Port",
|
||||||
@ -156,12 +162,12 @@ int main(int argc, char* argv[])
|
|||||||
>> parameter( 'P', "jsonApiBindAddress", conf.jsonApiBindAddress,
|
>> parameter( 'P', "jsonApiBindAddress", conf.jsonApiBindAddress,
|
||||||
"TCP bind address", "JSON API Bind Address default "
|
"TCP bind address", "JSON API Bind Address default "
|
||||||
"127.0.0.1.", false );
|
"127.0.0.1.", false );
|
||||||
#endif // def RS_JSONAPI
|
#endif
|
||||||
|
|
||||||
#if (defined(RS_JSONAPI) || defined(RS_WEBUI)) && defined(RS_SERVICE_TERMINAL_WEBUI_PASSWORD)
|
#if (defined(RS_JSONAPI) || defined(RS_WEBUI)) && defined(RS_SERVICE_TERMINAL_WEBUI_PASSWORD)
|
||||||
bool askWebUiPassword = false;
|
bool askWebUiPassword = false;
|
||||||
as >> option( 'W', "webui-password", askWebUiPassword,
|
as >> parameter( 'B', "webui-directory", webui_base_directory, "Place where to find the html/js files for the webui.",false );
|
||||||
"Ask WebUI password on the console." );
|
as >> option( 'W', "webui-password", askWebUiPassword, "Ask WebUI password on the console." );
|
||||||
#endif /* defined(RS_JSONAPI) && defined(RS_WEBUI) \
|
#endif /* defined(RS_JSONAPI) && defined(RS_WEBUI) \
|
||||||
&& defined(RS_SERVICE_TERMINAL_WEBUI_PASSWORD) */
|
&& defined(RS_SERVICE_TERMINAL_WEBUI_PASSWORD) */
|
||||||
|
|
||||||
@ -169,12 +175,12 @@ int main(int argc, char* argv[])
|
|||||||
#ifdef LOCALNET_TESTING
|
#ifdef LOCALNET_TESTING
|
||||||
as >> parameter( 'R', "restrict-port" , portRestrictions, "port1-port2",
|
as >> parameter( 'R', "restrict-port" , portRestrictions, "port1-port2",
|
||||||
"Apply port restriction", false);
|
"Apply port restriction", false);
|
||||||
#endif // ifdef LOCALNET_TESTING
|
#endif
|
||||||
|
|
||||||
#ifdef RS_AUTOLOGIN
|
#ifdef RS_AUTOLOGIN
|
||||||
as >> option( 'a', "auto-login", conf.autoLogin,
|
as >> option( 'a', "auto-login", conf.autoLogin,
|
||||||
"enable auto-login." );
|
"enable auto-login." );
|
||||||
#endif // ifdef RS_AUTOLOGIN
|
#endif
|
||||||
|
|
||||||
as >> help( 'h', "help", "Display this Help" );
|
as >> help( 'h', "help", "Display this Help" );
|
||||||
as.defaultErrorHandling(true, true);
|
as.defaultErrorHandling(true, true);
|
||||||
@ -212,6 +218,7 @@ int main(int argc, char* argv[])
|
|||||||
conf.main_executable_path = argv[0];
|
conf.main_executable_path = argv[0];
|
||||||
|
|
||||||
int initResult = RsInit::InitRetroShare(conf);
|
int initResult = RsInit::InitRetroShare(conf);
|
||||||
|
|
||||||
if(initResult != RS_INIT_OK)
|
if(initResult != RS_INIT_OK)
|
||||||
{
|
{
|
||||||
RsErr() << "Retroshare core initalization failed with: " << initResult
|
RsErr() << "Retroshare core initalization failed with: " << initResult
|
||||||
@ -274,8 +281,7 @@ int main(int argc, char* argv[])
|
|||||||
rsNotify->registerNotifyClient(notify);
|
rsNotify->registerNotifyClient(notify);
|
||||||
|
|
||||||
// supply empty passwd so that it is properly asked 3 times on console
|
// supply empty passwd so that it is properly asked 3 times on console
|
||||||
RsInit::LoadCertificateStatus result =
|
RsInit::LoadCertificateStatus result = rsLoginHelper->attemptLogin(ssl_id, "");
|
||||||
rsLoginHelper->attemptLogin(ssl_id, "");
|
|
||||||
|
|
||||||
switch(result)
|
switch(result)
|
||||||
{
|
{
|
||||||
@ -297,14 +303,20 @@ int main(int argc, char* argv[])
|
|||||||
<< std::endl;
|
<< std::endl;
|
||||||
return -result;
|
return -result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Start-up libretroshare server threads */
|
||||||
|
RsControl::instance()->StartupRetroShare();
|
||||||
}
|
}
|
||||||
#endif // def RS_SERVICE_TERMINAL_LOGIN
|
#endif // def RS_SERVICE_TERMINAL_LOGIN
|
||||||
|
|
||||||
#if (defined(RS_JSONAPI) || defined(RS_WEBUI)) && defined(RS_SERVICE_TERMINAL_WEBUI_PASSWORD)
|
#if (defined(RS_JSONAPI) || defined(RS_WEBUI)) && defined(RS_SERVICE_TERMINAL_WEBUI_PASSWORD)
|
||||||
if(jsonApiServer && !webui_pass1.empty())
|
if(rsJsonAPI && !webui_pass1.empty())
|
||||||
jsonApiServer->authorizeToken("webui:"+webui_pass1);
|
{
|
||||||
#endif /* defined(RS_JSONAPI) && defined(RS_WEBUI) \
|
rsWebUI->setHtmlFilesDirectory(webui_base_directory);
|
||||||
&& defined(RS_SERVICE_TERMINAL_WEBUI_PASSWORD) */
|
rsWebUI->setUserPassword(webui_pass1);
|
||||||
|
rsWebUI->restart();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __ANDROID__
|
#ifdef __ANDROID__
|
||||||
rsControl->setShutdownCallback(QCoreApplication::exit);
|
rsControl->setShutdownCallback(QCoreApplication::exit);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user