mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-12 07:59:29 -05:00
fixed a few bugs. First running version.
This commit is contained in:
parent
0103a741d6
commit
3446f0b677
@ -47,6 +47,13 @@ static constexpr char *mime_types[3] = {
|
|||||||
"image/svg+xml"
|
"image/svg+xml"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifdef WINDOWS_SYS
|
||||||
|
static std::string _base_directory = "data/webui";
|
||||||
|
#else
|
||||||
|
static std::string _base_directory = "/usr/share/retroshare/webui/";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
template<int MIME_TYPE_INDEX> class handler
|
template<int MIME_TYPE_INDEX> class handler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -79,16 +86,8 @@ template<int MIME_TYPE_INDEX> class handler
|
|||||||
session->close( restbed::NOT_FOUND );
|
session->close( restbed::NOT_FOUND );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string _base_directory ;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef WINDOWS_SYS
|
|
||||||
template<int MIME_TYPE_INDEX> std::string handler<MIME_TYPE_INDEX>::_base_directory = "data/webui";
|
|
||||||
#else
|
|
||||||
template<int MIME_TYPE_INDEX> std::string handler<MIME_TYPE_INDEX>::_base_directory = "/usr/share/retroshare/webui/";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static void service_ready_handler( restbed::Service& )
|
static void service_ready_handler( restbed::Service& )
|
||||||
{
|
{
|
||||||
fprintf( stderr, "Hey! The service is up and running." );
|
fprintf( stderr, "Hey! The service is up and running." );
|
||||||
@ -100,7 +99,7 @@ public:
|
|||||||
WebUIThread()
|
WebUIThread()
|
||||||
{
|
{
|
||||||
_service = std::make_shared<restbed::Service>();
|
_service = std::make_shared<restbed::Service>();
|
||||||
|
_listening_port = 1984;
|
||||||
}
|
}
|
||||||
|
|
||||||
void runloop() override
|
void runloop() override
|
||||||
@ -128,7 +127,7 @@ public:
|
|||||||
resource3->set_method_handler( "GET", handler<TEXT_SVG>::get_handler );
|
resource3->set_method_handler( "GET", handler<TEXT_SVG>::get_handler );
|
||||||
|
|
||||||
auto settings = std::make_shared< restbed::Settings >( );
|
auto settings = std::make_shared< restbed::Settings >( );
|
||||||
settings->set_port( 1984 );
|
settings->set_port( _listening_port );
|
||||||
settings->set_default_header( "Connection", "close" );
|
settings->set_default_header( "Connection", "close" );
|
||||||
|
|
||||||
_service->publish( resource1 );
|
_service->publish( resource1 );
|
||||||
@ -136,7 +135,16 @@ public:
|
|||||||
_service->publish( resource3 );
|
_service->publish( resource3 );
|
||||||
|
|
||||||
_service->set_ready_handler( service_ready_handler );
|
_service->set_ready_handler( service_ready_handler );
|
||||||
_service->start( settings );
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_service->start( settings );
|
||||||
|
}
|
||||||
|
catch(std::exception& e)
|
||||||
|
{
|
||||||
|
RsErr() << "Could not start web interface: " << e.what() << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
void stop()
|
void stop()
|
||||||
{
|
{
|
||||||
@ -148,8 +156,12 @@ public:
|
|||||||
sleep(1);
|
sleep(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setListeningPort(uint16_t p) { _listening_port = p ; }
|
||||||
|
uint16_t listeningPort() const { return _listening_port;}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<restbed::Service> _service;
|
std::shared_ptr<restbed::Service> _service;
|
||||||
|
uint16_t _listening_port;
|
||||||
};
|
};
|
||||||
|
|
||||||
p3WebUI::p3WebUI()
|
p3WebUI::p3WebUI()
|
||||||
@ -169,7 +181,7 @@ p3WebUI::~p3WebUI()
|
|||||||
|
|
||||||
bool p3WebUI::restart()
|
bool p3WebUI::restart()
|
||||||
{
|
{
|
||||||
RsDbg() << "Restarting web interface listening on port " << _listening_port << std::endl;
|
RsDbg() << "Restarting web interface listening on port " << _webui_thread->listeningPort() << std::endl;
|
||||||
|
|
||||||
if(_webui_thread->isRunning())
|
if(_webui_thread->isRunning())
|
||||||
_webui_thread->stop();
|
_webui_thread->stop();
|
||||||
@ -186,11 +198,11 @@ bool p3WebUI::stop()
|
|||||||
|
|
||||||
void p3WebUI::setHtmlFilesDirectory(const std::string& html_dir)
|
void p3WebUI::setHtmlFilesDirectory(const std::string& html_dir)
|
||||||
{
|
{
|
||||||
_html_files_directory = html_dir;
|
_base_directory = html_dir;
|
||||||
}
|
}
|
||||||
void p3WebUI::setListeningPort(uint16_t port)
|
void p3WebUI::setListeningPort(uint16_t port)
|
||||||
{
|
{
|
||||||
_listening_port = port;
|
_webui_thread->setListeningPort(port);
|
||||||
|
|
||||||
if(_webui_thread->isRunning())
|
if(_webui_thread->isRunning())
|
||||||
restart();
|
restart();
|
||||||
|
@ -41,9 +41,6 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
WebUIThread *_webui_thread;
|
WebUIThread *_webui_thread;
|
||||||
|
|
||||||
std::string _html_files_directory;
|
|
||||||
uint16_t _listening_port;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ WebuiPage::WebuiPage(QWidget */*parent*/, Qt::WindowFlags /*flags*/)
|
|||||||
connect(ui.port_SB, SIGNAL(valueChanged(int)), this, SLOT(onPortValueChanged(int)));
|
connect(ui.port_SB, SIGNAL(valueChanged(int)), this, SLOT(onPortValueChanged(int)));
|
||||||
connect(ui.allIp_CB, SIGNAL(clicked(bool)), this, SLOT(onAllIPCBClicked(bool)));
|
connect(ui.allIp_CB, SIGNAL(clicked(bool)), this, SLOT(onAllIPCBClicked(bool)));
|
||||||
connect(ui.applyStartBrowser_PB, SIGNAL(clicked()), this, SLOT(onApplyClicked()));
|
connect(ui.applyStartBrowser_PB, SIGNAL(clicked()), this, SLOT(onApplyClicked()));
|
||||||
connect(ui.webInterfaceFiles_LE, SIGNAL(clicked()), this, SLOT(selectWebInterfaceDirectory()));
|
connect(ui.webInterfaceFilesDirectory_PB, SIGNAL(clicked()), this, SLOT(selectWebInterfaceDirectory()));
|
||||||
}
|
}
|
||||||
|
|
||||||
WebuiPage::~WebuiPage()
|
WebuiPage::~WebuiPage()
|
||||||
@ -58,6 +58,11 @@ WebuiPage::~WebuiPage()
|
|||||||
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());
|
||||||
|
|
||||||
|
if(dirname.isNull())
|
||||||
|
return;
|
||||||
|
|
||||||
|
whileBlocking(ui.webInterfaceFiles_LE)->setText(dirname);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WebuiPage::updateParams(QString &errmsg)
|
bool WebuiPage::updateParams(QString &errmsg)
|
||||||
@ -71,12 +76,16 @@ bool WebuiPage::updateParams(QString &errmsg)
|
|||||||
changed = true;
|
changed = true;
|
||||||
if(ui.allIp_CB->isChecked() != Settings->getWebinterfaceAllowAllIps())
|
if(ui.allIp_CB->isChecked() != Settings->getWebinterfaceAllowAllIps())
|
||||||
changed = true;
|
changed = true;
|
||||||
|
if(ui.webInterfaceFiles_LE->text() != Settings->getWebinterfaceFilesDirectory())
|
||||||
|
changed = true;
|
||||||
|
|
||||||
if(changed)
|
if(changed)
|
||||||
{
|
{
|
||||||
// store config
|
// store config
|
||||||
Settings->setWebinterfaceEnabled(ui.enableWebUI_CB->isChecked());
|
Settings->setWebinterfaceEnabled(ui.enableWebUI_CB->isChecked());
|
||||||
Settings->setWebinterfacePort(ui.port_SB->value());
|
Settings->setWebinterfacePort(ui.port_SB->value());
|
||||||
Settings->setWebinterfaceAllowAllIps(ui.allIp_CB->isChecked());
|
Settings->setWebinterfaceAllowAllIps(ui.allIp_CB->isChecked());
|
||||||
|
Settings->setWebinterfaceFilesDirectory(ui.webInterfaceFiles_LE->text());
|
||||||
|
|
||||||
// apply config
|
// apply config
|
||||||
checkShutdownWebui();
|
checkShutdownWebui();
|
||||||
|
@ -60,7 +60,29 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
<item row="1" column="1">
|
||||||
<widget class="QLineEdit" name="webInterfaceFiles_LE"/>
|
<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><html><head/><body><p>Select directory for webinterface files (advanced)</p></body></html></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>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
@ -106,6 +128,8 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources>
|
||||||
|
<include location="../images.qrc"/>
|
||||||
|
</resources>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
@ -1150,11 +1150,6 @@ void RshareSettings::setWebinterfaceEnabled(bool enabled)
|
|||||||
setValueToGroup("Webinterface", "enabled", enabled);
|
setValueToGroup("Webinterface", "enabled", enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t RshareSettings::getWebinterfacePort()
|
|
||||||
{
|
|
||||||
return valueFromGroup("Webinterface", "port", 1984).toUInt();
|
|
||||||
}
|
|
||||||
|
|
||||||
QString RshareSettings::getWebinterfaceFilesDirectory()
|
QString RshareSettings::getWebinterfaceFilesDirectory()
|
||||||
{
|
{
|
||||||
#ifdef WINDOWS_SYS
|
#ifdef WINDOWS_SYS
|
||||||
@ -1163,6 +1158,17 @@ QString RshareSettings::getWebinterfaceFilesDirectory()
|
|||||||
return valueFromGroup("Webinterface","directory","/usr/share/retroshare/webui/").toString();
|
return valueFromGroup("Webinterface","directory","/usr/share/retroshare/webui/").toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RshareSettings::setWebinterfaceFilesDirectory(const QString& s)
|
||||||
|
{
|
||||||
|
setValueToGroup("Webinterface","directory",s);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint16_t RshareSettings::getWebinterfacePort()
|
||||||
|
{
|
||||||
|
return valueFromGroup("Webinterface", "port", 1984).toUInt();
|
||||||
|
}
|
||||||
|
|
||||||
void RshareSettings::setWebinterfacePort(uint16_t port)
|
void RshareSettings::setWebinterfacePort(uint16_t port)
|
||||||
{
|
{
|
||||||
setValueToGroup("Webinterface", "port", port);
|
setValueToGroup("Webinterface", "port", port);
|
||||||
|
Loading…
Reference in New Issue
Block a user