code to embed webUI server in the main executable (initial version, not yet working)

This commit is contained in:
csoler 2019-11-10 17:38:16 +01:00
parent aabba04be9
commit 6603dbd913
No known key found for this signature in database
GPG key ID: 7BCA522266C0804C
17 changed files with 355 additions and 111 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
@ -605,9 +605,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_DHT), tr("Statistics"), this, SLOT(showStatisticsWindow()));
@ -1116,7 +1116,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

@ -27,11 +27,7 @@
#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 "rsharesettings.h"
@ -51,6 +47,7 @@ WebuiPage::WebuiPage(QWidget */*parent*/, Qt::WindowFlags /*flags*/)
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.webInterfaceFiles_LE, SIGNAL(clicked()), this, SLOT(selectWebInterfaceDirectory()));
}
WebuiPage::~WebuiPage()
@ -58,6 +55,11 @@ 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());
}
bool WebuiPage::updateParams(QString &errmsg)
{
std::cerr << "WebuiPage::save()" << std::endl;
@ -90,6 +92,7 @@ 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.webInterfaceFiles_LE)->setText(Settings->getWebinterfaceFilesDirectory());
whileBlocking(ui.allIp_CB)->setChecked(Settings->getWebinterfaceAllowAllIps());
onEnableCBClicked(Settings->getWebinterfaceEnabled());
}
@ -105,49 +108,18 @@ QString WebuiPage::helpText() const
{
if(!Settings->getWebinterfaceEnabled())
return true;
if(apiServer || apiServerMHD || controlModule)
return true;
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->setListeningPort(Settings->getWebinterfacePort());
rsWebUI->setHtmlFilesDirectory(Settings->getWebinterfaceFilesDirectory().toStdString());
RsPlugInInterfaces ifaces;
resource_api::getPluginInterfaces(ifaces);
apiServer->loadMainModules(ifaces);
rsWebUI->restart();
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()

View file

@ -58,6 +58,7 @@ public:
static void showWebui();
public slots:
void selectWebInterfaceDirectory();
void onEnableCBClicked(bool checked);
void onPortValueChanged(int value);
void onAllIPCBClicked(bool checked);

View file

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>497</width>
<height>404</height>
<width>960</width>
<height>717</height>
</rect>
</property>
<property name="windowTitle">
@ -29,25 +29,42 @@
<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="port_Label">
<property name="text">
<string>Listening port:</string>
</property>
</widget>
</item>
<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>
<property name="value">
<number>1984</number>
</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="1" column="1">
<widget class="QLineEdit" name="webInterfaceFiles_LE"/>
</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="text">
<string>Allow access from all IP addresses (Default: localhost only)</string>
@ -67,7 +84,7 @@
<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>

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,9 +164,9 @@ SettingsPage::initStackedWidget()
addPage(new AppearancePage()); // APPEARENCE
addPage(new SoundPage() ); // SOUND
addPage(new ServicePermissionsPage() ); // PERMISSIONS
#ifdef ENABLE_WEBUI
#ifdef RS_WEBUI
addPage(new WebuiPage() );
#endif // ENABLE_WEBUI
#endif
#ifdef RS_JSONAPI
addPage(new JsonApiPage());

View file

@ -1152,7 +1152,15 @@ void RshareSettings::setWebinterfaceEnabled(bool enabled)
uint16_t RshareSettings::getWebinterfacePort()
{
return valueFromGroup("Webinterface", "port", 9090).toUInt();
return valueFromGroup("Webinterface", "port", 1984).toUInt();
}
QString RshareSettings::getWebinterfaceFilesDirectory()
{
#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)

View file

@ -334,6 +334,9 @@ public:
uint16_t getWebinterfacePort();
void setWebinterfacePort(uint16_t port);
QString getWebinterfaceFilesDirectory();
void setWebinterfaceFilesDirectory(const QString& dirname);
bool getWebinterfaceAllowAllIps();
void setWebinterfaceAllowAllIps(bool allow_all);

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
@ -574,7 +574,7 @@ feenableexcept(FE_INVALID | FE_DIVBYZERO);
notify->enable() ; // enable notification system after GUI creation, to avoid data races in Qt.
#ifdef ENABLE_WEBUI
#ifdef RS_WEBUI
WebuiPage::checkStartWebui();
#endif // ENABLE_WEBUI
@ -595,9 +595,9 @@ feenableexcept(FE_INVALID | FE_DIVBYZERO);
JsonApiPage::checkShutdownJsonApi();
#endif // RS_JSONAPI
#ifdef ENABLE_WEBUI
#ifdef RS_WEBUI
WebuiPage::checkShutdownWebui();
#endif // ENABLE_WEBUI
#endif
/* cleanup */
ChatDialog::cleanupChat();

View file

@ -28,7 +28,7 @@ DEFINES += TARGET=\\\"$${TARGET}\\\"
DEPENDPATH *= $${PWD} $${RS_INCLUDE_DIR} retroshare-gui
INCLUDEPATH *= $${PWD} retroshare-gui
libresapihttpserver {
rs_webui {
!include("../../libresapi/src/use_libresapi.pri"):error("Including")
HEADERS *= gui/settings/WebuiPage.h
SOURCES *= gui/settings/WebuiPage.cpp