mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-02 05:02:33 -04:00
fixed interactions between webui and jsonapi in GUI
This commit is contained in:
parent
6878a7773d
commit
9491f1a78e
10 changed files with 94 additions and 27 deletions
|
@ -144,7 +144,7 @@ bool RsJsonAPI::parseToken(const std::string& clear_token,std::string& user,std:
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
user = clear_token.substr(0,last_index);
|
user = clear_token.substr(0,last_index);
|
||||||
passwd = clear_token.substr(last_index+1,(int)clear_token.size()-(int)last_index-2);
|
passwd = clear_token.substr(last_index+1,(int)clear_token.size()-(int)last_index-1);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
#include "util/rsthreads.h"
|
#include "util/rsthreads.h"
|
||||||
#include "util/rsdebug.h"
|
#include "util/rsdebug.h"
|
||||||
#include "retroshare/rswebui.h"
|
#include "retroshare/rswebui.h"
|
||||||
|
#include "retroshare/rsjsonapi.h"
|
||||||
|
|
||||||
#define TEXT_HTML 0
|
#define TEXT_HTML 0
|
||||||
#define TEXT_CSS 1
|
#define TEXT_CSS 1
|
||||||
|
@ -139,3 +140,12 @@ int p3WebUI::status() const
|
||||||
return WEBUI_STATUS_NOT_RUNNING;
|
return WEBUI_STATUS_NOT_RUNNING;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void p3WebUI::setUserPassword(const std::string& passwd)
|
||||||
|
{
|
||||||
|
#ifdef RS_JSONAPI
|
||||||
|
if(!rsJsonAPI->authorizeUser("webui",passwd))
|
||||||
|
std::cerr << "(EE) Cannot register webui token. Some error occurred when calling authorizeUser()" << std::endl;
|
||||||
|
#else
|
||||||
|
std::cerr << "(EE) JsonAPI is not available in this buildof Retroshare! Cannot register a user password for the WebUI" << std::endl;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
|
@ -38,6 +38,7 @@ public:
|
||||||
virtual bool stop() override { return RestbedService::stop();}
|
virtual bool stop() override { return RestbedService::stop();}
|
||||||
virtual void setListeningPort(uint16_t port) override { RestbedService::setListeningPort(port) ;}
|
virtual void setListeningPort(uint16_t port) override { RestbedService::setListeningPort(port) ;}
|
||||||
virtual void setBindingAddress(const std::string& address) override { RestbedService::setBindAddress(address) ;}
|
virtual void setBindingAddress(const std::string& address) override { RestbedService::setBindAddress(address) ;}
|
||||||
|
virtual void setUserPassword(const std::string& passwd) override;
|
||||||
|
|
||||||
virtual int status() const override;
|
virtual int status() const override;
|
||||||
virtual std::vector<std::shared_ptr<restbed::Resource> > getResources() const override;
|
virtual std::vector<std::shared_ptr<restbed::Resource> > getResources() const override;
|
||||||
|
|
|
@ -35,14 +35,15 @@ JsonApiPage::JsonApiPage(QWidget */*parent*/, Qt::WindowFlags /*flags*/)
|
||||||
connect( ui.enableCheckBox, SIGNAL(toggled(bool)), this, SLOT(enableJsonApi(bool)));
|
connect( ui.enableCheckBox, SIGNAL(toggled(bool)), this, SLOT(enableJsonApi(bool)));
|
||||||
connect( ui.addTokenPushButton, SIGNAL(clicked()), this, SLOT(addTokenClicked()));
|
connect( ui.addTokenPushButton, SIGNAL(clicked()), this, SLOT(addTokenClicked()));
|
||||||
connect( ui.removeTokenPushButton, SIGNAL(clicked()), this, SLOT(removeTokenClicked() ));
|
connect( ui.removeTokenPushButton, SIGNAL(clicked()), this, SLOT(removeTokenClicked() ));
|
||||||
connect( ui.tokensListView, SIGNAL(clicked()), this, SLOT(tokenClicked() ));
|
connect( ui.tokensListView, SIGNAL(clicked(const QModelIndex&)), this, SLOT(tokenClicked(const QModelIndex&) ));
|
||||||
connect( ui.applyConfigPushButton, SIGNAL(clicked()), this, SLOT(onApplyClicked() ));
|
connect( ui.applyConfigPushButton, SIGNAL(clicked()), this, SLOT(onApplyClicked() ));
|
||||||
connect( ui.portSpinBox, SIGNAL(valueChanged(int)), this, SLOT(updateParams() ));
|
connect( ui.portSpinBox, SIGNAL(valueChanged(int)), this, SLOT(updateParams() ));
|
||||||
connect( ui.listenAddressLineEdit, SIGNAL(textChanged(QString)), this, SLOT(updateParams() ));
|
connect( ui.listenAddressLineEdit, SIGNAL(textChanged(QString)), this, SLOT(updateParams() ));
|
||||||
|
connect( ui.tokenLineEdit, SIGNAL(textChanged(QString)), this, SLOT(checkToken(QString) ));
|
||||||
|
|
||||||
// This limits the possible tokens to alphanumeric
|
// This limits the possible tokens to alphanumeric
|
||||||
|
|
||||||
QString anRange = "{[a-z]|[A-Z]|[0-9]}+";
|
QString anRange = "[a-zA-Z0-9]+";
|
||||||
QRegExp anRegex ("^" + anRange + ":" + anRange + "$");
|
QRegExp anRegex ("^" + anRange + ":" + anRange + "$");
|
||||||
QRegExpValidator *anValidator = new QRegExpValidator(anRegex, this);
|
QRegExpValidator *anValidator = new QRegExpValidator(anRegex, this);
|
||||||
|
|
||||||
|
@ -152,7 +153,7 @@ bool JsonApiPage::checkStartJsonApi()
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void JsonApiPage::onApplyClicked(bool)
|
void JsonApiPage::onApplyClicked()
|
||||||
{
|
{
|
||||||
// restart
|
// restart
|
||||||
|
|
||||||
|
@ -160,7 +161,26 @@ void JsonApiPage::onApplyClicked(bool)
|
||||||
checkStartJsonApi();
|
checkStartJsonApi();
|
||||||
}
|
}
|
||||||
|
|
||||||
void JsonApiPage::addTokenClicked(bool)
|
void JsonApiPage::checkToken(QString s)
|
||||||
|
{
|
||||||
|
std::string user,passwd;
|
||||||
|
|
||||||
|
bool valid = RsJsonAPI::parseToken(s.toStdString(),user,passwd) && !user.empty() && !passwd.empty();
|
||||||
|
QColor color;
|
||||||
|
|
||||||
|
if(!valid)
|
||||||
|
color = QApplication::palette().color(QPalette::Disabled, QPalette::Base);
|
||||||
|
else
|
||||||
|
color = QApplication::palette().color(QPalette::Active, QPalette::Base);
|
||||||
|
|
||||||
|
/* unpolish widget to clear the stylesheet's palette cache */
|
||||||
|
//ui.searchLineFrame->style()->unpolish(ui.searchLineFrame);
|
||||||
|
|
||||||
|
QPalette palette = ui.tokenLineEdit->palette();
|
||||||
|
palette.setColor(ui.tokenLineEdit->backgroundRole(), color);
|
||||||
|
ui.tokenLineEdit->setPalette(palette);
|
||||||
|
}
|
||||||
|
void JsonApiPage::addTokenClicked()
|
||||||
{
|
{
|
||||||
QString token(ui.tokenLineEdit->text());
|
QString token(ui.tokenLineEdit->text());
|
||||||
std::string user,passwd;
|
std::string user,passwd;
|
||||||
|
@ -178,7 +198,7 @@ void JsonApiPage::addTokenClicked(bool)
|
||||||
whileBlocking(ui.tokensListView)->setModel(new QStringListModel(newTk));
|
whileBlocking(ui.tokensListView)->setModel(new QStringListModel(newTk));
|
||||||
}
|
}
|
||||||
|
|
||||||
void JsonApiPage::removeTokenClicked(bool)
|
void JsonApiPage::removeTokenClicked()
|
||||||
{
|
{
|
||||||
QString token(ui.tokenLineEdit->text());
|
QString token(ui.tokenLineEdit->text());
|
||||||
rsJsonAPI->revokeAuthToken(token.toStdString());
|
rsJsonAPI->revokeAuthToken(token.toStdString());
|
||||||
|
|
|
@ -33,7 +33,6 @@ public:
|
||||||
~JsonApiPage() {}
|
~JsonApiPage() {}
|
||||||
|
|
||||||
/** Loads the settings for this page */
|
/** Loads the settings for this page */
|
||||||
virtual void load();
|
|
||||||
|
|
||||||
virtual QPixmap iconPixmap() const
|
virtual QPixmap iconPixmap() const
|
||||||
{ return QPixmap(":/icons/svg/empty-circle.svg"); }
|
{ return QPixmap(":/icons/svg/empty-circle.svg"); }
|
||||||
|
@ -49,12 +48,15 @@ public:
|
||||||
static void checkShutdownJsonApi();
|
static void checkShutdownJsonApi();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void onApplyClicked(bool);
|
void load() override;
|
||||||
void addTokenClicked(bool);
|
|
||||||
void removeTokenClicked(bool);
|
void onApplyClicked();
|
||||||
|
void addTokenClicked();
|
||||||
|
void removeTokenClicked();
|
||||||
void tokenClicked(const QModelIndex& index);
|
void tokenClicked(const QModelIndex& index);
|
||||||
void enableJsonApi(bool checked);
|
void enableJsonApi(bool checked);
|
||||||
bool updateParams();
|
bool updateParams();
|
||||||
|
void checkToken(QString);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::JsonApiPage ui; /// Qt Designer generated object
|
Ui::JsonApiPage ui; /// Qt Designer generated object
|
||||||
|
|
|
@ -87,7 +87,7 @@
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLineEdit" name="tokenLineEdit">
|
<widget class="QLineEdit" name="tokenLineEdit">
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
<string><html><head/><body><p>ApiUser:ApiPassword</p></body></html></string>
|
<string><html><head/><body><p>Tokens should spell as &quot;user:password&quot; where both user and password are alphanumeric strings.</p></body></html></string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
|
|
||||||
#include "util/misc.h"
|
#include "util/misc.h"
|
||||||
#include "retroshare/rswebui.h"
|
#include "retroshare/rswebui.h"
|
||||||
|
#include "retroshare/rsjsonapi.h"
|
||||||
|
|
||||||
#include "rsharesettings.h"
|
#include "rsharesettings.h"
|
||||||
|
|
||||||
|
@ -57,10 +58,6 @@ WebuiPage::~WebuiPage()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebuiPage::onPasswordValueChanged(QString password)
|
|
||||||
{
|
|
||||||
std::cerr << "Setting new password to \"" << password.toStdString() << "\"" << std::endl;
|
|
||||||
}
|
|
||||||
void WebuiPage::selectWebInterfaceDirectory()
|
void WebuiPage::selectWebInterfaceDirectory()
|
||||||
{
|
{
|
||||||
QString dirname = QFileDialog::getExistingDirectory(NULL,tr("Please select the directory were to find retroshare webinterface files"),ui.webInterfaceFiles_LE->text());
|
QString dirname = QFileDialog::getExistingDirectory(NULL,tr("Please select the directory were to find retroshare webinterface files"),ui.webInterfaceFiles_LE->text());
|
||||||
|
@ -96,6 +93,25 @@ bool WebuiPage::updateParams(QString &errmsg)
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebuiPage::onPasswordValueChanged(QString password)
|
||||||
|
{
|
||||||
|
QColor color;
|
||||||
|
|
||||||
|
bool valid = password.length() >= 1;
|
||||||
|
|
||||||
|
if(!valid)
|
||||||
|
color = QApplication::palette().color(QPalette::Disabled, QPalette::Base);
|
||||||
|
else
|
||||||
|
color = QApplication::palette().color(QPalette::Active, QPalette::Base);
|
||||||
|
|
||||||
|
/* unpolish widget to clear the stylesheet's palette cache */
|
||||||
|
//ui.searchLineFrame->style()->unpolish(ui.searchLineFrame);
|
||||||
|
|
||||||
|
QPalette palette = ui.password_LE->palette();
|
||||||
|
palette.setColor(ui.password_LE->backgroundRole(), color);
|
||||||
|
ui.password_LE->setPalette(palette);
|
||||||
|
}
|
||||||
|
|
||||||
bool WebuiPage::restart()
|
bool WebuiPage::restart()
|
||||||
{
|
{
|
||||||
// apply config
|
// apply config
|
||||||
|
@ -110,6 +126,14 @@ void WebuiPage::load()
|
||||||
whileBlocking(ui.port_SB)->setValue(Settings->getWebinterfacePort());
|
whileBlocking(ui.port_SB)->setValue(Settings->getWebinterfacePort());
|
||||||
whileBlocking(ui.webInterfaceFiles_LE)->setText(Settings->getWebinterfaceFilesDirectory());
|
whileBlocking(ui.webInterfaceFiles_LE)->setText(Settings->getWebinterfaceFilesDirectory());
|
||||||
whileBlocking(ui.allIp_CB)->setChecked(Settings->getWebinterfaceAllowAllIps());
|
whileBlocking(ui.allIp_CB)->setChecked(Settings->getWebinterfaceAllowAllIps());
|
||||||
|
|
||||||
|
#ifdef RS_JSONAPI
|
||||||
|
auto smap = rsJsonAPI->getAuthorizedTokens();
|
||||||
|
auto it = smap.find("webui");
|
||||||
|
|
||||||
|
if(it != smap.end())
|
||||||
|
whileBlocking(ui.password_LE)->setText(QString::fromStdString(it->second));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -180,11 +204,15 @@ void WebuiPage::onApplyClicked()
|
||||||
{
|
{
|
||||||
QString errmsg;
|
QString errmsg;
|
||||||
|
|
||||||
|
rsWebUI->setUserPassword(ui.password_LE->text().toStdString());
|
||||||
|
|
||||||
if(!restart())
|
if(!restart())
|
||||||
{
|
{
|
||||||
QMessageBox::warning(0, tr("failed to start Webinterface"), "Failed to start the webinterface.");
|
QMessageBox::warning(0, tr("failed to start Webinterface"), "Failed to start the webinterface.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
emit passwordChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebuiPage::onStartWebBrowserClicked()
|
void WebuiPage::onStartWebBrowserClicked()
|
||||||
|
|
|
@ -66,6 +66,9 @@ public slots:
|
||||||
void onApplyClicked();
|
void onApplyClicked();
|
||||||
void onStartWebBrowserClicked();
|
void onStartWebBrowserClicked();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void passwordChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** Qt Designer generated object */
|
/** Qt Designer generated object */
|
||||||
Ui::WebuiPage ui;
|
Ui::WebuiPage ui;
|
||||||
|
|
|
@ -164,12 +164,15 @@ SettingsPage::initStackedWidget()
|
||||||
addPage(new AppearancePage()); // APPEARENCE
|
addPage(new AppearancePage()); // APPEARENCE
|
||||||
addPage(new SoundPage() ); // SOUND
|
addPage(new SoundPage() ); // SOUND
|
||||||
addPage(new ServicePermissionsPage() ); // PERMISSIONS
|
addPage(new ServicePermissionsPage() ); // PERMISSIONS
|
||||||
#ifdef RS_WEBUI
|
|
||||||
addPage(new WebuiPage() );
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef RS_JSONAPI
|
#ifdef RS_JSONAPI
|
||||||
|
JsonApiPage *jsonapi_p = new JsonApiPage() ;
|
||||||
addPage(new JsonApiPage());
|
addPage(new JsonApiPage());
|
||||||
|
#ifdef RS_WEBUI
|
||||||
|
WebuiPage *webui_p = new WebuiPage() ;
|
||||||
|
addPage(new WebuiPage() );
|
||||||
|
|
||||||
|
QObject::connect(webui_p,SIGNAL(passwordChanged()),jsonapi_p,SLOT(load()));
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// add widgets from plugins
|
// add widgets from plugins
|
||||||
|
|
|
@ -572,14 +572,14 @@ feenableexcept(FE_INVALID | FE_DIVBYZERO);
|
||||||
|
|
||||||
notify->enable() ; // enable notification system after GUI creation, to avoid data races in Qt.
|
notify->enable() ; // enable notification system after GUI creation, to avoid data races in Qt.
|
||||||
|
|
||||||
#ifdef RS_WEBUI
|
|
||||||
WebuiPage::checkStartWebui(); // normally we should rather save the UI flags internally to p3webui
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef RS_JSONAPI
|
#ifdef RS_JSONAPI
|
||||||
JsonApiPage::checkStartJsonApi();
|
JsonApiPage::checkStartJsonApi();
|
||||||
#endif // RS_JSONAPI
|
#endif // RS_JSONAPI
|
||||||
|
|
||||||
|
#ifdef RS_WEBUI
|
||||||
|
WebuiPage::checkStartWebui(); // normally we should rather save the UI flags internally to p3webui
|
||||||
|
#endif
|
||||||
|
|
||||||
// This is done using a timer, because the passphrase request from notify is asynchrouneous and therefore clearing the
|
// This is done using a timer, because the passphrase request from notify is asynchrouneous and therefore clearing the
|
||||||
// passphrase here makes it request for a passphrase when creating the default chat identity.
|
// passphrase here makes it request for a passphrase when creating the default chat identity.
|
||||||
|
|
||||||
|
@ -589,14 +589,14 @@ feenableexcept(FE_INVALID | FE_DIVBYZERO);
|
||||||
int ti = rshare.exec();
|
int ti = rshare.exec();
|
||||||
delete w ;
|
delete w ;
|
||||||
|
|
||||||
#ifdef RS_JSONAPI
|
|
||||||
JsonApiPage::checkShutdownJsonApi();
|
|
||||||
#endif // RS_JSONAPI
|
|
||||||
|
|
||||||
#ifdef RS_WEBUI
|
#ifdef RS_WEBUI
|
||||||
WebuiPage::checkShutdownWebui();
|
WebuiPage::checkShutdownWebui();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef RS_JSONAPI
|
||||||
|
JsonApiPage::checkShutdownJsonApi();
|
||||||
|
#endif // RS_JSONAPI
|
||||||
|
|
||||||
/* cleanup */
|
/* cleanup */
|
||||||
ChatDialog::cleanupChat();
|
ChatDialog::cleanupChat();
|
||||||
#ifdef RS_ENABLE_GXS
|
#ifdef RS_ENABLE_GXS
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue