Warning: session_start(): open(/var/lib/php/sessions/sess_lt7enaiflopvbcv27ir9l5291g, 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 GazelleContextCache contextCache;
transient new ThreadLocal bodyParams;
transient new ThreadLocal authed;
int absoluteMaxResults = 1000, defaultMaxResults = 100;
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);
temp tempSetTL(this.authed, authed);
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" := moreForMsgID(line.msgID)
);
}), 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;
long startTime = sysNow();
L tree = dm_gazelle_revisitChatLine(msgID,
ctx := contextCache!);
long endTime = sysNow();
//print("Tree to string.");
S tv = treeViewToString_withoutHijackPrint(gazelle_treeView(tree),
stringifier := func(TreeView t) -> S { gazelleTreeToHTML(t.node()) });
//print("children=" + l(tree) + ", tv = " + quote(tv));
ret hframe("Revisiting msg " + msgID,
hheading("Revisiting message " + msgID + ": " + htmlEncode2(line.text))
+ nlToBr_withIndents(tv)
+ p((endTime-startTime) + " ms"));
}
Request request = new(authed, params);
if (swic(uri, "/rule/", m)) {
S ruleID = assertGlobalID(m.rest());
ret request.serveRule(ruleID, params);
}
if (eq(uri, "/search"))
ret search(params);
if (eq(uri, "/wikipedia"))
ret request.serveWikipedia();
if (eq(uri, "/commands"))
ret hhtml_head_title_body("Commands | Gazelle",
hprelude() +
linesLL(hheading("Commands"),
h3("!eval"),
p([[You can evaluate Java code directly through Discord.
Unless you are specifically authorized, only a ]] + ahref(rawSelfLink("safeIdentifiers"), "safe subset of identifiers") + " is allowed."),
p("Example: " + tt("!eval 1+2")),
p("In rare cases " + tt("!eval") + " may fail and you need to type " + tt("!real-eval") + " instead (which invokes an actual Java compiler).")), bodyParams);
if (eq(uri, "/safeIdentifiers"))
ret hhtml_head_title_body("Safe Java Identifiers | Gazelle",
hprelude() +
linesLL(
hheading("Safe Java(X) identifiers for !eval"),
hpre(lines(sortedIC(codeAnalysis_allSafeIdentifiers())))), bodyParams);
if (!eq(uri, "/"))
ret serve404();
//final Map feedbackStats = dm_gazelle_feedbackStats();
final Map feedbackStats2 = dm_gazelle_feedbackStatsByJudgement();
final Map feedbackStats3 = dm_gazelle_feedbackStatsForNonJudged();
// Home Page / Main List
L> rules = dm_allRulesFromRulesModuleWithCommentsAndIDs();
// dm_gazelle_allRulesWithComment("discord");
bool showAll = eq("1", params.get('showAll));
L