Skip to content
Snippets Groups Projects
Commit 35b37fa0 authored by Sergey Linev's avatar Sergey Linev Committed by Olivier Couet
Browse files

http: Introduce TCivetwebSSL class for https-only servers

It is small sub-class, which allows to start http server like: 

    new THttpServer("https:4567?ssl_cert=certificate.pem");

Certificate should be provided in any case
parent 7f0c9ac2
No related branches found
No related tags found
No related merge requests found
......@@ -9,6 +9,7 @@
#pragma link C++ class THttpWSHandler;
#pragma link C++ class TFastCgi;
#pragma link C++ class TCivetweb;
#pragma link C++ class TCivetwebSSL;
#pragma link C++ class THttpLongPollEngine;
#pragma link C++ class THttpCallArg;
......
......@@ -25,6 +25,8 @@ protected:
virtual void Terminate() { fTerminating = kTRUE; }
virtual Bool_t IsSecured() const { return kFALSE; }
public:
TCivetweb();
virtual ~TCivetweb();
......@@ -42,4 +44,16 @@ public:
ClassDef(TCivetweb, 0) // http server implementation, based on civetweb embedded server
};
//=========================================================================
class TCivetwebSSL : public TCivetweb {
protected:
virtual Bool_t IsSecured() const { return kTRUE; }
public:
TCivetwebSSL() = default;
ClassDef(TCivetwebSSL, 0) // using only https protocol
};
#endif
......@@ -400,6 +400,7 @@ Int_t TCivetweb::ProcessLog(const char *message)
/// Extra parameters like in URL string could be specified after '?' mark:
/// thrds=N - there N is number of threads used by the civetweb (default is 10)
/// top=name - configure top name, visible in the web browser
/// ssl_certificate=filename - SSL certificate, see docs/OpenSSL.md from civetweb
/// auth_file=filename - authentication file name, created with htdigets utility
/// auth_domain=domain - authentication domain
/// websocket_timeout=tm - set web sockets timeout in seconds (default 300)
......@@ -417,17 +418,18 @@ Bool_t TCivetweb::Create(const char *args)
memset(fCallbacks, 0, sizeof(struct mg_callbacks));
//((struct mg_callbacks *) fCallbacks)->begin_request = begin_request_handler;
((struct mg_callbacks *)fCallbacks)->log_message = log_message_handler;
TString sport = "8080", num_threads = "10", websocket_timeout = "300000";
TString sport = IsSecured() ? "8480s" : "8080", num_threads = "10", websocket_timeout = "300000";
TString auth_file, auth_domain, log_file, ssl_cert;
Bool_t use_ws = kTRUE;
// extract arguments
if ((args != 0) && (strlen(args) > 0)) {
if (args && (strlen(args) > 0)) {
// first extract port number
sport = "";
while ((*args != 0) && (*args != '?') && (*args != '/'))
sport.Append(*args++);
if (IsSecured() && (sport.Index("s")==kNPOS)) sport.Append("s");
// than search for extra parameters
while ((*args != 0) && (*args != '?'))
......@@ -440,11 +442,11 @@ Bool_t TCivetweb::Create(const char *args)
url.ParseOptions();
const char *top = url.GetValueFromOptions("top");
if (top != 0)
if (top)
fTopName = top;
const char *log = url.GetValueFromOptions("log");
if (log != 0)
if (log)
log_file = log;
Int_t thrds = url.GetIntValueFromOptions("thrds");
......@@ -452,15 +454,15 @@ Bool_t TCivetweb::Create(const char *args)
num_threads.Form("%d", thrds);
const char *afile = url.GetValueFromOptions("auth_file");
if (afile != 0)
if (afile)
auth_file = afile;
const char *adomain = url.GetValueFromOptions("auth_domain");
if (adomain != 0)
if (adomain)
auth_domain = adomain;
const char *sslc = url.GetValueFromOptions("ssl_cert");
if (sslc != 0)
if (sslc)
ssl_cert = sslc;
Int_t wtmout = url.GetIntValueFromOptions("websocket_timeout");
......@@ -516,9 +518,9 @@ Bool_t TCivetweb::Create(const char *args)
if (ssl_cert.Length() > 0) {
options[op++] = "ssl_certificate";
options[op++] = ssl_cert.Data();
}
} else if (IsSecured()) Error("Create", "No SSL certificate file configured");
options[op++] = 0;
options[op++] = nullptr;
// Start the web server.
fCtx = mg_start((struct mg_callbacks *)fCallbacks, this, options);
......@@ -526,11 +528,11 @@ Bool_t TCivetweb::Create(const char *args)
if (!fCtx)
return kFALSE;
mg_set_request_handler((struct mg_context *)fCtx, "/", begin_request_handler, 0);
mg_set_request_handler((struct mg_context *)fCtx, "/", begin_request_handler, nullptr);
if (use_ws)
mg_set_websocket_handler((struct mg_context *)fCtx, "**root.websocket$", websocket_connect_handler,
websocket_ready_handler, websocket_data_handler, websocket_close_handler, 0);
websocket_ready_handler, websocket_data_handler, websocket_close_handler, nullptr);
return kTRUE;
}
......@@ -355,10 +355,10 @@ Bool_t THttpServer::CreateEngine(const char *engine)
if ((clname.Length() == 0) || (clname == "http") || (clname == "civetweb"))
clname = "TCivetweb";
else if (clname == "https")
clname = "TCivetwebSSL";
else if (clname == "fastcgi")
clname = "TFastCgi";
else if (clname == "dabc")
clname = "TDabcEngine";
// ensure that required engine class exists before we try to create it
TClass *engine_class = gROOT->LoadClass(clname.Data());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment