added passwd request for webUI at start of rs-service. All this should be later handled using commandline options

This commit is contained in:
csoler 2019-08-29 10:57:15 +02:00
parent 90d0686e88
commit 158da65fc4
No known key found for this signature in database
GPG key ID: 7BCA522266C0804C

View file

@ -17,6 +17,7 @@
*/ */
#include "util/stacktrace.h" #include "util/stacktrace.h"
#include "jsonapi/jsonapi.h"
CrashStackTrace gCrashStackTrace; CrashStackTrace gCrashStackTrace;
@ -91,11 +92,11 @@ std::string readStringFromKeyboard(const char *prompt, bool show_asterisk=true)
return password; return password;
} }
class NotifyTxt: public NotifyClient class RsServiceNotify: public NotifyClient
{ {
public: public:
NotifyTxt(){} RsServiceNotify(){}
virtual ~NotifyTxt() {} virtual ~RsServiceNotify() {}
virtual bool askForPassword(const std::string& title, const std::string& question, bool prev_is_bad, std::string& password,bool& cancel) virtual bool askForPassword(const std::string& title, const std::string& question, bool prev_is_bad, std::string& password,bool& cancel)
{ {
@ -126,15 +127,40 @@ int main(int argc, char* argv[])
RsControl::earlyInitNotificationSystem(); RsControl::earlyInitNotificationSystem();
#ifndef __ANDROID__ #ifndef __ANDROID__
NotifyTxt *notify = new NotifyTxt(); RsServiceNotify *notify = new RsServiceNotify();
rsNotify->registerNotifyClient(notify); rsNotify->registerNotifyClient(notify);
#endif #endif
#ifndef __ANDROID__
std::string webui_pass1 = "Y";
std::string webui_pass2 = "N";
for(;;)
{
webui_pass1 = readStringFromKeyboard("Please register a password for the web interface: ");
webui_pass2 = readStringFromKeyboard("Please enter the same password again : ");
if(webui_pass1 != webui_pass2)
{
std::cerr << "Passwords do not match!" << std::endl;
continue;
}
if(webui_pass1.empty())
{
std::cerr << "Password cannot be empty!" << std::endl;
continue;
}
break;
}
#endif
if(RsInit::InitRetroShare(argc, argv, true)) if(RsInit::InitRetroShare(argc, argv, true))
{ {
std::cerr << "Could not properly init Retroshare core." << std::endl; std::cerr << "Could not properly init Retroshare core." << std::endl;
return 1; return 1;
} }
#ifdef __ANDROID__ #ifdef __ANDROID__
rsControl->setShutdownCallback(QCoreApplication::exit); rsControl->setShutdownCallback(QCoreApplication::exit);
@ -146,6 +172,9 @@ int main(int argc, char* argv[])
return app.exec(); return app.exec();
#else #else
if(jsonApiServer)
jsonApiServer->authorizeToken("webui:"+webui_pass1);
while(true) while(true)
sleep(1); sleep(1);
#endif #endif