mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-17 10:59:38 -04:00
removed Qt from unix version of retroshare service. Enabled loging at start with option -u
This commit is contained in:
parent
a84a96e0b7
commit
90d0686e88
4 changed files with 196 additions and 57 deletions
|
@ -614,4 +614,4 @@ namespace json
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //__SUPER_EASY_JSON_H__
|
#endif //__SUPER_EASY_JSON_H__
|
||||||
|
|
|
@ -52,6 +52,8 @@ extern JsonApiServer* jsonApiServer;
|
||||||
*/
|
*/
|
||||||
struct JsonApiServer : RsSingleJobThread, p3Config
|
struct JsonApiServer : RsSingleJobThread, p3Config
|
||||||
{
|
{
|
||||||
|
static const uint16_t DEFAULT_PORT = 9092 ;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief construct a JsonApiServer instance with given parameters
|
* @brief construct a JsonApiServer instance with given parameters
|
||||||
* @param[in] port listening port fpt the JSON API socket
|
* @param[in] port listening port fpt the JSON API socket
|
||||||
|
@ -62,7 +64,7 @@ struct JsonApiServer : RsSingleJobThread, p3Config
|
||||||
* false otherwise, this usually requires user interacion to confirm access
|
* false otherwise, this usually requires user interacion to confirm access
|
||||||
*/
|
*/
|
||||||
JsonApiServer(
|
JsonApiServer(
|
||||||
uint16_t port = 9092,
|
uint16_t port = DEFAULT_PORT,
|
||||||
const std::string& bindAddress = "127.0.0.1",
|
const std::string& bindAddress = "127.0.0.1",
|
||||||
const std::function<bool(const std::string&)> newAccessRequestCallback = [](const std::string&){return false;} );
|
const std::function<bool(const std::string&)> newAccessRequestCallback = [](const std::string&){return false;} );
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,8 @@
|
||||||
/// RetroShare initialization and login API implementation
|
/// RetroShare initialization and login API implementation
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <termios.h>
|
||||||
|
|
||||||
#ifndef WINDOWS_SYS
|
#ifndef WINDOWS_SYS
|
||||||
// for locking instances
|
// for locking instances
|
||||||
|
@ -42,6 +44,8 @@
|
||||||
#include "util/folderiterator.h"
|
#include "util/folderiterator.h"
|
||||||
#include "util/rsstring.h"
|
#include "util/rsstring.h"
|
||||||
#include "retroshare/rsinit.h"
|
#include "retroshare/rsinit.h"
|
||||||
|
#include "retroshare/rsnotify.h"
|
||||||
|
#include "retroshare/rsiface.h"
|
||||||
#include "plugins/pluginmanager.h"
|
#include "plugins/pluginmanager.h"
|
||||||
|
|
||||||
#include "rsserver/rsloginhandler.h"
|
#include "rsserver/rsloginhandler.h"
|
||||||
|
@ -114,7 +118,7 @@ RsAccounts* rsAccounts = nullptr;
|
||||||
|
|
||||||
struct RsInitConfig
|
struct RsInitConfig
|
||||||
{
|
{
|
||||||
RsInitConfig() : jsonApiPort(0), jsonApiBindAddress("127.0.0.1") {}
|
RsInitConfig() : jsonApiPort(JsonApiServer::DEFAULT_PORT), jsonApiBindAddress("127.0.0.1") {}
|
||||||
|
|
||||||
RsFileHash main_executable_hash;
|
RsFileHash main_executable_hash;
|
||||||
|
|
||||||
|
@ -243,14 +247,6 @@ void RsInit::InitRsConfig()
|
||||||
setOutputLevel(RsLog::Warning);
|
setOutputLevel(RsLog::Warning);
|
||||||
}
|
}
|
||||||
|
|
||||||
/********
|
|
||||||
* LOCALNET_TESTING - allows port restrictions
|
|
||||||
*
|
|
||||||
* #define LOCALNET_TESTING 1
|
|
||||||
*
|
|
||||||
********/
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef LOCALNET_TESTING
|
#ifdef LOCALNET_TESTING
|
||||||
|
|
||||||
std::string portRestrictions;
|
std::string portRestrictions;
|
||||||
|
@ -264,6 +260,12 @@ bool doPortRestrictions = false;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/********
|
||||||
|
* LOCALNET_TESTING - allows port restrictions
|
||||||
|
*
|
||||||
|
* #define LOCALNET_TESTING 1
|
||||||
|
*
|
||||||
|
********/
|
||||||
int RsInit::InitRetroShare(int argc, char **argv, bool /* strictCheck */)
|
int RsInit::InitRetroShare(int argc, char **argv, bool /* strictCheck */)
|
||||||
{
|
{
|
||||||
#ifdef DEBUG_RSINIT
|
#ifdef DEBUG_RSINIT
|
||||||
|
@ -290,25 +292,20 @@ int RsInit::InitRetroShare(int argc, char **argv, bool /* strictCheck */)
|
||||||
|
|
||||||
|
|
||||||
argstream as(argc,argv);
|
argstream as(argc,argv);
|
||||||
as >> option('m',"minimized" ,rsInitConfig->startMinimised ,"Start minimized." )
|
as >> option('s',"stderr" ,rsInitConfig->outStderr ,"output to stderr instead of log file." )
|
||||||
>> option('s',"stderr" ,rsInitConfig->outStderr ,"output to stderr instead of log file." )
|
|
||||||
>> option('u',"udp" ,rsInitConfig->udpListenerOnly,"Only listen to UDP." )
|
>> option('u',"udp" ,rsInitConfig->udpListenerOnly,"Only listen to UDP." )
|
||||||
>> option('e',"external-port" ,rsInitConfig->forceExtPort ,"Use a forwarded external port." )
|
>> option('e',"external-port" ,rsInitConfig->forceExtPort ,"Use a forwarded external port." )
|
||||||
|
>> parameter('c',"base-dir" ,opt_base_dir ,"directory", "Set base directory." ,false)
|
||||||
>> parameter('l',"log-file" ,rsInitConfig->logfname ,"logfile" ,"Set Log filename." ,false)
|
>> parameter('l',"log-file" ,rsInitConfig->logfname ,"logfile" ,"Set Log filename." ,false)
|
||||||
>> parameter('d',"debug-level" ,rsInitConfig->debugLevel ,"level" ,"Set debug level." ,false)
|
>> parameter('d',"debug-level" ,rsInitConfig->debugLevel ,"level" ,"Set debug level." ,false)
|
||||||
>> parameter('i',"ip-address" ,rsInitConfig->inet ,"nnn.nnn.nnn.nnn", "Force IP address to use (if cannot be detected)." ,false)
|
>> parameter('i',"ip-address" ,rsInitConfig->inet ,"nnn.nnn.nnn.nnn", "Force IP address to use (if cannot be detected)." ,false)
|
||||||
>> parameter('o',"opmode" ,rsInitConfig->opModeStr ,"opmode" ,"Set Operating mode (Full, NoTurtle, Gaming, Minimal)." ,false)
|
>> parameter('o',"opmode" ,rsInitConfig->opModeStr ,"opmode" ,"Set Operating mode (Full, NoTurtle, Gaming, Minimal)." ,false)
|
||||||
>> parameter('p',"port" ,rsInitConfig->port ,"port", "Set listenning port to use." ,false)
|
>> parameter('p',"port" ,rsInitConfig->port ,"port", "Set listenning port to use." ,false)
|
||||||
>> parameter('c',"base-dir" ,opt_base_dir ,"directory", "Set base directory." ,false)
|
>> parameter('U',"user-id" ,prefUserString ,"ID", "[ocation Id] Selected account to use and asks for passphrase. Use \"-u list\" in order to list available accounts.",false);
|
||||||
>> parameter('U',"user-id" ,prefUserString ,"ID", "[ocation Id] Sets Account to Use, Useful when Autologin is enabled.",false);
|
|
||||||
|
|
||||||
#ifdef RS_JSONAPI
|
#ifdef RS_JSONAPI
|
||||||
as >> parameter(
|
as >> parameter('J', "jsonApiPort", rsInitConfig->jsonApiPort, "jsonApiPort", "Enable JSON API on the specified port", false )
|
||||||
"jsonApiPort", rsInitConfig->jsonApiPort, "jsonApiPort",
|
>> parameter('P', "jsonApiBindAddress", rsInitConfig->jsonApiBindAddress, "jsonApiBindAddress", "JSON API Bind Address.", false);
|
||||||
"Enable JSON API on the specified port", false )
|
|
||||||
>> parameter(
|
|
||||||
"jsonApiBindAddress", rsInitConfig->jsonApiBindAddress,
|
|
||||||
"jsonApiBindAddress", "JSON API Bind Address.", false);
|
|
||||||
#endif // ifdef RS_JSONAPI
|
#endif // ifdef RS_JSONAPI
|
||||||
|
|
||||||
#ifdef LOCALNET_TESTING
|
#ifdef LOCALNET_TESTING
|
||||||
|
@ -322,6 +319,7 @@ int RsInit::InitRetroShare(int argc, char **argv, bool /* strictCheck */)
|
||||||
as >> help('h',"help","Display this Help");
|
as >> help('h',"help","Display this Help");
|
||||||
as.defaultErrorHandling(true,true);
|
as.defaultErrorHandling(true,true);
|
||||||
|
|
||||||
|
|
||||||
if(rsInitConfig->autoLogin) rsInitConfig->startMinimised = true ;
|
if(rsInitConfig->autoLogin) rsInitConfig->startMinimised = true ;
|
||||||
if(rsInitConfig->outStderr) rsInitConfig->haveLogFile = false ;
|
if(rsInitConfig->outStderr) rsInitConfig->haveLogFile = false ;
|
||||||
if(!rsInitConfig->logfname.empty()) rsInitConfig->haveLogFile = true;
|
if(!rsInitConfig->logfname.empty()) rsInitConfig->haveLogFile = true;
|
||||||
|
@ -408,20 +406,88 @@ int RsInit::InitRetroShare(int argc, char **argv, bool /* strictCheck */)
|
||||||
// choose alternative account.
|
// choose alternative account.
|
||||||
if(prefUserString != "")
|
if(prefUserString != "")
|
||||||
{
|
{
|
||||||
RsPeerId ssl_id(prefUserString);
|
if(prefUserString == "list")
|
||||||
|
{
|
||||||
|
std::cerr << "Available accounts:" << std::endl;
|
||||||
|
|
||||||
if(ssl_id.isNull())
|
std::list<RsPeerId> account_ids;
|
||||||
{
|
RsAccounts::GetAccountIds(account_ids);
|
||||||
std::cerr << "Invalid User location id: not found in list";
|
|
||||||
std::cerr << std::endl;
|
int account_number_size = (int)ceil(log(account_ids.size())/log(10.0f)) ;
|
||||||
return RS_INIT_AUTH_FAILED ;
|
int i=1;
|
||||||
}
|
|
||||||
|
for(auto it(account_ids.begin());it!=account_ids.end();++it,++i)
|
||||||
|
{
|
||||||
|
RsPgpId pgp_id;
|
||||||
|
std::string pgp_name;
|
||||||
|
std::string loc_name;
|
||||||
|
std::string pgp_email;
|
||||||
|
|
||||||
|
RsAccounts::GetAccountDetails(*it,pgp_id,pgp_name,pgp_email,loc_name);
|
||||||
|
|
||||||
|
std::cout << "[" << std::setw(account_number_size) << std::setfill('0')
|
||||||
|
<< i << "] " << *it << " (" << pgp_id << "): " << pgp_name << " \t (" << loc_name << ")" << std::endl;
|
||||||
|
}
|
||||||
|
int nacc=0;
|
||||||
|
|
||||||
|
while(nacc < 1 || nacc >= account_ids.size())
|
||||||
|
{
|
||||||
|
std::cout << "Please enter account number: ";
|
||||||
|
std::cout.flush();
|
||||||
|
std::string str;
|
||||||
|
std::getline(std::cin, str);
|
||||||
|
|
||||||
|
nacc = atoi(str.c_str());
|
||||||
|
|
||||||
|
i=1;
|
||||||
|
for(auto it(account_ids.begin());it!=account_ids.end();++it,++i)
|
||||||
|
if(i==nacc)
|
||||||
|
{
|
||||||
|
prefUserString = (*it).toStdString();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
nacc=0; // allow to continue if something goes wrong.
|
||||||
|
|
||||||
|
|
||||||
|
RsPeerId ssl_id(prefUserString);
|
||||||
|
|
||||||
|
if(ssl_id.isNull())
|
||||||
|
{
|
||||||
|
std::cerr << "Invalid User location id: not found in list";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!RsAccounts::SelectAccount(ssl_id))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if(!RsLoginHandler::getSSLPassword(ssl_id,true,rsInitConfig->passwd))
|
||||||
|
{
|
||||||
|
std::cerr << "No valid password supplied for this account." << std::endl;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string lockFile;
|
||||||
|
int retVal = RsInit::LockAndLoadCertificates(false, lockFile);
|
||||||
|
|
||||||
|
switch (retVal)
|
||||||
|
{
|
||||||
|
case 0: break;
|
||||||
|
case 1: std::cerr << "Another RetroShare using the same profile is already running on your system. Please close "
|
||||||
|
"that instance first\n Lock file:\n" << lockFile << std::endl;
|
||||||
|
continue;
|
||||||
|
case 2: std::cerr << "An unexpected error occurred when Retroshare tried to acquire the single instance lock\n Lock file:\n"
|
||||||
|
<< lockFile.c_str() << std::endl;
|
||||||
|
continue;
|
||||||
|
case 3:
|
||||||
|
default: std::cerr << "Rshare::loadCertificate() unexpected switch value " << retVal << std::endl;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
RsControl::instance()->StartupRetroShare();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(RsAccounts::SelectAccount(ssl_id))
|
|
||||||
{
|
|
||||||
std::cerr << "Auto-selectng account ID " << ssl_id << std::endl;
|
|
||||||
return RS_INIT_HAVE_ACCOUNT;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef RS_AUTOLOGIN
|
#ifdef RS_AUTOLOGIN
|
||||||
|
|
|
@ -20,34 +20,99 @@
|
||||||
|
|
||||||
CrashStackTrace gCrashStackTrace;
|
CrashStackTrace gCrashStackTrace;
|
||||||
|
|
||||||
#include <QCoreApplication>
|
|
||||||
#include <csignal>
|
#include <csignal>
|
||||||
#include <QObject>
|
|
||||||
#include <QStringList>
|
#ifndef __ANDROID__
|
||||||
|
#include <termios.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __ANDROID__
|
#ifdef __ANDROID__
|
||||||
# include <QAndroidService>
|
# include <QAndroidService>
|
||||||
|
# include <QCoreApplication>
|
||||||
|
# include <QObject>
|
||||||
|
# include <QStringList>
|
||||||
|
|
||||||
|
# include "util/androiddebug.h"
|
||||||
#endif // def __ANDROID__
|
#endif // def __ANDROID__
|
||||||
|
|
||||||
#include "retroshare/rsinit.h"
|
#include "retroshare/rsinit.h"
|
||||||
#include "retroshare/rsiface.h"
|
#include "retroshare/rsiface.h"
|
||||||
|
|
||||||
#ifdef __ANDROID__
|
|
||||||
# include "util/androiddebug.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef RS_JSONAPI
|
#ifndef RS_JSONAPI
|
||||||
# error Inconsistent build configuration retroshare_service needs rs_jsonapi
|
# error Inconsistent build configuration retroshare_service needs rs_jsonapi
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
int getch() {
|
||||||
|
int ch;
|
||||||
|
struct termios t_old, t_new;
|
||||||
|
|
||||||
|
tcgetattr(STDIN_FILENO, &t_old);
|
||||||
|
t_new = t_old;
|
||||||
|
t_new.c_lflag &= ~(ICANON | ECHO);
|
||||||
|
tcsetattr(STDIN_FILENO, TCSANOW, &t_new);
|
||||||
|
|
||||||
|
ch = getchar();
|
||||||
|
|
||||||
|
tcsetattr(STDIN_FILENO, TCSANOW, &t_old);
|
||||||
|
return ch;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string readStringFromKeyboard(const char *prompt, bool show_asterisk=true)
|
||||||
|
{
|
||||||
|
const char BACKSPACE=127;
|
||||||
|
const char RETURN=10;
|
||||||
|
|
||||||
|
std::string password;
|
||||||
|
unsigned char ch=0;
|
||||||
|
|
||||||
|
std::cout <<prompt; std::cout.flush();
|
||||||
|
|
||||||
|
while((ch=getch())!=RETURN)
|
||||||
|
{
|
||||||
|
if(ch==BACKSPACE)
|
||||||
|
{
|
||||||
|
if(password.length()!=0)
|
||||||
|
{
|
||||||
|
if(show_asterisk)
|
||||||
|
std::cout <<"\b \b";
|
||||||
|
password.resize(password.length()-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
password+=ch;
|
||||||
|
if(show_asterisk)
|
||||||
|
std::cout <<'*';
|
||||||
|
else
|
||||||
|
std::cout << ch,std::cout.flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::cout <<std::endl;
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
|
class NotifyTxt: public NotifyClient
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
NotifyTxt(){}
|
||||||
|
virtual ~NotifyTxt() {}
|
||||||
|
|
||||||
|
virtual bool askForPassword(const std::string& title, const std::string& question, bool prev_is_bad, std::string& password,bool& cancel)
|
||||||
|
{
|
||||||
|
std::string question1=title + "\nPlease enter your PGP password for key:\n " + question + " :";
|
||||||
|
password = readStringFromKeyboard(question1.c_str()) ;
|
||||||
|
cancel = false ;
|
||||||
|
|
||||||
|
return !password.empty();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
#ifdef __ANDROID__
|
#ifdef __ANDROID__
|
||||||
AndroidStdIOCatcher dbg; (void) dbg;
|
AndroidStdIOCatcher dbg; (void) dbg;
|
||||||
QAndroidService app(argc, argv);
|
QAndroidService app(argc, argv);
|
||||||
#else // def __ANDROID__
|
|
||||||
QCoreApplication app(argc, argv);
|
|
||||||
#endif // def __ANDROID__
|
|
||||||
|
|
||||||
signal(SIGINT, QCoreApplication::exit);
|
signal(SIGINT, QCoreApplication::exit);
|
||||||
signal(SIGTERM, QCoreApplication::exit);
|
signal(SIGTERM, QCoreApplication::exit);
|
||||||
|
@ -55,23 +120,24 @@ int main(int argc, char* argv[])
|
||||||
signal(SIGBREAK, QCoreApplication::exit);
|
signal(SIGBREAK, QCoreApplication::exit);
|
||||||
#endif // ifdef SIGBREAK
|
#endif // ifdef SIGBREAK
|
||||||
|
|
||||||
|
#endif // def __ANDROID__
|
||||||
|
|
||||||
RsInit::InitRsConfig();
|
RsInit::InitRsConfig();
|
||||||
|
|
||||||
// clumsy way to enable JSON API by default
|
|
||||||
if(!QCoreApplication::arguments().contains("--jsonApiPort"))
|
|
||||||
{
|
|
||||||
int argc2 = argc + 2;
|
|
||||||
char* argv2[argc2]; for (int i = 0; i < argc; ++i ) argv2[i] = argv[i];
|
|
||||||
char opt[] = "--jsonApiPort";
|
|
||||||
char val[] = "9092";
|
|
||||||
argv2[argc] = opt;
|
|
||||||
argv2[argc+1] = val;
|
|
||||||
RsInit::InitRetroShare(argc2, argv2, true);
|
|
||||||
}
|
|
||||||
else RsInit::InitRetroShare(argc, argv, true);
|
|
||||||
|
|
||||||
RsControl::earlyInitNotificationSystem();
|
RsControl::earlyInitNotificationSystem();
|
||||||
|
|
||||||
|
#ifndef __ANDROID__
|
||||||
|
NotifyTxt *notify = new NotifyTxt();
|
||||||
|
rsNotify->registerNotifyClient(notify);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if(RsInit::InitRetroShare(argc, argv, true))
|
||||||
|
{
|
||||||
|
std::cerr << "Could not properly init Retroshare core." << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
#ifdef __ANDROID__
|
||||||
rsControl->setShutdownCallback(QCoreApplication::exit);
|
rsControl->setShutdownCallback(QCoreApplication::exit);
|
||||||
|
|
||||||
QObject::connect(
|
QObject::connect(
|
||||||
&app, &QCoreApplication::aboutToQuit,
|
&app, &QCoreApplication::aboutToQuit,
|
||||||
[](){
|
[](){
|
||||||
|
@ -79,4 +145,9 @@ int main(int argc, char* argv[])
|
||||||
RsControl::instance()->rsGlobalShutDown(); } );
|
RsControl::instance()->rsGlobalShutDown(); } );
|
||||||
|
|
||||||
return app.exec();
|
return app.exec();
|
||||||
|
#else
|
||||||
|
while(true)
|
||||||
|
sleep(1);
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue