From d80fe50ade9d74b83310b926d0d98037ecdac1d8 Mon Sep 17 00:00:00 2001 From: onefang Date: Wed, 22 Apr 2020 05:51:40 +1000 Subject: Various fixes and additions I'm too tired to untangle now. lol Method to include a query in the GET redirection. More testing instructions. More stuff v shs sanity. Various functions changed from figuring out their arguments to just pass them in. Changed some function names. Added "You are person X" linky at top of logged in pages. Allow gods to edit the level of others. No doubt various small things I forgot. lol --- src/sledjchisl/sledjchisl.c | 372 +++++++++++++++++++++++++++++--------------- 1 file changed, 249 insertions(+), 123 deletions(-) (limited to 'src/sledjchisl') diff --git a/src/sledjchisl/sledjchisl.c b/src/sledjchisl/sledjchisl.c index f6f8f9d..8fb505b 100644 --- a/src/sledjchisl/sledjchisl.c +++ b/src/sledjchisl/sledjchisl.c @@ -380,7 +380,7 @@ struct _reqData { lua_State *L; qhashtbl_t *configs, *queries, *body, *cookies, *headers, *valid, *stuff, *database, *Rcookies, *Rheaders; - char *Scheme, *Host, *Method, *Script, *RUri, *doit, *form, *output; + char *Scheme, *Host, *Method, *Script, *RUri, *doit, *form, *output, *outQuery; sesh shs, *lnk; MYSQL *db; gridStats *stats; @@ -2539,6 +2539,8 @@ static void HTMLfooter(qgrow_t *reply) " So feel free to create as many test accounts as you need to test things.
\n" "We follow the usual web site registration process, which sends a validation email, with a link to click. " " However, during this test mode, no emails will be sent, instead a link will be displayed near the top of the page when a user is logged in.
\n" + "After creating an account, log on as your grid god account, click the 'validated members' button, click on the new member, set their level to 'approved', " + " then click on the 'save' button. In theory that will create their in world account, in practice I still haven't written that bit.
" "Missing bits that are still being written - sending the emails, creating real grid accounts, editing accounts, listing accounts, deleting accounts.
\n" " \n"); // reply->addstr(reply, "Title / level : %s / %d
", getLevel(Rd), Rd->shs.level); + Rd->reply->addstrf(Rd->reply, "Name : %s
", name); + Rd->reply->addstrf(Rd->reply, "Title / level : %s / %s
", getLevel(atoi(level)), level); Rd->reply->addstrf(Rd->reply, "Date of birth : %s
", getStrH(Rd->database, "Lua.DoB")); Rd->reply->addstrf(Rd->reply, "Created : %s
", ctime(&crtd)); Rd->reply->addstrf(Rd->reply, "Email : %s
", email); - Rd->reply->addstrf(Rd->reply, "UUID : %s
", Rd->shs.UUID); + Rd->reply->addstrf(Rd->reply, "UUID : %s
", getStrH(Rd->database, "UserAccounts.PrincipalID")); Rd->reply->addstrf(Rd->reply, "Voucher : %s
", voucher); // Rd->reply->addstrf(Rd->reply, "About :
" // "", qurl_decode(getStrH(Rd->database, "Lua.aboutMe"))); @@ -4332,43 +4351,65 @@ static void accountViewWeb(reqData *Rd, inputForm *oF, inputValue *oV) static void accountEditWeb(reqData *Rd, inputForm *oF, inputValue *oV) { - char *name = getStrH(Rd->stuff, "name"); + char *name = getStrH(Rd->database, "Lua.name"), + *level = getStrH(Rd->database, "UserAccounts.UserLevel"), + *email = displayPrep(getStrH(Rd->database, "UserAccounts.Email")), + *voucher = displayPrep(getStrH(Rd->database, "Lua.voucher")), + *about = displayPrep(getStrH(Rd->database, "Lua.aboutMe")), + *lvl = getLevel(atoi(level)); - accountWebHeaders(Rd, oF, name); + accountWebHeaders(Rd, oF); accountWebFields(Rd, oF, oV); - HTMLtext(Rd->reply, "password", "Old password", "password", "", 16, 0, FALSE); - Rd->reply->addstr(Rd->reply, "Warning, the limit on password length is set by your viewer, some can't handle longer than 16 characters.
\n"); +// HTMLtext(Rd->reply, "password", "Old password", "password", "", 16, 0, FALSE); +// Rd->reply->addstr(Rd->reply, "Warning, the limit on password length is set by your viewer, some can't handle longer than 16 characters.
\n"); //// HTMLtext(Rd->reply, "title", "text", "title", getStrH(Rh->stuff, "title"), 16, 64, TRUE); - qlisttbl_obj_t obj; - char *lvl = getLevel(Rd); + HTMLhidden(Rd->reply, "user", name); + Rd->reply->addstrf(Rd->reply, "Name : %s
", name); + Rd->reply->addstrf(Rd->reply, "Email : %s
", email); + Rd->reply->addstrf(Rd->reply, "Voucher : %s
", voucher); - HTMLselect(Rd->reply, "level", "level"); - memset((void*)&obj, 0, sizeof(obj)); // must be cleared before call - accountLevels->lock(accountLevels); - while(accountLevels->getnext(accountLevels, &obj, NULL, false) == true) + if (200 <= Rd->shs.level) { - boolean is = false; + qlisttbl_obj_t obj; - if (strcmp(lvl, (char *) obj.data) == 0) - is = true; - HTMLoption(Rd->reply, (char *) obj.data, is); + HTMLselect(Rd->reply, "level", "level"); + memset((void*)&obj, 0, sizeof(obj)); // must be cleared before call + accountLevels->lock(accountLevels); + while(accountLevels->getnext(accountLevels, &obj, NULL, false) == true) + { + boolean is = false; + + if (strcmp(lvl, (char *) obj.data) == 0) + is = true; + HTMLoption(Rd->reply, (char *) obj.data, is); + } + accountLevels->unlock(accountLevels); + HTMLselectEnd(Rd->reply); + + Rd->reply->addstrf(Rd->reply, "Title / level : %s / %s
", lvl, level); accountWebSubs(Rd, oF); accountWebFooter(Rd, oF); } -static int accountRead(reqData *Rd, inputForm *iF, inputValue *iV) +static int accountRead(reqData *Rd, char *uuid, char *firstName, char *lastName) { int ret = 0, rt = -1; struct stat st; struct timespec now; qhashtbl_t *tnm = qhashtbl(0, 0); - char *uuid, *first, *last; uuid_t binuuid; rowData *rows = NULL; @@ -4413,7 +4454,33 @@ static int accountRead(reqData *Rd, inputForm *iF, inputValue *iV) dbRequests->addfirst(dbRequests, auth, sizeof(*auth)); } - uuid = Rd->shs.UUID; first = getStrH(Rd->stuff, "firstName"); last = getStrH(Rd->stuff, "lastName"); +// uuid = Rd->shs.UUID; first = getStrH(Rd->stuff, "firstName"); last = getStrH(Rd->stuff, "lastName"); + + // Special for showing another users details. + if ('\0' != getStrH(Rd->queries, "user")[0]) + uuid = ""; + + char *first = xstrdup(""), *last = xstrdup(""); + + if (NULL != firstName) + { + first = xstrdup(firstName); + if (NULL == lastName) + { + char *t = strchr(first, ' '); + +d("accountRead() single name |%s| |%s|", first, last); + if (NULL == t) + t = strchr(first, '+'); + if (NULL != t) + { + *t++ = '\0'; + last = xstrdup(t); + } + } + else + last = xstrdup(lastName); + } d("accountRead() UUID %s, name %s %s", uuid, first, last); uuid_clear(binuuid); if ((NULL != uuid) && ('\0' != uuid[0])) @@ -4471,10 +4538,16 @@ d("accountRead() UUID %s, name %s %s", uuid, first, last); } else if (rows) { + ret += rows->rows->size(rows->rows); if (1 == ret) { dbPull(Rd, "UserAccounts", rows); + + char *name = xmprintf("%s %s", getStrH(Rd->database, "UserAccounts.FirstName"), getStrH(Rd->database, "UserAccounts.LastName")); + + Rd->database->putstr(Rd->database, "Lua.name", name); + free(name); dbDoSomething(auth, FALSE, getStrH(Rd->database, "UserAccounts.PrincipalID")); rows = auth->rows; if (rows) @@ -4492,19 +4565,28 @@ d("accountRead() UUID %s, name %s %s", uuid, first, last); if (1 == ret) { // TODO - this has to change when we are editing other peoples accounts. - Rd->shs.UUID = Rd->database->getstr(Rd->database, "UserAccounts.PrincipalID", true); - Rd->stuff->putstr(Rd->stuff, "email", getStrH(Rd->database, "UserAccounts.Email")); - Rd->shs.level = atoi(getStrH(Rd->database, "UserAccounts.UserLevel")); + if ('\0' == getStrH(Rd->queries, "user")[0]) + { +// Rd->shs.level = atoi(getStrH(Rd->database, "UserAccounts.UserLevel")); +// TODO - might have to combine first and last here. +// Rd->shs.name = Rd->database->getstr(Rd->database, "Lua.name", true); +// Rd->shs.UUID = Rd->database->getstr(Rd->database, "UserAccounts.PrincipalID", true); +//d("accountRead() setting session uuid %s level %d name %s ", Rd->shs.UUID, (int) Rd->shs.level, Rd->shs.name); + } +// Rd->stuff->putstr(Rd->stuff, "email", getStrH(Rd->database, "UserAccounts.Email")); } + free(last); + free(first); tnm->free(tnm); return ret; } -static int accountDel(reqData *Rd, inputForm *iF, inputValue *iV) +static int accountDelSub(reqData *Rd, inputForm *iF, inputValue *iV) { int ret = 0; - int c = accountRead(Rd, iF, iV); + char *uuid = Rd->shs.UUID, *first = getStrH(Rd->stuff, "firstName"), *last = getStrH(Rd->stuff, "lastName"); + int c = accountRead(Rd, uuid, first, last); if (1 != c) { @@ -4519,10 +4601,12 @@ static int accountDel(reqData *Rd, inputForm *iF, inputValue *iV) } return ret; } -static int accountCreate(reqData *Rd, inputForm *iF, inputValue *iV) + +static int accountCreateSub(reqData *Rd, inputForm *iF, inputValue *iV) { int ret = 0; - int c = accountRead(Rd, iF, iV); + char *uuid = Rd->shs.UUID, *first = getStrH(Rd->stuff, "firstName"), *last = getStrH(Rd->stuff, "lastName"); + int c = accountRead(Rd, uuid, first, last); boolean wipe = FALSE; if (strcmp("POST", Rd->Method) == 0) @@ -4558,10 +4642,12 @@ static int accountCreate(reqData *Rd, inputForm *iF, inputValue *iV) newSesh(Rd, FALSE); return ret; } -static int accountAdd(reqData *Rd, inputForm *iF, inputValue *iV) + +static int accountAddSub(reqData *Rd, inputForm *iF, inputValue *iV) { int ret = 0; - int c = accountRead(Rd, iF, iV); + char *uuid = Rd->shs.UUID, *first = getStrH(Rd->stuff, "firstName"), *last = getStrH(Rd->stuff, "lastName"); + int c = accountRead(Rd, uuid, first, last); boolean wipe = FALSE; if (0 != c) @@ -4587,11 +4673,12 @@ static int accountAdd(reqData *Rd, inputForm *iF, inputValue *iV) Rd->stuff->putstr(Rd->stuff, "passwordHash", getStrH(Rd->stuff, "passHash")); Rd->stuff->putstr(Rd->stuff, "passwordSalt", getStrH(Rd->stuff, "passSalt")); Rd->shs.level = -200; + Rd->database->putstr(Rd->database, "UserAccounts.UserLevel", "-200"); freeSesh(Rd, FALSE, wipe); newSesh(Rd, TRUE); accountWrite(Rd); // log them in - I("Logged on %s %s Level %d %s", Rd->shs.UUID, getStrH(Rd->stuff, "name"), Rd->shs.level, getLevel(Rd)); + I("Logged on %s %s Level %d %s", Rd->shs.UUID, getStrH(Rd->stuff, "name"), Rd->shs.level, getLevel(Rd->shs.level)); Rd->output = "accountView"; Rd->form = "accountView"; Rd->doit = "login"; @@ -4603,10 +4690,11 @@ static int accountAdd(reqData *Rd, inputForm *iF, inputValue *iV) return ret; } -static int accountSave(reqData *Rd, inputForm *iF, inputValue *iV) +static int accountSaveSub(reqData *Rd, inputForm *iF, inputValue *iV) { int ret = 0; - int c = accountRead(Rd, iF, iV); + char *uuid = Rd->shs.UUID, *first = getStrH(Rd->body, "user"), *last = NULL; + int c = accountRead(Rd, NULL, first, last); boolean wipe = FALSE; if (1 != c) @@ -4616,31 +4704,45 @@ static int accountSave(reqData *Rd, inputForm *iF, inputValue *iV) } else if ((0 == ret) && (strcmp("POST", Rd->Method) == 0)) { - char *h = checkSLOSpassword(Rd, getStrH(Rd->stuff, "passSalt"), getStrH(Rd->body, "password"), getStrH(Rd->stuff, "passHash"), "Passwords are not the same."); - if (NULL == h) - { - ret++; - wipe = TRUE; - Rd->shs.UUID = NULL; - Rd->output = "accountLogin"; - } - else + Rd->stuff->putstr(Rd->stuff, "email", getStrH(Rd->database, "UserAccounts.Email")); + Rd->stuff->putstr(Rd->stuff, "created", getStrH(Rd->database, "UserAccounts.Created")); + Rd->stuff->putstr(Rd->stuff, "flags", getStrH(Rd->database, "UserAccounts.UserFlags")); + Rd->stuff->putstr(Rd->stuff, "active", getStrH(Rd->database, "UserAccounts.active")); + Rd->stuff->putstr(Rd->stuff, "passwordSalt", getStrH(Rd->database, "auth.passwordSalt")); + Rd->stuff->putstr(Rd->stuff, "passwordHash", getStrH(Rd->database, "auth.passwordHash")); + Rd->stuff->putstr(Rd->stuff, "name", getStrH(Rd->database, "Lua.name")); + Rd->stuff->putstr(Rd->stuff, "DoB", getStrH(Rd->database, "Lua.DoB")); + Rd->stuff->putstr(Rd->stuff, "agree", getStrH(Rd->database, "Lua.agree")); + Rd->stuff->putstr(Rd->stuff, "adult", getStrH(Rd->database, "Lua.adult")); + Rd->stuff->putstr(Rd->stuff, "aboutMe", getStrH(Rd->database, "Lua.aboutMe")); + Rd->stuff->putstr(Rd->stuff, "vouched", getStrH(Rd->database, "Lua.vouched")); + Rd->stuff->putstr(Rd->stuff, "voucher", getStrH(Rd->database, "Lua.voucher")); + + char *lvl = getStrH(Rd->body, "level"); + qlisttbl_obj_t obj; + + memset((void*)&obj, 0, sizeof(obj)); // must be cleared before call + accountLevels->lock(accountLevels); + while(accountLevels->getnext(accountLevels, &obj, NULL, false) == true) { - free(h); - Rd->stuff->putstr(Rd->stuff, "passwordHash", getStrH(Rd->stuff, "passHash")); - Rd->stuff->putstr(Rd->stuff, "passwordSalt", getStrH(Rd->stuff, "passSalt")); - accountWrite(Rd); + if (strcmp(lvl, (char *) obj.data) == 0) + Rd->database->putstr(Rd->database, "UserAccounts.UserLevel", obj.name); } + accountLevels->unlock(accountLevels); + accountWrite(Rd); + free(Rd->outQuery); + Rd->outQuery = xmprintf("?user=%s+%s", getStrH(Rd->database, "UserAccounts.FirstName"), getStrH(Rd->database, "UserAccounts.LastName")); } - freeSesh(Rd, FALSE, wipe); - newSesh(Rd, FALSE); +// freeSesh(Rd, FALSE, wipe); +// newSesh(Rd, FALSE); return ret; } -static int accountValidate(reqData *Rd, inputForm *iF, inputValue *iV) +static int accountValidateSub(reqData *Rd, inputForm *iF, inputValue *iV) { int ret = 0; - int c = accountRead(Rd, iF, iV); + char *uuid = Rd->shs.UUID, *first = getStrH(Rd->stuff, "firstName"), *last = getStrH(Rd->stuff, "lastName"); + int c = accountRead(Rd, uuid, first, last); boolean wipe = FALSE; if (1 != c) @@ -4664,6 +4766,7 @@ static int accountValidate(reqData *Rd, inputForm *iF, inputValue *iV) Rd->stuff->putstr(Rd->stuff, "vouched", getStrH(Rd->database, "Lua.vouched")); Rd->stuff->putstr(Rd->stuff, "voucher", getStrH(Rd->database, "Lua.voucher")); Rd->shs.level = -100; + Rd->database->putstr(Rd->database, "UserAccounts.UserLevel", "-100"); accountWrite(Rd); wipe = TRUE; } @@ -4672,15 +4775,15 @@ static int accountValidate(reqData *Rd, inputForm *iF, inputValue *iV) return ret; } - -static int accountView(reqData *Rd, inputForm *iF, inputValue *iV) +static int accountViewSub(reqData *Rd, inputForm *iF, inputValue *iV) { // TODO - this has to change when we are editing other peoples accounts. int ret = 0; - int c = accountRead(Rd, iF, iV); + char *uuid = Rd->shs.UUID, *first = getStrH(Rd->stuff, "firstName"), *last = getStrH(Rd->stuff, "lastName"); + int c = accountRead(Rd, uuid, first, last); boolean wipe = FALSE; -d("Sub accountView %s %s %s", getStrH(Rd->database, "UserAccounts.PrincipalID"), getStrH(Rd->database, "UserAccounts.FirstName"), getStrH(Rd->database, "UserAccounts.LastName")); +d("Sub accountViewSub() %s %s %s", uuid, first, last); if (1 != c) { bitch(Rd, "Cannot view account.", "Account doesn't exist."); @@ -4693,7 +4796,7 @@ d("Sub accountView %s %s %s", getStrH(Rd->database, "UserAccounts.PrincipalID") { // Check password on POST if the session user is the same as the shown user, coz this is the page shown on login. // Also only check on login. - if ((strcmp("POST", Rd->Method) == 0) && (strcmp(Rd->shs.UUID, getStrH(Rd->database, "UserAccounts.PrincipalID")) == 0) + if ((strcmp("POST", Rd->Method) == 0) //&& (strcmp(Rd->shs.UUID, getStrH(Rd->database, "UserAccounts.PrincipalID")) == 0) && (strcmp("login", Rd->doit) == 0) && (strcmp("accountLogin", Rd->form) == 0)) { char *h = checkSLOSpassword(Rd, getStrH(Rd->database, "auth.passwordSalt"), getStrH(Rd->body, "password"), getStrH(Rd->database, "auth.passwordHash"), "Login failed."); @@ -4706,8 +4809,11 @@ d("Sub accountView %s %s %s", getStrH(Rd->database, "UserAccounts.PrincipalID") } else { + Rd->shs.level = atoi(getStrH(Rd->database, "UserAccounts.UserLevel")); + Rd->shs.name = getStrH(Rd->database, "Lua.name"); + Rd->shs.UUID = getStrH(Rd->database, "UserAccounts.PrincipalID"); free(h); - I("Logged on %s %s Level %d %s", Rd->shs.UUID, getStrH(Rd->stuff, "name"), Rd->shs.level, getLevel(Rd)); + I("Logged on %s %s Level %d %s", Rd->shs.UUID, Rd->shs.name, Rd->shs.level, getLevel(Rd->shs.level)); } } } @@ -4716,12 +4822,13 @@ d("Sub accountView %s %s %s", getStrH(Rd->database, "UserAccounts.PrincipalID") return ret; } -static int accountEdit(reqData *Rd, inputForm *iF, inputValue *iV) +static int accountEditSub(reqData *Rd, inputForm *iF, inputValue *iV) { int ret = 0; - int c = accountRead(Rd, iF, iV); + char *uuid = Rd->shs.UUID, *first = getStrH(Rd->stuff, "firstName"), *last = getStrH(Rd->stuff, "lastName"); + int c = accountRead(Rd, uuid, first, last); -d("Sub accountView %s %s %s", getStrH(Rd->database, "UserAccounts.PrincipalID"), getStrH(Rd->database, "UserAccounts.FirstName"), getStrH(Rd->database, "UserAccounts.LastName")); +d("Sub accountEditSub %s %s %s", uuid, first, last); if (1 != c) { bitch(Rd, "Cannot edit account.", "Account doesn't exist."); @@ -4734,16 +4841,19 @@ d("Sub accountView %s %s %s", getStrH(Rd->database, "UserAccounts.PrincipalID") } return ret; } -static int accountExplore(reqData *Rd, inputForm *iF, inputValue *iV) + +static int accountExploreSub(reqData *Rd, inputForm *iF, inputValue *iV) { int ret = 0; // get a list of user records return ret; } -static int accountOut(reqData *Rd, inputForm *iF, inputValue *iV) + +static int accountOutSub(reqData *Rd, inputForm *iF, inputValue *iV) { int ret = 0; - int c = accountRead(Rd, iF, iV); + char *uuid = Rd->shs.UUID, *first = getStrH(Rd->stuff, "firstName"), *last = getStrH(Rd->stuff, "lastName"); + int c = accountRead(Rd, uuid, first, last); if (1 != c) { @@ -4782,7 +4892,7 @@ static int accountFilterValidated(struct dirtree *node) char *where = xmprintf("%s/users/%s", scData, node->name); int rt = LuaToHash(rdl->Rd, where, "user", tnm, 0, &st, &now, "user"); -//t("accountFilterValidatedVoucher %s (%s) -> %s -> %s", name, getStrH(tnm, "level"), getStrH(tnm, "name"), getStrH(tnm, "voucher")); +t("accountFilterValidatedVoucher %s (%s) -> %s -> %s", name, getStrH(tnm, "level"), getStrH(tnm, "name"), getStrH(tnm, "voucher")); if ((0 == rt) && (strcmp("-100", getStrH(tnm, "level")) == 0)) rdl->list->put(rdl->list, getStrH(tnm, "name"), tnm, sizeof(*tnm)); else @@ -4808,10 +4918,10 @@ qlisttbl_t *getAccounts(reqData *Rd) static void accountExploreValidatedVouchersWeb(reqData *Rd, inputForm *oF, inputValue *oV) { qlisttbl_t *list =getAccounts(Rd); - char *name = getStrH(Rd->stuff, "name"); +// char *name = getStrH(Rd->stuff, "name"); Rd->shs.UUID = NULL; - accountWebHeaders(Rd, oF, name); + accountWebHeaders(Rd, oF); accountWebFields(Rd, oF, oV); count = list->size(list); @@ -4829,9 +4939,9 @@ static void accountExploreValidatedVouchersWeb(reqData *Rd, inputForm *oF, input while(list->getnext(list, &obj, NULL, false) == true) { qhashtbl_t *tnm = (qhashtbl_t *) obj.data; - char *nm = qstrreplace("tr", xstrdup(obj.name), " ", "_"); + char *nm = qstrreplace("tr", xstrdup(obj.name), " ", "+"); - Rd->reply->addstrf(Rd->reply, "