Warning: session_start(): open(/var/lib/php/sessions/sess_bp40l6d76n1ao5530pabv1ej1d, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
!7
cmodule GazelleWebServer > DynPrintLogAndEnabled {
transient MyHTTPD server;
new Set authedCookies;
transient new ThreadLocal bodyParams;
void start() ctex {
super.start();
if (!enabled) ret;
dm_useLocalMechListCopies();
server = new MyHTTPD(80);
server.serveFunction = func(S uri, SS parms) {
serve(uri, parms)
};
server.start();
print("HTTP server started on port " + server.getPort());
}
void cleanMeUp {
server.stop();
server = null;
}
O serve(S uri, SS params) enter {
new Matches m;
S cookie = serveHttp_cookieHandling();
bool authed = nempty(cookie) && syncContains(authedCookies, cookie);
print("Cookie: " + cookie + ", authed: " + authed);
S master = trim(loadTextFile(javaxSecretDir("gazelle-master-pw")));
S attempt = params.get('_pass);
if (nempty(attempt) && nempty(cookie) && nempty(master)) {
if (eq(attempt, master)) {
print("Login SUCCEEDED");
syncAdd(authedCookies, cookie);
change();
authed = true;
} else
print("Login FAILED");
}
if (eq(uri, "/favicon.ico"))
ret serveFile(loadLibrary(#1400189), faviconMimeType());
O[] bodyParams = litobjectarray(style := "font-family: Roboto Mono; " + (authed ? "background-color: #FFFF88" : ""));
temp tempSetTL(this.bodyParams, bodyParams);
if (eq(uri, "/login"))
ret hhtml_head_title_body("Login" + " | Gazelle",
hprelude() +
(nempty(master) ? hpostform(hpasswordfield('_pass)) : "No master PW"), bodyParams);
if (swic(uri, "/texts/", m)) {
S textID = m.rest();
if (!possibleMD5(textID)) ret serve404();
ret serveTextFileAsUTF8(javaxDataDir("Gazelle Texts/" + textID));
}
if (eq(uri, "/lastOutput")) {
L lines = reversed(takeLast(10, dm_discord_allBotLines()));
ret hframe("Last Output", hcenter(hheading("Last Output")
+ htmlTable2(
map(lines, line -> {
L applications = dm_gazelle_applicationsForMsgID(line.msgID);
//print("Got " + n2(applications, "application") + " for " + line.msgID + " from " + dm_gazelle_longFeedbackCRUD());
ret litorderedmap(
"Date" := spanTitle("Message ID: " + line.msgID, htmlencode2(localDateWithMinutes(line.timestamp))),
"Gazelle said:" := htmlencode2(line.text),
"Applied rules" := joinWithSpace(map(f ruleLink, collect ruleID(applications)))
);
}), htmlEncode := false, tableParams := litparams(cellpadding := 5))
));
}
if (eq(uri, "/lastInput")) {
L lines = reversed(takeLast(30, dm_discord_allLines()));
ret hframe("Last Input", hcenter(hheading("Last Input")
+ htmlTable2(
map(lines, line -> {
//L applications = dm_gazelle_applicationsForMsgID(line.msgID);
ret litorderedmap(
"Date" := spanTitle("Message ID: " + line.msgID, htmlencode2(localDateWithMinutes(line.timestamp))),
"Author" := htmlencode(line.user),
"Bot?" := htmlencode(line.bot ? "yes" : ""),
"Line" := htmlencode2(line.text),
//"Applied rules" := joinWithSpace(map(f ruleLink, collect ruleID(applications)))
"More" := ahref(rawSelfLink("revisit/" + line.msgID), "revisit")
);
}), htmlEncode := false, tableParams := litparams(cellpadding := 5))
));
}
if (swic(uri, "revisit/", m)) {
long msgID = assertNotZero(parseLong(m.rest()));
GazelleLine line = dm_discord_lineForMsgID(msgID);
if (line == null) ret "Message not found: " + msgID;
L tree = dm_gazelle_revisitChatLine(msgID);
ret hframe("Revisiting msg " + msgID,
hheading("Revisiting message " + msgID + ": " + htmlEncode2(line.text))
+ hblock(lines(tree)));
}
if (swic(uri, "/rule/", m)) {
S ruleID = assertGlobalID(m.rest());
// add rule comment
S comment = trim(params.get("comment"));
if (nempty(comment)) {
if (!authed) comment = "[anon] " + comment;
dm_gazelle_addRuleComments_verbose(ruleID, ll(comment));
}
PairS textAndComment = unnull(dm_textAndCommentForRule(ruleID));
L feedback = dm_gazelle_feedbackForRule(ruleID);
L applications = dm_gazelle_applicationsForRule(ruleID);
Map feedbackByContext = indexByFieldNotNull context(feedback);
S title = "Rule " + ruleID;
bool showStruct = eq("1", params.get('struct));
L list = cloneList(feedback);
for (O o : applications)
if (!containsKey(feedbackByContext, getString context(o)))
list.add(o);
// add feedback comments
for (S applicationID, S text : subMapStartingWith_dropPrefix(params, "comment_")) {
continue if empty(text = trim(text));
if (!authed) text = "[anon] " + text;
O app = findByField(list, globalID := applicationID);
print("Processing comment for " + applicationID + " - " + app);
if (app == null) continue;
Set comments = asSet(tlft(getString comments(app)));
if (!contains(comments, text))
call(app, '_setField, comments := appendWithNewLine(getString comments(app), text));
}
// Serve Rule & Applications & Feedback
L