Imported existing sources
This commit is contained in:
1 parent
5634a187a0
commit
3426433a22
26 files changed
+1011
No files matched your search
@@ -0,0 +1,121 @@
|
||||
#include <QCoreApplication>
|
||||
#include <QDir>
|
||||
#include <QLibrary>
|
||||
#include <QPluginLoader>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
#include <QDebug>
|
||||
|
||||
#include <stdexcept>
|
||||
#include <iterator>
|
||||
|
||||
#include "utils.h"
|
||||
#include "webplugin.h"
|
||||
#include "weblistener.h"
|
||||
#include "webapplication.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
QCoreApplication app(argc, argv);
|
||||
QCoreApplication::setApplicationName("webserver");
|
||||
|
||||
QHash<QString, WebPlugin*> plugins;
|
||||
|
||||
{
|
||||
QDir dir(QDir(QCoreApplication::applicationDirPath()).absoluteFilePath(QStringLiteral("plugins/") + QCoreApplication::applicationName()));
|
||||
for(const auto &fileInfo : dir.entryInfoList(QDir::Files | QDir::NoSymLinks))
|
||||
{
|
||||
if(!QLibrary::isLibrary(fileInfo.filePath()))
|
||||
{
|
||||
qWarning() << "skipping" << fileInfo.fileName() << "because no QLibrary";
|
||||
continue; // to skip windows junk files
|
||||
}
|
||||
|
||||
QPluginLoader pluginLoader(fileInfo.filePath());
|
||||
if(!pluginLoader.load())
|
||||
{
|
||||
qCritical() << "error loading plugin" << fileInfo.fileName() << "because" << pluginLoader.errorString();
|
||||
continue;
|
||||
}
|
||||
|
||||
if(auto plugin = qobject_cast<WebPlugin*>(pluginLoader.instance()))
|
||||
{
|
||||
const auto pluginName = plugin->pluginName();
|
||||
if(plugins.contains(pluginName))
|
||||
throw std::runtime_error(QString("duplicate plugin %0").arg(pluginName).toStdString());
|
||||
plugins.insert(pluginName, plugin);
|
||||
}
|
||||
else
|
||||
qCritical() << "plugin" << fileInfo.fileName() << "could not be casted to WebPlugin";
|
||||
}
|
||||
}
|
||||
|
||||
QHash<QString, WebApplication*> applications;
|
||||
|
||||
const auto configPath = QDir(QCoreApplication::applicationDirPath()).absoluteFilePath(QCoreApplication::applicationName() + QStringLiteral(".json"));
|
||||
const auto config = getJson<QJsonObject>(configPath);
|
||||
|
||||
if(!config.contains(QStringLiteral("applications")))
|
||||
throw std::runtime_error("settings does not contain a applications");
|
||||
|
||||
{
|
||||
const auto applicationsVal = config.value(QStringLiteral("applications"));
|
||||
if(!applicationsVal.isObject())
|
||||
throw std::runtime_error("applications is not a json object");
|
||||
|
||||
const auto applicationsList = applicationsVal.toObject();
|
||||
for(auto iter = applicationsList.constBegin(); iter != applicationsList.constEnd(); iter++)
|
||||
{
|
||||
const auto applicationVal = iter.value();
|
||||
if(!applicationVal.isObject())
|
||||
throw std::runtime_error(QString("application %0 is not a json object").arg(iter.key()).toStdString());
|
||||
|
||||
auto application = applicationVal.toObject();
|
||||
if(!application.contains(QStringLiteral("_pluginName")))
|
||||
throw std::runtime_error(QString("application %0 does not contain a _pluginName").arg(iter.key()).toStdString());
|
||||
|
||||
const auto pluginNameVal = application.take(QStringLiteral("_pluginName"));
|
||||
if(!pluginNameVal.isString())
|
||||
throw std::runtime_error(QString("application %0 pluginName is not a string").arg(iter.key()).toStdString());
|
||||
|
||||
auto pluginName = pluginNameVal.toString();
|
||||
|
||||
const auto pluginsIter = plugins.find(pluginName);
|
||||
if(pluginsIter == plugins.constEnd())
|
||||
throw std::runtime_error(QString("application %0 references not installed plugin %1").arg(iter.key(), pluginName).toStdString());
|
||||
|
||||
applications.insert(iter.key(), pluginsIter.value()->createApplication(application));
|
||||
}
|
||||
}
|
||||
|
||||
QList<WebListener*> listeners;
|
||||
|
||||
if(!config.contains(QStringLiteral("listeners")))
|
||||
throw std::runtime_error("settings does not contain a listeners");
|
||||
|
||||
{
|
||||
const auto listenersVal = config.value(QStringLiteral("listeners"));
|
||||
if(!listenersVal.isArray())
|
||||
throw std::runtime_error("listeners is not a json array");
|
||||
|
||||
const auto listenersList = listenersVal.toArray();
|
||||
for(auto iter = listenersList.constBegin(); iter != listenersList.constEnd(); iter++)
|
||||
{
|
||||
const auto listenerVal = *iter;
|
||||
if(!listenerVal.isObject())
|
||||
throw std::runtime_error(QString("listener %0 is not an object").arg(std::distance(listenersList.constBegin(), iter)).toStdString());
|
||||
|
||||
const auto listener = listenerVal.toObject();
|
||||
|
||||
listeners.append(new WebListener(listener, applications));
|
||||
}
|
||||
}
|
||||
|
||||
for(auto iter = applications.constBegin(); iter != applications.constEnd(); iter++)
|
||||
iter.value()->start();
|
||||
|
||||
for(auto listener : listeners)
|
||||
listener->start();
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
{
|
||||
"applications": {
|
||||
"Fallback": {
|
||||
"_pluginName": "fileserver",
|
||||
"rootPath": "htdocs/__fallback"
|
||||
},
|
||||
"HelloWorld": {
|
||||
"_pluginName": "helloworld"
|
||||
},
|
||||
"1000serien.com": {
|
||||
"_pluginName": "series",
|
||||
"mysql": {
|
||||
"hostname": "localhost",
|
||||
"username": "series",
|
||||
"password": "_stripped_",
|
||||
"database": "series"
|
||||
}
|
||||
},
|
||||
"cdn.1000serien.com": {
|
||||
"_pluginName": "fileserver",
|
||||
"rootPath": "/komposthaufen/multimedia/Videos"
|
||||
},
|
||||
"brunner.ninja": {
|
||||
"_pluginName": "fileserver",
|
||||
"rootPath": "htdocs/brunner.ninja"
|
||||
},
|
||||
"telegram.brunner.ninja": {
|
||||
"_pluginName": "fileserver",
|
||||
"rootPath": "htdocs/telegram.brunner.ninja/dist"
|
||||
},
|
||||
"transmission.brunner.ninja": {
|
||||
"_pluginName": "proxy",
|
||||
"url": "http://127.0.0.1:9091/"
|
||||
},
|
||||
"findtheinvisiblegspot.com": {
|
||||
"_pluginName": "fileserver",
|
||||
"rootPath": "htdocs/findtheinvisiblegspot.com"
|
||||
},
|
||||
"flucky.xyz": {
|
||||
"_pluginName": "fileserver",
|
||||
"rootPath": "htdocs/flucky.xyz"
|
||||
},
|
||||
"mail.flucky.xyz": {
|
||||
"_pluginName": "fileserver",
|
||||
"rootPath": "/etc/webapps/roundcubemail"
|
||||
},
|
||||
"phpmyadmin.flucky.xyz": {
|
||||
"_pluginName": "fileserver",
|
||||
"rootPath": "/usr/share/webapps/phpMyAdmin"
|
||||
},
|
||||
"localhorst.xyz": {
|
||||
"_pluginName": "fileserver",
|
||||
"rootPath": "htdocs/localhorst.xyz"
|
||||
},
|
||||
"maik-mahlow.de": {
|
||||
"_pluginName": "fileserver",
|
||||
"rootPath": "htdocs/maik-mahlow.de"
|
||||
},
|
||||
"WifiLamp": {
|
||||
"_pluginName": "wifilamp",
|
||||
"controlHostAdress": "QHostAddress::Any",
|
||||
"controlPort": 1234
|
||||
}
|
||||
},
|
||||
"listeners": [{
|
||||
"hostAddress": "QHostAddress::Any",
|
||||
"port": 8080,
|
||||
"vhosts": {
|
||||
"*": "Fallback",
|
||||
"1000serien.com": "1000serien.com",
|
||||
"www.1000serien.com": "1000serien.com",
|
||||
"cdn.1000serien.com": "cdn.1000serien.com",
|
||||
"brunner.ninja": "brunner.ninja",
|
||||
"www.brunner.ninja": "brunner.ninja",
|
||||
"telegram.brunner.ninja": "telegram.brunner.ninja",
|
||||
"transmission.brunner.ninja": "transmission.brunner.ninja",
|
||||
"findtheinvisiblegspot.com": "findtheinvisiblegspot.com",
|
||||
"www.findtheinvisiblegspot.com": "findtheinvisiblegspot.com",
|
||||
"flucky.xyz": "flucky.xyz",
|
||||
"www.flucky.xyz": "flucky.xyz",
|
||||
"mail.flucky.xyz": "mail.flucky.xyz",
|
||||
"phpmyadmin.flucky.xyz": "phpmyadmin.flucky.xyz",
|
||||
"localhorst.xyz": "localhorst.xyz",
|
||||
"www.localhorst.xyz": "localhorst.xyz",
|
||||
"maik-mahlow.de": "maik-mahlow.de",
|
||||
"www.maik-mahlow.de": "maik-mahlow.de",
|
||||
"flucky-server": "HelloWorld",
|
||||
"192.168.0.2": "HelloWorld",
|
||||
"lampen": "WifiLamp"
|
||||
}
|
||||
}]
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
QT += core network
|
||||
QT -= gui widgets
|
||||
|
||||
DBLIBS += webserverlib
|
||||
|
||||
PROJECT_ROOT = ../..
|
||||
|
||||
SOURCES += main.cpp
|
||||
|
||||
HEADERS +=
|
||||
|
||||
FORMS +=
|
||||
|
||||
RESOURCES +=
|
||||
|
||||
TRANSLATIONS +=
|
||||
|
||||
configinstall.path = $${OUT_PWD}/$${PROJECT_ROOT}/bin
|
||||
configinstall.files = webserver.json
|
||||
INSTALLS += configinstall
|
||||
|
||||
include($${PROJECT_ROOT}/app.pri)
|
||||
Reference in new issue
Block a user