summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2015-05-05 20:53:30 -0700
committerAdam Ierymenko <adam.ierymenko@gmail.com>2015-05-05 20:53:30 -0700
commitb2b32e5969c91e05b0d54feaf64045321f70517b (patch)
treed6206c744822ddb758676daacdb355506e416aa7 /service
parent40f312a827ffecf7d5a233ee5d13b0a3bc88e8a6 (diff)
downloadinfinitytier-b2b32e5969c91e05b0d54feaf64045321f70517b.tar.gz
infinitytier-b2b32e5969c91e05b0d54feaf64045321f70517b.zip
Beginning of HTML+Bootstrap+React UI for new desktop client -- looking like it will be easier than retrofitting the old Qt client for the new API.
Diffstat (limited to 'service')
-rw-r--r--service/ControlPlane.cpp61
-rw-r--r--service/ControlPlane.hpp3
-rw-r--r--service/OneService.cpp2
3 files changed, 35 insertions, 31 deletions
diff --git a/service/ControlPlane.cpp b/service/ControlPlane.cpp
index 3604dd1e..c92087f7 100644
--- a/service/ControlPlane.cpp
+++ b/service/ControlPlane.cpp
@@ -37,8 +37,7 @@
#include "../node/InetAddress.hpp"
#include "../node/Node.hpp"
#include "../node/Utils.hpp"
-
-#define ZT_BUILD_IN_WEB_UI
+#include "../osdep/OSUtils.hpp"
namespace ZeroTier {
@@ -242,9 +241,10 @@ static void _jsonAppend(unsigned int depth,std::string &buf,const ZT1_Peer *peer
buf.append(json);
}
-ControlPlane::ControlPlane(OneService *svc,Node *n) :
+ControlPlane::ControlPlane(OneService *svc,Node *n,const char *uiStaticPath) :
_svc(svc),
- _node(n)
+ _node(n),
+ _uiStaticPath((uiStaticPath) ? uiStaticPath : "")
{
}
@@ -316,31 +316,34 @@ unsigned int ControlPlane::handleRequest(
* dot in the first path element (e.g. foo.html) is considered a static page,
* as nothing in the API is so named. */
-#ifdef ZT_BUILD_IN_WEB_UI
- if (ext == ".html")
- responseContentType = "text/html";
- else if (ext == ".js")
- responseContentType = "application/javascript";
- else if (ext == ".json")
- responseContentType = "application/json";
- else if (ext == ".css")
- responseContentType = "text/css";
- else if (ext == ".png")
- responseContentType = "image/png";
- else if (ext == ".jpg")
- responseContentType = "image/jpeg";
- else if (ext == ".gif")
- responseContentType = "image/gif";
- else if (ext == ".txt")
- responseContentType = "text/plain";
- else if (ext == ".xml")
- responseContentType = "text/xml";
- else if (ext == ".svg")
- responseContentType = "image/svg+xml";
- else responseContentType = "application/octet-stream";
- responseBody = "<html><body>Hello World!</body></html>";
- scode = 200;
-#endif // ZT_BUILD_IN_WEB_UI
+ if (_uiStaticPath.length() > 0) {
+ if (ext == ".html")
+ responseContentType = "text/html";
+ else if (ext == ".js")
+ responseContentType = "application/javascript";
+ else if (ext == ".jsx")
+ responseContentType = "text/jsx";
+ else if (ext == ".json")
+ responseContentType = "application/json";
+ else if (ext == ".css")
+ responseContentType = "text/css";
+ else if (ext == ".png")
+ responseContentType = "image/png";
+ else if (ext == ".jpg")
+ responseContentType = "image/jpeg";
+ else if (ext == ".gif")
+ responseContentType = "image/gif";
+ else if (ext == ".txt")
+ responseContentType = "text/plain";
+ else if (ext == ".xml")
+ responseContentType = "text/xml";
+ else if (ext == ".svg")
+ responseContentType = "image/svg+xml";
+ else responseContentType = "application/octet-stream";
+ scode = OSUtils::readFile((_uiStaticPath + ZT_PATH_SEPARATOR_S + ps[0]).c_str(),responseBody) ? 200 : 404;
+ } else {
+ scode = 404;
+ }
} else if (isAuth) {
/* Things that require authentication -- a.k.a. everything but static web app pages. */
diff --git a/service/ControlPlane.hpp b/service/ControlPlane.hpp
index 3db1ddd0..b7b0a857 100644
--- a/service/ControlPlane.hpp
+++ b/service/ControlPlane.hpp
@@ -49,7 +49,7 @@ struct InetAddress;
class ControlPlane
{
public:
- ControlPlane(OneService *svc,Node *n);
+ ControlPlane(OneService *svc,Node *n,const char *uiStaticPath);
~ControlPlane();
/**
@@ -102,6 +102,7 @@ public:
private:
OneService *const _svc;
Node *const _node;
+ std::string _uiStaticPath;
std::set<std::string> _authTokens;
std::map<std::string,ControlPlaneSubsystem *> _subsystems;
Mutex _lock;
diff --git a/service/OneService.cpp b/service/OneService.cpp
index 421b47dd..56b1d979 100644
--- a/service/OneService.cpp
+++ b/service/OneService.cpp
@@ -226,7 +226,7 @@ public:
if (_master)
_node->setNetconfMaster((void *)_master);
- _controlPlane = new ControlPlane(this,_node);
+ _controlPlane = new ControlPlane(this,_node,(_homePath + ZT_PATH_SEPARATOR_S + "ui").c_str());
_controlPlane->addAuthToken(authToken.c_str());
if (_master)
_controlPlane->mount("controller",reinterpret_cast<ControlPlaneSubsystem *>(_master));