From 5e05f276c5ea784df0de86d70bf7aab2e5de32d5 Mon Sep 17 00:00:00 2001 From: onefang Date: Thu, 9 Sep 2021 12:30:24 +1000 Subject: Rejig the web stuff. Move to examples to example/var/www. Move the web socket to scRoot/var/run. Make the name of the web socket configurable. Populate the scRoot/var/www from exomples if it's empty. Everyone uses SledjChisl.css now. Some clean ups. Comment++ --- src/.sledjChisl.conf.lua | 7 ++-- src/sledjchisl/sledjchisl.c | 83 ++++++++++++++++++++------------------------- 2 files changed, 40 insertions(+), 50 deletions(-) (limited to 'src') diff --git a/src/.sledjChisl.conf.lua b/src/.sledjChisl.conf.lua index cede4e4..61d709d 100644 --- a/src/.sledjChisl.conf.lua +++ b/src/.sledjChisl.conf.lua @@ -14,7 +14,7 @@ config = ["debug"] = false; ["scUser"] = "opensimsc"; ["Tconsole"] = "SledjChisl"; - ["Tsocket"] = "opensim-tmux.socket"; + ["Tsocket"] = "opensim-tmux.socket"; -- Ends up in scRoot/var/run ["Ttab"] = "SC"; ["loadAverageInc"] = 0.7; ["simTimeOut"] = 45; -- seconds @@ -22,9 +22,8 @@ config = ["backupIARsim"] = "Sandbox"; ["rsync"] = ""; ["rsyncPort"] = 0; - ["webRoot"] = "/var/www/html"; - ["webHost"] = "localhost"; - ["URL"] = "sledjchisl.fcgi"; + ["webRoot"] = "/var/www/html"; -- Relative to scRoot. + ["webSocket"] = "sledjchisl.socket"; -- Ends up in scRoot/var/run ["webIframers"] = ""; -- Space separated list of hosts allowed to iFrame us, coz someone asked. Include the "https://" bit. ["seshRenew"] = 10 * 60; -- seconds ["idleTimeOut"] = 30 * 60; -- seconds diff --git a/src/sledjchisl/sledjchisl.c b/src/sledjchisl/sledjchisl.c index b333357..e5e6460 100644 --- a/src/sledjchisl/sledjchisl.c +++ b/src/sledjchisl/sledjchisl.c @@ -535,7 +535,7 @@ char *backupIARsim = "Sandbox"; char *rSync = ""; int rSyncPort = 0; char *webRoot = "/var/www/html"; -char *URL = "fcgi-bin/sledjchisl.fcgi"; +char *webSocket = "sledjchisl.socket"; char *ToS = "Be good."; char *webIframers = ""; int seshRenew = 10 * 60; @@ -1428,7 +1428,6 @@ static void testOpenSim(simData *simd, char *sim, char *type, int count, int win - static int getIntFromIni(qlisttbl_t *ini, char *name) { int ret; @@ -4151,6 +4150,7 @@ cookie *setCookie(reqData *Rd, char *cki, char *value) ret->httpOnly = TRUE; ret->site = CS_STRICT; ret->secure = TRUE; +// TODO - can we use Rd->Script here? ret->path = getStrH(Rd->headers, "SCRIPT_NAME"); Rd->Rcookies->put(Rd->Rcookies, cook, ret, sizeof(cookie)); free(ret); @@ -4259,27 +4259,13 @@ static void HTMLheader(qgrow_t *reply, char *title) " %s\n" " \n" " \n" + " \n" , title); - reply->addstrf(reply, " \n"); if (DEBUG) reply->addstrf(reply, " \n"); reply->addstrf(reply, - " \n" " \n" " \n" " \n" @@ -5080,9 +5066,6 @@ t("checkSLOSpassword(%s, %s, %s, ", password, salt, passwordHash, fail); return ret; } - - - char *checkLinky(reqData *Rd) { // TODO - should be from Rd.shs->linky-hashish @@ -5109,7 +5092,10 @@ char *checkLinky(reqData *Rd) // "%s" "

\n", "grid_no_reply", Rd->Host, - Rd->Host, Rd->RUri + "grid_no_reply", Rd->Host, + "grid_no_reply", Rd->Host, + "grid_no_reply", Rd->Host +// Rd->Host, Rd->RUri // ,t1, t0 ); free(t1); @@ -8073,12 +8059,12 @@ static void cleanup(void) { C("Caught signal, or quitting, cleaning up."); - char *cmd = xmprintf("%s/sledjchisl.socket", scRun); + char *cmd = xmprintf("%s/%s", scRun, webSocket); if (isWeb && qfile_exist(cmd)) { V("Deleting web socket."); - if (shellMeFail("rm %s/sledjchisl.socket", scRun)) + if (shellMeFail("rm %s/%s", scRun, webSocket)) E("rm command failed!"); } free(cmd); @@ -8191,7 +8177,7 @@ int scanForConfigs(char **cPaths) if ((tmp = configs->getstr(configs, "rsync", false)) != NULL) {rSync = tmp; V("Setting rsync = %s", rSync);} if ((vd = configs->getstr(configs, "rsyncPort", false)) != NULL) {rSyncPort = (int) *((float *) vd); V("Setting rsyncPort = %s", rSyncPort);} if ((tmp = configs->getstr(configs, "webRoot", false)) != NULL) {webRoot = tmp; V("Setting webRoot = %s", webRoot);} - if ((tmp = configs->getstr(configs, "URL", false)) != NULL) {URL = tmp; V("Setting URL = %s", URL);} + if ((tmp = configs->getstr(configs, "webSocket", false)) != NULL) {webSocket = tmp; V("Setting webSocket = %s", webSocket);} if ((vd = configs->get (configs, "seshRenew", NULL, false)) != NULL) {seshRenew = (int) *((float *) vd); V("Setting seshRenew = %d", seshRenew);} if ((vd = configs->get (configs, "idleTimeOut", NULL, false)) != NULL) {idleTimeOut = (int) *((float *) vd); V("Setting idleTimeOut = %d", idleTimeOut);} if ((vd = configs->get (configs, "seshTimeOut", NULL, false)) != NULL) {seshTimeOut = (int) *((float *) vd); V("Setting seshTimeOut = %d", seshTimeOut);} @@ -8483,7 +8469,7 @@ Copy correct config/config.ini to there. // A bit chicken and egg here. // We need to be the correct user to set the correct perms on the scRun directory // But we wont be the correct user until we run tmux as that user. -// The path to sledjchisl.socket needs to be readable by the www-data group. So the FCGI socket will work. +// The path to the web socket needs to be readable by the www-data group. So the FCGI socket will work. // AND it needs to be group sticky on opensimsc group. So the tmux socket will work. // Put both in scRun, and make it other readable? // TODO - No idea of the SECURITY HOLE that might cause. @@ -8570,7 +8556,7 @@ Copy correct config/config.ini to there. // Make the FCGI socket world read / write, coz we can't set it to group www-data, since -G only works for root, and we ain't root. // TODO - BIG SECURITY HOLE??? "bash -c 'export PATH=%s:$PATH; printf \"\\033]0;FCGI web server\\007\"; sleep 2;" // The sleep is so that both are not creating the .shini files at the same time. - "spawn-fcgi -n -u %s -s %s/sledjchisl.socket -M 0666 -G www-data -- /usr/bin/valgrind --leak-check=full %s/current/bin/sledjchisl %s; " + "spawn-fcgi -n -u %s -s %s/%s -M 0666 -G www-data -- /usr/bin/valgrind --leak-check=full %s/current/bin/sledjchisl %s; " "cd %s; bash'" , pre, Tcmd, scRun, Tsocket, scBin, @@ -8580,7 +8566,7 @@ Copy correct config/config.ini to there. Tconsole, Tconsole, scBin, - scUser, scRun, scRoot, FLAG(v) ? "-v" : "", + scUser, scRun, webSocket, scRoot, FLAG(v) ? "-v" : "", scRoot ); free(pre); @@ -8638,31 +8624,36 @@ Copy correct config/config.ini to there. and by a privileged process */ V("Making directories in %s.", scRoot); - if ((! qfile_exist(scBin)) && (! qfile_mkdir(scBin, S_IRWXU | S_IRGRP | S_IXGRP, true))) C("Unable to create path %s", scBin); - if ((! qfile_exist(scEtc)) && (! qfile_mkdir(scEtc, S_IRWXU | S_IRGRP | S_IXGRP, true))) C("Unable to create path %s", scEtc); - if ((! qfile_exist(scLib)) && (! qfile_mkdir(scLib, S_IRWXU | S_IRGRP | S_IXGRP, true))) C("Unable to create path %s", scLib); - if ((! qfile_exist(scBackup)) && (! qfile_mkdir(scBackup, S_IRWXU | S_IRGRP | S_IXGRP, true))) C("Unable to create path %s", scBackup); - if ((! qfile_exist(scCache)) && (! qfile_mkdir(scCache, S_IRWXU | S_IRGRP | S_IXGRP, true))) C("Unable to create path %s", scCache); - if ((! qfile_exist(scData)) && (! qfile_mkdir(scData, S_IRWXU | S_IRGRP | S_IXGRP, true))) C("Unable to create path %s", scData); - if ((! qfile_exist(scLog)) && (! qfile_mkdir(scLog, S_IRWXU, true))) C("Unable to create path %s", scLog); - if ((! qfile_exist(scTemp)) && (! qfile_mkdir(scTemp, S_IRWXU | S_IRGRP | S_IXGRP, true))) C("Unable to create path %s", scTemp); + if ((! qfile_exist(scBin)) && (! qfile_mkdir(scBin, S_IRWXU | S_IRGRP | S_IXGRP, true))) C("Unable to create path %s", scBin); + if ((! qfile_exist(scEtc)) && (! qfile_mkdir(scEtc, S_IRWXU | S_IRGRP | S_IXGRP, true))) C("Unable to create path %s", scEtc); + if ((! qfile_exist(scLib)) && (! qfile_mkdir(scLib, S_IRWXU | S_IRGRP | S_IXGRP, true))) C("Unable to create path %s", scLib); + if ((! qfile_exist(scBackup)) && (! qfile_mkdir(scBackup, S_IRWXU | S_IRGRP | S_IXGRP, true))) C("Unable to create path %s", scBackup); + if ((! qfile_exist(scCache)) && (! qfile_mkdir(scCache, S_IRWXU | S_IRGRP | S_IXGRP, true))) C("Unable to create path %s", scCache); + if ((! qfile_exist(scData)) && (! qfile_mkdir(scData, S_IRWXU | S_IRGRP | S_IXGRP, true))) C("Unable to create path %s", scData); + if ((! qfile_exist(scLog)) && (! qfile_mkdir(scLog, S_IRWXU, true))) C("Unable to create path %s", scLog); + if ((! qfile_exist(scTemp)) && (! qfile_mkdir(scTemp, S_IRWXU | S_IRGRP | S_IXGRP, true))) C("Unable to create path %s", scTemp); tmp = xmprintf("%s/sessions", scCache); - if ((! qfile_exist(tmp)) && (! qfile_mkdir(tmp, S_IRWXU | S_IRGRP | S_IXGRP, true))) C("Unable to create path %s", tmp); + if ((! qfile_exist(tmp)) && (! qfile_mkdir(tmp, S_IRWXU | S_IRGRP | S_IXGRP, true))) C("Unable to create path %s", tmp); free(tmp); tmp = xmprintf("%s/users", scData); - if ((! qfile_exist(tmp)) && (! qfile_mkdir(tmp, S_IRWXU | S_IRGRP | S_IXGRP, true))) C("Unable to create path %s", tmp); + if ((! qfile_exist(tmp)) && (! qfile_mkdir(tmp, S_IRWXU | S_IRGRP | S_IXGRP, true))) C("Unable to create path %s", tmp); free(tmp); tmp = xmprintf("%s/db", scData); - if ((! qfile_exist(tmp)) && (! qfile_mkdir(tmp, S_IRWXU | S_IRGRP | S_IXGRP, true))) C("Unable to create path %s", tmp); + if ((! qfile_exist(tmp)) && (! qfile_mkdir(tmp, S_IRWXU | S_IRGRP | S_IXGRP, true))) C("Unable to create path %s", tmp); free(tmp); tmp = xmprintf("%s/config", scRoot); - if ((! qfile_exist(tmp)) && (! qfile_mkdir(tmp, S_IRWXU | S_IRGRP | S_IXGRP, true))) C("Unable to create path %s", tmp); + if ((! qfile_exist(tmp)) && (! qfile_mkdir(tmp, S_IRWXU | S_IRGRP | S_IXGRP, true))) C("Unable to create path %s", tmp); free(tmp); tmp = xmprintf("%s/AssetFiles/data", scRoot); - if ((! qfile_exist(tmp)) && (! qfile_mkdir(tmp, S_IRWXU | S_IRGRP | S_IXGRP, true))) C("Unable to create path %s", tmp); + if ((! qfile_exist(tmp)) && (! qfile_mkdir(tmp, S_IRWXU | S_IRGRP | S_IXGRP, true))) C("Unable to create path %s", tmp); free(tmp); - tmp = xmprintf("%s/web", scRoot); - if ((! qfile_exist(tmp)) && (! qfile_mkdir(tmp, S_IRWXU | S_IRGRP | S_IXGRP, true))) C("Unable to create path %s", tmp); + tmp = xmprintf("%s/var/www/html", scRoot); + if (! qfile_exist(tmp)) + { + if (! qfile_mkdir(tmp, S_IRWXU | S_IRGRP | S_IXGRP, true)) C("Unable to create path %s", tmp); + free(tmp); + if (shellMeFail("cp %s/current/example/var/www/html/* %s/var/www/html", scRoot, scRoot)) C("Unable to copy files to %s/var/www/html", scRoot); + } free(tmp); /* TODO - tighten up security. @@ -9004,7 +8995,7 @@ Create the /opt/opensim-SC directory structure. // FCGI_LISTENSOCK_FILENO is the socket to the web server. // STDOUT and STDERR go to the web servers error log, or at least it does in Apache 2 mod_fcgid. - I("Running SledjChisl inside a web server, pid %d, socket %s/sledjchisl.socket.", getpid(), scRun); + I("Running SledjChisl inside a web server, pid %d, socket %s/%s.", getpid(), scRun, webSocket); if (0 == toys.optc) D("no args"); @@ -9144,7 +9135,7 @@ t("BODY"); free(Body); santize(Rd->body); - D("%s %s://%s%s -> %s%s", Rd->Method, Rd->Scheme, Rd->Host, Rd->RUri, webRoot, Rd->Path); + D("%s %s://%s%s -> %s%s%s", Rd->Method, Rd->Scheme, Rd->Host, Rd->RUri, scRoot, webRoot, Rd->Path); D("Started FCGI web request ROLE = %s, body is %s bytes, pid %d.", Role, Length, getpid()); if (NULL == Rd->Path) @@ -9208,7 +9199,7 @@ t("BODY"); } memset(toybuf, 0, sizeof(toybuf)); - snprintf(toybuf, sizeof(toybuf), "%s%s", webRoot, Rd->Path); + snprintf(toybuf, sizeof(toybuf), "%s%s%s", scRoot, webRoot, Rd->Path); HTMLfile *thisFile = checkHTMLcache(toybuf); if (NULL == thisFile) { @@ -9335,7 +9326,7 @@ sendReply: fcgiDone: FCGI_Finish(); - snprintf(toybuf, sizeof(toybuf), " for %s %s://%s%s -> %s%s", Rd->Method, Rd->Scheme, Rd->Host, Rd->RUri, webRoot, Rd->Path); + snprintf(toybuf, sizeof(toybuf), " for %s %s://%s%s -> %s%s%s", Rd->Method, Rd->Scheme, Rd->Host, Rd->RUri, scRoot, webRoot, Rd->Path); if (NULL != Rd->outQuery) free(Rd->outQuery); if (NULL != Rd->shs.name) free(Rd->shs.name); Rd->shs.name = NULL; -- cgit v1.1