Merge branch 'v0.6-WebUI'

This commit is contained in:
Gioacchino Mazzurco 2019-11-27 19:19:29 +01:00
commit 5fae53d65c
No known key found for this signature in database
GPG key ID: A1FBCA3872E87051
43 changed files with 2153 additions and 998 deletions

View file

@ -23,16 +23,14 @@
#include "HelpDialog.h"
#include "rshare.h"
#include "restbed"
#include <retroshare/rsiface.h>
#include <retroshare/rsplugin.h>
#include <retroshare/rsdisc.h>
#include <retroshare/rspeers.h>
#include "settings/rsharesettings.h"
#ifdef ENABLE_WEBUI
#include <microhttpd.h>
#endif
#include <QClipboard>
#include <QSysInfo>
#include <QHBoxLayout>
@ -972,13 +970,13 @@ void AboutWidget::on_copy_button_clicked()
RsControl::instance()->getLibraries(libraries);
verInfo+=addLibraries("libretroshare", libraries);
#ifdef ENABLE_WEBUI
/* Add version numbers of RetroShare */
// Add versions here. Find a better place.
libraries.clear();
libraries.push_back(RsLibraryInfo("Libmicrohttpd", MHD_get_version()));
verInfo+=addLibraries("RetroShare", libraries);
#endif // ENABLE_WEBUI
// #ifdef RS_WEBUI
// /* Add version numbers of RetroShare */
// // Add versions here. Find a better place.
// libraries.clear();
// libraries.push_back(RsLibraryInfo("RestBed", restbed::get_version()));
// verInfo+=addLibraries("RetroShare", libraries);
// #endif
/* Add version numbers of plugins */
if (rsPlugins) {

View file

@ -25,10 +25,6 @@
#include <retroshare/rsplugin.h>
#include "rshare.h"
#ifdef ENABLE_WEBUI
#include <microhttpd.h>
#endif // ENABLE_WEBUI
#include <QFile>
#include <QTextStream>
@ -91,13 +87,13 @@ HelpDialog::HelpDialog(QWidget *parent) :
RsControl::instance()->getLibraries(libraries);
addLibraries(ui->libraryLayout, "libretroshare", libraries);
#ifdef ENABLE_WEBUI
/* Add version numbers of RetroShare */
// Add versions here. Find a better place.
libraries.clear();
libraries.push_back(RsLibraryInfo("Libmicrohttpd", MHD_get_version()));
addLibraries(ui->libraryLayout, "RetroShare", libraries);
#endif // ENABLE_WEBUI
// #ifdef RS_WEBUI
// /* Add version numbers of RetroShare */
// // Add versions here. Find a better place.
// libraries.clear();
// libraries.push_back(RsLibraryInfo("Restbed", restbed::get_version()));
// addLibraries(ui->libraryLayout, "RetroShare", libraries);
// #endif // ENABLE_WEBUI
/* Add version numbers of plugins */
if (rsPlugins) {

View file

@ -113,7 +113,7 @@
#include "common/StatusDefs.h"
#include "gui/notifyqt.h"
#ifdef ENABLE_WEBUI
#ifdef RS_WEBUI
# include "settings/WebuiPage.h"
#endif
@ -606,9 +606,9 @@ void MainWindow::createTrayIcon()
trayMenu->addAction(QIcon(IMAGE_MESSENGER), tr("Open Messenger"), this, SLOT(showMessengerWindow()));
#endif
trayMenu->addAction(QIcon(IMAGE_MESSAGES), tr("Open Messages"), this, SLOT(showMess()));
#ifdef ENABLE_WEBUI
#ifdef RS_WEBUI
trayMenu->addAction(QIcon(":/images/emblem-web.png"), tr("Show web interface"), this, SLOT(showWebinterface()));
#endif // ENABLE_WEBUI
#endif
trayMenu->addAction(QIcon(IMAGE_BWGRAPH), tr("Bandwidth Graph"), this, SLOT(showBandwidthGraph()));
trayMenu->addAction(QIcon(IMAGE_STATS), tr("Statistics"), this, SLOT(showStatisticsWindow()));
@ -1117,7 +1117,7 @@ void MainWindow::showStatisticsWindow()
StatisticsWindow::showYourself();
}
#ifdef ENABLE_WEBUI
#ifdef RS_WEBUI
void MainWindow::showWebinterface()
{
WebuiPage::showWebui();

View file

@ -230,7 +230,7 @@ private slots:
void showMessengerWindow();
#endif
void showStatisticsWindow();
#ifdef ENABLE_WEBUI
#ifdef RS_WEBUI
void showWebinterface();
#endif
//void servicePermission();

View file

@ -32,141 +32,162 @@
JsonApiPage::JsonApiPage(QWidget */*parent*/, Qt::WindowFlags /*flags*/)
{
ui.setupUi(this);
connect( ui.addTokenPushButton, &QPushButton::clicked,
this, &JsonApiPage::addTokenClicked);
connect( ui.removeTokenPushButton, &QPushButton::clicked,
this, &JsonApiPage::removeTokenClicked );
connect( ui.tokensListView, &QListView::clicked,
this, &JsonApiPage::tokenClicked );
connect( ui.applyConfigPushButton, &QPushButton::clicked,
this, &JsonApiPage::onApplyClicked );
connect( ui.enableCheckBox, SIGNAL(toggled(bool)), this, SLOT(enableJsonApi(bool)));
connect( ui.addTokenPushButton, SIGNAL(clicked()), this, SLOT(addTokenClicked()));
connect( ui.removeTokenPushButton, SIGNAL(clicked()), this, SLOT(removeTokenClicked() ));
connect( ui.tokensListView, SIGNAL(clicked(const QModelIndex&)), this, SLOT(tokenClicked(const QModelIndex&) ));
connect( ui.applyConfigPushButton, SIGNAL(clicked()), this, SLOT(onApplyClicked() ));
connect( ui.portSpinBox, SIGNAL(valueChanged(int)), 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
QString anRange = "[a-zA-Z0-9]+";
QRegExp anRegex ("^" + anRange + ":" + anRange + "$");
QRegExpValidator *anValidator = new QRegExpValidator(anRegex, this);
ui.tokenLineEdit->setValidator(anValidator);
// This limits the possible tokens to alphanumeric
QString ipRange = "(?:[0-1]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])";
// You may want to use QRegularExpression for new code with Qt 5 (not mandatory).
QRegExp ipRegex ("^" + ipRange + "\\." + ipRange + "\\." + ipRange + "\\." + ipRange + "$");
QRegExpValidator *ipValidator = new QRegExpValidator(ipRegex, this);
ui.listenAddressLineEdit->setValidator(ipValidator);
}
bool JsonApiPage::updateParams(QString &errmsg)
void JsonApiPage::enableJsonApi(bool checked)
{
ui.addTokenPushButton->setEnabled(checked);
ui.applyConfigPushButton->setEnabled(checked);
ui.removeTokenPushButton->setEnabled(checked);
ui.tokensListView->setEnabled(checked);
ui.portSpinBox->setEnabled(checked);
ui.listenAddressLineEdit->setEnabled(checked);
Settings->setJsonApiEnabled(checked);
if(checked)
checkStartJsonApi();
else
checkShutdownJsonApi();
}
bool JsonApiPage::updateParams()
{
bool ok = true;
bool changed = false;
bool enabled = ui.enableCheckBox->isChecked();
if( enabled != Settings->getJsonApiEnabled())
{
Settings->setJsonApiEnabled(enabled);
changed = true;
}
uint16_t port = static_cast<uint16_t>(ui.portSpinBox->value());
if(port != Settings->getJsonApiPort())
{
Settings->setJsonApiPort(port);
changed = true;
}
QString listenAddress = ui.listenAddressLineEdit->text();
if(listenAddress != Settings->getJsonApiListenAddress())
{
Settings->setJsonApiListenAddress(listenAddress);
changed = true;
}
if(changed)
{
checkShutdownJsonApi();
ok = checkStartJsonApi();
}
Settings->setJsonApiEnabled(ui.enableCheckBox->isChecked());
Settings->setJsonApiPort(port);
Settings->setJsonApiListenAddress(listenAddress);
if(!ok) errmsg = "Could not start JSON API Server!";
return ok;
}
void JsonApiPage::load()
{
whileBlocking(ui.enableCheckBox)->setChecked(Settings->getJsonApiEnabled());
whileBlocking(ui.portSpinBox)->setValue(Settings->getJsonApiPort());
whileBlocking(ui.listenAddressLineEdit)->setText(Settings->getJsonApiListenAddress());
whileBlocking(ui.tokensListView)->setModel(new QStringListModel(Settings->getJsonApiAuthTokens()));
whileBlocking(ui.enableCheckBox)->setChecked(Settings->getJsonApiEnabled());
QStringList newTk;
for(const auto& it : rsJsonApi->getAuthorizedTokens())
newTk.push_back(
QString::fromStdString(it.first) + ":" +
QString::fromStdString(it.second) );
whileBlocking(ui.tokensListView)->setModel(new QStringListModel(newTk));
}
QString JsonApiPage::helpText() const { return ""; }
/*static*/ bool JsonApiPage::checkStartJsonApi()
bool JsonApiPage::checkStartJsonApi()
{
checkShutdownJsonApi();
if(!Settings->getJsonApiEnabled())
return false;
if(Settings->getJsonApiEnabled())
{
jsonApiServer = new JsonApiServer(
Settings->getJsonApiPort(),
Settings->getJsonApiListenAddress().toStdString() );
jsonApiServer->start("jsonApiServer");
for(const QString& token : Settings->getJsonApiAuthTokens())
jsonApiServer->authorizeToken(token.toStdString());
}
rsJsonApi->setListeningPort(Settings->getJsonApiPort());
rsJsonApi->setBindingAddress(Settings->getJsonApiListenAddress().toStdString());
rsJsonApi->restart();
return true;
}
/*static*/ void JsonApiPage::checkShutdownJsonApi()
{
if(jsonApiServer)
{
/* It is important to make a copy of +jsonApiServer+ pointer so the old
* object can be deleted later, while the original pointer is
* reassigned */
JsonApiServer* oldJsonApiServer = jsonApiServer;
jsonApiServer = nullptr;
oldJsonApiServer->shutdown();
QProgressDialog* pd = new QProgressDialog(
"Stopping JSON API Server", QString(), 0, 3000);
QTimer* prtm = new QTimer;
prtm->setInterval(16); // 60 FPS
connect( prtm, &QTimer::timeout,
pd, [=](){pd->setValue(pd->value()+16);} );
pd->show();
prtm->start();
/* Must wait for deletion because stopping of the server is async.
* It is important to capture a copy so it "survive" after
* safeStopJsonApiServer returns */
QTimer::singleShot(3*1000, [=]()
{
delete oldJsonApiServer;
prtm->stop();
pd->close();
prtm->deleteLater();
pd->deleteLater();
});
}
if(!rsJsonApi->isRunning()) return;
rsJsonApi->fullstop(); // this is a blocks until the thread is terminated.
}
void JsonApiPage::onApplyClicked(bool)
void JsonApiPage::onApplyClicked()
{
QString errmsg;
updateParams(errmsg);
// restart
checkShutdownJsonApi();
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());
if(jsonApiServer) jsonApiServer->authorizeToken(token.toStdString());
QStringList newTk(Settings->getJsonApiAuthTokens());
newTk.removeAll(token);
newTk.append(token);
Settings->setJsonApiAuthTokens(newTk);
std::string user,passwd;
if(!RsJsonApi::parseToken(token.toStdString(),user,passwd)) return;
rsJsonApi->authorizeUser(user,passwd);
QStringList newTk;
for(const auto& it : rsJsonApi->getAuthorizedTokens())
newTk.push_back(
QString::fromStdString(it.first) + ":" +
QString::fromStdString(it.second) );
whileBlocking(ui.tokensListView)->setModel(new QStringListModel(newTk));
}
void JsonApiPage::removeTokenClicked(bool)
void JsonApiPage::removeTokenClicked()
{
QString token(ui.tokenLineEdit->text());
if(jsonApiServer) jsonApiServer->revokeAuthToken(token.toStdString());
QStringList newTk(Settings->getJsonApiAuthTokens());
newTk.removeAll(token);
Settings->setJsonApiAuthTokens(newTk);
whileBlocking(ui.tokensListView)->setModel(
new QStringListModel(Settings->getJsonApiAuthTokens()) );
rsJsonApi->revokeAuthToken(token.toStdString());
QStringList newTk;
for(const auto& it : rsJsonApi->getAuthorizedTokens())
newTk.push_back(
QString::fromStdString(it.first) + ":" +
QString::fromStdString(it.second) );
whileBlocking(ui.tokensListView)->setModel(new QStringListModel(Settings->getJsonApiAuthTokens()) );
}
void JsonApiPage::tokenClicked(const QModelIndex& index)

View file

@ -33,7 +33,6 @@ public:
~JsonApiPage() {}
/** Loads the settings for this page */
virtual void load();
virtual QPixmap iconPixmap() const
{ return QPixmap(":/icons/svg/empty-circle.svg"); }
@ -49,13 +48,16 @@ public:
static void checkShutdownJsonApi();
public slots:
void onApplyClicked(bool);
void addTokenClicked(bool);
void removeTokenClicked(bool);
void load() override;
void onApplyClicked();
void addTokenClicked();
void removeTokenClicked();
void tokenClicked(const QModelIndex& index);
void enableJsonApi(bool checked);
bool updateParams();
void checkToken(QString);
private:
Ui::JsonApiPage ui; /// Qt Designer generated object
bool updateParams(QString &errmsg);
};

View file

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>521</width>
<height>393</height>
<width>545</width>
<height>569</height>
</rect>
</property>
<property name="windowTitle">
@ -87,7 +87,7 @@
<item>
<widget class="QLineEdit" name="tokenLineEdit">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;ApiUser:ApiPassword&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Tokens should spell as &amp;quot;user:password&amp;quot; where both user and password are alphanumeric strings.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
@ -123,7 +123,7 @@
<item>
<widget class="QPushButton" name="applyConfigPushButton">
<property name="text">
<string>Restart JSON API Server to apply settings</string>
<string>Apply settings</string>
</property>
</widget>
</item>

View file

@ -27,11 +27,8 @@
#include <QSpinBox>
#include "util/misc.h"
#include "api/ApiServer.h"
#include "api/ApiServerMHD.h"
#include "api/ApiServerLocal.h"
#include "api/RsControlModule.h"
#include "api/GetPluginInterfaces.h"
#include "retroshare/rswebui.h"
#include "retroshare/rsjsonapi.h"
#include "rsharesettings.h"
@ -48,9 +45,11 @@ WebuiPage::WebuiPage(QWidget */*parent*/, Qt::WindowFlags /*flags*/)
{
ui.setupUi(this);
connect(ui.enableWebUI_CB, SIGNAL(clicked(bool)), this, SLOT(onEnableCBClicked(bool)));
connect(ui.port_SB, SIGNAL(valueChanged(int)), this, SLOT(onPortValueChanged(int)));
connect(ui.allIp_CB, SIGNAL(clicked(bool)), this, SLOT(onAllIPCBClicked(bool)));
connect(ui.applyStartBrowser_PB, SIGNAL(clicked()), this, SLOT(onApplyClicked()));
connect(ui.apply_PB, SIGNAL(clicked()), this, SLOT(onApplyClicked()));
connect(ui.password_LE, SIGNAL(textChanged(QString)), this, SLOT(onPasswordValueChanged(QString)));
connect(ui.startWebBrowser_PB, SIGNAL(clicked()), this, SLOT(onStartWebBrowserClicked()));
connect(ui.webInterfaceFilesDirectory_PB, SIGNAL(clicked()), this, SLOT(selectWebInterfaceDirectory()));
}
WebuiPage::~WebuiPage()
@ -58,6 +57,16 @@ WebuiPage::~WebuiPage()
}
void WebuiPage::selectWebInterfaceDirectory()
{
QString dirname = QFileDialog::getExistingDirectory(NULL,tr("Please select the directory were to find retroshare webinterface files"),ui.webInterfaceFiles_LE->text());
if(dirname.isNull())
return;
whileBlocking(ui.webInterfaceFiles_LE)->setText(dirname);
}
bool WebuiPage::updateParams(QString &errmsg)
{
std::cerr << "WebuiPage::save()" << std::endl;
@ -65,35 +74,58 @@ bool WebuiPage::updateParams(QString &errmsg)
bool changed = false;
if(ui.enableWebUI_CB->isChecked() != Settings->getWebinterfaceEnabled())
changed = true;
if(ui.port_SB->value() != Settings->getWebinterfacePort())
changed = true;
if(ui.allIp_CB->isChecked() != Settings->getWebinterfaceAllowAllIps())
if(ui.webInterfaceFiles_LE->text() != Settings->getWebinterfaceFilesDirectory())
changed = true;
if(changed)
{
// store config
Settings->setWebinterfaceEnabled(ui.enableWebUI_CB->isChecked());
Settings->setWebinterfacePort(ui.port_SB->value());
Settings->setWebinterfaceAllowAllIps(ui.allIp_CB->isChecked());
// apply config
checkShutdownWebui();
ok = checkStartWebui();
Settings->setWebinterfaceFilesDirectory(ui.webInterfaceFiles_LE->text());
}
if(!ok)
errmsg = "Could not start webinterface.";
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()
{
return checkStartWebui();
}
void WebuiPage::load()
{
std::cerr << "WebuiPage::load()" << std::endl;
whileBlocking(ui.enableWebUI_CB)->setChecked(Settings->getWebinterfaceEnabled());
whileBlocking(ui.port_SB)->setValue(Settings->getWebinterfacePort());
whileBlocking(ui.allIp_CB)->setChecked(Settings->getWebinterfaceAllowAllIps());
onEnableCBClicked(Settings->getWebinterfaceEnabled());
whileBlocking(ui.webInterfaceFiles_LE)->setText(Settings->getWebinterfaceFilesDirectory());
#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
}
QString WebuiPage::helpText() const
{
return tr("<h1><img width=\"24\" src=\":/icons/help_64.png\">&nbsp;&nbsp;Webinterface</h1> \
@ -104,58 +136,29 @@ QString WebuiPage::helpText() const
/*static*/ bool WebuiPage::checkStartWebui()
{
if(!Settings->getWebinterfaceEnabled())
return true;
if(apiServer || apiServerMHD || controlModule)
return true;
return false;
apiServer = new resource_api::ApiServer();
controlModule = new resource_api::RsControlModule(0, 0, apiServer->getStateTokenServer(), apiServer, false);
apiServer->addResourceHandler("control", dynamic_cast<resource_api::ResourceRouter*>(controlModule), &resource_api::RsControlModule::handleRequest);
rsWebUI->setHtmlFilesDirectory(Settings->getWebinterfaceFilesDirectory().toStdString());
rsWebUI->restart();
RsPlugInInterfaces ifaces;
resource_api::getPluginInterfaces(ifaces);
apiServer->loadMainModules(ifaces);
apiServerMHD = new resource_api::ApiServerMHD(apiServer);
bool ok = apiServerMHD->configure(resource_api::getDefaultDocroot(),
Settings->getWebinterfacePort(),
"",
Settings->getWebinterfaceAllowAllIps());
apiServerMHD->start();
// TODO: LIBRESAPI_LOCAL_SERVER Move in appropriate place
#ifdef LIBRESAPI_LOCAL_SERVER
apiServerLocal = new resource_api::ApiServerLocal(apiServer, resource_api::ApiServerLocal::serverPath());
#endif
return ok;
return true;
}
/*static*/ void WebuiPage::checkShutdownWebui()
{
if(apiServer || apiServerMHD)
{
apiServerMHD->stop();
delete apiServerMHD;
apiServerMHD = 0;
// TODO: LIBRESAPI_LOCAL_SERVER Move in appropriate place
#ifdef LIBRESAPI_LOCAL_SERVER
delete apiServerLocal;
apiServerLocal = 0;
#endif
delete apiServer;
apiServer = 0;
delete controlModule;
controlModule = 0;
}
rsWebUI->stop();
}
/*static*/ void WebuiPage::showWebui()
{
if(Settings->getWebinterfaceEnabled())
{
QDesktopServices::openUrl(QUrl(QString("http://localhost:")+QString::number(Settings->getWebinterfacePort())));
}
if(Settings->getWebinterfaceEnabled())
{
QUrl webuiUrl;
webuiUrl.setScheme("http");
webuiUrl.setHost(QString::fromStdString(rsJsonApi->getBindingAddress()));
webuiUrl.setPort(rsJsonApi->listeningPort());
QDesktopServices::openUrl(webuiUrl);
}
else
{
QMessageBox::warning(0, tr("Webinterface not enabled"), tr("The webinterface is not enabled. Enable it in Settings -> Webinterface."));
@ -165,9 +168,16 @@ QString WebuiPage::helpText() const
void WebuiPage::onEnableCBClicked(bool checked)
{
ui.params_GB->setEnabled(checked);
ui.applyStartBrowser_PB->setEnabled(checked);
ui.apply_PB->setEnabled(checked);
ui.startWebBrowser_PB->setEnabled(checked);
QString S;
updateParams(S);
Settings->setWebinterfaceEnabled(checked);
if(checked)
checkStartWebui();
else
checkShutdownWebui();
}
void WebuiPage::onPortValueChanged(int /*value*/)
@ -181,15 +191,17 @@ void WebuiPage::onAllIPCBClicked(bool /*checked*/)
QString S;
updateParams(S);
}
void WebuiPage::onApplyClicked()
{
QString errmsg;
bool ok = updateParams(errmsg);
if(!ok)
rsWebUI->setUserPassword(ui.password_LE->text().toStdString());
if(!restart())
{
QMessageBox::warning(0, tr("failed to start Webinterface"), "Failed to start the webinterface.");
return;
}
QDesktopServices::openUrl(QUrl(QString("http://localhost:")+QString::number(ui.port_SB->value())));
emit passwordChanged();
}
void WebuiPage::onStartWebBrowserClicked() { showWebui(); }

View file

@ -58,15 +58,22 @@ public:
static void showWebui();
public slots:
void selectWebInterfaceDirectory();
void onEnableCBClicked(bool checked);
void onPortValueChanged(int value);
void onPasswordValueChanged(QString password);
void onAllIPCBClicked(bool checked);
void onApplyClicked();
void onStartWebBrowserClicked();
signals:
void passwordChanged();
private:
/** Qt Designer generated object */
Ui::WebuiPage ui;
bool restart();
bool updateParams(QString &errmsg);
static resource_api::ApiServer* apiServer;

View file

@ -6,14 +6,14 @@
<rect>
<x>0</x>
<y>0</y>
<width>497</width>
<height>404</height>
<width>960</width>
<height>717</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="WebuiPageVLayout">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QCheckBox" name="enableWebUI_CB">
<property name="text">
@ -29,26 +29,62 @@
<property name="title">
<string>Web parameters</string>
</property>
<layout class="QGridLayout" name="params_GBGLayout">
<item row="0" column="1">
<widget class="QSpinBox" name="port_SB">
<property name="minimum">
<number>1024</number>
</property>
<property name="maximum">
<number>65535</number>
</property>
</widget>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Password:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Web interface directory:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="password_LE">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLineEdit" name="webInterfaceFiles_LE">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="webInterfaceFilesDirectory_PB">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Select directory for webinterface files (advanced)&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/folder-draft24-pressed.png</normaloff>:/images/folder-draft24-pressed.png</iconset>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item row="0" column="0">
<widget class="QLabel" name="port_Label">
<property name="text">
<string>Port:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<item>
<widget class="QCheckBox" name="allIp_CB">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Allow access from all IP addresses (Default: localhost only)</string>
</property>
@ -58,16 +94,27 @@
</widget>
</item>
<item>
<widget class="QPushButton" name="applyStartBrowser_PB">
<property name="text">
<string>Apply setting and start browser</string>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="apply_PB">
<property name="text">
<string>Apply settings</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="startWebBrowser_PB">
<property name="text">
<string>Start web browser</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="noteLabel">
<property name="text">
<string>Note: these settings do not affect retroshare-nogui. Retroshare-nogui has a command line switch to activate the web interface.</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Note: these settings do not affect retroshare-service, which has a command line switch to activate the web interface and select the listening port.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="wordWrap">
<bool>true</bool>
@ -89,6 +136,8 @@
</item>
</layout>
</widget>
<resources/>
<resources>
<include location="../images.qrc"/>
</resources>
<connections/>
</ui>

View file

@ -44,7 +44,7 @@
#include "gui/common/FloatingHelpBrowser.h"
#include "gui/common/RSElidedItemDelegate.h"
#ifdef ENABLE_WEBUI
#ifdef RS_WEBUI
# include "WebuiPage.h"
#endif
@ -164,12 +164,15 @@ SettingsPage::initStackedWidget()
addPage(new AppearancePage()); // APPEARENCE
addPage(new SoundPage() ); // SOUND
addPage(new ServicePermissionsPage() ); // PERMISSIONS
#ifdef ENABLE_WEBUI
addPage(new WebuiPage() );
#endif // ENABLE_WEBUI
#ifdef RS_JSONAPI
JsonApiPage *jsonapi_p = 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
// add widgets from plugins

View file

@ -30,6 +30,9 @@
#include "rsharesettings.h"
#include "gui/MainWindow.h"
// for this one, we'd rather use a file in retroshare/*h list.
#include <jsonapi/jsonapi.h>
#include <retroshare/rsnotify.h>
#include <retroshare/rspeers.h>
@ -1150,25 +1153,19 @@ void RshareSettings::setWebinterfaceEnabled(bool enabled)
setValueToGroup("Webinterface", "enabled", enabled);
}
uint16_t RshareSettings::getWebinterfacePort()
QString RshareSettings::getWebinterfaceFilesDirectory()
{
return valueFromGroup("Webinterface", "port", 9090).toUInt();
#ifdef WINDOWS_SYS
return valueFromGroup("Webinterface","directory","data/webui/").toString().toStdString();
#endif
return valueFromGroup("Webinterface","directory","/usr/share/retroshare/webui/").toString();
}
void RshareSettings::setWebinterfacePort(uint16_t port)
void RshareSettings::setWebinterfaceFilesDirectory(const QString& s)
{
setValueToGroup("Webinterface", "port", port);
setValueToGroup("Webinterface","directory",s);
}
bool RshareSettings::getWebinterfaceAllowAllIps()
{
return valueFromGroup("Webinterface", "allowAllIps", false).toBool();
}
void RshareSettings::setWebinterfaceAllowAllIps(bool allow_all)
{
setValueToGroup("Webinterface", "allowAllIps", allow_all);
}
bool RshareSettings::getPageAlreadyDisplayed(const QString& page_name)
{
@ -1194,7 +1191,7 @@ void RshareSettings::setJsonApiEnabled(bool enabled)
uint16_t RshareSettings::getJsonApiPort()
{
return valueFromGroup("JsonApi", "port", 9092).toUInt();
return valueFromGroup("JsonApi", "port", JsonApiServer::DEFAULT_PORT).toUInt();
}
void RshareSettings::setJsonApiPort(uint16_t port)

View file

@ -331,12 +331,9 @@ public:
bool getWebinterfaceEnabled();
void setWebinterfaceEnabled(bool enabled);
uint16_t getWebinterfacePort();
void setWebinterfacePort(uint16_t port);
QString getWebinterfaceFilesDirectory();
void setWebinterfaceFilesDirectory(const QString& dirname);
bool getWebinterfaceAllowAllIps();
void setWebinterfaceAllowAllIps(bool allow_all);
// proxy function that computes the best icon size among sizes passed as array, to match the recommended size on screen.
int computeBestIconSize(int n_sizes, int *sizes, int recommended_size);

View file

@ -56,7 +56,7 @@ CrashStackTrace gCrashStackTrace;
#ifdef MESSENGER_WINDOW
#include "gui/MessengerWindow.h"
#endif
#ifdef ENABLE_WEBUI
#ifdef RS_WEBUI
# include "gui/settings/WebuiPage.h"
#endif
@ -233,8 +233,6 @@ feenableexcept(FE_INVALID | FE_DIVBYZERO);
RsConfigOptions conf;
conf.jsonApiPort = 0 ; // disable JSon API at start. The JSonAPI preference UI will enable it according to saved parameters.
argstream as(argc,argv);
as >> option('s',"stderr" ,conf.outStderr ,"output to stderr instead of log file." )
>> option('u',"udp" ,conf.udpListenerOnly,"Only listen to UDP." )
@ -574,14 +572,14 @@ feenableexcept(FE_INVALID | FE_DIVBYZERO);
notify->enable() ; // enable notification system after GUI creation, to avoid data races in Qt.
#ifdef ENABLE_WEBUI
WebuiPage::checkStartWebui();
#endif // ENABLE_WEBUI
#ifdef RS_JSONAPI
JsonApiPage::checkStartJsonApi();
#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
// passphrase here makes it request for a passphrase when creating the default chat identity.
@ -595,10 +593,6 @@ feenableexcept(FE_INVALID | FE_DIVBYZERO);
JsonApiPage::checkShutdownJsonApi();
#endif // RS_JSONAPI
#ifdef ENABLE_WEBUI
WebuiPage::checkShutdownWebui();
#endif // ENABLE_WEBUI
/* cleanup */
ChatDialog::cleanupChat();
#ifdef RS_ENABLE_GXS

View file

@ -28,13 +28,12 @@ DEFINES += TARGET=\\\"$${TARGET}\\\"
DEPENDPATH *= $${PWD} $${RS_INCLUDE_DIR} retroshare-gui
INCLUDEPATH *= $${PWD} retroshare-gui
libresapihttpserver {
!include("../../libresapi/src/use_libresapi.pri"):error("Including")
!include("../../libretroshare/src/use_libretroshare.pri"):error("Including")
rs_webui {
HEADERS *= gui/settings/WebuiPage.h
SOURCES *= gui/settings/WebuiPage.cpp
FORMS *= gui/settings/WebuiPage.ui
} else {
!include("../../libretroshare/src/use_libretroshare.pri"):error("Including")
}
rs_jsonapi {
@ -273,9 +272,9 @@ macx {
mac_icon.files = $$files($$PWD/rsMacIcon.icns)
mac_icon.path = Contents/Resources
QMAKE_BUNDLE_DATA += mac_icon
mac_webui.files = $$files($$PWD/../../libresapi/src/webui)
mac_webui.path = Contents/Resources
QMAKE_BUNDLE_DATA += mac_webui
# mac_webui.files = $$files($$PWD/../../libresapi/src/webui)
# mac_webui.path = Contents/Resources
# QMAKE_BUNDLE_DATA += mac_webui
CONFIG += version_detail_bash_script
LIBS += -lssl -lcrypto -lz